From b1d8da925c537644c3568b886ee15dc54e7a339e Mon Sep 17 00:00:00 2001 From: Joshua Ogunyinka Date: Mon, 6 Dec 2021 11:58:16 +0400 Subject: [PATCH] Add support for sprite slicing --- src/app/file/psd_format.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/app/file/psd_format.cpp b/src/app/file/psd_format.cpp index 1c3ba5610..f3f08eb93 100644 --- a/src/app/file/psd_format.cpp +++ b/src/app/file/psd_format.cpp @@ -11,6 +11,7 @@ #include "doc/image_impl.h" #include "doc/layer.h" #include "doc/palette.h" +#include "doc/slice.h" #include "doc/sprite.h" #include "psd/psd.h" @@ -118,6 +119,25 @@ public: m_layerHasTransparentChannel = hasTransparency(header.nchannels); } + void onSlicesData(const psd::Slices& slices) override + { + auto& spriteSlices = m_sprite->slices(); + for (const auto& slice : slices.slices) { + const gfx::Rect rect(slice.bound.left, + slice.bound.top, + slice.bound.right - slice.bound.left, + slice.bound.bottom - slice.bound.top); + if (!rect.isEmpty() && slice.groupID > 0) { + auto slice = new doc::Slice; + slice->insert(0, doc::SliceKey(rect)); + + // TO-DO: the slices color should come from the app preference + slice->userData().setColor(doc::rgba(0, 0, 255, 255)); + spriteSlices.add(slice); + } + } + } + void onFramesData(const std::vector& frameInfo, const uint32_t activeFrameIndex) override {