Open3D (C++ API)  0.13.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Events.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2021 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <cstdint>
30 #include <sstream>
31 #include <string>
32 
34 
36 namespace Json {
37 class Value;
38 } // namespace Json
40 
41 namespace open3d {
42 namespace visualization {
43 namespace gui {
44 
45 enum class MouseButton {
46  NONE = 0,
47  LEFT = (1 << 0),
48  MIDDLE = (1 << 1),
49  RIGHT = (1 << 2),
50  BUTTON4 = (1 << 3),
51  BUTTON5 = (1 << 4)
52 };
53 
54 // The key modifiers are labeled by functionality; for instance,
55 // Ctrl on Windows and Command on macOS have roughly the same functionality.
56 enum class KeyModifier {
57  NONE = 0,
58  SHIFT = (1 << 0),
59  CTRL = (1 << 1), // win/linux: ctrl, macOS: command
60  ALT = (1 << 2), // win/linux: alt, macOS: ctrl
61  META = (1 << 3), // win/linux: windows key, macOS: option
62 };
63 
64 struct MouseEvent {
65  enum Type { MOVE, BUTTON_DOWN, DRAG, BUTTON_UP, WHEEL };
66 
67  static MouseEvent MakeMoveEvent(const Type type,
68  const int x,
69  const int y,
70  const int modifiers,
71  const int buttons);
72 
73  static MouseEvent MakeButtonEvent(const Type type,
74  const int x,
75  const int y,
76  const int modifiers,
77  const MouseButton button,
78  const int count);
79 
80  static MouseEvent MakeWheelEvent(const Type type,
81  const int x,
82  const int y,
83  const int modifiers,
84  const float dx,
85  const float dy,
86  const bool isTrackpad);
87 
89  int x;
90  int y;
91  int modifiers; // KeyModifiers ORed together
92  union {
93  struct {
94  int buttons; // MouseButtons ORed together
95  } move; // includes drag
96  struct {
98  int count;
99  } button;
100  struct {
101  float dx; // macOS gives fractional values, and is required
102  float dy; // for the buttery-smooth trackpad scrolling on macOS
104  } wheel;
105  };
106 
107  bool FromJson(const Json::Value &value);
108  std::string ToString() const;
109 };
110 
111 struct TickEvent {
112  double dt;
113 };
114 
115 enum KeyName {
116  KEY_NONE = 0,
118  KEY_TAB = 9,
119  KEY_ENTER = 10,
121  KEY_SPACE = 32,
124  KEY_HASH = 35,
132  KEY_PLUS = 43,
133  KEY_COMMA = 44,
134  KEY_MINUS = 45,
136  KEY_SLASH = 47,
137  KEY_0 = 48,
147  KEY_COLON = 58,
153  KEY_AT = 64,
157  KEY_CARET = 94,
160  KEY_A = 97,
187  KEY_PIPE = 124,
189  KEY_TILDE = 126,
190  KEY_DELETE = 127,
191  KEY_LSHIFT = 256,
207  KEY_UNKNOWN = 1000
208 };
209 
210 struct KeyEvent {
211  enum Type { DOWN, UP };
213  // This is the actual key that was pressed, not the character that
214  // was generated (use TextInputEvent for that). Values correspond
215  // to ASCII values where applicable.
217  bool isRepeat;
218 };
219 
221  const char *utf8;
222 };
223 
224 } // namespace gui
225 } // namespace visualization
226 } // namespace open3d
Definition: Events.h:143
Definition: Events.h:181
Definition: Events.h:174
Definition: Events.h:172
Definition: Events.h:185
uint32_t key
Definition: Events.h:216
Definition: Events.h:161
Type type
Definition: Events.h:88
Definition: Events.h:187
Definition: Events.h:196
MouseButton button
Definition: Events.h:97
int modifiers
Definition: Events.h:91
const char * utf8
Definition: Events.h:221
Definition: Events.h:139
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t timeout_in_ms capture_handle capture_handle capture_handle image_handle temperature_c k4a_image_t image_handle uint8_t image_handle image_handle image_handle image_handle uint32_t
Definition: K4aPlugin.cpp:557
Definition: Events.h:183
Definition: Events.h:163
Definition: Events.h:198
Definition: Events.h:137
Definition: Events.h:144
Definition: Events.h:178
float dy
Definition: Events.h:102
Definition: Events.h:176
bool isTrackpad
Definition: Events.h:103
Definition: Events.h:168
Definition: Events.h:153
Definition: Events.h:164
double dt
Definition: Events.h:112
Definition: Events.h:175
Definition: Events.h:145
float dx
Definition: Events.h:101
Definition: Events.h:180
int x
Definition: Events.h:89
Definition: Events.h:195
int y
Definition: Events.h:90
Definition: Events.h:200
Definition: Events.h:142
Definition: Events.h:170
Definition: Events.h:162
Definition: Events.h:124
MouseButton
Definition: Events.h:45
Definition: Events.h:167
Definition: Events.h:146
Definition: Events.h:132
Definition: Events.h:138
Definition: Events.h:140
int count
Definition: FilePCD.cpp:61
char type
Definition: FilePCD.cpp:60
Definition: Events.h:179
Definition: Events.h:118
int buttons
Definition: Events.h:94
KeyModifier
Definition: Events.h:56
Definition: Events.h:177
Definition: PinholeCameraIntrinsic.cpp:35
Definition: Events.h:184
Definition: Events.h:204
Definition: Events.h:141
int count
Definition: Events.h:98
KeyName
Definition: Events.h:115
bool isRepeat
Definition: Events.h:217
Definition: Events.h:171
Definition: Events.h:169
Definition: Events.h:116
Definition: Events.h:210
Definition: Events.h:203
Type
Definition: Events.h:211
Definition: Events.h:165
Type type
Definition: Events.h:212
Definition: Events.h:173
Definition: Events.h:166
Definition: Events.h:182
Definition: Events.h:201
Definition: Events.h:160