@@ -141,7 +141,7 @@ void Painter::fill_rect(const Rect& a_rect, Color color)
141
141
}
142
142
}
143
143
144
- void Painter::fill_rect_with_gradient (const Rect& a_rect, Color gradient_start, Color gradient_end)
144
+ void Painter::fill_rect_with_gradient (Orientation orientation, const Rect& a_rect, Color gradient_start, Color gradient_end)
145
145
{
146
146
#ifdef NO_FPU
147
147
return fill_rect (a_rect, gradient_start);
@@ -151,12 +151,12 @@ void Painter::fill_rect_with_gradient(const Rect& a_rect, Color gradient_start,
151
151
if (clipped_rect.is_empty ())
152
152
return ;
153
153
154
- int x_offset = clipped_rect.x ( ) - rect.x ( );
154
+ int offset = clipped_rect.primary_offset_for_orientation (orientation ) - rect.primary_offset_for_orientation (orientation );
155
155
156
156
RGBA32* dst = m_target->scanline (clipped_rect.top ()) + clipped_rect.left ();
157
157
const size_t dst_skip = m_target->pitch () / sizeof (RGBA32);
158
158
159
- float increment = (1.0 / ((rect.width ( )) / 255.0 ));
159
+ float increment = (1.0 / ((rect.primary_size_for_orientation (orientation )) / 255.0 ));
160
160
161
161
int r2 = gradient_start.red ();
162
162
int g2 = gradient_start.green ();
@@ -165,20 +165,40 @@ void Painter::fill_rect_with_gradient(const Rect& a_rect, Color gradient_start,
165
165
int g1 = gradient_end.green ();
166
166
int b1 = gradient_end.blue ();
167
167
168
- for (int i = clipped_rect.height () - 1 ; i >= 0 ; --i) {
169
- float c = x_offset * increment;
170
- for (int j = 0 ; j < clipped_rect.width (); ++j) {
171
- dst[j] = Color (
168
+ if (orientation == Orientation::Horizontal) {
169
+ for (int i = clipped_rect.height () - 1 ; i >= 0 ; --i) {
170
+ float c = offset * increment;
171
+ for (int j = 0 ; j < clipped_rect.width (); ++j) {
172
+ dst[j] = Color (
173
+ r1 / 255.0 * c + r2 / 255.0 * (255 - c),
174
+ g1 / 255.0 * c + g2 / 255.0 * (255 - c),
175
+ b1 / 255.0 * c + b2 / 255.0 * (255 - c))
176
+ .value ();
177
+ c += increment;
178
+ }
179
+ dst += dst_skip;
180
+ }
181
+ } else {
182
+ float c = offset * increment;
183
+ for (int i = clipped_rect.height () - 1 ; i >= 0 ; --i) {
184
+ Color color (
172
185
r1 / 255.0 * c + r2 / 255.0 * (255 - c),
173
186
g1 / 255.0 * c + g2 / 255.0 * (255 - c),
174
- b1 / 255.0 * c + b2 / 255.0 * (255 - c))
175
- .value ();
187
+ b1 / 255.0 * c + b2 / 255.0 * (255 - c));
188
+ for (int j = 0 ; j < clipped_rect.width (); ++j) {
189
+ dst[j] = color.value ();
190
+ }
176
191
c += increment;
192
+ dst += dst_skip;
177
193
}
178
- dst += dst_skip;
179
194
}
180
195
}
181
196
197
+ void Painter::fill_rect_with_gradient (const Rect& a_rect, Color gradient_start, Color gradient_end)
198
+ {
199
+ return fill_rect_with_gradient (Orientation::Horizontal, a_rect, gradient_start, gradient_end);
200
+ }
201
+
182
202
void Painter::draw_ellipse_intersecting (const Rect& rect, Color color, int thickness)
183
203
{
184
204
constexpr int number_samples = 100 ; // FIXME: dynamically work out the number of samples based upon the rect size
0 commit comments