Add XYParameter annotation

This commit is contained in:
Edwin Jakobs
2020-03-19 23:39:57 +01:00
parent 96ad0f6e68
commit 963038d74e
3 changed files with 29 additions and 12 deletions

View File

@@ -18,7 +18,7 @@ project.ext {
openrndrVersion = "0.3.40-rc.4" openrndrVersion = "0.3.40-rc.4"
panelVersion = "0.3.22-rc.2" panelVersion = "0.3.22-rc.2"
kotlinVersion = "1.3.70" kotlinVersion = "1.3.70"
spekVersion = "2.0.9" spekVersion = "2.0.10"
libfreenectVersion = "0.5.7-1.5.2" libfreenectVersion = "0.5.7-1.5.2"
gsonVersion = "2.8.6" gsonVersion = "2.8.6"
} }
@@ -61,11 +61,11 @@ allprojects {
} }
dependencies { 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-core:$openrndrVersion"
implementation "org.openrndr:openrndr-filter:$openrndrVersion" implementation "org.openrndr:openrndr-filter:$openrndrVersion"
implementation "org.openrndr:openrndr-shape:$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.spekframework.spek2:spek-dsl-jvm:$spekVersion"
testImplementation "org.amshove.kluent:kluent:1.60" testImplementation "org.amshove.kluent:kluent:1.60"
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlinVersion" testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlinVersion"

View File

@@ -177,7 +177,7 @@ class GUI : Extension {
this.width = 175.px this.width = 175.px
} }
descendant(has type "vector2") { descendant(has type "xy-pad") {
this.width = 175.px this.width = 175.px
this.height = 175.px this.height = 175.px
} }
@@ -413,12 +413,15 @@ class GUI : Extension {
} }
} }
ParameterType.Vector2 -> { ParameterType.XY -> {
planarPad { xyPad {
minX = parameter.vectorRange!!.first.x minX = parameter.vectorRange!!.first.x
minY = parameter.vectorRange!!.first.y minY = parameter.vectorRange!!.first.y
maxX = parameter.vectorRange!!.second.x maxX = parameter.vectorRange!!.second.x
maxY = parameter.vectorRange!!.second.y maxY = parameter.vectorRange!!.second.y
keyboardIncrement = parameter.keyboardIncrement!!
precision = parameter.precision!!
showAngle = parameter.showAngle!!
events.valueChanged.subscribe { events.valueChanged.subscribe {
setAndPersist( setAndPersist(
@@ -468,7 +471,7 @@ class GUI : Extension {
ParameterType.Color -> ParameterValue(colorValue = k.property.qget(lo.obj) as ColorRGBa) ParameterType.Color -> ParameterValue(colorValue = k.property.qget(lo.obj) as ColorRGBa)
ParameterType.Text -> ParameterValue(textValue = k.property.qget(lo.obj) as String) ParameterType.Text -> ParameterValue(textValue = k.property.qget(lo.obj) as String)
ParameterType.Boolean -> ParameterValue(booleanValue = k.property.qget(lo.obj) as Boolean) 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 { ParameterType.Color -> parameterValue.colorValue?.let {
parameter.property.qset(lo.obj, it) parameter.property.qset(lo.obj, it)
} }
ParameterType.Vector2 -> parameterValue.vectorValue?.let { ParameterType.XY -> parameterValue.vectorValue?.let {
parameter.property.qset(lo.obj, it) parameter.property.qset(lo.obj, it)
} }
ParameterType.Boolean -> parameterValue.booleanValue?.let { ParameterType.Boolean -> parameterValue.booleanValue?.let {

View File

@@ -6,7 +6,6 @@ import kotlin.reflect.KClass
import kotlin.reflect.KMutableProperty1 import kotlin.reflect.KMutableProperty1
import kotlin.reflect.KVisibility import kotlin.reflect.KVisibility
import kotlin.reflect.full.declaredMemberFunctions import kotlin.reflect.full.declaredMemberFunctions
import kotlin.reflect.full.declaredMemberProperties
import kotlin.reflect.full.findAnnotation import kotlin.reflect.full.findAnnotation
import kotlin.reflect.full.memberProperties import kotlin.reflect.full.memberProperties
@@ -80,12 +79,15 @@ annotation class ColorParameter(val label: String, val order: Int = Integer.MAX_
*/ */
@Target(AnnotationTarget.PROPERTY) @Target(AnnotationTarget.PROPERTY)
@Retention(AnnotationRetention.RUNTIME) @Retention(AnnotationRetention.RUNTIME)
annotation class Vector2Parameter( annotation class XYParameter(
val label: String, val label: String,
val minX: Double = -1.0, val minX: Double = -1.0,
val minY: Double = -1.0, val minY: Double = -1.0,
val maxX: Double = 1.0, val maxX: Double = 1.0,
val maxY: 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 val order: Int = Integer.MAX_VALUE
) )
@@ -107,7 +109,7 @@ enum class ParameterType(val annotationClass: KClass<out Annotation>) {
Action(ActionParameter::class), Action(ActionParameter::class),
Text(TextParameter::class), Text(TextParameter::class),
Color(ColorParameter::class), Color(ColorParameter::class),
Vector2(Vector2Parameter::class) XY(XYParameter::class)
; ;
companion object { companion object {
@@ -128,6 +130,7 @@ enum class ParameterType(val annotationClass: KClass<out Annotation>) {
* @property doubleRange a floating point based range in case [DoubleParameter] is used * @property doubleRange a floating point based range in case [DoubleParameter] is used
* @property intRange an integer range in case [IntParameter] 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 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 * @property order a hint for where in the ui this parameter is placed, lower value means higher priority
*/ */
class Parameter( class Parameter(
@@ -139,6 +142,8 @@ class Parameter(
val vectorRange: Pair<Vector2, Vector2>?, val vectorRange: Pair<Vector2, Vector2>?,
val intRange: IntRange?, val intRange: IntRange?,
val precision: Int?, val precision: Int?,
val keyboardIncrement: Double?,
val showAngle: Boolean?,
val order: Int) val order: Int)
/** /**
@@ -159,6 +164,8 @@ fun Any.listParameters(): List<Parameter> {
var precision: Int? = null var precision: Int? = null
var type: ParameterType? = null var type: ParameterType? = null
var vectorRange = Pair(Vector2(-1.0, -1.0), Vector2(1.0, 1.0)) var vectorRange = Pair(Vector2(-1.0, -1.0), Vector2(1.0, 1.0))
var keyboardIncrement: Double? = null
var showAngle: Boolean? = null
annotations.forEach { annotations.forEach {
type = ParameterType.forParameterAnnotationClass(it) type = ParameterType.forParameterAnnotationClass(it)
@@ -186,10 +193,13 @@ fun Any.listParameters(): List<Parameter> {
label = it.label label = it.label
order = it.order order = it.order
} }
is Vector2Parameter -> { is XYParameter -> {
label = it.label label = it.label
order = it.order order = it.order
vectorRange = Pair(Vector2(it.minX, it.minY), Vector2(it.maxX, it.maxY)) 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<Parameter> {
vectorRange = vectorRange, vectorRange = vectorRange,
intRange = intRange, intRange = intRange,
precision = precision, precision = precision,
keyboardIncrement = keyboardIncrement,
showAngle = showAngle,
order = order order = order
) )
} + this::class.declaredMemberFunctions.filter { } + this::class.declaredMemberFunctions.filter {
@@ -220,6 +232,8 @@ fun Any.listParameters(): List<Parameter> {
intRange = null, intRange = null,
vectorRange = null, vectorRange = null,
precision = null, precision = null,
keyboardIncrement = null,
showAngle = false,
order = order order = order
) )
}).sortedBy { it.order } }).sortedBy { it.order }