Add love.window.getDisplayOrientation and a love.displayrotated callback. Resolves issue #1441.

Note that this tracks screen orientation, rather than device orientation.
This commit is contained in:
Alex Szpakowski
2018-12-17 16:19:56 -04:00
parent 43ee232897
commit d4762b4612
8 changed files with 134 additions and 0 deletions
+35
View File
@@ -369,6 +369,41 @@ Message *Event::convert(const SDL_Event &e)
case SDL_WINDOWEVENT:
msg = convertWindowEvent(e);
break;
#if SDL_VERSION_ATLEAST(2, 0, 9)
case SDL_DISPLAYEVENT:
if (e.display.event == SDL_DISPLAYEVENT_ORIENTATION)
{
auto orientation = window::Window::ORIENTATION_UNKNOWN;
switch ((SDL_DisplayOrientation) e.display.data1)
{
case SDL_ORIENTATION_UNKNOWN:
default:
orientation = window::Window::ORIENTATION_UNKNOWN;
break;
case SDL_ORIENTATION_LANDSCAPE:
orientation = window::Window::ORIENTATION_LANDSCAPE;
break;
case SDL_ORIENTATION_LANDSCAPE_FLIPPED:
orientation = window::Window::ORIENTATION_LANDSCAPE_FLIPPED;
break;
case SDL_ORIENTATION_PORTRAIT:
orientation = window::Window::ORIENTATION_PORTRAIT;
break;
case SDL_ORIENTATION_PORTRAIT_FLIPPED:
orientation = window::Window::ORIENTATION_PORTRAIT_FLIPPED;
break;
}
if (!window::Window::getConstant(orientation, txt))
txt = "unknown";
vargs.emplace_back((double)(e.display.display + 1));
vargs.emplace_back(txt);
msg = new Message("displayrotated", vargs);
}
break;
#endif
case SDL_DROPFILE:
filesystem = Module::getInstance<filesystem::Filesystem>(Module::M_FILESYSTEM);
if (filesystem != nullptr)