Compare commits

..

No commits in common. "a7051174a99c7fcff1e0caf961806530b670ed5c" and "cc1d49c43523b60f3c428b4ef0e7cd506a20163d" have entirely different histories.

6 changed files with 1 additions and 105 deletions

View file

@ -11,7 +11,6 @@ Raven is a simple user interface library.
- pango - pango
- pangocairo - pangocairo
- xlib - xlib
- librsvg
# Installing # Installing

View file

@ -10,13 +10,11 @@ add_project_arguments('-g3', language : 'cpp')
cairomm_dep = dependency('cairomm-1.0') cairomm_dep = dependency('cairomm-1.0')
pangocairo_dep = dependency('pangocairo') pangocairo_dep = dependency('pangocairo')
xlib_dep = dependency('x11') xlib_dep = dependency('x11')
librsvg_dep = dependency('librsvg-2.0')
raven_dependencies = [ raven_dependencies = [
cairomm_dep, cairomm_dep,
xlib_dep, xlib_dep,
pangocairo_dep, pangocairo_dep
librsvg_dep
] ]
headers = include_directories('src') headers = include_directories('src')
@ -27,7 +25,6 @@ raven_source_files = [
'./src/Painter.cpp', './src/Painter.cpp',
'./src/Window.cpp', './src/Window.cpp',
'./src/Widget.cpp', './src/Widget.cpp',
'./src/SvgWidget.cpp',
'./src/ScrollContainer.cpp', './src/ScrollContainer.cpp',
'./src/Button.cpp', './src/Button.cpp',
'./src/DocumentLayout.cpp', './src/DocumentLayout.cpp',
@ -55,7 +52,6 @@ raven_header_files = [
'./src/ScrollContainer.hpp', './src/ScrollContainer.hpp',
'./src/Styles.hpp', './src/Styles.hpp',
'./src/Widget.hpp', './src/Widget.hpp',
'./src/SvgWidget.hpp',
'./src/Window.hpp' './src/Window.hpp'
] ]

View file

@ -1,59 +0,0 @@
#include "SvgWidget.hpp"
#include "cairomm/context.h"
#include "cairomm/enums.h"
#include "cairomm/surface.h"
namespace Raven {
void SvgWidget::on_init() {
m_file = g_file_new_for_path(m_path.c_str());
m_handle = rsvg_handle_new_from_gfile_sync(m_file, RSVG_HANDLE_FLAGS_NONE, NULL, NULL);
set_style(&clear_widget_style);
if (!m_handle) {
std::cerr << "could not load svg file: " << m_path << std::endl;
exit(EXIT_FAILURE);
}
set_did_init(true);
}
void SvgWidget::on_after_layout() {
auto width = rect().width();
auto height = rect().height();
if (width == m_known_width && height == m_known_height) {
return;
}
m_known_width = width;
m_known_height = height;
RsvgRectangle viewport = {
.x = 0.0,
.y = 0.0,
.width = width,
.height = height,
};
m_image_surface = Cairo::ImageSurface::create(Cairo::Format::FORMAT_ARGB32, width, height);
m_image_context = Cairo::Context::create(m_image_surface);
rsvg_handle_render_document(m_handle, m_image_context->cobj(), &viewport, NULL);
}
void SvgWidget::on_paint() {
if (!m_image_surface)
return;
painter()->cairo()->set_source(m_image_surface, 0, 0);
painter()->cairo()->paint();
}
SvgWidget::~SvgWidget() {
g_object_unref(m_file);
g_object_unref(m_handle);
}
}

View file

@ -1,37 +0,0 @@
#pragma once
#include <string>
#include "cairomm/context.h"
#include "cairomm/enums.h"
#include "cairomm/refptr.h"
#include "cairomm/surface.h"
#include "raven/Widget.hpp"
#include "librsvg/rsvg.h"
namespace Raven {
class SvgWidget : public Raven::Widget {
public:
SvgWidget(std::string path)
: Raven::Widget()
, m_path(path) {}
~SvgWidget();
std::string &path() { return m_path; }
void set_path(std::string path) { m_path = path; repaint(); }
protected:
void on_init();
void on_after_layout();
void on_paint();
private:
std::string m_path;
RsvgHandle *m_handle;
GFile *m_file;
Cairo::RefPtr<Cairo::Context> m_image_context;
Cairo::RefPtr<Cairo::ImageSurface> m_image_surface;
double m_known_width { 0.0 };
double m_known_height { 0.0 };
};
}

View file

@ -202,8 +202,6 @@ void Widget::handle_relayout_subtree(RelayoutSubtreeEvent &event) {
for (auto child : m_children) { for (auto child : m_children) {
child->dispatch_event(event); child->dispatch_event(event);
} }
on_after_layout();
} }
void Widget::handle_mouse_move_event(MouseMoveEvent &event) { void Widget::handle_mouse_move_event(MouseMoveEvent &event) {

View file

@ -119,7 +119,6 @@ protected:
virtual void on_activation_update(ActivationUpdateEvent &event) {} virtual void on_activation_update(ActivationUpdateEvent &event) {}
virtual void on_paint() {} virtual void on_paint() {}
virtual void on_layout() {} virtual void on_layout() {}
virtual void on_after_layout() {}
void set_did_init(bool did_init) { m_did_init = did_init; } void set_did_init(bool did_init) { m_did_init = did_init; }
Point compute_window_relative(); Point compute_window_relative();