[orx-view-box] Add update() function and result property
This commit is contained in:
@@ -38,6 +38,15 @@ class ViewBox(
|
||||
|
||||
override val extensions: MutableList<Extension> = mutableListOf<Extension>()
|
||||
|
||||
val result: ColorBuffer
|
||||
get() {
|
||||
return if (resolved == null) {
|
||||
renderTarget?.colorBuffer(0) ?: error("no result available")
|
||||
} else {
|
||||
return resolved ?: error("no result available")
|
||||
}
|
||||
}
|
||||
|
||||
inner class TranslatedMouseEvents : MouseEvents {
|
||||
override val buttonDown = Event<MouseEvent>()
|
||||
override val buttonUp = Event<MouseEvent>()
|
||||
@@ -229,8 +238,21 @@ class ViewBox(
|
||||
}
|
||||
|
||||
override fun draw() {
|
||||
configureRenderTarget()
|
||||
update()
|
||||
program.drawer.isolated {
|
||||
if (resolved == null) {
|
||||
program.drawer.image(renderTarget!!.colorBuffer(0), clientArea.corner)
|
||||
} else {
|
||||
program.drawer.image(resolved!!, clientArea.corner)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the view box by executing all the extension draw stages. [Update] will not visualize the results
|
||||
*/
|
||||
fun update() {
|
||||
configureRenderTarget()
|
||||
if (viewBoxReconfigured || shouldDraw()) {
|
||||
program.drawer.isolatedWithTarget(renderTarget!!) {
|
||||
drawer.clear(ColorRGBa.BLACK)
|
||||
@@ -246,13 +268,8 @@ class ViewBox(
|
||||
|
||||
viewBoxReconfigured = false
|
||||
}
|
||||
}
|
||||
program.drawer.isolated {
|
||||
if (resolved == null) {
|
||||
program.drawer.image(renderTarget!!.colorBuffer(0), clientArea.corner)
|
||||
} else {
|
||||
if (resolved != null) {
|
||||
renderTarget!!.colorBuffer(0).copyTo(resolved!!)
|
||||
program.drawer.image(resolved!!, clientArea.corner)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
30
orx-view-box/src/jvmDemo/kotlin/DemoUpdate01.kt
Normal file
30
orx-view-box/src/jvmDemo/kotlin/DemoUpdate01.kt
Normal file
@@ -0,0 +1,30 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.extra.camera.Camera2D
|
||||
import org.openrndr.extra.viewbox.viewBox
|
||||
import org.openrndr.shape.Rectangle
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
}
|
||||
program {
|
||||
val vbx = viewBox(Rectangle(0.0, 0.0, 200.0, 200.0)) {
|
||||
extend(Camera2D())
|
||||
extend {
|
||||
drawer.rectangle(20.0, 20.0, 100.0, 100.0)
|
||||
}
|
||||
}
|
||||
|
||||
extend {
|
||||
vbx.update()
|
||||
for (j in 0 until 4) {
|
||||
for (i in 0 until 4) {
|
||||
drawer.image(vbx.result, j * 200.0, i * 200.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user