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

📄 cirrdevicemacosx.mm

📁 game engine, which is useful for everyone who is interested in it. I hope you can enjoy it.
💻 MM
📖 第 1 页 / 共 2 页
字号:
bool	CIrrDeviceMacOSX::run(){	NSEvent		*event;	irr::SEvent	ievent;		os::Timer::tick();	storeMouseLocation();	event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES];	if (event != nil)	{		bzero(&ievent,sizeof(ievent));		switch([event type])		{			case NSKeyDown:				postKeyEvent(event,ievent,true);				break;							case NSKeyUp:				postKeyEvent(event,ievent,false);				break;			case NSLeftMouseDown:				ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;				ievent.MouseInput.Event = irr::EMIE_LMOUSE_PRESSED_DOWN;				postMouseEvent(event,ievent);				break;			case NSLeftMouseUp:				ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;				ievent.MouseInput.Event = irr::EMIE_LMOUSE_LEFT_UP;				postMouseEvent(event,ievent);				break;			case NSMouseMoved:			case NSLeftMouseDragged:			case NSRightMouseDragged:				ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;				ievent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;				postMouseEvent(event,ievent);				break;						case NSRightMouseDown:				ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;				ievent.MouseInput.Event = irr::EMIE_RMOUSE_PRESSED_DOWN;				postMouseEvent(event,ievent);				break;			case NSRightMouseUp:				ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;				ievent.MouseInput.Event = irr::EMIE_RMOUSE_LEFT_UP;				postMouseEvent(event,ievent);				break;			case NSScrollWheel:				ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;				ievent.MouseInput.Event = irr::EMIE_MOUSE_WHEEL;				ievent.MouseInput.Wheel = [event deltaY];				if (ievent.MouseInput.Wheel < 1.0f) ievent.MouseInput.Wheel *= 10.0f;				else ievent.MouseInput.Wheel *= 5.0f;				postMouseEvent(event,ievent);				break;			default:				[NSApp sendEvent:event];				break;		}	}		return (![[NSApp delegate] isQuit] && _active);}void	CIrrDeviceMacOSX::present(video::IImage* image, s32 windowId, core::rect<s32>* src ){}void	CIrrDeviceMacOSX::setWindowCaption(const wchar_t* text){	size_t	size;	char	title[1024];	if (_window != NULL)	{		size = wcstombs(title,text,1024);		if (size == 1024) title[1023] = 0;		[_window setTitle:[NSString stringWithCString:title length:size]];	}}bool	CIrrDeviceMacOSX::isWindowActive(){	return (_active);}void	CIrrDeviceMacOSX::postKeyEvent(void *event,irr::SEvent &ievent,bool pressed){	NSString							*str;	std::map<int,int>::const_iterator	iter;	unsigned int						result,c,mkey,mchar;	const unsigned char					*cStr;	BOOL								skipCommand;		str = [event characters];	if (str != nil && [str length] > 0)	{		mkey = mchar = 0;		skipCommand = false;		c = [str characterAtIndex:0];		iter = _keycodes.find(c);		if (iter != _keycodes.end()) mkey = (*iter).second;		else		{			cStr = (unsigned char *)[str cStringUsingEncoding:NSWindowsCP1252StringEncoding];			if (cStr != NULL && strlen((char*)cStr) > 0)			{				mchar = cStr[0];				mkey = toupper(mchar);				if ([event modifierFlags] & NSCommandKeyMask)				{					if (mkey == 'C' || mkey == 'V' || mkey == 'X')					{						mchar = 0;						skipCommand = true;					}				}			}		}		ievent.EventType = irr::EET_KEY_INPUT_EVENT;		ievent.KeyInput.Key = (irr::EKEY_CODE)mkey;		ievent.KeyInput.PressedDown = pressed;		ievent.KeyInput.Shift = ([event modifierFlags] & NSShiftKeyMask) != 0;		ievent.KeyInput.Control = ([event modifierFlags] & NSControlKeyMask) != 0;		ievent.KeyInput.Char = (irr::EKEY_CODE)mchar;		if (skipCommand) ievent.KeyInput.Control = true;		else if ([event modifierFlags] & NSCommandKeyMask) [NSApp sendEvent:(NSEvent *)event];		postEventFromUser(ievent);	}}void	CIrrDeviceMacOSX::postMouseEvent(void *event,irr::SEvent &ievent){	BOOL	post = true;		if (_window != NULL)	{		ievent.MouseInput.X = (int)[event locationInWindow].x;		ievent.MouseInput.Y = _height - (int)[event locationInWindow].y;		if (ievent.MouseInput.Y < 0) post = false;	}	else	{		ievent.MouseInput.X = (int)[NSEvent mouseLocation].x;		ievent.MouseInput.Y = _height - (int)[NSEvent mouseLocation].y;	}	if (post) postEventFromUser(ievent);	[NSApp sendEvent:(NSEvent *)event];}void	CIrrDeviceMacOSX::storeMouseLocation(){	NSPoint		p;	int			x,y;	p = [NSEvent mouseLocation];		if (_window != NULL)	{		p = [_window convertScreenToBase:p];		x = (int)p.x;		y = _height - (int)p.y;	}	else	{		x = (int)p.x;		y = _screenHeight - (int)p.y;	}	((CCursorControl *)CursorControl)->updateInternalCursorPosition(x,y);}void	CIrrDeviceMacOSX::setMouseLocation(int x,int y){	NSPoint		p;	CGPoint		c;		if (_window != NULL)	{		p.x = (float) x;		p.y = (float) (_height - y);		p = [_window convertBaseToScreen:p];		p.y = _screenHeight - p.y;	}	else	{		p.x = (float) x;		p.y = (float) (_height - y);	}	c.x = p.x;	c.y = p.y;	CGSetLocalEventsSuppressionInterval(0);	CGWarpMouseCursorPosition(c);}void	CIrrDeviceMacOSX::setCursorVisible(bool visible){	CGDirectDisplayID		display;	display = CGMainDisplayID();	if (visible) CGDisplayShowCursor(display);	else CGDisplayHideCursor(display);}void	CIrrDeviceMacOSX::initKeycodes(){	_keycodes[NSUpArrowFunctionKey] = irr::KEY_UP;	_keycodes[NSDownArrowFunctionKey] = irr::KEY_DOWN;	_keycodes[NSLeftArrowFunctionKey] = irr::KEY_LEFT;	_keycodes[NSRightArrowFunctionKey] = irr::KEY_RIGHT;	_keycodes[NSF1FunctionKey] = irr::KEY_F1;	_keycodes[NSF2FunctionKey] = irr::KEY_F2;	_keycodes[NSF3FunctionKey] = irr::KEY_F3;	_keycodes[NSF4FunctionKey] = irr::KEY_F4;	_keycodes[NSF5FunctionKey] = irr::KEY_F5;	_keycodes[NSF6FunctionKey] = irr::KEY_F6;	_keycodes[NSF7FunctionKey] = irr::KEY_F7;	_keycodes[NSF8FunctionKey] = irr::KEY_F8;	_keycodes[NSF9FunctionKey] = irr::KEY_F9;	_keycodes[NSF10FunctionKey] = irr::KEY_F10;	_keycodes[NSF11FunctionKey] = irr::KEY_F11;	_keycodes[NSF12FunctionKey] = irr::KEY_F12;	_keycodes[NSF13FunctionKey] = irr::KEY_F13;	_keycodes[NSF14FunctionKey] = irr::KEY_F14;	_keycodes[NSF15FunctionKey] = irr::KEY_F15;	_keycodes[NSF16FunctionKey] = irr::KEY_F16;	_keycodes[NSHomeFunctionKey] = irr::KEY_HOME;	_keycodes[NSEndFunctionKey] = irr::KEY_END;	_keycodes[NSInsertFunctionKey] = irr::KEY_INSERT;	_keycodes[NSDeleteFunctionKey] = irr::KEY_DELETE;	_keycodes[NSHelpFunctionKey] = irr::KEY_HELP;	_keycodes[NSSelectFunctionKey] = irr::KEY_SELECT;	_keycodes[NSPrintFunctionKey] = irr::KEY_PRINT;	_keycodes[NSExecuteFunctionKey] = irr::KEY_EXECUT;	_keycodes[NSPrintScreenFunctionKey] = irr::KEY_SNAPSHOT;	_keycodes[NSPauseFunctionKey] = irr::KEY_PAUSE;	_keycodes[NSScrollLockFunctionKey] = irr::KEY_SCROLL;	_keycodes[0x7F] = irr::KEY_BACK;	_keycodes[0x09] = irr::KEY_TAB;	_keycodes[0x0D] = irr::KEY_RETURN;	_keycodes[0x03] = irr::KEY_RETURN;	_keycodes[0x1B] = irr::KEY_ESCAPE;}#define IRRLICHT_API#if defined(_STDCALL_SUPPORTED)#define IRRCALLCONV __stdcall  // Declare the calling convention.#else#define IRRCALLCONV#endif // STDCALL_SUPPORTEDIRRLICHT_API IrrlichtDevice* IRRCALLCONV createDeviceEx(const SIrrlichtCreationParameters& param){	CIrrDeviceMacOSX* dev = new CIrrDeviceMacOSX(		param.DriverType, 		param.WindowSize, 		param.Bits,		param.Fullscreen, 		param.Stencilbuffer, 		param.Vsync,		param.AntiAlias,		param.EventReceiver,		param.SDK_version_do_not_use);	if (dev && !dev->getVideoDriver() && param.DriverType != video::EDT_NULL)	{		dev->drop();		dev = 0;	}		return dev;}}#endif

⌨️ 快捷键说明

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