1 // Aseprite 2 // Copyright (C) 2001-2015 David Capello 3 // 4 // This program is distributed under the terms of 5 // the End-User License Agreement for Aseprite. 6 7 #ifndef APP_CMD_REPLACE_IMAGE_H_INCLUDED 8 #define APP_CMD_REPLACE_IMAGE_H_INCLUDED 9 #pragma once 10 11 #include "app/cmd.h" 12 #include "app/cmd/with_sprite.h" 13 #include "doc/image_ref.h" 14 15 #include <sstream> 16 17 namespace app { 18 namespace cmd { 19 using namespace doc; 20 21 class ReplaceImage : public Cmd 22 , public WithSprite { 23 public: 24 ReplaceImage(Sprite* sprite, const ImageRef& oldImage, const ImageRef& newImage); 25 26 protected: 27 void onExecute() override; 28 void onUndo() override; 29 void onRedo() override; onMemSize()30 size_t onMemSize() const override { 31 return sizeof(*this) + 32 (m_copy ? m_copy->getMemSize(): 0); 33 } 34 35 private: 36 void replaceImage(ObjectId oldId, const ImageRef& newImage); 37 38 ObjectId m_oldImageId; 39 ObjectId m_newImageId; 40 41 // Reference used only to keep the copy of the new image from the 42 // ReplaceImage() ctor until the ReplaceImage::onExecute() call. 43 // Then the reference is not used anymore. 44 ImageRef m_newImage; 45 ImageRef m_copy; 46 }; 47 48 } // namespace cmd 49 } // namespace app 50 51 #endif 52