Skip to content

Commit 5aeb6e5

Browse files
committed
Revert "Cleanup and bug fixes"
This reverts commit b8103a2.
1 parent b8103a2 commit 5aeb6e5

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

+1365
-946
lines changed

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

Lines changed: 33 additions & 18 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.UIContainer
8-
import net.prismclient.aether.ui.component.type.layout.UIContainerSheet
7+
import net.prismclient.aether.ui.component.type.layout.container.UIContainer
8+
import net.prismclient.aether.ui.component.type.layout.styles.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,10 +33,9 @@ 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-
*
3836
* @author sen
3937
* @since 1.0
38+
* @see <a href="https://aether.prismclient.net/getting-started">UICore documentation</a>
4039
* @see UIProvider
4140
*/
4241
open class Aether(renderer: UIRenderer) {
@@ -109,14 +108,12 @@ open class Aether(renderer: UIRenderer) {
109108
open fun render() {
110109
renderer {
111110
if (activeScreen != null) {
112-
timings.onFrameRenderStart()
113111
beginFrame(width, height, devicePxRatio)
114112
for (i in 0 until components!!.size) {
115113
val component = components!![i]
116114
if (component.visible) component.render()
117115
}
118116
endFrame()
119-
timings.onFrameRenderEnd()
120117
}
121118
}
122119
}
@@ -126,7 +123,7 @@ open class Aether(renderer: UIRenderer) {
126123
* eligibility to be focused or bubbled. The [Properties.mouseX] and [Properties.mouseY]
127124
* properties can be found in [Aether.Properties].
128125
*/
129-
open fun mouseMoved(mouseX: Float, mouseY: Float) {
126+
fun mouseMoved(mouseX: Float, mouseY: Float) {
130127
updateMouse(mouseX, mouseY)
131128
mouseMoveListeners?.forEach { it.value.run() }
132129
if (activeScreen != null) for (i in 0 until components!!.size) components!![i].mouseMoved(mouseX, mouseY)
@@ -142,10 +139,10 @@ open class Aether(renderer: UIRenderer) {
142139
*
143140
* @see mouseScrolled
144141
*/
145-
open fun mouseChanged(mouseButton: Int, isRelease: Boolean) {
142+
fun mouseChanged(mouseButton: Int, isRelease: Boolean) {
146143
if (isRelease) {
147144
mouseReleasedListeners?.forEach { it.value.run() }
148-
components?.forEach { it.mouseReleased(it.getMouseX(), it.getMouseY()) }
145+
components?.forEach { it.mouseReleased(mouseX, mouseY) }
149146
return
150147
}
151148

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

186183
return if (component != null) {
187184
component.focus()
188-
component.mousePressed(UIMouseEvent(component.getMouseX(), component.getMouseY(), mouseButton, clickCount))
185+
component.mousePressed(UIMouseEvent(mouseX, mouseY, mouseButton, clickCount))
189186
true
190187
} else false
191188
}
@@ -214,7 +211,7 @@ open class Aether(renderer: UIRenderer) {
214211
i++
215212
}
216213
c?.focus()
217-
c?.mousePressed(UIMouseEvent(c.getMouseX(), c.getMouseY(), mouseButton, clickCount))
214+
c?.mousePressed(UIMouseEvent(mouseX, mouseY, mouseButton, clickCount))
218215
}
219216

220217
/**
@@ -223,7 +220,7 @@ open class Aether(renderer: UIRenderer) {
223220
* @param character The key which was pressed or '\u0000'
224221
* @see updateModifierKey To update keys such as Shift, Alt, Tab etc...
225222
*/
226-
open fun keyPressed(character: Char) {
223+
fun keyPressed(character: Char) {
227224
keyPressListeners?.forEach { it.value.accept(character) }
228225
(focusedComponent as? UIComponent<*>)?.keyPressed(character)
229226
}
@@ -233,7 +230,6 @@ open class Aether(renderer: UIRenderer) {
233230
* of their eligibility to be focused or bubbled.
234231
*/
235232
open fun mouseScrolled(scrollAmount: Float) {
236-
if (scrollAmount == 0f) return
237233
tryFocus()
238234
mouseScrollListeners?.forEach { it.value.accept(scrollAmount) }
239235
components?.forEach { it.mouseScrolled(mouseX, mouseY, scrollAmount) }
@@ -245,20 +241,20 @@ open class Aether(renderer: UIRenderer) {
245241
* as de-focusing the focused component and adding listeners to input.
246242
*/
247243
companion object Properties {
248-
249-
val timings: Timings = Timings()
250-
251244
@JvmStatic
252245
var debug: Boolean = true
253246

254247
@JvmStatic
255248
lateinit var instance: Aether
249+
protected set
256250

257251
@JvmStatic
258252
lateinit var renderer: UIRenderer
253+
protected set
259254

260255
@JvmStatic
261256
var activeScreen: UIScreen? = null
257+
protected set
262258

263259
/**
264260
* The focused component (if applicable).
@@ -269,79 +265,92 @@ open class Aether(renderer: UIRenderer) {
269265
*/
270266
@JvmStatic
271267
var focusedComponent: UIFocusable? = null
268+
protected set
272269

273270
/**
274271
* The width of the screen. It can be set via [update]
275272
*/
276273
@JvmStatic
277274
var width: Float = 0f
275+
protected set
278276

279277
/**
280278
* The width of the screen. It can be set via [update]
281279
*/
282280
@JvmStatic
283281
var height: Float = 0f
282+
protected set
284283

285284
/**
286285
* The device pixel ratio. It can be set via [update]. It is the equivalent of content scale.
287286
*/
288287
@JvmStatic
289288
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
296297

297298
/**
298299
* The y position of the mouse relative to the screen
299300
*/
300301
@JvmStatic
301302
var mouseY: Float = 0f
303+
protected set
302304

303305
/**
304306
* Invoked whenever the layout needs to be updated. This can be when the screen
305307
* is resized or created. Invoked prior to components.
306308
*/
307309
@JvmStatic
308310
var updateListeners: HashMap<String, Runnable>? = null
311+
protected set
309312

310313
/**
311314
* The listeners for then the mouse is moved. Invoked prior to components.
312315
*/
313316
@JvmStatic
314317
var mouseMoveListeners: HashMap<String, Runnable>? = null
318+
protected set
315319

316320
/**
317321
* Invoked when the mouse is pressed. Invoked prior to components.
318322
*/
319323
@JvmStatic
320324
var mousePressedListeners: HashMap<String, Runnable>? = null
325+
protected set
321326

322327
/**
323328
* Invoked when the mouse is released. Invoked prior to components.
324329
*/
325330
@JvmStatic
326331
var mouseReleasedListeners: HashMap<String, Runnable>? = null
332+
protected set
327333

328334
/**
329335
* Invoked when a key is pressed. Invoked prior to components.
330336
*/
331337
@JvmStatic
332338
var keyPressListeners: HashMap<String, Consumer<Char>>? = null
339+
protected set
333340

334341
/**
335342
* Invoked when the mouse is scrolled. Invoked prior to components.
336343
*/
337344
@JvmStatic
338345
var mouseScrollListeners: HashMap<String, Consumer<Float>>? = null
346+
protected set
339347

340348
/**
341349
* Invoked when the screen is deleted. This is used to deallocate listeners added to UICore.
342350
*/
343351
@JvmStatic
344352
var deallocationListeners: HashMap<String, Runnable>? = null
353+
protected set
345354

346355
/**
347356
* The list of modifier keys. The value is if the key is pressed
@@ -493,7 +502,13 @@ open class Aether(renderer: UIRenderer) {
493502
* Focuses the component. Please use [UIComponent.focus] instead.
494503
*/
495504
@JvmStatic
496-
fun <T> focus(component: T) where T : UIComponent<*>, T : UIFocusable {
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+
}
497512
focusedComponent = component
498513
}
499514

@@ -533,7 +548,7 @@ open class Aether(renderer: UIRenderer) {
533548
for (i in 0 until instance.frames!!.size) {
534549
// UIContainers are what control scrolling, so
535550
// if it is not an instance of it, skip and continue
536-
val container = instance.frames!![i] as? UIContainer<UIContainerSheet> ?: continue
551+
val container = instance.frames!![i] as? UIContainer<*> ?: continue
537552
if (container.isMouseInsideBounds() && container.expandedHeight > 0f && container.style.overflowY != UIContainerSheet.Overflow.None) {
538553
// Iterate through the frame to see if there are more
539554
// containers with it. If there are, it will pass true

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

Lines changed: 0 additions & 83 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package net.prismclient.aether.ui.callback
2+
3+
/**
4+
* [UICoreCallback] is an interface for getting data that
5+
* is not available to aether by default.
6+
*
7+
* @author sen
8+
* @since 5/13/2022
9+
*/
10+
interface UICoreCallback {
11+
/**
12+
* Returns the color of the pixel at the given position
13+
*
14+
* @return RGB(A) formatted int
15+
*/
16+
fun getPixelColor(x: Float, y: Float): Int
17+
}

0 commit comments

Comments
 (0)