Add SelectionAsGrid command

This commit is contained in:
David Capello 2015-08-10 18:27:53 -03:00
parent 3dff25246b
commit c159a3c4b5
3 changed files with 45 additions and 8 deletions

View File

@ -641,6 +641,7 @@
<item command="ShowGrid" text="Show &amp;Grid" />
<item command="SnapToGrid" text="&amp;Snap to Grid" />
<item command="GridSettings" text="Gri&amp;d Settings" />
<item command="SelectionAsGrid" text="Select&amp;ion as Grid" />
<separator />
<item command="SetLoopSection" text="Set &amp;Loop Section" />
<item command="ShowOnionSkin" text="Show &amp;Onion Skin" />

View File

@ -12,6 +12,7 @@
#include "app/app.h"
#include "app/commands/command.h"
#include "app/context.h"
#include "app/context_access.h"
#include "app/document.h"
#include "app/find_widget.h"
#include "app/load_widget.h"
@ -19,6 +20,8 @@
#include "app/pref/preferences.h"
#include "app/ui/status_bar.h"
#include "app/ui_context.h"
#include "doc/document.h"
#include "doc/mask.h"
#include "ui/window.h"
namespace app {
@ -37,12 +40,12 @@ public:
Command* clone() const override { return new ShowGridCommand(*this); }
protected:
bool onChecked(Context* ctx) {
bool onChecked(Context* ctx) override {
DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
return docPref.grid.visible();
}
void onExecute(Context* ctx) {
void onExecute(Context* ctx) override {
DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
docPref.grid.visible(!docPref.grid.visible());
}
@ -59,12 +62,12 @@ public:
Command* clone() const override { return new ShowPixelGridCommand(*this); }
protected:
bool onChecked(Context* ctx) {
bool onChecked(Context* ctx) override {
DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
return docPref.pixelGrid.visible();
}
void onExecute(Context* ctx) {
void onExecute(Context* ctx) override {
DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
docPref.pixelGrid.visible(!docPref.pixelGrid.visible());
}
@ -81,12 +84,12 @@ public:
Command* clone() const override { return new SnapToGridCommand(*this); }
protected:
bool onChecked(Context* ctx) {
bool onChecked(Context* ctx) override {
DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
return docPref.grid.snap();
}
void onExecute(Context* ctx) {
void onExecute(Context* ctx) override {
DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
bool newValue = !docPref.grid.snap();
docPref.grid.snap(newValue);
@ -95,14 +98,41 @@ protected:
}
};
class SelectionAsGridCommand : public Command {
public:
SelectionAsGridCommand()
: Command("SelectionAsGrid",
"Selection as Grid",
CmdUIOnlyFlag) {
}
Command* clone() const override { return new SelectionAsGridCommand(*this); }
protected:
bool onEnabled(Context* ctx) override {
return (ctx->activeDocument() &&
ctx->activeDocument()->isMaskVisible());
}
void onExecute(Context* ctx) override {
const ContextReader reader(ctx);
const Document* document = reader.document();
const Mask* mask(document->mask());
DocumentPreferences& docPref =
Preferences::instance().document(ctx->activeDocument());
docPref.grid.bounds(mask->bounds());
}
};
class GridSettingsCommand : public Command {
public:
GridSettingsCommand();
Command* clone() const override { return new GridSettingsCommand(*this); }
protected:
bool onEnabled(Context* context);
void onExecute(Context* context);
bool onEnabled(Context* context) override;
void onExecute(Context* context) override;
};
GridSettingsCommand::GridSettingsCommand()
@ -168,4 +198,9 @@ Command* CommandFactory::createGridSettingsCommand()
return new GridSettingsCommand;
}
Command* CommandFactory::createSelectionAsGridCommand()
{
return new SelectionAsGridCommand;
}
} // namespace app

View File

@ -101,6 +101,7 @@ FOR_EACH_COMMAND(SavePalette)
FOR_EACH_COMMAND(Scroll)
FOR_EACH_COMMAND(SetColorSelector)
FOR_EACH_COMMAND(SetLoopSection)
FOR_EACH_COMMAND(SelectionAsGrid)
FOR_EACH_COMMAND(SetPalette)
FOR_EACH_COMMAND(SetPaletteEntrySize)
FOR_EACH_COMMAND(ShowGrid)