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,534 +0,0 @@
1
- #ifndef NOMINMAX
2
- #define NOMINMAX
3
- #endif // RAGE >_<
4
-
5
- #include <Gosu/Window.hpp>
6
- #include <Gosu/WinUtility.hpp>
7
- #include <Gosu/Timing.hpp>
8
- #include <Gosu/Audio.hpp>
9
- #include <Gosu/Graphics.hpp>
10
- #include <Gosu/Input.hpp>
11
- #include <Gosu/TextInput.hpp>
12
- #include <Gosu/TR1.hpp>
13
- #include <GosuImpl/Graphics/Common.hpp>
14
- #include <cassert>
15
- #include <memory>
16
- #include <stdexcept>
17
- #include <vector>
18
-
19
- using namespace std::tr1::placeholders;
20
-
21
- // TODO: Put fullscreen logic in different file, track fullscreen state and
22
- // enable dynamic toggling between fullscreen and window.
23
-
24
- namespace Gosu
25
- {
26
- namespace FPS
27
- {
28
- void registerFrame();
29
- }
30
-
31
- unsigned screenWidth()
32
- {
33
- return GetSystemMetrics(SM_CXSCREEN);
34
- }
35
-
36
- unsigned screenHeight()
37
- {
38
- return GetSystemMetrics(SM_CYSCREEN);
39
- }
40
-
41
- namespace
42
- {
43
- // Mode guessing experimentally adapted from GLFW library.
44
- // http://glfw.sourceforge.net/
45
-
46
- int findClosestVideoMode(int *w, int *h, int *bpp, int *refresh)
47
- {
48
- int mode, bestmode, match, bestmatch, rr, bestrr, success;
49
- DEVMODE dm;
50
-
51
- // Find best match
52
- bestmatch = 0x7fffffff;
53
- bestrr = 0x7fffffff;
54
- mode = bestmode = 0;
55
- do
56
- {
57
- dm.dmSize = sizeof(DEVMODE);
58
- success = EnumDisplaySettings(NULL, mode, &dm);
59
- if( success )
60
- {
61
- match = dm.dmBitsPerPel - *bpp;
62
- if( match < 0 ) match = -match;
63
- match = (match << 25) |
64
- ((dm.dmPelsWidth - *w) * (dm.dmPelsWidth - *w) +
65
- (dm.dmPelsHeight - *h) * (dm.dmPelsHeight - *h));
66
- if( match < bestmatch )
67
- {
68
- bestmatch = match;
69
- bestmode = mode;
70
- bestrr = (dm.dmDisplayFrequency - *refresh) *
71
- (dm.dmDisplayFrequency - *refresh);
72
- }
73
- else if( match == bestmatch && *refresh > 0 )
74
- {
75
- rr = (dm.dmDisplayFrequency - *refresh) *
76
- (dm.dmDisplayFrequency - *refresh);
77
- if( rr < bestrr )
78
- {
79
- bestmatch = match;
80
- bestmode = mode;
81
- bestrr = rr;
82
- }
83
- }
84
- }
85
- ++mode;
86
- }
87
- while (success);
88
-
89
- // Get the parameters for the best matching display mode
90
- dm.dmSize = sizeof(DEVMODE);
91
- EnumDisplaySettings( NULL, bestmode, &dm );
92
-
93
- *w = dm.dmPelsWidth;
94
- *h = dm.dmPelsHeight;
95
- *bpp = dm.dmBitsPerPel;
96
- *refresh = dm.dmDisplayFrequency;
97
-
98
- return bestmode;
99
- }
100
-
101
- void setVideoMode(int mode)
102
- {
103
- // Get the parameters for the best matching display mode
104
- DEVMODE dm;
105
- dm.dmSize = sizeof(DEVMODE);
106
- EnumDisplaySettings(NULL, mode, &dm);
107
-
108
- // Set which fields we want to specify
109
- dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
110
-
111
- // Change display setting
112
- dm.dmSize = sizeof(DEVMODE);
113
- if (ChangeDisplaySettings(&dm, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
114
- throw std::runtime_error("Could not set fullscreen mode");
115
- }
116
-
117
- void setupVSync()
118
- {
119
- char* extensions = (char*)glGetString(GL_EXTENSIONS);
120
- // The Intel BootCamp drivers will actually have a proc address for wglSwapInterval
121
- // that doesn't do much, so check the string instead of just getting the address.
122
- if (!strstr(extensions, "WGL_EXT_swap_control"))
123
- return;
124
- typedef void (APIENTRY *PFNWGLEXTSWAPCONTROLPROC) (int);
125
- PFNWGLEXTSWAPCONTROLPROC wglSwapIntervalEXT =
126
- (PFNWGLEXTSWAPCONTROLPROC) wglGetProcAddress("wglSwapIntervalEXT");
127
- if (!wglSwapIntervalEXT)
128
- return;
129
- wglSwapIntervalEXT(1);
130
- }
131
-
132
- LRESULT CALLBACK windowProc(HWND wnd, UINT message, WPARAM wparam,
133
- LPARAM lparam)
134
- {
135
- LONG_PTR lptr = GetWindowLongPtr(wnd, GWLP_USERDATA);
136
-
137
- if (lptr)
138
- {
139
- Window* obj = reinterpret_cast<Window*>(lptr);
140
- return obj->handleMessage(message, wparam, lparam);
141
- }
142
- else
143
- return DefWindowProc(wnd, message, wparam, lparam);
144
- }
145
-
146
- LPCTSTR windowClass()
147
- {
148
- static LPCTSTR name = 0;
149
- if (name)
150
- return name;
151
-
152
- WNDCLASSEX wc;
153
- ZeroMemory(&wc, sizeof wc);
154
- wc.cbSize = sizeof wc;
155
- wc.lpszClassName = L"Gosu::Window";
156
- wc.style = CS_OWNDC;
157
- wc.lpfnWndProc = windowProc;
158
- wc.cbClsExtra = 0;
159
- wc.cbWndExtra = 0;
160
- wc.hInstance = Win::instance();
161
- wc.hIcon = ExtractIcon(wc.hInstance, Win::appFilename().c_str(), 0);
162
- wc.hCursor = 0;
163
- wc.hbrBackground = CreateSolidBrush(0);
164
- wc.lpszMenuName = 0;
165
- wc.hIconSm = (HICON)CopyImage(wc.hIcon, IMAGE_ICON,
166
- GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
167
- LR_COPYFROMRESOURCE | LR_COPYRETURNORG);
168
-
169
- name = reinterpret_cast<LPCTSTR>(RegisterClassEx(&wc));
170
- Win::check(name, "registering a window class");
171
- return name;
172
- }
173
- }
174
- }
175
-
176
- struct Gosu::Window::Impl
177
- {
178
- HWND handle;
179
- HDC hdc;
180
- GOSU_UNIQUE_PTR<Graphics> graphics;
181
- GOSU_UNIQUE_PTR<Input> input;
182
- double updateInterval;
183
- bool iconified;
184
-
185
- unsigned originalWidth, originalHeight;
186
-
187
- Impl()
188
- : handle(0), hdc(0), iconified(false)
189
- {
190
- }
191
-
192
- ~Impl()
193
- {
194
- if (hdc)
195
- ReleaseDC(handle, hdc);
196
- if (handle)
197
- DestroyWindow(handle);
198
- }
199
- };
200
-
201
- Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen,
202
- double updateInterval)
203
- : pimpl(new Impl)
204
- {
205
- pimpl->originalWidth = width;
206
- pimpl->originalHeight = height;
207
-
208
- DWORD style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
209
- DWORD styleEx = WS_EX_APPWINDOW;
210
- if (fullscreen)
211
- {
212
- style |= WS_POPUP;
213
- #ifdef NDEBUG
214
- styleEx |= WS_EX_TOPMOST;
215
- #endif
216
- }
217
- else
218
- {
219
- style |= WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
220
- styleEx |= WS_EX_WINDOWEDGE;
221
- }
222
-
223
- pimpl->handle = CreateWindowEx(styleEx, windowClass(), 0, style,
224
- CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0,
225
- Win::instance(), 0);
226
- Win::check(pimpl->handle);
227
-
228
- pimpl->hdc = GetDC(handle());
229
- Win::check(pimpl->hdc);
230
-
231
- PIXELFORMATDESCRIPTOR pfd;
232
- ZeroMemory(&pfd, sizeof pfd);
233
- pfd.nSize = sizeof pfd;
234
- pfd.nVersion = 1;
235
- pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
236
- pfd.iLayerType = PFD_MAIN_PLANE;
237
- pfd.iPixelType = PFD_TYPE_RGBA;
238
- pfd.cColorBits = 32;
239
- int pf = ChoosePixelFormat(pimpl->hdc, &pfd);
240
- Win::check(pf);
241
- Win::check(SetPixelFormat(pimpl->hdc, pf, &pfd));
242
-
243
- HGLRC hrc = Win::check(wglCreateContext(pimpl->hdc), "creating rendering context");
244
- Win::check(wglMakeCurrent(pimpl->hdc, hrc), "selecting the rendering context");
245
-
246
- setupVSync();
247
-
248
- SetLastError(0);
249
- SetWindowLongPtr(handle(), GWLP_USERDATA,
250
- reinterpret_cast<LONG_PTR>(this));
251
- if (GetLastError() != 0)
252
- Win::throwLastError("setting the window's GWLP_USERDATA pointer");
253
-
254
- // Windowed: Create window large enough to display stuff
255
- // This is a pretty brutal heuristic I guess.
256
-
257
- if (!fullscreen)
258
- {
259
- double factor = std::min(0.9 * screenWidth() / width,
260
- 0.8 * screenHeight() / height);
261
-
262
- if (factor < 1)
263
- width *= factor, height *= factor;
264
- }
265
-
266
- // Determine the size the window needs to have including UI chrome.
267
- RECT rc = { 0, 0, width, height };
268
- AdjustWindowRectEx(&rc, style, FALSE, styleEx);
269
- unsigned windowW = rc.right - rc.left;
270
- unsigned windowH = rc.bottom - rc.top;
271
-
272
- int windowX = 0;
273
- int windowY = 0;
274
-
275
- if (!fullscreen)
276
- {
277
- // Center the window.
278
- HWND desktopWindow = GetDesktopWindow();
279
- RECT desktopRect;
280
- GetClientRect(desktopWindow, &desktopRect);
281
- int desktopW = desktopRect.right - desktopRect.left;
282
- int desktopH = desktopRect.bottom - desktopRect.top;
283
- windowX = (desktopW - windowW) / 2;
284
- windowY = (desktopH - windowH) / 2;
285
- }
286
-
287
- MoveWindow(handle(), windowX, windowY, windowW, windowH, false);
288
-
289
- pimpl->graphics.reset(new Gosu::Graphics(width, height, fullscreen));
290
- graphics().setResolution(pimpl->originalWidth, pimpl->originalHeight);
291
- pimpl->input.reset(new Gosu::Input(handle()));
292
- input().setMouseFactors(1.0 * pimpl->originalWidth / width, 1.0 * pimpl->originalHeight / height);
293
- input().onButtonDown = std::tr1::bind(&Window::buttonDown, this, _1);
294
- input().onButtonUp = std::tr1::bind(&Window::buttonUp, this, _1);
295
-
296
- pimpl->updateInterval = updateInterval;
297
- }
298
-
299
- Gosu::Window::~Window()
300
- {
301
- wglMakeCurrent(0, 0);
302
- }
303
-
304
- std::wstring Gosu::Window::caption() const
305
- {
306
- int bufLen = GetWindowTextLength(handle()) + 1;
307
-
308
- if (bufLen < 2)
309
- return L"";
310
-
311
- std::vector<TCHAR> buf(bufLen);
312
- GetWindowText(handle(), &buf.front(), bufLen);
313
- return &buf.front();
314
- }
315
-
316
- void Gosu::Window::setCaption(const std::wstring& value)
317
- {
318
- SetWindowText(handle(), value.c_str());
319
- }
320
-
321
- double Gosu::Window::updateInterval() const
322
- {
323
- return pimpl->updateInterval;
324
- }
325
-
326
- namespace GosusDarkSide
327
- {
328
- // TODO: Find a way for this to fit into Gosu's design.
329
- // This can point to a function that wants to be called every
330
- // frame, e.g. rb_thread_schedule.
331
- typedef void (*HookOfHorror)();
332
- HookOfHorror oncePerTick = 0;
333
- }
334
-
335
- void Gosu::Window::show()
336
- {
337
- int w = pimpl->originalWidth, h = pimpl->originalHeight, bpp = 32, rr = 60;
338
- if (graphics().fullscreen())
339
- setVideoMode(findClosestVideoMode(&w, &h, &bpp, &rr));
340
- ShowWindow(handle(), SW_SHOW);
341
- UpdateWindow(handle());
342
- try
343
- {
344
- Win::processMessages();
345
-
346
- unsigned lastTick = 0;
347
-
348
- for (;;)
349
- {
350
- Win::processMessages();
351
-
352
- if (!::IsWindowVisible(handle()))
353
- {
354
- // TODO: Find out what the Sleep here is doing...
355
- Sleep(50);
356
- return;
357
- }
358
-
359
- unsigned ms = milliseconds();
360
-
361
- if (ms < lastTick || ms - lastTick >= static_cast<unsigned>(pimpl->updateInterval))
362
- {
363
- lastTick = ms;
364
- Song::update();
365
- input().update();
366
- // TODO: Bad heuristic -- this causes flickering cursor on right and bottom border of the
367
- // window.
368
- if (input().mouseX() >= 0 && input().mouseY() >= 0)
369
- SendMessage(handle(), WM_SETCURSOR, reinterpret_cast<WPARAM>(handle()), HTCLIENT);
370
- update();
371
- if (needsRedraw())
372
- {
373
- ::InvalidateRect(handle(), 0, FALSE);
374
- FPS::registerFrame();
375
- }
376
- // There probably should be a proper "oncePerTick" handler
377
- // system in the future. Right now, this is necessary to give
378
- // timeslices to Ruby's green threads in Ruby/Gosu.
379
- if (GosusDarkSide::oncePerTick) GosusDarkSide::oncePerTick();
380
- }
381
- else if (pimpl->updateInterval - (ms - lastTick) > 5)
382
- // More than 5 ms left until next update: Sleep to reduce
383
- // processur usage, Sleep() is accurate enough for that.
384
- Sleep(5);
385
- }
386
- }
387
- catch (...)
388
- {
389
- close();
390
- throw;
391
- }
392
- }
393
-
394
- void Gosu::Window::close()
395
- {
396
- ShowWindow(handle(), SW_HIDE);
397
- if (graphics().fullscreen())
398
- ChangeDisplaySettings(NULL, CDS_FULLSCREEN);
399
- }
400
-
401
- const Gosu::Graphics& Gosu::Window::graphics() const
402
- {
403
- return *pimpl->graphics;
404
- }
405
-
406
- Gosu::Graphics& Gosu::Window::graphics()
407
- {
408
- return *pimpl->graphics;
409
- }
410
-
411
- const Gosu::Input& Gosu::Window::input() const
412
- {
413
- return *pimpl->input;
414
- }
415
-
416
- Gosu::Input& Gosu::Window::input()
417
- {
418
- return *pimpl->input;
419
- }
420
-
421
- HWND Gosu::Window::handle() const
422
- {
423
- return pimpl->handle;
424
- }
425
-
426
- LRESULT Gosu::Window::handleMessage(UINT message, WPARAM wparam, LPARAM lparam)
427
- {
428
- if (message == WM_SETCURSOR)
429
- {
430
- try
431
- {
432
- if (LOWORD(lparam) != HTCLIENT || GetForegroundWindow() != handle() || needsCursor())
433
- {
434
- static const HCURSOR arrowCursor = LoadCursor(0, IDC_ARROW);
435
- SetCursor(arrowCursor);
436
- }
437
- else
438
- SetCursor(NULL);
439
- return TRUE;
440
- }
441
- catch (std::exception& e)
442
- {
443
- // TODO - mark needsCursor() as noexcept and remove this try/catch block altogether
444
- }
445
- }
446
-
447
- if (message == WM_SETFOCUS && graphics().fullscreen() && IsWindowVisible(pimpl->handle))
448
- {
449
- if (pimpl->iconified)
450
- {
451
- OpenIcon(pimpl->handle);
452
- int w = graphics().width(), h = graphics().height(), bpp = 32, rr = 60;
453
- setVideoMode(findClosestVideoMode(&w, &h, &bpp, &rr));
454
- pimpl->iconified = false;
455
- }
456
- return 0;
457
- }
458
-
459
- if (message == WM_KILLFOCUS && graphics().fullscreen() && IsWindowVisible(pimpl->handle))
460
- {
461
- if (!pimpl->iconified)
462
- {
463
- ChangeDisplaySettings(NULL, CDS_FULLSCREEN);
464
- CloseWindow(pimpl->handle);
465
- pimpl->iconified = true;
466
- }
467
- return 0;
468
- }
469
-
470
- if (message == WM_CLOSE)
471
- {
472
- close();
473
- return 0;
474
- }
475
-
476
- if (message == WM_PAINT)
477
- {
478
- PAINTSTRUCT ps;
479
- pimpl->hdc = BeginPaint(handle(), &ps);
480
-
481
- if (pimpl->graphics.get() && graphics().begin())
482
- {
483
- try
484
- {
485
- draw();
486
- graphics().end();
487
- }
488
- catch (std::exception& e)
489
- {
490
- ::MessageBoxA(0, e.what(), "Error", MB_OK | MB_ICONERROR);
491
- abort();
492
- }
493
- }
494
-
495
- SwapBuffers(pimpl->hdc);
496
- EndPaint(handle(), &ps);
497
- return 0;
498
- }
499
-
500
- if (message == WM_SYSCOMMAND)
501
- {
502
- switch(wparam)
503
- {
504
- case SC_SCREENSAVE:
505
- case SC_MONITORPOWER:
506
- if (graphics().fullscreen())
507
- return 0;
508
- else
509
- break;
510
- case SC_KEYMENU:
511
- return 0;
512
- }
513
- }
514
-
515
- if (pimpl->input.get() && input().textInput() && input().textInput()->feedMessage(message, wparam, lparam))
516
- return 0;
517
-
518
- return DefWindowProc(handle(), message, wparam, lparam);
519
- }
520
-
521
- // Deprecated.
522
-
523
- class Gosu::Audio {};
524
- namespace { Gosu::Audio dummyAudio; }
525
-
526
- const Gosu::Audio& Gosu::Window::audio() const
527
- {
528
- return dummyAudio;
529
- }
530
-
531
- Gosu::Audio& Gosu::Window::audio()
532
- {
533
- return dummyAudio;
534
- }