Skip to content

Commit 78ff49c

Browse files
committed
Fix screen scaling of iOS
1 parent 1f826b5 commit 78ff49c

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

lib/irrlicht/source/Irrlicht/CEAGLManager.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
}
6868

6969
dataStorage->Layer = (CAEAGLLayer*)[view layer];
70+
dataStorage->Layer.contentsScale = view.contentScaleFactor;
7071

7172
return true;
7273
}

lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.mm

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,22 @@ - (bool)hasFocus
173173
@interface CIrrViewiOS : UIView
174174

175175
- (id)initWithFrame:(CGRect)frame forDevice:(irr::CIrrDeviceiOS*)device;
176+
@property (nonatomic) float Scale;
176177

177178
@end
178179

179180
@implementation CIrrViewiOS
180181
{
181182
irr::CIrrDeviceiOS* Device;
182-
float Scale;
183183
}
184184

185185
- (id)initWithFrame:(CGRect)frame forDevice:(irr::CIrrDeviceiOS*)device;
186186
{
187187
self = [super initWithFrame:frame];
188-
188+
self.Scale = 1.0f;
189189
if (self)
190190
{
191191
Device = device;
192-
Scale = ([self respondsToSelector:@selector(setContentScaleFactor:)]) ? [[UIScreen mainScreen] scale] : 1.f;
193192
}
194193

195194
return self;
@@ -216,8 +215,8 @@ - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
216215

217216
CGPoint touchPoint = [touch locationInView:self];
218217

219-
ev.TouchInput.X = touchPoint.x*Scale;
220-
ev.TouchInput.Y = touchPoint.y*Scale;
218+
ev.TouchInput.X = touchPoint.x * self.Scale;
219+
ev.TouchInput.Y = touchPoint.y * self.Scale;
221220

222221
Device->postEventFromUser(ev);
223222
if (ev.TouchInput.ID == 0)
@@ -247,8 +246,8 @@ - (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
247246

248247
CGPoint touchPoint = [touch locationInView:self];
249248

250-
ev.TouchInput.X = touchPoint.x*Scale;
251-
ev.TouchInput.Y = touchPoint.y*Scale;
249+
ev.TouchInput.X = touchPoint.x * self.Scale;
250+
ev.TouchInput.Y = touchPoint.y * self.Scale;
252251

253252
Device->postEventFromUser(ev);
254253
if (ev.TouchInput.ID == 0)
@@ -278,8 +277,8 @@ - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
278277

279278
CGPoint touchPoint = [touch locationInView:self];
280279

281-
ev.TouchInput.X = touchPoint.x*Scale;
282-
ev.TouchInput.Y = touchPoint.y*Scale;
280+
ev.TouchInput.X = touchPoint.x * self.Scale;
281+
ev.TouchInput.Y = touchPoint.y * self.Scale;
283282

284283
Device->postEventFromUser(ev);
285284
if (ev.TouchInput.ID == 0)
@@ -309,8 +308,8 @@ - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event
309308

310309
CGPoint touchPoint = [touch locationInView:self];
311310

312-
ev.TouchInput.X = touchPoint.x*Scale;
313-
ev.TouchInput.Y = touchPoint.y*Scale;
311+
ev.TouchInput.X = touchPoint.x * self.Scale;
312+
ev.TouchInput.Y = touchPoint.y * self.Scale;
314313

315314
Device->postEventFromUser(ev);
316315
if (ev.TouchInput.ID == 0)
@@ -797,8 +796,13 @@ + (Class)layerClass
797796
#ifdef _IRR_COMPILE_WITH_OGLES2_
798797
{
799798
CIrrViewEAGLiOS* view = [[CIrrViewEAGLiOS alloc] initWithFrame:resolution forDevice:this];
800-
CreationParams.WindowSize = core::dimension2d<u32>(view.frame.size.width, view.frame.size.height);
801-
799+
view.contentScaleFactor = dataStorage->Window.screen.nativeScale;
800+
view.Scale = view.contentScaleFactor;
801+
CreationParams.WindowSize =
802+
{
803+
view.frame.size.width * view.contentScaleFactor,
804+
view.frame.size.height * view.contentScaleFactor
805+
};
802806
dataStorage->View = view;
803807
data.OpenGLiOS.View = (__bridge void*)view;
804808

0 commit comments

Comments
 (0)