Added XYParameter demo, made XYPad draw it's label
This commit is contained in:
committed by
Edwin Jakobs
parent
95d06d22e6
commit
8cc9ddedad
32
orx-gui/src/demo/kotlin/DemoXYParameter.kt
Normal file
32
orx-gui/src/demo/kotlin/DemoXYParameter.kt
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import org.openrndr.application
|
||||||
|
import org.openrndr.extra.gui.GUI
|
||||||
|
import org.openrndr.extra.parameters.ActionParameter
|
||||||
|
import org.openrndr.extra.parameters.Description
|
||||||
|
import org.openrndr.extra.parameters.XYParameter
|
||||||
|
import org.openrndr.math.Vector2
|
||||||
|
|
||||||
|
fun main() = application {
|
||||||
|
configure {
|
||||||
|
width = 800
|
||||||
|
height = 800
|
||||||
|
}
|
||||||
|
|
||||||
|
program {
|
||||||
|
val gui = GUI()
|
||||||
|
|
||||||
|
val settings = @Description("Vector parameter!") object {
|
||||||
|
@XYParameter("Position", 0.0, 800.0, 0.0, 800.0,
|
||||||
|
precision = 2,
|
||||||
|
invertY = true,
|
||||||
|
showVector = true)
|
||||||
|
var position: Vector2 = Vector2(0.0,0.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.add(settings)
|
||||||
|
|
||||||
|
extend(gui)
|
||||||
|
extend {
|
||||||
|
drawer.circle(settings.position, 50.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -463,6 +463,7 @@ class GUI : Extension {
|
|||||||
precision = parameter.precision!!
|
precision = parameter.precision!!
|
||||||
showVector = parameter.showVector!!
|
showVector = parameter.showVector!!
|
||||||
invertY = parameter.invertY!!
|
invertY = parameter.invertY!!
|
||||||
|
label = parameter.label
|
||||||
|
|
||||||
events.valueChanged.listen {
|
events.valueChanged.listen {
|
||||||
setAndPersist(
|
setAndPersist(
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ class XYPad : Element(ElementType("xy-pad")) {
|
|||||||
var maxX = 1.0
|
var maxX = 1.0
|
||||||
var maxY = 1.0
|
var maxY = 1.0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The label
|
||||||
|
*/
|
||||||
|
var label: String? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The precision of the control, default is 2
|
* The precision of the control, default is 2
|
||||||
*/
|
*/
|
||||||
@@ -198,12 +203,13 @@ class XYPad : Element(ElementType("xy-pad")) {
|
|||||||
drawer.stroke = ColorRGBa.WHITE
|
drawer.stroke = ColorRGBa.WHITE
|
||||||
drawer.circle(ballPosition, 8.0)
|
drawer.circle(ballPosition, 8.0)
|
||||||
|
|
||||||
val label = "${String.format("%.0${precision}f", value.x)}, ${String.format("%.0${precision}f", value.y)}"
|
val valueLabel = "${String.format("%.0${precision}f", value.x)}, ${String.format("%.0${precision}f", value.y)}"
|
||||||
|
|
||||||
(root() as? Body)?.controlManager?.fontManager?.let {
|
(root() as? Body)?.controlManager?.fontManager?.let {
|
||||||
val font = it.font(computedStyle)
|
val font = it.font(computedStyle)
|
||||||
val writer = Writer(drawer)
|
val writer = Writer(drawer)
|
||||||
drawer.fontMap = (font)
|
drawer.fontMap = (font)
|
||||||
val textWidth = writer.textWidth(label)
|
val textWidth = writer.textWidth(valueLabel)
|
||||||
val textHeight = font.ascenderLength
|
val textHeight = font.ascenderLength
|
||||||
|
|
||||||
drawer.fill = ((computedStyle.color as? Color.RGBa)?.color ?: ColorRGBa.WHITE).opacify(
|
drawer.fill = ((computedStyle.color as? Color.RGBa)?.color ?: ColorRGBa.WHITE).opacify(
|
||||||
@@ -211,7 +217,11 @@ class XYPad : Element(ElementType("xy-pad")) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
drawer.text(label, Vector2(layout.screenWidth - textWidth - 4.0, layout.screenHeight - textHeight + 6.0))
|
if (label != null) {
|
||||||
|
drawer.text(label!!, Vector2(0.0, 0.0))
|
||||||
|
}
|
||||||
|
|
||||||
|
drawer.text(valueLabel, Vector2(layout.screenWidth - textWidth - 4.0, layout.screenHeight - textHeight + 6.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
drawer.popStyle()
|
drawer.popStyle()
|
||||||
|
|||||||
Reference in New Issue
Block a user