@@ -91,8 +91,6 @@ void CInput::KeyUpdate()
9191 if (b_altF4)
9292 return ;
9393
94- bool b_dik_pause_was_pressed = false ;
95-
9694 const Uint8* state = SDL_GetKeyboardState (NULL );
9795#ifndef _EDITOR
9896 bool b_alt_tab = false ;
@@ -107,34 +105,15 @@ void CInput::KeyUpdate()
107105 SDL_PushEvent (&ev);
108106 }
109107#endif
110- if (b_altF4)
111- return ;
112108
113109#ifndef _EDITOR
114110 if (Device.dwPrecacheFrame == 0 )
115111#endif
116112 {
117- for (u32 i = 0 ; i < COUNT_KB_BUTTONS; i++)
118- {
119- if (state[i])
120- cbStack.back ()->IR_OnKeyboardPress (i);
121- else
122- {
123- cbStack.back ()->IR_OnKeyboardRelease (i);
124113#ifndef _EDITOR
125- if (SDL_SCANCODE_TAB == state[i] &&
126- (iGetAsyncKeyState (SDL_SCANCODE_LALT) || iGetAsyncKeyState (SDL_SCANCODE_RALT)))
127- b_alt_tab = true ;
114+ if (state[SDL_SCANCODE_TAB] && (iGetAsyncKeyState (SDL_SCANCODE_LALT) || iGetAsyncKeyState (SDL_SCANCODE_RALT)))
115+ b_alt_tab = true ;
128116#endif
129- }
130- }
131-
132- for (u32 i = 0 ; i < COUNT_KB_BUTTONS; i++)
133- if (KBState[i] && state[i])
134- cbStack.back ()->IR_OnKeyboardHold (i);
135-
136- for (u32 idx = 0 ; idx < COUNT_KB_BUTTONS; idx++)
137- KBState[idx] = state[idx];
138117 }
139118
140119#ifndef _EDITOR
@@ -188,73 +167,6 @@ void CInput::ClipCursor(bool clip)
188167 }
189168}
190169
191- void CInput::MouseUpdate (SDL_Event* event)
192- {
193- #ifndef _EDITOR
194- if (Device.dwPrecacheFrame )
195- return ;
196- #endif
197- BOOL mouse_prev[COUNT_MOUSE_BUTTONS];
198-
199- offs[0 ] = offs[1 ] = offs[2 ] = 0 ;
200-
201- switch (event->type )
202- {
203- case SDL_MOUSEMOTION:
204- {
205- offs[0 ] += event->motion .xrel ;
206- offs[1 ] += event->motion .yrel ;
207- timeStamp[0 ] = event->motion .timestamp ;
208- timeStamp[1 ] = event->motion .timestamp ;
209- if (offs[0 ] || offs[1 ])
210- cbStack.back ()->IR_OnMouseMove (offs[0 ], offs[1 ]);
211- }
212- break ;
213- case SDL_MOUSEBUTTONUP:
214- mouseState[event->button .button ] = FALSE ;
215- cbStack.back ()->IR_OnKeyboardRelease (SDL_NUM_SCANCODES + event->button .button );
216- break ;
217- case SDL_MOUSEBUTTONDOWN:
218- mouseState[event->button .button ] = TRUE ;
219- cbStack.back ()->IR_OnKeyboardPress (SDL_NUM_SCANCODES + event->button .button );
220- break ;
221- case SDL_MOUSEWHEEL:
222- offs[2 ] += event->wheel .direction ;
223- timeStamp[2 ] = event->wheel .timestamp ;
224- if (offs[2 ])
225- cbStack.back ()->IR_OnMouseWheel (offs[2 ]);
226- break ;
227- default :
228- if (timeStamp[1 ] && ((dwCurTime - timeStamp[1 ]) >= 25 ))
229- cbStack.back ()->IR_OnMouseStop (1 , timeStamp[1 ] = 0 );
230- if (timeStamp[0 ] && ((dwCurTime - timeStamp[0 ]) >= 25 ))
231- cbStack.back ()->IR_OnMouseStop (0 , timeStamp[0 ] = 0 );
232- break ;
233- }
234-
235- auto isButtonOnHold = [&](int i) {
236- if (mouseState[i] && mouse_prev[i])
237- cbStack.back ()->IR_OnMouseHold (i);
238- };
239-
240- isButtonOnHold (0 );
241- isButtonOnHold (1 );
242- isButtonOnHold (2 );
243- isButtonOnHold (3 );
244- isButtonOnHold (4 );
245- isButtonOnHold (5 );
246- isButtonOnHold (6 );
247-
248- mouse_prev[0 ] = mouseState[0 ];
249- mouse_prev[1 ] = mouseState[1 ];
250- mouse_prev[2 ] = mouseState[2 ];
251- mouse_prev[3 ] = mouseState[3 ];
252- mouse_prev[4 ] = mouseState[4 ];
253- mouse_prev[5 ] = mouseState[5 ];
254- mouse_prev[6 ] = mouseState[6 ];
255- mouse_prev[7 ] = mouseState[7 ];
256- }
257-
258170// -------------------------------------------------------
259171void CInput::iCapture (IInputReceiver* p)
260172{
@@ -331,25 +243,64 @@ void CInput::OnFrame(void)
331243
332244 while (SDL_PollEvent (&event))
333245 {
246+ #ifndef _EDITOR
247+ if (Device.dwPrecacheFrame )
248+ continue ;
249+ #endif
334250 BOOL b_break_cycle = false ;
335251 switch (event.type )
336252 {
337253 case SDL_KEYDOWN:
338- case SDL_KEYUP: KeyUpdate (); continue ;
254+ {
255+ cbStack.back ()->IR_OnKeyboardPress (event.key .keysym .scancode );
339256
257+ if (0 != event.key .repeat )
258+ cbStack.back ()->IR_OnKeyboardHold (event.key .keysym .scancode );
259+
260+ KBState[event.key .keysym .scancode ] = TRUE ;
261+ }
262+ break ;
263+ case SDL_KEYUP:
264+ {
265+ cbStack.back ()->IR_OnKeyboardRelease (event.key .keysym .scancode );
266+ KBState[event.key .keysym .scancode ] = FALSE ;
267+ }
268+ break ;
340269 case SDL_MOUSEMOTION:
270+ {
271+ timeStamp[0 ] = event.motion .timestamp ;
272+ timeStamp[1 ] = event.motion .timestamp ;
273+ cbStack.back ()->IR_OnMouseMove (event.motion .xrel , event.motion .yrel );
274+ }
275+ break ;
341276 case SDL_MOUSEBUTTONUP:
277+ {
278+ cbStack.back ()->IR_OnMouseRelease (event.button .button );
279+ mouseState[event.button .button ] = FALSE ;
280+ }
281+ break ;
342282 case SDL_MOUSEBUTTONDOWN:
283+ {
284+ cbStack.back ()->IR_OnMousePress (event.button .button );
285+
286+ if (mouseState[event.button .button ])
287+ cbStack.back ()->IR_OnMouseHold (event.button .button );
288+
289+ mouseState[event.button .button ] = TRUE ;
290+ }
291+ break ;
343292 case SDL_MOUSEWHEEL:
344- MouseUpdate (&event);
345- continue ;
293+ {
294+ timeStamp[2 ] = event.wheel .timestamp ;
295+ cbStack.back ()->IR_OnMouseWheel (event.wheel .direction );
296+ }
297+ break ;
346298 case SDL_QUIT: // go to outside event loop
347299 event.type = SDL_QUIT;
348300 SDL_PushEvent (&event);
349301 b_break_cycle = TRUE ;
350302 break ;
351-
352- default : continue ;
303+ default : break ;
353304 }
354305
355306 if (b_break_cycle)
0 commit comments