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