gosu 0.7.45 → 0.7.46

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/COPYING +6 -11
  2. data/Gosu/{ButtonsWin.hpp → Buttons.hpp} +91 -4
  3. data/Gosu/ButtonsMac.hpp +91 -4
  4. data/Gosu/Graphics.hpp +10 -0
  5. data/Gosu/ImageData.hpp +1 -0
  6. data/Gosu/Input.hpp +2 -3
  7. data/Gosu/Version.hpp +2 -2
  8. data/Gosu/Window.hpp +1 -1
  9. data/GosuImpl/Audio/AudioToolboxFile.hpp +4 -0
  10. data/GosuImpl/Graphics/BitmapApple.mm +5 -11
  11. data/GosuImpl/Graphics/ClipRectStack.hpp +2 -2
  12. data/GosuImpl/Graphics/Common.hpp +1 -1
  13. data/GosuImpl/Graphics/DrawOpQueue.hpp +30 -29
  14. data/GosuImpl/Graphics/Graphics.cpp +2 -3
  15. data/GosuImpl/Graphics/TextMac.cpp +9 -5
  16. data/GosuImpl/Graphics/TextTouch.mm +8 -4
  17. data/GosuImpl/Graphics/Texture.cpp +4 -1
  18. data/GosuImpl/InputMac.mm +24 -45
  19. data/GosuImpl/InputX.cpp +25 -39
  20. data/GosuImpl/RubyGosu.swg +11 -0
  21. data/GosuImpl/RubyGosu_wrap.cxx +109 -40
  22. data/GosuImpl/RubyGosu_wrap.h +1 -1
  23. data/GosuImpl/TextInputWin.cpp +1 -1
  24. data/GosuImpl/TextInputX.cpp +3 -1
  25. data/GosuImpl/WinMain.cpp +3 -4
  26. data/GosuImpl/WindowMac.mm +83 -73
  27. data/GosuImpl/WindowWin.cpp +65 -58
  28. data/dependencies/libogg/AUTHORS +4 -0
  29. data/dependencies/libogg/CHANGES +70 -0
  30. data/dependencies/libogg/COPYING +28 -0
  31. data/dependencies/libogg/include/ogg/ogg.h +209 -0
  32. data/dependencies/libogg/include/ogg/os_types.h +147 -0
  33. data/dependencies/libogg/src/bitwise.c +857 -0
  34. data/dependencies/libogg/src/framing.c +2089 -0
  35. data/dependencies/libvorbis/AUTHORS +3 -0
  36. data/dependencies/libvorbis/CHANGES +126 -0
  37. data/dependencies/libvorbis/COPYING +28 -0
  38. data/dependencies/libvorbis/include/vorbis/codec.h +243 -0
  39. data/dependencies/libvorbis/include/vorbis/vorbisenc.h +436 -0
  40. data/dependencies/libvorbis/include/vorbis/vorbisfile.h +206 -0
  41. data/dependencies/libvorbis/lib/analysis.c +120 -0
  42. data/dependencies/libvorbis/lib/backends.h +144 -0
  43. data/dependencies/libvorbis/lib/barkmel.c +64 -0
  44. data/dependencies/libvorbis/lib/bitrate.c +253 -0
  45. data/dependencies/libvorbis/lib/bitrate.h +59 -0
  46. data/dependencies/libvorbis/lib/block.c +1046 -0
  47. data/dependencies/libvorbis/lib/books/coupled/res_books_51.h +12257 -0
  48. data/dependencies/libvorbis/lib/books/coupled/res_books_stereo.h +15783 -0
  49. data/dependencies/libvorbis/lib/books/floor/floor_books.h +1547 -0
  50. data/dependencies/libvorbis/lib/books/uncoupled/res_books_uncoupled.h +7758 -0
  51. data/dependencies/libvorbis/lib/codebook.c +479 -0
  52. data/dependencies/libvorbis/lib/codebook.h +119 -0
  53. data/dependencies/libvorbis/lib/codec_internal.h +167 -0
  54. data/dependencies/libvorbis/lib/envelope.c +375 -0
  55. data/dependencies/libvorbis/lib/envelope.h +80 -0
  56. data/dependencies/libvorbis/lib/floor0.c +222 -0
  57. data/dependencies/libvorbis/lib/floor1.c +1099 -0
  58. data/dependencies/libvorbis/lib/highlevel.h +58 -0
  59. data/dependencies/libvorbis/lib/info.c +664 -0
  60. data/dependencies/libvorbis/lib/lookup.c +94 -0
  61. data/dependencies/libvorbis/lib/lookup.h +32 -0
  62. data/dependencies/libvorbis/lib/lookup_data.h +192 -0
  63. data/dependencies/libvorbis/lib/lpc.c +160 -0
  64. data/dependencies/libvorbis/lib/lpc.h +29 -0
  65. data/dependencies/libvorbis/lib/lsp.c +456 -0
  66. data/dependencies/libvorbis/lib/lsp.h +28 -0
  67. data/dependencies/libvorbis/lib/mapping0.c +816 -0
  68. data/dependencies/libvorbis/lib/masking.h +785 -0
  69. data/dependencies/libvorbis/lib/mdct.c +563 -0
  70. data/dependencies/libvorbis/lib/mdct.h +71 -0
  71. data/dependencies/libvorbis/lib/misc.h +57 -0
  72. data/dependencies/libvorbis/lib/modes/floor_all.h +260 -0
  73. data/dependencies/libvorbis/lib/modes/psych_11.h +51 -0
  74. data/dependencies/libvorbis/lib/modes/psych_16.h +133 -0
  75. data/dependencies/libvorbis/lib/modes/psych_44.h +642 -0
  76. data/dependencies/libvorbis/lib/modes/psych_8.h +101 -0
  77. data/dependencies/libvorbis/lib/modes/residue_16.h +163 -0
  78. data/dependencies/libvorbis/lib/modes/residue_44.h +292 -0
  79. data/dependencies/libvorbis/lib/modes/residue_44p51.h +451 -0
  80. data/dependencies/libvorbis/lib/modes/residue_44u.h +318 -0
  81. data/dependencies/libvorbis/lib/modes/residue_8.h +109 -0
  82. data/dependencies/libvorbis/lib/modes/setup_11.h +143 -0
  83. data/dependencies/libvorbis/lib/modes/setup_16.h +153 -0
  84. data/dependencies/libvorbis/lib/modes/setup_22.h +128 -0
  85. data/dependencies/libvorbis/lib/modes/setup_32.h +132 -0
  86. data/dependencies/libvorbis/lib/modes/setup_44.h +117 -0
  87. data/dependencies/libvorbis/lib/modes/setup_44p51.h +74 -0
  88. data/dependencies/libvorbis/lib/modes/setup_44u.h +74 -0
  89. data/dependencies/libvorbis/lib/modes/setup_8.h +149 -0
  90. data/dependencies/libvorbis/lib/modes/setup_X.h +225 -0
  91. data/dependencies/libvorbis/lib/os.h +186 -0
  92. data/dependencies/libvorbis/lib/psy.c +1203 -0
  93. data/dependencies/libvorbis/lib/psy.h +154 -0
  94. data/dependencies/libvorbis/lib/psytune.c +524 -0
  95. data/dependencies/libvorbis/lib/registry.c +45 -0
  96. data/dependencies/libvorbis/lib/registry.h +32 -0
  97. data/dependencies/libvorbis/lib/res0.c +889 -0
  98. data/dependencies/libvorbis/lib/scales.h +90 -0
  99. data/dependencies/libvorbis/lib/sharedbook.c +579 -0
  100. data/dependencies/libvorbis/lib/smallft.c +1255 -0
  101. data/dependencies/libvorbis/lib/smallft.h +34 -0
  102. data/dependencies/libvorbis/lib/synthesis.c +184 -0
  103. data/dependencies/libvorbis/lib/tone.c +54 -0
  104. data/dependencies/libvorbis/lib/vorbisenc.c +1215 -0
  105. data/dependencies/libvorbis/lib/vorbisfile.c +2337 -0
  106. data/dependencies/libvorbis/lib/window.c +2135 -0
  107. data/dependencies/libvorbis/lib/window.h +26 -0
  108. data/dependencies/ogg_vorbis.license +28 -0
  109. data/lib/gosu/swig_patches.rb +2 -2
  110. data/linux/extconf.rb +17 -3
  111. metadata +96 -17
  112. data/Gosu/ButtonsX.hpp +0 -141
  113. data/GosuImpl/Audio/AudioSDL.cpp +0 -315
@@ -1,6 +1,6 @@
1
1
  /* ----------------------------------------------------------------------------
2
2
  * This file was automatically generated by SWIG (http://www.swig.org).
3
- * Version 2.0.7
3
+ * Version 2.0.9
4
4
  *
5
5
  * This file is not intended to be easily readable and contains a number of
6
6
  * coding conventions designed to improve portability and efficiency. Do not make
@@ -1,5 +1,5 @@
1
1
  #include <Gosu/TextInput.hpp>
2
- #include <Gosu/ButtonsWin.hpp>
2
+ #include <Gosu/Buttons.hpp>
3
3
  #include <algorithm>
4
4
  #include <vector>
5
5
  #include <wctype.h>
@@ -65,7 +65,9 @@ bool Gosu::TextInput::feedXEvent(void* display, void* event)
65
65
  bool shiftDown = (ev->xkey.state & ShiftMask);
66
66
 
67
67
  KeySym lower, upper;
68
- XConvertCase(XKeycodeToKeysym((Display*)display, ev->xkey.keycode, 0), &lower, &upper);
68
+ int keysyms_per_keycode_return;
69
+ KeySym keysym = (KeySym)XGetKeyboardMapping((Display*)display, ev->xkey.keycode, 0, &keysyms_per_keycode_return);
70
+ XConvertCase(keysym, &lower, &upper);
69
71
 
70
72
  wchar_t ch = static_cast<wchar_t>(shiftDown ? upper : lower);
71
73
 
@@ -4,7 +4,6 @@
4
4
  #include <vector>
5
5
  using namespace std;
6
6
 
7
- // IMPR: Check for security issues. I hacked this together.
8
7
  vector<string> splitCmdLine()
9
8
  {
10
9
  vector<string> result;
@@ -29,12 +28,12 @@ vector<string> splitCmdLine()
29
28
  argBegin = 0;
30
29
  }
31
30
  }
32
- else if (!isspace(*cmdLine) && argBegin == 0)
31
+ else if (!isspace((unsigned char)*cmdLine) && argBegin == 0)
33
32
  {
34
33
  argBegin = cmdLine;
35
34
  isQuotedArg = false;
36
35
  }
37
- else if (isspace(*cmdLine) && argBegin != 0 && !isQuotedArg)
36
+ else if (isspace((unsigned char)*cmdLine) && argBegin != 0 && !isQuotedArg)
38
37
  {
39
38
  result.push_back(std::string(argBegin, cmdLine + 1));
40
39
  argBegin = 0;
@@ -58,7 +57,7 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
58
57
  vector<char*> argv(arguments.size());
59
58
  for (unsigned i = 0; i < argv.size(); ++i)
60
59
  argv[i] = const_cast<char*>(arguments[i].c_str());
61
- return main(argv.size(), &argv[0]);
60
+ return main(argv.size(), &argv[0]);
62
61
  }
63
62
  catch (const std::exception& e)
64
63
  {
@@ -23,7 +23,7 @@ namespace Gosu
23
23
  void registerFrame();
24
24
  }
25
25
 
26
- NSRect screenRect = [[[NSScreen screens] objectAtIndex: 0] frame];
26
+ NSRect screenRect = [[NSScreen mainScreen] frame];
27
27
 
28
28
  unsigned screenWidth()
29
29
  {
@@ -34,16 +34,30 @@ namespace Gosu
34
34
  {
35
35
  return screenRect.size.height;
36
36
  }
37
+
38
+ static NSUInteger windowStyleMask = NSTitledWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask;
39
+
40
+ void scaleDownWindowIfNecessary(unsigned& width, unsigned& height)
41
+ {
42
+ NSRect usableFrameRect = [[NSScreen mainScreen] visibleFrame];
43
+ NSRect usableContentRect = [NSWindow contentRectForFrameRect:usableFrameRect styleMask:windowStyleMask];
44
+ double factor = std::min(usableContentRect.size.width / width, usableContentRect.size.height / height);
45
+ if (factor < 1) {
46
+ width *= factor;
47
+ height *= factor;
48
+ }
49
+ }
37
50
  }
38
51
 
39
52
  #ifndef __LP64__
40
53
  // Workaround for Apple NSScreen bug :(
54
+ // TODO - fill in the details ... on which systems does Gosu break without this?
41
55
  @interface NSScreen (NSScreenAccess)
42
- - (void) setFrame:(NSRect)frame;
56
+ - (void)setFrame:(NSRect)frame;
43
57
  @end
44
58
 
45
59
  @implementation NSScreen (NSScreenAccess)
46
- - (void) setFrame:(NSRect)frame;
60
+ - (void)setFrame:(NSRect)frame;
47
61
  {
48
62
  _frame = frame;
49
63
  }
@@ -94,40 +108,40 @@ namespace
94
108
 
95
109
  typedef void (*WindowProc)(Gosu::Window&);
96
110
 
97
- @interface GosuForwarder : NSObject
111
+ @interface GosuForwarder : NSObject<NSWindowDelegate>
98
112
  {
99
113
  Gosu::Window* win;
100
114
  WindowProc pr;
101
115
  }
102
- - (id)initWithWindow: (Gosu::Window*)window withProc:(WindowProc)proc;
103
- - (void)doTick: (NSTimer*)timer;
104
- - (BOOL)windowShouldClose: (id)sender;
116
+ - (id)initWithWindow:(Gosu::Window *)window withProc:(WindowProc)proc;
117
+ - (void)doTick:(NSTimer *)timer;
118
+ - (BOOL)windowShouldClose:(id)sender;
105
119
  @end
106
120
 
107
121
  @implementation GosuForwarder
108
- - (id)initWithWindow: (Gosu::Window*)window withProc:(WindowProc)proc
122
+ - (id)initWithWindow:(Gosu::Window*)window withProc:(WindowProc)proc
109
123
  {
110
- if (![super init])
111
- return nil;
112
- win = window;
113
- pr = proc;
124
+ if ((self = [super init])) {
125
+ win = window;
126
+ pr = proc;
127
+ }
114
128
  return self;
115
129
  }
116
130
 
117
- - (void)doTick: (NSTimer*)timer
131
+ - (void)doTick:(NSTimer*)timer
118
132
  {
119
133
  pr(*win);
120
134
  }
121
135
 
122
- - (BOOL)windowShouldClose: (id)sender
136
+ - (BOOL)windowShouldClose:(id)sender
123
137
  {
124
- [NSApp stop: nil];
138
+ [NSApp stop:nil];
125
139
  return YES;
126
140
  }
127
141
  @end
128
142
 
129
143
  #define OVERRIDE_METHOD(method) \
130
- - (void) method: (NSEvent*) event \
144
+ - (void)method:(NSEvent*) event \
131
145
  { \
132
146
  _input->feedNSEvent(event); \
133
147
  }
@@ -138,7 +152,7 @@ typedef void (*WindowProc)(Gosu::Window&);
138
152
  }
139
153
  @end
140
154
  @implementation GosuWindow
141
- - (void) setInput: (Gosu::Input*)input
155
+ - (void)setInput:(Gosu::Input *)input
142
156
  {
143
157
  _input = input;
144
158
  }
@@ -155,11 +169,11 @@ OVERRIDE_METHOD(scrollWheel);
155
169
 
156
170
  @interface GosuView : NSView
157
171
  {
158
- Gosu::Input* _input;
172
+ Gosu::Input *_input;
159
173
  }
160
174
  @end
161
175
  @implementation GosuView
162
- - (void) setInput: (Gosu::Input*)input
176
+ - (void)setInput:(Gosu::Input *)input
163
177
  {
164
178
  _input = input;
165
179
 
@@ -201,12 +215,11 @@ struct Gosu::Window::Impl
201
215
  void createWindow(unsigned width, unsigned height)
202
216
  {
203
217
  NSRect rect = NSMakeRect(0, 0, width, height);
204
- unsigned style = NSTitledWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask;
205
- window.reset([[GosuWindow alloc] initWithContentRect:rect styleMask:style
218
+ window.reset([[GosuWindow alloc] initWithContentRect:rect styleMask:windowStyleMask
206
219
  backing:NSBackingStoreBuffered defer:NO]);
207
220
  [window.obj() retain]; // TODO: Why?
208
221
 
209
- [window.obj() setContentView: [[GosuView alloc] init]];
222
+ [window.obj() setContentView:[[GosuView alloc] init]];
210
223
  [window.obj() center];
211
224
  }
212
225
 
@@ -222,6 +235,11 @@ Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen,
222
235
  double updateInterval)
223
236
  : pimpl(new Impl)
224
237
  {
238
+ if (fullscreen) {
239
+ NSLog(@"Fullscreen mode is temporarily unavailable on OS X; see https://github.com/jlnr/gosu/issues/157");
240
+ fullscreen = false;
241
+ }
242
+
225
243
  pimpl->pool.reset([[NSAutoreleasePool alloc] init]); // <- necessary...?
226
244
 
227
245
  // Create NSApp global variable
@@ -254,11 +272,11 @@ Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen,
254
272
 
255
273
  // Create pixel format and OpenGL context
256
274
  ObjRef<NSOpenGLPixelFormat> fmt([[NSOpenGLPixelFormat alloc] initWithAttributes:attrs]);
257
- if (not fmt.get())
275
+ if (! fmt.get())
258
276
  throw std::runtime_error("Could not find a suitable OpenGL pixel format");
259
- ::context = [[NSOpenGLContext alloc] initWithFormat: fmt.obj() shareContext:nil];
277
+ ::context = [[NSOpenGLContext alloc] initWithFormat:fmt.obj() shareContext:nil];
260
278
  pimpl->context.reset(context);
261
- if (not pimpl->context.get())
279
+ if (! pimpl->context.get())
262
280
  throw std::runtime_error("Unable to create an OpenGL context with the supplied pixel format");
263
281
 
264
282
  unsigned realWidth = width, realHeight = height;
@@ -268,7 +286,7 @@ Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen,
268
286
 
269
287
  // Save old mode and retrieve BPP
270
288
  pimpl->savedMode = CGDisplayCurrentMode(kCGDirectMainDisplay);
271
- pimpl->savedFrame = [[NSScreen mainScreen] frame];
289
+ pimpl->savedFrame = [[NSScreen mainScreen] frame];
272
290
  int bpp;
273
291
  CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(pimpl->savedMode, kCGDisplayBitsPerPixel),
274
292
  kCFNumberIntType, &bpp);
@@ -283,15 +301,7 @@ Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen,
283
301
  }
284
302
  else
285
303
  {
286
- // Windowed: Create window large enough to display stuff
287
- // This is a pretty brutal heuristic I guess.
288
-
289
- double factor = std::min(0.9 * screenWidth() / width,
290
- 0.8 * screenHeight() / height);
291
-
292
- if (factor < 1)
293
- realWidth *= factor, realHeight *= factor;
294
-
304
+ scaleDownWindowIfNecessary(realWidth, realHeight);
295
305
  pimpl->createWindow(realWidth, realHeight);
296
306
  // Tell context to draw on this window.
297
307
  [pimpl->context.obj() setView:[pimpl->window.obj() contentView]];
@@ -309,15 +319,15 @@ Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen,
309
319
  pimpl->input->onButtonUp = std::tr1::bind(&Window::buttonUp, this, _1);
310
320
  pimpl->input->setMouseFactors(1.0 * width / realWidth, 1.0 * height / realHeight);
311
321
  if (fullscreen)
312
- [NSApp setInput: input()];
322
+ [NSApp setInput:input()];
313
323
 
314
- pimpl->forwarder.reset([[GosuForwarder alloc] initWithWindow: this withProc: &Impl::doTick]);
324
+ pimpl->forwarder.reset([[GosuForwarder alloc] initWithWindow:this withProc:&Impl::doTick]);
315
325
 
316
- if (not fullscreen)
326
+ if (! fullscreen)
317
327
  {
318
- [pimpl->window.obj() setDelegate: pimpl->forwarder.obj()];
319
- [pimpl->window.obj() setInput: pimpl->input.get()];
320
- [(GosuView*)[pimpl->window.obj() contentView] setInput: pimpl->input.get()];
328
+ [pimpl->window.obj() setDelegate:pimpl->forwarder.obj()];
329
+ [pimpl->window.obj() setInput:pimpl->input.get()];
330
+ [(GosuView*)[pimpl->window.obj() contentView] setInput:pimpl->input.get()];
321
331
  // Finally, safely hide the window.
322
332
  [pimpl->window.obj() orderOut:nil];
323
333
  }
@@ -343,7 +353,7 @@ Gosu::Window::~Window()
343
353
 
344
354
  std::wstring Gosu::Window::caption() const
345
355
  {
346
- if (not pimpl->window.get())
356
+ if (! pimpl->window.get())
347
357
  return L"";
348
358
 
349
359
  ObjRef<NSAutoreleasePool> pool([[NSAutoreleasePool alloc] init]);
@@ -353,11 +363,11 @@ std::wstring Gosu::Window::caption() const
353
363
 
354
364
  void Gosu::Window::setCaption(const std::wstring& caption)
355
365
  {
356
- if (not pimpl->window.get())
366
+ if (! pimpl->window.get())
357
367
  return;
358
368
 
359
369
  std::string utf8 = wstringToUTF8(caption);
360
- ObjRef<NSString> title([[NSString alloc] initWithUTF8String: utf8.c_str()]);
370
+ ObjRef<NSString> title([[NSString alloc] initWithUTF8String:utf8.c_str()]);
361
371
  [pimpl->window.obj() setTitle: title.obj()];
362
372
  }
363
373
 
@@ -368,15 +378,15 @@ double Gosu::Window::updateInterval() const
368
378
 
369
379
  void Gosu::Window::show()
370
380
  {
371
- // This is for Ruby/Gosu and misc. hackery:
372
- // Usually, applications on the Mac can only get keyboard and mouse input if
373
- // run by double-clicking an .app. So if this is run from the Terminal (i.e.
374
- // during Ruby/Gosu game development), tell the OS we need input in any case.
375
- ProcessSerialNumber psn = { 0, kCurrentProcess };
376
- TransformProcessType(&psn, kProcessTransformToForegroundApplication);
381
+ // This is for Ruby/Gosu and misc. hackery:
382
+ // Usually, applications on the Mac can only get keyboard and mouse input if
383
+ // run by double-clicking an .app. So if this is run from the Terminal (i.e.
384
+ // during Ruby/Gosu game development), tell the OS we need input in any case.
385
+ ProcessSerialNumber psn = { 0, kCurrentProcess };
386
+ TransformProcessType(&psn, kProcessTransformToForegroundApplication);
377
387
  SetFrontProcess(&psn);
378
388
 
379
- [NSThread setThreadPriority: 1.0];
389
+ [NSThread setThreadPriority:1.0];
380
390
 
381
391
  if (graphics().fullscreen())
382
392
  {
@@ -390,7 +400,7 @@ void Gosu::Window::show()
390
400
  else
391
401
  [pimpl->window.obj() makeKeyAndOrderFront:nil];
392
402
 
393
- NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval: pimpl->interval / 1000.0
403
+ NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:pimpl->interval / 1000.0
394
404
  target:pimpl->forwarder.obj() selector:@selector(doTick:)
395
405
  userInfo:nil repeats:YES];
396
406
  [NSApp run];
@@ -416,15 +426,15 @@ void Gosu::Window::close()
416
426
  // NSApp doesn't check its 'stopped' flag until it finishes processing
417
427
  // the next event (timers are not events), so here's a rather hacky way
418
428
  // to make sure it has one in its queue
419
- [NSApp postEvent: [NSEvent otherEventWithType:NSApplicationDefined
420
- location:NSZeroPoint
421
- modifierFlags:0
422
- timestamp:0.0
423
- windowNumber:0
424
- context:NULL
425
- subtype:0
426
- data1:0
427
- data2:0] atStart:NO];
429
+ [NSApp postEvent:[NSEvent otherEventWithType:NSApplicationDefined
430
+ location:NSZeroPoint
431
+ modifierFlags:0
432
+ timestamp:0.0
433
+ windowNumber:0
434
+ context:NULL
435
+ subtype:0
436
+ data1:0
437
+ data2:0] atStart:NO];
428
438
  }
429
439
 
430
440
  const Gosu::Graphics& Gosu::Window::graphics() const
@@ -449,14 +459,15 @@ Gosu::Input& Gosu::Window::input()
449
459
 
450
460
  namespace
451
461
  {
452
- void makeCurrentContext(NSOpenGLContext* context)
462
+ void makeCurrentContext(NSOpenGLContext *context)
453
463
  {
454
464
  [context makeCurrentContext];
455
465
  }
456
466
 
457
- void releaseContext(NSOpenGLContext* context)
467
+ void releaseContextAndDelete(NSOpenGLContext *context, std::tr1::function<void()> *function)
458
468
  {
459
469
  [context release];
470
+ delete function;
460
471
  }
461
472
  }
462
473
 
@@ -471,16 +482,15 @@ Gosu::Window::SharedContext Gosu::Window::createSharedContext()
471
482
  (NSOpenGLPixelFormatAttribute)0
472
483
  };
473
484
 
474
- NSOpenGLPixelFormat* pf =
475
- [[[NSOpenGLPixelFormat alloc]
476
- initWithAttributes:attributes] autorelease];
485
+ NSOpenGLPixelFormat* pf = [[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes] autorelease];
477
486
 
478
- NSOpenGLContext* ctx = [[NSOpenGLContext alloc]
479
- initWithFormat: pf
480
- shareContext: pimpl->context.obj()];
487
+ NSOpenGLContext* ctx = [[NSOpenGLContext alloc] initWithFormat:pf shareContext:pimpl->context.obj()];
481
488
 
482
- return SharedContext(new std::tr1::function<void()>(std::tr1::bind(makeCurrentContext, ctx)),
483
- std::tr1::bind(releaseContext, ctx));
489
+ // TODO: Exception safety? Oh man, is this construction really worth it? :)
490
+ std::tr1::function<void()> *makeCurrent =
491
+ new std::tr1::function<void()>(std::tr1::bind(makeCurrentContext, ctx));
492
+ return SharedContext(makeCurrent,
493
+ std::tr1::bind(releaseContextAndDelete, ctx, _1));
484
494
  }
485
495
 
486
496
  namespace GosusDarkSide
@@ -496,7 +506,7 @@ void Gosu::Window::Impl::doTick(Window& window)
496
506
  {
497
507
  // Enable vsync.
498
508
  GLint value = 1;
499
- [window.pimpl->context.obj() setValues: &value forParameter: NSOpenGLCPSwapInterval];
509
+ [window.pimpl->context.obj() setValues:&value forParameter:NSOpenGLCPSwapInterval];
500
510
 
501
511
  if ((window.graphics().fullscreen() ||
502
512
  NSPointInRect([window.pimpl->window.obj() mouseLocationOutsideOfEventStream],
@@ -509,7 +519,7 @@ void Gosu::Window::Impl::doTick(Window& window)
509
519
  }
510
520
  else
511
521
  {
512
- if (not window.pimpl->mouseViz)
522
+ if (! window.pimpl->mouseViz)
513
523
  [NSCursor unhide];
514
524
  window.pimpl->mouseViz = true;
515
525
  }
@@ -117,7 +117,7 @@ namespace Gosu
117
117
  void setupVSync()
118
118
  {
119
119
  char* extensions = (char*)glGetString(GL_EXTENSIONS);
120
- // The Intel BootCamp drivers will actually have a proc address for wglSwapInterval
120
+ // The Intel BootCamp drivers will actually have a proc address for wglSwapInterval
121
121
  // that doesn't do much, so check the string instead of just getting the address.
122
122
  if (!strstr(extensions, "WGL_EXT_swap_control"))
123
123
  return;
@@ -176,10 +176,10 @@ namespace Gosu
176
176
  struct Gosu::Window::Impl
177
177
  {
178
178
  HWND handle;
179
- HDC hdc;
179
+ HDC hdc;
180
180
  std::auto_ptr<Graphics> graphics;
181
181
  std::auto_ptr<Input> input;
182
- double updateInterval;
182
+ double updateInterval;
183
183
  bool iconified;
184
184
 
185
185
  unsigned originalWidth, originalHeight;
@@ -225,22 +225,22 @@ Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen,
225
225
  Win::instance(), 0);
226
226
  Win::check(pimpl->handle);
227
227
 
228
- pimpl->hdc = GetDC(handle());
228
+ pimpl->hdc = GetDC(handle());
229
229
  Win::check(pimpl->hdc);
230
230
 
231
- PIXELFORMATDESCRIPTOR pfd;
232
- ZeroMemory(&pfd, sizeof pfd);
231
+ PIXELFORMATDESCRIPTOR pfd;
232
+ ZeroMemory(&pfd, sizeof pfd);
233
233
  pfd.nSize = sizeof pfd;
234
234
  pfd.nVersion = 1;
235
235
  pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
236
236
  pfd.iLayerType = PFD_MAIN_PLANE;
237
237
  pfd.iPixelType = PFD_TYPE_RGBA;
238
238
  pfd.cColorBits = 32;
239
- int pf = ChoosePixelFormat(pimpl->hdc, &pfd);
239
+ int pf = ChoosePixelFormat(pimpl->hdc, &pfd);
240
240
  Win::check(pf);
241
241
  Win::check(SetPixelFormat(pimpl->hdc, pf, &pfd));
242
242
 
243
- HGLRC hrc = Win::check(wglCreateContext(pimpl->hdc), "creating rendering context");
243
+ HGLRC hrc = Win::check(wglCreateContext(pimpl->hdc), "creating rendering context");
244
244
  Win::check(wglMakeCurrent(pimpl->hdc, hrc), "selecting the rendering context");
245
245
 
246
246
  setupVSync();
@@ -256,12 +256,12 @@ Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen,
256
256
 
257
257
  if (!fullscreen)
258
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
- }
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
265
 
266
266
  // Determine the size the window needs to have including UI chrome.
267
267
  RECT rc = { 0, 0, width, height };
@@ -287,9 +287,9 @@ Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen,
287
287
  MoveWindow(handle(), windowX, windowY, windowW, windowH, false);
288
288
 
289
289
  pimpl->graphics.reset(new Gosu::Graphics(width, height, fullscreen));
290
- graphics().setResolution(pimpl->originalWidth, pimpl->originalHeight);
290
+ graphics().setResolution(pimpl->originalWidth, pimpl->originalHeight);
291
291
  pimpl->input.reset(new Gosu::Input(handle()));
292
- input().setMouseFactors(1.0 * pimpl->originalWidth / width, 1.0 * pimpl->originalHeight / height);
292
+ input().setMouseFactors(1.0 * pimpl->originalWidth / width, 1.0 * pimpl->originalHeight / height);
293
293
  input().onButtonDown = std::tr1::bind(&Window::buttonDown, this, _1);
294
294
  input().onButtonUp = std::tr1::bind(&Window::buttonUp, this, _1);
295
295
 
@@ -343,46 +343,46 @@ void Gosu::Window::show()
343
343
  {
344
344
  Win::processMessages();
345
345
 
346
- unsigned lastTick = 0;
346
+ unsigned lastTick = 0;
347
347
 
348
- for (;;)
349
- {
350
- Win::processMessages();
348
+ for (;;)
349
+ {
350
+ Win::processMessages();
351
351
 
352
- if (!::IsWindowVisible(handle()))
353
- {
352
+ if (!::IsWindowVisible(handle()))
353
+ {
354
354
  // TODO: Find out what the Sleep here is doing...
355
- Sleep(50);
356
- return;
357
- }
355
+ Sleep(50);
356
+ return;
357
+ }
358
358
 
359
- unsigned ms = milliseconds();
359
+ unsigned ms = milliseconds();
360
360
 
361
- if (ms < lastTick || ms - lastTick >= static_cast<unsigned>(pimpl->updateInterval))
362
- {
363
- lastTick = ms;
361
+ if (ms < lastTick || ms - lastTick >= static_cast<unsigned>(pimpl->updateInterval))
362
+ {
363
+ lastTick = ms;
364
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();
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
371
  if (needsRedraw())
372
372
  {
373
- ::InvalidateRect(handle(), 0, FALSE);
373
+ ::InvalidateRect(handle(), 0, FALSE);
374
374
  FPS::registerFrame();
375
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
- }
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
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
- }
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
386
  }
387
387
  catch (...)
388
388
  {
@@ -425,16 +425,23 @@ HWND Gosu::Window::handle() const
425
425
 
426
426
  LRESULT Gosu::Window::handleMessage(UINT message, WPARAM wparam, LPARAM lparam)
427
427
  {
428
- if (message == WM_SETCURSOR)
428
+ if (message == WM_SETCURSOR)
429
429
  {
430
- if (LOWORD(lparam) != HTCLIENT || GetForegroundWindow() != handle() || needsCursor())
431
- {
432
- static const HCURSOR arrowCursor = LoadCursor(0, IDC_ARROW);
433
- SetCursor(arrowCursor);
434
- }
435
- else
436
- SetCursor(NULL);
437
- return TRUE;
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
+ }
438
445
  }
439
446
 
440
447
  if (message == WM_SETFOCUS && graphics().fullscreen() && IsWindowVisible(pimpl->handle))
@@ -476,13 +483,13 @@ LRESULT Gosu::Window::handleMessage(UINT message, WPARAM wparam, LPARAM lparam)
476
483
  try
477
484
  {
478
485
  draw();
486
+ graphics().end();
479
487
  }
480
- catch (...)
488
+ catch (std::exception& e)
481
489
  {
482
- graphics().end();
483
- throw;
490
+ ::MessageBoxA(0, e.what(), "Error", MB_OK | MB_ICONERROR);
491
+ abort();
484
492
  }
485
- graphics().end();
486
493
  }
487
494
 
488
495
  SwapBuffers(pimpl->hdc);