Allow HIDPI on macOS.

--HG--
branch : dev
This commit is contained in:
Martín Lucas Golini
2017-03-29 01:58:37 -03:00
parent b0d4d7e9db
commit 0735ded34e
3 changed files with 16 additions and 8 deletions

View File

@@ -37,8 +37,8 @@ void InputSDL::update() {
case SDL_WINDOWEVENT_RESIZED:
{
EEEvent.Type = InputEvent::VideoResize;
EEEvent.resize.w = SDLEvent.window.data1;
EEEvent.resize.h = SDLEvent.window.data2;
EEEvent.resize.w = SDLEvent.window.data1 * mDPIScale;
EEEvent.resize.h = SDLEvent.window.data2 * mDPIScale;
break;
}
case SDL_WINDOWEVENT_EXPOSED:
@@ -141,10 +141,10 @@ void InputSDL::update() {
EEEvent.Type = InputEvent::MouseMotion;
EEEvent.motion.which = SDLEvent.motion.windowID;
EEEvent.motion.state = SDLEvent.motion.state;
EEEvent.motion.x = SDLEvent.motion.x;
EEEvent.motion.y = SDLEvent.motion.y;
EEEvent.motion.xrel = SDLEvent.motion.xrel;
EEEvent.motion.yrel = SDLEvent.motion.yrel;
EEEvent.motion.x = SDLEvent.motion.x * mDPIScale;
EEEvent.motion.y = SDLEvent.motion.y * mDPIScale;
EEEvent.motion.xrel = SDLEvent.motion.xrel * mDPIScale;
EEEvent.motion.yrel = SDLEvent.motion.yrel * mDPIScale;
break;
}
case SDL_MOUSEBUTTONDOWN:
@@ -322,6 +322,13 @@ void InputSDL::injectMousePos( const Uint16& x, const Uint16& y ) {
}
void InputSDL::init() {
int realX, realY;
int scaledX, scaledY;
SDL_Window * sdlw = reinterpret_cast<WindowSDL*>( mWindow )->GetSDLWindow();
SDL_GL_GetDrawableSize(sdlw, &realX, &realY);
SDL_GetWindowSize(sdlw, &scaledX, &scaledY);
mDPIScale = (Float)realX / (Float)scaledX;
Vector2if mTempMouse;
SDL_GetMouseState( &mTempMouse.x, &mTempMouse.y );

View File

@@ -23,6 +23,7 @@ class EE_API InputSDL : public Input {
void injectMousePos( const Uint16& x, const Uint16& y );
protected:
friend class WindowSDL;
Float mDPIScale;
InputSDL( EE::Window::Window * window );

View File

@@ -126,7 +126,7 @@ bool WindowSDL::create( WindowSettings Settings, ContextSettings Context ) {
mWindow.WindowConfig.Height = mWindow.DesktopResolution.getHeight();
}
mWindow.Flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
mWindow.Flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI;
if ( mWindow.WindowConfig.Style & WindowStyle::Resize ) {
mWindow.Flags |= SDL_WINDOW_RESIZABLE;
@@ -156,7 +156,7 @@ bool WindowSDL::create( WindowSettings Settings, ContextSettings Context ) {
/// In some platforms it will not create the desired window size, so we query the real window size created
int w, h;
SDL_GetWindowSize( mSDLWindow, &w, &h );
SDL_GL_GetDrawableSize( mSDLWindow, &w, &h );
mWindow.WindowConfig.Width = w;
mWindow.WindowConfig.Height = h;