mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-17 00:56:07 +09:00
improved slider mouse op
This commit is contained in:
@@ -451,6 +451,8 @@ class UIItemControlPaletteBaloon(val parent: UIKeyboardControlPanel, initialX: I
|
|||||||
parent.setControlOf(parent.keycapClicked, selected)
|
parent.setControlOf(parent.keycapClicked, selected)
|
||||||
parent.keycapClicked = -13372
|
parent.keycapClicked = -13372
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mouseDown) mouseLatched = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,11 +89,14 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
|||||||
open val mouseUp: Boolean
|
open val mouseUp: Boolean
|
||||||
get() = itemRelativeMouseX in 0 until width && itemRelativeMouseY in 0 until height
|
get() = itemRelativeMouseX in 0 until width && itemRelativeMouseY in 0 until height
|
||||||
/** If mouse is hovering over it and mouse is down */
|
/** If mouse is hovering over it and mouse is down */
|
||||||
open val mousePushed: Boolean
|
val mousePushed: Boolean
|
||||||
get() = mouseUp && Terrarum.mouseDown
|
get() = mouseUp && Terrarum.mouseDown
|
||||||
|
val mouseDown: Boolean
|
||||||
|
get() = Terrarum.mouseDown
|
||||||
|
|
||||||
|
|
||||||
protected var mouseLatched = Terrarum.mouseDown
|
/** to be used by customised mouse handling */
|
||||||
|
protected var mouseLatched = false
|
||||||
|
|
||||||
/** UI to call (show up) while mouse is up */
|
/** UI to call (show up) while mouse is up */
|
||||||
open var mouseOverCall: UICanvas? = null
|
open var mouseOverCall: UICanvas? = null
|
||||||
@@ -164,7 +167,6 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mouseUp) mouseLatched = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import kotlin.math.roundToInt
|
|||||||
* [-]--|--|--[]--|--[+]
|
* [-]--|--|--[]--|--[+]
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
* Created by minjaesong on 2023-07-14.
|
* Created by minjaesong on 2023-07-14.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -25,7 +27,8 @@ class UIItemHorzSlider(
|
|||||||
val max: Double,
|
val max: Double,
|
||||||
override val width: Int,
|
override val width: Int,
|
||||||
val handleWidth: Int = 12,
|
val handleWidth: Int = 12,
|
||||||
private val backgroundTexture: TextureRegion? = null
|
private val backgroundTexture: TextureRegion? = null,
|
||||||
|
private val disposeTexture: Boolean = false
|
||||||
) : UIItem(parentUI, initialX, initialY) {
|
) : UIItem(parentUI, initialX, initialY) {
|
||||||
|
|
||||||
override val height = 24
|
override val height = 24
|
||||||
@@ -35,7 +38,6 @@ class UIItemHorzSlider(
|
|||||||
private var handlePos = 0.0
|
private var handlePos = 0.0
|
||||||
|
|
||||||
var value: Double = initialValue; private set
|
var value: Double = initialValue; private set
|
||||||
|
|
||||||
var selectionChangeListener: (Double) -> Unit = {}
|
var selectionChangeListener: (Double) -> Unit = {}
|
||||||
|
|
||||||
override fun update(delta: Float) {
|
override fun update(delta: Float) {
|
||||||
@@ -44,15 +46,20 @@ class UIItemHorzSlider(
|
|||||||
mouseOnHandle = itemRelativeMouseX in handlePos.roundToInt() until handlePos.roundToInt() + handleWidth && itemRelativeMouseY in 0 until height
|
mouseOnHandle = itemRelativeMouseX in handlePos.roundToInt() until handlePos.roundToInt() + handleWidth && itemRelativeMouseY in 0 until height
|
||||||
|
|
||||||
// update handle position and value
|
// update handle position and value
|
||||||
if (mouseUp && mousePushed) {
|
if (mouseUp && Terrarum.mouseDown || mouseLatched) {
|
||||||
|
mouseLatched = true
|
||||||
handlePos = (itemRelativeMouseX - handleWidth/2.0).coerceIn(0.0, handleTravelDist.toDouble())
|
handlePos = (itemRelativeMouseX - handleWidth/2.0).coerceIn(0.0, handleTravelDist.toDouble())
|
||||||
value = interpolateLinear(handlePos / handleTravelDist, min, max)
|
value = interpolateLinear(handlePos / handleTravelDist, min, max)
|
||||||
selectionChangeListener(value)
|
selectionChangeListener(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!Terrarum.mouseDown) {
|
||||||
|
mouseLatched = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val troughBorderCol: Color; get() = if (mouseUp) Toolkit.Theme.COL_MOUSE_UP else Toolkit.Theme.COL_INACTIVE
|
val troughBorderCol: Color; get() = if (mouseUp || mouseLatched) Toolkit.Theme.COL_MOUSE_UP else Toolkit.Theme.COL_INACTIVE
|
||||||
val handleCol: Color; get() = if (mouseOnHandle && mousePushed) Toolkit.Theme.COL_SELECTED
|
val handleCol: Color; get() = if (mouseOnHandle && mousePushed || mouseLatched) Toolkit.Theme.COL_SELECTED
|
||||||
else if (mouseOnHandle) Toolkit.Theme.COL_MOUSE_UP else Color.WHITE
|
else if (mouseOnHandle) Toolkit.Theme.COL_MOUSE_UP else Color.WHITE
|
||||||
|
|
||||||
|
|
||||||
@@ -95,6 +102,7 @@ class UIItemHorzSlider(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
|
if (disposeTexture) backgroundTexture?.texture?.tryDispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user