1 module rpui.events; 2 3 import rpui.math; 4 import rpui.input; 5 import rpui.primitives; 6 7 struct ProgressEvent { 8 float deltaTime; 9 } 10 11 struct CreateEvent { 12 } 13 14 struct KeyPressedEvent { 15 KeyCode key; 16 } 17 18 struct KeyReleasedEvent { 19 KeyCode key; 20 } 21 22 struct TextEnteredEvent { 23 utf32char key; 24 } 25 26 struct ChangeEvent { 27 } 28 29 struct MouseDownEvent { 30 uint x; 31 uint y; 32 MouseButton button; 33 } 34 35 struct MouseUpEvent { 36 uint x; 37 uint y; 38 MouseButton button; 39 } 40 41 struct DblClickEvent { 42 uint x; 43 uint y; 44 MouseButton button; 45 } 46 47 struct TripleClickEvent { 48 uint x; 49 uint y; 50 MouseButton button; 51 } 52 53 struct MouseMoveEvent { 54 int x; 55 int y; 56 MouseButton button; 57 } 58 59 struct MouseWheelEvent { 60 int dx; 61 int dy; 62 } 63 64 struct WindowResizeEvent { 65 uint width; 66 uint height; 67 } 68 69 struct WindowExposedEvent { 70 } 71 72 struct CopyCommand { 73 } 74 75 struct PasteCommand { 76 } 77 78 struct CutCommand { 79 } 80 81 struct UnselectCommand { 82 } 83 84 struct SelectAllCommand { 85 } 86 87 const windowEvents = [ 88 typeid(KeyPressedEvent), 89 typeid(KeyReleasedEvent), 90 typeid(TextEnteredEvent), 91 typeid(MouseDownEvent), 92 typeid(MouseUpEvent), 93 typeid(DblClickEvent), 94 typeid(TripleClickEvent), 95 typeid(MouseMoveEvent), 96 typeid(MouseWheelEvent), 97 typeid(WindowResizeEvent), 98 typeid(WindowExposedEvent), 99 ]; 100 101 const commands = [ 102 typeid(CopyCommand), 103 typeid(CutCommand), 104 typeid(PasteCommand), 105 typeid(UnselectCommand), 106 typeid(SelectAllCommand), 107 ]; 108 109 interface EventsListener { 110 void onKeyPressed(in KeyPressedEvent event); 111 void onKeyReleased(in KeyReleasedEvent event); 112 void onTextEntered(in TextEnteredEvent event); 113 void onMouseDown(in MouseDownEvent event); 114 void onMouseUp(in MouseUpEvent event); 115 void onDblClick(in DblClickEvent event); 116 void onTripleClick(in TripleClickEvent event); 117 void onMouseMove(in MouseMoveEvent event); 118 void onMouseWheel(in MouseWheelEvent event); 119 void onWindowResize(in WindowResizeEvent event); 120 void onWindowExposed(in WindowExposedEvent event); 121 } 122 123 abstract class EventsListenerEmpty : EventsListener { 124 void onKeyPressed(in KeyPressedEvent event) {} 125 void onKeyReleased(in KeyReleasedEvent event) {} 126 void onTextEntered(in TextEnteredEvent event) {} 127 void onMouseDown(in MouseDownEvent event) {} 128 void onMouseUp(in MouseUpEvent event) {} 129 void onDblClick(in DblClickEvent event) {} 130 void onTripleClick(in TripleClickEvent event) {} 131 void onMouseMove(in MouseMoveEvent event) {} 132 void onMouseWheel(in MouseWheelEvent event) {} 133 void onWindowResize(in WindowResizeEvent event) {} 134 void onWindowExposed(in WindowExposedEvent event) {} 135 }