@@ -53,29 +53,20 @@ struct SdlHost :
53
53
break ;
54
54
55
55
case SDL_KEYDOWN: {
56
- Events::KeyboardEvent uiEvent{
57
- .type = Events::KeyboardEvent::PRESS,
58
- };
59
- event (uiEvent);
56
+ event<Events::TypedEvent>(*this , Events::KeyboardEvent::PRESS);
60
57
break ;
61
58
}
62
59
63
60
case SDL_KEYUP: {
64
- Events::KeyboardEvent uiEvent{
65
- .type = Events::KeyboardEvent::RELEASE,
66
- };
67
- event (uiEvent);
61
+ event<Events::TypedEvent>(*this , Events::KeyboardEvent::RELEASE);
68
62
break ;
69
63
}
70
64
71
65
case SDL_TEXTINPUT: {
72
66
Str text = sdlEvent.text .text ;
73
67
for (u8 c : iterRunes (text)) {
74
- Events::TypedEvent uiEvent{
75
- .codepoint = c,
76
- };
77
68
logInfo (" typed: {c}" , c);
78
- event (uiEvent );
69
+ event<Events::TypedEvent>(* this , c );
79
70
}
80
71
break ;
81
72
}
@@ -88,21 +79,24 @@ struct SdlHost :
88
79
Math::Vec2<i32> screenPos = {};
89
80
SDL_GetGlobalMouseState (&screenPos.x , &screenPos.y );
90
81
91
- Events::MouseEvent uiEvent{
92
- .type = Events::MouseEvent::MOVE,
82
+ Events::Button buttons = Events::Button ::NONE;
83
+ buttons |= (sdlEvent.motion .state & SDL_BUTTON_LMASK) ? Events::Button ::LEFT : Events::Button ::NONE;
84
+ buttons |= (sdlEvent.motion .state & SDL_BUTTON_MMASK) ? Events::Button ::MIDDLE : Events::Button ::NONE;
85
+ buttons |= (sdlEvent.motion .state & SDL_BUTTON_RMASK) ? Events::Button ::RIGHT : Events::Button ::NONE;
93
86
94
- .pos = {sdlEvent.motion .x , sdlEvent.motion .y },
95
- .delta = screenPos - _lastScreenMousePos,
96
- };
87
+ _lastMousePos = {sdlEvent.motion .x , sdlEvent.motion .y };
97
88
98
- uiEvent.buttons |= (sdlEvent.motion .state & SDL_BUTTON_LMASK) ? Events::Button ::LEFT : Events::Button ::NONE;
99
- uiEvent.buttons |= (sdlEvent.motion .state & SDL_BUTTON_MMASK) ? Events::Button ::MIDDLE : Events::Button ::NONE;
100
- uiEvent.buttons |= (sdlEvent.motion .state & SDL_BUTTON_RMASK) ? Events::Button ::RIGHT : Events::Button ::NONE;
89
+ event<Events::MouseEvent>(
90
+ *this ,
91
+ Events::MouseEvent{
92
+ .type = Events::MouseEvent::MOVE,
93
+ .pos = _lastMousePos,
94
+ .delta = screenPos - _lastScreenMousePos,
95
+ .buttons = buttons,
96
+ });
101
97
102
- _lastMousePos = uiEvent.pos ;
103
98
_lastScreenMousePos = screenPos.cast <isize>();
104
99
105
- event (uiEvent);
106
100
break ;
107
101
}
108
102
@@ -111,20 +105,28 @@ struct SdlHost :
111
105
return ;
112
106
}
113
107
114
- Events::MouseEvent uiEvent{
115
- .type = Events::MouseEvent::RELEASE,
116
- .pos = _lastMousePos,
117
- };
118
-
119
- uiEvent.button = (sdlEvent.button .which == SDL_BUTTON_LEFT) ? Events::Button ::LEFT : Events::Button ::NONE;
120
- uiEvent.button = (sdlEvent.button .which == SDL_BUTTON_RIGHT) ? Events::Button ::MIDDLE : Events::Button ::NONE;
121
- uiEvent.button = (sdlEvent.button .which == SDL_BUTTON_MIDDLE) ? Events::Button ::RIGHT : Events::Button ::NONE;
122
-
123
- uiEvent.buttons |= (sdlEvent.button .state & SDL_BUTTON_LMASK) ? Events::Button ::LEFT : Events::Button ::NONE;
124
- uiEvent.buttons |= (sdlEvent.button .state & SDL_BUTTON_MMASK) ? Events::Button ::MIDDLE : Events::Button ::NONE;
125
- uiEvent.buttons |= (sdlEvent.button .state & SDL_BUTTON_RMASK) ? Events::Button ::RIGHT : Events::Button ::NONE;
108
+ Events::Button buttons = Events::Button ::NONE;
109
+ buttons |= (sdlEvent.motion .state & SDL_BUTTON_LMASK) ? Events::Button ::LEFT : Events::Button ::NONE;
110
+ buttons |= (sdlEvent.motion .state & SDL_BUTTON_MMASK) ? Events::Button ::MIDDLE : Events::Button ::NONE;
111
+ buttons |= (sdlEvent.motion .state & SDL_BUTTON_RMASK) ? Events::Button ::RIGHT : Events::Button ::NONE;
112
+
113
+ Events::Button button = Events::Button ::NONE;
114
+ if (sdlEvent.button .button == SDL_BUTTON_LEFT) {
115
+ button = Events::Button ::LEFT;
116
+ } else if (sdlEvent.button .button == SDL_BUTTON_RIGHT) {
117
+ button = Events::Button ::RIGHT;
118
+ } else if (sdlEvent.button .button == SDL_BUTTON_MIDDLE) {
119
+ button = Events::Button ::MIDDLE;
120
+ }
126
121
127
- event (uiEvent);
122
+ event<Events::MouseEvent>(
123
+ *this ,
124
+ Events::MouseEvent{
125
+ .type = Events::MouseEvent::RELEASE,
126
+ .pos = _lastMousePos,
127
+ .buttons = buttons,
128
+ .button = button,
129
+ });
128
130
break ;
129
131
}
130
132
@@ -133,20 +135,28 @@ struct SdlHost :
133
135
return ;
134
136
}
135
137
136
- Events::MouseEvent uiEvent{
137
- .type = Events::MouseEvent::PRESS,
138
- .pos = _lastMousePos,
139
- };
140
-
141
- uiEvent.button = (sdlEvent.button .button == SDL_BUTTON_LEFT) ? Events::Button ::LEFT : Events::Button ::NONE;
142
- uiEvent.button = (sdlEvent.button .button == SDL_BUTTON_RIGHT) ? Events::Button ::MIDDLE : Events::Button ::NONE;
143
- uiEvent.button = (sdlEvent.button .button == SDL_BUTTON_MIDDLE) ? Events::Button ::RIGHT : Events::Button ::NONE;
144
-
145
- uiEvent.buttons |= (sdlEvent.button .state & SDL_BUTTON_LMASK) ? Events::Button ::LEFT : Events::Button ::NONE;
146
- uiEvent.buttons |= (sdlEvent.button .state & SDL_BUTTON_MMASK) ? Events::Button ::MIDDLE : Events::Button ::NONE;
147
- uiEvent.buttons |= (sdlEvent.button .state & SDL_BUTTON_RMASK) ? Events::Button ::RIGHT : Events::Button ::NONE;
138
+ Events::Button buttons = Events::Button ::NONE;
139
+ buttons |= (sdlEvent.motion .state & SDL_BUTTON_LMASK) ? Events::Button ::LEFT : Events::Button ::NONE;
140
+ buttons |= (sdlEvent.motion .state & SDL_BUTTON_MMASK) ? Events::Button ::MIDDLE : Events::Button ::NONE;
141
+ buttons |= (sdlEvent.motion .state & SDL_BUTTON_RMASK) ? Events::Button ::RIGHT : Events::Button ::NONE;
142
+
143
+ Events::Button button = Events::Button ::NONE;
144
+ if (sdlEvent.button .button == SDL_BUTTON_LEFT) {
145
+ button = Events::Button ::LEFT;
146
+ } else if (sdlEvent.button .button == SDL_BUTTON_RIGHT) {
147
+ button = Events::Button ::RIGHT;
148
+ } else if (sdlEvent.button .button == SDL_BUTTON_MIDDLE) {
149
+ button = Events::Button ::MIDDLE;
150
+ }
148
151
149
- event (uiEvent);
152
+ event<Events::MouseEvent>(
153
+ *this ,
154
+ Events::MouseEvent{
155
+ .type = Events::MouseEvent::PRESS,
156
+ .pos = _lastMousePos,
157
+ .buttons = buttons,
158
+ .button = button,
159
+ });
150
160
break ;
151
161
}
152
162
@@ -155,32 +165,27 @@ struct SdlHost :
155
165
return ;
156
166
}
157
167
158
- Events::MouseEvent uiEvent{
159
- .type = Events::MouseEvent::SCROLL,
160
- .pos = _lastMousePos,
161
- .scrollLines = {
162
- sdlEvent.wheel .x ,
163
- sdlEvent.wheel .y ,
164
- },
165
- .scrollPrecise = {
168
+ event<Events::MouseEvent>(
169
+ *this ,
170
+ Events::MouseEvent{
171
+ .type = Events::MouseEvent::SCROLL,
172
+ .pos = _lastMousePos,
173
+ .scroll = {
166
174
#if SDL_VERSION_ATLEAST(2, 0, 18)
167
- sdlEvent.wheel .preciseX ,
168
- sdlEvent.wheel .preciseY ,
175
+ sdlEvent.wheel .preciseX ,
176
+ sdlEvent.wheel .preciseY ,
169
177
#else
170
- (f64)sdlEvent.wheel .x ,
171
- (f64)sdlEvent.wheel .y ,
178
+ (f64)sdlEvent.wheel .x ,
179
+ (f64)sdlEvent.wheel .y ,
172
180
#endif
173
- },
174
- };
175
-
176
- event (uiEvent);
181
+ },
182
+ });
177
183
178
184
break ;
179
185
}
180
186
181
187
case SDL_QUIT: {
182
- Events::ExitEvent uiEvent{Ok ()};
183
- bubble (uiEvent);
188
+ bubble<Events::ExitEvent>(*this , Ok ());
184
189
break ;
185
190
}
186
191
@@ -189,7 +194,8 @@ struct SdlHost :
189
194
}
190
195
}
191
196
192
- void pump () override {
197
+ void
198
+ pump () override {
193
199
SDL_Event e{};
194
200
195
201
while (SDL_PollEvent (&e) != 0 and alive ()) {
@@ -201,7 +207,7 @@ struct SdlHost :
201
207
SDL_WaitEventTimeout (nullptr , span.toMSecs ());
202
208
}
203
209
204
- void bubble (Events ::Event &e) override {
210
+ void bubble (Async ::Event &e) override {
205
211
if (e.is <Ui::DragEvent>()) {
206
212
auto &dragEvent = e.unwrap <Ui::DragEvent>();
207
213
if (dragEvent.type == Ui::DragEvent::START) {
0 commit comments