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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -47,26 +47,21 @@ public:
, m_inkType(inkType)
, m_inkOpacity(inkOpacity)
, m_shade(shade)
, m_pixelPerfect(pixelPerfect) {
, m_pixelPerfect(pixelPerfect)
{
}
Flags flags() const { return m_flags; }
void setFlags(Flags flags) { m_flags = flags; }
bool isEmpty() const {
return int(m_flags) == 0;
}
bool isEmpty() const { return int(m_flags) == 0; }
bool hasFlag(Flags flag) const {
return ((int(m_flags) & int(flag)) == int(flag));
}
bool hasFlag(Flags flag) const { return ((int(m_flags) & int(flag)) == int(flag)); }
bool hasBrush() const {
return
(brush() &&
(hasFlag(Flags::BrushType) ||
hasFlag(Flags::BrushSize) ||
hasFlag(Flags::BrushAngle)));
bool hasBrush() const
{
return (brush() &&
(hasFlag(Flags::BrushType) || hasFlag(Flags::BrushSize) || hasFlag(Flags::BrushAngle)));
}
// 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
// access it.
bool locked() const {
return hasFlag(Flags::Locked);
}
bool locked() const { return hasFlag(Flags::Locked); }
void setLocked(bool locked) {
void setLocked(bool locked)
{
if (locked)
m_flags = static_cast<Flags>(int(m_flags) | int(Flags::Locked));
else

View File

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

View File

@ -33,10 +33,7 @@ namespace app {
bool isReceived() const;
const updater::CheckUpdateResponse& getResponse() const
{
return m_response;
}
const updater::CheckUpdateResponse& getResponse() const { return m_response; }
private:
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"))
#endif
, 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_saveAs(m_po.add("save-as").requiresValue("<filename>").description("Save the last given sprite with other format"))
, m_palette(m_po.add("palette").requiresValue("<filename>").description("Change the palette of the last given sprite"))
, m_scale(m_po.add("scale").requiresValue("<factor>").description("Resize all previously opened sprites"))
, 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_preview(m_po.add("preview").mnemonic('p').description(
"Do not execute actions, just print what will be\ndone"))
, m_saveAs(m_po.add("save-as")
.requiresValue("<filename>")
.description("Save the last given sprite with other format"))
, m_palette(m_po.add("palette")
.requiresValue("<filename>")
.description("Change the palette of the last given sprite"))
, m_scale(m_po.add("scale")
.requiresValue("<factor>")
.description("Resize all previously opened sprites"))
, 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_sheetWidth(m_po.add("sheet-width").requiresValue("<pixels>").description("Sprite sheet width"))
, m_sheetHeight(m_po.add("sheet-height").requiresValue("<pixels>").description("Sprite sheet height"))
, 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_sheetWidth(
m_po.add("sheet-width").requiresValue("<pixels>").description("Sprite sheet width"))
, m_sheetHeight(
m_po.add("sheet-height").requiresValue("<pixels>").description("Sprite sheet height"))
, 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_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_layer(m_po.add("layer").alias("import-layer").requiresValue("<name>").description("Include just the given layer in the sheet\nor save as operation"))
, m_allLayers(m_po.add("all-layers").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_layer(m_po.add("layer")
.alias("import-layer")
.requiresValue("<name>")
.description("Include just the given layer in the sheet\nor save as operation"))
, m_allLayers(m_po.add("all-layers")
.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_mergeDuplicates(m_po.add("merge-duplicates").description("Merge all duplicate frames into one in the sprite sheet"))
, m_borderPadding(m_po.add("border-padding").requiresValue("<value>").description("Add padding on the texture borders"))
, m_shapePadding(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_mergeDuplicates(m_po.add("merge-duplicates")
.description("Merge all duplicate frames into one in the sprite sheet"))
, m_borderPadding(m_po.add("border-padding")
.requiresValue("<value>")
.description("Add padding on the texture borders"))
, m_shapePadding(
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_crop(m_po.add("crop").requiresValue("x,y,width,height").description("Crop all the images to the given rectangle"))
, 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"))
, m_crop(m_po.add("crop")
.requiresValue("x,y,width,height")
.description("Crop all the images to the given rectangle"))
, 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
, m_script(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"))
, m_script(
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
, m_listLayers(m_po.add("list-layers").description("List layers of the next given sprite\nor include layers 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_listLayers(
m_po.add("list-layers")
.description("List layers of the next given sprite\nor include layers 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_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_debug(m_po.add("debug").description("Extreme verbose mode and\ncopy log to desktop"))
#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
#ifdef _WIN32
, 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_showVersion = m_po.enabled(m_version);
if (m_startShell ||
m_showHelp ||
m_showVersion ||
m_po.enabled(m_batch)) {
if (m_startShell || m_showHelp || m_showVersion || m_po.enabled(m_batch)) {
m_startUI = false;
}
}
@ -121,9 +203,7 @@ AppOptions::AppOptions(int argc, const char* argv[])
bool AppOptions::hasExporterParams() const
{
return
m_po.enabled(m_data) ||
m_po.enabled(m_sheet);
return m_po.enabled(m_data) || m_po.enabled(m_sheet);
}
#ifdef ENABLE_STEAM
@ -140,4 +220,4 @@ bool AppOptions::disableWintab() const
}
#endif
}
} // namespace app

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -8,8 +8,8 @@
#define APP_CMD_drop_on_timeline_H_INCLUDED
#pragma once
#include "app/cmd_sequence.h"
#include "app/cmd/with_document.h"
#include "app/cmd_sequence.h"
#include "app/doc_observer.h"
#include "base/paths.h"
#include "doc/frame.h"
@ -17,11 +17,10 @@
#include "doc/layer.h"
#include "doc/layer_list.h"
namespace app {
namespace cmd {
namespace app { namespace cmd {
class DropOnTimeline : public CmdSequence
, public WithDocument {
class DropOnTimeline : public CmdSequence,
public WithDocument {
public:
enum class InsertionPoint {
BeforeLayer,
@ -37,21 +36,27 @@ namespace cmd {
// 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.
DropOnTimeline(app::Doc* doc, doc::frame_t frame, doc::layer_t layerIndex,
InsertionPoint insert, DroppedOn droppedOn, const base::paths& paths);
DropOnTimeline(app::Doc* doc,
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
// 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,
InsertionPoint insert, DroppedOn droppedOn, const doc::ImageRef& image);
DropOnTimeline(app::Doc* doc,
doc::frame_t frame,
doc::layer_t layerIndex,
InsertionPoint insert,
DroppedOn droppedOn,
const doc::ImageRef& image);
protected:
void onExecute() override;
void onUndo() override;
void onRedo() override;
size_t onMemSize() const override {
return sizeof(*this) + m_size;
}
size_t onMemSize() const override { return sizeof(*this) + m_size; }
private:
void setupInsertionLayer(doc::Layer** layer, doc::LayerGroup** group);
@ -81,7 +86,6 @@ namespace cmd {
doc::frame_t m_previousTotalFrames;
};
} // namespace cmd
} // namespace app
}} // namespace app::cmd
#endif

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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