add png support
This commit is contained in:
parent
5663552527
commit
711c244ef2
7 changed files with 36 additions and 5 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@ buildclang/
|
||||||
releaseclang/
|
releaseclang/
|
||||||
.cache/
|
.cache/
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
pkgname=libraven
|
pkgname=libraven
|
||||||
pkgver=r84.2fa09ab
|
pkgver=r85.5663552
|
||||||
pkgrel=1
|
pkgrel=1
|
||||||
pkgdesc='The Raven user interface library'
|
pkgdesc='The Raven user interface library'
|
||||||
url='https://git.hippoz.xyz/hippoz/raven'
|
url='https://git.hippoz.xyz/hippoz/raven'
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "Painter.hpp"
|
#include "Painter.hpp"
|
||||||
#include "RGB.hpp"
|
#include "RGB.hpp"
|
||||||
|
#include "cairomm/surface.h"
|
||||||
#include "pango/pango-layout.h"
|
#include "pango/pango-layout.h"
|
||||||
#include "pango/pango-types.h"
|
#include "pango/pango-types.h"
|
||||||
#include "pango/pangocairo.h"
|
#include "pango/pangocairo.h"
|
||||||
|
@ -101,4 +102,11 @@ void Painter::flush_paint_group() {
|
||||||
m_cairo->get_target()->flush();
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ public:
|
||||||
bool can_paint() { if (m_cairo) return true; else return false; }
|
bool can_paint() { if (m_cairo) return true; else return false; }
|
||||||
|
|
||||||
void source_rgb(RGB source_rgb);
|
void source_rgb(RGB source_rgb);
|
||||||
|
Point png(std::string path);
|
||||||
void fill();
|
void fill();
|
||||||
|
|
||||||
void begin_paint_group();
|
void begin_paint_group();
|
||||||
|
|
|
@ -9,6 +9,14 @@
|
||||||
|
|
||||||
namespace Raven {
|
namespace Raven {
|
||||||
|
|
||||||
|
Painter *Widget::painter() {
|
||||||
|
if (!window()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return &window()->painter();
|
||||||
|
}
|
||||||
|
|
||||||
Point Widget::compute_window_relative() {
|
Point Widget::compute_window_relative() {
|
||||||
Point point = { 0, 0 };
|
Point point = { 0, 0 };
|
||||||
for (Widget* parent = m_parent; parent; parent = parent->parent()) {
|
for (Widget* parent = m_parent; parent; parent = parent->parent()) {
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "RGB.hpp"
|
#include "RGB.hpp"
|
||||||
#include "GenericStyle.hpp"
|
#include "GenericStyle.hpp"
|
||||||
#include "Styles.hpp"
|
#include "Styles.hpp"
|
||||||
|
#include "Window.hpp"
|
||||||
|
|
||||||
namespace Raven {
|
namespace Raven {
|
||||||
|
|
||||||
|
@ -70,6 +71,8 @@ public:
|
||||||
Window *window() { return m_window; }
|
Window *window() { return m_window; }
|
||||||
void set_window(Window *window);
|
void set_window(Window *window);
|
||||||
|
|
||||||
|
Painter *painter();
|
||||||
|
|
||||||
GenericStyle *style() { return m_style; }
|
GenericStyle *style() { return m_style; }
|
||||||
void set_style(GenericStyle *style) { m_style = style; reflow(); }
|
void set_style(GenericStyle *style) { m_style = style; reflow(); }
|
||||||
void set_style_pure(GenericStyle *style) { m_style = style; }
|
void set_style_pure(GenericStyle *style) { m_style = style; }
|
||||||
|
|
18
src/main.cpp
18
src/main.cpp
|
@ -16,6 +16,19 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
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() {
|
int main() {
|
||||||
Raven::Window window {};
|
Raven::Window window {};
|
||||||
window.spawn_window();
|
window.spawn_window();
|
||||||
|
@ -35,10 +48,7 @@ int main() {
|
||||||
auto new_button = top_bar->add<Raven::Button>("add");
|
auto new_button = top_bar->add<Raven::Button>("add");
|
||||||
new_button->rect().set_max_width(50);
|
new_button->rect().set_max_width(50);
|
||||||
new_button->on_click = [container_widget]() {
|
new_button->on_click = [container_widget]() {
|
||||||
auto button = container_widget->add<Raven::Button>("button");
|
container_widget->add<Fish>();
|
||||||
button->on_click = [button]() {
|
|
||||||
button->set_style(&Raven::accent_button_style);
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
auto remove_button = top_bar->add<Raven::Button>("remove");
|
auto remove_button = top_bar->add<Raven::Button>("remove");
|
||||||
remove_button->on_click = [container_widget]() {
|
remove_button->on_click = [container_widget]() {
|
||||||
|
|
Loading…
Reference in a new issue