-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtraEventHandlers.hpp
More file actions
220 lines (174 loc) · 6.05 KB
/
Copy pathExtraEventHandlers.hpp
File metadata and controls
220 lines (174 loc) · 6.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
* Copyright (C) 2021 Filipe Coelho <falktx@falktx.com>, Rob van den Berg <rghvdberg at gmail dot com
* SPDX-License-Identifier: ISC
*/
#pragma once
#include "Widget.hpp"
#include <vector>
START_NAMESPACE_DGL
static float clamp(float x, float upper, float lower)
{
return std::min(upper, std::max(x, lower));
}
// --------------------------------------------------------------------------------------------------------------------
class SwitchEventHandler
{
public:
class Callback
{
public:
virtual ~Callback() {}
virtual void switchClicked(SubWidget *widget, bool down) = 0;
};
explicit SwitchEventHandler(SubWidget *self);
explicit SwitchEventHandler(SubWidget *self, const SwitchEventHandler &other);
SwitchEventHandler &operator=(const SwitchEventHandler &other);
~SwitchEventHandler();
bool isDown() const noexcept;
void setDown(bool down) noexcept;
void setCallback(Callback *callback) noexcept;
bool mouseEvent(const Widget::MouseEvent &ev);
protected:
private:
struct PrivateData;
PrivateData *const pData;
DISTRHO_LEAK_DETECTOR(SwitchEventHandler)
};
class SliderEventHandler
{
public:
enum Orientation
{
Horizontal,
Vertical
};
// NOTE hover not implemented yet
enum State
{
kSliderStateDefault = 0x0,
kSliderStateHover = 0x1,
kSliderStateDragging = 0x2,
kSliderStateDraggingHover = kSliderStateDragging | kSliderStateHover
};
class Callback
{
public:
virtual ~Callback() {}
virtual void sliderDragStarted(SubWidget *widget) = 0;
virtual void sliderDragFinished(SubWidget *widget) = 0;
virtual void sliderValueChanged(SubWidget *widget, float value) = 0;
};
explicit SliderEventHandler(SubWidget *self);
explicit SliderEventHandler(SubWidget *self, const SliderEventHandler &other);
SliderEventHandler &operator=(const SliderEventHandler &other);
~SliderEventHandler();
// returns raw value, is assumed to be scaled if using log
float getValue() const noexcept;
// NOTE: value is assumed to be scaled if using log
virtual bool setValue(float value, bool sendCallback = false) noexcept;
// returns 0-1 ranged value, already with log scale as needed
float getNormalizedValue() const noexcept;
// NOTE: value is assumed to be scaled if using log
void setDefault(float def) noexcept;
void setSliderArea(const double x, const double y, const double w, const double h) noexcept;
void setInverted(bool inverted) noexcept;
bool isInverted() noexcept;
void setRange(float min, float max) noexcept;
void setStep(float step) noexcept;
void setUsingLogScale(bool yesNo) noexcept;
void setStartPos(const int x, const int y) noexcept;
void setEndPos(const int x, const int y) noexcept;
void setCallback(Callback *callback) noexcept;
bool mouseEvent(const Widget::MouseEvent &ev);
bool motionEvent(const Widget::MotionEvent &ev);
bool scrollEvent(const Widget::ScrollEvent &ev);
protected:
// State getState() const noexcept;
private:
struct PrivateData;
PrivateData *const pData;
DISTRHO_LEAK_DETECTOR(SliderEventHandler)
};
class SpinnerEventHandler
{
public:
class Callback
{
public:
virtual ~Callback() {}
virtual void spinnerValueChanged(SubWidget *widget, float value) = 0;
};
explicit SpinnerEventHandler(SubWidget *self);
explicit SpinnerEventHandler(SubWidget *self, const SpinnerEventHandler &other);
SpinnerEventHandler &operator=(const SpinnerEventHandler &other);
~SpinnerEventHandler();
float getValue() const noexcept;
virtual bool setValue(float value, bool sendCallback = false) noexcept;
void setIncrementArea(const double x, const double y, const double w, const double h) noexcept;
void setDecrementArea(const double x, const double y, const double w, const double h) noexcept;
void setRange(float min, float max) noexcept;
void setStep(float step) noexcept;
void setCallback(Callback *callback) noexcept;
Rectangle<double> getIncrementArea() noexcept;
Rectangle<double> getDecrementArea() noexcept;
bool mouseEvent(const Widget::MouseEvent &ev);
bool motionEvent(const Widget::MotionEvent &ev);
bool scrollEvent(const Widget::ScrollEvent &ev);
protected:
// State getState() const noexcept;
private:
struct PrivateData;
PrivateData *const pData;
DISTRHO_LEAK_DETECTOR(SpinnerEventHandler)
};
// --------------------------------------------------------------------------------------------------------------------
class RadioEventHandler
{
public:
class Callback
{
public:
virtual ~Callback() {}
virtual void radioValueChanged(SubWidget *widget, float value) = 0;
};
struct Option
{
const char *name;
float value;
Rectangle<double> hitbox;
Option(const char *nm, float val)
{
name = nm;
value = val;
}
};
explicit RadioEventHandler(SubWidget *self);
explicit RadioEventHandler(SubWidget *self, const RadioEventHandler &other);
RadioEventHandler &operator=(const RadioEventHandler &other);
~RadioEventHandler();
float getValue() const noexcept;
virtual bool setValue(float value, bool sendCallback = false) noexcept;
/*
* addOption also calculates the hitboxes
*/
void addOption(const char *name, float value);
/*
* call this after changing size
*/
void initHitboxes();
/*
* clear the vector !
*/
void getHitboxes(std::vector<Rectangle<double>> &hitboxes);
void getOptions(std::vector<Option>&options);
void setCallback(Callback *callback) noexcept;
bool mouseEvent(const Widget::MouseEvent &ev);
protected:
// State getState() const noexcept;
private:
struct PrivateData;
PrivateData *const pData;
DISTRHO_LEAK_DETECTOR(SpinnerEventHandler)
};
// --------------------------------------------------------------------------------------------------------------------
END_NAMESPACE_DGL