Merge branch 'reinvdwoerd-master'

This commit is contained in:
Edwin Jakobs
2020-03-20 00:10:34 +01:00
3 changed files with 87 additions and 4 deletions

View File

@@ -49,6 +49,7 @@ allprojects {
repositories { repositories {
mavenCentral() mavenCentral()
mavenLocal()
jcenter() jcenter()
maven { maven {
url = "https://dl.bintray.com/openrndr/openrndr" url = "https://dl.bintray.com/openrndr/openrndr"

View File

@@ -13,6 +13,7 @@ import org.openrndr.dialogs.saveFileDialog
import org.openrndr.draw.Drawer import org.openrndr.draw.Drawer
import org.openrndr.extra.parameters.* import org.openrndr.extra.parameters.*
import org.openrndr.internal.Driver import org.openrndr.internal.Driver
import org.openrndr.math.Vector2
import org.openrndr.panel.ControlManager import org.openrndr.panel.ControlManager
import org.openrndr.panel.controlManager import org.openrndr.panel.controlManager
import org.openrndr.panel.elements.* import org.openrndr.panel.elements.*
@@ -175,6 +176,11 @@ class GUI : Extension {
descendant(has type "toggle") { descendant(has type "toggle") {
this.width = 175.px this.width = 175.px
} }
descendant(has type "xy-pad") {
this.width = 175.px
this.height = 175.px
}
} }
styleSheet(has class_ "randomize-strong") { 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<Any, Vector2>,
obj,
it.newValue
)
onChangeListener?.invoke(parameter.property!!.name, it.newValue)
}
}
}
} }
} }
@@ -423,6 +451,7 @@ class GUI : Extension {
var intValue: Int? = null, var intValue: Int? = null,
var booleanValue: Boolean? = null, var booleanValue: Boolean? = null,
var colorValue: ColorRGBa? = null, var colorValue: ColorRGBa? = null,
var vectorValue: Vector2? = null,
var textValue: String? = null) var textValue: String? = null)
@@ -442,6 +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.XY -> ParameterValue(vectorValue = k.property.qget(lo.obj) as Vector2)
}) })
}) })
} }
@@ -476,6 +506,9 @@ 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.XY -> parameterValue.vectorValue?.let {
parameter.property.qset(lo.obj, it)
}
ParameterType.Boolean -> parameterValue.booleanValue?.let { ParameterType.Boolean -> parameterValue.booleanValue?.let {
parameter.property.qset(lo.obj, it) parameter.property.qset(lo.obj, it)
} }
@@ -505,6 +538,11 @@ class GUI : Extension {
ParameterType.Color -> { ParameterType.Color -> {
(control as ColorpickerButton).color = (parameter.property as KMutableProperty1<Any, ColorRGBa>).get(labeledObject.obj) (control as ColorpickerButton).color = (parameter.property as KMutableProperty1<Any, ColorRGBa>).get(labeledObject.obj)
} }
ParameterType.XY -> {
(control as XYPad).value = (parameter.property as KMutableProperty1<Any, Vector2>).get(labeledObject.obj)
}
ParameterType.Boolean -> { ParameterType.Boolean -> {
(control as Toggle).value = (parameter.property as KMutableProperty1<Any, Boolean>).get(labeledObject.obj) (control as Toggle).value = (parameter.property as KMutableProperty1<Any, Boolean>).get(labeledObject.obj)
} }

View File

@@ -1,11 +1,11 @@
package org.openrndr.extra.parameters package org.openrndr.extra.parameters
import org.openrndr.math.Vector2
import kotlin.reflect.KCallable import kotlin.reflect.KCallable
import kotlin.reflect.KClass 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
@@ -71,6 +71,28 @@ annotation class TextParameter(val label: String, val order: Int = Integer.MAX_V
@Retention(AnnotationRetention.RUNTIME) @Retention(AnnotationRetention.RUNTIME)
annotation class ColorParameter(val label: String, val order: Int = Integer.MAX_VALUE) 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 * ActionParameter annotation for functions without arguments
* @property label a short description of the parameter * @property label a short description of the parameter
@@ -86,7 +108,8 @@ enum class ParameterType(val annotationClass: KClass<out Annotation>) {
Boolean(BooleanParameter::class), Boolean(BooleanParameter::class),
Action(ActionParameter::class), Action(ActionParameter::class),
Text(TextParameter::class), Text(TextParameter::class),
Color(ColorParameter::class) Color(ColorParameter::class),
XY(XYParameter::class)
; ;
companion object { companion object {
@@ -107,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 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 * @property order a hint for where in the ui this parameter is placed, lower value means higher priority
*/ */
class Parameter( class Parameter(
@@ -115,8 +139,11 @@ class Parameter(
val function: KCallable<Unit>?, val function: KCallable<Unit>?,
val label: String, val label: String,
val doubleRange: ClosedRange<Double>?, val doubleRange: ClosedRange<Double>?,
val vectorRange: Pair<Vector2, Vector2>?,
val intRange: IntRange?, val intRange: IntRange?,
val precision: Int?, val precision: Int?,
val invertY: Boolean?,
val showVector: Boolean?,
val order: Int) val order: Int)
/** /**
@@ -136,6 +163,9 @@ fun Any.listParameters(): List<Parameter> {
var label = "" var label = ""
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 invertY: Boolean? = null
var showVector: Boolean? = null
annotations.forEach { annotations.forEach {
type = ParameterType.forParameterAnnotationClass(it) type = ParameterType.forParameterAnnotationClass(it)
@@ -163,6 +193,14 @@ fun Any.listParameters(): List<Parameter> {
label = it.label label = it.label
order = it.order 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( Parameter(
@@ -171,8 +209,11 @@ fun Any.listParameters(): List<Parameter> {
function = null, function = null,
label = label, label = label,
doubleRange = doubleRange, doubleRange = doubleRange,
vectorRange = vectorRange,
intRange = intRange, intRange = intRange,
precision = precision, precision = precision,
showVector = showVector,
invertY = invertY,
order = order order = order
) )
} + this::class.declaredMemberFunctions.filter { } + this::class.declaredMemberFunctions.filter {
@@ -189,7 +230,10 @@ fun Any.listParameters(): List<Parameter> {
label = label, label = label,
doubleRange = null, doubleRange = null,
intRange = null, intRange = null,
vectorRange = null,
precision = null, precision = null,
showVector = null,
invertY = null,
order = order order = order
) )
}).sortedBy { it.order } }).sortedBy { it.order }