1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:57:34 +00:00

Snazz up the windows with some title bar gradients. :^)

This commit is contained in:
Andreas Kling 2019-01-25 05:01:27 +01:00
parent c6b7b92625
commit 0db72786cf
7 changed files with 95 additions and 9 deletions

View file

@ -29,6 +29,10 @@ public:
Color(byte r, byte g, byte b) : m_value((r << 16) | (g << 8) | b) { }
Color(RGBA32 rgba) : m_value(rgba) { }
int red() const { return (m_value >> 16) & 0xff; }
int green() const { return (m_value >> 8) & 0xff; }
int blue() const { return m_value & 0xff; }
RGBA32 value() const { return m_value; }
private:

View file

@ -74,6 +74,45 @@ void Painter::fill_rect(const Rect& a_rect, Color color)
}
}
void Painter::fill_rect_with_gradient(const Rect& a_rect, Color gradient_start, Color gradient_end)
{
#ifdef NO_FPU
return fill_rect(a_rect, gradient_start);
#endif
auto rect = a_rect;
rect.move_by(m_translation);
auto clipped_rect = Rect::intersection(rect, m_clip_rect);
if (clipped_rect.is_empty())
return;
int x_offset = clipped_rect.x() - rect.x();
RGBA32* dst = m_target->scanline(clipped_rect.top()) + clipped_rect.left();
const unsigned dst_skip = m_target->width();
float increment = (1.0/((rect.width())/255.0));
int r2 = gradient_start.red();
int g2 = gradient_start.green();
int b2 = gradient_start.blue();
int r1 = gradient_end.red();
int g1 = gradient_end.green();
int b1 = gradient_end.blue();
for (int i = clipped_rect.height() - 1; i >= 0; --i) {
float c = x_offset * increment;
for (int j = 0; j < clipped_rect.width(); ++j) {
dst[j] = Color(
r1 / 255.0 * c + r2 / 255.0 * (255 - c),
g1 / 255.0 * c + g2 / 255.0 * (255 - c),
b1 / 255.0 * c + b2 / 255.0 * (255 - c)
).value();
c += increment;
}
dst += dst_skip;
}
}
void Painter::draw_rect(const Rect& a_rect, Color color)
{
Rect rect = a_rect;

View file

@ -23,6 +23,7 @@ public:
explicit Painter(GraphicsBitmap&);
~Painter();
void fill_rect(const Rect&, Color);
void fill_rect_with_gradient(const Rect&, Color gradient_start, Color gradient_end);
void draw_rect(const Rect&, Color);
void draw_bitmap(const Point&, const CharacterBitmap&, Color = Color());
void set_pixel(const Point&, Color);