forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTitleContainer.MacOS.cs
57 lines (52 loc) · 1.82 KB
/
TitleContainer.MacOS.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using System.IO;
#if IOS
using Foundation;
using UIKit;
#elif MONOMAC
using Foundation;
#endif
namespace Microsoft.Xna.Framework
{
partial class TitleContainer
{
static partial void PlatformInit()
{
Location = NSBundle.MainBundle.ResourcePath;
#if IOS
SupportRetina = UIScreen.MainScreen.Scale >= 2.0f;
RetinaScale = (int)Math.Round(UIScreen.MainScreen.Scale);
#endif
}
#if IOS
static internal bool SupportRetina { get; private set; }
static internal int RetinaScale { get; private set; }
#endif
private static Stream PlatformOpenStream(string safeName)
{
#if IOS
var absolutePath = Path.Combine(Location, safeName);
if (SupportRetina)
{
for (var scale = RetinaScale; scale >= 2; scale--)
{
// Insert the @#x immediately prior to the extension. If this file exists
// and we are on a Retina device, return this file instead.
var absolutePathX = Path.Combine(Path.GetDirectoryName(absolutePath),
Path.GetFileNameWithoutExtension(absolutePath)
+ "@" + scale + "x" + Path.GetExtension(absolutePath));
if (File.Exists(absolutePathX))
return File.OpenRead(absolutePathX);
}
}
return File.OpenRead(absolutePath);
#else
var absolutePath = Path.Combine(Location, safeName);
return File.OpenRead(absolutePath);
#endif
}
}
}