1// Aseprite
2// Copyright (C) 2020 Igara Studio S.A.
3// Copyright (C) 2001-2017 David Capello
4//
5// This program is distributed under the terms of
6// the End-User License Agreement for Aseprite.
7
8#ifdef HAVE_CONFIG_H
9#include "config.h"
10#endif
11
12#include "app/commands/command.h"
13#include "app/context.h"
14#include "app/modules/gui.h"
15#include "app/pref/preferences.h"
16
17namespace app {
18
19class ShowExtrasCommand : public Command {
20public:
21 ShowExtrasCommand()
22 : Command(CommandId::ShowExtras(), CmdUIOnlyFlag) {
23 }
24
25protected:
26 bool onChecked(Context* ctx) override {
27 DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
28 return docPref.show.selectionEdges();
29 }
30
31 void onExecute(Context* ctx) override {
32 DocumentPreferences& globPref = Preferences::instance().document(nullptr);
33 DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
34 if (docPref.show.selectionEdges()) {
35 globPref.show = docPref.show;
36 docPref.show.selectionEdges(false);
37 docPref.show.layerEdges(false);
38 docPref.show.grid(false);
39 docPref.show.pixelGrid(false);
40 }
41 else {
42 docPref.show.selectionEdges(true);
43 docPref.show.layerEdges(
44 docPref.show.layerEdges() ||
45 globPref.show.layerEdges());
46 docPref.show.grid(
47 docPref.show.grid() ||
48 globPref.show.grid());
49 docPref.show.pixelGrid(
50 docPref.show.pixelGrid() ||
51 globPref.show.pixelGrid());
52 }
53 }
54};
55
56class ShowLayerEdgesCommand : public Command {
57public:
58 ShowLayerEdgesCommand()
59 : Command(CommandId::ShowLayerEdges(), CmdUIOnlyFlag) {
60 }
61
62protected:
63 bool onChecked(Context* ctx) override {
64 DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
65 return docPref.show.layerEdges();
66 }
67
68 void onExecute(Context* ctx) override {
69 DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
70 docPref.show.layerEdges(!docPref.show.layerEdges());
71 }
72};
73
74class ShowGridCommand : public Command {
75public:
76 ShowGridCommand()
77 : Command(CommandId::ShowGrid(), CmdUIOnlyFlag) {
78 }
79
80protected:
81 bool onChecked(Context* ctx) override {
82 DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
83 return docPref.show.grid();
84 }
85
86 void onExecute(Context* ctx) override {
87 DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
88 docPref.show.grid(!docPref.show.grid());
89 }
90};
91
92class ShowPixelGridCommand : public Command {
93public:
94 ShowPixelGridCommand()
95 : Command(CommandId::ShowPixelGrid(), CmdUIOnlyFlag) {
96 }
97
98protected:
99 bool onChecked(Context* ctx) override {
100 DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
101 return docPref.show.pixelGrid();
102 }
103
104 void onExecute(Context* ctx) override {
105 DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
106 docPref.show.pixelGrid(!docPref.show.pixelGrid());
107 }
108};
109
110class ShowSelectionEdgesCommand : public Command {
111public:
112 ShowSelectionEdgesCommand()
113 : Command(CommandId::ShowSelectionEdges(), CmdUIOnlyFlag) {
114 }
115
116protected:
117 bool onChecked(Context* ctx) override {
118 DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
119 return docPref.show.selectionEdges();
120 }
121
122 void onExecute(Context* ctx) override {
123 DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
124 docPref.show.selectionEdges(!docPref.show.selectionEdges());
125 }
126};
127
128class ShowBrushPreviewCommand : public Command {
129public:
130 ShowBrushPreviewCommand()
131 : Command(CommandId::ShowBrushPreview(), CmdUIOnlyFlag) {
132 }
133
134protected:
135 bool onChecked(Context* ctx) override {
136 DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
137 return docPref.show.brushPreview();
138 }
139
140 void onExecute(Context* ctx) override {
141 DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
142 docPref.show.brushPreview(!docPref.show.brushPreview());
143
144 // TODO we shouldn't need this, but it happens to be that the
145 // Preview editor isn't being updated correctly when we change the
146 // brush preview state.
147 update_screen_for_document(ctx->activeDocument());
148 }
149};
150
151class ShowAutoGuidesCommand : public Command {
152public:
153 ShowAutoGuidesCommand()
154 : Command(CommandId::ShowAutoGuides(), CmdUIOnlyFlag) {
155 }
156
157protected:
158 bool onChecked(Context* ctx) override {
159 DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
160 return docPref.show.autoGuides();
161 }
162
163 void onExecute(Context* ctx) override {
164 DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
165 docPref.show.autoGuides(!docPref.show.autoGuides());
166 }
167};
168
169class ShowSlicesCommand : public Command {
170public:
171 ShowSlicesCommand()
172 : Command(CommandId::ShowSlices(), CmdUIOnlyFlag) {
173 }
174
175protected:
176 bool onChecked(Context* ctx) override {
177 DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
178 return docPref.show.slices();
179 }
180
181 void onExecute(Context* ctx) override {
182 DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
183 docPref.show.slices(!docPref.show.slices());
184 }
185};
186
187class ShowTileNumbersCommand : public Command {
188public:
189 ShowTileNumbersCommand()
190 : Command(CommandId::ShowTileNumbers(), CmdUIOnlyFlag) {
191 }
192
193protected:
194 bool onChecked(Context* ctx) override {
195 DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
196 return docPref.show.tileNumbers();
197 }
198
199 void onExecute(Context* ctx) override {
200 DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
201 docPref.show.tileNumbers(!docPref.show.tileNumbers());
202 }
203};
204
205Command* CommandFactory::createShowExtrasCommand()
206{
207 return new ShowExtrasCommand;
208}
209
210Command* CommandFactory::createShowGridCommand()
211{
212 return new ShowGridCommand;
213}
214
215Command* CommandFactory::createShowPixelGridCommand()
216{
217 return new ShowPixelGridCommand;
218}
219
220Command* CommandFactory::createShowLayerEdgesCommand()
221{
222 return new ShowLayerEdgesCommand;
223}
224
225Command* CommandFactory::createShowSelectionEdgesCommand()
226{
227 return new ShowSelectionEdgesCommand;
228}
229
230Command* CommandFactory::createShowBrushPreviewCommand()
231{
232 return new ShowBrushPreviewCommand;
233}
234
235Command* CommandFactory::createShowAutoGuidesCommand()
236{
237 return new ShowAutoGuidesCommand;
238}
239
240Command* CommandFactory::createShowSlicesCommand()
241{
242 return new ShowSlicesCommand;
243}
244
245Command* CommandFactory::createShowTileNumbersCommand()
246{
247 return new ShowTileNumbersCommand;
248}
249
250} // namespace app
251