This repository has been archived by the owner on Jan 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathSSKMultiplatform.h
105 lines (90 loc) · 2.65 KB
/
SSKMultiplatform.h
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef SSKMultiplatform
#define SSKMultiplatform
#pragma mark - Types
#if TARGET_OS_IPHONE
#define SSKWindowType UIWindow
#define SSKViewControllerType UIViewController
#define SSKFontType UIFont
#define SSKEdgeInsetsType UIEdgeInsets
#else
#define SSKWindowType NSWindow
#define SSKViewControllerType NSViewController
#define SSKFontType NSFont
#define SSKEdgeInsetsType NSEdgeInsets
#endif
/**
* Create an edge insets struct specific to the current platform
*
* @param top The top value of the edge insets
* @param left The left value of the edge insets
* @param bottom The bottom value of the edge insets
* @param right The right value of the edge insets
*/
static inline SSKEdgeInsetsType SSKEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)
{
SSKEdgeInsetsType edgeInsets;
edgeInsets.top = top;
edgeInsets.left = left;
edgeInsets.bottom = bottom;
edgeInsets.right = right;
return edgeInsets;
}
#pragma mark - Platform information
/**
* Enum describing various platforms that a SpriteKit game can run on
*/
typedef enum : NSUInteger {
SSKPlatformTypePhone,
SSKPlatformTypePad,
SSKPlatformTypeDesktop
} SSKPlatformType;
/**
* Get the current platform type that the game is currently running on
*/
static inline SSKPlatformType SSKCurrentPlatform()
{
#if TARGET_OS_IPHONE
return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? SSKPlatformTypePhone : SSKPlatformTypePad;
#else
return SSKPlatformTypeDesktop;
#endif
}
#pragma mark - Device orientation information
/**
* Enum providing a simplified, platform-agnostic way to handle device orientation
*/
typedef enum : NSUInteger {
SSKDeviceOrientationPortrait,
SSKDeviceOrientationLandscape
} SSKDeviceOrientation;
/**
* Get the current orientation of the device that the game is currently running on
*
* @discussion For OSX, this will always return SSKDeviceOrientationLandscape
*/
static inline SSKDeviceOrientation SSKCurrentDeviceOrientation()
{
#if TARGET_OS_IPHONE
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
return SSKDeviceOrientationLandscape;
return SSKDeviceOrientationPortrait;
#else
return SSKDeviceOrientationLandscape;
#endif
}
#pragma mark - Screen scale information
/**
* Get the scale of the screen that the game is currently running on
*
* @discussion For OSX, this will return the scale of the screen on which the
* application's key window is being rendered.
*/
static inline CGFloat SSKCurrentScreenScale()
{
#if TARGET_OS_IPHONE
return [UIScreen mainScreen].scale;
#else
return [[NSScreen mainScreen] backingScaleFactor];
#endif
}
#endif