From 2cc5e1c1e053c2622b2ad351e93e2736b8ee5c1f Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Tue, 8 Mar 2022 02:25:22 +0200 Subject: [PATCH] basic structure --- meson.build | 11 +- src/Box.cpp | 14 ++ src/Box.hpp | 36 +++++ src/Events.cpp | 0 src/Events.hpp | 54 +++++++ src/Painter.cpp | 0 src/Painter.hpp | 9 ++ src/Point.cpp | 0 src/Point.hpp | 23 +++ src/Widget.cpp | 0 src/Widget.hpp | 18 +++ src/Window.cpp | 37 +++++ src/Window.hpp | 22 +++ src/_main_old.cpp | 357 ++++++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 341 +------------------------------------------ 15 files changed, 585 insertions(+), 337 deletions(-) create mode 100644 src/Box.cpp create mode 100644 src/Box.hpp create mode 100644 src/Events.cpp create mode 100644 src/Events.hpp create mode 100644 src/Painter.cpp create mode 100644 src/Painter.hpp create mode 100644 src/Point.cpp create mode 100644 src/Point.hpp create mode 100644 src/Widget.cpp create mode 100644 src/Widget.hpp create mode 100644 src/Window.cpp create mode 100644 src/Window.hpp create mode 100644 src/_main_old.cpp diff --git a/meson.build b/meson.build index 0c58a1c..bbf25d7 100644 --- a/meson.build +++ b/meson.build @@ -5,4 +5,13 @@ cairomm_dep = dependency('cairomm-1.0') pangocairo_dep = dependency('pangocairo') xlib_dep = dependency('x11') -executable('blit_app', './src/main.cpp', dependencies : [cairomm_dep, xlib_dep, pangocairo_dep]) \ No newline at end of file +executable( + 'blit_app', + './src/Box.cpp', + './src/Point.cpp', + './src/Events.cpp', + './src/Widget.cpp', + './src/Window.cpp', + './src/main.cpp', + dependencies : [cairomm_dep, xlib_dep, pangocairo_dep] +) diff --git a/src/Box.cpp b/src/Box.cpp new file mode 100644 index 0000000..05c890f --- /dev/null +++ b/src/Box.cpp @@ -0,0 +1,14 @@ +#include "Box.hpp" + +namespace Raven { + +bool Box::contains_point(double x, double y) { + return x >= m_x && m_x + m_width >= x && y >= m_y && m_y + m_height >= y; +} + +bool Box::contains_box(const Box &other) { + // FIXME + return false; +} + +} diff --git a/src/Box.hpp b/src/Box.hpp new file mode 100644 index 0000000..34aead3 --- /dev/null +++ b/src/Box.hpp @@ -0,0 +1,36 @@ +#pragma once + +namespace Raven { + +class Box { +private: + double m_x {0}; + double m_y {0}; + double m_width {0}; + double m_height {0}; +public: + Box() {} + Box(double x, double y, double width, double height) + : m_x(x) + , m_y(y) + , m_width(width) + , m_height(height) + { + + } + + double get_x() { return m_x; } + double get_y() { return m_y; } + double get_width() { return m_width; } + double get_height() { return m_height; } + + void set_x(double x) { m_x = x; } + void set_y(double y) { m_y = y; } + void set_width(double width) { m_width = width; } + void set_height(double height) { m_height = height; } + + bool contains_point(double x, double y); + bool contains_box(const Box &other); +}; + +} diff --git a/src/Events.cpp b/src/Events.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/Events.hpp b/src/Events.hpp new file mode 100644 index 0000000..ba63f5a --- /dev/null +++ b/src/Events.hpp @@ -0,0 +1,54 @@ +#include +#include "Point.hpp" + +namespace Raven { + +enum class EventType { + None, + + MouseButton, + MouseMove +}; + +class Event { +private: + bool m_accepted { false }; +public: + Event() {} + + void accept() { m_accepted = true; } + bool is_accepted() { return m_accepted; } + virtual EventType get_event_type() { return EventType::None; } + virtual const char *get_event_name() { return "None"; } +}; + +class MouseButtonEvent : public Event { +private: + bool m_was_left_button_pressed; + bool m_was_right_button_pressed; +public: + MouseButtonEvent(bool was_left_button_pressed, bool was_right_button_pressed) + : m_was_left_button_pressed(was_left_button_pressed) + , m_was_right_button_pressed(was_right_button_pressed) {} + + EventType get_event_type() { return EventType::MouseButton; } + const char *get_event_name() { return "MouseButton"; } + + bool get_was_left_button_pressed() { return m_was_left_button_pressed; } + bool get_was_right_button_pressed() { return m_was_right_button_pressed; } +}; + +class MouseMoveEvent : public Event { +private: + Point m_point; +public: + MouseMoveEvent(Point point) + : m_point(point) {} + + EventType get_event_type() { return EventType::MouseMove; } + const char *get_event_name() { return "MouseMove"; } + + Point &get_point() { return m_point; } +}; + +} \ No newline at end of file diff --git a/src/Painter.cpp b/src/Painter.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/Painter.hpp b/src/Painter.hpp new file mode 100644 index 0000000..2173cea --- /dev/null +++ b/src/Painter.hpp @@ -0,0 +1,9 @@ +namespace Raven { + +class Painter { + Painter() { + + } +}; + +} \ No newline at end of file diff --git a/src/Point.cpp b/src/Point.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/Point.hpp b/src/Point.hpp new file mode 100644 index 0000000..7cda038 --- /dev/null +++ b/src/Point.hpp @@ -0,0 +1,23 @@ +#include + +namespace Raven { + +class Point { +private: + int m_x; + int m_y; +public: + Point(int x, int y) + : m_x(x) + , m_y(y) {} + + int get_x() { return m_x; } + const int get_x() const { return m_x; } + int get_y() { return m_y; } + const int get_y() const { return m_y; } + + void set_x(int x) { m_x = x; } + void set_y(int y) { m_y = y; } +}; + +} \ No newline at end of file diff --git a/src/Widget.cpp b/src/Widget.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/Widget.hpp b/src/Widget.hpp new file mode 100644 index 0000000..0c4e4ac --- /dev/null +++ b/src/Widget.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include "Box.hpp" + +namespace Raven { + +class Widget { +private: + Box m_current_geometry {}; +public: + Widget() { + + } + + const Box &get_current_geometry() const { return m_current_geometry; } +}; + +} \ No newline at end of file diff --git a/src/Window.cpp b/src/Window.cpp new file mode 100644 index 0000000..83eb78b --- /dev/null +++ b/src/Window.cpp @@ -0,0 +1,37 @@ +#include +#include "Window.hpp" +#include +#include +#include +#include +#include + +namespace Raven { + +bool Window::spawn_window() { + Display *dsp; + Drawable da; + int screen; + + if ((dsp = XOpenDisplay(NULL)) == NULL) { + std::cout << "error: XOpenDisplay(NULL)" << "\n"; + return false; + } + + screen = DefaultScreen(dsp); + da = XCreateSimpleWindow(dsp, DefaultRootWindow(dsp), 0, 0, get_current_geometry().get_width(), get_current_geometry().get_height(), 0, 0, 0); + XSelectInput(dsp, da, ButtonPressMask | ButtonReleaseMask | KeyPressMask | PointerMotionMask); + XMapWindow(dsp, da); + auto x_surface = Cairo::XlibSurface::create( + dsp, + da, + DefaultVisual(dsp, screen), + get_current_geometry().get_width(), + get_current_geometry().get_height() + ); + Cairo::Context::create(x_surface); + + return true; +} + +} \ No newline at end of file diff --git a/src/Window.hpp b/src/Window.hpp new file mode 100644 index 0000000..294863e --- /dev/null +++ b/src/Window.hpp @@ -0,0 +1,22 @@ +#include "Widget.hpp" + +namespace Raven { + +class Window { +private: + Widget *m_active_widget { nullptr }; + Box m_current_geometry { 0, 0, 800, 600 }; +public: + Window() { + + } + + Widget *get_active_widget() { return m_active_widget; } + void set_active_widget(Widget *active_widget) { m_active_widget = active_widget; } + Box &get_current_geometry() { return m_current_geometry; } + + bool spawn_window(); + void window_event_loop(); +}; + +} diff --git a/src/_main_old.cpp b/src/_main_old.cpp new file mode 100644 index 0000000..ebc03d7 --- /dev/null +++ b/src/_main_old.cpp @@ -0,0 +1,357 @@ +#include +#include +#include +#include +#include +#include +#include + + +void panic(int exit_code, const char *message) { + fputs(message, stderr); + exit(exit_code); +} + +namespace Blit { + +bool collide_point_rect(double x, double y, double w, double h, double x1, double y1) { + return x1 >= x && x + w >= x1 && + y1 >= y && y + h >= y1; +} + + +enum TextAlign { + TEXT_ALIGN_NONE, + TEXT_ALIGN_CENTER_LEFT, + TEXT_ALIGN_CENTER +}; + + +class RGB { +public: + double r, g, b; +public: + RGB(double r, double g, double b) : r(r), g(g), b(b) { + + } +}; + + +class BaseElement { +public: + std::vector> bound_elements; + + BaseElement() {} + virtual ~BaseElement() {} + + bool should_get_x_events = true; + virtual void on_draw() = 0; + virtual void handle_event(XEvent *e) = 0; + + void draw() { + on_draw(); + for (auto i : bound_elements) { + i.get().draw(); + } + } + + void bind_element(BaseElement &other) { + bound_elements.push_back(other); + } +}; + + +class Window { +public: + Cairo::RefPtr cr; + Display *dsp; +private: + std::vector m_attached_elements; +public: + Window(int x, int y) + { + Drawable da; + int screen; + + if ((dsp = XOpenDisplay(NULL)) == NULL) + panic(1, "Failed to open display"); + + screen = DefaultScreen(dsp); + da = XCreateSimpleWindow(dsp, DefaultRootWindow(dsp), 0, 0, x, y, 0, 0, 0); + XSelectInput(dsp, da, ButtonPressMask | ButtonReleaseMask | KeyPressMask | PointerMotionMask); + XMapWindow(dsp, da); + + auto x_surface = Cairo::XlibSurface::create( + dsp, + da, + DefaultVisual(dsp, screen), + x, + y + ); + cr = Cairo::Context::create(x_surface); + } + + void attach_element_init(Blit::BaseElement *element) { + m_attached_elements.push_back(element); + } + + void attach_element(Blit::BaseElement *element) { + m_attached_elements.push_back(element); + element->draw(); + } + + void redraw_all() { + for (Blit::BaseElement * element : m_attached_elements) { + element->draw(); + } + } + + void handle_x_event(XEvent *e) { + for (Blit::BaseElement * element : m_attached_elements) { + if (element->should_get_x_events) + element->handle_event(e); + } + } +}; + + +class Text : public BaseElement { +public: + PangoFontDescription *font_description; + bool should_get_x_events = false; + Blit::TextAlign text_align = Blit::TextAlign::TEXT_ALIGN_NONE; + double x, y, box_x, box_y, box_w, box_h = 0; + std::string text; + Blit::RGB fg; + + Cairo::RefPtr cr; +public: + Text(Cairo::RefPtr cr, std::string& text, PangoFontDescription *font_description) : + cr(cr), + text(text), + font_description(font_description), + fg(0.0, 0.0, 0.0) + {} + + virtual ~Text() {} + + void on_draw() { + cr->save(); + cr->set_source_rgb(fg.r, fg.g, fg.b); + + if (text_align == Blit::TextAlign::TEXT_ALIGN_NONE) { + PangoLayout *layout = pango_cairo_create_layout(cr->cobj()); + pango_layout_set_font_description(layout, font_description); + pango_layout_set_text(layout, text.c_str(), -1); + cr->move_to(x, y); + pango_cairo_show_layout(cr->cobj(), layout); + g_object_unref(layout); + } else if (text_align == Blit::TextAlign::TEXT_ALIGN_CENTER_LEFT) { + PangoLayout *layout = pango_cairo_create_layout(cr->cobj()); + int font_width; + int font_height; + + pango_layout_set_font_description(layout, font_description); + pango_layout_set_text(layout, text.c_str(), -1); + pango_layout_get_pixel_size(layout, &font_width, &font_height); + + double x = box_x + ((box_w - font_width) / 2); + double y = box_y + ((box_h - font_height) / 2); + + // TODO: unhardcode the padding + x = box_x + 4; + + cr->move_to(x, y); + pango_cairo_show_layout(cr->cobj(), layout); + g_object_unref(layout); + } else if (text_align == Blit::TextAlign::TEXT_ALIGN_CENTER) { + PangoLayout *layout = pango_cairo_create_layout(cr->cobj()); + int font_width; + int font_height; + + pango_layout_set_font_description(layout, font_description); + pango_layout_set_text(layout, text.c_str(), -1); + pango_layout_get_pixel_size(layout, &font_width, &font_height); + + double x = box_x + ((box_w - font_width) / 2); + double y = box_y + ((box_h - font_height) / 2); + + cr->move_to(x, y); + pango_cairo_show_layout(cr->cobj(), layout); + g_object_unref(layout); + } + + cr->fill(); + cr->restore(); + } + + void handle_event(XEvent *e) {} + + void set_x(double val) { + x = val; + draw(); + } + void set_y(double val) { + y = val; + draw(); + } + void set_box_x(double val) { + box_x = val; + draw(); + } + void set_box_y(double val) { + box_y = val; + draw(); + } + void set_box_w(double val) { + box_w = val; + draw(); + } + void set_box_h(double val) { + box_h = val; + draw(); + } + void set_text(std::string& text) { + text = text; + draw(); + } + void set_text_align(Blit::TextAlign val) { + text_align = val; + draw(); + } + void set_current_fg(Blit::RGB val) { + fg = val; + draw(); + } +}; + + +class Button : public BaseElement { +public: + bool should_get_x_events = true; + double x, y, w, h, border_radius = 0; + Blit::RGB current_bg, bg, sel_bg; + + bool is_hot, is_active = false; + + Cairo::RefPtr cr; +public: + Button(Cairo::RefPtr cr) : + should_get_x_events(true), + current_bg(0.0, 0.0, 0.0), + sel_bg(0.0, 0.0, 0.0), + bg(0.0, 0.0, 0.0), + cr(cr) + {} + + virtual ~Button() {} + + void on_draw() { + cr->save(); + cr->set_source_rgb(current_bg.r, current_bg.g, current_bg.b); + if (border_radius > 0) { + double aspect = 1.0; + double radius = border_radius / aspect; + double degrees = M_PI / 180.0; + + cr->begin_new_sub_path(); + cr->arc(x + w - radius, y + radius, radius, -90 * degrees, 0 * degrees); + cr->arc(x + w - radius, y + h - radius, radius, 0 * degrees, 90 * degrees); + cr->arc(x + radius, y + h - radius, radius, 90 * degrees, 180 * degrees); + cr->arc(x + radius, y + radius, radius, 180 * degrees, 270 * degrees); + cr->close_path(); + } else { + cr->rectangle(x, y, w, h); + } + cr->fill(); + cr->restore(); + } + + void handle_event(XEvent *e) { + char keybuf[8]; + KeySym key; + + switch (e->type) { + case MotionNotify: + bool is_hot_now = Blit::collide_point_rect(x, y, w, h, e->xmotion.x, e->xmotion.y); + if (!is_hot && is_hot_now) { // just became hot + set_current_bg(sel_bg); + is_hot = true; + } else if (is_hot && !is_hot_now) { // just became not hot + set_current_bg(bg); + is_hot = false; + } + break; + } + } + + void set_x(double val) { + x = val; + draw(); + } + void set_y(double val) { + y = val; + draw(); + } + void set_w(double val) { + w = val; + draw(); + } + void set_h(double val) { + h = val; + draw(); + } + void set_border_radius(double val) { + border_radius = val; + draw(); + } + void set_current_bg(Blit::RGB val) { + current_bg = val; + draw(); + } +}; + +} + +int main() { + std::string text = "click me now"; + XEvent e; + PangoFontDescription *font_description = pango_font_description_new(); + + pango_font_description_set_family(font_description, "sans-serif"); + pango_font_description_set_weight(font_description, PANGO_WEIGHT_NORMAL); + pango_font_description_set_absolute_size(font_description, 16 * PANGO_SCALE); + + Blit::Window window(800, 600); + Blit::Button button(window.cr); + Blit::Text button_text(window.cr, text, font_description); + + button.x = 20.0; + button.y = 20.0; + button.w = 100.0; + button.h = 30.0; + button.border_radius = 0.0; + button.bg = Blit::RGB(1.0, 0.0, 0.0); + button.sel_bg = Blit::RGB(0.0, 1.0, 0.0); + + button_text.x = button.x; + button_text.y = button.y; + button_text.box_x = button.x; + button_text.box_y = button.y; + button_text.box_w = button.w; + button_text.box_h = button.h; + button_text.fg = Blit::RGB(1.0, 1.0, 1.0); + button_text.text_align = Blit::TextAlign::TEXT_ALIGN_CENTER; + + button.bind_element(button_text); + + window.attach_element(&button); + window.attach_element(&button_text); + + for (;;) { + XNextEvent(window.dsp, &e); + window.handle_x_event(&e); + } + + return 0; +} diff --git a/src/main.cpp b/src/main.cpp index 0ff8d19..f086965 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,342 +1,11 @@ -#include -#include #include -#include -#include -#include -#include - - -void panic(int exit_code, const char *message) { - fputs(message, stderr); - exit(exit_code); -} - -namespace Blit { - -bool collide_point_rect(double x, double y, double w, double h, double x1, double y1) { - return x1 >= x && x + w >= x1 && - y1 >= y && y + h >= y1; -} - - -enum TextAlign { - TEXT_ALIGN_NONE, - TEXT_ALIGN_CENTER_LEFT, - TEXT_ALIGN_CENTER -}; - - -class RGB { -public: - double r, g, b; -public: - RGB(double r, double g, double b) : r(r), g(g), b(b) { - - } -}; - - -class BaseElement { -public: - BaseElement() {} - virtual ~BaseElement() {} - - bool should_get_x_events = true; - virtual void draw() = 0; - virtual void handle_event(XEvent *e) = 0; -}; - - -class Window { -public: - Cairo::RefPtr cr; - Display *dsp; -private: - std::vector m_attached_elements; -public: - Window(int x, int y) - { - Drawable da; - int screen; - - if ((dsp = XOpenDisplay(NULL)) == NULL) - panic(1, "Failed to open display"); - - screen = DefaultScreen(dsp); - da = XCreateSimpleWindow(dsp, DefaultRootWindow(dsp), 0, 0, x, y, 0, 0, 0); - XSelectInput(dsp, da, ButtonPressMask | ButtonReleaseMask | KeyPressMask | PointerMotionMask); - XMapWindow(dsp, da); - - auto x_surface = Cairo::XlibSurface::create( - dsp, - da, - DefaultVisual(dsp, screen), - x, - y - ); - cr = Cairo::Context::create(x_surface); - } - - void attach_element_init(Blit::BaseElement *element) { - m_attached_elements.push_back(element); - } - - void attach_element(Blit::BaseElement *element) { - m_attached_elements.push_back(element); - element->draw(); - } - - void redraw_all() { - for (Blit::BaseElement * element : m_attached_elements) { - element->draw(); - } - } - - void handle_x_event(XEvent *e) { - for (Blit::BaseElement * element : m_attached_elements) { - if (element->should_get_x_events) - element->handle_event(e); - } - } -}; - - -class Text : public BaseElement { -public: - PangoFontDescription *font_description; - bool should_get_x_events = false; - Blit::TextAlign text_align = Blit::TextAlign::TEXT_ALIGN_NONE; - double x, y, box_x, box_y, box_w, box_h = 0; - std::string text; - Blit::RGB fg; - - Cairo::RefPtr cr; -public: - Text(Cairo::RefPtr cr, std::string& text, PangoFontDescription *font_description) : - cr(cr), - text(text), - font_description(font_description), - fg(0.0, 0.0, 0.0) - {} - - virtual ~Text() {} - - void draw() { - cr->save(); - cr->set_source_rgb(fg.r, fg.g, fg.b); - - if (text_align == Blit::TextAlign::TEXT_ALIGN_NONE) { - PangoLayout *layout = pango_cairo_create_layout(cr->cobj()); - pango_layout_set_font_description(layout, font_description); - pango_layout_set_text(layout, text.c_str(), -1); - cr->move_to(x, y); - pango_cairo_show_layout(cr->cobj(), layout); - g_object_unref(layout); - } else if (text_align == Blit::TextAlign::TEXT_ALIGN_CENTER_LEFT) { - PangoLayout *layout = pango_cairo_create_layout(cr->cobj()); - int font_width; - int font_height; - - pango_layout_set_font_description(layout, font_description); - pango_layout_set_text(layout, text.c_str(), -1); - pango_layout_get_pixel_size(layout, &font_width, &font_height); - - double x = box_x + ((box_w - font_width) / 2); - double y = box_y + ((box_h - font_height) / 2); - - // TODO: unhardcode the padding - x = box_x + 4; - - cr->move_to(x, y); - pango_cairo_show_layout(cr->cobj(), layout); - g_object_unref(layout); - } else if (text_align == Blit::TextAlign::TEXT_ALIGN_CENTER) { - PangoLayout *layout = pango_cairo_create_layout(cr->cobj()); - int font_width; - int font_height; - - pango_layout_set_font_description(layout, font_description); - pango_layout_set_text(layout, text.c_str(), -1); - pango_layout_get_pixel_size(layout, &font_width, &font_height); - - double x = box_x + ((box_w - font_width) / 2); - double y = box_y + ((box_h - font_height) / 2); - - cr->move_to(x, y); - pango_cairo_show_layout(cr->cobj(), layout); - g_object_unref(layout); - } - - cr->fill(); - cr->restore(); - } - - void handle_event(XEvent *e) {} - - void set_x(double val) { - x = val; - draw(); - } - void set_y(double val) { - y = val; - draw(); - } - void set_box_x(double val) { - box_x = val; - draw(); - } - void set_box_y(double val) { - box_y = val; - draw(); - } - void set_box_w(double val) { - box_w = val; - draw(); - } - void set_box_h(double val) { - box_h = val; - draw(); - } - void set_text(std::string& text) { - text = text; - draw(); - } - void set_text_align(Blit::TextAlign val) { - text_align = val; - draw(); - } - void set_current_fg(Blit::RGB val) { - fg = val; - draw(); - } -}; - - -class Button : public BaseElement { -public: - bool should_get_x_events = true; - double x, y, w, h, border_radius = 0; - Blit::RGB current_bg, bg, sel_bg; - - bool is_hot, is_active = false; - - Cairo::RefPtr cr; -public: - Button(Cairo::RefPtr cr) : - should_get_x_events(true), - current_bg(0.0, 0.0, 0.0), - sel_bg(0.0, 0.0, 0.0), - bg(0.0, 0.0, 0.0), - cr(cr) - {} - - virtual ~Button() {} - - void draw() { - cr->save(); - cr->set_source_rgb(current_bg.r, current_bg.g, current_bg.b); - if (border_radius > 0) { - double aspect = 1.0; - double radius = border_radius / aspect; - double degrees = M_PI / 180.0; - - cr->begin_new_sub_path(); - cr->arc(x + w - radius, y + radius, radius, -90 * degrees, 0 * degrees); - cr->arc(x + w - radius, y + h - radius, radius, 0 * degrees, 90 * degrees); - cr->arc(x + radius, y + h - radius, radius, 90 * degrees, 180 * degrees); - cr->arc(x + radius, y + radius, radius, 180 * degrees, 270 * degrees); - cr->close_path(); - } else { - cr->rectangle(x, y, w, h); - } - cr->fill(); - cr->restore(); - } - - void handle_event(XEvent *e) { - char keybuf[8]; - KeySym key; - - switch (e->type) { - case MotionNotify: - bool is_hot_now = Blit::collide_point_rect(x, y, w, h, e->xmotion.x, e->xmotion.y); - if (!is_hot && is_hot_now) { // just became hot - set_current_bg(sel_bg); - is_hot = true; - } else if (is_hot && !is_hot_now) { // just became not hot - set_current_bg(bg); - is_hot = false; - } - break; - } - } - - void set_x(double val) { - x = val; - draw(); - } - void set_y(double val) { - y = val; - draw(); - } - void set_w(double val) { - w = val; - draw(); - } - void set_h(double val) { - h = val; - draw(); - } - void set_border_radius(double val) { - border_radius = val; - draw(); - } - void set_current_bg(Blit::RGB val) { - current_bg = val; - draw(); - } -}; - -} +#include "Window.hpp" int main() { - std::string text = "click me now"; - XEvent e; - PangoFontDescription *font_description = pango_font_description_new(); + Raven::Window window{}; - pango_font_description_set_family(font_description, "sans-serif"); - pango_font_description_set_weight(font_description, PANGO_WEIGHT_NORMAL); - pango_font_description_set_absolute_size(font_description, 16 * PANGO_SCALE); - - Blit::Window window(800, 600); - Blit::Button button(window.cr); - Blit::Text button_text(window.cr, text, font_description); - - button.x = 20.0; - button.y = 20.0; - button.w = 100.0; - button.h = 30.0; - button.border_radius = 0.0; - button.bg = Blit::RGB(1.0, 0.0, 0.0); - button.sel_bg = Blit::RGB(0.0, 1.0, 0.0); - - button_text.x = button.x; - button_text.y = button.y; - button_text.box_x = button.x; - button_text.box_y = button.y; - button_text.box_w = button.w; - button_text.box_h = button.h; - button_text.fg = Blit::RGB(1.0, 1.0, 1.0); - button_text.text_align = Blit::TextAlign::TEXT_ALIGN_CENTER; - - window.attach_element(&button); - window.attach_element(&button_text); - - for (;;) { - XNextEvent(window.dsp, &e); - window.handle_x_event(&e); - } + window.spawn_window(); + for(;;){} return 0; -} +} \ No newline at end of file