73 lines
2.0 KiB
Kotlin
73 lines
2.0 KiB
Kotlin
package net.shadowfacts.asmr.ui
|
|
|
|
import net.shadowfacts.asmr.program.ExecutableBlock
|
|
import net.shadowfacts.asmr.program.Program
|
|
import net.shadowfacts.asmr.program.ProgramBlock
|
|
import net.shadowfacts.cacao.geometry.Point
|
|
import net.shadowfacts.cacao.util.Color
|
|
import net.shadowfacts.cacao.util.RenderHelper
|
|
import net.shadowfacts.cacao.view.View
|
|
|
|
/**
|
|
* @author shadowfacts
|
|
*/
|
|
class ProgramCanvasView(val program: Program): View() {
|
|
|
|
lateinit var blocks: Map<ProgramBlock, ProgramBlockView>
|
|
|
|
override fun wasAdded() {
|
|
super.wasAdded()
|
|
|
|
zIndex = 5.0
|
|
|
|
blocks = program.blocks.associateWith { ProgramBlockView(it) }
|
|
blocks.values.forEach {
|
|
addSubview(it)
|
|
}
|
|
}
|
|
|
|
override fun drawContent(mouse: Point, delta: Float) {
|
|
super.drawContent(mouse, delta)
|
|
|
|
|
|
for ((block, view) in blocks) {
|
|
(block as? ExecutableBlock)?.executionFlow?.next?.let { next ->
|
|
blocks[next]?.let { nextView ->
|
|
val outgoing = view.outgoingExeuction!!
|
|
val incoming = nextView.incomingExecution!!
|
|
|
|
val start = outgoing.convert(outgoing.bounds.center, to = this)
|
|
val end = incoming.convert(outgoing.bounds.center, to = this)
|
|
|
|
RenderHelper.drawLine(start, end, zIndex, 5f, Color.GREEN)
|
|
}
|
|
}
|
|
|
|
for (input in block.inputs) {
|
|
if (input.source == null) continue
|
|
val source = input.source!!
|
|
|
|
blocks[source.block]?.let { sourceView ->
|
|
view.inputViews[input]?.let { inputView ->
|
|
sourceView.outputViews[source]?.let { outputView ->
|
|
val start = inputView.convert(inputView.bounds.center, to = this)
|
|
val end = outputView.convert(outputView.bounds.center, to = this)
|
|
|
|
RenderHelper.drawLine(start, end, zIndex, 5f, Color.RED)
|
|
}
|
|
}
|
|
}
|
|
|
|
// val start = block.position
|
|
// val sourcePosition = source.block.position
|
|
// val end = Point(sourcePosition.x + blocks[source.block]!!.bounds.width, sourcePosition.y)
|
|
|
|
// val inputView = view.inputViews[input]
|
|
// val outputView =
|
|
//
|
|
// RenderHelper.drawLine(start, end, zIndex, 5f, Color.RED)
|
|
}
|
|
}
|
|
}
|
|
|
|
} |