summaryrefslogtreecommitdiff
path: root/LibGUI
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-03-28 17:19:56 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-03-28 17:19:56 +0100
commit9fa21fa5852fc9b7605d953a3e9f8a9e8bd28864 (patch)
tree551051e45da768531505855a2df3e3eccd9f3331 /LibGUI
parent326c6fd607893af0dd6200815540708bc218145d (diff)
downloadserenity-9fa21fa5852fc9b7605d953a3e9f8a9e8bd28864.zip
LibGUI: Add a GPainter class that inherits from Painter.
This gets rid of the last little piece of LibGUI knowledge in Painter.
Diffstat (limited to 'LibGUI')
-rw-r--r--LibGUI/GAbstractView.cpp2
-rw-r--r--LibGUI/GButton.cpp4
-rw-r--r--LibGUI/GCheckBox.cpp4
-rw-r--r--LibGUI/GFrame.cpp4
-rw-r--r--LibGUI/GItemView.cpp4
-rw-r--r--LibGUI/GLabel.cpp4
-rw-r--r--LibGUI/GListBox.cpp4
-rw-r--r--LibGUI/GPainter.cpp19
-rw-r--r--LibGUI/GPainter.h12
-rw-r--r--LibGUI/GProgressBar.cpp4
-rw-r--r--LibGUI/GScrollBar.cpp4
-rw-r--r--LibGUI/GStatusBar.cpp4
-rw-r--r--LibGUI/GStyle.cpp2
-rw-r--r--LibGUI/GTableView.cpp4
-rw-r--r--LibGUI/GTextBox.cpp4
-rw-r--r--LibGUI/GTextEditor.cpp4
-rw-r--r--LibGUI/GToolBar.cpp6
-rw-r--r--LibGUI/GWidget.cpp6
-rw-r--r--LibGUI/GWindow.cpp2
-rw-r--r--LibGUI/Makefile1
20 files changed, 65 insertions, 33 deletions
diff --git a/LibGUI/GAbstractView.cpp b/LibGUI/GAbstractView.cpp
index 34c73b4ab6..b1f64ae7d4 100644
--- a/LibGUI/GAbstractView.cpp
+++ b/LibGUI/GAbstractView.cpp
@@ -1,7 +1,7 @@
#include <LibGUI/GAbstractView.h>
#include <LibGUI/GModel.h>
#include <LibGUI/GScrollBar.h>
-#include <SharedGraphics/Painter.h>
+#include <LibGUI/GPainter.h>
#include <Kernel/KeyCode.h>
GAbstractView::GAbstractView(GWidget* parent)
diff --git a/LibGUI/GButton.cpp b/LibGUI/GButton.cpp
index fe7ccc65bf..96f329113e 100644
--- a/LibGUI/GButton.cpp
+++ b/LibGUI/GButton.cpp
@@ -1,5 +1,5 @@
#include "GButton.h"
-#include <SharedGraphics/Painter.h>
+#include <LibGUI/GPainter.h>
#include <LibGUI/GStyle.h>
//#define GBUTTON_DEBUG
@@ -23,7 +23,7 @@ void GButton::set_caption(const String& caption)
void GButton::paint_event(GPaintEvent& event)
{
- Painter painter(*this);
+ GPainter painter(*this);
painter.set_clip_rect(event.rect());
GStyle::the().paint_button(painter, rect(), m_button_style, m_being_pressed, m_hovered);
diff --git a/LibGUI/GCheckBox.cpp b/LibGUI/GCheckBox.cpp
index 101ca32707..506ce76e3d 100644
--- a/LibGUI/GCheckBox.cpp
+++ b/LibGUI/GCheckBox.cpp
@@ -1,5 +1,5 @@
#include "GCheckBox.h"
-#include <SharedGraphics/Painter.h>
+#include <LibGUI/GPainter.h>
#include <SharedGraphics/CharacterBitmap.h>
#include <Kernel/KeyCode.h>
@@ -54,7 +54,7 @@ void GCheckBox::set_checked(bool b)
void GCheckBox::paint_event(GPaintEvent& event)
{
- Painter painter(*this);
+ GPainter painter(*this);
painter.set_clip_rect(event.rect());
auto text_rect = rect();
diff --git a/LibGUI/GFrame.cpp b/LibGUI/GFrame.cpp
index 0d31da6c57..322331163d 100644
--- a/LibGUI/GFrame.cpp
+++ b/LibGUI/GFrame.cpp
@@ -1,6 +1,6 @@
#include <LibGUI/GFrame.h>
#include <LibGUI/GStyle.h>
-#include <SharedGraphics/Painter.h>
+#include <LibGUI/GPainter.h>
GFrame::GFrame(GWidget* parent)
: GWidget(parent)
@@ -16,7 +16,7 @@ void GFrame::paint_event(GPaintEvent& event)
if (m_shape == Shape::NoFrame)
return;
- Painter painter(*this);
+ GPainter painter(*this);
painter.set_clip_rect(event.rect());
auto rect = this->rect();
diff --git a/LibGUI/GItemView.cpp b/LibGUI/GItemView.cpp
index 21628c9f66..92d71b79a2 100644
--- a/LibGUI/GItemView.cpp
+++ b/LibGUI/GItemView.cpp
@@ -1,7 +1,7 @@
#include <LibGUI/GItemView.h>
#include <LibGUI/GModel.h>
#include <LibGUI/GScrollBar.h>
-#include <SharedGraphics/Painter.h>
+#include <LibGUI/GPainter.h>
#include <Kernel/KeyCode.h>
GItemView::GItemView(GWidget* parent)
@@ -98,7 +98,7 @@ void GItemView::paint_event(GPaintEvent& event)
{
GFrame::paint_event(event);
- Painter painter(*this);
+ GPainter painter(*this);
painter.set_clip_rect(widget_inner_rect());
painter.set_clip_rect(event.rect());
painter.fill_rect(event.rect(), Color::White);
diff --git a/LibGUI/GLabel.cpp b/LibGUI/GLabel.cpp
index bb6da3abaf..b3a29e941b 100644
--- a/LibGUI/GLabel.cpp
+++ b/LibGUI/GLabel.cpp
@@ -1,5 +1,5 @@
#include "GLabel.h"
-#include <SharedGraphics/Painter.h>
+#include <LibGUI/GPainter.h>
#include <SharedGraphics/GraphicsBitmap.h>
GLabel::GLabel(GWidget* parent)
@@ -34,7 +34,7 @@ void GLabel::paint_event(GPaintEvent& event)
{
GFrame::paint_event(event);
- Painter painter(*this);
+ GPainter painter(*this);
painter.set_clip_rect(event.rect());
if (m_icon) {
diff --git a/LibGUI/GListBox.cpp b/LibGUI/GListBox.cpp
index c7ed5faab3..328716e5b2 100644
--- a/LibGUI/GListBox.cpp
+++ b/LibGUI/GListBox.cpp
@@ -1,6 +1,6 @@
#include "GListBox.h"
#include <SharedGraphics/Font.h>
-#include <SharedGraphics/Painter.h>
+#include <LibGUI/GPainter.h>
GListBox::GListBox(GWidget* parent)
: GWidget(parent)
@@ -19,7 +19,7 @@ Rect GListBox::item_rect(int index) const
void GListBox::paint_event(GPaintEvent& event)
{
- Painter painter(*this);
+ GPainter painter(*this);
painter.set_clip_rect(event.rect());
painter.fill_rect({ rect().x() + 1, rect().y() + 1, rect().width() - 2, rect().height() - 2 }, background_color());
diff --git a/LibGUI/GPainter.cpp b/LibGUI/GPainter.cpp
new file mode 100644
index 0000000000..c5bf01e4a2
--- /dev/null
+++ b/LibGUI/GPainter.cpp
@@ -0,0 +1,19 @@
+#include <LibGUI/GPainter.h>
+#include <LibGUI/GWidget.h>
+#include <LibGUI/GWindow.h>
+
+GPainter::GPainter(GraphicsBitmap& bitmap)
+ : Painter(bitmap)
+{
+}
+
+GPainter::GPainter(GWidget& widget)
+ : Painter(*widget.window()->back_bitmap())
+{
+ state().font = &widget.font();
+ auto origin_rect = widget.window_relative_rect();
+ state().translation = origin_rect.location();
+ state().clip_rect = origin_rect;
+ m_clip_origin = origin_rect;
+ state().clip_rect.intersect(m_target->rect());
+}
diff --git a/LibGUI/GPainter.h b/LibGUI/GPainter.h
new file mode 100644
index 0000000000..1ad436e343
--- /dev/null
+++ b/LibGUI/GPainter.h
@@ -0,0 +1,12 @@
+#pragma once
+
+#include <SharedGraphics/Painter.h>
+
+class GWidget;
+class GraphicsBitmap;
+
+class GPainter : public Painter {
+public:
+ explicit GPainter(GWidget&);
+ explicit GPainter(GraphicsBitmap&);
+};
diff --git a/LibGUI/GProgressBar.cpp b/LibGUI/GProgressBar.cpp
index a0aa7b07f0..e03d40168f 100644
--- a/LibGUI/GProgressBar.cpp
+++ b/LibGUI/GProgressBar.cpp
@@ -1,5 +1,5 @@
#include <LibGUI/GProgressBar.h>
-#include <SharedGraphics/Painter.h>
+#include <LibGUI/GPainter.h>
#include <AK/StringBuilder.h>
GProgressBar::GProgressBar(GWidget* parent)
@@ -32,7 +32,7 @@ void GProgressBar::set_range(int min, int max)
void GProgressBar::paint_event(GPaintEvent& event)
{
- Painter painter(*this);
+ GPainter painter(*this);
painter.set_clip_rect(event.rect());
// First we fill the entire widget with the gradient. This incurs a bit of
diff --git a/LibGUI/GScrollBar.cpp b/LibGUI/GScrollBar.cpp
index d952c92af6..c63aae935b 100644
--- a/LibGUI/GScrollBar.cpp
+++ b/LibGUI/GScrollBar.cpp
@@ -2,7 +2,7 @@
#include <LibGUI/GStyle.h>
#include <SharedGraphics/CharacterBitmap.h>
#include <SharedGraphics/GraphicsBitmap.h>
-#include <SharedGraphics/Painter.h>
+#include <LibGUI/GPainter.h>
//#define GUTTER_DOES_PAGEUP_PAGEDOWN
@@ -185,7 +185,7 @@ Rect GScrollBar::scrubber_rect() const
void GScrollBar::paint_event(GPaintEvent& event)
{
- Painter painter(*this);
+ GPainter painter(*this);
painter.set_clip_rect(event.rect());
painter.fill_rect(rect(), Color(164, 164, 164));
diff --git a/LibGUI/GStatusBar.cpp b/LibGUI/GStatusBar.cpp
index a1d6d7e1bd..bf4a775dd2 100644
--- a/LibGUI/GStatusBar.cpp
+++ b/LibGUI/GStatusBar.cpp
@@ -2,7 +2,7 @@
#include <LibGUI/GLabel.h>
#include <LibGUI/GBoxLayout.h>
#include <LibGUI/GStyle.h>
-#include <SharedGraphics/Painter.h>
+#include <LibGUI/GPainter.h>
GStatusBar::GStatusBar(GWidget* parent)
: GWidget(parent)
@@ -34,7 +34,7 @@ String GStatusBar::text() const
void GStatusBar::paint_event(GPaintEvent& event)
{
- Painter painter(*this);
+ GPainter painter(*this);
painter.set_clip_rect(event.rect());
GStyle::the().paint_surface(painter, rect());
}
diff --git a/LibGUI/GStyle.cpp b/LibGUI/GStyle.cpp
index f792b81bdd..375477e484 100644
--- a/LibGUI/GStyle.cpp
+++ b/LibGUI/GStyle.cpp
@@ -1,5 +1,5 @@
#include <LibGUI/GStyle.h>
-#include <SharedGraphics/Painter.h>
+#include <LibGUI/GPainter.h>
static GStyle* s_the;
diff --git a/LibGUI/GTableView.cpp b/LibGUI/GTableView.cpp
index 88100c4304..2f3c6e6ea8 100644
--- a/LibGUI/GTableView.cpp
+++ b/LibGUI/GTableView.cpp
@@ -1,7 +1,7 @@
#include <LibGUI/GTableView.h>
#include <LibGUI/GModel.h>
#include <LibGUI/GScrollBar.h>
-#include <SharedGraphics/Painter.h>
+#include <LibGUI/GPainter.h>
#include <Kernel/KeyCode.h>
GTableView::GTableView(GWidget* parent)
@@ -100,7 +100,7 @@ void GTableView::paint_event(GPaintEvent& event)
{
GFrame::paint_event(event);
- Painter painter(*this);
+ GPainter painter(*this);
painter.set_clip_rect(frame_inner_rect());
painter.set_clip_rect(event.rect());
painter.save();
diff --git a/LibGUI/GTextBox.cpp b/LibGUI/GTextBox.cpp
index 5ebc962128..743360c08b 100644
--- a/LibGUI/GTextBox.cpp
+++ b/LibGUI/GTextBox.cpp
@@ -2,7 +2,7 @@
#include <AK/StdLibExtras.h>
#include <SharedGraphics/CharacterBitmap.h>
#include <SharedGraphics/Font.h>
-#include <SharedGraphics/Painter.h>
+#include <LibGUI/GPainter.h>
#include <Kernel/KeyCode.h>
GTextBox::GTextBox(GWidget* parent)
@@ -73,7 +73,7 @@ Point GTextBox::cursor_content_position() const
void GTextBox::paint_event(GPaintEvent& event)
{
- Painter painter(*this);
+ GPainter painter(*this);
painter.set_clip_rect(event.rect());
painter.fill_rect(rect().shrunken(2, 2), background_color());
diff --git a/LibGUI/GTextEditor.cpp b/LibGUI/GTextEditor.cpp
index b22512ed62..9fae1dbca9 100644
--- a/LibGUI/GTextEditor.cpp
+++ b/LibGUI/GTextEditor.cpp
@@ -2,7 +2,7 @@
#include <LibGUI/GScrollBar.h>
#include <LibGUI/GFontDatabase.h>
#include <LibGUI/GClipboard.h>
-#include <SharedGraphics/Painter.h>
+#include <LibGUI/GPainter.h>
#include <Kernel/KeyCode.h>
#include <AK/StringBuilder.h>
#include <unistd.h>
@@ -152,7 +152,7 @@ void GTextEditor::paint_event(GPaintEvent& event)
{
GFrame::paint_event(event);
- Painter painter(*this);
+ GPainter painter(*this);
painter.set_clip_rect(widget_inner_rect());
painter.set_clip_rect(event.rect());
painter.fill_rect(event.rect(), Color::White);
diff --git a/LibGUI/GToolBar.cpp b/LibGUI/GToolBar.cpp
index 1a53bfa59a..93559b8a42 100644
--- a/LibGUI/GToolBar.cpp
+++ b/LibGUI/GToolBar.cpp
@@ -2,7 +2,7 @@
#include <LibGUI/GBoxLayout.h>
#include <LibGUI/GButton.h>
#include <LibGUI/GAction.h>
-#include <SharedGraphics/Painter.h>
+#include <LibGUI/GPainter.h>
GToolBar::GToolBar(GWidget* parent)
: GWidget(parent)
@@ -56,7 +56,7 @@ public:
virtual void paint_event(GPaintEvent& event) override
{
- Painter painter(*this);
+ GPainter painter(*this);
painter.set_clip_rect(event.rect());
painter.translate(rect().center().x() - 1, 0);
painter.draw_line({ 0, 0 }, { 0, rect().bottom() }, Color::MidGray);
@@ -77,7 +77,7 @@ void GToolBar::add_separator()
void GToolBar::paint_event(GPaintEvent& event)
{
- Painter painter(*this);
+ GPainter painter(*this);
painter.set_clip_rect(event.rect());
GStyle::the().paint_surface(painter, rect());
}
diff --git a/LibGUI/GWidget.cpp b/LibGUI/GWidget.cpp
index f78ec48ebf..e22dd03b59 100644
--- a/LibGUI/GWidget.cpp
+++ b/LibGUI/GWidget.cpp
@@ -5,7 +5,7 @@
#include <LibGUI/GLayout.h>
#include <AK/Assertions.h>
#include <SharedGraphics/GraphicsBitmap.h>
-#include <SharedGraphics/Painter.h>
+#include <LibGUI/GPainter.h>
#include <unistd.h>
@@ -85,13 +85,13 @@ void GWidget::handle_paint_event(GPaintEvent& event)
{
ASSERT(is_visible());
if (fill_with_background_color()) {
- Painter painter(*this);
+ GPainter painter(*this);
painter.fill_rect(event.rect(), background_color());
} else {
#ifdef DEBUG_WIDGET_UNDERDRAW
// FIXME: This is a bit broken.
// If the widget is not opaque, let's not mess it up with debugging color.
- Painter painter(*this);
+ GPainter painter(*this);
painter.fill_rect(rect(), Color::Red);
#endif
}
diff --git a/LibGUI/GWindow.cpp b/LibGUI/GWindow.cpp
index 09e316ed7b..7c8e1461eb 100644
--- a/LibGUI/GWindow.cpp
+++ b/LibGUI/GWindow.cpp
@@ -3,7 +3,7 @@
#include "GEventLoop.h"
#include "GWidget.h"
#include <SharedGraphics/GraphicsBitmap.h>
-#include <SharedGraphics/Painter.h>
+#include <LibGUI/GPainter.h>
#include <LibC/stdio.h>
#include <LibC/stdlib.h>
#include <LibC/unistd.h>
diff --git a/LibGUI/Makefile b/LibGUI/Makefile
index d004387557..aa63cbc48b 100644
--- a/LibGUI/Makefile
+++ b/LibGUI/Makefile
@@ -8,6 +8,7 @@ SHAREDGRAPHICS_OBJS = \
../SharedGraphics/PNGLoader.o
LIBGUI_OBJS = \
+ GPainter.o \
GIODevice.o \
GFile.o \
GButton.o \