Skip to content

Commit b513baf

Browse files
committed
Fancy design
1 parent de2490c commit b513baf

File tree

20 files changed

+265
-121
lines changed

20 files changed

+265
-121
lines changed

common/src/main/kotlin/com/lambda/graphics/animation/Animation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Animation(initialValue: Double, val update: (Double) -> Double) {
5252
fun AnimationTicker.exp(min: Double, max: Double, speed: Double, flag: () -> Boolean) =
5353
exp({ min }, { max }, { speed }, flag)
5454

55-
fun AnimationTicker.exp(target: () -> Double, speed: Double) =
55+
fun AnimationTicker.exp(speed: Double, target: () -> Double) =
5656
exp(target, target, { speed }, { true })
5757

5858
fun AnimationTicker.exp(min: () -> Double, max: () -> Double, speed: () -> Double, flag: () -> Boolean) =

common/src/main/kotlin/com/lambda/graphics/buffer/VertexPipeline.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ import java.awt.Color
3939
class VertexPipeline(
4040
private val mode: VertexMode,
4141
attributes: VertexAttrib.Group,
42+
usage: Int = GL_DYNAMIC_DRAW
4243
) : IRenderContext {
4344
private val stride = attributes.stride
4445
private val size = stride * mode.indicesCount
4546

4647
private val vao = VertexArray()
47-
private val vbo = VertexBuffer(mode, attributes)
48-
private val ebo = ElementBuffer(mode)
48+
private val vbo = VertexBuffer(mode, attributes, usage)
49+
private val ebo = ElementBuffer(mode, usage)
4950

5051
private var vertices = byteBuffer(size * 1.kibibyte)
5152
private var verticesPointer = address(vertices)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import com.lambda.graphics.gl.kibibyte
2323
import org.lwjgl.opengl.GL30C.*
2424
import java.nio.ByteBuffer
2525

26-
class ElementBuffer(mode: VertexMode) :
27-
Buffer(buffers = 1)
28-
{
29-
override val usage: Int = GL_DYNAMIC_DRAW
26+
class ElementBuffer(
27+
mode: VertexMode,
28+
override val usage: Int = GL_DYNAMIC_DRAW,
29+
) : Buffer(buffers = 1) {
3030
override val target: Int = GL_ELEMENT_ARRAY_BUFFER
3131
override val access: Int = GL_MAP_WRITE_BIT
3232

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import java.nio.ByteBuffer
2727
class VertexBuffer(
2828
mode: VertexMode,
2929
attributes: VertexAttrib.Group,
30-
) : Buffer(buffers = 1) {
3130
override val usage: Int = GL_DYNAMIC_DRAW
31+
) : Buffer(buffers = 1) {
3232
override val target: Int = GL_ARRAY_BUFFER
3333
override val access: Int = GL_MAP_WRITE_BIT
3434

common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/FontRenderer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ object FontRenderer : AbstractGUIRenderer(VertexAttrib.Group.FONT, shader("font/
6060
position: Vec2d = Vec2d.ZERO,
6161
color: Color = Color.WHITE,
6262
scale: Double = 1.0,
63-
shadow: Boolean = RenderSettings.shadow,
63+
shadow: Boolean = true,
6464
parseEmoji: Boolean = LambdaMoji.isEnabled
6565
) = render {
6666
shader["u_FontTexture"] = 0
@@ -213,7 +213,7 @@ object FontRenderer : AbstractGUIRenderer(VertexAttrib.Group.FONT, shader("font/
213213

214214
val glyph = chars[char] ?: return@forEach
215215

216-
if (shadow) drawGlyph(glyph, shadowColor, true)
216+
if (shadow && RenderSettings.shadow) drawGlyph(glyph, shadowColor, true)
217217
drawGlyph(glyph, color)
218218
}
219219
} else {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ object FilledRectRenderer : AbstractGUIRenderer(
2828
VertexAttrib.Group.RECT_FILLED, shader("renderer/rect_filled")
2929
) {
3030
private const val MIN_SIZE = 0.5
31-
private const val MIN_ALPHA = 3
31+
private const val MIN_ALPHA = 1
3232

3333
fun filledRect(
3434
rect: Rect,

common/src/main/kotlin/com/lambda/gui/component/core/FilledRect.kt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.lambda.gui.component.core
1919

2020
import com.lambda.graphics.renderer.gui.rect.FilledRectRenderer.filledRect
21+
import com.lambda.gui.component.core.FilledRect.Companion.rectBehind
2122
import com.lambda.gui.component.layout.Layout
2223
import com.lambda.util.math.Rect
2324
import java.awt.Color
@@ -97,7 +98,26 @@ class FilledRect(
9798
* Creates a [FilledRect] component - layout-based rect representation
9899
*/
99100
@UIBuilder
100-
fun Layout.rect(block: FilledRect.() -> Unit = {}) =
101-
FilledRect(this).apply(children::add).apply(block)
101+
fun Layout.rect(
102+
block: FilledRect.() -> Unit = {}
103+
) = FilledRect(this).apply(children::add).apply(block)
104+
105+
/**
106+
* Adds a [FilledRect] behind given [layout]
107+
*/
108+
@UIBuilder
109+
fun Layout.rectBehind(
110+
layout: Layout,
111+
block: FilledRect.() -> Unit = {}
112+
) = FilledRect(this).relativeLayout(this, layout, false).apply(block)
113+
114+
/**
115+
* Adds a [FilledRect] over given [layout]
116+
*/
117+
@UIBuilder
118+
fun Layout.rectOver(
119+
layout: Layout,
120+
block: FilledRect.() -> Unit = {}
121+
) = FilledRect(this).relativeLayout(this, layout, true).apply(block)
102122
}
103123
}

common/src/main/kotlin/com/lambda/gui/component/core/OutlineRect.kt

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.lambda.gui.component.core
1919

2020
import com.lambda.graphics.renderer.gui.rect.OutlineRectRenderer.outlineRect
21+
import com.lambda.gui.component.core.FilledRect.Companion.rectBehind
2122
import com.lambda.gui.component.layout.Layout
2223
import java.awt.Color
2324

@@ -62,10 +63,29 @@ class OutlineRect(
6263

6364
companion object {
6465
/**
65-
* Creates a [OutlineRect] component - layout-based rect representation
66+
* Creates an [OutlineRect] component - layout-based rect representation
6667
*/
6768
@UIBuilder
68-
fun Layout.outline(block: OutlineRect.() -> Unit = {}) =
69-
OutlineRect(this).apply(children::add).apply(block)
69+
fun Layout.outline(
70+
block: OutlineRect.() -> Unit = {}
71+
) = OutlineRect(this).apply(children::add).apply(block)
72+
73+
/**
74+
* Adds a [OutlineRect] behind given [layout]
75+
*/
76+
@UIBuilder
77+
fun Layout.outlineBehind(
78+
layout: Layout,
79+
block: OutlineRect.() -> Unit = {}
80+
) = OutlineRect(this).relativeLayout(this, layout, false).apply(block)
81+
82+
/**
83+
* Creates an [OutlineRect] component - layout-based rect representation
84+
*/
85+
@UIBuilder
86+
fun Layout.outlineOver(
87+
layout: Layout,
88+
block: OutlineRect.() -> Unit = {}
89+
) = OutlineRect(this).relativeLayout(this, layout, true).apply(block)
7090
}
7191
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.lambda.graphics.renderer.gui.font.FontRenderer
2121
import com.lambda.graphics.renderer.gui.font.FontRenderer.drawString
2222
import com.lambda.gui.component.HAlign
2323
import com.lambda.gui.component.VAlign
24+
import com.lambda.gui.component.core.OutlineRect.Companion.outlineBehind
2425
import com.lambda.gui.component.layout.Layout
2526
import com.lambda.util.math.Vec2d
2627
import com.lambda.util.math.lerp
@@ -62,5 +63,23 @@ class TextField(
6263
fun Layout.textField(
6364
block: TextField.() -> Unit = {}
6465
) = TextField(this).apply(children::add).apply(block)
66+
67+
/**
68+
* Adds a [TextField] behind given [layout]
69+
*/
70+
@UIBuilder
71+
fun Layout.textFieldBehind(
72+
layout: Layout,
73+
block: TextField.() -> Unit = {}
74+
) = TextField(this).relativeLayout(this, layout, false).apply(block)
75+
76+
/**
77+
* Adds a [TextField] over given [layout]
78+
*/
79+
@UIBuilder
80+
fun Layout.textFieldOver(
81+
layout: Layout,
82+
block: TextField.() -> Unit = {}
83+
) = TextField(this).relativeLayout(this, layout, true).apply(block)
6584
}
6685
}

common/src/main/kotlin/com/lambda/gui/component/core/UIBuilder.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
package com.lambda.gui.component.core
1919

20+
import com.lambda.gui.component.layout.Layout
21+
import com.lambda.util.math.MathUtils.toInt
22+
2023
@DslMarker
2124
annotation class UIBuilder
2225

@@ -25,3 +28,13 @@ annotation class LayoutBuilder
2528

2629
@DslMarker
2730
annotation class UIRenderPr0p3rty
31+
32+
fun <T : Layout> T.relativeLayout(
33+
owner: Layout,
34+
base: Layout,
35+
next: Boolean
36+
) = apply {
37+
val index = owner.children.indexOf(base)
38+
check(index != -1 && base.owner == owner) { "Given layout belongs to different owner" }
39+
owner.children.add(index + next.toInt(), this)
40+
}

0 commit comments

Comments
 (0)