diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-01-12 03:42:50 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-01-12 03:42:50 +0100 |
commit | bb28c315311da4e3e5224505c79ba41297813004 (patch) | |
tree | dee3b3edefe5a5277f0b908f039b496421f46566 /Widgets | |
parent | 0e6c19ffa6901fd570cdfb5302f6e28f3c1366d3 (diff) | |
download | serenity-bb28c315311da4e3e5224505c79ba41297813004.zip |
Get rid of the "root widget" concept in WindowManager.
Instead just create a GraphicsBitmap wrapper around the display framebuffer
and teach Painter how to draw directly into a GraphicsBitmap.
Diffstat (limited to 'Widgets')
-rw-r--r-- | Widgets/Makefile | 1 | ||||
-rw-r--r-- | Widgets/Painter.cpp | 11 | ||||
-rw-r--r-- | Widgets/Painter.h | 2 | ||||
-rw-r--r-- | Widgets/RootWidget.cpp | 29 | ||||
-rw-r--r-- | Widgets/RootWidget.h | 19 | ||||
-rw-r--r-- | Widgets/WindowManager.cpp | 20 | ||||
-rw-r--r-- | Widgets/WindowManager.h | 7 | ||||
-rw-r--r-- | Widgets/test.cpp | 4 |
8 files changed, 18 insertions, 75 deletions
diff --git a/Widgets/Makefile b/Widgets/Makefile index 2b380f7d90..ec3533fc08 100644 --- a/Widgets/Makefile +++ b/Widgets/Makefile @@ -13,7 +13,6 @@ VFS_OBJS = \ Rect.o \ Object.o \ Widget.o \ - RootWidget.o \ Color.o \ Painter.o \ Label.o \ diff --git a/Widgets/Painter.cpp b/Widgets/Painter.cpp index 9c07df1148..2c4ee41686 100644 --- a/Widgets/Painter.cpp +++ b/Widgets/Painter.cpp @@ -6,9 +6,15 @@ #include <AK/Assertions.h> #include <AK/StdLibExtras.h> +Painter::Painter(GraphicsBitmap& bitmap) +{ + m_font = &Font::defaultFont(); + m_target = &bitmap; + m_clipRect = { { 0, 0 }, bitmap.size() }; +} + Painter::Painter(Widget& widget) - : m_widget(widget) - , m_font(&widget.font()) + : m_font(&widget.font()) { m_target = widget.backing(); ASSERT(m_target); @@ -102,7 +108,6 @@ void Painter::drawText(const Rect& rect, const String& text, TextAlignment align if (alignment == TextAlignment::TopLeft) { point = rect.location(); } else if (alignment == TextAlignment::CenterLeft) { - int textWidth = text.length() * font().glyphWidth(); point = { rect.x(), rect.center().y() - (font().glyphHeight() / 2) }; } else if (alignment == TextAlignment::Center) { int textWidth = text.length() * font().glyphWidth(); diff --git a/Widgets/Painter.h b/Widgets/Painter.h index 9a26cb0811..155f05f8a7 100644 --- a/Widgets/Painter.h +++ b/Widgets/Painter.h @@ -16,6 +16,7 @@ class Painter { public: enum class TextAlignment { TopLeft, CenterLeft, Center }; explicit Painter(Widget&); + explicit Painter(GraphicsBitmap&); ~Painter(); void fillRect(const Rect&, Color); void drawRect(const Rect&, Color); @@ -37,7 +38,6 @@ public: private: void set_pixel_with_draw_op(dword& pixel, const Color&); - Widget& m_widget; const Font* m_font; Point m_translation; Rect m_clipRect; diff --git a/Widgets/RootWidget.cpp b/Widgets/RootWidget.cpp deleted file mode 100644 index 15db5754d0..0000000000 --- a/Widgets/RootWidget.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "AbstractScreen.h" -#include "GraphicsBitmap.h" -#include "RootWidget.h" -#include "Painter.h" -#include "WindowManager.h" -#include "FrameBuffer.h" - -RootWidget::RootWidget() -{ - setWindowRelativeRect(FrameBuffer::the().rect()); - m_backing = GraphicsBitmap::create_wrapper(size(), FrameBuffer::the().scanline(0)); -} - -RootWidget::~RootWidget() -{ -} - -void RootWidget::paintEvent(PaintEvent& event) -{ - Painter painter(*this); - painter.fillRect(event.rect(), Color(0, 72, 96)); -} - -void RootWidget::mouseMoveEvent(MouseEvent& event) -{ - //printf("RootWidget::mouseMoveEvent: x=%d, y=%d\n", event.x(), event.y()); - Widget::mouseMoveEvent(event); -} - diff --git a/Widgets/RootWidget.h b/Widgets/RootWidget.h deleted file mode 100644 index 30dfbe91f4..0000000000 --- a/Widgets/RootWidget.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "Widget.h" - -class GraphicsBitmap; - -class RootWidget final : public Widget { -public: - RootWidget(); - virtual ~RootWidget() override; - -private: - virtual void paintEvent(PaintEvent&) override; - virtual void mouseMoveEvent(MouseEvent&) override; - - virtual GraphicsBitmap* backing() override { return m_backing.ptr(); } - - RetainPtr<GraphicsBitmap> m_backing; -}; diff --git a/Widgets/WindowManager.cpp b/Widgets/WindowManager.cpp index 90e8fa2a0b..56d26b5b77 100644 --- a/Widgets/WindowManager.cpp +++ b/Widgets/WindowManager.cpp @@ -63,6 +63,8 @@ void WindowManager::initialize() WindowManager::WindowManager() { + m_root_bitmap = GraphicsBitmap::create_wrapper(FrameBuffer::the().rect().size(), FrameBuffer::the().scanline(0)); + m_activeWindowBorderColor = Color(0, 64, 192); m_activeWindowTitleColor = Color::White; @@ -78,7 +80,7 @@ WindowManager::~WindowManager() void WindowManager::paintWindowFrame(Window& window) { - Painter p(*m_rootWidget); + Painter p(*m_root_bitmap); //printf("[WM] paintWindowFrame {%p}, rect: %d,%d %dx%d\n", &window, window.rect().x(), window.rect().y(), window.rect().width(), window.rect().height()); @@ -253,12 +255,12 @@ void WindowManager::compose() return false; }; { + Painter p(*m_root_bitmap); for (auto& r : m_invalidated_rects) { if (any_window_contains_rect(r)) continue; dbgprintf("Repaint root %d,%d %dx%d\n", r.x(), r.y(), r.width(), r.height()); - PaintEvent event(r); - m_rootWidget->paintEvent(event); + p.fillRect(r, Color(0, 72, 96)); } } auto& framebuffer = FrameBuffer::the(); @@ -279,7 +281,7 @@ void WindowManager::compose() void WindowManager::redraw_cursor() { auto cursor_location = AbstractScreen::the().cursor_location(); - Painter painter(*m_rootWidget); + Painter painter(*m_root_bitmap); painter.set_draw_op(Painter::DrawOp::Xor); auto draw_cross = [&painter] (const Point& p) { painter.drawLine({ p.x() - 10, p.y() }, { p.x() + 10, p.y() }, Color::Red); @@ -307,16 +309,6 @@ void WindowManager::event(Event& event) return Object::event(event); } -void WindowManager::setRootWidget(Widget* widget) -{ - // FIXME: Should we support switching root widgets? - ASSERT(!m_rootWidget); - ASSERT(widget); - - m_rootWidget = widget; - EventLoop::main().postEvent(m_rootWidget, make<ShowEvent>()); -} - void WindowManager::setActiveWindow(Window* window) { if (window == m_activeWindow.ptr()) diff --git a/Widgets/WindowManager.h b/Widgets/WindowManager.h index 9592c66cc4..d79e01ecb6 100644 --- a/Widgets/WindowManager.h +++ b/Widgets/WindowManager.h @@ -11,6 +11,7 @@ class MouseEvent; class PaintEvent; class Widget; class Window; +class GraphicsBitmap; class WindowManager : public Object { public: @@ -21,9 +22,6 @@ public: void notifyTitleChanged(Window&); void notifyRectChanged(Window&, const Rect& oldRect, const Rect& newRect); - Widget* rootWidget() { return m_rootWidget; } - void setRootWidget(Widget*); - Window* activeWindow() { return m_activeWindow.ptr(); } void setActiveWindow(Window*); @@ -60,7 +58,6 @@ private: void paintWindowFrame(Window&); HashTable<Window*> m_windows; InlineLinkedList<Window> m_windows_in_order; - Widget* m_rootWidget { nullptr }; WeakPtr<Window> m_activeWindow; @@ -76,5 +73,7 @@ private: unsigned m_recompose_count { 0 }; + RetainPtr<GraphicsBitmap> m_root_bitmap; + Vector<Rect> m_invalidated_rects; }; diff --git a/Widgets/test.cpp b/Widgets/test.cpp index 2ba6192f90..762b8191e0 100644 --- a/Widgets/test.cpp +++ b/Widgets/test.cpp @@ -1,6 +1,5 @@ #include "FrameBuffer.h" #include "EventLoop.h" -#include "RootWidget.h" #include "Label.h" #include "Button.h" #include "WindowManager.h" @@ -19,9 +18,6 @@ int main(int argc, char** argv) EventLoop loop; - RootWidget w; - WindowManager::the().setRootWidget(&w); - auto* fontTestWindow = new Window; fontTestWindow->setTitle("Font test"); fontTestWindow->setRect({ 140, 100, 300, 80 }); |