Class MouseDragHelper
java.lang.Object
io.github.thecsdev.tcdcommons.api.client.gui.util.input.MouseDragHelper
A helper
Class
that helps TElement
s implement
their own mouse-drag behaviors that require tracking mouse movement.
The main reason for this Class
is that mouse movement is tracked
as a Double
, whereas the Minecraft GUI coordinate system uses Integer
s.
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
apply
(int deltaX, int deltaY) Invoked automatically byonMouseDrag(double, double)
when there's sufficientmouseDragX
ormouseDragY
.final void
clear()
Invoke this when the mouse stops dragging.final boolean
onMouseDrag
(double deltaX, double deltaY) Call this whenever the mouse drag event takes place.final boolean
onMouseDrag
(Point2D mouseDelta) Call this whenever the mouse drag event takes place.static boolean
snapToParentBounds
(TElement element) Checks if the givenTElement
is outside of itsTParentElement
bounds, and if it it, it will get snapped back in.
-
Field Details
-
mouseDragX
protected double mouseDragX -
mouseDragY
protected double mouseDragY
-
-
Constructor Details
-
MouseDragHelper
public MouseDragHelper()
-
-
Method Details
-
onMouseDrag
Call this whenever the mouse drag event takes place. -
onMouseDrag
public final boolean onMouseDrag(double deltaX, double deltaY) Call this whenever the mouse drag event takes place. -
clear
public final void clear()Invoke this when the mouse stops dragging. -
apply
protected abstract void apply(int deltaX, int deltaY) Invoked automatically byonMouseDrag(double, double)
when there's sufficientmouseDragX
ormouseDragY
. -
snapToParentBounds
Checks if the givenTElement
is outside of itsTParentElement
bounds, and if it it, it will get snapped back in.- Parameters:
element
- The targetTElement
.- Returns:
- True if the given
TElement
was outside of its parent's bounds. - Throws:
NullPointerException
-