mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:18:11 +00:00
SharedGraphics: Add some useful painting helpers and make use of them.
This commit is contained in:
parent
b782055b96
commit
38f589a9cb
6 changed files with 38 additions and 22 deletions
|
@ -28,15 +28,11 @@ void GButton::paint_event(GPaintEvent&)
|
|||
Color shadow_color = Color(96, 96, 96);
|
||||
|
||||
Painter painter(*this);
|
||||
|
||||
painter.draw_line({ 1, 0 }, { width() - 2, 0 }, Color::Black);
|
||||
painter.draw_line({ 1, height() - 1 }, { width() - 2, height() - 1}, Color::Black);
|
||||
painter.draw_line({ 0, 1 }, { 0, height() - 2 }, Color::Black);
|
||||
painter.draw_line({ width() - 1, 1 }, { width() - 1, height() - 2 }, Color::Black);
|
||||
painter.draw_rect(rect(), Color::Black, true);
|
||||
|
||||
if (m_being_pressed) {
|
||||
// Base
|
||||
painter.fill_rect({ 1, 1, width() - 2, height() - 2 }, button_color);
|
||||
painter.fill_rect(rect().shrunken(2, 2), button_color);
|
||||
|
||||
// Sunken shadow
|
||||
painter.draw_line({ 1, 1 }, { width() - 2, 1 }, shadow_color);
|
||||
|
|
|
@ -68,17 +68,11 @@ void GCheckBox::paint_event(GPaintEvent&)
|
|||
painter.fill_rect(box_rect, Color::White);
|
||||
painter.draw_rect(box_rect, Color::Black);
|
||||
|
||||
if (m_being_modified) {
|
||||
auto modification_rect = box_rect;
|
||||
modification_rect.shrink(2, 2);
|
||||
painter.draw_rect(modification_rect, Color::MidGray);
|
||||
}
|
||||
if (m_being_modified)
|
||||
painter.draw_rect(box_rect.shrunken(2, 2), Color::MidGray);
|
||||
|
||||
if (m_checked) {
|
||||
auto bitmap_rect = box_rect;
|
||||
bitmap_rect.shrink(2, 2);
|
||||
painter.draw_bitmap(bitmap_rect.location(), *s_checked_bitmap, foreground_color());
|
||||
}
|
||||
if (m_checked)
|
||||
painter.draw_bitmap(box_rect.shrunken(2, 2).location(), *s_checked_bitmap, foreground_color());
|
||||
|
||||
if (!caption().is_empty())
|
||||
painter.draw_text(text_rect, caption(), Painter::TextAlignment::TopLeft, foreground_color());
|
||||
|
|
|
@ -137,7 +137,7 @@ void Painter::fill_rect_with_gradient(const Rect& a_rect, Color gradient_start,
|
|||
}
|
||||
}
|
||||
|
||||
void Painter::draw_rect(const Rect& a_rect, Color color)
|
||||
void Painter::draw_rect(const Rect& a_rect, Color color, bool rough)
|
||||
{
|
||||
Rect rect = a_rect;
|
||||
rect.move_by(m_translation);
|
||||
|
@ -150,11 +150,15 @@ void Painter::draw_rect(const Rect& a_rect, Color color)
|
|||
int max_y = clipped_rect.bottom();
|
||||
|
||||
if (rect.top() >= clipped_rect.top() && rect.top() <= clipped_rect.bottom()) {
|
||||
fast_dword_fill(m_target->scanline(rect.top()) + clipped_rect.left(), color.value(), clipped_rect.width());
|
||||
int start_x = rough ? max(rect.x() + 1, clipped_rect.x()) : clipped_rect.x();
|
||||
int width = rough ? min(rect.width() - 2, clipped_rect.width()) : clipped_rect.width();
|
||||
fast_dword_fill(m_target->scanline(rect.top()) + start_x, color.value(), width);
|
||||
++min_y;
|
||||
}
|
||||
if (rect.bottom() >= clipped_rect.top() && rect.bottom() <= clipped_rect.bottom()) {
|
||||
fast_dword_fill(m_target->scanline(rect.bottom()) + clipped_rect.left(), color.value(), clipped_rect.width());
|
||||
int start_x = rough ? max(rect.x() + 1, clipped_rect.x()) : clipped_rect.x();
|
||||
int width = rough ? min(rect.width() - 2, clipped_rect.width()) : clipped_rect.width();
|
||||
fast_dword_fill(m_target->scanline(rect.bottom()) + start_x, color.value(), width);
|
||||
--max_y;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
~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_rect(const Rect&, Color, bool rough = false);
|
||||
void draw_bitmap(const Point&, const CharacterBitmap&, Color = Color());
|
||||
void draw_bitmap(const Point&, const GlyphBitmap&, Color = Color());
|
||||
void set_pixel(const Point&, Color);
|
||||
|
|
|
@ -67,6 +67,27 @@ public:
|
|||
set_height(height() - h);
|
||||
}
|
||||
|
||||
Rect shrunken(int w, int h)
|
||||
{
|
||||
Rect rect = *this;
|
||||
rect.shrink(w, h);
|
||||
return rect;
|
||||
}
|
||||
|
||||
Rect inflated(int w, int h)
|
||||
{
|
||||
Rect rect = *this;
|
||||
rect.inflate(w, h);
|
||||
return rect;
|
||||
}
|
||||
|
||||
Rect translated(int dx, int dy)
|
||||
{
|
||||
Rect rect = *this;
|
||||
rect.move_by(dx, dy);
|
||||
return rect;
|
||||
}
|
||||
|
||||
bool contains(int x, int y) const
|
||||
{
|
||||
return x >= m_location.x() && x <= right() && y >= m_location.y() && y <= bottom();
|
||||
|
|
|
@ -236,8 +236,9 @@ void WSWindowManager::paint_window_frame(WSWindow& window)
|
|||
if (!s_close_button_bitmap)
|
||||
s_close_button_bitmap = CharacterBitmap::create_from_ascii(s_close_button_bitmap_data, s_close_button_bitmap_width, s_close_button_bitmap_height).leak_ref();
|
||||
|
||||
m_back_painter->fill_rect_with_gradient(close_button_rect, Color::LightGray, Color::White);
|
||||
m_back_painter->draw_rect(close_button_rect, Color::Black);
|
||||
m_back_painter->fill_rect_with_gradient(close_button_rect.shrunken(2, 2), Color::LightGray, Color::White);
|
||||
|
||||
m_back_painter->draw_rect(close_button_rect, Color::Black, true);
|
||||
auto x_location = close_button_rect.center();
|
||||
x_location.move_by(-(s_close_button_bitmap_width / 2), -(s_close_button_bitmap_height / 2));
|
||||
m_back_painter->draw_bitmap(x_location, *s_close_button_bitmap, Color::Black);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue