1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 08:57:47 +00:00

LibGfx+LibGUI: Add support for vertical ProgressBars

This commit is contained in:
thankyouverycool 2021-03-07 17:39:01 -05:00 committed by Andreas Kling
parent bd34cdbbb3
commit 5806630cf4
7 changed files with 60 additions and 13 deletions

View file

@ -309,13 +309,13 @@ void ClassicStylePainter::paint_window_frame(Painter& painter, const IntRect& re
painter.draw_line(rect.bottom_left().translated(3, -3), rect.bottom_right().translated(-3, -3), base_color);
}
void ClassicStylePainter::paint_progress_bar(Painter& painter, const IntRect& rect, const Palette& palette, int min, int max, int value, const StringView& text)
void ClassicStylePainter::paint_progress_bar(Painter& painter, const IntRect& rect, const Palette& palette, int min, int max, int value, const StringView& text, Orientation orientation)
{
// First we fill the entire widget with the gradient. This incurs a bit of
// overdraw but ensures a consistent look throughout the progression.
Color start_color = palette.active_window_border1();
Color end_color = palette.active_window_border2();
painter.fill_rect_with_gradient(rect, start_color, end_color);
painter.fill_rect_with_gradient(orientation, rect, start_color, end_color);
if (!text.is_null()) {
painter.draw_text(rect.translated(1, 1), text, TextAlignment::Center, palette.base_text());
@ -327,8 +327,14 @@ void ClassicStylePainter::paint_progress_bar(Painter& painter, const IntRect& re
// Then we carve out a hole in the remaining part of the widget.
// We draw the text a third time, clipped and inverse, for sharp contrast.
float progress_width = progress * rect.width();
IntRect hole_rect { (int)progress_width, 0, (int)(rect.width() - progress_width), rect.height() };
IntRect hole_rect;
if (orientation == Orientation::Horizontal) {
float progress_width = progress * rect.width();
hole_rect = { (int)progress_width, 0, (int)(rect.width() - progress_width), rect.height() };
} else {
float progress_height = progress * rect.height();
hole_rect = { 0, 0, rect.width(), (int)(rect.height() - progress_height) };
}
hole_rect.move_by(rect.location());
hole_rect.set_right_without_resize(rect.right());
PainterStateSaver saver(painter);

View file

@ -40,7 +40,7 @@ public:
void paint_surface(Painter&, const IntRect&, const Palette&, bool paint_vertical_lines = true, bool paint_top_line = true) override;
void paint_frame(Painter&, const IntRect&, const Palette&, FrameShape, FrameShadow, int thickness, bool skip_vertical_lines = false) override;
void paint_window_frame(Painter&, const IntRect&, const Palette&) override;
void paint_progress_bar(Painter&, const IntRect&, const Palette&, int min, int max, int value, const StringView& text) override;
void paint_progress_bar(Painter&, const IntRect&, const Palette&, int min, int max, int value, const StringView& text, Orientation = Orientation::Horizontal) override;
void paint_radio_button(Painter&, const IntRect&, const Palette&, bool is_checked, bool is_being_pressed) override;
void paint_check_box(Painter&, const IntRect&, const Palette&, bool is_enabled, bool is_checked, bool is_being_pressed) override;
void paint_transparency_grid(Painter&, const IntRect&, const Palette&) override;

View file

@ -245,7 +245,7 @@ void Painter::fill_rect_with_gradient(Orientation orientation, const IntRect& a_
float c = offset * increment;
float c_alpha = gradient_start.alpha() + offset * alpha_increment;
for (int i = clipped_rect.height() - 1; i >= 0; --i) {
auto color = gamma_accurate_blend(gradient_start, gradient_end, c);
auto color = gamma_accurate_blend(gradient_end, gradient_start, c);
color.set_alpha(c_alpha);
for (int j = 0; j < clipped_rect.width(); ++j) {
dst[j] = color.value();

View file

@ -63,9 +63,9 @@ void StylePainter::paint_window_frame(Painter& painter, const IntRect& rect, con
current().paint_window_frame(painter, rect, palette);
}
void StylePainter::paint_progress_bar(Painter& painter, const IntRect& rect, const Palette& palette, int min, int max, int value, const StringView& text)
void StylePainter::paint_progress_bar(Painter& painter, const IntRect& rect, const Palette& palette, int min, int max, int value, const StringView& text, Orientation orientation)
{
current().paint_progress_bar(painter, rect, palette, min, max, value, text);
current().paint_progress_bar(painter, rect, palette, min, max, value, text, orientation);
}
void StylePainter::paint_radio_button(Painter& painter, const IntRect& rect, const Palette& palette, bool is_checked, bool is_being_pressed)

View file

@ -59,7 +59,7 @@ public:
virtual void paint_surface(Painter&, const IntRect&, const Palette&, bool paint_vertical_lines = true, bool paint_top_line = true) = 0;
virtual void paint_frame(Painter&, const IntRect&, const Palette&, FrameShape, FrameShadow, int thickness, bool skip_vertical_lines = false) = 0;
virtual void paint_window_frame(Painter&, const IntRect&, const Palette&) = 0;
virtual void paint_progress_bar(Painter&, const IntRect&, const Palette&, int min, int max, int value, const StringView& text) = 0;
virtual void paint_progress_bar(Painter&, const IntRect&, const Palette&, int min, int max, int value, const StringView& text, Orientation = Orientation::Horizontal) = 0;
virtual void paint_radio_button(Painter&, const IntRect&, const Palette&, bool is_checked, bool is_being_pressed) = 0;
virtual void paint_check_box(Painter&, const IntRect&, const Palette&, bool is_enabled, bool is_checked, bool is_being_pressed) = 0;
virtual void paint_transparency_grid(Painter&, const IntRect&, const Palette&) = 0;
@ -78,7 +78,7 @@ public:
static void paint_surface(Painter&, const IntRect&, const Palette&, bool paint_vertical_lines = true, bool paint_top_line = true);
static void paint_frame(Painter&, const IntRect&, const Palette&, FrameShape, FrameShadow, int thickness, bool skip_vertical_lines = false);
static void paint_window_frame(Painter&, const IntRect&, const Palette&);
static void paint_progress_bar(Painter&, const IntRect&, const Palette&, int min, int max, int value, const StringView& text);
static void paint_progress_bar(Painter&, const IntRect&, const Palette&, int min, int max, int value, const StringView& text, Orientation = Orientation::Horizontal);
static void paint_radio_button(Painter&, const IntRect&, const Palette&, bool is_checked, bool is_being_pressed);
static void paint_check_box(Painter&, const IntRect&, const Palette&, bool is_enabled, bool is_checked, bool is_being_pressed);
static void paint_transparency_grid(Painter&, const IntRect&, const Palette&);