Compare commits
No commits in common. "174f840226aa7f044251bf6b13e5a19231a3a81c" and "1c43549b8f93463fc99f72b76cb0e5ae278d22a2" have entirely different histories.
174f840226
...
1c43549b8f
@ -6,7 +6,6 @@ import fr.username404.snowygui.gui.SnowyScreen
|
|||||||
import fr.username404.snowygui.gui.elements.ClickBox
|
import fr.username404.snowygui.gui.elements.ClickBox
|
||||||
import net.minecraft.client.input.MouseButtonEvent
|
import net.minecraft.client.input.MouseButtonEvent
|
||||||
import org.lwjgl.glfw.GLFW
|
import org.lwjgl.glfw.GLFW
|
||||||
import kotlin.math.roundToInt
|
|
||||||
|
|
||||||
object ClickGui: SnowyScreen() {
|
object ClickGui: SnowyScreen() {
|
||||||
override val components = mutableSetOf<Element>()
|
override val components = mutableSetOf<Element>()
|
||||||
@ -19,8 +18,8 @@ object ClickGui: SnowyScreen() {
|
|||||||
|
|
||||||
private var draggingBox: String? = null
|
private var draggingBox: String? = null
|
||||||
private inline fun currentBoxContext(args: ClickBox.() -> Unit): Unit? = draggingBox?.run { boxContext { if (name.string == draggingBox) args() } }
|
private inline fun currentBoxContext(args: ClickBox.() -> Unit): Unit? = draggingBox?.run { boxContext { if (name.string == draggingBox) args() } }
|
||||||
private var offsetX: Double = 0.0
|
private var offsetX: Double = 0.0;
|
||||||
private var offsetY: Double = 0.0
|
private var offsetY: Double = 0.0;
|
||||||
override fun mouseClicked(event: MouseButtonEvent, isDoubleClick: Boolean): Boolean {
|
override fun mouseClicked(event: MouseButtonEvent, isDoubleClick: Boolean): Boolean {
|
||||||
if (event.input() == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
|
if (event.input() == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
|
||||||
clickBoxes.find { it.isWithinBounds(event.x, event.y) }?.let { draggingBox = it.name.string }
|
clickBoxes.find { it.isWithinBounds(event.x, event.y) }?.let { draggingBox = it.name.string }
|
||||||
@ -37,12 +36,8 @@ object ClickGui: SnowyScreen() {
|
|||||||
override fun mouseDragged(event: MouseButtonEvent, mouseX: Double, mouseY: Double): Boolean {
|
override fun mouseDragged(event: MouseButtonEvent, mouseX: Double, mouseY: Double): Boolean {
|
||||||
if (event.input() == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
|
if (event.input() == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
|
||||||
currentBoxContext {
|
currentBoxContext {
|
||||||
val targetX = (event.x + offsetX).coerceIn(0.0..this@ClickGui.width - width.toDouble())
|
x = (event.x + offsetX).coerceIn(0.0..this@ClickGui.width - width.toDouble())
|
||||||
val targetY = (event.y + offsetY).coerceIn(0.0..this@ClickGui.height - height.toDouble())
|
y = (event.y + offsetY).coerceIn(0.0..this@ClickGui.height - height.toDouble())
|
||||||
|
|
||||||
// Snap to integer pixels => stable spacing
|
|
||||||
x = targetX.roundToInt().toDouble()
|
|
||||||
y = targetY.roundToInt().toDouble()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.mouseDragged(event, mouseX, mouseY)
|
return super.mouseDragged(event, mouseX, mouseY)
|
||||||
|
|||||||
@ -12,8 +12,6 @@ import net.minecraft.client.Minecraft
|
|||||||
import net.minecraft.client.gui.GuiGraphics
|
import net.minecraft.client.gui.GuiGraphics
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
import net.minecraft.util.ARGB
|
import net.minecraft.util.ARGB
|
||||||
import kotlin.math.floor
|
|
||||||
import kotlin.math.roundToInt
|
|
||||||
import org.jetbrains.annotations.ApiStatus
|
import org.jetbrains.annotations.ApiStatus
|
||||||
import java.util.TreeSet
|
import java.util.TreeSet
|
||||||
import kotlin.collections.LinkedHashSet
|
import kotlin.collections.LinkedHashSet
|
||||||
@ -75,17 +73,13 @@ class ClickBox(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun render(guiGraphics: GuiGraphics?) {
|
override fun render(guiGraphics: GuiGraphics?) {
|
||||||
val xi = floor(x).toInt()
|
|
||||||
val yi = floor(y).toInt()
|
|
||||||
|
|
||||||
// Header
|
// Header
|
||||||
RenderingUtil.drawSlantedHeader(
|
RenderingUtil.drawRectangle(
|
||||||
guiGraphics = guiGraphics,
|
guiGraphics = guiGraphics,
|
||||||
x = xi,
|
x = x,
|
||||||
y = yi,
|
y = y,
|
||||||
width = width,
|
|
||||||
height = height,
|
height = height,
|
||||||
slantTop = inclination,
|
width = width,
|
||||||
color = color,
|
color = color,
|
||||||
opacity = opacity
|
opacity = opacity
|
||||||
)
|
)
|
||||||
@ -93,10 +87,10 @@ class ClickBox(
|
|||||||
// Body
|
// Body
|
||||||
RenderingUtil.drawRectangle(
|
RenderingUtil.drawRectangle(
|
||||||
guiGraphics = guiGraphics,
|
guiGraphics = guiGraphics,
|
||||||
x = xi.toDouble(),
|
x = x,
|
||||||
y = (yi + height).toDouble(),
|
y = (y + height),
|
||||||
height = clickboxHeightOffset,
|
height = clickboxHeightOffset,
|
||||||
width = width + inclination.roundToInt(),
|
width = width,
|
||||||
color = color,
|
color = color,
|
||||||
opacity = opacity
|
opacity = opacity
|
||||||
)
|
)
|
||||||
@ -104,36 +98,24 @@ class ClickBox(
|
|||||||
// Separator line
|
// Separator line
|
||||||
RenderingUtil.hLine(
|
RenderingUtil.hLine(
|
||||||
guiGraphics = guiGraphics,
|
guiGraphics = guiGraphics,
|
||||||
x1 = (xi + inclination).toInt(),
|
x1 = (x + 0).toInt(),
|
||||||
x2 = (xi + width),
|
x2 = (x + width).toInt(),
|
||||||
y = (yi + height),
|
y = (y + height).toInt(),
|
||||||
rgb = Colors.WHITE_LINES.hexValue,
|
rgb = Colors.WHITE_LINES.hexValue,
|
||||||
opacity = 1f
|
opacity = 1f
|
||||||
)
|
)
|
||||||
|
|
||||||
if (buttons.isNotEmpty()) {
|
if (buttons.isNotEmpty()) {
|
||||||
val barWidth = 3
|
|
||||||
val leftPadding = 3
|
|
||||||
val gapToBar = 1
|
|
||||||
buttonsProgressBar.apply {
|
buttonsProgressBar.apply {
|
||||||
this.width = barWidth
|
this.x = this@ClickBox.x + this@ClickBox.width - 3
|
||||||
this.x = this@ClickBox.x + this@ClickBox.width - barWidth
|
|
||||||
this.y = this@ClickBox.y + this@ClickBox.height + 3
|
this.y = this@ClickBox.y + this@ClickBox.height + 3
|
||||||
}.display(guiGraphics)
|
}.display(guiGraphics)
|
||||||
|
|
||||||
val buttonWidth = (this@ClickBox.width - leftPadding - barWidth - gapToBar).coerceAtLeast(10)
|
|
||||||
|
|
||||||
buttons.forEachIndexed { num, button ->
|
buttons.forEachIndexed { num, button ->
|
||||||
val fullHeight = (y + height.toDouble())..(this.y + height + clickboxHeightOffset)
|
val fullHeight = (y + height.toDouble())..(this.y + height + clickboxHeightOffset)
|
||||||
button.also {
|
button.also {
|
||||||
it.x = this.x + leftPadding
|
it.x = this.x + 3
|
||||||
it.y = this.y + 3 + height + (((num + 1) - barStage) * 9)
|
it.y = this.y + 3 + height + (((num + 1) - barStage) * 9)
|
||||||
|
it.hidden = if ((num + 1) <= 8) ((it.y) !in fullHeight) else ((it.y + it.height) !in fullHeight)
|
||||||
it.width = buttonWidth
|
|
||||||
|
|
||||||
it.hidden =
|
|
||||||
if ((num + 1) <= 8) ((it.y) !in fullHeight)
|
|
||||||
else ((it.y + it.height) !in fullHeight)
|
|
||||||
}.display(guiGraphics)
|
}.display(guiGraphics)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,9 +124,8 @@ class ClickBox(
|
|||||||
guiGraphics?.drawString(
|
guiGraphics?.drawString(
|
||||||
this,
|
this,
|
||||||
Component.nullToEmpty(name.string),
|
Component.nullToEmpty(name.string),
|
||||||
(xi + 5 + (inclination / 2f)).toInt(),
|
(x + 5).toInt(), (y + 2).toInt(),
|
||||||
(yi + 2),
|
ARGB.opaque(Colors.TRANSPARENT.hexValue),
|
||||||
ARGB.opaque(Colors.WHITE.hexValue),
|
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,10 +4,6 @@ import com.mojang.blaze3d.opengl.GlStateManager
|
|||||||
import fr.username404.snowygui.gui.feature.Colors
|
import fr.username404.snowygui.gui.feature.Colors
|
||||||
import net.minecraft.client.gui.GuiGraphics
|
import net.minecraft.client.gui.GuiGraphics
|
||||||
import net.minecraft.util.ARGB
|
import net.minecraft.util.ARGB
|
||||||
import kotlin.math.ceil
|
|
||||||
import kotlin.math.floor
|
|
||||||
import kotlin.math.max
|
|
||||||
import kotlin.math.min
|
|
||||||
|
|
||||||
object RenderingUtil {
|
object RenderingUtil {
|
||||||
fun prepareDraw() = GlStateManager._enableBlend()
|
fun prepareDraw() = GlStateManager._enableBlend()
|
||||||
@ -31,74 +27,18 @@ object RenderingUtil {
|
|||||||
color: Int = Colors.TRANSPARENT(),
|
color: Int = Colors.TRANSPARENT(),
|
||||||
opacity: Float = 1F
|
opacity: Float = 1F
|
||||||
) {
|
) {
|
||||||
if (guiGraphics == null) return
|
|
||||||
|
|
||||||
val x1 = floor(x).toInt()
|
|
||||||
val y1 = floor(y).toInt()
|
|
||||||
val x2 = ceil(x + width).toInt()
|
|
||||||
val y2 = ceil(y + height).toInt()
|
|
||||||
|
|
||||||
prepareDraw()
|
prepareDraw()
|
||||||
guiGraphics.fill(x1, y1, x2, y2, argbFromRgb(color, opacity))
|
guiGraphics?.fill(
|
||||||
endDraw()
|
x.toInt(), y.toInt(),
|
||||||
}
|
(x + width).toInt(), (y + height).toInt(),
|
||||||
|
argbFromRgb(color, opacity)
|
||||||
fun drawSlantedHeader(
|
)
|
||||||
guiGraphics: GuiGraphics?,
|
|
||||||
x: Int,
|
|
||||||
y: Int,
|
|
||||||
width: Int,
|
|
||||||
height: Int,
|
|
||||||
slantTop: Float,
|
|
||||||
color: Int,
|
|
||||||
opacity: Float
|
|
||||||
) {
|
|
||||||
if (guiGraphics == null) return
|
|
||||||
if (width <= 0 || height <= 0) return
|
|
||||||
|
|
||||||
val slant = slantTop.toDouble()
|
|
||||||
val baseArgb = argbFromRgb(color, opacity)
|
|
||||||
|
|
||||||
prepareDraw()
|
|
||||||
for (dy in 0 until height) {
|
|
||||||
val t = if (height == 1) 0.0 else dy.toDouble() / (height - 1).toDouble()
|
|
||||||
|
|
||||||
val leftF = x + slant * (1.0 - t)
|
|
||||||
val rightF = x + width + slant * t
|
|
||||||
|
|
||||||
val left = min(leftF, rightF)
|
|
||||||
val right = max(leftF, rightF)
|
|
||||||
|
|
||||||
val lx = floor(left).toInt()
|
|
||||||
val rx = floor(right).toInt()
|
|
||||||
val yy = y + dy
|
|
||||||
|
|
||||||
val midStart = lx + 1
|
|
||||||
val midEnd = rx
|
|
||||||
if (midEnd > midStart) {
|
|
||||||
guiGraphics.fill(midStart, yy, midEnd, yy + 1, baseArgb)
|
|
||||||
}
|
|
||||||
|
|
||||||
val leftFrac = (left - floor(left)).toFloat().coerceIn(0f, 1f)
|
|
||||||
val rightFrac = (right - floor(right)).toFloat().coerceIn(0f, 1f)
|
|
||||||
|
|
||||||
val leftAlpha = (1f - leftFrac) * opacity
|
|
||||||
val rightAlpha = rightFrac * opacity
|
|
||||||
|
|
||||||
if (leftAlpha > 0f) guiGraphics.fill(lx, yy, lx + 1, yy + 1, argbFromRgb(color, leftAlpha))
|
|
||||||
if (rightAlpha > 0f) guiGraphics.fill(rx, yy, rx + 1, yy + 1, argbFromRgb(color, rightAlpha))
|
|
||||||
|
|
||||||
if (rx <= lx) {
|
|
||||||
guiGraphics.fill(lx, yy, lx + 1, yy + 1, baseArgb)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
endDraw()
|
endDraw()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hLine(guiGraphics: GuiGraphics?, x1: Int, x2: Int, y: Int, rgb: Int, opacity: Float = 1f) {
|
fun hLine(guiGraphics: GuiGraphics?, x1: Int, x2: Int, y: Int, rgb: Int, opacity: Float = 1f) {
|
||||||
if (guiGraphics == null) return
|
|
||||||
prepareDraw()
|
prepareDraw()
|
||||||
guiGraphics.hLine(x1, x2, y, argbFromRgb(rgb, opacity))
|
guiGraphics?.hLine(x1, x2, y, argbFromRgb(rgb, opacity))
|
||||||
endDraw()
|
endDraw()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user