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,458 +0,0 @@
1
- // While (re)writing this file, I have been looking at many other libraries since all the
2
- // "official" documentation was horrible, at least those parts that I was able to find.
3
- // Kudos to the Pyglet folks (http://www.pyglet.org/) who wrote code that was much easier to
4
- // understand than that! --jlnr
5
-
6
- #include <Gosu/Window.hpp>
7
- #include <Gosu/Audio.hpp>
8
- #include <Gosu/Input.hpp>
9
- #include <Gosu/Graphics.hpp>
10
- #include <Gosu/Timing.hpp>
11
- #include <Gosu/TR1.hpp>
12
- #include <Gosu/Utility.hpp>
13
- #include <cstdio>
14
- #include <algorithm>
15
- #include <memory>
16
- #include <sstream>
17
- #include <stdexcept>
18
- #include <vector>
19
-
20
- #include <GL/glx.h>
21
- #include <X11/Xlib.h>
22
- #include <X11/Xutil.h>
23
- #include "X11vroot.h"
24
-
25
- #include <X11/extensions/Xinerama.h>
26
-
27
- using namespace std::tr1::placeholders;
28
-
29
- namespace Gosu
30
- {
31
- namespace FPS
32
- {
33
- void registerFrame();
34
- }
35
-
36
- void screenMetrics(int *x_org, int *y_org, int *width, int *height){
37
- // Open the X Display; passing NULL returns the default display.
38
- Display* display = XOpenDisplay(NULL);
39
-
40
- // Raw screen information from the X server.
41
- Screen* screen = XScreenOfDisplay(display, DefaultScreen(display));
42
-
43
- // Xinerama screen information; if available, this info is more accurate.
44
- // This is especially important for multi-monitor configurations.
45
- int screen_count = 0;
46
- XineramaScreenInfo *screen_info = XineramaQueryScreens(display, &screen_count);
47
-
48
- // If screen_info is not NULL, we got preferred measurements from Xinerama,
49
- // otherwise we use the measurements from the X server.
50
- if(screen_info != NULL){
51
- // screen_info is an array of length screen_count
52
- // Index zero should hold the "default" or "primary"
53
- // screen as configured by the user.
54
- *x_org = screen_info[0].x_org;
55
- *y_org = screen_info[0].y_org;
56
- *width = screen_info[0].width;
57
- *height = screen_info[0].height;
58
- }else{
59
- // screen is a reference to the default X Server screen
60
- // Since we know Xinerama isn't running, this screen
61
- // should correspond to exactly one physical display.
62
- *x_org = 0;
63
- *y_org = 0;
64
- *width = screen->width;
65
- *height = screen->height;
66
- }
67
-
68
- // Release the Xinerama screen info, if we have it.
69
- if(screen_info != NULL){
70
- XFree(screen_info);
71
- }
72
-
73
- // Release the connection to the X Display
74
- XCloseDisplay(display);
75
-
76
- return;
77
- }
78
-
79
- unsigned screenWidth()
80
- {
81
- int x_org, y_org, width, height;
82
- screenMetrics(&x_org, &y_org, &width, &height);
83
- return width;
84
- }
85
-
86
- unsigned screenHeight()
87
- {
88
- int x_org, y_org, width, height;
89
- screenMetrics(&x_org, &y_org, &width, &height);
90
- return height;
91
- }
92
- }
93
-
94
- struct Gosu::Window::Impl
95
- {
96
- GOSU_UNIQUE_PTR<Graphics> graphics;
97
- GOSU_UNIQUE_PTR<Input> input;
98
-
99
- ::Display* display;
100
-
101
- bool mapped, showing, active;
102
-
103
- Cursor emptyCursor;
104
- bool showingCursor;
105
-
106
- ::GLXContext context;
107
- ::Window window;
108
- ::XVisualInfo* visual;
109
-
110
- // Last set title
111
- std::wstring title;
112
- // Last known position
113
- int x, y;
114
- // Last known size
115
- int width, height;
116
-
117
- double updateInterval;
118
- bool fullscreen;
119
-
120
- Impl(unsigned width, unsigned height, unsigned fullscreen, double updateInterval)
121
- : mapped(false), showing(false), active(true),
122
- x(0), y(0), width(width), height(height),
123
- updateInterval(updateInterval), fullscreen(fullscreen)
124
- {
125
-
126
- }
127
-
128
- void executeAndWait(std::tr1::function<void(Display*, ::Window)> function, int forMessage)
129
- {
130
- XSelectInput(display, window, StructureNotifyMask);
131
- function(display, window);
132
- while (true)
133
- {
134
- ::XEvent event;
135
- XNextEvent(display, &event);
136
- if (event.type == forMessage)
137
- break;
138
- }
139
- XSelectInput(display, window, 0x1ffffff & ~PointerMotionHintMask & ~ResizeRedirectMask);
140
- }
141
-
142
- void doTick(Window* window)
143
- {
144
- for (int i = XPending(display); i > 0; --i)
145
- {
146
- XEvent event;
147
- XNextEvent(display, &event);
148
-
149
- // Override redirect fix (thanks go to the Pyglet folks again):
150
- if (event.type == ButtonPress && fullscreen && !active)
151
- XSetInputFocus(display, this->window, RevertToParent, CurrentTime);
152
-
153
- if (!window->input().feedXEvent(event))
154
- {
155
- if (event.type == ConfigureNotify)
156
- {
157
- // Only boring stuff to do? Let's do something random:
158
- glXMakeCurrent(display, this->window, context);
159
- }
160
- else if (event.type == ClientMessage)
161
- {
162
- if (static_cast<unsigned>(event.xclient.data.l[0]) ==
163
- XInternAtom(display, "WM_DELETE_WINDOW", false))
164
- window->close();
165
- }
166
- else if (event.type == FocusIn)
167
- active = true;
168
- else if (event.type == FocusOut)
169
- active = false;
170
- }
171
- if (event.type == Expose && event.xexpose.count == 0 &&
172
- window->graphics().begin(Color::BLACK)) {
173
- FPS::registerFrame();
174
- window->draw();
175
- window->graphics().end();
176
- glXSwapBuffers(display, this->window);
177
- }
178
- }
179
-
180
- if (showingCursor && !window->needsCursor())
181
- {
182
- XDefineCursor(display, this->window, emptyCursor);
183
- showingCursor = false;
184
- }
185
- else if (!showingCursor && window->needsCursor())
186
- {
187
- XUndefineCursor(display, this->window);
188
- showingCursor = true;
189
- }
190
-
191
- Song::update();
192
- window->input().update();
193
- window->update();
194
-
195
- if (window->needsRedraw() && window->graphics().begin(Color::BLACK))
196
- {
197
- FPS::registerFrame();
198
- window->draw();
199
- window->graphics().end();
200
- glXSwapBuffers(display, this->window);
201
- }
202
- }
203
- };
204
-
205
- Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen,
206
- double updateInterval)
207
- : pimpl(new Impl(width, height, fullscreen, updateInterval))
208
- {
209
- pimpl->display = XOpenDisplay(NULL);
210
- if (!pimpl->display)
211
- throw std::runtime_error("Cannot find display");
212
-
213
- ::Window root = DefaultRootWindow(pimpl->display);
214
-
215
- // Setup GLX visual
216
- static int glxAttributes[] =
217
- {
218
- GLX_RGBA,
219
- GLX_DOUBLEBUFFER,
220
- GLX_RED_SIZE, 1,
221
- GLX_GREEN_SIZE, 1,
222
- GLX_BLUE_SIZE, 1,
223
- GLX_DEPTH_SIZE, 1,
224
- None
225
- };
226
- pimpl->visual = glXChooseVisual(pimpl->display, DefaultScreen(pimpl->display), glxAttributes);
227
-
228
- // Create GLX context
229
- pimpl->context = glXCreateContext(pimpl->display, pimpl->visual, 0, GL_TRUE);
230
-
231
- // Set up window attributes (& mask)
232
- XSetWindowAttributes windowAttributes;
233
- windowAttributes.colormap = XCreateColormap(pimpl->display, root, pimpl->visual->visual, AllocNone);
234
- windowAttributes.bit_gravity = NorthWestGravity;
235
- windowAttributes.background_pixel = 0;
236
- unsigned mask = CWColormap | CWBitGravity | CWBackPixel;
237
-
238
- // Create window
239
- pimpl->window = XCreateWindow(pimpl->display, root, 0, 0, width, height, 0,
240
- pimpl->visual->depth, InputOutput, pimpl->visual->visual,
241
- mask, &windowAttributes);
242
-
243
- // Request a close button for the window
244
- Atom atoms[] = { XInternAtom(pimpl->display, "WM_DELETE_WINDOW", false) };
245
- XSetWMProtocols(pimpl->display, pimpl->window, atoms, 1);
246
-
247
-
248
- // Get reference to X Screen
249
- Screen* screen = XScreenOfDisplay(pimpl->display,
250
- DefaultScreen(pimpl->display));
251
-
252
- if (fullscreen){
253
- // If we're going fullscreen, replace the window
254
- // position and size with our screen metrics.
255
- int screen_x_org, screen_y_org, screen_width, screen_height;
256
- Gosu::screenMetrics(&screen_x_org, &screen_y_org, &screen_width, &screen_height);
257
- pimpl->width = screen_width;
258
- pimpl->height = screen_height;
259
- pimpl->x = screen_x_org;
260
- pimpl->y = screen_y_org;
261
-
262
- // Override Redirect (JohnColburn says: I don't actually know what this is for.)
263
- XSetWindowAttributes windowAttributes;
264
- windowAttributes.override_redirect = true;
265
- unsigned mask = CWOverrideRedirect;
266
- XChangeWindowAttributes(pimpl->display, pimpl->window, mask, &windowAttributes);
267
- }
268
-
269
- // Move and resize the window to its current position and size.
270
- XMoveResizeWindow(pimpl->display, pimpl->window, pimpl->x, pimpl->y, pimpl->width, pimpl->height);
271
-
272
- // Set window to be non-resizable
273
- XSizeHints *sizeHints = XAllocSizeHints();
274
- sizeHints->flags = PMinSize | PMaxSize;
275
- sizeHints->min_width = sizeHints->max_width = pimpl->width;
276
- sizeHints->min_height = sizeHints->max_height = pimpl->height;
277
- XSetWMNormalHints(pimpl->display, pimpl->window, sizeHints);
278
- XFree(sizeHints);
279
-
280
- // TODO: Window style (_MOTIF_WM_HINTS)?
281
-
282
- XColor black, dummy;
283
- XAllocNamedColor(pimpl->display, screen->cmap, "black", &black, &dummy);
284
- char emptyData[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
285
- Pixmap emptyBitmap =
286
- XCreateBitmapFromData(pimpl->display, pimpl->window, emptyData, 8, 8);
287
- pimpl->emptyCursor = XCreatePixmapCursor(pimpl->display, emptyBitmap,
288
- emptyBitmap, &black, &black, 0, 0);
289
- pimpl->showingCursor = true; // Empty cursor not yet installed
290
-
291
- // Must be current already so that Graphics' constructor can set up things
292
- glXMakeCurrent(pimpl->display, pimpl->window, pimpl->context);
293
-
294
- // Now set up major Gosu components
295
- pimpl->graphics.reset(new Graphics(pimpl->width, pimpl->height, fullscreen));
296
- pimpl->input.reset(new Input(pimpl->display, pimpl->window));
297
- input().onButtonDown = std::tr1::bind(&Window::buttonDown, this, _1);
298
- input().onButtonUp = std::tr1::bind(&Window::buttonUp, this, _1);
299
-
300
- // Fix coordinates for fullscreen screen-scaling
301
- if (fullscreen)
302
- {
303
- graphics().setResolution(width, height);
304
- input().setMouseFactors(1.0 * width / pimpl->width,
305
- 1.0 * height / pimpl->height);
306
- }
307
- }
308
-
309
- Gosu::Window::~Window()
310
- {
311
- XFreeCursor(pimpl->display, pimpl->emptyCursor);
312
- XDestroyWindow(pimpl->display, pimpl->window);
313
- XSync(pimpl->display, false);
314
- }
315
-
316
- std::wstring Gosu::Window::caption() const
317
- {
318
- return pimpl->title;
319
- }
320
-
321
- double Gosu::Window::updateInterval() const
322
- {
323
- return pimpl->updateInterval;
324
- }
325
-
326
- void Gosu::Window::setCaption(const std::wstring& caption)
327
- {
328
- // TODO: Update to _NET_WM_NAME to support Unicode
329
-
330
- pimpl->title = caption;
331
-
332
- std::string tmpString(pimpl->title.begin(), pimpl->title.end());
333
- std::vector<char> title(pimpl->title.size() + 1);
334
- std::copy(tmpString.begin(), tmpString.end(), title.begin());
335
- title.back() = 0;
336
-
337
- XTextProperty titleprop;
338
- char* titlePtr = &title[0];
339
- XStringListToTextProperty(&titlePtr, 1, &titleprop);
340
-
341
- XSetWMName(pimpl->display, pimpl->window, &titleprop);
342
- XFree(titleprop.value);
343
- XSync(pimpl->display, false);
344
- }
345
-
346
- namespace GosusDarkSide
347
- {
348
- // TODO: Find a way for this to fit into Gosu's design.
349
- // This can point to a function that wants to be called every
350
- // frame, e.g. rb_thread_schedule.
351
- typedef void (*HookOfHorror)();
352
- HookOfHorror oncePerTick = 0;
353
- }
354
-
355
- // TODO: Some exception safety
356
-
357
- void Gosu::Window::show()
358
- {
359
- // Map window
360
- pimpl->executeAndWait(XMapRaised, MapNotify);
361
- pimpl->mapped = true;
362
-
363
- // Make glx current
364
- glXMakeCurrent(pimpl->display, pimpl->window, pimpl->context);
365
-
366
- if (pimpl->fullscreen){
367
- XSetInputFocus(pimpl->display, pimpl->window, RevertToParent, CurrentTime);
368
- XGrabPointer(pimpl->display, pimpl->window, true, 0, GrabModeAsync, GrabModeAsync, pimpl->window, None, CurrentTime);
369
- }
370
-
371
- setCaption(pimpl->title);
372
-
373
- unsigned startTime, endTime;
374
-
375
- pimpl->showing = true;
376
- while (pimpl->showing)
377
- {
378
- startTime = milliseconds();
379
- pimpl->doTick(this);
380
- if (GosusDarkSide::oncePerTick) GosusDarkSide::oncePerTick();
381
- endTime = milliseconds();
382
-
383
- if (startTime <= endTime && (endTime - startTime) < pimpl->updateInterval)
384
- sleep(pimpl->updateInterval - (endTime - startTime));
385
- }
386
-
387
- glXMakeCurrent(pimpl->display, 0, 0);
388
- pimpl->executeAndWait(XUnmapWindow, UnmapNotify);
389
- pimpl->mapped = false;
390
- }
391
-
392
- void Gosu::Window::close()
393
- {
394
- pimpl->showing = false;
395
- }
396
-
397
- const Gosu::Graphics& Gosu::Window::graphics() const
398
- {
399
- return *pimpl->graphics;
400
- }
401
-
402
- Gosu::Graphics& Gosu::Window::graphics()
403
- {
404
- return *pimpl->graphics;
405
- }
406
-
407
- const Gosu::Input& Gosu::Window::input() const
408
- {
409
- return *pimpl->input;
410
- }
411
-
412
- Gosu::Input& Gosu::Window::input()
413
- {
414
- return *pimpl->input;
415
- }
416
-
417
- namespace
418
- {
419
- void makeCurrentContext(Display* dpy, GLXDrawable drawable, GLXContext context) {
420
- if (!glXMakeCurrent(dpy, drawable, context))
421
- std::printf("glXMakeCurrent failed\n");
422
- }
423
-
424
- void releaseContext(Display* dpy, GLXContext context) {
425
- glXDestroyContext(dpy, context);
426
- }
427
- }
428
-
429
- Gosu::Window::SharedContext Gosu::Window::createSharedContext() {
430
- const char* displayName = DisplayString( pimpl->display );
431
- Display* dpy2 = XOpenDisplay( displayName );
432
- if (!dpy2)
433
- throw std::runtime_error("Could not duplicate X display");
434
-
435
- GLXContext ctx = glXCreateContext(dpy2, pimpl->visual, pimpl->context, True);
436
- if (!ctx)
437
- throw std::runtime_error("Could not create shared GLX context");
438
-
439
- return SharedContext(
440
- new std::tr1::function<void()>(std::tr1::bind(makeCurrentContext, dpy2, pimpl->window, ctx)),
441
- std::tr1::bind(releaseContext, dpy2, ctx));
442
- }
443
-
444
- // Deprecated.
445
-
446
- class Gosu::Audio {};
447
- namespace { Gosu::Audio dummyAudio; }
448
-
449
- const Gosu::Audio& Gosu::Window::audio() const
450
- {
451
- return dummyAudio;
452
- }
453
-
454
- Gosu::Audio& Gosu::Window::audio()
455
- {
456
- return dummyAudio;
457
- }
458
-