mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
LibGfx+LibGUI: Add support for vertical ProgressBars
This commit is contained in:
parent
bd34cdbbb3
commit
5806630cf4
Notes:
sideshowbarker
2024-07-18 21:30:06 +09:00
Author: https://github.com/thankyouverycool Commit: https://github.com/SerenityOS/serenity/commit/5806630cf49 Pull-request: https://github.com/SerenityOS/serenity/pull/5741 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/emanuele6
7 changed files with 60 additions and 13 deletions
|
@ -31,10 +31,13 @@
|
|||
#include <LibGfx/Palette.h>
|
||||
|
||||
REGISTER_WIDGET(GUI, ProgressBar)
|
||||
REGISTER_WIDGET(GUI, VerticalProgressBar)
|
||||
REGISTER_WIDGET(GUI, HorizontalProgressBar)
|
||||
|
||||
namespace GUI {
|
||||
|
||||
ProgressBar::ProgressBar()
|
||||
ProgressBar::ProgressBar(Orientation orientation)
|
||||
: m_orientation(orientation)
|
||||
{
|
||||
REGISTER_STRING_PROPERTY("text", text, set_text);
|
||||
REGISTER_ENUM_PROPERTY("format", format, set_format, Format,
|
||||
|
@ -90,7 +93,15 @@ void ProgressBar::paint_event(PaintEvent& event)
|
|||
progress_text = builder.to_string();
|
||||
}
|
||||
|
||||
Gfx::StylePainter::paint_progress_bar(painter, rect, palette(), m_min, m_max, m_value, progress_text);
|
||||
Gfx::StylePainter::paint_progress_bar(painter, rect, palette(), m_min, m_max, m_value, progress_text, m_orientation);
|
||||
}
|
||||
|
||||
void ProgressBar::set_orientation(Orientation value)
|
||||
{
|
||||
if (m_orientation == value)
|
||||
return;
|
||||
m_orientation = value;
|
||||
update();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,6 +44,9 @@ public:
|
|||
int min() const { return m_min; }
|
||||
int max() const { return m_max; }
|
||||
|
||||
void set_orientation(Orientation value);
|
||||
Orientation orientation() const { return m_orientation; }
|
||||
|
||||
String text() const { return m_text; }
|
||||
void set_text(String text) { m_text = move(text); }
|
||||
|
||||
|
@ -56,7 +59,7 @@ public:
|
|||
void set_format(Format format) { m_format = format; }
|
||||
|
||||
protected:
|
||||
ProgressBar();
|
||||
ProgressBar(Orientation = Orientation::Horizontal);
|
||||
|
||||
virtual void paint_event(PaintEvent&) override;
|
||||
|
||||
|
@ -66,6 +69,33 @@ private:
|
|||
int m_max { 100 };
|
||||
int m_value { 0 };
|
||||
String m_text;
|
||||
Orientation m_orientation { Orientation::Horizontal };
|
||||
};
|
||||
|
||||
class VerticalProgressBar final : public ProgressBar {
|
||||
C_OBJECT(VerticalProgressBar);
|
||||
|
||||
public:
|
||||
virtual ~VerticalProgressBar() override { }
|
||||
|
||||
private:
|
||||
VerticalProgressBar()
|
||||
: ProgressBar(Orientation::Vertical)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class HorizontalProgressBar final : public ProgressBar {
|
||||
C_OBJECT(HorizontalProgressBar);
|
||||
|
||||
public:
|
||||
virtual ~HorizontalProgressBar() override { }
|
||||
|
||||
private:
|
||||
HorizontalProgressBar()
|
||||
: ProgressBar(Orientation::Horizontal)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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&);
|
||||
|
|
Loading…
Reference in a new issue