NDEVR
API Documentation

A joystick that allows the user to move around, reporting the vector of the stick, relative to the center of the joystick. More...

Public Member Functions

 Joystick (QWidget *parent=nullptr)
 Constructs a Joystick widget.
void addButton (Button *button)
 Adds a custom button to the joystick widget.
QRect arrowRect (const Vector< 2, sint04 > &location, const Vector< 2, fltp04 > &center_point, fltp04 radius) const
 Computes the bounding rectangle for an arrow button at the given location.
Vector< 2, fltp04centerPoint () const
 Returns the center point of the joystick in widget coordinates.
bool event (QEvent *event) override
 Processes generic events, including touch events for the joystick.
bool isDragging () const
 Checks whether the joystick knob is currently being dragged.
void joystickButtonPressedSignal (const Vector< 2, fltp04 > &location)
 Emitted when the joystick knob is initially pressed.
void joystickButtonReleasedSignal (const Vector< 2, fltp04 > &location)
 Emitted when the joystick knob is released.
void joystickLocationChangedSignal (const Vector< 2, fltp04 > &location)
 Emitted when the joystick position changes during dragging.
Vector< 2, fltp04knobLocation () const
 Returns the current position of the joystick knob in widget coordinates.
fltp04 knobRadius () const
 Returns the radius of the joystick knob.
QSize minimumSizeHint () const override
 Returns the minimum size hint for the joystick widget.
virtual void mouseMoveEvent (QMouseEvent *ev) override
 Handles mouse move events to update the joystick knob position.
virtual void mousePressEvent (QMouseEvent *ev) override
 Handles mouse press events on the joystick.
virtual void mouseReleaseEvent (QMouseEvent *ev) override
 Handles mouse release events on the joystick.
fltp04 outerRadius () const
 Returns the radius of the outer joystick boundary.
void pressEvent (Vector< 2, fltp04 > mouse_location)
 Simulates a press event at the given location.
void releaseEvent ()
 Simulates a release event, triggering the snap-back animation.
void setBackgroundColor (RGBColor inner, RGBColor outer)
 Sets the gradient colors used to draw the joystick background.
void setDeadzone (fltp08 deadzone)
 Sets the deadzone radius below which joystick input is ignored.
void setDrawDeadzone (bool draw_deadzone)
 Sets whether the deadzone region is visually drawn on the joystick.
void setDrawSensitivity (bool draw_sense)
 Sets whether the sensitivity region is visually drawn on the joystick.
void setJoystickSettingsName (const StringView &name)
 Sets the INI settings name used for persisting joystick settings.
void setKnobColor (RGBColor inner, RGBColor outer)
 Sets the gradient colors used to draw the joystick knob.
void setSettings (const JoystickSettings &mode)
 Applies new joystick settings.
void setSnapBackPercent (float snap_percent)
 Sets the snap-back animation progress percentage.
const JoystickSettingssettings () const
 Returns the current joystick settings.
void setValue (const Vector< 2, fltp04 > &location)
 Programmatically sets the joystick position.
QSize sizeHint () const override
 Returns the preferred size hint for the joystick widget.
float snapBackPercent () const
 Returns the current snap-back animation progress as a percentage.

Private Member Functions

void paintEvent (QPaintEvent *paint_event) override
 Paints the joystick widget including background, knob, and buttons.
void resizeEvent (QResizeEvent *event) override
 Handles resize events to recalculate joystick geometry.

Detailed Description

A joystick that allows the user to move around, reporting the vector of the stick, relative to the center of the joystick.


Definition at line 87 of file Joystick.h.

Constructor & Destructor Documentation

◆ Joystick()

Joystick::Joystick ( QWidget * parent = nullptr)
explicit

Constructs a Joystick widget.

Parameters
[in]parentThe parent widget.

Member Function Documentation

◆ addButton()

void Joystick::addButton ( Button * button)

Adds a custom button to the joystick widget.

Parameters
[in]buttonThe button to add.

◆ arrowRect()

QRect Joystick::arrowRect ( const Vector< 2, sint04 > & location,
const Vector< 2, fltp04 > & center_point,
fltp04 radius ) const

Computes the bounding rectangle for an arrow button at the given location.

Parameters
[in]locationThe grid position of the arrow.
[in]center_pointThe center of the joystick.
[in]radiusThe radius used for positioning the arrow.
Returns
The bounding rectangle for the arrow.

◆ centerPoint()

Vector< 2, fltp04 > Joystick::centerPoint ( ) const

Returns the center point of the joystick in widget coordinates.

Returns
The 2D center point.

◆ event()

bool Joystick::event ( QEvent * event)
override

Processes generic events, including touch events for the joystick.

Parameters
[in]eventThe event to process.
Returns
True if the event was handled.

References event().

Referenced by event(), and resizeEvent().

◆ isDragging()

bool Joystick::isDragging ( ) const

Checks whether the joystick knob is currently being dragged.

Returns
True if the user is actively dragging the knob.

◆ joystickButtonPressedSignal()

void Joystick::joystickButtonPressedSignal ( const Vector< 2, fltp04 > & location)

Emitted when the joystick knob is initially pressed.

Parameters
[in]locationThe normalized joystick position at press time.

◆ joystickButtonReleasedSignal()

void Joystick::joystickButtonReleasedSignal ( const Vector< 2, fltp04 > & location)

Emitted when the joystick knob is released.

Parameters
[in]locationThe normalized joystick position at release time.

◆ joystickLocationChangedSignal()

void Joystick::joystickLocationChangedSignal ( const Vector< 2, fltp04 > & location)

Emitted when the joystick position changes during dragging.

Parameters
[in]locationThe current normalized joystick displacement.

◆ knobLocation()

Vector< 2, fltp04 > Joystick::knobLocation ( ) const

Returns the current position of the joystick knob in widget coordinates.

Returns
The 2D knob location.

◆ knobRadius()

fltp04 Joystick::knobRadius ( ) const

Returns the radius of the joystick knob.

Returns
The knob radius in pixels.

◆ minimumSizeHint()

QSize Joystick::minimumSizeHint ( ) const
override

Returns the minimum size hint for the joystick widget.

Returns
The minimum recommended size.

◆ mouseMoveEvent()

virtual void Joystick::mouseMoveEvent ( QMouseEvent * ev)
overridevirtual

Handles mouse move events to update the joystick knob position.

Parameters
[in]evThe mouse move event.

◆ mousePressEvent()

virtual void Joystick::mousePressEvent ( QMouseEvent * ev)
overridevirtual

Handles mouse press events on the joystick.

Parameters
[in]evThe mouse press event.

◆ mouseReleaseEvent()

virtual void Joystick::mouseReleaseEvent ( QMouseEvent * ev)
overridevirtual

Handles mouse release events on the joystick.

Parameters
[in]evThe mouse release event.

◆ outerRadius()

fltp04 Joystick::outerRadius ( ) const

Returns the radius of the outer joystick boundary.

Returns
The outer radius in pixels.

◆ paintEvent()

void Joystick::paintEvent ( QPaintEvent * paint_event)
overrideprivate

Paints the joystick widget including background, knob, and buttons.

Parameters
[in]paint_eventThe paint event.

◆ pressEvent()

void Joystick::pressEvent ( Vector< 2, fltp04 > mouse_location)

Simulates a press event at the given location.

Parameters
[in]mouse_locationThe location of the press in widget coordinates.

◆ resizeEvent()

void Joystick::resizeEvent ( QResizeEvent * event)
overrideprivate

Handles resize events to recalculate joystick geometry.

Parameters
[in]eventThe resize event.

References event().

◆ setBackgroundColor()

void Joystick::setBackgroundColor ( RGBColor inner,
RGBColor outer )

Sets the gradient colors used to draw the joystick background.

Parameters
[in]innerThe inner color of the background gradient.
[in]outerThe outer color of the background gradient.

◆ setDeadzone()

void Joystick::setDeadzone ( fltp08 deadzone)

Sets the deadzone radius below which joystick input is ignored.

Parameters
[in]deadzoneThe deadzone radius as a fraction of the outer radius.

◆ setDrawDeadzone()

void Joystick::setDrawDeadzone ( bool draw_deadzone)

Sets whether the deadzone region is visually drawn on the joystick.

Parameters
[in]draw_deadzoneTrue to draw the deadzone indicator.

◆ setDrawSensitivity()

void Joystick::setDrawSensitivity ( bool draw_sense)

Sets whether the sensitivity region is visually drawn on the joystick.

Parameters
[in]draw_senseTrue to draw the sensitivity indicator.

◆ setJoystickSettingsName()

void Joystick::setJoystickSettingsName ( const StringView & name)

Sets the INI settings name used for persisting joystick settings.

Parameters
[in]nameThe settings name identifier.

◆ setKnobColor()

void Joystick::setKnobColor ( RGBColor inner,
RGBColor outer )

Sets the gradient colors used to draw the joystick knob.

Parameters
[in]innerThe inner color of the knob gradient.
[in]outerThe outer color of the knob gradient.

◆ setSettings()

void Joystick::setSettings ( const JoystickSettings & mode)

Applies new joystick settings.

Parameters
[in]modeThe settings to apply.

◆ setSnapBackPercent()

void Joystick::setSnapBackPercent ( float snap_percent)

Sets the snap-back animation progress percentage.

Parameters
[in]snap_percentThe snap-back percentage to set.

◆ settings()

const JoystickSettings & Joystick::settings ( ) const
inline

Returns the current joystick settings.

Returns
A const reference to the settings.

Definition at line 157 of file Joystick.h.

◆ setValue()

void Joystick::setValue ( const Vector< 2, fltp04 > & location)

Programmatically sets the joystick position.

Parameters
[in]locationThe normalized joystick position to set.

◆ sizeHint()

QSize Joystick::sizeHint ( ) const
override

Returns the preferred size hint for the joystick widget.

Returns
The preferred size.

◆ snapBackPercent()

float Joystick::snapBackPercent ( ) const
inline

Returns the current snap-back animation progress as a percentage.

Returns
The snap-back percentage from 0.0 to 1.0.

Definition at line 124 of file Joystick.h.


The documentation for this class was generated from the following file: