Exemplo n.º 1
0
		bool update()
		{
			ThreadMessages::message msg;
			while (_threadMessages.peek(msg, true))
			{

			}
#ifdef __S3E__

			s3eDeviceYield(0);
			s3eKeyboardUpdate();
			s3ePointerUpdate();

			bool done = false;

			if (s3eDeviceCheckQuitRequest())
				done = true;

			if (s3eKeyboardGetState(s3eKeyEsc) & S3E_KEY_STATE_PRESSED)
				done = true;

			return done;
#endif


	#if OXYGINE_SDL || EMSCRIPTEN

			//log::messageln("update");
			Input *input = &Input::instance;
			bool done = false;
			SDL_Event event;
			while (SDL_PollEvent(&event)) 
			{
				Event ev(Input::event_platform);
				ev.userData = &event;
				Input::instance.dispatchEvent(&ev);
				
				ObjectScript::processKeyboardEvent(&ev, getStage().get());

				switch(event.type)
				{
				case SDL_QUIT:
					done = true;
					break;
				case SDL_WINDOWEVENT:
					{					
						/*
						if (event.window.event == SDL_WINDOWEVENT_ENTER)
							active = false;
						if (event.window.event == SDL_WINDOWEVENT_LEAVE)
							active = true;
							*/

						if (event.window.event == SDL_WINDOWEVENT_MINIMIZED)
							active = false;
						if (event.window.event == SDL_WINDOWEVENT_RESTORED)
							active = true;

						bool newFocus = focus;
						if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST)
							newFocus = false;
						if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
							newFocus = true;
						if (focus != newFocus)
						{
							focus = newFocus;
#if HANDLE_FOCUS_LOST

							if (focus)							
								focusAcquired();

							log::messageln("focus: %d", (int)focus);
							Event ev(focus ? Stage::ACTIVATE : Stage::DEACTIVATE);
							if (getStage())
								getStage()->dispatchEvent(&ev);

							if (!focus)
								focusLost();							
#endif							
						}
						//log::messageln("SDL_SYSWMEVENT %d", (int)event.window.event);
						break;
					}
				case SDL_MOUSEWHEEL:
					input->sendPointerWheelEvent(event.wheel.y, &input->_pointerMouse);
					break;
				case SDL_KEYDOWN:
				{
					KeyEvent ev(KeyEvent::KEY_DOWN, &event.key);
					getStage()->dispatchEvent(&ev);
				} break;
				case SDL_KEYUP:
				{
					KeyEvent ev(KeyEvent::KEY_UP, &event.key);
					getStage()->dispatchEvent(&ev);
				} break;
#if SDL_VIDEO_OPENGL
				case SDL_MOUSEMOTION:
					input->sendPointerMotionEvent((float)event.motion.x, (float)event.motion.y, 1.0f, &input->_pointerMouse);
					break;
				case SDL_MOUSEBUTTONDOWN:
				case SDL_MOUSEBUTTONUP:
					{
						MouseButton b = MouseButton_Left;
						switch(event.button.button)
						{
							case 1: b = MouseButton_Left; break;
							case 2: b = MouseButton_Middle; break;
							case 3: b = MouseButton_Right; break;
						}

						input->sendPointerButtonEvent(b, (float)event.button.x, (float)event.button.y, 1.0f, 
							event.type == SDL_MOUSEBUTTONDOWN ? TouchEvent::TOUCH_DOWN : TouchEvent::TOUCH_UP, &input->_pointerMouse);
					}					
					break;
#else

				case SDL_FINGERMOTION:
					{
						//log::messageln("SDL_FINGERMOTION");
						Vector2 pos = convertTouch(event);
						input->sendPointerMotionEvent(
							pos.x, pos.y, event.tfinger.pressure,
							input->getTouchByID((int)event.tfinger.fingerId));
					}
				
					break;
				case SDL_FINGERDOWN:
				case SDL_FINGERUP:
					{				
						//log::messageln("SDL_FINGER");
						Vector2 pos = convertTouch(event);
						input->sendPointerButtonEvent(
							MouseButton_Touch,
							pos.x, pos.y, event.tfinger.pressure,
							event.type == SDL_FINGERDOWN ? TouchEvent::TOUCH_DOWN : TouchEvent::TOUCH_UP,
							input->getTouchByID((int)event.tfinger.fingerId));
					}				
					break;
#endif
				}
			}


			return done;
	#elif EMSCRIPTEN
			return false;
	#endif


			log::warning("update not implemented");
			return true;
		}
Exemplo n.º 2
0
		void SDL_handleEvent(SDL_Event &event, bool &done)
		{
			Input *input = &Input::instance;


#ifndef EMSCRIPTEN
			SDL_Window *wnd = SDL_GetWindowFromID(event.window.windowID);			
			void *data = SDL_GetWindowData(wnd, "_");
			spStage stage = (Stage*)data;
#else
			spStage stage = getStage();
#endif
			if (!stage)
				stage = getStage();

			Event ev(Input::event_platform);
			ev.userData = &event;
			Input::instance.dispatchEvent(&ev);

			switch (event.type)
			{
			case SDL_QUIT:
				done = true;
				break;
			case SDL_WINDOWEVENT:
			{
				/*
				if (event.window.event == SDL_WINDOWEVENT_ENTER)
				active = false;
				if (event.window.event == SDL_WINDOWEVENT_LEAVE)
				active = true;
				*/

				if (event.window.event == SDL_WINDOWEVENT_MINIMIZED)
					active = false;
				if (event.window.event == SDL_WINDOWEVENT_RESTORED)
					active = true;

				bool newFocus = focus;
				if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST)
					newFocus = false;
				if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
					newFocus = true;
				if (focus != newFocus)
				{
					focus = newFocus;
#if HANDLE_FOCUS_LOST

					if (focus)
						focusAcquired();

					log::messageln("focus: %d", (int)focus);
					Event ev(focus ? Stage::ACTIVATE : Stage::DEACTIVATE);
					if (stage)
						stage->dispatchEvent(&ev);

					if (!focus)
						focusLost();
#endif							
				}
				//log::messageln("SDL_SYSWMEVENT %d", (int)event.window.event);
				break;
			}
			case SDL_MOUSEWHEEL:
				input->sendPointerWheelEvent(stage, event.wheel.y, &input->_pointerMouse);
				break;
			case SDL_KEYDOWN:
			{
				KeyEvent ev(KeyEvent::KEY_DOWN, &event.key);
				stage->dispatchEvent(&ev);
			} break;
			case SDL_KEYUP:
			{
				KeyEvent ev(KeyEvent::KEY_UP, &event.key);
				stage->dispatchEvent(&ev);
			} break;
#if SDL_VIDEO_OPENGL
			case SDL_MOUSEMOTION:
				input->sendPointerMotionEvent(stage, (float)event.motion.x, (float)event.motion.y, 1.0f, &input->_pointerMouse);
				break;
			case SDL_MOUSEBUTTONDOWN:
			case SDL_MOUSEBUTTONUP:
			{
				MouseButton b = MouseButton_Left;
				switch (event.button.button)
				{
				case 1: b = MouseButton_Left; break;
				case 2: b = MouseButton_Middle; break;
				case 3: b = MouseButton_Right; break;
				}

				input->sendPointerButtonEvent(stage, b, (float)event.button.x, (float)event.button.y, 1.0f,
					event.type == SDL_MOUSEBUTTONDOWN ? TouchEvent::TOUCH_DOWN : TouchEvent::TOUCH_UP, &input->_pointerMouse);
			}
				break;
#else

			case SDL_FINGERMOTION:
			{
				//log::messageln("SDL_FINGERMOTION");
				Vector2 pos = convertTouch(event);
				input->sendPointerMotionEvent(stage,
					pos.x, pos.y, event.tfinger.pressure,
					input->getTouchByID((int)event.tfinger.fingerId));
			}

				break;
			case SDL_FINGERDOWN:
			case SDL_FINGERUP:
			{
				//log::messageln("SDL_FINGER");
				Vector2 pos = convertTouch(event);
				input->sendPointerButtonEvent(stage, 
					MouseButton_Touch,
					pos.x, pos.y, event.tfinger.pressure,
					event.type == SDL_FINGERDOWN ? TouchEvent::TOUCH_DOWN : TouchEvent::TOUCH_UP,
					input->getTouchByID((int)event.tfinger.fingerId));
			}
				break;
#endif
			}

		}