Fillwave  10.0.0
Event.h
1 #pragma once
2 
3 /*
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2018 Filip Wasil and Fillwave community members
7  *
8  * Permission is hereby granted, free of charge, to any person
9  * obtaining a copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
12  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
24 namespace flw {
25 namespace flf {
26 
27 enum class EEventType {
28  mouseButton
29  , cursorPosition
30  , cursorEnter
31  , scroll
32  , key
33  , character
34  , characterMods
35  , time
36  , touch
37  , resizeScreen
38  , custom
39 };
40 
42  int direction;
43 };
44 
46  double xPosition;
47  double yPosition;
48 };
49 
51  int key;
52  int scanCode;
53  int action;
54  int mode;
55 };
56 
58  float whereX;
59  float whereY;
60  int button;
61  int action;
62  int mods;
63 };
64 
66  double offsetX;
67  double offsetY;
68 };
69 
71  unsigned int character;
72 };
73 
75  unsigned int width;
76  unsigned int height;
77 };
78 
80  int xPos;
81  int yPos;
82  int action;
83 };
84 
85 struct TimeEventData {
86  float timePassed;
87 };
88 
90  float* dataFloat;
91  int* dataInt;
92  unsigned int* dataUint;
93  char* dataChar;
94  unsigned int size;
95 };
96 
97 union EventData {
98  CursorEnterEventData mCursorEnter;
99  CursorPositionEventData mCursorPosition;
100  KeyboardEventData mKey;
101  MouseButtonEventData mMouseButton;
102  MouseScrollEventData mMouseScroll;
103  CharacterEventData mChar;
104  ResizeScreenEventData mResize;
105  TouchEventData mTouch;
106  TimeEventData mTime;
107  CustomEventData mCustom;
108 
109  operator CursorEnterEventData () const {
110  return mCursorEnter;
111  }
112 
113  operator CursorPositionEventData () const {
114  return mCursorPosition;
115  }
116 
117  operator KeyboardEventData () const {
118  return mKey;
119  }
120 
121  operator MouseButtonEventData () const {
122  return mMouseButton;
123  }
124 
125  operator MouseScrollEventData () const {
126  return mMouseScroll;
127  }
128 
129  operator CharacterEventData () const {
130  return mChar;
131  }
132 
133  operator ResizeScreenEventData () const {
134  return mResize;
135  }
136 
137  operator TouchEventData () const {
138  return mTouch;
139  }
140 
141  operator TimeEventData () const {
142  return mTime;
143  }
144 
145  operator CustomEventData () const {
146  return mCustom;
147  }
148 };
149 
154 class Event {
155  public:
156  Event(EEventType type, EventData data)
157  : mType(type)
158  , mData(data) {
159  // nothing
160  }
161 
162  EEventType getType() const {
163  return mType;
164  }
165 
166  EventData getData() const {
167  return mData;
168  }
169 
170  private:
171  EEventType mType;
172  EventData mData;
173 };
174 
175 } /* flf */
176 } /* flw */
Definition: Aliases.h:30
Definition: Event.h:65
Definition: Event.h:45
Definition: Event.h:85
Definition: Event.h:50
Definition: Event.h:74
Definition: Event.h:89
Event.
Definition: Event.h:154
Definition: Event.h:97
Definition: Event.h:57
Definition: Event.h:41
Definition: Event.h:70
Definition: Event.h:79