Skip to content

Commit

Permalink
Merge branch 'pr/110'
Browse files Browse the repository at this point in the history
  • Loading branch information
iProgramMC committed Apr 19, 2024
2 parents b18af84 + 3cd47a6 commit f0113cd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions platforms/sdl/base/AppPlatform_sdl_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ void AppPlatform_sdl_base::_init(std::string storageDir, SDL_Window *window)
m_bShiftPressed[0] = false;
m_bShiftPressed[1] = false;

_mousegrabbed = false;

ensureDirectoryExists(_storageDir.c_str());

m_pLogger = new Logger;
Expand Down Expand Up @@ -156,6 +158,7 @@ int AppPlatform_sdl_base::getScreenHeight() const

void AppPlatform_sdl_base::setMouseGrabbed(bool b)
{
_mousegrabbed = b;
SDL_SetWindowGrab(_window, b ? SDL_TRUE : SDL_FALSE);
SDL_SetRelativeMouseMode(b ? SDL_TRUE : SDL_FALSE);
}
Expand All @@ -164,6 +167,15 @@ void AppPlatform_sdl_base::setMouseDiff(int x, int y)
{
xrel = x;
yrel = y;

// Keep the mouse centered if its grabbed
if (_mousegrabbed)
{
int w = 0, h = 0;
SDL_GetWindowSize(_window,&w,&h);
SDL_WarpMouseInWindow(_window,w/2,h/2);
Mouse::feed(MouseButtonType::BUTTON_NONE, false, w/2,h/2);
}
}

void AppPlatform_sdl_base::getMouseDiff(int& x, int& y)
Expand Down
2 changes: 2 additions & 0 deletions platforms/sdl/base/AppPlatform_sdl_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class AppPlatform_sdl_base : public AppPlatform
int xrel;
int yrel;

bool _mousegrabbed;

Logger* m_pLogger;
SoundSystem* m_pSoundSystem;

Expand Down

0 comments on commit f0113cd

Please sign in to comment.