remove SvgWidget, as it is now a part of Raven

This commit is contained in:
hippoz 2022-07-27 03:27:15 +03:00
parent 2b1706a41a
commit 2d20a59a8c
No known key found for this signature in database
GPG key ID: 7C52899193467641
4 changed files with 1 additions and 91 deletions

View file

@ -9,7 +9,6 @@ librsvg_dep = dependency('librsvg-2.0')
executable( executable(
'filemanager', 'filemanager',
'./src/SvgWidget.cpp',
'./src/FileButton.cpp', './src/FileButton.cpp',
'./src/DirectoryView.cpp', './src/DirectoryView.cpp',
'./src/main.cpp', './src/main.cpp',

View file

@ -22,7 +22,7 @@ void FileButton::on_init() {
layout->slot_percent(100); // icon layout->slot_percent(100); // icon
layout->slot_pixel(24); // name (text) layout->slot_pixel(24); // name (text)
add<SvgWidget>("folder-adwaita.svg"); add<Raven::SvgWidget>("folder-adwaita.svg");
auto label = add<Raven::Label>(m_name, Raven::PaintTextAlign::Center); auto label = add<Raven::Label>(m_name, Raven::PaintTextAlign::Center);
label->rect().set_max_width(rect().width()); label->rect().set_max_width(rect().width());
label->rect().set_max_height(24); label->rect().set_max_height(24);

View file

@ -1,55 +0,0 @@
#include "SvgWidget.hpp"
#include "cairomm/context.h"
#include "cairomm/enums.h"
#include "cairomm/surface.h"
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(&Raven::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,34 +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"
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 };
};