Class ClickHelper

An aggregate helper class for widgets that can be clicked.

Keeps its current click state as well as its last click state, last pointer position and whether the last click state change resulted in an actual click.

Hierarchy (view full)

Constructors

Properties

clickState: ClickState = ClickState.Released

The current click state

clickStateChanged: boolean = false

Did the last click event handle result in a click state change?

lastClickState: ClickState = ClickState.Released

Last click state

pointerButton: number = 0

Which pointer button should count as a click? Left button by default

pointerPos: null | [number, number] = null

Last pointer position in normalised coordinates ([0,0] to [1,1]). If there is no last pointer position, such as after a leave event, this will be null. If pointer position was outside box, it will be beyond the [0,0] to [1,1] range.

startingPointerPos: null | [number, number] = null

Like ClickHelper#pointerPos, but only updated when a hold state begins.

Useful for implementing draggable widgets.

wasClick: boolean = false

Did the last click state change result in a click?

widget: Widget

Methods

  • Normalise pointer coordinates inside a rectangle

    Parameters

    • pX: number

      Pointer X coordinate, in pixels

    • pY: number

      Pointer Y coordinate, in pixels

    • rLeft: number

      Rectangle's left coordinate, in pixels

    • rRight: number

      Rectangle's right coordinate, in pixels

    • rTop: number

      Rectangle's top coordinate, in pixels

    • rBottom: number

      Rectangle's bottom coordinate, in pixels

    Returns [number, number]

    Returns normalised coordinates

  • Check if a normalised point is inside a rectangle.

    Since the coordinates are normalised, you don't have to define the coordinates of the rectangle, which may seem counterintuitive.

    Parameters

    • pX: number

      Pointer X coordinate, normalised

    • pY: number

      Pointer Y coordinate, normalised

    Returns boolean

    Returns true if [pX, pY] is inside the rectangle, else, false

  • Check if a point, in pixels, is inside a rectangle.

    Parameters

    • pX: number

      Pointer X coordinate, in pixels

    • pY: number

      Pointer Y coordinate, in pixels

    • rLeft: number

      Rectangle's left coordinate, in pixels

    • rRight: number

      Rectangle's right coordinate, in pixels

    • rTop: number

      Rectangle's top coordinate, in pixels

    • rBottom: number

      Rectangle's bottom coordinate, in pixels

    Returns boolean

    Returns true if [pX, pY] is inside the rectangle, else, false

  • Reset the click helper to its default state, except for the clickStateChanged flag, which is set to true. Only call this if absolutely necessary, such as when the owner Widget is re-activated (this way, hover states don't linger when a Widget is disabled).

    You may be looking for BaseClickHelper#doneProcessing instead.

    Returns void