Skip to content

Commit b8103a2

Browse files
committed
Cleanup and bug fixes
1 parent d02e14e commit b8103a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+946
-1365
lines changed

src/main/kotlin/net/prismclient/aether/ui/Aether.kt

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import net.prismclient.aether.ui.Aether.Properties
44
import net.prismclient.aether.ui.component.UIComponent
55
import net.prismclient.aether.ui.component.controller.UIController
66
import net.prismclient.aether.ui.component.type.layout.UIFrame
7-
import net.prismclient.aether.ui.component.type.layout.container.UIContainer
8-
import net.prismclient.aether.ui.component.type.layout.styles.UIContainerSheet
7+
import net.prismclient.aether.ui.component.type.layout.UIContainer
8+
import net.prismclient.aether.ui.component.type.layout.UIContainerSheet
99
import net.prismclient.aether.ui.event.input.UIMouseEvent
1010
import net.prismclient.aether.ui.renderer.UIProvider
1111
import net.prismclient.aether.ui.renderer.UIRenderer
@@ -33,9 +33,10 @@ import java.util.function.Consumer
3333
* functions [Properties.updateSize] and [Properties.updateMouse] to update the values without
3434
* invoking the [update], and [mouseMoved] functions.
3535
*
36+
* [Aether Documentation](https://aether.prismclient.net/getting-started)
37+
*
3638
* @author sen
3739
* @since 1.0
38-
* @see <a href="https://aether.prismclient.net/getting-started">UICore documentation</a>
3940
* @see UIProvider
4041
*/
4142
open class Aether(renderer: UIRenderer) {
@@ -108,12 +109,14 @@ open class Aether(renderer: UIRenderer) {
108109
open fun render() {
109110
renderer {
110111
if (activeScreen != null) {
112+
timings.onFrameRenderStart()
111113
beginFrame(width, height, devicePxRatio)
112114
for (i in 0 until components!!.size) {
113115
val component = components!![i]
114116
if (component.visible) component.render()
115117
}
116118
endFrame()
119+
timings.onFrameRenderEnd()
117120
}
118121
}
119122
}
@@ -123,7 +126,7 @@ open class Aether(renderer: UIRenderer) {
123126
* eligibility to be focused or bubbled. The [Properties.mouseX] and [Properties.mouseY]
124127
* properties can be found in [Aether.Properties].
125128
*/
126-
fun mouseMoved(mouseX: Float, mouseY: Float) {
129+
open fun mouseMoved(mouseX: Float, mouseY: Float) {
127130
updateMouse(mouseX, mouseY)
128131
mouseMoveListeners?.forEach { it.value.run() }
129132
if (activeScreen != null) for (i in 0 until components!!.size) components!![i].mouseMoved(mouseX, mouseY)
@@ -139,10 +142,10 @@ open class Aether(renderer: UIRenderer) {
139142
*
140143
* @see mouseScrolled
141144
*/
142-
fun mouseChanged(mouseButton: Int, isRelease: Boolean) {
145+
open fun mouseChanged(mouseButton: Int, isRelease: Boolean) {
143146
if (isRelease) {
144147
mouseReleasedListeners?.forEach { it.value.run() }
145-
components?.forEach { it.mouseReleased(mouseX, mouseY) }
148+
components?.forEach { it.mouseReleased(it.getMouseX(), it.getMouseY()) }
146149
return
147150
}
148151

@@ -182,7 +185,7 @@ open class Aether(renderer: UIRenderer) {
182185

183186
return if (component != null) {
184187
component.focus()
185-
component.mousePressed(UIMouseEvent(mouseX, mouseY, mouseButton, clickCount))
188+
component.mousePressed(UIMouseEvent(component.getMouseX(), component.getMouseY(), mouseButton, clickCount))
186189
true
187190
} else false
188191
}
@@ -211,7 +214,7 @@ open class Aether(renderer: UIRenderer) {
211214
i++
212215
}
213216
c?.focus()
214-
c?.mousePressed(UIMouseEvent(mouseX, mouseY, mouseButton, clickCount))
217+
c?.mousePressed(UIMouseEvent(c.getMouseX(), c.getMouseY(), mouseButton, clickCount))
215218
}
216219

217220
/**
@@ -220,7 +223,7 @@ open class Aether(renderer: UIRenderer) {
220223
* @param character The key which was pressed or '\u0000'
221224
* @see updateModifierKey To update keys such as Shift, Alt, Tab etc...
222225
*/
223-
fun keyPressed(character: Char) {
226+
open fun keyPressed(character: Char) {
224227
keyPressListeners?.forEach { it.value.accept(character) }
225228
(focusedComponent as? UIComponent<*>)?.keyPressed(character)
226229
}
@@ -230,6 +233,7 @@ open class Aether(renderer: UIRenderer) {
230233
* of their eligibility to be focused or bubbled.
231234
*/
232235
open fun mouseScrolled(scrollAmount: Float) {
236+
if (scrollAmount == 0f) return
233237
tryFocus()
234238
mouseScrollListeners?.forEach { it.value.accept(scrollAmount) }
235239
components?.forEach { it.mouseScrolled(mouseX, mouseY, scrollAmount) }
@@ -241,20 +245,20 @@ open class Aether(renderer: UIRenderer) {
241245
* as de-focusing the focused component and adding listeners to input.
242246
*/
243247
companion object Properties {
248+
249+
val timings: Timings = Timings()
250+
244251
@JvmStatic
245252
var debug: Boolean = true
246253

247254
@JvmStatic
248255
lateinit var instance: Aether
249-
protected set
250256

251257
@JvmStatic
252258
lateinit var renderer: UIRenderer
253-
protected set
254259

255260
@JvmStatic
256261
var activeScreen: UIScreen? = null
257-
protected set
258262

259263
/**
260264
* The focused component (if applicable).
@@ -265,92 +269,79 @@ open class Aether(renderer: UIRenderer) {
265269
*/
266270
@JvmStatic
267271
var focusedComponent: UIFocusable? = null
268-
protected set
269272

270273
/**
271274
* The width of the screen. It can be set via [update]
272275
*/
273276
@JvmStatic
274277
var width: Float = 0f
275-
protected set
276278

277279
/**
278280
* The width of the screen. It can be set via [update]
279281
*/
280282
@JvmStatic
281283
var height: Float = 0f
282-
protected set
283284

284285
/**
285286
* The device pixel ratio. It can be set via [update]. It is the equivalent of content scale.
286287
*/
287288
@JvmStatic
288289
var devicePxRatio: Float = 1f
289-
protected set
290290

291291
/**
292292
* The x position of the mouse relative to the screen
293293
*/
294294
@JvmStatic
295295
var mouseX: Float = 0f
296-
protected set
297296

298297
/**
299298
* The y position of the mouse relative to the screen
300299
*/
301300
@JvmStatic
302301
var mouseY: Float = 0f
303-
protected set
304302

305303
/**
306304
* Invoked whenever the layout needs to be updated. This can be when the screen
307305
* is resized or created. Invoked prior to components.
308306
*/
309307
@JvmStatic
310308
var updateListeners: HashMap<String, Runnable>? = null
311-
protected set
312309

313310
/**
314311
* The listeners for then the mouse is moved. Invoked prior to components.
315312
*/
316313
@JvmStatic
317314
var mouseMoveListeners: HashMap<String, Runnable>? = null
318-
protected set
319315

320316
/**
321317
* Invoked when the mouse is pressed. Invoked prior to components.
322318
*/
323319
@JvmStatic
324320
var mousePressedListeners: HashMap<String, Runnable>? = null
325-
protected set
326321

327322
/**
328323
* Invoked when the mouse is released. Invoked prior to components.
329324
*/
330325
@JvmStatic
331326
var mouseReleasedListeners: HashMap<String, Runnable>? = null
332-
protected set
333327

334328
/**
335329
* Invoked when a key is pressed. Invoked prior to components.
336330
*/
337331
@JvmStatic
338332
var keyPressListeners: HashMap<String, Consumer<Char>>? = null
339-
protected set
340333

341334
/**
342335
* Invoked when the mouse is scrolled. Invoked prior to components.
343336
*/
344337
@JvmStatic
345338
var mouseScrollListeners: HashMap<String, Consumer<Float>>? = null
346-
protected set
347339

348340
/**
349341
* Invoked when the screen is deleted. This is used to deallocate listeners added to UICore.
350342
*/
351343
@JvmStatic
352344
var deallocationListeners: HashMap<String, Runnable>? = null
353-
protected set
354345

355346
/**
356347
* The list of modifier keys. The value is if the key is pressed
@@ -502,13 +493,7 @@ open class Aether(renderer: UIRenderer) {
502493
* Focuses the component. Please use [UIComponent.focus] instead.
503494
*/
504495
@JvmStatic
505-
fun focus(component: UIFocusable) {
506-
// Check if the given value is a valid instance of UIComponent
507-
try {
508-
component as UIComponent<*>
509-
} catch (castException: ClassCastException) {
510-
throw RuntimeException("When trying to focus, the provided value is not an instance of UIComponent. Make sure you are only using the UIFocus interface to focus UIComponents.")
511-
}
496+
fun <T> focus(component: T) where T : UIComponent<*>, T : UIFocusable {
512497
focusedComponent = component
513498
}
514499

@@ -548,7 +533,7 @@ open class Aether(renderer: UIRenderer) {
548533
for (i in 0 until instance.frames!!.size) {
549534
// UIContainers are what control scrolling, so
550535
// if it is not an instance of it, skip and continue
551-
val container = instance.frames!![i] as? UIContainer<*> ?: continue
536+
val container = instance.frames!![i] as? UIContainer<UIContainerSheet> ?: continue
552537
if (container.isMouseInsideBounds() && container.expandedHeight > 0f && container.style.overflowY != UIContainerSheet.Overflow.None) {
553538
// Iterate through the frame to see if there are more
554539
// containers with it. If there are, it will pass true
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package net.prismclient.aether.ui
2+
3+
class Timings {
4+
5+
/**
6+
* Time when the current frame render started in milliseconds
7+
*/
8+
var frameRenderStartTime = 0L
9+
private set
10+
11+
/**
12+
* Time when the last frame render started in milliseconds
13+
*/
14+
var lastFrameRenderStartTime = 0L
15+
private set
16+
17+
/**
18+
* Time when the current frame render ended in milliseconds
19+
*/
20+
var frameRenderEndTime = 0L
21+
private set
22+
23+
/**
24+
* Time when the last frame render ended in milliseconds
25+
*/
26+
var lastFrameRenderEndTime = 0L
27+
private set
28+
29+
/**
30+
* The delta time (frame render start - frame render end) of the current frame in milliseconds
31+
*/
32+
val frameRenderDeltaTime
33+
get() = frameRenderEndTime - frameRenderStartTime
34+
35+
/**
36+
* The delta time (frame render start - frame render end) of the current frame in seconds
37+
*/
38+
val deltaFrameRenderTimeSeconds
39+
get() = frameRenderDeltaTime / 1000.0
40+
41+
/**
42+
* The delta time (frame render start - frame render end) of the last frame in milliseconds
43+
*/
44+
val lastFrameRenderDeltaTime
45+
get() = lastFrameRenderEndTime - lastFrameRenderStartTime
46+
47+
/**
48+
* The delta time (frame render start - frame render end) of the last frame in seconds
49+
*/
50+
val lastFrameRenderDeltaTimeSeconds
51+
get() = lastFrameRenderDeltaTime / 1000.0
52+
53+
/**
54+
* The approximate amount of renders the last frame would have made in a second
55+
*/
56+
val lastFrameRate
57+
get() = 1000.0 / lastFrameRenderDeltaTime
58+
59+
/**
60+
* The approximate amount of renders the current frame would have made in a second
61+
*/
62+
val frameRate
63+
get() = (1000 / (frameRenderDeltaTime + 1)).toInt()
64+
65+
/**
66+
* Set current & last render start times
67+
*/
68+
fun onFrameRenderStart() {
69+
lastFrameRenderStartTime = frameRenderStartTime
70+
71+
frameRenderStartTime = System.currentTimeMillis()
72+
}
73+
74+
/**
75+
* Set current & last render end times
76+
*/
77+
fun onFrameRenderEnd() {
78+
lastFrameRenderEndTime = frameRenderEndTime
79+
80+
frameRenderEndTime = System.currentTimeMillis()
81+
}
82+
83+
}

src/main/kotlin/net/prismclient/aether/ui/callback/UICoreCallback.kt

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)