ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Events.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <IJsonConvertible.h>
11 
12 #include <cstdint>
13 #include <sstream>
14 #include <string>
15 
17 namespace Json {
18 class Value;
19 } // namespace Json
21 
22 namespace cloudViewer {
23 namespace visualization {
24 namespace gui {
25 
26 enum class MouseButton {
27  NONE = 0,
28  LEFT = (1 << 0),
29  MIDDLE = (1 << 1),
30  RIGHT = (1 << 2),
31  BUTTON4 = (1 << 3),
32  BUTTON5 = (1 << 4)
33 };
34 
35 // The key modifiers are labeled by functionality; for instance,
36 // Ctrl on Windows and Command on macOS have roughly the same functionality.
37 enum class KeyModifier {
38  NONE = 0,
39  SHIFT = (1 << 0),
40  CTRL = (1 << 1), // win/linux: ctrl, macOS: command
41  ALT = (1 << 2), // win/linux: alt, macOS: ctrl
42  META = (1 << 3), // win/linux: windows key, macOS: option
43 };
44 
45 struct MouseEvent {
47 
48  static MouseEvent MakeMoveEvent(const Type type,
49  const int x,
50  const int y,
51  const int modifiers,
52  const int buttons);
53 
54  static MouseEvent MakeButtonEvent(const Type type,
55  const int x,
56  const int y,
57  const int modifiers,
58  const MouseButton button,
59  const int count);
60 
61  static MouseEvent MakeWheelEvent(const Type type,
62  const int x,
63  const int y,
64  const int modifiers,
65  const float dx,
66  const float dy,
67  const bool isTrackpad);
68 
70  int x;
71  int y;
72  int modifiers; // KeyModifiers ORed together
73  union {
74  struct {
75  int buttons; // MouseButtons ORed together
76  } move; // includes drag
77  struct {
79  int count;
80  } button;
81  struct {
82  float dx; // macOS gives fractional values, and is required
83  float dy; // for the buttery-smooth trackpad scrolling on macOS
84  bool isTrackpad;
85  } wheel;
86  };
87 
88  bool FromJson(const Json::Value &value);
89  std::string ToString() const;
90 };
91 
92 struct TickEvent {
93  double dt;
94 };
95 
96 enum KeyName {
97  KEY_NONE = 0,
99  KEY_TAB = 9,
100  KEY_ENTER = 10,
102  KEY_SPACE = 32,
105  KEY_HASH = 35,
113  KEY_PLUS = 43,
114  KEY_COMMA = 44,
115  KEY_MINUS = 45,
117  KEY_SLASH = 47,
118  KEY_0 = 48,
128  KEY_COLON = 58,
134  KEY_AT = 64,
138  KEY_CARET = 94,
141  KEY_A = 97,
168  KEY_PIPE = 124,
170  KEY_TILDE = 126,
171  KEY_DELETE = 127,
172  KEY_LSHIFT = 256,
188  KEY_F1 = 290,
200  KEY_UNKNOWN = 1000
201 };
202 
203 struct KeyEvent {
204  enum Type { DOWN, UP };
206  // This is the actual key that was pressed, not the character that
207  // was generated (use TextInputEvent for that). Values correspond
208  // to ASCII values where applicable.
209  uint32_t key;
210  bool isRepeat;
211 };
212 
214  const char *utf8;
215 };
216 
217 } // namespace gui
218 } // namespace visualization
219 } // namespace cloudViewer
Generic file read and write utility for python interface.
struct cloudViewer::visualization::gui::MouseEvent::@17::@21 wheel
bool FromJson(const Json::Value &value)
Definition: Events.cpp:70
struct cloudViewer::visualization::gui::MouseEvent::@17::@19 move
static MouseEvent MakeWheelEvent(const Type type, const int x, const int y, const int modifiers, const float dx, const float dy, const bool isTrackpad)
Definition: Events.cpp:169
static MouseEvent MakeButtonEvent(const Type type, const int x, const int y, const int modifiers, const MouseButton button, const int count)
Definition: Events.cpp:153
static MouseEvent MakeMoveEvent(const Type type, const int x, const int y, const int modifiers, const int buttons)
Definition: Events.cpp:139