gosu 0.7.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING.txt +29 -0
- data/Gosu/Async.hpp +48 -0
- data/Gosu/Audio.hpp +145 -0
- data/Gosu/AutoLink.hpp +16 -0
- data/Gosu/Bitmap.hpp +85 -0
- data/Gosu/ButtonsMac.hpp +114 -0
- data/Gosu/ButtonsWin.hpp +111 -0
- data/Gosu/ButtonsX.hpp +115 -0
- data/Gosu/Color.hpp +172 -0
- data/Gosu/Directories.hpp +36 -0
- data/Gosu/Font.hpp +59 -0
- data/Gosu/Fwd.hpp +31 -0
- data/Gosu/Gosu.hpp +26 -0
- data/Gosu/Graphics.hpp +86 -0
- data/Gosu/GraphicsBase.hpp +45 -0
- data/Gosu/IO.hpp +255 -0
- data/Gosu/Image.hpp +148 -0
- data/Gosu/ImageData.hpp +45 -0
- data/Gosu/Input.hpp +116 -0
- data/Gosu/Math.hpp +95 -0
- data/Gosu/Platform.hpp +61 -0
- data/Gosu/RotFlip.hpp +116 -0
- data/Gosu/Sockets.hpp +129 -0
- data/Gosu/Text.hpp +47 -0
- data/Gosu/TextInput.hpp +57 -0
- data/Gosu/Timing.hpp +16 -0
- data/Gosu/Utility.hpp +24 -0
- data/Gosu/WinUtility.hpp +76 -0
- data/Gosu/Window.hpp +84 -0
- data/GosuImpl/Async.cpp +37 -0
- data/GosuImpl/AudioFmod.cpp +417 -0
- data/GosuImpl/AudioSDL.cpp +255 -0
- data/GosuImpl/DirectoriesMac.mm +38 -0
- data/GosuImpl/DirectoriesUnix.cpp +48 -0
- data/GosuImpl/DirectoriesWin.cpp +42 -0
- data/GosuImpl/FileUnix.cpp +100 -0
- data/GosuImpl/FileWin.cpp +83 -0
- data/GosuImpl/Graphics/Bitmap.cpp +116 -0
- data/GosuImpl/Graphics/BitmapBMP.cpp +232 -0
- data/GosuImpl/Graphics/BitmapColorKey.cpp +39 -0
- data/GosuImpl/Graphics/BitmapPNG.cpp +276 -0
- data/GosuImpl/Graphics/BitmapUtils.cpp +67 -0
- data/GosuImpl/Graphics/BlockAllocator.cpp +127 -0
- data/GosuImpl/Graphics/BlockAllocator.hpp +34 -0
- data/GosuImpl/Graphics/Color.cpp +126 -0
- data/GosuImpl/Graphics/Common.hpp +21 -0
- data/GosuImpl/Graphics/DrawOp.hpp +154 -0
- data/GosuImpl/Graphics/Font.cpp +110 -0
- data/GosuImpl/Graphics/Graphics.cpp +295 -0
- data/GosuImpl/Graphics/Image.cpp +159 -0
- data/GosuImpl/Graphics/LargeImageData.cpp +115 -0
- data/GosuImpl/Graphics/LargeImageData.hpp +37 -0
- data/GosuImpl/Graphics/RotFlip.cpp +184 -0
- data/GosuImpl/Graphics/TexChunk.cpp +77 -0
- data/GosuImpl/Graphics/TexChunk.hpp +40 -0
- data/GosuImpl/Graphics/Text.cpp +223 -0
- data/GosuImpl/Graphics/TextMac.cpp +242 -0
- data/GosuImpl/Graphics/TextPangoFT.cpp +186 -0
- data/GosuImpl/Graphics/TextWin.cpp +172 -0
- data/GosuImpl/Graphics/Texture.cpp +104 -0
- data/GosuImpl/Graphics/Texture.hpp +34 -0
- data/GosuImpl/IO.cpp +48 -0
- data/GosuImpl/InputMac.mm +677 -0
- data/GosuImpl/InputWin.cpp +444 -0
- data/GosuImpl/InputX.cpp +158 -0
- data/GosuImpl/MacUtility.hpp +48 -0
- data/GosuImpl/Math.cpp +49 -0
- data/GosuImpl/RubyGosu.swg +474 -0
- data/GosuImpl/RubyGosuStub.mm +17 -0
- data/GosuImpl/RubyGosu_DllMain.cxx +30 -0
- data/GosuImpl/RubyGosu_wrap.cxx +8521 -0
- data/GosuImpl/RubyGosu_wrap.h +31 -0
- data/GosuImpl/Sockets/CommSocket.cpp +304 -0
- data/GosuImpl/Sockets/ListenerSocket.cpp +60 -0
- data/GosuImpl/Sockets/MessageSocket.cpp +136 -0
- data/GosuImpl/Sockets/Socket.cpp +145 -0
- data/GosuImpl/Sockets/Sockets.hpp +66 -0
- data/GosuImpl/TextInputMac.mm +207 -0
- data/GosuImpl/TextInputWin.cpp +197 -0
- data/GosuImpl/TextInputX.cpp +201 -0
- data/GosuImpl/TextTTFWin.cpp +247 -0
- data/GosuImpl/TimingUnix.cpp +17 -0
- data/GosuImpl/TimingWin.cpp +28 -0
- data/GosuImpl/Utility.cpp +140 -0
- data/GosuImpl/WinMain.cpp +69 -0
- data/GosuImpl/WinUtility.cpp +137 -0
- data/GosuImpl/WindowMac.mm +466 -0
- data/GosuImpl/WindowWin.cpp +447 -0
- data/GosuImpl/WindowX.cpp +392 -0
- data/GosuImpl/X11vroot.h +118 -0
- data/README.txt +13 -0
- data/Rakefile +178 -0
- data/examples/ChipmunkIntegration.rb +275 -0
- data/examples/CptnRuby.rb +231 -0
- data/examples/MoreChipmunkAndRMagick.rb +155 -0
- data/examples/OpenGLIntegration.rb +232 -0
- data/examples/RMagickIntegration.rb +449 -0
- data/examples/TextInput.cpp +170 -0
- data/examples/TextInput.rb +139 -0
- data/examples/Tutorial.cpp +215 -0
- data/examples/Tutorial.rb +137 -0
- data/examples/media/Beep.wav +0 -0
- data/examples/media/CptnRuby Gem.png +0 -0
- data/examples/media/CptnRuby Map.txt +25 -0
- data/examples/media/CptnRuby Tileset.png +0 -0
- data/examples/media/CptnRuby.png +0 -0
- data/examples/media/Cursor.png +0 -0
- data/examples/media/Earth.png +0 -0
- data/examples/media/Explosion.wav +0 -0
- data/examples/media/LargeStar.png +0 -0
- data/examples/media/Sky.jpg +0 -0
- data/examples/media/Smoke.png +0 -0
- data/examples/media/Soldier.png +0 -0
- data/examples/media/Space.png +0 -0
- data/examples/media/Star.png +0 -0
- data/examples/media/Starfighter.bmp +0 -0
- data/linux/Makefile.in +98 -0
- data/linux/configure +5658 -0
- data/linux/configure.ac +126 -0
- data/linux/extconf.rb +11 -0
- data/mac/English.lproj/InfoPlist.strings +0 -0
- data/mac/Gosu-Info.plist +26 -0
- data/mac/Gosu.xcodeproj/project.pbxproj +1194 -0
- data/mac/RubyGosu Template-Info.plist +26 -0
- data/mac/libboost_thread_1_34_1_universal.a +0 -0
- data/mac/libboost_thread_d_1_34_1_universal.a +0 -0
- data/mac/libfmod_universal.a +0 -0
- data/mac/libpng_universal.a +0 -0
- data/mac/libz_universal.a +0 -0
- data/reference/Async_8hpp-source.html +70 -0
- data/reference/Audio_8hpp-source.html +114 -0
- data/reference/Audio_8hpp.html +50 -0
- data/reference/AutoLink_8hpp-source.html +38 -0
- data/reference/AutoLink_8hpp.html +34 -0
- data/reference/Bitmap_8hpp-source.html +85 -0
- data/reference/Bitmap_8hpp.html +58 -0
- data/reference/ButtonsMac_8hpp-source.html +133 -0
- data/reference/ButtonsWin_8hpp-source.html +133 -0
- data/reference/ButtonsX_8hpp-source.html +134 -0
- data/reference/Color_8hpp-source.html +169 -0
- data/reference/Color_8hpp.html +85 -0
- data/reference/Directories_8hpp-source.html +42 -0
- data/reference/Directories_8hpp.html +46 -0
- data/reference/Font_8hpp-source.html +65 -0
- data/reference/Font_8hpp.html +41 -0
- data/reference/Fwd_8hpp-source.html +52 -0
- data/reference/Fwd_8hpp.html +37 -0
- data/reference/Gosu_8hpp-source.html +48 -0
- data/reference/Gosu_8hpp.html +34 -0
- data/reference/GraphicsBase_8hpp-source.html +57 -0
- data/reference/GraphicsBase_8hpp.html +56 -0
- data/reference/Graphics_8hpp-source.html +96 -0
- data/reference/Graphics_8hpp.html +53 -0
- data/reference/IO_8hpp-source.html +255 -0
- data/reference/IO_8hpp.html +74 -0
- data/reference/ImageData_8hpp-source.html +62 -0
- data/reference/ImageData_8hpp.html +43 -0
- data/reference/Image_8hpp-source.html +126 -0
- data/reference/Image_8hpp.html +48 -0
- data/reference/Input_8hpp-source.html +118 -0
- data/reference/Input_8hpp.html +50 -0
- data/reference/Math_8hpp-source.html +92 -0
- data/reference/Math_8hpp.html +74 -0
- data/reference/Platform_8hpp-source.html +83 -0
- data/reference/Platform_8hpp.html +73 -0
- data/reference/RotFlip_8hpp-source.html +138 -0
- data/reference/RotFlip_8hpp.html +77 -0
- data/reference/Sockets_8hpp-source.html +130 -0
- data/reference/Sockets_8hpp.html +66 -0
- data/reference/TextInput_8hpp-source.html +64 -0
- data/reference/TextInput_8hpp.html +41 -0
- data/reference/Text_8hpp-source.html +51 -0
- data/reference/Text_8hpp.html +46 -0
- data/reference/Timing_8hpp-source.html +36 -0
- data/reference/Timing_8hpp.html +42 -0
- data/reference/Utility_8hpp-source.html +44 -0
- data/reference/Utility_8hpp.html +48 -0
- data/reference/WinUtility_8hpp-source.html +79 -0
- data/reference/WinUtility_8hpp.html +64 -0
- data/reference/Window_8hpp-source.html +91 -0
- data/reference/Window_8hpp.html +41 -0
- data/reference/annotated.html +51 -0
- data/reference/classGosu_1_1Audio-members.html +34 -0
- data/reference/classGosu_1_1Audio.html +46 -0
- data/reference/classGosu_1_1Bitmap-members.html +44 -0
- data/reference/classGosu_1_1Bitmap.html +263 -0
- data/reference/classGosu_1_1Buffer-members.html +44 -0
- data/reference/classGosu_1_1Buffer.html +78 -0
- data/reference/classGosu_1_1Buffer.png +0 -0
- data/reference/classGosu_1_1Button-members.html +36 -0
- data/reference/classGosu_1_1Button.html +143 -0
- data/reference/classGosu_1_1Color-members.html +56 -0
- data/reference/classGosu_1_1Color.html +387 -0
- data/reference/classGosu_1_1File-members.html +41 -0
- data/reference/classGosu_1_1File.html +69 -0
- data/reference/classGosu_1_1File.png +0 -0
- data/reference/classGosu_1_1Font-members.html +39 -0
- data/reference/classGosu_1_1Font.html +309 -0
- data/reference/classGosu_1_1Graphics-members.html +50 -0
- data/reference/classGosu_1_1Graphics.html +234 -0
- data/reference/classGosu_1_1Image-members.html +45 -0
- data/reference/classGosu_1_1Image.html +518 -0
- data/reference/classGosu_1_1ImageData-members.html +37 -0
- data/reference/classGosu_1_1ImageData.html +60 -0
- data/reference/classGosu_1_1Input-members.html +44 -0
- data/reference/classGosu_1_1Input.html +223 -0
- data/reference/classGosu_1_1MessageSocket-members.html +40 -0
- data/reference/classGosu_1_1MessageSocket.html +233 -0
- data/reference/classGosu_1_1Resource-members.html +39 -0
- data/reference/classGosu_1_1Resource.html +116 -0
- data/reference/classGosu_1_1Resource.png +0 -0
- data/reference/classGosu_1_1Sample-members.html +37 -0
- data/reference/classGosu_1_1Sample.html +200 -0
- data/reference/classGosu_1_1SampleInstance-members.html +38 -0
- data/reference/classGosu_1_1SampleInstance.html +169 -0
- data/reference/classGosu_1_1Song-members.html +43 -0
- data/reference/classGosu_1_1Song.html +260 -0
- data/reference/classGosu_1_1TextInput-members.html +38 -0
- data/reference/classGosu_1_1TextInput.html +121 -0
- data/reference/classGosu_1_1Window-members.html +50 -0
- data/reference/classGosu_1_1Window.html +271 -0
- data/reference/doxyfile +233 -0
- data/reference/doxygen.css +433 -0
- data/reference/doxygen.png +0 -0
- data/reference/files.html +54 -0
- data/reference/functions.html +236 -0
- data/reference/functions_enum.html +45 -0
- data/reference/functions_func.html +227 -0
- data/reference/functions_vars.html +47 -0
- data/reference/hierarchy.html +53 -0
- data/reference/index.html +26 -0
- data/reference/namespaceGosu.html +2890 -0
- data/reference/namespaceGosu_1_1Colors.html +70 -0
- data/reference/namespaceGosu_1_1Win.html +275 -0
- data/reference/namespacemembers.html +216 -0
- data/reference/namespacemembers_enum.html +52 -0
- data/reference/namespacemembers_eval.html +54 -0
- data/reference/namespacemembers_func.html +185 -0
- data/reference/namespacemembers_type.html +46 -0
- data/reference/namespacemembers_vars.html +46 -0
- data/reference/namespaces.html +35 -0
- data/reference/tab_b.gif +0 -0
- data/reference/tab_l.gif +0 -0
- data/reference/tab_r.gif +0 -0
- data/reference/tabs.css +102 -0
- data/windows/Gosu.sln +29 -0
- data/windows/Gosu.vcproj +553 -0
- data/windows/RubyGosu.vcproj +138 -0
- 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
|
+
}
|