Vector control in GUI

Also using snapshot of panel
This commit is contained in:
Rein van der Woerd
2020-03-14 16:17:45 +01:00
parent c8605f7f53
commit cba59e6a89
3 changed files with 70 additions and 4 deletions

View File

@@ -16,7 +16,7 @@ apply plugin: 'org.jetbrains.dokka'
project.ext {
openrndrVersion = "0.3.39"
panelVersion = "0.3.21"
panelVersion = "0.4.0-SNAPSHOT"
kotlinVersion = "1.3.70"
spekVersion = "2.0.9"
libfreenectVersion = "0.5.7-1.5.2"
@@ -49,6 +49,7 @@ allprojects {
repositories {
mavenCentral()
mavenLocal()
jcenter()
maven {
url = "https://dl.bintray.com/openrndr/openrndr"
@@ -112,4 +113,4 @@ allprojects {
includeEngines 'spek2'
}
}
}
}

View File

@@ -13,6 +13,7 @@ import org.openrndr.dialogs.saveFileDialog
import org.openrndr.draw.Drawer
import org.openrndr.extra.parameters.*
import org.openrndr.internal.Driver
import org.openrndr.math.Vector2
import org.openrndr.panel.ControlManager
import org.openrndr.panel.controlManager
import org.openrndr.panel.elements.*
@@ -175,6 +176,11 @@ class GUI : Extension {
descendant(has type "toggle") {
this.width = 175.px
}
descendant(has type "vector2") {
this.width = 175.px
this.height = 175.px
}
}
styleSheet(has class_ "randomize-strong") {
@@ -406,6 +412,25 @@ class GUI : Extension {
}
}
}
ParameterType.Vector2 -> {
vector2 {
minX = parameter.vectorRange!!.first.x
minY = parameter.vectorRange!!.first.y
maxX = parameter.vectorRange!!.second.x
maxY = parameter.vectorRange!!.second.y
events.valueChanged.subscribe {
setAndPersist(
compartment.label,
parameter.property as KMutableProperty1<Any, Vector2>,
obj,
it.newValue
)
onChangeListener?.invoke(parameter.property!!.name, it.newValue)
}
}
}
}
}
@@ -423,6 +448,7 @@ class GUI : Extension {
var intValue: Int? = null,
var booleanValue: Boolean? = null,
var colorValue: ColorRGBa? = null,
var vectorValue: Vector2? = null,
var textValue: String? = null)
@@ -442,6 +468,7 @@ class GUI : Extension {
ParameterType.Color -> ParameterValue(colorValue = k.property.qget(lo.obj) as ColorRGBa)
ParameterType.Text -> ParameterValue(textValue = k.property.qget(lo.obj) as String)
ParameterType.Boolean -> ParameterValue(booleanValue = k.property.qget(lo.obj) as Boolean)
ParameterType.Vector2 -> ParameterValue(vectorValue = k.property.qget(lo.obj) as Vector2)
})
})
}
@@ -476,6 +503,9 @@ class GUI : Extension {
ParameterType.Color -> parameterValue.colorValue?.let {
parameter.property.qset(lo.obj, it)
}
ParameterType.Vector2 -> parameterValue.vectorValue?.let {
parameter.property.qset(lo.obj, it)
}
ParameterType.Boolean -> parameterValue.booleanValue?.let {
parameter.property.qset(lo.obj, it)
}
@@ -505,6 +535,11 @@ class GUI : Extension {
ParameterType.Color -> {
(control as ColorpickerButton).color = (parameter.property as KMutableProperty1<Any, ColorRGBa>).get(labeledObject.obj)
}
// ParameterType.Vector2 -> {
// (control as Vector2Control).value = (parameter.property as KMutableProperty1<Any, Vector2>).get(labeledObject.obj)
// }
ParameterType.Boolean -> {
(control as Toggle).value = (parameter.property as KMutableProperty1<Any, Boolean>).get(labeledObject.obj)
}
@@ -614,4 +649,4 @@ class GUI : Extension {
fun <T : Any> T.addTo(gui: GUI, label:String? = this.title()): T {
gui.add(this, label)
return this
}
}

View File

@@ -1,5 +1,6 @@
package org.openrndr.extra.parameters
import org.openrndr.math.Vector2
import kotlin.reflect.KCallable
import kotlin.reflect.KClass
import kotlin.reflect.KMutableProperty1
@@ -71,6 +72,25 @@ annotation class TextParameter(val label: String, val order: Int = Integer.MAX_V
@Retention(AnnotationRetention.RUNTIME)
annotation class ColorParameter(val label: String, val order: Int = Integer.MAX_VALUE)
/**
* Vector2 annotation for a vector 2 parameter
* @property label a short description of the parameter
* @property order hint for where to place the parameter in user interfaces
*/
@Target(AnnotationTarget.PROPERTY)
@Retention(AnnotationRetention.RUNTIME)
annotation class Vector2Parameter(
val label: String,
val minX: Double = -1.0,
val minY: Double = -1.0,
val maxX: Double = 1.0,
val maxY: Double = 1.0,
val order: Int = Integer.MAX_VALUE
)
/**
* ActionParameter annotation for functions without arguments
* @property label a short description of the parameter
@@ -86,7 +106,8 @@ enum class ParameterType(val annotationClass: KClass<out Annotation>) {
Boolean(BooleanParameter::class),
Action(ActionParameter::class),
Text(TextParameter::class),
Color(ColorParameter::class)
Color(ColorParameter::class),
Vector2(Vector2Parameter::class)
;
companion object {
@@ -115,6 +136,7 @@ class Parameter(
val function: KCallable<Unit>?,
val label: String,
val doubleRange: ClosedRange<Double>?,
val vectorRange: Pair<Vector2, Vector2>?,
val intRange: IntRange?,
val precision: Int?,
val order: Int)
@@ -136,6 +158,7 @@ fun Any.listParameters(): List<Parameter> {
var label = ""
var precision: Int? = null
var type: ParameterType? = null
var vectorRange = Pair(Vector2(-1.0, -1.0), Vector2(1.0, 1.0))
annotations.forEach {
type = ParameterType.forParameterAnnotationClass(it)
@@ -163,6 +186,11 @@ fun Any.listParameters(): List<Parameter> {
label = it.label
order = it.order
}
is Vector2Parameter -> {
label = it.label
order = it.order
vectorRange = Pair(Vector2(it.minX, it.minY), Vector2(it.maxX, it.maxY))
}
}
}
Parameter(
@@ -171,6 +199,7 @@ fun Any.listParameters(): List<Parameter> {
function = null,
label = label,
doubleRange = doubleRange,
vectorRange = vectorRange,
intRange = intRange,
precision = precision,
order = order
@@ -189,6 +218,7 @@ fun Any.listParameters(): List<Parameter> {
label = label,
doubleRange = null,
intRange = null,
vectorRange = null,
precision = null,
order = order
)