gosu 1.2.0 → 1.3.0

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: b9f867c68587f182be0ba872daf669724376a55b6f7e0c3853eca5f350dc413f
4
- data.tar.gz: f24639563ba937303f9a81dd22a78ad5a22fa9243d980c629d163605656be0b2
3
+ metadata.gz: 7d58f7d332c57be8c599f33a6c60df54d7143e6ef2980eacd1a84f5d51f7a26a
4
+ data.tar.gz: e22cf468c5392985d6429aac77b958d71c63c33ac40a4a06b1f01187837bb224
5
5
  SHA512:
6
- metadata.gz: 6bb10eafcfa8742066e246e607ada383af5d2f3a461910e386064b27788d5620ab289b2081e0e4652240df9faf7cb1bb8d669fb95b7bcfbfb040e767c4354edd
7
- data.tar.gz: dc56b6a28a0f8980027c3f3bc5fd110e806617a4b22b3d6e918fa24f99d59cea98cd03d85af875968bcc7b98bc283ac810aca7a37e199ff1f4aaaaea1de7fc80
6
+ metadata.gz: 69605aee52675d916c27e58ad596d294ea4268e24520b137a2afa184a38f92b4120646a1e0c3ada0e6293088db9f965adf907a99b164052ee741b81cfd2a779c
7
+ data.tar.gz: 55615664e9ababb8ee986af01191a296b364d53d42986fcd45a94436b33f4d59aa46643da62a14e0e0a960def6a699d782f03bf74876c70405e4f6ec4d8591df
@@ -1,6 +1,3 @@
1
- //! \file Color.hpp
2
- //! Interface of the Color class.
3
-
4
1
  #pragma once
5
2
 
6
3
  #include <Gosu/Platform.hpp>
@@ -8,154 +5,105 @@
8
5
 
9
6
  namespace Gosu
10
7
  {
11
- //! Represents an RGBA color value with 8 bits for each channel.
12
- //! Can be implicitly constructed from literals of the form 0xaarrggbb.
13
- //! Has fast value semantics.
14
- //! The four-byte layout in memory is RGBA. On Big-Endian machines the unsigned int will look
15
- //! like 0xrrggbbaa, on Little-Endian machines it is 0xaabbggrr.
16
- class Color
8
+ /// Represents an RGBA color value with 8 bit for each channel.
9
+ /// Can be implicitly constructed from literals of the form 0xaarrggbb.
10
+ struct Color
17
11
  {
18
- std::uint32_t rep;
19
- #ifdef GOSU_IS_LITTLE_ENDIAN
20
- enum { RED_OFFSET = 0, GREEN_OFFSET = 8, BLUE_OFFSET = 16, ALPHA_OFFSET = 24 };
21
- #else
22
- enum { RED_OFFSET = 24, GREEN_OFFSET = 16, BLUE_OFFSET = 8, ALPHA_OFFSET = 0 };
23
- #endif
24
-
25
- public:
26
- typedef std::uint8_t Channel;
27
12
  static const unsigned GL_FORMAT = 0x1908; // GL_RGBA
28
-
29
- //! The default constructor does not initialize the color to any value.
30
- Color()
31
- {
32
- }
33
-
34
- //! Conversion constructor for literals of the form 0xaarrggbb.
35
- Color(unsigned argb)
36
- : Color((argb >> 24) & 0xff, (argb >> 16) & 0xff, (argb >> 8) & 0xff, (argb >> 0) & 0xff)
37
- {
38
- }
39
-
40
- Color(Channel red, Channel green, Channel blue)
41
- : Color(0xff, red, green, blue)
42
- {
43
- }
44
-
45
- Color(Channel alpha, Channel red, Channel green, Channel blue)
46
- {
47
- rep = (alpha << ALPHA_OFFSET) | (red << RED_OFFSET) |
48
- (green << GREEN_OFFSET) | (blue << BLUE_OFFSET);
49
- }
50
-
51
- //! Constructs a color from the given hue/saturation/value triple.
52
- //! Ranges of these values are given as 0..360, 0..1, and 0..1, respectively.
53
- static Color from_hsv(double h, double s, double v);
54
-
55
- //! Constructs a color from the given hue/saturation/value triple.
56
- //! Ranges of these values are given as 0..360, 0..1, and 0..1, respectively.
57
- static Color from_ahsv(Channel alpha, double h, double s, double v);
58
13
 
59
- Channel red() const
60
- {
61
- return static_cast<Channel>(rep >> RED_OFFSET);
62
- }
63
-
64
- Channel green() const
65
- {
66
- return static_cast<Channel>(rep >> GREEN_OFFSET);
67
- }
14
+ typedef std::uint8_t Channel;
68
15
 
69
- Channel blue() const
70
- {
71
- return static_cast<Channel>(rep >> BLUE_OFFSET);
72
- }
16
+ Channel red, green, blue, alpha;
73
17
 
74
- Channel alpha() const
18
+ constexpr Color()
19
+ : red{0}, green{0}, blue{0}, alpha{0}
75
20
  {
76
- return static_cast<Channel>(rep >> ALPHA_OFFSET);
77
21
  }
78
22
 
79
- void set_red(Channel value)
23
+ /// Conversion constructor for literals of the form 0xaarrggbb.
24
+ // NOLINTNEXTLINE: We want to allow implicit conversions.
25
+ constexpr Color(std::uint32_t argb)
26
+ : red{static_cast<Channel>(argb >> 16)}, green{static_cast<Channel>(argb >> 8)},
27
+ blue{static_cast<Channel>(argb >> 0)}, alpha{static_cast<Channel>(argb >> 24)}
80
28
  {
81
- rep &= ~(0xff << RED_OFFSET);
82
- rep |= value << RED_OFFSET;
83
29
  }
84
30
 
85
- void set_green(Channel value)
31
+ constexpr Color(Channel red, Channel green, Channel blue)
32
+ : red{red}, green{green}, blue{blue}, alpha{255}
86
33
  {
87
- rep &= ~(0xff << GREEN_OFFSET);
88
- rep |= value << GREEN_OFFSET;
89
34
  }
90
35
 
91
- void set_blue(Channel value)
36
+ Color with_alpha(Channel new_alpha)
92
37
  {
93
- rep &= ~(0xff << BLUE_OFFSET);
94
- rep |= value << BLUE_OFFSET;
38
+ Color result = *this;
39
+ result.alpha = new_alpha;
40
+ return result;
95
41
  }
96
42
 
97
- void set_alpha(Channel value)
98
- {
99
- rep &= ~(0xff << ALPHA_OFFSET);
100
- rep |= value << ALPHA_OFFSET;
101
- }
43
+ /// Constructs a color from the given hue/saturation/value triple.
44
+ /// Ranges of these values are given as 0..360, 0..1, and 0..1, respectively.
45
+ static Color from_hsv(double h, double s, double v);
102
46
 
103
- //! Returns the hue of the color, in the usual range of 0..360.
47
+ /// Returns the hue of the color, in the usual range of 0..360.
104
48
  double hue() const;
105
49
 
106
- //! Changes the current color so hue() will return h.
50
+ /// Changes the current color so hue() will return h.
107
51
  void set_hue(double h);
108
52
 
109
- //! Returns the saturation of the color, in the range of 0..1.
53
+ /// Returns the saturation of the color, in the range of 0..1.
110
54
  double saturation() const;
111
55
 
112
- //! Changes the current color so saturation() will return s.
56
+ /// Changes the current color so saturation() will return s.
113
57
  void set_saturation(double s);
114
58
 
115
- //! Returns the value (brightness) of the color, in the range of 0..1.
59
+ /// Returns the value (brightness) of the color, in the range of 0..1.
116
60
  double value() const;
117
61
 
118
- //! Changes the current color so value() will return v.
62
+ /// Changes the current color so value() will return v.
119
63
  void set_value(double v);
120
64
 
121
- //! Returns the color in 0xaarrggbb representation.
122
- std::uint32_t argb() const { return alpha() << 24 | red() << 16 | green() << 8 | blue(); }
65
+ /// Returns the color in 0xaarrggbb representation.
66
+ std::uint32_t argb() const { return alpha << 24 | red << 16 | green << 8 | blue; }
123
67
 
124
- //! Returns the color in 0x00bbggrr representation. Useful for Win32 programming.
125
- std::uint32_t bgr() const { return blue() << 16 | green() << 8 | red(); }
68
+ /// Returns the color in 0x00bbggrr representation. Useful for Win32 programming.
69
+ std::uint32_t bgr() const { return blue << 16 | green << 8 | red; }
70
+
71
+ /// Returns the color in 0xaabbggrr representation.
72
+ std::uint32_t abgr() const { return alpha << 24 | blue << 16 | green << 8 | red; }
73
+
74
+ /// Returns the internal representation of the color (RGBA in memory).
75
+ std::uint32_t gl() const { return *reinterpret_cast<const std::uint32_t*>(this); }
126
76
 
127
- //! Returns the color in 0xaabbggrr representation.
128
- std::uint32_t abgr() const { return alpha() << 24 | blue() << 16 | green() << 8 | red(); }
129
-
130
- //! Returns the internal representation of the color (RGBA in memory).
131
- std::uint32_t gl() const { return rep; }
132
-
133
77
  static const Color NONE;
134
78
  static const Color BLACK;
135
79
  static const Color GRAY;
136
80
  static const Color WHITE;
137
-
81
+
82
+ /// Same as Color::CYAN.
138
83
  static const Color AQUA;
139
84
  static const Color RED;
140
85
  static const Color GREEN;
141
86
  static const Color BLUE;
142
87
  static const Color YELLOW;
143
88
  static const Color FUCHSIA;
89
+ /// Same as Color::AQUA.
144
90
  static const Color CYAN;
145
91
  };
92
+
93
+ // Ensure that we can pass vectors of Gosu::Color straight to OpenGL and back.
94
+ static_assert(sizeof(Color) == sizeof(std::uint32_t));
146
95
 
147
96
  #ifndef SWIG
148
97
  inline bool operator<(Color a, Color b) { return a.gl() < b.gl(); }
149
98
  inline bool operator==(Color a, Color b) { return a.gl() == b.gl(); }
150
99
  inline bool operator!=(Color a, Color b) { return a.gl() != b.gl(); }
151
100
 
152
- //! Interpolates linearly between two colors, with a given weight towards
153
- //! the second color.
154
- //! Specialization of the general function in Gosu/Math.hpp.
155
- Color interpolate(Color a, Color b, double weight = 0.5);
101
+ /// Interpolates linearly between two colors, with a given weight towards
102
+ /// the second color.
103
+ Color lerp(Color a, Color b, double t = 0.5);
156
104
 
157
- //! Combines two colors as if their channels were mapped to the 0..1 range
158
- //! and then multiplied with each other.
105
+ /// Combines two colors as if their channels were mapped to the 0..1 range
106
+ /// and then multiplied with each other.
159
107
  Color multiply(Color a, Color b);
160
108
  #endif
161
109
  }
data/include/Gosu/Fwd.hpp CHANGED
@@ -5,7 +5,7 @@ namespace Gosu
5
5
  class Bitmap;
6
6
  class Buffer;
7
7
  class Channel;
8
- class Color;
8
+ struct Color;
9
9
  class File;
10
10
  class Font;
11
11
  class Graphics;
@@ -67,17 +67,7 @@ namespace Gosu
67
67
  {
68
68
  return value * value;
69
69
  }
70
-
71
- //! Returns min if value is smaller than min, max if value is larger than
72
- //! max and value otherwise.
73
- template<typename T>
74
- T clamp(T value, T min, T max)
75
- {
76
- if (value < min) return min;
77
- if (value > max) return max;
78
- return value;
79
- }
80
-
70
+
81
71
  //! Returns (value-min) % (max-min) + min, where % always has a positive
82
72
  //! result for max > min. The results are undefined for max <= min.
83
73
  //! Note: This means that max is exclusive.
@@ -100,12 +90,10 @@ namespace Gosu
100
90
  //! Returns the distance between two points.
101
91
  double distance(double x1, double y1, double x2, double y2);
102
92
 
103
- //! Interpolates a value between a and b, weight being the bias towards the second value.
104
- //! Examples: interpolate(0, 10, 0.5) == 5, interpolate(-10, 10, 0.25) == 5,
105
- //! interpolate(0, 10, -0.5) == -5.
93
+ //! Placeholder for std::lerp, will be removed when Gosu requires C++20.
106
94
  template<typename T>
107
- T interpolate(T a, T b, double weight = 0.5)
95
+ T lerp(T a, T b, double t = 0.5)
108
96
  {
109
- return a * (1.0 - weight) + b * weight;
97
+ return a * (1.0 - t) + b * t;
110
98
  }
111
99
  }
@@ -1,51 +1,5 @@
1
- //! \file Platform.hpp
2
- //! Macros and utility functions to facilitate programming on all of Gosu's supported platforms.
3
-
4
1
  #pragma once
5
2
 
6
- #ifdef __BIG_ENDIAN__
7
- # define GOSU_IS_BIG_ENDIAN
8
- # define IDENTITY_FUN big_to_native
9
- # define IDENTITY_FUN2 native_to_big
10
- # define CONV_FUN little_to_native
11
- # define CONV_FUN2 native_to_little
12
- #else
13
- # define GOSU_IS_LITTLE_ENDIAN
14
- # define IDENTITY_FUN little_to_native
15
- # define IDENTITY_FUN2 native_to_little
16
- # define CONV_FUN big_to_native
17
- # define CONV_FUN2 native_to_big
18
- #endif
19
-
20
- #include <algorithm>
21
-
22
- namespace Gosu
23
- {
24
- template<typename T> T IDENTITY_FUN(T t) { return t; }
25
- template<typename T> T IDENTITY_FUN2(T t) { return t; }
26
-
27
- template<typename T>
28
- T CONV_FUN(T t)
29
- {
30
- char* begin = reinterpret_cast<char*>(&t);
31
- std::reverse(begin, begin + sizeof t);
32
- return t;
33
- }
34
-
35
- template<typename T> T CONV_FUN2(T t) { return CONV_FUN(t); }
36
- }
37
-
38
- #undef IDENTITY_FUN
39
- #undef IDENTITY_FUN2
40
- #undef CONV_FUN
41
- #undef CONV_FUN2
42
-
43
- #if defined(_MSC_VER)
44
- # define GOSU_NORETURN __declspec(noreturn)
45
- #elif defined(__GNUC__)
46
- # define GOSU_NORETURN __attribute__ ((noreturn))
47
- #endif
48
-
49
3
  #if defined(WIN32) || defined(_WIN64)
50
4
  # define GOSU_IS_WIN
51
5
  #else
@@ -63,9 +17,5 @@ namespace Gosu
63
17
  #endif
64
18
 
65
19
  #ifndef GOSU_DEPRECATED
66
- # if defined(GOSU_IS_WIN)
67
- # define GOSU_DEPRECATED __declspec(deprecated)
68
- # else
69
- # define GOSU_DEPRECATED __attribute__((__deprecated__))
70
- # endif
20
+ # define GOSU_DEPRECATED [[deprecated]]
71
21
  #endif
@@ -1,6 +1,3 @@
1
- //! \file Text.hpp
2
- //! Functions to output text on bitmaps.
3
-
4
1
  #pragma once
5
2
 
6
3
  #include <Gosu/Fwd.hpp>
@@ -10,55 +7,55 @@
10
7
 
11
8
  namespace Gosu
12
9
  {
13
- //! Returns the name of a neutral font that is available on the current platform.
10
+ /// Returns the name of a neutral font that is available on the current platform.
14
11
  std::string default_font_name();
15
12
 
16
- //! Returns the width an unformatted line of text would span on a bitmap if it were drawn using
17
- //! draw_text with the same arguments.
18
- //! \param text A UCS-4 string, normalization: NFC.
19
- //! \param font_name Name of a system font, or filename of a TTF file (must contain '/' or '.').
13
+ /// Returns the width that an unformatted line of text would span on a bitmap if it were drawn
14
+ /// using draw_text with the same arguments.
15
+ /// @param text A UCS-4 string, normalization: NFC.
16
+ /// @param font_name Name of a system font, or filename of a TTF file (must contain '/' or '.').
20
17
  double text_width(const std::u32string& text, const std::string& font_name, double font_height,
21
18
  unsigned font_flags = 0);
22
19
 
23
- //! Draws a line of plain text on a bitmap. This is a low-level function that does not
24
- //! understand any of Gosu's HTML-like markup.
25
- //! \param text A UCS-4 string, normalization: NFC.
26
- //! \param font_name Name of a system font, or filename of a TTF file (must contain '/' or '.').
27
- //! \param font_height Height, in pixels, of the text.
28
- //! \param font_flags Binary combination of members of the FontFlags enum.
20
+ /// Draws a line of plain text on a bitmap. This is a low-level function that does not
21
+ /// understand any of Gosu's HTML-like markup.
22
+ /// @param text A UCS-4 string, normalization: NFC.
23
+ /// @param font_name Name of a system font, or filename of a TTF file (must contain '/' or '.').
24
+ /// @param font_height Height, in pixels, of the text.
25
+ /// @param font_flags Binary combination of members of the FontFlags enum.
29
26
  double draw_text(Bitmap& bitmap, double x, double y, Color c, const std::u32string& text,
30
27
  const std::string& font_name, double font_height, unsigned font_flags = 0);
31
28
 
32
- //! Creates a bitmap that is filled with the plain text given to the function.
33
- //! The line can contain line breaks and HTML-like markup.
34
- //! \param text Plain text.
35
- //! \param font_name Name of a system font, or filename of a TTF file (must contain '/' or '.').
36
- //! \param font_height Height of the font in pixels.
37
- //! \param line_spacing Spacing between two lines of text in pixels. Can be negative to make
38
- //! text stick together more closely.
39
- //! \param width Width of the bitmap that will be returned.
40
- //! Text will be split into multiple lines to avoid drawing over the right border.
41
- //! When a single word is too long, it will be truncated.
42
- //! A width smaller than 0 indicates that lines should not be wrapped, and the resulting
43
- //! bitmap will be as wide as the widest line.
44
- //! \param font_flags Binary combination of members of the FontFlags enum.
29
+ /// Creates a bitmap that is filled with the plain text given to the function.
30
+ /// The line can contain line breaks and HTML-like markup.
31
+ /// @param text Plain text.
32
+ /// @param font_name Name of a system font, or filename of a TTF file (must contain '/' or '.').
33
+ /// @param font_height Height of the font in pixels.
34
+ /// @param line_spacing Spacing between two lines of text in pixels. Can be negative to make
35
+ /// text stick together more closely.
36
+ /// @param width Width of the bitmap that will be returned.
37
+ /// Text will be split into multiple lines to avoid drawing over the right border.
38
+ /// When a single word is too long, it will be truncated.
39
+ /// A width smaller than 0 indicates that lines should not be wrapped, and the resulting
40
+ /// bitmap will be as wide as the widest line.
41
+ /// @param font_flags Binary combination of members of the FontFlags enum.
45
42
  Bitmap layout_text(const std::string& text, const std::string& font_name,
46
43
  double font_height, double line_spacing = 0,
47
44
  int width = -1, Alignment align = AL_LEFT, unsigned font_flags = 0);
48
45
 
49
- //! Creates a bitmap that is filled with the formatted text given to the function.
50
- //! The line can contain line breaks and HTML-like markup.
51
- //! \param markup Formatted text.
52
- //! \param font_name Name of a system font, or filename of a TTF file (must contain '/' or '.').
53
- //! \param font_height Height of the font in pixels.
54
- //! \param line_spacing Spacing between two lines of text in pixels. Can be negative to make
55
- //! text stick together more closely.
56
- //! \param width Width of the bitmap that will be returned.
57
- //! Text will be split into multiple lines to avoid drawing over the right border.
58
- //! When a single word is too long, it will be truncated.
59
- //! A width smaller than 0 indicates that lines should not be wrapped, and the resulting
60
- //! bitmap will be as wide as the widest line.
61
- //! \param font_flags Binary combination of members of the FontFlags enum.
46
+ /// Creates a bitmap that is filled with the formatted text given to the function.
47
+ /// The line can contain line breaks and HTML-like markup.
48
+ /// @param markup Formatted text.
49
+ /// @param font_name Name of a system font, or filename of a TTF file (must contain '/' or '.').
50
+ /// @param font_height Height of the font in pixels.
51
+ /// @param line_spacing Spacing between two lines of text in pixels. Can be negative to make
52
+ /// text stick together more closely.
53
+ /// @param width Width of the bitmap that will be returned.
54
+ /// Text will be split into multiple lines to avoid drawing over the right border.
55
+ /// When a single word is too long, it will be truncated.
56
+ /// A width smaller than 0 indicates that lines should not be wrapped, and the resulting
57
+ /// bitmap will be as wide as the widest line.
58
+ /// @param font_flags Binary combination of members of the FontFlags enum.
62
59
  Bitmap layout_markup(const std::string& markup, const std::string& font_name,
63
60
  double font_height, double line_spacing = 0,
64
61
  int width = -1, Alignment align = AL_LEFT, unsigned font_flags = 0);
@@ -3,7 +3,7 @@
3
3
  #include <string>
4
4
 
5
5
  #define GOSU_MAJOR_VERSION 1
6
- #define GOSU_MINOR_VERSION 2
6
+ #define GOSU_MINOR_VERSION 3
7
7
  #define GOSU_POINT_VERSION 0
8
8
 
9
9
  namespace Gosu
@@ -89,6 +89,8 @@ namespace Gosu
89
89
  //! If this function returns true, the system cursor will be visible while over the window.
90
90
  virtual bool needs_cursor() const { return true; }
91
91
 
92
+ virtual void gain_focus() {}
93
+
92
94
  //! This function is called when the window loses focus on some platforms.
93
95
  //! Most importantly, it is called on the iPhone or iPad when the user locks the screen.
94
96
  virtual void lose_focus() {}
@@ -20,7 +20,7 @@ class Gosu::Window
20
20
  end
21
21
 
22
22
  %w(update draw needs_redraw? needs_cursor?
23
- lose_focus button_down button_up
23
+ gain_focus lose_focus button_down button_up
24
24
  gamepad_connected gamepad_disconnected drop).each do |callback|
25
25
  define_method "protected_#{callback}" do |*args|
26
26
  begin
@@ -35,13 +35,13 @@ class Gosu::Window
35
35
  end
36
36
  end
37
37
  end
38
-
38
+
39
39
  def protected_draw_2
40
40
  protected_draw
41
41
  $gosu_gl_blocks_2 = $gosu_gl_blocks
42
42
  $gosu_gl_blocks = nil
43
43
  end
44
-
44
+
45
45
  alias_method :show_internal, :show
46
46
  def show
47
47
  show_internal
@@ -54,6 +54,21 @@ class Gosu::Window
54
54
  raise @_exception
55
55
  end
56
56
  end
57
+
58
+ alias_method :tick_internal, :tick
59
+ def tick
60
+ value = tick_internal
61
+ # Try to format the message nicely, without any useless patching that we are
62
+ # doing here.
63
+ if defined? @_exception
64
+ if @_exception.backtrace.is_a? Array and not @_exception.backtrace.frozen?
65
+ @_exception.backtrace.reject! { |line| line.include? "lib/gosu/swig_patches.rb" }
66
+ end
67
+ raise @_exception
68
+ end
69
+
70
+ value
71
+ end
57
72
  end
58
73
 
59
74
  module Gosu
@@ -73,6 +88,19 @@ end
73
88
  # SWIG somehow maps the instance method "argb" as an overload of the class
74
89
  # method of the same name.
75
90
  class Gosu::Color
91
+ alias_method :initialize_without_argb, :initialize
92
+
93
+ # The (a,r,g,b) constructor overload was dropped in C++ to reduce ambiguity,
94
+ # adding it via %extend in gosu.i does not work, so patch it here.
95
+ def initialize(*args)
96
+ if args.size == 4
97
+ initialize_without_argb(args[1], args[2], args[3])
98
+ self.alpha = args[0]
99
+ else
100
+ initialize_without_argb(*args)
101
+ end
102
+ end
103
+
76
104
  alias_method :argb, :to_i
77
105
  end
78
106
 
data/rdoc/gosu.rb CHANGED
@@ -481,7 +481,7 @@ module Gosu
481
481
  # Draws the image rotated, with its rotational center at (x, y).
482
482
  #
483
483
  # @return [void]
484
- # @param angle [Float]
484
+ # @param angle [Float] the angle to rotate, in degrees.
485
485
  # @param center_x [Float] the relative horizontal rotation origin.
486
486
  # @param center_y [Float] the relative vertical rotation origin.
487
487
  # @param (see #draw)
@@ -960,6 +960,14 @@ module Gosu
960
960
  # @see Gosu.gamepad_name
961
961
  def gamepad_disconnected(index); end
962
962
 
963
+ ##
964
+ # Called when the window gains focus
965
+ def gain_focus; end
966
+
967
+ ##
968
+ # Called when the windows loses focus
969
+ def lose_focus; end
970
+
963
971
  # @!endgroup
964
972
  end
965
973
 
data/src/Bitmap.cpp CHANGED
@@ -31,20 +31,20 @@ void Gosu::Bitmap::resize(int width, int height, Color c)
31
31
 
32
32
  void Gosu::Bitmap::blend_pixel(int x, int y, Color c)
33
33
  {
34
- if (c.alpha() == 0) return;
34
+ if (c.alpha == 0) return;
35
35
 
36
36
  Color out = get_pixel(x, y);
37
- if (out.alpha() == 0) {
37
+ if (out.alpha == 0) {
38
38
  set_pixel(x, y, c);
39
39
  return;
40
40
  }
41
41
 
42
- int inv_alpha = out.alpha() * (255 - c.alpha()) / 255;
42
+ int inv_alpha = out.alpha * (255 - c.alpha) / 255;
43
43
 
44
- out.set_alpha(c.alpha() + inv_alpha);
45
- out.set_red ((c.red() * c.alpha() + out.red() * inv_alpha) / out.alpha());
46
- out.set_green((c.green() * c.alpha() + out.green() * inv_alpha) / out.alpha());
47
- out.set_blue ((c.blue() * c.alpha() + out.blue() * inv_alpha) / out.alpha());
44
+ out.alpha = (c.alpha + inv_alpha);
45
+ out.red = ((c.red * c.alpha + out.red * inv_alpha) / out.alpha);
46
+ out.green = ((c.green * c.alpha + out.green * inv_alpha) / out.alpha);
47
+ out.blue = ((c.blue * c.alpha + out.blue * inv_alpha) / out.alpha);
48
48
 
49
49
  set_pixel(x, y, out);
50
50
  }
@@ -108,9 +108,9 @@ void Gosu::apply_color_key(Bitmap& bitmap, Color key)
108
108
  auto visit = [&](Color c) {
109
109
  if (c != key) {
110
110
  neighbors += 1;
111
- red += c.red();
112
- green += c.green();
113
- blue += c.blue();
111
+ red += c.red;
112
+ green += c.green;
113
+ blue += c.blue;
114
114
  }
115
115
  };
116
116
 
@@ -121,9 +121,9 @@ void Gosu::apply_color_key(Bitmap& bitmap, Color key)
121
121
 
122
122
  Color replacement = Color::NONE;
123
123
  if (neighbors > 0) {
124
- replacement.set_red(red / neighbors);
125
- replacement.set_green(green / neighbors);
126
- replacement.set_blue(blue / neighbors);
124
+ replacement.red = red / neighbors;
125
+ replacement.green = green / neighbors;
126
+ replacement.blue = blue / neighbors;
127
127
  }
128
128
  bitmap.set_pixel(x, y, replacement);
129
129
  }