☢️☢️☢️☢️☢️☢️

This commit is contained in:
hippoz 2022-04-30 09:40:09 +03:00
parent 4145115697
commit 1aec5d3e44
Signed by: hippoz
GPG key ID: 7C52899193467641
20 changed files with 120 additions and 120 deletions

View file

@ -8,7 +8,7 @@ bool Box::contains_point(double x, double y) const {
} }
bool Box::contains_point(const Point &point) const { bool Box::contains_point(const Point &point) const {
return point.get_x() >= m_x && m_x + m_width >= point.get_x() && point.get_y() >= m_y && m_y + m_height >= point.get_y(); return point.x() >= m_x && m_x + m_width >= point.x() && point.y() >= m_y && m_y + m_height >= point.y();
} }
bool Box::contains_box(const Box &other) const { bool Box::contains_box(const Box &other) const {
@ -17,10 +17,10 @@ bool Box::contains_box(const Box &other) const {
double ay1 = m_y; double ay1 = m_y;
double ay2 = m_y + m_height; double ay2 = m_y + m_height;
double bx1 = other.get_x(); double bx1 = other.x();
double bx2 = other.get_x() + other.get_width(); double bx2 = other.x() + other.width();
double by1 = other.get_y(); double by1 = other.y();
double by2 = other.get_y() + other.get_height(); double by2 = other.y() + other.height();
// https://stackoverflow.com/a/306332 // https://stackoverflow.com/a/306332
bool boxes_overlap = (ax1 < bx2 && ax2 > bx1 && ay1 < by2 && ay2 > by1); bool boxes_overlap = (ax1 < bx2 && ax2 > bx1 && ay1 < by2 && ay2 > by1);

View file

@ -21,15 +21,15 @@ public:
} }
double get_x() { return m_x; } double x() { return m_x; }
double get_y() { return m_y; } double y() { return m_y; }
double get_width() { return m_width; } double width() { return m_width; }
double get_height() { return m_height; } double height() { return m_height; }
double get_x() const { return m_x; } double x() const { return m_x; }
double get_y() const { return m_y; } double y() const { return m_y; }
double get_width() const { return m_width; } double width() const { return m_width; }
double get_height() const { return m_height; } double height() const { return m_height; }
void set_x(double x) { m_x = x; } void set_x(double x) { m_x = x; }
void set_y(double y) { m_y = y; } void set_y(double y) { m_y = y; }

View file

@ -9,7 +9,7 @@
namespace Raven { namespace Raven {
void Button::on_init() { void Button::on_init() {
set_background_fill_color(get_styles()->get_button_normal_color()); set_background_fill_color(styles()->button_normal_color());
set_do_background_fill(true); set_do_background_fill(true);
set_did_init(true); set_did_init(true);
@ -17,21 +17,21 @@ void Button::on_init() {
void Button::update_color() { void Button::update_color() {
if (is_active()) { if (is_active()) {
set_background_fill_color(get_styles()->get_button_active_color()); set_background_fill_color(styles()->button_active_color());
} else if (is_focused()) { } else if (is_focused()) {
set_background_fill_color(get_styles()->get_button_focused_color()); set_background_fill_color(styles()->button_focused_color());
} else { } else {
set_background_fill_color(get_styles()->get_button_normal_color()); set_background_fill_color(styles()->button_normal_color());
} }
} }
void Button::on_paint() { void Button::on_paint() {
auto painter = get_window()->get_painter(); auto painter = window()->painter();
auto text_color = get_styles()->get_button_text_color(); auto text_color = styles()->button_text_color();
painter.source_rgb(text_color); painter.source_rgb(text_color);
painter.set_pango_font_description(get_styles()->get_controls_font_description()); painter.set_pango_font_description(styles()->controls_font_description());
painter.text(get_current_geometry(), m_text, PaintTextAlign::Center, PANGO_ELLIPSIZE_END); painter.text(current_geometry(), m_text, PaintTextAlign::Center, PANGO_ELLIPSIZE_END);
painter.fill(); painter.fill();
} }
@ -41,7 +41,7 @@ void Button::on_focus_update(FocusUpdateEvent &event) {
void Button::on_activation_update(ActivationUpdateEvent &event) { void Button::on_activation_update(ActivationUpdateEvent &event) {
update_color(); update_color();
if (event.get_activation_status() == false) { if (event.activation_status() == false) {
on_click(); on_click();
} }
} }

View file

@ -18,7 +18,7 @@ public:
, m_text(text) {} , m_text(text) {}
void set_text(std::string text) { m_text = text; wants_repaint(); } void set_text(std::string text) { m_text = text; wants_repaint(); }
std::string &get_text() { return m_text; } std::string &text() { return m_text; }
std::function<void()> on_click { [](){} }; std::function<void()> on_click { [](){} };
protected: protected:

View file

@ -8,22 +8,22 @@ void DocumentLayout::run() {
if (!m_target) if (!m_target)
return; return;
Point point { m_target->get_current_geometry().get_x() + m_margin, m_target->get_current_geometry().get_y() + m_margin }; Point point { m_target->current_geometry().x() + m_margin, m_target->current_geometry().y() + m_margin };
double row_largest_height = 0.0; double row_largest_height = 0.0;
auto children = m_target->get_children(); auto children = m_target->children();
for (auto& c : children) { for (auto& c : children) {
if (c->get_control_type() == ControlWidgetType::NewRow && row_largest_height) { if (c->control_type() == ControlWidgetType::NewRow && row_largest_height) {
point.add(0, row_largest_height + m_margin); point.add(0, row_largest_height + m_margin);
row_largest_height = 0.0; row_largest_height = 0.0;
point.set_x(0); point.set_x(0);
} }
if (c->get_current_geometry().get_height() > row_largest_height) { if (c->current_geometry().height() > row_largest_height) {
row_largest_height = c->get_current_geometry().get_height(); row_largest_height = c->current_geometry().height();
} }
auto new_geometry = Box{ point.get_x(), point.get_y(), c->get_current_geometry().get_width(), c->get_current_geometry().get_height() }; auto new_geometry = Box{ point.x(), point.y(), c->current_geometry().width(), c->current_geometry().height() };
c->set_current_geometry(std::move(new_geometry), true); c->set_current_geometry(std::move(new_geometry), true);
point.add(c->get_current_geometry().get_width() + m_margin, 0); point.add(c->current_geometry().width() + m_margin, 0);
} }
} }

View file

@ -17,7 +17,7 @@ public:
void run(); void run();
double get_margin() { return m_margin; } double margin() { return m_margin; }
void set_margin(double margin) { m_margin = margin; run(); } void set_margin(double margin) { m_margin = margin; run(); }
}; };

View file

@ -23,11 +23,11 @@ private:
public: public:
Event() {} Event() {}
virtual EventType get_type() { return EventType::NoneEvent; } virtual EventType type() { return EventType::NoneEvent; }
virtual const char *get_name() { return "NoneEvent"; } virtual const char *name() { return "NoneEvent"; }
void accept() { m_accepted = true; } void accept() { m_accepted = true; }
bool get_accepted() { return m_accepted; } bool accepted() { return m_accepted; }
virtual ~Event() = default; virtual ~Event() = default;
}; };
@ -43,13 +43,13 @@ public:
, m_was_right_button_pressed(was_right_button_pressed) , m_was_right_button_pressed(was_right_button_pressed)
, m_point(point) {} , m_point(point) {}
EventType get_type() { return EventType::MouseButton; } EventType type() { return EventType::MouseButton; }
const char *get_name() { return "MouseButton"; } const char *name() { return "MouseButton"; }
bool get_was_left_button_pressed() { return m_was_left_button_pressed; } bool was_left_button_pressed() { return m_was_left_button_pressed; }
bool get_was_right_button_pressed() { return m_was_right_button_pressed; } bool was_right_button_pressed() { return m_was_right_button_pressed; }
Point &get_point() { return m_point; } Point &point() { return m_point; }
}; };
class MouseMoveEvent : public Event { class MouseMoveEvent : public Event {
@ -59,10 +59,10 @@ public:
MouseMoveEvent(Point point) MouseMoveEvent(Point point)
: m_point(point) {} : m_point(point) {}
EventType get_type() { return EventType::MouseMove; } EventType type() { return EventType::MouseMove; }
const char *get_name() { return "MouseMove"; } const char *name() { return "MouseMove"; }
Point &get_point() { return m_point; } Point &point() { return m_point; }
}; };
class WidgetRepaintRequestedEvent : public Event { class WidgetRepaintRequestedEvent : public Event {
@ -72,8 +72,8 @@ public:
WidgetRepaintRequestedEvent(bool should_do_group) WidgetRepaintRequestedEvent(bool should_do_group)
: m_should_do_group(should_do_group) {} : m_should_do_group(should_do_group) {}
EventType get_type() { return EventType::WidgetRepaintRequested; } EventType type() { return EventType::WidgetRepaintRequested; }
const char *get_name() { return "WidgetRepaintRequested"; } const char *name() { return "WidgetRepaintRequested"; }
bool should_do_group() { return m_should_do_group; } bool should_do_group() { return m_should_do_group; }
void set_should_do_group(bool should_do_group) { m_should_do_group = should_do_group; } void set_should_do_group(bool should_do_group) { m_should_do_group = should_do_group; }
@ -83,8 +83,8 @@ class WidgetRelayoutRequestedEvent : public Event {
public: public:
WidgetRelayoutRequestedEvent() {} WidgetRelayoutRequestedEvent() {}
EventType get_type() { return EventType::WidgetRelayoutRequestedEvent; } EventType type() { return EventType::WidgetRelayoutRequestedEvent; }
const char *get_name() { return "WidgetRelayoutRequestedEvent"; } const char *name() { return "WidgetRelayoutRequestedEvent"; }
}; };
class FocusUpdateEvent : public Event { class FocusUpdateEvent : public Event {
@ -94,10 +94,10 @@ public:
FocusUpdateEvent(bool focus_status) FocusUpdateEvent(bool focus_status)
: m_focus_status(focus_status) {} : m_focus_status(focus_status) {}
EventType get_type() { return EventType::FocusUpdate; } EventType type() { return EventType::FocusUpdate; }
const char *get_name() { return "FocusUpdate"; } const char *name() { return "FocusUpdate"; }
bool get_focus_status() { return m_focus_status; } bool focus_status() { return m_focus_status; }
}; };
class ActivationUpdateEvent : public Event { class ActivationUpdateEvent : public Event {
@ -107,10 +107,10 @@ public:
ActivationUpdateEvent(bool activation_status) ActivationUpdateEvent(bool activation_status)
: m_activation_status(activation_status) {} : m_activation_status(activation_status) {}
EventType get_type() { return EventType::ActivationUpdate; } EventType type() { return EventType::ActivationUpdate; }
const char *get_name() { return "ActivationUpdate"; } const char *name() { return "ActivationUpdate"; }
bool get_activation_status() { return m_activation_status; } bool activation_status() { return m_activation_status; }
}; };
} }

View file

@ -6,20 +6,20 @@ namespace Raven {
void Label::on_init() { void Label::on_init() {
// the label will inherit the background color properties from the parent // the label will inherit the background color properties from the parent
if (Widget *parent = get_parent()) { if (parent()) {
set_do_background_fill(parent->get_do_background_fill()); set_do_background_fill(parent()->do_background_fill());
set_background_fill_color(parent->get_background_fill_color()); set_background_fill_color(parent()->background_fill_color());
} }
set_did_init(true); set_did_init(true);
} }
void Label::on_paint() { void Label::on_paint() {
auto painter = get_window()->get_painter(); auto painter = window()->painter();
auto text_color = get_styles()->get_label_text_color(); auto text_color = styles()->label_text_color();
painter.source_rgb(text_color); painter.source_rgb(text_color);
painter.set_pango_font_description(get_styles()->get_controls_font_description()); painter.set_pango_font_description(styles()->controls_font_description());
painter.text(get_current_geometry(), m_text, PaintTextAlign::Left, PANGO_ELLIPSIZE_NONE); painter.text(current_geometry(), m_text, PaintTextAlign::Left, PANGO_ELLIPSIZE_NONE);
painter.fill(); painter.fill();
} }

View file

@ -15,7 +15,7 @@ public:
~Label() {} ~Label() {}
std::string &get_text() { return m_text; } std::string &text() { return m_text; }
void set_text(std::string text) { m_text = text; wants_repaint(); } void set_text(std::string text) { m_text = text; wants_repaint(); }
protected: protected:
WidgetType m_type { WidgetType::Label }; WidgetType m_type { WidgetType::Label };

View file

@ -13,7 +13,7 @@ public:
virtual void run() {}; virtual void run() {};
void bind_to(Widget *target) { m_target = target; } void bind_to(Widget *target) { m_target = target; }
Widget *get_target() { return m_target; } Widget *target() { return m_target; }
virtual ~Layout() {} virtual ~Layout() {}
}; };

View file

@ -9,10 +9,10 @@ void Painter::rounded_rectangle(Box &geometry, double border_radius) {
double aspect = 1.0; double aspect = 1.0;
double radius = border_radius / aspect; double radius = border_radius / aspect;
double degrees = M_PI / 180.0; double degrees = M_PI / 180.0;
double x = geometry.get_x(); double x = geometry.x();
double y = geometry.get_y(); double y = geometry.y();
double w = geometry.get_width(); double w = geometry.width();
double h = geometry.get_height(); double h = geometry.height();
m_cairo->begin_new_sub_path(); m_cairo->begin_new_sub_path();
m_cairo->arc(x + w - radius, y + radius, radius, -90 * degrees, 0 * degrees); m_cairo->arc(x + w - radius, y + radius, radius, -90 * degrees, 0 * degrees);
@ -31,7 +31,7 @@ bool Painter::text(Point &where, std::string &text) {
pango_layout_set_font_description(layout, m_pango_font_description); pango_layout_set_font_description(layout, m_pango_font_description);
pango_layout_set_text(layout, text.c_str(), -1); pango_layout_set_text(layout, text.c_str(), -1);
m_cairo->move_to(where.get_x(), where.get_y()); m_cairo->move_to(where.x(), where.y());
pango_cairo_show_layout(m_cairo->cobj(), layout); pango_cairo_show_layout(m_cairo->cobj(), layout);
g_object_unref(layout); g_object_unref(layout);
@ -49,20 +49,20 @@ bool Painter::text(Box &geometry, std::string &text, PaintTextAlign align, Pango
int font_height; int font_height;
pango_layout_set_font_description(layout, m_pango_font_description); pango_layout_set_font_description(layout, m_pango_font_description);
pango_layout_set_width(layout, pango_units_from_double(geometry.get_width())); pango_layout_set_width(layout, pango_units_from_double(geometry.width()));
pango_layout_set_height(layout, pango_units_from_double(geometry.get_height())); pango_layout_set_height(layout, pango_units_from_double(geometry.height()));
pango_layout_set_ellipsize(layout, ellipsize); pango_layout_set_ellipsize(layout, ellipsize);
pango_layout_set_text(layout, text.c_str(), -1); pango_layout_set_text(layout, text.c_str(), -1);
pango_layout_get_pixel_size(layout, &font_width, &font_height); pango_layout_get_pixel_size(layout, &font_width, &font_height);
double x = -1; double x = -1;
double y = geometry.get_y() + ((geometry.get_height() - font_height) / 2); double y = geometry.y() + ((geometry.height() - font_height) / 2);
if (align == PaintTextAlign::Center) { if (align == PaintTextAlign::Center) {
x = geometry.get_x() + ((geometry.get_width() - font_width) / 2); x = geometry.x() + ((geometry.width() - font_width) / 2);
} else { } else {
x = geometry.get_x(); x = geometry.x();
} }
m_cairo->move_to(x, y); m_cairo->move_to(x, y);
@ -74,7 +74,7 @@ bool Painter::text(Box &geometry, std::string &text, PaintTextAlign align, Pango
} }
void Painter::source_rgb(RGB &source_rgb) { void Painter::source_rgb(RGB &source_rgb) {
m_cairo->set_source_rgb(source_rgb.get_r(), source_rgb.get_g(), source_rgb.get_b()); m_cairo->set_source_rgb(source_rgb.r(), source_rgb.g(), source_rgb.b());
} }
void Painter::fill() { void Painter::fill() {

View file

@ -21,11 +21,11 @@ private:
public: public:
Painter() {} Painter() {}
Cairo::RefPtr<Cairo::Context> get_cairo() { return m_cairo; } Cairo::RefPtr<Cairo::Context> cairo() { return m_cairo; }
void set_cairo(Cairo::RefPtr<Cairo::Context> cairo) { m_cairo = cairo; } void set_cairo(Cairo::RefPtr<Cairo::Context> cairo) { m_cairo = cairo; }
void set_pango_font_description(PangoFontDescription *pango_font_description) { m_pango_font_description = pango_font_description; } void set_pango_font_description(PangoFontDescription *pango_font_description) { m_pango_font_description = pango_font_description; }
PangoFontDescription *get_pango_font_description() { return m_pango_font_description; } PangoFontDescription *pango_font_description() { return m_pango_font_description; }
void rounded_rectangle(Box &geometry, double border_radius); void rounded_rectangle(Box &geometry, double border_radius);
bool text(Point &where, std::string &text); bool text(Point &where, std::string &text);

View file

@ -11,16 +11,16 @@ public:
: m_x(x) : m_x(x)
, m_y(y) {} , m_y(y) {}
double get_x() { return m_x; } double x() { return m_x; }
const double get_x() const { return m_x; } const double x() const { return m_x; }
double get_y() { return m_y; } double y() { return m_y; }
const double get_y() const { return m_y; } const double y() const { return m_y; }
void set_x(double x) { m_x = x; } void set_x(double x) { m_x = x; }
void set_y(double y) { m_y = y; } void set_y(double y) { m_y = y; }
void add(double x, double y) { m_x += x; m_y += y; } void add(double x, double y) { m_x += x; m_y += y; }
void add(Point const& other) { m_x += other.get_x(); m_y += other.get_y(); } void add(Point const& other) { m_x += other.x(); m_y += other.y(); }
}; };
} }

View file

@ -5,5 +5,5 @@
type m_##name {__VA_ARGS__}; \ type m_##name {__VA_ARGS__}; \
public: \ public: \
void set_##name(type new_prop_value) { m_##name = new_prop_value; wants_repaint(); } \ void set_##name(type new_prop_value) { m_##name = new_prop_value; wants_repaint(); } \
type get_##name() { return m_##name; } \ type name() { return m_##name; } \
private: private:

View file

@ -18,9 +18,9 @@ public:
void set_g(double g) { m_g = g; } void set_g(double g) { m_g = g; }
void set_b(double b) { m_b = b; } void set_b(double b) { m_b = b; }
double get_r() { return m_r; } double r() { return m_r; }
double get_g() { return m_g; } double g() { return m_g; }
double get_b() { return m_b; } double b() { return m_b; }
}; };
} }

View file

@ -48,7 +48,7 @@ public:
} }
} }
Window *get_window() { return m_window; } Window *window() { return m_window; }
void set_window(Window *window) { m_window = window; } void set_window(Window *window) { m_window = window; }
void wants_repaint(); void wants_repaint();

View file

@ -26,13 +26,13 @@ void Widget::set_window(Window *window) {
throw std::logic_error{"null window value for set_window"}; throw std::logic_error{"null window value for set_window"};
m_window = window; m_window = window;
m_styles = m_window->get_top_level_styles(); m_styles = m_window->top_level_styles();
on_init(); on_init();
} }
bool Widget::add_child(std::shared_ptr<Widget> child) { bool Widget::add_child(std::shared_ptr<Widget> child) {
if (child->get_parent()) { if (child->parent()) {
return false; return false;
} }
m_children.push_back(child); m_children.push_back(child);
@ -50,8 +50,8 @@ void Widget::remove_child(std::shared_ptr<Widget> child) {
void Widget::do_generic_paint() { void Widget::do_generic_paint() {
if (m_do_background_fill) { if (m_do_background_fill) {
auto painter = m_window->get_painter(); auto painter = m_window->painter();
auto cr = painter.get_cairo(); auto cr = painter.cairo();
cr->save(); cr->save();
@ -100,12 +100,12 @@ void Widget::handle_repaint(WidgetRepaintRequestedEvent &event) {
if (!m_did_init) if (!m_did_init)
return; return;
auto painter = m_window->get_painter(); auto painter = m_window->painter();
if (!painter.can_paint()) if (!painter.can_paint())
return; return;
auto cr = painter.get_cairo(); auto cr = painter.cairo();
auto event_should_do_group = event.should_do_group(); auto event_should_do_group = event.should_do_group();
if (event_should_do_group) { if (event_should_do_group) {
@ -133,7 +133,7 @@ void Widget::handle_repaint(WidgetRepaintRequestedEvent &event) {
void Widget::handle_mouse_move_event(MouseMoveEvent &event) { void Widget::handle_mouse_move_event(MouseMoveEvent &event) {
bool update_focus_to = true; bool update_focus_to = true;
if (!m_current_geometry.contains_point(event.get_point())) { if (!m_current_geometry.contains_point(event.point())) {
// we just became unfocused // we just became unfocused
if (m_is_focused) { if (m_is_focused) {
update_focus_to = false; update_focus_to = false;
@ -155,9 +155,9 @@ void Widget::handle_mouse_move_event(MouseMoveEvent &event) {
} }
void Widget::handle_mouse_button_event(MouseButtonEvent &event) { void Widget::handle_mouse_button_event(MouseButtonEvent &event) {
bool update_activation_to = event.get_was_left_button_pressed(); bool update_activation_to = event.was_left_button_pressed();
if (!m_current_geometry.contains_point(event.get_point())) { if (!m_current_geometry.contains_point(event.point())) {
event.accept(); event.accept();
return; return;
} }
@ -179,7 +179,7 @@ void Widget::dispatch_event(Event &event) {
if (!m_accepts_events) if (!m_accepts_events)
return; return;
switch (event.get_type()) { switch (event.type()) {
case EventType::MouseMove: { case EventType::MouseMove: {
handle_mouse_move_event(reinterpret_cast<MouseMoveEvent&>(event)); handle_mouse_move_event(reinterpret_cast<MouseMoveEvent&>(event));
break; break;
@ -204,7 +204,7 @@ void Widget::dispatch_event(Event &event) {
} }
} }
if (!event.get_accepted()) { if (!event.accepted()) {
for (auto& child : m_children) { for (auto& child : m_children) {
child->dispatch_event(event); child->dispatch_event(event);
} }
@ -212,7 +212,7 @@ void Widget::dispatch_event(Event &event) {
} }
void Widget::on_init() { void Widget::on_init() {
set_background_fill_color(get_styles()->get_background_color()); set_background_fill_color(styles()->background_color());
set_do_background_fill(true); set_do_background_fill(true);
set_did_init(true); set_did_init(true);
} }

View file

@ -55,41 +55,41 @@ public:
m_accepts_events = false; m_accepts_events = false;
} }
Box &get_current_geometry() { return m_current_geometry; } Box &current_geometry() { return m_current_geometry; }
void set_current_geometry(Box current_geometry) { m_current_geometry = current_geometry; wants_full_relayout(); } void set_current_geometry(Box current_geometry) { m_current_geometry = current_geometry; wants_full_relayout(); }
void set_current_geometry(Box current_geometry, bool is_pure) { m_current_geometry = current_geometry; if (!is_pure) { wants_full_relayout(); } } void set_current_geometry(Box current_geometry, bool is_pure) { m_current_geometry = current_geometry; if (!is_pure) { wants_full_relayout(); } }
std::vector<std::shared_ptr<Widget>> &get_children() { return m_children; } std::vector<std::shared_ptr<Widget>> &children() { return m_children; }
bool add_child(std::shared_ptr<Widget> child); bool add_child(std::shared_ptr<Widget> child);
void remove_child(std::shared_ptr<Widget> child); void remove_child(std::shared_ptr<Widget> child);
Widget *get_parent() { return m_parent; } Widget *parent() { return m_parent; }
void set_parent(Widget *parent) { m_parent = parent; } void set_parent(Widget *parent) { m_parent = parent; }
Window *get_window() { return m_window; } Window *window() { return m_window; }
void set_window(Window *window); void set_window(Window *window);
std::shared_ptr<TopLevelStyles> get_styles() { return m_styles; } std::shared_ptr<TopLevelStyles> styles() { return m_styles; }
void set_styles(std::shared_ptr<TopLevelStyles> styles) { m_styles = styles; wants_relayout(); } void set_styles(std::shared_ptr<TopLevelStyles> styles) { m_styles = styles; wants_relayout(); }
void set_did_init(bool did_init) { m_did_init = did_init; } void set_did_init(bool did_init) { m_did_init = did_init; }
bool get_did_init() { return m_did_init; } bool did_init() { return m_did_init; }
bool is_focused() { return m_is_focused; } bool is_focused() { return m_is_focused; }
bool is_active() { return m_is_active; } bool is_active() { return m_is_active; }
bool get_consumes_hits() { return m_consumes_hits; } bool consumes_hits() { return m_consumes_hits; }
void set_consumes_hits(bool consumes_hits) { m_consumes_hits = consumes_hits; } void set_consumes_hits(bool consumes_hits) { m_consumes_hits = consumes_hits; }
bool get_accepts_events() { return m_accepts_events; } bool accepts_events() { return m_accepts_events; }
void set_accepts_events(bool accepts_events) { m_accepts_events = accepts_events; } void set_accepts_events(bool accepts_events) { m_accepts_events = accepts_events; }
void set_layout(std::shared_ptr<Layout> layout); void set_layout(std::shared_ptr<Layout> layout);
std::shared_ptr<Layout> get_layout() { return m_layout; } std::shared_ptr<Layout> layout() { return m_layout; }
WidgetType get_type() { return m_type; } WidgetType type() { return m_type; }
ControlWidgetType get_control_type() { return m_control_type; } ControlWidgetType control_type() { return m_control_type; }
void dispatch_event(Event &event); void dispatch_event(Event &event);
void wants_repaint(); void wants_repaint();

View file

@ -33,8 +33,8 @@ bool Window::spawn_window() {
DefaultRootWindow(dsp), DefaultRootWindow(dsp),
0, 0,
0, 0,
m_current_geometry.get_width(), m_current_geometry.width(),
m_current_geometry.get_height(), m_current_geometry.height(),
0, 0,
0, 0,
CopyFromParent, CopyFromParent,
@ -50,8 +50,8 @@ bool Window::spawn_window() {
dsp, dsp,
da, da,
DefaultVisual(dsp, screen), DefaultVisual(dsp, screen),
get_current_geometry().get_width(), current_geometry().width(),
get_current_geometry().get_height() current_geometry().height()
); );
auto cairo_context = Cairo::Context::create(m_xlib_surface); auto cairo_context = Cairo::Context::create(m_xlib_surface);
@ -103,14 +103,14 @@ void Window::run(bool block) {
break; break;
} }
case ConfigureNotify: { case ConfigureNotify: {
if (e.xconfigure.width != m_current_geometry.get_width() || e.xconfigure.height != m_current_geometry.get_height()) { if (e.xconfigure.width != m_current_geometry.width() || e.xconfigure.height != m_current_geometry.height()) {
m_xlib_surface->set_size(e.xconfigure.width, e.xconfigure.height); m_xlib_surface->set_size(e.xconfigure.width, e.xconfigure.height);
m_current_geometry.set_width(e.xconfigure.width); m_current_geometry.set_width(e.xconfigure.width);
m_current_geometry.set_height(e.xconfigure.height); m_current_geometry.set_height(e.xconfigure.height);
// if we have a main widget, we are going to have to resize it as well // if we have a main widget, we are going to have to resize it as well
if (m_main_widget) { if (m_main_widget) {
m_main_widget->get_current_geometry().set_width(m_current_geometry.get_width()); m_main_widget->current_geometry().set_width(m_current_geometry.width());
m_main_widget->get_current_geometry().set_height(m_current_geometry.get_height()); m_main_widget->current_geometry().set_height(m_current_geometry.height());
} }
dispatch_full_repaint(); dispatch_full_repaint();
} }

View file

@ -23,18 +23,18 @@ private:
public: public:
Window() {} Window() {}
Painter &get_painter() { return m_painter; } Painter &painter() { return m_painter; }
Widget *get_focused_widget() { return m_focused_widget; } Widget *focused_widget() { return m_focused_widget; }
void set_focused_widget(Widget *focused_widget) { m_focused_widget = focused_widget; } void set_focused_widget(Widget *focused_widget) { m_focused_widget = focused_widget; }
Widget *get_active_widget() { return m_active_widget; } Widget *active_widget() { return m_active_widget; }
void set_active_widget(Widget *active_widget) { m_active_widget = active_widget; } void set_active_widget(Widget *active_widget) { m_active_widget = active_widget; }
std::shared_ptr<Widget> get_main_widget() { return m_main_widget; } std::shared_ptr<Widget> main_widget() { return m_main_widget; }
void set_main_widget(std::shared_ptr<Widget> main_widget); void set_main_widget(std::shared_ptr<Widget> main_widget);
std::shared_ptr<TopLevelStyles> get_top_level_styles() { return m_top_level_styles; } std::shared_ptr<TopLevelStyles> top_level_styles() { return m_top_level_styles; }
void widget_repaint(Widget *target); void widget_repaint(Widget *target);
void widget_relayout(Widget *target); void widget_relayout(Widget *target);
@ -44,7 +44,7 @@ public:
bool dispatch_full_relayout(); bool dispatch_full_relayout();
bool dispatch_to_main_widget(Event &event); bool dispatch_to_main_widget(Event &event);
Box &get_current_geometry() { return m_current_geometry; } Box &current_geometry() { return m_current_geometry; }
bool spawn_window(); bool spawn_window();
void run(bool block); void run(bool block);