⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdl_macevents.c

📁 Simple DirectMedia Layer - Simple DirectMedia Layer 是一个跨平台的多媒体库设计用来提供快速图形framebuffer和音频驱动。应用MPEG为软件
💻 C
📖 第 1 页 / 共 2 页
字号:
/*    SDL - Simple DirectMedia Layer    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga    This library is free software; you can redistribute it and/or    modify it under the terms of the GNU Library General Public    License as published by the Free Software Foundation; either    version 2 of the License, or (at your option) any later version.    This library is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    Library General Public License for more details.    You should have received a copy of the GNU Library General Public    License along with this library; if not, write to the Free    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA    Sam Lantinga    slouken@libsdl.org*/#ifdef SAVE_RCSIDstatic char rcsid = "@(#) $Id: SDL_macevents.c,v 1.8 2002/03/06 11:23:05 slouken Exp $";#endif#include <stdio.h>#if TARGET_API_MAC_CARBON#include <Carbon.h>#else#include <Script.h>#include <LowMem.h>#include <Devices.h>#include <DiskInit.h>#include <ToolUtils.h>#endif#include "SDL_events.h"#include "SDL_video.h"#include "SDL_error.h"#include "SDL_syswm.h"#include "SDL_events_c.h"#include "SDL_cursor_c.h"#include "SDL_sysevents.h"#include "SDL_macevents_c.h"#include "SDL_mackeys.h"#include "SDL_macmouse_c.h"/* Define this to be able to collapse SDL windows.#define USE_APPEARANCE_MANAGER *//* Macintosh resource constants */#define mApple	128			/* Apple menu resource */#define iAbout	1			/* About menu item *//* Functions to handle the About menu */static void Mac_DoAppleMenu(_THIS, long item);/* The translation table from a macintosh key scancode to a SDL keysym */static SDLKey MAC_keymap[256];static SDL_keysym *TranslateKey(int scancode, int modifiers,                                SDL_keysym *keysym, int pressed);/* Handle activation and deactivation  -- returns whether an event was posted */static int Mac_HandleActivate(int activate){	if ( activate ) {		/* Show the current SDL application cursor */		SDL_SetCursor(NULL);		/* put our mask back case it changed during context switch */		SetEventMask(everyEvent & ~autoKeyMask);	} else {#if TARGET_API_MAC_CARBON		{ Cursor cursor;			SetCursor(GetQDGlobalsArrow(&cursor));		}#else		SetCursor(&theQD->arrow);#endif		if ( ! Mac_cursor_showing ) {			ShowCursor();			Mac_cursor_showing = 1;		}	}	return(SDL_PrivateAppActive(activate, SDL_APPINPUTFOCUS));}static void myGlobalToLocal(_THIS, Point *pt){	if ( SDL_VideoSurface && !(SDL_VideoSurface->flags&SDL_FULLSCREEN) ) {		GrafPtr saveport;		GetPort(&saveport);#if TARGET_API_MAC_CARBON		SetPort(GetWindowPort(SDL_Window));#else		SetPort(SDL_Window);#endif		GlobalToLocal(pt);		SetPort(saveport);	}}/* The main MacOS event handler */static int Mac_HandleEvents(_THIS, int wait4it){	static int mouse_button = 1;	int i;	EventRecord event;#if TARGET_API_MAC_CARBON	/* There's no GetOSEvent() in the Carbon API. *sigh* */#define cooperative_multitasking 1#else	int cooperative_multitasking;	/* If we're running fullscreen, we can hog the MacOS events,	   otherwise we had better play nicely with the other apps.	*/	if ( this->screen && (this->screen->flags & SDL_FULLSCREEN) ) {		cooperative_multitasking = 0;	} else {		cooperative_multitasking = 1;	}#endif	/* If we call WaitNextEvent(), MacOS will check other processes	 * and allow them to run, and perform other high-level processing.	 */	if ( cooperative_multitasking || wait4it ) {		UInt32 wait_time;		/* Are we polling or not? */		if ( wait4it ) {			wait_time = 2147483647;		} else {			wait_time = 0;		}		WaitNextEvent(everyEvent, &event, wait_time, nil);	} else {#if ! TARGET_API_MAC_CARBON		GetOSEvent(everyEvent, &event);#endif	}#if TARGET_API_MAC_CARBON	/* for some reason, event.where isn't set ? */	GetGlobalMouse ( &event.where );#endif	/* Check for mouse motion */	if ( (event.where.h != last_where.h) ||	     (event.where.v != last_where.v) ) {		Point pt;		pt = last_where = event.where;		myGlobalToLocal(this, &pt);		SDL_PrivateMouseMotion(0, 0, pt.h, pt.v);	}	/* Check the current state of the keyboard */	if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) {		KeyMap keys;		/* Check for special non-event keys */		if ( event.modifiers != last_mods ) {			static struct {				EventModifiers mask;				SDLKey key;			} mods[] = {				{ alphaLock,		SDLK_CAPSLOCK },#if 0 /* These are handled below in the GetKeys() code */				{ cmdKey,		SDLK_LMETA },				{ shiftKey,		SDLK_LSHIFT },				{ rightShiftKey,	SDLK_RSHIFT },				{ optionKey,		SDLK_LALT },				{ rightOptionKey,	SDLK_RALT },				{ controlKey,		SDLK_LCTRL },				{ rightControlKey,	SDLK_RCTRL },#endif /* 0 */				{ 0,			0 }			};			SDL_keysym keysym;			Uint8 mode;			EventModifiers mod, mask;					/* Set up the keyboard event */			keysym.scancode = 0;			keysym.sym = SDLK_UNKNOWN;			keysym.mod = KMOD_NONE;			keysym.unicode = 0;			/* See what has changed, and generate events */			mod = event.modifiers;			for ( i=0; mods[i].mask; ++i ) {				mask = mods[i].mask;				if ( (mod&mask) != (last_mods&mask) ) {					keysym.sym = mods[i].key;					if ( (mod&mask) ||					     (mods[i].key == SDLK_CAPSLOCK) ) {						mode = SDL_PRESSED;					} else {						mode = SDL_RELEASED;					}					SDL_PrivateKeyboard(mode, &keysym);				}			}			/* Save state for next time */			last_mods = mod;		}		/* Check for normal event keys, but we have to scan the		   actual keyboard state because on MacOS X a keydown event		   is immediately followed by a keyup event.		*/		GetKeys(keys);		if ( (keys[0] != last_keys[0]) || (keys[1] != last_keys[1]) ||		     (keys[2] != last_keys[2]) || (keys[3] != last_keys[3]) ) {			SDL_keysym keysym;			int old_bit, new_bit;#ifdef DEBUG_KEYBOARD			fprintf(sterr, "New keys: 0x%x 0x%x 0x%x 0x%x\n",				new_keys[0], new_keys[1],				new_keys[2], new_keys[3]);#endif			for ( i=0; i<128; ++i ) {				old_bit = (((Uint8 *)last_keys)[i/8]>>(i%8)) & 0x01;				new_bit = (((Uint8 *)keys)[i/8]>>(i%8)) & 0x01;				if ( old_bit != new_bit ) {					/* Post the keyboard event */#ifdef DEBUG_KEYBOARD					fprintf(stderr,"Scancode: 0x%2.2X\n",i);#endif					SDL_PrivateKeyboard(new_bit,				            TranslateKey(i, event.modifiers,				                         &keysym, new_bit));				}			}			/* Save state for next time */			last_keys[0] = keys[0];			last_keys[1] = keys[1];			last_keys[2] = keys[2];			last_keys[3] = keys[3];		}	}	/* Handle normal events */	switch (event.what) {	  case mouseDown: {		WindowRef win;		short area;						area = FindWindow(event.where, &win);		/* Support switching between the SIOUX console		   and SDL_Window by clicking in the window.		 */		if ( win && (win != FrontWindow()) ) {			SelectWindow(win);		} 		switch (area) {		  case inMenuBar: /* Only the apple menu exists */			Mac_DoAppleMenu(this, MenuSelect(event.where));			HiliteMenu(0);			break;		  case inDrag:#if TARGET_API_MAC_CARBON			DragWindow(win, event.where, NULL);#else			DragWindow(win, event.where, &theQD->screenBits.bounds);#endif			break;		  case inGoAway:			if ( TrackGoAway(win, event.where) ) {				SDL_PrivateQuit();			}			break;		  case inContent:			myGlobalToLocal(this, &event.where);			/* Treat command-click as right mouse button */			if ( event.modifiers & optionKey ) {				mouse_button = 2;			} else if ( event.modifiers & cmdKey ) {				mouse_button = 3;			} else {				mouse_button = 1;			}			SDL_PrivateMouseButton(SDL_PRESSED,				mouse_button, event.where.h, event.where.v);			break;		  case inGrow: {			int newSize;			/* Don't allow resize if video mode isn't resizable */			if ( ! SDL_PublicSurface ||			     ! (SDL_PublicSurface->flags & SDL_RESIZABLE) ) {				break;			}#if TARGET_API_MAC_CARBON			newSize = GrowWindow(win, event.where, NULL);#else			newSize = GrowWindow(win, event.where, &theQD->screenBits.bounds);#endif			if ( newSize ) {#if !TARGET_API_MAC_CARBON				EraseRect ( &theQD->screenBits.bounds );#endif				SizeWindow ( win, LoWord (newSize), HiWord (newSize), 1 );				SDL_PrivateResize ( LoWord (newSize), HiWord (newSize) );			}		  	} break;		  case inZoomIn:		  case inZoomOut:			if ( TrackBox (win, event.where, area )) {				Rect rect;#if !TARGET_API_MAC_CARBON				EraseRect ( &theQD->screenBits.bounds );#endif				ZoomWindow ( win, area, 0);				if ( area == inZoomIn ) {					GetWindowUserState(SDL_Window, &rect);				} else {					GetWindowStandardState(SDL_Window, &rect);				}				SDL_PrivateResize (rect.right-rect.left,				                   rect.bottom-rect.top);			}			break;#if TARGET_API_MAC_CARBON		  case inCollapseBox:			if ( TrackBox (win, event.where, area )) {				if ( IsWindowCollapsable(win) ) {					CollapseWindow (win, !IsWindowCollapsed(win));					/* There should be something done like in inGrow case, but... */				}			}			break;#endif /* TARGET_API_MAC_CARBON */		  case inSysWindow:#if TARGET_API_MAC_CARBON			/* Never happens in Carbon? */#else			SystemClick(&event, win);#endif			break;		  default:			break;		}	  }	  break;	  case mouseUp: {		myGlobalToLocal(this, &event.where);		/* Release the mouse button we simulated in the last press.		   The drawback of this methos is we cannot press more than		   one button. However, this doesn't matter, since there is		   only a single logical mouse button, even if you have a		   multi-button mouse, this doesn't matter at all.		 */		SDL_PrivateMouseButton(SDL_RELEASED,			mouse_button, event.where.h, event.where.v);	  }	  break;#if 0 /* Handled above the switch statement */	  case keyDown: {		SDL_keysym keysym;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -