clang-format all files

This commit is contained in:
David Capello 2024-12-16 14:52:19 -03:00
parent 35c7f5bc4e
commit 09538f9a1a
1538 changed files with 57316 additions and 63036 deletions

2
laf

@ -1 +1 @@
Subproject commit 226a22bee53e888aff8d5df524edc31c19d9c29e Subproject commit 20d13cf0c762189650c7860bd3302a0a66cfa346

View File

@ -133,8 +133,7 @@ void ActiveSiteHandler::onAddFrame(DocEvent& ev)
void ActiveSiteHandler::onBeforeRemoveLayer(DocEvent& ev) void ActiveSiteHandler::onBeforeRemoveLayer(DocEvent& ev)
{ {
Data& data = getData(ev.document()); Data& data = getData(ev.document());
doc::Layer* selectedLayer = (data.layer != doc::NullId ? doc::Layer* selectedLayer = (data.layer != doc::NullId ? doc::get<doc::Layer>(data.layer) :
doc::get<doc::Layer>(data.layer):
nullptr); nullptr);
if (!selectedLayer) if (!selectedLayer)
return; return;
@ -143,11 +142,9 @@ void ActiveSiteHandler::onBeforeRemoveLayer(DocEvent& ev)
data.range.eraseAndAdjust(ev.layer()); data.range.eraseAndAdjust(ev.layer());
// Select other layer as active // Select other layer as active
doc::Layer* layerToSelect = doc::Layer* layerToSelect = view::candidate_if_layer_is_deleted(selectedLayer, ev.layer());
view::candidate_if_layer_is_deleted(selectedLayer, ev.layer());
if (selectedLayer != layerToSelect) { if (selectedLayer != layerToSelect) {
data.layer = (layerToSelect ? layerToSelect->id(): data.layer = (layerToSelect ? layerToSelect->id() : doc::NullId);
doc::NullId);
} }
} }

View File

@ -110,12 +110,9 @@ namespace {
class ConsoleEngineDelegate : public script::EngineDelegate { class ConsoleEngineDelegate : public script::EngineDelegate {
public: public:
ConsoleEngineDelegate(Console& console) : m_console(console) {} ConsoleEngineDelegate(Console& console) : m_console(console) {}
void onConsoleError(const char* text) override { void onConsoleError(const char* text) override { onConsolePrint(text); }
onConsolePrint(text); void onConsolePrint(const char* text) override { m_console.printf("%s\n", text); }
}
void onConsolePrint(const char* text) override {
m_console.printf("%s\n", text);
}
private: private:
Console& m_console; Console& m_console;
}; };
@ -149,8 +146,7 @@ public:
std::unique_ptr<app::crash::DataRecovery> m_recovery; std::unique_ptr<app::crash::DataRecovery> m_recovery;
#endif #endif
Modules(const bool createLogInDesktop, Modules(const bool createLogInDesktop, Preferences& pref)
Preferences& pref)
: m_loggerModule(createLogInDesktop) : m_loggerModule(createLogInDesktop)
, m_strings(pref, m_extensions) , m_strings(pref, m_extensions)
, m_activeToolManager(&m_toolbox) , m_activeToolManager(&m_toolbox)
@ -161,14 +157,15 @@ public:
{ {
} }
~Modules() { ~Modules()
{
#ifdef ENABLE_DATA_RECOVERY #ifdef ENABLE_DATA_RECOVERY
ASSERT(m_recovery == nullptr || ASSERT(m_recovery == nullptr || ui::get_app_state() == ui::AppState::kClosingWithException);
ui::get_app_state() == ui::AppState::kClosingWithException);
#endif #endif
} }
app::crash::DataRecovery* recovery() { app::crash::DataRecovery* recovery()
{
#ifdef ENABLE_DATA_RECOVERY #ifdef ENABLE_DATA_RECOVERY
return m_recovery.get(); return m_recovery.get();
#else #else
@ -176,18 +173,19 @@ public:
#endif #endif
} }
void createDataRecovery(Context* ctx) { void createDataRecovery(Context* ctx)
{
#ifdef ENABLE_DATA_RECOVERY #ifdef ENABLE_DATA_RECOVERY
#ifdef ENABLE_TRIAL_MODE #ifdef ENABLE_TRIAL_MODE
DRM_INVALID{ DRM_INVALID
{
return; return;
} }
#endif #endif
m_recovery = std::make_unique<app::crash::DataRecovery>(ctx); m_recovery = std::make_unique<app::crash::DataRecovery>(ctx);
m_recovery->SessionsListIsReady.connect( m_recovery->SessionsListIsReady.connect([] {
[] {
ui::assert_ui_thread(); ui::assert_ui_thread();
auto app = App::instance(); auto app = App::instance();
if (app && app->mainWindow()) { if (app && app->mainWindow()) {
@ -198,11 +196,13 @@ public:
#endif #endif
} }
void searchDataRecoverySessions() { void searchDataRecoverySessions()
{
#ifdef ENABLE_DATA_RECOVERY #ifdef ENABLE_DATA_RECOVERY
#ifdef ENABLE_TRIAL_MODE #ifdef ENABLE_TRIAL_MODE
DRM_INVALID{ DRM_INVALID
{
return; return;
} }
#endif #endif
@ -213,11 +213,13 @@ public:
#endif #endif
} }
void deleteDataRecovery() { void deleteDataRecovery()
{
#ifdef ENABLE_DATA_RECOVERY #ifdef ENABLE_DATA_RECOVERY
#ifdef ENABLE_TRIAL_MODE #ifdef ENABLE_TRIAL_MODE
DRM_INVALID{ DRM_INVALID
{
return; return;
} }
#endif #endif
@ -225,7 +227,6 @@ public:
m_recovery.reset(); m_recovery.reset();
#endif #endif
} }
}; };
App* App::m_instance = nullptr; App* App::m_instance = nullptr;
@ -258,8 +259,7 @@ int App::initialize(const AppOptions& options)
// True if we should show a warning when running the main Aseprite // True if we should show a warning when running the main Aseprite
// executable (no test/benchmark) without args and the GUI is not // executable (no test/benchmark) without args and the GUI is not
// available. // available.
m_showCliOnlyWarning = m_showCliOnlyWarning = (startGui && base::utf8_icmp(base::get_file_title(options.exeName()),
(startGui && base::utf8_icmp(base::get_file_title(options.exeName()),
get_app_name()) == 0); get_app_name()) == 0);
#endif #endif
@ -281,8 +281,7 @@ int App::initialize(const AppOptions& options)
#if LAF_WINDOWS #if LAF_WINDOWS
if (options.disableWintab() || if (options.disableWintab() || !pref.experimental.loadWintabDriver() ||
!pref.experimental.loadWintabDriver() ||
pref.tablet.api() == "pointer") { pref.tablet.api() == "pointer") {
tabletOptions.api = os::TabletAPI::WindowsPointerInput; tabletOptions.api = os::TabletAPI::WindowsPointerInput;
} }
@ -307,20 +306,15 @@ int App::initialize(const AppOptions& options)
system->setTabletOptions(tabletOptions); system->setTabletOptions(tabletOptions);
system->setAppName(get_app_name()); system->setAppName(get_app_name());
system->setAppMode(m_isGui ? os::AppMode::GUI: system->setAppMode(m_isGui ? os::AppMode::GUI : os::AppMode::CLI);
os::AppMode::CLI);
if (m_isGui) if (m_isGui)
m_uiSystem.reset(new ui::UISystem); m_uiSystem.reset(new ui::UISystem);
bool createLogInDesktop = false; bool createLogInDesktop = false;
switch (options.verboseLevel()) { switch (options.verboseLevel()) {
case AppOptions::kNoVerbose: case AppOptions::kNoVerbose: base::set_log_level(ERROR); break;
base::set_log_level(ERROR); case AppOptions::kVerbose: base::set_log_level(INFO); break;
break;
case AppOptions::kVerbose:
base::set_log_level(INFO);
break;
case AppOptions::kHighlyVerbose: case AppOptions::kHighlyVerbose:
base::set_log_level(VERBOSE); base::set_log_level(VERBOSE);
createLogInDesktop = true; createLogInDesktop = true;
@ -444,7 +438,8 @@ namespace {
struct DeleteAllDocs { struct DeleteAllDocs {
Context* m_ctx; Context* m_ctx;
DeleteAllDocs(Context* ctx) : m_ctx(ctx) {} DeleteAllDocs(Context* ctx) : m_ctx(ctx) {}
~DeleteAllDocs() { ~DeleteAllDocs()
{
std::vector<Doc*> docs; std::vector<Doc*> docs;
// Add all documents that were closed in the past, these docs // Add all documents that were closed in the past, these docs
@ -488,8 +483,7 @@ void App::run()
auto manager = ui::Manager::getDefault(); auto manager = ui::Manager::getDefault();
#if LAF_WINDOWS #if LAF_WINDOWS
// How to interpret one finger on Windows tablets. // How to interpret one finger on Windows tablets.
manager->display()->nativeWindow() manager->display()->nativeWindow()->setInterpretOneFingerGestureAsMouseMovement(
->setInterpretOneFingerGestureAsMouseMovement(
preferences().experimental.oneFingerAsMouseMovement()); preferences().experimental.oneFingerAsMouseMovement());
#if ENABLE_WEBP #if ENABLE_WEBP
// In Windows we use a custom webp decoder for drag & drop operations. // In Windows we use a custom webp decoder for drag & drop operations.
@ -507,8 +501,7 @@ void App::run()
ResourceFinder rf; ResourceFinder rf;
rf.includeDataDir(fmt::format("icons/ase{0}.png", size).c_str()); rf.includeDataDir(fmt::format("icons/ase{0}.png", size).c_str());
if (rf.findFirst()) { if (rf.findFirst()) {
os::SurfaceRef surf = os::System::instance() os::SurfaceRef surf = os::System::instance()->loadRgbaSurface(rf.filename().c_str());
->loadRgbaSurface(rf.filename().c_str());
if (surf) { if (surf) {
surf->setImmutable(); surf->setImmutable();
icons.push_back(surf); icons.push_back(surf);
@ -549,8 +542,7 @@ void App::run()
#ifdef ENABLE_UPDATER #ifdef ENABLE_UPDATER
// Launch the thread to check for updates. // Launch the thread to check for updates.
app::CheckUpdateThreadLauncher checkUpdate( app::CheckUpdateThreadLauncher checkUpdate(m_mainWindow->getCheckUpdateDelegate());
m_mainWindow->getCheckUpdateDelegate());
checkUpdate.launch(); checkUpdate.launch();
#endif #endif
@ -698,10 +690,8 @@ bool App::isPortable()
{ {
static std::optional<bool> is_portable; static std::optional<bool> is_portable;
if (!is_portable) { if (!is_portable) {
is_portable = is_portable = base::is_file(
base::is_file(base::join_path( base::join_path(base::get_file_path(base::get_app_path()), "aseprite.ini"));
base::get_file_path(base::get_app_path()),
"aseprite.ini"));
} }
return *is_portable; return *is_portable;
} }
@ -896,14 +886,20 @@ int app_get_color_to_clear_layer(Layer* layer)
} }
#ifdef ENABLE_DRM #ifdef ENABLE_DRM
void app_configure_drm() { void app_configure_drm()
{
ResourceFinder userDirRf, dataDirRf; ResourceFinder userDirRf, dataDirRf;
userDirRf.includeUserDir(""); userDirRf.includeUserDir("");
dataDirRf.includeDataDir(""); dataDirRf.includeDataDir("");
std::map<std::string, std::string> config = { std::map<std::string, std::string> config = {
{ "data", dataDirRf.getFirstOrCreateDefault() } { "data", dataDirRf.getFirstOrCreateDefault() }
}; };
DRM_CONFIGURE(get_app_url(), get_app_name(), get_app_version(), userDirRf.getFirstOrCreateDefault(), updater::getUserAgent(), config); DRM_CONFIGURE(get_app_url(),
get_app_name(),
get_app_version(),
userDirRf.getFirstOrCreateDefault(),
updater::getUserAgent(),
config);
} }
#endif #endif

View File

@ -60,7 +60,7 @@ namespace app {
class ActiveToolManager; class ActiveToolManager;
class Tool; class Tool;
class ToolBox; class ToolBox;
} } // namespace tools
using namespace doc; using namespace doc;
@ -99,7 +99,8 @@ namespace app {
Extensions& extensions() const; Extensions& extensions() const;
crash::DataRecovery* dataRecovery() const; crash::DataRecovery* dataRecovery() const;
AppBrushes& brushes() { AppBrushes& brushes()
{
ASSERT(m_brushes.get()); ASSERT(m_brushes.get());
return *m_brushes; return *m_brushes;
} }

View File

@ -41,9 +41,8 @@ ImageRef load_xml_image(const XMLElement* imageElem)
ImageRef image; ImageRef image;
int w, h; int w, h;
if (imageElem->QueryIntAttribute("width", &w) != XML_SUCCESS || if (imageElem->QueryIntAttribute("width", &w) != XML_SUCCESS ||
imageElem->QueryIntAttribute("height", &h) != XML_SUCCESS || imageElem->QueryIntAttribute("height", &h) != XML_SUCCESS || w < 0 || w > 9999 || h < 0 ||
w < 0 || w > 9999 || h > 9999)
h < 0 || h > 9999)
return image; return image;
auto formatValue = imageElem->Attribute("format"); auto formatValue = imageElem->Attribute("format");
@ -66,10 +65,14 @@ ImageRef load_xml_image(const XMLElement* imageElem)
if ((end - it) < 4) if ((end - it) < 4)
break; break;
int r = *it; ++it; int r = *it;
int g = *it; ++it; ++it;
int b = *it; ++it; int g = *it;
int a = *it; ++it; ++it;
int b = *it;
++it;
int a = *it;
++it;
pixel = doc::rgba(r, g, b, a); pixel = doc::rgba(r, g, b, a);
} }
@ -81,8 +84,10 @@ ImageRef load_xml_image(const XMLElement* imageElem)
if ((end - it) < 2) if ((end - it) < 2)
break; break;
int v = *it; ++it; int v = *it;
int a = *it; ++it; ++it;
int a = *it;
++it;
pixel = doc::graya(v, a); pixel = doc::graya(v, a);
} }
@ -187,8 +192,7 @@ AppBrushes::AppBrushes()
load(fn); load(fn);
} }
catch (const std::exception& ex) { catch (const std::exception& ex) {
LOG(ERROR, "BRSH: Error loading user brushes from '%s': %s\n", LOG(ERROR, "BRSH: Error loading user brushes from '%s': %s\n", fn.c_str(), ex.what());
fn.c_str(), ex.what());
} }
} }
m_userBrushesFilename = fn; m_userBrushesFilename = fn;
@ -202,8 +206,10 @@ AppBrushes::~AppBrushes()
} }
// We cannot throw exceptions from a destructor // We cannot throw exceptions from a destructor
catch (const std::exception& ex) { catch (const std::exception& ex) {
LOG(ERROR, "BRSH: Error saving user brushes to '%s': %s\n", LOG(ERROR,
m_userBrushesFilename.c_str(), ex.what()); "BRSH: Error saving user brushes to '%s': %s\n",
m_userBrushesFilename.c_str(),
ex.what());
} }
} }
} }
@ -230,8 +236,7 @@ void AppBrushes::removeBrushSlot(slot_id slot)
m_slots[slot] = BrushSlot(); m_slots[slot] = BrushSlot();
// Erase empty trailing slots // Erase empty trailing slots
while (!m_slots.empty() && while (!m_slots.empty() && m_slots[m_slots.size() - 1].isEmpty())
m_slots[m_slots.size()-1].isEmpty())
m_slots.erase(--m_slots.end()); m_slots.erase(--m_slots.end());
ItemsChange(); ItemsChange();
@ -249,8 +254,7 @@ void AppBrushes::removeAllBrushSlots()
bool AppBrushes::hasBrushSlot(slot_id slot) const bool AppBrushes::hasBrushSlot(slot_id slot) const
{ {
--slot; --slot;
return (slot >= 0 && slot < (int)m_slots.size() && return (slot >= 0 && slot < (int)m_slots.size() && !m_slots[slot].isEmpty());
!m_slots[slot].isEmpty());
} }
BrushSlot AppBrushes::getBrushSlot(slot_id slot) const BrushSlot AppBrushes::getBrushSlot(slot_id slot) const
@ -274,8 +278,7 @@ void AppBrushes::setBrushSlot(slot_id slot, const BrushSlot& brush)
void AppBrushes::lockBrushSlot(slot_id slot) void AppBrushes::lockBrushSlot(slot_id slot)
{ {
--slot; --slot;
if (slot >= 0 && slot < (int)m_slots.size() && if (slot >= 0 && slot < (int)m_slots.size() && !m_slots[slot].isEmpty()) {
!m_slots[slot].isEmpty()) {
m_slots[slot].setLocked(true); m_slots[slot].setLocked(true);
} }
} }
@ -283,8 +286,7 @@ void AppBrushes::lockBrushSlot(slot_id slot)
void AppBrushes::unlockBrushSlot(slot_id slot) void AppBrushes::unlockBrushSlot(slot_id slot)
{ {
--slot; --slot;
if (slot >= 0 && slot < (int)m_slots.size() && if (slot >= 0 && slot < (int)m_slots.size() && !m_slots[slot].isEmpty()) {
!m_slots[slot].isEmpty()) {
m_slots[slot].setLocked(false); m_slots[slot].setLocked(false);
} }
} }
@ -292,26 +294,22 @@ void AppBrushes::unlockBrushSlot(slot_id slot)
bool AppBrushes::isBrushSlotLocked(slot_id slot) const bool AppBrushes::isBrushSlotLocked(slot_id slot) const
{ {
--slot; --slot;
if (slot >= 0 && slot < (int)m_slots.size() && if (slot >= 0 && slot < (int)m_slots.size() && !m_slots[slot].isEmpty()) {
!m_slots[slot].isEmpty()) {
return m_slots[slot].locked(); return m_slots[slot].locked();
} }
else else
return false; return false;
} }
static const int kBrushFlags = static const int kBrushFlags = int(BrushSlot::Flags::BrushType) | int(BrushSlot::Flags::BrushSize) |
int(BrushSlot::Flags::BrushType) |
int(BrushSlot::Flags::BrushSize) |
int(BrushSlot::Flags::BrushAngle); int(BrushSlot::Flags::BrushAngle);
void AppBrushes::load(const std::string& filename) void AppBrushes::load(const std::string& filename)
{ {
XMLDocumentRef doc = app::open_xml(filename); XMLDocumentRef doc = app::open_xml(filename);
XMLHandle handle(doc.get()); XMLHandle handle(doc.get());
XMLElement* brushElem = handle XMLElement* brushElem =
.FirstChildElement("brushes") handle.FirstChildElement("brushes").FirstChildElement("brush").ToElement();
.FirstChildElement("brush").ToElement();
while (brushElem) { while (brushElem) {
// flags // flags
@ -329,12 +327,13 @@ void AppBrushes::load(const std::string& filename)
const char* size = brushElem->Attribute("size"); const char* size = brushElem->Attribute("size");
const char* angle = brushElem->Attribute("angle"); const char* angle = brushElem->Attribute("angle");
if (type || size || angle) { if (type || size || angle) {
if (type) flags |= int(BrushSlot::Flags::BrushType); if (type)
if (size) flags |= int(BrushSlot::Flags::BrushSize); flags |= int(BrushSlot::Flags::BrushType);
if (angle) flags |= int(BrushSlot::Flags::BrushAngle); if (size)
brush.reset( flags |= int(BrushSlot::Flags::BrushSize);
new Brush( if (angle)
(type ? string_id_to_brush_type(type): kFirstBrushType), flags |= int(BrushSlot::Flags::BrushAngle);
brush.reset(new Brush((type ? string_id_to_brush_type(type) : kFirstBrushType),
(size ? base::convert_to<int>(std::string(size)) : 1), (size ? base::convert_to<int>(std::string(size)) : 1),
(angle ? base::convert_to<int>(std::string(angle)) : 0))); (angle ? base::convert_to<int>(std::string(angle)) : 0)));
} }
@ -397,16 +396,19 @@ void AppBrushes::load(const std::string& filename)
} }
// Image color (enabled by default for backward compatibility) // Image color (enabled by default for backward compatibility)
if (!brushElem->Attribute("imagecolor") || if (!brushElem->Attribute("imagecolor") || bool_attr(brushElem, "imagecolor", false))
bool_attr(brushElem, "imagecolor", false))
flags |= int(BrushSlot::Flags::ImageColor); flags |= int(BrushSlot::Flags::ImageColor);
if (flags != 0) if (flags != 0)
flags |= int(BrushSlot::Flags::Locked); flags |= int(BrushSlot::Flags::Locked);
BrushSlot brushSlot(BrushSlot::Flags(flags), BrushSlot brushSlot(BrushSlot::Flags(flags),
brush, fgColor, bgColor, brush,
inkType, inkOpacity, shade, fgColor,
bgColor,
inkType,
inkOpacity,
shade,
pixelPerfect); pixelPerfect);
m_slots.push_back(brushSlot); m_slots.push_back(brushSlot);
@ -437,8 +439,7 @@ void AppBrushes::save(const std::string& filename) const
ASSERT(slot.brush()); ASSERT(slot.brush());
if (flags & int(BrushSlot::Flags::BrushType)) { if (flags & int(BrushSlot::Flags::BrushType)) {
brushElem->SetAttribute( brushElem->SetAttribute("type", brush_type_to_string_id(slot.brush()->type()).c_str());
"type", brush_type_to_string_id(slot.brush()->type()).c_str());
} }
if (flags & int(BrushSlot::Flags::BrushSize)) { if (flags & int(BrushSlot::Flags::BrushSize)) {
@ -449,8 +450,7 @@ void AppBrushes::save(const std::string& filename) const
brushElem->SetAttribute("angle", slot.brush()->angle()); brushElem->SetAttribute("angle", slot.brush()->angle());
} }
if (slot.brush()->type() == kImageBrushType && if (slot.brush()->type() == kImageBrushType && slot.brush()->originalImage()) {
slot.brush()->originalImage()) {
XMLElement* elem = brushElem->InsertNewChildElement("image"); XMLElement* elem = brushElem->InsertNewChildElement("image");
save_xml_image(elem, slot.brush()->originalImage()); save_xml_image(elem, slot.brush()->originalImage());
@ -460,8 +460,7 @@ void AppBrushes::save(const std::string& filename) const
} }
// Image color // Image color
brushElem->SetAttribute( brushElem->SetAttribute("imagecolor",
"imagecolor",
(flags & int(BrushSlot::Flags::ImageColor)) ? "true" : "false"); (flags & int(BrushSlot::Flags::ImageColor)) ? "true" : "false");
} }
} }
@ -480,8 +479,7 @@ void AppBrushes::save(const std::string& filename) const
// Ink // Ink
if (flags & int(BrushSlot::Flags::InkType)) { if (flags & int(BrushSlot::Flags::InkType)) {
XMLElement* elem = brushElem->InsertNewChildElement("inktype"); XMLElement* elem = brushElem->InsertNewChildElement("inktype");
elem->SetAttribute( elem->SetAttribute("value", app::tools::ink_type_to_string_id(slot.inkType()).c_str());
"value", app::tools::ink_type_to_string_id(slot.inkType()).c_str());
} }
if (flags & int(BrushSlot::Flags::InkOpacity)) { if (flags & int(BrushSlot::Flags::InkOpacity)) {

View File

@ -37,11 +37,11 @@
#include "tinyxml2.h" #include "tinyxml2.h"
#include <algorithm>
#include <cctype> #include <cctype>
#include <cstdlib>
#include <cstring> #include <cstring>
#include <string> #include <string>
#include <algorithm>
#include <cstdlib>
#define MENUS_TRACE(...) // TRACEARGS #define MENUS_TRACE(...) // TRACEARGS
@ -75,22 +75,12 @@ bool is_text_entry_shortcut(const os::Shortcut& shortcut)
const int lchr = std::tolower(chr); const int lchr = std::tolower(chr);
bool result = bool result =
((mod == os::KeyModifiers::kKeyNoneModifier || ((mod == os::KeyModifiers::kKeyNoneModifier || mod == os::KeyModifiers::kKeyShiftModifier) &&
mod == os::KeyModifiers::kKeyShiftModifier) && chr >= 32 && chr < 0xF000) ||
chr >= 32 && chr < 0xF000) ((mod == os::KeyModifiers::kKeyCmdModifier || mod == os::KeyModifiers::kKeyCtrlModifier) &&
|| (lchr == 'a' || lchr == 'c' || lchr == 'v' || lchr == 'x')) ||
((mod == os::KeyModifiers::kKeyCmdModifier || (chr == kUnicodeInsert || chr == kUnicodeDel || chr == kUnicodeHome || chr == kUnicodeEnd ||
mod == os::KeyModifiers::kKeyCtrlModifier) && chr == kUnicodeLeft || chr == kUnicodeRight || chr == kUnicodeEsc || chr == kUnicodeEnter);
(lchr == 'a' || lchr == 'c' || lchr == 'v' || lchr == 'x'))
||
(chr == kUnicodeInsert ||
chr == kUnicodeDel ||
chr == kUnicodeHome ||
chr == kUnicodeEnd ||
chr == kUnicodeLeft ||
chr == kUnicodeRight ||
chr == kUnicodeEsc ||
chr == kUnicodeEnter);
return result; return result;
} }
@ -120,8 +110,7 @@ bool can_call_global_shortcut(const AppMenuItem::Native* native)
// prefer text input, so we cannot call shortcuts without // prefer text input, so we cannot call shortcuts without
// modifiers (e.g. F or T keystrokes) to trigger a global command // modifiers (e.g. F or T keystrokes) to trigger a global command
// in a text field. // in a text field.
(focus == nullptr || (focus == nullptr || focus->type() != ui::kEntryWidget ||
focus->type() != ui::kEntryWidget ||
!is_text_entry_shortcut(native->shortcut)) && !is_text_entry_shortcut(native->shortcut)) &&
(native->keyContext == KeyContext::Any || (native->keyContext == KeyContext::Any ||
native->keyContext == KeyboardShortcuts::instance()->getCurrentKeyContext()); native->keyContext == KeyboardShortcuts::instance()->getCurrentKeyContext());
@ -266,8 +255,7 @@ int from_scancode_to_unicode(KeyScancode scancode)
return 0; return 0;
} }
AppMenuItem::Native get_native_shortcut_for_command( AppMenuItem::Native get_native_shortcut_for_command(const char* commandId,
const char* commandId,
const Params& params = Params()) const Params& params = Params())
{ {
AppMenuItem::Native native; AppMenuItem::Native native;
@ -307,8 +295,7 @@ os::Shortcut get_os_shortcut_from_key(const Key* key)
#endif #endif
return os::Shortcut( return os::Shortcut(
(accel.unicodeChar() ? accel.unicodeChar(): (accel.unicodeChar() ? accel.unicodeChar() : from_scancode_to_unicode(accel.scancode())),
from_scancode_to_unicode(accel.scancode())),
accel.modifiers()); accel.modifiers());
} }
else else
@ -323,15 +310,11 @@ AppMenus* AppMenus::instance()
return s_instance; return s_instance;
} }
AppMenus::AppMenus(RecentFiles* recentFiles) AppMenus::AppMenus(RecentFiles* recentFiles) : m_recentFilesPlaceholder(nullptr), m_osMenu(nullptr)
: m_recentFilesPlaceholder(nullptr)
, m_osMenu(nullptr)
{ {
ASSERT(s_instance == nullptr); ASSERT(s_instance == nullptr);
s_instance = this; s_instance = this;
m_recentFilesConn = m_recentFilesConn = recentFiles->Changed.connect([this] { rebuildRecentList(); });
recentFiles->Changed.connect(
[this]{ rebuildRecentList(); });
} }
AppMenus::~AppMenus() AppMenus::~AppMenus()
@ -386,8 +369,7 @@ void AppMenus::reload()
// Add one menu item to run each script from the user scripts/ folder // Add one menu item to run each script from the user scripts/ folder
{ {
MenuItem* scriptsMenu = dynamic_cast<MenuItem*>( MenuItem* scriptsMenu = dynamic_cast<MenuItem*>(m_rootMenu->findItemById("scripts_menu"));
m_rootMenu->findItemById("scripts_menu"));
#ifdef ENABLE_SCRIPTING #ifdef ENABLE_SCRIPTING
// Load scripts // Load scripts
ResourceFinder rf; ResourceFinder rf;
@ -455,9 +437,7 @@ void AppMenus::reload()
LOG("MENU: Loading commands keyboard shortcuts from %s\n", path); LOG("MENU: Loading commands keyboard shortcuts from %s\n", path);
XMLElement* xmlKey = handle XMLElement* xmlKey = handle.FirstChildElement("gui").FirstChildElement("keyboard").ToElement();
.FirstChildElement("gui")
.FirstChildElement("keyboard").ToElement();
// From a fresh start, load the default keys // From a fresh start, load the default keys
KeyboardShortcuts::instance()->clear(); KeyboardShortcuts::instance()->clear();
@ -465,11 +445,9 @@ void AppMenus::reload()
// Load extension-defined keys // Load extension-defined keys
for (const Extension* ext : App::instance()->extensions()) { for (const Extension* ext : App::instance()->extensions()) {
if (ext->isEnabled() && if (ext->isEnabled() && ext->hasKeys()) {
ext->hasKeys()) {
for (const auto& kv : ext->keys()) { for (const auto& kv : ext->keys()) {
KeyboardShortcuts::instance()->importFile( KeyboardShortcuts::instance()->importFile(kv.second, KeySource::ExtensionDefined);
kv.second, KeySource::ExtensionDefined);
} }
} }
} }
@ -489,13 +467,10 @@ void AppMenus::reload()
} }
#ifdef ENABLE_SCRIPTING #ifdef ENABLE_SCRIPTING
void AppMenus::loadScriptsSubmenu(ui::Menu* menu, void AppMenus::loadScriptsSubmenu(ui::Menu* menu, const std::string& dir, const bool rootLevel)
const std::string& dir,
const bool rootLevel)
{ {
auto files = base::list_files(dir); auto files = base::list_files(dir);
std::sort(files.begin(), files.end(), std::sort(files.begin(), files.end(), [](const std::string& a, const std::string& b) {
[](const std::string& a, const std::string& b) {
return base::compare_filenames(a, b) < 0; return base::compare_filenames(a, b) < 0;
}); });
int insertPos = 0; int insertPos = 0;
@ -510,18 +485,15 @@ void AppMenus::loadScriptsSubmenu(ui::Menu* menu,
if (base::string_to_lower(base::get_file_extension(fn)) == "lua") { if (base::string_to_lower(base::get_file_extension(fn)) == "lua") {
Params params; Params params;
params.set("filename", fullFn.c_str()); params.set("filename", fullFn.c_str());
menuitem = new AppMenuItem( menuitem =
base::get_file_title(fn).c_str(), new AppMenuItem(base::get_file_title(fn).c_str(), CommandId::RunScript(), params);
CommandId::RunScript(),
params);
} }
} }
else if (base::is_directory(fullFn)) { else if (base::is_directory(fullFn)) {
Menu* submenu = new Menu(); Menu* submenu = new Menu();
loadScriptsSubmenu(submenu, fullFn, false); loadScriptsSubmenu(submenu, fullFn, false);
menuitem = new AppMenuItem( menuitem = new AppMenuItem(base::get_file_title(fn).c_str());
base::get_file_title(fn).c_str());
menuitem->setSubmenu(submenu); menuitem->setSubmenu(submenu);
} }
if (menuitem) { if (menuitem) {
@ -543,7 +515,8 @@ void AppMenus::initTheme()
bool AppMenus::rebuildRecentList() bool AppMenus::rebuildRecentList()
{ {
MENUS_TRACE("MENUS: AppMenus::rebuildRecentList m_recentFilesPlaceholder=", m_recentFilesPlaceholder); MENUS_TRACE("MENUS: AppMenus::rebuildRecentList m_recentFilesPlaceholder=",
m_recentFilesPlaceholder);
if (!m_recentFilesPlaceholder) if (!m_recentFilesPlaceholder)
return true; return true;
@ -563,21 +536,15 @@ bool AppMenus::rebuildRecentList()
auto recent = App::instance()->recentFiles(); auto recent = App::instance()->recentFiles();
base::paths files; base::paths files;
files.insert(files.end(), files.insert(files.end(), recent->pinnedFiles().begin(), recent->pinnedFiles().end());
recent->pinnedFiles().begin(), files.insert(files.end(), recent->recentFiles().begin(), recent->recentFiles().end());
recent->pinnedFiles().end());
files.insert(files.end(),
recent->recentFiles().begin(),
recent->recentFiles().end());
if (!files.empty()) { if (!files.empty()) {
Params params; Params params;
for (const auto& fn : files) { for (const auto& fn : files) {
params.set("filename", fn.c_str()); params.set("filename", fn.c_str());
std::unique_ptr<AppMenuItem> menuitem( std::unique_ptr<AppMenuItem> menuitem(
new AppMenuItem(base::get_file_name(fn).c_str(), new AppMenuItem(base::get_file_name(fn).c_str(), CommandId::OpenFile(), params));
CommandId::OpenFile(),
params));
menuitem->setIsRecentFileItem(true); menuitem->setIsRecentFileItem(true);
m_recentMenuItems.push_back(menuitem.get()); m_recentMenuItems.push_back(menuitem.get());
@ -586,8 +553,7 @@ bool AppMenus::rebuildRecentList()
} }
else { else {
std::unique_ptr<AppMenuItem> menuitem( std::unique_ptr<AppMenuItem> menuitem(
new AppMenuItem( new AppMenuItem(Strings::main_menu_file_no_recent_file()));
Strings::main_menu_file_no_recent_file()));
menuitem->setIsRecentFileItem(true); menuitem->setIsRecentFileItem(true);
menuitem->setEnabled(false); menuitem->setEnabled(false);
@ -596,8 +562,7 @@ bool AppMenus::rebuildRecentList()
} }
// Sync native menus // Sync native menus
if (owner->native() && if (owner->native() && owner->native()->menuItem) {
owner->native()->menuItem) {
auto menus = os::System::instance()->menus(); auto menus = os::System::instance()->menus();
os::MenuRef osMenu = (menus ? menus->makeMenu() : nullptr); os::MenuRef osMenu = (menus ? menus->makeMenu() : nullptr);
if (osMenu) { if (osMenu) {
@ -611,16 +576,14 @@ bool AppMenus::rebuildRecentList()
Menu* AppMenus::getAnimationMenu() Menu* AppMenus::getAnimationMenu()
{ {
auto menuItem = auto menuItem = dynamic_cast<MenuItem*>(m_rootMenu->findItemById("animation_menu"));
dynamic_cast<MenuItem*>(m_rootMenu->findItemById("animation_menu"));
if (menuItem) if (menuItem)
return menuItem->getSubmenu(); return menuItem->getSubmenu();
else else
return nullptr; return nullptr;
} }
void AppMenus::addMenuGroup(const std::string& groupId, void AppMenus::addMenuGroup(const std::string& groupId, MenuItem* menuItem)
MenuItem* menuItem)
{ {
GroupInfo& group = m_groups[groupId]; GroupInfo& group = m_groups[groupId];
ASSERT(group.menu == nullptr); ASSERT(group.menu == nullptr);
@ -639,22 +602,20 @@ void AppMenus::removeMenuGroup(const std::string& groupId)
if (group.menu->getOwnerMenuItem()) { if (group.menu->getOwnerMenuItem()) {
ui::MenuItem* item = group.menu->getOwnerMenuItem(); ui::MenuItem* item = group.menu->getOwnerMenuItem();
removeMenuItemFromGroup( removeMenuItemFromGroup([item](Widget* i) { return item == i; });
[item](Widget* i){
return item == i;
});
} }
m_groups.erase(it); m_groups.erase(it);
} }
} }
void AppMenus::addMenuItemIntoGroup(const std::string& groupId, void AppMenus::addMenuItemIntoGroup(const std::string& groupId, std::unique_ptr<Widget>&& menuItem)
std::unique_ptr<Widget>&& menuItem)
{ {
auto it = m_groups.find(groupId); auto it = m_groups.find(groupId);
if (it == m_groups.end()) { if (it == m_groups.end()) {
LOG(ERROR, "MENU: An extension tried to add a command (%s) in a non-existent group (%s)\n", LOG(ERROR,
menuItem->text().c_str(), groupId.c_str()); "MENU: An extension tried to add a command (%s) in a non-existent group (%s)\n",
menuItem->text().c_str(),
groupId.c_str());
menuItem.release(); menuItem.release();
return; return;
} }
@ -702,8 +663,7 @@ void AppMenus::removeMenuItemFromGroup(Pred pred)
void AppMenus::removeMenuItemFromGroup(Command* cmd) void AppMenus::removeMenuItemFromGroup(Command* cmd)
{ {
removeMenuItemFromGroup( removeMenuItemFromGroup([cmd](Widget* item) {
[cmd](Widget* item){
auto appMenuItem = dynamic_cast<AppMenuItem*>(item); auto appMenuItem = dynamic_cast<AppMenuItem*>(item);
return (appMenuItem && appMenuItem->getCommand() == cmd); return (appMenuItem && appMenuItem->getCommand() == cmd);
}); });
@ -711,10 +671,7 @@ void AppMenus::removeMenuItemFromGroup(Command* cmd)
void AppMenus::removeMenuItemFromGroup(Widget* menuItem) void AppMenus::removeMenuItemFromGroup(Widget* menuItem)
{ {
removeMenuItemFromGroup( removeMenuItemFromGroup([menuItem](Widget* item) { return (item == menuItem); });
[menuItem](Widget* item){
return (item == menuItem);
});
} }
Menu* AppMenus::loadMenuById(XMLHandle& handle, const char* id) Menu* AppMenus::loadMenuById(XMLHandle& handle, const char* id)
@ -722,10 +679,8 @@ Menu* AppMenus::loadMenuById(XMLHandle& handle, const char* id)
ASSERT(id != NULL); ASSERT(id != NULL);
// <gui><menus><menu> // <gui><menus><menu>
XMLElement* xmlMenu = handle XMLElement* xmlMenu =
.FirstChildElement("gui") handle.FirstChildElement("gui").FirstChildElement("menus").FirstChildElement("menu").ToElement();
.FirstChildElement("menus")
.FirstChildElement("menu").ToElement();
while (xmlMenu) { while (xmlMenu) {
const char* menuId = xmlMenu->Attribute("id"); const char* menuId = xmlMenu->Attribute("id");
@ -785,9 +740,7 @@ Widget* AppMenus::convertXmlelemToMenuitem(XMLElement* elem, Menu* menu)
} }
const char* commandId = elem->Attribute("command"); const char* commandId = elem->Attribute("command");
Command* command = Command* command = (commandId ? Commands::instance()->byId(commandId) : nullptr);
(commandId ? Commands::instance()->byId(commandId):
nullptr);
// load params // load params
Params params; Params params;
@ -805,9 +758,8 @@ Widget* AppMenus::convertXmlelemToMenuitem(XMLElement* elem, Menu* menu)
} }
// Create the item // Create the item
AppMenuItem* menuitem = new AppMenuItem(m_xmlTranslator(elem, "text"), AppMenuItem* menuitem =
(command ? command->id(): ""), new AppMenuItem(m_xmlTranslator(elem, "text"), (command ? command->id() : ""), params);
params);
if (!menuitem) if (!menuitem)
return nullptr; return nullptr;
@ -821,7 +773,8 @@ Widget* AppMenus::convertXmlelemToMenuitem(XMLElement* elem, Menu* menu)
menuitem->processMnemonicFromText(); menuitem->processMnemonicFromText();
} }
if (id) menuitem->setId(id); if (id)
menuitem->setId(id);
if (group) { if (group) {
m_groups[group].menu = menu; m_groups[group].menu = menu;
m_groups[group].end = menuitem; m_groups[group].end = menuitem;
@ -876,8 +829,7 @@ void AppMenus::applyShortcutToMenuitemsWithCommand(Menu* menu,
const std::string& mi_commandId = menuitem->getCommandId(); const std::string& mi_commandId = menuitem->getCommandId();
const Params& mi_params = menuitem->getParams(); const Params& mi_params = menuitem->getParams();
if ((base::utf8_icmp(mi_commandId, command->id()) == 0) && if ((base::utf8_icmp(mi_commandId, command->id()) == 0) && (mi_params == params)) {
(mi_params == params)) {
// Set the keyboard shortcut to be shown in this menu-item // Set the keyboard shortcut to be shown in this menu-item
menuitem->setKey(key); menuitem->setKey(key);
} }
@ -975,7 +927,8 @@ void AppMenus::createNativeMenus()
appMenu->addItem(menus->makeMenuItem(preferences)); appMenu->addItem(menus->makeMenuItem(preferences));
appMenu->addItem(menus->makeMenuItem(os::MenuItemInfo(os::MenuItemInfo::Separator))); appMenu->addItem(menus->makeMenuItem(os::MenuItemInfo(os::MenuItemInfo::Separator)));
appMenu->addItem(menus->makeMenuItem(hide)); appMenu->addItem(menus->makeMenuItem(hide));
appMenu->addItem(menus->makeMenuItem(os::MenuItemInfo("Hide Others", os::MenuItemInfo::HideOthers))); appMenu->addItem(
menus->makeMenuItem(os::MenuItemInfo("Hide Others", os::MenuItemInfo::HideOthers)));
appMenu->addItem(menus->makeMenuItem(os::MenuItemInfo("Show All", os::MenuItemInfo::ShowAll))); appMenu->addItem(menus->makeMenuItem(os::MenuItemInfo("Show All", os::MenuItemInfo::ShowAll)));
appMenu->addItem(menus->makeMenuItem(os::MenuItemInfo(os::MenuItemInfo::Separator))); appMenu->addItem(menus->makeMenuItem(os::MenuItemInfo(os::MenuItemInfo::Separator)));
appMenu->addItem(menus->makeMenuItem(quit)); appMenu->addItem(menus->makeMenuItem(quit));
@ -1022,8 +975,7 @@ void AppMenus::createNativeMenus()
oldOSMenu.reset(); oldOSMenu.reset();
} }
void AppMenus::createNativeSubmenus(os::Menu* osMenu, void AppMenus::createNativeSubmenus(os::Menu* osMenu, const ui::Menu* uiMenu)
const ui::Menu* uiMenu)
{ {
os::Menus* menus = os::System::instance()->menus(); os::Menus* menus = os::System::instance()->menus();
@ -1036,10 +988,8 @@ void AppMenus::createNativeSubmenus(os::Menu* osMenu,
info.type = os::MenuItemInfo::Separator; info.type = os::MenuItemInfo::Separator;
} }
else if (child->type() == kMenuItemWidget) { else if (child->type() == kMenuItemWidget) {
if (appMenuItem && if (appMenuItem && appMenuItem->getCommand()) {
appMenuItem->getCommand()) { native = get_native_shortcut_for_command(appMenuItem->getCommandId().c_str(),
native = get_native_shortcut_for_command(
appMenuItem->getCommandId().c_str(),
appMenuItem->getParams()); appMenuItem->getParams());
} }
@ -1075,8 +1025,7 @@ void AppMenus::createNativeSubmenus(os::Menu* osMenu,
appMenuItem->setNative(native); appMenuItem->setNative(native);
} }
if (child->type() == ui::kMenuItemWidget && if (child->type() == ui::kMenuItemWidget && ((ui::MenuItem*)child)->hasSubmenu()) {
((ui::MenuItem*)child)->hasSubmenu()) {
os::MenuRef osSubmenu = menus->makeMenu(); os::MenuRef osSubmenu = menus->makeMenu();
createNativeSubmenus(osSubmenu.get(), ((ui::MenuItem*)child)->getSubmenu()); createNativeSubmenus(osSubmenu.get(), ((ui::MenuItem*)child)->getSubmenu());
osItem->setSubmenu(osSubmenu); osItem->setSubmenu(osSubmenu);

View File

@ -23,7 +23,7 @@
namespace tinyxml2 { namespace tinyxml2 {
class XMLElement; class XMLElement;
class XMLHandle; class XMLHandle;
} } // namespace tinyxml2
namespace app { namespace app {
class Command; class Command;
@ -62,16 +62,15 @@ namespace app {
Menu* getAnimationMenu(); Menu* getAnimationMenu();
Menu* getNewFrameMenu() { return m_newFramePopupMenu.get(); } Menu* getNewFrameMenu() { return m_newFramePopupMenu.get(); }
void applyShortcutToMenuitemsWithCommand(Command* command, const Params& params, void applyShortcutToMenuitemsWithCommand(Command* command,
const Params& params,
const KeyPtr& key); const KeyPtr& key);
void syncNativeMenuItemKeyShortcuts(); void syncNativeMenuItemKeyShortcuts();
// Menu item handling in groups // Menu item handling in groups
void addMenuGroup(const std::string& groupId, void addMenuGroup(const std::string& groupId, MenuItem* menuItem);
MenuItem* menuItem);
void removeMenuGroup(const std::string& groupId); void removeMenuGroup(const std::string& groupId);
void addMenuItemIntoGroup(const std::string& groupId, void addMenuItemIntoGroup(const std::string& groupId, std::unique_ptr<Widget>&& menuItem);
std::unique_ptr<Widget>&& menuItem);
void removeMenuItemFromGroup(Command* cmd); void removeMenuItemFromGroup(Command* cmd);
void removeMenuItemFromGroup(Widget* menuItem); void removeMenuItemFromGroup(Widget* menuItem);
@ -82,18 +81,17 @@ namespace app {
Menu* loadMenuById(tinyxml2::XMLHandle& handle, const char* id); Menu* loadMenuById(tinyxml2::XMLHandle& handle, const char* id);
Menu* convertXmlelemToMenu(tinyxml2::XMLElement* elem); Menu* convertXmlelemToMenu(tinyxml2::XMLElement* elem);
Widget* convertXmlelemToMenuitem(tinyxml2::XMLElement* elem, Menu* menu); Widget* convertXmlelemToMenuitem(tinyxml2::XMLElement* elem, Menu* menu);
void applyShortcutToMenuitemsWithCommand(Menu* menu, Command* command, const Params& params, void applyShortcutToMenuitemsWithCommand(Menu* menu,
Command* command,
const Params& params,
const KeyPtr& key); const KeyPtr& key);
void syncNativeMenuItemKeyShortcuts(Menu* menu); void syncNativeMenuItemKeyShortcuts(Menu* menu);
void updateMenusList(); void updateMenusList();
void createNativeMenus(); void createNativeMenus();
void createNativeSubmenus(os::Menu* osMenu, void createNativeSubmenus(os::Menu* osMenu, const ui::Menu* uiMenu);
const ui::Menu* uiMenu);
#ifdef ENABLE_SCRIPTING #ifdef ENABLE_SCRIPTING
void loadScriptsSubmenu(ui::Menu* menu, void loadScriptsSubmenu(ui::Menu* menu, const std::string& dir, const bool rootLevel);
const std::string& dir,
const bool rootLevel);
#endif #endif
struct GroupInfo { struct GroupInfo {

View File

@ -4,7 +4,6 @@
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -45,10 +44,8 @@ TEST(App, ExitCommand)
app::App app; app::App app;
app.initialize(options); app.initialize(options);
ui::execute_from_ui_thread([&app] { ui::execute_from_ui_thread(
app.context()->executeCommand( [&app] { app.context()->executeCommand(Commands::instance()->byId(CommandId::Exit())); });
Commands::instance()->byId(CommandId::Exit()));
});
app.run(); app.run();
} }
@ -64,10 +61,8 @@ TEST(App, ExitWithOneDoc)
ui::execute_from_ui_thread([&app] { ui::execute_from_ui_thread([&app] {
Params params; Params params;
params.set("ui", "false"); params.set("ui", "false");
app.context()->executeCommand( app.context()->executeCommand(Commands::instance()->byId(CommandId::NewFile()), params);
Commands::instance()->byId(CommandId::NewFile()), params); app.context()->executeCommand(Commands::instance()->byId(CommandId::Exit()));
app.context()->executeCommand(
Commands::instance()->byId(CommandId::Exit()));
}); });
app.run(); app.run();

View File

@ -47,26 +47,21 @@ public:
, m_inkType(inkType) , m_inkType(inkType)
, m_inkOpacity(inkOpacity) , m_inkOpacity(inkOpacity)
, m_shade(shade) , m_shade(shade)
, m_pixelPerfect(pixelPerfect) { , m_pixelPerfect(pixelPerfect)
{
} }
Flags flags() const { return m_flags; } Flags flags() const { return m_flags; }
void setFlags(Flags flags) { m_flags = flags; } void setFlags(Flags flags) { m_flags = flags; }
bool isEmpty() const { bool isEmpty() const { return int(m_flags) == 0; }
return int(m_flags) == 0;
}
bool hasFlag(Flags flag) const { bool hasFlag(Flags flag) const { return ((int(m_flags) & int(flag)) == int(flag)); }
return ((int(m_flags) & int(flag)) == int(flag));
}
bool hasBrush() const { bool hasBrush() const
return {
(brush() && return (brush() &&
(hasFlag(Flags::BrushType) || (hasFlag(Flags::BrushType) || hasFlag(Flags::BrushSize) || hasFlag(Flags::BrushAngle)));
hasFlag(Flags::BrushSize) ||
hasFlag(Flags::BrushAngle)));
} }
// Can be null if the user deletes the brush. // Can be null if the user deletes the brush.
@ -80,11 +75,10 @@ public:
// True if the user locked the brush using the shortcut key to // True if the user locked the brush using the shortcut key to
// access it. // access it.
bool locked() const { bool locked() const { return hasFlag(Flags::Locked); }
return hasFlag(Flags::Locked);
}
void setLocked(bool locked) { void setLocked(bool locked)
{
if (locked) if (locked)
m_flags = static_cast<Flags>(int(m_flags) | int(Flags::Locked)); m_flags = static_cast<Flags>(int(m_flags) | int(Flags::Locked));
else else

View File

@ -35,27 +35,22 @@ namespace app {
class CheckUpdateBackgroundJob : public updater::CheckUpdateDelegate { class CheckUpdateBackgroundJob : public updater::CheckUpdateDelegate {
public: public:
CheckUpdateBackgroundJob() CheckUpdateBackgroundJob() : m_received(false) {}
: m_received(false) { }
void abort() { void abort() { m_checker.abort(); }
m_checker.abort();
}
bool isReceived() const { bool isReceived() const { return m_received; }
return m_received;
}
void sendRequest(const updater::Uuid& uuid, const std::string& extraParams) { void sendRequest(const updater::Uuid& uuid, const std::string& extraParams)
{
m_checker.checkNewVersion(uuid, extraParams, this); m_checker.checkNewVersion(uuid, extraParams, this);
} }
const updater::CheckUpdateResponse& getResponse() const { const updater::CheckUpdateResponse& getResponse() const { return m_response; }
return m_response;
}
private: private:
void onResponse(updater::CheckUpdateResponse& data) override { void onResponse(updater::CheckUpdateResponse& data) override
{
m_response = data; m_response = data;
m_received = true; m_received = true;
} }
@ -87,8 +82,9 @@ CheckUpdateThreadLauncher::CheckUpdateThreadLauncher(CheckUpdateDelegate* delega
time_t now = std::time(NULL); time_t now = std::time(NULL);
// Verify if we are in the "WaitDays" period... // Verify if we are in the "WaitDays" period...
if (now < lastCheck+int(double(60*60*24*waitDays)) && if (now < lastCheck + int(double(60 * 60 * 24 * waitDays)) && now > lastCheck) { // <- Avoid
now > lastCheck) { // <- Avoid broken clocks // broken
// clocks
// So we do not check for updates. // So we do not check for updates.
m_doCheck = false; m_doCheck = false;
} }
@ -160,7 +156,6 @@ void CheckUpdateThreadLauncher::onMonitoringTick()
// Depending on the type of update received // Depending on the type of update received
switch (m_response.getUpdateType()) { switch (m_response.getUpdateType()) {
case updater::CheckUpdateResponse::NoUpdate: case updater::CheckUpdateResponse::NoUpdate:
// Clear // Clear
m_preferences.updater.newVersion(""); m_preferences.updater.newVersion("");
@ -207,8 +202,7 @@ void CheckUpdateThreadLauncher::checkForUpdates()
// Add mini-stats in the request // Add mini-stats in the request
std::stringstream extraParams; std::stringstream extraParams;
extraParams << "inits=" << m_inits extraParams << "inits=" << m_inits << "&exits=" << m_exits;
<< "&exits=" << m_exits;
if (m_isDeveloper) if (m_isDeveloper)
extraParams << "&dev=1"; extraParams << "&dev=1";
@ -235,8 +229,7 @@ void CheckUpdateThreadLauncher::showUI()
} }
if (newVer) { if (newVer) {
m_delegate->onNewUpdate(m_preferences.updater.newUrl(), m_delegate->onNewUpdate(m_preferences.updater.newUrl(), m_preferences.updater.newVersion());
m_preferences.updater.newVersion());
} }
else { else {
// If the program was updated, reset the "exits" counter // If the program was updated, reset the "exits" counter
@ -249,6 +242,6 @@ void CheckUpdateThreadLauncher::showUI()
} }
} }
} } // namespace app
#endif // ENABLE_UPDATER #endif // ENABLE_UPDATER

View File

@ -33,10 +33,7 @@ namespace app {
bool isReceived() const; bool isReceived() const;
const updater::CheckUpdateResponse& getResponse() const const updater::CheckUpdateResponse& getResponse() const { return m_response; }
{
return m_response;
}
private: private:
void onMonitoringTick(); void onMonitoringTick();

View File

@ -29,60 +29,145 @@ AppOptions::AppOptions(int argc, const char* argv[])
, m_shell(m_po.add("shell").description("Start an interactive console to execute scripts")) , m_shell(m_po.add("shell").description("Start an interactive console to execute scripts"))
#endif #endif
, m_batch(m_po.add("batch").mnemonic('b').description("Do not start the UI")) , m_batch(m_po.add("batch").mnemonic('b').description("Do not start the UI"))
, m_preview(m_po.add("preview").mnemonic('p').description("Do not execute actions, just print what will be\ndone")) , m_preview(m_po.add("preview").mnemonic('p').description(
, m_saveAs(m_po.add("save-as").requiresValue("<filename>").description("Save the last given sprite with other format")) "Do not execute actions, just print what will be\ndone"))
, m_palette(m_po.add("palette").requiresValue("<filename>").description("Change the palette of the last given sprite")) , m_saveAs(m_po.add("save-as")
, m_scale(m_po.add("scale").requiresValue("<factor>").description("Resize all previously opened sprites")) .requiresValue("<filename>")
, m_ditheringAlgorithm(m_po.add("dithering-algorithm").requiresValue("<algorithm>").description("Dithering algorithm used in --color-mode\nto convert images from RGB to Indexed\n none\n ordered\n old")) .description("Save the last given sprite with other format"))
, m_ditheringMatrix(m_po.add("dithering-matrix").requiresValue("<id>").description("Matrix used in ordered dithering algorithm\n bayer2x2\n bayer4x4\n bayer8x8\n filename.png")) , m_palette(m_po.add("palette")
, m_colorMode(m_po.add("color-mode").requiresValue("<mode>").description("Change color mode of all previously\nopened sprites:\n rgb\n grayscale\n indexed")) .requiresValue("<filename>")
, m_shrinkTo(m_po.add("shrink-to").requiresValue("width,height").description("Shrink each sprite if it is\nlarger than width or height")) .description("Change the palette of the last given sprite"))
, m_data(m_po.add("data").requiresValue("<filename.json>").description("File to store the sprite sheet metadata")) , m_scale(m_po.add("scale")
, m_format(m_po.add("format").requiresValue("<format>").description("Format to export the data file\n(json-hash, json-array)")) .requiresValue("<factor>")
, m_sheet(m_po.add("sheet").requiresValue("<filename.png>").description("Image file to save the texture")) .description("Resize all previously opened sprites"))
, m_sheetType(m_po.add("sheet-type").requiresValue("<type>").description("Algorithm to create the sprite sheet:\n horizontal\n vertical\n rows\n columns\n packed")) , m_ditheringAlgorithm(
m_po.add("dithering-algorithm")
.requiresValue("<algorithm>")
.description(
"Dithering algorithm used in --color-mode\nto convert images from RGB to Indexed\n none\n ordered\n old"))
, m_ditheringMatrix(
m_po.add("dithering-matrix")
.requiresValue("<id>")
.description(
"Matrix used in ordered dithering algorithm\n bayer2x2\n bayer4x4\n bayer8x8\n filename.png"))
, m_colorMode(
m_po.add("color-mode")
.requiresValue("<mode>")
.description(
"Change color mode of all previously\nopened sprites:\n rgb\n grayscale\n indexed"))
, m_shrinkTo(m_po.add("shrink-to")
.requiresValue("width,height")
.description("Shrink each sprite if it is\nlarger than width or height"))
, m_data(m_po.add("data")
.requiresValue("<filename.json>")
.description("File to store the sprite sheet metadata"))
, m_format(m_po.add("format")
.requiresValue("<format>")
.description("Format to export the data file\n(json-hash, json-array)"))
, m_sheet(m_po.add("sheet")
.requiresValue("<filename.png>")
.description("Image file to save the texture"))
, m_sheetType(
m_po.add("sheet-type")
.requiresValue("<type>")
.description(
"Algorithm to create the sprite sheet:\n horizontal\n vertical\n rows\n columns\n packed"))
, m_sheetPack(m_po.add("sheet-pack").description("Same as -sheet-type packed")) , m_sheetPack(m_po.add("sheet-pack").description("Same as -sheet-type packed"))
, m_sheetWidth(m_po.add("sheet-width").requiresValue("<pixels>").description("Sprite sheet width")) , m_sheetWidth(
, m_sheetHeight(m_po.add("sheet-height").requiresValue("<pixels>").description("Sprite sheet height")) m_po.add("sheet-width").requiresValue("<pixels>").description("Sprite sheet width"))
, m_sheetColumns(m_po.add("sheet-columns").requiresValue("<columns>").description("Fixed # of columns for -sheet-type rows")) , m_sheetHeight(
, m_sheetRows(m_po.add("sheet-rows").requiresValue("<rows>").description("Fixed # of rows for -sheet-type columns")) m_po.add("sheet-height").requiresValue("<pixels>").description("Sprite sheet height"))
, m_splitLayers(m_po.add("split-layers").description("Save each visible layer of sprites\nas separated images in the sheet\n")) , m_sheetColumns(m_po.add("sheet-columns")
.requiresValue("<columns>")
.description("Fixed # of columns for -sheet-type rows"))
, m_sheetRows(m_po.add("sheet-rows")
.requiresValue("<rows>")
.description("Fixed # of rows for -sheet-type columns"))
, m_splitLayers(
m_po.add("split-layers")
.description("Save each visible layer of sprites\nas separated images in the sheet\n"))
, m_splitTags(m_po.add("split-tags").description("Save each tag as a separated file")) , m_splitTags(m_po.add("split-tags").description("Save each tag as a separated file"))
, m_splitSlices(m_po.add("split-slices").description("Save each slice as a separated file")) , m_splitSlices(m_po.add("split-slices").description("Save each slice as a separated file"))
, m_splitGrid(m_po.add("split-grid").description("Save each grid tile as a separated file")) , m_splitGrid(m_po.add("split-grid").description("Save each grid tile as a separated file"))
, m_layer(m_po.add("layer").alias("import-layer").requiresValue("<name>").description("Include just the given layer in the sheet\nor save as operation")) , m_layer(m_po.add("layer")
, m_allLayers(m_po.add("all-layers").description("Make all layers visible\nBy default hidden layers will be ignored")) .alias("import-layer")
, m_ignoreLayer(m_po.add("ignore-layer").requiresValue("<name>").description("Exclude the given layer in the sheet\nor save as operation")) .requiresValue("<name>")
, m_tag(m_po.add("tag").alias("frame-tag").requiresValue("<name>").description("Include tagged frames in the sheet")) .description("Include just the given layer in the sheet\nor save as operation"))
, m_playSubtags(m_po.add("play-subtags").description("Play subtags and repeats when saving the frames of an animated sprite")) , m_allLayers(m_po.add("all-layers")
, m_frameRange(m_po.add("frame-range").requiresValue("from,to").description("Only export frames in the [from,to] range")) .description("Make all layers visible\nBy default hidden layers will be ignored"))
, m_ignoreLayer(m_po.add("ignore-layer")
.requiresValue("<name>")
.description("Exclude the given layer in the sheet\nor save as operation"))
, m_tag(m_po.add("tag")
.alias("frame-tag")
.requiresValue("<name>")
.description("Include tagged frames in the sheet"))
, m_playSubtags(
m_po.add("play-subtags")
.description("Play subtags and repeats when saving the frames of an animated sprite"))
, m_frameRange(m_po.add("frame-range")
.requiresValue("from,to")
.description("Only export frames in the [from,to] range"))
, m_ignoreEmpty(m_po.add("ignore-empty").description("Do not export empty frames/cels")) , m_ignoreEmpty(m_po.add("ignore-empty").description("Do not export empty frames/cels"))
, m_mergeDuplicates(m_po.add("merge-duplicates").description("Merge all duplicate frames into one in the sprite sheet")) , m_mergeDuplicates(m_po.add("merge-duplicates")
, m_borderPadding(m_po.add("border-padding").requiresValue("<value>").description("Add padding on the texture borders")) .description("Merge all duplicate frames into one in the sprite sheet"))
, m_shapePadding(m_po.add("shape-padding").requiresValue("<value>").description("Add padding between frames")) , m_borderPadding(m_po.add("border-padding")
, m_innerPadding(m_po.add("inner-padding").requiresValue("<value>").description("Add padding inside each frame")) .requiresValue("<value>")
, m_trim(m_po.add("trim").description("Trim whole sprite for --save-as\nor individual frames for --sheet")) .description("Add padding on the texture borders"))
, m_trimSprite(m_po.add("trim-sprite").description("Trim the whole sprite (for --save-as and --sheet)")) , m_shapePadding(
, m_trimByGrid(m_po.add("trim-by-grid").description("Trim all images by its correspondent grid boundaries before exporting")) m_po.add("shape-padding").requiresValue("<value>").description("Add padding between frames"))
, m_innerPadding(m_po.add("inner-padding")
.requiresValue("<value>")
.description("Add padding inside each frame"))
, m_trim(m_po.add("trim").description(
"Trim whole sprite for --save-as\nor individual frames for --sheet"))
, m_trimSprite(
m_po.add("trim-sprite").description("Trim the whole sprite (for --save-as and --sheet)"))
, m_trimByGrid(
m_po.add("trim-by-grid")
.description("Trim all images by its correspondent grid boundaries before exporting"))
, m_extrude(m_po.add("extrude").description("Extrude all images duplicating all edges one pixel")) , m_extrude(m_po.add("extrude").description("Extrude all images duplicating all edges one pixel"))
, m_crop(m_po.add("crop").requiresValue("x,y,width,height").description("Crop all the images to the given rectangle")) , m_crop(m_po.add("crop")
, m_slice(m_po.add("slice").requiresValue("<name>").description("Crop the sprite to the given slice area")) .requiresValue("x,y,width,height")
, m_filenameFormat(m_po.add("filename-format").requiresValue("<fmt>").description("Special format to generate filenames")) .description("Crop all the images to the given rectangle"))
, m_tagnameFormat(m_po.add("tagname-format").requiresValue("<fmt>").description("Special format to generate tagnames in JSON data")) , m_slice(m_po.add("slice").requiresValue("<name>").description(
"Crop the sprite to the given slice area"))
, m_filenameFormat(m_po.add("filename-format")
.requiresValue("<fmt>")
.description("Special format to generate filenames"))
, m_tagnameFormat(m_po.add("tagname-format")
.requiresValue("<fmt>")
.description("Special format to generate tagnames in JSON data"))
#ifdef ENABLE_SCRIPTING #ifdef ENABLE_SCRIPTING
, m_script(m_po.add("script").requiresValue("<filename>").description("Execute a specific script")) , m_script(
, m_scriptParam(m_po.add("script-param").requiresValue("name=value").description("Parameter for a script executed from the\nCLI that you can access with app.params")) m_po.add("script").requiresValue("<filename>").description("Execute a specific script"))
, m_scriptParam(
m_po.add("script-param")
.requiresValue("name=value")
.description(
"Parameter for a script executed from the\nCLI that you can access with app.params"))
#endif #endif
, m_listLayers(m_po.add("list-layers").description("List layers of the next given sprite\nor include layers in JSON data")) , m_listLayers(
, m_listLayerHierarchy(m_po.add("list-layer-hierarchy").description("List layers with groups of the next given sprite\nor include layers hierarchy in JSON data")) m_po.add("list-layers")
, m_listTags(m_po.add("list-tags").description("List tags of the next given sprite\nor include frame tags in JSON data")) .description("List layers of the next given sprite\nor include layers in JSON data"))
, m_listSlices(m_po.add("list-slices").description("List slices of the next given sprite\nor include slices in JSON data")) , m_listLayerHierarchy(
m_po.add("list-layer-hierarchy")
.description(
"List layers with groups of the next given sprite\nor include layers hierarchy in JSON data"))
, m_listTags(
m_po.add("list-tags")
.description("List tags of the next given sprite\nor include frame tags in JSON data"))
, m_listSlices(
m_po.add("list-slices")
.description("List slices of the next given sprite\nor include slices in JSON data"))
, m_oneFrame(m_po.add("oneframe").description("Load just the first frame")) , m_oneFrame(m_po.add("oneframe").description("Load just the first frame"))
, m_exportTileset(m_po.add("export-tileset").description("Export only tilesets from visible tilemap layers")) , m_exportTileset(
m_po.add("export-tileset").description("Export only tilesets from visible tilemap layers"))
, m_verbose(m_po.add("verbose").mnemonic('v').description("Explain what is being done")) , m_verbose(m_po.add("verbose").mnemonic('v').description("Explain what is being done"))
, m_debug(m_po.add("debug").description("Extreme verbose mode and\ncopy log to desktop")) , m_debug(m_po.add("debug").description("Extreme verbose mode and\ncopy log to desktop"))
#ifdef ENABLE_STEAM #ifdef ENABLE_STEAM
, m_noInApp(m_po.add("noinapp").description("Disable \"in game\" visibility on Steam\nDoesn't count playtime")) , m_noInApp(m_po.add("noinapp").description(
"Disable \"in game\" visibility on Steam\nDoesn't count playtime"))
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
, m_disableWintab(m_po.add("disable-wintab").description("Don't load wintab32.dll library")) , m_disableWintab(m_po.add("disable-wintab").description("Don't load wintab32.dll library"))
@ -105,10 +190,7 @@ AppOptions::AppOptions(int argc, const char* argv[])
m_showHelp = m_po.enabled(m_help); m_showHelp = m_po.enabled(m_help);
m_showVersion = m_po.enabled(m_version); m_showVersion = m_po.enabled(m_version);
if (m_startShell || if (m_startShell || m_showHelp || m_showVersion || m_po.enabled(m_batch)) {
m_showHelp ||
m_showVersion ||
m_po.enabled(m_batch)) {
m_startUI = false; m_startUI = false;
} }
} }
@ -121,9 +203,7 @@ AppOptions::AppOptions(int argc, const char* argv[])
bool AppOptions::hasExporterParams() const bool AppOptions::hasExporterParams() const
{ {
return return m_po.enabled(m_data) || m_po.enabled(m_sheet);
m_po.enabled(m_data) ||
m_po.enabled(m_sheet);
} }
#ifdef ENABLE_STEAM #ifdef ENABLE_STEAM
@ -140,4 +220,4 @@ bool AppOptions::disableWintab() const
} }
#endif #endif
} } // namespace app

View File

@ -41,9 +41,7 @@ public:
bool showVersion() const { return m_showVersion; } bool showVersion() const { return m_showVersion; }
VerboseLevel verboseLevel() const { return m_verboseLevel; } VerboseLevel verboseLevel() const { return m_verboseLevel; }
const ValueList& values() const { const ValueList& values() const { return m_po.values(); }
return m_po.values();
}
// Export options // Export options
const Option& saveAs() const { return m_saveAs; } const Option& saveAs() const { return m_saveAs; }
@ -181,7 +179,6 @@ private:
#endif #endif
Option& m_help; Option& m_help;
Option& m_version; Option& m_version;
}; };
} // namespace app } // namespace app

View File

@ -33,10 +33,7 @@ namespace app {
virtual void loadPalette(Context* ctx, const std::string& filename) {} virtual void loadPalette(Context* ctx, const std::string& filename) {}
virtual void exportFiles(Context* ctx, DocExporter& exporter) {} virtual void exportFiles(Context* ctx, DocExporter& exporter) {}
#ifdef ENABLE_SCRIPTING #ifdef ENABLE_SCRIPTING
virtual int execScript(const std::string& filename, virtual int execScript(const std::string& filename, const Params& params) { return 0; }
const Params& params) {
return 0;
}
#endif // ENABLE_SCRIPTING #endif // ENABLE_SCRIPTING
}; };

View File

@ -48,22 +48,13 @@ namespace app {
bool playSubtags = false; bool playSubtags = false;
gfx::Rect crop; gfx::Rect crop;
bool hasTag() const { bool hasTag() const { return (!tag.empty()); }
return (!tag.empty());
}
bool hasSlice() const { bool hasSlice() const { return (!slice.empty()); }
return (!slice.empty());
}
bool hasFrameRange() const { bool hasFrameRange() const { return (fromFrame >= 0 && toFrame >= 0); }
return (fromFrame >= 0 && toFrame >= 0);
}
bool hasLayersFilter() const { bool hasLayersFilter() const { return (!includeLayers.empty() || !excludeLayers.empty()); }
return (!includeLayers.empty() ||
!excludeLayers.empty());
}
FileOpROI roi() const; FileOpROI roi() const;
}; };

View File

@ -44,9 +44,7 @@ namespace app {
namespace { namespace {
bool match_path(const std::string& filter, bool match_path(const std::string& filter, const std::string& layer_path, const bool exclude)
const std::string& layer_path,
const bool exclude)
{ {
if (filter == layer_path) if (filter == layer_path)
return true; return true;
@ -66,10 +64,7 @@ bool match_path(const std::string& filter,
// case is only for exclusion because if we leave the group // case is only for exclusion because if we leave the group
// selected, the propagation of the selection will include all // selected, the propagation of the selection will include all
// visible children too (see SelectedLayers::propagateSelection()). // visible children too (see SelectedLayers::propagateSelection()).
if (exclude && if (exclude && a.size() > 1 && a.size() == b.size() + 1 && wildcard) {
a.size() > 1 &&
a.size() == b.size()+1 &&
wildcard) {
return true; return true;
} }
@ -95,8 +90,7 @@ bool filter_layer(const std::string& layer_path,
// If there is one layer with the given name "filter", we can convert // If there is one layer with the given name "filter", we can convert
// the filter to a full path to the layer (e.g. to match child layers // the filter to a full path to the layer (e.g. to match child layers
// of a group). // of a group).
std::string convert_filter_to_layer_path_if_possible( std::string convert_filter_to_layer_path_if_possible(const Sprite* sprite,
const Sprite* sprite,
const std::string& filter) const std::string& filter)
{ {
std::string fullName; std::string fullName;
@ -107,8 +101,7 @@ std::string convert_filter_to_layer_path_if_possible(
const Layer* layer = layers.front(); const Layer* layer = layers.front();
layers.pop(); layers.pop();
if (layer != sprite->root() && if (layer != sprite->root() && layer->name() == filter) {
layer->name() == filter) {
if (fullName.empty()) { if (fullName.empty()) {
fullName = get_layer_path(layer); fullName = get_layer_path(layer);
} }
@ -152,16 +145,14 @@ void CliProcessor::FilterLayers(const Sprite* sprite,
(!includes.empty() && !filter_layer(layer_path, includes, true))) (!includes.empty() && !filter_layer(layer_path, includes, true)))
continue; continue;
if (!excludes.empty() && if (!excludes.empty() && !filter_layer(layer_path, excludes, false))
!filter_layer(layer_path, excludes, false))
continue; continue;
filteredLayers.insert(layer); filteredLayers.insert(layer);
} }
} }
CliProcessor::CliProcessor(CliDelegate* delegate, CliProcessor::CliProcessor(CliDelegate* delegate, const AppOptions& options)
const AppOptions& options)
: m_delegate(delegate) : m_delegate(delegate)
, m_options(options) , m_options(options)
, m_exporter(nullptr) , m_exporter(nullptr)
@ -451,8 +442,7 @@ int CliProcessor::process(Context* ctx)
// Scale all sprites // Scale all sprites
for (auto doc : ctx->documents()) { for (auto doc : ctx->documents()) {
ctx->setActiveDocument(doc); ctx->setActiveDocument(doc);
ctx->executeCommand(Commands::instance()->byId(CommandId::SpriteSize()), ctx->executeCommand(Commands::instance()->byId(CommandId::SpriteSize()), params);
params);
} }
} }
// --dithering-algorithm <algorithm> // --dithering-algorithm <algorithm>
@ -466,7 +456,8 @@ int CliProcessor::process(Context* ctx)
else if (value.value() == "error-diffusion") else if (value.value() == "error-diffusion")
ditheringAlgorithm = render::DitheringAlgorithm::ErrorDiffusion; ditheringAlgorithm = render::DitheringAlgorithm::ErrorDiffusion;
else else
throw std::runtime_error("--dithering-algorithm needs a valid algorithm name\n" throw std::runtime_error(
"--dithering-algorithm needs a valid algorithm name\n"
"Usage: --dithering-algorithm <algorithm>\n" "Usage: --dithering-algorithm <algorithm>\n"
"Where <algorithm> can be none, ordered, old, or error-diffusion"); "Where <algorithm> can be none, ordered, old, or error-diffusion");
} }
@ -487,15 +478,9 @@ int CliProcessor::process(Context* ctx)
else if (value.value() == "indexed") { else if (value.value() == "indexed") {
params.set("format", "indexed"); params.set("format", "indexed");
switch (ditheringAlgorithm) { switch (ditheringAlgorithm) {
case render::DitheringAlgorithm::None: case render::DitheringAlgorithm::None: params.set("dithering", "none"); break;
params.set("dithering", "none"); case render::DitheringAlgorithm::Ordered: params.set("dithering", "ordered"); break;
break; case render::DitheringAlgorithm::Old: params.set("dithering", "old"); break;
case render::DitheringAlgorithm::Ordered:
params.set("dithering", "ordered");
break;
case render::DitheringAlgorithm::Old:
params.set("dithering", "old");
break;
case render::DitheringAlgorithm::ErrorDiffusion: case render::DitheringAlgorithm::ErrorDiffusion:
params.set("dithering", "error-diffusion"); params.set("dithering", "error-diffusion");
break; break;
@ -539,8 +524,7 @@ int CliProcessor::process(Context* ctx)
scale = std::min(scaleWidth, scaleHeight); scale = std::min(scaleWidth, scaleHeight);
Params params; Params params;
params.set("scale", base::convert_to<std::string>(scale).c_str()); params.set("scale", base::convert_to<std::string>(scale).c_str());
ctx->executeCommand(Commands::instance()->byId(CommandId::SpriteSize()), ctx->executeCommand(Commands::instance()->byId(CommandId::SpriteSize()), params);
params);
} }
} }
} }
@ -564,8 +548,7 @@ int CliProcessor::process(Context* ctx)
const std::string& v = value.value(); const std::string& v = value.value();
auto i = v.find('='); auto i = v.find('=');
if (i != std::string::npos) if (i != std::string::npos)
scriptParams.set(v.substr(0, i).c_str(), scriptParams.set(v.substr(0, i).c_str(), v.substr(i + 1).c_str());
v.substr(i+1).c_str());
else else
scriptParams.set(v.c_str(), "1"); scriptParams.set(v.c_str(), "1");
} }
@ -652,9 +635,7 @@ bool CliProcessor::openFile(Context* ctx, CliOpenFile& cof)
Doc* oldDoc = ctx->activeDocument(); Doc* oldDoc = ctx->activeDocument();
m_batch.open(ctx, m_batch.open(ctx, cof.filename, cof.oneFrame);
cof.filename,
cof.oneFrame);
// Mark used file names as "already processed" so we don't try to // Mark used file names as "already processed" so we don't try to
// open then again // open then again
@ -691,8 +672,7 @@ bool CliProcessor::openFile(Context* ctx, CliOpenFile& cof)
if (cof.hasFrameRange()) { if (cof.hasFrameRange()) {
// --frame-range with --frame-tag // --frame-range with --frame-tag
if (tag) { if (tag) {
selFrames.insert( selFrames.insert(tag->fromFrame() + std::clamp(cof.fromFrame, 0, tag->frames() - 1),
tag->fromFrame()+std::clamp(cof.fromFrame, 0, tag->frames()-1),
tag->fromFrame() + std::clamp(cof.toFrame, 0, tag->frames() - 1)); tag->fromFrame() + std::clamp(cof.toFrame, 0, tag->frames() - 1));
} }
// --frame-range without --frame-tag // --frame-range without --frame-tag
@ -706,13 +686,11 @@ bool CliProcessor::openFile(Context* ctx, CliOpenFile& cof)
filterLayers(doc->sprite(), cof, filteredLayers); filterLayers(doc->sprite(), cof, filteredLayers);
if (cof.exportTileset) { if (cof.exportTileset) {
m_exporter->addTilesetsSamples( m_exporter->addTilesetsSamples(doc, (cof.hasLayersFilter() ? &filteredLayers : nullptr));
doc,
(cof.hasLayersFilter() ? &filteredLayers: nullptr));
} }
else { else {
m_exporter->addDocumentSamples( m_exporter->addDocumentSamples(doc,
doc, tag, tag,
cof.splitLayers, cof.splitLayers,
cof.splitTags, cof.splitTags,
cof.splitGrid, cof.splitGrid,
@ -742,17 +720,14 @@ void CliProcessor::saveFile(Context* ctx, const CliOpenFile& cof)
cropParams.set("y", base::convert_to<std::string>(cof.crop.y).c_str()); cropParams.set("y", base::convert_to<std::string>(cof.crop.y).c_str());
cropParams.set("width", base::convert_to<std::string>(cof.crop.w).c_str()); cropParams.set("width", base::convert_to<std::string>(cof.crop.w).c_str());
cropParams.set("height", base::convert_to<std::string>(cof.crop.h).c_str()); cropParams.set("height", base::convert_to<std::string>(cof.crop.h).c_str());
ctx->executeCommand( ctx->executeCommand(Commands::instance()->byId(CommandId::CropSprite()), cropParams);
Commands::instance()->byId(CommandId::CropSprite()),
cropParams);
} }
std::string fn = cof.filename; std::string fn = cof.filename;
std::string filenameFormat = cof.filenameFormat; std::string filenameFormat = cof.filenameFormat;
if (filenameFormat.empty()) { // Default format if (filenameFormat.empty()) { // Default format
bool hasFrames = (cof.roi().frames() > 1); bool hasFrames = (cof.roi().frames() > 1);
filenameFormat = get_default_filename_format( filenameFormat = get_default_filename_format(fn,
fn,
true, // With path true, // With path
hasFrames, // Has frames hasFrames, // Has frames
cof.splitLayers, // Has layer cof.splitLayers, // Has layer
@ -777,8 +752,7 @@ void CliProcessor::saveFile(Context* ctx, const CliOpenFile& cof)
std::vector<doc::Tag*> tags; std::vector<doc::Tag*> tags;
if (cof.hasTag()) { if (cof.hasTag()) {
tags.push_back( tags.push_back(doc->sprite()->tags().getByName(cof.tag));
doc->sprite()->tags().getByName(cof.tag));
} }
else { else {
doc::Tags& origTags = cof.document->sprite()->tags(); doc::Tags& origTags = cof.document->sprite()->tags();
@ -786,8 +760,7 @@ void CliProcessor::saveFile(Context* ctx, const CliOpenFile& cof)
for (doc::Tag* tag : origTags) { for (doc::Tag* tag : origTags) {
// In case the tag is outside the given --frame-range // In case the tag is outside the given --frame-range
if (cof.hasFrameRange()) { if (cof.hasFrameRange()) {
if (tag->toFrame() < cof.fromFrame || if (tag->toFrame() < cof.fromFrame || tag->fromFrame() > cof.toFrame)
tag->fromFrame() > cof.toFrame)
continue; continue;
} }
tags.push_back(tag); tags.push_back(tag);
@ -799,8 +772,7 @@ void CliProcessor::saveFile(Context* ctx, const CliOpenFile& cof)
std::vector<doc::Slice*> slices; std::vector<doc::Slice*> slices;
if (cof.hasSlice()) { if (cof.hasSlice()) {
slices.push_back( slices.push_back(doc->sprite()->slices().getByName(cof.slice));
doc->sprite()->slices().getByName(cof.slice));
} }
else { else {
doc::Slices& origSlices = cof.document->sprite()->slices(); doc::Slices& origSlices = cof.document->sprite()->slices();
@ -868,9 +840,7 @@ void CliProcessor::saveFile(Context* ctx, const CliOpenFile& cof)
itemCof.includeLayers.push_back(layer->name()); itemCof.includeLayers.push_back(layer->name());
} }
if (tag) { if (tag) {
fnInfo fnInfo.innerTagName(tag->name()).outerTagName(tag->name());
.innerTagName(tag->name())
.outerTagName(tag->name());
itemCof.tag = tag->name(); itemCof.tag = tag->name();
} }
if (slice) { if (slice) {

View File

@ -32,8 +32,7 @@ namespace app {
class CliProcessor { class CliProcessor {
public: public:
CliProcessor(CliDelegate* delegate, CliProcessor(CliDelegate* delegate, const AppOptions& options);
const AppOptions& options);
int process(Context* ctx); int process(Context* ctx);
// Public so it can be tested // Public so it can be tested
@ -49,12 +48,9 @@ namespace app {
void filterLayers(const doc::Sprite* sprite, void filterLayers(const doc::Sprite* sprite,
const CliOpenFile& cof, const CliOpenFile& cof,
doc::SelectedLayers& filteredLayers) { doc::SelectedLayers& filteredLayers)
CliProcessor::FilterLayers( {
sprite, CliProcessor::FilterLayers(sprite, cof.includeLayers, cof.excludeLayers, filteredLayers);
cof.includeLayers,
cof.excludeLayers,
filteredLayers);
} }
CliDelegate* m_delegate; CliDelegate* m_delegate;

View File

@ -17,7 +17,8 @@ using namespace app;
class CliTestDelegate : public CliDelegate { class CliTestDelegate : public CliDelegate {
public: public:
CliTestDelegate() { CliTestDelegate()
{
m_helpWasShown = false; m_helpWasShown = false;
m_versionWasShown = false; m_versionWasShown = false;
m_uiMode = false; m_uiMode = false;
@ -35,10 +36,7 @@ public:
void saveFile(Context* ctx, const CliOpenFile& cof) override {} void saveFile(Context* ctx, const CliOpenFile& cof) override {}
void exportFiles(Context* ctx, DocExporter& exporter) override {} void exportFiles(Context* ctx, DocExporter& exporter) override {}
#ifdef ENABLE_SCRIPTING #ifdef ENABLE_SCRIPTING
int execScript(const std::string& filename, int execScript(const std::string& filename, const Params& params) override { return 0; }
const Params& params) override {
return 0;
}
#endif #endif
bool helpWasShown() const { return m_helpWasShown; } bool helpWasShown() const { return m_helpWasShown; }
@ -52,7 +50,8 @@ private:
bool m_batchMode; bool m_batchMode;
}; };
std::unique_ptr<AppOptions> args(std::initializer_list<const char*> l) { std::unique_ptr<AppOptions> args(std::initializer_list<const char*> l)
{
int argc = l.size() + 1; int argc = l.size() + 1;
const char** argv = new const char*[argc]; const char** argv = new const char*[argc];
argv[0] = "aseprite.exe"; argv[0] = "aseprite.exe";

View File

@ -42,15 +42,11 @@ namespace app {
void DefaultCliDelegate::showHelp(const AppOptions& options) void DefaultCliDelegate::showHelp(const AppOptions& options)
{ {
std::cout std::cout << get_app_name() << " v" << get_app_version() << " | A pixel art program\n"
<< get_app_name() << " v" << get_app_version() << get_app_copyright() << "\n\nUsage:\n"
<< " | A pixel art program\n"
<< get_app_copyright()
<< "\n\nUsage:\n"
<< " " << options.exeName() << " [OPTIONS] [FILES]...\n\n" << " " << options.exeName() << " [OPTIONS] [FILES]...\n\n"
<< "Options:\n" << "Options:\n"
<< options.programOptions() << options.programOptions() << "\nFind more information in " << get_app_name()
<< "\nFind more information in " << get_app_name()
<< " web site: " << get_app_url() << "\n\n"; << " web site: " << get_app_url() << "\n\n";
} }
@ -111,8 +107,7 @@ void DefaultCliDelegate::saveFile(Context* ctx, const CliOpenFile& cof)
ctx->executeCommand(saveAsCommand, params); ctx->executeCommand(saveAsCommand, params);
} }
void DefaultCliDelegate::loadPalette(Context* ctx, void DefaultCliDelegate::loadPalette(Context* ctx, const std::string& filename)
const std::string& filename)
{ {
std::unique_ptr<doc::Palette> palette(load_palette(filename.c_str())); std::unique_ptr<doc::Palette> palette(load_palette(filename.c_str()));
if (palette) { if (palette) {
@ -123,8 +118,7 @@ void DefaultCliDelegate::loadPalette(Context* ctx,
ctx->executeCommand(loadPalCommand, params); ctx->executeCommand(loadPalCommand, params);
} }
else { else {
Console().printf("Error loading palette in --palette '%s'\n", Console().printf("Error loading palette in --palette '%s'\n", filename.c_str());
filename.c_str());
} }
} }
@ -133,8 +127,7 @@ void DefaultCliDelegate::exportFiles(Context* ctx, DocExporter& exporter)
LOG("APP: Exporting sheet...\n"); LOG("APP: Exporting sheet...\n");
base::task_token token; base::task_token token;
std::unique_ptr<Doc> spriteSheet( std::unique_ptr<Doc> spriteSheet(exporter.exportSheet(ctx, token));
exporter.exportSheet(ctx, token));
// Sprite sheet isn't used, we just delete it. // Sprite sheet isn't used, we just delete it.
@ -142,8 +135,7 @@ void DefaultCliDelegate::exportFiles(Context* ctx, DocExporter& exporter)
} }
#ifdef ENABLE_SCRIPTING #ifdef ENABLE_SCRIPTING
int DefaultCliDelegate::execScript(const std::string& filename, int DefaultCliDelegate::execScript(const std::string& filename, const Params& params)
const Params& params)
{ {
ScriptInputChain scriptInputChain; ScriptInputChain scriptInputChain;
if (!App::instance()->isGui()) { if (!App::instance()->isGui()) {

View File

@ -22,8 +22,7 @@ namespace app {
void loadPalette(Context* ctx, const std::string& filename) override; void loadPalette(Context* ctx, const std::string& filename) override;
void exportFiles(Context* ctx, DocExporter& exporter) override; void exportFiles(Context* ctx, DocExporter& exporter) override;
#ifdef ENABLE_SCRIPTING #ifdef ENABLE_SCRIPTING
int execScript(const std::string& filename, int execScript(const std::string& filename, const Params& params) override;
const Params& params) override;
#endif #endif
}; };

View File

@ -15,8 +15,7 @@ using namespace doc;
class FilterLayers : public ::testing::Test { class FilterLayers : public ::testing::Test {
public: public:
FilterLayers() FilterLayers() : sprite(ImageSpec(ColorMode::RGB, 32, 32))
: sprite(ImageSpec(ColorMode::RGB, 32, 32))
{ {
a->setName("a"); a->setName("a");
b->setName("b"); b->setName("b");
@ -33,12 +32,9 @@ public:
b->addLayer(bb); b->addLayer(bb);
} }
void filter( void filter(std::vector<std::string> includes, std::vector<std::string> excludes)
std::vector<std::string> includes,
std::vector<std::string> excludes)
{ {
CliProcessor::FilterLayers( CliProcessor::FilterLayers(&sprite, std::move(includes), std::move(excludes), sel);
&sprite, std::move(includes), std::move(excludes), sel);
} }
Sprite sprite; Sprite sprite;

View File

@ -94,10 +94,7 @@ void PreviewCliDelegate::saveFile(Context* ctx, const CliOpenFile& cof)
<< " - Sprite: '" << cof.document->filename() << "'\n"; << " - Sprite: '" << cof.document->filename() << "'\n";
if (!cof.crop.isEmpty()) { if (!cof.crop.isEmpty()) {
std::cout << " - Crop: " std::cout << " - Crop: " << cof.crop.x << "," << cof.crop.y << " " << cof.crop.w << "x"
<< cof.crop.x << ","
<< cof.crop.y << " "
<< cof.crop.w << "x"
<< cof.crop.h << "\n"; << cof.crop.h << "\n";
} }
@ -112,8 +109,7 @@ void PreviewCliDelegate::saveFile(Context* ctx, const CliOpenFile& cof)
std::cout << " - Ignore empty frames\n"; std::cout << " - Ignore empty frames\n";
} }
std::cout << " - Size: " std::cout << " - Size: " << cof.document->sprite()->width() << "x"
<< cof.document->sprite()->width() << "x"
<< cof.document->sprite()->height() << "\n"; << cof.document->sprite()->height() << "\n";
showLayersFilter(cof); showLayersFilter(cof);
@ -136,8 +132,7 @@ void PreviewCliDelegate::saveFile(Context* ctx, const CliOpenFile& cof)
const auto& selFrames = cof.roi().framesSequence(); const auto& selFrames = cof.roi().framesSequence();
if (!selFrames.empty()) { if (!selFrames.empty()) {
if (selFrames.ranges() == 1) if (selFrames.ranges() == 1)
std::cout << " - Frame range from " std::cout << " - Frame range from " << selFrames.firstFrame() << " to "
<< selFrames.firstFrame() << " to "
<< selFrames.lastFrame() << "\n"; << selFrames.lastFrame() << "\n";
else { else {
std::cout << " - Specific frames:"; std::cout << " - Specific frames:";
@ -151,9 +146,7 @@ void PreviewCliDelegate::saveFile(Context* ctx, const CliOpenFile& cof)
if (!cof.filenameFormat.empty()) if (!cof.filenameFormat.empty())
std::cout << " - Filename format: '" << cof.filenameFormat << "'\n"; std::cout << " - Filename format: '" << cof.filenameFormat << "'\n";
std::unique_ptr<FileOp> fop( std::unique_ptr<FileOp> fop(FileOp::createSaveDocumentOperation(ctx,
FileOp::createSaveDocumentOperation(
ctx,
cof.roi(), cof.roi(),
cof.filename, cof.filename,
cof.filenameFormat, cof.filenameFormat,
@ -173,8 +166,7 @@ void PreviewCliDelegate::saveFile(Context* ctx, const CliOpenFile& cof)
std::cout << " - No output\n"; std::cout << " - No output\n";
} }
void PreviewCliDelegate::loadPalette(Context* ctx, void PreviewCliDelegate::loadPalette(Context* ctx, const std::string& filename)
const std::string& filename)
{ {
std::cout << "- Load palette:\n" std::cout << "- Load palette:\n"
<< " - Palette: '" << filename << "'\n"; << " - Palette: '" << filename << "'\n";
@ -197,8 +189,7 @@ void PreviewCliDelegate::exportFiles(Context* ctx, DocExporter& exporter)
<< " - Size: " << size.w << "x" << size.h << "\n"; << " - Size: " << size.w << "x" << size.h << "\n";
if (!exporter.textureFilename().empty()) { if (!exporter.textureFilename().empty()) {
std::cout << " - Save texture file: '" std::cout << " - Save texture file: '" << exporter.textureFilename() << "'\n";
<< exporter.textureFilename() << "'\n";
} }
if (!exporter.dataFilename().empty()) { if (!exporter.dataFilename().empty()) {
@ -211,15 +202,13 @@ void PreviewCliDelegate::exportFiles(Context* ctx, DocExporter& exporter)
<< " - Data format: " << format << "\n"; << " - Data format: " << format << "\n";
if (!exporter.filenameFormat().empty()) { if (!exporter.filenameFormat().empty()) {
std::cout << " - Filename format for JSON items: '" std::cout << " - Filename format for JSON items: '" << exporter.filenameFormat() << "'\n";
<< exporter.filenameFormat() << "'\n";
} }
} }
} }
#ifdef ENABLE_SCRIPTING #ifdef ENABLE_SCRIPTING
int PreviewCliDelegate::execScript(const std::string& filename, int PreviewCliDelegate::execScript(const std::string& filename, const Params& params)
const Params& params)
{ {
std::cout << "- Run script: '" << filename << "'\n"; std::cout << "- Run script: '" << filename << "'\n";
if (!params.empty()) { if (!params.empty()) {
@ -257,8 +246,7 @@ void PreviewCliDelegate::showLayerVisibility(const doc::LayerGroup* group,
continue; continue;
std::cout << indent << "- " << layer->name() << "\n"; std::cout << indent << "- " << layer->name() << "\n";
if (layer->isGroup()) if (layer->isGroup())
showLayerVisibility(static_cast<const LayerGroup*>(layer), showLayerVisibility(static_cast<const LayerGroup*>(layer), indent + " ");
indent + " ");
} }
} }

View File

@ -32,14 +32,12 @@ namespace app {
void loadPalette(Context* ctx, const std::string& filename) override; void loadPalette(Context* ctx, const std::string& filename) override;
void exportFiles(Context* ctx, DocExporter& exporter) override; void exportFiles(Context* ctx, DocExporter& exporter) override;
#ifdef ENABLE_SCRIPTING #ifdef ENABLE_SCRIPTING
int execScript(const std::string& filename, int execScript(const std::string& filename, const Params& params) override;
const Params& params) override;
#endif // ENABLE_SCRIPTING #endif // ENABLE_SCRIPTING
private: private:
void showLayersFilter(const CliOpenFile& cof); void showLayersFilter(const CliOpenFile& cof);
void showLayerVisibility(const doc::LayerGroup* group, void showLayerVisibility(const doc::LayerGroup* group, const std::string& indent);
const std::string& indent);
}; };
} // namespace app } // namespace app

View File

@ -20,8 +20,7 @@
namespace app { namespace app {
ClosedDocs::ClosedDocs(const Preferences& pref) ClosedDocs::ClosedDocs(const Preferences& pref) : m_done(false)
: m_done(false)
{ {
if (pref.general.dataRecovery()) if (pref.general.dataRecovery())
m_dataRecoveryPeriodMSecs = int(1000.0 * 60.0 * pref.general.dataRecoveryPeriod()); m_dataRecoveryPeriodMSecs = int(1000.0 * 60.0 * pref.general.dataRecoveryPeriod());
@ -34,8 +33,10 @@ ClosedDocs::ClosedDocs(const Preferences& pref)
m_keepClosedDocAliveForMSecs = 0; m_keepClosedDocAliveForMSecs = 0;
CLOSEDOC_TRACE("CLOSEDOC: Init", CLOSEDOC_TRACE("CLOSEDOC: Init",
"dataRecoveryPeriod", m_dataRecoveryPeriodMSecs, "dataRecoveryPeriod",
"keepClosedDocs", m_keepClosedDocAliveForMSecs); m_dataRecoveryPeriodMSecs,
"keepClosedDocs",
m_keepClosedDocAliveForMSecs);
} }
ClosedDocs::~ClosedDocs() ClosedDocs::~ClosedDocs()
@ -62,8 +63,7 @@ bool ClosedDocs::hasClosedDocs()
std::unique_lock<std::mutex> lock(m_mutex); std::unique_lock<std::mutex> lock(m_mutex);
result = !m_docs.empty(); result = !m_docs.empty();
} }
CLOSEDOC_TRACE("CLOSEDOC: Has closed docs?", CLOSEDOC_TRACE("CLOSEDOC: Has closed docs?", (result ? "true" : "false"));
(result ? "true": "false"));
return result; return result;
} }

View File

@ -115,7 +115,8 @@ std::string Cmd::onLabel() const
return ""; return "";
} }
size_t Cmd::onMemSize() const { size_t Cmd::onMemSize() const
{
return sizeof(*this); return sizeof(*this);
} }

View File

@ -21,17 +21,13 @@
#include "doc/layer.h" #include "doc/layer.h"
#include "doc/subobjects_io.h" #include "doc/subobjects_io.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace base::serialization; using namespace base::serialization;
using namespace base::serialization::little_endian; using namespace base::serialization::little_endian;
using namespace doc; using namespace doc;
AddCel::AddCel(Layer* layer, Cel* cel) AddCel::AddCel(Layer* layer, Cel* cel) : WithLayer(layer), WithCel(cel), m_size(0)
: WithLayer(layer)
, WithCel(cel)
, m_size(0)
{ {
} }
@ -119,5 +115,4 @@ void AddCel::removeCel(Layer* layer, Cel* cel)
delete cel; delete cel;
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -17,15 +17,14 @@
namespace doc { namespace doc {
class Cel; class Cel;
class Layer; class Layer;
} } // namespace doc
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class AddCel : public Cmd class AddCel : public Cmd,
, public WithLayer public WithLayer,
, public WithCel { public WithCel {
public: public:
AddCel(Layer* layer, Cel* cel); AddCel(Layer* layer, Cel* cel);
@ -33,9 +32,7 @@ namespace cmd {
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
void onRedo() override; void onRedo() override;
size_t onMemSize() const override { size_t onMemSize() const override { return sizeof(*this) + m_size; }
return sizeof(*this) + m_size;
}
private: private:
void addCel(Layer* layer, Cel* cel); void addCel(Layer* layer, Cel* cel);
@ -45,7 +42,6 @@ namespace cmd {
std::stringstream m_stream; std::stringstream m_stream;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -18,8 +18,7 @@
#include "doc/primitives.h" #include "doc/primitives.h"
#include "doc/sprite.h" #include "doc/sprite.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
@ -77,5 +76,4 @@ void AddFrame::onUndo()
doc->notify_observers<DocEvent&>(&DocObserver::onRemoveFrame, ev); doc->notify_observers<DocEvent&>(&DocObserver::onRemoveFrame, ev);
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -19,22 +19,18 @@ namespace doc {
class Sprite; class Sprite;
} }
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class AddFrame : public Cmd class AddFrame : public Cmd,
, public WithSprite { public WithSprite {
public: public:
AddFrame(Sprite* sprite, frame_t frame); AddFrame(Sprite* sprite, frame_t frame);
protected: protected:
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
size_t onMemSize() const override { size_t onMemSize() const override { return sizeof(*this) + (m_addCel ? m_addCel->memSize() : 0); }
return sizeof(*this) +
(m_addCel ? m_addCel->memSize() : 0);
}
private: private:
void moveFrames(Layer* layer, frame_t fromThis, frame_t delta); void moveFrames(Layer* layer, frame_t fromThis, frame_t delta);
@ -43,7 +39,6 @@ namespace cmd {
std::unique_ptr<AddCel> m_addCel; std::unique_ptr<AddCel> m_addCel;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -16,8 +16,7 @@
#include "doc/layer_io.h" #include "doc/layer_io.h"
#include "doc/subobjects_io.h" #include "doc/subobjects_io.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
@ -93,5 +92,4 @@ void AddLayer::removeLayer(Layer* group, Layer* layer)
delete layer; delete layer;
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -17,8 +17,7 @@ namespace doc {
class Layer; class Layer;
} }
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class AddLayer : public Cmd { class AddLayer : public Cmd {
@ -29,9 +28,7 @@ namespace cmd {
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
void onRedo() override; void onRedo() override;
size_t onMemSize() const override { size_t onMemSize() const override { return sizeof(*this) + m_size; }
return sizeof(*this) + m_size;
}
private: private:
void addLayer(Layer* group, Layer* newLayer, Layer* afterThis); void addLayer(Layer* group, Layer* newLayer, Layer* afterThis);
@ -44,7 +41,6 @@ namespace cmd {
std::stringstream m_stream; std::stringstream m_stream;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -10,12 +10,11 @@
#include "app/cmd/add_palette.h" #include "app/cmd/add_palette.h"
#include "doc/sprite.h"
#include "doc/palette.h" #include "doc/palette.h"
#include "doc/palette_io.h" #include "doc/palette_io.h"
#include "doc/sprite.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
@ -47,5 +46,4 @@ void AddPalette::onUndo()
sprite->incrementVersion(); sprite->incrementVersion();
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -17,23 +17,20 @@
namespace doc { namespace doc {
class Palette; class Palette;
class Sprite; class Sprite;
} } // namespace doc
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class AddPalette : public Cmd class AddPalette : public Cmd,
, public WithSprite { public WithSprite {
public: public:
AddPalette(Sprite* sprite, Palette* pal); AddPalette(Sprite* sprite, Palette* pal);
protected: protected:
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
size_t onMemSize() const override { size_t onMemSize() const override { return sizeof(*this) + m_size; }
return sizeof(*this) + m_size;
}
private: private:
size_t m_size; size_t m_size;
@ -41,7 +38,6 @@ namespace cmd {
frame_t m_frame; frame_t m_frame;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif // CMD_ADD_PALETTE_H_INCLUDED #endif // CMD_ADD_PALETTE_H_INCLUDED

View File

@ -17,15 +17,11 @@
#include "doc/slice_io.h" #include "doc/slice_io.h"
#include "doc/sprite.h" #include "doc/sprite.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
AddSlice::AddSlice(Sprite* sprite, Slice* slice) AddSlice::AddSlice(Sprite* sprite, Slice* slice) : WithSprite(sprite), WithSlice(slice), m_size(0)
: WithSprite(sprite)
, WithSlice(slice)
, m_size(0)
{ {
} }
@ -84,5 +80,4 @@ void AddSlice::removeSlice(Sprite* sprite, Slice* slice)
delete slice; delete slice;
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -15,13 +15,12 @@
#include <sstream> #include <sstream>
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class AddSlice : public Cmd class AddSlice : public Cmd,
, public WithSprite public WithSprite,
, public WithSlice { public WithSlice {
public: public:
AddSlice(Sprite* sprite, Slice* slice); AddSlice(Sprite* sprite, Slice* slice);
@ -29,9 +28,7 @@ namespace cmd {
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
void onRedo() override; void onRedo() override;
size_t onMemSize() const override { size_t onMemSize() const override { return sizeof(*this) + m_size; }
return sizeof(*this) + m_size;
}
private: private:
void addSlice(Sprite* sprite, Slice* slice); void addSlice(Sprite* sprite, Slice* slice);
@ -41,7 +38,6 @@ namespace cmd {
std::stringstream m_stream; std::stringstream m_stream;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -17,15 +17,11 @@
#include "doc/tag.h" #include "doc/tag.h"
#include "doc/tag_io.h" #include "doc/tag_io.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
AddTag::AddTag(Sprite* sprite, Tag* tag) AddTag::AddTag(Sprite* sprite, Tag* tag) : WithSprite(sprite), WithTag(tag), m_size(0)
: WithSprite(sprite)
, WithTag(tag)
, m_size(0)
{ {
} }
@ -86,5 +82,4 @@ void AddTag::onRedo()
doc->notify_observers<DocEvent&>(&DocObserver::onAddTag, ev); doc->notify_observers<DocEvent&>(&DocObserver::onAddTag, ev);
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -10,18 +10,17 @@
#pragma once #pragma once
#include "app/cmd.h" #include "app/cmd.h"
#include "app/cmd/with_tag.h"
#include "app/cmd/with_sprite.h" #include "app/cmd/with_sprite.h"
#include "app/cmd/with_tag.h"
#include <sstream> #include <sstream>
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class AddTag : public Cmd class AddTag : public Cmd,
, public WithSprite public WithSprite,
, public WithTag { public WithTag {
public: public:
AddTag(Sprite* sprite, Tag* tag); AddTag(Sprite* sprite, Tag* tag);
@ -29,16 +28,13 @@ namespace cmd {
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
void onRedo() override; void onRedo() override;
size_t onMemSize() const override { size_t onMemSize() const override { return sizeof(*this) + m_size; }
return sizeof(*this) + m_size;
}
private: private:
size_t m_size; size_t m_size;
std::stringstream m_stream; std::stringstream m_stream;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -16,12 +16,9 @@
#include "doc/tileset.h" #include "doc/tileset.h"
#include "doc/tilesets.h" #include "doc/tilesets.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
AddTile::AddTile(doc::Tileset* tileset, AddTile::AddTile(doc::Tileset* tileset, const doc::ImageRef& image, const doc::UserData& userData)
const doc::ImageRef& image,
const doc::UserData& userData)
: WithTileset(tileset) : WithTileset(tileset)
, WithImage(image.get()) , WithImage(image.get())
, m_size(0) , m_size(0)
@ -31,8 +28,7 @@ AddTile::AddTile(doc::Tileset* tileset,
{ {
} }
AddTile::AddTile(doc::Tileset* tileset, AddTile::AddTile(doc::Tileset* tileset, const doc::tile_index ti)
const doc::tile_index ti)
: WithTileset(tileset) : WithTileset(tileset)
, WithImage(tileset->get(ti).get()) , WithImage(tileset->get(ti).get())
, m_size(0) , m_size(0)
@ -94,8 +90,7 @@ void AddTile::onFireNotifications()
doc::Tileset* tileset = this->tileset(); doc::Tileset* tileset = this->tileset();
// Notify that the tileset's changed // Notify that the tileset's changed
static_cast<Doc*>(tileset->sprite()->document()) static_cast<Doc*>(tileset->sprite()->document())->notifyTilesetChanged(tileset);
->notifyTilesetChanged(tileset);
} }
void AddTile::addTile(doc::Tileset* tileset, void AddTile::addTile(doc::Tileset* tileset,
@ -111,5 +106,4 @@ void AddTile::addTile(doc::Tileset* tileset,
tileset->incrementVersion(); tileset->incrementVersion();
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -21,18 +21,16 @@ namespace doc {
class Tileset; class Tileset;
} }
namespace app { namespace app { namespace cmd {
namespace cmd {
class AddTile : public Cmd class AddTile : public Cmd,
, public WithTileset public WithTileset,
, public WithImage { public WithImage {
public: public:
AddTile(doc::Tileset* tileset, AddTile(doc::Tileset* tileset,
const doc::ImageRef& image, const doc::ImageRef& image,
const doc::UserData& userData = UserData()); const doc::UserData& userData = UserData());
AddTile(doc::Tileset* tileset, AddTile(doc::Tileset* tileset, const doc::tile_index ti);
const doc::tile_index ti);
doc::tile_index tileIndex() const { return m_tileIndex; } doc::tile_index tileIndex() const { return m_tileIndex; }
@ -41,15 +39,14 @@ namespace cmd {
void onUndo() override; void onUndo() override;
void onRedo() override; void onRedo() override;
void onFireNotifications() override; void onFireNotifications() override;
size_t onMemSize() const override { size_t onMemSize() const override
{
// TODO add m_userData size // TODO add m_userData size
return sizeof(*this) + m_size; return sizeof(*this) + m_size;
} }
private: private:
void addTile(doc::Tileset* tileset, void addTile(doc::Tileset* tileset, const doc::ImageRef& image, const doc::UserData& userData);
const doc::ImageRef& image,
const doc::UserData& userData);
size_t m_size; size_t m_size;
std::stringstream m_stream; std::stringstream m_stream;
@ -58,7 +55,6 @@ namespace cmd {
doc::UserData m_userData; doc::UserData m_userData;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -16,8 +16,7 @@
#include "doc/tileset_io.h" #include "doc/tileset_io.h"
#include "doc/tilesets.h" #include "doc/tilesets.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
@ -84,5 +83,4 @@ void AddTileset::addTileset(doc::Tileset* tileset)
sprite->tilesets()->incrementVersion(); sprite->tilesets()->incrementVersion();
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -19,12 +19,11 @@ namespace doc {
class Tileset; class Tileset;
} }
namespace app { namespace app { namespace cmd {
namespace cmd {
class AddTileset : public Cmd class AddTileset : public Cmd,
, public WithSprite public WithSprite,
, public WithTileset { public WithTileset {
public: public:
AddTileset(doc::Sprite* sprite, doc::Tileset* tileset); AddTileset(doc::Sprite* sprite, doc::Tileset* tileset);
AddTileset(doc::Sprite* sprite, const doc::tileset_index tsi); AddTileset(doc::Sprite* sprite, const doc::tileset_index tsi);
@ -35,9 +34,7 @@ namespace cmd {
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
void onRedo() override; void onRedo() override;
size_t onMemSize() const override { size_t onMemSize() const override { return sizeof(*this) + m_size; }
return sizeof(*this) + m_size;
}
private: private:
void addTileset(doc::Tileset* tileset); void addTileset(doc::Tileset* tileset);
@ -47,7 +44,6 @@ namespace cmd {
doc::tileset_index m_tilesetIndex; doc::tileset_index m_tilesetIndex;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -14,8 +14,7 @@
#include "app/doc_event.h" #include "app/doc_event.h"
#include "doc/sprite.h" #include "doc/sprite.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
AssignColorProfile::AssignColorProfile(doc::Sprite* sprite, const gfx::ColorSpaceRef& cs) AssignColorProfile::AssignColorProfile(doc::Sprite* sprite, const gfx::ColorSpaceRef& cs)
: WithSprite(sprite) : WithSprite(sprite)
@ -45,5 +44,4 @@ void AssignColorProfile::onFireNotifications()
doc->notifyColorSpaceChanged(); doc->notifyColorSpaceChanged();
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -12,8 +12,7 @@
#include "app/cmd/with_sprite.h" #include "app/cmd/with_sprite.h"
#include "gfx/color_space.h" #include "gfx/color_space.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
class AssignColorProfile : public Cmd, class AssignColorProfile : public Cmd,
public WithSprite { public WithSprite {
@ -24,11 +23,9 @@ namespace cmd {
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
void onFireNotifications() override; void onFireNotifications() override;
size_t onMemSize() const override { size_t onMemSize() const override
return sizeof(*this) + {
2*sizeof(gfx::ColorSpace) + return sizeof(*this) + 2 * sizeof(gfx::ColorSpace) + m_oldCS->iccSize() + m_newCS->iccSize();
m_oldCS->iccSize() +
m_newCS->iccSize();
} }
private: private:
@ -36,7 +33,6 @@ namespace cmd {
gfx::ColorSpaceRef m_newCS; gfx::ColorSpaceRef m_newCS;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -25,11 +25,9 @@
#include "doc/sprite.h" #include "doc/sprite.h"
#include "render/render.h" #include "render/render.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
BackgroundFromLayer::BackgroundFromLayer(Layer* layer) BackgroundFromLayer::BackgroundFromLayer(Layer* layer) : WithLayer(layer)
: WithLayer(layer)
{ {
ASSERT(layer); ASSERT(layer);
ASSERT(layer->isVisible()); ASSERT(layer->isVisible());
@ -60,10 +58,11 @@ void BackgroundFromLayer::onExecute()
ASSERT(cel_image->pixelFormat() != IMAGE_TILEMAP); ASSERT(cel_image->pixelFormat() != IMAGE_TILEMAP);
clear_image(bg_image.get(), bgcolor); clear_image(bg_image.get(), bgcolor);
render::composite_image( render::composite_image(bg_image.get(),
bg_image.get(), cel_image, cel_image,
sprite->palette(cel->frame()), sprite->palette(cel->frame()),
cel->x(), cel->y(), cel->x(),
cel->y(),
std::clamp(cel->opacity(), 0, 255), std::clamp(cel->opacity(), 0, 255),
static_cast<LayerImage*>(layer)->blendMode()); static_cast<LayerImage*>(layer)->blendMode());
@ -76,10 +75,8 @@ void BackgroundFromLayer::onExecute()
// Same size of cel image and background image, we can just // Same size of cel image and background image, we can just
// replace pixels. // replace pixels.
if (bg_image->width() == cel_image->width() && if (bg_image->width() == cel_image->width() && bg_image->height() == cel_image->height()) {
bg_image->height() == cel_image->height()) { executeAndAdd(new CopyRect(cel_image, bg_image.get(), gfx::Clip(0, 0, cel_image->bounds())));
executeAndAdd(new CopyRect(cel_image, bg_image.get(),
gfx::Clip(0, 0, cel_image->bounds())));
} }
// In other case we have to replace the whole image (this is the // In other case we have to replace the whole image (this is the
// most common case, a smaller transparent cel that is converted // most common case, a smaller transparent cel that is converted
@ -94,8 +91,7 @@ void BackgroundFromLayer::onExecute()
for (frame_t frame(0); frame < sprite->totalFrames(); ++frame) { for (frame_t frame(0); frame < sprite->totalFrames(); ++frame) {
Cel* cel = layer->cel(frame); Cel* cel = layer->cel(frame);
if (!cel) { if (!cel) {
ImageRef cel_image(Image::create(sprite->pixelFormat(), ImageRef cel_image(Image::create(sprite->pixelFormat(), sprite->width(), sprite->height()));
sprite->width(), sprite->height()));
clear_image(cel_image.get(), bgcolor); clear_image(cel_image.get(), bgcolor);
// Create the new cel and add it to the new background layer // Create the new cel and add it to the new background layer
@ -107,5 +103,4 @@ void BackgroundFromLayer::onExecute()
executeAndAdd(new cmd::ConfigureBackground(layer)); executeAndAdd(new cmd::ConfigureBackground(layer));
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -11,12 +11,11 @@
#include "app/cmd/with_layer.h" #include "app/cmd/with_layer.h"
#include "app/cmd_sequence.h" #include "app/cmd_sequence.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class BackgroundFromLayer : public CmdSequence class BackgroundFromLayer : public CmdSequence,
, public WithLayer { public WithLayer {
public: public:
BackgroundFromLayer(Layer* layer); BackgroundFromLayer(Layer* layer);
@ -24,7 +23,6 @@ namespace cmd {
void onExecute() override; void onExecute() override;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -16,13 +16,11 @@
#include "doc/cel.h" #include "doc/cel.h"
#include "doc/layer.h" #include "doc/layer.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
ClearCel::ClearCel(Cel* cel) ClearCel::ClearCel(Cel* cel) : WithCel(cel)
: WithCel(cel)
{ {
Doc* doc = static_cast<Doc*>(cel->document()); Doc* doc = static_cast<Doc*>(cel->document());
@ -30,8 +28,7 @@ ClearCel::ClearCel(Cel* cel)
Image* image = cel->image(); Image* image = cel->image();
ASSERT(image); ASSERT(image);
if (image) if (image)
m_seq.add(new cmd::ClearImage(image, m_seq.add(new cmd::ClearImage(image, doc->bgColor(cel->layer())));
doc->bgColor(cel->layer())));
} }
else { else {
m_seq.add(new cmd::RemoveCel(cel)); m_seq.add(new cmd::RemoveCel(cel));
@ -53,5 +50,4 @@ void ClearCel::onRedo()
m_seq.redo(); m_seq.redo();
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -12,12 +12,11 @@
#include "app/cmd/with_cel.h" #include "app/cmd/with_cel.h"
#include "app/cmd_sequence.h" #include "app/cmd_sequence.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class ClearCel : public Cmd class ClearCel : public Cmd,
, public WithCel { public WithCel {
public: public:
ClearCel(Cel* cel); ClearCel(Cel* cel);
@ -25,15 +24,12 @@ namespace cmd {
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
void onRedo() override; void onRedo() override;
size_t onMemSize() const override { size_t onMemSize() const override { return sizeof(*this) + m_seq.memSize(); }
return sizeof(*this) + m_seq.memSize();
}
private: private:
CmdSequence m_seq; CmdSequence m_seq;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -14,14 +14,11 @@
#include "doc/image.h" #include "doc/image.h"
#include "doc/primitives.h" #include "doc/primitives.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
ClearImage::ClearImage(Image* image, color_t color) ClearImage::ClearImage(Image* image, color_t color) : WithImage(image), m_color(color)
: WithImage(image)
, m_color(color)
{ {
} }
@ -46,5 +43,4 @@ void ClearImage::onUndo()
image->incrementVersion(); image->incrementVersion();
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -13,28 +13,24 @@
#include "doc/color.h" #include "doc/color.h"
#include "doc/image_ref.h" #include "doc/image_ref.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class ClearImage : public Cmd class ClearImage : public Cmd,
, public WithImage { public WithImage {
public: public:
ClearImage(Image* image, color_t color); ClearImage(Image* image, color_t color);
protected: protected:
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
size_t onMemSize() const override { size_t onMemSize() const override { return sizeof(*this) + (m_copy ? m_copy->getMemSize() : 0); }
return sizeof(*this) + (m_copy ? m_copy->getMemSize(): 0);
}
private: private:
ImageRef m_copy; ImageRef m_copy;
color_t m_color; color_t m_color;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -21,13 +21,11 @@
#include "doc/mask.h" #include "doc/mask.h"
#include "doc/primitives.h" #include "doc/primitives.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
ClearMask::ClearMask(Cel* cel) ClearMask::ClearMask(Cel* cel) : WithCel(cel)
: WithCel(cel)
{ {
Doc* doc = static_cast<Doc*>(cel->document()); Doc* doc = static_cast<Doc*>(cel->document());
@ -51,8 +49,7 @@ ClearMask::ClearMask(Cel* cel)
gfx::Rect maskBounds; gfx::Rect maskBounds;
if (image->pixelFormat() == IMAGE_TILEMAP) { if (image->pixelFormat() == IMAGE_TILEMAP) {
auto grid = cel->grid(); auto grid = cel->grid();
imageBounds = gfx::Rect(grid.canvasToTile(cel->position()), imageBounds = gfx::Rect(grid.canvasToTile(cel->position()), cel->image()->size());
cel->image()->size());
maskBounds = grid.canvasToTile(mask->bounds()); maskBounds = grid.canvasToTile(mask->bounds());
m_bgcolor = doc::notile; // TODO configurable empty tile m_bgcolor = doc::notile; // TODO configurable empty tile
} }
@ -100,8 +97,7 @@ void ClearMask::clear()
Mask* mask = doc->mask(); Mask* mask = doc->mask();
Grid grid = cel->grid(); Grid grid = cel->grid();
doc::algorithm::fill_selection( doc::algorithm::fill_selection(cel->image(),
cel->image(),
cel->bounds(), cel->bounds(),
mask, mask,
m_bgcolor, m_bgcolor,
@ -114,11 +110,7 @@ void ClearMask::restore()
return; return;
Cel* cel = this->cel(); Cel* cel = this->cel();
copy_image(cel->image(), copy_image(cel->image(), m_copy.get(), m_cropPos.x, m_cropPos.y);
m_copy.get(),
m_cropPos.x,
m_cropPos.y);
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -18,12 +18,11 @@
#include <memory> #include <memory>
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class ClearMask : public Cmd class ClearMask : public Cmd,
, public WithCel { public WithCel {
public: public:
ClearMask(Cel* cel); ClearMask(Cel* cel);
@ -31,9 +30,9 @@ namespace cmd {
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
void onRedo() override; void onRedo() override;
size_t onMemSize() const override { size_t onMemSize() const override
return sizeof(*this) + m_seq.memSize() + {
(m_copy ? m_copy->getMemSize(): 0); return sizeof(*this) + m_seq.memSize() + (m_copy ? m_copy->getMemSize() : 0);
} }
private: private:
@ -46,7 +45,6 @@ namespace cmd {
color_t m_bgcolor; color_t m_bgcolor;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -16,8 +16,7 @@
#include "doc/layer.h" #include "doc/layer.h"
#include "doc/primitives.h" #include "doc/primitives.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
@ -32,11 +31,8 @@ ClearRect::ClearRect(Cel* cel, const gfx::Rect& bounds)
m_offsetX = bounds.x - cel->x(); m_offsetX = bounds.x - cel->x();
m_offsetY = bounds.y - cel->y(); m_offsetY = bounds.y - cel->y();
gfx::Rect bounds2 = gfx::Rect bounds2 = image->bounds().createIntersection(
image->bounds().createIntersection( gfx::Rect(m_offsetX, m_offsetY, bounds.w, bounds.h));
gfx::Rect(
m_offsetX, m_offsetY,
bounds.w, bounds.h));
if (bounds.isEmpty()) if (bounds.isEmpty())
return; return;
@ -45,8 +41,7 @@ ClearRect::ClearRect(Cel* cel, const gfx::Rect& bounds)
Doc* doc = static_cast<Doc*>(cel->document()); Doc* doc = static_cast<Doc*>(cel->document());
m_bgcolor = doc->bgColor(cel->layer()); m_bgcolor = doc->bgColor(cel->layer());
m_copy.reset(crop_image(image, m_copy.reset(crop_image(image, bounds2.x, bounds2.y, bounds2.w, bounds2.h, m_bgcolor));
bounds2.x, bounds2.y, bounds2.w, bounds2.h, m_bgcolor));
} }
void ClearRect::onExecute() void ClearRect::onExecute()
@ -73,7 +68,8 @@ void ClearRect::onRedo()
void ClearRect::clear() void ClearRect::clear()
{ {
fill_rect(m_dstImage->image(), fill_rect(m_dstImage->image(),
m_offsetX, m_offsetY, m_offsetX,
m_offsetY,
m_offsetX + m_copy->width() - 1, m_offsetX + m_copy->width() - 1,
m_offsetY + m_copy->height() - 1, m_offsetY + m_copy->height() - 1,
m_bgcolor); m_bgcolor);
@ -84,5 +80,4 @@ void ClearRect::restore()
copy_image(m_dstImage->image(), m_copy.get(), m_offsetX, m_offsetY); copy_image(m_dstImage->image(), m_copy.get(), m_offsetX, m_offsetY);
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -20,8 +20,7 @@ namespace doc {
class Cel; class Cel;
} }
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class ClearRect : public Cmd { class ClearRect : public Cmd {
@ -32,9 +31,9 @@ namespace cmd {
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
void onRedo() override; void onRedo() override;
size_t onMemSize() const override { size_t onMemSize() const override
return sizeof(*this) + m_seq.memSize() + {
(m_copy ? m_copy->getMemSize(): 0); return sizeof(*this) + m_seq.memSize() + (m_copy ? m_copy->getMemSize() : 0);
} }
private: private:
@ -48,7 +47,6 @@ namespace cmd {
color_t m_bgcolor; color_t m_bgcolor;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -20,8 +20,7 @@
#include "doc/layer_list.h" #include "doc/layer_list.h"
#include "doc/primitives.h" #include "doc/primitives.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
@ -58,8 +57,7 @@ ClearSlices::ClearSlices(const Site& site,
color_t bgcolor = doc->bgColor(layer); color_t bgcolor = doc->bgColor(layer);
if (image->pixelFormat() == IMAGE_TILEMAP) { if (image->pixelFormat() == IMAGE_TILEMAP) {
auto grid = cel->grid(); auto grid = cel->grid();
imageBounds = gfx::Rect(grid.canvasToTile(cel->position()), imageBounds = gfx::Rect(grid.canvasToTile(cel->position()), cel->image()->size());
cel->image()->size());
maskBounds = grid.canvasToTile(maskBounds); maskBounds = grid.canvasToTile(maskBounds);
bgcolor = doc::notile; // TODO configurable empty tile bgcolor = doc::notile; // TODO configurable empty tile
} }
@ -101,21 +99,20 @@ void ClearSlices::clear()
if (!sc.copy) if (!sc.copy)
continue; continue;
if (sc.cel()->layer()->isTilemap() && m_tilemapMode == TilemapMode::Pixels) { if (sc.cel()->layer()->isTilemap() && m_tilemapMode == TilemapMode::Pixels) {
Doc* doc = static_cast<Doc*>(sc.cel()->document()); Doc* doc = static_cast<Doc*>(sc.cel()->document());
color_t bgcolor = doc->bgColor(sc.cel()->layer()); color_t bgcolor = doc->bgColor(sc.cel()->layer());
modify_tilemap_cel_region( modify_tilemap_cel_region(
&m_seq, sc.cel(), nullptr, &m_seq,
sc.cel(),
nullptr,
gfx::Region(sc.mask.bounds()), gfx::Region(sc.mask.bounds()),
m_tilesetMode, m_tilesetMode,
[sc, bgcolor](const doc::ImageRef& origTile, [sc, bgcolor](const doc::ImageRef& origTile,
const gfx::Rect& tileBoundsInCanvas) -> doc::ImageRef { const gfx::Rect& tileBoundsInCanvas) -> doc::ImageRef {
doc::ImageRef modified(doc::Image::createCopy(origTile.get())); doc::ImageRef modified(doc::Image::createCopy(origTile.get()));
doc::algorithm::fill_selection( doc::algorithm::fill_selection(modified.get(),
modified.get(),
tileBoundsInCanvas, tileBoundsInCanvas,
&sc.mask, &sc.mask,
bgcolor, bgcolor,
@ -125,8 +122,7 @@ void ClearSlices::clear()
} }
else { else {
Grid grid = sc.cel()->grid(); Grid grid = sc.cel()->grid();
doc::algorithm::fill_selection( doc::algorithm::fill_selection(sc.cel()->image(),
sc.cel()->image(),
sc.cel()->bounds(), sc.cel()->bounds(),
&sc.mask, &sc.mask,
sc.bgcolor, sc.bgcolor,
@ -141,12 +137,8 @@ void ClearSlices::restore()
if (!sc.copy) if (!sc.copy)
continue; continue;
copy_image(sc.cel()->image(), copy_image(sc.cel()->image(), sc.copy.get(), sc.cropPos.x, sc.cropPos.y);
sc.copy.get(),
sc.cropPos.x,
sc.cropPos.y);
} }
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -9,8 +9,8 @@
#pragma once #pragma once
#include "app/cmd.h" #include "app/cmd.h"
#include "app/cmd_sequence.h"
#include "app/cmd/with_cel.h" #include "app/cmd/with_cel.h"
#include "app/cmd_sequence.h"
#include "app/tilemap_mode.h" #include "app/tilemap_mode.h"
#include "app/tileset_mode.h" #include "app/tileset_mode.h"
#include "doc/cel.h" #include "doc/cel.h"
@ -41,7 +41,8 @@ namespace cmd {
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
void onRedo() override; void onRedo() override;
size_t onMemSize() const override { size_t onMemSize() const override
{
size_t sliceContentsSize = 0; size_t sliceContentsSize = 0;
for (const auto& sc : m_slicesContents) { for (const auto& sc : m_slicesContents) {
sliceContentsSize += sc.memSize(); sliceContentsSize += sc.memSize();
@ -57,9 +58,7 @@ namespace cmd {
Mask mask; Mask mask;
gfx::Point cropPos; gfx::Point cropPos;
color_t bgcolor; color_t bgcolor;
size_t memSize() const { size_t memSize() const { return sizeof(*this) + (copy ? copy->getMemSize() : 0); }
return sizeof(*this) + (copy ? copy->getMemSize(): 0);
}
}; };
void clear(); void clear();

View File

@ -16,25 +16,21 @@
#include "app/cmd/set_layer_opacity.h" #include "app/cmd/set_layer_opacity.h"
#include "doc/sprite.h" #include "doc/sprite.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
ConfigureBackground::ConfigureBackground(Layer* layer) ConfigureBackground::ConfigureBackground(Layer* layer)
{ {
// Add "Background" and "LockMove" flags // Add "Background" and "LockMove" flags
LayerFlags newFlags = LayerFlags(int(layer->flags()) LayerFlags newFlags = LayerFlags(int(layer->flags()) | int(LayerFlags::BackgroundLayerFlags));
| int(LayerFlags::BackgroundLayerFlags));
add(new cmd::SetLayerFlags(layer, newFlags)); add(new cmd::SetLayerFlags(layer, newFlags));
add(new cmd::SetLayerName(layer, "Background")); add(new cmd::SetLayerName(layer, "Background"));
if (layer->isImage() && if (layer->isImage() && static_cast<LayerImage*>(layer)->opacity() < 255) {
static_cast<LayerImage*>(layer)->opacity() < 255) {
add(new cmd::SetLayerOpacity(static_cast<LayerImage*>(layer), 255)); add(new cmd::SetLayerOpacity(static_cast<LayerImage*>(layer), 255));
} }
add(new cmd::MoveLayer(layer, layer->sprite()->root(), nullptr)); add(new cmd::MoveLayer(layer, layer->sprite()->root(), nullptr));
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -14,8 +14,7 @@ namespace doc {
class Layer; class Layer;
} }
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class ConfigureBackground : public CmdSequence { class ConfigureBackground : public CmdSequence {
@ -23,7 +22,6 @@ namespace cmd {
ConfigureBackground(Layer* layer); ConfigureBackground(Layer* layer);
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -20,8 +20,7 @@
#include "os/color_space.h" #include "os/color_space.h"
#include "os/system.h" #include "os/system.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
static doc::ImageRef convert_image_color_space(const doc::Image* srcImage, static doc::ImageRef convert_image_color_space(const doc::Image* srcImage,
const gfx::ColorSpaceRef& newCS, const gfx::ColorSpaceRef& newCS,
@ -70,8 +69,7 @@ static doc::ImageRef convert_image_color_space(const doc::Image* srcImage,
return dstImage; return dstImage;
} }
void convert_color_profile(doc::Sprite* sprite, void convert_color_profile(doc::Sprite* sprite, const gfx::ColorSpaceRef& newCS)
const gfx::ColorSpaceRef& newCS)
{ {
ASSERT(sprite->colorSpace()); ASSERT(sprite->colorSpace());
ASSERT(newCS); ASSERT(newCS);
@ -89,8 +87,7 @@ void convert_color_profile(doc::Sprite* sprite,
for (Cel* cel : sprite->uniqueCels()) { for (Cel* cel : sprite->uniqueCels()) {
ImageRef old_image = cel->imageRef(); ImageRef old_image = cel->imageRef();
if (old_image.get()->pixelFormat() != IMAGE_TILEMAP) { if (old_image.get()->pixelFormat() != IMAGE_TILEMAP) {
ImageRef new_image = convert_image_color_space( ImageRef new_image = convert_image_color_space(old_image.get(), newCS, conversion.get());
old_image.get(), newCS, conversion.get());
sprite->replaceImage(old_image->id(), new_image); sprite->replaceImage(old_image->id(), new_image);
} }
@ -106,8 +103,7 @@ void convert_color_profile(doc::Sprite* sprite,
for (int i = 0; i < pal->size(); ++i) { for (int i = 0; i < pal->size(); ++i) {
color_t oldCol = pal->entry(i); color_t oldCol = pal->entry(i);
color_t newCol = pal->entry(i); color_t newCol = pal->entry(i);
conversion->convertRgba((uint32_t*)&newCol, conversion->convertRgba((uint32_t*)&newCol, (const uint32_t*)&oldCol, 1);
(const uint32_t*)&oldCol, 1);
newPal.setEntry(i, newCol); newPal.setEntry(i, newCol);
} }
@ -142,8 +138,7 @@ void convert_color_profile(doc::Image* image,
switch (image->pixelFormat()) { switch (image->pixelFormat()) {
case doc::IMAGE_RGB: case doc::IMAGE_RGB:
case doc::IMAGE_GRAYSCALE: { case doc::IMAGE_GRAYSCALE: {
ImageRef newImage = convert_image_color_space( ImageRef newImage = convert_image_color_space(image, newCS, conversion.get());
image, newCS, conversion.get());
image->copy(newImage.get(), gfx::Clip(image->bounds())); image->copy(newImage.get(), gfx::Clip(image->bounds()));
break; break;
@ -153,8 +148,7 @@ void convert_color_profile(doc::Image* image,
for (int i = 0; i < palette->size(); ++i) { for (int i = 0; i < palette->size(); ++i) {
color_t oldCol, newCol; color_t oldCol, newCol;
oldCol = newCol = palette->entry(i); oldCol = newCol = palette->entry(i);
conversion->convertRgba((uint32_t*)&newCol, conversion->convertRgba((uint32_t*)&newCol, (const uint32_t*)&oldCol, 1);
(const uint32_t*)&oldCol, 1);
palette->setEntry(i, newCol); palette->setEntry(i, newCol);
} }
break; break;
@ -184,8 +178,7 @@ ConvertColorProfile::ConvertColorProfile(doc::Sprite* sprite, const gfx::ColorSp
for (Cel* cel : sprite->uniqueCels()) { for (Cel* cel : sprite->uniqueCels()) {
ImageRef old_image = cel->imageRef(); ImageRef old_image = cel->imageRef();
if (old_image.get()->pixelFormat() != IMAGE_TILEMAP) { if (old_image.get()->pixelFormat() != IMAGE_TILEMAP) {
ImageRef new_image = convert_image_color_space( ImageRef new_image = convert_image_color_space(old_image.get(), newCS, conversion.get());
old_image.get(), newCS, conversion.get());
m_seq.add(new cmd::ReplaceImage(sprite, old_image, new_image)); m_seq.add(new cmd::ReplaceImage(sprite, old_image, new_image));
} }
@ -201,8 +194,7 @@ ConvertColorProfile::ConvertColorProfile(doc::Sprite* sprite, const gfx::ColorSp
for (int i = 0; i < pal->size(); ++i) { for (int i = 0; i < pal->size(); ++i) {
color_t oldCol = pal->entry(i); color_t oldCol = pal->entry(i);
color_t newCol = pal->entry(i); color_t newCol = pal->entry(i);
conversion->convertRgba((uint32_t*)&newCol, conversion->convertRgba((uint32_t*)&newCol, (const uint32_t*)&oldCol, 1);
(const uint32_t*)&oldCol, 1);
newPal.setEntry(i, newCol); newPal.setEntry(i, newCol);
} }
@ -230,5 +222,4 @@ void ConvertColorProfile::onRedo()
m_seq.redo(); m_seq.redo();
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -20,10 +20,9 @@ namespace gfx {
namespace doc { namespace doc {
class Image; class Image;
class Palette; class Palette;
} } // namespace doc
namespace app { namespace app { namespace cmd {
namespace cmd {
class ConvertColorProfile : public Cmd, class ConvertColorProfile : public Cmd,
public WithSprite { public WithSprite {
@ -34,9 +33,7 @@ namespace cmd {
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
void onRedo() override; void onRedo() override;
size_t onMemSize() const override { size_t onMemSize() const override { return sizeof(*this) + m_seq.memSize(); }
return sizeof(*this) + m_seq.memSize();
}
private: private:
CmdSequence m_seq; CmdSequence m_seq;
@ -44,15 +41,13 @@ namespace cmd {
// Converts the sprite to the new color profile without undo information. // Converts the sprite to the new color profile without undo information.
// TODO how to merge this function with cmd::ConvertColorProfile // TODO how to merge this function with cmd::ConvertColorProfile
void convert_color_profile(doc::Sprite* sprite, void convert_color_profile(doc::Sprite* sprite, const gfx::ColorSpaceRef& newCS);
const gfx::ColorSpaceRef& newCS);
void convert_color_profile(doc::Image* image, void convert_color_profile(doc::Image* image,
doc::Palette* palette, doc::Palette* palette,
const gfx::ColorSpaceRef& oldCS, const gfx::ColorSpaceRef& oldCS,
const gfx::ColorSpaceRef& newCS); const gfx::ColorSpaceRef& newCS);
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -27,14 +27,15 @@
#include "render/rasterize.h" #include "render/rasterize.h"
#include "render/render.h" #include "render/render.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
CopyCel::CopyCel( CopyCel::CopyCel(Layer* srcLayer,
Layer* srcLayer, frame_t srcFrame, frame_t srcFrame,
Layer* dstLayer, frame_t dstFrame, bool continuous) Layer* dstLayer,
frame_t dstFrame,
bool continuous)
: m_srcLayer(srcLayer) : m_srcLayer(srcLayer)
, m_dstLayer(dstLayer) , m_dstLayer(dstLayer)
, m_srcFrame(srcFrame) , m_srcFrame(srcFrame)
@ -79,15 +80,13 @@ void CopyCel::onExecute()
if (dstCel) if (dstCel)
dstImage = dstCel->imageRef(); dstImage = dstCel->imageRef();
bool createLink = bool createLink = (srcLayer == dstLayer && m_continuous);
(srcLayer == dstLayer && m_continuous);
// For background layer // For background layer
if (dstLayer->isBackground()) { if (dstLayer->isBackground()) {
ASSERT(dstCel); ASSERT(dstCel);
ASSERT(dstImage); ASSERT(dstImage);
if (!dstCel || !dstImage || if (!dstCel || !dstImage || !srcCel || !srcImage)
!srcCel || !srcImage)
return; return;
ASSERT(!dstLayer->isTilemap()); // TODO support background tilemaps ASSERT(!dstLayer->isTilemap()); // TODO support background tilemaps
@ -102,15 +101,16 @@ void CopyCel::onExecute()
executeAndAdd(new cmd::CopyRect(dstImage.get(), tmp.get(), gfx::Clip(tmp->bounds()))); executeAndAdd(new cmd::CopyRect(dstImage.get(), tmp.get(), gfx::Clip(tmp->bounds())));
} }
else { else {
BlendMode blend = (srcLayer->isBackground() ? BlendMode blend = (srcLayer->isBackground() ? BlendMode::SRC : BlendMode::NORMAL);
BlendMode::SRC:
BlendMode::NORMAL);
ImageRef tmp(Image::createCopy(dstImage.get())); ImageRef tmp(Image::createCopy(dstImage.get()));
render::composite_image( render::composite_image(tmp.get(),
tmp.get(), srcImage, srcImage,
srcSprite->palette(m_srcFrame), srcSprite->palette(m_srcFrame),
srcCel->x(), srcCel->y(), 255, blend); srcCel->x(),
srcCel->y(),
255,
blend);
executeAndAdd(new cmd::CopyRect(dstImage.get(), tmp.get(), gfx::Clip(tmp->bounds()))); executeAndAdd(new cmd::CopyRect(dstImage.get(), tmp.get(), gfx::Clip(tmp->bounds())));
} }
} }
@ -142,10 +142,7 @@ void CopyCel::onFireNotifications()
ASSERT(m_dstLayer.layer()); ASSERT(m_dstLayer.layer());
static_cast<Doc*>(m_dstLayer.layer()->sprite()->document()) static_cast<Doc*>(m_dstLayer.layer()->sprite()->document())
->notifyCelCopied( ->notifyCelCopied(m_srcLayer.layer(), m_srcFrame, m_dstLayer.layer(), m_dstFrame);
m_srcLayer.layer(), m_srcFrame,
m_dstLayer.layer(), m_dstFrame);
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -14,15 +14,12 @@
#include "doc/color.h" #include "doc/color.h"
#include "doc/frame.h" #include "doc/frame.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class CopyCel : public CmdSequence { class CopyCel : public CmdSequence {
public: public:
CopyCel( CopyCel(Layer* srcLayer, frame_t srcFrame, Layer* dstLayer, frame_t dstFrame, bool continuous);
Layer* srcLayer, frame_t srcFrame,
Layer* dstLayer, frame_t dstFrame, bool continuous);
protected: protected:
void onExecute() override; void onExecute() override;
@ -34,7 +31,6 @@ namespace cmd {
bool m_continuous; bool m_continuous;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -14,11 +14,10 @@
#include "app/cmd/add_frame.h" #include "app/cmd/add_frame.h"
#include "app/cmd/copy_cel.h" #include "app/cmd/copy_cel.h"
#include "app/cmd/set_frame_duration.h" #include "app/cmd/set_frame_duration.h"
#include "doc/sprite.h"
#include "doc/layer.h" #include "doc/layer.h"
#include "doc/sprite.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
@ -41,5 +40,4 @@ void CopyFrame::onExecute()
// Do not copy cels (cmd::CopyCel must be called from outside) // Do not copy cels (cmd::CopyCel must be called from outside)
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -8,24 +8,23 @@
#define APP_CMD_COPY_FRAME_H_INCLUDED #define APP_CMD_COPY_FRAME_H_INCLUDED
#pragma once #pragma once
#include "app/cmd_sequence.h"
#include "app/cmd/with_sprite.h" #include "app/cmd/with_sprite.h"
#include "app/cmd_sequence.h"
#include "doc/frame.h" #include "doc/frame.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class CopyFrame : public CmdSequence class CopyFrame : public CmdSequence,
, public WithSprite { public WithSprite {
public: public:
CopyFrame(Sprite* sprite, frame_t fromFrame, frame_t newFrame); CopyFrame(Sprite* sprite, frame_t fromFrame, frame_t newFrame);
protected: protected:
void onExecute() override; void onExecute() override;
size_t onMemSize() const override { size_t onMemSize() const override
return sizeof(*this) + {
CmdSequence::onMemSize() - sizeof(CmdSequence); return sizeof(*this) + CmdSequence::onMemSize() - sizeof(CmdSequence);
} }
private: private:
@ -33,7 +32,6 @@ namespace cmd {
frame_t m_newFrame; frame_t m_newFrame;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -15,16 +15,13 @@
#include <algorithm> #include <algorithm>
namespace app { namespace app { namespace cmd {
namespace cmd {
CopyRect::CopyRect(Image* dst, const Image* src, const gfx::Clip& clip) CopyRect::CopyRect(Image* dst, const Image* src, const gfx::Clip& clip)
: WithImage(dst) : WithImage(dst)
, m_clip(clip) , m_clip(clip)
{ {
if (!m_clip.clip( if (!m_clip.clip(dst->width(), dst->height(), src->width(), src->height()))
dst->width(), dst->height(),
src->width(), src->height()))
return; return;
// Fill m_data with "src" data // Fill m_data with "src" data
@ -34,8 +31,7 @@ CopyRect::CopyRect(Image* dst, const Image* src, const gfx::Clip& clip)
auto it = m_data.begin(); auto it = m_data.begin();
for (int v = 0; v < m_clip.size.h; ++v) { for (int v = 0; v < m_clip.size.h; ++v) {
uint8_t* addr = src->getPixelAddress( uint8_t* addr = src->getPixelAddress(m_clip.dst.x, m_clip.dst.y + v);
m_clip.dst.x, m_clip.dst.y+v);
std::copy(addr, addr + lineSize, it); std::copy(addr, addr + lineSize, it);
it += lineSize; it += lineSize;
@ -68,8 +64,7 @@ void CopyRect::swap()
auto it = m_data.begin(); auto it = m_data.begin();
for (int v = 0; v < m_clip.size.h; ++v) { for (int v = 0; v < m_clip.size.h; ++v) {
uint8_t* addr = image->getPixelAddress( uint8_t* addr = image->getPixelAddress(m_clip.dst.x, m_clip.dst.y + v);
m_clip.dst.x, m_clip.dst.y+v);
std::copy(addr, addr + lineSize, tmp.begin()); std::copy(addr, addr + lineSize, tmp.begin());
std::copy(it, it + lineSize, addr); std::copy(it, it + lineSize, addr);
@ -86,5 +81,4 @@ int CopyRect::lineSize()
return image()->bytesPerPixel() * m_clip.size.w; return image()->bytesPerPixel() * m_clip.size.w;
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -18,12 +18,11 @@ namespace doc {
class Image; class Image;
} }
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class CopyRect : public Cmd class CopyRect : public Cmd,
, public WithImage { public WithImage {
public: public:
CopyRect(Image* dst, const Image* src, const gfx::Clip& clip); CopyRect(Image* dst, const Image* src, const gfx::Clip& clip);
@ -31,9 +30,7 @@ namespace cmd {
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
void onRedo() override; void onRedo() override;
size_t onMemSize() const override { size_t onMemSize() const override { return sizeof(*this) + m_data.size(); }
return sizeof(*this) + m_data.size();
}
private: private:
void swap(); void swap();
@ -43,7 +40,6 @@ namespace cmd {
std::vector<uint8_t> m_data; std::vector<uint8_t> m_data;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -17,10 +17,10 @@
#include "doc/sprite.h" #include "doc/sprite.h"
#include "doc/tileset.h" #include "doc/tileset.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
CopyRegion::CopyRegion(Image* dst, const Image* src, CopyRegion::CopyRegion(Image* dst,
const Image* src,
const gfx::Region& region, const gfx::Region& region,
const gfx::Point& dstPos, const gfx::Point& dstPos,
bool alreadyCopied) bool alreadyCopied)
@ -30,12 +30,8 @@ CopyRegion::CopyRegion(Image* dst, const Image* src,
ASSERT(!region.isEmpty()); ASSERT(!region.isEmpty());
gfx::Rect rc = region.bounds(); gfx::Rect rc = region.bounds();
gfx::Clip clip( gfx::Clip clip(rc.x + dstPos.x, rc.y + dstPos.y, rc.x, rc.y, rc.w, rc.h);
rc.x+dstPos.x, rc.y+dstPos.y, if (clip.clip(dst->width(), dst->height(), src->width(), src->height())) {
rc.x, rc.y, rc.w, rc.h);
if (clip.clip(
dst->width(), dst->height(),
src->width(), src->height())) {
// Create region to save/swap later // Create region to save/swap later
m_region = region; m_region = region;
m_region.offset(dstPos); m_region.offset(dstPos);
@ -45,7 +41,8 @@ CopyRegion::CopyRegion(Image* dst, const Image* src,
save_image_region_in_buffer(m_region, src, dstPos, m_buffer); save_image_region_in_buffer(m_region, src, dstPos, m_buffer);
} }
CopyTileRegion::CopyTileRegion(Image* dst, const Image* src, CopyTileRegion::CopyTileRegion(Image* dst,
const Image* src,
const gfx::Region& region, const gfx::Region& region,
const gfx::Point& dstPos, const gfx::Point& dstPos,
bool alreadyCopied, bool alreadyCopied,
@ -96,11 +93,9 @@ void CopyTileRegion::rehash()
tileset->notifyTileContentChange(m_tileIndex); tileset->notifyTileContentChange(m_tileIndex);
// Notify that the tileset changed // Notify that the tileset changed
static_cast<Doc*>(tileset->sprite()->document()) static_cast<Doc*>(tileset->sprite()->document())->notifyTilesetChanged(tileset);
->notifyTilesetChanged(tileset);
} }
} }
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -20,18 +20,18 @@ namespace doc {
class Tileset; class Tileset;
} }
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class CopyRegion : public Cmd class CopyRegion : public Cmd,
, public WithImage { public WithImage {
public: public:
// If alreadyCopied is false, it means that onExecute() will copy // If alreadyCopied is false, it means that onExecute() will copy
// pixels from src to dst. If it's true, it means that "onExecute" // pixels from src to dst. If it's true, it means that "onExecute"
// should do nothing, because modified pixels are alreadt on "dst" // should do nothing, because modified pixels are alreadt on "dst"
// (so we use "src" as the original image). // (so we use "src" as the original image).
CopyRegion(Image* dst, const Image* src, CopyRegion(Image* dst,
const Image* src,
const gfx::Region& region, const gfx::Region& region,
const gfx::Point& dstPos, const gfx::Point& dstPos,
bool alreadyCopied = false); bool alreadyCopied = false);
@ -40,9 +40,7 @@ namespace cmd {
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
void onRedo() override; void onRedo() override;
size_t onMemSize() const override { size_t onMemSize() const override { return sizeof(*this) + m_buffer.size(); }
return sizeof(*this) + m_buffer.size();
}
private: private:
void swap(); void swap();
@ -55,7 +53,8 @@ namespace cmd {
class CopyTileRegion : public CopyRegion { class CopyTileRegion : public CopyRegion {
public: public:
CopyTileRegion(Image* dst, const Image* src, CopyTileRegion(Image* dst,
const Image* src,
const gfx::Region& region, const gfx::Region& region,
const gfx::Point& dstPos, const gfx::Point& dstPos,
bool alreadyCopied, bool alreadyCopied,
@ -69,7 +68,6 @@ namespace cmd {
doc::ObjectId m_tilesetId; doc::ObjectId m_tilesetId;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -16,8 +16,7 @@
#include "doc/layer_tilemap.h" #include "doc/layer_tilemap.h"
#include "doc/primitives.h" #include "doc/primitives.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
@ -45,8 +44,7 @@ void CropCel::onUndo()
} }
// Crops the cel image leaving the same ID in the image. // Crops the cel image leaving the same ID in the image.
void CropCel::cropImage(const gfx::Point& origin, void CropCel::cropImage(const gfx::Point& origin, const gfx::Rect& bounds)
const gfx::Rect& bounds)
{ {
Cel* cel = this->cel(); Cel* cel = this->cel();
@ -60,8 +58,10 @@ void CropCel::cropImage(const gfx::Point& origin,
} }
if (bounds != cel->image()->bounds()) { if (bounds != cel->image()->bounds()) {
ImageRef image(crop_image(cel->image(), ImageRef image(crop_image(cel->image(),
localBounds.x, localBounds.y, localBounds.x,
localBounds.w, localBounds.h, localBounds.y,
localBounds.w,
localBounds.h,
cel->image()->maskColor())); cel->image()->maskColor()));
ObjectId id = cel->image()->id(); ObjectId id = cel->image()->id();
ObjectVersion ver = cel->image()->version(); ObjectVersion ver = cel->image()->version();
@ -80,5 +80,4 @@ void CropCel::cropImage(const gfx::Point& origin,
} }
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -14,24 +14,20 @@
#include "gfx/point.h" #include "gfx/point.h"
#include "gfx/rect.h" #include "gfx/rect.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
class CropCel : public Cmd class CropCel : public Cmd,
, public WithCel { public WithCel {
public: public:
CropCel(doc::Cel* cel, const gfx::Rect& newBounds); CropCel(doc::Cel* cel, const gfx::Rect& newBounds);
protected: protected:
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
size_t onMemSize() const override { size_t onMemSize() const override { return sizeof(*this); }
return sizeof(*this);
}
private: private:
void cropImage(const gfx::Point& origin, void cropImage(const gfx::Point& origin, const gfx::Rect& bounds);
const gfx::Rect& bounds);
gfx::Point m_oldOrigin; gfx::Point m_oldOrigin;
gfx::Point m_newOrigin; gfx::Point m_newOrigin;
@ -39,7 +35,6 @@ namespace cmd {
gfx::Rect m_newBounds; gfx::Rect m_newBounds;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -15,11 +15,9 @@
#include "app/doc.h" #include "app/doc.h"
#include "doc/mask.h" #include "doc/mask.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
DeselectMask::DeselectMask(Doc* doc) DeselectMask::DeselectMask(Doc* doc) : WithDocument(doc)
: WithDocument(doc)
{ {
} }
@ -49,5 +47,4 @@ size_t DeselectMask::onMemSize() const
return sizeof(*this) + (m_oldMask ? m_oldMask->getMemSize() : 0); return sizeof(*this) + (m_oldMask ? m_oldMask->getMemSize() : 0);
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -17,12 +17,11 @@ namespace doc {
class Mask; class Mask;
} }
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class DeselectMask : public Cmd class DeselectMask : public Cmd,
, public WithDocument { public WithDocument {
public: public:
DeselectMask(Doc* doc); DeselectMask(Doc* doc);
@ -35,7 +34,6 @@ namespace cmd {
std::unique_ptr<Mask> m_oldMask; std::unique_ptr<Mask> m_oldMask;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -11,30 +11,30 @@
#include "app/cmd/drop_on_timeline.h" #include "app/cmd/drop_on_timeline.h"
#include "app/cmd/add_layer.h" #include "app/cmd/add_layer.h"
#include "app/cmd/set_pixel_format.h"
#include "app/cmd/move_cel.h" #include "app/cmd/move_cel.h"
#include "app/context_flags.h" #include "app/cmd/set_pixel_format.h"
#include "app/console.h" #include "app/console.h"
#include "app/context_flags.h"
#include "app/doc.h" #include "app/doc.h"
#include "app/doc_event.h" #include "app/doc_event.h"
#include "app/file/file.h" #include "app/file/file.h"
#include "app/tx.h"
#include "app/util/layer_utils.h" #include "app/util/layer_utils.h"
#include "app/util/open_file_job.h" #include "app/util/open_file_job.h"
#include "app/tx.h"
#include "doc/layer_list.h" #include "doc/layer_list.h"
#include "render/dithering.h" #include "render/dithering.h"
#include <algorithm> #include <algorithm>
namespace app { namespace app { namespace cmd {
namespace cmd {
DropOnTimeline::DropOnTimeline(app::Doc* doc, DropOnTimeline::DropOnTimeline(app::Doc* doc,
doc::frame_t frame, doc::frame_t frame,
doc::layer_t layerIndex, doc::layer_t layerIndex,
InsertionPoint insert, InsertionPoint insert,
DroppedOn droppedOn, DroppedOn droppedOn,
const base::paths& paths) : WithDocument(doc) const base::paths& paths)
: WithDocument(doc)
, m_size(0) , m_size(0)
, m_paths(paths) , m_paths(paths)
, m_frame(frame) , m_frame(frame)
@ -52,7 +52,8 @@ DropOnTimeline::DropOnTimeline(app::Doc* doc,
doc::layer_t layerIndex, doc::layer_t layerIndex,
InsertionPoint insert, InsertionPoint insert,
DroppedOn droppedOn, DroppedOn droppedOn,
const doc::ImageRef& image) : WithDocument(doc) const doc::ImageRef& image)
: WithDocument(doc)
, m_size(0) , m_size(0)
, m_image(image) , m_image(image)
, m_frame(frame) , m_frame(frame)
@ -106,11 +107,10 @@ bool DropOnTimeline::getNextDocFromPaths(Doc** srcDoc)
{ {
Console console; Console console;
Context* context = document()->context(); Context* context = document()->context();
int flags = FILE_LOAD_DATA_FILE | FILE_LOAD_AVOID_BACKGROUND_LAYER | int flags = FILE_LOAD_DATA_FILE | FILE_LOAD_AVOID_BACKGROUND_LAYER | FILE_LOAD_CREATE_PALETTE |
FILE_LOAD_CREATE_PALETTE | FILE_LOAD_SEQUENCE_YES; FILE_LOAD_SEQUENCE_YES;
std::unique_ptr<FileOp> fop( std::unique_ptr<FileOp> fop(FileOp::createLoadDocumentOperation(context, m_paths.front(), flags));
FileOp::createLoadDocumentOperation(context, m_paths.front(), flags));
// Remove the path that is currently being processed // Remove the path that is currently being processed
m_paths.erase(m_paths.begin()); m_paths.erase(m_paths.begin());
@ -174,8 +174,8 @@ void DropOnTimeline::onExecute()
// Execute in a source doc transaction because we don't need undo/redo // Execute in a source doc transaction because we don't need undo/redo
// this. // this.
Tx tx(srcDoc); Tx tx(srcDoc);
tx(new cmd::SetPixelFormat( tx(new cmd::SetPixelFormat(srcDoc->sprite(),
srcDoc->sprite(), destDoc->sprite()->pixelFormat(), destDoc->sprite()->pixelFormat(),
render::Dithering(), render::Dithering(),
Preferences::instance().quantization.rgbmapAlgorithm(), Preferences::instance().quantization.rgbmapAlgorithm(),
nullptr, nullptr,
@ -314,11 +314,8 @@ bool DropOnTimeline::canMoveCelFrom(app::Doc* srcDoc)
{ {
auto* srcLayer = srcDoc->sprite()->firstLayer(); auto* srcLayer = srcDoc->sprite()->firstLayer();
auto* destLayer = document()->sprite()->allLayers()[m_layerIndex]; auto* destLayer = document()->sprite()->allLayers()[m_layerIndex];
return m_droppedOn == DroppedOn::Cel && return m_droppedOn == DroppedOn::Cel && srcDoc->sprite()->allLayersCount() == 1 &&
srcDoc->sprite()->allLayersCount() == 1 && srcDoc->sprite()->totalFrames() == 1 && srcLayer->isImage() && destLayer->isImage();
srcDoc->sprite()->totalFrames() == 1 &&
srcLayer->isImage() &&
destLayer->isImage();
} }
void DropOnTimeline::notifyDocObservers(Layer* layer) void DropOnTimeline::notifyDocObservers(Layer* layer)
@ -341,5 +338,4 @@ void DropOnTimeline::notifyDocObservers(Layer* layer)
doc->notify_observers<DocEvent&>(&DocObserver::onAfterRemoveLayer, ev); doc->notify_observers<DocEvent&>(&DocObserver::onAfterRemoveLayer, ev);
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -8,8 +8,8 @@
#define APP_CMD_drop_on_timeline_H_INCLUDED #define APP_CMD_drop_on_timeline_H_INCLUDED
#pragma once #pragma once
#include "app/cmd_sequence.h"
#include "app/cmd/with_document.h" #include "app/cmd/with_document.h"
#include "app/cmd_sequence.h"
#include "app/doc_observer.h" #include "app/doc_observer.h"
#include "base/paths.h" #include "base/paths.h"
#include "doc/frame.h" #include "doc/frame.h"
@ -17,11 +17,10 @@
#include "doc/layer.h" #include "doc/layer.h"
#include "doc/layer_list.h" #include "doc/layer_list.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
class DropOnTimeline : public CmdSequence class DropOnTimeline : public CmdSequence,
, public WithDocument { public WithDocument {
public: public:
enum class InsertionPoint { enum class InsertionPoint {
BeforeLayer, BeforeLayer,
@ -37,21 +36,27 @@ namespace cmd {
// Inserts the layers and frames of the documents pointed by the specified // Inserts the layers and frames of the documents pointed by the specified
// paths, at the specified frame and before or after the specified layer index. // paths, at the specified frame and before or after the specified layer index.
DropOnTimeline(app::Doc* doc, doc::frame_t frame, doc::layer_t layerIndex, DropOnTimeline(app::Doc* doc,
InsertionPoint insert, DroppedOn droppedOn, const base::paths& paths); doc::frame_t frame,
doc::layer_t layerIndex,
InsertionPoint insert,
DroppedOn droppedOn,
const base::paths& paths);
// Inserts the image as if it were a document with just one layer and one // Inserts the image as if it were a document with just one layer and one
// frame, at the specified frame and before or after the specified layer index. // frame, at the specified frame and before or after the specified layer index.
DropOnTimeline(app::Doc* doc, doc::frame_t frame, doc::layer_t layerIndex, DropOnTimeline(app::Doc* doc,
InsertionPoint insert, DroppedOn droppedOn, const doc::ImageRef& image); doc::frame_t frame,
doc::layer_t layerIndex,
InsertionPoint insert,
DroppedOn droppedOn,
const doc::ImageRef& image);
protected: protected:
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
void onRedo() override; void onRedo() override;
size_t onMemSize() const override { size_t onMemSize() const override { return sizeof(*this) + m_size; }
return sizeof(*this) + m_size;
}
private: private:
void setupInsertionLayer(doc::Layer** layer, doc::LayerGroup** group); void setupInsertionLayer(doc::Layer** layer, doc::LayerGroup** group);
@ -81,7 +86,6 @@ namespace cmd {
doc::frame_t m_previousTotalFrames; doc::frame_t m_previousTotalFrames;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -11,19 +11,19 @@
#include "app/cmd/flatten_layers.h" #include "app/cmd/flatten_layers.h"
#include "app/cmd/add_layer.h"
#include "app/cmd/add_cel.h" #include "app/cmd/add_cel.h"
#include "app/cmd/add_layer.h"
#include "app/cmd/configure_background.h" #include "app/cmd/configure_background.h"
#include "app/cmd/move_layer.h" #include "app/cmd/move_layer.h"
#include "app/cmd/remove_layer.h"
#include "app/cmd/remove_cel.h" #include "app/cmd/remove_cel.h"
#include "app/cmd/remove_layer.h"
#include "app/cmd/replace_image.h" #include "app/cmd/replace_image.h"
#include "app/cmd/set_cel_opacity.h"
#include "app/cmd/set_cel_position.h"
#include "app/cmd/set_cel_zindex.h"
#include "app/cmd/set_layer_blend_mode.h"
#include "app/cmd/set_layer_name.h" #include "app/cmd/set_layer_name.h"
#include "app/cmd/set_layer_opacity.h" #include "app/cmd/set_layer_opacity.h"
#include "app/cmd/set_layer_blend_mode.h"
#include "app/cmd/set_cel_opacity.h"
#include "app/cmd/set_cel_zindex.h"
#include "app/cmd/set_cel_position.h"
#include "app/cmd/unlink_cel.h" #include "app/cmd/unlink_cel.h"
#include "app/doc.h" #include "app/doc.h"
#include "app/i18n/strings.h" #include "app/i18n/strings.h"
@ -37,8 +37,7 @@
#include <algorithm> #include <algorithm>
namespace app { namespace app { namespace cmd {
namespace cmd {
FlattenLayers::FlattenLayers(doc::Sprite* sprite, FlattenLayers::FlattenLayers(doc::Sprite* sprite,
const doc::SelectedLayers& layers0, const doc::SelectedLayers& layers0,
@ -139,8 +138,7 @@ void FlattenLayers::onExecute()
for (frame_t frame(0); frame < sprite->totalFrames(); ++frame) { for (frame_t frame(0); frame < sprite->totalFrames(); ++frame) {
// If the flatLayer is the only cel in this frame, we can skip // If the flatLayer is the only cel in this frame, we can skip
// this frame to keep existing links in the flatLayer. // this frame to keep existing links in the flatLayer.
const bool anotherCelExists = const bool anotherCelExists = std::any_of(visibleLayers.begin(),
std::any_of(visibleLayers.begin(),
visibleLayers.end(), visibleLayers.end(),
[flatLayer, frame](const Layer* other) { [flatLayer, frame](const Layer* other) {
return (flatLayer != other && other->cel(frame)); return (flatLayer != other && other->cel(frame));
@ -154,9 +152,11 @@ void FlattenLayers::onExecute()
// Get exact bounds for rendered frame // Get exact bounds for rendered frame
gfx::Rect bounds = image->bounds(); gfx::Rect bounds = image->bounds();
const bool shrink = doc::algorithm::shrink_bounds( const bool shrink = doc::algorithm::shrink_bounds(image.get(),
image.get(), image->maskColor(), nullptr, image->maskColor(),
image->bounds(), bounds); nullptr,
image->bounds(),
bounds);
// Skip when fully transparent // Skip when fully transparent
Cel* cel = flatLayer->cel(frame); Cel* cel = flatLayer->cel(frame);
@ -168,12 +168,10 @@ void FlattenLayers::onExecute()
} }
// Apply shrunk bounds to new image // Apply shrunk bounds to new image
const ImageRef new_image(doc::crop_image( const ImageRef new_image(doc::crop_image(image.get(), bounds, image->maskColor()));
image.get(), bounds, image->maskColor()));
// Replace image on existing cel // Replace image on existing cel
if (cel) { if (cel) {
// TODO Keep cel links when possible // TODO Keep cel links when possible
if (cel->links()) if (cel->links())
@ -190,8 +188,7 @@ void FlattenLayers::onExecute()
if (cel->zIndex() != 0) if (cel->zIndex() != 0)
executeAndAdd(new cmd::SetCelZIndex(cel, 0)); executeAndAdd(new cmd::SetCelZIndex(cel, 0));
executeAndAdd(new cmd::SetCelPosition(cel, executeAndAdd(new cmd::SetCelPosition(cel, area.x + bounds.x, area.y + bounds.y));
area.x+bounds.x, area.y+bounds.y));
} }
// Modify destination cel // Modify destination cel
@ -221,9 +218,7 @@ void FlattenLayers::onExecute()
// Add new flatten layer // Add new flatten layer
if (newFlatLayer) { if (newFlatLayer) {
executeAndAdd(new cmd::AddLayer( executeAndAdd(new cmd::AddLayer(list.front()->parent(), flatLayer, list.front()));
list.front()->parent(), flatLayer, list.front()));
} }
// Reset layer properties when flattening in-place // Reset layer properties when flattening in-place
else { else {
@ -231,8 +226,7 @@ void FlattenLayers::onExecute()
executeAndAdd(new cmd::SetLayerOpacity(flatLayer, 255)); executeAndAdd(new cmd::SetLayerOpacity(flatLayer, 255));
if (flatLayer->blendMode() != doc::BlendMode::NORMAL) if (flatLayer->blendMode() != doc::BlendMode::NORMAL)
executeAndAdd(new cmd::SetLayerBlendMode( executeAndAdd(new cmd::SetLayerBlendMode(flatLayer, doc::BlendMode::NORMAL));
flatLayer, doc::BlendMode::NORMAL));
} }
// Delete flattened layers. // Delete flattened layers.
@ -245,5 +239,4 @@ void FlattenLayers::onExecute()
} }
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -14,30 +14,21 @@
#include "doc/object_ids.h" #include "doc/object_ids.h"
#include "doc/selected_layers.h" #include "doc/selected_layers.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
class FlattenLayers : public CmdSequence class FlattenLayers : public CmdSequence,
, public WithSprite { public WithSprite {
public: public:
struct Options { struct Options {
bool newBlendMethod : 1; bool newBlendMethod : 1;
bool inplace : 1; bool inplace : 1;
bool mergeDown : 1; bool mergeDown : 1;
bool dynamicCanvas : 1; bool dynamicCanvas : 1;
Options(): Options() : newBlendMethod(false), inplace(false), mergeDown(false), dynamicCanvas(false) {}
newBlendMethod(false),
inplace(false),
mergeDown(false),
dynamicCanvas(false) {
}
}; };
FlattenLayers(doc::Sprite* sprite, FlattenLayers(doc::Sprite* sprite, const doc::SelectedLayers& layers, const Options options);
const doc::SelectedLayers& layers,
const Options options);
protected: protected:
void onExecute() override; void onExecute() override;
@ -47,7 +38,6 @@ namespace cmd {
Options m_options; Options m_options;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -10,11 +10,10 @@
#include "app/cmd/flip_image.h" #include "app/cmd/flip_image.h"
#include "doc/image.h"
#include "doc/algorithm/flip_image.h" #include "doc/algorithm/flip_image.h"
#include "doc/image.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
FlipImage::FlipImage(Image* image, const gfx::Rect& bounds, doc::algorithm::FlipType flipType) FlipImage::FlipImage(Image* image, const gfx::Rect& bounds, doc::algorithm::FlipType flipType)
: WithImage(image) : WithImage(image)
@ -43,5 +42,4 @@ void FlipImage::swap()
image->incrementVersion(); image->incrementVersion();
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -19,22 +19,18 @@ namespace doc {
class Image; class Image;
} }
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class FlipImage : public Cmd class FlipImage : public Cmd,
, public WithImage { public WithImage {
public: public:
FlipImage(Image* image, const gfx::Rect& bounds, FlipImage(Image* image, const gfx::Rect& bounds, doc::algorithm::FlipType flipType);
doc::algorithm::FlipType flipType);
protected: protected:
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
size_t onMemSize() const override { size_t onMemSize() const override { return sizeof(*this); }
return sizeof(*this);
}
private: private:
void swap(); void swap();
@ -43,7 +39,6 @@ namespace cmd {
doc::algorithm::FlipType m_flipType; doc::algorithm::FlipType m_flipType;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -15,8 +15,7 @@
#include "doc/algorithm/flip_image.h" #include "doc/algorithm/flip_image.h"
#include "doc/mask.h" #include "doc/mask.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
@ -46,12 +45,10 @@ void FlipMask::swap()
return; return;
mask->freeze(); mask->freeze();
doc::algorithm::flip_image(mask->bitmap(), doc::algorithm::flip_image(mask->bitmap(), mask->bitmap()->bounds(), m_flipType);
mask->bitmap()->bounds(), m_flipType);
mask->unfreeze(); mask->unfreeze();
doc->notifySelectionChanged(); doc->notifySelectionChanged();
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -12,21 +12,18 @@
#include "app/cmd/with_document.h" #include "app/cmd/with_document.h"
#include "doc/algorithm/flip_type.h" #include "doc/algorithm/flip_type.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class FlipMask : public Cmd class FlipMask : public Cmd,
, public WithDocument { public WithDocument {
public: public:
FlipMask(Doc* doc, doc::algorithm::FlipType flipType); FlipMask(Doc* doc, doc::algorithm::FlipType flipType);
protected: protected:
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
size_t onMemSize() const override { size_t onMemSize() const override { return sizeof(*this); }
return sizeof(*this);
}
private: private:
void swap(); void swap();
@ -34,7 +31,6 @@ namespace cmd {
doc::algorithm::FlipType m_flipType; doc::algorithm::FlipType m_flipType;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -19,8 +19,7 @@
#include "doc/layer.h" #include "doc/layer.h"
#include "doc/mask.h" #include "doc/mask.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
FlipMaskedCel::FlipMaskedCel(Cel* cel, doc::algorithm::FlipType flipType) FlipMaskedCel::FlipMaskedCel(Cel* cel, doc::algorithm::FlipType flipType)
{ {
@ -36,16 +35,13 @@ FlipMaskedCel::FlipMaskedCel(Cel* cel, doc::algorithm::FlipType flipType)
int x = cel->x(); int x = cel->x();
int y = cel->y(); int y = cel->y();
mask->offsetOrigin(-x, -y); mask->offsetOrigin(-x, -y);
doc::algorithm::flip_image_with_mask( doc::algorithm::flip_image_with_mask(copy.get(), mask, flipType, bgcolor);
copy.get(), mask, flipType, bgcolor);
mask->offsetOrigin(x, y); mask->offsetOrigin(x, y);
int x1, y1, x2, y2; int x1, y1, x2, y2;
if (get_shrink_rect2(&x1, &y1, &x2, &y2, image, copy.get())) { if (get_shrink_rect2(&x1, &y1, &x2, &y2, image, copy.get())) {
add(new cmd::CopyRect(image, copy.get(), add(new cmd::CopyRect(image, copy.get(), gfx::Clip(x1, y1, x1, y1, x2 - x1 + 1, y2 - y1 + 1)));
gfx::Clip(x1, y1, x1, y1, x2-x1+1, y2-y1+1)));
} }
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -16,8 +16,7 @@ namespace doc {
class Cel; class Cel;
} }
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class FlipMaskedCel : public CmdSequence { class FlipMaskedCel : public CmdSequence {
@ -25,7 +24,6 @@ namespace cmd {
FlipMaskedCel(Cel* cel, doc::algorithm::FlipType flipType); FlipMaskedCel(Cel* cel, doc::algorithm::FlipType flipType);
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -15,8 +15,7 @@
#include "doc/layer.h" #include "doc/layer.h"
#include "doc/sprite.h" #include "doc/sprite.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
LayerFromBackground::LayerFromBackground(Layer* layer) LayerFromBackground::LayerFromBackground(Layer* layer)
{ {
@ -29,12 +28,10 @@ LayerFromBackground::LayerFromBackground(Layer* layer)
ASSERT(layer->sprite()->backgroundLayer() != NULL); ASSERT(layer->sprite()->backgroundLayer() != NULL);
// Remove "Background" and "LockMove" flags // Remove "Background" and "LockMove" flags
LayerFlags newFlags = LayerFlags(int(layer->flags()) LayerFlags newFlags = LayerFlags(int(layer->flags()) & ~int(LayerFlags::BackgroundLayerFlags));
& ~int(LayerFlags::BackgroundLayerFlags));
add(new cmd::SetLayerFlags(layer, newFlags)); add(new cmd::SetLayerFlags(layer, newFlags));
add(new cmd::SetLayerName(layer, "Layer 0")); add(new cmd::SetLayerName(layer, "Layer 0"));
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -14,8 +14,7 @@ namespace doc {
class Layer; class Layer;
} }
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class LayerFromBackground : public CmdSequence { class LayerFromBackground : public CmdSequence {
@ -23,7 +22,6 @@ namespace cmd {
LayerFromBackground(Layer* layer); LayerFromBackground(Layer* layer);
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -29,14 +29,15 @@
#include "render/rasterize.h" #include "render/rasterize.h"
#include "render/render.h" #include "render/render.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
MoveCel::MoveCel( MoveCel::MoveCel(LayerImage* srcLayer,
LayerImage* srcLayer, frame_t srcFrame, frame_t srcFrame,
LayerImage* dstLayer, frame_t dstFrame, bool continuous) LayerImage* dstLayer,
frame_t dstFrame,
bool continuous)
: m_srcLayer(srcLayer) : m_srcLayer(srcLayer)
, m_dstLayer(dstLayer) , m_dstLayer(dstLayer)
, m_srcFrame(srcFrame) , m_srcFrame(srcFrame)
@ -81,15 +82,13 @@ void MoveCel::onExecute()
if (dstCel) if (dstCel)
dstImage = dstCel->imageRef(); dstImage = dstCel->imageRef();
bool createLink = bool createLink = (srcLayer == dstLayer && m_continuous);
(srcLayer == dstLayer && m_continuous);
// For background layer // For background layer
if (dstLayer->isBackground()) { if (dstLayer->isBackground()) {
ASSERT(dstCel); ASSERT(dstCel);
ASSERT(dstImage); ASSERT(dstImage);
if (!dstCel || !dstImage || if (!dstCel || !dstImage || !srcCel || !srcImage)
!srcCel || !srcImage)
return; return;
ASSERT(!dstLayer->isTilemap()); // TODO support background tilemaps ASSERT(!dstLayer->isTilemap()); // TODO support background tilemaps
@ -105,15 +104,16 @@ void MoveCel::onExecute()
executeAndAdd(new cmd::CopyRect(dstImage.get(), tmp.get(), gfx::Clip(tmp->bounds()))); executeAndAdd(new cmd::CopyRect(dstImage.get(), tmp.get(), gfx::Clip(tmp->bounds())));
} }
else { else {
BlendMode blend = (srcLayer->isBackground() ? BlendMode blend = (srcLayer->isBackground() ? BlendMode::SRC : BlendMode::NORMAL);
BlendMode::SRC:
BlendMode::NORMAL);
ImageRef tmp(Image::createCopy(dstImage.get())); ImageRef tmp(Image::createCopy(dstImage.get()));
render::composite_image( render::composite_image(tmp.get(),
tmp.get(), srcImage, srcImage,
srcSprite->palette(m_srcFrame), srcSprite->palette(m_srcFrame),
srcCel->x(), srcCel->y(), 255, blend); srcCel->x(),
srcCel->y(),
255,
blend);
executeAndAdd(new cmd::CopyRect(dstImage.get(), tmp.get(), gfx::Clip(tmp->bounds()))); executeAndAdd(new cmd::CopyRect(dstImage.get(), tmp.get(), gfx::Clip(tmp->bounds())));
} }
executeAndAdd(new cmd::ClearCel(srcCel)); executeAndAdd(new cmd::ClearCel(srcCel));
@ -141,10 +141,7 @@ void MoveCel::onFireNotifications()
{ {
CmdSequence::onFireNotifications(); CmdSequence::onFireNotifications();
static_cast<Doc*>(m_dstLayer.layer()->sprite()->document()) static_cast<Doc*>(m_dstLayer.layer()->sprite()->document())
->notifyCelMoved( ->notifyCelMoved(m_srcLayer.layer(), m_srcFrame, m_dstLayer.layer(), m_dstFrame);
m_srcLayer.layer(), m_srcFrame,
m_dstLayer.layer(), m_dstFrame);
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -17,15 +17,16 @@ namespace doc {
class LayerImage; class LayerImage;
} }
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class MoveCel : public CmdSequence { class MoveCel : public CmdSequence {
public: public:
MoveCel( MoveCel(LayerImage* srcLayer,
LayerImage* srcLayer, frame_t srcFrame, frame_t srcFrame,
LayerImage* dstLayer, frame_t dstFrame, bool continuous); LayerImage* dstLayer,
frame_t dstFrame,
bool continuous);
protected: protected:
void onExecute() override; void onExecute() override;
@ -37,7 +38,6 @@ namespace cmd {
bool m_continuous; bool m_continuous;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -15,14 +15,11 @@
#include "doc/layer.h" #include "doc/layer.h"
#include "doc/sprite.h" #include "doc/sprite.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
MoveLayer::MoveLayer(Layer* layer, MoveLayer::MoveLayer(Layer* layer, Layer* newParent, Layer* afterThis)
Layer* newParent,
Layer* afterThis)
: m_layer(layer) : m_layer(layer)
, m_oldParent(layer->parent()) , m_oldParent(layer->parent())
, m_oldAfterThis(layer->getPrevious()) , m_oldAfterThis(layer->getPrevious())
@ -99,5 +96,4 @@ void MoveLayer::onFireNotifications()
doc->notify_observers<DocEvent&>(&DocObserver::onLayerRestacked, ev); doc->notify_observers<DocEvent&>(&DocObserver::onLayerRestacked, ev);
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -11,23 +11,18 @@
#include "app/cmd.h" #include "app/cmd.h"
#include "app/cmd/with_layer.h" #include "app/cmd/with_layer.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class MoveLayer : public Cmd { class MoveLayer : public Cmd {
public: public:
MoveLayer(Layer* layer, MoveLayer(Layer* layer, Layer* newParent, Layer* afterThis);
Layer* newParent,
Layer* afterThis);
protected: protected:
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
void onFireNotifications() override; void onFireNotifications() override;
size_t onMemSize() const override { size_t onMemSize() const override { return sizeof(*this); }
return sizeof(*this);
}
private: private:
WithLayer m_layer; WithLayer m_layer;
@ -35,7 +30,6 @@ namespace cmd {
WithLayer m_newParent, m_newAfterThis; WithLayer m_newParent, m_newAfterThis;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -17,8 +17,7 @@
#include "doc/cel.h" #include "doc/cel.h"
#include "doc/layer_tilemap.h" #include "doc/layer_tilemap.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
@ -57,17 +56,10 @@ void PatchCel::onExecute()
if (cel->image()->pixelFormat() == IMAGE_TILEMAP) { if (cel->image()->pixelFormat() == IMAGE_TILEMAP) {
executeAndAdd( executeAndAdd(
new CopyRegion(cel->image(), new CopyRegion(cel->image(), m_patch, regionInTiles, -grid.canvasToTile(cel->position())));
m_patch,
regionInTiles,
-grid.canvasToTile(cel->position())));
} }
else { else {
executeAndAdd( executeAndAdd(new CopyRegion(cel->image(), m_patch, m_region, m_pos - cel->position()));
new CopyRegion(cel->image(),
m_patch,
m_region,
m_pos - cel->position()));
} }
executeAndAdd(new TrimCel(cel)); executeAndAdd(new TrimCel(cel));
@ -75,5 +67,4 @@ void PatchCel::onExecute()
m_patch = nullptr; m_patch = nullptr;
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -16,13 +16,12 @@
namespace doc { namespace doc {
class Cel; class Cel;
class Image; class Image;
} } // namespace doc
namespace app { namespace app { namespace cmd {
namespace cmd {
class PatchCel : public CmdSequence class PatchCel : public CmdSequence,
, public WithCel { public WithCel {
public: public:
PatchCel(doc::Cel* dstCel, PatchCel(doc::Cel* dstCel,
const doc::Image* patch, const doc::Image* patch,
@ -37,7 +36,6 @@ namespace cmd {
gfx::Point m_pos; gfx::Point m_pos;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -16,14 +16,11 @@
#include "doc/remap.h" #include "doc/remap.h"
#include "doc/sprite.h" #include "doc/sprite.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
RemapColors::RemapColors(Sprite* sprite, const Remap& remap) RemapColors::RemapColors(Sprite* sprite, const Remap& remap) : WithSprite(sprite), m_remap(remap)
: WithSprite(sprite)
, m_remap(remap)
{ {
} }
@ -51,5 +48,4 @@ void RemapColors::incrementVersions(Sprite* spr)
cel->image()->incrementVersion(); cel->image()->incrementVersion();
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -12,21 +12,18 @@
#include "app/cmd/with_sprite.h" #include "app/cmd/with_sprite.h"
#include "doc/remap.h" #include "doc/remap.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class RemapColors : public Cmd class RemapColors : public Cmd,
, public WithSprite { public WithSprite {
public: public:
RemapColors(Sprite* sprite, const Remap& remap); RemapColors(Sprite* sprite, const Remap& remap);
protected: protected:
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
size_t onMemSize() const override { size_t onMemSize() const override { return sizeof(*this) + m_remap.getMemSize(); }
return sizeof(*this) + m_remap.getMemSize();
}
private: private:
void incrementVersions(Sprite* spr); void incrementVersions(Sprite* spr);
@ -34,7 +31,6 @@ namespace cmd {
Remap m_remap; Remap m_remap;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -20,13 +20,11 @@
#include "doc/sprite.h" #include "doc/sprite.h"
#include "doc/tileset.h" #include "doc/tileset.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
RemapTilemaps::RemapTilemaps(Tileset* tileset, RemapTilemaps::RemapTilemaps(Tileset* tileset, const Remap& remap)
const Remap& remap)
: WithTileset(tileset) : WithTileset(tileset)
, m_remap(remap) , m_remap(remap)
{ {
@ -69,5 +67,4 @@ void RemapTilemaps::incrementVersions(Tileset* tileset)
} }
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -12,22 +12,18 @@
#include "app/cmd/with_tileset.h" #include "app/cmd/with_tileset.h"
#include "doc/remap.h" #include "doc/remap.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class RemapTilemaps : public Cmd class RemapTilemaps : public Cmd,
, public WithTileset { public WithTileset {
public: public:
RemapTilemaps(Tileset* tileset, RemapTilemaps(Tileset* tileset, const Remap& remap);
const Remap& remap);
protected: protected:
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
size_t onMemSize() const override { size_t onMemSize() const override { return sizeof(*this) + m_remap.getMemSize(); }
return sizeof(*this) + m_remap.getMemSize();
}
private: private:
void remapTileset(Tileset* tileset, const Remap& remap); void remapTileset(Tileset* tileset, const Remap& remap);
@ -36,7 +32,6 @@ namespace cmd {
Remap m_remap; Remap m_remap;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -19,13 +19,11 @@
#include "doc/sprite.h" #include "doc/sprite.h"
#include "doc/tileset.h" #include "doc/tileset.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
RemapTileset::RemapTileset(Tileset* tileset, RemapTileset::RemapTileset(Tileset* tileset, const Remap& remap)
const Remap& remap)
: WithTileset(tileset) : WithTileset(tileset)
, m_remap(remap) , m_remap(remap)
{ {
@ -50,5 +48,4 @@ void RemapTileset::applyRemap(Tileset* tileset, const Remap& remap)
tileset->sprite()->incrementVersion(); tileset->sprite()->incrementVersion();
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -12,22 +12,18 @@
#include "app/cmd/with_tileset.h" #include "app/cmd/with_tileset.h"
#include "doc/remap.h" #include "doc/remap.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class RemapTileset : public Cmd class RemapTileset : public Cmd,
, public WithTileset { public WithTileset {
public: public:
RemapTileset(Tileset* tileset, RemapTileset(Tileset* tileset, const Remap& remap);
const Remap& remap);
protected: protected:
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
size_t onMemSize() const override { size_t onMemSize() const override { return sizeof(*this) + m_remap.getMemSize(); }
return sizeof(*this) + m_remap.getMemSize();
}
private: private:
void applyRemap(Tileset* tileset, const Remap& remap); void applyRemap(Tileset* tileset, const Remap& remap);
@ -35,7 +31,6 @@ namespace cmd {
Remap m_remap; Remap m_remap;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -13,13 +13,11 @@
#include "doc/cel.h" #include "doc/cel.h"
#include "doc/layer.h" #include "doc/layer.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
RemoveCel::RemoveCel(Cel* cel) RemoveCel::RemoveCel(Cel* cel) : AddCel(cel->layer(), cel)
: AddCel(cel->layer(), cel)
{ {
} }
@ -38,5 +36,4 @@ void RemoveCel::onRedo()
AddCel::onUndo(); AddCel::onUndo();
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -10,8 +10,7 @@
#include "app/cmd/add_cel.h" #include "app/cmd/add_cel.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class RemoveCel : public AddCel { class RemoveCel : public AddCel {
@ -24,7 +23,6 @@ namespace cmd {
void onRedo() override; void onRedo() override;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -16,8 +16,7 @@
#include "doc/cels_range.h" #include "doc/cels_range.h"
#include "doc/sprite.h" #include "doc/sprite.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
@ -79,5 +78,4 @@ void RemoveFrame::onUndo()
doc->notify_observers<DocEvent&>(&DocObserver::onAddFrame, ev); doc->notify_observers<DocEvent&>(&DocObserver::onAddFrame, ev);
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

View File

@ -13,21 +13,18 @@
#include "app/cmd_sequence.h" #include "app/cmd_sequence.h"
#include "doc/frame.h" #include "doc/frame.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
class RemoveFrame : public Cmd class RemoveFrame : public Cmd,
, public WithSprite { public WithSprite {
public: public:
RemoveFrame(Sprite* sprite, frame_t frame); RemoveFrame(Sprite* sprite, frame_t frame);
protected: protected:
void onExecute() override; void onExecute() override;
void onUndo() override; void onUndo() override;
size_t onMemSize() const override { size_t onMemSize() const override { return sizeof(*this) + m_seq.memSize(); }
return sizeof(*this) + m_seq.memSize();
}
private: private:
frame_t m_frame; frame_t m_frame;
@ -37,7 +34,6 @@ namespace cmd {
bool m_frameRemoved; bool m_frameRemoved;
}; };
} // namespace cmd }} // namespace app::cmd
} // namespace app
#endif #endif

View File

@ -10,16 +10,13 @@
#include "app/cmd/remove_layer.h" #include "app/cmd/remove_layer.h"
#include "doc/layer.h"
#include "doc/layer.h" #include "doc/layer.h"
namespace app { namespace app { namespace cmd {
namespace cmd {
using namespace doc; using namespace doc;
RemoveLayer::RemoveLayer(Layer* layer) RemoveLayer::RemoveLayer(Layer* layer) : AddLayer(layer->parent(), layer, layer->getPrevious())
: AddLayer(layer->parent(), layer, layer->getPrevious())
{ {
} }
@ -38,5 +35,4 @@ void RemoveLayer::onRedo()
AddLayer::onUndo(); AddLayer::onUndo();
} }
} // namespace cmd }} // namespace app::cmd
} // namespace app

Some files were not shown because too many files have changed in this diff Show More