gosu 0.7.31 → 0.7.32

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,6 +10,7 @@ namespace Gosu
10
10
  class Audio;
11
11
  class Bitmap;
12
12
  class Buffer;
13
+ class Button;
13
14
  class Color;
14
15
  class File;
15
16
  class Font;
@@ -3,7 +3,37 @@
3
3
 
4
4
  #define GOSU_MAJOR_VERSION 0
5
5
  #define GOSU_MINOR_VERSION 7
6
- #define GOSU_POINT_VERSION 31
7
- #define GOSU_VERSION "0.7.31"
6
+ #define GOSU_POINT_VERSION 32
7
+ #define GOSU_VERSION "0.7.32"
8
8
 
9
+ #define GOSU_COPYRIGHT_NOTICE \
10
+ "May contain `ogg', `vorbis' libraries (c) 2002-2008 Xiph.org Foundation" \
11
+ "\n\n" \
12
+ "Redistribution and use in source and binary forms, with or without" \
13
+ "modification, are permitted provided that the following conditions" \
14
+ "are met:" \
15
+ "\n\n" \
16
+ "- Redistributions of source code must retain the above copyright" \
17
+ "notice, this list of conditions and the following disclaimer." \
18
+ "\n\n" \
19
+ "- Redistributions in binary form must reproduce the above copyright" \
20
+ "notice, this list of conditions and the following disclaimer in the" \
21
+ "documentation and/or other materials provided with the distribution." \
22
+ "\n\n" \
23
+ "- Neither the name of the Xiph.org Foundation nor the names of its" \
24
+ "contributors may be used to endorse or promote products derived from" \
25
+ "this software without specific prior written permission." \
26
+ "\n\n" \
27
+ "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS" \
28
+ "``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT" \
29
+ "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR" \
30
+ "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION" \
31
+ "OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL," \
32
+ "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT" \
33
+ "LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE," \
34
+ "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY" \
35
+ "THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT" \
36
+ "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE" \
37
+ "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
38
+
9
39
  #endif
@@ -164,7 +164,8 @@ void Gosu::saveImageFile(const Bitmap& bmp, Writer writer, const std::wstring& f
164
164
  {
165
165
  Bitmap bitmap = bmp;
166
166
  unapplyColorKey(bitmap, Color::FUCHSIA);
167
- return Gosu::saveToBMP(bitmap, writer);
167
+ Gosu::saveToBMP(bitmap, writer);
168
+ return;
168
169
  }
169
170
 
170
171
  ObjRef<NSAutoreleasePool> pool([NSAutoreleasePool new]);
@@ -193,7 +194,5 @@ void Gosu::saveImageFile(const Bitmap& bmp, Writer writer, const std::wstring& f
193
194
  CGImageRelease(imageRef);
194
195
 
195
196
  CGDataProviderRelease(dataProvider);
196
-
197
- return writer;
198
197
  }
199
198
  #endif
@@ -6,6 +6,18 @@
6
6
  #include <boost/cstdint.hpp>
7
7
  #include <FreeImage.h>
8
8
 
9
+ // Compatibility with FreeImage < 3.1.3 which is still stuck in many package repositories
10
+ #ifndef JPEG_EXIFROTATE
11
+ #define JPEG_EXIFROTATE 0
12
+ #endif
13
+
14
+ // In Windows, add a suffix to all functions so they can be used as a fallback for GDI+.
15
+ #ifdef GOSU_IS_WIN
16
+ #define FI(x) x##_FreeImage
17
+ #else
18
+ #define FI(x) x
19
+ #endif
20
+
9
21
  namespace
10
22
  {
11
23
  const int GOSU_FIFLAGS = (JPEG_EXIFROTATE | ICO_MAKEALPHA | PNG_IGNOREGAMMA);
@@ -68,54 +80,57 @@ namespace
68
80
 
69
81
  // TODO: error checking w/ FreeImage_SetOutputMessage?
70
82
 
71
- Gosu::Bitmap Gosu::loadImageFile(const std::wstring& filename)
83
+ namespace Gosu
72
84
  {
73
- #ifdef GOSU_IS_WIN
74
- FREE_IMAGE_FORMAT fif = GetFileTypeU(filename.c_str());
75
- FIBITMAP* fib = FreeImage_LoadU(filename.c_str(), GOSU_FIFLAGS);
76
- #else
77
- std::string utf8Filename = wstringToUTF8(filename);
78
- FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(utf8Filename.c_str());
79
- FIBITMAP* fib = FreeImage_Load(fif, utf8Filename.c_str(), GOSU_FIFLAGS);
80
- #endif
85
+ Bitmap FI(loadImageFile)(const std::wstring& filename)
86
+ {
87
+ #ifdef GOSU_IS_WIN
88
+ FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeU(filename.c_str());
89
+ FIBITMAP* fib = FreeImage_LoadU(fif, filename.c_str(), GOSU_FIFLAGS);
90
+ #else
91
+ std::string utf8Filename = wstringToUTF8(filename);
92
+ FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(utf8Filename.c_str());
93
+ FIBITMAP* fib = FreeImage_Load(fif, utf8Filename.c_str(), GOSU_FIFLAGS);
94
+ #endif
81
95
 
82
- return fibToBitmap(fib, fif);
83
- }
96
+ return fibToBitmap(fib, fif);
97
+ }
84
98
 
85
- Gosu::Bitmap Gosu::loadImageFile(Gosu::Reader input)
86
- {
87
- // Read all available input
88
- std::vector<BYTE> data(input.resource().size() - input.position());
89
- input.read(&data[0], data.size());
90
- FIMEMORY* fim = FreeImage_OpenMemory(&data[0], data.size());
91
- FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(fim);
92
- FIBITMAP* fib = FreeImage_LoadFromMemory(fif, fim, GOSU_FIFLAGS);
99
+ Bitmap FI(loadImageFile)(Gosu::Reader input)
100
+ {
101
+ // Read all available input
102
+ std::vector<BYTE> data(input.resource().size() - input.position());
103
+ input.read(&data[0], data.size());
104
+ FIMEMORY* fim = FreeImage_OpenMemory(&data[0], data.size());
105
+ FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(fim);
106
+ FIBITMAP* fib = FreeImage_LoadFromMemory(fif, fim, GOSU_FIFLAGS);
93
107
 
94
- return fibToBitmap(fib, fif);
95
- }
108
+ return fibToBitmap(fib, fif);
109
+ }
96
110
 
97
- void Gosu::saveImageFile(const Bitmap& bitmap, const std::wstring& filename)
98
- {
99
- std::string utf8Filename = wstringToUTF8(filename);
100
- FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(utf8Filename.c_str());
101
- FIBITMAP* fib = bitmapToFIB(bitmap, fif);
111
+ void FI(saveImageFile)(const Bitmap& bitmap, const std::wstring& filename)
112
+ {
113
+ std::string utf8Filename = wstringToUTF8(filename);
114
+ FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(utf8Filename.c_str());
115
+ FIBITMAP* fib = bitmapToFIB(bitmap, fif);
102
116
 
103
- #ifdef GOSU_IS_WIN
104
- FreeImage_SaveU(fif, fib, filename.c_str());
105
- #else
106
- FreeImage_Save(fif, fib, utf8Filename.c_str());
107
- #endif
108
- FreeImage_Unload(fib);
109
- }
117
+ #ifdef GOSU_IS_WIN
118
+ FreeImage_SaveU(fif, fib, filename.c_str());
119
+ #else
120
+ FreeImage_Save(fif, fib, utf8Filename.c_str());
121
+ #endif
122
+ FreeImage_Unload(fib);
123
+ }
110
124
 
111
- void Gosu::saveImageFile(const Bitmap& bitmap, Gosu::Writer writer,
112
- const std::wstring& formatHint)
113
- {
114
- std::string utf8FormatHint = wstringToUTF8(formatHint);
115
- FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(utf8FormatHint.c_str());
116
- FIBITMAP* fib = bitmapToFIB(bitmap, fif);
117
-
118
- FreeImageIO fio = { NULL, WriteProc, SeekProc, TellProc };
119
- FreeImage_SaveToHandle(fif, fib, &fio, &writer);
120
- FreeImage_Unload(fib);
125
+ void FI(saveImageFile)(const Bitmap& bitmap, Gosu::Writer writer,
126
+ const std::wstring& formatHint)
127
+ {
128
+ std::string utf8FormatHint = wstringToUTF8(formatHint);
129
+ FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(utf8FormatHint.c_str());
130
+ FIBITMAP* fib = bitmapToFIB(bitmap, fif);
131
+
132
+ FreeImageIO fio = { NULL, WriteProc, SeekProc, TellProc };
133
+ FreeImage_SaveToHandle(fif, fib, &fio, &writer);
134
+ FreeImage_Unload(fib);
135
+ }
121
136
  }
@@ -192,10 +192,15 @@ namespace
192
192
  unsigned Gosu::textWidth(const std::wstring& text,
193
193
  const std::wstring& fontName, unsigned fontHeight, unsigned fontFlags)
194
194
  {
195
+ if (text.find_first_of(L"\r\n") != std::wstring::npos)
196
+ throw std::invalid_argument("the argument to textWidth cannot contain line breaks");
197
+
198
+ // TODO: Why 1?
195
199
  if (text.empty())
196
200
  return 1;
197
-
198
- // TODO: special case :///7
201
+
202
+ // TODO: special case :(
203
+ // TODO: Why? I guess it was empty otherwise?
199
204
  if (text == L" ")
200
205
  return fontHeight / 3;
201
206
 
@@ -208,6 +213,9 @@ void Gosu::drawText(Bitmap& bitmap, const std::wstring& text, int x, int y,
208
213
  Color c, const std::wstring& fontName, unsigned fontHeight,
209
214
  unsigned fontFlags)
210
215
  {
216
+ if (text.find_first_of(L"\r\n") != std::wstring::npos)
217
+ throw std::invalid_argument("the argument to drawText cannot contain line breaks");
218
+
211
219
  if (text.empty())
212
220
  return;
213
221
 
@@ -2,12 +2,13 @@
2
2
 
3
3
  #if defined(GOSU_IS_IPHONE) || defined(__LP64__)
4
4
 
5
- #import <Gosu/Text.hpp>
6
- #import <Gosu/Bitmap.hpp>
7
- #import <Gosu/Utility.hpp>
8
- #import <GosuImpl/MacUtility.hpp>
9
- #import <map>
10
- #import <cmath>
5
+ #include <Gosu/Text.hpp>
6
+ #include <Gosu/Bitmap.hpp>
7
+ #include <Gosu/Utility.hpp>
8
+ #include <GosuImpl/MacUtility.hpp>
9
+ #include <boost/algorithm/string.hpp>
10
+ #include <map>
11
+ #include <cmath>
11
12
  using namespace std;
12
13
 
13
14
  #if defined(GOSU_IS_IPHONE)
@@ -130,6 +131,9 @@ namespace
130
131
  unsigned Gosu::textWidth(const wstring& text,
131
132
  const wstring& fontName, unsigned fontHeight, unsigned fontFlags)
132
133
  {
134
+ if (text.find_first_of(L"\r\n") != wstring::npos)
135
+ throw std::invalid_argument("the argument to textWidth cannot contain line breaks");
136
+
133
137
  OSXFont* font = getFont(fontName, fontFlags, fontHeight);
134
138
 
135
139
  // This will, of course, compute a too large size; fontHeight is in pixels,
@@ -141,7 +145,7 @@ unsigned Gosu::textWidth(const wstring& text,
141
145
  #else
142
146
  CGSize size = [string.obj() sizeWithFont: font];
143
147
  #endif
144
-
148
+
145
149
  // Now adjust the scaling...
146
150
  return ceil(size.width / size.height * fontHeight);
147
151
  }
@@ -150,6 +154,9 @@ void Gosu::drawText(Bitmap& bitmap, const wstring& text, int x, int y,
150
154
  Color c, const wstring& fontName, unsigned fontHeight,
151
155
  unsigned fontFlags)
152
156
  {
157
+ if (text.find_first_of(L"\r\n") != wstring::npos)
158
+ throw std::invalid_argument("the argument to drawText cannot contain line breaks");
159
+
153
160
  OSXFont* font = getFont(fontName, fontFlags, fontHeight);
154
161
  ObjRef<NSString> string([[NSString alloc] initWithUTF8String: wstringToUTF8(text).c_str()]);
155
162
 
@@ -243,6 +243,9 @@ unsigned Gosu::textWidth(const std::wstring& text,
243
243
  const std::wstring& fontName, unsigned fontHeight,
244
244
  unsigned fontFlags)
245
245
  {
246
+ if (text.find_first_of(L"\r\n") != std::wstring::npos)
247
+ throw std::invalid_argument("the argument to textWidth cannot contain line breaks");
248
+
246
249
  if (fontName.find(L"/") == std::wstring::npos)
247
250
  return PangoRenderer().textWidth(text, fontName, fontHeight, fontFlags);
248
251
  else
@@ -253,6 +256,9 @@ void Gosu::drawText(Bitmap& bitmap, const std::wstring& text, int x, int y,
253
256
  Color c, const std::wstring& fontName, unsigned fontHeight,
254
257
  unsigned fontFlags)
255
258
  {
259
+ if (text.find_first_of(L"\r\n") != std::wstring::npos)
260
+ throw std::invalid_argument("the argument to drawText cannot contain line breaks");
261
+
256
262
  if (fontName.find(L"/") == std::wstring::npos)
257
263
  PangoRenderer().drawText(bitmap, text, x, y, c, fontName, fontHeight, fontFlags);
258
264
  else
@@ -143,6 +143,9 @@ namespace Gosu
143
143
  unsigned Gosu::textWidth(const std::wstring& text,
144
144
  const std::wstring& fontName, unsigned fontHeight, unsigned fontFlags)
145
145
  {
146
+ if (text.find_first_of(L"\r\n") != std::wstring::npos)
147
+ throw std::invalid_argument("the argument to textWidth cannot contain line breaks");
148
+
146
149
  WinBitmap helper(1, 1);
147
150
  helper.selectFont(fontName, fontHeight, fontFlags);
148
151
 
@@ -157,6 +160,9 @@ void Gosu::drawText(Bitmap& bitmap, const std::wstring& text, int x, int y,
157
160
  Color c, const std::wstring& fontName, unsigned fontHeight,
158
161
  unsigned fontFlags)
159
162
  {
163
+ if (text.find_first_of(L"\r\n") != std::wstring::npos)
164
+ throw std::invalid_argument("the argument to drawText cannot contain line breaks");
165
+
160
166
  unsigned width = textWidth(text, fontName, fontHeight, fontFlags);
161
167
 
162
168
  WinBitmap helper(width, fontHeight);
@@ -173,6 +173,9 @@
173
173
  #include <Gosu/Utility.hpp>
174
174
  #include <Gosu/Version.hpp>
175
175
  #include <Gosu/Window.hpp>
176
+ #ifdef GOSU_IS_WIN
177
+ #include <FreeImage.h>
178
+ #endif
176
179
 
177
180
  namespace Gosu {
178
181
  void enableUndocumentedRetrofication() { extern bool undocumentedRetrofication; undocumentedRetrofication = true; }
@@ -215,17 +218,49 @@ namespace
215
218
  }
216
219
  }
217
220
 
218
- // Allow filenames and RMagick Images to be passed where Bitmaps are needed.
219
221
  namespace Gosu
220
222
  {
223
+ #ifdef GOSU_IS_WIN
224
+ void ping_FreeImage()
225
+ {
226
+ // Copied and pasted from MSDN.
227
+ // TODO: Remove duplication, this is also in AudioAudiere.cpp
228
+ #define FACILITY_VISUALCPP ((LONG)0x6d)
229
+ #define VcppException(sev,err) ((sev) | (FACILITY_VISUALCPP<<16) | err)
230
+ #define BAD_MOD VcppException(ERROR_SEVERITY_ERROR, ERROR_MOD_NOT_FOUND)
231
+
232
+ __try
233
+ {
234
+ FreeImage_GetVersion();
235
+ }
236
+ __except ((GetExceptionCode() == BAD_MOD) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
237
+ {
238
+ rb_raise(rb_eRuntimeError, "unable to locate FreeImage.dll");
239
+ }
240
+ #undef BAD_MOD
241
+ #undef VcppException
242
+ #undef FACILITY_VISUALCPP
243
+ }
244
+ Bitmap loadImageFile_FreeImage(const std::wstring& filename);
245
+ #endif
221
246
  Gosu::Bitmap loadBitmap(VALUE val)
222
247
  {
223
248
  // Try to treat as filename first.
224
249
  if (rb_respond_to(val, rb_intern("to_str")))
225
250
  {
226
251
  VALUE to_str = rb_funcall(val, rb_intern("to_str"), 0);
227
- const char* filename = StringValuePtr(to_str);
228
- return loadImageFile(Gosu::utf8ToWstring(filename));
252
+ const char* filenameUTF8 = StringValuePtr(to_str);
253
+ std::wstring filename = Gosu::utf8ToWstring(filenameUTF8);
254
+ try {
255
+ return loadImageFile(filename);
256
+ } catch (const std::exception&) {
257
+ #ifdef GOSU_IS_WIN
258
+ ping_FreeImage();
259
+ return loadImageFile_FreeImage(filename);
260
+ #else
261
+ throw;
262
+ #endif
263
+ }
229
264
  }
230
265
 
231
266
  // Otherwise, try to call .to_blob on it (works with RMagick, TexPlay etc).
@@ -1,13 +1,11 @@
1
- Index: GosuImpl/RubyGosu_wrap.cxx
2
- ===================================================================
3
1
  --- GosuImpl/RubyGosu_wrap.cxx
4
2
  +++ GosuImpl/RubyGosu_wrap.cxx
5
- @@ -2877,14 +2877,14 @@ SwigDirector_Window::~SwigDirector_Window() {
3
+ @@ -2912,14 +2912,14 @@ SwigDirector_Window::~SwigDirector_Window() {
6
4
  void SwigDirector_Window::update() {
7
5
  VALUE result;
8
6
 
9
7
  - result = rb_funcall(swig_get_self(), rb_intern("update"), 0, NULL);
10
- + result = rb_funcall(swig_get_self(), rb_intern("update_"), 0, NULL);
8
+ + result = rb_funcall(swig_get_self(), rb_intern("protected_update"), 0, NULL);
11
9
  }
12
10
 
13
11
 
@@ -15,7 +13,50 @@ Index: GosuImpl/RubyGosu_wrap.cxx
15
13
  VALUE result;
16
14
 
17
15
  - result = rb_funcall(swig_get_self(), rb_intern("draw"), 0, NULL);
18
- + result = rb_funcall(swig_get_self(), rb_intern("draw_"), 0, NULL);
16
+ + result = rb_funcall(swig_get_self(), rb_intern("protected_draw"), 0, NULL);
19
17
  }
20
18
 
21
19
 
20
+ @@ -2927,7 +2927,7 @@ bool SwigDirector_Window::needsRedraw() const {
21
+ bool c_result ;
22
+ VALUE result;
23
+
24
+ - result = rb_funcall(swig_get_self(), rb_intern("needs_redraw?"), 0, NULL);
25
+ + result = rb_funcall(swig_get_self(), rb_intern("protected_needs_redraw?"), 0, NULL);
26
+ bool swig_val;
27
+ int swig_res = SWIG_AsVal_bool(result, &swig_val);
28
+ if (!SWIG_IsOK(swig_res)) {
29
+ @@ -2942,7 +2942,7 @@ bool SwigDirector_Window::needsCursor() const {
30
+ bool c_result ;
31
+ VALUE result;
32
+
33
+ - result = rb_funcall(swig_get_self(), rb_intern("needs_cursor?"), 0, NULL);
34
+ + result = rb_funcall(swig_get_self(), rb_intern("protected_needs_cursor?"), 0, NULL);
35
+ bool swig_val;
36
+ int swig_res = SWIG_AsVal_bool(result, &swig_val);
37
+ if (!SWIG_IsOK(swig_res)) {
38
+ @@ -2956,7 +2956,7 @@ bool SwigDirector_Window::needsCursor() const {
39
+ void SwigDirector_Window::loseFocus() {
40
+ VALUE result;
41
+
42
+ - result = rb_funcall(swig_get_self(), rb_intern("lose_focus"), 0, NULL);
43
+ + result = rb_funcall(swig_get_self(), rb_intern("protected_lose_focus"), 0, NULL);
44
+ }
45
+
46
+
47
+ @@ -2977,7 +2977,7 @@ void SwigDirector_Window::buttonDown(Gosu::Button arg0) {
48
+ else
49
+ obj0 = LONG2NUM((&arg0)->id());
50
+ }
51
+ - result = rb_funcall(swig_get_self(), rb_intern("button_down"), 1,obj0);
52
+ + result = rb_funcall(swig_get_self(), rb_intern("protected_button_down"), 1,obj0);
53
+ }
54
+
55
+
56
+ @@ -2991,7 +2991,7 @@ void SwigDirector_Window::buttonUp(Gosu::Button arg0) {
57
+ else
58
+ obj0 = LONG2NUM((&arg0)->id());
59
+ }
60
+ - result = rb_funcall(swig_get_self(), rb_intern("button_up"), 1,obj0);
61
+ + result = rb_funcall(swig_get_self(), rb_intern("protected_button_up"), 1,obj0);
62
+ }
@@ -2241,6 +2241,9 @@ static VALUE mGosu;
2241
2241
  #include <Gosu/Utility.hpp>
2242
2242
  #include <Gosu/Version.hpp>
2243
2243
  #include <Gosu/Window.hpp>
2244
+ #ifdef GOSU_IS_WIN
2245
+ #include <FreeImage.h>
2246
+ #endif
2244
2247
 
2245
2248
  namespace Gosu {
2246
2249
  void enableUndocumentedRetrofication() { extern bool undocumentedRetrofication; undocumentedRetrofication = true; }
@@ -2283,17 +2286,49 @@ namespace
2283
2286
  }
2284
2287
  }
2285
2288
 
2286
- // Allow filenames and RMagick Images to be passed where Bitmaps are needed.
2287
2289
  namespace Gosu
2288
2290
  {
2291
+ #ifdef GOSU_IS_WIN
2292
+ void ping_FreeImage()
2293
+ {
2294
+ // Copied and pasted from MSDN.
2295
+ // TODO: Remove duplication, this is also in AudioAudiere.cpp
2296
+ #define FACILITY_VISUALCPP ((LONG)0x6d)
2297
+ #define VcppException(sev,err) ((sev) | (FACILITY_VISUALCPP<<16) | err)
2298
+ #define BAD_MOD VcppException(ERROR_SEVERITY_ERROR, ERROR_MOD_NOT_FOUND)
2299
+
2300
+ __try
2301
+ {
2302
+ FreeImage_GetVersion();
2303
+ }
2304
+ __except ((GetExceptionCode() == BAD_MOD) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
2305
+ {
2306
+ rb_raise(rb_eRuntimeError, "unable to locate FreeImage.dll");
2307
+ }
2308
+ #undef BAD_MOD
2309
+ #undef VcppException
2310
+ #undef FACILITY_VISUALCPP
2311
+ }
2312
+ Bitmap loadImageFile_FreeImage(const std::wstring& filename);
2313
+ #endif
2289
2314
  Gosu::Bitmap loadBitmap(VALUE val)
2290
2315
  {
2291
2316
  // Try to treat as filename first.
2292
2317
  if (rb_respond_to(val, rb_intern("to_str")))
2293
2318
  {
2294
2319
  VALUE to_str = rb_funcall(val, rb_intern("to_str"), 0);
2295
- const char* filename = StringValuePtr(to_str);
2296
- return loadImageFile(Gosu::utf8ToWstring(filename));
2320
+ const char* filenameUTF8 = StringValuePtr(to_str);
2321
+ std::wstring filename = Gosu::utf8ToWstring(filenameUTF8);
2322
+ try {
2323
+ return loadImageFile(filename);
2324
+ } catch (const std::exception&) {
2325
+ #ifdef GOSU_IS_WIN
2326
+ ping_FreeImage();
2327
+ return loadImageFile_FreeImage(filename);
2328
+ #else
2329
+ throw;
2330
+ #endif
2331
+ }
2297
2332
  }
2298
2333
 
2299
2334
  // Otherwise, try to call .to_blob on it (works with RMagick, TexPlay etc).
@@ -2877,14 +2912,14 @@ SwigDirector_Window::~SwigDirector_Window() {
2877
2912
  void SwigDirector_Window::update() {
2878
2913
  VALUE result;
2879
2914
 
2880
- result = rb_funcall(swig_get_self(), rb_intern("update_"), 0, NULL);
2915
+ result = rb_funcall(swig_get_self(), rb_intern("protected_update"), 0, NULL);
2881
2916
  }
2882
2917
 
2883
2918
 
2884
2919
  void SwigDirector_Window::draw() {
2885
2920
  VALUE result;
2886
2921
 
2887
- result = rb_funcall(swig_get_self(), rb_intern("draw_"), 0, NULL);
2922
+ result = rb_funcall(swig_get_self(), rb_intern("protected_draw"), 0, NULL);
2888
2923
  }
2889
2924
 
2890
2925
 
@@ -2892,7 +2927,7 @@ bool SwigDirector_Window::needsRedraw() const {
2892
2927
  bool c_result ;
2893
2928
  VALUE result;
2894
2929
 
2895
- result = rb_funcall(swig_get_self(), rb_intern("needs_redraw?"), 0, NULL);
2930
+ result = rb_funcall(swig_get_self(), rb_intern("protected_needs_redraw?"), 0, NULL);
2896
2931
  bool swig_val;
2897
2932
  int swig_res = SWIG_AsVal_bool(result, &swig_val);
2898
2933
  if (!SWIG_IsOK(swig_res)) {
@@ -2907,7 +2942,7 @@ bool SwigDirector_Window::needsCursor() const {
2907
2942
  bool c_result ;
2908
2943
  VALUE result;
2909
2944
 
2910
- result = rb_funcall(swig_get_self(), rb_intern("needs_cursor?"), 0, NULL);
2945
+ result = rb_funcall(swig_get_self(), rb_intern("protected_needs_cursor?"), 0, NULL);
2911
2946
  bool swig_val;
2912
2947
  int swig_res = SWIG_AsVal_bool(result, &swig_val);
2913
2948
  if (!SWIG_IsOK(swig_res)) {
@@ -2921,7 +2956,7 @@ bool SwigDirector_Window::needsCursor() const {
2921
2956
  void SwigDirector_Window::loseFocus() {
2922
2957
  VALUE result;
2923
2958
 
2924
- result = rb_funcall(swig_get_self(), rb_intern("lose_focus"), 0, NULL);
2959
+ result = rb_funcall(swig_get_self(), rb_intern("protected_lose_focus"), 0, NULL);
2925
2960
  }
2926
2961
 
2927
2962
 
@@ -2942,7 +2977,7 @@ void SwigDirector_Window::buttonDown(Gosu::Button arg0) {
2942
2977
  else
2943
2978
  obj0 = LONG2NUM((&arg0)->id());
2944
2979
  }
2945
- result = rb_funcall(swig_get_self(), rb_intern("button_down"), 1,obj0);
2980
+ result = rb_funcall(swig_get_self(), rb_intern("protected_button_down"), 1,obj0);
2946
2981
  }
2947
2982
 
2948
2983
 
@@ -2956,7 +2991,7 @@ void SwigDirector_Window::buttonUp(Gosu::Button arg0) {
2956
2991
  else
2957
2992
  obj0 = LONG2NUM((&arg0)->id());
2958
2993
  }
2959
- result = rb_funcall(swig_get_self(), rb_intern("button_up"), 1,obj0);
2994
+ result = rb_funcall(swig_get_self(), rb_intern("protected_button_up"), 1,obj0);
2960
2995
  }
2961
2996
 
2962
2997
 
@@ -11085,8 +11120,9 @@ SWIGEXPORT void Init_gosu(void) {
11085
11120
  SWIG_RubyInitializeTrackings();
11086
11121
  rb_define_const(mGosu, "MAJOR_VERSION", SWIG_From_int(static_cast< int >(0)));
11087
11122
  rb_define_const(mGosu, "MINOR_VERSION", SWIG_From_int(static_cast< int >(7)));
11088
- rb_define_const(mGosu, "POINT_VERSION", SWIG_From_int(static_cast< int >(31)));
11089
- rb_define_const(mGosu, "VERSION", SWIG_FromCharPtr("0.7.31"));
11123
+ rb_define_const(mGosu, "POINT_VERSION", SWIG_From_int(static_cast< int >(32)));
11124
+ rb_define_const(mGosu, "VERSION", SWIG_FromCharPtr("0.7.32"));
11125
+ rb_define_const(mGosu, "GOSU_COPYRIGHT_NOTICE", SWIG_FromCharPtr("May contain `ogg\', `vorbis\' libraries (c) 2002-2008 Xiph.org Foundation\n\nRedistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditionsare met:\n\n- Redistributions of source code must retain the above copyrightnotice, this list of conditions and the following disclaimer.\n\n- Redistributions in binary form must reproduce the above copyrightnotice, this list of conditions and the following disclaimer in thedocumentation and/or other materials provided with the distribution.\n\n- Neither the name of the Xiph.org Foundation nor the names of itscontributors may be used to endorse or promote products derived fromthis software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS``AS IS\'\' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOTLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FORA PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATIONOR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOTLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANYTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USEOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."));
11090
11126
  rb_define_module_function(mGosu, "milliseconds", VALUEFUNC(_wrap_milliseconds), -1);
11091
11127
  rb_define_module_function(mGosu, "random", VALUEFUNC(_wrap_random), -1);
11092
11128
  rb_define_module_function(mGosu, "degrees_to_radians", VALUEFUNC(_wrap_degrees_to_radians), -1);
@@ -321,6 +321,9 @@ Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen,
321
321
 
322
322
  pimpl->interval = updateInterval;
323
323
  pimpl->mouseViz = true;
324
+
325
+ // Clear gl error flag if it should accidentally be set. (Huh?)
326
+ while (glGetError() != GL_NO_ERROR);
324
327
  }
325
328
 
326
329
  Gosu::Window::~Window()
@@ -4,7 +4,7 @@
4
4
  ## Date: 2007-10-05
5
5
  ## License: Same as for Gosu (MIT)
6
6
  ## Comments: Based on the Gosu Ruby Tutorial, but incorporating the Chipmunk Physics Engine
7
- ## See http://code.google.com/p/gosu/wiki/RubyChipmunkIntegration for the accompanying text.
7
+ ## See https://github.com/jlnr/gosu/wiki/Ruby-Chipmunk-Integration for the accompanying text.
8
8
 
9
9
  require 'rubygems'
10
10
  require 'gosu'
@@ -1,16 +1,16 @@
1
- require 'rbconfig'
2
-
3
- begin
4
- if defined? RUBY_VERSION and RUBY_VERSION[0..2] == '1.9' then
5
- version = '1_9'
6
- else
7
- version = '1_8'
8
- end
9
- require "#{File.dirname(__FILE__)}/gosu.for_#{version}.#{Config::CONFIG['DLEXT']}"
10
- require "#{File.dirname(__FILE__)}/gosu/swig_patches.rb"
11
- rescue LoadError => e
12
- require "#{File.dirname(__FILE__)}/gosu.#{Config::CONFIG['DLEXT']}"
13
- require "#{File.dirname(__FILE__)}/gosu/swig_patches.rb"
14
- end
15
-
16
- require "#{File.dirname(__FILE__)}/gosu/patches.rb"
1
+ require 'rbconfig'
2
+
3
+ begin
4
+ if defined? RUBY_VERSION and RUBY_VERSION[0..2] == '1.9' then
5
+ version = '1_9'
6
+ else
7
+ version = '1_8'
8
+ end
9
+ require "#{File.dirname(__FILE__)}/gosu.for_#{version}.#{Config::CONFIG['DLEXT']}"
10
+ require "#{File.dirname(__FILE__)}/gosu/swig_patches.rb"
11
+ rescue LoadError => e
12
+ require "#{File.dirname(__FILE__)}/gosu.#{Config::CONFIG['DLEXT']}"
13
+ require "#{File.dirname(__FILE__)}/gosu/swig_patches.rb"
14
+ end
15
+
16
+ require "#{File.dirname(__FILE__)}/gosu/patches.rb"
@@ -3,27 +3,38 @@
3
3
 
4
4
  # Exceptions in Window callbacks often get lost, this is especially annoying in draw/update.
5
5
  # It is not clear whether this is a SWIG issue or if some stack frame is not exception
6
- # compatible, but I just call update_ and draw_ in the Ruby wrapper so I can add this
6
+ # compatible, but I just call protected_update etc. in the Ruby wrapper so I can add this
7
7
  # custom debugging help:
8
8
  class Gosu::Window
9
- def update_
10
- update
11
- rescue Exception => e
12
- puts e.inspect
13
- puts e.backtrace
14
- raise e
9
+ %w(update draw needs_redraw? needs_cursor?
10
+ lose_focus button_down button_up).each do |callback|
11
+ define_method "protected_#{callback}" do |*args|
12
+ begin
13
+ # Turn into a boolean result for needs_cursor? etc while we are at it.
14
+ !!send(callback, *args) unless @_exception
15
+ rescue Exception => e
16
+ # Exit the message loop naturally, then re-throw
17
+ @_exception = e
18
+ close
19
+ end
20
+ end
15
21
  end
16
-
17
- def draw_
18
- draw
19
- rescue Exception => e
20
- puts e.inspect
21
- puts e.backtrace
22
- raise e
22
+
23
+ alias show_internal show
24
+ def show
25
+ show_internal
26
+ # Try to format the message nicely, without any useless patching that we are
27
+ # doing here.
28
+ if @_exception then
29
+ if @_exception.backtrace.is_a? Array and not @_exception.backtrace.frozen? then
30
+ @_exception.backtrace.reject! { |line| line.include? 'lib/gosu/swig_patches.rb' }
31
+ end
32
+ raise @_exception
33
+ end
23
34
  end
24
35
  end
25
36
 
26
- # SWIG doesn't understand the C++ overloading.
37
+ # SWIG doesn't understand the C++ overloading, so we need this simple check in Ruby.
27
38
  class Gosu::Image
28
39
  def self.from_text(*args)
29
40
  args.size == 4 ? from_text4(*args) : from_text7(*args)
@@ -10,7 +10,7 @@ end
10
10
 
11
11
  puts 'The Gosu gem requires some libraries to be installed system-wide.'
12
12
  puts 'See the following site for a list:'
13
- puts 'http://code.google.com/p/gosu/wiki/GettingStartedOnLinux'
13
+ puts 'https://github.com/jlnr/gosu/wiki/Getting-Started-on-Linux'
14
14
  puts
15
15
 
16
16
  BASE_FILES = %w(
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: 61
4
+ hash: 67
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 31
10
- version: 0.7.31
9
+ - 32
10
+ version: 0.7.32
11
11
  platform: ruby
12
12
  authors:
13
13
  - Julian Raschke
@@ -16,8 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-04-30 00:00:00 +08:00
20
- default_executable:
19
+ date: 2011-06-05 00:00:00 Z
21
20
  dependencies: []
22
21
 
23
22
  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 Ruby-OpenGL.\n"
@@ -175,7 +174,6 @@ files:
175
174
  - GosuImpl/WinUtility.cpp
176
175
  - GosuImpl/X11vroot.h
177
176
  - linux/extconf.rb
178
- has_rdoc: true
179
177
  homepage: http://libgosu.org/
180
178
  licenses: []
181
179
 
@@ -205,9 +203,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
203
  - 0
206
204
  version: "0"
207
205
  requirements:
208
- - See http://code.google.com/p/gosu/wiki/GettingStartedOnLinux
206
+ - See https://github.com/jlnr/gosu/wiki/Getting-Started-on-Linux
209
207
  rubyforge_project:
210
- rubygems_version: 1.6.2
208
+ rubygems_version: 1.8.4
211
209
  signing_key:
212
210
  specification_version: 3
213
211
  summary: 2D game development library.