Can render SVGs that have relative sizes, also clip SVGs that go out of bounds
This commit is contained in:
parent
91603e1fc1
commit
d91c7e987f
10 changed files with 23 additions and 12 deletions
|
|
@ -17,7 +17,7 @@ bool FileResourceDisplay::update_draw() const {
|
|||
void FileResourceDisplay::update(World& w) {
|
||||
}
|
||||
|
||||
bool FileResourceDisplay::load(const std::string& fileName, const std::string& fileData) {
|
||||
bool FileResourceDisplay::load(ResourceManager& rMan, const std::string& fileName, const std::string& fileData) {
|
||||
this->fileName = fileName;
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
class FileResourceDisplay : public ResourceDisplay {
|
||||
public:
|
||||
virtual void update(World& w) override;
|
||||
virtual bool load(const std::string& fileName, const std::string& fileData) override;
|
||||
virtual bool load(ResourceManager& rMan, 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;
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ void ImageResourceDisplay::update(World& w) {
|
|||
}
|
||||
}
|
||||
|
||||
bool ImageResourceDisplay::load(const std::string& fileName, const std::string& fileData) {
|
||||
bool ImageResourceDisplay::load(ResourceManager& rMan, const std::string& fileName, const std::string& fileData) {
|
||||
sk_sp<SkData> newData = SkData::MakeWithoutCopy(fileData.c_str(), fileData.size());
|
||||
std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(newData, decoders);
|
||||
mustUpdateDraw = true;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
class ImageResourceDisplay : public ResourceDisplay {
|
||||
public:
|
||||
virtual void update(World& w) override;
|
||||
virtual bool load(const std::string& fileName, const std::string& fileData) override;
|
||||
virtual bool load(ResourceManager& rMan, 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;
|
||||
|
|
|
|||
|
|
@ -7,11 +7,12 @@ using namespace Eigen;
|
|||
|
||||
struct DrawData;
|
||||
class World;
|
||||
class ResourceManager;
|
||||
|
||||
class ResourceDisplay {
|
||||
public:
|
||||
virtual void update(World& w) = 0;
|
||||
virtual bool load(const std::string& fileName, const std::string& fileData) = 0;
|
||||
virtual bool load(ResourceManager& rMan, const std::string& fileName, const std::string& fileData) = 0;
|
||||
virtual bool update_draw() const = 0;
|
||||
virtual void draw(SkCanvas* canvas, const DrawData& drawData, const SkRect& imRect) = 0;
|
||||
virtual Vector2f get_dimensions() const = 0;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ void SvgResourceDisplay::update(World& w) {
|
|||
mustUpdateDraw = false;
|
||||
}
|
||||
|
||||
bool SvgResourceDisplay::load(const std::string& fileName, const std::string& fileData) {
|
||||
bool SvgResourceDisplay::load(ResourceManager& rMan, const std::string& fileName, const std::string& fileData) {
|
||||
SkMemoryStream strm(fileData.c_str(), fileData.size());
|
||||
svgDom = SkSVGDOM::Builder().make(strm);
|
||||
|
||||
|
|
@ -23,11 +23,20 @@ bool SvgResourceDisplay::load(const std::string& fileName, const std::string& fi
|
|||
|
||||
svgRootSize = svgDom->containerSize();
|
||||
|
||||
if(svgRootSize.width() == 0 || svgRootSize.height() == 0) {
|
||||
svgDom->setContainerSize({1000, 1000});
|
||||
svgRootSize = svgDom->containerSize();
|
||||
}
|
||||
|
||||
if(svgRootSize.width() == 0 || svgRootSize.height() == 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SvgResourceDisplay::draw(SkCanvas* canvas, const DrawData& drawData, const SkRect& imRect) {
|
||||
canvas->save();
|
||||
canvas->clipRect(imRect);
|
||||
canvas->translate(imRect.x(), imRect.y());
|
||||
canvas->scale(imRect.width() / svgRootSize.width(), imRect.height() / svgRootSize.height());
|
||||
svgDom->render(canvas);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
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 load(ResourceManager& rMan, 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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue