Clean up MSVC warnings in CIrrDeviceSDL.{h,cpp} (#14872)

The only changes are to add a number of `static_cast`s to make implicit
type conversions explicit.
This commit is contained in:
JosiahWI 2024-07-27 11:28:54 -05:00 committed by GitHub
parent 7625f88a0c
commit ac284e61b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 16 deletions

@ -647,8 +647,9 @@ bool CIrrDeviceSDL::createWindowWithContext()
if (ScaleX != 1.0f || ScaleY != 1.0f) { if (ScaleX != 1.0f || ScaleY != 1.0f) {
// The given window size is in pixels, not in screen coordinates. // The given window size is in pixels, not in screen coordinates.
// We can only do the conversion now since we didn't know the scale before. // We can only do the conversion now since we didn't know the scale before.
SDL_SetWindowSize(Window, CreationParams.WindowSize.Width / ScaleX, SDL_SetWindowSize(Window,
CreationParams.WindowSize.Height / ScaleY); static_cast<int>(CreationParams.WindowSize.Width / ScaleX),
static_cast<int>(CreationParams.WindowSize.Height / ScaleY));
// Re-center, otherwise large, non-maximized windows go offscreen. // Re-center, otherwise large, non-maximized windows go offscreen.
SDL_SetWindowPosition(Window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); SDL_SetWindowPosition(Window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
updateSizeAndScale(); updateSizeAndScale();
@ -717,10 +718,12 @@ bool CIrrDeviceSDL::run()
irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT; irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;
irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED; irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;
MouseX = irrevent.MouseInput.X = SDL_event.motion.x * ScaleX; MouseX = irrevent.MouseInput.X =
MouseY = irrevent.MouseInput.Y = SDL_event.motion.y * ScaleY; static_cast<s32>(SDL_event.motion.x * ScaleX);
MouseXRel = SDL_event.motion.xrel * ScaleX; MouseY = irrevent.MouseInput.Y =
MouseYRel = SDL_event.motion.yrel * ScaleY; static_cast<s32>(SDL_event.motion.y * ScaleY);
MouseXRel = static_cast<s32>(SDL_event.motion.xrel * ScaleX);
MouseYRel = static_cast<s32>(SDL_event.motion.yrel * ScaleY);
irrevent.MouseInput.ButtonStates = MouseButtonStates; irrevent.MouseInput.ButtonStates = MouseButtonStates;
irrevent.MouseInput.Shift = (keymod & KMOD_SHIFT) != 0; irrevent.MouseInput.Shift = (keymod & KMOD_SHIFT) != 0;
irrevent.MouseInput.Control = (keymod & KMOD_CTRL) != 0; irrevent.MouseInput.Control = (keymod & KMOD_CTRL) != 0;
@ -752,8 +755,8 @@ bool CIrrDeviceSDL::run()
SDL_Keymod keymod = SDL_GetModState(); SDL_Keymod keymod = SDL_GetModState();
irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT; irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;
irrevent.MouseInput.X = SDL_event.button.x * ScaleX; irrevent.MouseInput.X = static_cast<s32>(SDL_event.button.x * ScaleX);
irrevent.MouseInput.Y = SDL_event.button.y * ScaleY; irrevent.MouseInput.Y = static_cast<s32>(SDL_event.button.y * ScaleY);
irrevent.MouseInput.Shift = (keymod & KMOD_SHIFT) != 0; irrevent.MouseInput.Shift = (keymod & KMOD_SHIFT) != 0;
irrevent.MouseInput.Control = (keymod & KMOD_CTRL) != 0; irrevent.MouseInput.Control = (keymod & KMOD_CTRL) != 0;
@ -918,8 +921,8 @@ bool CIrrDeviceSDL::run()
irrevent.EventType = EET_TOUCH_INPUT_EVENT; irrevent.EventType = EET_TOUCH_INPUT_EVENT;
irrevent.TouchInput.Event = ETIE_PRESSED_DOWN; irrevent.TouchInput.Event = ETIE_PRESSED_DOWN;
irrevent.TouchInput.ID = SDL_event.tfinger.fingerId; irrevent.TouchInput.ID = SDL_event.tfinger.fingerId;
irrevent.TouchInput.X = SDL_event.tfinger.x * Width; irrevent.TouchInput.X = static_cast<s32>(SDL_event.tfinger.x * Width);
irrevent.TouchInput.Y = SDL_event.tfinger.y * Height; irrevent.TouchInput.Y = static_cast<s32>(SDL_event.tfinger.y * Height);
CurrentTouchCount++; CurrentTouchCount++;
irrevent.TouchInput.touchedCount = CurrentTouchCount; irrevent.TouchInput.touchedCount = CurrentTouchCount;
@ -930,8 +933,8 @@ bool CIrrDeviceSDL::run()
irrevent.EventType = EET_TOUCH_INPUT_EVENT; irrevent.EventType = EET_TOUCH_INPUT_EVENT;
irrevent.TouchInput.Event = ETIE_MOVED; irrevent.TouchInput.Event = ETIE_MOVED;
irrevent.TouchInput.ID = SDL_event.tfinger.fingerId; irrevent.TouchInput.ID = SDL_event.tfinger.fingerId;
irrevent.TouchInput.X = SDL_event.tfinger.x * Width; irrevent.TouchInput.X = static_cast<s32>(SDL_event.tfinger.x * Width);
irrevent.TouchInput.Y = SDL_event.tfinger.y * Height; irrevent.TouchInput.Y = static_cast<s32>(SDL_event.tfinger.y * Height);
irrevent.TouchInput.touchedCount = CurrentTouchCount; irrevent.TouchInput.touchedCount = CurrentTouchCount;
postEventFromUser(irrevent); postEventFromUser(irrevent);
@ -941,8 +944,8 @@ bool CIrrDeviceSDL::run()
irrevent.EventType = EET_TOUCH_INPUT_EVENT; irrevent.EventType = EET_TOUCH_INPUT_EVENT;
irrevent.TouchInput.Event = ETIE_LEFT_UP; irrevent.TouchInput.Event = ETIE_LEFT_UP;
irrevent.TouchInput.ID = SDL_event.tfinger.fingerId; irrevent.TouchInput.ID = SDL_event.tfinger.fingerId;
irrevent.TouchInput.X = SDL_event.tfinger.x * Width; irrevent.TouchInput.X = static_cast<s32>(SDL_event.tfinger.x * Width);
irrevent.TouchInput.Y = SDL_event.tfinger.y * Height; irrevent.TouchInput.Y = static_cast<s32>(SDL_event.tfinger.y * Height);
// To match Android behavior, still count the pointer that was // To match Android behavior, still count the pointer that was
// just released. // just released.
irrevent.TouchInput.touchedCount = CurrentTouchCount; irrevent.TouchInput.touchedCount = CurrentTouchCount;

@ -159,7 +159,8 @@ public:
void setPosition(s32 x, s32 y) override void setPosition(s32 x, s32 y) override
{ {
SDL_WarpMouseInWindow(Device->Window, SDL_WarpMouseInWindow(Device->Window,
x / Device->ScaleX, y / Device->ScaleY); static_cast<int>(x / Device->ScaleX),
static_cast<int>(y / Device->ScaleY));
if (SDL_GetRelativeMouseMode()) { if (SDL_GetRelativeMouseMode()) {
// There won't be an event for this warp (details on libsdl-org/SDL/issues/6034) // There won't be an event for this warp (details on libsdl-org/SDL/issues/6034)
@ -192,7 +193,7 @@ public:
virtual void setRelativeMode(bool relative) _IRR_OVERRIDE_ virtual void setRelativeMode(bool relative) _IRR_OVERRIDE_
{ {
// Only change it when necessary, as it flushes mouse motion when enabled // Only change it when necessary, as it flushes mouse motion when enabled
if (relative != SDL_GetRelativeMouseMode()) { if (relative != static_cast<bool>(SDL_GetRelativeMouseMode())) {
if (relative) if (relative)
SDL_SetRelativeMouseMode(SDL_TRUE); SDL_SetRelativeMouseMode(SDL_TRUE);
else else