VCV Rack API v2
Loading...
Searching...
No Matches
event.hpp
Go to the documentation of this file.
1#pragma once
2#include <vector>
3#include <set>
4
5#include <common.hpp>
6#include <math.hpp>
7
8
9
13#if defined ARCH_MAC
14 #define RACK_MOD_CTRL GLFW_MOD_SUPER
15 #define RACK_MOD_CTRL_NAME "⌘"
16#else
17 #define RACK_MOD_CTRL GLFW_MOD_CONTROL
18 #define RACK_MOD_CTRL_NAME "Ctrl"
19#endif
20#define RACK_MOD_SHIFT_NAME "Shift"
21#define RACK_MOD_ALT_NAME "Alt"
22
28#define RACK_MOD_MASK (GLFW_MOD_SHIFT | GLFW_MOD_CONTROL | GLFW_MOD_ALT | GLFW_MOD_SUPER)
29
32#define RACK_HELD 3
33
34
35namespace rack {
36namespace widget {
37
38
39struct Widget;
40
41
45 bool propagating = true;
47 bool consumed = false;
49 Widget* target = NULL;
50};
51
52
54struct BaseEvent {
56
59 void stopPropagating() const {
60 if (!context)
61 return;
62 context->propagating = false;
63 }
64 bool isPropagating() const {
65 if (!context)
66 return true;
67 return context->propagating;
68 }
72 void setTarget(Widget* w) const {
73 if (!context)
74 return;
75 context->target = w;
76 }
77 Widget* getTarget() const {
78 if (!context)
79 return NULL;
80 return context->target;
81 }
85 void consume(Widget* w) const {
86 if (!context)
87 return;
88 context->propagating = false;
89 context->consumed = true;
90 context->target = w;
91 }
92 void unconsume() const {
93 if (!context)
94 return;
95 context->consumed = false;
96 }
97 bool isConsumed() const {
98 if (!context)
99 return false;
100 return context->consumed;
101 }
102};
103
104
112 int dragButton = 0;
116 double lastClickTime = -INFINITY;
118 std::set<int> heldKeys;
119
121 return rootWidget;
122 }
124 return hoveredWidget;
125 }
127 return draggedWidget;
128 }
135
137 void setDraggedWidget(Widget* w, int button);
141 DEPRECATED void setDragged(Widget* w, int button) {setDraggedWidget(w, button);}
146
147 bool handleButton(math::Vec pos, int button, int action, int mods);
148 bool handleHover(math::Vec pos, math::Vec mouseDelta);
150 bool handleScroll(math::Vec pos, math::Vec scrollDelta);
151 bool handleText(math::Vec pos, int codepoint);
152 bool handleKey(math::Vec pos, int key, int scancode, int action, int mods);
153 bool handleDrop(math::Vec pos, const std::vector<std::string>& paths);
155};
156
157
158} // namespace widget
159} // namespace rack
#define DEPRECATED
Attribute for deprecated functions and symbols.
Definition common.hpp:24
Root namespace for the Rack API.
Definition AudioDisplay.hpp:9
2-dimensional vector of floats, representing a point on the plane for graphics.
Definition math.hpp:189
Base class for all events.
Definition event.hpp:54
void stopPropagating() const
Prevents the event from being handled by more Widgets.
Definition event.hpp:59
void setTarget(Widget *w) const
Tells the event handler that a particular Widget consumed the event.
Definition event.hpp:72
void unconsume() const
Definition event.hpp:92
EventContext * context
Definition event.hpp:55
bool isPropagating() const
Definition event.hpp:64
bool isConsumed() const
Definition event.hpp:97
Widget * getTarget() const
Definition event.hpp:77
void consume(Widget *w) const
Sets the target Widget and stops propagating.
Definition event.hpp:85
A per-event state shared and writable by all widgets that recursively handle an event.
Definition event.hpp:43
Widget * target
The widget that responded to the event.
Definition event.hpp:49
bool propagating
Whether the event should continue recursing to children Widgets.
Definition event.hpp:45
bool consumed
Whether the event has been consumed by an event handler and no more handlers should consume the event...
Definition event.hpp:47
Definition event.hpp:105
void setHoveredWidget(Widget *w)
double lastClickTime
For double-clicking.
Definition event.hpp:116
void setSelectedWidget(Widget *w)
Widget * rootWidget
Definition event.hpp:106
DEPRECATED void setHovered(Widget *w)
Definition event.hpp:140
bool handleDrop(math::Vec pos, const std::vector< std::string > &paths)
bool handleScroll(math::Vec pos, math::Vec scrollDelta)
int dragButton
Definition event.hpp:112
bool handleButton(math::Vec pos, int button, int action, int mods)
void finalizeWidget(Widget *w)
Prepares a widget for deletion.
void setDragHoveredWidget(Widget *w)
DEPRECATED void setSelected(Widget *w)
Definition event.hpp:143
Widget * selectedWidget
Definition event.hpp:114
Widget * draggedWidget
Definition event.hpp:111
void setDraggedWidget(Widget *w, int button)
DEPRECATED void setDragged(Widget *w, int button)
Definition event.hpp:141
Widget * getRootWidget()
Definition event.hpp:120
Widget * dragHoveredWidget
Definition event.hpp:113
bool handleText(math::Vec pos, int codepoint)
Widget * lastClickedWidget
Definition event.hpp:117
DEPRECATED void setDragHovered(Widget *w)
Definition event.hpp:142
Widget * getDragHoveredWidget()
Definition event.hpp:129
Widget * hoveredWidget
State widgets Don't set these directly unless you know what you're doing.
Definition event.hpp:110
std::set< int > heldKeys
Definition event.hpp:118
Widget * getDraggedWidget()
Definition event.hpp:126
bool handleHover(math::Vec pos, math::Vec mouseDelta)
bool handleKey(math::Vec pos, int key, int scancode, int action, int mods)
Widget * getSelectedWidget()
Definition event.hpp:132
Widget * getHoveredWidget()
Definition event.hpp:123
A node in the 2D scene graph.
Definition Widget.hpp:21