@@ -69,8 +69,7 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
69
69
TopPadding(0 ), BottomPadding(0 ), LeftPadding(0 ), RightPadding(0 ),
70
70
InitialOrientation(0 ), WindowHasFocus(false ), WindowMinimized(false ),
71
71
Resizable(false ), AccelerometerIndex(-1 ), AccelerometerInstance(-1 ),
72
- GyroscopeIndex(-1 ), GyroscopeInstance(-1 ), NativeScaleX(1 .0f ),
73
- NativeScaleY(1 .0f )
72
+ GyroscopeIndex(-1 ), GyroscopeInstance(-1 )
74
73
{
75
74
#ifdef _DEBUG
76
75
setDebugName (" CIrrDeviceSDL" );
@@ -187,11 +186,6 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
187
186
}
188
187
else
189
188
return ;
190
- updateNativeScale (&Width, &Height);
191
- Width = (u32 )((f32 )Width * NativeScaleX);
192
- Height = (u32 )((f32 )Height * NativeScaleY);
193
- CreationParams.WindowSize .Width = Width;
194
- CreationParams.WindowSize .Height = Height;
195
189
}
196
190
197
191
// create cursor control
@@ -213,30 +207,6 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
213
207
}
214
208
215
209
216
- void CIrrDeviceSDL::updateNativeScale (u32 * saving_width, u32 * saving_height)
217
- {
218
- int width, height = 0 ;
219
- SDL_GetWindowSize (Window, &width, &height);
220
- int real_width = width;
221
- int real_height = height;
222
- if (CreationParams.DriverType == video::EDT_OPENGL ||
223
- CreationParams.DriverType == video::EDT_OGLES2)
224
- {
225
- SDL_GL_GetDrawableSize (Window, &real_width, &real_height);
226
- }
227
- else if (CreationParams.DriverType == video::EDT_VULKAN)
228
- {
229
- SDL_Vulkan_GetDrawableSize (Window, &real_width, &real_height);
230
- }
231
- NativeScaleX = (f32 )real_width / (f32 )width;
232
- NativeScaleY = (f32 )real_height / (f32 )height;
233
- if (saving_width)
234
- *saving_width = width;
235
- if (saving_height)
236
- *saving_height = height;
237
- }
238
-
239
-
240
210
// ! destructor
241
211
CIrrDeviceSDL::~CIrrDeviceSDL ()
242
212
{
@@ -422,6 +392,7 @@ extern "C" void update_swap_interval(int swap_interval)
422
392
423
393
bool CIrrDeviceSDL::createWindow ()
424
394
{
395
+ CreationParams.m_sdl_window = NULL ;
425
396
// Ignore alpha size here, this follow irr_driver.cpp:450
426
397
// Try 32 and, upon failure, 24 then 16 bit per pixels
427
398
if (CreationParams.DriverType == video::EDT_OPENGL ||
@@ -520,6 +491,7 @@ bool CIrrDeviceSDL::createWindow()
520
491
return false ;
521
492
}
522
493
}
494
+ CreationParams.m_sdl_window = Window;
523
495
return true ;
524
496
}
525
497
@@ -723,10 +695,6 @@ void CIrrDeviceSDL::createDriver()
723
695
try
724
696
{
725
697
VideoDriver = video::createVulkanDriver (CreationParams, FileSystem, Window, this );
726
- // SDL_Vulkan_GetDrawableSize only works after driver is created
727
- updateNativeScale (&Width, &Height);
728
- Width = (u32 )((f32 )Width * NativeScaleX);
729
- Height = (u32 )((f32 )Height * NativeScaleY);
730
698
}
731
699
catch (std::exception& e)
732
700
{
@@ -845,8 +813,8 @@ bool CIrrDeviceSDL::run()
845
813
irrevent.TouchInput .ID = getTouchId (SDL_event.tfinger .fingerId );
846
814
if (SDL_event.type == SDL_FINGERUP)
847
815
removeTouchId (SDL_event.tfinger .fingerId );
848
- irrevent.TouchInput .X = SDL_event.tfinger .x * Width;
849
- irrevent.TouchInput .Y = SDL_event.tfinger .y * Height;
816
+ irrevent.TouchInput .X = SDL_event.tfinger .x * getRealScreenSize (). Width ;
817
+ irrevent.TouchInput .Y = SDL_event.tfinger .y * getRealScreenSize (). Height ;
850
818
postEventFromUser (irrevent);
851
819
break ;
852
820
@@ -871,8 +839,8 @@ bool CIrrDeviceSDL::run()
871
839
case SDL_MOUSEMOTION:
872
840
irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;
873
841
irrevent.MouseInput .Event = irr::EMIE_MOUSE_MOVED;
874
- MouseX = irrevent.MouseInput .X = SDL_event.motion .x * NativeScaleX ;
875
- MouseY = irrevent.MouseInput .Y = SDL_event.motion .y * NativeScaleY ;
842
+ MouseX = irrevent.MouseInput .X = SDL_event.motion .x * getNativeScaleX () ;
843
+ MouseY = irrevent.MouseInput .Y = SDL_event.motion .y * getNativeScaleY () ;
876
844
irrevent.MouseInput .ButtonStates = MouseButtonStates;
877
845
878
846
postEventFromUser (irrevent);
@@ -882,8 +850,8 @@ bool CIrrDeviceSDL::run()
882
850
case SDL_MOUSEBUTTONUP:
883
851
884
852
irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;
885
- irrevent.MouseInput .X = SDL_event.button .x * NativeScaleX ;
886
- irrevent.MouseInput .Y = SDL_event.button .y * NativeScaleY ;
853
+ irrevent.MouseInput .X = SDL_event.button .x * getNativeScaleX () ;
854
+ irrevent.MouseInput .Y = SDL_event.button .y * getNativeScaleY () ;
887
855
888
856
irrevent.MouseInput .Event = irr::EMIE_MOUSE_MOVED;
889
857
@@ -1060,13 +1028,10 @@ bool CIrrDeviceSDL::run()
1060
1028
1061
1029
void CIrrDeviceSDL::handleNewSize (u32 width, u32 height)
1062
1030
{
1063
- updateNativeScale ();
1064
- u32 new_width = width * NativeScaleX;
1065
- u32 new_height = height * NativeScaleY;
1066
- if (new_width != Width || new_height != Height)
1031
+ if (width != Width || height != Height)
1067
1032
{
1068
- Width = new_width ;
1069
- Height = new_height ;
1033
+ Width = width ;
1034
+ Height = height ;
1070
1035
if (VideoDriver)
1071
1036
VideoDriver->OnResize (core::dimension2d<u32 >(Width, Height));
1072
1037
reset_network_body ();
@@ -1597,7 +1562,7 @@ extern "C" int Android_getMovedHeight();
1597
1562
s32 CIrrDeviceSDL::getMovedHeight () const
1598
1563
{
1599
1564
#if defined(IOS_STK)
1600
- return SDL_GetMovedHeightByScreenKeyboard () * NativeScaleY ;
1565
+ return SDL_GetMovedHeightByScreenKeyboard () * getNativeScaleY () ;
1601
1566
#elif defined(ANDROID)
1602
1567
return Android_getMovedHeight ();
1603
1568
#else
@@ -1610,7 +1575,7 @@ extern "C" int Android_getKeyboardHeight();
1610
1575
u32 CIrrDeviceSDL::getOnScreenKeyboardHeight () const
1611
1576
{
1612
1577
#if defined(IOS_STK)
1613
- return SDL_GetScreenKeyboardHeight () * NativeScaleY ;
1578
+ return SDL_GetScreenKeyboardHeight () * getNativeScaleY () ;
1614
1579
#elif defined(ANDROID)
1615
1580
return Android_getKeyboardHeight ();
1616
1581
#else
@@ -1621,13 +1586,17 @@ u32 CIrrDeviceSDL::getOnScreenKeyboardHeight() const
1621
1586
1622
1587
f32 CIrrDeviceSDL::getNativeScaleX () const
1623
1588
{
1624
- return NativeScaleX;
1589
+ if (VideoDriver)
1590
+ return (f32 )VideoDriver->getScreenSize ().Width / (f32 )Width;
1591
+ return 1 .0f ;
1625
1592
}
1626
1593
1627
1594
1628
1595
f32 CIrrDeviceSDL::getNativeScaleY () const
1629
1596
{
1630
- return NativeScaleY;
1597
+ if (VideoDriver)
1598
+ return (f32 )VideoDriver->getScreenSize ().Height / (f32 )Height;
1599
+ return 1 .0f ;
1631
1600
}
1632
1601
1633
1602
@@ -1701,6 +1670,15 @@ void CIrrDeviceSDL::createGUIAndVulkanScene()
1701
1670
}
1702
1671
1703
1672
1673
+ const core::dimension2du& CIrrDeviceSDL::getRealScreenSize () const
1674
+ {
1675
+ static core::dimension2du ss;
1676
+ if (VideoDriver)
1677
+ return VideoDriver->getScreenSize ();
1678
+ return ss;
1679
+ }
1680
+
1681
+
1704
1682
} // end namespace irr
1705
1683
1706
1684
#endif // _IRR_COMPILE_WITH_SDL_DEVICE_
0 commit comments