From b91479d9b90e1c6dd33c83d0a2cfc6ba94d1464e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 20 Jan 2019 04:49:48 +0100 Subject: [PATCH] Rename all the LibGUI classes to GClassName. --- LibGUI/.gitignore | 3 +- LibGUI/Button.h | 27 ---- LibGUI/CheckBox.h | 26 ---- LibGUI/ClockWidget.cpp | 6 +- LibGUI/EventLoop.h | 37 ----- LibGUI/{Button.cpp => GButton.cpp} | 20 +-- LibGUI/GButton.h | 27 ++++ LibGUI/{CheckBox.cpp => GCheckBox.cpp} | 18 +-- LibGUI/GCheckBox.h | 26 ++++ LibGUI/{Event.h => GEvent.h} | 69 ++++------ LibGUI/{EventLoop.cpp => GEventLoop.cpp} | 38 +++--- LibGUI/GEventLoop.h | 34 +++++ LibGUI/{Label.cpp => GLabel.cpp} | 18 +-- LibGUI/GLabel.h | 22 +++ LibGUI/{ListBox.cpp => GListBox.cpp} | 21 ++- LibGUI/GListBox.h | 25 ++++ LibGUI/{Object.cpp => GObject.cpp} | 36 ++--- LibGUI/GObject.h | 40 ++++++ LibGUI/{TextBox.cpp => GTextBox.cpp} | 30 ++--- LibGUI/GTextBox.h | 29 ++++ LibGUI/GWidget.cpp | 163 +++++++++++++++++++++++ LibGUI/{Widget.h => GWidget.h} | 46 +++---- LibGUI/GWindow.cpp | 42 ++++++ LibGUI/{Window.h => GWindow.h} | 10 +- LibGUI/Label.h | 22 --- LibGUI/ListBox.h | 25 ---- LibGUI/Makefile | 51 +++++++ LibGUI/Object.h | 40 ------ LibGUI/TextBox.h | 29 ---- LibGUI/Widget.cpp | 163 ----------------------- LibGUI/Window.cpp | 42 ------ SharedGraphics/Painter.cpp | 4 +- SharedGraphics/Painter.h | 15 ++- 33 files changed, 623 insertions(+), 581 deletions(-) delete mode 100644 LibGUI/Button.h delete mode 100644 LibGUI/CheckBox.h delete mode 100644 LibGUI/EventLoop.h rename LibGUI/{Button.cpp => GButton.cpp} (87%) create mode 100644 LibGUI/GButton.h rename LibGUI/{CheckBox.cpp => GCheckBox.cpp} (81%) create mode 100644 LibGUI/GCheckBox.h rename LibGUI/{Event.h => GEvent.h} (62%) rename LibGUI/{EventLoop.cpp => GEventLoop.cpp} (53%) create mode 100644 LibGUI/GEventLoop.h rename LibGUI/{Label.cpp => GLabel.cpp} (56%) create mode 100644 LibGUI/GLabel.h rename LibGUI/{ListBox.cpp => GListBox.cpp} (76%) create mode 100644 LibGUI/GListBox.h rename LibGUI/{Object.cpp => GObject.cpp} (54%) create mode 100644 LibGUI/GObject.h rename LibGUI/{TextBox.cpp => GTextBox.cpp} (85%) create mode 100644 LibGUI/GTextBox.h create mode 100644 LibGUI/GWidget.cpp rename LibGUI/{Widget.h => GWidget.h} (67%) create mode 100644 LibGUI/GWindow.cpp rename LibGUI/{Window.h => GWindow.h} (87%) delete mode 100644 LibGUI/Label.h delete mode 100644 LibGUI/ListBox.h create mode 100644 LibGUI/Makefile delete mode 100644 LibGUI/Object.h delete mode 100644 LibGUI/TextBox.h delete mode 100644 LibGUI/Widget.cpp delete mode 100644 LibGUI/Window.cpp diff --git a/LibGUI/.gitignore b/LibGUI/.gitignore index 677b78a50b..0e4334e117 100644 --- a/LibGUI/.gitignore +++ b/LibGUI/.gitignore @@ -1,3 +1,2 @@ *.o -*.swp -test +LibGUI.a diff --git a/LibGUI/Button.h b/LibGUI/Button.h deleted file mode 100644 index cdbc522ecf..0000000000 --- a/LibGUI/Button.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "Widget.h" -#include -#include - -class Button final : public Widget { -public: - explicit Button(Widget* parent); - virtual ~Button() override; - - String caption() const { return m_caption; } - void setCaption(String&&); - - Function onClick; - -private: - virtual void paintEvent(PaintEvent&) override; - virtual void mouseDownEvent(MouseEvent&) override; - virtual void mouseUpEvent(MouseEvent&) override; - - virtual const char* class_name() const override { return "Button"; } - - String m_caption; - bool m_beingPressed { false }; -}; - diff --git a/LibGUI/CheckBox.h b/LibGUI/CheckBox.h deleted file mode 100644 index 638b5fb629..0000000000 --- a/LibGUI/CheckBox.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "Widget.h" -#include - -class CheckBox final : public Widget { -public: - explicit CheckBox(Widget* parent); - virtual ~CheckBox() override; - - String caption() const { return m_caption; } - void setCaption(String&&); - - bool isChecked() const { return m_isChecked; } - void setIsChecked(bool); - -private: - virtual void paintEvent(PaintEvent&) override; - virtual void mouseDownEvent(MouseEvent&) override; - - virtual const char* class_name() const override { return "CheckBox"; } - - String m_caption; - bool m_isChecked { false }; -}; - diff --git a/LibGUI/ClockWidget.cpp b/LibGUI/ClockWidget.cpp index c1f800bd79..b3c7dee94f 100644 --- a/LibGUI/ClockWidget.cpp +++ b/LibGUI/ClockWidget.cpp @@ -1,9 +1,9 @@ #include "ClockWidget.h" -#include "Painter.h" +#include #include -ClockWidget::ClockWidget(Widget* parent) - : Widget(parent) +ClockWidget::ClockWidget(GWidget* parent) + : GWidget(parent) { setWindowRelativeRect({ 0, 0, 100, 40 }); startTimer(250); diff --git a/LibGUI/EventLoop.h b/LibGUI/EventLoop.h deleted file mode 100644 index 289a6f2f02..0000000000 --- a/LibGUI/EventLoop.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include "Event.h" -#include -#include - -class Object; -class Process; - -class EventLoop { -public: - EventLoop(); - ~EventLoop(); - - int exec(); - - void postEvent(Object* receiver, OwnPtr&&); - - static EventLoop& main(); - - static void initialize(); - - bool running() const { return m_running; } - Process& server_process() { return *m_server_process; } - -private: - void waitForEvent(); - - struct QueuedEvent { - Object* receiver { nullptr }; - OwnPtr event; - }; - Vector m_queuedEvents; - - Process* m_server_process { nullptr }; - bool m_running { false }; -}; diff --git a/LibGUI/Button.cpp b/LibGUI/GButton.cpp similarity index 87% rename from LibGUI/Button.cpp rename to LibGUI/GButton.cpp index ef3a15e959..bc5511019e 100644 --- a/LibGUI/Button.cpp +++ b/LibGUI/GButton.cpp @@ -1,17 +1,17 @@ -#include "Button.h" +#include "GButton.h" #include -Button::Button(Widget* parent) - : Widget(parent) +GButton::GButton(GWidget* parent) + : GWidget(parent) { setFillWithBackgroundColor(false); } -Button::~Button() +GButton::~GButton() { } -void Button::setCaption(String&& caption) +void GButton::setCaption(String&& caption) { if (caption == m_caption) return; @@ -19,7 +19,7 @@ void Button::setCaption(String&& caption) update(); } -void Button::paintEvent(PaintEvent&) +void GButton::paintEvent(GPaintEvent&) { Color buttonColor = Color::LightGray; Color highlightColor = Color::White; @@ -64,24 +64,24 @@ void Button::paintEvent(PaintEvent&) } } -void Button::mouseDownEvent(MouseEvent& event) +void GButton::mouseDownEvent(GMouseEvent& event) { dbgprintf("Button::mouseDownEvent: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button()); m_beingPressed = true; update(); - Widget::mouseDownEvent(event); + GWidget::mouseDownEvent(event); } -void Button::mouseUpEvent(MouseEvent& event) +void GButton::mouseUpEvent(GMouseEvent& event) { dbgprintf("Button::mouseUpEvent: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button()); m_beingPressed = false; update(); - Widget::mouseUpEvent(event); + GWidget::mouseUpEvent(event); if (onClick) onClick(*this); diff --git a/LibGUI/GButton.h b/LibGUI/GButton.h new file mode 100644 index 0000000000..0bceef727e --- /dev/null +++ b/LibGUI/GButton.h @@ -0,0 +1,27 @@ +#pragma once + +#include "GWidget.h" +#include +#include + +class GButton final : public GWidget { +public: + explicit GButton(GWidget* parent); + virtual ~GButton() override; + + String caption() const { return m_caption; } + void setCaption(String&&); + + Function onClick; + +private: + virtual void paintEvent(GPaintEvent&) override; + virtual void mouseDownEvent(GMouseEvent&) override; + virtual void mouseUpEvent(GMouseEvent&) override; + + virtual const char* class_name() const override { return "Button"; } + + String m_caption; + bool m_beingPressed { false }; +}; + diff --git a/LibGUI/CheckBox.cpp b/LibGUI/GCheckBox.cpp similarity index 81% rename from LibGUI/CheckBox.cpp rename to LibGUI/GCheckBox.cpp index 2871ce2a15..e2834cb29e 100644 --- a/LibGUI/CheckBox.cpp +++ b/LibGUI/GCheckBox.cpp @@ -1,17 +1,17 @@ -#include "CheckBox.h" +#include "GCheckBox.h" #include #include -CheckBox::CheckBox(Widget* parent) - : Widget(parent) +GCheckBox::GCheckBox(GWidget* parent) + : GWidget(parent) { } -CheckBox::~CheckBox() +GCheckBox::~GCheckBox() { } -void CheckBox::setCaption(String&& caption) +void GCheckBox::setCaption(String&& caption) { if (caption == m_caption) return; @@ -19,7 +19,7 @@ void CheckBox::setCaption(String&& caption) update(); } -void CheckBox::setIsChecked(bool b) +void GCheckBox::setIsChecked(bool b) { if (m_isChecked == b) return; @@ -72,7 +72,7 @@ static const char* checkedBitmap = { "###########" }; -void CheckBox::paintEvent(PaintEvent&) +void GCheckBox::paintEvent(GPaintEvent&) { Painter painter(*this); auto bitmap = CharacterBitmap::create_from_ascii(isChecked() ? checkedBitmap : uncheckedBitmap, 11, 11); @@ -93,9 +93,9 @@ void CheckBox::paintEvent(PaintEvent&) } } -void CheckBox::mouseDownEvent(MouseEvent& event) +void GCheckBox::mouseDownEvent(GMouseEvent& event) { - dbgprintf("CheckBox::mouseDownEvent: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button()); + dbgprintf("GCheckBox::mouseDownEvent: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button()); setIsChecked(!isChecked()); } diff --git a/LibGUI/GCheckBox.h b/LibGUI/GCheckBox.h new file mode 100644 index 0000000000..1d0c071443 --- /dev/null +++ b/LibGUI/GCheckBox.h @@ -0,0 +1,26 @@ +#pragma once + +#include "GWidget.h" +#include + +class GCheckBox final : public GWidget { +public: + explicit GCheckBox(GWidget* parent); + virtual ~GCheckBox() override; + + String caption() const { return m_caption; } + void setCaption(String&&); + + bool isChecked() const { return m_isChecked; } + void setIsChecked(bool); + +private: + virtual void paintEvent(GPaintEvent&) override; + virtual void mouseDownEvent(GMouseEvent&) override; + + virtual const char* class_name() const override { return "GCheckBox"; } + + String m_caption; + bool m_isChecked { false }; +}; + diff --git a/LibGUI/Event.h b/LibGUI/GEvent.h similarity index 62% rename from LibGUI/Event.h rename to LibGUI/GEvent.h index 4fffb5c16c..9aded85a72 100644 --- a/LibGUI/Event.h +++ b/LibGUI/GEvent.h @@ -20,7 +20,7 @@ static const char* eventNames[] = { "DeferredDestroy", }; -class Event { +class GEvent { public: enum Type { Invalid = 0, @@ -37,12 +37,11 @@ public: DeferredDestroy, WindowBecameInactive, WindowBecameActive, - WM_Compose, }; - Event() { } - explicit Event(Type type) : m_type(type) { } - virtual ~Event() { } + GEvent() { } + explicit GEvent(Type type) : m_type(type) { } + virtual ~GEvent() { } Type type() const { return m_type; } @@ -56,60 +55,51 @@ private: Type m_type { Invalid }; }; -class DeferredDestroyEvent final : public Event { -public: - DeferredDestroyEvent() - : Event(Event::DeferredDestroy) - { - } -}; - -class QuitEvent final : public Event { +class QuitEvent final : public GEvent { public: QuitEvent() - : Event(Event::Quit) + : GEvent(GEvent::Quit) { } }; -class PaintEvent final : public Event { +class GPaintEvent final : public GEvent { public: - explicit PaintEvent(const Rect& rect = Rect()) - : Event(Event::Paint) + explicit GPaintEvent(const Rect& rect = Rect()) + : GEvent(GEvent::Paint) , m_rect(rect) { } const Rect& rect() const { return m_rect; } private: - friend class WindowManager; Rect m_rect; }; -class ShowEvent final : public Event { +class GShowEvent final : public GEvent { public: - ShowEvent() - : Event(Event::Show) + GShowEvent() + : GEvent(GEvent::Show) { } }; -class HideEvent final : public Event { +class GHideEvent final : public GEvent { public: - HideEvent() - : Event(Event::Hide) + GHideEvent() + : GEvent(GEvent::Hide) { } }; -enum class MouseButton : byte { +enum class GMouseButton : byte { None = 0, Left, Middle, Right, }; -enum KeyboardKey { +enum GKeyboardKey { Invalid, LeftArrow, RightArrow, @@ -119,10 +109,10 @@ enum KeyboardKey { Return, }; -class KeyEvent final : public Event { +class GKeyEvent final : public GEvent { public: - KeyEvent(Type type, int key) - : Event(type) + GKeyEvent(Type type, int key) + : GEvent(type) , m_key(key) { } @@ -134,8 +124,7 @@ public: String text() const { return m_text; } private: - friend class EventLoop; - friend class AbstractScreen; + friend class GEventLoop; int m_key { 0 }; bool m_ctrl { false }; bool m_alt { false }; @@ -143,10 +132,10 @@ private: String m_text; }; -class MouseEvent final : public Event { +class GMouseEvent final : public GEvent { public: - MouseEvent(Type type, int x, int y, MouseButton button = MouseButton::None) - : Event(type) + GMouseEvent(Type type, int x, int y, GMouseButton button = GMouseButton::None) + : GEvent(type) , m_position(x, y) , m_button(button) { @@ -155,16 +144,16 @@ public: Point position() const { return m_position; } int x() const { return m_position.x(); } int y() const { return m_position.y(); } - MouseButton button() const { return m_button; } + GMouseButton button() const { return m_button; } private: Point m_position; - MouseButton m_button { MouseButton::None }; + GMouseButton m_button { GMouseButton::None }; }; -class TimerEvent final : public Event { +class GTimerEvent final : public GEvent { public: - TimerEvent() : Event(Event::Timer) { } - ~TimerEvent() { } + GTimerEvent() : GEvent(GEvent::Timer) { } + ~GTimerEvent() { } }; diff --git a/LibGUI/EventLoop.cpp b/LibGUI/GEventLoop.cpp similarity index 53% rename from LibGUI/EventLoop.cpp rename to LibGUI/GEventLoop.cpp index c3553d9f19..3a787f4f5c 100644 --- a/LibGUI/EventLoop.cpp +++ b/LibGUI/GEventLoop.cpp @@ -1,31 +1,31 @@ -#include "EventLoop.h" -#include "Event.h" -#include "Object.h" +#include "GEventLoop.h" +#include "GEvent.h" +#include "GObject.h" -static EventLoop* s_mainEventLoop; +static GEventLoop* s_mainGEventLoop; -void EventLoop::initialize() +void GEventLoop::initialize() { - s_mainEventLoop = nullptr; + s_mainGEventLoop = nullptr; } -EventLoop::EventLoop() +GEventLoop::GEventLoop() { - if (!s_mainEventLoop) - s_mainEventLoop = this; + if (!s_mainGEventLoop) + s_mainGEventLoop = this; } -EventLoop::~EventLoop() +GEventLoop::~GEventLoop() { } -EventLoop& EventLoop::main() +GEventLoop& GEventLoop::main() { - ASSERT(s_mainEventLoop); - return *s_mainEventLoop; + ASSERT(s_mainGEventLoop); + return *s_mainGEventLoop; } -int EventLoop::exec() +int GEventLoop::exec() { m_running = true; for (;;) { @@ -38,10 +38,10 @@ int EventLoop::exec() for (auto& queuedEvent : events) { auto* receiver = queuedEvent.receiver; auto& event = *queuedEvent.event; - //printf("EventLoop: Object{%p} event %u (%s)\n", receiver, (unsigned)event.type(), event.name()); + //printf("GEventLoop: GObject{%p} event %u (%s)\n", receiver, (unsigned)event.type(), event.name()); if (!receiver) { switch (event.type()) { - case Event::Quit: + case GEvent::Quit: ASSERT_NOT_REACHED(); return 0; default: @@ -56,12 +56,12 @@ int EventLoop::exec() } } -void EventLoop::postEvent(Object* receiver, OwnPtr&& event) +void GEventLoop::postEvent(GObject* receiver, OwnPtr&& event) { - //printf("EventLoop::postEvent: {%u} << receiver=%p, event=%p\n", m_queuedEvents.size(), receiver, event.ptr()); + //printf("GEventLoop::postGEvent: {%u} << receiver=%p, event=%p\n", m_queuedEvents.size(), receiver, event.ptr()); m_queuedEvents.append({ receiver, move(event) }); } -void EventLoop::waitForEvent() +void GEventLoop::waitForEvent() { } diff --git a/LibGUI/GEventLoop.h b/LibGUI/GEventLoop.h new file mode 100644 index 0000000000..9d28634ecd --- /dev/null +++ b/LibGUI/GEventLoop.h @@ -0,0 +1,34 @@ +#pragma once + +#include "GEvent.h" +#include +#include + +class GObject; + +class GEventLoop { +public: + GEventLoop(); + ~GEventLoop(); + + int exec(); + + void postEvent(GObject* receiver, OwnPtr&&); + + static GEventLoop& main(); + + static void initialize(); + + bool running() const { return m_running; } + +private: + void waitForEvent(); + + struct QueuedEvent { + GObject* receiver { nullptr }; + OwnPtr event; + }; + Vector m_queuedEvents; + + bool m_running { false }; +}; diff --git a/LibGUI/Label.cpp b/LibGUI/GLabel.cpp similarity index 56% rename from LibGUI/Label.cpp rename to LibGUI/GLabel.cpp index b187a08bd1..a953ffda58 100644 --- a/LibGUI/Label.cpp +++ b/LibGUI/GLabel.cpp @@ -1,16 +1,16 @@ -#include "Label.h" +#include "GLabel.h" #include -Label::Label(Widget* parent) - : Widget(parent) +GLabel::GLabel(GWidget* parent) + : GWidget(parent) { } -Label::~Label() +GLabel::~GLabel() { } -void Label::setText(String&& text) +void GLabel::setText(String&& text) { if (text == m_text) return; @@ -18,7 +18,7 @@ void Label::setText(String&& text) update(); } -void Label::paintEvent(PaintEvent&) +void GLabel::paintEvent(GPaintEvent&) { Painter painter(*this); if (fillWithBackgroundColor()) @@ -27,9 +27,9 @@ void Label::paintEvent(PaintEvent&) painter.draw_text({ 4, 4, width(), height() }, text(), Painter::TextAlignment::TopLeft, foregroundColor()); } -void Label::mouseMoveEvent(MouseEvent& event) +void GLabel::mouseMoveEvent(GMouseEvent& event) { - dbgprintf("Label::mouseMoveEvent: x=%d, y=%d\n", event.x(), event.y()); - Widget::mouseMoveEvent(event); + dbgprintf("GLabel::mouseMoveEvent: x=%d, y=%d\n", event.x(), event.y()); + GWidget::mouseMoveEvent(event); } diff --git a/LibGUI/GLabel.h b/LibGUI/GLabel.h new file mode 100644 index 0000000000..fe71b7655f --- /dev/null +++ b/LibGUI/GLabel.h @@ -0,0 +1,22 @@ +#pragma once + +#include "GWidget.h" +#include + +class GLabel final : public GWidget { +public: + explicit GLabel(GWidget* parent); + virtual ~GLabel() override; + + String text() const { return m_text; } + void setText(String&&); + +private: + virtual void paintEvent(GPaintEvent&) override; + virtual void mouseMoveEvent(GMouseEvent&) override; + + virtual const char* class_name() const override { return "GLabel"; } + + String m_text; +}; + diff --git a/LibGUI/ListBox.cpp b/LibGUI/GListBox.cpp similarity index 76% rename from LibGUI/ListBox.cpp rename to LibGUI/GListBox.cpp index 400a36b596..bc7027f8cf 100644 --- a/LibGUI/ListBox.cpp +++ b/LibGUI/GListBox.cpp @@ -1,24 +1,23 @@ -#include "ListBox.h" -#include "Window.h" +#include "GListBox.h" #include #include -ListBox::ListBox(Widget* parent) - : Widget(parent) +GListBox::GListBox(GWidget* parent) + : GWidget(parent) { } -ListBox::~ListBox() +GListBox::~GListBox() { } -Rect ListBox::item_rect(int index) const +Rect GListBox::item_rect(int index) const { int item_height = font().glyph_height() + 2; return Rect { 2, 2 + (index * item_height), width() - 4, item_height }; } -void ListBox::paintEvent(PaintEvent&) +void GListBox::paintEvent(GPaintEvent&) { Painter painter(*this); @@ -45,21 +44,21 @@ void ListBox::paintEvent(PaintEvent&) } } -void ListBox::mouseDownEvent(MouseEvent& event) +void GListBox::mouseDownEvent(GMouseEvent& event) { - dbgprintf("ListBox::mouseDownEvent %d,%d\n", event.x(), event.y()); + dbgprintf("GListBox::mouseDownEvent %d,%d\n", event.x(), event.y()); for (int i = m_scrollOffset; i < static_cast(m_items.size()); ++i) { auto itemRect = item_rect(i); if (itemRect.contains(event.position())) { m_selectedIndex = i; - dbgprintf("ListBox: selected item %u (\"%s\")\n", i, m_items[i].characters()); + dbgprintf("GListBox: selected item %u (\"%s\")\n", i, m_items[i].characters()); update(); return; } } } -void ListBox::addItem(String&& item) +void GListBox::addItem(String&& item) { m_items.append(move(item)); if (m_selectedIndex == -1) diff --git a/LibGUI/GListBox.h b/LibGUI/GListBox.h new file mode 100644 index 0000000000..12750b7ddd --- /dev/null +++ b/LibGUI/GListBox.h @@ -0,0 +1,25 @@ +#pragma once + +#include "GWidget.h" + +class GListBox final : public GWidget { +public: + explicit GListBox(GWidget* parent); + virtual ~GListBox() override; + + void addItem(String&&); + int selectedIndex() const { return m_selectedIndex; } + +private: + virtual void paintEvent(GPaintEvent&) override; + virtual void mouseDownEvent(GMouseEvent&) override; + virtual const char* class_name() const override { return "GListBox"; } + + Rect item_rect(int index) const; + + int m_scrollOffset { 0 }; + int m_selectedIndex { -1 }; + + Vector m_items; +}; + diff --git a/LibGUI/Object.cpp b/LibGUI/GObject.cpp similarity index 54% rename from LibGUI/Object.cpp rename to LibGUI/GObject.cpp index 8511d4bced..5b5ca3acec 100644 --- a/LibGUI/Object.cpp +++ b/LibGUI/GObject.cpp @@ -1,16 +1,16 @@ -#include "Object.h" -#include "Event.h" -#include "EventLoop.h" +#include "GObject.h" +#include "GEvent.h" +#include "GEventLoop.h" #include -Object::Object(Object* parent) +GObject::GObject(GObject* parent) : m_parent(parent) { if (m_parent) m_parent->addChild(*this); } -Object::~Object() +GObject::~GObject() { if (m_parent) m_parent->removeChild(*this); @@ -19,15 +19,15 @@ Object::~Object() delete child; } -void Object::event(Event& event) +void GObject::event(GEvent& event) { switch (event.type()) { - case Event::Timer: - return timerEvent(static_cast(event)); - case Event::DeferredDestroy: + case GEvent::Timer: + return timerEvent(static_cast(event)); + case GEvent::DeferredDestroy: delete this; break; - case Event::Invalid: + case GEvent::Invalid: ASSERT_NOT_REACHED(); break; default: @@ -35,12 +35,12 @@ void Object::event(Event& event) } } -void Object::addChild(Object& object) +void GObject::addChild(GObject& object) { m_children.append(&object); } -void Object::removeChild(Object& object) +void GObject::removeChild(GObject& object) { for (unsigned i = 0; i < m_children.size(); ++i) { if (m_children[i] == &object) { @@ -50,27 +50,27 @@ void Object::removeChild(Object& object) } } -void Object::timerEvent(TimerEvent&) +void GObject::timerEvent(GTimerEvent&) { } -void Object::startTimer(int ms) +void GObject::startTimer(int ms) { if (m_timerID) { - dbgprintf("Object{%p} already has a timer!\n", this); + dbgprintf("GObject{%p} already has a timer!\n", this); ASSERT_NOT_REACHED(); } } -void Object::stopTimer() +void GObject::stopTimer() { if (!m_timerID) return; m_timerID = 0; } -void Object::deleteLater() +void GObject::deleteLater() { - EventLoop::main().postEvent(this, make()); + GEventLoop::main().postEvent(this, make(GEvent::DeferredDestroy)); } diff --git a/LibGUI/GObject.h b/LibGUI/GObject.h new file mode 100644 index 0000000000..48870defcc --- /dev/null +++ b/LibGUI/GObject.h @@ -0,0 +1,40 @@ +#pragma once + +#include +#include + +class GEvent; +class GTimerEvent; + +class GObject : public Weakable { +public: + GObject(GObject* parent = nullptr); + virtual ~GObject(); + + virtual const char* class_name() const { return "GObject"; } + + virtual void event(GEvent&); + + Vector& children() { return m_children; } + + GObject* parent() { return m_parent; } + const GObject* parent() const { return m_parent; } + + void startTimer(int ms); + void stopTimer(); + bool hasTimer() const { return m_timerID; } + + void addChild(GObject&); + void removeChild(GObject&); + + void deleteLater(); + +private: + virtual void timerEvent(GTimerEvent&); + + GObject* m_parent { nullptr }; + + int m_timerID { 0 }; + + Vector m_children; +}; diff --git a/LibGUI/TextBox.cpp b/LibGUI/GTextBox.cpp similarity index 85% rename from LibGUI/TextBox.cpp rename to LibGUI/GTextBox.cpp index cfa6cf2a1c..7319bab0af 100644 --- a/LibGUI/TextBox.cpp +++ b/LibGUI/GTextBox.cpp @@ -1,27 +1,27 @@ -#include "TextBox.h" +#include "GTextBox.h" #include #include #include #include -TextBox::TextBox(Widget* parent) - : Widget(parent) +GTextBox::GTextBox(GWidget* parent) + : GWidget(parent) { startTimer(500); } -TextBox::~TextBox() +GTextBox::~GTextBox() { } -void TextBox::setText(String&& text) +void GTextBox::setText(String&& text) { m_text = move(text); m_cursorPosition = m_text.length(); update(); } -void TextBox::paintEvent(PaintEvent&) +void GTextBox::paintEvent(GPaintEvent&) { Painter painter(*this); @@ -48,7 +48,7 @@ void TextBox::paintEvent(PaintEvent&) int x = innerRect.x() + (i * font().glyph_width()); auto* bitmap = font().glyph_bitmap(ch); if (!bitmap) { - dbgprintf("TextBox: glyph missing: %02x\n", ch); + dbgprintf("GTextBox: glyph missing: %02x\n", ch); ASSERT_NOT_REACHED(); } painter.draw_bitmap({x, y}, *bitmap, Color::Black); @@ -61,11 +61,11 @@ void TextBox::paintEvent(PaintEvent&) } } -void TextBox::mouseDownEvent(MouseEvent&) +void GTextBox::mouseDownEvent(GMouseEvent&) { } -void TextBox::handleBackspace() +void GTextBox::handleBackspace() { if (m_cursorPosition == 0) return; @@ -88,24 +88,24 @@ void TextBox::handleBackspace() update(); } -void TextBox::keyDownEvent(KeyEvent& event) +void GTextBox::keyDownEvent(GKeyEvent& event) { switch (event.key()) { - case KeyboardKey::LeftArrow: + case GKeyboardKey::LeftArrow: if (m_cursorPosition) --m_cursorPosition; m_cursorBlinkState = true; update(); return; - case KeyboardKey::RightArrow: + case GKeyboardKey::RightArrow: if (m_cursorPosition < m_text.length()) ++m_cursorPosition; m_cursorBlinkState = true; update(); return; - case KeyboardKey::Backspace: + case GKeyboardKey::Backspace: return handleBackspace(); - case KeyboardKey::Return: + case GKeyboardKey::Return: if (onReturnPressed) onReturnPressed(*this); return; @@ -128,7 +128,7 @@ void TextBox::keyDownEvent(KeyEvent& event) } } -void TextBox::timerEvent(TimerEvent&) +void GTextBox::timerEvent(GTimerEvent&) { // FIXME: Disable the timer when not focused. if (!isFocused()) diff --git a/LibGUI/GTextBox.h b/LibGUI/GTextBox.h new file mode 100644 index 0000000000..779d3b9734 --- /dev/null +++ b/LibGUI/GTextBox.h @@ -0,0 +1,29 @@ +#pragma once + +#include "GWidget.h" +#include + +class GTextBox final : public GWidget { +public: + explicit GTextBox(GWidget* parent); + virtual ~GTextBox() override; + + String text() const { return m_text; } + void setText(String&&); + + Function onReturnPressed; + +private: + virtual const char* class_name() const override { return "GTextBox"; } + virtual void paintEvent(GPaintEvent&) override; + virtual void mouseDownEvent(GMouseEvent&) override; + virtual void keyDownEvent(GKeyEvent&) override; + virtual void timerEvent(GTimerEvent&) override; + + void handleBackspace(); + + String m_text; + unsigned m_cursorPosition { 0 }; + bool m_cursorBlinkState { false }; +}; + diff --git a/LibGUI/GWidget.cpp b/LibGUI/GWidget.cpp new file mode 100644 index 0000000000..08150f7fc0 --- /dev/null +++ b/LibGUI/GWidget.cpp @@ -0,0 +1,163 @@ +#include "GWidget.h" +#include "GEvent.h" +#include "GEventLoop.h" +#include "GWindow.h" +#include +#include +#include + +GWidget::GWidget(GWidget* parent) + : GObject(parent) +{ + setFont(nullptr); + m_backgroundColor = Color::White; + m_foregroundColor = Color::Black; +} + +GWidget::~GWidget() +{ +} + +void GWidget::setWindowRelativeRect(const Rect& rect, bool should_update) +{ + // FIXME: Make some kind of event loop driven ResizeEvent? + m_relativeRect = rect; + if (should_update) + update(); +} + +void GWidget::repaint(const Rect& rect) +{ + // FIXME: Implement. +} + +void GWidget::event(GEvent& event) +{ + switch (event.type()) { + case GEvent::Paint: + m_hasPendingPaintEvent = false; + if (auto* win = window()) { + if (win->is_being_dragged()) + return; + if (!win->is_visible()) + return; + } + return paintEvent(static_cast(event)); + case GEvent::Show: + return showEvent(static_cast(event)); + case GEvent::Hide: + return hideEvent(static_cast(event)); + case GEvent::KeyDown: + return keyDownEvent(static_cast(event)); + case GEvent::KeyUp: + return keyUpEvent(static_cast(event)); + case GEvent::MouseMove: + return mouseMoveEvent(static_cast(event)); + case GEvent::MouseDown: + // FIXME: Focus self if needed. + return mouseDownEvent(static_cast(event)); + case GEvent::MouseUp: + return mouseUpEvent(static_cast(event)); + default: + return GObject::event(event); + } +} + +void GWidget::paintEvent(GPaintEvent& event) +{ + //printf("GWidget::paintEvent :)\n"); + if (fillWithBackgroundColor()) { + Painter painter(*this); + painter.fill_rect(rect(), backgroundColor()); + } + for (auto* ch : children()) { + auto* child = (GWidget*)ch; + child->event(event); + } +} + +void GWidget::showEvent(GShowEvent&) +{ +} + +void GWidget::hideEvent(GHideEvent&) +{ +} + +void GWidget::keyDownEvent(GKeyEvent&) +{ +} + +void GWidget::keyUpEvent(GKeyEvent&) +{ +} + +void GWidget::mouseDownEvent(GMouseEvent&) +{ +} + +void GWidget::mouseUpEvent(GMouseEvent&) +{ +} + +void GWidget::mouseMoveEvent(GMouseEvent&) +{ +} + +void GWidget::update() +{ + auto* w = window(); + if (!w) + return; + if (m_hasPendingPaintEvent) + return; + m_hasPendingPaintEvent = true; + GEventLoop::main().postEvent(w, make(relativeRect())); +} + +GWidget::HitTestResult GWidget::hitTest(int x, int y) +{ + // FIXME: Care about z-order. + for (auto* ch : children()) { + auto* child = (GWidget*)ch; + if (child->relativeRect().contains(x, y)) { + return child->hitTest(x - child->relativeRect().x(), y - child->relativeRect().y()); + } + } + return { this, x, y }; +} + +void GWidget::setWindow(GWindow* window) +{ + if (m_window == window) + return; + m_window = window; +} + +bool GWidget::isFocused() const +{ + // FIXME: Implement. + return false; +} + +void GWidget::setFocus(bool focus) +{ + if (focus == isFocused()) + return; + // FIXME: Implement. +} + +void GWidget::setFont(RetainPtr&& font) +{ + if (!font) + m_font = Font::default_font(); + else + m_font = move(font); +} + +GraphicsBitmap* GWidget::backing() +{ + if (auto* w = window()) + return w->backing(); + return nullptr; +} diff --git a/LibGUI/Widget.h b/LibGUI/GWidget.h similarity index 67% rename from LibGUI/Widget.h rename to LibGUI/GWidget.h index a102c06f33..adfa9397e4 100644 --- a/LibGUI/Widget.h +++ b/LibGUI/GWidget.h @@ -1,29 +1,29 @@ #pragma once -#include "Event.h" -#include "Object.h" +#include "GEvent.h" +#include "GObject.h" #include #include #include #include class GraphicsBitmap; -class Window; +class GWindow; -class Widget : public Object { +class GWidget : public GObject { public: - explicit Widget(Widget* parent = nullptr); - virtual ~Widget(); + explicit GWidget(GWidget* parent = nullptr); + virtual ~GWidget(); - virtual void event(Event&) override; - virtual void paintEvent(PaintEvent&); - virtual void showEvent(ShowEvent&); - virtual void hideEvent(HideEvent&); - virtual void keyDownEvent(KeyEvent&); - virtual void keyUpEvent(KeyEvent&); - virtual void mouseMoveEvent(MouseEvent&); - virtual void mouseDownEvent(MouseEvent&); - virtual void mouseUpEvent(MouseEvent&); + virtual void event(GEvent&) override; + virtual void paintEvent(GPaintEvent&); + virtual void showEvent(GShowEvent&); + virtual void hideEvent(GHideEvent&); + virtual void keyDownEvent(GKeyEvent&); + virtual void keyUpEvent(GKeyEvent&); + virtual void mouseMoveEvent(GMouseEvent&); + virtual void mouseDownEvent(GMouseEvent&); + virtual void mouseUpEvent(GMouseEvent&); Rect relativeRect() const { return m_relativeRect; } Point relativePosition() const { return m_relativeRect.location(); } @@ -43,13 +43,13 @@ public: void setFocus(bool); struct HitTestResult { - Widget* widget { nullptr }; + GWidget* widget { nullptr }; int localX { 0 }; int localY { 0 }; }; HitTestResult hitTest(int x, int y); - virtual const char* class_name() const override { return "Widget"; } + virtual const char* class_name() const override { return "GWidget"; } void setWindowRelativeRect(const Rect&, bool should_update = true); @@ -59,24 +59,24 @@ public: void setBackgroundColor(Color color) { m_backgroundColor = color; } void setForegroundColor(Color color) { m_foregroundColor = color; } - Window* window() + GWindow* window() { if (auto* pw = parentWidget()) return pw->window(); return m_window; } - const Window* window() const + const GWindow* window() const { if (auto* pw = parentWidget()) return pw->window(); return m_window; } - void setWindow(Window*); + void setWindow(GWindow*); - Widget* parentWidget() { return static_cast(parent()); } - const Widget* parentWidget() const { return static_cast(parent()); } + GWidget* parentWidget() { return static_cast(parent()); } + const GWidget* parentWidget() const { return static_cast(parent()); } void setFillWithBackgroundColor(bool b) { m_fillWithBackgroundColor = b; } bool fillWithBackgroundColor() const { return m_fillWithBackgroundColor; } @@ -87,7 +87,7 @@ public: virtual GraphicsBitmap* backing(); private: - Window* m_window { nullptr }; + GWindow* m_window { nullptr }; Rect m_relativeRect; Color m_backgroundColor { 0xffffff }; diff --git a/LibGUI/GWindow.cpp b/LibGUI/GWindow.cpp new file mode 100644 index 0000000000..fa24d66186 --- /dev/null +++ b/LibGUI/GWindow.cpp @@ -0,0 +1,42 @@ +#include "GWindow.h" +#include "GEvent.h" +#include "GEventLoop.h" +#include + +GWindow::GWindow(int window_id) + : m_window_id(window_id) +{ +} + +GWindow::~GWindow() +{ +} + +void GWindow::set_title(String&& title) +{ + if (m_title == title) + return; + + m_title = move(title); +} +void GWindow::set_rect(const Rect& rect) +{ + if (m_rect == rect) + return; + m_rect = rect; + dbgprintf("GWindow::setRect %d,%d %dx%d\n", m_rect.x(), m_rect.y(), m_rect.width(), m_rect.height()); +} + +void GWindow::event(GEvent& event) +{ +} + +bool GWindow::is_visible() const +{ + return false; +} + +void GWindow::close() +{ +} + diff --git a/LibGUI/Window.h b/LibGUI/GWindow.h similarity index 87% rename from LibGUI/Window.h rename to LibGUI/GWindow.h index 3758295f78..0ba848a55c 100644 --- a/LibGUI/Window.h +++ b/LibGUI/GWindow.h @@ -1,14 +1,14 @@ #pragma once -#include "Object.h" +#include "GObject.h" #include #include #include -class Window final : public Object { +class GWindow final : public GObject { public: - explicit Window(int window_id); - virtual ~Window() override; + explicit GWindow(int window_id); + virtual ~GWindow() override; int window_id() const { return m_window_id; } @@ -27,7 +27,7 @@ public: Point position() const { return m_rect.location(); } void set_position_without_repaint(const Point& position) { set_rect_without_repaint({ position.x(), position.y(), width(), height() }); } - virtual void event(Event&) override; + virtual void event(GEvent&) override; bool is_being_dragged() const { return m_is_being_dragged; } void set_is_being_dragged(bool b) { m_is_being_dragged = b; } diff --git a/LibGUI/Label.h b/LibGUI/Label.h deleted file mode 100644 index 062c14a99a..0000000000 --- a/LibGUI/Label.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "Widget.h" -#include - -class Label final : public Widget { -public: - explicit Label(Widget* parent); - virtual ~Label() override; - - String text() const { return m_text; } - void setText(String&&); - -private: - virtual void paintEvent(PaintEvent&) override; - virtual void mouseMoveEvent(MouseEvent&) override; - - virtual const char* class_name() const override { return "Label"; } - - String m_text; -}; - diff --git a/LibGUI/ListBox.h b/LibGUI/ListBox.h deleted file mode 100644 index ca227f2b54..0000000000 --- a/LibGUI/ListBox.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "Widget.h" - -class ListBox final : public Widget { -public: - explicit ListBox(Widget* parent); - virtual ~ListBox() override; - - void addItem(String&&); - int selectedIndex() const { return m_selectedIndex; } - -private: - virtual void paintEvent(PaintEvent&) override; - virtual void mouseDownEvent(MouseEvent&) override; - virtual const char* class_name() const override { return "ListBox"; } - - Rect item_rect(int index) const; - - int m_scrollOffset { 0 }; - int m_selectedIndex { -1 }; - - Vector m_items; -}; - diff --git a/LibGUI/Makefile b/LibGUI/Makefile new file mode 100644 index 0000000000..f38bdc94be --- /dev/null +++ b/LibGUI/Makefile @@ -0,0 +1,51 @@ +SHAREDGRAPHICS_OBJS = \ + ../SharedGraphics/Painter.o \ + ../SharedGraphics/Font.o \ + ../SharedGraphics/Rect.o \ + ../SharedGraphics/GraphicsBitmap.o \ + ../SharedGraphics/CharacterBitmap.o \ + ../SharedGraphics/Color.o + +LIBGUI_OBJS = \ + GButton.o \ + GCheckBox.o \ + GEventLoop.o \ + GLabel.o \ + GListBox.o \ + GObject.o \ + GTextBox.o \ + GWidget.o \ + GWindow.o + +OBJS = $(SHAREDGRAPHICS_OBJS) $(LIBGUI_OBJS) + +LIBS = ../LibC/LibC.a + +LIBRARY = LibGUI.a +ARCH_FLAGS = +STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib -nostdinc +LIBC_FLAGS = -ffreestanding -fno-stack-protector -fno-ident +WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings +FLAVOR_FLAGS = -fomit-frame-pointer -mregparm=3 -march=i386 -m32 -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -fmerge-all-constants -fno-unroll-loops -fno-pie -fno-pic +OPTIMIZATION_FLAGS = -Oz -fno-asynchronous-unwind-tables +INCLUDE_FLAGS = -I../LibC -I.. -I. + +DEFINES = -DSERENITY -DUSERLAND -DSANITIZE_PTRS -DLIBGUI + +CXXFLAGS = $(WARNING_FLAGS) $(OPTIMIZATION_FLAGS) $(LIBC_FLAGS) $(FLAVOR_FLAGS) $(ARCH_FLAGS) $(STANDARD_FLAGS) $(INCLUDE_FLAGS) $(DEFINES) +CXX = clang +LD = ld +AR = ar +LDFLAGS = -T linker.ld --strip-debug -melf_i386 --gc-sections --build-id=none -z norelro -z now + +all: $(LIBRARY) + +$(LIBRARY): $(OBJS) + @echo "LIB $@"; $(AR) rcs $@ $(OBJS) $(LIBS) + +.cpp.o: + @echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $< + +clean: + @echo "CLEAN"; rm -f $(LIBRARY) $(OBJS) + diff --git a/LibGUI/Object.h b/LibGUI/Object.h deleted file mode 100644 index 4e4f8eb7cc..0000000000 --- a/LibGUI/Object.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include -#include - -class Event; -class TimerEvent; - -class Object : public Weakable { -public: - Object(Object* parent = nullptr); - virtual ~Object(); - - virtual const char* class_name() const { return "Object"; } - - virtual void event(Event&); - - Vector& children() { return m_children; } - - Object* parent() { return m_parent; } - const Object* parent() const { return m_parent; } - - void startTimer(int ms); - void stopTimer(); - bool hasTimer() const { return m_timerID; } - - void addChild(Object&); - void removeChild(Object&); - - void deleteLater(); - -private: - virtual void timerEvent(TimerEvent&); - - Object* m_parent { nullptr }; - - int m_timerID { 0 }; - - Vector m_children; -}; diff --git a/LibGUI/TextBox.h b/LibGUI/TextBox.h deleted file mode 100644 index 5236749099..0000000000 --- a/LibGUI/TextBox.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include "Widget.h" -#include - -class TextBox final : public Widget { -public: - explicit TextBox(Widget* parent = nullptr); - virtual ~TextBox() override; - - String text() const { return m_text; } - void setText(String&&); - - Function onReturnPressed; - -private: - virtual const char* class_name() const override { return "TextBox"; } - virtual void paintEvent(PaintEvent&) override; - virtual void mouseDownEvent(MouseEvent&) override; - virtual void keyDownEvent(KeyEvent&) override; - virtual void timerEvent(TimerEvent&) override; - - void handleBackspace(); - - String m_text; - unsigned m_cursorPosition { 0 }; - bool m_cursorBlinkState { false }; -}; - diff --git a/LibGUI/Widget.cpp b/LibGUI/Widget.cpp deleted file mode 100644 index a6d76caf34..0000000000 --- a/LibGUI/Widget.cpp +++ /dev/null @@ -1,163 +0,0 @@ -#include "Widget.h" -#include "Event.h" -#include "EventLoop.h" -#include "Window.h" -#include -#include -#include - -Widget::Widget(Widget* parent) - : Object(parent) -{ - setFont(nullptr); - m_backgroundColor = Color::White; - m_foregroundColor = Color::Black; -} - -Widget::~Widget() -{ -} - -void Widget::setWindowRelativeRect(const Rect& rect, bool should_update) -{ - // FIXME: Make some kind of event loop driven ResizeEvent? - m_relativeRect = rect; - if (should_update) - update(); -} - -void Widget::repaint(const Rect& rect) -{ - // FIXME: Implement. -} - -void Widget::event(Event& event) -{ - switch (event.type()) { - case Event::Paint: - m_hasPendingPaintEvent = false; - if (auto* win = window()) { - if (win->is_being_dragged()) - return; - if (!win->is_visible()) - return; - } - return paintEvent(static_cast(event)); - case Event::Show: - return showEvent(static_cast(event)); - case Event::Hide: - return hideEvent(static_cast(event)); - case Event::KeyDown: - return keyDownEvent(static_cast(event)); - case Event::KeyUp: - return keyUpEvent(static_cast(event)); - case Event::MouseMove: - return mouseMoveEvent(static_cast(event)); - case Event::MouseDown: - // FIXME: Focus self if needed. - return mouseDownEvent(static_cast(event)); - case Event::MouseUp: - return mouseUpEvent(static_cast(event)); - default: - return Object::event(event); - } -} - -void Widget::paintEvent(PaintEvent& event) -{ - //printf("Widget::paintEvent :)\n"); - if (fillWithBackgroundColor()) { - Painter painter(*this); - painter.fill_rect(rect(), backgroundColor()); - } - for (auto* ch : children()) { - auto* child = (Widget*)ch; - child->event(event); - } -} - -void Widget::showEvent(ShowEvent&) -{ -} - -void Widget::hideEvent(HideEvent&) -{ -} - -void Widget::keyDownEvent(KeyEvent&) -{ -} - -void Widget::keyUpEvent(KeyEvent&) -{ -} - -void Widget::mouseDownEvent(MouseEvent&) -{ -} - -void Widget::mouseUpEvent(MouseEvent&) -{ -} - -void Widget::mouseMoveEvent(MouseEvent&) -{ -} - -void Widget::update() -{ - auto* w = window(); - if (!w) - return; - if (m_hasPendingPaintEvent) - return; - m_hasPendingPaintEvent = true; - EventLoop::main().postEvent(w, make(relativeRect())); -} - -Widget::HitTestResult Widget::hitTest(int x, int y) -{ - // FIXME: Care about z-order. - for (auto* ch : children()) { - auto* child = (Widget*)ch; - if (child->relativeRect().contains(x, y)) { - return child->hitTest(x - child->relativeRect().x(), y - child->relativeRect().y()); - } - } - return { this, x, y }; -} - -void Widget::setWindow(Window* window) -{ - if (m_window == window) - return; - m_window = window; -} - -bool Widget::isFocused() const -{ - // FIXME: Implement. - return false; -} - -void Widget::setFocus(bool focus) -{ - if (focus == isFocused()) - return; - // FIXME: Implement. -} - -void Widget::setFont(RetainPtr&& font) -{ - if (!font) - m_font = Font::default_font(); - else - m_font = move(font); -} - -GraphicsBitmap* Widget::backing() -{ - if (auto* w = window()) - return w->backing(); - return nullptr; -} diff --git a/LibGUI/Window.cpp b/LibGUI/Window.cpp deleted file mode 100644 index f5a07875da..0000000000 --- a/LibGUI/Window.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "Window.h" -#include "Event.h" -#include "EventLoop.h" -#include - -Window::Window(int window_id) - : m_window_id(window_id) -{ -} - -Window::~Window() -{ -} - -void Window::set_title(String&& title) -{ - if (m_title == title) - return; - - m_title = move(title); -} -void Window::set_rect(const Rect& rect) -{ - if (m_rect == rect) - return; - m_rect = rect; - dbgprintf("Window::setRect %d,%d %dx%d\n", m_rect.x(), m_rect.y(), m_rect.width(), m_rect.height()); -} - -void Window::event(Event& event) -{ -} - -bool Window::is_visible() const -{ - return false; -} - -void Window::close() -{ -} - diff --git a/SharedGraphics/Painter.cpp b/SharedGraphics/Painter.cpp index 486803a25a..d8e9400601 100644 --- a/SharedGraphics/Painter.cpp +++ b/SharedGraphics/Painter.cpp @@ -5,7 +5,7 @@ #include #ifdef LIBGUI -#include +#include #endif #define DEBUG_WIDGET_UNDERDRAW @@ -18,7 +18,7 @@ Painter::Painter(GraphicsBitmap& bitmap) } #ifdef LIBGUI -Painter::Painter(Widget& widget) +Painter::Painter(GWidget& widget) : m_font(&widget.font()) { m_target = widget.backing(); diff --git a/SharedGraphics/Painter.h b/SharedGraphics/Painter.h index adf41a3805..5c66faf3a5 100644 --- a/SharedGraphics/Painter.h +++ b/SharedGraphics/Painter.h @@ -9,12 +9,17 @@ class CharacterBitmap; class GraphicsBitmap; class Font; -class Widget; -class Window; + +#ifdef LIBGUI +class GWidget; +class GWindow; +#endif class Painter { public: - explicit Painter(Widget&); +#ifdef LIBGUI + explicit Painter(GWidget&); +#endif explicit Painter(GraphicsBitmap&); ~Painter(); void fill_rect(const Rect&, Color); @@ -42,6 +47,8 @@ private: Point m_translation; Rect m_clip_rect; RetainPtr m_target; - Window* m_window { nullptr }; +#ifdef LIBGUI + GWindow* m_window { nullptr }; +#endif DrawOp m_draw_op { DrawOp::Copy }; };