diff --git a/lib/src/main/kotlin/com/github/mnemotechnician/mkui/windows/Window.kt b/lib/src/main/kotlin/com/github/mnemotechnician/mkui/windows/Window.kt index 859d3cf..8f0de24 100644 --- a/lib/src/main/kotlin/com/github/mnemotechnician/mkui/windows/Window.kt +++ b/lib/src/main/kotlin/com/github/mnemotechnician/mkui/windows/Window.kt @@ -17,6 +17,10 @@ abstract class Window { var isCollapsed = false internal set + /** Whether the window is being dragged by the user right now */ + var isDragging = false + internal set + /** Name of this window displayed in the top bar */ open var name = "unnamed window" diff --git a/lib/src/main/kotlin/com/github/mnemotechnician/mkui/windows/WindowManager.kt b/lib/src/main/kotlin/com/github/mnemotechnician/mkui/windows/WindowManager.kt index 6a67fe1..28ffbc7 100644 --- a/lib/src/main/kotlin/com/github/mnemotechnician/mkui/windows/WindowManager.kt +++ b/lib/src/main/kotlin/com/github/mnemotechnician/mkui/windows/WindowManager.kt @@ -4,6 +4,7 @@ import arc.* import arc.math.* import arc.util.* import arc.struct.* +import arc.input.* import arc.scene.event.* import arc.scene.ui.* import arc.scene.ui.layout.* @@ -38,6 +39,9 @@ object WindowManager { Mathf.clamp(pos.y, root.getPrefHeight() / 2, windowGroup.height - root.getPrefHeight() / 2) ); + root.color.a = if (it.isDragging) 0.5f else 1f + it.table.setSize(it.table.prefWidth, it.table.prefHeight) + it.onUpdate() } } @@ -63,12 +67,28 @@ object WindowManager { window.onToggle(it) } - dragged { x, y -> - val oldPos = window.rootTable.localToParentCoordinates(Tmp.v1.set(x, y)) - window.rootTable.setPosition(oldPos.x, oldPos.y) + //making it draggable + addListener(object : InputListener() { + var dragx = 0f + var dragy = 0f; - window.onDrag() - } + override fun touchDown(event: InputEvent, x: Float, y: Float, pointer: Int, button: KeyCode): Boolean { + dragx = x; dragy = y; + window.isDragging = true; + return true; + } + + override fun touchDragged(event: InputEvent, x: Float, y: Float, pointer: Int) { + val oldPos = window.rootTable.localToParentCoordinates(Tmp.v1.set(x, y)) + window.rootTable.setPosition(oldPos.x, oldPos.y) + + window.onDrag() + } + + override fun touchUp(e: InputEvent, x: Float, y: Float, pointer: Int, button: KeyCode) { + window.isDragging = false; + } + }) }.fillX().marginBottom(5f) row()