Mercurial > hg > pub > prymula > com
annotate DPF-Prymula-audioplugins/dpf/dgl/src/EventHandlers.cpp @ 3:84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
author | prymula <prymula76@outlook.com> |
---|---|
date | Mon, 16 Oct 2023 21:53:34 +0200 |
parents | |
children |
rev | line source |
---|---|
3
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
1 /* |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
2 * DISTRHO Plugin Framework (DPF) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com> |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
4 * |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
5 * Permission to use, copy, modify, and/or distribute this software for any purpose with |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
6 * or without fee is hereby granted, provided that the above copyright notice and this |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
7 * permission notice appear in all copies. |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
8 * |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
10 * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
11 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
12 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
15 */ |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
16 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
17 #include "../EventHandlers.hpp" |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
18 #include "../SubWidget.hpp" |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
19 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
20 START_NAMESPACE_DGL |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
21 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
22 // -------------------------------------------------------------------------------------------------------------------- |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
23 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
24 struct ButtonEventHandler::PrivateData { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
25 ButtonEventHandler* const self; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
26 SubWidget* const widget; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
27 ButtonEventHandler::Callback* internalCallback; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
28 ButtonEventHandler::Callback* userCallback; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
29 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
30 int button; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
31 int state; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
32 bool checkable; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
33 bool checked; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
34 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
35 Point<double> lastClickPos; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
36 Point<double> lastMotionPos; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
37 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
38 PrivateData(ButtonEventHandler* const s, SubWidget* const w) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
39 : self(s), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
40 widget(w), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
41 internalCallback(nullptr), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
42 userCallback(nullptr), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
43 button(-1), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
44 state(kButtonStateDefault), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
45 checkable(false), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
46 checked(false), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
47 lastClickPos(0, 0), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
48 lastMotionPos(0, 0) {} |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
49 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
50 bool mouseEvent(const Widget::MouseEvent& ev) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
51 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
52 lastClickPos = ev.pos; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
53 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
54 // button was released, handle it now |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
55 if (button != -1 && ! ev.press) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
56 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
57 DISTRHO_SAFE_ASSERT(state & kButtonStateActive); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
58 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
59 // release button |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
60 const int button2 = button; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
61 button = -1; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
62 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
63 const int state2 = state; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
64 state &= ~kButtonStateActive; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
65 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
66 self->stateChanged(static_cast<State>(state), static_cast<State>(state2)); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
67 widget->repaint(); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
68 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
69 // cursor was moved outside the button bounds, ignore click |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
70 if (! widget->contains(ev.pos)) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
71 return true; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
72 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
73 // still on bounds, register click |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
74 if (checkable) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
75 checked = !checked; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
76 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
77 if (internalCallback != nullptr) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
78 internalCallback->buttonClicked(widget, button2); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
79 else if (userCallback != nullptr) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
80 userCallback->buttonClicked(widget, button2); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
81 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
82 return true; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
83 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
84 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
85 // button was pressed, wait for release |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
86 if (ev.press && widget->contains(ev.pos)) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
87 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
88 const int state2 = state; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
89 button = static_cast<int>(ev.button); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
90 state |= kButtonStateActive; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
91 self->stateChanged(static_cast<State>(state), static_cast<State>(state2)); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
92 widget->repaint(); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
93 return true; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
94 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
95 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
96 return false; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
97 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
98 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
99 bool motionEvent(const Widget::MotionEvent& ev) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
100 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
101 // keep pressed |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
102 if (button != -1) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
103 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
104 lastMotionPos = ev.pos; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
105 return true; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
106 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
107 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
108 bool ret = false; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
109 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
110 if (widget->contains(ev.pos)) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
111 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
112 // check if entering hover |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
113 if ((state & kButtonStateHover) == 0x0) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
114 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
115 const int state2 = state; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
116 state |= kButtonStateHover; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
117 ret = widget->contains(lastMotionPos); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
118 self->stateChanged(static_cast<State>(state), static_cast<State>(state2)); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
119 widget->repaint(); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
120 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
121 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
122 else |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
123 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
124 // check if exiting hover |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
125 if (state & kButtonStateHover) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
126 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
127 const int state2 = state; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
128 state &= ~kButtonStateHover; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
129 ret = widget->contains(lastMotionPos); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
130 self->stateChanged(static_cast<State>(state), static_cast<State>(state2)); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
131 widget->repaint(); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
132 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
133 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
134 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
135 lastMotionPos = ev.pos; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
136 return ret; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
137 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
138 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
139 void setActive(const bool active2, const bool sendCallback) noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
140 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
141 const bool active = state & kButtonStateActive; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
142 if (active == active2) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
143 return; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
144 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
145 state |= kButtonStateActive; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
146 widget->repaint(); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
147 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
148 if (sendCallback) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
149 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
150 if (internalCallback != nullptr) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
151 internalCallback->buttonClicked(widget, -1); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
152 else if (userCallback != nullptr) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
153 userCallback->buttonClicked(widget, -1); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
154 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
155 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
156 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
157 void setChecked(const bool checked2, const bool sendCallback) noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
158 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
159 if (checked == checked2) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
160 return; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
161 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
162 checked = checked2; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
163 widget->repaint(); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
164 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
165 if (sendCallback) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
166 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
167 if (internalCallback != nullptr) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
168 internalCallback->buttonClicked(widget, -1); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
169 else if (userCallback != nullptr) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
170 userCallback->buttonClicked(widget, -1); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
171 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
172 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
173 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
174 DISTRHO_DECLARE_NON_COPYABLE(PrivateData) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
175 }; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
176 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
177 // -------------------------------------------------------------------------------------------------------------------- |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
178 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
179 ButtonEventHandler::ButtonEventHandler(SubWidget* const self) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
180 : pData(new PrivateData(this, self)) {} |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
181 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
182 ButtonEventHandler::~ButtonEventHandler() |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
183 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
184 delete pData; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
185 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
186 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
187 bool ButtonEventHandler::isActive() noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
188 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
189 return pData->state & kButtonStateActive; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
190 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
191 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
192 void ButtonEventHandler::setActive(const bool active, const bool sendCallback) noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
193 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
194 pData->setActive(active, sendCallback); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
195 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
196 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
197 bool ButtonEventHandler::isChecked() const noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
198 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
199 return pData->checked; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
200 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
201 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
202 void ButtonEventHandler::setChecked(const bool checked, const bool sendCallback) noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
203 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
204 pData->setChecked(checked, sendCallback); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
205 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
206 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
207 bool ButtonEventHandler::isCheckable() const noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
208 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
209 return pData->checkable; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
210 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
211 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
212 void ButtonEventHandler::setCheckable(const bool checkable) noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
213 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
214 if (pData->checkable == checkable) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
215 return; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
216 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
217 pData->checkable = checkable; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
218 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
219 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
220 Point<double> ButtonEventHandler::getLastClickPosition() const noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
221 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
222 return pData->lastClickPos; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
223 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
224 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
225 Point<double> ButtonEventHandler::getLastMotionPosition() const noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
226 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
227 return pData->lastMotionPos; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
228 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
229 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
230 void ButtonEventHandler::setCallback(Callback* const callback) noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
231 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
232 pData->userCallback = callback; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
233 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
234 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
235 bool ButtonEventHandler::mouseEvent(const Widget::MouseEvent& ev) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
236 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
237 return pData->mouseEvent(ev); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
238 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
239 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
240 bool ButtonEventHandler::motionEvent(const Widget::MotionEvent& ev) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
241 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
242 return pData->motionEvent(ev); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
243 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
244 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
245 ButtonEventHandler::State ButtonEventHandler::getState() const noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
246 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
247 return static_cast<State>(pData->state); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
248 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
249 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
250 void ButtonEventHandler::clearState() noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
251 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
252 pData->state = kButtonStateDefault; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
253 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
254 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
255 void ButtonEventHandler::stateChanged(State, State) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
256 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
257 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
258 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
259 void ButtonEventHandler::setInternalCallback(Callback* const callback) noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
260 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
261 pData->internalCallback = callback; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
262 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
263 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
264 void ButtonEventHandler::triggerUserCallback(SubWidget* const widget, const int button) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
265 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
266 if (pData->userCallback != nullptr) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
267 pData->userCallback->buttonClicked(widget, button); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
268 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
269 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
270 // -------------------------------------------------------------------------------------------------------------------- |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
271 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
272 struct KnobEventHandler::PrivateData { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
273 KnobEventHandler* const self; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
274 SubWidget* const widget; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
275 KnobEventHandler::Callback* callback; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
276 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
277 float accel; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
278 float minimum; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
279 float maximum; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
280 float step; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
281 float value; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
282 float valueDef; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
283 float valueTmp; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
284 bool usingDefault; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
285 bool usingLog; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
286 Orientation orientation; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
287 int state; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
288 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
289 double lastX; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
290 double lastY; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
291 uint lastClickTime; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
292 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
293 PrivateData(KnobEventHandler* const s, SubWidget* const w) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
294 : self(s), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
295 widget(w), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
296 callback(nullptr), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
297 accel(200.f), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
298 minimum(0.f), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
299 maximum(1.f), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
300 step(0.0f), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
301 value(0.5f), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
302 valueDef(value), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
303 valueTmp(value), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
304 usingDefault(false), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
305 usingLog(false), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
306 orientation(Vertical), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
307 state(kKnobStateDefault), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
308 lastX(0.0), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
309 lastY(0.0), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
310 lastClickTime(0) {} |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
311 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
312 PrivateData(KnobEventHandler* const s, SubWidget* const w, PrivateData* const other) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
313 : self(s), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
314 widget(w), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
315 callback(other->callback), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
316 accel(other->accel), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
317 minimum(other->minimum), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
318 maximum(other->maximum), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
319 step(other->step), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
320 value(other->value), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
321 valueDef(other->valueDef), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
322 valueTmp(value), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
323 usingDefault(other->usingDefault), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
324 usingLog(other->usingLog), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
325 orientation(other->orientation), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
326 state(kKnobStateDefault), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
327 lastX(0.0), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
328 lastY(0.0), |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
329 lastClickTime(0) {} |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
330 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
331 void assignFrom(PrivateData* const other) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
332 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
333 callback = other->callback; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
334 accel = other->accel; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
335 minimum = other->minimum; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
336 maximum = other->maximum; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
337 step = other->step; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
338 value = other->value; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
339 valueDef = other->valueDef; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
340 valueTmp = value; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
341 usingDefault = other->usingDefault; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
342 usingLog = other->usingLog; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
343 orientation = other->orientation; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
344 state = kKnobStateDefault; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
345 lastX = 0.0; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
346 lastY = 0.0; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
347 lastClickTime = 0; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
348 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
349 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
350 inline float logscale(const float v) const |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
351 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
352 const float b = std::log(maximum/minimum)/(maximum-minimum); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
353 const float a = maximum/std::exp(maximum*b); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
354 return a * std::exp(b*v); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
355 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
356 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
357 inline float invlogscale(const float v) const |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
358 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
359 const float b = std::log(maximum/minimum)/(maximum-minimum); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
360 const float a = maximum/std::exp(maximum*b); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
361 return std::log(v/a)/b; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
362 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
363 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
364 bool mouseEvent(const Widget::MouseEvent& ev, const double scaleFactor) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
365 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
366 if (ev.button != 1) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
367 return false; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
368 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
369 if (ev.press) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
370 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
371 if (! widget->contains(ev.pos)) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
372 return false; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
373 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
374 if ((ev.mod & kModifierShift) != 0 && usingDefault) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
375 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
376 setValue(valueDef, true); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
377 valueTmp = value; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
378 return true; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
379 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
380 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
381 lastX = ev.pos.getX() / scaleFactor; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
382 lastY = ev.pos.getY() / scaleFactor; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
383 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
384 if (lastClickTime > 0 && ev.time > lastClickTime && ev.time - lastClickTime <= 300) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
385 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
386 lastClickTime = 0; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
387 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
388 if (callback != nullptr) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
389 callback->knobDoubleClicked(widget); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
390 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
391 return true; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
392 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
393 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
394 lastClickTime = ev.time; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
395 state |= kKnobStateDragging; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
396 widget->repaint(); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
397 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
398 if (callback != nullptr) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
399 callback->knobDragStarted(widget); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
400 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
401 return true; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
402 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
403 else if (state & kKnobStateDragging) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
404 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
405 state &= ~kKnobStateDragging; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
406 widget->repaint(); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
407 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
408 if (callback != nullptr) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
409 callback->knobDragFinished(widget); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
410 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
411 return true; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
412 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
413 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
414 return false; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
415 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
416 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
417 bool motionEvent(const Widget::MotionEvent& ev, const double scaleFactor) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
418 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
419 if ((state & kKnobStateDragging) == 0x0) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
420 return false; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
421 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
422 float movDiff; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
423 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
424 switch (orientation) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
425 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
426 case Horizontal: |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
427 movDiff = ev.pos.getX() / scaleFactor - lastX; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
428 break; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
429 case Vertical: |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
430 movDiff = lastY - ev.pos.getY() / scaleFactor; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
431 break; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
432 case Both: |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
433 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
434 const float movDiffX = ev.pos.getX() / scaleFactor - lastX; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
435 const float movDiffY = lastY - ev.pos.getY() / scaleFactor; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
436 movDiff = std::abs(movDiffX) > std::abs(movDiffY) ? movDiffX : movDiffY; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
437 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
438 break; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
439 default: |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
440 return false; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
441 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
442 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
443 if (d_isZero(movDiff)) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
444 return true; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
445 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
446 const float divisor = (ev.mod & kModifierControl) ? accel * 10.f : accel; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
447 valueTmp += (maximum - minimum) / divisor * movDiff; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
448 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
449 if (usingLog) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
450 valueTmp = logscale(valueTmp); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
451 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
452 float value2; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
453 bool valueChanged = false; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
454 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
455 if (valueTmp < minimum) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
456 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
457 valueTmp = value2 = minimum; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
458 valueChanged = true; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
459 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
460 else if (valueTmp > maximum) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
461 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
462 valueTmp = value2 = maximum; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
463 valueChanged = true; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
464 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
465 else |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
466 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
467 if (d_isNotZero(step)) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
468 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
469 if (std::abs(valueTmp - value) >= step) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
470 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
471 const float rest = std::fmod(valueTmp, step); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
472 valueChanged = true; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
473 value2 = valueTmp - rest; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
474 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
475 if (rest < 0 && rest < step * -0.5f) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
476 value2 -= step; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
477 else if (rest > 0 && rest > step * 0.5f) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
478 value2 += step; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
479 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
480 if (value2 < minimum) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
481 value2 = minimum; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
482 else if (value2 > maximum) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
483 value2 = maximum; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
484 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
485 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
486 else |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
487 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
488 value2 = valueTmp; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
489 valueChanged = true; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
490 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
491 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
492 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
493 if (valueChanged) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
494 setValue(value2, true); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
495 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
496 lastX = ev.pos.getX() / scaleFactor; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
497 lastY = ev.pos.getY() / scaleFactor; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
498 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
499 return true; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
500 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
501 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
502 bool scrollEvent(const Widget::ScrollEvent& ev) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
503 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
504 if (! widget->contains(ev.pos)) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
505 return false; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
506 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
507 const float dir = (ev.delta.getY() > 0.f) ? 1.f : -1.f; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
508 const float d = (ev.mod & kModifierControl) ? accel * 10.f : accel; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
509 float value2 = (usingLog ? invlogscale(valueTmp) : valueTmp) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
510 + ((maximum - minimum) / d * 10.f * dir); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
511 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
512 if (usingLog) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
513 value2 = logscale(value2); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
514 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
515 if (value2 < minimum) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
516 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
517 valueTmp = value2 = minimum; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
518 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
519 else if (value2 > maximum) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
520 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
521 valueTmp = value2 = maximum; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
522 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
523 else |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
524 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
525 valueTmp = value2; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
526 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
527 if (d_isNotZero(step)) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
528 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
529 const float rest = std::fmod(value2, step); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
530 value2 = value2 - rest + (rest > step/2.0f ? step : 0.0f); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
531 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
532 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
533 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
534 setValue(value2, true); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
535 return true; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
536 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
537 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
538 float getNormalizedValue() const noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
539 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
540 const float diff = maximum - minimum; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
541 return ((usingLog ? invlogscale(value) : value) - minimum) / diff; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
542 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
543 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
544 void setRange(const float min, const float max) noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
545 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
546 DISTRHO_SAFE_ASSERT_RETURN(max > min,); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
547 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
548 if (value < min) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
549 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
550 valueTmp = value = min; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
551 widget->repaint(); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
552 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
553 else if (value > max) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
554 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
555 valueTmp = value = max; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
556 widget->repaint(); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
557 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
558 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
559 minimum = min; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
560 maximum = max; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
561 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
562 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
563 bool setValue(const float value2, const bool sendCallback) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
564 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
565 if (d_isEqual(value, value2)) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
566 return false; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
567 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
568 valueTmp = value = value2; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
569 widget->repaint(); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
570 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
571 if (sendCallback && callback != nullptr) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
572 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
573 try { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
574 callback->knobValueChanged(widget, value); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
575 } DISTRHO_SAFE_EXCEPTION("KnobEventHandler::setValue"); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
576 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
577 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
578 return true; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
579 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
580 }; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
581 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
582 // -------------------------------------------------------------------------------------------------------------------- |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
583 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
584 KnobEventHandler::KnobEventHandler(SubWidget* const self) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
585 : pData(new PrivateData(this, self)) {} |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
586 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
587 KnobEventHandler::KnobEventHandler(SubWidget* const self, const KnobEventHandler& other) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
588 : pData(new PrivateData(this, self, other.pData)) {} |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
589 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
590 KnobEventHandler& KnobEventHandler::operator=(const KnobEventHandler& other) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
591 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
592 pData->assignFrom(other.pData); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
593 return *this; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
594 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
595 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
596 KnobEventHandler::~KnobEventHandler() |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
597 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
598 delete pData; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
599 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
600 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
601 bool KnobEventHandler::isInteger() const noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
602 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
603 return d_isEqual(pData->step, 1.f); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
604 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
605 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
606 float KnobEventHandler::getValue() const noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
607 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
608 return pData->value; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
609 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
610 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
611 bool KnobEventHandler::setValue(const float value, const bool sendCallback) noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
612 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
613 return pData->setValue(value, sendCallback); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
614 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
615 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
616 float KnobEventHandler::getNormalizedValue() const noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
617 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
618 return pData->getNormalizedValue(); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
619 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
620 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
621 void KnobEventHandler::setDefault(const float def) noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
622 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
623 pData->valueDef = def; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
624 pData->usingDefault = true; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
625 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
626 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
627 void KnobEventHandler::setRange(const float min, const float max) noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
628 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
629 pData->setRange(min, max); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
630 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
631 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
632 void KnobEventHandler::setStep(const float step) noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
633 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
634 pData->step = step; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
635 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
636 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
637 void KnobEventHandler::setUsingLogScale(const bool yesNo) noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
638 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
639 pData->usingLog = yesNo; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
640 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
641 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
642 KnobEventHandler::Orientation KnobEventHandler::getOrientation() const noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
643 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
644 return pData->orientation; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
645 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
646 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
647 void KnobEventHandler::setOrientation(const Orientation orientation) noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
648 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
649 pData->orientation = orientation; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
650 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
651 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
652 void KnobEventHandler::setCallback(Callback* const callback) noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
653 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
654 pData->callback = callback; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
655 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
656 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
657 void KnobEventHandler::setMouseDeceleration(float accel) noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
658 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
659 pData->accel = accel; |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
660 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
661 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
662 bool KnobEventHandler::mouseEvent(const Widget::MouseEvent& ev, const double scaleFactor) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
663 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
664 return pData->mouseEvent(ev, scaleFactor); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
665 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
666 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
667 bool KnobEventHandler::motionEvent(const Widget::MotionEvent& ev, const double scaleFactor) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
668 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
669 return pData->motionEvent(ev, scaleFactor); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
670 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
671 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
672 bool KnobEventHandler::scrollEvent(const Widget::ScrollEvent& ev) |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
673 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
674 return pData->scrollEvent(ev); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
675 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
676 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
677 KnobEventHandler::State KnobEventHandler::getState() const noexcept |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
678 { |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
679 return static_cast<State>(pData->state); |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
680 } |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
681 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
682 // -------------------------------------------------------------------------------------------------------------------- |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
683 |
84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff
changeset
|
684 END_NAMESPACE_DGL |