java.lang.Object
io.github.thecsdev.tcdcommons.api.client.gui.util.input.MouseDragHelper

public abstract class MouseDragHelper extends Object
A helper Class that helps TElements 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 Integers.

See Also:
  • Field Details

    • mouseDragX

      protected double mouseDragX
    • mouseDragY

      protected double mouseDragY
  • Constructor Details

    • MouseDragHelper

      public MouseDragHelper()
  • Method Details

    • onMouseDrag

      public final boolean onMouseDrag(Point2D mouseDelta)
      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 by onMouseDrag(double, double) when there's sufficient mouseDragX or mouseDragY.
    • snapToParentBounds

      public static boolean snapToParentBounds(TElement element) throws NullPointerException
      Checks if the given TElement is outside of its TParentElement bounds, and if it it, it will get snapped back in.
      Parameters:
      element - The target TElement.
      Returns:
      True if the given TElement was outside of its parent's bounds.
      Throws:
      NullPointerException