gosu 0.7.22 → 0.7.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/Gosu/Audio.hpp +2 -0
  2. data/Gosu/Fwd.hpp +0 -1
  3. data/Gosu/Gosu.hpp +1 -1
  4. data/Gosu/Graphics.hpp +12 -11
  5. data/Gosu/GraphicsBase.hpp +5 -0
  6. data/Gosu/Image.hpp +0 -14
  7. data/Gosu/Input.hpp +32 -18
  8. data/Gosu/Text.hpp +3 -2
  9. data/Gosu/Version.hpp +2 -2
  10. data/Gosu/Window.hpp +21 -8
  11. data/GosuImpl/Audio/AudioOpenAL.mm +74 -8
  12. data/GosuImpl/Graphics/Common.hpp +25 -1
  13. data/GosuImpl/Graphics/DrawOp.hpp +54 -222
  14. data/GosuImpl/Graphics/DrawOpQueue.hpp +127 -0
  15. data/GosuImpl/Graphics/FormattedString.hpp +63 -20
  16. data/GosuImpl/Graphics/GosuView.hpp +5 -8
  17. data/GosuImpl/Graphics/GosuView.mm +36 -65
  18. data/GosuImpl/Graphics/Graphics.cpp +121 -110
  19. data/GosuImpl/Graphics/Image.cpp +0 -51
  20. data/GosuImpl/Graphics/Macro.hpp +1 -0
  21. data/GosuImpl/Graphics/RenderState.hpp +107 -0
  22. data/GosuImpl/Graphics/TexChunk.cpp +1 -10
  23. data/GosuImpl/Graphics/Text.cpp +22 -10
  24. data/GosuImpl/Graphics/TextMac.cpp +2 -4
  25. data/GosuImpl/Graphics/TextTouch.mm +14 -21
  26. data/GosuImpl/Graphics/TextWin.cpp +5 -2
  27. data/GosuImpl/Graphics/Texture.cpp +11 -10
  28. data/GosuImpl/Graphics/Transform.cpp +3 -1
  29. data/GosuImpl/Input/AccelerometerReader.hpp +10 -0
  30. data/GosuImpl/Input/AccelerometerReader.mm +31 -0
  31. data/GosuImpl/InputMac.mm +51 -24
  32. data/GosuImpl/InputTouch.mm +112 -1
  33. data/GosuImpl/InputWin.cpp +27 -3
  34. data/GosuImpl/InputX.cpp +21 -0
  35. data/GosuImpl/MacUtility.hpp +33 -0
  36. data/GosuImpl/Orientation.hpp +15 -0
  37. data/GosuImpl/Orientation.mm +34 -0
  38. data/GosuImpl/RubyGosu.swg +7 -9
  39. data/GosuImpl/RubyGosu_wrap.cxx +328 -82
  40. data/GosuImpl/RubyGosu_wrap.h +3 -0
  41. data/GosuImpl/TextInputWin.cpp +2 -0
  42. data/GosuImpl/Utility.cpp +2 -0
  43. data/GosuImpl/WindowMac.mm +13 -19
  44. data/GosuImpl/WindowTouch.mm +44 -32
  45. data/GosuImpl/WindowWin.cpp +20 -12
  46. data/GosuImpl/WindowX.cpp +33 -23
  47. data/examples/CptnRuby.rb +8 -9
  48. data/lib/gosu.rb +0 -0
  49. data/lib/gosu/swig_patches.rb +0 -12
  50. data/linux/extconf.rb +2 -2
  51. metadata +11 -7
  52. data/Gosu/RotFlip.hpp +0 -125
  53. data/GosuImpl/Graphics/RotFlip.cpp +0 -184
@@ -33,6 +33,9 @@ public:
33
33
  virtual void update();
34
34
  virtual void draw();
35
35
  virtual bool needsRedraw() const;
36
+ virtual bool needsCursor() const;
37
+ virtual void loseFocus();
38
+ virtual void releaseMemory();
36
39
  virtual void buttonDown(Gosu::Button arg0);
37
40
  virtual void buttonUp(Gosu::Button arg0);
38
41
  };
@@ -5,7 +5,9 @@
5
5
  #include <wctype.h>
6
6
 
7
7
  // OPT-IN, have you heard of it?!
8
+ #ifndef NOMINMAX
8
9
  #define NOMINMAX
10
+ #endif
9
11
  #include <windows.h>
10
12
 
11
13
  struct Gosu::TextInput::Impl
@@ -53,7 +53,9 @@ namespace Gosu {
53
53
 
54
54
  #endif
55
55
  #else
56
+ #ifndef NOMINMAX
56
57
  #define NOMINMAX
58
+ #endif
57
59
  #include <windows.h>
58
60
  wstring Gosu::utf8ToWstring(const string& utf8)
59
61
  {
@@ -370,8 +370,6 @@ void Gosu::Window::show()
370
370
 
371
371
  if (graphics().fullscreen())
372
372
  {
373
- [NSCursor hide];
374
-
375
373
  // Set new mode
376
374
  cgCheck(CGDisplayCapture(kCGDirectMainDisplay), "capturing display");
377
375
  cgCheck(CGDisplaySwitchToMode(kCGDirectMainDisplay, pimpl->newMode), "switching mode");
@@ -389,8 +387,6 @@ void Gosu::Window::show()
389
387
 
390
388
  if (graphics().fullscreen())
391
389
  {
392
- [NSCursor unhide];
393
-
394
390
  // Resetting the mode shouldn't be all too important according to the docs.
395
391
  // Let's leave it in until time for testing comes, though.
396
392
  CGDisplaySwitchToMode(kCGDirectMainDisplay, pimpl->savedMode);
@@ -487,22 +483,20 @@ void Gosu::Window::Impl::doTick(Window& window)
487
483
  GLint value = 1;
488
484
  [window.pimpl->context.obj() setValues: &value forParameter: NSOpenGLCPSwapInterval];
489
485
 
490
- if (!window.graphics().fullscreen())
486
+ if ((window.graphics().fullscreen() ||
487
+ NSPointInRect([window.pimpl->window.obj() mouseLocationOutsideOfEventStream],
488
+ [[window.pimpl->window.obj() contentView] frame])) &&
489
+ [NSApp isActive] && !window.needsCursor())
490
+ {
491
+ if (window.pimpl->mouseViz)
492
+ [NSCursor hide];
493
+ window.pimpl->mouseViz = false;
494
+ }
495
+ else
491
496
  {
492
- if (NSPointInRect([window.pimpl->window.obj() mouseLocationOutsideOfEventStream],
493
- [[window.pimpl->window.obj() contentView] frame]) &&
494
- [NSApp isActive])
495
- {
496
- if (window.pimpl->mouseViz)
497
- [NSCursor hide];
498
- window.pimpl->mouseViz = false;
499
- }
500
- else
501
- {
502
- if (not window.pimpl->mouseViz)
503
- [NSCursor unhide];
504
- window.pimpl->mouseViz = true;
505
- }
497
+ if (not window.pimpl->mouseViz)
498
+ [NSCursor unhide];
499
+ window.pimpl->mouseViz = true;
506
500
  }
507
501
 
508
502
  Gosu::Song::update();
@@ -1,9 +1,11 @@
1
- #import <Gosu/Window.hpp>
2
- #import <Gosu/Graphics.hpp>
3
- #import <Gosu/Audio.hpp>
4
- #import <Gosu/Input.hpp>
5
- #import <GosuImpl/MacUtility.hpp>
6
- #import <GosuImpl/Graphics/GosuView.hpp>
1
+ #include <Gosu/Window.hpp>
2
+ #include <Gosu/Graphics.hpp>
3
+ #include <Gosu/Audio.hpp>
4
+ #include <Gosu/Input.hpp>
5
+ #include <GosuImpl/MacUtility.hpp>
6
+ #include <GosuImpl/Graphics/GosuView.hpp>
7
+ #include <boost/bind.hpp>
8
+
7
9
  #import <CoreGraphics/CoreGraphics.h>
8
10
  #import <UIKit/UIKit.h>
9
11
  #import <OpenGLES/EAGL.h>
@@ -23,16 +25,15 @@ namespace Gosu {
23
25
  }
24
26
 
25
27
  int main(int argc, char *argv[]) {
26
- Gosu::ObjRef<NSAutoreleasePool> pool([[NSAutoreleasePool alloc] init]);
28
+ [[NSAutoreleasePool alloc] init];
27
29
  return UIApplicationMain(argc, argv, nil, @"GosuAppDelegate");
28
30
  }
29
31
 
30
32
  class Gosu::Audio {};
31
33
 
32
34
  struct Gosu::Window::Impl {
33
- ObjRef<NSAutoreleasePool> pool;
34
35
  ObjRef<UIWindow> window;
35
- ObjRef<GosuView> view;
36
+ ObjRef<GosuViewController> controller;
36
37
  boost::scoped_ptr<Graphics> graphics;
37
38
  boost::scoped_ptr<Audio> audio;
38
39
  boost::scoped_ptr<Input> input;
@@ -45,17 +46,19 @@ Gosu::Window& windowInstance();
45
46
  }
46
47
  @end
47
48
 
48
- // Ugly monkey patching to bridge the C++ and ObjC sides.
49
49
  namespace
50
50
  {
51
+ // Ugly patching to bridge the C++ and ObjC sides.
51
52
  GosuView* gosuView = nil;
53
+ bool pausedSong = false;
54
+ bool paused = false;
52
55
  }
53
56
 
54
57
  @implementation GosuAppDelegate
55
58
  - (void)applicationDidFinishLaunching:(UIApplication *)application {
56
- [[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
57
- [UIApplication sharedApplication].idleTimerDisabled = YES;
58
- [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
59
+ [UIDevice.currentDevice beginGeneratingDeviceOrientationNotifications];
60
+ UIApplication.sharedApplication.idleTimerDisabled = YES;
61
+ UIApplication.sharedApplication.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
59
62
 
60
63
  windowInstance();
61
64
 
@@ -67,17 +70,31 @@ namespace
67
70
  }
68
71
 
69
72
  - (void)applicationWillResignActive:(UIApplication *)application {
70
- // TODO: stop updating; periodically draw
73
+ if (Gosu::Song::currentSong())
74
+ {
75
+ Gosu::Song::currentSong()->pause();
76
+ pausedSong = true;
77
+ }
78
+ paused = true;
79
+ windowInstance().loseFocus();
71
80
  }
72
81
 
73
82
  - (void)applicationDidBecomeActive:(UIApplication *)application {
74
- // TODO: start updating again
83
+ if (pausedSong)
84
+ {
85
+ if (Gosu::Song::currentSong())
86
+ Gosu::Song::currentSong()->play();
87
+ pausedSong = false;
88
+ }
89
+ paused = false;
75
90
  }
76
91
 
77
92
  - (void)doTick:(NSTimer*)timer {
78
- windowInstance().update();
93
+ if (!paused)
94
+ windowInstance().update();
79
95
  [gosuView drawView];
80
- [gosuView removeDeadTouches];
96
+ Gosu::Song::update();
97
+ windowInstance().input().update();
81
98
  }
82
99
  @end
83
100
 
@@ -85,17 +102,18 @@ Gosu::Window::Window(unsigned width, unsigned height,
85
102
  bool fullscreen, double updateInterval)
86
103
  : pimpl(new Impl)
87
104
  {
88
- pimpl->pool.reset([[NSAutoreleasePool alloc] init]);
89
105
  pimpl->window.reset([[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]);
90
- pimpl->view.reset([[GosuView alloc] initWithFrame:[pimpl->window.obj() bounds]]);
91
- gosuView = pimpl->view.obj();
92
-
93
- [pimpl->window.obj() addSubview: pimpl->view.obj()];
106
+ pimpl->controller.reset([[GosuViewController alloc] init]);
107
+ gosuView = (GosuView*)pimpl->controller.obj().view;
108
+ [pimpl->window.obj() addSubview: gosuView];
94
109
 
95
- pimpl->graphics.reset(new Graphics(320, 480, false));
96
- pimpl->graphics->setResolution(480, 320);
110
+ pimpl->graphics.reset(new Graphics(screenWidth(), screenHeight(), false));
111
+ pimpl->graphics->setResolution(screenHeight(), screenWidth());
97
112
  pimpl->audio.reset(new Audio());
98
- pimpl->input.reset(new Input());
113
+ pimpl->input.reset(new Input(gosuView, updateInterval));
114
+ pimpl->input->onTouchBegan = boost::bind(&Window::touchBegan, this, _1);
115
+ pimpl->input->onTouchMoved = boost::bind(&Window::touchMoved, this, _1);
116
+ pimpl->input->onTouchEnded = boost::bind(&Window::touchEnded, this, _1);
99
117
  pimpl->interval = updateInterval;
100
118
 
101
119
  [pimpl->window.obj() makeKeyAndVisible];
@@ -143,15 +161,9 @@ Gosu::Input& Gosu::Window::input() {
143
161
 
144
162
  void Gosu::Window::show()
145
163
  {
146
- throw std::logic_error("Gosu::Window::show not available on iPhone");
147
164
  }
148
165
 
149
166
  void Gosu::Window::close()
150
167
  {
151
- throw "NYI";
152
- }
153
-
154
- const Gosu::Touches& Gosu::Window::currentTouches() const
155
- {
156
- return [pimpl->view.obj() currentTouches];
168
+ throw std::logic_error("Cannot close windows manually on iOS");
157
169
  }
@@ -1,4 +1,6 @@
1
- #define NOMINMAX // RAGE >_<
1
+ #ifndef NOMINMAX
2
+ #define NOMINMAX
3
+ #endif // RAGE >_<
2
4
 
3
5
  #include <Gosu/Window.hpp>
4
6
  #include <Gosu/WinUtility.hpp>
@@ -156,7 +158,6 @@ namespace Gosu
156
158
  wc.hIconSm = (HICON)CopyImage(wc.hIcon, IMAGE_ICON,
157
159
  GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
158
160
  LR_COPYFROMRESOURCE | LR_COPYRETURNORG);
159
-
160
161
 
161
162
  name = reinterpret_cast<LPCTSTR>(RegisterClassEx(&wc));
162
163
  Win::check(name, "registering a window class");
@@ -197,7 +198,6 @@ Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen,
197
198
  pimpl->originalWidth = width;
198
199
  pimpl->originalHeight = height;
199
200
 
200
- // Select window styles depending on mode.fullscreen.
201
201
  DWORD style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
202
202
  DWORD styleEx = WS_EX_APPWINDOW;
203
203
  if (fullscreen)
@@ -257,7 +257,7 @@ Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen,
257
257
  width *= factor, height *= factor;
258
258
  }
259
259
 
260
- // Determine the size the window needs to have.
260
+ // Determine the size the window needs to have including UI chrome.
261
261
  RECT rc = { 0, 0, width, height };
262
262
  AdjustWindowRectEx(&rc, style, FALSE, styleEx);
263
263
  unsigned windowW = rc.right - rc.left;
@@ -357,6 +357,10 @@ void Gosu::Window::show()
357
357
  {
358
358
  lastTick = ms;
359
359
  input().update();
360
+ // TODO: Bad heuristic -- this causes flickering cursor on right and bottom border of the
361
+ // window.
362
+ if (input().mouseX() >= 0 && input().mouseY() >= 0)
363
+ SendMessage(handle(), WM_SETCURSOR, reinterpret_cast<WPARAM>(handle()), HTCLIENT);
360
364
  update();
361
365
  if (needsRedraw())
362
366
  ::InvalidateRect(handle(), 0, FALSE);
@@ -412,6 +416,18 @@ HWND Gosu::Window::handle() const
412
416
 
413
417
  LRESULT Gosu::Window::handleMessage(UINT message, WPARAM wparam, LPARAM lparam)
414
418
  {
419
+ if (message == WM_SETCURSOR)
420
+ {
421
+ if (LOWORD(lparam) != HTCLIENT || GetForegroundWindow() != handle() || needsCursor())
422
+ {
423
+ static const HCURSOR arrowCursor = LoadCursor(0, IDC_ARROW);
424
+ SetCursor(arrowCursor);
425
+ }
426
+ else
427
+ SetCursor(NULL);
428
+ return TRUE;
429
+ }
430
+
415
431
  if (message == WM_SETFOCUS && graphics().fullscreen() && IsWindowVisible(pimpl->handle))
416
432
  {
417
433
  if (pimpl->iconified)
@@ -461,12 +477,6 @@ LRESULT Gosu::Window::handleMessage(UINT message, WPARAM wparam, LPARAM lparam)
461
477
  return 0;
462
478
  }
463
479
 
464
- if (message == WM_SETCURSOR && LOWORD(lparam) == HTCLIENT)
465
- {
466
- SetCursor(0);
467
- return TRUE;
468
- }
469
-
470
480
  if (message == WM_SYSCOMMAND)
471
481
  {
472
482
  switch(wparam)
@@ -483,9 +493,7 @@ LRESULT Gosu::Window::handleMessage(UINT message, WPARAM wparam, LPARAM lparam)
483
493
  }
484
494
 
485
495
  if (pimpl->input && input().textInput() && input().textInput()->feedMessage(message, wparam, lparam))
486
- {
487
496
  return 0;
488
- }
489
497
 
490
498
  return DefWindowProc(handle(), message, wparam, lparam);
491
499
  }
@@ -83,6 +83,9 @@ struct Gosu::Window::Impl
83
83
 
84
84
  bool mapped, showing, active;
85
85
 
86
+ Cursor emptyCursor;
87
+ bool showingCursor;
88
+
86
89
  ::GLXContext context;
87
90
  ::Window window;
88
91
  ::XVisualInfo* visual;
@@ -150,6 +153,17 @@ struct Gosu::Window::Impl
150
153
  }
151
154
  }
152
155
 
156
+ if (showingCursor && !window->needsCursor())
157
+ {
158
+ XUndefineCursor(display, this->window);
159
+ showingCursor = false;
160
+ }
161
+ else if (!showingCursor && window->needsCursor())
162
+ {
163
+ XDefineCursor(display, this->window, emptyCursor);
164
+ showingCursor = true;
165
+ }
166
+
153
167
  window->input().update();
154
168
  window->update();
155
169
 
@@ -237,10 +251,9 @@ Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen,
237
251
  char emptyData[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
238
252
  Pixmap emptyBitmap =
239
253
  XCreateBitmapFromData(pimpl->display, pimpl->window, emptyData, 8, 8);
240
- Cursor emptyCursor = XCreatePixmapCursor(pimpl->display, emptyBitmap,
254
+ pimpl->emptyCursor = XCreatePixmapCursor(pimpl->display, emptyBitmap,
241
255
  emptyBitmap, &black, &black, 0, 0);
242
- XDefineCursor(pimpl->display, pimpl->window, emptyCursor);
243
- XFreeCursor(pimpl->display, emptyCursor);
256
+ pimpl->showingCursor = true; // Empty cursor not yet installed
244
257
 
245
258
  // Must be current already so that Graphics' constructor can set up things
246
259
  glXMakeCurrent(pimpl->display, pimpl->window, pimpl->context);
@@ -262,6 +275,7 @@ Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen,
262
275
 
263
276
  Gosu::Window::~Window()
264
277
  {
278
+ XFreeCursor(pimpl->display, pimpl->emptyCursor);
265
279
  XDestroyWindow(pimpl->display, pimpl->window);
266
280
  XSync(pimpl->display, false);
267
281
  }
@@ -282,10 +296,6 @@ void Gosu::Window::setCaption(const std::wstring& caption)
282
296
 
283
297
  pimpl->title = caption;
284
298
 
285
- // TODO: Why?!
286
- //if (!pimpl->showing)
287
- // return;
288
-
289
299
  std::string tmpString(pimpl->title.begin(), pimpl->title.end());
290
300
  std::vector<char> title(pimpl->title.size() + 1);
291
301
  std::copy(tmpString.begin(), tmpString.end(), title.begin());
@@ -394,20 +404,20 @@ Gosu::Window::SharedContext Gosu::Window::createSharedContext() {
394
404
  return SharedContext(
395
405
  new boost::function<void()>(boost::bind(makeCurrentContext, dpy2, pimpl->window, ctx)),
396
406
  boost::bind(releaseContext, dpy2, ctx));
397
- }
398
-
399
- // Deprecated.
400
-
401
- class Gosu::Audio {};
402
- namespace { Gosu::Audio dummyAudio; }
403
-
404
- const Gosu::Audio& Gosu::Window::audio() const
405
- {
406
- return dummyAudio;
407
- }
408
-
409
- Gosu::Audio& Gosu::Window::audio()
410
- {
411
- return dummyAudio;
412
- }
407
+ }
408
+
409
+ // Deprecated.
410
+
411
+ class Gosu::Audio {};
412
+ namespace { Gosu::Audio dummyAudio; }
413
+
414
+ const Gosu::Audio& Gosu::Window::audio() const
415
+ {
416
+ return dummyAudio;
417
+ }
418
+
419
+ Gosu::Audio& Gosu::Window::audio()
420
+ {
421
+ return dummyAudio;
422
+ }
413
423
 
@@ -25,15 +25,14 @@
25
25
  # ...Enemies, a more sophisticated object system, weapons, title and credits
26
26
  # screens...
27
27
 
28
- require '../lib/gosu'
29
- # begin
30
- # # In case you use Gosu via rubygems.
31
- # require 'rubygems'
32
- # rescue LoadError
33
- # # In case you don't.
34
- # end
35
- #
36
- # require 'gosu'
28
+ begin
29
+ # In case you use Gosu via rubygems.
30
+ require 'rubygems'
31
+ rescue LoadError
32
+ # In case you don't.
33
+ end
34
+
35
+ require 'gosu'
37
36
  include Gosu
38
37
 
39
38
  module Tiles
File without changes
@@ -7,15 +7,3 @@ class Gosu::Image
7
7
  args.size == 4 ? from_text4(*args) : from_text7(*args)
8
8
  end
9
9
  end
10
-
11
- # Linux workaround: instead of declaring a constant, we declare a hidden function and
12
- # call it when we need to define the constant. Otherwise, we get a weird libGL.so segfault.
13
- module Gosu
14
- def self.const_missing sym
15
- if sym == :MAX_TEXTURE_SIZE then
16
- const_set sym, __max_texture_size
17
- else
18
- super
19
- end
20
- end
21
- end
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- if defined? RUBY_PLATFORM and (RUBY_PLATFORM['-win32'] or RUBY_PLATFORM['win32-'] or RUBY_PLATFORM['-mingw32']) then
3
+ if defined? RUBY_PLATFORM and (RUBY_PLATFORM['-win32'] or RUBY_PLATFORM['win32-'] or RUBY_PLATFORM['mswin'] or RUBY_PLATFORM['mingw32']) then
4
4
  puts 'This gem is not meant to be installed on Windows. If you see this message, gem made a mistake.'
5
5
  puts 'On Windows, please use:'
6
6
  puts 'gem install gosu --platform=i386-mingw32'
@@ -17,7 +17,7 @@ SOURCE_FILES =
17
17
  %w(Math.cpp Utility.cpp IO.cpp FileUnix.cpp InputX.cpp TextInputX.cpp TimingUnix.cpp WindowX.cpp
18
18
  Graphics/Bitmap.cpp Graphics/BitmapUtils.cpp Graphics/Color.cpp
19
19
  Graphics/TexChunk.cpp Graphics/Graphics.cpp Graphics/Image.cpp
20
- Graphics/RotFlip.cpp Graphics/BlockAllocator.cpp
20
+ Graphics/BlockAllocator.cpp
21
21
  Graphics/Texture.cpp Graphics/LargeImageData.cpp
22
22
  Graphics/BitmapPNG.cpp Graphics/Font.cpp Graphics/BitmapBMP.cpp
23
23
  Graphics/TextUnix.cpp Graphics/Text.cpp Graphics/Transform.cpp