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
46 {
47 public:
58 bool uses_buttons = false;
59 bool uses_knob = true;
60 bool operator==(const JoystickSettings& settings) const
61 {
62 return settings.deadzone == deadzone
64 && settings.sensitivity == sensitivity
65 && settings.uses_buttons == uses_buttons
66 && settings.uses_knob == uses_knob;
67 }
68 void resetToDefaults();
69 void getINI(INIFactory& factory) override;
70 };
71
72
73 class NDEVR_WIDGETS_API Joystick : public QWidget
74 {
75 Q_OBJECT
76 Q_PROPERTY(float snap_back_percent READ snapBackPercent WRITE setSnapBackPercent)
77 public:
78
79 explicit Joystick(QWidget* parent = nullptr);
80 Vector<2, fltp04> centerPoint() const;
81 Vector<2, fltp04> knobLocation() const;
82 fltp04 knobRadius() const;
83 fltp04 outerRadius() const;
84 QSize sizeHint() const override;
85 void setKnobColor(RGBColor inner, RGBColor outer);
86 void setBackgroundColor(RGBColor inner, RGBColor outer);
87 float snapBackPercent() const { return m_snap_back_percent; }
88 void setSnapBackPercent(float snap_percent);
89 virtual void mousePressEvent(QMouseEvent* ev) override;
90 virtual void mouseMoveEvent(QMouseEvent* ev) override;
91 virtual void mouseReleaseEvent(QMouseEvent* ev) override;
92 void addButton(Button* button);
93 bool event(QEvent* event) override;
94 void setDeadzone(fltp08 deadzone);
95 void setJoystickSettingsName(const String& name);
96 const JoystickSettings& settings() const { return m_settings; }
97 void setValue(const Vector<2, fltp04>& location);
98 bool isDragging() const;
99 void setSettings(const JoystickSettings& mode);
100 void setDrawDeadzone(bool draw_deadzone);
101 void setDrawSensitivity(bool draw_sense);
102 QRect arrowRect(const Vector<2, sint04>& location, const Vector<2, fltp04>& center_point, fltp04 radius) const;
103 signals:
107 protected:
108 void showSettings(const PopupInfo& info);
109 void updateButton(uint04 button);
110 void updateButtons();
111 Vector<2, fltp04> convertLocationToSignal(Vector<2, fltp04> mouse_location);
112 void resizeEvent(QResizeEvent* event) override;
113 void paintEvent(QPaintEvent* paint_event) override;
114 protected:
125 fltp04 m_snap_back_percent = 0.0f;
126 QPropertyAnimation* m_joystick_release_animation;
132 };
133}
#define NDEVR_WIDGETS_API
Definition DLLInfo.h:81
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
Definition Button.h:60
Definition INIReader.h:57
Definition INIInterface.h:40
Definition Joystick.h:74
Vector< 2, fltp04 > m_joystick_draw_location
Definition Joystick.h:124
float snapBackPercent() const
Definition Joystick.h:87
RGBColor m_inner_color
Definition Joystick.h:120
bool m_is_pressing
Definition Joystick.h:129
bool m_dragging
Definition Joystick.h:128
fltp04 m_inner_radius
Definition Joystick.h:118
Button * m_settings_button
Definition Joystick.h:116
QPropertyAnimation * m_joystick_release_animation
Definition Joystick.h:126
void joystickLocationChangedSignal(const Vector< 2, fltp04 > &location)
Vector< 2, fltp04 > m_location
Definition Joystick.h:117
fltp04 m_knob_radius
Definition Joystick.h:127
JoystickSettings m_settings
Definition Joystick.h:115
bool m_draw_sensitivity
Definition Joystick.h:131
void joystickButtonReleasedSignal(const Vector< 2, fltp04 > &location)
Buffer< Button * > m_custom_buttons
Definition Joystick.h:121
RGBColor m_knob_inner_color
Definition Joystick.h:122
RGBColor m_knob_outer_color
Definition Joystick.h:123
bool m_draw_deadzone
Definition Joystick.h:130
void joystickButtonPressedSignal(const Vector< 2, fltp04 > &location)
RGBColor m_outer_color
Definition Joystick.h:119
const JoystickSettings & settings() const
Definition Joystick.h:96
Definition Joystick.h:46
fltp04 deadzone
Definition Joystick.h:55
void getINI(INIFactory &factory) override
Definition Joystick.cpp:582
SensitivityMode sensitivity_mode
Definition Joystick.h:56
SensitivityMode
Definition Joystick.h:50
@ e_exponential
Definition Joystick.h:52
@ e_linear
Definition Joystick.h:51
@ e_sinusoidal
Definition Joystick.h:53
bool operator==(const JoystickSettings &settings) const
Definition Joystick.h:60
fltp04 sensitivity
Definition Joystick.h:57
bool uses_knob
Definition Joystick.h:59
bool uses_buttons
Definition Joystick.h:58
JoystickSettings()
Definition Joystick.cpp:569
void resetToDefaults()
Definition Joystick.cpp:574
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:53
Definition String.h:40
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
Definition ACIColor.h:37
float fltp04
Defines an alias representing a 4 byte floating-point number.
Definition BaseValues.hpp:157
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181
Definition PopupInfo.h:10