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
21#define RACK_MOD_SHIFT GLFW_MOD_SHIFT
22#define RACK_MOD_SHIFT_NAME "Shift"
23
24#define RACK_MOD_ALT GLFW_MOD_ALT
25#define RACK_MOD_ALT_NAME "Alt"
26
32#define RACK_MOD_MASK (GLFW_MOD_SHIFT | GLFW_MOD_CONTROL | GLFW_MOD_ALT | GLFW_MOD_SUPER)
33
36#define RACK_HELD 3
37
38
39namespace rack {
40namespace widget {
41
42
43std::string getKeyName(int key);
44std::string getKeyCommandName(int key, int mods);
45
46
47struct Widget;
48
49
53 bool propagating = true;
55 bool consumed = false;
57 Widget* target = NULL;
58};
59
60
62struct BaseEvent {
64
67 void stopPropagating() const {
68 if (!context)
69 return;
70 context->propagating = false;
71 }
72 bool isPropagating() const {
73 if (!context)
74 return true;
75 return context->propagating;
76 }
80 void setTarget(Widget* w) const {
81 if (!context)
82 return;
83 context->target = w;
84 }
85 Widget* getTarget() const {
86 if (!context)
87 return NULL;
88 return context->target;
89 }
93 void consume(Widget* w) const {
94 if (!context)
95 return;
96 context->propagating = false;
97 context->consumed = true;
98 context->target = w;
99 }
100 void unconsume() const {
101 if (!context)
102 return;
103 context->consumed = false;
104 }
105 bool isConsumed() const {
106 if (!context)
107 return false;
108 return context->consumed;
109 }
110};
111
112
120 int dragButton = 0;
124 double lastClickTime = -INFINITY;
126 std::set<int> heldKeys;
127
129 return rootWidget;
130 }
132 return hoveredWidget;
133 }
135 return draggedWidget;
136 }
143
145 void setDraggedWidget(Widget* w, int button);
149 DEPRECATED void setDragged(Widget* w, int button) {setDraggedWidget(w, button);}
154
155 bool handleButton(math::Vec pos, int button, int action, int mods);
156 bool handleHover(math::Vec pos, math::Vec mouseDelta);
158 bool handleScroll(math::Vec pos, math::Vec scrollDelta);
159 bool handleText(math::Vec pos, uint32_t codepoint);
160 bool handleKey(math::Vec pos, int key, int scancode, int action, int mods);
161 bool handleDrop(math::Vec pos, const std::vector<std::string>& paths);
163};
164
165
166} // namespace widget
167} // namespace rack
#define DEPRECATED
Attribute for deprecated functions and symbols.
Definition common.hpp:26
std::string getKeyName(int key)
std::string getKeyCommandName(int key, int mods)
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:62
void stopPropagating() const
Prevents the event from being handled by more Widgets.
Definition event.hpp:67
void setTarget(Widget *w) const
Tells the event handler that a particular Widget consumed the event.
Definition event.hpp:80
void unconsume() const
Definition event.hpp:100
EventContext * context
Definition event.hpp:63
bool isPropagating() const
Definition event.hpp:72
bool isConsumed() const
Definition event.hpp:105
Widget * getTarget() const
Definition event.hpp:85
void consume(Widget *w) const
Sets the target Widget and stops propagating.
Definition event.hpp:93
A per-event state shared and writable by all widgets that recursively handle an event.
Definition event.hpp:51
Widget * target
The widget that responded to the event.
Definition event.hpp:57
bool propagating
Whether the event should continue recursing to children Widgets.
Definition event.hpp:53
bool consumed
Whether the event has been consumed by an event handler and no more handlers should consume the event...
Definition event.hpp:55
Definition event.hpp:113
void setHoveredWidget(Widget *w)
double lastClickTime
For double-clicking.
Definition event.hpp:124
void setSelectedWidget(Widget *w)
Widget * rootWidget
Definition event.hpp:114
DEPRECATED void setHovered(Widget *w)
Definition event.hpp:148
bool handleDrop(math::Vec pos, const std::vector< std::string > &paths)
bool handleText(math::Vec pos, uint32_t codepoint)
bool handleScroll(math::Vec pos, math::Vec scrollDelta)
int dragButton
Definition event.hpp:120
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:151
Widget * selectedWidget
Definition event.hpp:122
Widget * draggedWidget
Definition event.hpp:119
void setDraggedWidget(Widget *w, int button)
DEPRECATED void setDragged(Widget *w, int button)
Definition event.hpp:149
Widget * getRootWidget()
Definition event.hpp:128
Widget * dragHoveredWidget
Definition event.hpp:121
Widget * lastClickedWidget
Definition event.hpp:125
DEPRECATED void setDragHovered(Widget *w)
Definition event.hpp:150
Widget * getDragHoveredWidget()
Definition event.hpp:137
Widget * hoveredWidget
State widgets Don't set these directly unless you know what you're doing.
Definition event.hpp:118
std::set< int > heldKeys
Definition event.hpp:126
Widget * getDraggedWidget()
Definition event.hpp:134
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:140
Widget * getHoveredWidget()
Definition event.hpp:131
A node in the 2D scene graph.
Definition Widget.hpp:21