gosu 1.4.6 → 2.0.0.pre6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/COPYING +2 -1
  3. data/dependencies/SDL/include/SDL_atomic.h +2 -3
  4. data/dependencies/SDL/include/SDL_audio.h +7 -7
  5. data/dependencies/SDL/include/SDL_blendmode.h +1 -1
  6. data/dependencies/SDL/include/SDL_endian.h +3 -3
  7. data/dependencies/SDL/include/SDL_gamecontroller.h +4 -4
  8. data/dependencies/SDL/include/SDL_hints.h +72 -28
  9. data/dependencies/SDL/include/SDL_joystick.h +8 -5
  10. data/dependencies/SDL/include/SDL_keycode.h +1 -1
  11. data/dependencies/SDL/include/SDL_main.h +7 -0
  12. data/dependencies/SDL/include/SDL_mouse.h +6 -7
  13. data/dependencies/SDL/include/SDL_mutex.h +79 -5
  14. data/dependencies/SDL/include/SDL_opengl_glext.h +5 -1
  15. data/dependencies/SDL/include/SDL_power.h +7 -8
  16. data/dependencies/SDL/include/SDL_render.h +5 -0
  17. data/dependencies/SDL/include/SDL_revision.h +2 -2
  18. data/dependencies/SDL/include/SDL_sensor.h +1 -1
  19. data/dependencies/SDL/include/SDL_stdinc.h +19 -11
  20. data/dependencies/SDL/include/SDL_thread.h +2 -2
  21. data/dependencies/SDL/include/SDL_version.h +2 -2
  22. data/dependencies/SDL/include/SDL_video.h +30 -2
  23. data/dependencies/SDL/include/begin_code.h +7 -7
  24. data/dependencies/SDL/include/close_code.h +2 -2
  25. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  26. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  27. data/dependencies/SDL_sound/SDL_sound.h +1 -1
  28. data/dependencies/SDL_sound/dr_flac.h +48 -23
  29. data/dependencies/SDL_sound/dr_mp3.h +34 -14
  30. data/dependencies/SDL_sound/stb_vorbis.h +3 -2
  31. data/dependencies/mojoAL/mojoal.c +1 -1
  32. data/ext/{gosu → gosu-ffi}/extconf.rb +34 -33
  33. data/ext/gosu-ffi/gosu-ffi.def +464 -0
  34. data/ffi/Gosu.cpp +307 -0
  35. data/ffi/Gosu.h +84 -0
  36. data/ffi/Gosu_Channel.cpp +62 -0
  37. data/ffi/Gosu_Channel.h +17 -0
  38. data/ffi/Gosu_Color.cpp +132 -0
  39. data/ffi/Gosu_Color.h +31 -0
  40. data/ffi/Gosu_Constants.cpp +334 -0
  41. data/ffi/Gosu_FFI.h +34 -0
  42. data/ffi/Gosu_FFI_internal.h +161 -0
  43. data/ffi/Gosu_Font.cpp +92 -0
  44. data/ffi/Gosu_Font.h +32 -0
  45. data/ffi/Gosu_Image.cpp +206 -0
  46. data/ffi/Gosu_Image.h +60 -0
  47. data/ffi/Gosu_Sample.cpp +29 -0
  48. data/ffi/Gosu_Sample.h +14 -0
  49. data/ffi/Gosu_Song.cpp +69 -0
  50. data/ffi/Gosu_Song.h +18 -0
  51. data/ffi/Gosu_TextInput.cpp +94 -0
  52. data/ffi/Gosu_TextInput.h +25 -0
  53. data/ffi/Gosu_Window.cpp +314 -0
  54. data/ffi/Gosu_Window.h +78 -0
  55. data/include/Gosu/Audio.hpp +6 -11
  56. data/include/Gosu/Bitmap.hpp +38 -53
  57. data/include/Gosu/Buffer.hpp +54 -0
  58. data/include/Gosu/Color.hpp +27 -35
  59. data/include/Gosu/Directories.hpp +25 -28
  60. data/include/Gosu/Drawable.hpp +58 -0
  61. data/include/Gosu/Font.hpp +6 -5
  62. data/include/Gosu/Fwd.hpp +4 -6
  63. data/include/Gosu/Gosu.hpp +5 -5
  64. data/include/Gosu/Graphics.hpp +51 -61
  65. data/include/Gosu/GraphicsBase.hpp +1 -11
  66. data/include/Gosu/Image.hpp +11 -14
  67. data/include/Gosu/Math.hpp +50 -72
  68. data/include/Gosu/Transform.hpp +32 -0
  69. data/include/Gosu/Utility.hpp +51 -1
  70. data/include/Gosu/Version.hpp +3 -3
  71. data/include/Gosu/Window.hpp +15 -9
  72. data/lib/SDL2.dll +0 -0
  73. data/lib/gosu/channel.rb +49 -0
  74. data/lib/gosu/color.rb +150 -0
  75. data/lib/gosu/compat.rb +29 -8
  76. data/lib/gosu/constants.rb +386 -0
  77. data/lib/gosu/ffi.rb +258 -0
  78. data/lib/gosu/font.rb +56 -0
  79. data/lib/gosu/gl_tex_info.rb +33 -0
  80. data/lib/gosu/gosu.rb +210 -0
  81. data/lib/gosu/image.rb +141 -0
  82. data/lib/gosu/numeric.rb +17 -0
  83. data/lib/gosu/preview.rb +6 -6
  84. data/lib/gosu/sample.rb +24 -0
  85. data/lib/gosu/song.rb +56 -0
  86. data/lib/gosu/text_input.rb +69 -0
  87. data/lib/gosu/window.rb +228 -0
  88. data/lib/gosu.rb +29 -8
  89. data/lib64/SDL2.dll +0 -0
  90. data/rdoc/gosu.rb +0 -2
  91. data/src/Audio.cpp +12 -12
  92. data/src/AudioFile.hpp +5 -4
  93. data/src/AudioFileAudioToolbox.cpp +8 -8
  94. data/src/AudioFileSDLSound.cpp +7 -10
  95. data/src/BinPacker.cpp +187 -0
  96. data/src/BinPacker.hpp +55 -0
  97. data/src/Bitmap.cpp +166 -144
  98. data/src/BitmapIO.cpp +60 -86
  99. data/src/Buffer.cpp +159 -0
  100. data/src/Color.cpp +75 -80
  101. data/src/Directories.cpp +47 -0
  102. data/src/DirectoriesUIKit.cpp +50 -0
  103. data/src/DrawOp.hpp +9 -4
  104. data/src/DrawOpQueue.hpp +2 -2
  105. data/src/Drawable.cpp +95 -0
  106. data/src/EmptyDrawable.hpp +38 -0
  107. data/src/FPS.cpp +31 -0
  108. data/src/Font.cpp +104 -74
  109. data/src/GosuGLView.cpp +14 -6
  110. data/src/GosuViewController.cpp +2 -10
  111. data/src/Graphics.cpp +60 -126
  112. data/src/GraphicsImpl.hpp +17 -47
  113. data/src/Image.cpp +41 -35
  114. data/src/Input.cpp +7 -8
  115. data/src/Macro.cpp +6 -6
  116. data/src/Macro.hpp +4 -4
  117. data/src/MarkupParser.cpp +5 -5
  118. data/src/Math.cpp +35 -22
  119. data/src/OffScreenTarget.cpp +53 -49
  120. data/src/OffScreenTarget.hpp +13 -11
  121. data/src/OpenGLContext.cpp +117 -0
  122. data/src/OpenGLContext.hpp +41 -0
  123. data/src/RenderState.hpp +21 -19
  124. data/src/Resolution.cpp +23 -21
  125. data/src/TexChunk.cpp +35 -80
  126. data/src/TexChunk.hpp +44 -35
  127. data/src/Text.cpp +1 -1
  128. data/src/TextBuilder.cpp +35 -21
  129. data/src/TextBuilder.hpp +6 -9
  130. data/src/Texture.cpp +62 -80
  131. data/src/Texture.hpp +25 -23
  132. data/src/TiledDrawable.cpp +150 -0
  133. data/src/TiledDrawable.hpp +47 -0
  134. data/src/TimingApple.cpp +1 -1
  135. data/src/Transform.cpp +45 -50
  136. data/src/TransformStack.hpp +16 -16
  137. data/src/TrueTypeFont.cpp +59 -51
  138. data/src/TrueTypeFont.hpp +6 -7
  139. data/src/TrueTypeFontApple.cpp +28 -19
  140. data/src/TrueTypeFontUnix.cpp +27 -23
  141. data/src/TrueTypeFontWin.cpp +30 -30
  142. data/src/Utility.cpp +84 -21
  143. data/src/UtilityWin.cpp +45 -0
  144. data/src/Window.cpp +92 -142
  145. data/src/WindowUIKit.cpp +14 -14
  146. metadata +72 -31
  147. data/include/Gosu/IO.hpp +0 -254
  148. data/include/Gosu/ImageData.hpp +0 -53
  149. data/include/Gosu/Inspection.hpp +0 -7
  150. data/lib/gosu/patches.rb +0 -66
  151. data/lib/gosu/run.rb +0 -20
  152. data/lib/gosu/swig_patches.rb +0 -110
  153. data/src/BlockAllocator.cpp +0 -131
  154. data/src/BlockAllocator.hpp +0 -32
  155. data/src/DirectoriesApple.cpp +0 -69
  156. data/src/DirectoriesUnix.cpp +0 -46
  157. data/src/DirectoriesWin.cpp +0 -65
  158. data/src/EmptyImageData.hpp +0 -52
  159. data/src/FileUnix.cpp +0 -99
  160. data/src/FileWin.cpp +0 -88
  161. data/src/IO.cpp +0 -60
  162. data/src/Iconv.hpp +0 -51
  163. data/src/Inspection.cpp +0 -27
  164. data/src/LargeImageData.cpp +0 -215
  165. data/src/LargeImageData.hpp +0 -39
  166. data/src/Log.hpp +0 -19
  167. data/src/RubyGosu.cxx +0 -13100
  168. data/src/RubyGosu.h +0 -49
  169. data/src/WinUtility.cpp +0 -61
  170. data/src/WinUtility.hpp +0 -27
@@ -1,96 +1,74 @@
1
1
  #pragma once
2
2
 
3
- #include <cmath>
4
-
5
- // Portability: Define M_PI, which MSVC's <cmath> does not do by default.
6
- #if !defined(M_PI) && !defined(SWIG)
7
- #define M_PI 3.14159265358979323846264338327950288
8
- #endif
3
+ #include <numbers>
9
4
 
10
5
  namespace Gosu
11
6
  {
12
- //! Returns a real value between min (inclusive) and max (exclusive).
13
- //! Uses std::rand, so you should call std::srand before using it.
7
+ /// Returns a double value between min (inclusive) and max (exclusive).
8
+ /// This function returns random values based on a uniform distribution.
9
+ /// Special case: If min and max are the same value, then that value is returned.
14
10
  double random(double min, double max);
15
-
16
- //! Translates between Gosu's angle system (where 0 is at the top)
17
- //! and radians (where 0 is at the right).
18
- inline double gosu_to_radians(double angle)
11
+
12
+ /// Translates between 360° degrees (as used by Gosu) and radians, but does not change the
13
+ /// origin from the top to the right.
14
+ inline double degrees_to_radians(double angle)
19
15
  {
20
- return (angle - 90) * M_PI / 180;
16
+ return angle * std::numbers::pi / 180;
21
17
  }
22
- //! Translates between Gosu's angle system (where 0 is at the top)
23
- //! and radians (where 0 is at the right).
24
- inline double radians_to_gosu(double angle)
18
+
19
+ /// Translates between 360° degrees (as used by Gosu) and radians, but does not change the
20
+ /// origin from the right to the top.
21
+ inline double radians_to_degrees(double angle)
25
22
  {
26
- return angle * 180 / M_PI + 90;
23
+ return angle * 180 / std::numbers::pi;
27
24
  }
28
25
 
29
- //! Translates between degrees (used by Gosu) and radians, i.e. it
30
- //! does not change the 'origin' of the angle system.
31
- inline double degrees_to_radians(double angle)
26
+ /// Translates between Gosu's 360° angle system, where 0 is at the top, and radians, where 0 is
27
+ /// to the right.
28
+ inline double radians_to_angle(double angle)
32
29
  {
33
- return angle * M_PI / 180;
30
+ return radians_to_degrees(angle) + 90;
34
31
  }
35
- //! Translates between degrees (used by Gosu) and radians, i.e. it
36
- //! does not change the 'origin' of the angle system.
37
- inline double radians_to_degrees(double angle)
32
+
33
+ /// Translates between Gosu's 360° angle system, where 0 is at the top, and radians, where 0 is
34
+ /// to the right.
35
+ inline double angle_to_radians(double angle)
38
36
  {
39
- return angle * 180 / M_PI;
37
+ return degrees_to_radians(angle - 90);
40
38
  }
41
-
42
- //! Returns the horizontal distance between the origin and the point to
43
- //! which you would get if you moved radius pixels in the direction
44
- //! specified by angle.
45
- //! \param angle Angle in degrees where 0.0 means upwards.
39
+
40
+ /// Returns the horizontal distance between the origin and the point to
41
+ /// which you would get if you moved radius pixels in the direction
42
+ /// specified by angle.
43
+ /// @param angle Angle in degrees where 0.0 means upwards.
46
44
  double offset_x(double angle, double radius);
47
- //! Returns the vertical distance between the origin and the point to
48
- //! which you would get if you moved radius pixels in the direction
49
- //! specified by angle.
50
- //! \param angle Angle in degrees where 0.0 means upwards.
45
+
46
+ /// Returns the vertical distance between the origin and the point to
47
+ /// which you would get if you moved radius pixels in the direction
48
+ /// specified by angle.
49
+ /// @param angle Angle in degrees where 0.0 means upwards.
51
50
  double offset_y(double angle, double radius);
52
- //! Returns the angle from point 1 to point 2 in degrees, where 0.0 means
53
- //! upwards. Returns def if both points are equal.
54
- double angle(double from_x, double from_y, double to_x, double to_y, double def = 0);
55
- //! Returns the smallest angle that can be added to angle1 to get to
56
- //! angle2 (can be negative if counter-clockwise movement is shorter).
51
+
52
+ /// Returns the angle from the first point to the second point in degrees, where 0.0 points up.
53
+ /// Returns "fallback" if both points are equal.
54
+ double angle(double from_x, double from_y, double to_x, double to_y, double fallback = 0);
55
+
56
+ /// Returns the smallest angle that can be added to angle1 to get to angle2.
57
+ /// The result can be negative if counter-clockwise movement is shorter.
57
58
  double angle_diff(double angle1, double angle2);
58
- //! Normalizes an angle to fit into the range [0; 360[.
59
+
60
+ /// Normalizes an angle to fit into the range [0; 360[.
59
61
  double normalize_angle(double angle);
60
-
61
- //! Returns value * value.
62
- template<typename T>
63
- T square(T value)
64
- {
65
- return value * value;
66
- }
67
62
 
68
- //! Returns (value-min) % (max-min) + min, where % always has a positive
69
- //! result for max > min. The results are undefined for max <= min.
70
- //! Note: This means that max is exclusive.
63
+ /// Returns (value-min) % (max-min) + min, where % always has a positive
64
+ /// result for max > min. The results are undefined for max <= min.
65
+ /// Note: This means that max is exclusive.
71
66
  int wrap(int value, int min, int max);
72
- //! Returns (value-min) % (max-min) + min, where % always has a positive
73
- //! result for max > min. The results are undefined for max <= min.
74
- //! Note: This means that max is exclusive.
75
- float wrap(float value, float min, float max);
76
- //! Returns (value-min) % (max-min) + min, where % always has a positive
77
- //! result for max > min. The results are undefined for max <= min.
78
- //! Note: This means that max is exclusive.
67
+ /// Returns (value-min) % (max-min) + min, where % always has a positive
68
+ /// result for max > min. The results are undefined for max <= min.
69
+ /// Note: This means that max is exclusive.
79
70
  double wrap(double value, double min, double max);
80
-
81
- //! Returns the square of the distance between two points.
82
- inline double distance_sqr(double x1, double y1, double x2, double y2)
83
- {
84
- return square(x1 - x2) + square(y1 - y2);
85
- }
86
-
87
- //! Returns the distance between two points.
71
+
72
+ /// Returns the distance between two points.
88
73
  double distance(double x1, double y1, double x2, double y2);
89
-
90
- //! Placeholder for std::lerp, will be removed when Gosu requires C++20.
91
- template<typename T>
92
- T lerp(T a, T b, double t = 0.5)
93
- {
94
- return a * (1.0 - t) + b * t;
95
- }
96
74
  }
@@ -0,0 +1,32 @@
1
+ #pragma once
2
+
3
+ #include <array>
4
+
5
+ namespace Gosu
6
+ {
7
+ /// Describes an affine transformation that can be temporarily applied to everything on the
8
+ /// screen using the Gosu::Graphics::transform() method.
9
+ struct Transform
10
+ {
11
+ /// The 4x4 transformation matrix in row-major order: matrix[row * 4 + column].
12
+ std::array<double, 16> matrix;
13
+
14
+ /// Applies this transform to the given point.
15
+ void apply(double& x, double& y) const;
16
+
17
+ [[nodiscard]] static Transform translate(double x, double y);
18
+ [[nodiscard]] static Transform rotate(double angle);
19
+ [[nodiscard]] static Transform scale(double factor);
20
+ [[nodiscard]] static Transform scale(double scale_x, double scale_y);
21
+ /// This helper is supposed to be used on the return value of rotate() or scale() in order
22
+ /// to set the center around which to rotate/scale. It will not have any effect on the
23
+ /// return value of translate().
24
+ [[nodiscard]] Transform around(double around_x, double around_y) const;
25
+
26
+ /// Performs a matrix multiplication that has the effect of "concatenating" transforms.
27
+ /// The left-hand side will be applied to a point before the right-hand side.
28
+ Transform operator*(const Transform& rhs) const;
29
+
30
+ bool operator==(const Transform&) const = default;
31
+ };
32
+ }
@@ -1,14 +1,32 @@
1
1
  #pragma once
2
2
 
3
+ #include <Gosu/Platform.hpp>
3
4
  #include <string>
5
+ #include <string_view>
4
6
  #include <vector>
5
7
 
6
8
  namespace Gosu
7
9
  {
8
- std::u32string utf8_to_composed_utc4(const std::string& utf8);
10
+ /// Converts a UTF-8 string to composed UTC-4, i.e. to a list of Unicode codepoints.
11
+ ///
12
+ /// This is not quite as good as splitting a string into graphemes. For example, the "family of
13
+ /// four" Emoji is actually composed of seven(!) codepoints. But because Gosu's text rendering
14
+ /// facilities have no support for multi-codepoint graphemes, Gosu::Font and related classes are
15
+ /// based on codepoints.
16
+ ///
17
+ /// This method will silently skip over invalid UTF-8 sequences.
18
+ std::u32string utf8_to_composed_utc4(std::string_view utf8);
19
+
20
+ #ifdef GOSU_IS_WIN
21
+ /// Converts UTF-8 to UTF-16, as it is used in "UNICODE" Windows APIs.
22
+ std::wstring utf8_to_utf16(const std::string& utf8);
23
+ /// Converts UTF-16 to UTF-8.
24
+ std::string utf16_to_utf8(const std::wstring& utf16);
25
+ #endif
9
26
 
10
27
  /// Returns true if the filename has the given extension.
11
28
  /// The comparison is case-insensitive, but you must pass the extension in lower case.
29
+ /// If the extension does not start with a dot, then it will be implied.
12
30
  bool has_extension(std::string_view filename, std::string_view extension);
13
31
 
14
32
  /// Returns the user's preferred user_languages/locales, e.g. {"en_US", "de_DE", "ja"}.
@@ -17,6 +35,7 @@ namespace Gosu
17
35
  /// typically the first language in the returned array that your game supports.
18
36
  std::vector<std::string> user_languages();
19
37
 
38
+ /// Base class to quickly make a type non-copyable/non-movable. Same as boost::noncopyable.
20
39
  class Noncopyable
21
40
  {
22
41
  protected:
@@ -30,4 +49,35 @@ namespace Gosu
30
49
  Noncopyable(Noncopyable&& other) = delete;
31
50
  Noncopyable& operator=(Noncopyable&& other) = delete;
32
51
  };
52
+
53
+ /// An int-based rectangle class, mostly for internal use.
54
+ struct Rect
55
+ {
56
+ int x = 0, y = 0;
57
+ int width = 0, height = 0;
58
+
59
+ int right() const { return x + width; }
60
+ int bottom() const { return y + height; }
61
+
62
+ bool empty() const { return width <= 0 || height <= 0; }
63
+
64
+ /// Returns a Rect that starts at the origin and uses T::width() and T::height() as its
65
+ /// extents.
66
+ template <typename T> static Rect covering(const T& object)
67
+ {
68
+ return Rect { .x = 0, .y = 0, .width = object.width(), .height = object.height() };
69
+ }
70
+
71
+ bool overlaps(const Rect& other) const;
72
+ bool contains(const Rect& other) const;
73
+
74
+ /// Makes sure that this rectangle does not exceed the bounding box.
75
+ /// @param adjust_x If the rectangle origin will be moved to the right by this operation,
76
+ /// then the pointed-to int (if any) will be adjusted by the same amount.
77
+ /// @param adjust_y If the rectangle origin will be moved down by this operation,
78
+ /// then the pointed-to int (if any) will be adjusted by the same amount.
79
+ void clip_to(const Rect& bounding_box, int* adjust_x = nullptr, int* adjust_y = nullptr);
80
+
81
+ bool operator==(const Rect& other) const = default;
82
+ };
33
83
  }
@@ -2,9 +2,9 @@
2
2
 
3
3
  #include <string>
4
4
 
5
- #define GOSU_MAJOR_VERSION 1
6
- #define GOSU_MINOR_VERSION 4
7
- #define GOSU_POINT_VERSION 6
5
+ #define GOSU_MAJOR_VERSION 2
6
+ #define GOSU_MINOR_VERSION 0
7
+ #define GOSU_POINT_VERSION 0
8
8
 
9
9
  namespace Gosu
10
10
  {
@@ -7,6 +7,8 @@
7
7
  #include <memory>
8
8
  #include <string>
9
9
 
10
+ struct SDL_Window;
11
+
10
12
  namespace Gosu
11
13
  {
12
14
  enum WindowFlags
@@ -124,45 +126,49 @@ namespace Gosu
124
126
  /// method will be called several times.
125
127
  virtual void drop(const std::string& filename) {}
126
128
 
127
- // Ignore when SWIG is wrapping this class for Ruby/Gosu.
128
- #ifndef SWIG
129
129
  // Callbacks for touch events. So far these are only used on iOS.
130
130
  virtual void touch_began(Touch touch) {}
131
131
  virtual void touch_moved(Touch touch) {}
132
132
  virtual void touch_ended(Touch touch) {}
133
133
  virtual void touch_cancelled(Touch touch) {}
134
134
 
135
- const Graphics& graphics() const;
136
- Graphics& graphics();
135
+ const Viewport& viewport() const;
136
+ Viewport& viewport();
137
137
 
138
138
  const Input& input() const;
139
139
  Input& input();
140
- #endif
141
140
 
142
141
  #ifdef GOSU_IS_IPHONE
143
142
  void* uikit_window() const;
144
143
  #endif
144
+
145
+ #ifndef GOSU_IS_IPHONE
146
+ SDL_Window* sdl_window() const;
147
+ #endif
145
148
  };
146
149
 
150
+ /// Returns the current framerate.
151
+ int fps();
152
+
147
153
  /// Returns the width (in pixels) of a screen.
148
154
  /// @param window The result describes the screen on which the window is shown, or the
149
155
  /// primary screen if no window is given.
150
- int screen_width(Window* window = nullptr);
156
+ int screen_width(const Window* window = nullptr);
151
157
 
152
158
  /// Returns the height (in pixels) of the user's primary screen.
153
159
  /// @param window The result describes the screen on which the window is shown, or the
154
160
  /// primary screen if no window is given.
155
- int screen_height(Window* window = nullptr);
161
+ int screen_height(const Window* window = nullptr);
156
162
 
157
163
  /// Returns the maximum width (in 'points') that is available for a non-fullscreen Window.
158
164
  /// All windows larger than this size will automatically be shrunk to fit.
159
165
  /// @param window The result describes the screen on which the window is shown, or the
160
166
  /// primary screen if no window is given.
161
- int available_width(Window* window = nullptr);
167
+ int available_width(const Window* window = nullptr);
162
168
 
163
169
  /// Returns the maximum height (in 'points') that is available for a non-fullscreen Window.
164
170
  /// All windows larger than this size will automatically be shrunk to fit.
165
171
  /// @param window The result describes the screen on which the window is shown, or the
166
172
  /// primary screen if no window is given.
167
- int available_height(Window* window = nullptr);
173
+ int available_height(const Window* window = nullptr);
168
174
  }
data/lib/SDL2.dll CHANGED
Binary file
@@ -0,0 +1,49 @@
1
+ module Gosu
2
+ class Channel
3
+ def initialize(pointer)
4
+ @managed_pointer = FFI::AutoPointer.new(pointer, GosuFFI.method(:Gosu_Channel_destroy))
5
+ end
6
+
7
+ def __pointer
8
+ @managed_pointer
9
+ end
10
+
11
+ def playing?
12
+ GosuFFI.check_last_error(GosuFFI.Gosu_Channel_playing(__pointer))
13
+ end
14
+
15
+ def pause
16
+ GosuFFI.Gosu_Channel_pause(__pointer)
17
+ GosuFFI.check_last_error
18
+ end
19
+
20
+ def paused?
21
+ GosuFFI.check_last_error(GosuFFI.Gosu_Channel_paused(__pointer))
22
+ end
23
+
24
+ def resume
25
+ GosuFFI.Gosu_Channel_resume(__pointer)
26
+ GosuFFI.check_last_error
27
+ end
28
+
29
+ def stop
30
+ GosuFFI.Gosu_Channel_stop(__pointer)
31
+ GosuFFI.check_last_error
32
+ end
33
+
34
+ def volume=(double)
35
+ GosuFFI.Gosu_Channel_set_volume(__pointer, double)
36
+ GosuFFI.check_last_error
37
+ end
38
+
39
+ def speed=(double)
40
+ GosuFFI.Gosu_Channel_set_speed(__pointer, double)
41
+ GosuFFI.check_last_error
42
+ end
43
+
44
+ def pan=(double)
45
+ GosuFFI.Gosu_Channel_set_pan(__pointer, double)
46
+ GosuFFI.check_last_error
47
+ end
48
+ end
49
+ end
data/lib/gosu/color.rb ADDED
@@ -0,0 +1,150 @@
1
+ module Gosu
2
+ class Color
3
+ include Comparable
4
+
5
+ # Gosu::Color is stored as an unsigned int in C
6
+ # this is used for {Gosu::Image#to_blob} and {Gosu::Image.from_blob}
7
+ SIZEOF = 4
8
+
9
+ def self.argb(*args)
10
+ Gosu::Color.new(*args)
11
+ end
12
+
13
+ def self.rgba(r, g, b, a)
14
+ Gosu::Color.new(a, r, g, b)
15
+ end
16
+
17
+ def self.rgb(r, g, b)
18
+ Gosu::Color.new(255, r, g, b)
19
+ end
20
+
21
+ def self.from_ahsv(alpha, h, s, v)
22
+ __color = GosuFFI.Gosu_Color_create_from_ahsv(alpha.clamp(0.0, 255.0), h % 360.0, s.clamp(0.0, 1.0), v.clamp(0.0, 1.0))
23
+ GosuFFI.check_last_error
24
+ Gosu::Color.new(__color)
25
+ end
26
+
27
+ def self.from_hsv(h, s, v)
28
+ __color = GosuFFI.Gosu_Color_create_from_hsv(h % 360.0, s.clamp(0.0, 1.0), v.clamp(0.0, 1.0))
29
+ GosuFFI.check_last_error
30
+ Gosu::Color.new(__color)
31
+ end
32
+
33
+ def initialize(*args)
34
+ case args.size
35
+ when 1
36
+ @__color = GosuFFI.Gosu_Color_create(args.first)
37
+ GosuFFI.check_last_error
38
+ when 4
39
+ @__color = GosuFFI.Gosu_Color_create_argb(args[0].clamp(0, 255), args[1].clamp(0, 255), args[2].clamp(0, 255), args[3].clamp(0, 255))
40
+ GosuFFI.check_last_error
41
+ else
42
+ raise ArgumentError
43
+ end
44
+ end
45
+
46
+ def alpha
47
+ GosuFFI.check_last_error(GosuFFI.Gosu_Color_alpha(@__color))
48
+ end
49
+
50
+ def alpha=(value)
51
+ @__color = GosuFFI.check_last_error(GosuFFI.Gosu_Color_set_alpha(@__color, value.clamp(0, 255)))
52
+ end
53
+
54
+ def red
55
+ GosuFFI.check_last_error(GosuFFI.Gosu_Color_red(@__color))
56
+ end
57
+
58
+ def red=(value)
59
+ @__color = GosuFFI.check_last_error(GosuFFI.Gosu_Color_set_red(@__color, value.clamp(0, 255)))
60
+ end
61
+
62
+ def green
63
+ GosuFFI.check_last_error(GosuFFI.Gosu_Color_green(@__color))
64
+ end
65
+
66
+ def green=(value)
67
+ @__color = GosuFFI.check_last_error(GosuFFI.Gosu_Color_set_green(@__color, value.clamp(0, 255)))
68
+ end
69
+
70
+ def blue
71
+ GosuFFI.check_last_error(GosuFFI.Gosu_Color_blue(@__color))
72
+ end
73
+
74
+ def blue=(value)
75
+ @__color = GosuFFI.check_last_error(GosuFFI.Gosu_Color_set_blue(@__color, value.clamp(0, 255)))
76
+ end
77
+
78
+ def value
79
+ GosuFFI.check_last_error(GosuFFI.Gosu_Color_value(@__color))
80
+ end
81
+
82
+ def value=(value)
83
+ @__color = GosuFFI.check_last_error(GosuFFI.Gosu_Color_set_value(@__color, value.clamp(0.0, 1.0)))
84
+ end
85
+
86
+ def saturation
87
+ GosuFFI.check_last_error(GosuFFI.Gosu_Color_saturation(@__color))
88
+ end
89
+
90
+ def saturation=(value)
91
+ @__color = GosuFFI.check_last_error(GosuFFI.Gosu_Color_set_saturation(@__color, value.clamp(0.0, 1.0)))
92
+ end
93
+
94
+ def hue
95
+ GosuFFI.check_last_error(GosuFFI.Gosu_Color_hue(@__color))
96
+ end
97
+
98
+ def hue=(value)
99
+ @__color = GosuFFI.check_last_error(GosuFFI.Gosu_Color_set_hue(@__color, value % 360.0))
100
+ end
101
+
102
+ def bgr
103
+ GosuFFI.check_last_error(GosuFFI.Gosu_Color_bgr(@__color))
104
+ end
105
+
106
+ def abgr
107
+ GosuFFI.check_last_error(GosuFFI.Gosu_Color_abgr(@__color))
108
+ end
109
+
110
+ def argb
111
+ GosuFFI.check_last_error(GosuFFI.Gosu_Color_argb(@__color))
112
+ end
113
+
114
+ def gl
115
+ @__color
116
+ end
117
+
118
+ def to_i
119
+ @__color
120
+ end
121
+
122
+ def <=>(other)
123
+ if other.is_a? Color
124
+ to_i <=> other.to_i
125
+ elsif other.is_a? Numeric
126
+ to_i <=> other
127
+ else
128
+ nil
129
+ end
130
+ end
131
+
132
+ alias hash gl
133
+
134
+ def eql?(other)
135
+ self == other
136
+ end
137
+
138
+ NONE = Gosu::Color.argb(0x00_000000)
139
+ BLACK = Gosu::Color.argb(0xff_000000)
140
+ GRAY = Gosu::Color.argb(0xff_808080)
141
+ WHITE = Gosu::Color.argb(0xff_ffffff)
142
+ AQUA = Gosu::Color.argb(0xff_00ffff)
143
+ RED = Gosu::Color.argb(0xff_ff0000)
144
+ GREEN = Gosu::Color.argb(0xff_00ff00)
145
+ BLUE = Gosu::Color.argb(0xff_0000ff)
146
+ YELLOW = Gosu::Color.argb(0xff_ffff00)
147
+ FUCHSIA = Gosu::Color.argb(0xff_ff00ff)
148
+ CYAN = Gosu::Color.argb(0xff_00ffff)
149
+ end
150
+ end
data/lib/gosu/compat.rb CHANGED
@@ -59,16 +59,19 @@ Gosu.deprecate Gosu::Color, :abgr, :none
59
59
  class Gosu::Image
60
60
  alias_method :initialize_without_window, :initialize
61
61
 
62
- def initialize(*args)
62
+ def initialize(*args, **kwargs)
63
63
  if args[0].is_a? Gosu::Window
64
- Gosu.deprecation_message("Passing a Window to Image#initialize has been deprecated in Gosu 0.9 and this method now uses an options hash, see https://www.libgosu.org/rdoc/Gosu/Image.html ")
64
+ # Old method signature: initialize(window, file_or_image, tileable)
65
+ Gosu.deprecation_message("Passing a Window to Image#initialize has been deprecated in Gosu 0.9, and this method now uses named arguments. https://www.libgosu.org/rdoc/Gosu/Image.html")
65
66
  if args.size == 7
66
67
  initialize_without_window args[1], tileable: args[2], rect: args[3..-1]
67
- else
68
+ elsif args.size == 3
68
69
  initialize_without_window args[1], tileable: args[2]
70
+ else
71
+ raise ArgumentError, "wrong number of arguments (given #{args.size})"
69
72
  end
70
73
  else
71
- initialize_without_window(*args)
74
+ initialize_without_window(*args, **kwargs)
72
75
  end
73
76
  end
74
77
 
@@ -76,17 +79,30 @@ class Gosu::Image
76
79
  alias_method :from_text_without_window, :from_text
77
80
  end
78
81
 
79
- def self.from_text(*args)
82
+ def self.from_text(*args, **kwargs)
80
83
  if args.size == 4
81
- Gosu.deprecation_message("Passing a Window to Image.from_text has been deprecated in Gosu 0.9 and this method now uses an options hash, see https://www.libgosu.org/rdoc/Gosu/Image.html ")
84
+ Gosu.deprecation_message("Passing a Window to Image.from_text has been deprecated in Gosu 0.9 and this method now uses named arguments. https://www.libgosu.org/rdoc/Gosu/Image.html")
82
85
  from_text_without_window(args[1], args[3], font: args[2])
83
86
  elsif args.size == 7
84
- Gosu.deprecation_message("Passing a Window to Image.from_text has been deprecated in Gosu 0.9 and this method now uses an options hash, see https://www.libgosu.org/rdoc/Gosu/Image.html ")
87
+ Gosu.deprecation_message("Passing a Window to Image.from_text has been deprecated in Gosu 0.9 and this method now uses named arguments. https://www.libgosu.org/rdoc/Gosu/Image.html")
85
88
  from_text_without_window(args[1], args[3],
86
89
  font: args[2], spacing: args[4], width: args[5],
87
90
  align: args[6])
88
91
  else
89
- from_text_without_window(*args)
92
+ from_text_without_window(*args, **kwargs)
93
+ end
94
+ end
95
+
96
+ class << self
97
+ alias_method :load_tiles_without_window, :load_tiles
98
+ end
99
+
100
+ def self.load_tiles(*args, **kwargs)
101
+ if args.first.is_a? Gosu::Window
102
+ # Old method signature: load_tiles(window, file_or_image, w, h, tileable)
103
+ load_tiles_without_window(args[1], args[2], args[3], tileable: args[4])
104
+ else
105
+ load_tiles_without_window(*args, **kwargs)
90
106
  end
91
107
  end
92
108
  end
@@ -154,6 +170,11 @@ class Gosu::Window
154
170
  end
155
171
  end
156
172
 
173
+ def set_mouse_position(x, y)
174
+ self.mouse_x = x
175
+ self.mouse_y = y
176
+ end
177
+
157
178
  Gosu.deprecate Gosu::Window, :set_mouse_position, "Window#mouse_x= and Window#mouse_y="
158
179
  end
159
180