Skip to content

Commit dbbe522

Browse files
committed
Windows design
1 parent 9eba76a commit dbbe522

File tree

11 files changed

+157
-63
lines changed

11 files changed

+157
-63
lines changed

common/src/main/kotlin/com/lambda/config/groups/Targeting.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ abstract class Targeting(
143143

144144
return@runSafe entitySearch<LivingEntity>(targetingRange) {
145145
predicate(it)
146-
}.minBy {
146+
}.minByOrNull {
147147
priority.factor(this, it)
148148
}
149149
}

common/src/main/kotlin/com/lambda/graphics/buffer/vao/vertex/VertexAttrib.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ enum class VertexAttrib(val componentCount: Int, componentSize: Int, val normali
1717

1818
// GUI
1919
FONT(Vec3, Vec2, Color), // pos, uv, color
20-
RECT_FILLED(Vec2, Vec2, Vec2, Float, Float, Color), // pos, uv, size, roundRadius, shade, color
20+
RECT_FILLED(Vec2, Vec2, Vec2, Vec2, Vec2, Float, Color), // pos, uv, size, roundL, roundR, shade, color
2121
RECT_OUTLINE(Vec2, Float, Float, Color), // pos, alpha, shade, color
2222

2323
// WORLD

common/src/main/kotlin/com/lambda/graphics/renderer/gui/rect/FilledRectRenderer.kt

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,39 @@ class FilledRectRenderer : AbstractRectRenderer(
2525
rightBottom: Color = Color.WHITE,
2626
leftBottom: Color = Color.WHITE,
2727
shade: Boolean = false,
28+
) = build(
29+
rect,
30+
roundRadius, roundRadius, roundRadius, roundRadius,
31+
leftTop, rightTop, rightBottom, leftBottom,
32+
shade
33+
)
34+
35+
fun build(
36+
rect: Rect,
37+
leftTopRadius: Double = 0.0,
38+
rightTopRadius: Double = 0.0,
39+
rightBottomRadius: Double = 0.0,
40+
leftBottomRadius: Double = 0.0,
41+
color: Color = Color.WHITE,
42+
shade: Boolean = false,
43+
) = build(
44+
rect,
45+
leftTopRadius, rightTopRadius, rightBottomRadius, leftBottomRadius,
46+
color, color, color, color,
47+
shade
48+
)
49+
50+
fun build(
51+
rect: Rect,
52+
leftTopRadius: Double = 0.0,
53+
rightTopRadius: Double = 0.0,
54+
rightBottomRadius: Double = 0.0,
55+
leftBottomRadius: Double = 0.0,
56+
leftTop: Color = Color.WHITE,
57+
rightTop: Color = Color.WHITE,
58+
rightBottom: Color = Color.WHITE,
59+
leftBottom: Color = Color.WHITE,
60+
shade: Boolean = false,
2861
) = vao.use {
2962
val pos1 = rect.leftTop
3063
val pos2 = rect.rightBottom
@@ -36,12 +69,16 @@ class FilledRectRenderer : AbstractRectRenderer(
3669
rightBottom.alpha < MIN_ALPHA &&
3770
leftBottom.alpha < MIN_ALPHA
3871
) return@use
72+
3973
if (size.x < MIN_SIZE || size.y < MIN_SIZE) return@use
4074

4175
val halfSize = size * 0.5
4276
val maxRadius = min(halfSize.x, halfSize.y)
4377

44-
val round = roundRadius.coerceAtMost(maxRadius).coerceAtLeast(0.0)
78+
val ltr = leftTopRadius.coerceAtMost(maxRadius).coerceAtLeast(0.0)
79+
val lbr = leftBottomRadius.coerceAtMost(maxRadius).coerceAtLeast(0.0)
80+
val rbr = rightBottomRadius.coerceAtMost(maxRadius).coerceAtLeast(0.0)
81+
val rtr = rightTopRadius.coerceAtMost(maxRadius).coerceAtLeast(0.0)
4582

4683
val p1 = pos1 - 0.25
4784
val p2 = pos2 + 0.25
@@ -50,10 +87,10 @@ class FilledRectRenderer : AbstractRectRenderer(
5087
grow(4)
5188

5289
putQuad(
53-
vec2m(p1.x, p1.y).vec2(0.0, 0.0).vec2(size.x, size.y).float(round).float(s).color(leftTop).end(),
54-
vec2m(p1.x, p2.y).vec2(0.0, 1.0).vec2(size.x, size.y).float(round).float(s).color(leftBottom).end(),
55-
vec2m(p2.x, p2.y).vec2(1.0, 1.0).vec2(size.x, size.y).float(round).float(s).color(rightBottom).end(),
56-
vec2m(p2.x, p1.y).vec2(1.0, 0.0).vec2(size.x, size.y).float(round).float(s).color(rightTop).end()
90+
vec2m(p1.x, p1.y).vec2(0.0, 0.0).vec2(size.x, size.y).vec2(ltr, lbr).vec2(rtr, rbr).float(s).color(leftTop).end(),
91+
vec2m(p1.x, p2.y).vec2(0.0, 1.0).vec2(size.x, size.y).vec2(ltr, lbr).vec2(rtr, rbr).float(s).color(leftBottom).end(),
92+
vec2m(p2.x, p2.y).vec2(1.0, 1.0).vec2(size.x, size.y).vec2(ltr, lbr).vec2(rtr, rbr).float(s).color(rightBottom).end(),
93+
vec2m(p2.x, p1.y).vec2(1.0, 0.0).vec2(size.x, size.y).vec2(ltr, lbr).vec2(rtr, rbr).float(s).color(rightTop).end()
5794
)
5895
}
5996

common/src/main/kotlin/com/lambda/gui/api/RenderLayer.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,28 @@ import com.lambda.threading.mainThread
1010
class RenderLayer {
1111
val filled by mainThread(::FilledRectRenderer)
1212
val outline by mainThread(::OutlineRectRenderer)
13+
1314
val font by mainThread {
1415
FontRenderer(
1516
LambdaFont.FiraSansRegular,
1617
LambdaEmoji.Twemoji,
1718
)
1819
}
1920

21+
private val boldFont0 = lazy {
22+
FontRenderer(
23+
LambdaFont.FiraSansBold,
24+
LambdaEmoji.Twemoji,
25+
)
26+
}
27+
28+
val boldFont by boldFont0
29+
2030
fun render() {
2131
filled.render()
2232
outline.render()
2333
font.render()
34+
35+
if (boldFont0.isInitialized()) boldFont0.value.render()
2436
}
2537
}

common/src/main/kotlin/com/lambda/module/modules/client/NewCGui.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,28 @@ import com.lambda.newgui.LambdaScreen.Companion.gui
66
import com.lambda.newgui.LambdaScreen.Companion.toScreen
77
import com.lambda.newgui.component.window.Window.Companion.window
88
import com.lambda.util.math.Vec2d
9+
import com.lambda.util.math.setAlpha
10+
import java.awt.Color
911

1012
object NewCGui : Module(
1113
name = "NewCGui",
1214
description = "ggs",
1315
defaultTags = setOf(ModuleTag.CLIENT)
1416
) {
15-
val titleBarHeight by setting("Title Bar Height", 16.0, 0.0..25.0, 0.1)
17+
val titleBarHeight by setting("Title Bar Height", 18.0, 0.0..25.0, 0.1)
1618
val padding by setting("Padding", 2.0, 1.0..6.0, 0.1)
1719
val listStep by setting("List Step", 2.0, 0.0..6.0, 0.1)
1820

21+
val roundRadius by setting("Round Radius", 2.0, 0.0..10.0, 0.1)
22+
23+
val backgroundColor by setting("Background Color", Color.WHITE.setAlpha(0.4))
24+
val backgroundShade by setting("Background Shade", true)
25+
26+
val outline by setting("Outline", true)
27+
val outlineWidth by setting("Outline Width", 10.0, 1.0..10.0, 0.1) { outline }
28+
val outlineColor by setting("Outline Color", Color.WHITE.setAlpha(0.6)) { outline }
29+
val outlineShade by setting("Outline Shade", true) { outline }
30+
1931
private val clickGuiLayout =
2032
gui {
2133
window(position = Vec2d.ONE * 20.0, title = "Test window") {

common/src/main/kotlin/com/lambda/newgui/component/core/TextField.kt

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,17 @@ import java.awt.Color
99

1010
class TextField(
1111
owner: Layout,
12-
initialText: String,
13-
initialColor: Color = Color.WHITE,
14-
initialScale: Double = 1.0,
15-
initialShadow: Boolean = true,
16-
initialOffset: Double = 0.0,
12+
var text: String,
13+
var color: Color,
14+
var scale: Double,
15+
var bold: Boolean,
16+
var shadow: Boolean,
17+
var offset: Double,
1718
) : Layout(owner, true, true) {
18-
var text = initialText
19-
var color = initialColor
20-
var scale = initialScale
21-
var shadow = initialShadow
19+
val textWidth get() = fr.getWidth(text, scale)
20+
val textHeight get() = fr.getHeight(scale)
2221

23-
var offset = initialOffset
24-
25-
val textWidth get() = renderer.font.getWidth(text, scale)
26-
val textHeight get() = renderer.font.getHeight(scale)
22+
private val fr get() = if (bold) renderer.boldFont else renderer.font
2723

2824
init {
2925
properties.interactionPassthrough = true
@@ -48,7 +44,7 @@ class TextField(
4844
)
4945
}
5046

51-
font.build(text, Vec2d(x, y), color, scale, shadow)
47+
fr.build(text, Vec2d(x, y), color, scale, shadow)
5248
}
5349
}
5450

@@ -62,6 +58,8 @@ class TextField(
6258
*
6359
* @param scale Scale of the font
6460
*
61+
* @param bold Whether to use the bold variant of the font
62+
*
6563
* @param shadow Whether the font should drop a shadow
6664
*
6765
* @param offset Offset from the corner(specified by [horizontalAlignment]) of the text (ignored for [HAlign.CENTER])
@@ -71,9 +69,10 @@ class TextField(
7169
text: String,
7270
color: Color = Color.WHITE,
7371
scale: Double = 1.0,
72+
bold: Boolean = false,
7473
shadow: Boolean = true,
7574
offset: Double = 0.0,
7675
block: TextField.() -> Unit = {}
77-
) = TextField(this, text, color, scale, shadow, offset).apply(children::add).apply(block)
76+
) = TextField(this, text, color, scale, bold, shadow, offset).apply(children::add).apply(block)
7877
}
7978
}

common/src/main/kotlin/com/lambda/newgui/component/layout/Layout.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,10 @@ open class Layout(
290290
val drawAction = {
291291
val drawChildren = rect.size.let { it.x > 0.1 && it.y > 0.1 }
292292

293-
// ToDo: clipping filter to increase performance
294-
// filter { it.rect in this.rect }
295-
val partition by lazy { children.partition { !it.owningRenderer } }
293+
val partition by lazy {
294+
children.filter { properties.scissor || it.rect in this.rect }
295+
.partition { !it.owningRenderer }
296+
}
296297

297298
renderActions.forEach { it(renderer) }
298299

common/src/main/kotlin/com/lambda/newgui/component/window/Window.kt

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import com.lambda.util.Mouse
1111
import com.lambda.util.math.Rect
1212
import com.lambda.util.math.Vec2d
1313
import com.lambda.util.math.coerceIn
14-
import java.awt.Color
1514

1615
/**
1716
* Represents a window component
@@ -26,7 +25,8 @@ open class Window(
2625
draggable: Boolean,
2726
scrollable: Boolean,
2827
private val minimizable: Boolean,
29-
private val resizable: Boolean
28+
private val resizable: Boolean,
29+
clean: Boolean
3030
) : Layout(owner, false, true) {
3131
val titleBar = titleBar(initialTitle, draggable)
3232
val content = windowContent(scrollable)
@@ -68,6 +68,11 @@ open class Window(
6868
}
6969

7070
with(titleBar) {
71+
textField.apply {
72+
bold = true
73+
shadow = false
74+
}
75+
7176
onRender {
7277
// Update title bar position
7378
rect = Rect(this@Window.rect.leftTop, this@Window.rect.rightTop + Vec2d.BOTTOM * NewCGui.titleBarHeight)
@@ -105,23 +110,25 @@ open class Window(
105110
cursorController.reset()
106111
}
107112

108-
onRender {
109-
// Render window background
110-
filled.build(
111-
rect,
112-
2.0,
113-
Color(50, 50, 50),
114-
shade = true
115-
)
116-
117-
// Render outline
118-
outline.build(
119-
rect,
120-
2.0,
121-
1.0,
122-
Color.WHITE,
123-
true
124-
)
113+
if (!clean) {
114+
onRender {
115+
// Render window background
116+
filled.build(rect, NewCGui.roundRadius, NewCGui.backgroundColor, NewCGui.backgroundShade)
117+
118+
// Render window outline
119+
if (NewCGui.outline) {
120+
outline.build(rect, NewCGui.roundRadius, NewCGui.outlineWidth, NewCGui.outlineColor, NewCGui.outlineShade)
121+
}
122+
123+
// Shadow
124+
/*val topColor = Color.BLACK.setAlpha(0.15)
125+
val bottomColor = Color.BLACK.setAlpha(0.0)
126+
filled.build(
127+
Rect(titleBar.rect.leftBottom, titleBar.rect.rightBottom + Vec2d.BOTTOM * 7.0), 0.0,
128+
topColor, topColor,
129+
bottomColor, bottomColor
130+
)*/
131+
}
125132
}
126133

127134
onTick {
@@ -206,6 +213,8 @@ open class Window(
206213
*
207214
* @param resizable Whether to allow user to resize the window
208215
*
216+
* @param clean Whether to skip the background rendering
217+
*
209218
* @param block Actions to perform within content space of the window
210219
*/
211220
@UIBuilder
@@ -217,11 +226,13 @@ open class Window(
217226
scrollable: Boolean = true,
218227
minimizable: Boolean = true,
219228
resizable: Boolean = true,
229+
clean: Boolean = false,
220230
block: WindowContent.() -> Unit = {}
221231
) = Window(
222232
this, title,
223233
position, size,
224-
draggable, scrollable, minimizable, resizable
234+
draggable, scrollable, minimizable, resizable,
235+
clean
225236
).apply(children::add).apply {
226237
block(this.content)
227238
}

common/src/main/kotlin/com/lambda/newgui/component/window/WindowContent.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class WindowContent(
2626

2727
init {
2828
onShow {
29+
dwheel = 0.0
2930
scrollOffset = 0.0
3031
rubberbandDelta = 0.0
31-
dwheel = 0.0
3232
renderScrollOffset = 0.0
3333

3434
reorderChildren()
@@ -55,15 +55,6 @@ class WindowContent(
5555
}
5656

5757
onRender {
58-
// Shadow
59-
val topColor = Color.BLACK.setAlpha(0.2)
60-
val bottomColor = Color.BLACK.setAlpha(0.0)
61-
filled.build(
62-
Rect(rect.leftTop, rect.rightTop + Vec2d.BOTTOM * 10.0), 0.0,
63-
topColor, topColor,
64-
bottomColor, bottomColor
65-
)
66-
6758
reorderChildren()
6859
}
6960

common/src/main/resources/assets/lambda/shaders/fragment/renderer/rect_filled.frag

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ in vec2 v_Position;
99
in vec2 v_TexCoord;
1010
in vec4 v_Color;
1111
in vec2 v_Size;
12-
in float v_RoundRadius;
12+
in vec2 v_RoundRadiusL;
13+
in vec2 v_RoundRadiusR;
1314
in float v_Shade;
1415

1516
out vec4 color;
@@ -33,10 +34,37 @@ vec4 shade() {
3334
return mix(u_Color1, u_Color2, p) * v_Color;
3435
}
3536

37+
float getRoundRadius() {
38+
bool xcmp = v_TexCoord.x > 0.5;
39+
bool ycmp = v_TexCoord.y > 0.5;
40+
41+
float r = 0.0;
42+
43+
if (xcmp) {
44+
if (ycmp) {
45+
// Right bottom
46+
r = v_RoundRadiusR.y;
47+
} else {
48+
// Right top
49+
r = v_RoundRadiusR.x;
50+
}
51+
} else {
52+
if (ycmp) {
53+
// Left bottom
54+
r = v_RoundRadiusL.y;
55+
} else {
56+
// Left top
57+
r = v_RoundRadiusL.x;
58+
}
59+
}
60+
61+
return r;
62+
}
63+
3664
vec4 round() {
3765
vec2 halfSize = v_Size * 0.5;
3866

39-
float radius = max(v_RoundRadius, SMOOTHING);
67+
float radius = max(getRoundRadius(), SMOOTHING);
4068

4169
vec2 smoothVec = vec2(SMOOTHING);
4270
vec2 coord = mix(-smoothVec, v_Size + smoothVec, v_TexCoord);

0 commit comments

Comments
 (0)