summaryrefslogtreecommitdiff
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
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.
-rw-r--r--Applications/Launcher/main.cpp2
-rw-r--r--Applications/ProcessManager/MemoryStatsWidget.cpp4
-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.h17
-rw-r--r--LibGUI/GToolBar.cpp4
-rw-r--r--LibGUI/Makefile2
-rw-r--r--Servers/WindowServer/Makefile1
-rw-r--r--SharedGraphics/StylePainter.cpp (renamed from LibGUI/GStyle.cpp)20
-rw-r--r--SharedGraphics/StylePainter.h17
13 files changed, 47 insertions, 46 deletions
diff --git a/Applications/Launcher/main.cpp b/Applications/Launcher/main.cpp
index 5b27f2f8f6..cc1fd4eb47 100644
--- a/Applications/Launcher/main.cpp
+++ b/Applications/Launcher/main.cpp
@@ -39,7 +39,7 @@ public:
: GButton(parent)
, m_executable_path(exec_path)
{
- set_button_style(GButtonStyle::CoolBar);
+ set_button_style(ButtonStyle::CoolBar);
set_icon(GraphicsBitmap::load_from_file(icon_path));
set_preferred_size({ 50, 50 });
set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
diff --git a/Applications/ProcessManager/MemoryStatsWidget.cpp b/Applications/ProcessManager/MemoryStatsWidget.cpp
index d3b216ada1..6704627dd4 100644
--- a/Applications/ProcessManager/MemoryStatsWidget.cpp
+++ b/Applications/ProcessManager/MemoryStatsWidget.cpp
@@ -2,7 +2,7 @@
#include <LibGUI/GPainter.h>
#include <LibGUI/GBoxLayout.h>
#include <LibGUI/GLabel.h>
-#include <LibGUI/GStyle.h>
+#include <SharedGraphics/StylePainter.h>
#include <stdio.h>
#include <stdlib.h>
@@ -106,5 +106,5 @@ void MemoryStatsWidget::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/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.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 \
diff --git a/Servers/WindowServer/Makefile b/Servers/WindowServer/Makefile
index ed3b4ec4f1..0b8dcafbf2 100644
--- a/Servers/WindowServer/Makefile
+++ b/Servers/WindowServer/Makefile
@@ -1,5 +1,6 @@
SHAREDGRAPHICS_OBJS = \
../../SharedGraphics/Painter.o \
+ ../../SharedGraphics/StylePainter.o \
../../SharedGraphics/Font.o \
../../SharedGraphics/Rect.o \
../../SharedGraphics/GraphicsBitmap.o \
diff --git a/LibGUI/GStyle.cpp b/SharedGraphics/StylePainter.cpp
index 375477e484..9d37a9de75 100644
--- a/LibGUI/GStyle.cpp
+++ b/SharedGraphics/StylePainter.cpp
@@ -1,16 +1,16 @@
-#include <LibGUI/GStyle.h>
+#include <SharedGraphics/StylePainter.h>
#include <LibGUI/GPainter.h>
-static GStyle* s_the;
+static StylePainter* s_the;
-GStyle& GStyle::the()
+StylePainter& StylePainter::the()
{
if (!s_the)
- s_the = new GStyle;
+ s_the = new StylePainter;
return *s_the;
}
-GStyle::GStyle()
+StylePainter::StylePainter()
{
}
@@ -56,16 +56,16 @@ static void paint_button_new(Painter& painter, const Rect& rect, bool pressed)
}
}
-void GStyle::paint_button(Painter& painter, const Rect& rect, GButtonStyle button_style, bool pressed, bool hovered)
+void StylePainter::paint_button(Painter& painter, const Rect& rect, ButtonStyle button_style, bool pressed, bool hovered)
{
- if (button_style == GButtonStyle::Normal)
+ if (button_style == ButtonStyle::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)
+ if (button_style == ButtonStyle::OldNormal)
painter.draw_rect(rect, Color::Black);
PainterStateSaver saver(painter);
@@ -82,7 +82,7 @@ void GStyle::paint_button(Painter& painter, const Rect& rect, GButtonStyle butto
// 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)) {
+ } else if (button_style == ButtonStyle::OldNormal || (button_style == ButtonStyle::CoolBar && hovered)) {
// Base
painter.fill_rect({ 1, 1, rect.width() - 2, rect.height() - 2 }, button_color);
@@ -96,7 +96,7 @@ void GStyle::paint_button(Painter& painter, const Rect& rect, GButtonStyle butto
}
}
-void GStyle::paint_surface(Painter& painter, const Rect& rect)
+void StylePainter::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);
diff --git a/SharedGraphics/StylePainter.h b/SharedGraphics/StylePainter.h
new file mode 100644
index 0000000000..7e6ad5f955
--- /dev/null
+++ b/SharedGraphics/StylePainter.h
@@ -0,0 +1,17 @@
+#pragma once
+
+class Painter;
+class Rect;
+
+enum class ButtonStyle { Normal, CoolBar, OldNormal };
+
+class StylePainter {
+public:
+ static StylePainter& the();
+
+ void paint_button(Painter&, const Rect&, ButtonStyle, bool pressed, bool hovered = false);
+ void paint_surface(Painter&, const Rect&);
+
+private:
+ StylePainter();
+};