diff --git a/Kernel/Makefile b/Kernel/Makefile index 6d35faf34d7..ac6ce72827a 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -55,7 +55,6 @@ WIDGETS_OBJS = \ ../Widgets/Color.o \ ../Widgets/CharacterBitmap.o \ ../Widgets/EventLoop.o \ - ../Widgets/RootWidget.o \ ../Widgets/Label.o \ ../Widgets/Button.o \ ../Widgets/MsgBox.o \ diff --git a/Kernel/WindowComposer.cpp b/Kernel/WindowComposer.cpp index 7a883d6dc9f..683a8418d1a 100644 --- a/Kernel/WindowComposer.cpp +++ b/Kernel/WindowComposer.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -26,11 +25,8 @@ void WindowComposer_main() dbgprintf("Screen is %ux%ux%ubpp\n", info.width, info.height, info.bpp); FrameBuffer framebuffer((dword*)info.framebuffer, info.width, info.height); - RootWidget rw; EventLoop loop; - WindowManager::the().setRootWidget(&rw); - MsgBox(nullptr, "Serenity Operating System"); { diff --git a/Widgets/Makefile b/Widgets/Makefile index 2b380f7d90c..ec3533fc089 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 9c07df11482..2c4ee416864 100644 --- a/Widgets/Painter.cpp +++ b/Widgets/Painter.cpp @@ -6,9 +6,15 @@ #include #include +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 9a26cb0811e..155f05f8a7b 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 15db5754d0b..00000000000 --- 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 30dfbe91f46..00000000000 --- 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 m_backing; -}; diff --git a/Widgets/WindowManager.cpp b/Widgets/WindowManager.cpp index 90e8fa2a0bd..56d26b5b77e 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()); -} - void WindowManager::setActiveWindow(Window* window) { if (window == m_activeWindow.ptr()) diff --git a/Widgets/WindowManager.h b/Widgets/WindowManager.h index 9592c66cc41..d79e01ecb64 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 m_windows; InlineLinkedList m_windows_in_order; - Widget* m_rootWidget { nullptr }; WeakPtr m_activeWindow; @@ -76,5 +73,7 @@ private: unsigned m_recompose_count { 0 }; + RetainPtr m_root_bitmap; + Vector m_invalidated_rects; }; diff --git a/Widgets/test.cpp b/Widgets/test.cpp index 2ba6192f90e..762b8191e0a 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 });