WinRT: fixed incorrect cursor positions when using non-native screen resolutions
This commit is contained in:
parent
377091d020
commit
9c173dcc1d
2 changed files with 16 additions and 1 deletions
|
@ -167,11 +167,25 @@ void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Applies necessary geometric transformations to raw cursor positions:
|
||||||
|
Point SDL_WinRTApp::TransformCursor(Point rawPosition)
|
||||||
|
{
|
||||||
|
if ( ! m_sdlWindowData || ! m_sdlWindowData->sdlWindow ) {
|
||||||
|
return rawPosition;
|
||||||
|
}
|
||||||
|
CoreWindow ^ nativeWindow = CoreWindow::GetForCurrentThread();
|
||||||
|
Point outputPosition;
|
||||||
|
outputPosition.X = rawPosition.X * (((float32)m_sdlWindowData->sdlWindow->w) / nativeWindow->Bounds.Width);
|
||||||
|
outputPosition.Y = rawPosition.Y * (((float32)m_sdlWindowData->sdlWindow->h) / nativeWindow->Bounds.Height);
|
||||||
|
return outputPosition;
|
||||||
|
}
|
||||||
|
|
||||||
void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
|
void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
|
||||||
{
|
{
|
||||||
if (m_sdlWindowData)
|
if (m_sdlWindowData)
|
||||||
{
|
{
|
||||||
SDL_SendMouseMotion(m_sdlWindowData->sdlWindow, 0, (int)args->CurrentPoint->Position.X, (int)args->CurrentPoint->Position.Y);
|
Point transformedPoint = TransformCursor(args->CurrentPoint->Position);
|
||||||
|
SDL_SendMouseMotion(m_sdlWindowData->sdlWindow, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ internal:
|
||||||
void SetSDLWindowData(const SDL_WindowData * windowData);
|
void SetSDLWindowData(const SDL_WindowData * windowData);
|
||||||
void UpdateWindowFramebuffer(SDL_Surface * surface, SDL_Rect * rects, int numrects);
|
void UpdateWindowFramebuffer(SDL_Surface * surface, SDL_Rect * rects, int numrects);
|
||||||
void ResizeMainTexture(int w, int h);
|
void ResizeMainTexture(int w, int h);
|
||||||
|
Windows::Foundation::Point TransformCursor(Windows::Foundation::Point rawPosition);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Event Handlers.
|
// Event Handlers.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue