| 1 | // Aseprite |
|---|---|
| 2 | // Copyright (C) 2019 Igara Studio S.A. |
| 3 | // |
| 4 | // This program is distributed under the terms of |
| 5 | // the End-User License Agreement for Aseprite. |
| 6 | |
| 7 | #ifdef HAVE_CONFIG_H |
| 8 | #include "config.h" |
| 9 | #endif |
| 10 | |
| 11 | #include "app/cmd/set_grid_bounds.h" |
| 12 | |
| 13 | #include "app/doc.h" |
| 14 | #include "app/doc_event.h" |
| 15 | #include "app/doc_observer.h" |
| 16 | #include "app/pref/preferences.h" |
| 17 | #include "doc/sprite.h" |
| 18 | |
| 19 | namespace app { |
| 20 | namespace cmd { |
| 21 | |
| 22 | using namespace doc; |
| 23 | |
| 24 | SetGridBounds::SetGridBounds(Sprite* sprite, const gfx::Rect& bounds) |
| 25 | : WithSprite(sprite) |
| 26 | , m_oldBounds(sprite->gridBounds()) |
| 27 | , m_newBounds(bounds) |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | void SetGridBounds::onExecute() |
| 32 | { |
| 33 | setGrid(m_newBounds); |
| 34 | } |
| 35 | |
| 36 | void SetGridBounds::onUndo() |
| 37 | { |
| 38 | setGrid(m_oldBounds); |
| 39 | } |
| 40 | |
| 41 | void SetGridBounds::setGrid(const gfx::Rect& grid) |
| 42 | { |
| 43 | Sprite* spr = sprite(); |
| 44 | spr->setGridBounds(grid); |
| 45 | |
| 46 | Doc* doc = static_cast<Doc*>(spr->document()); |
| 47 | auto& docPref = Preferences::instance().document(doc); |
| 48 | docPref.grid.bounds(grid); |
| 49 | |
| 50 | spr->incrementVersion(); |
| 51 | } |
| 52 | |
| 53 | void SetGridBounds::onFireNotifications() |
| 54 | { |
| 55 | Sprite* sprite = this->sprite(); |
| 56 | Doc* doc = static_cast<Doc*>(sprite->document()); |
| 57 | DocEvent ev(doc); |
| 58 | ev.sprite(sprite); |
| 59 | doc->notify_observers<DocEvent&>(&DocObserver::onSpriteGridBoundsChanged, ev); |
| 60 | } |
| 61 | |
| 62 | } // namespace cmd |
| 63 | } // namespace app |
| 64 |