diff options
author | thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> | 2023-04-29 16:47:52 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-04-30 05:49:46 +0200 |
commit | f7e034d4b257a22b898252d62652587601fa7f99 (patch) | |
tree | a69511f055f54e0215a63d6082637d38293e97f6 /Userland/Libraries/LibGfx | |
parent | 4c9933bfb701c43a2f9aeadf8d06398fd6327749 (diff) | |
download | serenity-f7e034d4b257a22b898252d62652587601fa7f99.zip |
LibGfx+Userland: Merge FrameShape and FrameShadow into FrameStyle
Previously, Frames could set both these properties along with a
thickness to confusing effect: Most shapes of the same shadowing only
differentiated at a thickness >= 2, and some not at all. This led
to a lot of creative but ultimately superfluous choices in the code.
Instead let's streamline our options, automate thickness, and get
the right look without so much guesswork.
Plain shadowing has been consolidated into a single Plain style,
and 0 thickness can be had by setting style to NoFrame.
Diffstat (limited to 'Userland/Libraries/LibGfx')
-rw-r--r-- | Userland/Libraries/LibGfx/ClassicStylePainter.cpp | 54 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/ClassicStylePainter.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/StylePainter.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/StylePainter.h | 22 |
4 files changed, 42 insertions, 40 deletions
diff --git a/Userland/Libraries/LibGfx/ClassicStylePainter.cpp b/Userland/Libraries/LibGfx/ClassicStylePainter.cpp index 007febdbb2..426ca14c01 100644 --- a/Userland/Libraries/LibGfx/ClassicStylePainter.cpp +++ b/Userland/Libraries/LibGfx/ClassicStylePainter.cpp @@ -241,12 +241,12 @@ void ClassicStylePainter::paint_button(Painter& painter, IntRect const& rect, Pa } } -void ClassicStylePainter::paint_frame(Painter& painter, IntRect const& rect, Palette const& palette, FrameShape shape, FrameShadow shadow, int thickness, bool skip_vertical_lines) +void ClassicStylePainter::paint_frame(Painter& painter, IntRect const& rect, Palette const& palette, FrameStyle style, bool skip_vertical_lines) { - if (shape == Gfx::FrameShape::NoFrame) + if (style == Gfx::FrameStyle::NoFrame) return; - if (shape == FrameShape::Window) { + if (style == FrameStyle::Window) { StylePainter::paint_window_frame(painter, rect, palette); return; } @@ -256,48 +256,50 @@ void ClassicStylePainter::paint_frame(Painter& painter, IntRect const& rect, Pal Color dark_shade = palette.threed_shadow1(); Color light_shade = palette.threed_highlight(); - if (shape == FrameShape::Container && thickness >= 2) { - if (shadow == FrameShadow::Raised) { - dark_shade = palette.threed_shadow2(); - } - } + if (style == FrameStyle::RaisedContainer) + dark_shade = palette.threed_shadow2(); - if (shadow == FrameShadow::Raised) { + switch (style) { + case FrameStyle::RaisedContainer: + case FrameStyle::RaisedBox: + case FrameStyle::RaisedPanel: top_left_color = light_shade; bottom_right_color = dark_shade; - } else if (shadow == FrameShadow::Sunken) { + break; + case FrameStyle::SunkenContainer: + case FrameStyle::SunkenBox: + case FrameStyle::SunkenPanel: top_left_color = dark_shade; bottom_right_color = light_shade; - } else if (shadow == FrameShadow::Plain) { + break; + case FrameStyle::Plain: top_left_color = dark_shade; bottom_right_color = dark_shade; + break; + default: + VERIFY_NOT_REACHED(); } - if (thickness >= 1) { - painter.draw_line(rect.top_left(), rect.top_right(), top_left_color); - painter.draw_line(rect.bottom_left(), rect.bottom_right(), bottom_right_color); + painter.draw_line(rect.top_left(), rect.top_right(), top_left_color); + painter.draw_line(rect.bottom_left(), rect.bottom_right(), bottom_right_color); - if (shape != FrameShape::Panel || !skip_vertical_lines) { - painter.draw_line(rect.top_left().translated(0, 1), rect.bottom_left().translated(0, -1), top_left_color); - painter.draw_line(rect.top_right(), rect.bottom_right().translated(0, -1), bottom_right_color); - } + if ((style != FrameStyle::SunkenPanel && style != FrameStyle::RaisedPanel) || !skip_vertical_lines) { + painter.draw_line(rect.top_left().translated(0, 1), rect.bottom_left().translated(0, -1), top_left_color); + painter.draw_line(rect.top_right(), rect.bottom_right().translated(0, -1), bottom_right_color); } - if (shape == FrameShape::Container && thickness >= 2) { + if (style == FrameStyle::RaisedContainer || style == FrameStyle::SunkenContainer) { Color top_left_color; Color bottom_right_color; Color dark_shade = palette.threed_shadow2(); Color light_shade = palette.button(); - if (shadow == FrameShadow::Raised) { + if (style == FrameStyle::RaisedContainer) { dark_shade = palette.threed_shadow1(); top_left_color = light_shade; bottom_right_color = dark_shade; - } else if (shadow == FrameShadow::Sunken) { + } else if (style == FrameStyle::SunkenContainer) { top_left_color = dark_shade; bottom_right_color = light_shade; - } else if (shadow == FrameShadow::Plain) { - top_left_color = dark_shade; - bottom_right_color = dark_shade; } IntRect inner_container_frame_rect = rect.shrunken(2, 2); painter.draw_line(inner_container_frame_rect.top_left(), inner_container_frame_rect.top_right(), top_left_color); @@ -306,7 +308,7 @@ void ClassicStylePainter::paint_frame(Painter& painter, IntRect const& rect, Pal painter.draw_line(inner_container_frame_rect.top_right(), inner_container_frame_rect.bottom_right().translated(0, -1), bottom_right_color); } - if (shape == FrameShape::Box && thickness >= 2) { + if (style == FrameStyle::RaisedBox || style == FrameStyle::SunkenBox) { swap(top_left_color, bottom_right_color); IntRect inner_rect = rect.shrunken(2, 2); painter.draw_line(inner_rect.top_left(), inner_rect.top_right(), top_left_color); @@ -555,7 +557,7 @@ static constexpr Gfx::CharacterBitmap s_checked_bitmap { void ClassicStylePainter::paint_check_box(Painter& painter, IntRect const& rect, Palette const& palette, bool is_enabled, bool is_checked, bool is_being_pressed) { painter.fill_rect(rect, is_enabled ? palette.base() : palette.window()); - paint_frame(painter, rect, palette, Gfx::FrameShape::Container, Gfx::FrameShadow::Sunken, 2); + paint_frame(painter, rect, palette, Gfx::FrameStyle::SunkenContainer); if (is_being_pressed) { // FIXME: This color should not be hard-coded. diff --git a/Userland/Libraries/LibGfx/ClassicStylePainter.h b/Userland/Libraries/LibGfx/ClassicStylePainter.h index 4c9fe615ff..1a9b98e69f 100644 --- a/Userland/Libraries/LibGfx/ClassicStylePainter.h +++ b/Userland/Libraries/LibGfx/ClassicStylePainter.h @@ -17,7 +17,7 @@ class ClassicStylePainter : public BaseStylePainter { public: virtual void paint_button(Painter&, IntRect const&, Palette const&, ButtonStyle, bool pressed, bool hovered = false, bool checked = false, bool enabled = true, bool focused = false, bool default_button = false) override; virtual void paint_tab_button(Painter&, IntRect const&, Palette const&, bool active, bool hovered, bool enabled, GUI::TabWidget::TabPosition position, bool in_active_window, bool accented) override; - virtual void paint_frame(Painter&, IntRect const&, Palette const&, FrameShape, FrameShadow, int thickness, bool skip_vertical_lines = false) override; + virtual void paint_frame(Painter&, IntRect const&, Palette const&, FrameStyle, bool skip_vertical_lines = false) override; virtual void paint_window_frame(Painter&, IntRect const&, Palette const&) override; virtual void paint_progressbar(Painter&, IntRect const&, Palette const&, int min, int max, int value, StringView text, Orientation = Orientation::Horizontal) override; virtual void paint_radio_button(Painter&, IntRect const&, Palette const&, bool is_checked, bool is_being_pressed) override; diff --git a/Userland/Libraries/LibGfx/StylePainter.cpp b/Userland/Libraries/LibGfx/StylePainter.cpp index 37106f5b14..256aed6305 100644 --- a/Userland/Libraries/LibGfx/StylePainter.cpp +++ b/Userland/Libraries/LibGfx/StylePainter.cpp @@ -28,9 +28,9 @@ void StylePainter::paint_button(Painter& painter, IntRect const& rect, Palette c current().paint_button(painter, rect, palette, button_style, pressed, hovered, checked, enabled, focused, default_button); } -void StylePainter::paint_frame(Painter& painter, IntRect const& rect, Palette const& palette, FrameShape shape, FrameShadow shadow, int thickness, bool skip_vertical_lines) +void StylePainter::paint_frame(Painter& painter, IntRect const& rect, Palette const& palette, FrameStyle style, bool skip_vertical_lines) { - current().paint_frame(painter, rect, palette, shape, shadow, thickness, skip_vertical_lines); + current().paint_frame(painter, rect, palette, style, skip_vertical_lines); } void StylePainter::paint_window_frame(Painter& painter, IntRect const& rect, Palette const& palette) diff --git a/Userland/Libraries/LibGfx/StylePainter.h b/Userland/Libraries/LibGfx/StylePainter.h index 8951a2afb5..9a7de46282 100644 --- a/Userland/Libraries/LibGfx/StylePainter.h +++ b/Userland/Libraries/LibGfx/StylePainter.h @@ -19,17 +19,17 @@ enum class ButtonStyle { Coolbar, Tray, }; -enum class FrameShadow { - Plain, - Raised, - Sunken -}; -enum class FrameShape { + +enum class FrameStyle { NoFrame, - Box, - Container, - Panel, Window, + Plain, + RaisedBox, + SunkenBox, + RaisedContainer, + SunkenContainer, + RaisedPanel, + SunkenPanel, }; // FIXME: should this be in its own header? @@ -39,7 +39,7 @@ public: virtual void paint_button(Painter&, IntRect const&, Palette const&, ButtonStyle, bool pressed, bool hovered = false, bool checked = false, bool enabled = true, bool focused = false, bool default_button = false) = 0; virtual void paint_tab_button(Painter&, IntRect const&, Palette const&, bool active, bool hovered, bool enabled, GUI::TabWidget::TabPosition position, bool in_active_window, bool accented) = 0; - virtual void paint_frame(Painter&, IntRect const&, Palette const&, FrameShape, FrameShadow, int thickness, bool skip_vertical_lines = false) = 0; + virtual void paint_frame(Painter&, IntRect const&, Palette const&, FrameStyle, bool skip_vertical_lines = false) = 0; virtual void paint_window_frame(Painter&, IntRect const&, Palette const&) = 0; virtual void paint_progressbar(Painter&, IntRect const&, Palette const&, int min, int max, int value, StringView text, Orientation = Orientation::Horizontal) = 0; virtual void paint_radio_button(Painter&, IntRect const&, Palette const&, bool is_checked, bool is_being_pressed) = 0; @@ -58,7 +58,7 @@ public: // FIXME: These are here for API compatibility, we should probably remove them and move BaseStylePainter into here static void paint_button(Painter&, IntRect const&, Palette const&, ButtonStyle, bool pressed, bool hovered = false, bool checked = false, bool enabled = true, bool focused = false, bool default_button = false); static void paint_tab_button(Painter&, IntRect const&, Palette const&, bool active, bool hovered, bool enabled, GUI::TabWidget::TabPosition position, bool in_active_window, bool accented); - static void paint_frame(Painter&, IntRect const&, Palette const&, FrameShape, FrameShadow, int thickness, bool skip_vertical_lines = false); + static void paint_frame(Painter&, IntRect const&, Palette const&, FrameStyle, bool skip_vertical_lines = false); static void paint_window_frame(Painter&, IntRect const&, Palette const&); static void paint_progressbar(Painter&, IntRect const&, Palette const&, int min, int max, int value, StringView text, Orientation = Orientation::Horizontal); static void paint_radio_button(Painter&, IntRect const&, Palette const&, bool is_checked, bool is_being_pressed); |