MCPcopy Create free account
hub / github.com/LibreSprite/LibreSprite / cropSprite

Method cropSprite

src/app/document_api.cpp:80–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80void DocumentApi::cropSprite(Sprite* sprite, const gfx::Rect& bounds)
81{
82 setSpriteSize(sprite, bounds.w, bounds.h);
83
84 app::Document* doc = static_cast<app::Document*>(sprite->document());
85 std::vector<Layer*> layers;
86 sprite->getLayersList(layers);
87 for (Layer* layer : layers) {
88 if (!layer->isImage())
89 continue;
90
91 std::set<ObjectId> visited;
92 CelIterator it = ((LayerImage*)layer)->getCelBegin();
93 CelIterator end = ((LayerImage*)layer)->getCelEnd();
94 for (; it != end; ++it) {
95 auto cel = *it;
96 if (visited.find(cel->data()->id()) != visited.end())
97 continue;
98 visited.insert(cel->data()->id());
99
100 if (layer->isBackground()) {
101 Image* image = cel->image();
102 if (image && !cel->link()) {
103 ASSERT(cel->x() == 0);
104 ASSERT(cel->y() == 0);
105
106 // Create the new image through a crop
107 ImageRef new_image(
108 crop_image(image,
109 bounds.x, bounds.y,
110 bounds.w, bounds.h,
111 doc->bgColor(layer)));
112
113 // Replace the image in the stock that is pointed by the cel
114 replaceImage(sprite, cel->imageRef(), new_image);
115 }
116 }
117 else {
118 // Update the cel's position
119 setCelPosition(sprite, cel,
120 cel->x()-bounds.x, cel->y()-bounds.y);
121 }
122 }
123 }
124
125 if (!m_document->mask()->isEmpty())
126 setMaskPosition(m_document->mask()->bounds().x-bounds.x,
127 m_document->mask()->bounds().y-bounds.y);
128}
129
130void DocumentApi::trimSprite(Sprite* sprite)
131{

Callers 2

onExecuteMethod · 0.80
onExecuteMethod · 0.80

Calls 15

crop_imageFunction · 0.85
getLayersListMethod · 0.80
isImageMethod · 0.80
getCelBeginMethod · 0.80
getCelEndMethod · 0.80
linkMethod · 0.80
maskMethod · 0.80
documentMethod · 0.45
idMethod · 0.45
dataMethod · 0.45
endMethod · 0.45
isBackgroundMethod · 0.45

Tested by

no test coverage detected