NDEVR
API Documentation
Joystick.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Widgets
28File: Joystick
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/INIInterface.h>
35#include <NDEVR/Vector.h>
36#include <NDEVR/RGBColor.h>
37#include <QWidget>
38class QPropertyAnimation;
39class QPainterPath;
40namespace NDEVR
41{
42 class Button;
43 struct PopupInfo;
48 class JoystickSettings : public INIInterface
49 {
50 public:
51 JoystickSettings();
59 fltp04 deadzone = 0.05f;
62 bool uses_buttons = false;
63 bool uses_knob = true;
67 bool operator==(const JoystickSettings& settings) const
68 {
69 return settings.deadzone == deadzone
71 && settings.sensitivity == sensitivity
72 && settings.uses_buttons == uses_buttons
73 && settings.uses_knob == uses_knob;
74 }
75
79 void getINI(INIFactory& factory) override;
80 };
81
87 class NDEVR_WIDGETS_API Joystick : public QWidget
88 {
89 Q_OBJECT
90 Q_PROPERTY(float snap_back_percent READ snapBackPercent WRITE setSnapBackPercent)
91 public:
92
95 explicit Joystick(QWidget* parent = nullptr);
110 QSize minimumSizeHint() const override;
113 QSize sizeHint() const override;
117 void setKnobColor(RGBColor inner, RGBColor outer);
124 float snapBackPercent() const { return m_snap_back_percent; }
127 void setSnapBackPercent(float snap_percent);
130 void pressEvent(Vector<2, fltp04> mouse_location);
135 virtual void mousePressEvent(QMouseEvent* ev) override;
138 virtual void mouseMoveEvent(QMouseEvent* ev) override;
141 virtual void mouseReleaseEvent(QMouseEvent* ev) override;
144 void addButton(Button* button);
148 bool event(QEvent* event) override;
151 void setDeadzone(fltp08 deadzone);
157 const JoystickSettings& settings() const { return m_settings; }
160 void setValue(const Vector<2, fltp04>& location);
163 bool isDragging() const;
166 void setSettings(const JoystickSettings& mode);
169 void setDrawDeadzone(bool draw_deadzone);
172 void setDrawSensitivity(bool draw_sense);
178 QRect arrowRect(const Vector<2, sint04>& location, const Vector<2, fltp04>& center_point, fltp04 radius) const;
179 signals:
189 private:
192 void showSettings(PopupInfo info);
195 void updateButton(uint04 button);
197 void updateButtons();
201 Vector<2, fltp04> convertLocationToSignal(Vector<2, fltp04> mouse_location);
204 void resizeEvent(QResizeEvent* event) override;
207 void paintEvent(QPaintEvent* paint_event) override;
208 private:
209 JoystickSettingsDialog* m_settings_dialog = nullptr;
210 JoystickSettings m_settings;
211 Button* m_settings_button;
212 Vector<2, fltp04> m_location;
213 fltp04 m_inner_radius;
214 RGBColor m_outer_color;
215 RGBColor m_inner_color;
216 Buffer<Button*> m_custom_buttons;
217 RGBColor m_knob_inner_color;
218 RGBColor m_knob_outer_color;
219 Vector<2, fltp04> m_joystick_draw_location;
220 fltp04 m_snap_back_percent = 0.0f;
221 QPropertyAnimation* m_joystick_release_animation;
222 fltp04 m_knob_radius;
223 bool m_dragging;
224 bool m_is_pressing;
225 bool m_draw_deadzone;
226 bool m_draw_sensitivity;
227 };
228}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A core widget that allows the user to click one of many button types.
Definition Button.h:68
Contains methods for easily reading and writing to an INI file including efficient casting,...
Definition INIReader.h:107
INIInterface()
Constructs an INIInterface with no default INI file.
A dialog which allows the user to set sensitivity and other properties of a Joystick object.
Settings that define how a Joystick will behave.
Definition Joystick.h:49
bool uses_knob
Whether the draggable knob is enabled on the joystick.
Definition Joystick.h:63
SensitivityMode sensitivity_mode
The curve used to map displacement to output.
Definition Joystick.h:60
SensitivityMode
The method used to map raw joystick displacement to output sensitivity.
Definition Joystick.h:54
@ e_exponential
Exponential mapping, giving finer control near center.
Definition Joystick.h:56
@ e_linear
Linear mapping from displacement to output.
Definition Joystick.h:55
@ e_sinusoidal
Sinusoidal mapping for smooth acceleration curve.
Definition Joystick.h:57
bool uses_buttons
Whether directional arrow buttons are enabled on the joystick.
Definition Joystick.h:62
bool operator==(const JoystickSettings &settings) const
Checks equality between two JoystickSettings objects.
Definition Joystick.h:67
void getINI(INIFactory &factory) override
Serializes or deserializes the joystick settings to or from an INI file.
fltp04 sensitivity
The overall sensitivity multiplier applied to joystick output.
Definition Joystick.h:61
void resetToDefaults()
Resets all joystick settings to their default values.
fltp04 deadzone
The minimum displacement threshold before input is registered.
Definition Joystick.h:59
void setDrawDeadzone(bool draw_deadzone)
Sets whether the deadzone region is visually drawn on the joystick.
void resizeEvent(QResizeEvent *event) override
Handles resize events to recalculate joystick geometry.
void pressEvent(Vector< 2, fltp04 > mouse_location)
Simulates a press event at the given location.
void setJoystickSettingsName(const StringView &name)
Sets the INI settings name used for persisting joystick settings.
void releaseEvent()
Simulates a release event, triggering the snap-back animation.
void setKnobColor(RGBColor inner, RGBColor outer)
Sets the gradient colors used to draw the joystick knob.
virtual void mousePressEvent(QMouseEvent *ev) override
Handles mouse press events on the joystick.
void paintEvent(QPaintEvent *paint_event) override
Paints the joystick widget including background, knob, and buttons.
void setSettings(const JoystickSettings &mode)
Applies new joystick settings.
const JoystickSettings & settings() const
Returns the current joystick settings.
Definition Joystick.h:157
QSize minimumSizeHint() const override
Returns the minimum size hint for the joystick widget.
void joystickLocationChangedSignal(const Vector< 2, fltp04 > &location)
Emitted when the joystick position changes during dragging.
void setBackgroundColor(RGBColor inner, RGBColor outer)
Sets the gradient colors used to draw the joystick background.
fltp04 knobRadius() const
Returns the radius of the joystick knob.
QSize sizeHint() const override
Returns the preferred size hint for 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.
void setSnapBackPercent(float snap_percent)
Sets the snap-back animation progress percentage.
void joystickButtonReleasedSignal(const Vector< 2, fltp04 > &location)
Emitted when the joystick knob is released.
Joystick(QWidget *parent=nullptr)
Constructs a Joystick widget.
void setDrawSensitivity(bool draw_sense)
Sets whether the sensitivity region is visually drawn on the joystick.
fltp04 outerRadius() const
Returns the radius of the outer joystick boundary.
Vector< 2, fltp04 > centerPoint() 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.
virtual void mouseReleaseEvent(QMouseEvent *ev) override
Handles mouse release events on the joystick.
void joystickButtonPressedSignal(const Vector< 2, fltp04 > &location)
Emitted when the joystick knob is initially pressed.
void setValue(const Vector< 2, fltp04 > &location)
Programmatically sets the joystick position.
Vector< 2, fltp04 > knobLocation() const
Returns the current position of the joystick knob in widget coordinates.
virtual void mouseMoveEvent(QMouseEvent *ev) override
Handles mouse move events to update the joystick knob position.
void addButton(Button *button)
Adds a custom button to the joystick widget.
bool isDragging() const
Checks whether the joystick knob is currently being dragged.
void setDeadzone(fltp08 deadzone)
Sets the deadzone radius below which joystick input is ignored.
float snapBackPercent() const
Returns the current snap-back animation progress as a percentage.
Definition Joystick.h:124
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:57
The core String View class for the NDEVR API.
Definition StringView.h:58
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
The primary namespace for the NDEVR SDK.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
Class which is used to pass arguments and requests for creating a popup dialog or widget.
Definition PopupInfo.h:16