[orx-view-box] Add demo for proxy programs
This commit is contained in:
@@ -31,7 +31,7 @@ class ViewBox(
|
||||
|
||||
override val extensions: MutableList<Extension> = mutableListOf<Extension>()
|
||||
|
||||
inner class TranslatedMouseEvents: MouseEvents {
|
||||
inner class TranslatedMouseEvents : MouseEvents {
|
||||
override val buttonDown = Event<MouseEvent>()
|
||||
override val buttonUp = Event<MouseEvent>()
|
||||
override val dragged = Event<MouseEvent>()
|
||||
@@ -45,7 +45,7 @@ class ViewBox(
|
||||
override val scrolled = Event<MouseEvent>()
|
||||
}
|
||||
|
||||
override val mouse: MouseEvents = if (translateMouse) {
|
||||
override val mouse: MouseEvents = if (translateMouse) {
|
||||
TranslatedMouseEvents()
|
||||
} else {
|
||||
program.mouse
|
||||
@@ -235,10 +235,12 @@ class ViewBox(
|
||||
* @param f [ViewBox] configuration function
|
||||
* @return a newly created [ViewBox]
|
||||
*/
|
||||
fun Program.viewBox(area: Rectangle,
|
||||
translateMouse: Boolean = true,
|
||||
translateKeyboard: Boolean = true,
|
||||
f: ViewBox.() -> Unit): ViewBox {
|
||||
fun Program.viewBox(
|
||||
area: Rectangle,
|
||||
translateMouse: Boolean = true,
|
||||
translateKeyboard: Boolean = true,
|
||||
f: ViewBox.() -> Unit = {}
|
||||
): ViewBox {
|
||||
val viewBox = ViewBox(this, area, translateMouse, translateKeyboard)
|
||||
viewBox.f()
|
||||
return viewBox
|
||||
|
||||
38
orx-view-box/src/demo/kotlin/DemoProxyProgram01.kt
Normal file
38
orx-view-box/src/demo/kotlin/DemoProxyProgram01.kt
Normal file
@@ -0,0 +1,38 @@
|
||||
import org.openrndr.Program
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.viewbox.viewBox
|
||||
import org.openrndr.math.Vector2
|
||||
import kotlin.math.cos
|
||||
|
||||
fun Program.program01() {
|
||||
var color: ColorRGBa by this.userProperties
|
||||
color = ColorRGBa.WHITE
|
||||
|
||||
var someFunction : ()->Unit by this.userProperties
|
||||
someFunction = {
|
||||
color = ColorRGBa(Math.random(), Math.random(), Math.random())
|
||||
}
|
||||
|
||||
extend {
|
||||
drawer.fill = color
|
||||
drawer.circle(Vector2(width/2.0, height/2.0), cos(seconds) * 50.0 + 50.0)
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
val proxyBox = viewBox(drawer.bounds).apply { program01() }
|
||||
var color: ColorRGBa by proxyBox.userProperties
|
||||
var someFunction: () -> Unit by proxyBox.userProperties
|
||||
color = ColorRGBa.PINK
|
||||
extend {
|
||||
if (Math.random() < 0.01) {
|
||||
someFunction()
|
||||
}
|
||||
proxyBox.draw()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user