gosu 0.14.0 → 0.14.3.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74fc901e66738f4992205611236f6a7e71e5e3db59f91cda307c54a7b4f1c1d5
4
- data.tar.gz: '08b48f76d3a3d55f5d192551abd7c8c41c6b1a5c8fce354261195a179f7f45c9'
3
+ metadata.gz: 72db8840a17208ca69cb3fe332ab3acb532bba3951b38d117bfb9077f7e541c2
4
+ data.tar.gz: 3a9766f8ca34f70d833756024c1e9716db63b5efbec441f47a55bfe83ae127bb
5
5
  SHA512:
6
- metadata.gz: eb408ee328e685dea6324d6bc8a954b180fd7b1bcb286df3897e7f3b734ba7225c7d05895d21cbfaa9cb168cd59e806a3a16599d9c770603727d9f9a20cb1a7d
7
- data.tar.gz: d033a75590ece4317582ad74f6b2183e0ebe715df51d8993c5d2b3754499ca209bebe6bb31d5e3ec38d5a44fd8516e5bd09de50256cf11782243f353fef21871
6
+ metadata.gz: d498e4bcb3497f40a240ebd3fe1541b5ba9a000353645d80c3157b44cfa4871d257710f2815f46aabb3d01cd68bd5a7fe37d6da5b62d32ea59439dc85c11a748
7
+ data.tar.gz: 3c572470779e3814b3885c16cbeaf05de2754c53dbda66103a08431b7e1f11c25fc925dbdd95e48ed35170f3751928e0995da14e53e0e25eb822a440560a7c14
data/Gosu/Graphics.hpp CHANGED
@@ -60,7 +60,10 @@ namespace Gosu
60
60
  const std::function<void ()>& f);
61
61
 
62
62
  //! Renders everything drawn in f onto a new Image of size (width, height).
63
- static Gosu::Image render(int width, int height, const std::function<void ()>& f);
63
+ //! \param image_flags Pass Gosu::IF_RETRO if you do not want the resulting image to use
64
+ //! interpolation when it is scaled or rotated.
65
+ static Gosu::Image render(int width, int height, const std::function<void ()>& f,
66
+ unsigned image_flags = 0);
64
67
 
65
68
  //! Records a macro and returns it as an Image.
66
69
  static Gosu::Image record(int width, int height, const std::function<void ()>& f);
data/Gosu/Version.hpp CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  #define GOSU_MAJOR_VERSION 0
6
6
  #define GOSU_MINOR_VERSION 14
7
- #define GOSU_POINT_VERSION 0
7
+ #define GOSU_POINT_VERSION 3
8
8
 
9
9
  namespace Gosu
10
10
  {
data/Gosu/Window.hpp CHANGED
@@ -94,7 +94,7 @@ namespace Gosu
94
94
 
95
95
  //! Called before update when the user presses a button while the window has the focus.
96
96
  //! By default, this will toggle fullscreen mode if the user presses Alt+Enter (Windows,
97
- //! Linux) or cmd+F (macOS).
97
+ //! Linux), cmd+F (macOS), or F11 (on all operating systems).
98
98
  //! To support these shortcuts in your application, make sure to call Window::button_down
99
99
  //! in your implementation.
100
100
  virtual void button_down(Gosu::Button);
data/rdoc/gosu.rb CHANGED
@@ -852,8 +852,8 @@ module Gosu
852
852
  ##
853
853
  # This method is called before {#update} if a button is pressed while the window has focus.
854
854
  #
855
- # By default, this method will toggle fullscreen mode if the user presses Alt+Enter (Windows,
856
- # Linux) or cmd+F (macOS).
855
+ # By default, this will toggle fullscreen mode if the user presses Alt+Enter (Windows,
856
+ # Linux), cmd+F (macOS), or F11 (on all operating systems).
857
857
  # To support these shortcuts in your application, make sure to call super in your
858
858
  # implementation.
859
859
  #
@@ -1080,6 +1080,8 @@ module Gosu
1080
1080
  # @return [Gosu::Image] the rendered drawing operations.
1081
1081
  # @param width [Integer] the width of the recorded image.
1082
1082
  # @param height [Integer] the height of the recorded image.
1083
+ # @param [Hash] options
1084
+ # @option options [true, false] :retro (false) if true, the resulting image will not be interpolated when it is scaled up or down.
1083
1085
  # @yield rendering code.
1084
1086
  #
1085
1087
  # @see Window#record
data/src/Audio.cpp CHANGED
@@ -12,11 +12,9 @@
12
12
  #ifdef GOSU_IS_MAC
13
13
  #import <Foundation/Foundation.h>
14
14
  #include "AudioToolboxFile.hpp"
15
- #define WAVE_FILE AudioToolboxFile
16
15
  #else
17
16
  #include "MPEGFile.hpp"
18
17
  #include "SndFile.hpp"
19
- #define WAVE_FILE SndFile
20
18
  #endif
21
19
 
22
20
  #ifdef GOSU_IS_IPHONE
@@ -47,7 +45,7 @@ struct Gosu::Sample::SampleData
47
45
  {
48
46
  ALuint buffer;
49
47
 
50
- SampleData(AudioFile& audio_file)
48
+ SampleData(AudioFile&& audio_file)
51
49
  {
52
50
  al_initialize();
53
51
  alGenBuffers(1, &buffer);
@@ -74,37 +72,41 @@ Gosu::Sample::Sample(const string& filename)
74
72
  {
75
73
  if (is_ogg_file(filename)) {
76
74
  File file(filename);
77
- OggFile ogg_file(file.front_reader());
78
- data.reset(new SampleData(ogg_file));
75
+ data.reset(new SampleData(OggFile(file.front_reader())));
76
+ return;
79
77
  }
80
- else {
81
- WAVE_FILE audio_file(filename);
82
- data.reset(new SampleData(audio_file));
78
+
79
+ #ifdef GOSU_IS_MAC
80
+ File file(filename);
81
+ data.reset(new SampleData(AudioToolboxFile(file.front_reader())));
82
+ #else
83
+ try {
84
+ data.reset(new SampleData(SndFile(filename)));
83
85
  }
86
+ catch (const runtime_error& ex) {
87
+ File file(filename);
88
+ data.reset(new SampleData(MPEGFile(file.front_reader())));
89
+ }
90
+ #endif
84
91
  }
85
92
 
86
93
  Gosu::Sample::Sample(Gosu::Reader reader)
87
94
  {
88
95
  if (is_ogg_file(reader)) {
89
- OggFile ogg_file(reader);
90
- data.reset(new SampleData(ogg_file));
96
+ data.reset(new SampleData(OggFile(reader)));
91
97
  return;
92
98
  }
93
99
 
100
+ #ifdef GOSU_IS_MAC
101
+ data.reset(new SampleData(AudioToolboxFile(reader)));
102
+ #else
94
103
  try {
95
- WAVE_FILE audio_file(reader);
96
- data.reset(new SampleData(audio_file));
104
+ data.reset(new SampleData(SndFile(reader)));
97
105
  }
98
106
  catch (const runtime_error& ex) {
99
- #ifndef GOSU_IS_MAC
100
- if (string(ex.what()).find("unknown format") != string::npos) {
101
- MPEGFile mpeg_file(reader);
102
- data.reset(new SampleData(mpeg_file));
103
- return;
104
- }
105
- #endif
106
- throw ex;
107
+ data.reset(new SampleData(MPEGFile(reader)));
107
108
  }
109
+ #endif
108
110
  }
109
111
 
110
112
  Gosu::Channel Gosu::Sample::play(double volume, double speed, bool looping) const
@@ -252,19 +254,17 @@ public:
252
254
  file.reset(new OggFile(source_file.front_reader()));
253
255
  }
254
256
  else {
257
+ #ifdef GOSU_IS_MAC
258
+ file.reset(new AudioToolboxFile(filename));
259
+ #else
255
260
  try {
256
- file.reset(new WAVE_FILE(filename));
261
+ file.reset(new SndFile(filename));
257
262
  }
258
263
  catch (const runtime_error& ex) {
259
- #ifndef GOSU_IS_MAC
260
- if (string(ex.what()).find("unknown format") != string::npos) {
261
- File source_file(filename);
262
- file.reset(new MPEGFile(source_file.front_reader()));
263
- }
264
- else
265
- #endif
266
- throw ex;
264
+ File source_file(filename);
265
+ file.reset(new MPEGFile(source_file.front_reader()));
267
266
  }
267
+ #endif
268
268
  }
269
269
 
270
270
  al_initialize();
@@ -277,18 +277,16 @@ public:
277
277
  file.reset(new OggFile(reader));
278
278
  }
279
279
  else {
280
+ #ifdef GOSU_IS_MAC
281
+ file.reset(new AudioToolboxFile(reader));
282
+ #else
280
283
  try {
281
- file.reset(new WAVE_FILE(reader));
284
+ file.reset(new SndFile(reader));
282
285
  }
283
286
  catch (const runtime_error& ex) {
284
- #ifndef GOSU_IS_MAC
285
- if (string(ex.what()).find("unknown format") != string::npos) {
286
- file.reset(new MPEGFile(reader));
287
- }
288
- else
289
- #endif
290
- throw ex;
287
+ file.reset(new MPEGFile(reader));
291
288
  }
289
+ #endif
292
290
  }
293
291
 
294
292
  al_initialize();
@@ -401,8 +399,8 @@ Gosu::Song::Song(const string& filename)
401
399
  has_extension(filename, ".aac") ||
402
400
  has_extension(filename, ".m4a")) {
403
401
  data.reset(new ModuleData(filename));
402
+ return;
404
403
  }
405
- else
406
404
  #endif
407
405
  data.reset(new StreamData(filename));
408
406
  }
data/src/Bitmap.cpp CHANGED
@@ -1,24 +1,24 @@
1
- #include <Gosu/Bitmap.hpp>
2
- #include <cassert>
3
- #include <algorithm>
1
+ #include <Gosu/Bitmap.hpp>
2
+ #include <cassert>
3
+ #include <algorithm>
4
4
  #include <vector>
5
- using namespace std;
6
-
7
- void Gosu::Bitmap::swap(Bitmap& other)
8
- {
9
- std::swap(pixels, other.pixels);
10
- std::swap(w, other.w);
11
- std::swap(h, other.h);
12
- }
13
-
14
- void Gosu::Bitmap::resize(unsigned width, unsigned height, Color c)
15
- {
16
- if (width == w && height == h) return;
17
-
18
- Bitmap temp(width, height, c);
19
- temp.insert(*this, 0, 0);
20
- swap(temp);
21
- }
5
+ using namespace std;
6
+
7
+ void Gosu::Bitmap::swap(Bitmap& other)
8
+ {
9
+ std::swap(pixels, other.pixels);
10
+ std::swap(w, other.w);
11
+ std::swap(h, other.h);
12
+ }
13
+
14
+ void Gosu::Bitmap::resize(unsigned width, unsigned height, Color c)
15
+ {
16
+ if (width == w && height == h) return;
17
+
18
+ Bitmap temp(width, height, c);
19
+ temp.insert(*this, 0, 0);
20
+ swap(temp);
21
+ }
22
22
 
23
23
  void Gosu::Bitmap::blend_pixel(unsigned x, unsigned y, Color c)
24
24
  {
@@ -39,146 +39,160 @@ void Gosu::Bitmap::blend_pixel(unsigned x, unsigned y, Color c)
39
39
 
40
40
  set_pixel(x, y, out);
41
41
  }
42
-
43
- void Gosu::Bitmap::insert(const Bitmap& source, int x, int y)
44
- {
45
- insert(source, x, y, 0, 0, source.width(), source.height());
46
- }
47
-
48
- void Gosu::Bitmap::insert(const Bitmap& source, int x, int y, unsigned src_x, unsigned src_y,
49
- unsigned src_width, unsigned src_height)
50
- {
51
- // TODO: This should use memcpy if possible (x == 0 && src_width == this->width())
52
-
53
- if (x < 0) {
54
- unsigned clip_left = -x;
55
-
56
- if (clip_left >= src_width) return;
57
-
58
- src_x += clip_left;
59
- src_width -= clip_left;
60
- x = 0;
61
- }
62
-
63
- if (y < 0) {
64
- unsigned clip_top = -y;
65
-
66
- if (clip_top >= src_height) return;
67
-
68
- src_y += clip_top;
69
- src_height -= clip_top;
70
- y = 0;
71
- }
72
-
73
- if (x + src_width > w) {
74
- if (static_cast<unsigned>(x) >= w) return;
75
-
76
- src_width = w - x;
77
- }
78
-
79
- if (y + src_height > h) {
80
- if (static_cast<unsigned>(y) >= h) return;
81
-
82
- src_height = h - y;
83
- }
84
-
85
- for (unsigned rel_y = 0; rel_y < src_height; ++rel_y) {
86
- for (unsigned rel_x = 0; rel_x < src_width; ++rel_x) {
42
+
43
+ void Gosu::Bitmap::insert(const Bitmap& source, int x, int y)
44
+ {
45
+ insert(source, x, y, 0, 0, source.width(), source.height());
46
+ }
47
+
48
+ void Gosu::Bitmap::insert(const Bitmap& source, int x, int y, unsigned src_x, unsigned src_y,
49
+ unsigned src_width, unsigned src_height)
50
+ {
51
+ // TODO: This should use memcpy if possible (x == 0 && src_width == this->width())
52
+
53
+ if (x < 0) {
54
+ unsigned clip_left = -x;
55
+
56
+ if (clip_left >= src_width) return;
57
+
58
+ src_x += clip_left;
59
+ src_width -= clip_left;
60
+ x = 0;
61
+ }
62
+
63
+ if (y < 0) {
64
+ unsigned clip_top = -y;
65
+
66
+ if (clip_top >= src_height) return;
67
+
68
+ src_y += clip_top;
69
+ src_height -= clip_top;
70
+ y = 0;
71
+ }
72
+
73
+ if (x + src_width > w) {
74
+ if (static_cast<unsigned>(x) >= w) return;
75
+
76
+ src_width = w - x;
77
+ }
78
+
79
+ if (y + src_height > h) {
80
+ if (static_cast<unsigned>(y) >= h) return;
81
+
82
+ src_height = h - y;
83
+ }
84
+
85
+ for (unsigned rel_y = 0; rel_y < src_height; ++rel_y) {
86
+ for (unsigned rel_x = 0; rel_x < src_width; ++rel_x) {
87
87
  set_pixel(x + rel_x, y + rel_y, source.get_pixel(src_x + rel_x, src_y + rel_y));
88
88
  }
89
- }
90
- }
91
-
92
- void Gosu::apply_color_key(Bitmap& bitmap, Color key)
93
- {
94
- vector<Color> surrounding_colors;
95
- surrounding_colors.reserve(4);
96
-
97
- for (unsigned y = 0; y < bitmap.height(); ++y)
98
- for (unsigned x = 0; x < bitmap.width(); ++x)
99
- if (bitmap.get_pixel(x, y) == key) {
100
- surrounding_colors.clear();
101
- if (x > 0 && bitmap.get_pixel(x - 1, y) != key)
102
- surrounding_colors.push_back(bitmap.get_pixel(x - 1, y));
103
- if (x < bitmap.width() - 1 && bitmap.get_pixel(x + 1, y) != key)
104
- surrounding_colors.push_back(bitmap.get_pixel(x + 1, y));
105
- if (y > 0 && bitmap.get_pixel(x, y - 1) != key)
106
- surrounding_colors.push_back(bitmap.get_pixel(x, y - 1));
107
- if (y < bitmap.height() - 1 && bitmap.get_pixel(x, y + 1) != key)
108
- surrounding_colors.push_back(bitmap.get_pixel(x, y + 1));
109
-
110
- if (surrounding_colors.empty()) {
111
- bitmap.set_pixel(x, y, Color::NONE);
112
- continue;
113
- }
114
-
115
- unsigned red = 0, green = 0, blue = 0;
116
- for (auto& color : surrounding_colors) {
117
- red += color.red();
118
- green += color.green();
119
- blue += color.blue();
120
- }
89
+ }
90
+ }
91
+
92
+ void Gosu::apply_color_key(Bitmap& bitmap, Color key)
93
+ {
94
+ vector<Color> surrounding_colors;
95
+ surrounding_colors.reserve(4);
96
+
97
+ for (unsigned y = 0; y < bitmap.height(); ++y) {
98
+ for (unsigned x = 0; x < bitmap.width(); ++x) {
99
+ if (bitmap.get_pixel(x, y) == key) {
100
+ surrounding_colors.clear();
101
+ if (x > 0 && bitmap.get_pixel(x - 1, y) != key) {
102
+ surrounding_colors.push_back(bitmap.get_pixel(x - 1, y));
103
+ }
104
+ if (x < bitmap.width() - 1 && bitmap.get_pixel(x + 1, y) != key) {
105
+ surrounding_colors.push_back(bitmap.get_pixel(x + 1, y));
106
+ }
107
+ if (y > 0 && bitmap.get_pixel(x, y - 1) != key) {
108
+ surrounding_colors.push_back(bitmap.get_pixel(x, y - 1));
109
+ }
110
+ if (y < bitmap.height() - 1 && bitmap.get_pixel(x, y + 1) != key) {
111
+ surrounding_colors.push_back(bitmap.get_pixel(x, y + 1));
112
+ }
113
+
114
+ if (surrounding_colors.empty()) {
115
+ bitmap.set_pixel(x, y, Color::NONE);
116
+ continue;
117
+ }
118
+
119
+ unsigned red = 0, green = 0, blue = 0;
120
+ for (auto& color : surrounding_colors) {
121
+ red += color.red();
122
+ green += color.green();
123
+ blue += color.blue();
124
+ }
121
125
  bitmap.set_pixel(x, y, Color(0,
122
- red / surrounding_colors.size(),
126
+ red / surrounding_colors.size(),
123
127
  green / surrounding_colors.size(),
124
- blue / surrounding_colors.size()));
125
- }
126
- }
127
-
128
- void Gosu::unapply_color_key(Bitmap& bitmap, Color color)
129
- {
130
- Color* p = bitmap.data();
131
- for (int i = bitmap.width() * bitmap.height(); i > 0; --i, ++p) {
132
- if (p->alpha() == 0) {
128
+ blue / surrounding_colors.size()));
129
+ }
130
+ }
131
+ }
132
+ }
133
+
134
+ void Gosu::unapply_color_key(Bitmap& bitmap, Color color)
135
+ {
136
+ Color* p = bitmap.data();
137
+ for (int i = bitmap.width() * bitmap.height(); i > 0; --i, ++p) {
138
+ if (p->alpha() == 0) {
133
139
  *p = color;
134
- }
135
- else {
140
+ }
141
+ else {
136
142
  p->set_alpha(255);
137
143
  }
138
- }
139
- }
140
-
141
- void Gosu::apply_border_flags(Bitmap& dest, const Bitmap& source, unsigned src_x, unsigned src_y,
142
- unsigned src_width, unsigned src_height, unsigned image_flags)
143
- {
144
- // Backward compatibility: This used to be 'bool tileable'.
145
- if (image_flags == 1) image_flags = IF_TILEABLE;
146
-
147
- dest.resize(src_width + 2, src_height + 2);
148
-
149
- // The borders are made "harder" by duplicating the original bitmap's
150
- // borders.
151
-
152
- // Top.
153
- if (image_flags & IF_TILEABLE_TOP)
154
- dest.insert(source, 1, 0, src_x, src_y, src_width, 1);
155
- // Bottom.
156
- if (image_flags & IF_TILEABLE_BOTTOM)
157
- dest.insert(source, 1, dest.height() - 1, src_x, src_y + src_height - 1, src_width, 1);
158
- // Left.
159
- if (image_flags & IF_TILEABLE_LEFT)
160
- dest.insert(source, 0, 1, src_x, src_y, 1, src_height);
161
- // Right.
162
- if (image_flags & IF_TILEABLE_RIGHT)
163
- dest.insert(source, dest.width() - 1, 1, src_x + src_width - 1, src_y, 1, src_height);
164
-
165
- // Top left.
166
- if ((image_flags & IF_TILEABLE_TOP) && (image_flags & IF_TILEABLE_LEFT))
144
+ }
145
+ }
146
+
147
+ void Gosu::apply_border_flags(Bitmap& dest, const Bitmap& source, unsigned src_x, unsigned src_y,
148
+ unsigned src_width, unsigned src_height, unsigned image_flags)
149
+ {
150
+ // Backward compatibility: This used to be 'bool tileable'.
151
+ if (image_flags == 1) image_flags = IF_TILEABLE;
152
+
153
+ dest.resize(src_width + 2, src_height + 2);
154
+
155
+ // The borders are made "harder" by duplicating the original bitmap's
156
+ // borders.
157
+
158
+ // Top.
159
+ if (image_flags & IF_TILEABLE_TOP) {
160
+ dest.insert(source, 1, 0, src_x, src_y, src_width, 1);
161
+ }
162
+ // Bottom.
163
+ if (image_flags & IF_TILEABLE_BOTTOM) {
164
+ dest.insert(source, 1, dest.height() - 1, src_x, src_y + src_height - 1, src_width, 1);
165
+ }
166
+ // Left.
167
+ if (image_flags & IF_TILEABLE_LEFT) {
168
+ dest.insert(source, 0, 1, src_x, src_y, 1, src_height);
169
+ }
170
+ // Right.
171
+ if (image_flags & IF_TILEABLE_RIGHT) {
172
+ dest.insert(source, dest.width() - 1, 1, src_x + src_width - 1, src_y, 1, src_height);
173
+ }
174
+
175
+ // Top left.
176
+ if ((image_flags & IF_TILEABLE_TOP) && (image_flags & IF_TILEABLE_LEFT)) {
167
177
  dest.set_pixel(0, 0,
168
- source.get_pixel(src_x, src_y));
169
- // Top right.
170
- if ((image_flags & IF_TILEABLE_TOP) && (image_flags & IF_TILEABLE_RIGHT))
178
+ source.get_pixel(src_x, src_y));
179
+ }
180
+ // Top right.
181
+ if ((image_flags & IF_TILEABLE_TOP) && (image_flags & IF_TILEABLE_RIGHT)) {
171
182
  dest.set_pixel(dest.width() - 1, 0,
172
- source.get_pixel(src_x + src_width - 1, src_y));
173
- // Bottom left.
174
- if ((image_flags & IF_TILEABLE_BOTTOM) && (image_flags & IF_TILEABLE_LEFT))
183
+ source.get_pixel(src_x + src_width - 1, src_y));
184
+ }
185
+ // Bottom left.
186
+ if ((image_flags & IF_TILEABLE_BOTTOM) && (image_flags & IF_TILEABLE_LEFT)) {
175
187
  dest.set_pixel(0, dest.height() - 1,
176
- source.get_pixel(src_x, src_y + src_height - 1));
177
- // Bottom right.
178
- if ((image_flags & IF_TILEABLE_BOTTOM) && (image_flags & IF_TILEABLE_RIGHT))
179
- dest.set_pixel(dest.width() - 1, dest.height() - 1,
180
- source.get_pixel(src_x + src_width - 1, src_y + src_height - 1));
181
-
182
- // Now put the final image into the prepared borders.
183
- dest.insert(source, 1, 1, src_x, src_y, src_width, src_height);
184
- }
188
+ source.get_pixel(src_x, src_y + src_height - 1));
189
+ }
190
+ // Bottom right.
191
+ if ((image_flags & IF_TILEABLE_BOTTOM) && (image_flags & IF_TILEABLE_RIGHT)) {
192
+ dest.set_pixel(dest.width() - 1, dest.height() - 1,
193
+ source.get_pixel(src_x + src_width - 1, src_y + src_height - 1));
194
+ }
195
+
196
+ // Now put the final image into the prepared borders.
197
+ dest.insert(source, 1, 1, src_x, src_y, src_width, src_height);
198
+ }