1 // Aseprite 2 // Copyright (C) 2001-2018 David Capello 3 // 4 // This program is distributed under the terms of 5 // the End-User License Agreement for Aseprite. 6 7 #ifndef APP_UTIL_EXPAND_CEL_CANVAS_H_INCLUDED 8 #define APP_UTIL_EXPAND_CEL_CANVAS_H_INCLUDED 9 #pragma once 10 11 #include "doc/frame.h" 12 #include "doc/image_ref.h" 13 #include "filters/tiled_mode.h" 14 #include "gfx/point.h" 15 #include "gfx/rect.h" 16 #include "gfx/region.h" 17 #include "gfx/size.h" 18 19 namespace doc { 20 class Cel; 21 class Image; 22 class Layer; 23 class Sprite; 24 } 25 26 namespace app { 27 class Doc; 28 class Site; 29 class Transaction; 30 31 using namespace filters; 32 using namespace doc; 33 34 // This class can be used to expand the canvas of the current cel to 35 // the visible portion of sprite. If the user cancels the operation, 36 // you've a rollback() method to restore the cel to its original 37 // state. If all changes are committed, some undo information is 38 // stored in the document's UndoHistory to go back to the original 39 // state using "Undo" command. 40 class ExpandCelCanvas { 41 public: 42 enum Flags { 43 None = 0, 44 NeedsSource = 1, 45 UseModifiedRegionAsUndoInfo = 2, 46 }; 47 48 ExpandCelCanvas(Site site, Layer* layer, 49 TiledMode tiledMode, Transaction& undo, Flags flags); 50 ~ExpandCelCanvas(); 51 52 // Commit changes made in getDestCanvas() in the cel's image. Adds 53 // information in the undo history so the user can undo the 54 // modifications in the canvas. 55 void commit(); 56 57 // Restore the cel as its original state as when ExpandCelCanvas() 58 // was created. 59 void rollback(); 60 61 Image* getSourceCanvas(); // You can read pixels from here 62 Image* getDestCanvas(); // You can write pixels right here 63 64 void validateSourceCanvas(const gfx::Region& rgn); 65 void validateDestCanvas(const gfx::Region& rgn); 66 void invalidateDestCanvas(); 67 void invalidateDestCanvas(const gfx::Region& rgn); 68 void copyValidDestToSourceCanvas(const gfx::Region& rgn); 69 getCel()70 const Cel* getCel() const { return m_cel; } 71 72 private: 73 gfx::Rect getTrimDstImageBounds() const; 74 ImageRef trimDstImage(const gfx::Rect& bounds) const; 75 76 Doc* m_document; 77 Sprite* m_sprite; 78 Layer* m_layer; 79 frame_t m_frame; 80 Cel* m_cel; 81 ImageRef m_celImage; 82 bool m_celCreated; 83 gfx::Point m_origCelPos; 84 Flags m_flags; 85 gfx::Rect m_bounds; 86 ImageRef m_srcImage; 87 ImageRef m_dstImage; 88 bool m_closed; 89 bool m_committed; 90 Transaction& m_transaction; 91 gfx::Region m_validSrcRegion; 92 gfx::Region m_validDstRegion; 93 94 // True if we can compare src image with dst image to patch the 95 // cel. This is false when dst is copied to the src, so we cannot 96 // reduce the patched region because both images will be the same. 97 bool m_canCompareSrcVsDst; 98 }; 99 100 } // namespace app 101 102 #endif 103