| 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 |  | 
|---|
| 17 | namespace app { | 
|---|
| 18 |  | 
|---|
| 19 | class ShowExtrasCommand : public Command { | 
|---|
| 20 | public: | 
|---|
| 21 | ShowExtrasCommand() | 
|---|
| 22 | : Command(CommandId::ShowExtras(), CmdUIOnlyFlag) { | 
|---|
| 23 | } | 
|---|
| 24 |  | 
|---|
| 25 | protected: | 
|---|
| 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 |  | 
|---|
| 56 | class ShowLayerEdgesCommand : public Command { | 
|---|
| 57 | public: | 
|---|
| 58 | ShowLayerEdgesCommand() | 
|---|
| 59 | : Command(CommandId::ShowLayerEdges(), CmdUIOnlyFlag) { | 
|---|
| 60 | } | 
|---|
| 61 |  | 
|---|
| 62 | protected: | 
|---|
| 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 |  | 
|---|
| 74 | class ShowGridCommand : public Command { | 
|---|
| 75 | public: | 
|---|
| 76 | ShowGridCommand() | 
|---|
| 77 | : Command(CommandId::ShowGrid(), CmdUIOnlyFlag) { | 
|---|
| 78 | } | 
|---|
| 79 |  | 
|---|
| 80 | protected: | 
|---|
| 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 |  | 
|---|
| 92 | class ShowPixelGridCommand : public Command { | 
|---|
| 93 | public: | 
|---|
| 94 | ShowPixelGridCommand() | 
|---|
| 95 | : Command(CommandId::ShowPixelGrid(), CmdUIOnlyFlag) { | 
|---|
| 96 | } | 
|---|
| 97 |  | 
|---|
| 98 | protected: | 
|---|
| 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 |  | 
|---|
| 110 | class ShowSelectionEdgesCommand : public Command { | 
|---|
| 111 | public: | 
|---|
| 112 | ShowSelectionEdgesCommand() | 
|---|
| 113 | : Command(CommandId::ShowSelectionEdges(), CmdUIOnlyFlag) { | 
|---|
| 114 | } | 
|---|
| 115 |  | 
|---|
| 116 | protected: | 
|---|
| 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 |  | 
|---|
| 128 | class ShowBrushPreviewCommand : public Command { | 
|---|
| 129 | public: | 
|---|
| 130 | ShowBrushPreviewCommand() | 
|---|
| 131 | : Command(CommandId::ShowBrushPreview(), CmdUIOnlyFlag) { | 
|---|
| 132 | } | 
|---|
| 133 |  | 
|---|
| 134 | protected: | 
|---|
| 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 |  | 
|---|
| 151 | class ShowAutoGuidesCommand : public Command { | 
|---|
| 152 | public: | 
|---|
| 153 | ShowAutoGuidesCommand() | 
|---|
| 154 | : Command(CommandId::ShowAutoGuides(), CmdUIOnlyFlag) { | 
|---|
| 155 | } | 
|---|
| 156 |  | 
|---|
| 157 | protected: | 
|---|
| 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 |  | 
|---|
| 169 | class ShowSlicesCommand : public Command { | 
|---|
| 170 | public: | 
|---|
| 171 | ShowSlicesCommand() | 
|---|
| 172 | : Command(CommandId::ShowSlices(), CmdUIOnlyFlag) { | 
|---|
| 173 | } | 
|---|
| 174 |  | 
|---|
| 175 | protected: | 
|---|
| 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 |  | 
|---|
| 187 | class ShowTileNumbersCommand : public Command { | 
|---|
| 188 | public: | 
|---|
| 189 | ShowTileNumbersCommand() | 
|---|
| 190 | : Command(CommandId::ShowTileNumbers(), CmdUIOnlyFlag) { | 
|---|
| 191 | } | 
|---|
| 192 |  | 
|---|
| 193 | protected: | 
|---|
| 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 |  | 
|---|
| 205 | Command* CommandFactory::createShowExtrasCommand() | 
|---|
| 206 | { | 
|---|
| 207 | return new ShowExtrasCommand; | 
|---|
| 208 | } | 
|---|
| 209 |  | 
|---|
| 210 | Command* CommandFactory::createShowGridCommand() | 
|---|
| 211 | { | 
|---|
| 212 | return new ShowGridCommand; | 
|---|
| 213 | } | 
|---|
| 214 |  | 
|---|
| 215 | Command* CommandFactory::createShowPixelGridCommand() | 
|---|
| 216 | { | 
|---|
| 217 | return new ShowPixelGridCommand; | 
|---|
| 218 | } | 
|---|
| 219 |  | 
|---|
| 220 | Command* CommandFactory::createShowLayerEdgesCommand() | 
|---|
| 221 | { | 
|---|
| 222 | return new ShowLayerEdgesCommand; | 
|---|
| 223 | } | 
|---|
| 224 |  | 
|---|
| 225 | Command* CommandFactory::createShowSelectionEdgesCommand() | 
|---|
| 226 | { | 
|---|
| 227 | return new ShowSelectionEdgesCommand; | 
|---|
| 228 | } | 
|---|
| 229 |  | 
|---|
| 230 | Command* CommandFactory::createShowBrushPreviewCommand() | 
|---|
| 231 | { | 
|---|
| 232 | return new ShowBrushPreviewCommand; | 
|---|
| 233 | } | 
|---|
| 234 |  | 
|---|
| 235 | Command* CommandFactory::createShowAutoGuidesCommand() | 
|---|
| 236 | { | 
|---|
| 237 | return new ShowAutoGuidesCommand; | 
|---|
| 238 | } | 
|---|
| 239 |  | 
|---|
| 240 | Command* CommandFactory::createShowSlicesCommand() | 
|---|
| 241 | { | 
|---|
| 242 | return new ShowSlicesCommand; | 
|---|
| 243 | } | 
|---|
| 244 |  | 
|---|
| 245 | Command* CommandFactory::createShowTileNumbersCommand() | 
|---|
| 246 | { | 
|---|
| 247 | return new ShowTileNumbersCommand; | 
|---|
| 248 | } | 
|---|
| 249 |  | 
|---|
| 250 | } // namespace app | 
|---|
| 251 |  | 
|---|