1// Aseprite
2// Copyright (C) 2019-2021 Igara Studio S.A.
3// Copyright (C) 2001-2018 David Capello
4//
5// This program is distributed under the terms of
6// the End-User License Agreement for Aseprite.
7
8#ifndef APP_SITE_H_INCLUDED
9#define APP_SITE_H_INCLUDED
10#pragma once
11
12#include "app/doc_range.h"
13#include "app/tilemap_mode.h"
14#include "app/tileset_mode.h"
15#include "doc/frame.h"
16#include "doc/palette_picks.h"
17#include "doc/selected_objects.h"
18#include "gfx/fwd.h"
19
20namespace doc {
21 class Cel;
22 class Grid;
23 class Image;
24 class Layer;
25 class Palette;
26 class RgbMap;
27 class Sprite;
28 class Tileset;
29} // namespace doc
30
31namespace app {
32 class Doc;
33
34 // Specifies the current location in a context. E.g. the location in
35 // the current Editor (current document, sprite, layer, frame,
36 // etc.).
37 class Site {
38 public:
39 // Were is the user focus. E.g. If this focus is in the timeline,
40 // it means that commands should applied in the context of the
41 // timeline (layers, or frames, or cels).
42 enum Focus {
43 None,
44 InEditor,
45 InLayers,
46 InFrames,
47 InCels,
48 InColorBar
49 };
50
51 Site()
52 : m_focus(None)
53 , m_document(nullptr)
54 , m_sprite(nullptr)
55 , m_layer(nullptr)
56 , m_frame(0)
57 , m_tilemapMode(TilemapMode::Pixels)
58 , m_tilesetMode(TilesetMode::Manual) { }
59
60 const Focus focus() const { return m_focus; }
61 bool inEditor() const { return m_focus == InEditor; }
62 bool inLayers() const { return m_focus == InLayers; }
63 bool inFrames() const { return m_focus == InFrames; }
64 bool inCels() const { return m_focus == InCels; }
65 bool inColorBar() const { return m_focus == InColorBar; }
66 bool inTimeline() const { return (inLayers() || inFrames() || inCels()); }
67
68 Doc* document() const { return m_document; }
69 doc::Sprite* sprite() const { return m_sprite; }
70 doc::Layer* layer() const { return m_layer; }
71 doc::frame_t frame() const { return m_frame; }
72 doc::Cel* cel() const;
73 const DocRange& range() const { return m_range; }
74
75 void focus(Focus focus) { m_focus = focus; }
76 void document(Doc* document) { m_document = document; }
77 void sprite(doc::Sprite* sprite) { m_sprite = sprite; }
78 void layer(doc::Layer* layer) { m_layer = layer; }
79 void frame(doc::frame_t frame) { m_frame = frame; }
80 void range(const DocRange& range);
81
82 const doc::SelectedLayers& selectedLayers() const { return m_range.selectedLayers(); }
83 const doc::SelectedFrames& selectedFrames() const { return m_range.selectedFrames(); }
84
85 // Selected colors selected in the ColorBar
86 const doc::PalettePicks& selectedColors() const { return m_selectedColors; }
87 doc::PalettePicks& selectedColors() { return m_selectedColors; }
88 void selectedColors(const doc::PalettePicks& colors) {
89 m_selectedColors = colors;
90 }
91
92 // Selected tiles selected in the ColorBar
93 const doc::PalettePicks& selectedTiles() const { return m_selectedTiles; }
94 doc::PalettePicks& selectedTiles() { return m_selectedTiles; }
95 void selectedTiles(const doc::PalettePicks& tiles) {
96 m_selectedTiles = tiles;
97 }
98
99 const doc::SelectedObjects& selectedSlices() const { return m_selectedSlices; }
100 doc::SelectedObjects& selectedSlices() { return m_selectedSlices; }
101 void selectedSlices(const doc::SelectedObjects& set) {
102 m_selectedSlices = set;
103 }
104
105 doc::Palette* palette();
106 doc::Image* image(int* x = nullptr, int* y = nullptr, int* opacity = nullptr) const;
107 doc::Palette* palette() const;
108 doc::RgbMap* rgbMap() const;
109
110 doc::Tileset* tileset() const;
111 doc::Grid grid() const;
112 gfx::Rect gridBounds() const;
113
114 void tilemapMode(const TilemapMode mode) { m_tilemapMode = mode; }
115 void tilesetMode(const TilesetMode mode) { m_tilesetMode = mode; }
116 TilemapMode tilemapMode() const { return m_tilemapMode; }
117 TilesetMode tilesetMode() const { return m_tilesetMode; }
118
119 bool shouldTrimCel(Cel* cel) const;
120
121 private:
122 Focus m_focus;
123 Doc* m_document;
124 doc::Sprite* m_sprite;
125 doc::Layer* m_layer;
126 doc::frame_t m_frame;
127 DocRange m_range;
128 doc::PalettePicks m_selectedColors;
129 doc::PalettePicks m_selectedTiles;
130 doc::SelectedObjects m_selectedSlices;
131 TilemapMode m_tilemapMode;
132 TilesetMode m_tilesetMode;
133 };
134
135} // namespace app
136
137#endif
138