gosu 0.7.41 → 0.7.43

Sign up to get free protection for your applications and to get access to all the features.
data/COPYING CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2004-2011 Julian Raschke, Jan Lücker and all contributors.
1
+ Copyright (C) 2004-2012 Julian Raschke, Jan Lücker and all contributors.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a
4
4
  copy of this software and associated documentation files (the "Software"),
@@ -67,8 +67,8 @@ namespace Gosu
67
67
  kbRightControl = XK_Control_R,
68
68
  kbLeftAlt = XK_Alt_L,
69
69
  kbRightAlt = XK_Alt_R,
70
- kbLeftMeta = 0, // TODO?!
71
- kbRightMeta = 0,
70
+ kbLeftMeta = XK_Meta_L,
71
+ kbRightMeta = XK_Meta_R,
72
72
  kbBackspace = XK_BackSpace,
73
73
  kbLeft = XK_Left,
74
74
  kbRight = XK_Right,
@@ -3,8 +3,8 @@
3
3
 
4
4
  #define GOSU_MAJOR_VERSION 0
5
5
  #define GOSU_MINOR_VERSION 7
6
- #define GOSU_POINT_VERSION 41
7
- #define GOSU_VERSION "0.7.41"
6
+ #define GOSU_POINT_VERSION 43
7
+ #define GOSU_VERSION "0.7.43"
8
8
 
9
9
  #define GOSU_COPYRIGHT_NOTICE \
10
10
  " " \
@@ -13,11 +13,157 @@
13
13
 
14
14
  class Gosu::Macro : public Gosu::ImageData
15
15
  {
16
+ typedef double Float;
17
+
16
18
  Graphics& graphics;
17
19
  VertexArrays vertexArrays;
18
- int givenWidth, givenHeight;
20
+ int w, h;
19
21
 
20
- void realDraw(double x1, double y1, double x2, double y3) const
22
+ Transform findTransformForTarget(Float x1, Float y1, Float x2, Float y2, Float x3, Float y3, Float x4, Float y4) const
23
+ {
24
+ // Transformation logic follows a discussion on the ImageMagick mailing
25
+ // list (on which ImageMagick's perspective_transform.pl is based).
26
+
27
+ // To draw a macro at an arbitrary position, we solve the following system:
28
+
29
+ // 0, 0, 1, 0, 0, 0, 0, 0 | x1
30
+ // 0, 0, 0, 0, 0, 1, 0, 0 | y1
31
+ // w, 0, 1, 0, 0, 0, -x2w, 0 | x2
32
+ // 0, 0, 0, w, 0, 1, -y2w, 0 | y2
33
+ // 0, h, 1, 0, 0, 0, 0, -x3h | x3
34
+ // 0, 0, 0, 0, h, 1, 0, -y3h | y3
35
+ // w, h, 1, 0, 0, 0, -x4w, -x4h | x4
36
+ // 0, 0, 0, w, h, 1, -y4w, -y4h | y4
37
+
38
+ // Equivalent:
39
+
40
+ // 0, 0, 1, 0, 0, 0, 0, 0 | x1
41
+ // 0, 0, 0, 0, 0, 1, 0, 0 | y1
42
+ // w, 0, 0, 0, 0, 0, -x2w, 0 | x2-x1
43
+ // 0, 0, 0, w, 0, 0, -y2w, 0 | y2-y1
44
+ // 0, h, 0, 0, 0, 0, 0, -x3h | x3-x1
45
+ // 0, 0, 0, 0, h, 0, 0, -y3h | y3-y1
46
+ // 0, 0, 0, 0, 0, 0, (x2-x4)w, (x3-x4)h | x1-x2-x3+x4
47
+ // 0, 0, 0, 0, 0, 0, (y2-y4)w, (y3-y4)h | y1-y2-y3+y4
48
+
49
+ // Since this matrix is relatively sparse, we unroll all three solving paths.
50
+
51
+ static const Transform nullTransform = { 0 };
52
+
53
+ // Row 7 is completely useless
54
+ if (x2 == x4 && x3 == x4)
55
+ return nullTransform;
56
+ // Row 8 is completely useless
57
+ if (y2 == y3 && y3 == y4)
58
+ return nullTransform;
59
+ // Col 7 is completely useless
60
+ if (x2 == x4 && y2 == y4)
61
+ return nullTransform;
62
+ // Col 8 is completely useless
63
+ if (x3 == x4 && y3 == y4)
64
+ return nullTransform;
65
+
66
+ Float c[8];
67
+
68
+ // Rows 1, 2
69
+ c[2] = x1, c[5] = y1;
70
+
71
+ // The logic below assumes x2 != x4, i.e. row7 can be used to eliminate
72
+ // the leftmost value in row 8 and afterwards the values in rows 3 & 4.
73
+ // If x2 == x4, we need to exchange rows 7 and 8.
74
+
75
+ // TODO: x2==x4 is the normal case where an image is
76
+ // drawn upright; the code should rather swap in the rare case that x3==x4!
77
+
78
+ Float leftCell7 = (x2-x4)*w, rightCell7 = (x3-x4)*h, origRightSide7 = (x1-x2-x3+x4);
79
+ Float leftCell8 = (y2-y4)*w, rightCell8 = (y3-y4)*h, origRightSide8 = (y1-y2-y3+y4);
80
+
81
+ bool swapRows78 = x2 == x4;
82
+ if (swapRows78)
83
+ {
84
+ std::swap(leftCell7, leftCell8);
85
+ std::swap(rightCell7, rightCell8);
86
+ std::swap(origRightSide7, origRightSide8);
87
+ }
88
+
89
+ // 0, 0, 1, 0, 0, 0, 0, 0 | x1
90
+ // 0, 0, 0, 0, 0, 1, 0, 0 | y1
91
+ // w, 0, 0, 0, 0, 0, -x2w, 0 | x2-x1
92
+ // 0, 0, 0, w, 0, 0, -y2w, 0 | y2-y1
93
+ // 0, h, 0, 0, 0, 0, 0, -x3h | x3-x1
94
+ // 0, 0, 0, 0, h, 0, 0, -y3h | y3-y1
95
+ // 0, 0, 0, 0, 0, 0, leftCell7, rightCell7 | origRightSide7
96
+ // 0, 0, 0, 0, 0, 0, leftCell8, rightCell8 | origRightSide8
97
+
98
+ // Use row 7 to eliminate the left cell in row 8
99
+ // Row8 = Row8 - factor78 * Row7
100
+ Float factor78 = leftCell8 / leftCell7;
101
+ Float remCell8 = rightCell8 - rightCell7 * factor78;
102
+ Float rightSide8 = origRightSide8 - origRightSide7 * factor78;
103
+ c[7] = rightSide8 / remCell8;
104
+
105
+ // 0, 0, 1, 0, 0, 0, 0, 0 | x1
106
+ // 0, 0, 0, 0, 0, 1, 0, 0 | y1
107
+ // w, 0, 0, 0, 0, 0, -x2w, 0 | x2-x1
108
+ // 0, 0, 0, w, 0, 0, -y2w, 0 | y2-y1
109
+ // 0, h, 0, 0, 0, 0, 0, -x3h | x3-x1
110
+ // 0, 0, 0, 0, h, 0, 0, -y3h | y3-y1
111
+ // 0, 0, 0, 0, 0, 0, leftCell7, rightCell7 | origRightSide7
112
+ // 0, 0, 0, 0, 0, 0, 0, remCell8 | rightSide8
113
+
114
+ // Use the remainding value in row 8 to eliminate the right value in row 7.
115
+ // Row7 = Row7 - factor87 * Row8
116
+ Float factor87 = rightCell7 / remCell8;
117
+ Float remCell7 = leftCell7;
118
+ Float rightSide7 = origRightSide7 - rightSide8 * factor87;
119
+ c[6] = rightSide7 / remCell7;
120
+
121
+ // 0, 0, 1, 0, 0, 0, 0, 0 | x1
122
+ // 0, 0, 0, 0, 0, 1, 0, 0 | y1
123
+ // w, 0, 0, 0, 0, 0, -x2w, 0 | x2-x1
124
+ // 0, 0, 0, w, 0, 0, -y2w, 0 | y2-y1
125
+ // 0, h, 0, 0, 0, 0, 0, -x3h | x3-x1
126
+ // 0, 0, 0, 0, h, 0, 0, -y3h | y3-y1
127
+ // 0, 0, 0, 0, 0, 0, remCell7, 0 | rightSide7
128
+ // 0, 0, 0, 0, 0, 0, 0, remCell8 | rightSide8
129
+
130
+ // Use the new rows 7 and 8 to calculate c0, c1, c3 & c4.
131
+ // Row3 = Row3 - factor73 * Row7
132
+ Float factor73 = -x2*w / remCell7;
133
+ Float remCell3 = w;
134
+ Float rightSide3 = (x2-x1) - rightSide7 * factor73;
135
+ c[0] = rightSide3 / remCell3;
136
+ // Row4 = Row4 - factor74 * Row7
137
+ Float factor74 = -y2*w / remCell7;
138
+ Float remCell4 = w;
139
+ Float rightSide4 = (y2-y1) - rightSide7 * factor74;
140
+ c[3] = rightSide4 / remCell4;
141
+ // Row5 = Row5 - factor85 * Row7
142
+ Float factor85 = -x3*h / remCell8;
143
+ Float remCell5 = h;
144
+ Float rightSide5 = (x3-x1) - rightSide8 * factor85;
145
+ c[1] = rightSide5 / remCell5;
146
+ // Row6 = Row6 - factor86 * Row8
147
+ Float factor86 = -y3*h / remCell8;
148
+ Float remCell6 = h;
149
+ Float rightSide6 = (y3-y1) - rightSide8 * factor86;
150
+ c[4] = rightSide6 / remCell6;
151
+
152
+ if (swapRows78)
153
+ std::swap(c[6], c[7]);
154
+
155
+ // Let's hope I never have to debug/understand this again! :D
156
+
157
+ Transform result = {
158
+ c[0], c[3], 0, c[6],
159
+ c[1], c[4], 0, c[7],
160
+ 0, 0, 1, 0,
161
+ c[2], c[5], 0, 1
162
+ };
163
+ return result;
164
+ }
165
+
166
+ void drawVertexArrays(Float x1, Float y1, Float x2, Float y2, Float x3, Float y3, Float x4, Float y4) const
21
167
  {
22
168
  // TODO: Macros should not be split up because they have different transforms! This is insane.
23
169
  // They should be premultiplied and have the same transform by definition. Then, the transformation
@@ -27,14 +173,14 @@ class Gosu::Macro : public Gosu::ImageData
27
173
  glEnable(GL_BLEND);
28
174
  glMatrixMode(GL_MODELVIEW);
29
175
 
176
+ Transform transform =
177
+ findTransformForTarget(x1, y1, x2, y2, x3, y3, x4, y4);
178
+
30
179
  for (VertexArrays::const_iterator it = vertexArrays.begin(), end = vertexArrays.end(); it != end; ++it)
31
180
  {
32
181
  glPushMatrix();
33
182
  it->renderState.apply();
34
-
35
- glTranslated(x1, y1, 0);
36
- glScaled((x2 - x1) / width(), (y3 - y1) / height(), 1);
37
-
183
+ glMultMatrixd(&transform[0]);
38
184
  glInterleavedArrays(GL_T2F_C4UB_V3F, 0, &it->vertices[0]);
39
185
  glDrawArrays(GL_QUADS, 0, it->vertices.size());
40
186
  glPopMatrix();
@@ -44,19 +190,19 @@ class Gosu::Macro : public Gosu::ImageData
44
190
 
45
191
  public:
46
192
  Macro(Graphics& graphics, DrawOpQueue& queue, int width, int height)
47
- : graphics(graphics), givenWidth(width), givenHeight(height)
193
+ : graphics(graphics), w(width), h(height)
48
194
  {
49
195
  queue.compileTo(vertexArrays);
50
196
  }
51
197
 
52
198
  int width() const
53
199
  {
54
- return givenWidth;
200
+ return w;
55
201
  }
56
202
 
57
203
  int height() const
58
204
  {
59
- return givenHeight;
205
+ return h;
60
206
  }
61
207
 
62
208
  void draw(double x1, double y1, Color c1,
@@ -65,11 +211,9 @@ public:
65
211
  double x4, double y4, Color c4,
66
212
  ZPos z, AlphaMode mode) const
67
213
  {
68
- if (x1 != x3 || x2 != x4 || y1 != y2 || y3 != y4)
69
- throw std::invalid_argument("Macros cannot be rotated yet");
70
214
  if (c1 != 0xffffffff || c2 != 0xffffffff || c3 != 0xffffffff || c4 != 0xffffffff)
71
215
  throw std::invalid_argument("Macros cannot be tinted with colors yet");
72
- std::tr1::function<void()> f = std::tr1::bind(&Macro::realDraw, this, x1, y1, x2, y3);
216
+ std::tr1::function<void()> f = std::tr1::bind(&Macro::drawVertexArrays, this, x1, y1, x2, y2, x3, y3, x4, y4);
73
217
  graphics.scheduleGL(f, z);
74
218
  }
75
219
 
@@ -180,7 +180,9 @@ namespace Gosu
180
180
  public:
181
181
  SDLSurface(TTF_Font* font, const std::wstring& text, Gosu::Color c)
182
182
  {
183
- SDL_Color color = { c.red(), c.green(), c.blue() };
183
+ // This is intentionally re-ordered to BGR. This way, the surface pixels do not
184
+ // have to be converted from RGB to BGR later in the process.
185
+ SDL_Color color = { c.blue(), c.green(), c.red() };
184
186
  surface = TTF_RenderUTF8_Blended(font, Gosu::wstringToUTF8(text).c_str(), color);
185
187
  if (!surface)
186
188
  throw std::runtime_error("Could not render text " + Gosu::wstringToUTF8(text));
@@ -657,8 +657,7 @@ namespace Gosu {
657
657
  %markfunc Gosu::Window "markWindow";
658
658
  %include "../Gosu/Window.hpp"
659
659
 
660
- // TODO: Why is this even necessary, does the GC not trace into my Window privates?
661
- // If necessary, can I fake this using an @ivar?
660
+ // TODO: Can I fake this using an @ivar?
662
661
  %header %{
663
662
  static void markWindow(void* window) {
664
663
  #ifndef __MACRUBY__
@@ -739,12 +738,12 @@ namespace Gosu {
739
738
  return $self->graphics().fullscreen();
740
739
  }
741
740
 
742
- void gl() {
741
+ void unsafe_gl() {
743
742
  $self->graphics().beginGL();
744
743
  rb_yield(Qnil);
745
744
  $self->graphics().endGL();
746
745
  }
747
- void gl(Gosu::ZPos z) {
746
+ void unsafe_gl(Gosu::ZPos z) {
748
747
  $self->graphics().scheduleGL(std::tr1::bind(callRubyBlock, rb_block_proc()), z);
749
748
  }
750
749
  void clipTo(double x, double y, double width, double height) {
@@ -13,7 +13,7 @@
13
13
  VALUE result;
14
14
 
15
15
  - result = rb_funcall(swig_get_self(), rb_intern("draw"), 0, NULL);
16
- + result = rb_funcall(swig_get_self(), rb_intern("protected_draw"), 0, NULL);
16
+ + result = rb_funcall(swig_get_self(), rb_intern("protected_draw_2"), 0, NULL);
17
17
  }
18
18
 
19
19
 
@@ -2795,12 +2795,12 @@ SWIGINTERN int Gosu_Window_height(Gosu::Window const *self){
2795
2795
  SWIGINTERN bool Gosu_Window_fullscreen(Gosu::Window const *self){
2796
2796
  return self->graphics().fullscreen();
2797
2797
  }
2798
- SWIGINTERN void Gosu_Window_gl__SWIG_0(Gosu::Window *self){
2798
+ SWIGINTERN void Gosu_Window_unsafe_gl__SWIG_0(Gosu::Window *self){
2799
2799
  self->graphics().beginGL();
2800
2800
  rb_yield(Qnil);
2801
2801
  self->graphics().endGL();
2802
2802
  }
2803
- SWIGINTERN void Gosu_Window_gl__SWIG_1(Gosu::Window *self,Gosu::ZPos z){
2803
+ SWIGINTERN void Gosu_Window_unsafe_gl__SWIG_1(Gosu::Window *self,Gosu::ZPos z){
2804
2804
  self->graphics().scheduleGL(std::tr1::bind(callRubyBlock, rb_block_proc()), z);
2805
2805
  }
2806
2806
  SWIGINTERN void Gosu_Window_clipTo(Gosu::Window *self,double x,double y,double width,double height){
@@ -2913,7 +2913,7 @@ void SwigDirector_Window::update() {
2913
2913
  void SwigDirector_Window::draw() {
2914
2914
  VALUE result;
2915
2915
 
2916
- result = rb_funcall(swig_get_self(), rb_intern("protected_draw"), 0, NULL);
2916
+ result = rb_funcall(swig_get_self(), rb_intern("protected_draw_2"), 0, NULL);
2917
2917
  }
2918
2918
 
2919
2919
 
@@ -10176,7 +10176,7 @@ fail:
10176
10176
 
10177
10177
 
10178
10178
  SWIGINTERN VALUE
10179
- _wrap_Window_gl__SWIG_0(int argc, VALUE *argv, VALUE self) {
10179
+ _wrap_Window_unsafe_gl__SWIG_0(int argc, VALUE *argv, VALUE self) {
10180
10180
  Gosu::Window *arg1 = (Gosu::Window *) 0 ;
10181
10181
  void *argp1 = 0 ;
10182
10182
  int res1 = 0 ;
@@ -10186,12 +10186,12 @@ _wrap_Window_gl__SWIG_0(int argc, VALUE *argv, VALUE self) {
10186
10186
  }
10187
10187
  res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_Gosu__Window, 0 | 0 );
10188
10188
  if (!SWIG_IsOK(res1)) {
10189
- SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "Gosu::Window *","gl", 1, self ));
10189
+ SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "Gosu::Window *","unsafe_gl", 1, self ));
10190
10190
  }
10191
10191
  arg1 = reinterpret_cast< Gosu::Window * >(argp1);
10192
10192
  {
10193
10193
  try {
10194
- Gosu_Window_gl__SWIG_0(arg1);
10194
+ Gosu_Window_unsafe_gl__SWIG_0(arg1);
10195
10195
  } catch (const std::exception& e) {
10196
10196
  SWIG_exception(SWIG_RuntimeError, e.what());
10197
10197
  }
@@ -10203,7 +10203,7 @@ fail:
10203
10203
 
10204
10204
 
10205
10205
  SWIGINTERN VALUE
10206
- _wrap_Window_gl__SWIG_1(int argc, VALUE *argv, VALUE self) {
10206
+ _wrap_Window_unsafe_gl__SWIG_1(int argc, VALUE *argv, VALUE self) {
10207
10207
  Gosu::Window *arg1 = (Gosu::Window *) 0 ;
10208
10208
  Gosu::ZPos arg2 ;
10209
10209
  void *argp1 = 0 ;
@@ -10216,17 +10216,17 @@ _wrap_Window_gl__SWIG_1(int argc, VALUE *argv, VALUE self) {
10216
10216
  }
10217
10217
  res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_Gosu__Window, 0 | 0 );
10218
10218
  if (!SWIG_IsOK(res1)) {
10219
- SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "Gosu::Window *","gl", 1, self ));
10219
+ SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "Gosu::Window *","unsafe_gl", 1, self ));
10220
10220
  }
10221
10221
  arg1 = reinterpret_cast< Gosu::Window * >(argp1);
10222
10222
  ecode2 = SWIG_AsVal_double(argv[0], &val2);
10223
10223
  if (!SWIG_IsOK(ecode2)) {
10224
- SWIG_exception_fail(SWIG_ArgError(ecode2), Ruby_Format_TypeError( "", "Gosu::ZPos","gl", 2, argv[0] ));
10224
+ SWIG_exception_fail(SWIG_ArgError(ecode2), Ruby_Format_TypeError( "", "Gosu::ZPos","unsafe_gl", 2, argv[0] ));
10225
10225
  }
10226
10226
  arg2 = static_cast< Gosu::ZPos >(val2);
10227
10227
  {
10228
10228
  try {
10229
- Gosu_Window_gl__SWIG_1(arg1,arg2);
10229
+ Gosu_Window_unsafe_gl__SWIG_1(arg1,arg2);
10230
10230
  } catch (const std::exception& e) {
10231
10231
  SWIG_exception(SWIG_RuntimeError, e.what());
10232
10232
  }
@@ -10237,7 +10237,7 @@ fail:
10237
10237
  }
10238
10238
 
10239
10239
 
10240
- SWIGINTERN VALUE _wrap_Window_gl(int nargs, VALUE *args, VALUE self) {
10240
+ SWIGINTERN VALUE _wrap_Window_unsafe_gl(int nargs, VALUE *args, VALUE self) {
10241
10241
  int argc;
10242
10242
  VALUE argv[3];
10243
10243
  int ii;
@@ -10254,7 +10254,7 @@ SWIGINTERN VALUE _wrap_Window_gl(int nargs, VALUE *args, VALUE self) {
10254
10254
  int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_Gosu__Window, 0);
10255
10255
  _v = SWIG_CheckState(res);
10256
10256
  if (_v) {
10257
- return _wrap_Window_gl__SWIG_0(nargs, args, self);
10257
+ return _wrap_Window_unsafe_gl__SWIG_0(nargs, args, self);
10258
10258
  }
10259
10259
  }
10260
10260
  if (argc == 2) {
@@ -10268,15 +10268,15 @@ SWIGINTERN VALUE _wrap_Window_gl(int nargs, VALUE *args, VALUE self) {
10268
10268
  _v = SWIG_CheckState(res);
10269
10269
  }
10270
10270
  if (_v) {
10271
- return _wrap_Window_gl__SWIG_1(nargs, args, self);
10271
+ return _wrap_Window_unsafe_gl__SWIG_1(nargs, args, self);
10272
10272
  }
10273
10273
  }
10274
10274
  }
10275
10275
 
10276
10276
  fail:
10277
- Ruby_Format_OverloadedError( argc, 3, "gl",
10278
- " void gl()\n"
10279
- " void gl(Gosu::ZPos z)\n");
10277
+ Ruby_Format_OverloadedError( argc, 3, "unsafe_gl",
10278
+ " void unsafe_gl()\n"
10279
+ " void unsafe_gl(Gosu::ZPos z)\n");
10280
10280
 
10281
10281
  return Qnil;
10282
10282
  }
@@ -11228,8 +11228,8 @@ SWIGEXPORT void Init_gosu(void) {
11228
11228
  SWIG_RubyInitializeTrackings();
11229
11229
  rb_define_const(mGosu, "MAJOR_VERSION", SWIG_From_int(static_cast< int >(0)));
11230
11230
  rb_define_const(mGosu, "MINOR_VERSION", SWIG_From_int(static_cast< int >(7)));
11231
- rb_define_const(mGosu, "POINT_VERSION", SWIG_From_int(static_cast< int >(41)));
11232
- rb_define_const(mGosu, "VERSION", SWIG_FromCharPtr("0.7.41"));
11231
+ rb_define_const(mGosu, "POINT_VERSION", SWIG_From_int(static_cast< int >(43)));
11232
+ rb_define_const(mGosu, "VERSION", SWIG_FromCharPtr("0.7.43"));
11233
11233
  rb_define_module_function(mGosu, "milliseconds", VALUEFUNC(_wrap_milliseconds), -1);
11234
11234
  rb_define_module_function(mGosu, "random", VALUEFUNC(_wrap_random), -1);
11235
11235
  rb_define_module_function(mGosu, "degrees_to_radians", VALUEFUNC(_wrap_degrees_to_radians), -1);
@@ -11579,7 +11579,7 @@ SWIGEXPORT void Init_gosu(void) {
11579
11579
  rb_define_method(SwigClassWindow.klass, "width", VALUEFUNC(_wrap_Window_width), -1);
11580
11580
  rb_define_method(SwigClassWindow.klass, "height", VALUEFUNC(_wrap_Window_height), -1);
11581
11581
  rb_define_method(SwigClassWindow.klass, "fullscreen?", VALUEFUNC(_wrap_Window_fullscreenq___), -1);
11582
- rb_define_method(SwigClassWindow.klass, "gl", VALUEFUNC(_wrap_Window_gl), -1);
11582
+ rb_define_method(SwigClassWindow.klass, "unsafe_gl", VALUEFUNC(_wrap_Window_unsafe_gl), -1);
11583
11583
  rb_define_method(SwigClassWindow.klass, "clip_to", VALUEFUNC(_wrap_Window_clip_to), -1);
11584
11584
  rb_define_method(SwigClassWindow.klass, "record", VALUEFUNC(_wrap_Window_record), -1);
11585
11585
  rb_define_method(SwigClassWindow.klass, "transform", VALUEFUNC(_wrap_Window_transform), -1);
@@ -468,6 +468,9 @@ LRESULT Gosu::Window::handleMessage(UINT message, WPARAM wparam, LPARAM lparam)
468
468
 
469
469
  if (message == WM_PAINT)
470
470
  {
471
+ PAINTSTRUCT ps;
472
+ pimpl->hdc = BeginPaint(handle(), &ps);
473
+
471
474
  if (pimpl->graphics.get() && graphics().begin())
472
475
  {
473
476
  try
@@ -481,11 +484,12 @@ LRESULT Gosu::Window::handleMessage(UINT message, WPARAM wparam, LPARAM lparam)
481
484
  }
482
485
  graphics().end();
483
486
  }
487
+
484
488
  SwapBuffers(pimpl->hdc);
485
- ValidateRect(handle(), 0);
489
+ EndPaint(handle(), &ps);
486
490
  return 0;
487
491
  }
488
-
492
+
489
493
  if (message == WM_SYSCOMMAND)
490
494
  {
491
495
  switch(wparam)
@@ -0,0 +1,68 @@
1
+ # Gosu Zen example based on erisdiscord's comment here:
2
+ # https://github.com/jlnr/gosu/pull/120
3
+
4
+ # Gosu Zen is the (inline) Sinatra of Ruby multimedia programming.
5
+ # The interface is still in flux. If you want to tune the interface
6
+ # a little further or provide more examples, please fork Gosu and
7
+ # send a pull request. Thanks!
8
+
9
+ require 'rubygems'
10
+ require 'gosu/zen'
11
+ include Gosu::Zen
12
+
13
+ window 480, 240, :fullscreen => false
14
+
15
+ button_down Gosu::KbEscape do
16
+ close
17
+ end
18
+
19
+ update do
20
+ t = Gosu.milliseconds / 1000.0
21
+
22
+ @radius = [width, height].min * 0.37
23
+ @angle = t * Math::PI
24
+
25
+ a, b =\
26
+ (Math.cos(t) + 0.5) * 0xff,
27
+ (Math.sin(t) + 0.5) * 0xff
28
+
29
+ c = (a + b) / 2
30
+
31
+ @colors = [
32
+ Gosu::Color.rgb(a, b, 0xff),
33
+ Gosu::Color.rgb(a, 0x00, b),
34
+ Gosu::Color.rgb(0xff, b, a),
35
+ Gosu::Color.rgb(b, a, 0x00),
36
+ Gosu::Color.rgb(b, 0xff, a),
37
+ Gosu::Color.rgb(0x00, a, b) ]
38
+
39
+ @background = Gosu::Color.rgb(c, c, c)
40
+ end
41
+
42
+ draw do
43
+ draw_quad\
44
+ 0, 0, @background,
45
+ 0, height, @background,
46
+ width, height, @background,
47
+ width, 0, @background, 0
48
+
49
+ translate width / 2, height / 2 do
50
+ @colors.each.with_index do |color, i|
51
+
52
+ angle = @angle + i.to_f / @colors.length * 2.0 * Math::PI
53
+ x = @radius * Math.sin(angle)
54
+ y = @radius * Math.cos(angle)
55
+ w, h = x, y
56
+
57
+ translate x, y do
58
+ rotate Gosu.radians_to_degrees(angle) do
59
+ draw_quad\
60
+ -w, +h, color,
61
+ -w, -h, color,
62
+ +w, -h, color,
63
+ +w, +h, color, 0
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -85,37 +85,55 @@ module Gosu
85
85
  end
86
86
  end
87
87
 
88
+ def self.button_down? id
89
+ $window.button_down? id
90
+ end
91
+
92
+ def self.mouse_x
93
+ $window.mouse_x
94
+ end
95
+
96
+ def self.mouse_y
97
+ $window.mouse_y
98
+ end
99
+
100
+ def self.draw_line *args
101
+ $window.draw_line *args
102
+ end
103
+
104
+ def self.draw_triangle *args
105
+ $window.draw_triangle *args
106
+ end
107
+
88
108
  def self.draw_quad *args
89
109
  $window.draw_quad *args
90
110
  end
91
111
 
92
- def self.clip_to *args
93
- $window.clip_to *args do
94
- yield
95
- end
112
+ def self.clip_to *args, &draw
113
+ $window.clip_to *args, &draw
96
114
  end
97
115
 
98
- def self.translate *args
99
- $window.translate *args do
100
- yield
101
- end
116
+ def self.translate *args, &draw
117
+ $window.translate *args, &draw
102
118
  end
103
119
 
104
- def self.scale *args
105
- $window.scale *args do
106
- yield
107
- end
120
+ def self.scale *args, &draw
121
+ $window.scale *args, &draw
108
122
  end
109
123
 
110
- def self.rotate *args
111
- $window.rotate *args do
112
- yield
113
- end
124
+ def self.rotate *args, &draw
125
+ $window.rotate *args, &draw
114
126
  end
115
127
 
116
- def self.transform *args
117
- $window.transform *args do
118
- yield
119
- end
128
+ def self.transform *args, &draw
129
+ $window.transform *args, &draw
130
+ end
131
+
132
+ def self.record width, height, &draw
133
+ $window.record width, height, &draw
134
+ end
135
+
136
+ def self.gl *args, &draw
137
+ $window.gl *args, &draw
120
138
  end
121
139
  end
@@ -10,8 +10,8 @@ class Gosu::Window
10
10
  lose_focus button_down button_up).each do |callback|
11
11
  define_method "protected_#{callback}" do |*args|
12
12
  begin
13
- # Turn into a boolean result for needs_cursor? etc while we are at it.
14
13
  # If there has been an exception, don't do anything as to not make matters worse.
14
+ # Conveniently turn the return value into a boolean result (for needs_cursor? etc).
15
15
  defined?(@_exception) ? false : !!send(callback, *args)
16
16
  rescue Exception => e
17
17
  # Exit the message loop naturally, then re-throw
@@ -21,6 +21,17 @@ class Gosu::Window
21
21
  end
22
22
  end
23
23
 
24
+ def protected_draw_2
25
+ protected_draw
26
+ $gosu_gl_blocks = nil
27
+ end
28
+
29
+ def gl(*args, &block)
30
+ $gosu_blocks ||= []
31
+ $gosu_blocks << block
32
+ unsafe_gl(*args, &block)
33
+ end
34
+
24
35
  alias show_internal show
25
36
  def show
26
37
  show_internal
@@ -1,28 +1,77 @@
1
- require 'gosu'
2
- require 'singleton'
1
+ require 'gosu/preview'
3
2
 
4
3
  module Gosu
4
+ module Zen
5
+
6
+ @@window_args = [800, 600, {}]
7
+ @@options = {}
8
+
9
+ def window width, height, options = nil
10
+ if $window.nil?
11
+ @@window_args[0] = width
12
+ @@window_args[1] = height
13
+ @@window_args[2].merge! options if options
14
+ else
15
+ raise "window size can only be set before the window is created"
16
+ end
17
+ end
18
+
19
+ def set what, value
20
+ if $window.nil?
21
+ @@options[what.to_sym] = value
22
+ else
23
+ $window.send "#{what}=", value
24
+ end
25
+ end
26
+
27
+ def button_down id = nil, &body
28
+ m = id ? "button_down_#{id}" : :button_down_other
29
+ ZenWindow.send :define_method, m, &body
30
+ end
31
+
32
+ def button_up id = nil, &body
33
+ m = id ? "button_up_#{id}" : :button_up_other
34
+ ZenWindow.send :define_method, m, &body
35
+ end
36
+
37
+ def update &body
38
+ ZenWindow.send :define_method, :update, &body
39
+ end
40
+
41
+ def draw &body
42
+ ZenWindow.send :define_method, :draw, &body
43
+ end
44
+
45
+ def run!
46
+ window = ZenWindow.new *@@window_args
47
+ @@options.each do |opt, value|
48
+ window.send "#{opt}=", value
49
+ end
50
+ window.show
51
+ end
52
+
53
+ def Zen.included mod
54
+ at_exit { run! unless $! }
55
+ end
56
+
57
+ end
58
+
5
59
  class ZenWindow < Window
6
- include Singleton
60
+ def button_down id
61
+ m = :"button_down_#{id}"
62
+ respond_to?(m) ? send(m) : button_down_other(id)
63
+ end
64
+
65
+ def button_up id
66
+ m = :"button_up_#{id}"
67
+ respond_to?(m) ? send(m) : button_up_other(id)
68
+ end
69
+
70
+ def button_down_other id
71
+ end
7
72
 
8
- def initialize
9
- super 800, 600, false
73
+ def button_up_other id
10
74
  end
75
+
11
76
  end
12
77
  end
13
-
14
- def set what, value
15
- Gosu::ZenWindow.instance.send "#{what}=", value
16
- end
17
-
18
- def update(&proc)
19
- Gosu::ZenWindow.send :define_method, :update, proc
20
- end
21
-
22
- # WIP - needs all other callbacks, even with arguments
23
-
24
- # WIP - needs to be compatible with gosu/preview.rb later
25
-
26
- at_exit do
27
- Gosu::ZenWindow.instance.show
28
- end
@@ -59,6 +59,7 @@ LINUX_FILES = %w(
59
59
  )
60
60
 
61
61
  require 'mkmf'
62
+ require 'fileutils'
62
63
 
63
64
  $INCFLAGS << " -I../ -I../GosuImpl"
64
65
 
@@ -66,41 +67,43 @@ if `uname`.chomp == 'Darwin' then
66
67
  SOURCE_FILES = BASE_FILES + MAC_FILES
67
68
 
68
69
  # Apple curiously distributes libpng only inside X11
69
- $INCFLAGS << " -I/usr/X11/include"
70
+ $INCFLAGS << " -I/usr/X11/include"
70
71
  # To make everything work with the Objective C runtime
71
- $CFLAGS << " -x objective-c++ -fobjc-gc -DNDEBUG"
72
- $LDFLAGS << " -L/usr/X11/lib -logg -lvorbis -lvorbisfile -liconv"
72
+ $CFLAGS << " -x objective-c++ -fobjc-gc -DNDEBUG"
73
+ $LDFLAGS << " -L/usr/X11/lib -logg -lvorbis -lvorbisfile -liconv"
73
74
  %w(AudioToolbox IOKit OpenAL OpenGL AppKit ApplicationServices Foundation Carbon).each do |f|
74
- #$INCFLAGS << " -framework #{f}" <- not necessary? I only get lots of warnings
75
- $LDFLAGS << " -framework #{f}"
75
+ $LDFLAGS << " -framework #{f}"
76
76
  end
77
-
77
+
78
78
  # Symlink our pretty gosu.so into ../lib
79
79
  # FIXME gosu.rb should just look in the right place.
80
- `ln -s ../linux/gosu.bundle ../lib/gosu.bundle`
80
+ FileUtils.ln_s("../linux/gosu.bundle", "../lib/gosu.bundle")
81
81
  else
82
82
  SOURCE_FILES = BASE_FILES + LINUX_FILES
83
83
 
84
84
  # Symlink our pretty gosu.so into ../lib
85
85
  # FIXME gosu.rb should just look in the right place.
86
- `ln -s ../linux/gosu.so ../lib/gosu.so`
87
-
88
- sdl_config = with_config("sdl-config", "sdl-config")
89
- pango_config = "pkg-config pangoft2"
86
+ FileUtils.ln_s("../linux/gosu.so", "../lib/gosu.so")
90
87
 
91
- $INCFLAGS << " `#{sdl_config} --cflags` `#{pango_config} --cflags`"
92
- $LDFLAGS << " `#{sdl_config} --libs` `#{pango_config} --libs` -lX11"
93
- have_header('SDL_ttf.h') if have_library('SDL_ttf', 'TTF_RenderUTF8_Blended')
94
- have_header('gl.h') if have_library('GL', 'glMatrixMode')
88
+ pkg_config("sdl")
89
+ pkg_config("pangoft2")
90
+ pkg_config("x11")
91
+
92
+ pkg_config("gl")
93
+ pkg_config("vorbisfile")
94
+ pkg_config("openal")
95
+ pkg_config("sndfile")
96
+ pkg_config("xinerama")
97
+
98
+ have_header('SDL_ttf.h') if have_library('SDL_ttf', 'TTF_RenderUTF8_Blended')
95
99
  have_header('FreeImage.h') if have_library('freeimage', 'FreeImage_ConvertFromRawBits')
96
- have_header('vorbisfile.h') if have_library('vorbisfile', 'ov_open_callbacks')
97
- have_header('AL/al.h') if have_library('openal')
98
- have_header('sndfile.h') if have_library('sndfile')
99
- have_header('X11/extensions/Xinerama.h') if have_library('Xinerama', 'XineramaQueryScreens')
100
+ have_header('AL/al.h') if have_library('openal')
100
101
  end
101
102
 
102
103
  # Copy all relevant C++ files into the current directory
103
104
  # FIXME Could be done by gem task instead.
104
- SOURCE_FILES.each { |file| `cp ../GosuImpl/#{file} #{File.basename(file).sub(/\.mm$/, '.cpp')}` }
105
+ SOURCE_FILES.each do |file|
106
+ FileUtils.cp("../GosuImpl/#{file}", File.basename(file).sub(/\.mm$/, '.cpp'))
107
+ end
105
108
 
106
109
  create_makefile("gosu")
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gosu
3
3
  version: !ruby/object:Gem::Version
4
- hash: 81
4
+ hash: 85
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 41
10
- version: 0.7.41
9
+ - 43
10
+ version: 0.7.43
11
11
  platform: ruby
12
12
  authors:
13
13
  - Julian Raschke
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-17 00:00:00 Z
18
+ date: 2012-03-18 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: " 2D game development library.\n\n Gosu features easy to use and game-friendly interfaces to 2D graphics\n and text (accelerated by 3D hardware), sound samples and music as well as\n keyboard, mouse and gamepad/joystick input.\n\n Also includes demos for integration with RMagick, Chipmunk and OpenGL.\n"
@@ -68,6 +68,7 @@ files:
68
68
  - lib/gosu.rb
69
69
  - examples/ChipmunkIntegration.rb
70
70
  - examples/CptnRuby.rb
71
+ - examples/GosuZen.rb
71
72
  - examples/MoreChipmunkAndRMagick.rb
72
73
  - examples/OpenGLIntegration.rb
73
74
  - examples/RMagickIntegration.rb
@@ -219,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
220
  requirements:
220
221
  - See https://github.com/jlnr/gosu/wiki/Getting-Started-on-Linux
221
222
  rubyforge_project:
222
- rubygems_version: 1.8.11
223
+ rubygems_version: 1.8.16
223
224
  signing_key:
224
225
  specification_version: 3
225
226
  summary: 2D game development library.