Loading [MathJax]/extensions/tex2jax.js
VCV Rack API v2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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
43struct Widget;
44
45
54std::string getKeyName(int key);
58std::string getKeyCommandName(int key, int mods = 0);
59
60
64 bool propagating = true;
66 bool consumed = false;
69};
70
71
73struct BaseEvent {
75
78 void stopPropagating() const {
79 if (!context)
80 return;
81 context->propagating = false;
82 }
83 bool isPropagating() const {
84 if (!context)
85 return true;
86 return context->propagating;
87 }
88
91 void setTarget(Widget* w) const {
92 if (!context)
93 return;
94 context->target = w;
95 }
96 Widget* getTarget() const {
97 if (!context)
98 return NULL;
99 return context->target;
100 }
101
104 void consume(Widget* w) const {
105 if (!context)
106 return;
107 context->propagating = false;
108 context->consumed = true;
109 context->target = w;
110 }
111 void unconsume() const {
112 if (!context)
113 return;
114 context->consumed = false;
115 }
116 bool isConsumed() const {
117 if (!context)
118 return false;
119 return context->consumed;
120 }
121};
122
123
131 int dragButton = 0;
135 double lastClickTime = -INFINITY;
137 std::set<int> heldKeys;
138
140 return rootWidget;
141 }
143 return hoveredWidget;
144 }
146 return draggedWidget;
147 }
154
156 void setDraggedWidget(Widget* w, int button);
160 DEPRECATED void setDragged(Widget* w, int button) {setDraggedWidget(w, button);}
165
166 bool handleButton(math::Vec pos, int button, int action, int mods);
167 bool handleHover(math::Vec pos, math::Vec mouseDelta);
169 bool handleScroll(math::Vec pos, math::Vec scrollDelta);
170 bool handleText(math::Vec pos, uint32_t codepoint);
171 bool handleKey(math::Vec pos, int key, int scancode, int action, int mods);
172 bool handleDrop(math::Vec pos, const std::vector<std::string>& paths);
174};
175
176
177} // namespace widget
178} // namespace rack
#define DEPRECATED
Attribute for deprecated functions and symbols.
Definition common.hpp:26
std::string getKeyName(int key)
Returns the name of a GLFW key macro.
std::string getKeyCommandName(int key, int mods=0)
Returns the name of a key command/chord/combo.
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:73
void stopPropagating() const
Prevents the event from being handled by more Widgets.
Definition event.hpp:78
void setTarget(Widget *w) const
Tells the event handler that a particular Widget consumed the event.
Definition event.hpp:91
void unconsume() const
Definition event.hpp:111
EventContext * context
Definition event.hpp:74
bool isPropagating() const
Definition event.hpp:83
bool isConsumed() const
Definition event.hpp:116
Widget * getTarget() const
Definition event.hpp:96
void consume(Widget *w) const
Sets the target Widget and stops propagating.
Definition event.hpp:104
A per-event state shared and writable by all widgets that recursively handle an event.
Definition event.hpp:62
Widget * target
The widget that responded to the event.
Definition event.hpp:68
bool propagating
Whether the event should continue recursing to children Widgets.
Definition event.hpp:64
bool consumed
Whether the event has been consumed by an event handler and no more handlers should consume the event...
Definition event.hpp:66
Definition event.hpp:124
void setHoveredWidget(Widget *w)
double lastClickTime
For double-clicking.
Definition event.hpp:135
void setSelectedWidget(Widget *w)
Widget * rootWidget
Definition event.hpp:125
DEPRECATED void setHovered(Widget *w)
Definition event.hpp:159
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:131
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:162
Widget * selectedWidget
Definition event.hpp:133
Widget * draggedWidget
Definition event.hpp:130
void setDraggedWidget(Widget *w, int button)
DEPRECATED void setDragged(Widget *w, int button)
Definition event.hpp:160
Widget * getRootWidget()
Definition event.hpp:139
Widget * dragHoveredWidget
Definition event.hpp:132
Widget * lastClickedWidget
Definition event.hpp:136
DEPRECATED void setDragHovered(Widget *w)
Definition event.hpp:161
Widget * getDragHoveredWidget()
Definition event.hpp:148
Widget * hoveredWidget
State widgets Don't set these directly unless you know what you're doing.
Definition event.hpp:129
std::set< int > heldKeys
Definition event.hpp:137
Widget * getDraggedWidget()
Definition event.hpp:145
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:151
Widget * getHoveredWidget()
Definition event.hpp:142
A node in the 2D scene graph.
Definition Widget.hpp:21