gosu 0.8.0.pre3 → 0.8.0.pre4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/Gosu/Buttons.hpp +13 -11
  3. data/{linux → ext/gosu}/extconf.rb +25 -47
  4. data/{GosuImpl/RubyGosu_wrap.cxx → ext/gosu/gosu_wrap.cxx} +3 -2
  5. data/{GosuImpl/RubyGosu_wrap.h → ext/gosu/gosu_wrap.h} +0 -0
  6. data/lib/gosu.rb +6 -7
  7. data/lib/gosu/zen.rb +12 -0
  8. data/{GosuImpl → src}/Audio/ALChannelManagement.hpp +0 -0
  9. data/{GosuImpl → src}/Audio/AudioFile.hpp +0 -0
  10. data/{GosuImpl → src}/Audio/AudioOpenAL.cpp +0 -0
  11. data/{GosuImpl → src}/Audio/AudioOpenAL.mm +0 -0
  12. data/{GosuImpl → src}/Audio/AudioToolboxFile.hpp +0 -0
  13. data/{GosuImpl → src}/Audio/OggFile.hpp +0 -0
  14. data/{GosuImpl → src}/Audio/SndFile.hpp +0 -0
  15. data/{GosuImpl/Graphics → src/Bitmap}/Bitmap.cpp +2 -0
  16. data/{GosuImpl/Graphics → src/Bitmap}/BitmapApple.mm +0 -0
  17. data/{GosuImpl/Graphics → src/Bitmap}/BitmapBMP.cpp +0 -0
  18. data/{GosuImpl/Graphics → src/Bitmap}/BitmapColorKey.cpp +0 -0
  19. data/{GosuImpl/Graphics → src/Bitmap}/BitmapFreeImage.cpp +0 -0
  20. data/{GosuImpl/Graphics → src/Bitmap}/BitmapGDIplus.cpp +0 -0
  21. data/{GosuImpl/Graphics → src/Bitmap}/BitmapUtils.cpp +0 -0
  22. data/{GosuImpl → src}/DirectoriesMac.mm +0 -0
  23. data/{GosuImpl → src}/DirectoriesTouch.mm +0 -0
  24. data/{GosuImpl → src}/DirectoriesUnix.cpp +0 -0
  25. data/{GosuImpl → src}/DirectoriesWin.cpp +0 -0
  26. data/{GosuImpl → src}/FileUnix.cpp +0 -0
  27. data/{GosuImpl → src}/FileWin.cpp +0 -0
  28. data/{GosuImpl/Graphics → src}/GosuView.hpp +0 -0
  29. data/{GosuImpl/Graphics → src}/GosuView.mm +0 -0
  30. data/{GosuImpl → src}/Graphics/BlockAllocator.cpp +0 -0
  31. data/{GosuImpl → src}/Graphics/BlockAllocator.hpp +0 -0
  32. data/{GosuImpl → src}/Graphics/ClipRectStack.hpp +0 -0
  33. data/{GosuImpl → src}/Graphics/Color.cpp +0 -0
  34. data/{GosuImpl → src}/Graphics/Common.hpp +0 -0
  35. data/{GosuImpl → src}/Graphics/DrawOp.hpp +0 -0
  36. data/{GosuImpl → src}/Graphics/DrawOpQueue.hpp +0 -0
  37. data/{GosuImpl → src}/Graphics/Graphics.cpp +0 -0
  38. data/{GosuImpl → src}/Graphics/Image.cpp +0 -0
  39. data/{GosuImpl → src}/Graphics/LargeImageData.cpp +0 -0
  40. data/{GosuImpl → src}/Graphics/LargeImageData.hpp +0 -0
  41. data/{GosuImpl → src}/Graphics/Macro.hpp +0 -0
  42. data/{GosuImpl → src}/Graphics/RenderState.hpp +0 -0
  43. data/{GosuImpl → src}/Graphics/TexChunk.cpp +0 -0
  44. data/{GosuImpl → src}/Graphics/TexChunk.hpp +0 -0
  45. data/{GosuImpl → src}/Graphics/Texture.cpp +0 -0
  46. data/{GosuImpl → src}/Graphics/Texture.hpp +0 -0
  47. data/{GosuImpl → src}/Graphics/Transform.cpp +0 -0
  48. data/{GosuImpl → src}/Graphics/TransformStack.hpp +0 -0
  49. data/{GosuImpl → src}/IO.cpp +0 -0
  50. data/{GosuImpl → src}/Iconv.hpp +0 -0
  51. data/{GosuImpl → src}/Input/AccelerometerReader.hpp +0 -0
  52. data/{GosuImpl → src}/Input/AccelerometerReader.mm +0 -0
  53. data/{GosuImpl → src/Input}/Input.cpp +0 -0
  54. data/{GosuImpl → src/Input}/InputTouch.mm +0 -0
  55. data/{GosuImpl → src/Input}/TextInput.cpp +0 -0
  56. data/{GosuImpl → src/Input}/TextInputMac.mm +0 -0
  57. data/{GosuImpl → src}/Inspection.cpp +0 -0
  58. data/{GosuImpl → src}/MacUtility.hpp +0 -0
  59. data/{GosuImpl → src}/Math.cpp +0 -0
  60. data/{GosuImpl → src}/Sockets/CommSocket.cpp +0 -0
  61. data/{GosuImpl → src}/Sockets/ListenerSocket.cpp +0 -0
  62. data/{GosuImpl → src}/Sockets/MessageSocket.cpp +0 -0
  63. data/{GosuImpl → src}/Sockets/Socket.cpp +0 -0
  64. data/{GosuImpl → src}/Sockets/Socket.hpp +0 -0
  65. data/{GosuImpl/Graphics → src/Text}/Font.cpp +1 -1
  66. data/{GosuImpl/Graphics → src/Text}/FormattedString.hpp +0 -0
  67. data/{GosuImpl/Graphics → src/Text}/Text.cpp +1 -1
  68. data/{GosuImpl/Graphics/TextTouch.mm → src/Text/TextApple.mm} +0 -0
  69. data/{GosuImpl/Graphics → src/Text}/TextMac.cpp +1 -1
  70. data/{GosuImpl/Graphics → src/Text}/TextTTFWin.cpp +0 -0
  71. data/{GosuImpl/Graphics → src/Text}/TextUnix.cpp +0 -0
  72. data/{GosuImpl/Graphics → src/Text}/TextWin.cpp +0 -0
  73. data/{GosuImpl → src}/TimingApple.cpp +0 -0
  74. data/{GosuImpl → src}/TimingUnix.cpp +0 -0
  75. data/{GosuImpl → src}/TimingWin.cpp +0 -0
  76. data/{GosuImpl → src}/Utility.cpp +0 -0
  77. data/{GosuImpl → src}/UtilityApple.mm +0 -0
  78. data/{GosuImpl → src}/UtilityWin.cpp +0 -0
  79. data/{GosuImpl → src}/WinMain.cpp +0 -0
  80. data/{GosuImpl → src}/WinUtility.cpp +0 -0
  81. data/{GosuImpl → src}/Window.cpp +0 -0
  82. data/{GosuImpl → src}/WindowTouch.mm +0 -0
  83. data/{GosuImpl → src}/X11vroot.h +0 -0
  84. metadata +97 -193
  85. data/.yardopts +0 -1
  86. data/COPYING +0 -29
  87. data/GosuImpl/InputMac.mm +0 -733
  88. data/GosuImpl/InputWin.cpp +0 -483
  89. data/GosuImpl/InputX.cpp +0 -243
  90. data/GosuImpl/RubyGosu.swg +0 -821
  91. data/GosuImpl/RubyGosu_SWIG_GC_PATCH.patch +0 -126
  92. data/GosuImpl/RubyGosu_SWIG_RENAME_PATCH.patch +0 -62
  93. data/GosuImpl/TextInputWin.cpp +0 -211
  94. data/GosuImpl/TextInputX.cpp +0 -217
  95. data/GosuImpl/WindowWin.cpp +0 -534
  96. data/GosuImpl/WindowX.cpp +0 -458
  97. data/README.txt +0 -25
  98. data/dependencies/libogg/AUTHORS +0 -4
  99. data/dependencies/libogg/CHANGES +0 -70
  100. data/dependencies/libogg/COPYING +0 -28
  101. data/dependencies/libogg/include/ogg/ogg.h +0 -209
  102. data/dependencies/libogg/include/ogg/os_types.h +0 -147
  103. data/dependencies/libogg/src/bitwise.c +0 -857
  104. data/dependencies/libogg/src/framing.c +0 -2089
  105. data/dependencies/libvorbis/AUTHORS +0 -3
  106. data/dependencies/libvorbis/CHANGES +0 -126
  107. data/dependencies/libvorbis/COPYING +0 -28
  108. data/dependencies/libvorbis/include/vorbis/codec.h +0 -243
  109. data/dependencies/libvorbis/include/vorbis/vorbisenc.h +0 -436
  110. data/dependencies/libvorbis/include/vorbis/vorbisfile.h +0 -206
  111. data/dependencies/libvorbis/lib/analysis.c +0 -120
  112. data/dependencies/libvorbis/lib/backends.h +0 -144
  113. data/dependencies/libvorbis/lib/barkmel.c +0 -64
  114. data/dependencies/libvorbis/lib/bitrate.c +0 -253
  115. data/dependencies/libvorbis/lib/bitrate.h +0 -59
  116. data/dependencies/libvorbis/lib/block.c +0 -1046
  117. data/dependencies/libvorbis/lib/books/coupled/res_books_51.h +0 -12257
  118. data/dependencies/libvorbis/lib/books/coupled/res_books_stereo.h +0 -15783
  119. data/dependencies/libvorbis/lib/books/floor/floor_books.h +0 -1547
  120. data/dependencies/libvorbis/lib/books/uncoupled/res_books_uncoupled.h +0 -7758
  121. data/dependencies/libvorbis/lib/codebook.c +0 -479
  122. data/dependencies/libvorbis/lib/codebook.h +0 -119
  123. data/dependencies/libvorbis/lib/codec_internal.h +0 -167
  124. data/dependencies/libvorbis/lib/envelope.c +0 -375
  125. data/dependencies/libvorbis/lib/envelope.h +0 -80
  126. data/dependencies/libvorbis/lib/floor0.c +0 -222
  127. data/dependencies/libvorbis/lib/floor1.c +0 -1099
  128. data/dependencies/libvorbis/lib/highlevel.h +0 -58
  129. data/dependencies/libvorbis/lib/info.c +0 -664
  130. data/dependencies/libvorbis/lib/lookup.c +0 -94
  131. data/dependencies/libvorbis/lib/lookup.h +0 -32
  132. data/dependencies/libvorbis/lib/lookup_data.h +0 -192
  133. data/dependencies/libvorbis/lib/lpc.c +0 -160
  134. data/dependencies/libvorbis/lib/lpc.h +0 -29
  135. data/dependencies/libvorbis/lib/lsp.c +0 -456
  136. data/dependencies/libvorbis/lib/lsp.h +0 -28
  137. data/dependencies/libvorbis/lib/mapping0.c +0 -816
  138. data/dependencies/libvorbis/lib/masking.h +0 -785
  139. data/dependencies/libvorbis/lib/mdct.c +0 -563
  140. data/dependencies/libvorbis/lib/mdct.h +0 -71
  141. data/dependencies/libvorbis/lib/misc.h +0 -57
  142. data/dependencies/libvorbis/lib/modes/floor_all.h +0 -260
  143. data/dependencies/libvorbis/lib/modes/psych_11.h +0 -51
  144. data/dependencies/libvorbis/lib/modes/psych_16.h +0 -133
  145. data/dependencies/libvorbis/lib/modes/psych_44.h +0 -642
  146. data/dependencies/libvorbis/lib/modes/psych_8.h +0 -101
  147. data/dependencies/libvorbis/lib/modes/residue_16.h +0 -163
  148. data/dependencies/libvorbis/lib/modes/residue_44.h +0 -292
  149. data/dependencies/libvorbis/lib/modes/residue_44p51.h +0 -451
  150. data/dependencies/libvorbis/lib/modes/residue_44u.h +0 -318
  151. data/dependencies/libvorbis/lib/modes/residue_8.h +0 -109
  152. data/dependencies/libvorbis/lib/modes/setup_11.h +0 -143
  153. data/dependencies/libvorbis/lib/modes/setup_16.h +0 -153
  154. data/dependencies/libvorbis/lib/modes/setup_22.h +0 -128
  155. data/dependencies/libvorbis/lib/modes/setup_32.h +0 -132
  156. data/dependencies/libvorbis/lib/modes/setup_44.h +0 -117
  157. data/dependencies/libvorbis/lib/modes/setup_44p51.h +0 -74
  158. data/dependencies/libvorbis/lib/modes/setup_44u.h +0 -74
  159. data/dependencies/libvorbis/lib/modes/setup_8.h +0 -149
  160. data/dependencies/libvorbis/lib/modes/setup_X.h +0 -225
  161. data/dependencies/libvorbis/lib/os.h +0 -186
  162. data/dependencies/libvorbis/lib/psy.c +0 -1203
  163. data/dependencies/libvorbis/lib/psy.h +0 -154
  164. data/dependencies/libvorbis/lib/psytune.c +0 -524
  165. data/dependencies/libvorbis/lib/registry.c +0 -45
  166. data/dependencies/libvorbis/lib/registry.h +0 -32
  167. data/dependencies/libvorbis/lib/res0.c +0 -889
  168. data/dependencies/libvorbis/lib/scales.h +0 -90
  169. data/dependencies/libvorbis/lib/sharedbook.c +0 -579
  170. data/dependencies/libvorbis/lib/smallft.c +0 -1255
  171. data/dependencies/libvorbis/lib/smallft.h +0 -34
  172. data/dependencies/libvorbis/lib/synthesis.c +0 -184
  173. data/dependencies/libvorbis/lib/tone.c +0 -54
  174. data/dependencies/libvorbis/lib/vorbisenc.c +0 -1215
  175. data/dependencies/libvorbis/lib/vorbisfile.c +0 -2337
  176. data/dependencies/libvorbis/lib/window.c +0 -2135
  177. data/dependencies/libvorbis/lib/window.h +0 -26
  178. data/dependencies/ogg_vorbis.license +0 -28
  179. data/reference/gosu.rb +0 -1284
@@ -1,243 +0,0 @@
1
- #include <Gosu/Input.hpp>
2
- #include <Gosu/TextInput.hpp>
3
- #include <Gosu/Utility.hpp>
4
- #include <vector>
5
- #include <map>
6
-
7
- struct Gosu::Input::Impl
8
- {
9
- TextInput* textInput;
10
- std::vector< ::XEvent> eventList;
11
- std::map<unsigned int, bool> keyMap;
12
- double mouseX, mouseY, mouseFactorX, mouseFactorY;
13
- static ::Display* display;
14
- ::Window window;
15
- Impl() : textInput(0) {}
16
- };
17
-
18
- // TODO - ugly, but necessary for charToId/idToChar, since they are static functions.
19
- // TODO - should instead create a global, shared connection to X11
20
- ::Display* Gosu::Input::Impl::display = NULL;
21
-
22
- Gosu::Input::Input(::Display* dpy, ::Window wnd)
23
- : pimpl(new Impl)
24
- {
25
- // IMPR: Get current position?
26
- pimpl->mouseX = pimpl->mouseY = 0;
27
- pimpl->mouseFactorX = pimpl->mouseFactorY = 1.0;
28
- pimpl->display = dpy;
29
- pimpl->window = wnd;
30
- }
31
-
32
- Gosu::Input::~Input()
33
- {
34
- Impl::display = NULL;
35
- }
36
-
37
- bool Gosu::Input::feedXEvent(::XEvent& event)
38
- {
39
- // IMPR: Wouldn't it make more sense to filter the other way around?
40
-
41
- if(event.type == VisibilityNotify ||
42
- event.type == CirculateRequest ||
43
- event.type == ConfigureRequest ||
44
- event.type == MapRequest ||
45
- event.type == ResizeRequest ||
46
- event.type == ClientMessage)
47
- return false;
48
-
49
- pimpl->eventList.push_back(event);
50
- return true;
51
- }
52
-
53
- bool Gosu::Input::down(Gosu::Button btn) const
54
- {
55
- if (btn == noButton)
56
- return false;
57
-
58
- // Will default to false for unknown indices (good).
59
- return pimpl->keyMap[btn.id()];
60
- }
61
-
62
- Gosu::Button Gosu::Input::charToId(wchar_t ch)
63
- {
64
- // TODO - Effectively, this is now a member function of Input again, not a
65
- // static member function.
66
- if (! Impl::display)
67
- return noButton;
68
-
69
- // TODO - Does this always work for ISO Latin 1 (which the lowest Unicode byte maps to)?
70
- if (ch >= 32 && ch <= 255)
71
- return Button(XKeysymToKeycode(Impl::display, ch) - 8);
72
-
73
- // TODO - no idea how other characters can be found. Maybe with the code above?
74
- return noButton;
75
- }
76
-
77
- wchar_t Gosu::Input::idToChar(Button btn)
78
- {
79
- // TODO - Effectively, this is now a member function of Input again, not a
80
- // static member function.
81
- if (! Impl::display)
82
- return 0;
83
-
84
- KeySym keySym = XKeycodeToKeysym(Impl::display, btn.id() + 8, 0);
85
- if (keySym == NoSymbol || keySym < 32 || keySym > 255)
86
- return 0;
87
- return keySym;
88
- }
89
-
90
- double Gosu::Input::mouseX() const
91
- {
92
- return pimpl->mouseX * pimpl->mouseFactorX;
93
- }
94
-
95
- double Gosu::Input::mouseY() const
96
- {
97
- return pimpl->mouseY * pimpl->mouseFactorY;
98
- }
99
-
100
- void Gosu::Input::setMouseFactors(double factorX, double factorY)
101
- {
102
- pimpl->mouseFactorX = factorX;
103
- pimpl->mouseFactorY = factorY;
104
- }
105
-
106
- const Gosu::Touches& Gosu::Input::currentTouches() const
107
- {
108
- static Gosu::Touches none;
109
- return none;
110
- }
111
-
112
- double Gosu::Input::accelerometerX() const
113
- {
114
- return 0.0;
115
- }
116
-
117
- double Gosu::Input::accelerometerY() const
118
- {
119
- return 0.0;
120
- }
121
-
122
- double Gosu::Input::accelerometerZ() const
123
- {
124
- return 0.0;
125
- }
126
-
127
- void Gosu::Input::update()
128
- {
129
- for (unsigned int i = 0; i < pimpl->eventList.size(); i++)
130
- {
131
- ::XEvent event = pimpl->eventList[i];
132
-
133
- if (textInput() && textInput()->feedXEvent(pimpl->display, &event))
134
- continue;
135
-
136
- if (event.type == KeyPress)
137
- {
138
- unsigned id = event.xkey.keycode - 8;
139
-
140
- pimpl->keyMap[id] = true;
141
- if (onButtonDown)
142
- onButtonDown(Button(id));
143
- }
144
- else if (event.type == KeyRelease)
145
- {
146
- if (i < pimpl->eventList.size() - 1)
147
- {
148
- ::XEvent nextEvent = pimpl->eventList[i + 1];
149
- if (nextEvent.type == KeyPress && nextEvent.xkey.keycode == event.xkey.keycode)
150
- {
151
- i += 1;
152
- continue;
153
- }
154
- }
155
-
156
- unsigned id = event.xkey.keycode - 8;
157
-
158
- pimpl->keyMap[id] = false;
159
- if (onButtonUp)
160
- onButtonUp(Button(id));
161
- }
162
- else if (event.type == ButtonPress)
163
- {
164
- unsigned id;
165
- switch (event.xbutton.button)
166
- {
167
- case Button1: id = msLeft; break;
168
- case Button2: id = msMiddle; break;
169
- case Button3: id = msRight; break;
170
- case Button4: id = msWheelUp; break;
171
- case Button5: id = msWheelDown; break;
172
- case 6: id = msOther0; break;
173
- case 7: id = msOther1; break;
174
- case 8: id = msOther2; break;
175
- case 9: id = msOther3; break;
176
- case 10: id = msOther4; break;
177
- case 11: id = msOther5; break;
178
- case 12: id = msOther6; break;
179
- case 13: id = msOther7; break;
180
- default: continue;
181
- }
182
- pimpl->keyMap[id] = true;
183
- if (onButtonDown)
184
- onButtonDown(Button(id));
185
- }
186
- else if (event.type == ButtonRelease)
187
- {
188
- unsigned id;
189
- switch (event.xbutton.button)
190
- {
191
- case Button1: id = msLeft; break;
192
- case Button2: id = msMiddle; break;
193
- case Button3: id = msRight; break;
194
- case Button4: id = msWheelUp; break;
195
- case Button5: id = msWheelDown; break;
196
- case 6: id = msOther0; break;
197
- case 7: id = msOther1; break;
198
- case 8: id = msOther2; break;
199
- case 9: id = msOther3; break;
200
- case 10: id = msOther4; break;
201
- case 11: id = msOther5; break;
202
- case 12: id = msOther6; break;
203
- case 13: id = msOther7; break;
204
- default: continue;
205
- }
206
- pimpl->keyMap[id] = false;
207
- if (onButtonUp)
208
- onButtonUp(Button(id));
209
- }
210
- else if (event.type == MotionNotify)
211
- {
212
- pimpl->mouseX = event.xbutton.x;
213
- pimpl->mouseY = event.xbutton.y;
214
- }
215
- else if (event.type == EnterNotify || event.type == LeaveNotify)
216
- {
217
- pimpl->mouseX = event.xcrossing.x;
218
- pimpl->mouseY = event.xcrossing.y;
219
- }
220
- }
221
- pimpl->eventList.clear();
222
- }
223
-
224
- void Gosu::Input::setMousePosition(double x, double y)
225
- {
226
- ::XWarpPointer(pimpl->display, None, pimpl->window, 0, 0, 0, 0,
227
- x / pimpl->mouseFactorX, y / pimpl->mouseFactorY);
228
- ::XSync(pimpl->display, False);
229
- // Couldn't find a way to fetch the current mouse position. These
230
- // values may not be correct if the cursor was grabbed, for example.
231
- pimpl->mouseX = x, pimpl->mouseY = y;
232
- }
233
-
234
- Gosu::TextInput* Gosu::Input::textInput() const
235
- {
236
- return pimpl->textInput;
237
- }
238
-
239
- void Gosu::Input::setTextInput(TextInput* textInput)
240
- {
241
- pimpl->textInput = textInput;
242
- }
243
-
@@ -1,821 +0,0 @@
1
- // Mini SWIG file TODO List:
2
- // - %predicate instead of %rename where applicable
3
- // - use Python names for op overloading for easier porting to other languages
4
-
5
- %trackobjects;
6
- %include exception.i
7
-
8
- // Don't complain about ignored operators.
9
- #pragma SWIG nowarn=378
10
-
11
- // The docs make it seem like this is a generally good idea.
12
- %feature("compactdefaultargs");
13
-
14
- // Overriding virtuals is necessary in Gosu::Window.
15
- %feature("director") Gosu::Window;
16
-
17
- // Overriding virtuals is necessary in Gosu::TextInput.
18
- %feature("director") Gosu::TextInput;
19
-
20
- // Resolve typedefs that SWIG doesn't recognize.
21
- %apply unsigned char { std::tr1::uint8_t };
22
- %apply unsigned long { std::tr1::uint32_t };
23
-
24
- // Custom typemaps for wchar/wstring.
25
- #pragma SWIG nowarn=-490,-319
26
- %typemap(in) wchar_t {
27
- VALUE rbString = rb_obj_as_string($input);
28
- char* utf8String = StringValueCStr(rbString);
29
- std::wstring ucsString = Gosu::utf8ToWstring(utf8String);
30
- if (ucsString.length() != 1)
31
- rb_raise(rb_eArgError,
32
- "A single-character string was expected, but `%s' given",
33
- utf8String);
34
-
35
- $1 = ucsString[0];
36
- }
37
- %typemap(out) wchar_t {
38
- if ($1 == 0)
39
- $result = Qnil;
40
- else
41
- {
42
- $result = rb_str_new2(Gosu::wstringToUTF8(std::wstring(1, $1)).c_str());
43
- FIX_ENCODING($result);
44
- }
45
- }
46
- %typemap(in) const std::wstring& (std::wstring temp) {
47
- VALUE localTemporary = rb_obj_as_string($input);
48
- temp = Gosu::utf8ToWstring(StringValueCStr(localTemporary));
49
- $1 = &temp;
50
- }
51
- %apply const std::wstring& { std::wstring, const std::string };
52
- %typemap(out) std::wstring {
53
- $result = rb_str_new2(Gosu::wstringToUTF8($1).c_str());
54
- FIX_ENCODING($result);
55
- }
56
- %typemap(out) const std::wstring& {
57
- $result = rb_str_new2(Gosu::wstringToUTF8($1).c_str());
58
- FIX_ENCODING($result);
59
- }
60
- %typemap(directorin) const std::wstring& {
61
- $input = rb_str_new2(Gosu::wstringToUTF8($1).c_str());
62
- FIX_ENCODING($input);
63
- }
64
- %typemap(directorout) std::wstring {
65
- VALUE localTemporary = rb_obj_as_string($1);
66
- $result = Gosu::utf8ToWstring(StringValueCStr(localTemporary));;
67
- }
68
- %typemap(out) std::string {
69
- $result = rb_str_new2($1.c_str());
70
- FIX_ENCODING($result);
71
- }
72
-
73
- %typemap(in) Gosu::Button {
74
- if (NIL_P($input))
75
- $1 = Gosu::noButton;
76
- else
77
- $1 = Gosu::Button(NUM2LONG($input));
78
- }
79
- %typemap(out) Gosu::Button {
80
- if ($1 == Gosu::noButton)
81
- $result = Qnil;
82
- else
83
- $result = LONG2NUM($1.id());
84
- }
85
- %typemap(directorin) Gosu::Button {
86
- if ($1 == Gosu::noButton)
87
- $input = Qnil;
88
- else
89
- $input = LONG2NUM($1.id());
90
- }
91
-
92
- // Typemaps for enums that should be given in as symbols.
93
- %typemap(in) Gosu::AlphaMode {
94
- const char* cstr = Gosu::cstrFromSymbol($input);
95
-
96
- if (!cstr)
97
- SWIG_exception_fail(SWIG_ValueError, "alpha mode must be a symbol");
98
- else if (!strcmp(cstr, "default"))
99
- $1 = Gosu::amDefault;
100
- else if (!strcmp(cstr, "add"))
101
- $1 = Gosu::amAdditive;
102
- else if (!strcmp(cstr, "additive"))
103
- $1 = Gosu::amAdditive;
104
- else if (!strcmp(cstr, "multiply"))
105
- $1 = Gosu::amMultiply;
106
- else
107
- SWIG_exception_fail(SWIG_ValueError, "invalid alpha mode");
108
- }
109
- %typemap(in) Gosu::TextAlign {
110
- const char* cstr = Gosu::cstrFromSymbol($input);
111
-
112
- if (!cstr)
113
- SWIG_exception_fail(SWIG_ValueError, "text align must be a symbol");
114
- else if (!strcmp(cstr, "left"))
115
- $1 = Gosu::taLeft;
116
- else if (!strcmp(cstr, "center"))
117
- $1 = Gosu::taCenter;
118
- else if (!strcmp(cstr, "right"))
119
- $1 = Gosu::taRight;
120
- else if (!strcmp(cstr, "justify"))
121
- $1 = Gosu::taJustify;
122
- else
123
- SWIG_exception_fail(SWIG_ValueError, "invalid text align");
124
- }
125
-
126
- // Allow integral constants to be passed in place of Color values.
127
- %typemap(in) Gosu::Color {
128
- if (TYPE($input) == T_FIXNUM || TYPE($input) == T_BIGNUM)
129
- $1 = Gosu::Color(NUM2ULONG($input));
130
- else
131
- {
132
- void* ptr;
133
- int res = SWIG_ConvertPtr($input, &ptr, SWIGTYPE_p_Gosu__Color, 0);
134
- if (!SWIG_IsOK(res))
135
- SWIG_exception_fail(SWIG_ValueError, "invalid value");
136
- else if (!ptr)
137
- SWIG_exception_fail(SWIG_ValueError, "invalid null reference of type Gosu::Color");
138
- else
139
- $1 = *reinterpret_cast<Gosu::Color*>(ptr);
140
- }
141
- }
142
-
143
- // Make color channels less strict.
144
- %typemap(in) Gosu::Color::Channel {
145
- $1 = Gosu::clamp<int>(NUM2ULONG($input), 0, 255);
146
- }
147
- // To allow for overloading with Channel values.
148
- %typemap(typecheck) Gosu::Color::Channel {
149
- $1 = !!rb_respond_to($input, rb_intern("to_i"));
150
- }
151
-
152
- // Header inclusion (order irrelevant)
153
- %module(directors="1") gosu
154
- %{
155
- // Avoid Ruby Macro Hell on Windows...
156
- #undef accept
157
- #undef write
158
- #undef close
159
- #undef read
160
- #undef bind
161
- #undef send
162
- #undef sleep
163
- #undef Sleep
164
- #undef int8_t
165
- #undef uint8_t
166
- #undef int16_t
167
- #undef uint16_t
168
- #undef int32_t
169
- #undef uint32_t
170
- #undef int64_t
171
- #undef uint64_t
172
-
173
- //#ifndef WIN32
174
- //#include <Gosu/Async.hpp>
175
- //#endif
176
-
177
- #include <Gosu/Gosu.hpp>
178
- #ifdef GOSU_IS_WIN
179
- #include <FreeImage.h>
180
- #endif
181
- #include <Gosu/TR1.hpp>
182
-
183
- namespace Gosu {
184
- void enableUndocumentedRetrofication() { extern bool undocumentedRetrofication; undocumentedRetrofication = true; }
185
- void releaseAllOpenALResources();
186
- void register_entity(const std::wstring& name, Gosu::Image* image) { registerEntity(name, image->getData().toBitmap()); }
187
- }
188
-
189
- #include <cstring>
190
- #include <ctime>
191
- #include <sstream>
192
-
193
- // Preprocessor check for 1.9 (thanks banister)
194
- #if defined(ROBJECT_EMBED_LEN_MAX)
195
- #define FIX_ENCODING(var) \
196
- rb_funcall(var, rb_intern("force_encoding"), 1, rb_str_new2("UTF-8"));
197
- #define RUBY_18_19(r18, r19) r19
198
- #else
199
- #define FIX_ENCODING(var)
200
- #define RUBY_18_19(r18, r19) r18
201
- #endif
202
-
203
- namespace GosusDarkSide
204
- {
205
- // TODO: Find a way for this to fit into Gosu's design.
206
- // This can point to a function that wants to be called every
207
- // frame, e.g. rb_thread_schedule.
208
- typedef void (*HookOfHorror)();
209
- extern HookOfHorror oncePerTick;
210
-
211
- void yieldToOtherRubyThreads()
212
- {
213
- rb_thread_schedule();
214
- }
215
- }
216
-
217
- namespace
218
- {
219
- void callRubyBlock(VALUE block) {
220
- rb_funcall(block, rb_intern("call"), 0);
221
- }
222
- }
223
-
224
- namespace Gosu
225
- {
226
- #ifdef GOSU_IS_WIN
227
- void requireFreeImageFor(const char* filename)
228
- {
229
- // Copied and pasted from MSDN.
230
- // TODO: Remove duplication, this is also in AudioAudiere.cpp
231
- #define FACILITY_VISUALCPP ((LONG)0x6d)
232
- #define VcppException(sev,err) ((sev) | (FACILITY_VISUALCPP<<16) | err)
233
- #define BAD_MOD VcppException(ERROR_SEVERITY_ERROR, ERROR_MOD_NOT_FOUND)
234
-
235
- __try
236
- {
237
- FreeImage_GetVersion();
238
- }
239
- __except ((GetExceptionCode() == BAD_MOD) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
240
- {
241
- rb_raise(rb_eRuntimeError,
242
- "Could neither load image %s nor locate FreeImage.dll to retry with it",
243
- filename);
244
- }
245
- #undef BAD_MOD
246
- #undef VcppException
247
- #undef FACILITY_VISUALCPP
248
- }
249
- void loadImageFile_FreeImage(Bitmap& result, const std::wstring& filename);
250
- #endif
251
- void loadBitmap(Bitmap& bitmap, VALUE val)
252
- {
253
- // Try to treat as filename first.
254
- if (rb_respond_to(val, rb_intern("to_str")))
255
- {
256
- VALUE to_str = rb_funcall(val, rb_intern("to_str"), 0);
257
- const char* filenameUTF8 = StringValuePtr(to_str);
258
- std::wstring filename = Gosu::utf8ToWstring(filenameUTF8);
259
- try {
260
- loadImageFile(bitmap, filename);
261
- return;
262
- } catch (const std::exception&) {
263
- #ifdef GOSU_IS_WIN
264
- requireFreeImageFor(filenameUTF8);
265
- try {
266
- loadImageFile_FreeImage(bitmap, filename);
267
- }
268
- catch (const std::runtime_error& error) {
269
- rb_raise(rb_eRuntimeError,
270
- "Could not load image %s using either GDI+ or FreeImage: %s",
271
- filenameUTF8, error.what());
272
- }
273
- return;
274
- #else
275
- throw;
276
- #endif
277
- }
278
- }
279
-
280
- // Otherwise, try to call .to_blob on it (works with RMagick, TexPlay etc).
281
- VALUE conversion = rb_str_new2("to_blob { self.format = 'RGBA'; self.depth = 8 }");
282
- VALUE blob = rb_obj_instance_eval(1, &conversion, val);
283
- rb_check_safe_obj(blob);
284
- unsigned width = NUM2ULONG(rb_funcall(val, rb_intern("columns"), 0));
285
- unsigned height = NUM2ULONG(rb_funcall(val, rb_intern("rows"), 0));
286
-
287
- bitmap.resize(width, height, Gosu::Color::NONE);
288
- if (width * height * 4 == RSTRING_LEN(blob))
289
- {
290
- // 32 bit per pixel, assume R8G8B8A8
291
- std::memcpy(bitmap.data(),
292
- reinterpret_cast<const unsigned*>(RSTRING_PTR(blob)), width * height * 4);
293
- }
294
- else if (width * height * 4 * sizeof(float) == RSTRING_LEN(blob))
295
- {
296
- // 32 bit per channel, assume float/float/float/float
297
- const float* in = reinterpret_cast<const float*>(RSTRING_PTR(blob));
298
- Gosu::Color::Channel* out = reinterpret_cast<Gosu::Color::Channel*>(bitmap.data());
299
- for (int i = width * height * 4; i > 0; --i)
300
- *(out++) = *(in++) * 255;
301
- }
302
- else
303
- throw std::logic_error("Blob length mismatch!");
304
- }
305
-
306
- const char* cstrFromSymbol(VALUE symbol) {
307
- if (TYPE(symbol) != T_SYMBOL)
308
- return 0; // to be caught by the caller
309
- return rb_id2name(SYM2ID(symbol));
310
- }
311
- }
312
- %}
313
-
314
- // Exception wrapping
315
- %exception {
316
- try {
317
- $action
318
- } catch (const std::exception& e) {
319
- SWIG_exception(SWIG_RuntimeError, e.what());
320
- }
321
- }
322
-
323
- // Version constant
324
- %rename("MAJOR_VERSION") GOSU_MAJOR_VERSION;
325
- %rename("MINOR_VERSION") GOSU_MINOR_VERSION;
326
- %rename("POINT_VERSION") GOSU_POINT_VERSION;
327
- %rename("VERSION") GOSU_VERSION;
328
- %include "../Gosu/Version.hpp"
329
-
330
- // Miscellaneous functions (timing, math)
331
- %ignore Gosu::sleep;
332
- %include "../Gosu/Timing.hpp"
333
- %ignore Gosu::pi;
334
- %ignore Gosu::distanceSqr;
335
- %ignore Gosu::round;
336
- %ignore Gosu::trunc;
337
- %ignore Gosu::boundBy;
338
- %ignore Gosu::clamp;
339
- %ignore Gosu::wrap;
340
- %ignore Gosu::radiansToGosu;
341
- %ignore Gosu::gosuToRadians;
342
- %include "../Gosu/Math.hpp"
343
- %ignore Gosu::textWidth;
344
- %ignore Gosu::createText;
345
- %ignore Gosu::textHeight;
346
- %ignore Gosu::drawText;
347
- %ignore Gosu::registerEntity;
348
- %include "../Gosu/Text.hpp"
349
-
350
-
351
- // Graphics:
352
-
353
- // ZPos, AlphaMode, FontFlags, TextAlign
354
- %ignore Gosu::AlphaMode;
355
- %ignore Gosu::FontFlags;
356
- %ignore Gosu::TextAlign;
357
- %ignore Gosu::BorderFlags;
358
- %ignore Gosu::concat;
359
- %ignore Gosu::translate;
360
- %ignore Gosu::rotate;
361
- %ignore Gosu::scale;
362
- %include "../Gosu/GraphicsBase.hpp"
363
-
364
- // For screenWidth/screenHeight
365
- %ignore Gosu::Graphics;
366
- %ignore Gosu::BorderFlags;
367
- %ignore Gosu::MAX_TEXTURE_SIZE;
368
- %include "../Gosu/Graphics.hpp"
369
-
370
- %constant unsigned MAX_TEXTURE_SIZE = Gosu::MAX_TEXTURE_SIZE;
371
-
372
- %rename("_release_all_openal_resources") releaseAllOpenALResources;
373
-
374
- namespace Gosu {
375
- std::string language();
376
- void enableUndocumentedRetrofication();
377
- void releaseAllOpenALResources();
378
- void register_entity(const std::wstring& name, Gosu::Image* image);
379
- }
380
-
381
- // Color
382
- %rename("alpha=") setAlpha;
383
- %rename("red=") setRed;
384
- %rename("green=") setGreen;
385
- %rename("blue=") setBlue;
386
- %rename("hue=") setHue;
387
- %rename("saturation=") setSaturation;
388
- %rename("value=") setValue;
389
- %include "std_string.i"
390
-
391
- %ignore Gosu::Color::argb();
392
- %ignore Gosu::Color::bgr();
393
- %ignore Gosu::Color::abgr();
394
- %ignore Gosu::Color::NONE;
395
- %ignore Gosu::Color::BLACK;
396
- %ignore Gosu::Color::GRAY;
397
- %ignore Gosu::Color::WHITE;
398
- %ignore Gosu::Color::AQUA;
399
- %ignore Gosu::Color::RED;
400
- %ignore Gosu::Color::GREEN;
401
- %ignore Gosu::Color::BLUE;
402
- %ignore Gosu::Color::YELLOW;
403
- %ignore Gosu::Color::FUCHSIA;
404
- %ignore Gosu::Color::CYAN;
405
-
406
- %include "../Gosu/Color.hpp"
407
-
408
- %extend Gosu::Color {
409
- static Gosu::Color rgb(Gosu::Color::Channel r, Gosu::Color::Channel g,
410
- Gosu::Color::Channel b)
411
- {
412
- return Gosu::Color(r, g, b);
413
- }
414
-
415
- static Gosu::Color rgba(Gosu::Color::Channel r, Gosu::Color::Channel g,
416
- Gosu::Color::Channel b, Gosu::Color::Channel a)
417
- {
418
- return Gosu::Color(a, r, g, b);
419
- }
420
-
421
- static Gosu::Color rgba(std::tr1::uint32_t rgba)
422
- {
423
- return Gosu::Color(rgba & 0xff, (rgba >> 24) & 0xff,
424
- (rgba >> 16) & 0xff, (rgba >> 8) & 0xff);
425
- }
426
-
427
- static Gosu::Color argb(Gosu::Color::Channel a, Gosu::Color::Channel r,
428
- Gosu::Color::Channel g, Gosu::Color::Channel b)
429
- {
430
- return Gosu::Color(a, r, g, b);
431
- }
432
-
433
- static Gosu::Color argb(std::tr1::uint32_t argb)
434
- {
435
- return Gosu::Color(argb);
436
- }
437
-
438
- Gosu::Color dup() const {
439
- return *$self;
440
- }
441
-
442
- std::string toS() const {
443
- std::ostringstream stream;
444
- stream << "(ARGB: " << static_cast<int>($self->alpha())
445
- << "/" << static_cast<int>($self->red())
446
- << "/" << static_cast<int>($self->green())
447
- << "/" << static_cast<int>($self->blue()) << ")";
448
- return stream.str();
449
- }
450
-
451
- bool operator==(VALUE other) {
452
- if (TYPE(other) == T_FIXNUM || TYPE(other) == T_BIGNUM)
453
- return *$self == Gosu::Color(NUM2ULONG(other));
454
- void* ptr;
455
- int res = SWIG_ConvertPtr(other, &ptr, SWIGTYPE_p_Gosu__Color, 0);
456
- return SWIG_IsOK(res) && ptr && *$self == *reinterpret_cast<Gosu::Color*>(ptr);
457
- }
458
- }
459
-
460
- // Font
461
- %ignore Gosu::Font::Font(Graphics& graphics, const std::wstring& fontName,
462
- unsigned height, unsigned flags);
463
- %ignore Gosu::Font::setImage;
464
- %include "../Gosu/Font.hpp"
465
- %extend Gosu::Font {
466
- Font(Gosu::Window& window, const std::wstring& fontName, unsigned height) {
467
- return new Gosu::Font(window.graphics(), fontName, height);
468
- }
469
- void set_image(wchar_t wc, VALUE source) {
470
- // TODO: Super super super ugly hack that relies on the layout of std::tr1::shared_ptr.
471
- // To be removed once Image creation does not require a Graphics anymore.
472
- Gosu::Graphics& graphics = ***reinterpret_cast<Gosu::Graphics***>($self);
473
- Gosu::Bitmap bitmap;
474
- Gosu::loadBitmap(bitmap, source);
475
- $self->setImage(wc, Gosu::Image(graphics, bitmap, false));
476
- }
477
- }
478
-
479
- // AsyncResult
480
-
481
- //#ifndef WIN32
482
- //%ignore Gosu::asyncNewImage;
483
- //%ignore Gosu::asyncNewImage_Impl;
484
- //%ignore Gosu::AsyncResult::takeValue;
485
- //%include "../Gosu/Async.hpp"
486
- //%extend Gosu::AsyncResult {
487
- // %newobject value;
488
- // Gosu::Image* value() {
489
- // return $self->takeValue().release();
490
- // }
491
- //}
492
- //%template(AsyncImageResult) Gosu::AsyncResult<Gosu::Image>;
493
- //#endif
494
-
495
- %ignore Gosu::ImageData;
496
- %rename("tex_name") texName;
497
- %include "../Gosu/ImageData.hpp"
498
-
499
- // Image
500
- // Allow the user to pass Window& instead of Graphics&.
501
- // Also, provide convenience functions.
502
-
503
- // Typemap to return an array of images (for loadTiles)
504
- %typemap(out) std::vector<Gosu::Image*> {
505
- $result = rb_ary_new2($1.size());
506
- for (unsigned i = 0; i < $1.size(); i++) {
507
- VALUE curImg = SWIG_NewPointerObj(SWIG_as_voidptr((*&$1)[i]), SWIGTYPE_p_Gosu__Image, SWIG_POINTER_OWN);
508
- rb_ary_store($result, i, curImg);
509
- }
510
- }
511
-
512
- %ignore Gosu::Image::Image(Graphics& graphics, const std::wstring& filename, bool tileable = false);
513
- %ignore Gosu::Image::Image(Graphics& graphics, const std::wstring& filename, unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight, bool tileable = false);
514
- %ignore Gosu::Image::Image(Graphics& graphics, const Bitmap& source, bool tileable = false);
515
- %ignore Gosu::Image::Image(Graphics& graphics, const Bitmap& source, unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight, bool tileable = false);
516
- %ignore Gosu::Image::Image(GOSU_UNIQUE_PTR<ImageData> data);
517
- %ignore Gosu::loadTiles;
518
- %include "../Gosu/Image.hpp"
519
- %extend Gosu::Image {
520
- Image(Gosu::Window& window, VALUE source, bool tileable = false) {
521
- Gosu::Bitmap bmp;
522
- Gosu::loadBitmap(bmp, source);
523
- return new Gosu::Image(window.graphics(), bmp, tileable);
524
- }
525
- Image(Gosu::Window& window, VALUE source, bool tileable,
526
- unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight) {
527
- Gosu::Bitmap bmp;
528
- Gosu::loadBitmap(bmp, source);
529
- return new Gosu::Image(window.graphics(), bmp,
530
- srcX, srcY, srcWidth, srcHeight, tileable);
531
- }
532
- #ifndef WIN32
533
- // %newobject asyncNew;
534
- // static Gosu::AsyncResult<Gosu::Image>* asyncNew(Gosu::Window& window, const std::wstring& filename) {
535
- // return new Gosu::AsyncResult<Gosu::Image>(Gosu::asyncNewImage(window, filename));
536
- // }
537
- #endif
538
- void drawAsQuad(double x1, double y1, Color c1,
539
- double x2, double y2, Color c2,
540
- double x3, double y3, Color c3,
541
- double x4, double y4, Color c4,
542
- ZPos z, AlphaMode mode = Gosu::amDefault) {
543
- $self->getData().draw(x1, y1, c1, x2, y2, c2, x3, y3, c3, x4, y4, c4, z, mode);
544
- }
545
- %newobject glTexInfo;
546
- Gosu::GLTexInfo* glTexInfo() const {
547
- const Gosu::GLTexInfo* info = $self->getData().glTexInfo();
548
- if (info)
549
- return new Gosu::GLTexInfo(*info);
550
- else
551
- return 0;
552
- }
553
- %newobject subimage;
554
- Gosu::Image* subimage(int x, int y, int w, int h)
555
- {
556
- std::auto_ptr<Gosu::ImageData> imageData = $self->getData().subimage(x, y, w, h);
557
- return imageData.get() ? new Gosu::Image(imageData) : 0;
558
- }
559
- %newobject fromText4;
560
- static Gosu::Image* fromText4(Gosu::Window& window, const std::wstring& text,
561
- const std::wstring& fontName, unsigned fontHeight)
562
- {
563
- Gosu::Bitmap bmp = Gosu::createText(text, fontName, fontHeight);
564
- return new Gosu::Image(window.graphics(), bmp);
565
- }
566
- %newobject fromText7;
567
- static Gosu::Image* fromText7(Gosu::Window& window, const std::wstring& text,
568
- const std::wstring& fontName, unsigned fontHeight,
569
- int lineSpacing, unsigned width, TextAlign align)
570
- {
571
- Gosu::Bitmap bmp = Gosu::createText(text, fontName, fontHeight, lineSpacing, width, align);
572
- return new Gosu::Image(window.graphics(), bmp);
573
- }
574
- static std::vector<Gosu::Image*> loadTiles(Gosu::Window& window,
575
- VALUE source, int tileWidth, int tileHeight, bool tileable)
576
- {
577
- std::vector<Gosu::Image*> vec;
578
- // TODO: const correctness (<- did I mean exception safety?)
579
- Gosu::Bitmap bmp;
580
- Gosu::loadBitmap(bmp, source);
581
- Gosu::imagesFromTiledBitmap(window.graphics(), bmp,
582
- tileWidth, tileHeight, tileable, vec);
583
- return vec;
584
- }
585
- std::string toBlob() const
586
- {
587
- // TODO: Optimize with direct copy into a Ruby string
588
- Gosu::Bitmap bmp = $self->getData().toBitmap();
589
- return std::string(reinterpret_cast<const char*>(bmp.data()),
590
- reinterpret_cast<const char*>(bmp.data()) + bmp.width() * bmp.height() * 4);
591
- }
592
- unsigned columns() const
593
- {
594
- return $self->width();
595
- }
596
- unsigned rows() const
597
- {
598
- return $self->height();
599
- }
600
- void save(const std::wstring& filename) const
601
- {
602
- Gosu::saveImageFile($self->getData().toBitmap(), filename);
603
- }
604
- void insert(VALUE source, int x, int y)
605
- {
606
- Gosu::Bitmap bmp;
607
- Gosu::loadBitmap(bmp, source);
608
- $self->getData().insert(bmp, x, y);
609
- }
610
- }
611
-
612
- // Inspection:
613
-
614
- %include "../Gosu/Inspection.hpp"
615
-
616
-
617
- // Audio:
618
-
619
- %ignore Gosu::Sample::Sample(Reader reader);
620
- %ignore Gosu::Song::Song(Reader reader);
621
- %rename("playing?") playing;
622
- %rename("paused?") paused;
623
- %rename("volume=") changeVolume;
624
- %rename("pan=") changePan;
625
- %rename("speed=") changeSpeed;
626
- %include "../Gosu/Audio.hpp"
627
-
628
- // Input and Window:
629
-
630
- // Button ID constants
631
- %ignore Gosu::kbRangeBegin;
632
- %ignore Gosu::kbRangeEnd;
633
- %ignore Gosu::msRangeBegin;
634
- %ignore Gosu::msRangeEnd;
635
- %ignore Gosu::gpRangeBegin;
636
- %ignore Gosu::gpRangeEnd;
637
- %ignore Gosu::kbNum;
638
- %ignore Gosu::msNum;
639
- %ignore Gosu::gpNum;
640
- %ignore Gosu::gpNumPerGamepad;
641
- %ignore Gosu::numButtons;
642
- %ignore Gosu::numGamepads;
643
- %ignore Gosu::noButton;
644
- %include "../Gosu/Buttons.hpp"
645
- %init %{
646
- GosusDarkSide::oncePerTick = GosusDarkSide::yieldToOtherRubyThreads;
647
- // While we are at it, to some healthy srand() - otherwise unavailable to Ruby people
648
- std::srand(static_cast<unsigned int>(std::time(0)));
649
- std::rand(); // and flush the first value
650
- %}
651
-
652
- // TextInput
653
- %ignore Gosu::TextInput::feedNSEvent(void*);
654
- %ignore Gosu::TextInput::feedSDLEvent(void*);
655
- %ignore Gosu::TextInput::feedMessage(unsigned long, unsigned long, unsigned long);
656
- %ignore Gosu::TextInput::feedButtonId(unsigned);
657
- %ignore Gosu::TextInput::caretPos() const;
658
- %ignore Gosu::TextInput::selectionStart() const;
659
- %rename("text=") setText;
660
- %rename("caret_pos=") setCaretPos;
661
- %rename("selection_start=") setSelectionStart;
662
- %include "../Gosu/TextInput.hpp"
663
- %extend Gosu::TextInput {
664
- // Fix indices into UTF-8 string
665
- unsigned caret_pos() const {
666
- return RUBY_18_19(Gosu::wstringToUTF8($self->text().substr(0, $self->caretPos())).size(),
667
- $self->caretPos());
668
- }
669
- unsigned selection_start() const {
670
- return RUBY_18_19(Gosu::wstringToUTF8($self->text().substr(0, $self->selectionStart())).size(),
671
- $self->selectionStart());
672
- }
673
- };
674
-
675
- // Window
676
- %rename("caption=") setCaption;
677
- %rename("button_down?") isButtonDown;
678
- %rename("text_input=") setTextInput;
679
- %rename("mouse_x=") setMouseX;
680
- %rename("mouse_y=") setMouseY;
681
- %rename("needs_cursor?") needsCursor;
682
- %rename("needs_redraw?") needsRedraw;
683
- %rename("fullscreen?") fullscreen;
684
- %markfunc Gosu::Window "markWindow";
685
- %include "../Gosu/Window.hpp"
686
-
687
- // TODO: Can I fake this using an @ivar?
688
- %header %{
689
- static void markWindow(void* window) {
690
- #ifndef __MACRUBY__
691
- Gosu::TextInput* ti = static_cast<Gosu::Window*>(window)->input().textInput();
692
- if (VALUE ti_value = SWIG_RubyInstanceFor(ti))
693
- rb_gc_mark(ti_value);
694
- #endif
695
- }
696
- %}
697
-
698
- %extend Gosu::Window {
699
- void drawLine(double x1, double y1, Gosu::Color c1,
700
- double x2, double y2, Gosu::Color c2,
701
- Gosu::ZPos z = 0, Gosu::AlphaMode mode = Gosu::amDefault) {
702
- $self->graphics().drawLine(x1, y1, c1, x2, y2, c2,
703
- z, mode);
704
- }
705
- void drawTriangle(double x1, double y1, Gosu::Color c1,
706
- double x2, double y2, Gosu::Color c2,
707
- double x3, double y3, Gosu::Color c3,
708
- Gosu::ZPos z = 0, Gosu::AlphaMode mode = Gosu::amDefault) {
709
- $self->graphics().drawTriangle(x1, y1, c1, x2, y2, c2, x3, y3, c3,
710
- z, mode);
711
- }
712
- void drawQuad(double x1, double y1, Gosu::Color c1,
713
- double x2, double y2, Gosu::Color c2,
714
- double x3, double y3, Gosu::Color c3,
715
- double x4, double y4, Gosu::Color c4,
716
- Gosu::ZPos z = 0, Gosu::AlphaMode mode = Gosu::amDefault) {
717
- $self->graphics().drawQuad(x1, y1, c1, x2, y2, c2,
718
- x3, y3, c3, x4, y4, c4,
719
- z, mode);
720
- }
721
- void flush() {
722
- return $self->graphics().flush();
723
- }
724
- bool isButtonDown(Gosu::Button btn) const {
725
- return $self->input().down(btn);
726
- }
727
- static Gosu::Button charToButtonId(wchar_t ch) {
728
- return Gosu::Input::charToId(ch);
729
- }
730
- static wchar_t buttonIdToChar(Gosu::Button btn) {
731
- return Gosu::Input::idToChar(btn);
732
- }
733
-
734
- TextInput* textInput() const {
735
- return $self->input().textInput();
736
- }
737
-
738
- void setTextInput(TextInput* ti) {
739
- $self->input().setTextInput(ti);
740
- }
741
-
742
- double mouseX() const {
743
- return $self->input().mouseX();
744
- }
745
- double mouseY() const {
746
- return $self->input().mouseY();
747
- }
748
- void setMousePosition(double x, double y) {
749
- $self->input().setMousePosition(x, y);
750
- }
751
- void setMouseX(double x) {
752
- $self->input().setMousePosition(x, $self->input().mouseY());
753
- }
754
- void setMouseY(double y) {
755
- $self->input().setMousePosition($self->input().mouseX(), y);
756
- }
757
-
758
- int width() const {
759
- return $self->graphics().width();
760
- }
761
- int height() const {
762
- return $self->graphics().height();
763
- }
764
- bool fullscreen() const {
765
- return $self->graphics().fullscreen();
766
- }
767
-
768
- void unsafe_gl() {
769
- $self->graphics().beginGL();
770
- rb_yield(Qnil);
771
- $self->graphics().endGL();
772
- }
773
- void unsafe_gl(Gosu::ZPos z) {
774
- $self->graphics().scheduleGL(std::tr1::bind(callRubyBlock, rb_block_proc()), z);
775
- }
776
- void clipTo(double x, double y, double width, double height) {
777
- $self->graphics().beginClipping(x, y, width, height);
778
- rb_yield(Qnil);
779
- $self->graphics().endClipping();
780
- }
781
- %newobject record;
782
- Gosu::Image* record(int width, int height) {
783
- $self->graphics().beginRecording();
784
- rb_yield(Qnil);
785
- return new Gosu::Image($self->graphics().endRecording(width, height));
786
- }
787
- void transform(double m0, double m1, double m2, double m3, double m4, double m5, double m6, double m7,
788
- double m8, double m9, double m10, double m11, double m12, double m13, double m14, double m15) {
789
- Gosu::Transform transform = {
790
- m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15
791
- };
792
- $self->graphics().pushTransform(transform);
793
- rb_yield(Qnil);
794
- $self->graphics().popTransform();
795
- }
796
- void rotate(double angle, double aroundX = 0, double aroundY = 0) {
797
- $self->graphics().pushTransform(Gosu::rotate(angle, aroundX, aroundY));
798
- rb_yield(Qnil);
799
- $self->graphics().popTransform();
800
- }
801
- void scale(double factor) {
802
- $self->graphics().pushTransform(Gosu::scale(factor));
803
- rb_yield(Qnil);
804
- $self->graphics().popTransform();
805
- }
806
- void scale(double factorX, double factorY) {
807
- $self->graphics().pushTransform(Gosu::scale(factorX, factorY));
808
- rb_yield(Qnil);
809
- $self->graphics().popTransform();
810
- }
811
- void scale(double factorX, double factorY, double aroundX, double aroundY) {
812
- $self->graphics().pushTransform(Gosu::scale(factorX, factorY, aroundX, aroundY));
813
- rb_yield(Qnil);
814
- $self->graphics().popTransform();
815
- }
816
- void translate(double x, double y) {
817
- $self->graphics().pushTransform(Gosu::translate(x, y));
818
- rb_yield(Qnil);
819
- $self->graphics().popTransform();
820
- }
821
- };