1 (* |
|
2 * Hedgewars, a free turn based strategy game |
|
3 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 * |
|
5 * This program is free software; you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation; version 2 of the License |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License |
|
15 * along with this program; if not, write to the Free Software |
|
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 *) |
|
18 |
|
19 {$INCLUDE "options.inc"} |
|
20 |
|
21 (* |
|
22 * This unit contains a lot of useful functions when hw is running on mobile |
|
23 * Unlike HwLibrary when you declare functions that you will call from your code, |
|
24 * here you need to provide functions that Pascall code will call. |
|
25 *) |
|
26 |
|
27 unit uMobile; |
|
28 interface |
|
29 |
|
30 function isPhone: Boolean; inline; |
|
31 function getScreenDPI: Double; inline; |
|
32 procedure performRumble; inline; |
|
33 |
|
34 procedure GameLoading; inline; |
|
35 procedure GameLoaded; inline; |
|
36 procedure SaveLoadingEnded; inline; |
|
37 |
|
38 implementation |
|
39 uses uVariables, uConsole, SDLh; |
|
40 |
|
41 // add here any external call that you need |
|
42 {$IFDEF IPHONEOS} |
|
43 (* iOS calls written in ObjcExports.m *) |
|
44 procedure startLoadingIndicator; cdecl; external; |
|
45 procedure stopLoadingIndicator; cdecl; external; |
|
46 procedure saveFinishedSynching; cdecl; external; |
|
47 function isApplePhone: Boolean; cdecl; external; |
|
48 procedure AudioServicesPlaySystemSound(num: LongInt); cdecl; external; |
|
49 {$ENDIF} |
|
50 |
|
51 // this function is just to determine whether we are running on a limited screen device |
|
52 function isPhone: Boolean; inline; |
|
53 begin |
|
54 isPhone:= false; |
|
55 {$IFDEF IPHONEOS} |
|
56 isPhone:= isApplePhone(); |
|
57 {$ENDIF} |
|
58 {$IFDEF ANDROID} |
|
59 //nasty nasty hack. TODO: implement callback to java to have a unified way of determining if it is a tablet |
|
60 if (cScreenWidth < 1000) and (cScreenHeight < 500) then |
|
61 isPhone:= true; |
|
62 {$ENDIF} |
|
63 end; |
|
64 |
|
65 function getScreenDPI: Double; inline; |
|
66 begin |
|
67 {$IFDEF ANDROID} |
|
68 // getScreenDPI:= Android_JNI_getDensity(); |
|
69 getScreenDPI:= 1; |
|
70 {$ELSE} |
|
71 getScreenDPI:= 1; |
|
72 {$ENDIF} |
|
73 end; |
|
74 |
|
75 // this function should make the device vibrate in some way |
|
76 procedure performRumble; inline; |
|
77 {$IFDEF IPHONEOS}const kSystemSoundID_Vibrate = $00000FFF;{$ENDIF} |
|
78 begin |
|
79 // do not vibrate while synchronising a demo/save |
|
80 if not fastUntilLag then |
|
81 begin |
|
82 {$IFDEF IPHONEOS} |
|
83 AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); |
|
84 {$ENDIF} |
|
85 end; |
|
86 end; |
|
87 |
|
88 procedure GameLoading; inline; |
|
89 begin |
|
90 {$IFDEF IPHONEOS} |
|
91 startLoadingIndicator(); |
|
92 {$ENDIF} |
|
93 end; |
|
94 |
|
95 procedure GameLoaded; inline; |
|
96 begin |
|
97 {$IFDEF IPHONEOS} |
|
98 stopLoadingIndicator(); |
|
99 {$ENDIF} |
|
100 end; |
|
101 |
|
102 procedure SaveLoadingEnded; inline; |
|
103 begin |
|
104 {$IFDEF IPHONEOS} |
|
105 saveFinishedSynching(); |
|
106 {$ENDIF} |
|
107 end; |
|
108 |
|
109 |
|
110 end. |
|