Skip to content

Commit 14caf93

Browse files
committed
Corrected scissor usage
1 parent 09fcdc6 commit 14caf93

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -287,28 +287,31 @@ open class Layout(
287287
mouseClickActions.forEach { it(e.button, action) }
288288
}
289289
is GuiEvent.Render -> {
290-
val drawChildren = rect.size.let { it.x > 0.1 && it.y > 0.1 }
291-
val partition by lazy { children.partition { !it.owningRenderer } }
290+
val drawAction = {
291+
val drawChildren = rect.size.let { it.x > 0.1 && it.y > 0.1 }
292292

293-
renderActions.forEach { it(renderer) }
293+
// ToDo: clipping filter to increase performance
294+
// filter { it.rect in this.rect }
295+
val partition by lazy { children.partition { !it.owningRenderer } }
294296

295-
if (drawChildren) {
296-
partition.first.forEach { it.onEvent(e) }
297-
}
297+
renderActions.forEach { it(renderer) }
298298

299-
if (owningRenderer) {
300-
renderer.render()
301-
}
299+
if (drawChildren) {
300+
partition.first.forEach { it.onEvent(e) }
301+
}
302302

303-
if (drawChildren) {
304-
val postAction = {
305-
partition.second.forEach { it.onEvent(e) }
303+
if (owningRenderer) {
304+
renderer.render()
306305
}
307306

308-
if (properties.scissorChildren) {
309-
scissor(rect, postAction)
310-
} else postAction()
307+
if (drawChildren) {
308+
partition.second.forEach { it.onEvent(e) }
309+
}
311310
}
311+
312+
if (properties.scissor) {
313+
scissor(rect, drawAction)
314+
} else drawAction()
312315
}
313316
}
314317
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class LayoutProperties {
1212
var clampPosition = false
1313

1414
/**
15-
* If true, children using their own render layer are clipped within this rect.
15+
* If true, anything drawn onto this render layer are clipped within this rect.
1616
*/
17-
var scissorChildren = false
17+
var scissor = false
1818
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ open class Window(
4040
}
4141

4242
// Position
43+
// ToDo find a way to animate this only when dragging
4344
/*private val renderX by animation.exp(position::x, 0.8)
4445
private val renderY by animation.exp(position::y, 0.8)
4546
private val renderPosition get() = Vec2d(renderX, renderY)*/
@@ -68,11 +69,13 @@ open class Window(
6869

6970
with(titleBar) {
7071
onRender {
72+
// Update title bar position
7173
val heightVec = Vec2d(0.0, textField.textHeight * 1.5)
7274
rect = Rect(this@Window.rect.leftTop, this@Window.rect.rightTop + heightVec)
7375
}
7476

7577
onMouseClick { button, action ->
78+
// Toggle minimizing state when right-clicking title bar
7679
if (!minimizable) return@onMouseClick
7780
if (button != Mouse.Button.Right || action != Mouse.Action.Click) return@onMouseClick
7881

@@ -81,9 +84,10 @@ open class Window(
8184
}
8285

8386
with(content) {
84-
properties.scissorChildren = true
87+
properties.scissor = true
8588

8689
onRender {
90+
// Update content position
8791
rect = Rect(
8892
titleBar.rect.leftBottom + NewCGui.padding,
8993
this@Window.rect.rightBottom - NewCGui.padding
@@ -103,13 +107,15 @@ open class Window(
103107
}
104108

105109
onRender {
110+
// Render window background
106111
filled.build(
107112
rect,
108113
2.0,
109114
Color(50, 50, 50),
110115
shade = true
111116
)
112117

118+
// Render outline
113119
outline.build(
114120
rect,
115121
2.0,
@@ -120,6 +126,7 @@ open class Window(
120126
}
121127

122128
onTick {
129+
// Update cursor
123130
val rxh = resizeXHovered || resizeX != null
124131
val ryh = resizeYHovered || resizeY != null
125132

@@ -134,6 +141,7 @@ open class Window(
134141
}
135142

136143
onMouseClick { button: Mouse.Button, action: Mouse.Action ->
144+
// Update resize dragging offsets
137145
resizeX = null
138146
resizeY = null
139147

0 commit comments

Comments
 (0)