📄 sdl_macevents.c
字号:
SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey((event.message&keyCodeMask)>>8 event.modifiers, &keysym, 1)); } break; case keyUp: { SDL_keysym keysym; SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey((event.message&keyCodeMask)>>8 event.modifiers, &keysym, 0)); } break;#endif case updateEvt: { BeginUpdate(SDL_Window); if ( (SDL_VideoSurface->flags & SDL_HWSURFACE) == SDL_SWSURFACE ) { SDL_UpdateRect(SDL_VideoSurface, 0, 0, 0, 0); } EndUpdate(SDL_Window); } /* If this was an update event for the SIOUX console, we return 0 in order to stop an endless series of updates being triggered. */ if ( (WindowRef) event.message != SDL_Window ) { return 0; } break; case activateEvt: { Mac_HandleActivate(!!(event.modifiers & activeFlag)); } break; case diskEvt: {#if TARGET_API_MAC_CARBON /* What are we supposed to do? */;#else if ( ((event.message>>16)&0xFFFF) != noErr ) { Point spot; SetPt(&spot, 0x0070, 0x0050); DIBadMount(spot, event.message); }#endif } break; case osEvt: { switch ((event.message>>24) & 0xFF) {#if 0 /* Handled above the switch statement */ case mouseMovedMessage: { myGlobalToLocal(this, &event.where); SDL_PrivateMouseMotion(0, 0, event.where.h, event.where.v); } break;#endif /* 0 */ case suspendResumeMessage: { Mac_HandleActivate(!!(event.message & resumeFlag)); } break; } } break; default: { ; } break; } return (event.what != nullEvent);}void Mac_PumpEvents(_THIS){ /* Process pending MacOS events */ while ( Mac_HandleEvents(this, 0) ) { /* Loop and check again */; }}void Mac_InitOSKeymap(_THIS){ const void *KCHRPtr; UInt32 state; UInt32 value; int i; int world = SDLK_WORLD_0; /* Map the MAC keysyms */ for ( i=0; i<SDL_TABLESIZE(MAC_keymap); ++i ) MAC_keymap[i] = SDLK_UNKNOWN; /* Defined MAC_* constants */ MAC_keymap[MK_ESCAPE] = SDLK_ESCAPE; MAC_keymap[MK_F1] = SDLK_F1; MAC_keymap[MK_F2] = SDLK_F2; MAC_keymap[MK_F3] = SDLK_F3; MAC_keymap[MK_F4] = SDLK_F4; MAC_keymap[MK_F5] = SDLK_F5; MAC_keymap[MK_F6] = SDLK_F6; MAC_keymap[MK_F7] = SDLK_F7; MAC_keymap[MK_F8] = SDLK_F8; MAC_keymap[MK_F9] = SDLK_F9; MAC_keymap[MK_F10] = SDLK_F10; MAC_keymap[MK_F11] = SDLK_F11; MAC_keymap[MK_F12] = SDLK_F12; MAC_keymap[MK_PRINT] = SDLK_PRINT; MAC_keymap[MK_SCROLLOCK] = SDLK_SCROLLOCK; MAC_keymap[MK_PAUSE] = SDLK_PAUSE; MAC_keymap[MK_POWER] = SDLK_POWER; MAC_keymap[MK_BACKQUOTE] = SDLK_BACKQUOTE; MAC_keymap[MK_1] = SDLK_1; MAC_keymap[MK_2] = SDLK_2; MAC_keymap[MK_3] = SDLK_3; MAC_keymap[MK_4] = SDLK_4; MAC_keymap[MK_5] = SDLK_5; MAC_keymap[MK_6] = SDLK_6; MAC_keymap[MK_7] = SDLK_7; MAC_keymap[MK_8] = SDLK_8; MAC_keymap[MK_9] = SDLK_9; MAC_keymap[MK_0] = SDLK_0; MAC_keymap[MK_MINUS] = SDLK_MINUS; MAC_keymap[MK_EQUALS] = SDLK_EQUALS; MAC_keymap[MK_BACKSPACE] = SDLK_BACKSPACE; MAC_keymap[MK_INSERT] = SDLK_INSERT; MAC_keymap[MK_HOME] = SDLK_HOME; MAC_keymap[MK_PAGEUP] = SDLK_PAGEUP; MAC_keymap[MK_NUMLOCK] = SDLK_NUMLOCK; MAC_keymap[MK_KP_EQUALS] = SDLK_KP_EQUALS; MAC_keymap[MK_KP_DIVIDE] = SDLK_KP_DIVIDE; MAC_keymap[MK_KP_MULTIPLY] = SDLK_KP_MULTIPLY; MAC_keymap[MK_TAB] = SDLK_TAB; MAC_keymap[MK_q] = SDLK_q; MAC_keymap[MK_w] = SDLK_w; MAC_keymap[MK_e] = SDLK_e; MAC_keymap[MK_r] = SDLK_r; MAC_keymap[MK_t] = SDLK_t; MAC_keymap[MK_y] = SDLK_y; MAC_keymap[MK_u] = SDLK_u; MAC_keymap[MK_i] = SDLK_i; MAC_keymap[MK_o] = SDLK_o; MAC_keymap[MK_p] = SDLK_p; MAC_keymap[MK_LEFTBRACKET] = SDLK_LEFTBRACKET; MAC_keymap[MK_RIGHTBRACKET] = SDLK_RIGHTBRACKET; MAC_keymap[MK_BACKSLASH] = SDLK_BACKSLASH; MAC_keymap[MK_DELETE] = SDLK_DELETE; MAC_keymap[MK_END] = SDLK_END; MAC_keymap[MK_PAGEDOWN] = SDLK_PAGEDOWN; MAC_keymap[MK_KP7] = SDLK_KP7; MAC_keymap[MK_KP8] = SDLK_KP8; MAC_keymap[MK_KP9] = SDLK_KP9; MAC_keymap[MK_KP_MINUS] = SDLK_KP_MINUS; MAC_keymap[MK_CAPSLOCK] = SDLK_CAPSLOCK; MAC_keymap[MK_a] = SDLK_a; MAC_keymap[MK_s] = SDLK_s; MAC_keymap[MK_d] = SDLK_d; MAC_keymap[MK_f] = SDLK_f; MAC_keymap[MK_g] = SDLK_g; MAC_keymap[MK_h] = SDLK_h; MAC_keymap[MK_j] = SDLK_j; MAC_keymap[MK_k] = SDLK_k; MAC_keymap[MK_l] = SDLK_l; MAC_keymap[MK_SEMICOLON] = SDLK_SEMICOLON; MAC_keymap[MK_QUOTE] = SDLK_QUOTE; MAC_keymap[MK_RETURN] = SDLK_RETURN; MAC_keymap[MK_KP4] = SDLK_KP4; MAC_keymap[MK_KP5] = SDLK_KP5; MAC_keymap[MK_KP6] = SDLK_KP6; MAC_keymap[MK_KP_PLUS] = SDLK_KP_PLUS; MAC_keymap[MK_LSHIFT] = SDLK_LSHIFT; MAC_keymap[MK_z] = SDLK_z; MAC_keymap[MK_x] = SDLK_x; MAC_keymap[MK_c] = SDLK_c; MAC_keymap[MK_v] = SDLK_v; MAC_keymap[MK_b] = SDLK_b; MAC_keymap[MK_n] = SDLK_n; MAC_keymap[MK_m] = SDLK_m; MAC_keymap[MK_COMMA] = SDLK_COMMA; MAC_keymap[MK_PERIOD] = SDLK_PERIOD; MAC_keymap[MK_SLASH] = SDLK_SLASH;#if 0 /* These are the same as the left versions - use left by default */ MAC_keymap[MK_RSHIFT] = SDLK_RSHIFT;#endif MAC_keymap[MK_UP] = SDLK_UP; MAC_keymap[MK_KP1] = SDLK_KP1; MAC_keymap[MK_KP2] = SDLK_KP2; MAC_keymap[MK_KP3] = SDLK_KP3; MAC_keymap[MK_KP_ENTER] = SDLK_KP_ENTER; MAC_keymap[MK_LCTRL] = SDLK_LCTRL; MAC_keymap[MK_LALT] = SDLK_LALT; MAC_keymap[MK_LMETA] = SDLK_LMETA; MAC_keymap[MK_SPACE] = SDLK_SPACE;#if 0 /* These are the same as the left versions - use left by default */ MAC_keymap[MK_RMETA] = SDLK_RMETA; MAC_keymap[MK_RALT] = SDLK_RALT; MAC_keymap[MK_RCTRL] = SDLK_RCTRL;#endif MAC_keymap[MK_LEFT] = SDLK_LEFT; MAC_keymap[MK_DOWN] = SDLK_DOWN; MAC_keymap[MK_RIGHT] = SDLK_RIGHT; MAC_keymap[MK_KP0] = SDLK_KP0; MAC_keymap[MK_KP_PERIOD] = SDLK_KP_PERIOD;#if defined(__APPLE__) && defined(__MACH__) /* Wierd, these keys are on my iBook under MacOS X Note that the left arrow keysym is the same as left ctrl!? */ MAC_keymap[MK_IBOOK_ENTER] = SDLK_KP_ENTER; MAC_keymap[MK_IBOOK_RIGHT] = SDLK_RIGHT; MAC_keymap[MK_IBOOK_DOWN] = SDLK_DOWN; MAC_keymap[MK_IBOOK_UP] = SDLK_UP; MAC_keymap[MK_IBOOK_LEFT] = SDLK_LEFT;#endif /* MacOS X */ /* Up there we setup a static scancode->keysym map. However, it will not * work very well on international keyboard. Hence we now query MacOS * for its own keymap to adjust our own mapping table. However, this is * bascially only useful for ascii char keys. This is also the reason * why we keep the static table, too. */ /* Get a pointer to the systems cached KCHR */ KCHRPtr = (void *)GetScriptManagerVariable(smKCHRCache); if (KCHRPtr) { /* Loop over all 127 possible scan codes */ for (i = 0; i < 0x7F; i++) { /* We pretend a clean start to begin with (i.e. no dead keys active */ state = 0; /* Now translate the key code to a key value */ value = KeyTranslate(KCHRPtr, i, &state) & 0xff; /* If the state become 0, it was a dead key. We need to translate again, passing in the new state, to get the actual key value */ if (state != 0) value = KeyTranslate(KCHRPtr, i, &state) & 0xff; /* Now we should have an ascii value, or 0. Try to figure out to which SDL symbol it maps */ if (value >= 128) /* Some non-ASCII char, map it to SDLK_WORLD_* */ MAC_keymap[i] = world++; else if (value >= 32) /* non-control ASCII char */ MAC_keymap[i] = value; } } /* The keypad codes are re-setup here, because the loop above cannot * distinguish between a key on the keypad and a regular key. We maybe * could get around this problem in another fashion: NSEvent's flags * include a "NSNumericPadKeyMask" bit; we could check that and modify * the symbol we return on the fly. However, this flag seems to exhibit * some weird behaviour related to the num lock key */ MAC_keymap[MK_KP0] = SDLK_KP0; MAC_keymap[MK_KP1] = SDLK_KP1; MAC_keymap[MK_KP2] = SDLK_KP2; MAC_keymap[MK_KP3] = SDLK_KP3; MAC_keymap[MK_KP4] = SDLK_KP4; MAC_keymap[MK_KP5] = SDLK_KP5; MAC_keymap[MK_KP6] = SDLK_KP6; MAC_keymap[MK_KP7] = SDLK_KP7; MAC_keymap[MK_KP8] = SDLK_KP8; MAC_keymap[MK_KP9] = SDLK_KP9; MAC_keymap[MK_KP_MINUS] = SDLK_KP_MINUS; MAC_keymap[MK_KP_PLUS] = SDLK_KP_PLUS; MAC_keymap[MK_KP_PERIOD] = SDLK_KP_PERIOD; MAC_keymap[MK_KP_EQUALS] = SDLK_KP_EQUALS; MAC_keymap[MK_KP_DIVIDE] = SDLK_KP_DIVIDE; MAC_keymap[MK_KP_MULTIPLY] = SDLK_KP_MULTIPLY; MAC_keymap[MK_KP_ENTER] = SDLK_KP_ENTER;}static SDL_keysym *TranslateKey(int scancode, int modifiers, SDL_keysym *keysym, int pressed){ /* Set the keysym information */ keysym->scancode = scancode; keysym->sym = MAC_keymap[keysym->scancode]; keysym->mod = KMOD_NONE; keysym->unicode = 0; if ( pressed && SDL_TranslateUNICODE ) { static unsigned long state = 0; static Ptr keymap = nil; Ptr new_keymap; /* Get the current keyboard map resource */ new_keymap = (Ptr)GetScriptManagerVariable(smKCHRCache); if ( new_keymap != keymap ) { keymap = new_keymap; state = 0; } keysym->unicode = KeyTranslate(keymap, keysym->scancode|modifiers, &state) & 0xFFFF; } return(keysym);}void Mac_InitEvents(_THIS){ /* Create apple menu bar */ apple_menu = GetMenu(mApple); if ( apple_menu != nil ) { AppendResMenu(apple_menu, 'DRVR'); InsertMenu(apple_menu, 0); } DrawMenuBar(); /* Get rid of spurious events at startup */ FlushEvents(everyEvent, 0); /* Allow every event but keyrepeat */ SetEventMask(everyEvent & ~autoKeyMask);}void Mac_QuitEvents(_THIS){ ClearMenuBar(); if ( apple_menu != nil ) { ReleaseResource((char **)apple_menu); } /* Clean up pending events */ FlushEvents(everyEvent, 0);}static void Mac_DoAppleMenu(_THIS, long choice){#if !TARGET_API_MAC_CARBON /* No Apple menu in OS X */ short menu, item; item = (choice&0xFFFF); choice >>= 16; menu = (choice&0xFFFF); switch (menu) { case mApple: { switch (item) { case iAbout: { /* Run the about box */; } break; default: { Str255 name; GetMenuItemText(apple_menu, item, name); OpenDeskAcc(name); } break; } } break; default: { /* Ignore other menus */; } }#endif /* !TARGET_API_MAC_CARBON */}#if !TARGET_API_MAC_CARBON/* Since we don't initialize QuickDraw, we need to get a pointer to qd */QDGlobals *theQD = NULL;/* Exported to the macmain code */void SDL_InitQuickDraw(struct QDGlobals *the_qd){ theQD = the_qd;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -