Пример #1
0
void
SDL_SetMouseFocus(SDL_Window * window)
{
    SDL_Mouse *mouse = SDL_GetMouse();

    if (mouse->focus == window) {
        return;
    }

    /* Actually, this ends up being a bad idea, because most operating
       systems have an implicit grab when you press the mouse button down
       so you can drag things out of the window and then get the mouse up
       when it happens.  So, #if 0...
    */
#if 0
    if (mouse->focus && !window) {
        /* We won't get anymore mouse messages, so reset mouse state */
        SDL_ResetMouse();
    }
#endif

    /* See if the current window has lost focus */
    if (mouse->focus) {
        SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
    }

    mouse->focus = window;

    if (mouse->focus) {
        SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
    }

    /* Update cursor visibility */
    SDL_SetCursor(NULL);
}
Пример #2
0
/* This is global for SDL_eventloop.c */
int SDL_PrivateAppActive(Uint8 gain, Uint8 state)
{
	int posted;
	Uint8 new_state;

	/* Modify the current state with the given mask */
	if ( gain ) {
		new_state = (SDL_appstate | state);
	} else {
		new_state = (SDL_appstate & ~state);
	}

	/* Drop events that don't change state */
	if ( new_state == SDL_appstate ) {
		return(0);
	}

	/* Update internal active state */
	SDL_appstate = new_state;

	/* Post the event, if desired */
	posted = 0;
	if ( SDL_ProcessEvents[SDL_ACTIVEEVENT] == SDL_ENABLE ) {
		SDL_Event event;
		SDL_memset(&event, 0, sizeof(event));
		event.type = SDL_ACTIVEEVENT;
		event.active.gain = gain;
		event.active.state = state;
		if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) {
			posted = 1;
			SDL_PushEvent(&event);
		}
	}

	/* If we lost keyboard focus, post key-up events */
	if ( (state & SDL_APPINPUTFOCUS) && !gain ) {
		SDL_ResetKeyboard();
	}
	/* If we were minimized, post button-up events */
	if ( (state & SDL_APPACTIVE) && !gain ) {
		SDL_ResetMouse();
	}
	return(posted);
}
Пример #3
0
void						CELL_ReleaseAllMouseButtons	()
{
	SDL_ResetMouse();
	memset(MouseEventMap, 0, sizeof(MouseEventMap));
}
Пример #4
0
static void ProcessSDLEvents()
{
	SDL_Event in;
	while (SDL_PollEvent(&in))
	{
		ZL_Event out;
		switch (in.type)
		{
			case SDL_MOUSEMOTION:
				if (ZL_SDL_Mouse_IgnoreMotion) { ZL_SDL_Mouse_IgnoreMotion--; continue; }
				out.type = ZL_EVENT_MOUSEMOTION;
				out.motion.which = 0;
				out.motion.state = in.motion.state;
				out.motion.x = (scalar)in.motion.x;
				out.motion.y = (scalar)in.motion.y;
				out.motion.xrel = (scalar)in.motion.xrel;
				out.motion.yrel = (scalar)in.motion.yrel;
				break;
			case SDL_MOUSEBUTTONDOWN:
			case SDL_MOUSEBUTTONUP:
				if (ZL_SDL_Mouse_IgnoreButton) { ZL_SDL_Mouse_IgnoreButton--; continue; }
				out.type = (in.type == SDL_MOUSEBUTTONDOWN ? ZL_EVENT_MOUSEBUTTONDOWN : ZL_EVENT_MOUSEBUTTONUP);
				out.button.which = 0;
				out.button.button = in.button.button;
				out.button.is_down = (in.button.state == SDL_PRESSED);
				out.button.x = (scalar)in.button.x;
				out.button.y = (scalar)in.button.y;
				break;
			case SDL_MOUSEWHEEL:
				out.type = ZL_EVENT_MOUSEWHEEL;
				out.wheel.which = 0;
				out.wheel.x = (scalar)(in.wheel.x*120);
				out.wheel.y = (scalar)(in.wheel.y*120);
				break;
			case SDL_FINGERMOTION:
				if ((out.motion.which = ZL_SDL_FingerIDGetIndex(in.tfinger.fingerId)) == 0xFF) continue;
				if (out.motion.which == 0) ZL_SDL_Mouse_IgnoreMotion = 1;
				out.type = ZL_EVENT_MOUSEMOTION;
				out.motion.state = 1;
				out.motion.x = (scalar)in.tfinger.x * (scalar)ZL_SDL_Window->w;
				out.motion.y = (scalar)in.tfinger.y * (scalar)ZL_SDL_Window->h;
				out.motion.xrel = (scalar)in.tfinger.dx * (scalar)ZL_SDL_Window->w;
				out.motion.yrel = (scalar)in.tfinger.dy * (scalar)ZL_SDL_Window->h;
				break;
			case SDL_FINGERDOWN:
			case SDL_FINGERUP:
				out.button.is_down = (in.type == SDL_FINGERDOWN);
				if ((out.motion.which = ZL_SDL_FingerIDGetIndex(out.button.is_down ? 0 : in.tfinger.fingerId)) == 0xFF) continue;
				if (out.button.is_down)
				{
					if (out.motion.which == 0)
					{
						if (!ZL_SDL_FingerCount) ZL_SDL_Mouse_IgnoreButton = 2;
						else if ((out.motion.which = ZL_SDL_FingerIDGetIndex(0, 1)) == 0xFF) continue;
					}
					ZL_SDL_FingerIDs[out.motion.which] = in.tfinger.fingerId;
					ZL_SDL_FingerCount++;
					out.type = ZL_EVENT_MOUSEBUTTONDOWN;
				}
				else
				{
					if (out.motion.which == 0) ZL_SDL_Mouse_IgnoreMotion = 0;
					ZL_SDL_FingerIDs[out.motion.which] = 0;
					ZL_SDL_FingerCount--;
					out.type = ZL_EVENT_MOUSEBUTTONUP;
				}
				out.button.button = 1;
				out.button.x = (scalar)in.tfinger.x * (scalar)ZL_SDL_Window->w;
				out.button.y = (scalar)in.tfinger.y * (scalar)ZL_SDL_Window->h;
				break;
			case SDL_KEYDOWN:
			case SDL_KEYUP:
				out.type = (in.type == SDL_KEYDOWN ? ZL_EVENT_KEYDOWN : ZL_EVENT_KEYUP);
				out.key.is_down = (in.key.state == SDL_PRESSED);
				out.key.key = (ZL_Key)in.key.keysym.scancode;
				out.key.mod = in.key.keysym.mod;
				if (in.type == SDL_KEYDOWN && (out.key.key == ZLK_TAB || out.key.key == ZLK_RETURN || out.key.key == ZLK_KP_ENTER || out.key.key == ZLK_BACKSPACE))
				{
					in.type = SDL_TEXTINPUT;
					in.text.text[0] = (out.key.key == ZLK_RETURN || out.key.key == ZLK_KP_ENTER ? '\n' : (out.key.key == ZLK_BACKSPACE ? '\b' : '\t'));
					in.text.text[1] = 0;
					SDL_PushEvent(&in);
				}
				break;
			case SDL_TEXTINPUT:
				out.type = ZL_EVENT_TEXTINPUT;
				#if (defined(_MSC_VER) && !defined(WINAPI_FAMILY))
				//if compiler errors here, SDL text event size does not match ZL text event size
				enum { __asrt = 1/(int)(sizeof(out.text.text) == sizeof(in.text.text)) };
				#endif
				if (in.text.text[1]) memcpy(out.text.text, in.text.text, sizeof(out.text.text));
				else { out.text.text[0] = (in.text.text[0] == '\r' ? '\n' : in.text.text[0]) ; out.text.text[1] = 0; }
				break;
			case SDL_JOYAXISMOTION:
				out.type = ZL_EVENT_JOYAXISMOTION;
				out.jaxis.which = in.jaxis.which;
				out.jaxis.axis = in.jaxis.axis;
				out.jaxis.value = in.jaxis.value;
				break;
			case SDL_JOYBALLMOTION:
				out.type = ZL_EVENT_JOYBALLMOTION;
				out.jball.which = in.jball.which;
				out.jball.ball = in.jball.ball;
				out.jball.xrel = in.jball.xrel;
				out.jball.yrel = in.jball.yrel;
				break;
			case SDL_JOYHATMOTION:
				out.type = ZL_EVENT_JOYHATMOTION;
				out.jhat.which = in.jhat.which;
				out.jhat.hat = in.jhat.hat;
				out.jhat.value = in.jhat.value;
				break;
			case SDL_JOYBUTTONDOWN:
			case SDL_JOYBUTTONUP:
				out.type = (in.type == SDL_JOYBUTTONDOWN ? ZL_EVENT_JOYBUTTONDOWN : ZL_EVENT_JOYBUTTONUP);
				out.jbutton.which = in.jbutton.which;
				out.jbutton.button = in.jbutton.button;
				out.jbutton.is_down = (in.jbutton.state == SDL_PRESSED);
				break;
			case SDL_QUIT:
				out.type = ZL_EVENT_QUIT;
				break;
			case SDL_WINDOWEVENT:
				if (in.window.event == SDL_WINDOWEVENT_EXPOSED) continue;
				#if defined(__WIN32__) && defined(WM_MOUSELEAVE) && defined(TME_LEAVE)
				if (in.window.event == SDL_WINDOWEVENT_ENTER) //fix for SDL2, might not work with MINGW...
				{ TRACKMOUSEEVENT t = { sizeof(TRACKMOUSEEVENT), TME_LEAVE, *(((HWND*)(ZL_SDL_Window->driverdata))+1), 0 }; TrackMouseEvent(&t); }
				#endif
				out.type = ZL_EVENT_WINDOW;
				if (in.window.event == SDL_WINDOWEVENT_MOVED)          out.window.event = ZL_WINDOWEVENT_MOVED;
				else if (in.window.event == SDL_WINDOWEVENT_CLOSE)     out.window.event = ZL_WINDOWEVENT_CLOSE;
				else if (in.window.event == SDL_WINDOWEVENT_MINIMIZED) out.window.event = ZL_WINDOWEVENT_MINIMIZED;
				else if (in.window.event == SDL_WINDOWEVENT_RESTORED)  out.window.event = ZL_WINDOWEVENT_RESTORED;
				else if (in.window.event == SDL_WINDOWEVENT_MOVED)     out.window.event = ZL_WINDOWEVENT_MOVED;
				else if (in.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
				{
					out.window.event = ZL_WINDOWEVENT_RESIZED;
					out.window.data1 = in.window.data1;
					out.window.data2 = in.window.data2;
				}
				else
				{
					out.window.event = ZL_WINDOWEVENT_FOCUS;
					//linux SDL loses input focus when switching to fullscreen
					if (ZL_SDL_Window->flags & SDL_WINDOW_FULLSCREEN) ZL_SDL_Window->flags |= SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS;
				}
				#ifndef ZL_USE_EXTERNAL_SDL
				if ((out.window.event == ZL_WINDOWEVENT_MINIMIZED || out.window.event == ZL_WINDOWEVENT_FOCUS) && !ZL_WINDOWFLAGS_HAS(ZL_WINDOW_INPUT_FOCUS)) SDL_ResetMouse();
				#endif
				break;

			#if 0 //defined(ZILLALOG)
			case SDL_APP_TERMINATING: printf("UNUSED SDL EVENT [SDL_APP_TERMINATING]\n"); continue;
			case SDL_APP_LOWMEMORY: printf("UNUSED SDL EVENT [SDL_APP_LOWMEMORY]\n"); continue;
			case SDL_APP_WILLENTERBACKGROUND: printf("UNUSED SDL EVENT [SDL_APP_WILLENTERBACKGROUND]\n"); continue;
			case SDL_APP_DIDENTERBACKGROUND: printf("UNUSED SDL EVENT [SDL_APP_DIDENTERBACKGROUND]\n"); continue;
			case SDL_APP_WILLENTERFOREGROUND: printf("UNUSED SDL EVENT [SDL_APP_WILLENTERFOREGROUND]\n"); continue;
			case SDL_APP_DIDENTERFOREGROUND: printf("UNUSED SDL EVENT [SDL_APP_DIDENTERFOREGROUND]\n"); continue;
			case SDL_SYSWMEVENT: printf("UNUSED SDL EVENT [SDL_SYSWMEVENT]\n"); continue;
			case SDL_TEXTEDITING: printf("UNUSED SDL EVENT [SDL_TEXTEDITING]\n"); continue;
			case SDL_JOYDEVICEADDED: printf("UNUSED SDL EVENT [SDL_JOYDEVICEADDED]\n"); continue;
			case SDL_JOYDEVICEREMOVED: printf("UNUSED SDL EVENT [SDL_JOYDEVICEREMOVED]\n"); continue;
			case SDL_CONTROLLERAXISMOTION: printf("UNUSED SDL EVENT [SDL_CONTROLLERAXISMOTION]\n"); continue;
			case SDL_CONTROLLERBUTTONDOWN: printf("UNUSED SDL EVENT [SDL_CONTROLLERBUTTONDOWN]\n"); continue;
			case SDL_CONTROLLERBUTTONUP: printf("UNUSED SDL EVENT [SDL_CONTROLLERBUTTONUP]\n"); continue;
			case SDL_CONTROLLERDEVICEADDED: printf("UNUSED SDL EVENT [SDL_CONTROLLERDEVICEADDED]\n"); continue;
			case SDL_CONTROLLERDEVICEREMOVED: printf("UNUSED SDL EVENT [SDL_CONTROLLERDEVICEREMOVED]\n"); continue;
			case SDL_CONTROLLERDEVICEREMAPPED: printf("UNUSED SDL EVENT [SDL_CONTROLLERDEVICEREMAPPED]\n"); continue;
			case SDL_FINGERDOWN: printf("UNUSED SDL EVENT [SDL_FINGERDOWN]\n"); continue;
			case SDL_FINGERUP: printf("UNUSED SDL EVENT [SDL_FINGERUP]\n"); continue;
			case SDL_FINGERMOTION: printf("UNUSED SDL EVENT [SDL_FINGERMOTION]\n"); continue;
			case SDL_DOLLARGESTURE: printf("UNUSED SDL EVENT [SDL_DOLLARGESTURE]\n"); continue;
			case SDL_DOLLARRECORD: printf("UNUSED SDL EVENT [SDL_DOLLARRECORD]\n"); continue;
			case SDL_MULTIGESTURE: printf("UNUSED SDL EVENT [SDL_MULTIGESTURE]\n"); continue;
			case SDL_CLIPBOARDUPDATE: printf("UNUSED SDL EVENT [SDL_CLIPBOARDUPDATE]\n"); continue;
			case SDL_DROPFILE: printf("UNUSED SDL EVENT [SDL_DROPFILE]\n"); continue;
			case SDL_RENDER_TARGETS_RESET: printf("UNUSED SDL EVENT [SDL_RENDER_TARGETS_RESET]\n"); continue;
			case SDL_USEREVENT: printf("UNUSED SDL EVENT [SDL_USEREVENT]\n"); continue;
			#endif
			default: continue;
		}
		ZL_Display_Process_Event(out);
	}
}