summaryrefslogtreecommitdiff
path: root/LibGUI
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-03-28 17:32:38 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-03-28 17:32:38 +0100
commitc7ab643883b5b2fbadd799e84ed9e79fdeafb9e6 (patch)
treeeec552685be7e999ab9471d7d835a6d9c9101ea8 /LibGUI
parentd12b6b867760fc9faa366d765aade072eaa4a8dc (diff)
downloadserenity-c7ab643883b5b2fbadd799e84ed9e79fdeafb9e6.zip
Move LibGUI/GStyle to SharedGraphics/StylePainter.
I want to paint some buttons in WindowServer where we don't have LibGUI.
Diffstat (limited to 'LibGUI')
-rw-r--r--LibGUI/GButton.cpp4
-rw-r--r--LibGUI/GButton.h8
-rw-r--r--LibGUI/GFrame.cpp2
-rw-r--r--LibGUI/GScrollBar.cpp8
-rw-r--r--LibGUI/GStatusBar.cpp4
-rw-r--r--LibGUI/GStyle.cpp106
-rw-r--r--LibGUI/GStyle.h17
-rw-r--r--LibGUI/GToolBar.cpp4
-rw-r--r--LibGUI/Makefile2
9 files changed, 16 insertions, 139 deletions
diff --git a/LibGUI/GButton.cpp b/LibGUI/GButton.cpp
index 96f329113e..0053e67dce 100644
--- a/LibGUI/GButton.cpp
+++ b/LibGUI/GButton.cpp
@@ -1,6 +1,6 @@
#include "GButton.h"
#include <LibGUI/GPainter.h>
-#include <LibGUI/GStyle.h>
+#include <SharedGraphics/StylePainter.h>
//#define GBUTTON_DEBUG
@@ -26,7 +26,7 @@ void GButton::paint_event(GPaintEvent& event)
GPainter painter(*this);
painter.set_clip_rect(event.rect());
- GStyle::the().paint_button(painter, rect(), m_button_style, m_being_pressed, m_hovered);
+ StylePainter::the().paint_button(painter, rect(), m_button_style, m_being_pressed, m_hovered);
if (!caption().is_empty() || m_icon) {
auto content_rect = rect();
diff --git a/LibGUI/GButton.h b/LibGUI/GButton.h
index 1a5ed4b905..c76ceffbaa 100644
--- a/LibGUI/GButton.h
+++ b/LibGUI/GButton.h
@@ -1,7 +1,7 @@
#pragma once
#include <LibGUI/GWidget.h>
-#include <LibGUI/GStyle.h>
+#include <SharedGraphics/StylePainter.h>
#include <AK/AKString.h>
#include <AK/Function.h>
#include <SharedGraphics/GraphicsBitmap.h>
@@ -20,8 +20,8 @@ public:
Function<void(GButton&)> on_click;
- void set_button_style(GButtonStyle style) { m_button_style = style; }
- GButtonStyle button_style() const { return m_button_style; }
+ void set_button_style(ButtonStyle style) { m_button_style = style; }
+ ButtonStyle button_style() const { return m_button_style; }
void click();
@@ -37,7 +37,7 @@ private:
String m_caption;
RetainPtr<GraphicsBitmap> m_icon;
- GButtonStyle m_button_style { GButtonStyle::Normal };
+ ButtonStyle m_button_style { ButtonStyle::Normal };
bool m_being_pressed { false };
bool m_hovered { false };
};
diff --git a/LibGUI/GFrame.cpp b/LibGUI/GFrame.cpp
index 322331163d..0426b519ce 100644
--- a/LibGUI/GFrame.cpp
+++ b/LibGUI/GFrame.cpp
@@ -1,5 +1,5 @@
#include <LibGUI/GFrame.h>
-#include <LibGUI/GStyle.h>
+#include <SharedGraphics/StylePainter.h>
#include <LibGUI/GPainter.h>
GFrame::GFrame(GWidget* parent)
diff --git a/LibGUI/GScrollBar.cpp b/LibGUI/GScrollBar.cpp
index 9056135ded..9f0c235726 100644
--- a/LibGUI/GScrollBar.cpp
+++ b/LibGUI/GScrollBar.cpp
@@ -1,5 +1,5 @@
#include <LibGUI/GScrollBar.h>
-#include <LibGUI/GStyle.h>
+#include <SharedGraphics/StylePainter.h>
#include <SharedGraphics/CharacterBitmap.h>
#include <SharedGraphics/GraphicsBitmap.h>
#include <LibGUI/GPainter.h>
@@ -190,14 +190,14 @@ void GScrollBar::paint_event(GPaintEvent& event)
painter.fill_rect(rect(), Color::from_rgb(0xd6d2ce));
- GStyle::the().paint_button(painter, up_button_rect(), GButtonStyle::Normal, false);
+ StylePainter::the().paint_button(painter, up_button_rect(), ButtonStyle::Normal, false);
painter.draw_bitmap(up_button_rect().location().translated(3, 3), orientation() == Orientation::Vertical ? *s_up_arrow_bitmap : *s_left_arrow_bitmap, has_scrubber() ? Color::Black : Color::MidGray);
- GStyle::the().paint_button(painter, down_button_rect(), GButtonStyle::Normal, false);
+ StylePainter::the().paint_button(painter, down_button_rect(), ButtonStyle::Normal, false);
painter.draw_bitmap(down_button_rect().location().translated(3, 3), orientation() == Orientation::Vertical ? *s_down_arrow_bitmap : *s_right_arrow_bitmap, has_scrubber() ? Color::Black : Color::MidGray);
if (has_scrubber())
- GStyle::the().paint_button(painter, scrubber_rect(), GButtonStyle::Normal, false);
+ StylePainter::the().paint_button(painter, scrubber_rect(), ButtonStyle::Normal, false);
}
void GScrollBar::mousedown_event(GMouseEvent& event)
diff --git a/LibGUI/GStatusBar.cpp b/LibGUI/GStatusBar.cpp
index bf4a775dd2..e0e92be646 100644
--- a/LibGUI/GStatusBar.cpp
+++ b/LibGUI/GStatusBar.cpp
@@ -1,7 +1,7 @@
#include <LibGUI/GStatusBar.h>
#include <LibGUI/GLabel.h>
#include <LibGUI/GBoxLayout.h>
-#include <LibGUI/GStyle.h>
+#include <SharedGraphics/StylePainter.h>
#include <LibGUI/GPainter.h>
GStatusBar::GStatusBar(GWidget* parent)
@@ -36,5 +36,5 @@ void GStatusBar::paint_event(GPaintEvent& event)
{
GPainter painter(*this);
painter.set_clip_rect(event.rect());
- GStyle::the().paint_surface(painter, rect());
+ StylePainter::the().paint_surface(painter, rect());
}
diff --git a/LibGUI/GStyle.cpp b/LibGUI/GStyle.cpp
deleted file mode 100644
index 375477e484..0000000000
--- a/LibGUI/GStyle.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-#include <LibGUI/GStyle.h>
-#include <LibGUI/GPainter.h>
-
-static GStyle* s_the;
-
-GStyle& GStyle::the()
-{
- if (!s_the)
- s_the = new GStyle;
- return *s_the;
-}
-
-GStyle::GStyle()
-{
-}
-
-static void paint_button_new(Painter& painter, const Rect& rect, bool pressed)
-{
- Color button_color = Color::from_rgb(0xc0c0c0);
- Color highlight_color1 = Color::from_rgb(0xffffff);
- Color highlight_color2 = Color::from_rgb(0xdfdfdf);
- Color shadow_color1 = Color::from_rgb(0x808080);
- Color shadow_color2 = Color::from_rgb(0x404040);
-
- PainterStateSaver saver(painter);
- painter.translate(rect.location());
-
- if (pressed) {
- // Base
- painter.fill_rect({ 1, 1, rect.width() - 2, rect.height() - 2 }, button_color);
-
- painter.draw_rect(rect, shadow_color2);
-
- // Sunken shadow
- painter.draw_line({ 1, 1 }, { rect.width() - 2, 1 }, shadow_color1);
- painter.draw_line({ 1, 2 }, {1, rect.height() - 2 }, shadow_color1);
- } else {
- // Base
- painter.fill_rect({ 2, 2, rect.width() - 4, rect.height() - 4 }, button_color);
-
- // Outer highlight
- painter.draw_line({ 0, 0 }, { rect.width() - 2, 0 }, highlight_color2);
- painter.draw_line({ 0, 1 }, { 0, rect.height() - 2 }, highlight_color2);
-
- // Inner highlight
- painter.draw_line({ 1, 1 }, { rect.width() - 3, 1 }, highlight_color1);
- painter.draw_line({ 1, 2 }, { 1, rect.height() - 3 }, highlight_color1);
-
- // Outer shadow
- painter.draw_line({ 0, rect.height() - 1 }, { rect.width() - 1, rect.height() - 1 }, shadow_color2);
- painter.draw_line({ rect.width() - 1, 0 }, { rect.width() - 1, rect.height() - 2 }, shadow_color2);
-
- // Inner shadow
- painter.draw_line({ 1, rect.height() - 2 }, { rect.width() - 2, rect.height() - 2 }, shadow_color1);
- painter.draw_line({ rect.width() - 2, 1 }, { rect.width() - 2, rect.height() - 3 }, shadow_color1);
- }
-}
-
-void GStyle::paint_button(Painter& painter, const Rect& rect, GButtonStyle button_style, bool pressed, bool hovered)
-{
- if (button_style == GButtonStyle::Normal)
- return paint_button_new(painter, rect, pressed);
-
- Color button_color = Color::LightGray;
- Color highlight_color = Color::White;
- Color shadow_color = Color(96, 96, 96);
-
- if (button_style == GButtonStyle::OldNormal)
- painter.draw_rect(rect, Color::Black);
-
- PainterStateSaver saver(painter);
- painter.translate(rect.location());
-
- if (pressed) {
- // Base
- painter.fill_rect({ 1, 1, rect.width() - 2, rect.height() - 2 }, button_color);
-
- // Sunken shadow
- painter.draw_line({ 1, 1 }, { rect.width() - 2, 1 }, shadow_color);
- painter.draw_line({ 1, 2 }, {1, rect.height() - 2 }, shadow_color);
-
- // Bottom highlight
- painter.draw_line({ rect.width() - 2, 1 }, { rect.width() - 2, rect.height() - 3 }, highlight_color);
- painter.draw_line({ 1, rect.height() - 2 }, { rect.width() - 2, rect.height() - 2 }, highlight_color);
- } else if (button_style == GButtonStyle::OldNormal || (button_style == GButtonStyle::CoolBar && hovered)) {
- // Base
- painter.fill_rect({ 1, 1, rect.width() - 2, rect.height() - 2 }, button_color);
-
- // White highlight
- painter.draw_line({ 1, 1 }, { rect.width() - 2, 1 }, highlight_color);
- painter.draw_line({ 1, 2 }, { 1, rect.height() - 2 }, highlight_color);
-
- // Gray shadow
- painter.draw_line({ rect.width() - 2, 1 }, { rect.width() - 2, rect.height() - 3 }, shadow_color);
- painter.draw_line({ 1, rect.height() - 2 }, { rect.width() - 2, rect.height() - 2 }, shadow_color);
- }
-}
-
-void GStyle::paint_surface(Painter& painter, const Rect& rect)
-{
- painter.fill_rect({ rect.x(), rect.y() + 1, rect.width(), rect.height() - 2 }, Color::LightGray);
- painter.draw_line(rect.top_left(), rect.top_right(), Color::White);
- painter.draw_line(rect.bottom_left(), rect.bottom_right(), Color::MidGray);
- painter.draw_line(rect.top_left().translated(0, 1), rect.bottom_left().translated(0, -1), Color::White);
- painter.draw_line(rect.top_right(), rect.bottom_right().translated(0, -1), Color::MidGray);
-}
diff --git a/LibGUI/GStyle.h b/LibGUI/GStyle.h
deleted file mode 100644
index e18809bd85..0000000000
--- a/LibGUI/GStyle.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#pragma once
-
-class Painter;
-class Rect;
-
-enum class GButtonStyle { Normal, CoolBar, OldNormal };
-
-class GStyle {
-public:
- static GStyle& the();
-
- void paint_button(Painter&, const Rect&, GButtonStyle, bool pressed, bool hovered = false);
- void paint_surface(Painter&, const Rect&);
-
-private:
- GStyle();
-};
diff --git a/LibGUI/GToolBar.cpp b/LibGUI/GToolBar.cpp
index 93559b8a42..3acc17108d 100644
--- a/LibGUI/GToolBar.cpp
+++ b/LibGUI/GToolBar.cpp
@@ -34,7 +34,7 @@ void GToolBar::add_action(Retained<GAction>&& action)
raw_action_ptr->activate();
};
- button->set_button_style(GButtonStyle::CoolBar);
+ button->set_button_style(ButtonStyle::CoolBar);
button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
ASSERT(button->size_policy(Orientation::Horizontal) == SizePolicy::Fixed);
ASSERT(button->size_policy(Orientation::Vertical) == SizePolicy::Fixed);
@@ -79,5 +79,5 @@ void GToolBar::paint_event(GPaintEvent& event)
{
GPainter painter(*this);
painter.set_clip_rect(event.rect());
- GStyle::the().paint_surface(painter, rect());
+ StylePainter::the().paint_surface(painter, rect());
}
diff --git a/LibGUI/Makefile b/LibGUI/Makefile
index aa63cbc48b..fefb6158f6 100644
--- a/LibGUI/Makefile
+++ b/LibGUI/Makefile
@@ -1,5 +1,6 @@
SHAREDGRAPHICS_OBJS = \
../SharedGraphics/Painter.o \
+ ../SharedGraphics/StylePainter.o \
../SharedGraphics/Font.o \
../SharedGraphics/Rect.o \
../SharedGraphics/GraphicsBitmap.o \
@@ -22,7 +23,6 @@ LIBGUI_OBJS = \
GScrollBar.o \
GStatusBar.o \
GWidget.o \
- GStyle.o \
GLayout.o \
GBoxLayout.o \
GMenuBar.o \