-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to fill selection with foreground color (F key, related to …
- Loading branch information
Showing
9 changed files
with
207 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Aseprite | ||
// Copyright (C) 2018 David Capello | ||
// | ||
// This program is distributed under the terms of | ||
// the End-User License Agreement for Aseprite. | ||
|
||
#ifdef HAVE_CONFIG_H | ||
#include "config.h" | ||
#endif | ||
|
||
#include "app/app.h" | ||
#include "app/cmd/clear_mask.h" | ||
#include "app/cmd/trim_cel.h" | ||
#include "app/color_utils.h" | ||
#include "app/commands/command.h" | ||
#include "app/context_access.h" | ||
#include "app/modules/editors.h" | ||
#include "app/pref/preferences.h" | ||
#include "app/transaction.h" | ||
#include "app/ui/editor/editor.h" | ||
#include "app/util/expand_cel_canvas.h" | ||
#include "app/util/fill_selection.h" | ||
#include "doc/mask.h" | ||
|
||
namespace app { | ||
|
||
class FillCommand : public Command { | ||
public: | ||
FillCommand(); | ||
Command* clone() const override { return new FillCommand(*this); } | ||
|
||
protected: | ||
bool onEnabled(Context* ctx) override; | ||
void onExecute(Context* ctx) override; | ||
}; | ||
|
||
FillCommand::FillCommand() | ||
: Command(CommandId::Fill(), CmdUIOnlyFlag) | ||
{ | ||
} | ||
|
||
bool FillCommand::onEnabled(Context* ctx) | ||
{ | ||
if (ctx->checkFlags(ContextFlags::ActiveDocumentIsWritable | | ||
ContextFlags::ActiveLayerIsVisible | | ||
ContextFlags::ActiveLayerIsEditable | | ||
ContextFlags::ActiveLayerIsImage)) { | ||
return true; | ||
} | ||
else if (current_editor && | ||
current_editor->isMovingPixels()) { | ||
return true; | ||
} | ||
else | ||
return false; | ||
} | ||
|
||
void FillCommand::onExecute(Context* ctx) | ||
{ | ||
ContextWriter writer(ctx); | ||
Site site = *writer.site(); | ||
Document* doc = (app::Document*)site.document(); | ||
Sprite* sprite = site.sprite(); | ||
Cel* cel = site.cel(); | ||
Mask* mask = doc->mask(); | ||
if (!doc || !sprite || !cel || !mask || | ||
!doc->isMaskVisible()) | ||
return; | ||
|
||
Preferences& pref = Preferences::instance(); | ||
app::Color color = pref.colorBar.fgColor(); | ||
|
||
{ | ||
Transaction transaction(writer.context(), "Fill Selection with Foreground Color"); | ||
{ | ||
ExpandCelCanvas expand( | ||
site, cel->layer(), | ||
TiledMode::NONE, transaction, | ||
ExpandCelCanvas::None); | ||
|
||
gfx::Region rgn(sprite->bounds() | | ||
mask->bounds()); | ||
expand.validateDestCanvas(rgn); | ||
|
||
const gfx::Point offset = (mask->bounds().origin() | ||
- expand.getCel()->position()); | ||
|
||
fill_selection(expand.getDestCanvas(), | ||
offset, | ||
mask, | ||
color_utils::color_for_layer(color, | ||
cel->layer())); | ||
|
||
expand.commit(); | ||
} | ||
|
||
// If the cel wasn't deleted by cmd::ClearMask, we trim it. | ||
cel = ctx->activeSite().cel(); | ||
if (cel && cel->layer()->isTransparent()) | ||
transaction.execute(new cmd::TrimCel(cel)); | ||
|
||
transaction.commit(); | ||
} | ||
|
||
doc->notifyGeneralUpdate(); | ||
} | ||
|
||
Command* CommandFactory::createFillCommand() | ||
{ | ||
return new FillCommand; | ||
} | ||
|
||
} // namespace app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Aseprite | ||
// Copyright (C) 2018 David Capello | ||
// | ||
// This program is distributed under the terms of | ||
// the End-User License Agreement for Aseprite. | ||
|
||
#ifdef HAVE_CONFIG_H | ||
#include "config.h" | ||
#endif | ||
|
||
#include "app/util/fill_selection.h" | ||
|
||
#include "doc/image_impl.h" | ||
#include "doc/mask.h" | ||
#include "doc/primitives.h" | ||
|
||
namespace app { | ||
|
||
using namespace doc; | ||
|
||
void fill_selection(Image* image, | ||
const gfx::Point& offset, | ||
const Mask* mask, | ||
const color_t color) | ||
{ | ||
ASSERT(mask->bitmap()); | ||
if (!mask->bitmap()) | ||
return; | ||
|
||
const LockImageBits<BitmapTraits> maskBits(mask->bitmap()); | ||
LockImageBits<BitmapTraits>::const_iterator it = maskBits.begin(); | ||
|
||
const gfx::Rect maskBounds = mask->bounds(); | ||
for (int v=0; v<maskBounds.h; ++v) { | ||
for (int u=0; u<maskBounds.w; ++u, ++it) { | ||
ASSERT(it != maskBits.end()); | ||
if (*it) { | ||
put_pixel(image, | ||
u + offset.x, | ||
v + offset.y, color); | ||
} | ||
} | ||
} | ||
|
||
ASSERT(it == maskBits.end()); | ||
} | ||
|
||
} // namespace app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Aseprite | ||
// Copyright (C) 2018 David Capello | ||
// | ||
// This program is distributed under the terms of | ||
// the End-User License Agreement for Aseprite. | ||
|
||
#ifndef APP_UTIL_FILL_SELECTION_H_INCLUDED | ||
#define APP_UTIL_FILL_SELECTION_H_INCLUDED | ||
#pragma once | ||
|
||
#include "doc/color.h" | ||
#include "gfx/point.h" | ||
|
||
namespace doc { | ||
class Image; | ||
class Mask; | ||
} | ||
|
||
namespace app { | ||
|
||
void fill_selection(doc::Image* image, | ||
const gfx::Point& offset, | ||
const doc::Mask* mask, | ||
const doc::color_t color); | ||
|
||
} // namespace app | ||
|
||
#endif |