Cacao: Misc things
This commit is contained in:
parent
81ce590231
commit
2774cabfcc
|
@ -57,6 +57,16 @@ open class CacaoHandledScreen<Handler: ScreenHandler>(
|
|||
}
|
||||
}
|
||||
|
||||
override fun onClose() {
|
||||
super.onClose()
|
||||
|
||||
windows.forEach {
|
||||
// todo: VC callbacks
|
||||
|
||||
it.firstResponder = null
|
||||
}
|
||||
}
|
||||
|
||||
override fun drawBackground(matrixStack: MatrixStack, delta: Float, mouseX: Int, mouseY: Int) {
|
||||
renderBackground(matrixStack)
|
||||
}
|
||||
|
@ -95,6 +105,38 @@ open class CacaoHandledScreen<Handler: ScreenHandler>(
|
|||
}
|
||||
}
|
||||
|
||||
override fun mouseDragged(mouseX: Double, mouseY: Double, button: Int, deltaX: Double, deltaY: Double): Boolean {
|
||||
val window = windows.lastOrNull()
|
||||
val startPoint = Point(mouseX, mouseY)
|
||||
val delta = Point(deltaX, deltaY)
|
||||
val result = window?.mouseDragged(startPoint, delta, MouseButton.fromMC(button))
|
||||
return if (result == true) {
|
||||
true
|
||||
} else if (window is ScreenHandlerWindow) {
|
||||
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
override fun mouseReleased(mouseX: Double, mouseY: Double, button: Int): Boolean {
|
||||
val window = windows.lastOrNull()
|
||||
val result = window?.mouseReleased(Point(mouseX, mouseY), MouseButton.fromMC(button))
|
||||
return if (result == true) {
|
||||
true
|
||||
} else if (window is ScreenHandlerWindow) {
|
||||
super.mouseReleased(mouseX, mouseY, button)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
override fun mouseScrolled(mouseX: Double, mouseY: Double, amount: Double): Boolean {
|
||||
val window = windows.lastOrNull()
|
||||
val result = window?.mouseScrolled(Point(mouseX, mouseY), amount)
|
||||
return result == true
|
||||
}
|
||||
|
||||
override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
|
||||
val modifiersSet by lazy { KeyModifiers(modifiers) }
|
||||
if (findResponder { it.keyPressed(keyCode, modifiersSet) }) {
|
||||
|
|
|
@ -119,6 +119,12 @@ open class CacaoScreen(title: Text = LiteralText("CacaoScreen")): Screen(title),
|
|||
return result == true
|
||||
}
|
||||
|
||||
override fun mouseScrolled(mouseX: Double, mouseY: Double, amount: Double): Boolean {
|
||||
val window = windows.lastOrNull()
|
||||
val result = window?.mouseScrolled(Point(mouseX, mouseY), amount)
|
||||
return result == true
|
||||
}
|
||||
|
||||
override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
|
||||
val modifiersSet by lazy { KeyModifiers(modifiers) }
|
||||
if (findResponder { it.keyPressed(keyCode, modifiersSet) }) {
|
||||
|
|
|
@ -13,6 +13,7 @@ import no.birkett.kiwi.Solver
|
|||
import java.lang.RuntimeException
|
||||
import java.util.*
|
||||
import kotlin.collections.HashSet
|
||||
import kotlin.math.floor
|
||||
|
||||
/**
|
||||
* The base Cacao View class. Provides layout anchors, properties, and helper methods.
|
||||
|
@ -368,7 +369,7 @@ open class View(): Responder {
|
|||
*/
|
||||
open fun draw(matrixStack: MatrixStack, mouse: Point, delta: Float) {
|
||||
RenderHelper.pushMatrix()
|
||||
RenderHelper.translate(frame.left, frame.top)
|
||||
RenderHelper.translate(floor(frame.left), floor(frame.top))
|
||||
|
||||
RenderHelper.fill(matrixStack, bounds, backgroundColor)
|
||||
|
||||
|
@ -446,6 +447,23 @@ open class View(): Responder {
|
|||
return false
|
||||
}
|
||||
|
||||
open fun mouseDragEnded(point: Point, mouseButton: MouseButton) {
|
||||
val view = subviewsAtPoint(point).maxByOrNull(View::zIndex)
|
||||
if (view != null) {
|
||||
val pointInView = convert(point, to = view)
|
||||
return view.mouseDragEnded(pointInView, mouseButton)
|
||||
}
|
||||
}
|
||||
|
||||
open fun mouseScrolled(point: Point, amount: Double): Boolean {
|
||||
val view = subviewsAtPoint(point).maxByOrNull(View::zIndex)
|
||||
if (view != null) {
|
||||
val pointInView = convert(point, to = view)
|
||||
return view.mouseScrolled(pointInView, amount)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given point in this view's coordinate system to the coordinate system of another view or the window.
|
||||
*
|
||||
|
|
|
@ -11,6 +11,7 @@ import net.shadowfacts.cacao.util.MouseButton
|
|||
import net.shadowfacts.cacao.util.RenderHelper
|
||||
import net.shadowfacts.cacao.view.View
|
||||
import net.shadowfacts.phycon.mixin.client.TextFieldWidgetAccessor
|
||||
import org.lwjgl.glfw.GLFW
|
||||
|
||||
/**
|
||||
* An abstract text field class. Cannot be constructed directly, use for creating other text fields with more specific
|
||||
|
@ -159,7 +160,7 @@ abstract class AbstractTextField<Impl: AbstractTextField<Impl>>(
|
|||
@Suppress("UNCHECKED_CAST")
|
||||
handler?.invoke(this as Impl)
|
||||
}
|
||||
return result
|
||||
return result || (isFirstResponder && keyCode != GLFW.GLFW_KEY_ESCAPE)
|
||||
}
|
||||
|
||||
// todo: label for the TextFieldWidget?
|
||||
|
|
|
@ -234,7 +234,8 @@ open class Window(
|
|||
fun mouseDragged(startPoint: Point, delta: Point, mouseButton: MouseButton): Boolean {
|
||||
val currentlyDraggedView = this.currentDragReceiver
|
||||
if (currentlyDraggedView != null) {
|
||||
return currentlyDraggedView.mouseDragged(startPoint, delta, mouseButton)
|
||||
val pointInView = viewController.view.convert(startPoint, to = currentlyDraggedView)
|
||||
return currentlyDraggedView.mouseDragged(pointInView, delta, mouseButton)
|
||||
} else if (startPoint in viewController.view.frame) {
|
||||
val startInView =
|
||||
Point(startPoint.x - viewController.view.frame.left, startPoint.y - viewController.view.frame.top)
|
||||
|
@ -246,7 +247,12 @@ open class Window(
|
|||
view = view.subviewsAtPoint(pointInView).maxByOrNull(View::zIndex)
|
||||
}
|
||||
this.currentDragReceiver = view ?: prevView
|
||||
return this.currentDragReceiver?.mouseDragged(startPoint, delta, mouseButton) ?: false
|
||||
return if (this.currentDragReceiver != null) {
|
||||
val pointInView = viewController.view.convert(startPoint, to = this.currentDragReceiver!!)
|
||||
this.currentDragReceiver!!.mouseDragged(pointInView, delta, mouseButton)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -254,10 +260,16 @@ open class Window(
|
|||
fun mouseReleased(point: Point, mouseButton: MouseButton): Boolean {
|
||||
val currentlyDraggedView = this.currentDragReceiver
|
||||
if (currentlyDraggedView != null) {
|
||||
val pointInView = viewController.view.convert(point, to = currentlyDraggedView)
|
||||
currentlyDraggedView.mouseDragEnded(pointInView, mouseButton)
|
||||
this.currentDragReceiver = null
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun mouseScrolled(point: Point, amount: Double): Boolean {
|
||||
return viewController.view.mouseScrolled(point, amount)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue