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 +4 -4
- data/include/Gosu/Color.hpp +48 -100
- data/include/Gosu/Fwd.hpp +1 -1
- data/include/Gosu/Math.hpp +4 -16
- data/include/Gosu/Platform.hpp +1 -51
- data/include/Gosu/Text.hpp +37 -40
- data/include/Gosu/Version.hpp +1 -1
- data/include/Gosu/Window.hpp +2 -0
- data/lib/gosu/swig_patches.rb +31 -3
- data/rdoc/gosu.rb +9 -1
- data/src/Bitmap.cpp +13 -13
- data/src/Color.cpp +50 -46
- data/src/GosuViewController.cpp +2 -0
- data/src/LargeImageData.cpp +19 -19
- data/src/RubyGosu.cxx +386 -419
- data/src/RubyGosu.h +1 -0
- data/src/Text.cpp +31 -32
- data/src/TrueTypeFont.cpp +1 -1
- data/src/TrueTypeFontApple.cpp +0 -1
- data/src/Utility.cpp +31 -1
- data/src/WinUtility.hpp +2 -1
- data/src/Window.cpp +8 -0
- data/src/WindowUIKit.cpp +2 -2
- metadata +3 -3
data/src/Color.cpp
CHANGED
@@ -9,9 +9,9 @@ namespace
|
|
9
9
|
|
10
10
|
HSV color_to_hsv(const Gosu::Color& c)
|
11
11
|
{
|
12
|
-
double r = c.red
|
13
|
-
double g = c.green
|
14
|
-
double b = c.blue
|
12
|
+
double r = c.red / 255.0;
|
13
|
+
double g = c.green / 255.0;
|
14
|
+
double b = c.blue / 255.0;
|
15
15
|
|
16
16
|
double min = std::min(std::min(r, g), b);
|
17
17
|
double max = std::max(std::max(r, g), b);
|
@@ -22,7 +22,7 @@ namespace
|
|
22
22
|
return hsv;
|
23
23
|
}
|
24
24
|
|
25
|
-
HSV hsv;
|
25
|
+
HSV hsv{};
|
26
26
|
|
27
27
|
// Value.
|
28
28
|
hsv.v = max;
|
@@ -50,38 +50,33 @@ namespace
|
|
50
50
|
}
|
51
51
|
|
52
52
|
Gosu::Color Gosu::Color::from_hsv(double h, double s, double v)
|
53
|
-
{
|
54
|
-
return from_ahsv(255, h, s, v);
|
55
|
-
}
|
56
|
-
|
57
|
-
Gosu::Color Gosu::Color::from_ahsv(Channel alpha, double h, double s, double v)
|
58
53
|
{
|
59
54
|
// Normalize hue so that is always in the [0, 360) range and wraps around.
|
60
55
|
h = normalize_angle(h);
|
61
56
|
// Clamp s and v for consistency with the Ruby/Gosu ARGB getters/setters.
|
62
|
-
s = clamp(s, 0.0, 1.0);
|
63
|
-
v = clamp(v, 0.0, 1.0);
|
64
|
-
|
57
|
+
s = std::clamp(s, 0.0, 1.0);
|
58
|
+
v = std::clamp(v, 0.0, 1.0);
|
59
|
+
|
65
60
|
int sector = static_cast<int>(h / 60);
|
66
61
|
double factorial = h / 60 - sector;
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
62
|
+
|
63
|
+
Channel p = static_cast<Channel>(255 * v * (1 - s));
|
64
|
+
Channel q = static_cast<Channel>(255 * v * (1 - s * factorial));
|
65
|
+
Channel t = static_cast<Channel>(255 * v * (1 - s * (1 - factorial)));
|
66
|
+
|
72
67
|
switch (sector) {
|
73
68
|
case 0:
|
74
|
-
return Color(
|
69
|
+
return Color{static_cast<Channel>(255 * v), t, p};
|
75
70
|
case 1:
|
76
|
-
return Color
|
71
|
+
return Color{q, static_cast<Channel>(255 * v), p};
|
77
72
|
case 2:
|
78
|
-
return Color
|
73
|
+
return Color{p, static_cast<Channel>(255 * v), t};
|
79
74
|
case 3:
|
80
|
-
return Color
|
75
|
+
return Color{p, q, static_cast<Channel>(255 * v)};
|
81
76
|
case 4:
|
82
|
-
return Color
|
77
|
+
return Color{t, p, static_cast<Channel>(255 * v)};
|
83
78
|
default: // sector 5
|
84
|
-
return Color(
|
79
|
+
return Color{static_cast<Channel>(255 * v), p, q};
|
85
80
|
}
|
86
81
|
}
|
87
82
|
|
@@ -92,7 +87,7 @@ double Gosu::Color::hue() const
|
|
92
87
|
|
93
88
|
void Gosu::Color::set_hue(double h)
|
94
89
|
{
|
95
|
-
*this =
|
90
|
+
*this = from_hsv(h, saturation(), value()).with_alpha(alpha);
|
96
91
|
}
|
97
92
|
|
98
93
|
double Gosu::Color::saturation() const
|
@@ -102,7 +97,7 @@ double Gosu::Color::saturation() const
|
|
102
97
|
|
103
98
|
void Gosu::Color::set_saturation(double s)
|
104
99
|
{
|
105
|
-
*this =
|
100
|
+
*this = from_hsv(hue(), s, value()).with_alpha(alpha);
|
106
101
|
}
|
107
102
|
|
108
103
|
double Gosu::Color::value() const
|
@@ -112,33 +107,42 @@ double Gosu::Color::value() const
|
|
112
107
|
|
113
108
|
void Gosu::Color::set_value(double v)
|
114
109
|
{
|
115
|
-
*this =
|
110
|
+
*this = from_hsv(hue(), saturation(), v).with_alpha(alpha);
|
116
111
|
}
|
117
112
|
|
118
|
-
Gosu::Color Gosu::
|
113
|
+
Gosu::Color Gosu::lerp(Color a, Color b, double t)
|
119
114
|
{
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
115
|
+
const auto lerp_channel = [](Color::Channel a, Color::Channel b, double t) {
|
116
|
+
return static_cast<Color::Channel>(std::clamp(std::round(lerp(a, b, t)), 0.0, 255.0));
|
117
|
+
};
|
118
|
+
|
119
|
+
Color result;
|
120
|
+
result.red = lerp_channel(a.red, b.red, t);
|
121
|
+
result.green = lerp_channel(a.green, b.green, t);
|
122
|
+
result.blue = lerp_channel(a.blue, b.blue, t);
|
123
|
+
result.alpha = lerp_channel(a.alpha, b.alpha, t);
|
124
|
+
return result;
|
124
125
|
}
|
125
126
|
|
126
127
|
Gosu::Color Gosu::multiply(Color a, Color b)
|
127
128
|
{
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
129
|
+
Color result;
|
130
|
+
result.red = static_cast<Color::Channel>(std::round(a.red * b.red / 255.0));
|
131
|
+
result.green = static_cast<Color::Channel>(std::round(a.green * b.green / 255.0));
|
132
|
+
result.blue = static_cast<Color::Channel>(std::round(a.blue * b.blue / 255.0));
|
133
|
+
result.alpha = static_cast<Color::Channel>(std::round(a.alpha * b.alpha / 255.0));
|
134
|
+
return result;
|
132
135
|
}
|
133
136
|
|
134
|
-
const Gosu::Color Gosu::Color::NONE
|
135
|
-
const Gosu::Color Gosu::Color::BLACK
|
136
|
-
const Gosu::Color Gosu::Color::GRAY
|
137
|
-
const Gosu::Color Gosu::Color::WHITE
|
138
|
-
|
139
|
-
const Gosu::Color Gosu::Color::
|
140
|
-
const Gosu::Color Gosu::Color::
|
141
|
-
const Gosu::Color Gosu::Color::
|
142
|
-
const Gosu::Color Gosu::Color::
|
143
|
-
const Gosu::Color Gosu::Color::
|
144
|
-
const Gosu::Color Gosu::Color::
|
137
|
+
const Gosu::Color Gosu::Color::NONE{0x00'000000};
|
138
|
+
const Gosu::Color Gosu::Color::BLACK{0, 0, 0};
|
139
|
+
const Gosu::Color Gosu::Color::GRAY{128, 128, 128};
|
140
|
+
const Gosu::Color Gosu::Color::WHITE{255, 255, 255};
|
141
|
+
|
142
|
+
const Gosu::Color Gosu::Color::AQUA{0, 255, 255};
|
143
|
+
const Gosu::Color Gosu::Color::RED{255, 0, 0};
|
144
|
+
const Gosu::Color Gosu::Color::GREEN{0, 255, 0};
|
145
|
+
const Gosu::Color Gosu::Color::BLUE{0, 0, 255};
|
146
|
+
const Gosu::Color Gosu::Color::YELLOW{255, 255, 0};
|
147
|
+
const Gosu::Color Gosu::Color::FUCHSIA{255, 0, 255};
|
148
|
+
const Gosu::Color Gosu::Color::CYAN{0, 255, 255};
|
data/src/GosuViewController.cpp
CHANGED
@@ -121,6 +121,8 @@ static void handle_audio_interruption(void* unused, UInt32 inInterruptionState)
|
|
121
121
|
- (void)applicationWillEnterForeground:(NSNotification*)notification
|
122
122
|
{
|
123
123
|
[self setupTimerOrDisplayLink];
|
124
|
+
|
125
|
+
self.gosuWindowReference.gain_focus();
|
124
126
|
}
|
125
127
|
|
126
128
|
- (void)applicationDidEnterBackground:(NSNotification*)notification
|
data/src/LargeImageData.cpp
CHANGED
@@ -84,25 +84,25 @@ void Gosu::LargeImageData::draw(double x1, double y1, Color c1,
|
|
84
84
|
double rel_y_t = y / h;
|
85
85
|
double rel_y_b = (y + tile.height()) / h;
|
86
86
|
|
87
|
-
#define
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
double x_t_l =
|
93
|
-
double x_t_r =
|
94
|
-
double x_b_l =
|
95
|
-
double x_b_r =
|
96
|
-
|
97
|
-
double y_t_l =
|
98
|
-
double y_t_r =
|
99
|
-
double y_b_l =
|
100
|
-
double y_b_r =
|
101
|
-
|
102
|
-
Color c_t_l =
|
103
|
-
Color c_t_r =
|
104
|
-
Color c_b_l =
|
105
|
-
Color c_b_r =
|
87
|
+
#define LERP2D(what, x_weight, y_weight) \
|
88
|
+
lerp(lerp(what##1, what##3, y_weight), \
|
89
|
+
lerp(what##2, what##4, y_weight), \
|
90
|
+
x_weight);
|
91
|
+
|
92
|
+
double x_t_l = LERP2D(x, rel_x_l, rel_y_t);
|
93
|
+
double x_t_r = LERP2D(x, rel_x_r, rel_y_t);
|
94
|
+
double x_b_l = LERP2D(x, rel_x_l, rel_y_b);
|
95
|
+
double x_b_r = LERP2D(x, rel_x_r, rel_y_b);
|
96
|
+
|
97
|
+
double y_t_l = LERP2D(y, rel_x_l, rel_y_t);
|
98
|
+
double y_t_r = LERP2D(y, rel_x_r, rel_y_t);
|
99
|
+
double y_b_l = LERP2D(y, rel_x_l, rel_y_b);
|
100
|
+
double y_b_r = LERP2D(y, rel_x_r, rel_y_b);
|
101
|
+
|
102
|
+
Color c_t_l = LERP2D(c, rel_x_l, rel_y_t);
|
103
|
+
Color c_t_r = LERP2D(c, rel_x_r, rel_y_t);
|
104
|
+
Color c_b_l = LERP2D(c, rel_x_l, rel_y_b);
|
105
|
+
Color c_b_r = LERP2D(c, rel_x_r, rel_y_b);
|
106
106
|
|
107
107
|
tile.draw(x_t_l, y_t_l, c_t_l,
|
108
108
|
x_t_r, y_t_r, c_t_r,
|