From 963038d74e37a3c886759d9c4583545273e13deb Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Thu, 19 Mar 2020 23:39:57 +0100 Subject: [PATCH] Add XYParameter annotation --- build.gradle | 6 ++--- orx-gui/src/main/kotlin/Gui.kt | 13 ++++++----- orx-parameters/src/main/kotlin/Annotations.kt | 22 +++++++++++++++---- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index a3118aec..3b1d902a 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ project.ext { openrndrVersion = "0.3.40-rc.4" panelVersion = "0.3.22-rc.2" kotlinVersion = "1.3.70" - spekVersion = "2.0.9" + spekVersion = "2.0.10" libfreenectVersion = "0.5.7-1.5.2" gsonVersion = "2.8.6" } @@ -61,11 +61,11 @@ allprojects { } dependencies { - implementation 'io.github.microutils:kotlin-logging:1.7.8' + implementation 'io.github.microutils:kotlin-logging:1.7.9' implementation "org.openrndr:openrndr-core:$openrndrVersion" implementation "org.openrndr:openrndr-filter:$openrndrVersion" implementation "org.openrndr:openrndr-shape:$openrndrVersion" - implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.3.4' + implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.3.5' testImplementation "org.spekframework.spek2:spek-dsl-jvm:$spekVersion" testImplementation "org.amshove.kluent:kluent:1.60" testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlinVersion" diff --git a/orx-gui/src/main/kotlin/Gui.kt b/orx-gui/src/main/kotlin/Gui.kt index d1878a18..f2f60c86 100644 --- a/orx-gui/src/main/kotlin/Gui.kt +++ b/orx-gui/src/main/kotlin/Gui.kt @@ -177,7 +177,7 @@ class GUI : Extension { this.width = 175.px } - descendant(has type "vector2") { + descendant(has type "xy-pad") { this.width = 175.px this.height = 175.px } @@ -413,12 +413,15 @@ class GUI : Extension { } } - ParameterType.Vector2 -> { - planarPad { + ParameterType.XY -> { + xyPad { minX = parameter.vectorRange!!.first.x minY = parameter.vectorRange!!.first.y maxX = parameter.vectorRange!!.second.x maxY = parameter.vectorRange!!.second.y + keyboardIncrement = parameter.keyboardIncrement!! + precision = parameter.precision!! + showAngle = parameter.showAngle!! events.valueChanged.subscribe { setAndPersist( @@ -468,7 +471,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) + ParameterType.XY -> ParameterValue(vectorValue = k.property.qget(lo.obj) as Vector2) }) }) } @@ -503,7 +506,7 @@ class GUI : Extension { ParameterType.Color -> parameterValue.colorValue?.let { parameter.property.qset(lo.obj, it) } - ParameterType.Vector2 -> parameterValue.vectorValue?.let { + ParameterType.XY -> parameterValue.vectorValue?.let { parameter.property.qset(lo.obj, it) } ParameterType.Boolean -> parameterValue.booleanValue?.let { diff --git a/orx-parameters/src/main/kotlin/Annotations.kt b/orx-parameters/src/main/kotlin/Annotations.kt index dac0cab0..5442a6cf 100644 --- a/orx-parameters/src/main/kotlin/Annotations.kt +++ b/orx-parameters/src/main/kotlin/Annotations.kt @@ -6,7 +6,6 @@ import kotlin.reflect.KClass import kotlin.reflect.KMutableProperty1 import kotlin.reflect.KVisibility import kotlin.reflect.full.declaredMemberFunctions -import kotlin.reflect.full.declaredMemberProperties import kotlin.reflect.full.findAnnotation import kotlin.reflect.full.memberProperties @@ -80,12 +79,15 @@ annotation class ColorParameter(val label: String, val order: Int = Integer.MAX_ */ @Target(AnnotationTarget.PROPERTY) @Retention(AnnotationRetention.RUNTIME) -annotation class Vector2Parameter( +annotation class XYParameter( val label: String, val minX: Double = -1.0, val minY: Double = -1.0, val maxX: Double = 1.0, val maxY: Double = 1.0, + val precision: Int = 1, + val keyboardIncrement: Double = 10.0, + val showAngle: Boolean = false, val order: Int = Integer.MAX_VALUE ) @@ -107,7 +109,7 @@ enum class ParameterType(val annotationClass: KClass) { Action(ActionParameter::class), Text(TextParameter::class), Color(ColorParameter::class), - Vector2(Vector2Parameter::class) + XY(XYParameter::class) ; companion object { @@ -128,6 +130,7 @@ enum class ParameterType(val annotationClass: KClass) { * @property doubleRange a floating point based range in case [DoubleParameter] is used * @property intRange an integer range in case [IntParameter] is used * @property precision a precision hint in case a [DoubleParameter] annotation is used + * @property keyboardIncrement how much change the keyboard makes in case a [XYParameter] annotation is used * @property order a hint for where in the ui this parameter is placed, lower value means higher priority */ class Parameter( @@ -139,6 +142,8 @@ class Parameter( val vectorRange: Pair?, val intRange: IntRange?, val precision: Int?, + val keyboardIncrement: Double?, + val showAngle: Boolean?, val order: Int) /** @@ -159,6 +164,8 @@ fun Any.listParameters(): List { var precision: Int? = null var type: ParameterType? = null var vectorRange = Pair(Vector2(-1.0, -1.0), Vector2(1.0, 1.0)) + var keyboardIncrement: Double? = null + var showAngle: Boolean? = null annotations.forEach { type = ParameterType.forParameterAnnotationClass(it) @@ -186,10 +193,13 @@ fun Any.listParameters(): List { label = it.label order = it.order } - is Vector2Parameter -> { + is XYParameter -> { label = it.label order = it.order vectorRange = Pair(Vector2(it.minX, it.minY), Vector2(it.maxX, it.maxY)) + keyboardIncrement = it.keyboardIncrement + precision = it.precision + showAngle = it.showAngle } } } @@ -202,6 +212,8 @@ fun Any.listParameters(): List { vectorRange = vectorRange, intRange = intRange, precision = precision, + keyboardIncrement = keyboardIncrement, + showAngle = showAngle, order = order ) } + this::class.declaredMemberFunctions.filter { @@ -220,6 +232,8 @@ fun Any.listParameters(): List { intRange = null, vectorRange = null, precision = null, + keyboardIncrement = null, + showAngle = false, order = order ) }).sortedBy { it.order }