API Documentation
Loading...
Searching...
No Matches
Joystick.h
Go to the documentation of this file.
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: SunDial
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;
44
45 /**--------------------------------------------------------------------------------------------------
46 \brief Settings that define how a Joystick will behave.
47 **/
49 {
50 public:
61 bool uses_buttons = false;
62 bool uses_knob = true;
63 bool operator==(const JoystickSettings& settings) const
64 {
65 return settings.deadzone == deadzone
67 && settings.sensitivity == sensitivity
68 && settings.uses_buttons == uses_buttons
69 && settings.uses_knob == uses_knob;
70 }
72 void getINI(INIFactory& factory) override;
73 };
74
75 /**--------------------------------------------------------------------------------------------------
76 \brief A joystick that allows the user to move around, reporting the vector of the stick, relative
77 to the center of the joystick.
78 **/
79 class NDEVR_WIDGETS_API Joystick : public QWidget
80 {
81 Q_OBJECT
82 Q_PROPERTY(float snap_back_percent READ snapBackPercent WRITE setSnapBackPercent)
83 public:
84
85 explicit Joystick(QWidget* parent = nullptr);
90 QSize sizeHint() const override;
91 void setKnobColor(RGBColor inner, RGBColor outer);
93 float snapBackPercent() const { return m_snap_back_percent; }
94 void setSnapBackPercent(float snap_percent);
95 virtual void mousePressEvent(QMouseEvent* ev) override;
96 virtual void mouseMoveEvent(QMouseEvent* ev) override;
97 virtual void mouseReleaseEvent(QMouseEvent* ev) override;
98 void addButton(Button* button);
99 bool event(QEvent* event) override;
100 void setDeadzone(fltp08 deadzone);
102 const JoystickSettings& settings() const { return m_settings; }
103 void setValue(const Vector<2, fltp04>& location);
104 bool isDragging() const;
105 void setSettings(const JoystickSettings& mode);
106 void setDrawDeadzone(bool draw_deadzone);
107 void setDrawSensitivity(bool draw_sense);
108 QRect arrowRect(const Vector<2, sint04>& location, const Vector<2, fltp04>& center_point, fltp04 radius) const;
109 signals:
113 private:
114 void showSettings(const PopupInfo& info);
115 void updateButton(uint04 button);
116 void updateButtons();
117 Vector<2, fltp04> convertLocationToSignal(Vector<2, fltp04> mouse_location);
118 void resizeEvent(QResizeEvent* event) override;
119 void paintEvent(QPaintEvent* paint_event) override;
120 private:
121 JoystickSettings m_settings;
122 Button* m_settings_button;
123 Vector<2, fltp04> m_location;
124 fltp04 m_inner_radius;
125 RGBColor m_outer_color;
126 RGBColor m_inner_color;
127 Buffer<Button*> m_custom_buttons;
128 RGBColor m_knob_inner_color;
129 RGBColor m_knob_outer_color;
130 Vector<2, fltp04> m_joystick_draw_location;
131 fltp04 m_snap_back_percent = 0.0f;
132 QPropertyAnimation* m_joystick_release_animation;
133 fltp04 m_knob_radius;
134 bool m_dragging;
135 bool m_is_pressing;
136 bool m_draw_deadzone;
137 bool m_draw_sensitivity;
138 };
139}
#define NDEVR_WIDGETS_API
Definition DLLInfo.h:59
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
A core widget that allows the user to click one of many button types.
Definition Button.h:66
Contains methods for easily reading and writing to an INI file including efficient casting,...
Definition INIReader.h:68
Contains methods for easily reading and writing to an INI file including.
Definition INIInterface.h:45
A joystick that allows the user to move around, reporting the vector of the stick,...
Definition Joystick.h:80
virtual void mousePressEvent(QMouseEvent *ev) override
float snapBackPercent() const
Definition Joystick.h:93
bool isDragging() const
fltp04 outerRadius() const
void setValue(const Vector< 2, fltp04 > &location)
QSize sizeHint() const override
void setDeadzone(fltp08 deadzone)
void setDrawDeadzone(bool draw_deadzone)
bool event(QEvent *event) override
void joystickLocationChangedSignal(const Vector< 2, fltp04 > &location)
Joystick(QWidget *parent=nullptr)
void setBackgroundColor(RGBColor inner, RGBColor outer)
void setSettings(const JoystickSettings &mode)
void setJoystickSettingsName(const String &name)
void setDrawSensitivity(bool draw_sense)
void joystickButtonReleasedSignal(const Vector< 2, fltp04 > &location)
virtual void mouseReleaseEvent(QMouseEvent *ev) override
void setKnobColor(RGBColor inner, RGBColor outer)
void addButton(Button *button)
fltp04 knobRadius() const
void setSnapBackPercent(float snap_percent)
virtual void mouseMoveEvent(QMouseEvent *ev) override
Vector< 2, fltp04 > centerPoint() const
void joystickButtonPressedSignal(const Vector< 2, fltp04 > &location)
QRect arrowRect(const Vector< 2, sint04 > &location, const Vector< 2, fltp04 > &center_point, fltp04 radius) const
const JoystickSettings & settings() const
Definition Joystick.h:102
Vector< 2, fltp04 > knobLocation() const
Settings that define how a Joystick will behave.
Definition Joystick.h:49
fltp04 deadzone
Definition Joystick.h:58
void getINI(INIFactory &factory) override
SensitivityMode sensitivity_mode
Definition Joystick.h:59
SensitivityMode
Definition Joystick.h:53
@ e_exponential
Definition Joystick.h:55
@ e_linear
Definition Joystick.h:54
@ e_sinusoidal
Definition Joystick.h:56
bool operator==(const JoystickSettings &settings) const
Definition Joystick.h:63
fltp04 sensitivity
Definition Joystick.h:60
bool uses_knob
Definition Joystick.h:62
bool uses_buttons
Definition Joystick.h:61
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:54
The core String class for the NDEVR API.
Definition String.h:69
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
Definition ACIColor.h:37
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
Definition BaseValues.hpp:127
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
Class which is used to pass arguments and requests for creating a popup dialog or widget....
Definition PopupInfo.h:15