From ef684668a843dc3e04e3d7c24020bd3ccaf1160c Mon Sep 17 00:00:00 2001 From: CodeCox Date: Sun, 25 Nov 2018 09:51:41 +0000 Subject: [PATCH 1/3] provide a custom backdrop --- orx-no-clear/README.md | 49 ++++++++++++++++++++----- orx-no-clear/src/main/kotlin/NoClear.kt | 4 +- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/orx-no-clear/README.md b/orx-no-clear/README.md index 0f6923f2..3428b040 100644 --- a/orx-no-clear/README.md +++ b/orx-no-clear/README.md @@ -5,17 +5,48 @@ OPENRNDR does not support natively. #### Usage -``` -class NoClearProgram: Program() { - - override fun setup() { +```kotlin +fun main() = application { + configure { + title = "NoClearProgram" + } + program { backgroundColor = ColorRGBa.PINK extend(NoClear()) - } - - override fun draw() { - drawer.circle(Math.cos(seconds) * width / 2.0 + width / 2.0, Math.sin(seconds * 0.24) * height / 2.0 + height / 2.0, 20.0) + extend { + drawer.circle(Math.cos(seconds) * width / 2.0 + width / 2.0, Math.sin(seconds * 0.24) * height / 2.0 + height / 2.0, 20.0) + } } } - ``` + +#### Usage with a Lambda Expression Parameter +Optionally, the static backdrop may be initialised by passing a custom code block to the `NoClear()` function. + +- Example 1. Customising the backdrop with an image +```kotlin +val img = loadImage("file:data\\myImage.png") +val bgImage = { + 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 +```kotlin +val bgBoard = { + val xw = width / 8.0 + val yh = height / 8.0 + drawer.fill = ColorRGBa.RED + (0..7).forEach { row -> + (0..7).forEach { col -> + if ((row + col) % 2 == 0) { + drawer.rectangle(row * xw, col * yh, xw, yh) + } + } + } +} +extend(NoClear(bgBoard)) +``` + +NB! any submitted _lambda expression_ must be valid within the `renderTarget` context. \ No newline at end of file diff --git a/orx-no-clear/src/main/kotlin/NoClear.kt b/orx-no-clear/src/main/kotlin/NoClear.kt index 1663a3d9..941ff43f 100644 --- a/orx-no-clear/src/main/kotlin/NoClear.kt +++ b/orx-no-clear/src/main/kotlin/NoClear.kt @@ -9,11 +9,10 @@ import org.openrndr.draw.isolated import org.openrndr.draw.renderTarget import org.openrndr.math.Matrix44 -class NoClear : Extension { +class NoClear(val block: (() -> Unit)? = null): Extension { override var enabled: Boolean = true private var renderTarget: RenderTarget? = null - override fun beforeDraw(drawer: Drawer, program: Program) { 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) { @@ -30,6 +29,7 @@ class NoClear : Extension { renderTarget?.let { drawer.withTarget(it) { background(program.backgroundColor ?: ColorRGBa.TRANSPARENT) + block?.invoke() } } } From 1ce277bd41b4c15e718d79e26fbf140672ea0f03 Mon Sep 17 00:00:00 2001 From: CodeCox Date: Mon, 26 Nov 2018 05:23:56 +0000 Subject: [PATCH 2/3] feedback1-configurable-var --- orx-no-clear/README.md | 30 +++++++++++++------------ orx-no-clear/src/main/kotlin/NoClear.kt | 9 ++++++-- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/orx-no-clear/README.md b/orx-no-clear/README.md index 3428b040..6de33c33 100644 --- a/orx-no-clear/README.md +++ b/orx-no-clear/README.md @@ -20,33 +20,35 @@ fun main() = application { } ``` -#### Usage with a Lambda Expression Parameter -Optionally, the static backdrop may be initialised by passing a custom code block to the `NoClear()` function. +#### Usage with additional configuration +Optionally, a static `backdrop` may be setup by providing custom code. - Example 1. Customising the backdrop with an image ```kotlin -val img = loadImage("file:data\\myImage.png") -val bgImage = { +extend(NoClear()) { + val img = loadImage("data\\backdrop.png") + backdrop = { 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 ```kotlin -val bgBoard = { - val xw = width / 8.0 - val yh = height / 8.0 - drawer.fill = ColorRGBa.RED - (0..7).forEach { row -> - (0..7).forEach { col -> - if ((row + col) % 2 == 0) { - drawer.rectangle(row * xw, col * yh, xw, yh) +extend(NoClear()) { + backdrop = { + val xw = width / 8.0 + val yh = height / 8.0 + drawer.fill = ColorRGBa.RED + (0..7).forEach { row -> + (0..7).forEach { col -> + if ((row + col) % 2 == 0) { + drawer.rectangle(row * xw, col * yh, xw, yh) + } } } } } -extend(NoClear(bgBoard)) ``` NB! any submitted _lambda expression_ must be valid within the `renderTarget` context. \ No newline at end of file diff --git a/orx-no-clear/src/main/kotlin/NoClear.kt b/orx-no-clear/src/main/kotlin/NoClear.kt index 941ff43f..9a187282 100644 --- a/orx-no-clear/src/main/kotlin/NoClear.kt +++ b/orx-no-clear/src/main/kotlin/NoClear.kt @@ -9,10 +9,15 @@ import org.openrndr.draw.isolated import org.openrndr.draw.renderTarget import org.openrndr.math.Matrix44 -class NoClear(val block: (() -> Unit)? = null): Extension { +class NoClear : Extension { override var enabled: Boolean = true private var renderTarget: RenderTarget? = null + /** + * code-block to draw an optional custom backdrop + */ + var backdrop: (() -> Unit)? = null + override fun beforeDraw(drawer: Drawer, program: Program) { 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) { @@ -29,7 +34,7 @@ class NoClear(val block: (() -> Unit)? = null): Extension { renderTarget?.let { drawer.withTarget(it) { background(program.backgroundColor ?: ColorRGBa.TRANSPARENT) - block?.invoke() + backdrop?.invoke() // draw custom backdrop } } } From a79ece76aed0e5c10f0cfc1ffb7e6725c932a899 Mon Sep 17 00:00:00 2001 From: edwin Date: Mon, 26 Nov 2018 10:35:50 +0100 Subject: [PATCH 3/3] Bumped OPENRNDR to 0.3.30-rc2 --- README.md | 2 +- build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 678fd9a3..78bd109c 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ A growing library of assorted data structures, algorithms and utilities. - [`orx-obj-loader`](orx-obj-loader/README.md), simple Wavefront .obj mesh loader ## Usage -ORX 0.0.14 is built against OPENRNDR 0.3.30-rc1, make sure you use this version in your project. Because OPENRNDR's API is pre 1.0 it tends to change from time to time. +ORX 0.0.14 is built against OPENRNDR 0.3.30-rc2, make sure you use this version in your project. Because OPENRNDR's API is pre 1.0 it tends to change from time to time. The easiest way to add ORX to your project is through the use of Jitpack. [Jitpack](http://jitpack.io) is a service that pulls Gradle based libraries from Github, builds them and serves the jar files. diff --git a/build.gradle b/build.gradle index 26c597ea..700f88c9 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ repositories { } ext { - openrndrVersion = "0.3.30-rc1" + openrndrVersion = "0.3.30-rc2" } subprojects {