diff --git a/src/Button.cpp b/src/Button.cpp index 3acde4c..999a528 100644 --- a/src/Button.cpp +++ b/src/Button.cpp @@ -28,7 +28,7 @@ void Button::on_paint() { painter.source_rgb(style()->foreground()); painter.set_pango_font_description(style()->font_description()); - painter.text(current_geometry(), m_text, PaintTextAlign::Center, PANGO_ELLIPSIZE_END, true); + painter.text(rect(), m_text, PaintTextAlign::Center, PANGO_ELLIPSIZE_END, true); painter.fill(); } diff --git a/src/DocumentLayout.cpp b/src/DocumentLayout.cpp index dae8fd3..e529ace 100644 --- a/src/DocumentLayout.cpp +++ b/src/DocumentLayout.cpp @@ -17,21 +17,21 @@ void DocumentLayout::run() { if (child->absolute()) continue; - if (child->current_geometry().height() > largest_height_so_far) { - largest_height_so_far = child->current_geometry().height(); + if (child->rect().height() > largest_height_so_far) { + largest_height_so_far = child->rect().height(); } bool new_row_because_of_control_widget = (child->control_type() == ControlWidgetType::NewRow && largest_height_so_far); - bool new_row_because_of_justification = (current_position.x() + child->current_geometry().width() + m_margin) >= m_target->current_geometry().width(); + bool new_row_because_of_justification = (current_position.x() + child->rect().width() + m_margin) >= m_target->rect().width(); bool should_do_new_row = new_row_because_of_control_widget || new_row_because_of_justification; if (should_do_new_row) { current_position.add(0, largest_height_so_far + m_margin); current_position.set_x(m_margin); } - child->current_geometry().set_x(current_position.x()); - child->current_geometry().set_y(current_position.y()); - current_position.add(child->current_geometry().width() + m_margin, 0); + child->rect().set_x(current_position.x()); + child->rect().set_y(current_position.y()); + current_position.add(child->rect().width() + m_margin, 0); } } diff --git a/src/Label.cpp b/src/Label.cpp index 0f59781..26ec22e 100644 --- a/src/Label.cpp +++ b/src/Label.cpp @@ -24,7 +24,7 @@ void Label::on_paint() { painter.source_rgb(style()->foreground()); painter.set_pango_font_description(style()->font_description()); - painter.text(current_geometry(), m_text, PaintTextAlign::Left, PANGO_ELLIPSIZE_NONE, true); + painter.text(rect(), m_text, PaintTextAlign::Left, PANGO_ELLIPSIZE_NONE, true); painter.fill(); } diff --git a/src/Styles.cpp b/src/Styles.cpp index 596472a..3beecd4 100644 --- a/src/Styles.cpp +++ b/src/Styles.cpp @@ -1,7 +1,7 @@ #include "Styles.hpp" #include "pango/pango-font.h" -#include "src/RGB.hpp" +#include "RGB.hpp" namespace Raven { diff --git a/src/Styles.hpp b/src/Styles.hpp index dfe60ed..152ab74 100644 --- a/src/Styles.hpp +++ b/src/Styles.hpp @@ -1,6 +1,6 @@ #pragma once -#include "src/GenericStyle.hpp" +#include "GenericStyle.hpp" namespace Raven { diff --git a/src/Widget.cpp b/src/Widget.cpp index 9942f92..c92c396 100644 --- a/src/Widget.cpp +++ b/src/Widget.cpp @@ -12,7 +12,7 @@ namespace Raven { Point Widget::window_relative() { Point point = { 0, 0 }; for (Widget* parent = m_parent; parent; parent = parent->parent()) { - point.add(parent->current_geometry().x(), parent->current_geometry().y()); + point.add(parent->rect().x(), parent->rect().y()); } return point; } @@ -22,31 +22,31 @@ void Widget::fit_text(std::string &text) { return; window()->painter().set_pango_font_description(m_style->font_description()); - auto size = window()->painter().compute_text_size(current_geometry(), text); + auto size = window()->painter().compute_text_size(rect(), text); if (!resize(size)) { reflow(); } } bool Widget::resize(double width, double height) { - if (m_current_geometry.width() == width && m_current_geometry.height() == height) + if (m_rect.width() == width && m_rect.height() == height) return false; if (width < 0 || height < 0) return false; - m_current_geometry.set_width(width); - m_current_geometry.set_height(height); + m_rect.set_width(width); + m_rect.set_height(height); reflow(); return true; } void Widget::move_to(double x, double y) { - if (m_current_geometry.x() == x && m_current_geometry.y() == y) + if (m_rect.x() == x && m_rect.y() == y) return; - m_current_geometry.set_x(x); - m_current_geometry.set_y(y); + m_rect.set_x(x); + m_rect.set_y(y); reflow(); } @@ -106,7 +106,7 @@ void Widget::handle_repaint_rect(RepaintRectEvent &event) { if (!m_did_init || !painter.can_paint()) return; - if (!event.box().contains_box(current_geometry())) + if (!event.box().contains_box(m_rect)) return; // widgets contain their children, thus we don't need to recurse further // using a "group" in cairo reduces flickering @@ -121,7 +121,7 @@ void Widget::handle_repaint_rect(RepaintRectEvent &event) { cr->save(); // clip this widget. this ensures that the background fill or children won't overflow the bounds of it - painter.rounded_rectangle(m_current_geometry, m_style->border_radius()); + painter.rounded_rectangle(m_rect, m_style->border_radius()); cr->clip(); // paint the background fill @@ -145,12 +145,12 @@ void Widget::handle_repaint_rect(RepaintRectEvent &event) { // translate to the widget's position // the origin of the painter is now the widget's origin // this is because the position of children is relative to the origin of their parent - cr->translate(current_geometry().x(), current_geometry().y()); + cr->translate(rect().x(), rect().y()); on_paint(); // convert the paint event's origin to our coordinate space because all positions of children are relative to the origin of their parent - auto local_box = event.box().offset(-m_current_geometry.x(), -m_current_geometry.y()); + auto local_box = event.box().offset(-m_rect.x(), -m_rect.y()); auto local_event = RepaintRectEvent(false, local_box); for (auto child : m_children) { child->dispatch_event(local_event); @@ -171,7 +171,7 @@ void Widget::handle_mouse_move_event(MouseMoveEvent &event) { event.accept(); // we will do our own propagation logic bool update_focus_to = true; - if (!m_current_geometry.contains_point(event.point())) { + if (!m_rect.contains_point(event.point())) { // we just became unfocused update_focus_to = false; } @@ -194,8 +194,8 @@ void Widget::handle_mouse_move_event(MouseMoveEvent &event) { if (!m_consumes_hits) { // translate the event's point to our coordinate space because the position of all children is relative to the origin of their parent auto local_event = MouseMoveEvent(Point( - event.point().x() - m_current_geometry.x(), - event.point().y() - m_current_geometry.y() + event.point().x() - m_rect.x(), + event.point().y() - m_rect.y() )); for (auto child : m_children) { child->dispatch_event(local_event); @@ -208,7 +208,7 @@ void Widget::handle_mouse_button_event(MouseButtonEvent &event) { bool update_activation_to = event.was_left_button_pressed(); - if (!m_current_geometry.contains_point(event.point())) { + if (!m_rect.contains_point(event.point())) { return; } @@ -230,8 +230,8 @@ void Widget::handle_mouse_button_event(MouseButtonEvent &event) { if (!m_consumes_hits) { // translate the event's point to our coordinate space because the position of all children is relative to the origin of their parent auto local_event = MouseButtonEvent(event.was_left_button_pressed(), event.was_right_button_pressed(), Point( - event.point().x() - m_current_geometry.x(), - event.point().y() - m_current_geometry.y() + event.point().x() - m_rect.x(), + event.point().y() - m_rect.y() )); for (auto child : m_children) { child->dispatch_event(local_event); diff --git a/src/Widget.hpp b/src/Widget.hpp index 2fd8fc8..1d3f91f 100644 --- a/src/Widget.hpp +++ b/src/Widget.hpp @@ -9,8 +9,8 @@ #include "Events.hpp" #include "Forward.hpp" #include "RGB.hpp" -#include "src/GenericStyle.hpp" -#include "src/Styles.hpp" +#include "GenericStyle.hpp" +#include "Styles.hpp" namespace Raven { @@ -54,9 +54,9 @@ public: bool add_child(std::shared_ptr child); void remove_child(std::shared_ptr child); - Box ¤t_geometry() { return m_current_geometry; } - void set_current_geometry(Box current_geometry) { m_current_geometry = current_geometry; reflow(); } - void set_current_geometry(Box current_geometry, bool is_pure) { m_current_geometry = current_geometry; if (!is_pure) { reflow(); } } + Box &rect() { return m_rect; } + void set_rect(Box rect) { m_rect = rect; reflow(); } + void set_rect(Box rect, bool is_pure) { m_rect = rect; if (!is_pure) { reflow(); } } Point window_relative(); @@ -124,7 +124,7 @@ private: void handle_mouse_move_event(MouseMoveEvent &event); void handle_mouse_button_event(MouseButtonEvent &event); - Box m_current_geometry { 0, 0, 0, 0 }; + Box m_rect { 0, 0, 0, 0 }; std::vector> m_children; Widget *m_parent { nullptr }; Window *m_window { nullptr }; diff --git a/src/Window.cpp b/src/Window.cpp index 5488eeb..0518a0d 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -16,7 +16,7 @@ namespace Raven { void Window::set_main_widget(std::shared_ptr main_widget) { m_main_widget = main_widget; m_main_widget->set_window(this); - m_main_widget->set_current_geometry(m_current_geometry); + m_main_widget->set_rect(m_rect); } bool Window::spawn_window() { @@ -33,8 +33,8 @@ bool Window::spawn_window() { DefaultRootWindow(dsp), 0, 0, - m_current_geometry.width(), - m_current_geometry.height(), + m_rect.width(), + m_rect.height(), 0, 0, CopyFromParent, @@ -50,8 +50,8 @@ bool Window::spawn_window() { dsp, da, DefaultVisual(dsp, screen), - current_geometry().width(), - current_geometry().height() + rect().width(), + rect().height() ); auto cairo_context = Cairo::Context::create(m_xlib_surface); @@ -82,11 +82,11 @@ void Window::repaint(Box geometry) { } void Window::repaint(Widget *target) { - repaint(target->current_geometry().offset(target->window_relative().x(), target->window_relative().y())); + repaint(target->rect().offset(target->window_relative().x(), target->window_relative().y())); } void Window::repaint() { - repaint(m_current_geometry); + repaint(m_rect); } void Window::relayout(Widget *target) { @@ -148,14 +148,14 @@ void Window::run(bool block) { break; } case ConfigureNotify: { - if (e.xconfigure.width != m_current_geometry.width() || e.xconfigure.height != m_current_geometry.height()) { + if (e.xconfigure.width != m_rect.width() || e.xconfigure.height != m_rect.height()) { m_xlib_surface->set_size(e.xconfigure.width, e.xconfigure.height); - m_current_geometry.set_width(e.xconfigure.width); - m_current_geometry.set_height(e.xconfigure.height); + m_rect.set_width(e.xconfigure.width); + m_rect.set_height(e.xconfigure.height); // if we have a main widget, we are going to have to resize it as well if (m_main_widget) { - m_main_widget->current_geometry().set_width(m_current_geometry.width()); - m_main_widget->current_geometry().set_height(m_current_geometry.height()); + m_main_widget->rect().set_width(m_rect.width()); + m_main_widget->rect().set_height(m_rect.height()); } } break; diff --git a/src/Window.hpp b/src/Window.hpp index d8be93c..e3e457a 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -4,7 +4,7 @@ #include #include "Widget.hpp" #include "Painter.hpp" -#include "src/Events.hpp" +#include "Events.hpp" #include #include #include @@ -41,7 +41,7 @@ public: void relayout(); void reflow(); - Box ¤t_geometry() { return m_current_geometry; } + Box &rect() { return m_rect; } template std::shared_ptr set_main_widget(Args&&... args) { @@ -53,7 +53,7 @@ private: Widget *m_focused_widget { nullptr }; Widget *m_active_widget { nullptr }; std::shared_ptr m_main_widget { nullptr }; - Box m_current_geometry { 0, 0, 800, 600 }; + Box m_rect { 0, 0, 800, 600 }; Painter m_painter {}; Cairo::RefPtr m_xlib_surface { nullptr }; bool m_is_batching { true }; diff --git a/src/main.cpp b/src/main.cpp index 7741831..9cafb48 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,8 +6,8 @@ #include "Label.hpp" #include "Layout.hpp" #include "RGB.hpp" -#include "src/DocumentLayout.hpp" -#include "src/Events.hpp" +#include "DocumentLayout.hpp" +#include "Events.hpp" #include #include #include