Browse Source

Move LibGUI/GStyle to SharedGraphics/StylePainter.

I want to paint some buttons in WindowServer where we don't have LibGUI.
Andreas Kling 6 years ago
parent
commit
c7ab643883

+ 1 - 1
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);

+ 2 - 2
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());
 }

+ 2 - 2
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();

+ 4 - 4
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 };
 };

+ 1 - 1
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)

+ 4 - 4
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)

+ 2 - 2
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());
 }

+ 0 - 17
LibGUI/GStyle.h

@@ -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();
-};

+ 2 - 2
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());
 }

+ 1 - 1
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 \

+ 1 - 0
Servers/WindowServer/Makefile

@@ -1,5 +1,6 @@
 SHAREDGRAPHICS_OBJS = \
     ../../SharedGraphics/Painter.o \
+    ../../SharedGraphics/StylePainter.o \
     ../../SharedGraphics/Font.o \
     ../../SharedGraphics/Rect.o \
     ../../SharedGraphics/GraphicsBitmap.o \

+ 10 - 10
LibGUI/GStyle.cpp → 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);

+ 17 - 0
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();
+};