[orx-gui] Make WindowedGUI compatible with orx-olive
This commit is contained in:
@@ -9,6 +9,7 @@ dependencies {
|
|||||||
api(project(":orx-jvm:orx-panel"))
|
api(project(":orx-jvm:orx-panel"))
|
||||||
api(project(":orx-noise"))
|
api(project(":orx-noise"))
|
||||||
demoImplementation(project(":orx-property-watchers"))
|
demoImplementation(project(":orx-property-watchers"))
|
||||||
|
implementation(libs.kotlin.coroutines)
|
||||||
implementation(libs.openrndr.application)
|
implementation(libs.openrndr.application)
|
||||||
implementation(libs.openrndr.math)
|
implementation(libs.openrndr.math)
|
||||||
implementation(libs.openrndr.filter)
|
implementation(libs.openrndr.filter)
|
||||||
|
|||||||
@@ -1,31 +1,62 @@
|
|||||||
package org.openrndr.extra.gui
|
package org.openrndr.extra.gui
|
||||||
|
|
||||||
import org.openrndr.Extension
|
import org.openrndr.*
|
||||||
import org.openrndr.Program
|
|
||||||
import org.openrndr.WindowConfiguration
|
|
||||||
import org.openrndr.extra.parameters.title
|
import org.openrndr.extra.parameters.title
|
||||||
|
import org.openrndr.internal.Driver
|
||||||
import org.openrndr.math.IntVector2
|
import org.openrndr.math.IntVector2
|
||||||
import org.openrndr.panel.style.StyleSheet
|
import org.openrndr.panel.style.StyleSheet
|
||||||
import org.openrndr.panel.style.defaultStyles
|
import org.openrndr.panel.style.defaultStyles
|
||||||
import org.openrndr.window
|
|
||||||
|
|
||||||
class WindowedGUI(val appearance: GUIAppearance = GUIAppearance(), val defaultStyles: List<StyleSheet> = defaultStyles()) : Extension {
|
private val childWindows = mutableMapOf<Long, ApplicationWindow>()
|
||||||
|
|
||||||
|
class WindowedGUI(
|
||||||
|
val appearance: GUIAppearance = GUIAppearance(),
|
||||||
|
val defaultStyles: List<StyleSheet> = defaultStyles()
|
||||||
|
) : Extension {
|
||||||
override var enabled: Boolean = true
|
override var enabled: Boolean = true
|
||||||
|
|
||||||
val addedObjects = mutableListOf<Pair<Any, String?>>()
|
private val addedObjects = mutableListOf<Pair<Any, String?>>()
|
||||||
fun <T : Any> add(objectWithParameters: T, label: String? = objectWithParameters.title()): T {
|
fun <T : Any> add(objectWithParameters: T, label: String? = objectWithParameters.title()): T {
|
||||||
addedObjects.add(Pair(objectWithParameters, label))
|
addedObjects.add(Pair(objectWithParameters, label))
|
||||||
return objectWithParameters
|
return objectWithParameters
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun setup(program: Program) {
|
override fun setup(program: Program) {
|
||||||
program.window(WindowConfiguration(width = 200, height = program.height, position = program.window.position.toInt() - IntVector2(200,0) )) {
|
val window = childWindows[Driver.instance.contextID]
|
||||||
val gui = GUI(appearance, defaultStyles)
|
if (window != null) {
|
||||||
for ((obj, label) in addedObjects) {
|
window.program.mouse.exited.listeners.clear()
|
||||||
gui.add(obj, label)
|
window.program.mouse.entered.listeners.clear()
|
||||||
|
window.program.mouse.buttonUp.listeners.clear()
|
||||||
|
window.program.mouse.buttonDown.listeners.clear()
|
||||||
|
window.program.mouse.dragged.listeners.clear()
|
||||||
|
window.program.mouse.scrolled.listeners.clear()
|
||||||
|
window.program.mouse.moved.listeners.clear()
|
||||||
|
window.program.keyboard.keyUp.listeners.clear()
|
||||||
|
window.program.keyboard.keyDown.listeners.clear()
|
||||||
|
window.program.keyboard.keyRepeat.listeners.clear()
|
||||||
|
window.program.keyboard.character.listeners.clear()
|
||||||
|
window.program.extensions.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
val cw = childWindows.getOrPut(Driver.instance.contextID) {
|
||||||
|
program.window(
|
||||||
|
WindowConfiguration(
|
||||||
|
width = 200,
|
||||||
|
height = program.height,
|
||||||
|
position = program.window.position.toInt() - IntVector2(200, 0)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
//
|
||||||
}
|
}
|
||||||
extend(gui)
|
}
|
||||||
|
|
||||||
|
// launch because at this stage Driver.instance.contextID points to the context of the parent window
|
||||||
|
cw.program.launch {
|
||||||
|
val gui = GUI(appearance, defaultStyles)
|
||||||
|
for (o in addedObjects) {
|
||||||
|
gui.add(o.first, o.second)
|
||||||
|
}
|
||||||
|
cw.program.extend(gui)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user