Пример #1
0
/**
 * @brief Check call to SDL_GetMouseFocus
 *
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetMouseFocus
 */
int
mouse_getMouseFocus(void *arg)
{
    const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT;
    int x, y;
    SDL_Window *window;
    SDL_Window *focusWindow;

    /* Get focus - focus non-deterministic */
    focusWindow = SDL_GetMouseFocus();
    SDLTest_AssertPass("SDL_GetMouseFocus()");

        /* Create test window */
    window = _createMouseSuiteTestWindow();
    if (window == NULL) return TEST_ABORTED;

    /* Mouse to random position inside window */
    x = SDLTest_RandomIntegerInRange(1, w-1);
    y = SDLTest_RandomIntegerInRange(1, h-1);
    SDL_WarpMouseInWindow(window, x, y);
    SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);

    /* Pump events to update focus state */
    SDL_PumpEvents();
    SDLTest_AssertPass("SDL_PumpEvents()");

        /* Get focus with explicit window setup - focus deterministic */
    focusWindow = SDL_GetMouseFocus();
    SDLTest_AssertPass("SDL_GetMouseFocus()");
    SDLTest_AssertCheck (focusWindow != NULL, "Check returned window value is not NULL");
    SDLTest_AssertCheck (focusWindow == window, "Check returned window value is test window");

    /* Mouse to random position outside window */
    x = SDLTest_RandomIntegerInRange(-9, -1);
    y = SDLTest_RandomIntegerInRange(-9, -1);
    SDL_WarpMouseInWindow(window, x, y);
    SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);

        /* Clean up test window */
    _destroyMouseSuiteTestWindow(window);

    /* Pump events to update focus state */
    SDL_PumpEvents();
    SDLTest_AssertPass("SDL_PumpEvents()");

        /* Get focus for non-existing window */
    focusWindow = SDL_GetMouseFocus();
    SDLTest_AssertPass("SDL_GetMouseFocus()");
    SDLTest_AssertCheck (focusWindow == NULL, "Check returned window value is NULL");


    return TEST_COMPLETED;
}
Пример #2
0
	bool Multitouch::wasTouchActive(Window*window, unsigned int touchID)
	{
		if(window == nullptr)
		{
			SDL_Window*sdlwin = SDL_GetMouseFocus();
			if(sdlwin != nullptr)
			{
				window = EventManager::getWindowFromID(SDL_GetWindowID(sdlwin));
				if(window == nullptr)
				{
					return false;
				}
			}
		}
		
		bool pressed = false;
		Multitouch_state_mutex.lock();
		unsigned int index = Multitouch_indexOfData(Multitouch_prevActiveTouches, window, touchID);
		if(index != ARRAYLIST_NOTFOUND)
		{
			pressed = true;
		}
		Multitouch_state_mutex.unlock();
		
		return pressed;
	}
Пример #3
0
	Vector2d Multitouch::getPreviousPosition(Window*window, unsigned int touchID)
	{
		if(window == nullptr)
		{
			SDL_Window*sdlwin = SDL_GetMouseFocus();
			if(sdlwin != nullptr)
			{
				window = EventManager::getWindowFromID(SDL_GetWindowID(sdlwin));
				if(window == nullptr)
				{
					return Vector2d(0,0);
				}
			}
		}
		
		Multitouch_state_mutex.lock();
		unsigned int index = Multitouch_indexOfData(Multitouch_prevActiveTouches, window, touchID);
		if(index == ARRAYLIST_NOTFOUND)
		{
			Multitouch_state_mutex.unlock();
			return Vector2d(0,0);
		}
		Vector2d vect = Multitouch_prevActiveTouches.get(index).position;
		Multitouch_state_mutex.unlock();
		return vect;
	}
Пример #4
0
	Vector2d Mouse::getPreviousPosition(Window*window, unsigned int mouseIndex)
	{
		if(window == nullptr)
		{
			SDL_Window*sdlwin = SDL_GetMouseFocus();
			if(sdlwin != nullptr)
			{
				window = EventManager::getWindowFromID(SDL_GetWindowID(sdlwin));
				if(window == nullptr)
				{
					return Vector2d(0,0);
				}
			}
		}
		
		Mouse_state_mutex.lock();
		unsigned int index = Mouse_indexOfData(Mouse_prevStates, window, mouseIndex);
		if(index == ARRAYLIST_NOTFOUND)
		{
			Mouse_state_mutex.unlock();
			return Vector2d(0,0);
		}
		Vector2d vect = Mouse_prevStates.get(index).position;
		Mouse_state_mutex.unlock();
		return vect;
	}
Пример #5
0
	bool Mouse::wasButtonPressed(Window*window, unsigned int mouseIndex, Mouse::Button button)
	{
		if(window == nullptr)
		{
			SDL_Window*sdlwin = SDL_GetMouseFocus();
			if(sdlwin != nullptr)
			{
				window = EventManager::getWindowFromID(SDL_GetWindowID(sdlwin));
				if(window == nullptr)
				{
					return false;
				}
			}
		}
		
		bool pressed = false;
		Mouse_state_mutex.lock();
		unsigned int index = Mouse_indexOfData(Mouse_prevStates, window, mouseIndex);
		if(index != ARRAYLIST_NOTFOUND)
		{
			if(Mouse_prevStates[index].state[button])
			{
				pressed = true;
			}
		}
		Mouse_state_mutex.unlock();
		
		return pressed;
	}
Пример #6
0
bool MouseCursor::hasFocus() const {
#if SDL_VERSION_ATLEAST(2,0,0)
    return (SDL_GetMouseFocus() == display.sdl_window);
#else
    return (SDL_GetAppState() & SDL_APPMOUSEFOCUS);
#endif
}
Пример #7
0
void FLinuxCursor::SetPosition( const int32 X, const int32 Y )
{
	int WndX, WndY;

	SDL_HWindow WndFocus = SDL_GetMouseFocus();

	SDL_GetWindowPosition( WndFocus, &WndX, &WndY );	//	get top left
	SDL_WarpMouseInWindow( NULL, X - WndX, Y - WndY );
}
Пример #8
0
GHOST_TSuccess GHOST_SystemSDL::setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y)
{
  int x_win, y_win;
  SDL_Window *win = SDL_GetMouseFocus();
  SDL_GetWindowPosition(win, &x_win, &y_win);

  SDL_WarpMouseInWindow(win, x - x_win, y - y_win);
  return GHOST_kSuccess;
}
Пример #9
0
void Cursor::render(Scene &parent)
{
	if(SDL_GetMouseFocus() != parent.app().getWindow())
	{
		return;
	}

	int width, height;
	SDL_GetWindowSize(parent.app().getWindow(), &width, &height);
	int mouseX, mouseY;
	SDL_GetMouseState(&mouseX, &mouseY);

	int left = mouseX + offsetX;
	int right = left + texture.width();
	int top = height - mouseY - offsetY;
	int bottom = top - texture.height();

	glPushAttrib(GL_ENABLE_BIT);
	{
		glDisable(GL_DEPTH_TEST);
		glDisable(GL_LIGHTING);

		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		{
			glLoadIdentity();
			glOrtho(0, width, 0, height, -1, 1);
			glMatrixMode(GL_MODELVIEW);
			glPushMatrix();
			{
				glLoadIdentity();
				glBindTexture(texture);
				glBegin(GL_QUADS);
				{
					glTexCoord2f(0, 0);
					glVertex2i(left, top);
					glTexCoord2f(0, 1);
					glVertex2i(left, bottom);
					glTexCoord2f(1, 1);
					glVertex2i(right, bottom);
					glTexCoord2f(1, 0);
					glVertex2i(right, top);
				}
				glEnd();
			}
			glPopMatrix();
		}
		glMatrixMode(GL_PROJECTION);
		glPopMatrix();
		glMatrixMode(GL_MODELVIEW);
	}
	glPopAttrib();
}
Пример #10
0
static int
WIN_ShowCursor(SDL_Cursor * cursor)
{
    if (cursor) {
        SDL_cursor = (HCURSOR)cursor->driverdata;
    } else {
        SDL_cursor = NULL;
    }
    if (SDL_GetMouseFocus() != NULL) {
        SetCursor(SDL_cursor);
    }
    return 0;
}
Пример #11
0
GHOST_TSuccess GHOST_SystemSDL::getCursorPosition(GHOST_TInt32 &x, GHOST_TInt32 &y) const
{
  int x_win, y_win;
  SDL_Window *win = SDL_GetMouseFocus();
  SDL_GetWindowPosition(win, &x_win, &y_win);

  int xi, yi;
  SDL_GetMouseState(&xi, &yi);
  x = xi + x_win;
  y = yi + x_win;

  return GHOST_kSuccess;
}
Пример #12
0
static int
Emscripten_ShowCursor(SDL_Cursor* cursor)
{
    Emscripten_CursorData *curdata;
    if (SDL_GetMouseFocus() != NULL) {
        if(cursor && cursor->driverdata) {
            curdata = (Emscripten_CursorData *) cursor->driverdata;

            if(curdata->system_cursor) {
                EM_ASM_INT({
                    if (Module['canvas']) {
                        Module['canvas'].style['cursor'] = Module['Pointer_stringify']($0);
                    }
                    return 0;
                }, curdata->system_cursor);
            }
Пример #13
0
	point sdl_window::mouse_position() const
	{
		int x, y;
		SDL_Window* mouseFocus = SDL_GetMouseFocus();
		SDL_GetMouseState(&x, &y);
		if (mouseFocus != 0)
		{
			int mfx, mfy;
			SDL_GetWindowPosition(mouseFocus, &mfx, &mfy);
			x += mfx;
			y += mfy;
			SDL_GetWindowPosition(iHandle, &mfx, &mfy);
			x -= mfx;
			y -= mfy;
		}
		return point(static_cast<coordinate>(x), static_cast<coordinate>(y));
	}
Пример #14
0
static void IN_DeactivateMouse(void)
{
	if (!SDL_WasInit(SDL_INIT_VIDEO))
	{
		return;
	}

	// Always show the cursor when the mouse is disabled,
	// but not when fullscreen
	if (!cls.glconfig.isFullscreen)
	{
#if 0
		if ((Key_GetCatcher() == KEYCATCH_UI) &&
		    screen == SDL_GetMouseFocus())
		{
			// TODO: (SDL_GetAppState() & SDL_APPMOUSEFOCUS))
			IN_GrabMouse(qtrue, qtrue);
		}
		else
#endif
		{
			IN_GrabMouse(qfalse, qfalse);
		}
	}

	if (!mouseAvailable)
	{
		return;
	}

	if (mouseActive)
	{
		IN_GobbleMotionEvents();
		IN_GrabMouse(qfalse, qfalse);

		// Don't warp the mouse unless the cursor is within the window
		if (SDL_GetWindowFlags(mainScreen) & SDL_WINDOW_MOUSE_FOCUS)
		{
			SDL_WarpMouseInWindow(mainScreen, cls.glconfig.vidWidth / 2, cls.glconfig.vidHeight / 2);
		}

		mouseActive = qfalse;
	}
}
Пример #15
0
	bool Mouse::didButtonRelease(Window*window, unsigned int mouseIndex, Mouse::Button button)
	{
		if(window == nullptr)
		{
			SDL_Window*sdlwin = SDL_GetMouseFocus();
			if(sdlwin != nullptr)
			{
				window = EventManager::getWindowFromID(SDL_GetWindowID(sdlwin));
			}
		}
		
		Mouse_state_mutex.lock();
		bool released = false;
		if(Mouse::wasButtonPressed(window, mouseIndex, button) && !Mouse::isButtonPressed(window, mouseIndex, button))
		{
			released = true;
		}
		Mouse_state_mutex.unlock();
		return released;
	}
Пример #16
0
void DoInput(photon_instance &instance, float time){
    photon_input &input = instance.input;

    DoInputSingle(input.left, input);
    DoInputSingle(input.right, input);
    DoInputSingle(input.up, input);
    DoInputSingle(input.down, input);
    DoInputSingle(input.select, input);
    DoInputSingle(input.back, input);

    DoInputSingle(input.pause, input);

    DoInputSingle(input.interact, input);
    DoInputSingle(input.move_right, input);
    DoInputSingle(input.move_left, input);
    DoInputSingle(input.move_up, input);
    DoInputSingle(input.move_down, input);
    DoInputSingle(input.camera_right, input);
    DoInputSingle(input.camera_left, input);
    DoInputSingle(input.camera_up, input);
    DoInputSingle(input.camera_down, input);
    DoInputSingle(input.rotate_clockwise, input);
    DoInputSingle(input.rotate_counter_clockwise, input);
    DoInputSingle(input.zoom_in, input);
    DoInputSingle(input.zoom_out, input);
    DoInputSingle(input.next_item, input);
    DoInputSingle(input.previous_item, input);

    if(instance.gui.load_save_menu.loading || instance.gui.load_save_menu.saving){
        photon_gui_load_save_menu &load_save_menu = instance.gui.load_save_menu;
        if(IsActivated(input.select)){
            gui::ConfirmLoadSave(instance);
        }
        if(IsActivated(input.back)){
            gui::CancelLoadSave(instance);
        }
        if(IsActivated(input.left)){
            if(load_save_menu.cursor > 0){
                load_save_menu.cursor--;
            }
        }
        if(IsActivated(input.right)){
            if(++load_save_menu.cursor > load_save_menu.filename.length()){
                load_save_menu.cursor = load_save_menu.filename.length();
            }
        }
        if(IsActivated(input.up)){
            if(--load_save_menu.current_file_index < 0){
                load_save_menu.current_file_index = load_save_menu.file_list.size() - 1;
            }
            load_save_menu.filename = load_save_menu.file_list[load_save_menu.current_file_index];
        }
        if(IsActivated(input.down)){
            if(++load_save_menu.current_file_index >= (int)load_save_menu.file_list.size()){
                load_save_menu.current_file_index = 0;
            }
            load_save_menu.filename = load_save_menu.file_list[load_save_menu.current_file_index];
        }

    }else if(!instance.level.is_valid){
        photon_gui_button_list &menu = instance.gui.main_menu;
        if(IsActivated(input.select)){
            gui::ActivateButton(instance, menu, menu.highlighted);
        }
        if(IsActivated(input.up)){
            if(--menu.highlighted < 0){
                menu.highlighted = menu.buttons.size() - 1;
            }
        }
        if(IsActivated(input.down)){
            if(++menu.highlighted >= (int8_t)menu.buttons.size()){
                menu.highlighted = 0;
            }
        }
    }else if(instance.paused){
        photon_gui_button_list &menu = instance.gui.pause_menu;
        if(IsActivated(input.select)){
            gui::ActivateButton(instance, menu, menu.highlighted);
        }
        if(IsActivated(input.back) || IsActivated(input.pause)){
            instance.paused = false;
        }
        if(IsActivated(input.up)){
            if(--menu.highlighted < 0){
                menu.highlighted = menu.buttons.size() - 1;
            }
        }
        if(IsActivated(input.down)){
            if(++menu.highlighted >= (int8_t)menu.buttons.size()){
                menu.highlighted = 0;
            }
        }
    }else{
        instance.player.location.x += (input.move_right.current_state - input.move_left.current_state) * time * instance.camera_offset.z;
        instance.player.location.y += (input.move_up.current_state - input.move_down.current_state) * time * instance.camera_offset.z;

        glm::vec2 cam_offset(input.camera_right.current_state - input.camera_left.current_state,
                             input.camera_up.current_state - input.camera_down.current_state);

        // TODO - make a setting that enables/disables screen edges.
        // if only SDL_GetMouseState worked when the cursor is outside the window... oh well...
        if(SDL_GetMouseFocus() == instance.window.window_SDL){
            glm::ivec2 mouse;
            uint32_t buttons = SDL_GetMouseState(&mouse.x, &mouse.y);

            // if the mouse position is (0,0) chances are it hasn't recieved the first event yet... I should try to find a better way to fix this, but this will do for now...
            if(instance.settings.screen_edges && !(mouse == glm::ivec2(0))){
                cam_offset.x += (std::max(80 + mouse.x - int(instance.window.width),  0) - std::max(80 - mouse.x, 0)) / 80.0f;
                cam_offset.y += (std::max(80 - mouse.y, 0) - std::max(80 + mouse.y - int(instance.window.height), 0)) / 80.0f;
            }

            if(input.enable_mouse){
                glm::vec2 delta = WindowToWorldCoord(instance, mouse.x, mouse.y) - instance.player.location;
                if(buttons & SDL_BUTTON_LMASK){
                    if(glm::length(delta) > 0.5f){
                        instance.player.location += delta * time;
                    }
                }
                if(buttons & SDL_BUTTON_RMASK){
                    float angle = glm::degrees(glm::atan(delta.y, delta.x));

                    blocks::OnRotate(glm::uvec2(instance.player.location + 0.5f), instance.level, angle);
                }
            }
        }

        cam_offset *= instance.camera_offset.z * 0.5f * time * 2.0f;

        instance.camera_offset.x += cam_offset.x;
        instance.camera_offset.y += cam_offset.y;
        instance.camera_offset.x /= 1.0f + (time * 2.0f);
        instance.camera_offset.y /= 1.0f + (time * 2.0f);

        if(IsActivated(input.interact)){
            blocks::OnPhotonInteract(glm::uvec2(instance.player.location + glm::vec2(0.5f)), instance.level, instance.player);
        }
        if(IsActivated(input.rotate_clockwise)){
            blocks::OnRotate(glm::uvec2(instance.player.location + glm::vec2(0.5f)), instance.level);
        }
        if(IsActivated(input.rotate_counter_clockwise)){
            blocks::OnRotate(glm::uvec2(instance.player.location + glm::vec2(0.5f)), instance.level, true);
        }
        if(IsActivated(input.next_item)){
            player::NextItem(instance.player);
        }
        if(IsActivated(input.previous_item)){
            player::PreviousItem(instance.player);
        }

        instance.camera_offset.z -= (input.zoom_in.current_state - input.zoom_out.current_state) * instance.camera_offset.z * 0.5f * time;

        if(IsActivated(input.pause)){
            instance.paused = true;
        }
    }
}
Пример #17
0
bool Window::hasMouseFocus() const
{
	return (window && SDL_GetMouseFocus() == window);
}
Пример #18
0
void Platform::setMousePosition(s32 x, s32 y) {
	SDL_WarpMouseInWindow(SDL_GetMouseFocus(), x, y);
}
Пример #19
0
bool FLinuxWindow::IsForegroundWindow() const
{
	return (HWnd == SDL_GetMouseFocus() || HWnd == SDL_GetKeyboardFocus());
}