Oolite
Loading...
Searching...
No Matches
MyOpenGLView(Input) Category Reference

#include <MyOpenGLView+Input.h>

Instance Methods

(void) - autoShowMouse
(void) - initKeyMappingData
(void) - setStringInput:
(void) - allowStringInput:
(enum StringInput) - allowingStringInput
(NSString *) - typedString
(void) - resetTypedString
(void) - setTypedString:
(void) - noteMouseInteractionModeChangedFrom:to:
(void) - pollControls
(void) - setVirtualJoystick:vmy:
(NSPoint) - virtualJoystickPosition
(void) - clearKeys
(void) - clearMouse
(void) - clearKey:
(void) - resetMouse
(BOOL) - isAlphabetKeyDown
(void) - suppressKeysUntilKeyUp
(BOOL) - isDown:
(BOOL) - isOptDown
(BOOL) - isCtrlDown
(BOOL) - isCommandDown
(BOOL) - isShiftDown
(BOOL) - isCapsLockOn
(BOOL) - lastKeyWasShifted
(int) - numKeys
(int) - mouseWheelState
(float) - mouseWheelDelta
(void) - setMouseWheelDelta:
(BOOL) - isCommandQDown
(BOOL) - isCommandFDown
(void) - clearCommandF
(void) - setMouseInDeltaMode:
(void) - handleStringInput:keyID:

Detailed Description

Definition at line 28 of file MyOpenGLView+Input.h.

Method Documentation

◆ allowingStringInput

- (enum StringInput) allowingStringInput

Extends class MyOpenGLView.

Definition at line 70 of file MyOpenGLView+Input.m.

71{
73}
enum StringInput allowingStringInput()

References allowingStringInput.

Referenced by allowingStringInput, allowStringInput:, handleStringInput:keyID:, MyOpenGLView::init, pollControls, and setStringInput:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ allowStringInput:

- (void) allowStringInput: (BOOL) value

Extends class MyOpenGLView.

Definition at line 63 of file MyOpenGLView+Input.m.

63 :(BOOL)value
64{
65 if (value)
67 else
69}
@ gvStringInputAlpha
@ gvStringInputNo

References allowingStringInput, gvStringInputAlpha, and gvStringInputNo.

Here is the call graph for this function:

◆ autoShowMouse

- (void) autoShowMouse

Extends class MyOpenGLView.

Definition at line 48 of file MyOpenGLView+Input.m.

49{
50 // don't touch the 'please wait...' cursor.
51 if (fullScreen) {
52 if (SDL_CursorVisible())
53 SDL_HideCursor();
54 } else {
55 if (!SDL_CursorVisible())
56 SDL_ShowCursor();
57 }
58}

References autoShowMouse.

Referenced by autoShowMouse.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearCommandF

- (void) clearCommandF

Extends class MyOpenGLView.

Definition at line 221 of file MyOpenGLView+Input.m.

222{
223 // SDL stub for the mac function.
224}

References clearCommandF.

Referenced by clearCommandF.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearKey:

- (void) clearKey: (int) theKey

Extends class MyOpenGLView.

Definition at line 115 of file MyOpenGLView+Input.m.

115 :(int)theKey
116{
117 if (theKey >= 0 && theKey < [self numKeys]) {
118 keys[theKey] = NO;
119 }
120}
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque

References numKeys.

Here is the call graph for this function:

◆ clearKeys

- (void) clearKeys

Extends class MyOpenGLView.

Definition at line 102 of file MyOpenGLView+Input.m.

103{
104 int i;
105 lastKeyShifted = NO;
106 for (i = 0; i < [self numKeys]; i++)
107 keys[i] = NO;
108}

References clearKeys, and MyOpenGLView::numKeys.

Referenced by clearKeys.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearMouse

- (void) clearMouse

Extends class MyOpenGLView.

Definition at line 109 of file MyOpenGLView+Input.m.

110{
111 keys[gvMouseDoubleClick] = NO;
112 keys[gvMouseLeftButton] = NO;
113 doubleClick = NO;
114}

References clearMouse.

Referenced by clearMouse.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleStringInput:keyID:

- (void) handleStringInput: (SDL_KeyboardEvent*) kbd_event
keyID: (Uint16) key_id 

Extends class MyOpenGLView.

Definition at line 862 of file MyOpenGLView+Input.m.

862 :(SDL_KeyboardEvent*)kbd_event keyID:(Uint16)key_id
863{
864 SDL_Keycode key = kbd_event->key;
865
866 // Del, Backspace
867 if ((key == SDLK_BACKSPACE || key == SDLK_DELETE) && [typedString length] > 0) {
868 // delete
869 [typedString deleteCharactersInRange:NSMakeRange([typedString length] - 1, 1)];
870 }
871
873
874 // TODO: a more flexible mechanism for max. string length ?
875 if ([typedString length] < 40) {
876 lastKeyShifted = shift;
878 // inputAlpha - limited input for planet find screen
879 if (key >= SDLK_A && key <= SDLK_Z) {
880 isAlphabetKeyDown = YES;
881 [typedString appendFormat:@"%c", key];
882 // if in inputAlpha, keep in lower case.
883 }
884 } else {
885 // Uint16 unicode = kbd_event->keysym.unicode;
886 // printable range
887 if (key_id >= 32 && key_id <= 255) // 126
888 {
889 if ((char)key_id != '/' || allowingStringInput == gvStringInputAll) {
890 isAlphabetKeyDown = YES;
891 [typedString appendFormat:@"%c", key_id];
892 }
893 }
894 }
895 }
896}
@ gvStringInputAll

References allowingStringInput, gvStringInputAll, gvStringInputAlpha, isAlphabetKeyDown, and typedString.

Here is the call graph for this function:

◆ initKeyMappingData

- (void) initKeyMappingData

Extends class MyOpenGLView.

Definition at line 30 of file MyOpenGLView+Input.m.

31{
32 NSUserDefaults* prefs = [NSUserDefaults standardUserDefaults];
33 // load in our keyboard scancode mappings
34#if OOLITE_WINDOWS
35 NSDictionary* kmap = [NSDictionary dictionaryWithDictionary:[ResourceManager dictionaryFromFilesNamed:@"keymappings_windows.plist" inFolder:@"Config" mergeMode:MERGE_BASIC cache:NO]];
36#else
37 NSDictionary* kmap = [NSDictionary dictionaryWithDictionary:[ResourceManager dictionaryFromFilesNamed:@"keymappings_linux.plist" inFolder:@"Config" mergeMode:MERGE_BASIC cache:NO]];
38#endif
39 // get the stored keyboard code from preferences
40 NSString* kbd = [prefs oo_stringForKey:@"keyboard-code" defaultValue:@"default"];
41 NSDictionary* subset = [kmap objectForKey:kbd];
42
43 [keyMappings_normal release];
44 keyMappings_normal = [[subset objectForKey:@"mapping_normal"] copy];
45 [keyMappings_shifted release];
46 keyMappings_shifted = [[subset objectForKey:@"mapping_shifted"] copy];
47}
NSDictionary * dictionaryFromFilesNamed:inFolder:mergeMode:cache:(NSString *fileName,[inFolder] NSString *folderName,[mergeMode] OOResourceMergeMode mergeMode,[cache] BOOL useCache)

References ResourceManager::dictionaryFromFilesNamed:inFolder:mergeMode:cache:, and initKeyMappingData.

Referenced by initKeyMappingData.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isAlphabetKeyDown

- (BOOL) isAlphabetKeyDown

Extends class MyOpenGLView.

Definition at line 133 of file MyOpenGLView+Input.m.

134{
135 return isAlphabetKeyDown = NO;
136 ;
137}

References isAlphabetKeyDown.

Referenced by handleStringInput:keyID:, MyOpenGLView::init, and isAlphabetKeyDown.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isCapsLockOn

- (BOOL) isCapsLockOn

Extends class MyOpenGLView.

Definition at line 178 of file MyOpenGLView+Input.m.

179{
180 /* Caps Lock state check - This effectively gives us
181 an alternate keyboard state to play with and, in
182 the future, we could assign different behaviours
183 to existing controls, depending on the state of
184 Caps Lock. - Nikos 20160304
185 */
186 return (SDL_GetModState() & SDL_KMOD_CAPS) == SDL_KMOD_CAPS;
187}

References isCapsLockOn.

Referenced by isCapsLockOn, and pollControls.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isCommandDown

- (BOOL) isCommandDown

Extends class MyOpenGLView.

Definition at line 170 of file MyOpenGLView+Input.m.

171{
172 return command;
173}

References isCommandDown.

Referenced by isCommandDown.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isCommandFDown

- (BOOL) isCommandFDown

Extends class MyOpenGLView.

Definition at line 217 of file MyOpenGLView+Input.m.

218{
219 return NO;
220}

References isCommandFDown.

Referenced by isCommandFDown.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isCommandQDown

- (BOOL) isCommandQDown

Extends class MyOpenGLView.

Definition at line 213 of file MyOpenGLView+Input.m.

214{
215 return NO;
216}

References isCommandQDown.

Referenced by isCommandQDown.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isCtrlDown

- (BOOL) isCtrlDown

Extends class MyOpenGLView.

Definition at line 166 of file MyOpenGLView+Input.m.

167{
168 return ctrl;
169}

References isCtrlDown.

Referenced by isCtrlDown.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isDown:

- (BOOL) isDown: (int) key

Extends class MyOpenGLView.

Definition at line 152 of file MyOpenGLView+Input.m.

152 :(int)key
153{
154 if (suppressKeys)
155 return NO;
156 if (key < 0)
157 return NO;
158 if (key >= [self numKeys])
159 return NO;
160 return keys[key];
161}

References numKeys.

Here is the call graph for this function:

◆ isOptDown

- (BOOL) isOptDown

Extends class MyOpenGLView.

Definition at line 162 of file MyOpenGLView+Input.m.

163{
164 return opt;
165}

References isOptDown.

Referenced by isOptDown.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isShiftDown

- (BOOL) isShiftDown

Extends class MyOpenGLView.

Definition at line 174 of file MyOpenGLView+Input.m.

175{
176 return shift;
177}

References isShiftDown.

Referenced by isShiftDown.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lastKeyWasShifted

- (BOOL) lastKeyWasShifted

Extends class MyOpenGLView.

Definition at line 188 of file MyOpenGLView+Input.m.

189{
190 return lastKeyShifted;
191}

References lastKeyWasShifted.

Referenced by lastKeyWasShifted.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mouseWheelDelta

- (float) mouseWheelDelta

Extends class MyOpenGLView.

Definition at line 205 of file MyOpenGLView+Input.m.

206{
207 return _mouseWheelDelta / OOMOUSEWHEEL_DELTA;
208}
#define OOMOUSEWHEEL_DELTA

References mouseWheelDelta, and OOMOUSEWHEEL_DELTA.

Referenced by mouseWheelDelta.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mouseWheelState

- (int) mouseWheelState

Extends class MyOpenGLView.

Definition at line 196 of file MyOpenGLView+Input.m.

197{
198 if (_mouseWheelDelta > 0.0f)
199 return gvMouseWheelUp;
200 else if (_mouseWheelDelta < 0.0f)
201 return gvMouseWheelDown;
202 else
203 return gvMouseWheelNeutral;
204}
@ gvMouseWheelDown
@ gvMouseWheelNeutral
@ gvMouseWheelUp

References gvMouseWheelDown, gvMouseWheelNeutral, gvMouseWheelUp, int(), and mouseWheelState.

Referenced by mouseWheelState.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ noteMouseInteractionModeChangedFrom:to:

- (void) noteMouseInteractionModeChangedFrom: (OOMouseInteractionMode) oldMode
to: (OOMouseInteractionMode) newMode 

Extends class MyOpenGLView.

Definition at line 86 of file MyOpenGLView+Input.m.

87{
88 [self autoShowMouse];
89 [self setMouseInDeltaMode:OOMouseInteractionModeIsFlightMode(newMode)];
90}
OOMouseInteractionMode

References MyOpenGLView::autoShowMouse, and MyOpenGLView::setMouseInDeltaMode:.

Here is the call graph for this function:

◆ numKeys

- (int) numKeys

Extends class MyOpenGLView.

Definition at line 192 of file MyOpenGLView+Input.m.

193{
194 return NUM_KEYS;
195}
#define NUM_KEYS

References int(), NUM_KEYS, and numKeys.

Referenced by clearKey:, isDown:, numKeys, and pollControls.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pollControls

- (void) pollControls

Extends class MyOpenGLView.

Definition at line 225 of file MyOpenGLView+Input.m.

226{
227 SDL_Event event;
228 SDL_KeyboardEvent* kbd_event;
229 SDL_MouseButtonEvent* mbtn_event;
230 SDL_MouseMotionEvent* mmove_event;
231 SDL_MouseWheelEvent* mw_event;
232 float mxdelta, mydelta;
233 float mouseVirtualStickSensitivityX = viewSize.width * _mouseVirtualStickSensitivityFactor;
234 float mouseVirtualStickSensitivityY = viewSize.height * _mouseVirtualStickSensitivityFactor;
235 NSTimeInterval timeNow = [NSDate timeIntervalSinceReferenceDate];
236 Uint16 key_id;
237 SDL_Scancode scan_code;
238 float inDelta;
239 bool resize_pending = false;
240
241 while (SDL_PollEvent(&event)) {
242 switch (event.type) {
243 case SDL_EVENT_JOYSTICK_AXIS_MOTION:
244 case SDL_EVENT_JOYSTICK_BUTTON_UP:
245 case SDL_EVENT_JOYSTICK_BUTTON_DOWN:
246 case SDL_EVENT_GAMEPAD_AXIS_MOTION:
247 case SDL_EVENT_GAMEPAD_BUTTON_UP:
248 case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
249 case SDL_EVENT_JOYSTICK_HAT_MOTION:
251 break;
252
253 case SDL_EVENT_MOUSE_BUTTON_DOWN:
254 mbtn_event = (SDL_MouseButtonEvent*)&event;
255
256 switch (mbtn_event->button) {
257 case SDL_BUTTON_LEFT:
258 keys[gvMouseLeftButton] = YES;
259 break;
260 case SDL_BUTTON_RIGHT:
261 // Cocoa version does this in the GameController
262 /*
263 The mouseWarped variable is quite important as far as mouse control is concerned. When we
264 reset the virtual joystick (mouse) coordinates, we need to send a WarpMouse call because we
265 must recenter the pointer physically on screen. This goes together with a mouse motion event,
266 so we use mouseWarped to simply ignore handling of motion events in this case. - Nikos 20110721
267 */
268 [self resetMouse]; // Will set mouseWarped to YES
269 break;
270 // mousewheel stuff
271 }
272 break;
273
274 case SDL_EVENT_MOUSE_BUTTON_UP:
275 mbtn_event = (SDL_MouseButtonEvent*)&event;
276 NSTimeInterval timeBetweenClicks = timeNow - timeIntervalAtLastClick;
277 timeIntervalAtLastClick += timeBetweenClicks;
278 if (mbtn_event->button == SDL_BUTTON_LEFT) {
279 if (!doubleClick) {
280 doubleClick = (timeBetweenClicks < MOUSE_DOUBLE_CLICK_INTERVAL); // One fifth of a second
281 keys[gvMouseDoubleClick] = doubleClick;
282 }
283 keys[gvMouseLeftButton] = NO;
284 }
285 break;
286
287 case SDL_EVENT_MOUSE_WHEEL:
288 mw_event = (SDL_MouseWheelEvent*)&event;
289
290 inDelta = mw_event->y;
291 if (inDelta > 0) {
292 if (_mouseWheelDelta >= 0.0f)
293 _mouseWheelDelta += inDelta;
294 else
295 _mouseWheelDelta = 0.0f;
296 } else if (inDelta < 0) {
297 if (_mouseWheelDelta <= 0.0f)
298 _mouseWheelDelta += inDelta;
299 else
300 _mouseWheelDelta = 0.0f;
301 }
302 /*
303 Mousewheel handling - just note time since last use here and mark as inactive,
304 if needed, at the end of this method. Note that the mousewheel button up event is
305 kind of special, as in, it is sent at the same time as its corresponding mousewheel
306 button down one - Nikos 20140809
307 */
308 NSTimeInterval timeBetweenMouseWheels = timeNow - timeSinceLastMouseWheel;
309 timeSinceLastMouseWheel += timeBetweenMouseWheels;
310 break;
311
312 case SDL_EVENT_MOUSE_MOTION: {
313 // Delta mode is set when the game is in 'flight' mode.
314 // In this mode, the mouse movement delta is used rather
315 // than absolute position. This is because if the user
316 // clicks the right button to recentre the virtual joystick,
317 // if we are using absolute joystick positioning, as soon
318 // as the player touches the mouse again, the virtual joystick
319 // will snap back to the absolute position (which can be
320 // annoyingly fatal in battle).
321 if (mouseInDeltaMode) {
322 // note: virtual stick sensitivity is configurable
323 SDL_GetRelativeMouseState(&mxdelta, &mydelta);
324 double mxd = (double)mxdelta / mouseVirtualStickSensitivityX;
325 double myd = (double)mydelta / mouseVirtualStickSensitivityY;
326
327 if (!mouseWarped) // Standard event, update coordinates
328 {
331
332 // if we excceed the limits, revert changes
335 }
338 }
339 } else {
340 // Motion event generated by WarpMouse is ignored and
341 // we reset mouseWarped for the next time.
342 mouseWarped = NO;
343 }
344 } else {
345 // Windowed mode. Use the absolute position so the
346 // Oolite mouse pointer appears under the X Window System
347 // mouse pointer.
348 mmove_event = (SDL_MouseMotionEvent*)&event;
349
350 int w = viewSize.width;
351 int h = viewSize.height;
352
353 if (!mouseWarped) // standard event, handle it
354 {
355 // Event coordinates are in points, viewSize in pixels (they differ on high-DPI displays)
356 float pixelDensity = SDL_GetWindowPixelDensity(window);
357 if (pixelDensity <= 0.0f)
358 pixelDensity = 1.0f;
359 double mx = mmove_event->x * pixelDensity - w / 2.0;
360 double my = mmove_event->y * pixelDensity - h / 2.0;
361 if (display_z > 640.0) {
362 mx /= w * MAIN_GUI_PIXEL_WIDTH / display_z;
363 my /= h;
364 } else {
365 mx /= MAIN_GUI_PIXEL_WIDTH * w / 640.0;
366 my /= MAIN_GUI_PIXEL_HEIGHT * w / 640.0;
367 }
368
369 [self setVirtualJoystick:mx vmy:my];
370 } else {
371 // event coming from WarpMouse ignored, get ready for the next
372 mouseWarped = NO;
373 }
374 }
375 break;
376 }
377 case SDL_EVENT_KEY_DOWN:
378 kbd_event = (SDL_KeyboardEvent*)&event;
379 key_id = SDL_GetKeyFromScancode(kbd_event->scancode, kbd_event->mod, NO);
380 scan_code = kbd_event->scancode;
381
382 // char *keychar = SDL_GetKeyName(kbd_event->keysym.sym);
383 // deal with modifiers first
384 BOOL modifier_pressed = NO;
385 BOOL special_key = NO;
386
387 shift = (kbd_event->mod & SDL_KMOD_SHIFT) != 0;
388 ctrl = (kbd_event->mod & SDL_KMOD_CTRL) != 0;
389 opt = (kbd_event->mod & SDL_KMOD_ALT) != 0;
390
391 // translate scancode to unicode equiv
392 switch (kbd_event->key) {
393 case SDLK_LSHIFT:
394 case SDLK_RSHIFT:
395 case SDLK_LCTRL:
396 case SDLK_RCTRL:
397 case SDLK_LALT:
398 case SDLK_RALT:
399 modifier_pressed = YES;
400 break;
401
402 case SDLK_KP_0:
404 special_key = YES;
405 break;
406 case SDLK_KP_1:
408 special_key = YES;
409 break;
410 case SDLK_KP_2:
412 special_key = YES;
413 break;
414 case SDLK_KP_3:
416 special_key = YES;
417 break;
418 case SDLK_KP_4:
420 special_key = YES;
421 break;
422 case SDLK_KP_5:
424 special_key = YES;
425 break;
426 case SDLK_KP_6:
428 special_key = YES;
429 break;
430 case SDLK_KP_7:
432 special_key = YES;
433 break;
434 case SDLK_KP_8:
436 special_key = YES;
437 break;
438 case SDLK_KP_9:
440 special_key = YES;
441 break;
442 case SDLK_KP_PERIOD:
443 key_id = (!allowingStringInput ? gvNumberPadKeyPeriod : 46);
444 special_key = YES;
445 break;
446 case SDLK_KP_DIVIDE:
447 key_id = (!allowingStringInput ? gvNumberPadKeyDivide : 47);
448 special_key = YES;
449 break;
450 case SDLK_KP_MULTIPLY:
452 special_key = YES;
453 break;
454 case SDLK_KP_MINUS:
455 key_id = (!allowingStringInput ? gvNumberPadKeyMinus : 45);
456 special_key = YES;
457 break;
458 case SDLK_KP_PLUS:
459 key_id = (!allowingStringInput ? gvNumberPadKeyPlus : 43);
460 special_key = YES;
461 break;
462 case SDLK_KP_EQUALS:
463 key_id = (!allowingStringInput ? gvNumberPadKeyEquals : 61);
464 special_key = YES;
465 break;
466 case SDLK_KP_ENTER:
467 key_id = gvNumberPadKeyEnter;
468 special_key = YES;
469 break;
470 case SDLK_HOME:
471 key_id = gvHomeKey;
472 special_key = YES;
473 break;
474 case SDLK_END:
475 key_id = gvEndKey;
476 special_key = YES;
477 break;
478 case SDLK_INSERT:
479 key_id = gvInsertKey;
480 special_key = YES;
481 break;
482 case SDLK_PAGEUP:
483 key_id = gvPageUpKey;
484 special_key = YES;
485 break;
486 case SDLK_PAGEDOWN:
487 key_id = gvPageDownKey;
488 special_key = YES;
489 break;
490 case SDLK_SPACE:
491 key_id = 32;
492 special_key = YES;
493 break;
494 case SDLK_RETURN:
495 key_id = 13;
496 special_key = YES;
497 break;
498 case SDLK_TAB:
499 key_id = 9;
500 special_key = YES;
501 break;
502 case SDLK_UP:
503 key_id = gvArrowKeyUp;
504 special_key = YES;
505 break;
506 case SDLK_DOWN:
507 key_id = gvArrowKeyDown;
508 special_key = YES;
509 break;
510 case SDLK_LEFT:
511 key_id = gvArrowKeyLeft;
512 special_key = YES;
513 break;
514 case SDLK_RIGHT:
515 key_id = gvArrowKeyRight;
516 special_key = YES;
517 break;
518 case SDLK_PAUSE:
519 key_id = gvPauseKey;
520 special_key = YES;
521 break;
522 case SDLK_BACKSPACE:
523 key_id = gvBackspaceKey;
524 special_key = YES;
525 break;
526 case SDLK_DELETE:
527 key_id = gvDeleteKey;
528 special_key = YES;
529 break;
530 case SDLK_F1:
531 key_id = gvFunctionKey1;
532 special_key = YES;
533 break;
534 case SDLK_F2:
535 key_id = gvFunctionKey2;
536 special_key = YES;
537 break;
538 case SDLK_F3:
539 key_id = gvFunctionKey3;
540 special_key = YES;
541 break;
542 case SDLK_F4:
543 key_id = gvFunctionKey4;
544 special_key = YES;
545 break;
546 case SDLK_F5:
547 key_id = gvFunctionKey5;
548 special_key = YES;
549 break;
550 case SDLK_F6:
551 key_id = gvFunctionKey6;
552 special_key = YES;
553 break;
554 case SDLK_F7:
555 key_id = gvFunctionKey7;
556 special_key = YES;
557 break;
558 case SDLK_F8:
559 key_id = gvFunctionKey8;
560 special_key = YES;
561 break;
562 case SDLK_F9:
563 key_id = gvFunctionKey9;
564 special_key = YES;
565 break;
566 case SDLK_F10:
567 key_id = gvFunctionKey10;
568 special_key = YES;
569 break;
570 case SDLK_F11:
571 key_id = gvFunctionKey11;
572 special_key = YES;
573 break;
574 case SDLK_F12:
575 key_id = 327;
576 [self toggleScreenMode];
577 special_key = YES;
578 break;
579
580 case SDLK_ESCAPE:
581 if (shift) {
582 SDL_DestroyWindow(window);
583 [gameController exitAppWithContext:@"Shift-escape pressed"];
584 } else {
585 key_id = 27;
586 special_key = YES;
587 }
588 break;
589 default:
590 // OOLog(@"keys.test", @"Unhandled Keydown scancode with unicode = 0: %d", scan_code);
591 ;
592 }
593
594 // the keyup event doesn't give us the unicode value, so store it here so it can be retrieved on keyup
595 // the ctrl key tends to mix up the unicode values, so deal with some special cases
596 // we also need (in most cases) to get the character without the impact of caps lock.
597
598 if (((!special_key && (ctrl || key_id == 0)) || ([self isCapsLockOn] && (!special_key && !allowingStringInput))) && !modifier_pressed) //
599 {
600 // ctrl changes alpha characters to control codes (1-26)
601 if (ctrl && key_id >= 1 && key_id <= 26) {
602 if (shift)
603 key_id += 64; // A-Z is from 65, offset by -1 for the scancode start point
604 else
605 key_id += 96; // a-z is from 97, offset by -1 for the scancode start point
606 } else {
607 // SDL3 - the key_id should contain the correct unicode value, so we shouldn't need to run the key mapping
608 // - kanthoney
609 // key_id = 0; // reset the value here to force a lookup from the keymappings data
610 }
611 }
612
613 // if we've got the unicode value, we can store it in our array now
614 if (key_id > 0)
615 scancode2Unicode[scan_code] = key_id;
616
617 if (allowingStringInput && !modifier_pressed) {
618 [self handleStringInput:kbd_event keyID:key_id];
619 }
620
621 OOLog(kOOLogKeyDown, @"Keydown scancode = %d, unicode = %i", scan_code, key_id);
622
623 if (key_id > 0 && key_id <= [self numKeys]) {
624 keys[key_id] = YES;
625 } else {
626 OOLog(@"keys.test", @"Unhandled Keydown scancode/unicode: %d %i", scan_code, key_id);
627 }
628 break;
629
630 case SDL_EVENT_KEY_UP:
631 suppressKeys = NO; // DJS
632 kbd_event = (SDL_KeyboardEvent*)&event;
633 scan_code = kbd_event->scancode;
634
635 shift = kbd_event->mod & SDL_KMOD_SHIFT;
636 ctrl = kbd_event->mod & SDL_KMOD_CTRL;
637 opt = kbd_event->mod & SDL_KMOD_ALT;
638
639 // all the work should have been down on the keydown event, so all we need to do is get the unicode value from the array
640 key_id = scancode2Unicode[scan_code];
641
642 // deal with modifiers first
643 switch (kbd_event->key) {
644 case SDLK_LSHIFT:
645 case SDLK_RSHIFT:
646 shift = NO;
647 break;
648
649 case SDLK_LCTRL:
650 case SDLK_RCTRL:
651 ctrl = NO;
652 break;
653
654 case SDLK_LALT:
655 case SDLK_RALT:
656 opt = NO;
657 break;
658 default:;
659 }
660 OOLog(kOOLogKeyUp, @"Keyup scancode = %d, unicode = %i, character = %c, shift = %d, ctrl = %d, alt = %d", scan_code, key_id, key_id, shift, ctrl, opt);
661 // OOLog(kOOLogKeyUp, @"Keyup scancode = %d, shift = %d, ctrl = %d, alt = %d", scan_code, shift, ctrl, opt);
662
663 // translate scancode to unicode equiv
664 switch (kbd_event->key) {
665 case SDLK_KP_0:
667 break;
668 case SDLK_KP_1:
670 break;
671 case SDLK_KP_2:
673 break;
674 case SDLK_KP_3:
676 break;
677 case SDLK_KP_4:
679 break;
680 case SDLK_KP_5:
682 break;
683 case SDLK_KP_6:
685 break;
686 case SDLK_KP_7:
688 break;
689 case SDLK_KP_8:
691 break;
692 case SDLK_KP_9:
694 break;
695 case SDLK_KP_PERIOD:
696 key_id = (!allowingStringInput ? gvNumberPadKeyPeriod : 46);
697 break;
698 case SDLK_KP_DIVIDE:
699 key_id = (!allowingStringInput ? gvNumberPadKeyDivide : 47);
700 break;
701 case SDLK_KP_MULTIPLY:
703 break;
704 case SDLK_KP_MINUS:
705 key_id = (!allowingStringInput ? gvNumberPadKeyMinus : 45);
706 break;
707 case SDLK_KP_PLUS:
708 key_id = (!allowingStringInput ? gvNumberPadKeyPlus : 43);
709 break;
710 case SDLK_KP_EQUALS:
711 key_id = (!allowingStringInput ? gvNumberPadKeyEquals : 61);
712 break;
713 case SDLK_KP_ENTER:
714 key_id = gvNumberPadKeyEnter;
715 break;
716 case SDLK_HOME:
717 key_id = gvHomeKey;
718 break;
719 case SDLK_END:
720 key_id = gvEndKey;
721 break;
722 case SDLK_INSERT:
723 key_id = gvInsertKey;
724 break;
725 case SDLK_PAGEUP:
726 key_id = gvPageUpKey;
727 break;
728 case SDLK_PAGEDOWN:
729 key_id = gvPageDownKey;
730 break;
731 case SDLK_SPACE:
732 key_id = 32;
733 break;
734 case SDLK_RETURN:
735 key_id = 13;
736 break;
737 case SDLK_TAB:
738 key_id = 9;
739 break;
740 case SDLK_ESCAPE:
741 key_id = 27;
742 break;
743 case SDLK_UP:
744 key_id = gvArrowKeyUp;
745 break;
746 case SDLK_DOWN:
747 key_id = gvArrowKeyDown;
748 break;
749 case SDLK_LEFT:
750 key_id = gvArrowKeyLeft;
751 break;
752 case SDLK_RIGHT:
753 key_id = gvArrowKeyRight;
754 break;
755 case SDLK_PAUSE:
756 key_id = gvPauseKey;
757 break;
758 case SDLK_F1:
759 key_id = gvFunctionKey1;
760 break;
761 case SDLK_F2:
762 key_id = gvFunctionKey2;
763 break;
764 case SDLK_F3:
765 key_id = gvFunctionKey3;
766 break;
767 case SDLK_F4:
768 key_id = gvFunctionKey4;
769 break;
770 case SDLK_F5:
771 key_id = gvFunctionKey5;
772 break;
773 case SDLK_F6:
774 key_id = gvFunctionKey6;
775 break;
776 case SDLK_F7:
777 key_id = gvFunctionKey7;
778 break;
779 case SDLK_F8:
780 key_id = gvFunctionKey8;
781 break;
782 case SDLK_F9:
783 key_id = gvFunctionKey9;
784 break;
785 case SDLK_F10:
786 key_id = gvFunctionKey10;
787 break;
788 case SDLK_F11:
789 key_id = gvFunctionKey11;
790 break;
791 case SDLK_F12:
792 key_id = 327;
793 break;
794 case SDLK_BACKSPACE:
795 key_id = gvBackspaceKey;
796 break;
797 case SDLK_DELETE:
798 key_id = gvDeleteKey;
799 break;
800
801 default:
802 // OOLog(@"keys.test", @"Unhandled Keyup scancode with unicode = 0: %d", kbd_event->keysym.scancode);
803 ;
804 }
805
806 if (key_id > 0 && key_id <= [self numKeys]) {
807 keys[key_id] = NO;
808 } else {
809 // OOLog(@"keys.test", @"Unhandled Keyup scancode: %d", kbd_event->keysym.scancode);
810 }
811 break;
812
813 case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED: {
814 resize_pending = true;
815 break;
816 }
817
818#if OOLITE_WINDOWS
819 case SDL_EVENT_WINDOW_FOCUS_GAINED: {
820 [gameController setEcoQoS:[gameController isGamePaused]];
821 break;
822 }
823
824 case SDL_EVENT_WINDOW_FOCUS_LOST: {
825 [gameController setEcoQoS:YES];
826 break;
827 }
828#endif
829
830 // caused by INTR or someone hitting close
831 case SDL_EVENT_QUIT: {
832 SDL_DestroyWindow(window);
833 [gameController exitAppWithContext:@"SDL_QUIT event received"];
834 }
835 }
836 }
837 // check if enough time has passed since last use of the mousewheel and act
838 // if needed
839 if (timeNow >= timeSinceLastMouseWheel + OOMOUSEWHEEL_EVENTS_DELAY_INTERVAL) {
840 _mouseWheelDelta = 0.0f;
841 }
842 if (resize_pending) {
843 int pixelWidth, pixelHeight;
844 // Fetch actual pixel bounds back from SDL
845 SDL_GetWindowSizeInPixels(window, &pixelWidth, &pixelHeight);
846
847 [self updateGLSize:NSMakeSize(pixelWidth, pixelHeight)];
848
849 if (!fullScreen) {
850 // Save the window size in points, not pixels: they differ on high-DPI displays,
851 // and the saved size is passed back to SDL_SetWindowSize().
852 int windowWidth, windowHeight;
853 SDL_GetWindowSize(window, &windowWidth, &windowHeight);
854 [self saveWindowSize:NSMakeSize(windowWidth, windowHeight)];
855 }
856 resize_pending = false;
857 }
858}
#define MAIN_GUI_PIXEL_WIDTH
#define MAIN_GUI_PIXEL_HEIGHT
static NSString * kOOLogKeyDown
static NSString * kOOLogKeyUp
#define MOUSE_DOUBLE_CLICK_INTERVAL
@ gvNumberKey4
@ gvNumberPadKeyDivide
@ gvNumberPadKeyMultiply
@ gvNumberKey9
@ gvNumberKey5
@ gvNumberPadKeyPeriod
@ gvFunctionKey2
@ gvBackspaceKey
@ gvInsertKey
@ gvNumberPadKeyPlus
@ gvNumberPadKey9
@ gvNumberPadKey1
@ gvFunctionKey10
@ gvFunctionKey5
@ gvDeleteKey
@ gvNumberKey2
@ gvArrowKeyDown
@ gvNumberPadKey2
@ gvFunctionKey9
@ gvNumberPadKey3
@ gvFunctionKey4
@ gvEndKey
@ gvNumberKey0
@ gvNumberKey7
@ gvHomeKey
@ gvNumberPadKeyEquals
@ gvNumberPadKey6
@ gvNumberPadKeyEnter
@ gvNumberPadKey5
@ gvNumberPadKey4
@ gvNumberKey8
@ gvNumberKey3
@ gvNumberKey6
@ gvPauseKey
@ gvNumberPadKeyMinus
@ gvNumberPadKey7
@ gvFunctionKey11
@ gvFunctionKey8
@ gvNumberKey1
@ gvPageDownKey
@ gvNumberPadKey8
@ gvFunctionKey3
@ gvArrowKeyUp
@ gvArrowKeyRight
@ gvFunctionKey6
@ gvArrowKeyLeft
@ gvFunctionKey7
@ gvPageUpKey
@ gvNumberPadKey0
@ gvFunctionKey1
#define MOUSEY_MAXIMUM
#define OOMOUSEWHEEL_EVENTS_DELAY_INTERVAL
#define MOUSEX_MAXIMUM
#define OOLog(class, format,...)
Definition OOLogging.h:84
BOOL handleSDLEvent:(SDL_Event *evt)

References allowingStringInput, gvArrowKeyDown, gvArrowKeyLeft, gvArrowKeyRight, gvArrowKeyUp, gvBackspaceKey, gvDeleteKey, gvEndKey, gvFunctionKey1, gvFunctionKey10, gvFunctionKey11, gvFunctionKey2, gvFunctionKey3, gvFunctionKey4, gvFunctionKey5, gvFunctionKey6, gvFunctionKey7, gvFunctionKey8, gvFunctionKey9, gvHomeKey, gvInsertKey, gvNumberKey0, gvNumberKey1, gvNumberKey2, gvNumberKey3, gvNumberKey4, gvNumberKey5, gvNumberKey6, gvNumberKey7, gvNumberKey8, gvNumberKey9, gvNumberPadKey0, gvNumberPadKey1, gvNumberPadKey2, gvNumberPadKey3, gvNumberPadKey4, gvNumberPadKey5, gvNumberPadKey6, gvNumberPadKey7, gvNumberPadKey8, gvNumberPadKey9, gvNumberPadKeyDivide, gvNumberPadKeyEnter, gvNumberPadKeyEquals, gvNumberPadKeyMinus, gvNumberPadKeyMultiply, gvNumberPadKeyPeriod, gvNumberPadKeyPlus, gvPageDownKey, gvPageUpKey, gvPauseKey, OOSDLJoystickManager::handleSDLEvent:, MyOpenGLView::handleStringInput:keyID:, isCapsLockOn, kOOLogKeyDown, kOOLogKeyUp, MAIN_GUI_PIXEL_HEIGHT, MAIN_GUI_PIXEL_WIDTH, MOUSE_DOUBLE_CLICK_INTERVAL, MOUSEX_MAXIMUM, MOUSEY_MAXIMUM, numKeys, OOLog, OOMOUSEWHEEL_EVENTS_DELAY_INTERVAL, pollControls, MyOpenGLView::resetMouse, MyOpenGLView::saveWindowSize:, MyOpenGLView::setVirtualJoystick:vmy:, OOJoystickManager::sharedStickHandler, MyOpenGLView::toggleScreenMode, MyOpenGLView::updateGLSize:, and virtualJoystickPosition.

Referenced by pollControls.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resetMouse

- (void) resetMouse

Extends class MyOpenGLView.

Definition at line 121 of file MyOpenGLView+Input.m.

122{
123 [self setVirtualJoystick:0.0 vmy:0.0];
124 if ([[PlayerEntity sharedPlayer] isMouseControlOn]) {
125 // viewSize is in pixels; SDL mouse coordinates are in points (they differ on high-DPI displays)
126 float pixelDensity = SDL_GetWindowPixelDensity(window);
127 if (pixelDensity <= 0.0f)
128 pixelDensity = 1.0f;
129 SDL_WarpMouseInWindow(window, viewSize.width / 2 / pixelDensity, viewSize.height / 2 / pixelDensity);
130 mouseWarped = YES;
131 }
132}

References resetMouse, and MyOpenGLView::setVirtualJoystick:vmy:.

Referenced by resetMouse.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resetTypedString

- (void) resetTypedString

Extends class MyOpenGLView.

Definition at line 78 of file MyOpenGLView+Input.m.

79{
80 [typedString setString:@""];
81}

References resetTypedString.

Referenced by resetTypedString.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setMouseInDeltaMode:

- (void) setMouseInDeltaMode: (BOOL) inDelta

Extends class MyOpenGLView.

Definition at line 897 of file MyOpenGLView+Input.m.

897 :(BOOL)inDelta
898{
899 mouseInDeltaMode = inDelta;
900}

◆ setMouseWheelDelta:

- (void) setMouseWheelDelta: (float) newWheelDelta

Extends class MyOpenGLView.

Definition at line 209 of file MyOpenGLView+Input.m.

209 :(float)newWheelDelta
210{
211 _mouseWheelDelta = newWheelDelta * OOMOUSEWHEEL_DELTA;
212}

References OOMOUSEWHEEL_DELTA.

◆ setStringInput:

- (void) setStringInput: (enum StringInput) value

Extends class MyOpenGLView.

Definition at line 59 of file MyOpenGLView+Input.m.

59 :(enum StringInput)value
60{
61 allowingStringInput = value;
62}
StringInput

References allowingStringInput.

Here is the call graph for this function:

◆ setTypedString:

- (void) setTypedString: (NSString*) value

Extends class MyOpenGLView.

Definition at line 82 of file MyOpenGLView+Input.m.

82 :(NSString*)value
83{
84 [typedString setString:value];
85}

◆ setVirtualJoystick:vmy:

- (void) setVirtualJoystick: (double) vmx
vmy: (double) vmy 

Extends class MyOpenGLView.

Definition at line 91 of file MyOpenGLView+Input.m.

91 :(double)vmx vmy:(double)vmy
92{
95}

References virtualJoystickPosition.

Here is the call graph for this function:

◆ suppressKeysUntilKeyUp

- (void) suppressKeysUntilKeyUp

Extends class MyOpenGLView.

Definition at line 143 of file MyOpenGLView+Input.m.

144{
145 if (keys[gvMouseDoubleClick] == NO) {
146 suppressKeys = YES;
147 [self clearKeys];
148 } else {
149 [self clearMouse];
150 }
151}
@ gvMouseDoubleClick

References MyOpenGLView::clearKeys, MyOpenGLView::clearMouse, gvMouseDoubleClick, and suppressKeysUntilKeyUp.

Referenced by suppressKeysUntilKeyUp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ typedString

- (NSString *) typedString

Extends class MyOpenGLView.

Definition at line 74 of file MyOpenGLView+Input.m.

75{
76 return typedString;
77}

References typedString.

Referenced by MyOpenGLView::dealloc, PlayerEntity(KeyMapper)::handleKeyConfigEntryKeys:view:, handleStringInput:keyID:, MyOpenGLView::init, PlayerEntity(OOControlsPrivate)::pollDemoControls:, PlayerEntity(OOControlsPrivate)::pollGuiArrowKeyControls:, PlayerEntity(Scripting)::refreshMissionScreenTextEntry, PlayerEntity(LoadSave)::saveCommanderInputHandler, PlayerEntity(KeyMapper)::setGuiToKeyConfigEntryScreen, and typedString.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ virtualJoystickPosition

- (NSPoint) virtualJoystickPosition

Extends class MyOpenGLView.

Definition at line 96 of file MyOpenGLView+Input.m.

97{
99}

References virtualJoystickPosition.

Referenced by MyOpenGLView::init, pollControls, PlayerEntity(OOControlsPrivate)::pollCustomViewControls, PlayerEntity(OOControlsPrivate)::pollFlightArrowKeyControls:, PlayerEntity(OOControlsPrivate)::pollGuiArrowKeyControls:, setVirtualJoystick:vmy:, and virtualJoystickPosition.

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this category was generated from the following files: