[orx-jvm] Move panel, gui, dnk3, keyframer, triangulation to orx-jvm

This commit is contained in:
Edwin Jakobs
2021-06-27 21:32:24 +02:00
parent 5814acef8f
commit 874d49779f
159 changed files with 22 additions and 21 deletions

View File

@@ -0,0 +1,80 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extensions.SingleScreenshot
import org.openrndr.math.Spherical
import org.openrndr.math.Vector3
import org.openrndr.panel.controlManager
import org.openrndr.panel.elements.button
import org.openrndr.panel.elements.div
import org.openrndr.panel.elements.h1
import org.openrndr.panel.style.*
suspend fun main() = application {
program {
// -- this block is for automation purposes only
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
val cm = controlManager {
styleSheet(has class_ "horizontal") {
paddingLeft = 10.px
paddingTop = 10.px
// ----------------------------------------------
// The next two lines produce a horizontal layout
// ----------------------------------------------
display = Display.FLEX
flexDirection = FlexDirection.Row
width = 100.percent
}
styleSheet(has type "h1") {
marginTop = 10.px
marginLeft = 7.px
marginBottom = 10.px
}
layout {
val header = h1 { "click a button..." }
div("horizontal") {
// A bunch of names for generating buttons
listOf("load", "save", "redo", "stretch", "bounce",
"twist", "swim", "roll", "fly", "dance")
.forEachIndexed { i, word ->
// A fun way of generating a set of colors
// of similar brightness:
// Grab a point on the surface of a sphere
// and treat its coordinates as an rgb color.
val pos = Vector3.fromSpherical(
Spherical(i * 19.0, i * 17.0, 0.4))
val rgb = ColorRGBa.fromVector(pos + 0.4)
button {
label = word
style = styleSheet {
// Use Color.RGBa() to convert a ColorRGBa
// color (the standard color datatype)
// into "CSS" format:
background = Color.RGBa(rgb)
}
// When the button is clicked replace
// the header text with the button's label
events.clicked.listen {
header.replaceText(it.source.label)
}
}
}
}
}
}
extend(cm)
extend {
drawer.clear(0.2, 0.18, 0.16, 1.0)
}
}
}

View File

@@ -0,0 +1,47 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extensions.SingleScreenshot
import org.openrndr.panel.controlManager
import org.openrndr.panel.elements.div
import org.openrndr.panel.elements.slider
import org.openrndr.panel.style.*
suspend fun main() = application {
program {
// -- this block is for automation purposes only
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
val cm = controlManager {
styleSheet(has class_ "side-bar") {
this.height = 100.percent
this.width = 200.px
this.display = Display.FLEX
this.flexDirection = FlexDirection.Column
this.paddingLeft = 10.px
this.paddingRight = 10.px
this.background = Color.RGBa(ColorRGBa.GRAY)
}
styleSheet(has type "slider") {
this.marginTop = 25.px
this.marginBottom = 25.px
}
layout {
div("side-bar") {
slider {
label = "Slider 1"
}
slider {
label = "Slider 2"
}
}
}
}
extend(cm)
extend {
}
}
}

View File

@@ -0,0 +1,130 @@
import com.google.gson.Gson
import org.openrndr.application
import org.openrndr.dialogs.openFileDialog
import org.openrndr.dialogs.saveFileDialog
import org.openrndr.extensions.SingleScreenshot
import org.openrndr.panel.controlManager
import org.openrndr.panel.elements.*
import org.openrndr.panel.style.*
import java.io.File
// -- these have to be top-level classes or Gson will silently fail.
private class ConfigItem {
var value: Double = 0.0
}
private class ProgramState {
var rows = 1
var columns = 1
val matrix = mutableListOf(mutableListOf(ConfigItem()))
fun copyTo(programState: ProgramState) {
programState.rows = rows
programState.columns = columns
programState.matrix.clear()
programState.matrix.addAll(matrix)
}
fun save(file: File) {
file.writeText(Gson().toJson(this))
}
fun load(file: File) {
Gson().fromJson(file.readText(), ProgramState::class.java).copyTo(this)
}
}
suspend fun main() = application {
configure {
width = 900
height = 720
}
program {
// -- this block is for automation purposes only
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
val programState = ProgramState()
val cm = controlManager {
layout {
styleSheet(has class_ "matrix") {
this.width = 100.percent
}
styleSheet(has class_ "row") {
this.display = Display.FLEX
this.flexDirection = FlexDirection.Row
this.width = 100.percent
child(has type "slider") {
this.width = 80.px
}
}
button {
label = "save"
clicked {
saveFileDialog(supportedExtensions = listOf("json")) {
programState.save(it)
}
}
}
button {
label = "load"
clicked {
openFileDialog(supportedExtensions = listOf("json")) {
programState.load(it)
}
}
}
slider {
label = "rows"
precision = 0
bind(programState::rows)
events.valueChanged.listen {
while (programState.matrix.size > programState.rows) {
programState.matrix.removeAt(programState.matrix.size - 1)
}
while (programState.matrix.size < programState.rows) {
programState.matrix.add(MutableList(programState.columns) { ConfigItem() })
}
}
}
slider {
label = "columns"
precision = 0
bind(programState::columns)
events.valueChanged.listen {
for (row in programState.matrix) {
while (row.size > programState.columns) {
row.removeAt(row.size - 1)
}
while (row.size < programState.columns) {
row.add(ConfigItem())
}
}
}
}
watchListDiv("matrix", watchList = programState.matrix) { row ->
watchListDiv("row", watchList = row) { item ->
this.id = "some-row"
slider {
label = "value"
bind(item::value)
}
}
}
}
}
extend(cm)
}
}

View File

@@ -0,0 +1,75 @@
import org.openrndr.application
import org.openrndr.extensions.SingleScreenshot
import org.openrndr.panel.controlManager
import org.openrndr.panel.elements.*
import org.openrndr.panel.style.*
suspend fun main() = application {
configure {
width = 900
height = 720
}
// A very simple state
class State {
var x = 0
var y = 0
var z = 0
}
program {
// -- this block is for automation purposes only
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
val programState = State()
val cm = controlManager {
layout {
styleSheet(has class_ "matrix") {
this.width = 100.percent
}
styleSheet(has class_ "row") {
this.display = Display.FLEX
this.flexDirection = FlexDirection.Row
this.width = 100.percent
child(has type "slider") {
this.width = 80.px
}
}
slider {
label = "x"
precision = 0
bind(programState::x)
}
slider {
label = "y"
precision = 0
bind(programState::y)
}
watchObjectDiv("matrix", watchObject = object {
// for primitive types we have to use property references
val x = programState::x
val y = programState::y
}) {
for (y in 0 until watchObject.y.get()) {
div("row") {
for (x in 0 until watchObject.x.get()) {
button() {
label = "$x, $y"
}
}
}
}
}
}
}
extend(cm)
}
}