Add option to show layer edges

This commit is contained in:
David Capello 2016-05-03 16:23:38 -03:00
parent 6dc9bb984d
commit b60b76ff22
6 changed files with 50 additions and 3 deletions

View File

@ -736,6 +736,7 @@
<separator /> <separator />
<item command="ShowExtras" text="&amp;Extras" /> <item command="ShowExtras" text="&amp;Extras" />
<menu text="&amp;Show"> <menu text="&amp;Show">
<item command="ShowLayerEdges" text="&amp;Layer Edges" />
<item command="ShowSelectionEdges" text="&amp;Selection Edges" /> <item command="ShowSelectionEdges" text="&amp;Selection Edges" />
<item command="ShowGrid" text="&amp;Grid" /> <item command="ShowGrid" text="&amp;Grid" />
<item command="ShowPixelGrid" text="&amp;Pixel Grid" /> <item command="ShowPixelGrid" text="&amp;Pixel Grid" />

View File

@ -293,6 +293,7 @@
<option id="auto_scroll" type="bool" default="true" /> <option id="auto_scroll" type="bool" default="true" />
</section> </section>
<section id="show"> <section id="show">
<option id="layer_edges" type="bool" default="false" />
<option id="selection_edges" type="bool" default="true" /> <option id="selection_edges" type="bool" default="true" />
<option id="grid" type="bool" default="false" migrate="grid.visible" /> <option id="grid" type="bool" default="false" migrate="grid.visible" />
<option id="pixel_grid" type="bool" default="false" migrate="pixel_grid.visible" /> <option id="pixel_grid" type="bool" default="false" migrate="pixel_grid.visible" />

View File

@ -56,6 +56,7 @@
<color id="editor_face" value="#655561" /> <color id="editor_face" value="#655561" />
<color id="editor_sprite_border" value="#000000" /> <color id="editor_sprite_border" value="#000000" />
<color id="editor_sprite_bottom_border" value="#41412c" /> <color id="editor_sprite_bottom_border" value="#41412c" />
<color id="editor_layer_edges" value="#0000ff" />
<color id="listitem_normal_text" value="#000000" /> <color id="listitem_normal_text" value="#000000" />
<color id="listitem_normal_face" value="#ffffff" /> <color id="listitem_normal_face" value="#ffffff" />
<color id="listitem_selected_text" value="#ffffff" /> <color id="listitem_selected_text" value="#ffffff" />

View File

@ -38,11 +38,15 @@ protected:
if (docPref.show.selectionEdges()) { if (docPref.show.selectionEdges()) {
globPref.show = docPref.show; globPref.show = docPref.show;
docPref.show.selectionEdges(false); docPref.show.selectionEdges(false);
docPref.show.layerEdges(false);
docPref.show.grid(false); docPref.show.grid(false);
docPref.show.pixelGrid(false); docPref.show.pixelGrid(false);
} }
else { else {
docPref.show.selectionEdges(true); docPref.show.selectionEdges(true);
docPref.show.layerEdges(
docPref.show.layerEdges() ||
globPref.show.layerEdges());
docPref.show.grid( docPref.show.grid(
docPref.show.grid() || docPref.show.grid() ||
globPref.show.grid()); globPref.show.grid());
@ -53,6 +57,28 @@ protected:
} }
}; };
class ShowLayerEdgesCommand : public Command {
public:
ShowLayerEdgesCommand()
: Command("ShowLayerEdges",
"Show Layer Edges",
CmdUIOnlyFlag) {
}
Command* clone() const override { return new ShowLayerEdgesCommand(*this); }
protected:
bool onChecked(Context* ctx) override {
DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
return docPref.show.layerEdges();
}
void onExecute(Context* ctx) override {
DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
docPref.show.layerEdges(!docPref.show.layerEdges());
}
};
class ShowGridCommand : public Command { class ShowGridCommand : public Command {
public: public:
ShowGridCommand() ShowGridCommand()
@ -161,6 +187,11 @@ Command* CommandFactory::createShowPixelGridCommand()
return new ShowPixelGridCommand; return new ShowPixelGridCommand;
} }
Command* CommandFactory::createShowLayerEdgesCommand()
{
return new ShowLayerEdgesCommand;
}
Command* CommandFactory::createShowSelectionEdgesCommand() Command* CommandFactory::createShowSelectionEdgesCommand()
{ {
return new ShowSelectionEdgesCommand; return new ShowSelectionEdgesCommand;

View File

@ -119,6 +119,7 @@ FOR_EACH_COMMAND(SetSameInk)
FOR_EACH_COMMAND(ShowBrushPreview) FOR_EACH_COMMAND(ShowBrushPreview)
FOR_EACH_COMMAND(ShowExtras) FOR_EACH_COMMAND(ShowExtras)
FOR_EACH_COMMAND(ShowGrid) FOR_EACH_COMMAND(ShowGrid)
FOR_EACH_COMMAND(ShowLayerEdges)
FOR_EACH_COMMAND(ShowOnionSkin) FOR_EACH_COMMAND(ShowOnionSkin)
FOR_EACH_COMMAND(ShowPixelGrid) FOR_EACH_COMMAND(ShowPixelGrid)
FOR_EACH_COMMAND(ShowSelectionEdges) FOR_EACH_COMMAND(ShowSelectionEdges)

View File

@ -307,12 +307,15 @@ void Editor::setLayer(const Layer* layer)
m_layer = const_cast<Layer*>(layer); m_layer = const_cast<Layer*>(layer);
m_observers.notifyAfterLayerChanged(this); m_observers.notifyAfterLayerChanged(this);
// If the onion skinning depends on the active layer, we've to
// redraw the whole editor.
if (m_document && changed) { if (m_document && changed) {
if (m_docPref.onionskin.currentLayer()) if (// If the onion skinning depends on the active layer
m_docPref.onionskin.currentLayer() ||
// If the user want to see the active layer edges...
m_docPref.show.layerEdges()) {
// We've to redraw the whole editor
invalidate(); invalidate();
} }
}
// The active layer has changed. // The active layer has changed.
if (isActive()) if (isActive())
@ -679,6 +682,15 @@ void Editor::drawSpriteUnclippedRect(ui::Graphics* g, const gfx::Rect& _rc)
enclosingRect.x, enclosingRect.y+enclosingRect.h, enclosingRect.w); enclosingRect.x, enclosingRect.y+enclosingRect.h, enclosingRect.w);
} }
// Draw active cel edges
if (m_docPref.show.layerEdges()) {
Cel* cel = (m_layer ? m_layer->cel(m_frame): nullptr);
if (cel) {
g->drawRect(theme->colors.editorLayerEdges(),
editorToScreen(cel->bounds()).offset(-bounds().origin()));
}
}
// Draw the mask // Draw the mask
if (m_document->getMaskBoundaries()) if (m_document->getMaskBoundaries())
drawMask(g); drawMask(g);