gosu 0.7.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (249) hide show
  1. data/COPYING.txt +29 -0
  2. data/Gosu/Async.hpp +48 -0
  3. data/Gosu/Audio.hpp +145 -0
  4. data/Gosu/AutoLink.hpp +16 -0
  5. data/Gosu/Bitmap.hpp +85 -0
  6. data/Gosu/ButtonsMac.hpp +114 -0
  7. data/Gosu/ButtonsWin.hpp +111 -0
  8. data/Gosu/ButtonsX.hpp +115 -0
  9. data/Gosu/Color.hpp +172 -0
  10. data/Gosu/Directories.hpp +36 -0
  11. data/Gosu/Font.hpp +59 -0
  12. data/Gosu/Fwd.hpp +31 -0
  13. data/Gosu/Gosu.hpp +26 -0
  14. data/Gosu/Graphics.hpp +86 -0
  15. data/Gosu/GraphicsBase.hpp +45 -0
  16. data/Gosu/IO.hpp +255 -0
  17. data/Gosu/Image.hpp +148 -0
  18. data/Gosu/ImageData.hpp +45 -0
  19. data/Gosu/Input.hpp +116 -0
  20. data/Gosu/Math.hpp +95 -0
  21. data/Gosu/Platform.hpp +61 -0
  22. data/Gosu/RotFlip.hpp +116 -0
  23. data/Gosu/Sockets.hpp +129 -0
  24. data/Gosu/Text.hpp +47 -0
  25. data/Gosu/TextInput.hpp +57 -0
  26. data/Gosu/Timing.hpp +16 -0
  27. data/Gosu/Utility.hpp +24 -0
  28. data/Gosu/WinUtility.hpp +76 -0
  29. data/Gosu/Window.hpp +84 -0
  30. data/GosuImpl/Async.cpp +37 -0
  31. data/GosuImpl/AudioFmod.cpp +417 -0
  32. data/GosuImpl/AudioSDL.cpp +255 -0
  33. data/GosuImpl/DirectoriesMac.mm +38 -0
  34. data/GosuImpl/DirectoriesUnix.cpp +48 -0
  35. data/GosuImpl/DirectoriesWin.cpp +42 -0
  36. data/GosuImpl/FileUnix.cpp +100 -0
  37. data/GosuImpl/FileWin.cpp +83 -0
  38. data/GosuImpl/Graphics/Bitmap.cpp +116 -0
  39. data/GosuImpl/Graphics/BitmapBMP.cpp +232 -0
  40. data/GosuImpl/Graphics/BitmapColorKey.cpp +39 -0
  41. data/GosuImpl/Graphics/BitmapPNG.cpp +276 -0
  42. data/GosuImpl/Graphics/BitmapUtils.cpp +67 -0
  43. data/GosuImpl/Graphics/BlockAllocator.cpp +127 -0
  44. data/GosuImpl/Graphics/BlockAllocator.hpp +34 -0
  45. data/GosuImpl/Graphics/Color.cpp +126 -0
  46. data/GosuImpl/Graphics/Common.hpp +21 -0
  47. data/GosuImpl/Graphics/DrawOp.hpp +154 -0
  48. data/GosuImpl/Graphics/Font.cpp +110 -0
  49. data/GosuImpl/Graphics/Graphics.cpp +295 -0
  50. data/GosuImpl/Graphics/Image.cpp +159 -0
  51. data/GosuImpl/Graphics/LargeImageData.cpp +115 -0
  52. data/GosuImpl/Graphics/LargeImageData.hpp +37 -0
  53. data/GosuImpl/Graphics/RotFlip.cpp +184 -0
  54. data/GosuImpl/Graphics/TexChunk.cpp +77 -0
  55. data/GosuImpl/Graphics/TexChunk.hpp +40 -0
  56. data/GosuImpl/Graphics/Text.cpp +223 -0
  57. data/GosuImpl/Graphics/TextMac.cpp +242 -0
  58. data/GosuImpl/Graphics/TextPangoFT.cpp +186 -0
  59. data/GosuImpl/Graphics/TextWin.cpp +172 -0
  60. data/GosuImpl/Graphics/Texture.cpp +104 -0
  61. data/GosuImpl/Graphics/Texture.hpp +34 -0
  62. data/GosuImpl/IO.cpp +48 -0
  63. data/GosuImpl/InputMac.mm +677 -0
  64. data/GosuImpl/InputWin.cpp +444 -0
  65. data/GosuImpl/InputX.cpp +158 -0
  66. data/GosuImpl/MacUtility.hpp +48 -0
  67. data/GosuImpl/Math.cpp +49 -0
  68. data/GosuImpl/RubyGosu.swg +474 -0
  69. data/GosuImpl/RubyGosuStub.mm +17 -0
  70. data/GosuImpl/RubyGosu_DllMain.cxx +30 -0
  71. data/GosuImpl/RubyGosu_wrap.cxx +8521 -0
  72. data/GosuImpl/RubyGosu_wrap.h +31 -0
  73. data/GosuImpl/Sockets/CommSocket.cpp +304 -0
  74. data/GosuImpl/Sockets/ListenerSocket.cpp +60 -0
  75. data/GosuImpl/Sockets/MessageSocket.cpp +136 -0
  76. data/GosuImpl/Sockets/Socket.cpp +145 -0
  77. data/GosuImpl/Sockets/Sockets.hpp +66 -0
  78. data/GosuImpl/TextInputMac.mm +207 -0
  79. data/GosuImpl/TextInputWin.cpp +197 -0
  80. data/GosuImpl/TextInputX.cpp +201 -0
  81. data/GosuImpl/TextTTFWin.cpp +247 -0
  82. data/GosuImpl/TimingUnix.cpp +17 -0
  83. data/GosuImpl/TimingWin.cpp +28 -0
  84. data/GosuImpl/Utility.cpp +140 -0
  85. data/GosuImpl/WinMain.cpp +69 -0
  86. data/GosuImpl/WinUtility.cpp +137 -0
  87. data/GosuImpl/WindowMac.mm +466 -0
  88. data/GosuImpl/WindowWin.cpp +447 -0
  89. data/GosuImpl/WindowX.cpp +392 -0
  90. data/GosuImpl/X11vroot.h +118 -0
  91. data/README.txt +13 -0
  92. data/Rakefile +178 -0
  93. data/examples/ChipmunkIntegration.rb +275 -0
  94. data/examples/CptnRuby.rb +231 -0
  95. data/examples/MoreChipmunkAndRMagick.rb +155 -0
  96. data/examples/OpenGLIntegration.rb +232 -0
  97. data/examples/RMagickIntegration.rb +449 -0
  98. data/examples/TextInput.cpp +170 -0
  99. data/examples/TextInput.rb +139 -0
  100. data/examples/Tutorial.cpp +215 -0
  101. data/examples/Tutorial.rb +137 -0
  102. data/examples/media/Beep.wav +0 -0
  103. data/examples/media/CptnRuby Gem.png +0 -0
  104. data/examples/media/CptnRuby Map.txt +25 -0
  105. data/examples/media/CptnRuby Tileset.png +0 -0
  106. data/examples/media/CptnRuby.png +0 -0
  107. data/examples/media/Cursor.png +0 -0
  108. data/examples/media/Earth.png +0 -0
  109. data/examples/media/Explosion.wav +0 -0
  110. data/examples/media/LargeStar.png +0 -0
  111. data/examples/media/Sky.jpg +0 -0
  112. data/examples/media/Smoke.png +0 -0
  113. data/examples/media/Soldier.png +0 -0
  114. data/examples/media/Space.png +0 -0
  115. data/examples/media/Star.png +0 -0
  116. data/examples/media/Starfighter.bmp +0 -0
  117. data/linux/Makefile.in +98 -0
  118. data/linux/configure +5658 -0
  119. data/linux/configure.ac +126 -0
  120. data/linux/extconf.rb +11 -0
  121. data/mac/English.lproj/InfoPlist.strings +0 -0
  122. data/mac/Gosu-Info.plist +26 -0
  123. data/mac/Gosu.xcodeproj/project.pbxproj +1194 -0
  124. data/mac/RubyGosu Template-Info.plist +26 -0
  125. data/mac/libboost_thread_1_34_1_universal.a +0 -0
  126. data/mac/libboost_thread_d_1_34_1_universal.a +0 -0
  127. data/mac/libfmod_universal.a +0 -0
  128. data/mac/libpng_universal.a +0 -0
  129. data/mac/libz_universal.a +0 -0
  130. data/reference/Async_8hpp-source.html +70 -0
  131. data/reference/Audio_8hpp-source.html +114 -0
  132. data/reference/Audio_8hpp.html +50 -0
  133. data/reference/AutoLink_8hpp-source.html +38 -0
  134. data/reference/AutoLink_8hpp.html +34 -0
  135. data/reference/Bitmap_8hpp-source.html +85 -0
  136. data/reference/Bitmap_8hpp.html +58 -0
  137. data/reference/ButtonsMac_8hpp-source.html +133 -0
  138. data/reference/ButtonsWin_8hpp-source.html +133 -0
  139. data/reference/ButtonsX_8hpp-source.html +134 -0
  140. data/reference/Color_8hpp-source.html +169 -0
  141. data/reference/Color_8hpp.html +85 -0
  142. data/reference/Directories_8hpp-source.html +42 -0
  143. data/reference/Directories_8hpp.html +46 -0
  144. data/reference/Font_8hpp-source.html +65 -0
  145. data/reference/Font_8hpp.html +41 -0
  146. data/reference/Fwd_8hpp-source.html +52 -0
  147. data/reference/Fwd_8hpp.html +37 -0
  148. data/reference/Gosu_8hpp-source.html +48 -0
  149. data/reference/Gosu_8hpp.html +34 -0
  150. data/reference/GraphicsBase_8hpp-source.html +57 -0
  151. data/reference/GraphicsBase_8hpp.html +56 -0
  152. data/reference/Graphics_8hpp-source.html +96 -0
  153. data/reference/Graphics_8hpp.html +53 -0
  154. data/reference/IO_8hpp-source.html +255 -0
  155. data/reference/IO_8hpp.html +74 -0
  156. data/reference/ImageData_8hpp-source.html +62 -0
  157. data/reference/ImageData_8hpp.html +43 -0
  158. data/reference/Image_8hpp-source.html +126 -0
  159. data/reference/Image_8hpp.html +48 -0
  160. data/reference/Input_8hpp-source.html +118 -0
  161. data/reference/Input_8hpp.html +50 -0
  162. data/reference/Math_8hpp-source.html +92 -0
  163. data/reference/Math_8hpp.html +74 -0
  164. data/reference/Platform_8hpp-source.html +83 -0
  165. data/reference/Platform_8hpp.html +73 -0
  166. data/reference/RotFlip_8hpp-source.html +138 -0
  167. data/reference/RotFlip_8hpp.html +77 -0
  168. data/reference/Sockets_8hpp-source.html +130 -0
  169. data/reference/Sockets_8hpp.html +66 -0
  170. data/reference/TextInput_8hpp-source.html +64 -0
  171. data/reference/TextInput_8hpp.html +41 -0
  172. data/reference/Text_8hpp-source.html +51 -0
  173. data/reference/Text_8hpp.html +46 -0
  174. data/reference/Timing_8hpp-source.html +36 -0
  175. data/reference/Timing_8hpp.html +42 -0
  176. data/reference/Utility_8hpp-source.html +44 -0
  177. data/reference/Utility_8hpp.html +48 -0
  178. data/reference/WinUtility_8hpp-source.html +79 -0
  179. data/reference/WinUtility_8hpp.html +64 -0
  180. data/reference/Window_8hpp-source.html +91 -0
  181. data/reference/Window_8hpp.html +41 -0
  182. data/reference/annotated.html +51 -0
  183. data/reference/classGosu_1_1Audio-members.html +34 -0
  184. data/reference/classGosu_1_1Audio.html +46 -0
  185. data/reference/classGosu_1_1Bitmap-members.html +44 -0
  186. data/reference/classGosu_1_1Bitmap.html +263 -0
  187. data/reference/classGosu_1_1Buffer-members.html +44 -0
  188. data/reference/classGosu_1_1Buffer.html +78 -0
  189. data/reference/classGosu_1_1Buffer.png +0 -0
  190. data/reference/classGosu_1_1Button-members.html +36 -0
  191. data/reference/classGosu_1_1Button.html +143 -0
  192. data/reference/classGosu_1_1Color-members.html +56 -0
  193. data/reference/classGosu_1_1Color.html +387 -0
  194. data/reference/classGosu_1_1File-members.html +41 -0
  195. data/reference/classGosu_1_1File.html +69 -0
  196. data/reference/classGosu_1_1File.png +0 -0
  197. data/reference/classGosu_1_1Font-members.html +39 -0
  198. data/reference/classGosu_1_1Font.html +309 -0
  199. data/reference/classGosu_1_1Graphics-members.html +50 -0
  200. data/reference/classGosu_1_1Graphics.html +234 -0
  201. data/reference/classGosu_1_1Image-members.html +45 -0
  202. data/reference/classGosu_1_1Image.html +518 -0
  203. data/reference/classGosu_1_1ImageData-members.html +37 -0
  204. data/reference/classGosu_1_1ImageData.html +60 -0
  205. data/reference/classGosu_1_1Input-members.html +44 -0
  206. data/reference/classGosu_1_1Input.html +223 -0
  207. data/reference/classGosu_1_1MessageSocket-members.html +40 -0
  208. data/reference/classGosu_1_1MessageSocket.html +233 -0
  209. data/reference/classGosu_1_1Resource-members.html +39 -0
  210. data/reference/classGosu_1_1Resource.html +116 -0
  211. data/reference/classGosu_1_1Resource.png +0 -0
  212. data/reference/classGosu_1_1Sample-members.html +37 -0
  213. data/reference/classGosu_1_1Sample.html +200 -0
  214. data/reference/classGosu_1_1SampleInstance-members.html +38 -0
  215. data/reference/classGosu_1_1SampleInstance.html +169 -0
  216. data/reference/classGosu_1_1Song-members.html +43 -0
  217. data/reference/classGosu_1_1Song.html +260 -0
  218. data/reference/classGosu_1_1TextInput-members.html +38 -0
  219. data/reference/classGosu_1_1TextInput.html +121 -0
  220. data/reference/classGosu_1_1Window-members.html +50 -0
  221. data/reference/classGosu_1_1Window.html +271 -0
  222. data/reference/doxyfile +233 -0
  223. data/reference/doxygen.css +433 -0
  224. data/reference/doxygen.png +0 -0
  225. data/reference/files.html +54 -0
  226. data/reference/functions.html +236 -0
  227. data/reference/functions_enum.html +45 -0
  228. data/reference/functions_func.html +227 -0
  229. data/reference/functions_vars.html +47 -0
  230. data/reference/hierarchy.html +53 -0
  231. data/reference/index.html +26 -0
  232. data/reference/namespaceGosu.html +2890 -0
  233. data/reference/namespaceGosu_1_1Colors.html +70 -0
  234. data/reference/namespaceGosu_1_1Win.html +275 -0
  235. data/reference/namespacemembers.html +216 -0
  236. data/reference/namespacemembers_enum.html +52 -0
  237. data/reference/namespacemembers_eval.html +54 -0
  238. data/reference/namespacemembers_func.html +185 -0
  239. data/reference/namespacemembers_type.html +46 -0
  240. data/reference/namespacemembers_vars.html +46 -0
  241. data/reference/namespaces.html +35 -0
  242. data/reference/tab_b.gif +0 -0
  243. data/reference/tab_l.gif +0 -0
  244. data/reference/tab_r.gif +0 -0
  245. data/reference/tabs.css +102 -0
  246. data/windows/Gosu.sln +29 -0
  247. data/windows/Gosu.vcproj +553 -0
  248. data/windows/RubyGosu.vcproj +138 -0
  249. metadata +305 -0
@@ -0,0 +1,201 @@
1
+ #include <Gosu/TextInput.hpp>
2
+ #include <Gosu/Input.hpp>
3
+ #include <algorithm>
4
+ #include <vector>
5
+ #include <wctype.h>
6
+
7
+ struct Gosu::TextInput::Impl
8
+ {
9
+ std::wstring text;
10
+ unsigned caretPos, selectionStart;
11
+ Impl() : caretPos(0), selectionStart(0) {}
12
+ };
13
+
14
+ Gosu::TextInput::TextInput()
15
+ : pimpl(new Impl)
16
+ {
17
+ }
18
+
19
+ Gosu::TextInput::~TextInput()
20
+ {
21
+ }
22
+
23
+ std::wstring Gosu::TextInput::text() const
24
+ {
25
+ return pimpl->text;
26
+ }
27
+
28
+ void Gosu::TextInput::setText(const std::wstring& text)
29
+ {
30
+ pimpl->text = text;
31
+ pimpl->caretPos = pimpl->selectionStart = text.length();
32
+ }
33
+
34
+ unsigned Gosu::TextInput::caretPos() const
35
+ {
36
+ return pimpl->caretPos;
37
+ }
38
+
39
+ unsigned Gosu::TextInput::selectionStart() const
40
+ {
41
+ return pimpl->selectionStart;
42
+ }
43
+
44
+ #define CARET_POS (pimpl->caretPos)
45
+ #define SEL_START (pimpl->selectionStart)
46
+
47
+ bool Gosu::TextInput::feedXEvent(void* display, void* event)
48
+ {
49
+ XEvent* ev = static_cast<XEvent*>(event);
50
+
51
+ if (ev->type != KeyPress)
52
+ return false;
53
+
54
+ bool ctrlDown = (ev->xkey.state & ControlMask);
55
+ bool shiftDown = (ev->xkey.state & ShiftMask);
56
+
57
+ KeySym lower, upper;
58
+ XConvertCase(XKeycodeToKeysym((Display*)display, ev->xkey.keycode, 0), &lower, &upper);
59
+
60
+ wchar_t ch = static_cast<wchar_t>(shiftDown ? upper : lower);
61
+
62
+ if (ch >= 32 && ch != 127 && ch <= 255)
63
+ {
64
+ // Delete (overwrite) previous selection.
65
+ if (CARET_POS != SEL_START)
66
+ {
67
+ unsigned min = std::min(CARET_POS, SEL_START);
68
+ unsigned max = std::max(CARET_POS, SEL_START);
69
+ pimpl->text.erase(pimpl->text.begin() + min, pimpl->text.begin() + max);
70
+ CARET_POS = SEL_START = min;
71
+ }
72
+
73
+ pimpl->text.insert(pimpl->text.begin() + CARET_POS, ch);
74
+ CARET_POS += 1;
75
+ SEL_START = CARET_POS;
76
+ return true;
77
+ }
78
+
79
+ // Char left
80
+ if (ch == kbLeft && !ctrlDown)
81
+ {
82
+ if (CARET_POS > 0)
83
+ CARET_POS -= 1;
84
+
85
+ if (!shiftDown)
86
+ SEL_START = CARET_POS;
87
+
88
+ return true;
89
+ }
90
+
91
+ // Char right
92
+ if (ch == kbRight && !ctrlDown)
93
+ {
94
+ if (CARET_POS < pimpl->text.length())
95
+ CARET_POS += 1;
96
+
97
+ if (!shiftDown)
98
+ SEL_START = CARET_POS;
99
+
100
+ return true;
101
+ }
102
+
103
+ // Home
104
+ if (ch == kbHome)
105
+ {
106
+ CARET_POS = 0;
107
+
108
+ if (!shiftDown)
109
+ SEL_START = CARET_POS;
110
+
111
+ return true;
112
+ }
113
+
114
+ // End
115
+ if (ch == kbEnd)
116
+ {
117
+ CARET_POS = pimpl->text.length();
118
+
119
+ if (!shiftDown)
120
+ SEL_START = CARET_POS;
121
+
122
+ return true;
123
+ }
124
+
125
+ // Word left
126
+ if (ch == kbLeft && ctrlDown)
127
+ {
128
+ if (CARET_POS == pimpl->text.length())
129
+ --CARET_POS;
130
+
131
+ while (CARET_POS > 0 && iswspace(pimpl->text.at(CARET_POS - 1)))
132
+ --CARET_POS;
133
+
134
+ while (CARET_POS > 0 && !iswspace(pimpl->text.at(CARET_POS - 1)))
135
+ --CARET_POS;
136
+
137
+ if (!shiftDown)
138
+ SEL_START = CARET_POS;
139
+
140
+ return true;
141
+ }
142
+
143
+ // Word right
144
+ if (ch == kbRight && ctrlDown)
145
+ {
146
+ while (CARET_POS < pimpl->text.length() && iswspace(pimpl->text.at(CARET_POS)))
147
+ ++CARET_POS;
148
+
149
+ while (CARET_POS < pimpl->text.length() && !iswspace(pimpl->text.at(CARET_POS)))
150
+ ++CARET_POS;
151
+
152
+ if (!shiftDown)
153
+ SEL_START = CARET_POS;
154
+
155
+ return true;
156
+ }
157
+
158
+ // Delete existant selection
159
+ if (ch == kbBackspace)
160
+ {
161
+ if (SEL_START != CARET_POS)
162
+ {
163
+ unsigned min = std::min(CARET_POS, SEL_START);
164
+ unsigned max = std::max(CARET_POS, SEL_START);
165
+ pimpl->text.erase(pimpl->text.begin() + min, pimpl->text.begin() + max);
166
+ SEL_START = CARET_POS = min;
167
+ }
168
+ else if (CARET_POS > 0)
169
+ {
170
+ unsigned oldCaret = CARET_POS;
171
+ CARET_POS -= 1;
172
+ pimpl->text.erase(pimpl->text.begin() + CARET_POS, pimpl->text.begin() + oldCaret);
173
+ SEL_START = CARET_POS;
174
+ }
175
+
176
+ return true;
177
+ }
178
+
179
+ // Delete existant selection
180
+ if (ch == kbDelete)
181
+ {
182
+ if (SEL_START != CARET_POS)
183
+ {
184
+ unsigned min = std::min(CARET_POS, SEL_START);
185
+ unsigned max = std::max(CARET_POS, SEL_START);
186
+ pimpl->text.erase(pimpl->text.begin() + min, pimpl->text.begin() + max);
187
+ SEL_START = CARET_POS = min;
188
+ }
189
+ else if (CARET_POS < pimpl->text.length())
190
+ {
191
+ unsigned oldCaret = CARET_POS;
192
+ CARET_POS += 1;
193
+ pimpl->text.erase(pimpl->text.begin() + oldCaret, pimpl->text.begin() + CARET_POS);
194
+ SEL_START = CARET_POS = oldCaret;
195
+ }
196
+
197
+ return true;
198
+ }
199
+
200
+ return false;
201
+ }
@@ -0,0 +1,247 @@
1
+ #include <windows.h>
2
+ #include <Gosu/Utility.hpp>
3
+
4
+ // Adapted from http://www.codeproject.com/KB/GDI/xfont.aspx.
5
+ // Credits go to Philip Patrick and Hans Dietrich!
6
+
7
+ struct FONT_PROPERTIES_ANSI
8
+ {
9
+ char csName[1024];
10
+ char csCopyright[1024];
11
+ char csTrademark[1024];
12
+ char csFamily[1024];
13
+ };
14
+ struct TT_OFFSET_TABLE
15
+ {
16
+ USHORT uMajorVersion;
17
+ USHORT uMinorVersion;
18
+ USHORT uNumOfTables;
19
+ USHORT uSearchRange;
20
+ USHORT uEntrySelector;
21
+ USHORT uRangeShift;
22
+ };
23
+ struct TT_TABLE_DIRECTORY
24
+ {
25
+ char szTag[4]; //table name
26
+ ULONG uCheckSum; //Check sum
27
+ ULONG uOffset; //Offset from beginning of file
28
+ ULONG uLength; //length of the table in bytes
29
+ };
30
+ struct TT_NAME_TABLE_HEADER
31
+ {
32
+ USHORT uFSelector; //format selector. Always 0
33
+ USHORT uNRCount; //Name Records count
34
+ USHORT uStorageOffset; //Offset for strings storage, from start of the table
35
+ };
36
+ struct TT_NAME_RECORD
37
+ {
38
+ USHORT uPlatformID;
39
+ USHORT uEncodingID;
40
+ USHORT uLanguageID;
41
+ USHORT uNameID;
42
+ USHORT uStringLength;
43
+ USHORT uStringOffset; //from start of storage area
44
+ };
45
+
46
+ #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
47
+ #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
48
+
49
+ #define _T(x) x
50
+ #define TRACE printf
51
+
52
+ namespace Gosu
53
+ {
54
+ std::wstring getNameFromTTFFile(const std::wstring& filename)
55
+ {
56
+ FONT_PROPERTIES_ANSI fp;
57
+ FONT_PROPERTIES_ANSI * lpFontProps = &fp;
58
+ memset(lpFontProps, 0, sizeof(FONT_PROPERTIES_ANSI));
59
+
60
+ HANDLE hFile = INVALID_HANDLE_VALUE;
61
+ hFile = ::CreateFile(filename.c_str(),
62
+ GENERIC_READ,// | GENERIC_WRITE,
63
+ 0,
64
+ NULL,
65
+ OPEN_ALWAYS,
66
+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
67
+ NULL);
68
+
69
+ if (hFile == INVALID_HANDLE_VALUE)
70
+ {
71
+ TRACE(_T("ERROR: failed to open '%s'\n"), Gosu::narrow(filename).c_str());
72
+ TRACE(_T("ERROR: %s failed\n"), _T("CreateFile"));
73
+ return filename;
74
+ }
75
+
76
+ // get the file size
77
+ DWORD dwFileSize = ::GetFileSize(hFile, NULL);
78
+
79
+ if (dwFileSize == INVALID_FILE_SIZE)
80
+ {
81
+ TRACE(_T("ERROR: %s failed\n"), _T("GetFileSize"));
82
+ ::CloseHandle(hFile);
83
+ return filename;
84
+ }
85
+
86
+ //TRACE(_T("dwFileSize = %d\n"), dwFileSize);
87
+
88
+ // Create a file mapping object that is the current size of the file
89
+ HANDLE hMappedFile = NULL;
90
+ hMappedFile = ::CreateFileMapping(hFile,
91
+ NULL,
92
+ PAGE_READONLY, //PAGE_READWRITE,
93
+ 0,
94
+ dwFileSize,
95
+ NULL);
96
+
97
+ if (hMappedFile == NULL)
98
+ {
99
+ TRACE(_T("ERROR: %s failed\n"), _T("CreateFileMapping"));
100
+ ::CloseHandle(hFile);
101
+ return filename;
102
+ }
103
+
104
+ LPBYTE lpMapAddress = (LPBYTE) ::MapViewOfFile(hMappedFile, // handle to file-mapping object
105
+ FILE_MAP_READ,//FILE_MAP_WRITE, // access mode
106
+ 0, // high-order DWORD of offset
107
+ 0, // low-order DWORD of offset
108
+ 0); // number of bytes to map
109
+
110
+ if (lpMapAddress == NULL)
111
+ {
112
+ TRACE(_T("ERROR: %s failed\n"), _T("MapViewOfFile"));
113
+ ::CloseHandle(hMappedFile);
114
+ ::CloseHandle(hFile);
115
+ return filename;
116
+ }
117
+
118
+ BOOL bRetVal = FALSE;
119
+ int index = 0;
120
+
121
+ TT_OFFSET_TABLE ttOffsetTable;
122
+ memcpy(&ttOffsetTable, &lpMapAddress[index], sizeof(TT_OFFSET_TABLE));
123
+ index += sizeof(TT_OFFSET_TABLE);
124
+
125
+ ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
126
+ ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
127
+ ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
128
+
129
+ //check is this is a true type font and the version is 1.0
130
+ if (ttOffsetTable.uMajorVersion != 1 || ttOffsetTable.uMinorVersion != 0)
131
+ return L"";
132
+
133
+ TT_TABLE_DIRECTORY tblDir;
134
+ memset(&tblDir, 0, sizeof(TT_TABLE_DIRECTORY));
135
+ BOOL bFound = FALSE;
136
+ char szTemp[4096];
137
+ memset(szTemp, 0, sizeof(szTemp));
138
+
139
+ for (int i = 0; i< ttOffsetTable.uNumOfTables; i++)
140
+ {
141
+ //f.Read(&tblDir, sizeof(TT_TABLE_DIRECTORY));
142
+ memcpy(&tblDir, &lpMapAddress[index], sizeof(TT_TABLE_DIRECTORY));
143
+ index += sizeof(TT_TABLE_DIRECTORY);
144
+
145
+ strncpy(szTemp, tblDir.szTag, 4);
146
+ if (stricmp(szTemp, "name") == 0)
147
+ {
148
+ bFound = TRUE;
149
+ tblDir.uLength = SWAPLONG(tblDir.uLength);
150
+ tblDir.uOffset = SWAPLONG(tblDir.uOffset);
151
+ break;
152
+ }
153
+ else if (szTemp[0] == 0)
154
+ {
155
+ break;
156
+ }
157
+ }
158
+
159
+ if (bFound)
160
+ {
161
+ index = tblDir.uOffset;
162
+
163
+ TT_NAME_TABLE_HEADER ttNTHeader;
164
+ memcpy(&ttNTHeader, &lpMapAddress[index], sizeof(TT_NAME_TABLE_HEADER));
165
+ index += sizeof(TT_NAME_TABLE_HEADER);
166
+
167
+ ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
168
+ ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
169
+ TT_NAME_RECORD ttRecord;
170
+ bFound = FALSE;
171
+
172
+ for (int i = 0;
173
+ i < ttNTHeader.uNRCount &&
174
+ (lpFontProps->csCopyright[0] == 0 ||
175
+ lpFontProps->csName[0] == 0 ||
176
+ lpFontProps->csTrademark[0] == 0 ||
177
+ lpFontProps->csFamily[0] == 0);
178
+ i++)
179
+ {
180
+ memcpy(&ttRecord, &lpMapAddress[index], sizeof(TT_NAME_RECORD));
181
+ index += sizeof(TT_NAME_RECORD);
182
+
183
+ ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
184
+ ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
185
+ ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
186
+
187
+ if (ttRecord.uNameID == 1 || ttRecord.uNameID == 0 || ttRecord.uNameID == 7)
188
+ {
189
+ int nPos = index; //f.GetPosition();
190
+
191
+ index = tblDir.uOffset + ttRecord.uStringOffset + ttNTHeader.uStorageOffset;
192
+
193
+ memset(szTemp, 0, sizeof(szTemp));
194
+
195
+ memcpy(szTemp, &lpMapAddress[index], ttRecord.uStringLength);
196
+ index += ttRecord.uStringLength;
197
+
198
+ if (szTemp[0] != 0)
199
+ {
200
+ _ASSERTE(strlen(szTemp) < sizeof(lpFontProps->csName));
201
+
202
+ switch (ttRecord.uNameID)
203
+ {
204
+ case 0:
205
+ if (lpFontProps->csCopyright[0] == 0)
206
+ strncpy(lpFontProps->csCopyright, szTemp,
207
+ sizeof(lpFontProps->csCopyright)-1);
208
+ break;
209
+
210
+ case 1:
211
+ if (lpFontProps->csFamily[0] == 0)
212
+ strncpy(lpFontProps->csFamily, szTemp,
213
+ sizeof(lpFontProps->csFamily)-1);
214
+ bRetVal = TRUE;
215
+ break;
216
+
217
+ case 4:
218
+ if (lpFontProps->csName[0] == 0)
219
+ strncpy(lpFontProps->csName, szTemp,
220
+ sizeof(lpFontProps->csName)-1);
221
+ break;
222
+
223
+ case 7:
224
+ if (lpFontProps->csTrademark[0] == 0)
225
+ strncpy(lpFontProps->csTrademark, szTemp,
226
+ sizeof(lpFontProps->csTrademark)-1);
227
+ break;
228
+
229
+ default:
230
+ break;
231
+ }
232
+ }
233
+ index = nPos;
234
+ }
235
+ }
236
+ }
237
+
238
+ ::UnmapViewOfFile(lpMapAddress);
239
+ ::CloseHandle(hMappedFile);
240
+ ::CloseHandle(hFile);
241
+
242
+ if (lpFontProps->csName[0] == 0)
243
+ strcpy(lpFontProps->csName, lpFontProps->csFamily);
244
+
245
+ return Gosu::widen(lpFontProps->csName);
246
+ }
247
+ }
@@ -0,0 +1,17 @@
1
+ #include <Gosu/Timing.hpp>
2
+ #include <Gosu/Math.hpp>
3
+ #include <unistd.h>
4
+ #include <time.h>
5
+ #include <sys/time.h>
6
+
7
+ void Gosu::sleep(unsigned milliseconds)
8
+ {
9
+ usleep(milliseconds * 1000);
10
+ }
11
+
12
+ unsigned long Gosu::milliseconds()
13
+ {
14
+ timeval tp;
15
+ gettimeofday(&tp, NULL);
16
+ return Gosu::trunc(tp.tv_usec / 1000 + tp.tv_sec * 1000);
17
+ }