2019-08-09 18:36:12 +00:00
|
|
|
package net.shadowfacts.asmr.ui
|
|
|
|
|
|
|
|
import net.shadowfacts.asmr.program.ProgramBlock
|
|
|
|
import net.shadowfacts.cacao.geometry.Point
|
|
|
|
import net.shadowfacts.cacao.util.Color
|
|
|
|
import net.shadowfacts.cacao.util.MouseButton
|
|
|
|
import net.shadowfacts.cacao.view.Label
|
|
|
|
import net.shadowfacts.cacao.view.View
|
|
|
|
import net.shadowfacts.kiwidsl.dsl
|
|
|
|
import no.birkett.kiwi.Constraint
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author shadowfacts
|
|
|
|
*/
|
|
|
|
class ProgramBlockView(val block: ProgramBlock): View() {
|
|
|
|
|
|
|
|
var xConstraint: Constraint? = null
|
|
|
|
var yConstraint: Constraint? = null
|
|
|
|
|
|
|
|
override fun wasAdded() {
|
|
|
|
super.wasAdded()
|
|
|
|
|
|
|
|
respondsToDragging = true
|
|
|
|
|
|
|
|
backgroundColor = Color.BLACK
|
2019-08-09 19:23:48 +00:00
|
|
|
zIndex = 10.0
|
2019-08-09 18:36:12 +00:00
|
|
|
|
|
|
|
val title = addSubview(Label(block.javaClass.simpleName))
|
|
|
|
|
|
|
|
solver.dsl {
|
|
|
|
widthAnchor equalTo (title.widthAnchor + 8)
|
|
|
|
heightAnchor equalTo (title.heightAnchor + 8)
|
|
|
|
title.centerXAnchor equalTo centerXAnchor
|
|
|
|
title.centerYAnchor equalTo centerYAnchor
|
|
|
|
}
|
|
|
|
|
|
|
|
updateDraggingConstraints()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun mouseDragged(startPoint: Point, delta: Point, mouseButton: MouseButton): Boolean {
|
|
|
|
block.position += delta
|
|
|
|
updateDraggingConstraints()
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun updateDraggingConstraints() {
|
|
|
|
if (xConstraint != null) solver.removeConstraint(xConstraint)
|
|
|
|
if (yConstraint != null) solver.removeConstraint(yConstraint)
|
|
|
|
solver.dsl {
|
|
|
|
xConstraint = (leftAnchor equalTo superview!!.leftAnchor + block.position.x)
|
|
|
|
yConstraint = (topAnchor equalTo superview!!.topAnchor + block.position.y)
|
|
|
|
}
|
|
|
|
window!!.layout()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|