1 /** 2 Copyright: Copyright (c) 2017-2018 Andrey Penechko. 3 License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0). 4 Authors: Andrey Penechko. 5 */ 6 7 module voxelman.gui.events; 8 9 import voxelman.graphics : RenderQueue; 10 import voxelman.gui; 11 import voxelman.math; 12 public import voxelman.platform.input : KeyCode, PointerButton, KeyModifiers; 13 14 15 mixin template GuiEvent() 16 { 17 /// If this flag is set - event propagates from root widget to target widget 18 /// otherwise it is bubbling from target to root 19 bool sinking = true; 20 bool bubbling() { return !sinking; } 21 bool bubbling(bool newBubbling) { return sinking = !newBubbling; } 22 23 /// Specifies if event was already handled. 24 /// Useful for checking if any child has handled this event. 25 /// Set automatically by EventPropagator 26 bool handled; 27 } 28 29 struct GuiUpdateEvent 30 { 31 double deltaTime; 32 mixin GuiEvent!(); 33 } 34 35 struct DrawEvent 36 { 37 RenderQueue renderQueue; 38 int depth; 39 mixin GuiEvent!(); 40 } 41 42 private mixin template PointerButtonEvent() 43 { 44 import voxelman.platform.input : PointerButton; 45 ivec2 pointerPosition; 46 PointerButton button; 47 mixin ModifiersMixin!(); 48 mixin GuiEvent!(); 49 } 50 51 struct PointerPressEvent { 52 mixin PointerButtonEvent!(); 53 /// If event consumer sets this to true, then context will begin dragging 54 bool beginDrag; 55 } 56 struct PointerReleaseEvent { mixin PointerButtonEvent!(); } 57 struct PointerClickEvent { mixin PointerButtonEvent!(); } 58 struct PointerDoubleClickEvent { mixin PointerButtonEvent!(); } 59 struct PointerMoveEvent { 60 ivec2 newPointerPos; 61 ivec2 delta; 62 mixin GuiEvent!(); 63 } 64 struct ScrollEvent { 65 vec2 delta; 66 mixin GuiEvent!(); 67 } 68 69 struct DragEvent { ivec2 delta; mixin GuiEvent!(); } 70 struct DragBeginEvent { mixin GuiEvent!(); } 71 struct DragEndEvent { mixin GuiEvent!(); } 72 73 // Keyboard 74 struct CharEnterEvent 75 { 76 dchar character; 77 mixin GuiEvent!(); 78 } 79 80 private mixin template ModifiersMixin() 81 { 82 uint modifiers; // flags from KeyModifiers 83 bool shift() { return cast(bool)(modifiers & KeyModifiers.SHIFT); } 84 bool control() { return cast(bool)(modifiers & KeyModifiers.CONTROL); } 85 bool alt() { return cast(bool)(modifiers & KeyModifiers.ALT); } 86 } 87 88 private mixin template KeyEvent() 89 { 90 KeyCode keyCode; 91 mixin ModifiersMixin!(); 92 mixin GuiEvent!(); 93 } 94 95 struct KeyPressEvent { mixin KeyEvent!(); } 96 struct KeyReleaseEvent { mixin KeyEvent!(); } 97 98 // Hovering 99 struct PointerEnterEvent { mixin GuiEvent!(); } 100 struct PointerLeaveEvent { mixin GuiEvent!(); } 101 102 // Focus 103 struct FocusGainEvent { mixin GuiEvent!(); } 104 struct FocusLoseEvent { mixin GuiEvent!(); } 105 106 // Layout 107 struct MeasureEvent {} 108 struct LayoutEvent {} 109 110 // Misc 111 struct GroupSelectionEvent 112 { 113 WidgetId selected; 114 mixin GuiEvent!(); 115 }