Beispiel #1
0
void SDL_WarpMouse(int x, int y)
{
	const int client_x = x, client_y = y;
	const POINT screen_pt = ScreenFromClient(client_x, client_y);
	SetCursorPos(screen_pt.x, screen_pt.y);
	mouse_x = screen_pt.x;
	mouse_y = screen_pt.y;
}
Beispiel #2
0
void SDL_WarpMouse(int x, int y)
{
	//mouse_update();
	// SDL interface provides for int, but the values should be
	// idealized client coords (>= 0)
	//mouse_moved(x, y);

	const int client_x = x, client_y = y;
	const POINT screen_pt = ScreenFromClient(client_x, client_y);
	SetCursorPos(screen_pt.x, screen_pt.y);
	mouse_x = screen_pt.x;
	mouse_y = screen_pt.y;
}
Beispiel #3
0
// (we define a new function signature since the windowsx.h message crackers
// don't provide for passing uMsg)
LRESULT OnMouseButton(HWND hWnd, UINT uMsg, int client_x, int client_y, UINT flags)
{
	int button;
	int state;
	switch(uMsg)
	{
	case WM_LBUTTONDOWN:
		button = SDL_BUTTON_LEFT;
		state = SDL_PRESSED;
		break;
	case WM_LBUTTONUP:
		button = SDL_BUTTON_LEFT;
		state = SDL_RELEASED;
		break;
	case WM_RBUTTONDOWN:
		button = SDL_BUTTON_RIGHT;
		state = SDL_PRESSED;
		break;
	case WM_RBUTTONUP:
		button = SDL_BUTTON_RIGHT;
		state = SDL_RELEASED;
		break;
	case WM_MBUTTONDOWN:
		button = SDL_BUTTON_MIDDLE;
		state = SDL_PRESSED;
		break;
	case WM_MBUTTONUP:
		button = SDL_BUTTON_MIDDLE;
		state = SDL_RELEASED;
		break;
	}

	const POINT screen_pt = ScreenFromClient(client_x, client_y);

	// mouse capture
	static int outstanding_press_events = 0;
	static SDL_GrabMode oldMode;
	static bool saveMode = false;
	if(state == SDL_PRESSED)
	{
		// grab mouse to ensure we get up events
		if(++outstanding_press_events > 0)
		{
			if (!saveMode)
			{
				oldMode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
				saveMode = true;
			}
#ifndef DEBUG
			SDL_WM_GrabInput(SDL_GRAB_ON);
#endif
			SetCursorPos(screen_pt.x, screen_pt.y);
		}
	}
	else
	{
		// release after all up events received
		if(--outstanding_press_events <= 0)
		{
			if (saveMode)
			{
				SDL_WM_GrabInput(oldMode);
				SetCursorPos(screen_pt.x, screen_pt.y);
				saveMode = false;
			}
			outstanding_press_events = 0;
		}
	}

	// update button bitfield
	if(state == SDL_PRESSED)
		mouse_buttons |= SDL_BUTTON(button);
	else
		mouse_buttons &= ~SDL_BUTTON(button);

	int x, y;
	if(GetCoords(screen_pt.x, screen_pt.y, x, y))
		queue_button_event(button, state, x, y);
	return 0;
}
Beispiel #4
0
// (we define a new function signature since the windowsx.h message crackers
// don't provide for passing uMsg)
LRESULT OnMouseButton(HWND hWnd, UINT uMsg, int client_x, int client_y, UINT flags)
{
	int button;
	int state;
	switch(uMsg)
	{
	case WM_LBUTTONDOWN:
		button = SDL_BUTTON_LEFT;
		state = SDL_PRESSED;
		break;
	case WM_LBUTTONUP:
		button = SDL_BUTTON_LEFT;
		state = SDL_RELEASED;
		break;
	case WM_RBUTTONDOWN:
		button = SDL_BUTTON_RIGHT;
		state = SDL_PRESSED;
		break;
	case WM_RBUTTONUP:
		button = SDL_BUTTON_RIGHT;
		state = SDL_RELEASED;
		break;
	case WM_MBUTTONDOWN:
		button = SDL_BUTTON_MIDDLE;
		state = SDL_PRESSED;
		break;
	case WM_MBUTTONUP:
		button = SDL_BUTTON_MIDDLE;
		state = SDL_RELEASED;
		break;
	}

	//! mouse capture
	if (!fullscreen) {
		const POINT screen_pt = ScreenFromClient(client_x, client_y);

		static int outstanding_press_events = 0;
		static SDL_GrabMode oldMode;
		static bool saveMode = false;
		if(state == SDL_PRESSED) {
			//! grab mouse to ensure we get up events
			if(++outstanding_press_events > 0)
			{
				if (!saveMode)
				{
					oldMode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
					saveMode = true;
				}

				POINT pt;
				GetCursorPos(&pt); //! SDL_WM_GrabInput sometimes moves the cursor, so we have to reset it afterwards
				SDL_WM_GrabInput(SDL_GRAB_ON);
				SetCursorPos(pt.x, pt.y);
			}
		} else {
			//! release after all up events received
			if(--outstanding_press_events <= 0)
			{
				if (saveMode)
				{
					POINT pt;
					GetCursorPos(&pt); //! SDL_WM_GrabInput sometimes moves the cursor, so we have to reset it afterwards
					SDL_WM_GrabInput(oldMode);
					SetCursorPos(pt.x, pt.y);
					saveMode = false;
				}
				outstanding_press_events = 0;
			}
		}

		//! only queue clicks inside of the window
		int x, y;
		if(GetCoords(screen_pt.x, screen_pt.y, x, y))
			queue_button_event(button, state, x, y);
	} else {
		//! no outside checking needed for fullscreen
		queue_button_event(button, state, client_x, client_y);
	}


	return 0;
}