[ad_1]
I seemed up within the library supply code how do Scene2d Actors perceive that they’re hovered, and it appears to work this manner:
-
Button: calling innerClickListener.isOver(), which, actually, checking over or pressed non-public members. Member over is setted when there may be an InputEvent with enter kind (over is true) or exit kind (over is fake) and pointer == -1; -
SelectBox: very same means thatButtondoes. ExceptSelectBoxitself does not haveisOvermethodology. -
Slider: implementing hovering itself, utilizing non-public mouseOver member; It is including to itself InputListener that is observe InputEvent hovering the identical means thatClickListenerdoes, however change the mouseOver member as a substitute of over.
Other UI components both inherit from the Button (e.g. CheckBox), or haven’t any hovering detection potential (and to allow them to’t change the looks when they’re hovered).
Knowing that, I can implement HoverEvent that may set off hovering in that restricted checklist of UI components:
class HoverEvent: InputEvent() {
init {
kind = Type.enter
pointer = -1
}
}
It is change the looks of the weather, nonetheless to un-hover such factor I have to manually transfer mouse to it after which exterior of it. Or write some UnhoverEvent. This method, although it appears to me probably the most appropriate one, in the long run seems to be inconvenient and ultimately impractical.
So, as a workaround, I wrote extension operate to the Actor that transfer cursor place to Actor‘s middle:
enjoyable Actor.moveCursorToIt() {
val stageCoords = localToStageCoordinates(Vector2())
val screenCoords = stage.stageToScreenCoordinates(stageCoords)
Gdx.enter.setCursorPosition(
(screenCoords.x + width / 2).toInt(),
(screenCoords.y - peak / 2).toInt()
)
}
[ad_2]