diff --git a/build.gradle b/build.gradle index ecfc491e..3b1d902a 100644 --- a/build.gradle +++ b/build.gradle @@ -49,6 +49,7 @@ allprojects { repositories { mavenCentral() + mavenLocal() jcenter() maven { url = "https://dl.bintray.com/openrndr/openrndr" @@ -112,4 +113,4 @@ allprojects { includeEngines 'spek2' } } -} \ No newline at end of file +} diff --git a/orx-gui/src/main/kotlin/Gui.kt b/orx-gui/src/main/kotlin/Gui.kt index 093a2b2e..3ecda134 100644 --- a/orx-gui/src/main/kotlin/Gui.kt +++ b/orx-gui/src/main/kotlin/Gui.kt @@ -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 "xy-pad") { + this.width = 175.px + this.height = 175.px + } } styleSheet(has class_ "randomize-strong") { @@ -406,6 +412,28 @@ class GUI : Extension { } } } + + ParameterType.XY -> { + xyPad { + minX = parameter.vectorRange!!.first.x + minY = parameter.vectorRange!!.first.y + maxX = parameter.vectorRange!!.second.x + maxY = parameter.vectorRange!!.second.y + precision = parameter.precision!! + showVector = parameter.showVector!! + invertY = parameter.invertY!! + + events.valueChanged.subscribe { + setAndPersist( + compartment.label, + parameter.property as KMutableProperty1, + obj, + it.newValue + ) + onChangeListener?.invoke(parameter.property!!.name, it.newValue) + } + } + } } } @@ -423,6 +451,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 +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.XY -> ParameterValue(vectorValue = k.property.qget(lo.obj) as Vector2) }) }) } @@ -476,6 +506,9 @@ class GUI : Extension { ParameterType.Color -> parameterValue.colorValue?.let { parameter.property.qset(lo.obj, it) } + ParameterType.XY -> parameterValue.vectorValue?.let { + parameter.property.qset(lo.obj, it) + } ParameterType.Boolean -> parameterValue.booleanValue?.let { parameter.property.qset(lo.obj, it) } @@ -505,6 +538,11 @@ class GUI : Extension { ParameterType.Color -> { (control as ColorpickerButton).color = (parameter.property as KMutableProperty1).get(labeledObject.obj) } + + ParameterType.XY -> { + (control as XYPad).value = (parameter.property as KMutableProperty1).get(labeledObject.obj) + } + ParameterType.Boolean -> { (control as Toggle).value = (parameter.property as KMutableProperty1).get(labeledObject.obj) } @@ -614,4 +652,4 @@ class GUI : Extension { fun T.addTo(gui: GUI, label:String? = this.title()): T { gui.add(this, label) return this -} \ No newline at end of file +} diff --git a/orx-parameters/src/main/kotlin/Annotations.kt b/orx-parameters/src/main/kotlin/Annotations.kt index 5353647e..b20cc680 100644 --- a/orx-parameters/src/main/kotlin/Annotations.kt +++ b/orx-parameters/src/main/kotlin/Annotations.kt @@ -1,11 +1,11 @@ package org.openrndr.extra.parameters +import org.openrndr.math.Vector2 import kotlin.reflect.KCallable 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 @@ -71,6 +71,28 @@ 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 XYParameter( + val label: String, + val minX: Double = -1.0, + val maxX: Double = 1.0, + val minY: Double = -1.0, + val maxY: Double = 1.0, + val precision: Int = 1, + val showVector: Boolean = false, + val invertY: Boolean = true, + val order: Int = Integer.MAX_VALUE +) + + + /** * ActionParameter annotation for functions without arguments * @property label a short description of the parameter @@ -86,7 +108,8 @@ enum class ParameterType(val annotationClass: KClass) { Boolean(BooleanParameter::class), Action(ActionParameter::class), Text(TextParameter::class), - Color(ColorParameter::class) + Color(ColorParameter::class), + XY(XYParameter::class) ; companion object { @@ -107,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 invertY should the y-axis of [XYParameter] be inverted? * @property order a hint for where in the ui this parameter is placed, lower value means higher priority */ class Parameter( @@ -115,8 +139,11 @@ class Parameter( val function: KCallable?, val label: String, val doubleRange: ClosedRange?, + val vectorRange: Pair?, val intRange: IntRange?, val precision: Int?, + val invertY: Boolean?, + val showVector: Boolean?, val order: Int) /** @@ -136,6 +163,9 @@ fun Any.listParameters(): List { var label = "" var precision: Int? = null var type: ParameterType? = null + var vectorRange = Pair(Vector2(-1.0, -1.0), Vector2(1.0, 1.0)) + var invertY: Boolean? = null + var showVector: Boolean? = null annotations.forEach { type = ParameterType.forParameterAnnotationClass(it) @@ -163,6 +193,14 @@ fun Any.listParameters(): List { label = it.label order = it.order } + is XYParameter -> { + label = it.label + order = it.order + vectorRange = Pair(Vector2(it.minX, it.minY), Vector2(it.maxX, it.maxY)) + precision = it.precision + invertY = it.invertY + showVector = it.showVector + } } } Parameter( @@ -171,8 +209,11 @@ fun Any.listParameters(): List { function = null, label = label, doubleRange = doubleRange, + vectorRange = vectorRange, intRange = intRange, precision = precision, + showVector = showVector, + invertY = invertY, order = order ) } + this::class.declaredMemberFunctions.filter { @@ -189,7 +230,10 @@ fun Any.listParameters(): List { label = label, doubleRange = null, intRange = null, + vectorRange = null, precision = null, + showVector = null, + invertY = null, order = order ) }).sortedBy { it.order }