diff --git a/.gitignore b/.gitignore index 5fc81ac..85b5aa7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ buildclang/ releaseclang/ .cache/ compile_commands.json + diff --git a/pkg/makepkg/PKGBUILD b/pkg/makepkg/PKGBUILD index 2cb9ece..9c5030a 100644 --- a/pkg/makepkg/PKGBUILD +++ b/pkg/makepkg/PKGBUILD @@ -1,5 +1,5 @@ pkgname=libraven -pkgver=r84.2fa09ab +pkgver=r85.5663552 pkgrel=1 pkgdesc='The Raven user interface library' url='https://git.hippoz.xyz/hippoz/raven' diff --git a/src/Painter.cpp b/src/Painter.cpp index 8af132b..bc49c05 100644 --- a/src/Painter.cpp +++ b/src/Painter.cpp @@ -1,5 +1,6 @@ #include "Painter.hpp" #include "RGB.hpp" +#include "cairomm/surface.h" #include "pango/pango-layout.h" #include "pango/pango-types.h" #include "pango/pangocairo.h" @@ -101,4 +102,11 @@ void Painter::flush_paint_group() { m_cairo->get_target()->flush(); } +Point Painter::png(std::string path) { + auto image = Cairo::ImageSurface::create_from_png(path.c_str()); + m_cairo->set_source(image, 0, 0); + + return Point(image->get_width(), image->get_height()); +} + } diff --git a/src/Painter.hpp b/src/Painter.hpp index b862104..024d554 100644 --- a/src/Painter.hpp +++ b/src/Painter.hpp @@ -30,6 +30,7 @@ public: bool can_paint() { if (m_cairo) return true; else return false; } void source_rgb(RGB source_rgb); + Point png(std::string path); void fill(); void begin_paint_group(); diff --git a/src/Widget.cpp b/src/Widget.cpp index 0854689..578c41e 100644 --- a/src/Widget.cpp +++ b/src/Widget.cpp @@ -9,6 +9,14 @@ namespace Raven { +Painter *Widget::painter() { + if (!window()) { + return nullptr; + } + + return &window()->painter(); +} + Point Widget::compute_window_relative() { Point point = { 0, 0 }; for (Widget* parent = m_parent; parent; parent = parent->parent()) { diff --git a/src/Widget.hpp b/src/Widget.hpp index 3e882c6..4a43944 100644 --- a/src/Widget.hpp +++ b/src/Widget.hpp @@ -11,6 +11,7 @@ #include "RGB.hpp" #include "GenericStyle.hpp" #include "Styles.hpp" +#include "Window.hpp" namespace Raven { @@ -70,6 +71,8 @@ public: Window *window() { return m_window; } void set_window(Window *window); + Painter *painter(); + GenericStyle *style() { return m_style; } void set_style(GenericStyle *style) { m_style = style; reflow(); } void set_style_pure(GenericStyle *style) { m_style = style; } diff --git a/src/main.cpp b/src/main.cpp index 24e3861..803876b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,6 +16,19 @@ #include #include +class Fish : public Raven::Widget { +public: + Fish() + : Raven::Widget() {} +protected: + void on_paint() { + if (!painter()) return; + + painter()->png("tuna.png"); + painter()->cairo()->paint(); + } +}; + int main() { Raven::Window window {}; window.spawn_window(); @@ -35,10 +48,7 @@ int main() { auto new_button = top_bar->add("add"); new_button->rect().set_max_width(50); new_button->on_click = [container_widget]() { - auto button = container_widget->add("button"); - button->on_click = [button]() { - button->set_style(&Raven::accent_button_style); - }; + container_widget->add(); }; auto remove_button = top_bar->add("remove"); remove_button->on_click = [container_widget]() {