1 // SHE library 2 // Copyright (C) 2012-2018 David Capello 3 // 4 // This file is released under the terms of the MIT license. 5 // Read LICENSE.txt for more information. 6 7 #ifndef SHE_EVENT_H_INCLUDED 8 #define SHE_EVENT_H_INCLUDED 9 #pragma once 10 11 #include "base/paths.h" 12 #include "gfx/point.h" 13 #include "gfx/size.h" 14 #include "she/keys.h" 15 #include "she/pointer_type.h" 16 17 #pragma push_macro("None") 18 #undef None // Undefine the X11 None macro 19 20 namespace she { 21 22 class Display; 23 24 class Event { 25 public: 26 enum Type { 27 None, 28 CloseDisplay, 29 ResizeDisplay, 30 DropFiles, 31 MouseEnter, 32 MouseLeave, 33 MouseMove, 34 MouseDown, 35 MouseUp, 36 MouseWheel, 37 MouseDoubleClick, 38 KeyDown, 39 KeyUp, 40 TouchMagnify, 41 }; 42 43 enum MouseButton { 44 NoneButton, 45 LeftButton, 46 RightButton, 47 MiddleButton, 48 X1Button, 49 X2Button, 50 }; 51 Event()52 Event() : m_type(None), 53 m_display(nullptr), 54 m_scancode(kKeyNil), 55 m_modifiers(kKeyUninitializedModifier), 56 m_unicodeChar(0), 57 m_isDead(false), 58 m_repeat(0), 59 m_preciseWheel(false), 60 m_pointerType(PointerType::Unknown), 61 m_button(NoneButton), 62 m_magnification(0.0), 63 m_pressure(0.0) { 64 } 65 type()66 Type type() const { return m_type; } display()67 Display* display() const { return m_display; } files()68 const base::paths& files() const { return m_files; } 69 // TODO Rename this to virtualKey(), which is the real 70 // meaning. Then we need another kind of "scan code" with the 71 // position in the keyboard, which might be useful to identify 72 // keys by its position (e.g. WASD keys in other keyboard 73 // layouts). scancode()74 KeyScancode scancode() const { return m_scancode; } modifiers()75 KeyModifiers modifiers() const { return m_modifiers; } unicodeChar()76 int unicodeChar() const { return m_unicodeChar; } isDeadKey()77 bool isDeadKey() const { return m_isDead; } repeat()78 int repeat() const { return m_repeat; } position()79 gfx::Point position() const { return m_position; } wheelDelta()80 gfx::Point wheelDelta() const { return m_wheelDelta; } 81 82 // We suppose that if we are receiving precise scrolling deltas, 83 // it means that the user is using a touch-like surface (trackpad, 84 // magic mouse scrolling, touch wacom tablet, etc.) preciseWheel()85 bool preciseWheel() const { return m_preciseWheel; } 86 pointerType()87 PointerType pointerType() const { return m_pointerType; } button()88 MouseButton button() const { return m_button; } magnification()89 double magnification() const { return m_magnification; } pressure()90 double pressure() const { return m_pressure; } 91 setType(Type type)92 void setType(Type type) { m_type = type; } setDisplay(Display * display)93 void setDisplay(Display* display) { m_display = display; } setFiles(const base::paths & files)94 void setFiles(const base::paths& files) { m_files = files; } 95 setScancode(KeyScancode scancode)96 void setScancode(KeyScancode scancode) { m_scancode = scancode; } setModifiers(KeyModifiers modifiers)97 void setModifiers(KeyModifiers modifiers) { m_modifiers = modifiers; } setUnicodeChar(int unicodeChar)98 void setUnicodeChar(int unicodeChar) { m_unicodeChar = unicodeChar; } setDeadKey(bool state)99 void setDeadKey(bool state) { m_isDead = state; } setRepeat(int repeat)100 void setRepeat(int repeat) { m_repeat = repeat; } setPosition(const gfx::Point & pos)101 void setPosition(const gfx::Point& pos) { m_position = pos; } setWheelDelta(const gfx::Point & delta)102 void setWheelDelta(const gfx::Point& delta) { m_wheelDelta = delta; } setPreciseWheel(bool precise)103 void setPreciseWheel(bool precise) { m_preciseWheel = precise; } setPointerType(PointerType pointerType)104 void setPointerType(PointerType pointerType) { m_pointerType = pointerType; } setButton(MouseButton button)105 void setButton(MouseButton button) { m_button = button; } setMagnification(double magnification)106 void setMagnification(double magnification) { m_magnification = magnification; } setPressure(double pressure)107 void setPressure(double pressure) { m_pressure = pressure; } 108 109 private: 110 Type m_type; 111 Display* m_display; 112 base::paths m_files; 113 KeyScancode m_scancode; 114 KeyModifiers m_modifiers; 115 int m_unicodeChar; 116 bool m_isDead; 117 int m_repeat; // repeat=0 means the first time the key is pressed 118 gfx::Point m_position; 119 gfx::Point m_wheelDelta; 120 bool m_preciseWheel; 121 PointerType m_pointerType; 122 MouseButton m_button; 123 124 // For TouchMagnify event 125 double m_magnification; 126 127 // Pressure of stylus used in mouse-like events 128 double m_pressure; 129 }; 130 131 } // namespace she 132 133 #pragma pop_macro("None") 134 135 #endif 136