/** * Copies the previous cel of @a frame to @frame. */ void UndoTransaction::copyPreviousFrame(Layer* layer, int frame) { ASSERT(layer); ASSERT(frame > 0); // create a copy of the previous cel Cel* src_cel = static_cast<LayerImage*>(layer)->getCel(frame-1); Image* src_image = src_cel ? m_sprite->getStock()->getImage(src_cel->getImage()): NULL; // nothing to copy, it will be a transparent cel if (!src_image) return; // copy the image Image* dst_image = Image::createCopy(src_image); int image_index = addImageInStock(dst_image); // create the new cel Cel* dst_cel = new Cel(frame, image_index); if (src_cel) { // copy the data from the previous cel dst_cel->setPosition(src_cel->getX(), src_cel->getY()); dst_cel->setOpacity(src_cel->getOpacity()); } // add the cel in the layer addCel(static_cast<LayerImage*>(layer), dst_cel); }
void LayerImage::moveCel(Cel* cel, FrameNumber frame) { removeCel(cel); cel->setFrame(frame); addCel(cel); }
void UndoTransaction::backgroundFromLayer(LayerImage* layer, int bgcolor) { ASSERT(layer); ASSERT(layer->is_image()); ASSERT(layer->is_readable()); ASSERT(layer->is_writable()); ASSERT(layer->getSprite() == m_sprite); ASSERT(m_sprite->getBackgroundLayer() == NULL); // create a temporary image to draw each frame of the new // `Background' layer UniquePtr<Image> bg_image_wrap(Image::create(m_sprite->getPixelFormat(), m_sprite->getWidth(), m_sprite->getHeight())); Image* bg_image = bg_image_wrap.get(); CelIterator it = layer->getCelBegin(); CelIterator end = layer->getCelEnd(); for (; it != end; ++it) { Cel* cel = *it; ASSERT((cel->getImage() > 0) && (cel->getImage() < m_sprite->getStock()->size())); // get the image from the sprite's stock of images Image* cel_image = m_sprite->getStock()->getImage(cel->getImage()); ASSERT(cel_image); image_clear(bg_image, bgcolor); image_merge(bg_image, cel_image, cel->getX(), cel->getY(), MID(0, cel->getOpacity(), 255), layer->getBlendMode()); // now we have to copy the new image (bg_image) to the cel... setCelPosition(cel, 0, 0); // same size of cel-image and bg-image if (bg_image->w == cel_image->w && bg_image->h == cel_image->h) { if (isEnabled()) m_undoHistory->pushUndoer(new undoers::ImageArea(m_undoHistory->getObjects(), cel_image, 0, 0, cel_image->w, cel_image->h)); image_copy(cel_image, bg_image, 0, 0); } else { replaceStockImage(cel->getImage(), Image::createCopy(bg_image)); } } // Fill all empty cels with a flat-image filled with bgcolor for (int frame=0; frame<m_sprite->getTotalFrames(); frame++) { Cel* cel = layer->getCel(frame); if (!cel) { Image* cel_image = Image::create(m_sprite->getPixelFormat(), m_sprite->getWidth(), m_sprite->getHeight()); image_clear(cel_image, bgcolor); // Add the new image in the stock int image_index = addImageInStock(cel_image); // Create the new cel and add it to the new background layer cel = new Cel(frame, image_index); addCel(layer, cel); } } configureLayerAsBackground(layer); }