gosu 0.7.50 → 0.8.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,6 +23,7 @@ class Gosu::Window
23
23
 
24
24
  def protected_draw_2
25
25
  protected_draw
26
+ $gosu_gl_blocks_2 = $gosu_gl_blocks
26
27
  $gosu_gl_blocks = nil
27
28
  end
28
29
 
@@ -29,11 +29,14 @@ BASE_FILES = %w(
29
29
  Graphics/Text.cpp
30
30
  Graphics/Texture.cpp
31
31
  Graphics/Transform.cpp
32
+ Input.cpp
32
33
  Inspection.cpp
33
34
  IO.cpp
34
35
  Math.cpp
35
36
  RubyGosu_wrap.cxx
36
37
  Utility.cpp
38
+ TextInput.cpp
39
+ Window.cpp
37
40
  )
38
41
 
39
42
  MAC_FILES = %w(
@@ -41,21 +44,15 @@ MAC_FILES = %w(
41
44
  Graphics/BitmapApple.mm
42
45
  Graphics/TextMac.cpp
43
46
  Graphics/TextTouch.mm
44
- InputMac.mm
45
- TextInputMac.mm
46
47
  TimingApple.cpp
47
48
  UtilityApple.mm
48
- WindowMac.mm
49
49
  )
50
50
 
51
51
  LINUX_FILES = %w(
52
52
  Audio/AudioOpenAL.cpp
53
53
  Graphics/BitmapFreeImage.cpp
54
54
  Graphics/TextUnix.cpp
55
- InputX.cpp
56
- TextInputX.cpp
57
55
  TimingUnix.cpp
58
- WindowX.cpp
59
56
  )
60
57
 
61
58
  OGG_VORBIS_FILES = Dir['../dependencies/libogg/src/*.c'] +
@@ -75,20 +72,19 @@ $CFLAGS << " -DGOSU_DEPRECATED="
75
72
  $INCFLAGS << " -I../ -I../GosuImpl"
76
73
 
77
74
  if `uname`.chomp == 'Darwin' then
78
- SOURCE_FILES = BASE_FILES + MAC_FILES + OGG_VORBIS_FILES
75
+ SOURCE_FILES = BASE_FILES + MAC_FILES# + OGG_VORBIS_FILES
79
76
 
80
77
  # Apple curiously distributes libpng only inside X11
81
78
  $INCFLAGS << " -I/usr/X11/include"
82
79
  # Use included libogg, libvorbis to make Gosu easier to install on OS X
83
- $INCFLAGS << " -I../dependencies/libogg/include"
84
- $INCFLAGS << " -I../dependencies/libvorbis/include"
85
- $INCFLAGS << " -I../dependencies/libvorbis/lib"
80
+ #$INCFLAGS << " -I../dependencies/libogg/include"
81
+ #$INCFLAGS << " -I../dependencies/libvorbis/include"
82
+ #$INCFLAGS << " -I../dependencies/libvorbis/lib"
86
83
  # To make everything work with the Objective C runtime
87
84
  $CFLAGS << " -x objective-c -DNDEBUG"
88
85
  # Compile all C++ files as Objective C++ on OS X since mkmf does not support .mm
89
86
  # files.
90
- # Also undefine two debug flags that cause exceptions to randomly crash
91
- # otherwise; see:
87
+ # Also undefine two debug flags that cause exceptions to randomly crash, see:
92
88
  # https://trac.macports.org/ticket/27237#comment:21
93
89
  # http://newartisans.com/2009/10/a-c-gotcha-on-snow-leopard/#comment-893
94
90
  CONFIG['CXXFLAGS'] = "#{CONFIG['CXXFLAGS']} -x objective-c++ -U_GLIBCXX_DEBUG -U_GLIBCXX_DEBUG_PEDANTIC"
@@ -97,17 +93,15 @@ if `uname`.chomp == 'Darwin' then
97
93
  # TODO: This can probably be enabled starting from 10.6?
98
94
  CONFIG['CXXFLAGS'] << " -std=gnu++11"
99
95
  end
100
- $LDFLAGS << " -L/usr/X11/lib -liconv"
96
+ $LDFLAGS << " -L/usr/X11/lib -liconv -lSDL2 -logg -lvorbis -lvorbisfile"
101
97
  %w(AudioToolbox IOKit OpenAL OpenGL AppKit ApplicationServices Foundation Carbon).each do |f|
102
98
  $LDFLAGS << " -framework #{f}"
103
99
  end
104
100
  else
105
101
  SOURCE_FILES = BASE_FILES + LINUX_FILES
106
102
 
107
- pkg_config 'sdl'
103
+ pkg_config 'sdl2'
108
104
  pkg_config 'pangoft2'
109
- pkg_config 'x11'
110
- pkg_config 'xinerama'
111
105
 
112
106
  pkg_config 'gl'
113
107
  pkg_config 'vorbisfile'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gosu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.50
4
+ version: 0.8.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Raschke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-06 00:00:00.000000000 Z
11
+ date: 2014-04-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  2D game development library.
@@ -135,6 +135,7 @@ files:
135
135
  - GosuImpl/Graphics/TransformStack.hpp
136
136
  - GosuImpl/IO.cpp
137
137
  - GosuImpl/Iconv.hpp
138
+ - GosuImpl/Input.cpp
138
139
  - GosuImpl/Input/AccelerometerReader.hpp
139
140
  - GosuImpl/Input/AccelerometerReader.mm
140
141
  - GosuImpl/InputMac.mm
@@ -154,6 +155,7 @@ files:
154
155
  - GosuImpl/Sockets/MessageSocket.cpp
155
156
  - GosuImpl/Sockets/Socket.cpp
156
157
  - GosuImpl/Sockets/Socket.hpp
158
+ - GosuImpl/TextInput.cpp
157
159
  - GosuImpl/TextInputMac.mm
158
160
  - GosuImpl/TextInputWin.cpp
159
161
  - GosuImpl/TextInputX.cpp
@@ -165,7 +167,7 @@ files:
165
167
  - GosuImpl/UtilityWin.cpp
166
168
  - GosuImpl/WinMain.cpp
167
169
  - GosuImpl/WinUtility.cpp
168
- - GosuImpl/WindowMac.mm
170
+ - GosuImpl/Window.cpp
169
171
  - GosuImpl/WindowTouch.mm
170
172
  - GosuImpl/WindowWin.cpp
171
173
  - GosuImpl/WindowX.cpp
@@ -266,13 +268,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
266
268
  version: 1.8.2
267
269
  required_rubygems_version: !ruby/object:Gem::Requirement
268
270
  requirements:
269
- - - '>='
271
+ - - '>'
270
272
  - !ruby/object:Gem::Version
271
- version: '0'
273
+ version: 1.3.1
272
274
  requirements:
273
275
  - See https://github.com/jlnr/gosu/wiki/Getting-Started-on-Linux
274
276
  rubyforge_project:
275
- rubygems_version: 2.0.3
277
+ rubygems_version: 2.0.14
276
278
  signing_key:
277
279
  specification_version: 4
278
280
  summary: 2D game development library.
@@ -1,574 +0,0 @@
1
- #include <Gosu/Window.hpp>
2
- #include <Gosu/Audio.hpp>
3
- #include <Gosu/Graphics.hpp>
4
- #include <Gosu/Input.hpp>
5
- #include "MacUtility.hpp"
6
- #include <Gosu/Timing.hpp>
7
- #include <Gosu/TR1.hpp>
8
- #include <Gosu/Utility.hpp>
9
- #include <OpenGL/OpenGL.h>
10
- #include <OpenGL/gl.h>
11
- #include <memory>
12
- #include <vector>
13
- using namespace std::tr1::placeholders;
14
-
15
- #import <AppKit/AppKit.h>
16
- #import <ApplicationServices/ApplicationServices.h>
17
- #import <Carbon/Carbon.h>
18
-
19
- namespace Gosu
20
- {
21
- namespace FPS
22
- {
23
- void registerFrame();
24
- }
25
-
26
- NSRect screenRect = [[NSScreen mainScreen] frame];
27
-
28
- unsigned screenWidth()
29
- {
30
- return screenRect.size.width;
31
- }
32
-
33
- unsigned screenHeight()
34
- {
35
- return screenRect.size.height;
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
- }
50
- }
51
-
52
- #ifndef __LP64__
53
- // Workaround for Apple NSScreen bug :(
54
- // TODO - fill in the details ... on which systems does Gosu break without this?
55
- @interface NSScreen (NSScreenAccess)
56
- - (void)setFrame:(NSRect)frame;
57
- @end
58
-
59
- @implementation NSScreen (NSScreenAccess)
60
- - (void)setFrame:(NSRect)frame;
61
- {
62
- _frame = frame;
63
- }
64
- @end
65
- #endif
66
-
67
- // Necessary to catch input events in fullscreen mode
68
- @interface GosuApplication : NSApplication
69
- {
70
- Gosu::Input* input;
71
- }
72
- - (void)sendEvent:(NSEvent *)anEvent;
73
- - (void)setInput:(Gosu::Input&)ipt;
74
- @end
75
- @implementation GosuApplication
76
- - (void)sendEvent:(NSEvent *)anEvent
77
- {
78
- switch ([anEvent type])
79
- {
80
- case NSLeftMouseDown:
81
- case NSLeftMouseUp:
82
- case NSRightMouseDown:
83
- case NSRightMouseUp:
84
- case NSOtherMouseDown:
85
- case NSOtherMouseUp:
86
- case NSScrollWheel:
87
- case NSKeyUp:
88
- case NSKeyDown:
89
- case NSFlagsChanged:
90
- input->feedNSEvent(anEvent);
91
- break;
92
- default:
93
- [super sendEvent:anEvent];
94
- }
95
- }
96
- - (void)setInput:(Gosu::Input&)ipt
97
- {
98
- input = &ipt;
99
- }
100
- @end
101
-
102
- namespace
103
- {
104
- void cgCheck(CGDisplayErr err, const char* action)
105
- {
106
- if (err != CGDisplayNoErr)
107
- throw std::runtime_error(std::string("Core Graphics error while ") + action);
108
- }
109
- }
110
-
111
- typedef void (*WindowProc)(Gosu::Window&);
112
-
113
- @interface GosuForwarder : NSObject
114
- #ifdef __LP64__
115
- <NSWindowDelegate>
116
- #endif
117
- {
118
- Gosu::Window* win;
119
- WindowProc pr;
120
- }
121
- - (id)initWithWindow:(Gosu::Window *)window withProc:(WindowProc)proc;
122
- - (void)doTick:(NSTimer *)timer;
123
- - (BOOL)windowShouldClose:(id)sender;
124
- @end
125
-
126
- @implementation GosuForwarder
127
- - (id)initWithWindow:(Gosu::Window*)window withProc:(WindowProc)proc
128
- {
129
- if ((self = [super init])) {
130
- win = window;
131
- pr = proc;
132
- }
133
- return self;
134
- }
135
-
136
- - (void)doTick:(NSTimer*)timer
137
- {
138
- pr(*win);
139
- }
140
-
141
- - (BOOL)windowShouldClose:(id)sender
142
- {
143
- [NSApp stop:nil];
144
- return YES;
145
- }
146
- @end
147
-
148
- #define OVERRIDE_METHOD(method) \
149
- - (void)method:(NSEvent*) event \
150
- { \
151
- _input->feedNSEvent(event); \
152
- }
153
-
154
- @interface GosuWindow : NSWindow
155
- {
156
- Gosu::Input* _input;
157
- }
158
- @end
159
- @implementation GosuWindow
160
- - (void)setInput:(Gosu::Input *)input
161
- {
162
- _input = input;
163
- }
164
-
165
- OVERRIDE_METHOD(keyDown);
166
- OVERRIDE_METHOD(keyUp);
167
- OVERRIDE_METHOD(flagsChanged);
168
- OVERRIDE_METHOD(mouseDown);
169
- OVERRIDE_METHOD(mouseUp);
170
- OVERRIDE_METHOD(rightMouseDown);
171
- OVERRIDE_METHOD(rightMouseUp);
172
- OVERRIDE_METHOD(otherMouseDown);
173
- OVERRIDE_METHOD(otherMouseUp);
174
- OVERRIDE_METHOD(scrollWheel);
175
- @end
176
-
177
- @interface GosuView : NSView
178
- {
179
- Gosu::Input *_input;
180
- }
181
- @end
182
- @implementation GosuView
183
- - (void)setInput:(Gosu::Input *)input
184
- {
185
- _input = input;
186
-
187
- }
188
- - (BOOL)acceptsFirstResponder
189
- {
190
- return YES;
191
- }
192
- OVERRIDE_METHOD(keyDown);
193
- OVERRIDE_METHOD(keyUp);
194
- OVERRIDE_METHOD(flagsChanged);
195
- OVERRIDE_METHOD(mouseDown);
196
- OVERRIDE_METHOD(mouseUp);
197
- OVERRIDE_METHOD(rightMouseDown);
198
- OVERRIDE_METHOD(rightMouseUp);
199
- OVERRIDE_METHOD(scrollWheel);
200
- @end
201
-
202
- #undef OVERRIDE_METHOD
203
-
204
- #if __MAC_OS_X_VERSION_MAX_ALLOWED < 1070
205
- @interface NSView (GosuProvideMissingMethodDeclaration)
206
- - (NSRect)convertRectToBacking:(NSRect)aRect;
207
- @end
208
- #endif
209
-
210
- struct Gosu::Window::Impl
211
- {
212
- ObjRef<NSAutoreleasePool> pool;
213
-
214
- // Windowed mode: NSWindow subclass and delegate that forwards events to it.
215
- ObjRef<GosuWindow> window;
216
- ObjRef<GosuForwarder> forwarder;
217
-
218
- // Fullscreen mode. Also remember old display mode.
219
- CFDictionaryRef newMode, savedMode;
220
- NSRect savedFrame;
221
-
222
- ObjRef<NSOpenGLContext> context;
223
- std::auto_ptr<Graphics> graphics;
224
- std::auto_ptr<Input> input;
225
- double interval;
226
- bool mouseViz;
227
-
228
- void createWindowAndAdjustWidthHeight(unsigned& width, unsigned& height)
229
- {
230
- NSRect rect = NSMakeRect(0, 0, width, height);
231
- window.reset([[GosuWindow alloc] initWithContentRect:rect styleMask:windowStyleMask
232
- backing:NSBackingStoreBuffered defer:NO]);
233
- [window.obj() retain]; // TODO: Why?
234
-
235
- [window.obj() setContentView:[[GosuView alloc] init]];
236
- if ([[window.obj() contentView] respondsToSelector:@selector(wantsBestResolutionOpenGLSurface)])
237
- {
238
- [[window.obj() contentView] setValue:[NSNumber numberWithBool:YES] forKey:@"wantsBestResolutionOpenGLSurface"];
239
- NSRect pointRect = NSMakeRect(0, 0, width, height);
240
- NSRect backingRect = [(id)[window.obj() contentView] convertRectToBacking:pointRect];
241
- width = backingRect.size.width;
242
- height = backingRect.size.height;
243
- }
244
- [window.obj() center];
245
- }
246
-
247
- static void doTick(Window& window);
248
- };
249
-
250
- // An addition for MacRuby support:
251
- // Without this variable, the context seems to get eaten by the GC. (?)
252
-
253
- static NSOpenGLContext* context;
254
-
255
- Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen,
256
- double updateInterval)
257
- : pimpl(new Impl)
258
- {
259
- if (fullscreen) {
260
- NSLog(@"Fullscreen mode is temporarily unavailable on OS X; see https://github.com/jlnr/gosu/issues/157");
261
- fullscreen = false;
262
- }
263
-
264
- pimpl->pool.reset([[NSAutoreleasePool alloc] init]); // <- necessary...?
265
-
266
- // Create NSApp global variable
267
- if (fullscreen)
268
- [GosuApplication sharedApplication];
269
- else
270
- [NSApplication sharedApplication];
271
-
272
- // Settings, depending on fullscreen or not
273
- NSOpenGLPixelFormatAttribute windowedAttrs[] =
274
- {
275
- NSOpenGLPFADoubleBuffer,
276
- NSOpenGLPFAScreenMask,
277
- (NSOpenGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(CGMainDisplayID()),
278
- NSOpenGLPFADepthSize,
279
- (NSOpenGLPixelFormatAttribute)16,
280
- (NSOpenGLPixelFormatAttribute)0
281
- };
282
- NSOpenGLPixelFormatAttribute fullscreenAttrs[] =
283
- {
284
- NSOpenGLPFADoubleBuffer,
285
- NSOpenGLPFAScreenMask,
286
- (NSOpenGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(CGMainDisplayID()),
287
- NSOpenGLPFAFullScreen,
288
- NSOpenGLPFADepthSize,
289
- (NSOpenGLPixelFormatAttribute)16,
290
- (NSOpenGLPixelFormatAttribute)0
291
- };
292
- NSOpenGLPixelFormatAttribute* attrs = fullscreen ? fullscreenAttrs : windowedAttrs;
293
-
294
- // Create pixel format and OpenGL context
295
- ObjRef<NSOpenGLPixelFormat> fmt([[NSOpenGLPixelFormat alloc] initWithAttributes:attrs]);
296
- if (! fmt.get())
297
- throw std::runtime_error("Could not find a suitable OpenGL pixel format");
298
- ::context = [[NSOpenGLContext alloc] initWithFormat:fmt.obj() shareContext:nil];
299
- pimpl->context.reset(context);
300
- if (! pimpl->context.get())
301
- throw std::runtime_error("Unable to create an OpenGL context with the supplied pixel format");
302
-
303
- unsigned realWidth = width, realHeight = height;
304
- unsigned pixelWidth = width, pixelHeight = height;
305
-
306
- if (fullscreen) {
307
- // Fullscreen: Create no window, instead change resolution.
308
-
309
- // Save old mode and retrieve BPP
310
- pimpl->savedMode = CGDisplayCurrentMode(kCGDirectMainDisplay);
311
- pimpl->savedFrame = [[NSScreen mainScreen] frame];
312
- int bpp;
313
- CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(pimpl->savedMode, kCGDisplayBitsPerPixel),
314
- kCFNumberIntType, &bpp);
315
- pimpl->newMode =
316
- CGDisplayBestModeForParameters(kCGDirectMainDisplay, bpp, width, height, 0);
317
- CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(pimpl->newMode, kCGDisplayWidth),
318
- kCFNumberIntType, &width);
319
- CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(pimpl->newMode, kCGDisplayHeight),
320
- kCFNumberIntType, &height);
321
-
322
- // Actual changing postponed until show().
323
- }
324
- else
325
- {
326
- scaleDownWindowIfNecessary(realWidth, realHeight);
327
- pixelWidth = realWidth;
328
- pixelHeight = realHeight;
329
- pimpl->createWindowAndAdjustWidthHeight(pixelWidth, pixelHeight);
330
- // Tell context to draw on this window.
331
- [pimpl->context.obj() setView:[pimpl->window.obj() contentView]];
332
- }
333
-
334
- CGLEnable((CGLContextObj)[pimpl->context.obj() CGLContextObj], kCGLCEMPEngine);
335
-
336
- [pimpl->context.obj() makeCurrentContext];
337
-
338
- pimpl->graphics.reset(new Gosu::Graphics(pixelWidth, pixelHeight, fullscreen));
339
- pimpl->graphics->setResolution(width, height);
340
-
341
- pimpl->input.reset(new Input(pimpl->window.get()));
342
- pimpl->input->onButtonDown = std::tr1::bind(&Window::buttonDown, this, _1);
343
- pimpl->input->onButtonUp = std::tr1::bind(&Window::buttonUp, this, _1);
344
- pimpl->input->setMouseFactors(1.0 * width / realWidth, 1.0 * height / realHeight);
345
- if (fullscreen)
346
- [NSApp setInput:input()];
347
-
348
- pimpl->forwarder.reset([[GosuForwarder alloc] initWithWindow:this withProc:&Impl::doTick]);
349
-
350
- if (! fullscreen)
351
- {
352
- [pimpl->window.obj() setDelegate:pimpl->forwarder.obj()];
353
- [pimpl->window.obj() setInput:pimpl->input.get()];
354
- [(GosuView*)[pimpl->window.obj() contentView] setInput:pimpl->input.get()];
355
- // Finally, safely hide the window.
356
- [pimpl->window.obj() orderOut:nil];
357
- }
358
-
359
- pimpl->interval = updateInterval;
360
- pimpl->mouseViz = true;
361
-
362
- // Clear gl error flag if it should accidentally be set. (Huh?)
363
- while (glGetError() != GL_NO_ERROR);
364
- }
365
-
366
- Gosu::Window::~Window()
367
- {
368
- if (graphics().fullscreen())
369
- {
370
- CGDisplaySwitchToMode(kCGDirectMainDisplay, pimpl->savedMode);
371
- #ifndef __LP64__
372
- [[NSScreen mainScreen] setFrame:pimpl->savedFrame];
373
- #endif
374
- CGReleaseAllDisplays();
375
- }
376
- }
377
-
378
- std::wstring Gosu::Window::caption() const
379
- {
380
- ObjRef<NSAutoreleasePool> pool([[NSAutoreleasePool alloc] init]);
381
- const char* utf8 = [[pimpl->window.get() title] UTF8String];
382
- return utf8 ? Gosu::utf8ToWstring(utf8) : std::wstring();
383
- }
384
-
385
- void Gosu::Window::setCaption(const std::wstring& caption)
386
- {
387
- std::string utf8 = wstringToUTF8(caption);
388
- ObjRef<NSString> title([[NSString alloc] initWithUTF8String:utf8.c_str()]);
389
- [pimpl->window.get() setTitle:title.obj()];
390
- }
391
-
392
- double Gosu::Window::updateInterval() const
393
- {
394
- return pimpl->interval;
395
- }
396
-
397
- void Gosu::Window::show()
398
- {
399
- // This is for Ruby/Gosu and misc. hackery:
400
- // Usually, applications on the Mac can only get keyboard and mouse input if
401
- // run by double-clicking an .app. So if this is run from the Terminal (i.e.
402
- // during Ruby/Gosu game development), tell the OS we need input in any case.
403
- ProcessSerialNumber psn = { 0, kCurrentProcess };
404
- TransformProcessType(&psn, kProcessTransformToForegroundApplication);
405
- SetFrontProcess(&psn);
406
-
407
- [NSThread setThreadPriority:1.0];
408
-
409
- if (graphics().fullscreen())
410
- {
411
- // Set new mode
412
- cgCheck(CGDisplayCapture(kCGDirectMainDisplay), "capturing display");
413
- cgCheck(CGDisplaySwitchToMode(kCGDirectMainDisplay, pimpl->newMode), "switching mode");
414
-
415
- // Start drawing in fullscreen
416
- [pimpl->context.obj() setFullScreen];
417
- }
418
- else
419
- [pimpl->window.obj() makeKeyAndOrderFront:nil];
420
-
421
- NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:pimpl->interval / 1000.0
422
- target:pimpl->forwarder.obj() selector:@selector(doTick:)
423
- userInfo:nil repeats:YES];
424
- [NSApp run];
425
- [timer invalidate];
426
-
427
- if (graphics().fullscreen())
428
- {
429
- // Resetting the mode shouldn't be all too important according to the docs.
430
- // Let's leave it in until time for testing comes, though.
431
- CGDisplaySwitchToMode(kCGDirectMainDisplay, pimpl->savedMode);
432
- CGDisplayRelease(kCGDirectMainDisplay);
433
- }
434
- else
435
- {
436
- [pimpl->window.obj() orderOut:nil];
437
- }
438
- }
439
-
440
- void Gosu::Window::close()
441
- {
442
- [NSApp stop:nil];
443
-
444
- // NSApp doesn't check its 'stopped' flag until it finishes processing
445
- // the next event (timers are not events), so here's a rather hacky way
446
- // to make sure it has one in its queue
447
- [NSApp postEvent:[NSEvent otherEventWithType:NSApplicationDefined
448
- location:NSZeroPoint
449
- modifierFlags:0
450
- timestamp:0.0
451
- windowNumber:0
452
- context:NULL
453
- subtype:0
454
- data1:0
455
- data2:0] atStart:NO];
456
- }
457
-
458
- const Gosu::Graphics& Gosu::Window::graphics() const
459
- {
460
- return *pimpl->graphics;
461
- }
462
-
463
- Gosu::Graphics& Gosu::Window::graphics()
464
- {
465
- return *pimpl->graphics;
466
- }
467
-
468
- const Gosu::Input& Gosu::Window::input() const
469
- {
470
- return *pimpl->input;
471
- }
472
-
473
- Gosu::Input& Gosu::Window::input()
474
- {
475
- return *pimpl->input;
476
- }
477
-
478
- namespace
479
- {
480
- void makeCurrentContext(NSOpenGLContext *context)
481
- {
482
- [context makeCurrentContext];
483
- }
484
-
485
- void releaseContextAndDelete(NSOpenGLContext *context, std::tr1::function<void()> *function)
486
- {
487
- [context release];
488
- delete function;
489
- }
490
- }
491
-
492
- Gosu::Window::SharedContext Gosu::Window::createSharedContext()
493
- {
494
- NSOpenGLPixelFormatAttribute attributes[] = {
495
- NSOpenGLPFADoubleBuffer,
496
- NSOpenGLPFAScreenMask,
497
- (NSOpenGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(CGMainDisplayID()),
498
- NSOpenGLPFAFullScreen,
499
- NSOpenGLPFANoRecovery,
500
- (NSOpenGLPixelFormatAttribute)0
501
- };
502
-
503
- NSOpenGLPixelFormat* pf = [[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes] autorelease];
504
-
505
- NSOpenGLContext* ctx = [[NSOpenGLContext alloc] initWithFormat:pf shareContext:pimpl->context.obj()];
506
-
507
- // TODO: Exception safety? Oh man, is this construction really worth it? :)
508
- std::tr1::function<void()> *makeCurrent =
509
- new std::tr1::function<void()>(std::tr1::bind(makeCurrentContext, ctx));
510
- return SharedContext(makeCurrent,
511
- std::tr1::bind(releaseContextAndDelete, ctx, _1));
512
- }
513
-
514
- namespace GosusDarkSide
515
- {
516
- // TODO: Find a way for this to fit into Gosu's design.
517
- // This can point to a function that wants to be called every
518
- // frame, e.g. rb_thread_schedule.
519
- typedef void (*HookOfHorror)();
520
- HookOfHorror oncePerTick = 0;
521
- }
522
-
523
- void Gosu::Window::Impl::doTick(Window& window)
524
- {
525
- // Enable vsync.
526
- GLint value = 1;
527
- [window.pimpl->context.obj() setValues:&value forParameter:NSOpenGLCPSwapInterval];
528
-
529
- if ((window.graphics().fullscreen() ||
530
- NSPointInRect([window.pimpl->window.obj() mouseLocationOutsideOfEventStream],
531
- [[window.pimpl->window.obj() contentView] frame])) &&
532
- [NSApp isActive] && !window.needsCursor())
533
- {
534
- if (window.pimpl->mouseViz)
535
- [NSCursor hide];
536
- window.pimpl->mouseViz = false;
537
- }
538
- else
539
- {
540
- if (! window.pimpl->mouseViz)
541
- [NSCursor unhide];
542
- window.pimpl->mouseViz = true;
543
- }
544
-
545
- Gosu::Song::update();
546
- window.input().update();
547
- window.update();
548
-
549
- if (window.needsRedraw() and window.graphics().begin())
550
- {
551
- FPS::registerFrame();
552
- window.draw();
553
- window.graphics().end();
554
- [window.pimpl->context.obj() flushBuffer];
555
- }
556
-
557
- if (GosusDarkSide::oncePerTick) GosusDarkSide::oncePerTick();
558
- }
559
-
560
- // Deprecated.
561
-
562
- class Gosu::Audio {};
563
- namespace { Gosu::Audio dummyAudio; }
564
-
565
- const Gosu::Audio& Gosu::Window::audio() const
566
- {
567
- return dummyAudio;
568
- }
569
-
570
- Gosu::Audio& Gosu::Window::audio()
571
- {
572
- return dummyAudio;
573
- }
574
-