void LinkCelsCommand::onExecute(Context* context) { ContextWriter writer(context); Document* document(writer.document()); bool nonEditableLayers = false; { // TODO the range of selected frames should be in doc::Site. Timeline::Range range = App::instance()->getMainWindow()->getTimeline()->range(); if (!range.enabled()) return; Transaction transaction(writer.context(), friendlyName()); Sprite* sprite = writer.sprite(); frame_t begin = range.frameBegin(); frame_t end = range.frameEnd(); for (LayerIndex layerIdx = range.layerBegin(); layerIdx <= range.layerEnd(); ++layerIdx) { Layer* layer = sprite->indexToLayer(layerIdx); if (!layer->isImage()) continue; if (!layer->isEditable()) { nonEditableLayers = true; continue; } LayerImage* layerImage = static_cast<LayerImage*>(layer); for (frame_t frame=begin; frame < end+1; ++frame) { Cel* cel = layerImage->cel(frame); if (cel) { for (frame = cel->frame()+1; frame < end+1; ++frame) { transaction.execute( new cmd::CopyCel( layerImage, cel->frame(), layerImage, frame, true)); // true = force links } break; } } } transaction.commit(); } if (nonEditableLayers) StatusBar::instance()->showTip(1000, "There are locked layers"); update_screen_for_document(document); }
void SetCelFrame::onFireNotifications() { Cel* cel = this->cel(); Doc* doc = static_cast<Doc*>(cel->sprite()->document()); DocEvent ev(doc); ev.sprite(cel->layer()->sprite()); ev.layer(cel->layer()); ev.cel(cel); ev.frame(cel->frame()); doc->notify_observers<DocEvent&>(&DocObserver::onCelFrameChanged, ev); }
void LinkCelsCommand::onExecute(Context* context) { ContextWriter writer(context); Doc* document(writer.document()); bool nonEditableLayers = false; { auto site = context->activeSite(); if (!site.inTimeline()) return; Tx tx(writer.context(), friendlyName()); for (Layer* layer : site.selectedLayers()) { if (!layer->isImage()) continue; if (!layer->isEditableHierarchy()) { nonEditableLayers = true; continue; } LayerImage* layerImage = static_cast<LayerImage*>(layer); for (auto it=site.selectedFrames().begin(), end=site.selectedFrames().end(); it != end; ++it) { frame_t frame = *it; Cel* cel = layerImage->cel(frame); if (cel) { for (++it; it != end; ++it) { tx( new cmd::CopyCel( layerImage, cel->frame(), layerImage, *it, true)); // true = force links } break; } } } tx.commit(); } if (nonEditableLayers) StatusBar::instance()->showTip(1000, "There are locked layers"); update_screen_for_document(document); }
/** * [working thread] */ virtual void onJob() { UndoTransaction undoTransaction(m_writer.context(), "Sprite Size"); DocumentApi api = m_writer.document()->getApi(); // Get all sprite cels CelList cels; m_sprite->getCels(cels); // For each cel... int progress = 0; for (CelIterator it = cels.begin(); it != cels.end(); ++it, ++progress) { Cel* cel = *it; // Change its location api.setCelPosition(m_sprite, cel, scale_x(cel->x()), scale_y(cel->y())); // Get cel's image Image* image = cel->image(); if (!image) continue; // Resize the image int w = scale_x(image->width()); int h = scale_y(image->height()); Image* new_image = Image::create(image->pixelFormat(), MAX(1, w), MAX(1, h)); doc::algorithm::fixup_image_transparent_colors(image); doc::algorithm::resize_image(image, new_image, m_resize_method, m_sprite->getPalette(cel->frame()), m_sprite->getRgbMap(cel->frame())); api.replaceStockImage(m_sprite, cel->imageIndex(), new_image); jobProgress((float)progress / cels.size()); // cancel all the operation? if (isCanceled()) return; // UndoTransaction destructor will undo all operations } // Resize mask if (m_document->isMaskVisible()) { base::UniquePtr<Image> old_bitmap (crop_image(m_document->mask()->bitmap(), -1, -1, m_document->mask()->bitmap()->width()+2, m_document->mask()->bitmap()->height()+2, 0)); int w = scale_x(old_bitmap->width()); int h = scale_y(old_bitmap->height()); base::UniquePtr<Mask> new_mask(new Mask); new_mask->replace(scale_x(m_document->mask()->bounds().x-1), scale_y(m_document->mask()->bounds().y-1), MAX(1, w), MAX(1, h)); algorithm::resize_image(old_bitmap, new_mask->bitmap(), m_resize_method, m_sprite->getPalette(FrameNumber(0)), // Ignored m_sprite->getRgbMap(FrameNumber(0))); // Ignored // Reshrink new_mask->intersect(new_mask->bounds()); // Copy new mask api.copyToCurrentMask(new_mask); // Regenerate mask m_document->resetTransformation(); m_document->generateMaskBoundaries(); } // resize sprite api.setSpriteSize(m_sprite, m_new_width, m_new_height); // commit changes undoTransaction.commit(); }