feedback1-configurable-var
This commit is contained in:
@@ -20,21 +20,23 @@ fun main() = application {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Usage with a Lambda Expression Parameter
|
#### Usage with additional configuration
|
||||||
Optionally, the static backdrop may be initialised by passing a custom code block to the `NoClear()` function.
|
Optionally, a static `backdrop` may be setup by providing custom code.
|
||||||
|
|
||||||
- Example 1. Customising the backdrop with an image
|
- Example 1. Customising the backdrop with an image
|
||||||
```kotlin
|
```kotlin
|
||||||
val img = loadImage("file:data\\myImage.png")
|
extend(NoClear()) {
|
||||||
val bgImage = {
|
val img = loadImage("data\\backdrop.png")
|
||||||
|
backdrop = {
|
||||||
drawer.image(img, 0.0, 0.0, width * 1.0, height * 1.0)
|
drawer.image(img, 0.0, 0.0, width * 1.0, height * 1.0)
|
||||||
}
|
}
|
||||||
extend(NoClear(bgImage))
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
- Example 2. Customising the backdrop with a checker-board pattern
|
- Example 2. Customising the backdrop with a checker-board pattern
|
||||||
```kotlin
|
```kotlin
|
||||||
val bgBoard = {
|
extend(NoClear()) {
|
||||||
|
backdrop = {
|
||||||
val xw = width / 8.0
|
val xw = width / 8.0
|
||||||
val yh = height / 8.0
|
val yh = height / 8.0
|
||||||
drawer.fill = ColorRGBa.RED
|
drawer.fill = ColorRGBa.RED
|
||||||
@@ -45,8 +47,8 @@ val bgBoard = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
extend(NoClear(bgBoard))
|
|
||||||
```
|
```
|
||||||
|
|
||||||
NB! any submitted _lambda expression_ must be valid within the `renderTarget` context.
|
NB! any submitted _lambda expression_ must be valid within the `renderTarget` context.
|
||||||
@@ -9,10 +9,15 @@ import org.openrndr.draw.isolated
|
|||||||
import org.openrndr.draw.renderTarget
|
import org.openrndr.draw.renderTarget
|
||||||
import org.openrndr.math.Matrix44
|
import org.openrndr.math.Matrix44
|
||||||
|
|
||||||
class NoClear(val block: (() -> Unit)? = null): Extension {
|
class NoClear : Extension {
|
||||||
override var enabled: Boolean = true
|
override var enabled: Boolean = true
|
||||||
private var renderTarget: RenderTarget? = null
|
private var renderTarget: RenderTarget? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* code-block to draw an optional custom backdrop
|
||||||
|
*/
|
||||||
|
var backdrop: (() -> Unit)? = null
|
||||||
|
|
||||||
override fun beforeDraw(drawer: Drawer, program: Program) {
|
override fun beforeDraw(drawer: Drawer, program: Program) {
|
||||||
if (program.width > 0 && program.height > 0) { // only if the window is not minimised
|
if (program.width > 0 && program.height > 0) { // only if the window is not minimised
|
||||||
if (renderTarget == null || renderTarget?.width != program.width || renderTarget?.height != program.height) {
|
if (renderTarget == null || renderTarget?.width != program.width || renderTarget?.height != program.height) {
|
||||||
@@ -29,7 +34,7 @@ class NoClear(val block: (() -> Unit)? = null): Extension {
|
|||||||
renderTarget?.let {
|
renderTarget?.let {
|
||||||
drawer.withTarget(it) {
|
drawer.withTarget(it) {
|
||||||
background(program.backgroundColor ?: ColorRGBa.TRANSPARENT)
|
background(program.backgroundColor ?: ColorRGBa.TRANSPARENT)
|
||||||
block?.invoke()
|
backdrop?.invoke() // draw custom backdrop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user