Can now display SVGs, also fixed bad function call bug when taking screenshot
This commit is contained in:
parent
6d8d532952
commit
91603e1fc1
9 changed files with 70 additions and 28 deletions
43
src/ResourceDisplay/SvgResourceDisplay.cpp
Normal file
43
src/ResourceDisplay/SvgResourceDisplay.cpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#include "SvgResourceDisplay.hpp"
|
||||
#include "../MainProgram.hpp"
|
||||
#include <Helpers/Logger.hpp>
|
||||
#include <include/core/SkStream.h>
|
||||
#include <modules/svg/include/SkSVGRenderContext.h>
|
||||
|
||||
bool SvgResourceDisplay::update_draw() const {
|
||||
return mustUpdateDraw;
|
||||
}
|
||||
|
||||
void SvgResourceDisplay::update(World& w) {
|
||||
mustUpdateDraw = false;
|
||||
}
|
||||
|
||||
bool SvgResourceDisplay::load(const std::string& fileName, const std::string& fileData) {
|
||||
SkMemoryStream strm(fileData.c_str(), fileData.size());
|
||||
svgDom = SkSVGDOM::Builder().make(strm);
|
||||
|
||||
mustUpdateDraw = true;
|
||||
|
||||
if(!svgDom)
|
||||
return false;
|
||||
|
||||
svgRootSize = svgDom->containerSize();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SvgResourceDisplay::draw(SkCanvas* canvas, const DrawData& drawData, const SkRect& imRect) {
|
||||
canvas->save();
|
||||
canvas->translate(imRect.x(), imRect.y());
|
||||
canvas->scale(imRect.width() / svgRootSize.width(), imRect.height() / svgRootSize.height());
|
||||
svgDom->render(canvas);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
Vector2f SvgResourceDisplay::get_dimensions() const {
|
||||
return {svgRootSize.width(), svgRootSize.height()};
|
||||
}
|
||||
|
||||
float SvgResourceDisplay::get_dimension_scale() const {
|
||||
return 0.3f;
|
||||
}
|
||||
19
src/ResourceDisplay/SvgResourceDisplay.hpp
Normal file
19
src/ResourceDisplay/SvgResourceDisplay.hpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
#include "ResourceDisplay.hpp"
|
||||
#include <include/core/SkImage.h>
|
||||
#include <vector>
|
||||
#include <modules/svg/include/SkSVGDOM.h>
|
||||
|
||||
class SvgResourceDisplay : public ResourceDisplay {
|
||||
public:
|
||||
virtual void update(World& w) override;
|
||||
virtual bool load(const std::string& fileName, const std::string& fileData) override;
|
||||
virtual bool update_draw() const override;
|
||||
virtual void draw(SkCanvas* canvas, const DrawData& drawData, const SkRect& imRect) override;
|
||||
virtual Vector2f get_dimensions() const override;
|
||||
virtual float get_dimension_scale() const override;
|
||||
private:
|
||||
sk_sp<SkSVGDOM> svgDom;
|
||||
bool mustUpdateDraw = false;
|
||||
SkSize svgRootSize;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue