Merge branch 'main' into beta

This commit is contained in:
David Capello 2022-06-10 10:31:13 -03:00
commit 8f44b521b6
108 changed files with 509 additions and 522 deletions

View File

@ -37,6 +37,7 @@ jobs:
shell: bash shell: bash
run: | run: |
cmake -S . -B build -G Ninja \ cmake -S . -B build -G Ninja \
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.9 \
-DENABLE_TESTS=ON \ -DENABLE_TESTS=ON \
-DENABLE_UI=${{ matrix.enable_ui }} -DENABLE_UI=${{ matrix.enable_ui }}
- name: Compiling - name: Compiling

View File

@ -130,9 +130,9 @@ protected:
* [NL.26: Use conventional const notation](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#nl26-use-conventional-const-notation) * [NL.26: Use conventional const notation](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#nl26-use-conventional-const-notation)
## C++11 ## C++17
We are using some modern C++ (C++11, C++14, etc.) features, mainly: We are using C++17 standard. You can safely use:
* Use `nullptr` instead of `NULL` macro * Use `nullptr` instead of `NULL` macro
* Use `auto` for complex types, iterators, or when the variable type * Use `auto` for complex types, iterators, or when the variable type
@ -141,7 +141,10 @@ We are using some modern C++ (C++11, C++14, etc.) features, mainly:
* Use template alias (`template<typename T> alias = orig<T>;`) * Use template alias (`template<typename T> alias = orig<T>;`)
* Use non-generic lambda functions * Use non-generic lambda functions
* Use `std::shared_ptr`, `std::unique_ptr`, or `base::Ref` * Use `std::shared_ptr`, `std::unique_ptr`, or `base::Ref`
* Use `base::clamp` (no `std::clamp` yet) * Use `std::clamp`
* Use `std::optional`
* Use `std::optional::operator*` (because `std::optional::value` isn't
available on macOS 10.9, only since 10.13)
* Use `static constexpr T v = ...;` * Use `static constexpr T v = ...;`
* You can use `<atomic>`, `<thread>`, `<mutex>`, and `<condition_variable>` * You can use `<atomic>`, `<thread>`, `<mutex>`, and `<condition_variable>`
* Prefer `using T = ...;` instead of `typedef ... T` * Prefer `using T = ...;` instead of `typedef ... T`

2
laf

@ -1 +1 @@
Subproject commit 68a44741998e5a769a9b952ddb422e993dc5b6a9 Subproject commit 395a74c990f4df3889df0b7e140998ba68ea49af

View File

@ -87,6 +87,9 @@
#include "steam/steam.h" #include "steam/steam.h"
#endif #endif
#include <memory>
#include <optional>
namespace app { namespace app {
using namespace ui; using namespace ui;
@ -147,10 +150,12 @@ public:
InputChain m_inputChain; InputChain m_inputChain;
Clipboard m_clipboard; Clipboard m_clipboard;
#endif #endif
#ifdef ENABLE_DATA_RECOVERY
// This is a raw pointer because we want to delete it explicitly. // This is a raw pointer because we want to delete it explicitly.
// (e.g. if an exception occurs, the ~Modules() doesn't have to // (e.g. if an exception occurs, the ~Modules() doesn't have to
// delete m_recovery) // delete m_recovery)
app::crash::DataRecovery* m_recovery; std::unique_ptr<app::crash::DataRecovery> m_recovery;
#endif
Modules(const bool createLogInDesktop, Modules(const bool createLogInDesktop,
Preferences& pref) Preferences& pref)
@ -160,21 +165,30 @@ public:
#ifdef ENABLE_UI #ifdef ENABLE_UI
, m_recent_files(pref.general.recentItems()) , m_recent_files(pref.general.recentItems())
#endif #endif
, m_recovery(nullptr) { #ifdef ENABLE_DATA_RECOVERY
, m_recovery(nullptr)
#endif
{
} }
~Modules() { ~Modules() {
#ifdef ENABLE_DATA_RECOVERY
ASSERT(m_recovery == nullptr || ASSERT(m_recovery == nullptr ||
ui::get_app_state() == ui::AppState::kClosingWithException); ui::get_app_state() == ui::AppState::kClosingWithException);
#endif
} }
app::crash::DataRecovery* recovery() { app::crash::DataRecovery* recovery() {
return m_recovery; #ifdef ENABLE_DATA_RECOVERY
return m_recovery.get();
#else
return nullptr;
#endif
} }
void createDataRecovery(Context* ctx) { void createDataRecovery(Context* ctx) {
#ifdef ENABLE_DATA_RECOVERY #ifdef ENABLE_DATA_RECOVERY
m_recovery = new app::crash::DataRecovery(ctx); m_recovery = std::make_unique<app::crash::DataRecovery>(ctx);
m_recovery->SessionsListIsReady.connect( m_recovery->SessionsListIsReady.connect(
[] { [] {
ui::assert_ui_thread(); ui::assert_ui_thread();
@ -197,10 +211,7 @@ public:
void deleteDataRecovery() { void deleteDataRecovery() {
#ifdef ENABLE_DATA_RECOVERY #ifdef ENABLE_DATA_RECOVERY
if (m_recovery) { m_recovery.reset();
delete m_recovery;
m_recovery = nullptr;
}
#endif #endif
} }
@ -222,7 +233,7 @@ App::App(AppMod* mod)
, m_engine(new script::Engine) , m_engine(new script::Engine)
#endif #endif
{ {
ASSERT(m_instance == NULL); ASSERT(m_instance == nullptr);
m_instance = this; m_instance = this;
} }
@ -236,7 +247,7 @@ int App::initialize(const AppOptions& options)
m_isGui = false; m_isGui = false;
#endif #endif
m_isShell = options.startShell(); m_isShell = options.startShell();
m_coreModules = new CoreModules; m_coreModules = std::make_unique<CoreModules>();
#if LAF_WINDOWS #if LAF_WINDOWS
@ -289,10 +300,10 @@ int App::initialize(const AppOptions& options)
initialize_color_spaces(preferences()); initialize_color_spaces(preferences());
// Load modules // Load modules
m_modules = new Modules(createLogInDesktop, preferences()); m_modules = std::make_unique<Modules>(createLogInDesktop, preferences());
m_legacy = new LegacyModules(isGui() ? REQUIRE_INTERFACE: 0); m_legacy = std::make_unique<LegacyModules>(isGui() ? REQUIRE_INTERFACE: 0);
#ifdef ENABLE_UI #ifdef ENABLE_UI
m_brushes.reset(new AppBrushes); m_brushes = std::make_unique<AppBrushes>();
#endif #endif
// Data recovery is enabled only in GUI mode // Data recovery is enabled only in GUI mode
@ -577,17 +588,14 @@ App::~App()
// Finalize modules, configuration and core. // Finalize modules, configuration and core.
Editor::destroyEditorSharedInternals(); Editor::destroyEditorSharedInternals();
if (m_backupIndicator) { m_backupIndicator.reset();
delete m_backupIndicator;
m_backupIndicator = nullptr;
}
// Save brushes // Save brushes
m_brushes.reset(nullptr); m_brushes.reset();
#endif #endif
delete m_legacy; m_legacy.reset();
delete m_modules; m_modules.reset();
// Save preferences only if we are running in GUI mode. when we // Save preferences only if we are running in GUI mode. when we
// run in batch mode we might want to reset some preferences so // run in batch mode we might want to reset some preferences so
@ -596,15 +604,13 @@ App::~App()
if (isGui()) if (isGui())
preferences().save(); preferences().save();
delete m_coreModules; m_coreModules.reset();
#ifdef ENABLE_UI #ifdef ENABLE_UI
// Destroy the loaded gui.xml data. // Destroy the loaded gui.xml data.
delete KeyboardShortcuts::instance(); KeyboardShortcuts::destroyInstance();
delete GuiXml::instance(); GuiXml::destroyInstance();
#endif #endif
m_instance = NULL;
} }
catch (const std::exception& e) { catch (const std::exception& e) {
LOG(ERROR, "APP: Error: %s\n", e.what()); LOG(ERROR, "APP: Error: %s\n", e.what());
@ -617,6 +623,8 @@ App::~App()
// no re-throw // no re-throw
} }
m_instance = nullptr;
} }
Context* App::context() Context* App::context()
@ -626,13 +634,12 @@ Context* App::context()
bool App::isPortable() bool App::isPortable()
{ {
static bool* is_portable = NULL; static std::optional<bool> is_portable;
if (!is_portable) { if (!is_portable) {
is_portable = is_portable =
new bool( base::is_file(base::join_path(
base::is_file(base::join_path( base::get_file_path(base::get_app_path()),
base::get_file_path(base::get_app_path()), "aseprite.ini"));
"aseprite.ini")));
} }
return *is_portable; return *is_portable;
} }
@ -714,7 +721,7 @@ void App::showBackupNotification(bool state)
assert_ui_thread(); assert_ui_thread();
if (state) { if (state) {
if (!m_backupIndicator) if (!m_backupIndicator)
m_backupIndicator = new BackupIndicator; m_backupIndicator = std::make_unique<BackupIndicator>();
m_backupIndicator->start(); m_backupIndicator->start();
} }
else { else {

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -136,16 +136,16 @@ namespace app {
AppMod* m_mod; AppMod* m_mod;
std::unique_ptr<ui::UISystem> m_uiSystem; std::unique_ptr<ui::UISystem> m_uiSystem;
CoreModules* m_coreModules; std::unique_ptr<CoreModules> m_coreModules;
Modules* m_modules; std::unique_ptr<Modules> m_modules;
LegacyModules* m_legacy; std::unique_ptr<LegacyModules> m_legacy;
bool m_isGui; bool m_isGui;
bool m_isShell; bool m_isShell;
std::unique_ptr<MainWindow> m_mainWindow; std::unique_ptr<MainWindow> m_mainWindow;
base::paths m_files; base::paths m_files;
#ifdef ENABLE_UI #ifdef ENABLE_UI
std::unique_ptr<AppBrushes> m_brushes; std::unique_ptr<AppBrushes> m_brushes;
BackupIndicator* m_backupIndicator; std::unique_ptr<BackupIndicator> m_backupIndicator;
#endif // ENABLE_UI #endif // ENABLE_UI
#ifdef ENABLE_SCRIPTING #ifdef ENABLE_SCRIPTING
std::unique_ptr<script::Engine> m_engine; std::unique_ptr<script::Engine> m_engine;

View File

@ -460,9 +460,6 @@ void AppMenus::loadScriptsSubmenu(ui::Menu* menu,
const std::string& dir, const std::string& dir,
const bool rootLevel) const bool rootLevel)
{ {
Command* cmd_run_script =
Commands::instance()->byId(CommandId::RunScript());
auto files = base::list_files(dir); auto files = base::list_files(dir);
std::sort(files.begin(), files.end(), std::sort(files.begin(), files.end(),
[](const std::string& a, const std::string& b) { [](const std::string& a, const std::string& b) {
@ -482,7 +479,7 @@ void AppMenus::loadScriptsSubmenu(ui::Menu* menu,
params.set("filename", fullFn.c_str()); params.set("filename", fullFn.c_str());
menuitem = new AppMenuItem( menuitem = new AppMenuItem(
base::get_file_title(fn).c_str(), base::get_file_title(fn).c_str(),
cmd_run_script, CommandId::RunScript(),
params); params);
} }
} }
@ -531,8 +528,6 @@ bool AppMenus::rebuildRecentList()
removeMenuItemFromGroup(item); removeMenuItemFromGroup(item);
m_recentMenuItems.clear(); m_recentMenuItems.clear();
Command* openFile = Commands::instance()->byId(CommandId::OpenFile());
auto recent = App::instance()->recentFiles(); auto recent = App::instance()->recentFiles();
base::paths files; base::paths files;
files.insert(files.end(), files.insert(files.end(),
@ -548,7 +543,8 @@ bool AppMenus::rebuildRecentList()
std::unique_ptr<AppMenuItem> menuitem( std::unique_ptr<AppMenuItem> menuitem(
new AppMenuItem(base::get_file_name(fn).c_str(), new AppMenuItem(base::get_file_name(fn).c_str(),
openFile, params)); CommandId::OpenFile(),
params));
menuitem->setIsRecentFileItem(true); menuitem->setIsRecentFileItem(true);
m_recentMenuItems.push_back(menuitem.get()); m_recentMenuItems.push_back(menuitem.get());
@ -725,7 +721,8 @@ Widget* AppMenus::convertXmlelemToMenuitem(TiXmlElement* elem)
// Create the item // Create the item
AppMenuItem* menuitem = new AppMenuItem(m_xmlTranslator(elem, "text"), AppMenuItem* menuitem = new AppMenuItem(m_xmlTranslator(elem, "text"),
command, params); (command ? command->id(): ""),
params);
if (!menuitem) if (!menuitem)
return nullptr; return nullptr;
@ -775,11 +772,10 @@ void AppMenus::applyShortcutToMenuitemsWithCommand(Menu* menu,
if (!menuitem) if (!menuitem)
continue; continue;
Command* mi_command = menuitem->getCommand(); const std::string& mi_commandId = menuitem->getCommandId();
const Params& mi_params = menuitem->getParams(); const Params& mi_params = menuitem->getParams();
if ((mi_command) && if ((base::utf8_icmp(mi_commandId, command->id()) == 0) &&
(base::utf8_icmp(mi_command->id(), command->id()) == 0) &&
(mi_params == params)) { (mi_params == params)) {
// Set the keyboard shortcut to be shown in this menu-item // Set the keyboard shortcut to be shown in this menu-item
menuitem->setKey(key); menuitem->setKey(key);
@ -941,7 +937,7 @@ void AppMenus::createNativeSubmenus(os::Menu* osMenu,
if (appMenuItem && if (appMenuItem &&
appMenuItem->getCommand()) { appMenuItem->getCommand()) {
native = get_native_shortcut_for_command( native = get_native_shortcut_for_command(
appMenuItem->getCommand()->id().c_str(), appMenuItem->getCommandId().c_str(),
appMenuItem->getParams()); appMenuItem->getParams());
} }

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2018-2021 Igara Studio S.A. // Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -23,7 +23,6 @@
#include "app/filename_formatter.h" #include "app/filename_formatter.h"
#include "app/restore_visible_layers.h" #include "app/restore_visible_layers.h"
#include "app/ui_context.h" #include "app/ui_context.h"
#include "base/clamp.h"
#include "base/convert_to.h" #include "base/convert_to.h"
#include "base/fs.h" #include "base/fs.h"
#include "base/split_string.h" #include "base/split_string.h"
@ -665,8 +664,8 @@ bool CliProcessor::openFile(Context* ctx, CliOpenFile& cof)
// --frame-range with --frame-tag // --frame-range with --frame-tag
if (tag) { if (tag) {
selFrames.insert( selFrames.insert(
tag->fromFrame()+base::clamp(cof.fromFrame, 0, tag->frames()-1), tag->fromFrame()+std::clamp(cof.fromFrame, 0, tag->frames()-1),
tag->fromFrame()+base::clamp(cof.toFrame, 0, tag->frames()-1)); tag->fromFrame()+std::clamp(cof.toFrame, 0, tag->frames()-1));
} }
// --frame-range without --frame-tag // --frame-range without --frame-tag
else { else {

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello // Copyright (C) 2001-2016 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -18,7 +18,6 @@
#include "app/cmd/set_cel_opacity.h" #include "app/cmd/set_cel_opacity.h"
#include "app/cmd/set_cel_position.h" #include "app/cmd/set_cel_position.h"
#include "app/doc.h" #include "app/doc.h"
#include "base/clamp.h"
#include "doc/cel.h" #include "doc/cel.h"
#include "doc/image.h" #include "doc/image.h"
#include "doc/layer.h" #include "doc/layer.h"
@ -65,7 +64,7 @@ void BackgroundFromLayer::onExecute()
bg_image.get(), cel_image, bg_image.get(), cel_image,
sprite->palette(cel->frame()), sprite->palette(cel->frame()),
cel->x(), cel->y(), cel->x(), cel->y(),
base::clamp(cel->opacity(), 0, 255), std::clamp(cel->opacity(), 0, 255),
static_cast<LayerImage*>(layer)->blendMode()); static_cast<LayerImage*>(layer)->blendMode());
// now we have to copy the new image (bg_image) to the cel... // now we have to copy the new image (bg_image) to the cel...

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2020 Igara Studio S.A. // Copyright (C) 2020-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -13,7 +13,6 @@
#include "app/color_utils.h" #include "app/color_utils.h"
#include "app/modules/palettes.h" #include "app/modules/palettes.h"
#include "base/clamp.h"
#include "base/debug.h" #include "base/debug.h"
#include "doc/image.h" #include "doc/image.h"
#include "doc/palette.h" #include "doc/palette.h"
@ -206,8 +205,8 @@ std::string Color::toString() const
<< std::setprecision(2) << std::setprecision(2)
<< std::fixed << std::fixed
<< m_value.hsv.h << "," << m_value.hsv.h << ","
<< base::clamp(m_value.hsv.s*100.0, 0.0, 100.0) << "," << std::clamp(m_value.hsv.s*100.0, 0.0, 100.0) << ","
<< base::clamp(m_value.hsv.v*100.0, 0.0, 100.0) << "," << std::clamp(m_value.hsv.v*100.0, 0.0, 100.0) << ","
<< m_value.hsv.a << "}"; << m_value.hsv.a << "}";
break; break;
@ -216,8 +215,8 @@ std::string Color::toString() const
<< std::setprecision(2) << std::setprecision(2)
<< std::fixed << std::fixed
<< m_value.hsl.h << "," << m_value.hsl.h << ","
<< base::clamp(m_value.hsl.s*100.0, 0.0, 100.0) << "," << std::clamp(m_value.hsl.s*100.0, 0.0, 100.0) << ","
<< base::clamp(m_value.hsl.l*100.0, 0.0, 100.0) << "," << std::clamp(m_value.hsl.l*100.0, 0.0, 100.0) << ","
<< m_value.hsl.a << "}"; << m_value.hsl.a << "}";
break; break;
@ -270,8 +269,8 @@ std::string Color::toHumanReadableString(PixelFormat pixelFormat, HumanReadableS
else { else {
result << "HSV " result << "HSV "
<< int(m_value.hsv.h) << "\xc2\xb0 " << int(m_value.hsv.h) << "\xc2\xb0 "
<< base::clamp(int(m_value.hsv.s*100.0), 0, 100) << "% " << std::clamp(int(m_value.hsv.s*100.0), 0, 100) << "% "
<< base::clamp(int(m_value.hsv.v*100.0), 0, 100) << "%"; << std::clamp(int(m_value.hsv.v*100.0), 0, 100) << "%";
if (pixelFormat == IMAGE_INDEXED) if (pixelFormat == IMAGE_INDEXED)
result << " Index " << color_utils::color_for_image(*this, IMAGE_INDEXED); result << " Index " << color_utils::color_for_image(*this, IMAGE_INDEXED);
@ -290,8 +289,8 @@ std::string Color::toHumanReadableString(PixelFormat pixelFormat, HumanReadableS
else { else {
result << "HSL " result << "HSL "
<< int(m_value.hsl.h) << "\xc2\xb0 " << int(m_value.hsl.h) << "\xc2\xb0 "
<< base::clamp(int(m_value.hsl.s*100.0), 0, 100) << "% " << std::clamp(int(m_value.hsl.s*100.0), 0, 100) << "% "
<< base::clamp(int(m_value.hsl.l*100.0), 0, 100) << "%"; << std::clamp(int(m_value.hsl.l*100.0), 0, 100) << "%";
if (pixelFormat == IMAGE_INDEXED) if (pixelFormat == IMAGE_INDEXED)
result << " Index " << color_utils::color_for_image(*this, IMAGE_INDEXED); result << " Index " << color_utils::color_for_image(*this, IMAGE_INDEXED);
@ -360,8 +359,8 @@ std::string Color::toHumanReadableString(PixelFormat pixelFormat, HumanReadableS
} }
else { else {
result << int(m_value.hsv.h) << "\xc2\xb0" result << int(m_value.hsv.h) << "\xc2\xb0"
<< base::clamp(int(m_value.hsv.s*100.0), 0, 100) << "," << std::clamp(int(m_value.hsv.s*100.0), 0, 100) << ","
<< base::clamp(int(m_value.hsv.v*100.0), 0, 100); << std::clamp(int(m_value.hsv.v*100.0), 0, 100);
} }
break; break;
@ -371,8 +370,8 @@ std::string Color::toHumanReadableString(PixelFormat pixelFormat, HumanReadableS
} }
else { else {
result << int(m_value.hsl.h) << "\xc2\xb0" result << int(m_value.hsl.h) << "\xc2\xb0"
<< base::clamp(int(m_value.hsl.s*100.0), 0, 100) << "," << std::clamp(int(m_value.hsl.s*100.0), 0, 100) << ","
<< base::clamp(int(m_value.hsl.l*100.0), 0, 100); << std::clamp(int(m_value.hsl.l*100.0), 0, 100);
} }
break; break;
@ -910,7 +909,7 @@ int Color::getAlpha() const
void Color::setAlpha(int alpha) void Color::setAlpha(int alpha)
{ {
alpha = base::clamp(alpha, 0, 255); alpha = std::clamp(alpha, 0, 255);
switch (getType()) { switch (getType()) {

View File

@ -23,7 +23,6 @@
#include "app/ui/editor/select_box_state.h" #include "app/ui/editor/select_box_state.h"
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "app/ui_context.h" #include "app/ui_context.h"
#include "base/clamp.h"
#include "doc/image.h" #include "doc/image.h"
#include "doc/mask.h" #include "doc/mask.h"
#include "doc/sprite.h" #include "doc/sprite.h"

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2020 Igara Studio S.A. // Copyright (C) 2020-2022 Igara Studio S.A.
// Copyright (C) 2018 David Capello // Copyright (C) 2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -19,7 +19,6 @@
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/tx.h" #include "app/tx.h"
#include "app/ui/timeline/timeline.h" #include "app/ui/timeline/timeline.h"
#include "base/clamp.h"
#include "doc/cel.h" #include "doc/cel.h"
#include "doc/cels_range.h" #include "doc/cels_range.h"
#include "doc/sprite.h" #include "doc/sprite.h"
@ -53,7 +52,7 @@ CelOpacityCommand::CelOpacityCommand()
void CelOpacityCommand::onLoadParams(const Params& params) void CelOpacityCommand::onLoadParams(const Params& params)
{ {
m_opacity = params.get_as<int>("opacity"); m_opacity = params.get_as<int>("opacity");
m_opacity = base::clamp(m_opacity, 0, 255); m_opacity = std::clamp(m_opacity, 0, 255);
} }
bool CelOpacityCommand::onEnabled(Context* context) bool CelOpacityCommand::onEnabled(Context* context)

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2021 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -32,7 +32,6 @@
#include "app/ui/optional_alert.h" #include "app/ui/optional_alert.h"
#include "app/ui/status_bar.h" #include "app/ui/status_bar.h"
#include "app/ui/timeline/timeline.h" #include "app/ui/timeline/timeline.h"
#include "base/clamp.h"
#include "base/convert_to.h" #include "base/convert_to.h"
#include "base/fs.h" #include "base/fs.h"
#include "base/string.h" #include "base/string.h"
@ -184,9 +183,9 @@ Doc* generate_sprite_sheet_from_params(
const std::string filenameFormat = params.filenameFormat(); const std::string filenameFormat = params.filenameFormat();
const std::string layerName = params.layer(); const std::string layerName = params.layer();
const std::string tagName = params.tag(); const std::string tagName = params.tag();
const int borderPadding = base::clamp(params.borderPadding(), 0, 100); const int borderPadding = std::clamp(params.borderPadding(), 0, 100);
const int shapePadding = base::clamp(params.shapePadding(), 0, 100); const int shapePadding = std::clamp(params.shapePadding(), 0, 100);
const int innerPadding = base::clamp(params.innerPadding(), 0, 100); const int innerPadding = std::clamp(params.innerPadding(), 0, 100);
const bool trimSprite = params.trimSprite(); const bool trimSprite = params.trimSprite();
const bool trimCels = params.trim(); const bool trimCels = params.trim();
const bool trimByGrid = params.trimByGrid(); const bool trimByGrid = params.trimByGrid();
@ -667,17 +666,17 @@ private:
int borderPaddingValue() const { int borderPaddingValue() const {
int value = borderPadding()->textInt(); int value = borderPadding()->textInt();
return base::clamp(value, 0, 100); return std::clamp(value, 0, 100);
} }
int shapePaddingValue() const { int shapePaddingValue() const {
int value = shapePadding()->textInt(); int value = shapePadding()->textInt();
return base::clamp(value, 0, 100); return std::clamp(value, 0, 100);
} }
int innerPaddingValue() const { int innerPaddingValue() const {
int value = innerPadding()->textInt(); int value = innerPadding()->textInt();
return base::clamp(value, 0, 100); return std::clamp(value, 0, 100);
} }
bool trimSpriteValue() const { bool trimSpriteValue() const {

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -18,7 +18,6 @@
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "app/ui/editor/editor_customization_delegate.h" #include "app/ui/editor/editor_customization_delegate.h"
#include "app/ui/search_entry.h" #include "app/ui/search_entry.h"
#include "base/clamp.h"
#include "doc/sprite.h" #include "doc/sprite.h"
#include "doc/tag.h" #include "doc/tag.h"
#include "ui/combobox.h" #include "ui/combobox.h"
@ -257,7 +256,7 @@ private:
} }
} }
return base::clamp( return std::clamp(
m_frame-docPref.timeline.firstFrame(), m_frame-docPref.timeline.firstFrame(),
0, editor->sprite()->lastFrame()); 0, editor->sprite()->lastFrame());
} }

View File

@ -267,7 +267,7 @@ private:
ASSERT(m_menuitem->getCommand()); ASSERT(m_menuitem->getCommand());
m_key = m_keys.command( m_key = m_keys.command(
m_menuitem->getCommand()->id().c_str(), m_menuitem->getCommandId().c_str(),
m_menuitem->getParams()); m_menuitem->getParams());
m_menuKeys[m_menuitem] = m_key; m_menuKeys[m_menuitem] = m_key;
@ -1072,7 +1072,7 @@ void KeyboardShortcutsCommand::fillMenusKeys(app::KeyboardShortcuts& keys,
if (menuItem->getCommand()) { if (menuItem->getCommand()) {
menuKeys[menuItem] = menuKeys[menuItem] =
keys.command(menuItem->getCommand()->id().c_str(), keys.command(menuItem->getCommandId().c_str(),
menuItem->getParams()); menuItem->getParams());
} }

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2020 Igara Studio S.A. // Copyright (C) 2020-2022 Igara Studio S.A.
// Copyright (C) 2016-2018 David Capello // Copyright (C) 2016-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -19,7 +19,6 @@
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/tx.h" #include "app/tx.h"
#include "app/ui/timeline/timeline.h" #include "app/ui/timeline/timeline.h"
#include "base/clamp.h"
#include "doc/layer.h" #include "doc/layer.h"
#include "fmt/format.h" #include "fmt/format.h"
@ -51,7 +50,7 @@ LayerOpacityCommand::LayerOpacityCommand()
void LayerOpacityCommand::onLoadParams(const Params& params) void LayerOpacityCommand::onLoadParams(const Params& params)
{ {
m_opacity = params.get_as<int>("opacity"); m_opacity = params.get_as<int>("opacity");
m_opacity = base::clamp(m_opacity, 0, 255); m_opacity = std::clamp(m_opacity, 0, 255);
} }
bool LayerOpacityCommand::onEnabled(Context* context) bool LayerOpacityCommand::onEnabled(Context* context)

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2015-2018 David Capello // Copyright (C) 2015-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -18,7 +18,6 @@
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
#include "app/tx.h" #include "app/tx.h"
#include "base/clamp.h"
#include "base/convert_to.h" #include "base/convert_to.h"
#include "doc/algorithm/modify_selection.h" #include "doc/algorithm/modify_selection.h"
#include "doc/brush_type.h" #include "doc/brush_type.h"
@ -113,7 +112,7 @@ void ModifySelectionCommand::onExecute(Context* context)
return; return;
quantity = window.quantity()->textInt(); quantity = window.quantity()->textInt();
quantity = base::clamp(quantity, 1, 100); quantity = std::clamp(quantity, 1, 100);
brush = (window.circle()->isSelected() ? doc::kCircleBrushType: brush = (window.circle()->isSelected() ? doc::kCircleBrushType:
doc::kSquareBrushType); doc::kSquareBrushType);

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2018-2021 Igara Studio S.A. // Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -26,7 +26,6 @@
#include "app/ui_context.h" #include "app/ui_context.h"
#include "app/util/clipboard.h" #include "app/util/clipboard.h"
#include "app/util/pixel_ratio.h" #include "app/util/pixel_ratio.h"
#include "base/clamp.h"
#include "doc/cel.h" #include "doc/cel.h"
#include "doc/image.h" #include "doc/image.h"
#include "doc/layer.h" #include "doc/layer.h"
@ -127,7 +126,7 @@ void NewFileCommand::onExecute(Context* ctx)
int w = pref.newFile.width(); int w = pref.newFile.width();
int h = pref.newFile.height(); int h = pref.newFile.height();
int bg = pref.newFile.backgroundColor(); int bg = pref.newFile.backgroundColor();
bg = base::clamp(bg, 0, 2); bg = std::clamp(bg, 0, 2);
// If the clipboard contains an image, we can show the size of the // If the clipboard contains an image, we can show the size of the
// clipboard as default image size. // clipboard as default image size.
@ -184,10 +183,10 @@ void NewFileCommand::onExecute(Context* ctx)
static_assert(int(ColorMode::RGB) == 0, "RGB pixel format should be 0"); static_assert(int(ColorMode::RGB) == 0, "RGB pixel format should be 0");
static_assert(int(ColorMode::INDEXED) == 2, "Indexed pixel format should be 2"); static_assert(int(ColorMode::INDEXED) == 2, "Indexed pixel format should be 2");
colorMode = base::clamp(colorMode, ColorMode::RGB, ColorMode::INDEXED); colorMode = std::clamp(colorMode, ColorMode::RGB, ColorMode::INDEXED);
w = base::clamp(w, 1, DOC_SPRITE_MAX_WIDTH); w = std::clamp(w, 1, DOC_SPRITE_MAX_WIDTH);
h = base::clamp(h, 1, DOC_SPRITE_MAX_HEIGHT); h = std::clamp(h, 1, DOC_SPRITE_MAX_HEIGHT);
bg = base::clamp(bg, 0, 2); bg = std::clamp(bg, 0, 2);
// Select the background color // Select the background color
if (bg >= 0 && bg <= 3) { if (bg >= 0 && bg <= 3) {

View File

@ -33,7 +33,6 @@
#include "app/ui/sampling_selector.h" #include "app/ui/sampling_selector.h"
#include "app/ui/separator_in_view.h" #include "app/ui/separator_in_view.h"
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "base/clamp.h"
#include "base/convert_to.h" #include "base/convert_to.h"
#include "base/fs.h" #include "base/fs.h"
#include "base/string.h" #include "base/string.h"
@ -777,7 +776,7 @@ public:
int undo_size_limit_value; int undo_size_limit_value;
undo_size_limit_value = undoSizeLimit()->textInt(); undo_size_limit_value = undoSizeLimit()->textInt();
undo_size_limit_value = base::clamp(undo_size_limit_value, 0, 999999); undo_size_limit_value = std::clamp(undo_size_limit_value, 0, 999999);
m_pref.undo.sizeLimit(undo_size_limit_value); m_pref.undo.sizeLimit(undo_size_limit_value);
m_pref.undo.gotoModified(undoGotoModified()->isSelected()); m_pref.undo.gotoModified(undoGotoModified()->isSelected());

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2021 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -14,7 +14,6 @@
#include "app/commands/params.h" #include "app/commands/params.h"
#include "app/context_access.h" #include "app/context_access.h"
#include "app/tx.h" #include "app/tx.h"
#include "base/clamp.h"
#include "doc/palette.h" #include "doc/palette.h"
#include "doc/sprite.h" #include "doc/sprite.h"
@ -76,7 +75,7 @@ void PaletteSizeCommand::onExecute(Context* context)
if (ncolors == palette.size()) if (ncolors == palette.size())
return; return;
palette.resize(base::clamp(ncolors, 1, std::numeric_limits<int>::max())); palette.resize(std::clamp(ncolors, 1, std::numeric_limits<int>::max()));
ContextWriter writer(reader); ContextWriter writer(reader);
Tx tx(context, "Palette Size", ModifyDocument); Tx tx(context, "Palette Size", ModifyDocument);

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2021 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -21,7 +21,6 @@
#include "app/ui/font_popup.h" #include "app/ui/font_popup.h"
#include "app/ui/timeline/timeline.h" #include "app/ui/timeline/timeline.h"
#include "app/util/freetype_utils.h" #include "app/util/freetype_utils.h"
#include "base/clamp.h"
#include "base/fs.h" #include "base/fs.h"
#include "base/string.h" #include "base/string.h"
#include "doc/image.h" #include "doc/image.h"
@ -80,7 +79,7 @@ public:
int sizeValue() const { int sizeValue() const {
int size = fontSize()->textInt(); int size = fontSize()->textInt();
size = base::clamp(size, 1, 5000); size = std::clamp(size, 1, 5000);
return size; return size;
} }
@ -162,7 +161,7 @@ void PasteTextCommand::onExecute(Context* ctx)
bool antialias = window.antialias()->isSelected(); bool antialias = window.antialias()->isSelected();
std::string faceName = window.faceValue(); std::string faceName = window.faceValue();
int size = window.sizeValue(); int size = window.sizeValue();
size = base::clamp(size, 1, 999); size = std::clamp(size, 1, 999);
pref.textTool.fontFace(faceName); pref.textTool.fontFace(faceName);
pref.textTool.fontSize(size); pref.textTool.fontSize(size);
pref.textTool.antialias(antialias); pref.textTool.antialias(antialias);

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2021 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -21,7 +21,6 @@
#include "app/modules/palettes.h" #include "app/modules/palettes.h"
#include "app/sprite_job.h" #include "app/sprite_job.h"
#include "app/util/resize_image.h" #include "app/util/resize_image.h"
#include "base/clamp.h"
#include "base/convert_to.h" #include "base/convert_to.h"
#include "doc/algorithm/resize_image.h" #include "doc/algorithm/resize_image.h"
#include "doc/cel.h" #include "doc/cel.h"
@ -452,8 +451,8 @@ void SpriteSizeCommand::onExecute(Context* context)
} }
#endif // ENABLE_UI #endif // ENABLE_UI
new_width = base::clamp(new_width, 1, DOC_SPRITE_MAX_WIDTH); new_width = std::clamp(new_width, 1, DOC_SPRITE_MAX_WIDTH);
new_height = base::clamp(new_height, 1, DOC_SPRITE_MAX_HEIGHT); new_height = std::clamp(new_height, 1, DOC_SPRITE_MAX_HEIGHT);
{ {
SpriteSizeJob job(reader, new_width, new_height, resize_method); SpriteSizeJob job(reader, new_width, new_height, resize_method);

View File

@ -18,7 +18,6 @@
#include "app/context.h" #include "app/context.h"
#include "app/script/engine.h" #include "app/script/engine.h"
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "base/clamp.h"
#include "base/convert_to.h" #include "base/convert_to.h"
#include "base/file_content.h" #include "base/file_content.h"
#include "base/fs.h" #include "base/fs.h"

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -21,7 +21,6 @@
#include "app/ini_file.h" #include "app/ini_file.h"
#include "app/load_widget.h" #include "app/load_widget.h"
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
#include "base/clamp.h"
#include "doc/mask.h" #include "doc/mask.h"
#include "doc/sprite.h" #include "doc/sprite.h"
#include "filters/median_filter.h" #include "filters/median_filter.h"
@ -78,8 +77,8 @@ private:
m_heightEntry->textInt()); m_heightEntry->textInt());
// Avoid negative numbers // Avoid negative numbers
newSize.w = base::clamp(newSize.w, 1, 100); newSize.w = std::clamp(newSize.w, 1, 100);
newSize.h = base::clamp(newSize.h, 1, 100); newSize.h = std::clamp(newSize.h, 1, 100);
// If we had a previous filter preview running in the background, // If we had a previous filter preview running in the background,
// we explicitly request it be stopped. Otherwise, changing the // we explicitly request it be stopped. Otherwise, changing the

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2021 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -11,7 +11,6 @@
#include "app/commands/filters/color_curve_editor.h" #include "app/commands/filters/color_curve_editor.h"
#include "base/clamp.h"
#include "filters/color_curve.h" #include "filters/color_curve.h"
#include "ui/alert.h" #include "ui/alert.h"
#include "ui/entry.h" #include "ui/entry.h"
@ -140,8 +139,8 @@ bool ColorCurveEditor::onProcessMessage(Message* msg)
if (m_editPoint) { if (m_editPoint) {
gfx::Point mousePos = static_cast<MouseMessage*>(msg)->position(); gfx::Point mousePos = static_cast<MouseMessage*>(msg)->position();
*m_editPoint = screenToView(mousePos); *m_editPoint = screenToView(mousePos);
m_editPoint->x = base::clamp(m_editPoint->x, m_viewBounds.x, m_viewBounds.x2()-1); m_editPoint->x = std::clamp(m_editPoint->x, m_viewBounds.x, m_viewBounds.x2()-1);
m_editPoint->y = base::clamp(m_editPoint->y, m_viewBounds.y, m_viewBounds.y2()-1); m_editPoint->y = std::clamp(m_editPoint->y, m_viewBounds.y, m_viewBounds.y2()-1);
// TODO this should be optional // TODO this should be optional
CurveEditorChange(); CurveEditorChange();
@ -209,9 +208,9 @@ void ColorCurveEditor::onPaint(ui::PaintEvent& ev)
// Draw curve // Draw curve
for (c = client.x; c < client.x+client.w; ++c) { for (c = client.x; c < client.x+client.w; ++c) {
pt = clientToView(gfx::Point(c, 0)); pt = clientToView(gfx::Point(c, 0));
pt.x = base::clamp(pt.x, m_viewBounds.x, m_viewBounds.x2()-1); pt.x = std::clamp(pt.x, m_viewBounds.x, m_viewBounds.x2()-1);
pt.y = values[pt.x - m_viewBounds.x]; pt.y = values[pt.x - m_viewBounds.x];
pt.y = base::clamp(pt.y, m_viewBounds.y, m_viewBounds.y2()-1); pt.y = std::clamp(pt.y, m_viewBounds.y, m_viewBounds.y2()-1);
pt = viewToClient(pt); pt = viewToClient(pt);
g->putPixel(gfx::rgba(255, 255, 255), c, pt.y); g->putPixel(gfx::rgba(255, 255, 255), c, pt.y);
@ -270,8 +269,8 @@ bool ColorCurveEditor::editNodeManually(gfx::Point& viewPt)
if (window.closer() == window.ok()) { if (window.closer() == window.ok()) {
viewPt.x = window.x()->textInt(); viewPt.x = window.x()->textInt();
viewPt.y = window.y()->textInt(); viewPt.y = window.y()->textInt();
viewPt.x = base::clamp(viewPt.x, 0, 255); viewPt.x = std::clamp(viewPt.x, 0, 255);
viewPt.y = base::clamp(viewPt.y, 0, 255); viewPt.y = std::clamp(viewPt.y, 0, 255);
return true; return true;
} }
else if (window.closer() == window.deleteButton()) { else if (window.closer() == window.deleteButton()) {

View File

@ -15,7 +15,6 @@
#include "app/crash/doc_format.h" #include "app/crash/doc_format.h"
#include "app/crash/internals.h" #include "app/crash/internals.h"
#include "app/doc.h" #include "app/doc.h"
#include "base/clamp.h"
#include "base/convert_to.h" #include "base/convert_to.h"
#include "base/exception.h" #include "base/exception.h"
#include "base/fs.h" #include "base/fs.h"
@ -628,8 +627,8 @@ Doc* read_document_with_raw_images(const std::string& dir,
info.height = 256; info.height = 256;
info.filename = "Unknown"; info.filename = "Unknown";
} }
info.width = base::clamp(info.width, 1, 99999); info.width = std::clamp(info.width, 1, 99999);
info.height = base::clamp(info.height, 1, 99999); info.height = std::clamp(info.height, 1, 99999);
Sprite* spr = new Sprite(ImageSpec(info.mode, info.width, info.height), 256); Sprite* spr = new Sprite(ImageSpec(info.mode, info.width, info.height), 256);
// Load each image as a new frame // Load each image as a new frame

View File

@ -20,7 +20,6 @@
#include "app/restore_visible_layers.h" #include "app/restore_visible_layers.h"
#include "app/snap_to_grid.h" #include "app/snap_to_grid.h"
#include "app/util/autocrop.h" #include "app/util/autocrop.h"
#include "base/clamp.h"
#include "base/convert_to.h" #include "base/convert_to.h"
#include "base/fs.h" #include "base/fs.h"
#include "base/fstream_path.h" #include "base/fstream_path.h"
@ -127,7 +126,7 @@ int DocExporter::Item::frames() const
return selFrames->size(); return selFrames->size();
else if (tag) { else if (tag) {
int result = tag->toFrame() - tag->fromFrame() + 1; int result = tag->toFrame() - tag->fromFrame() + 1;
return base::clamp(result, 1, doc->sprite()->totalFrames()); return std::clamp(result, 1, doc->sprite()->totalFrames());
} }
else else
return doc->sprite()->totalFrames(); return doc->sprite()->totalFrames();
@ -140,8 +139,8 @@ doc::SelectedFrames DocExporter::Item::getSelectedFrames() const
doc::SelectedFrames frames; doc::SelectedFrames frames;
if (tag) { if (tag) {
frames.insert(base::clamp(tag->fromFrame(), 0, doc->sprite()->lastFrame()), frames.insert(std::clamp(tag->fromFrame(), 0, doc->sprite()->lastFrame()),
base::clamp(tag->toFrame(), 0, doc->sprite()->lastFrame())); std::clamp(tag->toFrame(), 0, doc->sprite()->lastFrame()));
} }
else { else {
frames.insert(0, doc->sprite()->lastFrame()); frames.insert(0, doc->sprite()->lastFrame());

View File

@ -332,14 +332,12 @@ bool Extension::canBeUninstalled() const
void Extension::enable(const bool state) void Extension::enable(const bool state)
{ {
// Do nothing if (m_isEnabled != state) {
if (m_isEnabled == state) set_config_bool("extensions", m_name.c_str(), state);
return; flush_config_file();
set_config_bool("extensions", m_name.c_str(), state); m_isEnabled = state;
flush_config_file(); }
m_isEnabled = state;
#ifdef ENABLE_SCRIPTING #ifdef ENABLE_SCRIPTING
if (hasScripts()) { if (hasScripts()) {
@ -365,6 +363,9 @@ void Extension::uninstall(const DeletePluginPref delPref)
TRACE("EXT: Uninstall extension '%s' from '%s'...\n", TRACE("EXT: Uninstall extension '%s' from '%s'...\n",
m_name.c_str(), m_path.c_str()); m_name.c_str(), m_path.c_str());
// Execute exit actions of scripts
executeExitActions();
// Remove all files inside the extension path // Remove all files inside the extension path
uninstallFiles(m_path, delPref); uninstallFiles(m_path, delPref);
ASSERT(!base::is_directory(m_path) || delPref == DeletePluginPref::kNo); ASSERT(!base::is_directory(m_path) || delPref == DeletePluginPref::kNo);

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -16,7 +16,6 @@
#include "app/file/format_options.h" #include "app/file/format_options.h"
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
#include "base/cfile.h" #include "base/cfile.h"
#include "base/clamp.h"
#include "base/exception.h" #include "base/exception.h"
#include "base/file_handle.h" #include "base/file_handle.h"
#include "base/fs.h" #include "base/fs.h"
@ -1103,8 +1102,8 @@ static void ase_file_write_tags_chunk(FILE* f,
tag->toFrame() < fromFrame) tag->toFrame() < fromFrame)
continue; continue;
frame_t from = base::clamp(tag->fromFrame()-fromFrame, 0, toFrame-fromFrame); frame_t from = std::clamp(tag->fromFrame()-fromFrame, 0, toFrame-fromFrame);
frame_t to = base::clamp(tag->toFrame()-fromFrame, from, toFrame-fromFrame); frame_t to = std::clamp(tag->toFrame()-fromFrame, from, toFrame-fromFrame);
fputw(from, f); fputw(from, f);
fputw(to, f); fputw(to, f);

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2018-2021 Igara Studio S.A. // Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -19,7 +19,6 @@
#include "app/find_widget.h" #include "app/find_widget.h"
#include "app/load_widget.h" #include "app/load_widget.h"
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
#include "base/clamp.h"
#include "base/file_handle.h" #include "base/file_handle.h"
#include "base/memory.h" #include "base/memory.h"
#include "doc/doc.h" #include "doc/doc.h"
@ -358,7 +357,7 @@ bool JpegFormat::onSave(FileOp* fop)
JDIMENSION buffer_height; JDIMENSION buffer_height;
const auto jpeg_options = std::static_pointer_cast<JpegOptions>(fop->formatOptions()); const auto jpeg_options = std::static_pointer_cast<JpegOptions>(fop->formatOptions());
const int qualityValue = const int qualityValue =
(jpeg_options ? (int)base::clamp(100.0f * jpeg_options->quality, 0.f, 100.f): (jpeg_options ? (int)std::clamp(100.0f * jpeg_options->quality, 0.f, 100.f):
100); 100);
int c; int c;

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2018-2021 Igara Studio S.A. // Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -14,7 +14,6 @@
#include "app/file/file.h" #include "app/file/file.h"
#include "app/file/file_format.h" #include "app/file/file_format.h"
#include "app/file/file_formats_manager.h" #include "app/file/file_formats_manager.h"
#include "base/clamp.h"
#include "base/fs.h" #include "base/fs.h"
#include "base/string.h" #include "base/string.h"
#include "dio/detect_format.h" #include "dio/detect_format.h"
@ -151,7 +150,7 @@ bool save_palette(const char* filename, const Palette* pal, int columns,
if (!ff || !ff->support(FILE_SUPPORT_SAVE)) if (!ff || !ff->support(FILE_SUPPORT_SAVE))
break; break;
int w = (columns > 0 ? base::clamp(columns, 0, pal->size()): pal->size()); int w = (columns > 0 ? std::clamp(columns, 0, pal->size()): pal->size());
int h = (pal->size() / w) + (pal->size() % w > 0 ? 1: 0); int h = (pal->size() / w) + (pal->size() % w > 0 ? 1: 0);
Context tmpContext; Context tmpContext;

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -16,7 +16,6 @@
#include "app/file/format_options.h" #include "app/file/format_options.h"
#include "app/file/png_format.h" #include "app/file/png_format.h"
#include "app/file/png_options.h" #include "app/file/png_options.h"
#include "base/clamp.h"
#include "base/file_handle.h" #include "base/file_handle.h"
#include "doc/doc.h" #include "doc/doc.h"
#include "gfx/color_space.h" #include "gfx/color_space.h"
@ -614,7 +613,7 @@ bool PngFormat::onSave(FileOp* fop)
if (color_type == PNG_COLOR_TYPE_PALETTE) { if (color_type == PNG_COLOR_TYPE_PALETTE) {
int c, r, g, b; int c, r, g, b;
int pal_size = fop->sequenceGetNColors(); int pal_size = fop->sequenceGetNColors();
pal_size = base::clamp(pal_size, 1, PNG_MAX_PALETTE_LENGTH); pal_size = std::clamp(pal_size, 1, PNG_MAX_PALETTE_LENGTH);
#if PNG_MAX_PALETTE_LENGTH != 256 #if PNG_MAX_PALETTE_LENGTH != 256
#error PNG_MAX_PALETTE_LENGTH should be 256 #error PNG_MAX_PALETTE_LENGTH should be 256

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (c) 2018-2020 Igara Studio S.A. // Copyright (c) 2018-2022 Igara Studio S.A.
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -17,7 +17,6 @@
#include "app/file/format_options.h" #include "app/file/format_options.h"
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
#include "base/cfile.h" #include "base/cfile.h"
#include "base/clamp.h"
#include "base/file_handle.h" #include "base/file_handle.h"
#include "doc/doc.h" #include "doc/doc.h"
#include "ui/window.h" #include "ui/window.h"
@ -85,7 +84,7 @@ bool SvgFormat::onSave(FileOp* fop)
const Image* image = fop->sequenceImage(); const Image* image = fop->sequenceImage();
int x, y, c, r, g, b, a, alpha; int x, y, c, r, g, b, a, alpha;
const auto svg_options = std::static_pointer_cast<SvgOptions>(fop->formatOptions()); const auto svg_options = std::static_pointer_cast<SvgOptions>(fop->formatOptions());
const int pixelScaleValue = base::clamp(svg_options->pixelScale, 0, 10000); const int pixelScaleValue = std::clamp(svg_options->pixelScale, 0, 10000);
FileHandle handle(open_file_with_exception_sync_on_close(fop->filename(), "wb")); FileHandle handle(open_file_with_exception_sync_on_close(fop->filename(), "wb"));
FILE* f = handle.get(); FILE* f = handle.get();
auto printcol = [f](int x, int y,int r, int g, int b, int a, int pxScale) { auto printcol = [f](int x, int y,int r, int g, int b, int a, int pxScale) {

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2015-2018 David Capello // Copyright (C) 2015-2018 David Capello
// Copyright (C) 2015 Gabriel Rauter // Copyright (C) 2015 Gabriel Rauter
// //
@ -20,7 +20,6 @@
#include "app/file/webp_options.h" #include "app/file/webp_options.h"
#include "app/ini_file.h" #include "app/ini_file.h"
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
#include "base/clamp.h"
#include "base/convert_to.h" #include "base/convert_to.h"
#include "base/file_handle.h" #include "base/file_handle.h"
#include "doc/doc.h" #include "doc/doc.h"
@ -243,7 +242,7 @@ static int progress_report(int percent, const WebPPicture* pic)
double newProgress = (double(wd->f) + double(percent)/100.0) / double(wd->n); double newProgress = (double(wd->f) + double(percent)/100.0) / double(wd->n);
wd->progress = std::max(wd->progress, newProgress); wd->progress = std::max(wd->progress, newProgress);
wd->progress = base::clamp(wd->progress, 0.0, 1.0); wd->progress = std::clamp(wd->progress, 0.0, 1.0);
fop->setProgress(wd->progress); fop->setProgress(wd->progress);
if (fop->isStop()) if (fop->isStop())

View File

@ -18,13 +18,20 @@
namespace app { namespace app {
static std::unique_ptr<GuiXml> g_singleton;
// static // static
GuiXml* GuiXml::instance() GuiXml* GuiXml::instance()
{ {
static GuiXml* singleton = 0; if (!g_singleton)
if (!singleton) g_singleton = std::make_unique<GuiXml>();
singleton = new GuiXml(); return g_singleton.get();
return singleton; }
// static
void GuiXml::destroyInstance()
{
g_singleton.reset();
} }
GuiXml::GuiXml() GuiXml::GuiXml()

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2020 Igara Studio S.A. // Copyright (C) 2020-2022 Igara Studio S.A.
// Copyright (C) 2001-2015 David Capello // Copyright (C) 2001-2015 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -11,6 +11,7 @@
#include "app/xml_document.h" #include "app/xml_document.h"
#include <memory>
#include <string> #include <string>
namespace app { namespace app {
@ -22,6 +23,9 @@ namespace app {
// gui.xml file will be loaded by the first time, which could // gui.xml file will be loaded by the first time, which could
// generated an exception if there are errors in the XML file. // generated an exception if there are errors in the XML file.
static GuiXml* instance(); static GuiXml* instance();
static void destroyInstance();
GuiXml();
// Returns the tinyxml document instance. // Returns the tinyxml document instance.
XmlDocumentRef doc() { XmlDocumentRef doc() {
@ -34,9 +38,8 @@ namespace app {
} }
private: private:
GuiXml();
XmlDocumentRef m_doc; XmlDocumentRef m_doc;
friend class std::unique_ptr<GuiXml>;
}; };
} // namespace app } // namespace app

View File

@ -37,7 +37,6 @@
#include "app/ui/toolbar.h" #include "app/ui/toolbar.h"
#include "app/ui_context.h" #include "app/ui_context.h"
#include "app/util/open_batch.h" #include "app/util/open_batch.h"
#include "base/clamp.h"
#include "base/fs.h" #include "base/fs.h"
#include "base/memory.h" #include "base/memory.h"
#include "base/string.h" #include "base/string.h"
@ -132,7 +131,7 @@ static bool create_main_window(bool gpuAccel,
try { try {
if (!spec.frame().isEmpty() || if (!spec.frame().isEmpty() ||
!spec.contentRect().isEmpty()) { !spec.contentRect().isEmpty()) {
spec.scale(scale == 0 ? 2: base::clamp(scale, 1, 4)); spec.scale(scale == 0 ? 2: std::clamp(scale, 1, 4));
main_window = os::instance()->makeWindow(spec); main_window = os::instance()->makeWindow(spec);
} }
} }
@ -418,16 +417,16 @@ void load_window_pos(Window* window, const char* section,
Rect pos = get_config_rect(section, "WindowPos", origPos); Rect pos = get_config_rect(section, "WindowPos", origPos);
if (limitMinSize) { if (limitMinSize) {
pos.w = base::clamp(pos.w, origPos.w, workarea.w); pos.w = std::clamp(pos.w, origPos.w, workarea.w);
pos.h = base::clamp(pos.h, origPos.h, workarea.h); pos.h = std::clamp(pos.h, origPos.h, workarea.h);
} }
else { else {
pos.w = std::min(pos.w, workarea.w); pos.w = std::min(pos.w, workarea.w);
pos.h = std::min(pos.h, workarea.h); pos.h = std::min(pos.h, workarea.h);
} }
pos.setOrigin(Point(base::clamp(pos.x, workarea.x, workarea.x2()-pos.w), pos.setOrigin(Point(std::clamp(pos.x, workarea.x, workarea.x2()-pos.w),
base::clamp(pos.y, workarea.y, workarea.y2()-pos.h))); std::clamp(pos.y, workarea.y, workarea.y2()-pos.h)));
window->setBounds(pos); window->setBounds(pos);

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2018-2021 Igara Studio S.A. // Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2015-2018 David Capello // Copyright (C) 2015-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -38,7 +38,6 @@
#include "app/ui/editor/tool_loop_impl.h" #include "app/ui/editor/tool_loop_impl.h"
#include "app/ui/timeline/timeline.h" #include "app/ui/timeline/timeline.h"
#include "app/ui_context.h" #include "app/ui_context.h"
#include "base/clamp.h"
#include "base/fs.h" #include "base/fs.h"
#include "base/replace_string.h" #include "base/replace_string.h"
#include "base/version.h" #include "base/version.h"
@ -371,14 +370,14 @@ int App_useTool(lua_State* L)
type = lua_getfield(L, 1, "opacity"); type = lua_getfield(L, 1, "opacity");
if (type != LUA_TNIL) { if (type != LUA_TNIL) {
params.opacity = lua_tointeger(L, -1); params.opacity = lua_tointeger(L, -1);
params.opacity = base::clamp(params.opacity, 0, 255); params.opacity = std::clamp(params.opacity, 0, 255);
} }
lua_pop(L, 1); lua_pop(L, 1);
type = lua_getfield(L, 1, "tolerance"); type = lua_getfield(L, 1, "tolerance");
if (type != LUA_TNIL) { if (type != LUA_TNIL) {
params.tolerance = lua_tointeger(L, -1); params.tolerance = lua_tointeger(L, -1);
params.tolerance = base::clamp(params.tolerance, 0, 255); params.tolerance = std::clamp(params.tolerance, 0, 255);
} }
lua_pop(L, 1); lua_pop(L, 1);

View File

@ -369,6 +369,19 @@ void push_app_events(lua_State* L)
void push_sprite_events(lua_State* L, Sprite* sprite) void push_sprite_events(lua_State* L, Sprite* sprite)
{ {
// Clear the g_spriteEvents map on Exit() signal because if the dtor
// is called in the normal C++ order destruction sequence by
// compilation units, it could crash because each ~SpriteEvents()
// needs the doc::get() function, which uses the "objects"
// collection from "src/doc/objects.cpp" (so we cannot garantize
// that that "objects" collection will be destroyed after
// "g_spriteEvents")
static bool atExit = false;
if (!atExit) {
atExit = true;
App::instance()->Exit.connect([]{ g_spriteEvents.clear(); });
}
ASSERT(sprite); ASSERT(sprite);
SpriteEvents* spriteEvents; SpriteEvents* spriteEvents;

View File

@ -19,7 +19,6 @@
#include "app/script/luacpp.h" #include "app/script/luacpp.h"
#include "app/script/userdata.h" #include "app/script/userdata.h"
#include "app/tx.h" #include "app/tx.h"
#include "base/clamp.h"
#include "doc/layer.h" #include "doc/layer.h"
#include "doc/layer_tilemap.h" #include "doc/layer_tilemap.h"
#include "doc/sprite.h" #include "doc/sprite.h"
@ -290,7 +289,7 @@ int Layer_set_stackIndex(lua_State* L)
} }
if (newStackIndex-1 < int(parent->layers().size())) { if (newStackIndex-1 < int(parent->layers().size())) {
beforeThis = parent->layers()[base::clamp(newStackIndex-1, 0, (int)parent->layers().size())]; beforeThis = parent->layers()[std::clamp(newStackIndex-1, 0, (int)parent->layers().size())];
} }
else { else {
beforeThis = nullptr; beforeThis = nullptr;

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2020 Igara Studio S.A. // Copyright (C) 2020-2022 Igara Studio S.A.
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -167,7 +167,7 @@ int Plugin_newCommand(lua_State* L)
if (!group.empty() && if (!group.empty() &&
App::instance()->isGui()) { // On CLI menus do not make sense App::instance()->isGui()) { // On CLI menus do not make sense
if (auto appMenus = AppMenus::instance()) { if (auto appMenus = AppMenus::instance()) {
std::unique_ptr<MenuItem> menuItem(new AppMenuItem(title, cmd)); std::unique_ptr<MenuItem> menuItem(new AppMenuItem(title, id));
appMenus->addMenuItemIntoGroup(group, std::move(menuItem)); appMenus->addMenuItemIntoGroup(group, std::move(menuItem));
} }
} }

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2021 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -12,7 +12,6 @@
#include "app/site.h" #include "app/site.h"
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
#include "base/clamp.h"
#include "doc/cel.h" #include "doc/cel.h"
#include "doc/grid.h" #include "doc/grid.h"
#include "doc/layer.h" #include "doc/layer.h"
@ -52,7 +51,7 @@ Image* Site::image(int* x, int* y, int* opacity) const
image = cel->image(); image = cel->image();
if (x) *x = cel->x(); if (x) *x = cel->x();
if (y) *y = cel->y(); if (y) *y = cel->y();
if (opacity) *opacity = base::clamp(cel->opacity(), 0, 255); if (opacity) *opacity = std::clamp(cel->opacity(), 0, 255);
} }
} }

View File

@ -17,7 +17,6 @@
#include "app/file/file.h" #include "app/file/file.h"
#include "app/file_system.h" #include "app/file_system.h"
#include "app/util/conversion_to_surface.h" #include "app/util/conversion_to_surface.h"
#include "base/clamp.h"
#include "base/thread.h" #include "base/thread.h"
#include "doc/algorithm/rotate.h" #include "doc/algorithm/rotate.h"
#include "doc/image.h" #include "doc/image.h"
@ -126,8 +125,8 @@ private:
thumb_w = w; thumb_w = w;
thumb_h = h; thumb_h = h;
} }
thumb_w = base::clamp(thumb_w, 1, MAX_THUMBNAIL_SIZE); thumb_w = std::clamp(thumb_w, 1, MAX_THUMBNAIL_SIZE);
thumb_h = base::clamp(thumb_h, 1, MAX_THUMBNAIL_SIZE); thumb_h = std::clamp(thumb_h, 1, MAX_THUMBNAIL_SIZE);
// Stretch the 'image' // Stretch the 'image'
thumbnailImage.reset( thumbnailImage.reset(

View File

@ -8,7 +8,6 @@
#include "app/color_utils.h" #include "app/color_utils.h"
#include "app/util/wrap_point.h" #include "app/util/wrap_point.h"
#include "app/util/wrap_value.h" #include "app/util/wrap_value.h"
#include "base/clamp.h"
#include "doc/blend_funcs.h" #include "doc/blend_funcs.h"
#include "doc/blend_internals.h" #include "doc/blend_internals.h"
#include "doc/image_impl.h" #include "doc/image_impl.h"
@ -676,8 +675,8 @@ private:
m_srcImageHeight), m_srcImageHeight),
pt, false); pt, false);
pt.x = base::clamp(pt.x, 0, m_srcImageWidth-1); pt.x = std::clamp(pt.x, 0, m_srcImageWidth-1);
pt.y = base::clamp(pt.y, 0, m_srcImageHeight-1); pt.y = std::clamp(pt.y, 0, m_srcImageHeight-1);
m_color = get_pixel(m_srcImage, pt.x, pt.y); m_color = get_pixel(m_srcImage, pt.x, pt.y);
} }

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2020-2021 Igara Studio S.A. // Copyright (C) 2020-2022 Igara Studio S.A.
// Copyright (C) 2001-2015 David Capello // Copyright (C) 2001-2015 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -14,11 +14,12 @@
#include "app/tools/ink.h" #include "app/tools/ink.h"
#include "app/tools/tool_loop.h" #include "app/tools/tool_loop.h"
#include "app/util/wrap_value.h" #include "app/util/wrap_value.h"
#include "base/clamp.h"
#include "doc/brush.h" #include "doc/brush.h"
#include "doc/image.h" #include "doc/image.h"
#include "doc/sprite.h" #include "doc/sprite.h"
#include <algorithm>
namespace app { namespace app {
namespace tools { namespace tools {
@ -84,8 +85,8 @@ void PointShape::doInkHline(int x1, int y, int x2, ToolLoop* loop)
if (x2 < 0 || x1 >= dstw || x2-x1+1 < 1) if (x2 < 0 || x1 >= dstw || x2-x1+1 < 1)
return; return;
x1 = base::clamp(x1, 0, dstw-1); x1 = std::clamp(x1, 0, dstw-1);
x2 = base::clamp(x2, 0, dstw-1); x2 = std::clamp(x2, 0, dstw-1);
ink->inkHline(x1, y, x2, loop); ink->inkHline(x1, y, x2, loop);
} }
} }

View File

@ -158,8 +158,8 @@ public:
} }
// Dynamic size and angle // Dynamic size and angle
int size = base::clamp(int(pt.size), int(Brush::kMinBrushSize), int(Brush::kMaxBrushSize)); int size = std::clamp(int(pt.size), int(Brush::kMinBrushSize), int(Brush::kMaxBrushSize));
int angle = base::clamp(int(pt.angle), -180, 180); int angle = std::clamp(int(pt.angle), -180, 180);
if ((brush->size() != size) || if ((brush->size() != size) ||
(brush->angle() != angle && m_origBrushType != kCircleBrushType) || (brush->angle() != angle && m_origBrushType != kCircleBrushType) ||
(m_hasDynamicGradient && pt.gradient != m_lastGradientValue)) { (m_hasDynamicGradient && pt.gradient != m_lastGradientValue)) {

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2021 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -20,7 +20,6 @@
#include "app/tools/symmetry.h" #include "app/tools/symmetry.h"
#include "app/tools/tool_loop.h" #include "app/tools/tool_loop.h"
#include "app/tools/velocity.h" #include "app/tools/velocity.h"
#include "base/clamp.h"
#include "doc/brush.h" #include "doc/brush.h"
#include "doc/image.h" #include "doc/image.h"
#include "doc/primitives.h" #include "doc/primitives.h"
@ -29,6 +28,7 @@
#include "gfx/rect_io.h" #include "gfx/rect_io.h"
#include "gfx/region.h" #include "gfx/region.h"
#include <algorithm>
#include <climits> #include <climits>
#include <cmath> #include <cmath>
@ -410,11 +410,11 @@ void ToolLoopManager::adjustPointWithDynamics(const Pointer& pointer,
} }
} }
ASSERT(p >= 0.0f && p <= 1.0f); ASSERT(p >= 0.0f && p <= 1.0f);
p = base::clamp(p, 0.0f, 1.0f); p = std::clamp(p, 0.0f, 1.0f);
// Velocity // Velocity
float v = pointer.velocity().magnitude() / VelocitySensor::kScreenPixelsForFullVelocity; float v = pointer.velocity().magnitude() / VelocitySensor::kScreenPixelsForFullVelocity;
v = base::clamp(v, 0.0f, 1.0f); v = std::clamp(v, 0.0f, 1.0f);
if (v < m_dynamics.minVelocityThreshold) { if (v < m_dynamics.minVelocityThreshold) {
v = 0.0f; v = 0.0f;
} }
@ -429,7 +429,7 @@ void ToolLoopManager::adjustPointWithDynamics(const Pointer& pointer,
(m_dynamics.maxVelocityThreshold - m_dynamics.minVelocityThreshold); (m_dynamics.maxVelocityThreshold - m_dynamics.minVelocityThreshold);
} }
ASSERT(v >= 0.0f && v <= 1.0f); ASSERT(v >= 0.0f && v <= 1.0f);
v = base::clamp(v, 0.0f, 1.0f); v = std::clamp(v, 0.0f, 1.0f);
switch (m_dynamics.size) { switch (m_dynamics.size) {
case DynamicSensor::Pressure: case DynamicSensor::Pressure:
@ -458,8 +458,8 @@ void ToolLoopManager::adjustPointWithDynamics(const Pointer& pointer,
break; break;
} }
pt.size = base::clamp(size, int(Brush::kMinBrushSize), int(Brush::kMaxBrushSize)); pt.size = std::clamp(size, int(Brush::kMinBrushSize), int(Brush::kMaxBrushSize));
pt.angle = base::clamp(angle, -180, 180); pt.angle = std::clamp(angle, -180, 180);
} }
} // namespace tools } // namespace tools

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2020-2021 Igara Studio S.A. // Copyright (C) 2020-2022 Igara Studio S.A.
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -10,7 +10,7 @@
#include "app/tools/velocity.h" #include "app/tools/velocity.h"
#include "base/clamp.h" #include <algorithm>
namespace app { namespace app {
namespace tools { namespace tools {
@ -39,7 +39,7 @@ void VelocitySensor::updateWithDisplayPoint(const gfx::Point& screenPoint)
else { else {
gfx::PointF newVelocity(screenPoint - m_lastPoint); gfx::PointF newVelocity(screenPoint - m_lastPoint);
const float a = base::clamp(float(dt) / kFullUpdateMSecs, 0.0f, 1.0f); const float a = std::clamp(float(dt) / kFullUpdateMSecs, 0.0f, 1.0f);
m_velocity.x = (1.0f-a)*m_velocity.x + a*newVelocity.x; m_velocity.x = (1.0f-a)*m_velocity.x + a*newVelocity.x;
m_velocity.y = (1.0f-a)*m_velocity.y + a*newVelocity.y; m_velocity.y = (1.0f-a)*m_velocity.y + a*newVelocity.y;
} }

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2021 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2017 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -13,6 +13,7 @@
#include "app/app_menus.h" #include "app/app_menus.h"
#include "app/commands/command.h" #include "app/commands/command.h"
#include "app/commands/commands.h"
#include "app/commands/params.h" #include "app/commands/params.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/ui/keyboard_shortcuts.h" #include "app/ui/keyboard_shortcuts.h"
@ -35,17 +36,25 @@ using namespace ui;
Params AppMenuItem::s_contextParams; Params AppMenuItem::s_contextParams;
AppMenuItem::AppMenuItem(const std::string& text, AppMenuItem::AppMenuItem(const std::string& text,
Command* command, const std::string& commandId,
const Params& params) const Params& params)
: MenuItem(text) : MenuItem(text)
, m_key(nullptr) , m_key(nullptr)
, m_command(command) , m_commandId(commandId)
, m_params(params) , m_params(params)
, m_isRecentFileItem(false) , m_isRecentFileItem(false)
, m_native(nullptr) , m_native(nullptr)
{ {
} }
Command* AppMenuItem::getCommand() const
{
if (!m_commandId.empty())
return Commands::instance()->byId(m_commandId.c_str());
else
return nullptr;
}
void AppMenuItem::setKey(const KeyPtr& key) void AppMenuItem::setKey(const KeyPtr& key)
{ {
m_key = key; m_key = key;
@ -126,18 +135,22 @@ void AppMenuItem::onClick()
{ {
MenuItem::onClick(); MenuItem::onClick();
if (m_command) { if (!m_commandId.empty()) {
Params params = m_params; Params params = m_params;
if (!s_contextParams.empty()) if (!s_contextParams.empty())
params |= s_contextParams; params |= s_contextParams;
// Load parameters to call Command::isEnabled, so we can check if // Load parameters to call Command::isEnabled, so we can check if
// the command is enabled with this parameters. // the command is enabled with this parameters.
m_command->loadParams(params); if (auto command = getCommand()) {
command->loadParams(params);
UIContext* context = UIContext::instance(); UIContext* context = UIContext::instance();
if (m_command->isEnabled(context)) { if (command->isEnabled(context))
context->executeCommandFromMenuOrShortcut(m_command, params); context->executeCommandFromMenuOrShortcut(command, params);
// TODO At this point, the "this" pointer might be deleted if
// the command reloaded the App main menu
} }
} }
} }
@ -150,15 +163,15 @@ void AppMenuItem::onValidate()
Context* context = UIContext::instance(); Context* context = UIContext::instance();
context->updateFlags(); context->updateFlags();
if (m_command) { if (auto command = getCommand()) {
Params params = m_params; Params params = m_params;
if (!s_contextParams.empty()) if (!s_contextParams.empty())
params |= s_contextParams; params |= s_contextParams;
m_command->loadParams(params); command->loadParams(params);
setEnabled(m_command->isEnabled(context)); setEnabled(command->isEnabled(context));
setSelected(m_command->isChecked(context)); setSelected(command->isChecked(context));
} }
} }

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2020 Igara Studio S.A. // Copyright (C) 2020-2022 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2017 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -18,7 +18,6 @@
#include <memory> #include <memory>
namespace app { namespace app {
class Command;
// A widget that represent a menu item of the application. // A widget that represent a menu item of the application.
// //
@ -34,7 +33,7 @@ namespace app {
}; };
AppMenuItem(const std::string& text, AppMenuItem(const std::string& text,
Command* command = nullptr, const std::string& commandId = std::string(),
const Params& params = Params()); const Params& params = Params());
KeyPtr key() { return m_key; } KeyPtr key() { return m_key; }
@ -43,7 +42,8 @@ namespace app {
void setIsRecentFileItem(bool state) { m_isRecentFileItem = state; } void setIsRecentFileItem(bool state) { m_isRecentFileItem = state; }
bool isRecentFileItem() const { return m_isRecentFileItem; } bool isRecentFileItem() const { return m_isRecentFileItem; }
Command* getCommand() { return m_command; } std::string getCommandId() const { return m_commandId; }
Command* getCommand() const;
const Params& getParams() const { return m_params; } const Params& getParams() const { return m_params; }
Native* native() const { return m_native.get(); } Native* native() const { return m_native.get(); }
@ -61,7 +61,7 @@ namespace app {
private: private:
KeyPtr m_key; KeyPtr m_key;
Command* m_command; std::string m_commandId;
Params m_params; Params m_params;
bool m_isRecentFileItem; bool m_isRecentFileItem;
std::unique_ptr<Native> m_native; std::unique_ptr<Native> m_native;

View File

@ -55,7 +55,6 @@
#include "app/ui_context.h" #include "app/ui_context.h"
#include "app/util/cel_ops.h" #include "app/util/cel_ops.h"
#include "app/util/clipboard.h" #include "app/util/clipboard.h"
#include "base/clamp.h"
#include "base/scoped_value.h" #include "base/scoped_value.h"
#include "doc/cel.h" #include "doc/cel.h"
#include "doc/cels_range.h" #include "doc/cels_range.h"
@ -1890,7 +1889,7 @@ void ColorBar::fixColorIndex(ColorButton& colorButton)
if (color.getType() == Color::IndexType) { if (color.getType() == Color::IndexType) {
int oldIndex = color.getIndex(); int oldIndex = color.getIndex();
int newIndex = base::clamp(oldIndex, 0, get_current_palette()->size()-1); int newIndex = std::clamp(oldIndex, 0, get_current_palette()->size()-1);
if (oldIndex != newIndex) { if (oldIndex != newIndex) {
color = Color::fromIndex(newIndex); color = Color::fromIndex(newIndex);
colorButton.setColor(color); colorButton.setColor(color);

View File

@ -23,7 +23,6 @@
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "app/ui/status_bar.h" #include "app/ui/status_bar.h"
#include "app/ui_context.h" #include "app/ui_context.h"
#include "base/clamp.h"
#include "doc/layer.h" #include "doc/layer.h"
#include "doc/sprite.h" #include "doc/sprite.h"
#include "gfx/rect_io.h" #include "gfx/rect_io.h"
@ -381,7 +380,7 @@ void ColorButton::openPopup(const bool forcePinned)
if (!pinned || (forcePinned && m_hiddenPopupBounds.isEmpty())) { if (!pinned || (forcePinned && m_hiddenPopupBounds.isEmpty())) {
gfx::Rect bounds = getWidgetBounds(this); gfx::Rect bounds = getWidgetBounds(this);
winBounds.x = base::clamp(bounds.x, workarea.x, workarea.x2()-winBounds.w); winBounds.x = std::clamp(bounds.x, workarea.x, workarea.x2()-winBounds.w);
if (bounds.y2()+winBounds.h <= workarea.y2()) if (bounds.y2()+winBounds.h <= workarea.y2())
winBounds.y = std::max(workarea.y, bounds.y2()); winBounds.y = std::max(workarea.y, bounds.y2());
else else

View File

@ -21,7 +21,6 @@
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "app/ui/status_bar.h" #include "app/ui/status_bar.h"
#include "app/util/shader_helpers.h" #include "app/util/shader_helpers.h"
#include "base/clamp.h"
#include "base/concurrent_queue.h" #include "base/concurrent_queue.h"
#include "base/scoped_value.h" #include "base/scoped_value.h"
#include "base/thread.h" #include "base/thread.h"
@ -299,7 +298,7 @@ app::Color ColorSelector::getAlphaBarColor(const int u, const int umax)
{ {
int alpha = (255 * u / umax); int alpha = (255 * u / umax);
app::Color color = m_color; app::Color color = m_color;
color.setAlpha(base::clamp(alpha, 0, 255)); color.setAlpha(std::clamp(alpha, 0, 255));
return color; return color;
} }

View File

@ -17,7 +17,6 @@
#include "app/shade.h" #include "app/shade.h"
#include "app/ui/color_bar.h" #include "app/ui/color_bar.h"
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "base/clamp.h"
#include "doc/color_mode.h" #include "doc/color_mode.h"
#include "doc/palette.h" #include "doc/palette.h"
#include "doc/palette_picks.h" #include "doc/palette_picks.h"
@ -27,8 +26,8 @@
#include "ui/paint_event.h" #include "ui/paint_event.h"
#include "ui/size_hint_event.h" #include "ui/size_hint_event.h"
#include "ui/system.h" #include "ui/system.h"
#include <algorithm>
#include <algorithm>
namespace app { namespace app {
@ -213,7 +212,7 @@ bool ColorShades::onProcessMessage(ui::Message* msg)
int count = std::max(1, size()); int count = std::max(1, size());
int boxWidth = std::max(1, bounds.w / count); int boxWidth = std::max(1, bounds.w / count);
hot = (mousePos.x - bounds.x) / boxWidth; hot = (mousePos.x - bounds.x) / boxWidth;
hot = base::clamp(hot, 0, count-1); hot = std::clamp(hot, 0, count-1);
} }
if (m_hotIndex != hot) { if (m_hotIndex != hot) {

View File

@ -185,7 +185,7 @@ namespace {
else else
++value; ++value;
setTextf("%d", base::clamp(value, minValue(), maxValue())); setTextf("%d", std::clamp(value, minValue(), maxValue()));
selectAllText(); selectAllText();
onChange(); onChange();
@ -461,7 +461,7 @@ void ColorSliders::onEntryChange(const Channel i)
Slider* slider = (m_mode == Mode::Absolute ? Slider* slider = (m_mode == Mode::Absolute ?
m_items[i].absSlider: m_items[i].absSlider:
m_items[i].relSlider); m_items[i].relSlider);
value = base::clamp(value, slider->getMinValue(), slider->getMaxValue()); value = std::clamp(value, slider->getMinValue(), slider->getMaxValue());
slider->setValue(value); slider->setValue(value);
onControlChange(i); onControlChange(i);

View File

@ -15,7 +15,6 @@
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "app/ui/status_bar.h" #include "app/ui/status_bar.h"
#include "app/util/shader_helpers.h" #include "app/util/shader_helpers.h"
#include "base/clamp.h"
#include "os/surface.h" #include "os/surface.h"
#include "ui/graphics.h" #include "ui/graphics.h"
#include "ui/message.h" #include "ui/message.h"
@ -88,9 +87,9 @@ app::Color ColorSpectrum::getMainAreaColor(const int u, const int umax,
double hue = 360.0 * u / umax; double hue = 360.0 * u / umax;
double lit = 1.0 - (double(v)/double(vmax)); double lit = 1.0 - (double(v)/double(vmax));
return app::Color::fromHsl( return app::Color::fromHsl(
base::clamp(hue, 0.0, 360.0), std::clamp(hue, 0.0, 360.0),
m_color.getHslSaturation(), m_color.getHslSaturation(),
base::clamp(lit, 0.0, 1.0), std::clamp(lit, 0.0, 1.0),
getCurrentAlphaForNewColor()); getCurrentAlphaForNewColor());
} }
@ -99,7 +98,7 @@ app::Color ColorSpectrum::getBottomBarColor(const int u, const int umax)
double sat = double(u) / double(umax); double sat = double(u) / double(umax);
return app::Color::fromHsl( return app::Color::fromHsl(
m_color.getHslHue(), m_color.getHslHue(),
base::clamp(sat, 0.0, 1.0), std::clamp(sat, 0.0, 1.0),
m_color.getHslLightness(), m_color.getHslLightness(),
getCurrentAlphaForNewColor()); getCurrentAlphaForNewColor());
} }
@ -147,9 +146,9 @@ void ColorSpectrum::onPaintSurfaceInBgThread(
gfx::Color color = color_utils::color_for_ui( gfx::Color color = color_utils::color_for_ui(
app::Color::fromHsl( app::Color::fromHsl(
base::clamp(hue, 0.0, 360.0), std::clamp(hue, 0.0, 360.0),
sat, sat,
base::clamp(lit, 0.0, 1.0))); std::clamp(lit, 0.0, 1.0)));
s->putPixel(color, main.x+x, main.y+y); s->putPixel(color, main.x+x, main.y+y);
} }

View File

@ -14,7 +14,6 @@
#include "app/color_utils.h" #include "app/color_utils.h"
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "app/util/shader_helpers.h" #include "app/util/shader_helpers.h"
#include "base/clamp.h"
#include "ui/graphics.h" #include "ui/graphics.h"
#include <algorithm> #include <algorithm>
@ -84,8 +83,8 @@ app::Color ColorTintShadeTone::getMainAreaColor(const int u, const int umax,
double val = (1.0 - double(v) / double(vmax)); double val = (1.0 - double(v) / double(vmax));
return app::Color::fromHsv( return app::Color::fromHsv(
m_color.getHsvHue(), m_color.getHsvHue(),
base::clamp(sat, 0.0, 1.0), std::clamp(sat, 0.0, 1.0),
base::clamp(val, 0.0, 1.0), std::clamp(val, 0.0, 1.0),
getCurrentAlphaForNewColor()); getCurrentAlphaForNewColor());
} }
@ -93,7 +92,7 @@ app::Color ColorTintShadeTone::getBottomBarColor(const int u, const int umax)
{ {
double hue = (360.0 * u / umax); double hue = (360.0 * u / umax);
return app::Color::fromHsv( return app::Color::fromHsv(
base::clamp(hue, 0.0, 360.0), std::clamp(hue, 0.0, 360.0),
m_color.getHsvSaturation(), m_color.getHsvSaturation(),
m_color.getHsvValue(), m_color.getHsvValue(),
getCurrentAlphaForNewColor()); getCurrentAlphaForNewColor());
@ -141,8 +140,8 @@ void ColorTintShadeTone::onPaintSurfaceInBgThread(
gfx::Color color = color_utils::color_for_ui( gfx::Color color = color_utils::color_for_ui(
app::Color::fromHsv( app::Color::fromHsv(
hue, hue,
base::clamp(sat, 0.0, 1.0), std::clamp(sat, 0.0, 1.0),
base::clamp(val, 0.0, 1.0))); std::clamp(val, 0.0, 1.0)));
s->putPixel(color, main.x+x, main.y+y); s->putPixel(color, main.x+x, main.y+y);
} }

View File

@ -16,7 +16,6 @@
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "app/ui/status_bar.h" #include "app/ui/status_bar.h"
#include "app/util/shader_helpers.h" #include "app/util/shader_helpers.h"
#include "base/clamp.h"
#include "base/pi.h" #include "base/pi.h"
#include "os/surface.h" #include "os/surface.h"
#include "ui/graphics.h" #include "ui/graphics.h"
@ -236,9 +235,9 @@ app::Color ColorWheel::getMainAreaColor(const int _u, const int umax,
int b = 255 - di; int b = 255 - di;
if (d <= m_wheelRadius) { if (d <= m_wheelRadius) {
return app::Color::fromRgb( return app::Color::fromRgb(
base::clamp(r, 0, 255), std::clamp(r, 0, 255),
base::clamp(g, 0, 255), std::clamp(g, 0, 255),
base::clamp(b, 128, 255)); std::clamp(b, 128, 255));
} }
else { else {
return app::Color::fromRgb(128, 128, 255); return app::Color::fromRgb(128, 128, 255);
@ -272,8 +271,8 @@ app::Color ColorWheel::getMainAreaColor(const int _u, const int umax,
} }
return app::Color::fromHsv( return app::Color::fromHsv(
base::clamp(hue, 0, 360), std::clamp(hue, 0, 360),
base::clamp(sat / 100.0, 0.0, 1.0), std::clamp(sat / 100.0, 0.0, 1.0),
(m_color.getType() != Color::MaskType ? m_color.getHsvValue(): 1.0), (m_color.getType() != Color::MaskType ? m_color.getHsvValue(): 1.0),
getCurrentAlphaForNewColor()); getCurrentAlphaForNewColor());
} }
@ -287,7 +286,7 @@ app::Color ColorWheel::getBottomBarColor(const int u, const int umax)
return app::Color::fromHsv( return app::Color::fromHsv(
m_color.getHsvHue(), m_color.getHsvHue(),
m_color.getHsvSaturation(), m_color.getHsvSaturation(),
base::clamp(val, 0.0, 1.0), std::clamp(val, 0.0, 1.0),
getCurrentAlphaForNewColor()); getCurrentAlphaForNewColor());
} }
@ -306,7 +305,7 @@ void ColorWheel::onPaintMainArea(ui::Graphics* g, const gfx::Rect& rc)
double angle = std::atan2(m_color.getGreen()-128, double angle = std::atan2(m_color.getGreen()-128,
m_color.getRed()-128); m_color.getRed()-128);
double dist = (255-m_color.getBlue()) / 128.0; double dist = (255-m_color.getBlue()) / 128.0;
dist = base::clamp(dist, 0.0, 1.0); dist = std::clamp(dist, 0.0, 1.0);
gfx::Point pos = gfx::Point pos =
m_wheelBounds.center() + m_wheelBounds.center() +
@ -450,18 +449,18 @@ void ColorWheel::setHarmony(Harmony harmony)
int ColorWheel::getHarmonies() const int ColorWheel::getHarmonies() const
{ {
int i = base::clamp((int)m_harmony, 0, (int)Harmony::LAST); int i = std::clamp((int)m_harmony, 0, (int)Harmony::LAST);
return harmonies[i].n; return harmonies[i].n;
} }
app::Color ColorWheel::getColorInHarmony(int j) const app::Color ColorWheel::getColorInHarmony(int j) const
{ {
int i = base::clamp((int)m_harmony, 0, (int)Harmony::LAST); int i = std::clamp((int)m_harmony, 0, (int)Harmony::LAST);
j = base::clamp(j, 0, harmonies[i].n-1); j = std::clamp(j, 0, harmonies[i].n-1);
double hue = convertHueAngle(m_color.getHsvHue(), -1) + harmonies[i].hues[j]; double hue = convertHueAngle(m_color.getHsvHue(), -1) + harmonies[i].hues[j];
double sat = m_color.getHsvSaturation() * harmonies[i].sats[j] / 100.0; double sat = m_color.getHsvSaturation() * harmonies[i].sats[j] / 100.0;
return app::Color::fromHsv(std::fmod(hue, 360), return app::Color::fromHsv(std::fmod(hue, 360),
base::clamp(sat, 0.0, 1.0), std::clamp(sat, 0.0, 1.0),
m_color.getHsvValue()); m_color.getHsvValue());
} }

View File

@ -48,7 +48,6 @@
#include "app/ui/selection_mode_field.h" #include "app/ui/selection_mode_field.h"
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "app/ui_context.h" #include "app/ui_context.h"
#include "base/clamp.h"
#include "base/fs.h" #include "base/fs.h"
#include "base/pi.h" #include "base/pi.h"
#include "base/scoped_value.h" #include "base/scoped_value.h"
@ -652,7 +651,7 @@ private:
char buf[32]; char buf[32];
int n = get_config_int("shades", "count", 0); int n = get_config_int("shades", "count", 0);
n = base::clamp(n, 0, 256); n = std::clamp(n, 0, 256);
for (int i=0; i<n; ++i) { for (int i=0; i<n; ++i) {
sprintf(buf, "shade%d", i); sprintf(buf, "shade%d", i);
Shade shade = shade_from_string(get_config_string("shades", buf, "")); Shade shade = shade_from_string(get_config_string("shades", buf, ""));
@ -864,7 +863,7 @@ public:
: ButtonSet(1) { : ButtonSet(1) {
addItem(SkinTheme::get(this)->parts.pivotCenter()); addItem(SkinTheme::get(this)->parts.pivotCenter());
Preferences::instance().selection.pivotPosition.AfterChange.connect( m_pivotConn = Preferences::instance().selection.pivotPosition.AfterChange.connect(
[this]{ onPivotChange(); }); [this]{ onPivotChange(); });
onPivotChange(); onPivotChange();
@ -936,6 +935,7 @@ private:
getItem(0)->setIcon(part); getItem(0)->setIcon(part);
} }
obs::scoped_connection m_pivotConn;
}; };
class ContextBar::RotAlgorithmField : public ComboBox { class ContextBar::RotAlgorithmField : public ComboBox {
@ -1119,7 +1119,7 @@ private:
} }
void onChangeSkew() { void onChangeSkew() {
double newSkew = PI * m_skew.textDouble() / 180.0; double newSkew = PI * m_skew.textDouble() / 180.0;
newSkew = base::clamp(newSkew, -PI*85.0/180.0, PI*85.0/180.0); newSkew = std::clamp(newSkew, -PI*85.0/180.0, PI*85.0/180.0);
m_t.skew(newSkew); m_t.skew(newSkew);
updateEditor(); updateEditor();
} }
@ -1769,17 +1769,15 @@ ContextBar::ContextBar(TooltipManager* tooltipManager,
App::instance()->activeToolManager()->add_observer(this); App::instance()->activeToolManager()->add_observer(this);
UIContext::instance()->add_observer(this); UIContext::instance()->add_observer(this);
pref.symmetryMode.enabled.AfterChange.connect( m_symmModeConn = pref.symmetryMode.enabled.AfterChange.connect(
[this]{ onSymmetryModeChange(); }); [this]{ onSymmetryModeChange(); });
pref.colorBar.fgColor.AfterChange.connect( m_fgColorConn = pref.colorBar.fgColor.AfterChange.connect(
[this]{ onFgOrBgColorChange(doc::Brush::ImageColor::MainColor); }); [this]{ onFgOrBgColorChange(doc::Brush::ImageColor::MainColor); });
pref.colorBar.bgColor.AfterChange.connect( m_bgColorConn = pref.colorBar.bgColor.AfterChange.connect(
[this]{ onFgOrBgColorChange(doc::Brush::ImageColor::BackgroundColor); }); [this]{ onFgOrBgColorChange(doc::Brush::ImageColor::BackgroundColor); });
m_keysConn = KeyboardShortcuts::instance()->UserChange.connect(
KeyboardShortcuts::instance()->UserChange.connect(
[this, tooltipManager]{ setupTooltips(tooltipManager); }); [this, tooltipManager]{ setupTooltips(tooltipManager); });
m_dropPixelsConn = m_dropPixels->DropPixels.connect(&ContextBar::onDropPixels, this);
m_dropPixels->DropPixels.connect(&ContextBar::onDropPixels, this);
setActiveBrush(createBrushFromPreferences()); setActiveBrush(createBrushFromPreferences());

View File

@ -200,6 +200,11 @@ namespace app {
ui::Label* m_selectBoxHelp; ui::Label* m_selectBoxHelp;
SymmetryField* m_symmetry; SymmetryField* m_symmetry;
SliceFields* m_sliceFields; SliceFields* m_sliceFields;
obs::scoped_connection m_symmModeConn;
obs::scoped_connection m_fgColorConn;
obs::scoped_connection m_bgColorConn;
obs::scoped_connection m_keysConn;
obs::scoped_connection m_dropPixelsConn;
obs::scoped_connection m_sizeConn; obs::scoped_connection m_sizeConn;
obs::scoped_connection m_angleConn; obs::scoped_connection m_angleConn;
obs::scoped_connection m_opacityConn; obs::scoped_connection m_opacityConn;

View File

@ -12,7 +12,6 @@
#include "app/ui/dithering_selector.h" #include "app/ui/dithering_selector.h"
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "base/clamp.h"
#include "os/font.h" #include "os/font.h"
#include "os/surface.h" #include "os/surface.h"
#include "ui/message.h" #include "ui/message.h"
@ -163,7 +162,7 @@ private:
auto mouseMsg = static_cast<MouseMessage*>(msg); auto mouseMsg = static_cast<MouseMessage*>(msg);
const gfx::Rect rc = bounds(); const gfx::Rect rc = bounds();
float u = (mouseMsg->position().x - rc.x) / float(rc.w); float u = (mouseMsg->position().x - rc.x) / float(rc.w);
u = base::clamp(u, 0.0f, 1.0f); u = std::clamp(u, 0.0f, 1.0f);
switch (capture) { switch (capture) {
case Capture::Min: case Capture::Min:
m_minThreshold = u; m_minThreshold = u;
@ -464,7 +463,7 @@ bool DynamicsPopup::onProcessMessage(Message* msg)
float v = m_velocity.velocity().magnitude() float v = m_velocity.velocity().magnitude()
/ tools::VelocitySensor::kScreenPixelsForFullVelocity; / tools::VelocitySensor::kScreenPixelsForFullVelocity;
v = base::clamp(v, 0.0f, 1.0f); v = std::clamp(v, 0.0f, 1.0f);
m_velocityThreshold->setSensorValue(v); m_velocityThreshold->setSensorValue(v);
} }

View File

@ -11,7 +11,6 @@
#include "app/ui/editor/dragging_value_state.h" #include "app/ui/editor/dragging_value_state.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "base/clamp.h"
#include "ui/display.h" #include "ui/display.h"
#include "ui/message.h" #include "ui/message.h"
#include "ui/scale.h" #include "ui/scale.h"

View File

@ -55,7 +55,7 @@
#include "app/util/conversion_to_surface.h" #include "app/util/conversion_to_surface.h"
#include "app/util/layer_utils.h" #include "app/util/layer_utils.h"
#include "base/chrono.h" #include "base/chrono.h"
#include "base/clamp.h" #include "base/convert_to.h"
#include "doc/doc.h" #include "doc/doc.h"
#include "doc/mask_boundaries.h" #include "doc/mask_boundaries.h"
#include "doc/slice.h" #include "doc/slice.h"
@ -640,8 +640,8 @@ void Editor::drawOneSpriteUnclippedRect(ui::Graphics* g, const gfx::Rect& sprite
const int maxw = std::max(0, m_sprite->width()-expose.x); const int maxw = std::max(0, m_sprite->width()-expose.x);
const int maxh = std::max(0, m_sprite->height()-expose.y); const int maxh = std::max(0, m_sprite->height()-expose.y);
expose.w = base::clamp(expose.w, 0, maxw); expose.w = std::clamp(expose.w, 0, maxw);
expose.h = base::clamp(expose.h, 0, maxh); expose.h = std::clamp(expose.h, 0, maxh);
if (expose.isEmpty()) if (expose.isEmpty())
return; return;
@ -818,7 +818,7 @@ void Editor::drawOneSpriteUnclippedRect(ui::Graphics* g, const gfx::Rect& sprite
if (m_docPref.pixelGrid.autoOpacity()) { if (m_docPref.pixelGrid.autoOpacity()) {
alpha = int(alpha * (m_proj.zoom().scale()-2.) / (16.-2.)); alpha = int(alpha * (m_proj.zoom().scale()-2.) / (16.-2.));
alpha = base::clamp(alpha, 0, 255); alpha = std::clamp(alpha, 0, 255);
} }
drawGrid(g, enclosingRect, Rect(0, 0, 1, 1), drawGrid(g, enclosingRect, Rect(0, 0, 1, 1),
@ -843,7 +843,7 @@ void Editor::drawOneSpriteUnclippedRect(ui::Graphics* g, const gfx::Rect& sprite
double len = (m_proj.applyX(gridrc.w) + double len = (m_proj.applyX(gridrc.w) +
m_proj.applyY(gridrc.h)) / 2.; m_proj.applyY(gridrc.h)) / 2.;
alpha = int(alpha * len / 32.); alpha = int(alpha * len / 32.);
alpha = base::clamp(alpha, 0, 255); alpha = std::clamp(alpha, 0, 255);
} }
if (alpha > 8) { if (alpha > 8) {
@ -1461,8 +1461,8 @@ gfx::Point Editor::autoScroll(const ui::MouseMessage* msg,
m_oldPos = mousePos; m_oldPos = mousePos;
mousePos = gfx::Point( mousePos = gfx::Point(
base::clamp(mousePos.x, vp.x, vp.x2()-1), std::clamp(mousePos.x, vp.x, vp.x2()-1),
base::clamp(mousePos.y, vp.y, vp.y2()-1)); std::clamp(mousePos.y, vp.y, vp.y2()-1));
} }
else else
m_oldPos = mousePos; m_oldPos = mousePos;
@ -2528,8 +2528,8 @@ void Editor::setZoomAndCenterInMouse(const Zoom& zoom,
// extra space for the zoom) // extra space for the zoom)
gfx::Rect visibleBounds = editorToScreen( gfx::Rect visibleBounds = editorToScreen(
getViewportBounds().createIntersection(gfx::Rect(gfx::Point(0, 0), canvasSize()))); getViewportBounds().createIntersection(gfx::Rect(gfx::Point(0, 0), canvasSize())));
screenPos.x = base::clamp(screenPos.x, visibleBounds.x, visibleBounds.x2()-1); screenPos.x = std::clamp(screenPos.x, visibleBounds.x, visibleBounds.x2()-1);
screenPos.y = base::clamp(screenPos.y, visibleBounds.y, visibleBounds.y2()-1); screenPos.y = std::clamp(screenPos.y, visibleBounds.y, visibleBounds.y2()-1);
spritePos = screenToEditor(screenPos); spritePos = screenToEditor(screenPos);
@ -2615,7 +2615,7 @@ void Editor::pasteImage(const Image* image, const Mask* mask)
// In other case, if the center is visible, we put the pasted // In other case, if the center is visible, we put the pasted
// image in its original location. // image in its original location.
else { else {
x = base::clamp(x, visibleBounds.x-image->width(), visibleBounds.x2()-1); x = std::clamp(x, visibleBounds.x-image->width(), visibleBounds.x2()-1);
} }
if (maskCenter.y < visibleBounds.y || if (maskCenter.y < visibleBounds.y ||
@ -2623,7 +2623,7 @@ void Editor::pasteImage(const Image* image, const Mask* mask)
y = visibleBounds.y + visibleBounds.h/2 - image->height()/2; y = visibleBounds.y + visibleBounds.h/2 - image->height()/2;
} }
else { else {
y = base::clamp(y, visibleBounds.y-image->height(), visibleBounds.y2()-1); y = std::clamp(y, visibleBounds.y-image->height(), visibleBounds.y2()-1);
} }
// Limit the image inside the sprite's bounds. // Limit the image inside the sprite's bounds.
@ -2631,13 +2631,13 @@ void Editor::pasteImage(const Image* image, const Mask* mask)
sprite->height() <= image->height()) { sprite->height() <= image->height()) {
// TODO review this (I think limits are wrong and high limit can // TODO review this (I think limits are wrong and high limit can
// be negative here) // be negative here)
x = base::clamp(x, 0, sprite->width() - image->width()); x = std::clamp(x, 0, sprite->width() - image->width());
y = base::clamp(y, 0, sprite->height() - image->height()); y = std::clamp(y, 0, sprite->height() - image->height());
} }
else { else {
// Also we always limit the 1 image pixel inside the sprite's bounds. // Also we always limit the 1 image pixel inside the sprite's bounds.
x = base::clamp(x, -image->width()+1, sprite->width()-1); x = std::clamp(x, -image->width()+1, sprite->width()-1);
y = base::clamp(y, -image->height()+1, sprite->height()-1); y = std::clamp(y, -image->height()+1, sprite->height()-1);
} }
} }

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2020 Igara Studio S.A. // Copyright (C) 2020-2022 Igara Studio S.A.
// Copyright (C) 2015-2016 David Capello // Copyright (C) 2015-2016 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -13,7 +13,6 @@
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "app/ui/status_bar.h" #include "app/ui/status_bar.h"
#include "base/clamp.h"
#include "fmt/format.h" #include "fmt/format.h"
#include "ui/message.h" #include "ui/message.h"
@ -51,12 +50,12 @@ bool MovingSymmetryState::onMouseMove(Editor* editor, MouseMessage* msg)
case app::gen::SymmetryMode::HORIZONTAL: case app::gen::SymmetryMode::HORIZONTAL:
pos = m_symmetryAxisStart + delta.x; pos = m_symmetryAxisStart + delta.x;
pos = std::round(pos*2.0)/2.0; pos = std::round(pos*2.0)/2.0;
pos = base::clamp(pos, 1.0, editor->sprite()->width()-1.0); pos = std::clamp(pos, 1.0, editor->sprite()->width()-1.0);
break; break;
case app::gen::SymmetryMode::VERTICAL: case app::gen::SymmetryMode::VERTICAL:
pos = m_symmetryAxisStart + delta.y; pos = m_symmetryAxisStart + delta.y;
pos = std::round(pos*2.0)/2.0; pos = std::round(pos*2.0)/2.0;
pos = base::clamp(pos, 1.0, editor->sprite()->height()-1.0); pos = std::clamp(pos, 1.0, editor->sprite()->height()-1.0);
break; break;
} }
m_symmetryAxis(pos); m_symmetryAxis(pos);

View File

@ -31,7 +31,6 @@
#include "app/util/expand_cel_canvas.h" #include "app/util/expand_cel_canvas.h"
#include "app/util/new_image_from_mask.h" #include "app/util/new_image_from_mask.h"
#include "app/util/range_utils.h" #include "app/util/range_utils.h"
#include "base/clamp.h"
#include "base/pi.h" #include "base/pi.h"
#include "doc/algorithm/flip_image.h" #include "doc/algorithm/flip_image.h"
#include "doc/algorithm/rotate.h" #include "doc/algorithm/rotate.h"
@ -692,7 +691,7 @@ void PixelsMovement::moveImage(const gfx::PointF& pos, MoveModifier moveModifier
// Calculate angle between AC and AC0 // Calculate angle between AC and AC0
double newSkew = std::atan2(AC.x*AC0.y - AC.y*AC0.x, AC * AC0); double newSkew = std::atan2(AC.x*AC0.y - AC.y*AC0.x, AC * AC0);
newSkew = base::clamp(newSkew, -PI*85.0/180.0, PI*85.0/180.0); newSkew = std::clamp(newSkew, -PI*85.0/180.0, PI*85.0/180.0);
newTransformation.skew(newSkew); newTransformation.skew(newSkew);
break; break;
} }

View File

@ -53,7 +53,6 @@
#include "app/util/layer_utils.h" #include "app/util/layer_utils.h"
#include "app/util/new_image_from_mask.h" #include "app/util/new_image_from_mask.h"
#include "app/util/readable_time.h" #include "app/util/readable_time.h"
#include "base/clamp.h"
#include "base/pi.h" #include "base/pi.h"
#include "base/vector2d.h" #include "base/vector2d.h"
#include "doc/grid.h" #include "doc/grid.h"
@ -69,6 +68,7 @@
#include "ui/message.h" #include "ui/message.h"
#include "ui/view.h" #include "ui/view.h"
#include <algorithm>
#include <cmath> #include <cmath>
#include <cstring> #include <cstring>
@ -946,7 +946,7 @@ bool StandbyState::Decorator::onSetCursor(tools::Ink* ink, Editor* editor, const
double angle = v.angle(); double angle = v.angle();
angle = base::fmod_radians(angle) + PI; angle = base::fmod_radians(angle) + PI;
ASSERT(angle >= 0.0 && angle <= 2*PI); ASSERT(angle >= 0.0 && angle <= 2*PI);
const int angleInt = base::clamp<int>(std::floor(8.0 * angle / (2.0*PI) + 0.5), 0, 8) % 8; const int angleInt = std::clamp<int>(std::floor(8.0 * angle / (2.0*PI) + 0.5), 0, 8) % 8;
if (handle == PivotHandle) { if (handle == PivotHandle) {
newCursorType = kHandCursor; newCursorType = kHandCursor;

View File

@ -25,7 +25,6 @@
#include "app/ui/keyboard_shortcuts.h" #include "app/ui/keyboard_shortcuts.h"
#include "app/ui/toolbar.h" #include "app/ui/toolbar.h"
#include "app/ui_context.h" #include "app/ui_context.h"
#include "base/clamp.h"
#include "base/string.h" #include "base/string.h"
#include "doc/brush.h" #include "doc/brush.h"
#include "doc/layer.h" #include "doc/layer.h"
@ -45,23 +44,23 @@ template<typename T>
static inline void adjust_value(bool preciseWheel, double dz, T& v, T min, T max) static inline void adjust_value(bool preciseWheel, double dz, T& v, T min, T max)
{ {
if (preciseWheel) if (preciseWheel)
v = base::clamp<T>(T(v+dz), min, max); v = std::clamp<T>(T(v+dz), min, max);
else else
v = base::clamp<T>(T(v+dz*max/T(10)), min, max); v = std::clamp<T>(T(v+dz*max/T(10)), min, max);
} }
template<typename T> template<typename T>
static inline void adjust_hue(bool preciseWheel, double dz, T& v, T min, T max) static inline void adjust_hue(bool preciseWheel, double dz, T& v, T min, T max)
{ {
if (preciseWheel) if (preciseWheel)
v = base::clamp<T>(T(v+dz), min, max); v = std::clamp<T>(T(v+dz), min, max);
else else
v = base::clamp<T>(T(v+dz*T(10)), min, max); v = std::clamp<T>(T(v+dz*T(10)), min, max);
} }
static inline void adjust_unit(bool preciseWheel, double dz, double& v) static inline void adjust_unit(bool preciseWheel, double dz, double& v)
{ {
v = base::clamp<double>(v+(preciseWheel ? dz/100.0: dz/25.0), 0.0, 1.0); v = std::clamp<double>(v+(preciseWheel ? dz/100.0: dz/25.0), 0.0, 1.0);
} }
StateWithWheelBehavior::StateWithWheelBehavior() StateWithWheelBehavior::StateWithWheelBehavior()
@ -169,7 +168,7 @@ void StateWithWheelBehavior::processWheelAction(
case WheelAction::FgColor: { case WheelAction::FgColor: {
int lastIndex = get_current_palette()->size()-1; int lastIndex = get_current_palette()->size()-1;
int newIndex = initialFgColor().getIndex() + int(dz); int newIndex = initialFgColor().getIndex() + int(dz);
newIndex = base::clamp(newIndex, 0, lastIndex); newIndex = std::clamp(newIndex, 0, lastIndex);
changeFgColor(app::Color::fromIndex(newIndex)); changeFgColor(app::Color::fromIndex(newIndex));
break; break;
} }
@ -177,7 +176,7 @@ void StateWithWheelBehavior::processWheelAction(
case WheelAction::BgColor: { case WheelAction::BgColor: {
int lastIndex = get_current_palette()->size()-1; int lastIndex = get_current_palette()->size()-1;
int newIndex = initialBgColor().getIndex() + int(dz); int newIndex = initialBgColor().getIndex() + int(dz);
newIndex = base::clamp(newIndex, 0, lastIndex); newIndex = std::clamp(newIndex, 0, lastIndex);
ColorBar::instance()->setBgColor(app::Color::fromIndex(newIndex)); ColorBar::instance()->setBgColor(app::Color::fromIndex(newIndex));
break; break;
} }
@ -186,7 +185,7 @@ void StateWithWheelBehavior::processWheelAction(
auto tilesView = ColorBar::instance()->getTilesView(); auto tilesView = ColorBar::instance()->getTilesView();
int lastIndex = tilesView->tileset()->size()-1; int lastIndex = tilesView->tileset()->size()-1;
int newIndex = initialFgTileIndex() + int(dz); int newIndex = initialFgTileIndex() + int(dz);
newIndex = base::clamp(newIndex, 0, lastIndex); newIndex = std::clamp(newIndex, 0, lastIndex);
ColorBar::instance()->setFgTile(newIndex); ColorBar::instance()->setFgTile(newIndex);
break; break;
} }
@ -195,7 +194,7 @@ void StateWithWheelBehavior::processWheelAction(
auto tilesView = ColorBar::instance()->getTilesView(); auto tilesView = ColorBar::instance()->getTilesView();
int lastIndex = tilesView->tileset()->size()-1; int lastIndex = tilesView->tileset()->size()-1;
int newIndex = initialBgTileIndex() + int(dz); int newIndex = initialBgTileIndex() + int(dz);
newIndex = base::clamp(newIndex, 0, lastIndex); newIndex = std::clamp(newIndex, 0, lastIndex);
ColorBar::instance()->setBgTile(newIndex); ColorBar::instance()->setBgTile(newIndex);
break; break;
} }
@ -283,7 +282,7 @@ void StateWithWheelBehavior::processWheelAction(
dz = -dz; dz = -dz;
brush.size( brush.size(
base::clamp( std::clamp(
int(initialBrushSize()+dz), int(initialBrushSize()+dz),
// If we use the "static const int" member directly here, // If we use the "static const int" member directly here,
// we'll get a linker error (when compiling without // we'll get a linker error (when compiling without
@ -304,7 +303,7 @@ void StateWithWheelBehavior::processWheelAction(
angle += 180; angle += 180;
angle %= 181; angle %= 181;
brush.angle(base::clamp(angle, 0, 180)); brush.angle(std::clamp(angle, 0, 180));
break; break;
} }
@ -398,9 +397,9 @@ void StateWithWheelBehavior::processWheelAction(
deltaInk = -1; deltaInk = -1;
} }
ink += deltaInk; ink += deltaInk;
ink = base::clamp(ink, ink = std::clamp(ink,
int(tools::InkType::FIRST), int(tools::InkType::FIRST),
int(tools::InkType::LAST)); int(tools::InkType::LAST));
App::instance()->contextBar()->setInkType(tools::InkType(ink)); App::instance()->contextBar()->setInkType(tools::InkType(ink));
break; break;
@ -489,9 +488,9 @@ void StateWithWheelBehavior::processWheelAction(
break; break;
} }
changeFgColor(Color::fromHsl(base::clamp(h, 0.0, 360.0), changeFgColor(Color::fromHsl(std::clamp(h, 0.0, 360.0),
base::clamp(s, 0.0, 1.0), std::clamp(s, 0.0, 1.0),
base::clamp(l, 0.0, 1.0))); std::clamp(l, 0.0, 1.0)));
break; break;
} }
@ -517,9 +516,9 @@ void StateWithWheelBehavior::processWheelAction(
break; break;
} }
changeFgColor(Color::fromHsv(base::clamp(h, 0.0, 360.0), changeFgColor(Color::fromHsv(std::clamp(h, 0.0, 360.0),
base::clamp(s, 0.0, 1.0), std::clamp(s, 0.0, 1.0),
base::clamp(v, 0.0, 1.0))); std::clamp(v, 0.0, 1.0)));
break; break;
} }

View File

@ -14,10 +14,11 @@
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "base/clamp.h"
#include "base/pi.h" #include "base/pi.h"
#include "os/surface.h" #include "os/surface.h"
#include <algorithm>
namespace app { namespace app {
using namespace app::skin; using namespace app::skin;
@ -242,7 +243,7 @@ void TransformHandles::drawHandle(Editor* editor, Graphics* g, int x, int y, dou
void TransformHandles::adjustHandle(int& x, int& y, int handle_w, int handle_h, double angle) void TransformHandles::adjustHandle(int& x, int& y, int handle_w, int handle_h, double angle)
{ {
angle = base::fmod_radians(angle + PI) + PI; angle = base::fmod_radians(angle + PI) + PI;
const int angleInt = base::clamp<int>(std::floor(8.0 * angle / (2.0*PI) + 0.5), 0, 8) % 8; const int angleInt = std::clamp<int>(std::floor(8.0 * angle / (2.0*PI) + 0.5), 0, 8) % 8;
// Adjust x,y position depending the angle of the handle // Adjust x,y position depending the angle of the handle
switch (angleInt) { switch (angleInt) {

View File

@ -14,7 +14,6 @@
#include "app/modules/gfx.h" #include "app/modules/gfx.h"
#include "app/thumbnail_generator.h" #include "app/thumbnail_generator.h"
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "base/clamp.h"
#include "base/string.h" #include "base/string.h"
#include "base/time.h" #include "base/time.h"
#include "os/font.h" #include "os/font.h"
@ -159,7 +158,7 @@ void FileList::goUp()
void FileList::setZoom(const double zoom) void FileList::setZoom(const double zoom)
{ {
m_zoom = base::clamp(zoom, 1.0, 8.0); m_zoom = std::clamp(zoom, 1.0, 8.0);
m_req_valid = false; m_req_valid = false;
// if (auto view = View::getView(this)) // if (auto view = View::getView(this))
@ -358,7 +357,7 @@ bool FileList::onProcessMessage(Message* msg)
} }
if (bottom > 0) if (bottom > 0)
selectIndex(base::clamp(select, 0, bottom-1)); selectIndex(std::clamp(select, 0, bottom-1));
return true; return true;
} }
@ -620,7 +619,7 @@ gfx::Rect FileList::mainThumbnailBounds()
gfx::Rect vp = view->viewportBounds(); gfx::Rect vp = view->viewportBounds();
int x = vp.x+vp.w - 2*guiscale() - thumbnail->width(); int x = vp.x+vp.w - 2*guiscale() - thumbnail->width();
int y = info.bounds.center().y - thumbnail->height()/2 + bounds().y; int y = info.bounds.center().y - thumbnail->height()/2 + bounds().y;
y = base::clamp(y, vp.y+2*guiscale(), vp.y+vp.h-3*guiscale()-thumbnail->height()); y = std::clamp(y, vp.y+2*guiscale(), vp.y+vp.h-3*guiscale()-thumbnail->height());
x -= bounds().x; x -= bounds().x;
y -= bounds().y; y -= bounds().y;
return gfx::Rect(x, y, thumbnail->width(), thumbnail->height()); return gfx::Rect(x, y, thumbnail->width(), thumbnail->height());

View File

@ -24,7 +24,6 @@
#include "app/ui/separator_in_view.h" #include "app/ui/separator_in_view.h"
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "app/widget_loader.h" #include "app/widget_loader.h"
#include "base/clamp.h"
#include "base/convert_to.h" #include "base/convert_to.h"
#include "base/fs.h" #include "base/fs.h"
#include "base/paths.h" #include "base/paths.h"
@ -130,7 +129,7 @@ void adjust_navigation_history(IFileItem* item)
} }
if (valid && !navigation_history.empty()) { if (valid && !navigation_history.empty()) {
pos = base::clamp(pos, 0, (int)navigation_history.size()-1); pos = std::clamp(pos, 0, (int)navigation_history.size()-1);
navigation_position.set(navigation_history.begin() + pos); navigation_position.set(navigation_history.begin() + pos);
FILESEL_TRACE("FILESEL: New navigation pos [%d] = %s\n", FILESEL_TRACE("FILESEL: New navigation pos [%d] = %s\n",

View File

@ -536,12 +536,20 @@ std::string Key::triggerString() const
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// KeyboardShortcuts // KeyboardShortcuts
static std::unique_ptr<KeyboardShortcuts> g_singleton;
// static
KeyboardShortcuts* KeyboardShortcuts::instance() KeyboardShortcuts* KeyboardShortcuts::instance()
{ {
static KeyboardShortcuts* singleton = NULL; if (!g_singleton)
if (!singleton) g_singleton = std::make_unique<KeyboardShortcuts>();
singleton = new KeyboardShortcuts(); return g_singleton.get();
return singleton; }
// static
void KeyboardShortcuts::destroyInstance()
{
g_singleton.reset();
} }
KeyboardShortcuts::KeyboardShortcuts() KeyboardShortcuts::KeyboardShortcuts()

View File

@ -22,6 +22,7 @@ namespace app {
typedef Keys::const_iterator const_iterator; typedef Keys::const_iterator const_iterator;
static KeyboardShortcuts* instance(); static KeyboardShortcuts* instance();
static void destroyInstance();
KeyboardShortcuts(); KeyboardShortcuts();
KeyboardShortcuts(const KeyboardShortcuts&) = delete; KeyboardShortcuts(const KeyboardShortcuts&) = delete;

View File

@ -28,7 +28,6 @@
#include "app/util/clipboard.h" #include "app/util/clipboard.h"
#include "app/util/conversion_to_surface.h" #include "app/util/conversion_to_surface.h"
#include "app/util/pal_ops.h" #include "app/util/pal_ops.h"
#include "base/clamp.h"
#include "base/convert_to.h" #include "base/convert_to.h"
#include "doc/image.h" #include "doc/image.h"
#include "doc/layer_tilemap.h" #include "doc/layer_tilemap.h"
@ -548,9 +547,9 @@ int PaletteView::getBoxSize() const
void PaletteView::setBoxSize(double boxsize) void PaletteView::setBoxSize(double boxsize)
{ {
if (isTiles()) if (isTiles())
m_boxsize = base::clamp(boxsize, 4.0, 64.0); m_boxsize = std::clamp(boxsize, 4.0, 64.0);
else else
m_boxsize = base::clamp(boxsize, 4.0, 32.0); m_boxsize = std::clamp(boxsize, 4.0, 32.0);
if (m_delegate) if (m_delegate)
m_delegate->onPaletteViewChangeSize(this, int(m_boxsize)); m_delegate->onPaletteViewChangeSize(this, int(m_boxsize));
@ -671,7 +670,7 @@ bool PaletteView::onProcessMessage(Message* msg)
(m_hot.part == Hit::COLOR || (m_hot.part == Hit::COLOR ||
m_hot.part == Hit::POSSIBLE_COLOR)) { m_hot.part == Hit::POSSIBLE_COLOR)) {
int idx = m_hot.color; int idx = m_hot.color;
idx = base::clamp(idx, 0, std::max(0, m_adapter->size()-1)); idx = std::clamp(idx, 0, std::max(0, m_adapter->size()-1));
const MouseButton button = mouseMsg->button(); const MouseButton button = mouseMsg->button();
@ -1137,7 +1136,7 @@ PaletteView::Hit PaletteView::hitTest(const gfx::Point& pos)
int colsLimit = m_columns; int colsLimit = m_columns;
if (m_state == State::DRAGGING_OUTLINE) if (m_state == State::DRAGGING_OUTLINE)
--colsLimit; --colsLimit;
int i = base::clamp((pos.x-vp.x)/box.w, 0, colsLimit) int i = std::clamp((pos.x-vp.x)/box.w, 0, colsLimit)
+ std::max(0, pos.y/box.h)*m_columns; + std::max(0, pos.y/box.h)*m_columns;
return Hit(Hit::POSSIBLE_COLOR, i); return Hit(Hit::POSSIBLE_COLOR, i);
} }

View File

@ -25,7 +25,6 @@
#include "app/ui/skin/skin_slider_property.h" #include "app/ui/skin/skin_slider_property.h"
#include "app/xml_document.h" #include "app/xml_document.h"
#include "app/xml_exception.h" #include "app/xml_exception.h"
#include "base/clamp.h"
#include "base/fs.h" #include "base/fs.h"
#include "base/log.h" #include "base/log.h"
#include "base/string.h" #include "base/string.h"
@ -1694,7 +1693,7 @@ void SkinTheme::paintProgressBar(ui::Graphics* g, const gfx::Rect& rc0, double p
rc.shrink(1); rc.shrink(1);
int u = (int)((double)rc.w*progress); int u = (int)((double)rc.w*progress);
u = base::clamp(u, 0, rc.w); u = std::clamp(u, 0, rc.w);
if (u > 0) if (u > 0)
g->fillRect(colors.selected(), gfx::Rect(rc.x, rc.y, u, rc.h)); g->fillRect(colors.selected(), gfx::Rect(rc.x, rc.y, u, rc.h));

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2020 Igara Studio S.A. // Copyright (C) 2020-2022 Igara Studio S.A.
// Copyright (C) 2017 David Capello // Copyright (C) 2017 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -12,7 +12,6 @@
#include "app/ui/slider2.h" #include "app/ui/slider2.h"
#include "app/ui/skin/skin_property.h" #include "app/ui/skin/skin_property.h"
#include "base/clamp.h"
#include "ui/manager.h" #include "ui/manager.h"
#include "ui/message.h" #include "ui/message.h"
@ -56,7 +55,7 @@ bool Slider2::Slider2Entry::onProcessMessage(ui::Message* msg)
else else
++value; ++value;
setTextf("%d", base::clamp(value, minValue(), maxValue())); setTextf("%d", std::clamp(value, minValue(), maxValue()));
selectAllText(); selectAllText();
onChange(); onChange();
@ -119,7 +118,7 @@ void Slider2::onSliderChange()
void Slider2::onEntryChange() void Slider2::onEntryChange()
{ {
int v = m_entry.textInt(); int v = m_entry.textInt();
v = base::clamp(v, m_slider.getMinValue(), m_slider.getMaxValue()); v = std::clamp(v, m_slider.getMinValue(), m_slider.getMaxValue());
m_slider.setValue(v); m_slider.setValue(v);
onChange(); onChange();

View File

@ -16,7 +16,6 @@
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/ui/editor/editor_view.h" #include "app/ui/editor/editor_view.h"
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "base/clamp.h"
#include "os/font.h" #include "os/font.h"
#include "os/surface.h" #include "os/surface.h"
#include "os/system.h" #include "os/system.h"
@ -261,7 +260,7 @@ void Tabs::setDropViewPreview(const gfx::Point& pos, TabView* view)
if (!m_list.empty()) { if (!m_list.empty()) {
newIndex = (pos.x - bounds().x) / m_list[0]->width; newIndex = (pos.x - bounds().x) / m_list[0]->width;
newIndex = base::clamp(newIndex, 0, (int)m_list.size()); newIndex = std::clamp(newIndex, 0, (int)m_list.size());
} }
else else
newIndex = 0; newIndex = 0;
@ -432,7 +431,7 @@ bool Tabs::onProcessMessage(Message* msg)
if (it != m_list.end()) { if (it != m_list.end()) {
int index = (it - m_list.begin()); int index = (it - m_list.begin());
int newIndex = index + dz; int newIndex = index + dz;
newIndex = base::clamp(newIndex, 0, int(m_list.size())-1); newIndex = std::clamp(newIndex, 0, int(m_list.size())-1);
if (newIndex != index) { if (newIndex != index) {
selectTabInternal(m_list[newIndex]); selectTabInternal(m_list[newIndex]);
} }
@ -1033,14 +1032,14 @@ void Tabs::updateDragTabIndexes(int mouseX, bool startAni)
int i = (mouseX - m_border*guiscale() - bounds().x) / m_dragTab->width; int i = (mouseX - m_border*guiscale() - bounds().x) / m_dragTab->width;
if (m_dragCopy) { if (m_dragCopy) {
i = base::clamp(i, 0, int(m_list.size())); i = std::clamp(i, 0, int(m_list.size()));
if (i != m_dragCopyIndex) { if (i != m_dragCopyIndex) {
m_dragCopyIndex = i; m_dragCopyIndex = i;
startAni = true; startAni = true;
} }
} }
else if (hasMouseOver()) { else if (hasMouseOver()) {
i = base::clamp(i, 0, int(m_list.size())-1); i = std::clamp(i, 0, int(m_list.size())-1);
if (i != m_dragTabIndex) { if (i != m_dragTabIndex) {
m_list.erase(m_list.begin()+m_dragTabIndex); m_list.erase(m_list.begin()+m_dragTabIndex);
m_list.insert(m_list.begin()+i, m_selected); m_list.insert(m_list.begin()+i, m_selected);

View File

@ -15,11 +15,12 @@
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
#include "app/ui/layer_frame_comboboxes.h" #include "app/ui/layer_frame_comboboxes.h"
#include "app/ui/user_data_view.h" #include "app/ui/user_data_view.h"
#include "base/clamp.h"
#include "doc/sprite.h" #include "doc/sprite.h"
#include "doc/tag.h" #include "doc/tag.h"
#include "ui/manager.h" #include "ui/manager.h"
#include <algorithm>
namespace app { namespace app {
TagWindow::TagWindow(const doc::Sprite* sprite, const doc::Tag* tag) TagWindow::TagWindow(const doc::Sprite* sprite, const doc::Tag* tag)
@ -58,8 +59,8 @@ void TagWindow::rangeValue(doc::frame_t& from, doc::frame_t& to)
from = this->from()->textInt()-m_base; from = this->from()->textInt()-m_base;
to = this->to()->textInt()-m_base; to = this->to()->textInt()-m_base;
from = base::clamp(from, first, last); from = std::clamp(from, first, last);
to = base::clamp(to, from, last); to = std::clamp(to, from, last);
} }
doc::AniDir TagWindow::aniDirValue() doc::AniDir TagWindow::aniDirValue()

View File

@ -13,7 +13,6 @@
#include "app/i18n/strings.h" #include "app/i18n/strings.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "base/clamp.h"
#include "ui/scale.h" #include "ui/scale.h"
#include <limits> #include <limits>
@ -56,9 +55,9 @@ TaskWidget::TaskWidget(const Type type,
float v = m_task.progress(); float v = m_task.progress();
if (v > 0.0f) { if (v > 0.0f) {
TRACEARGS("progressBar setValue", TRACEARGS("progressBar setValue",
int(base::clamp(v*100.0f, 0.0f, 100.0f))); int(std::clamp(v*100.0f, 0.0f, 100.0f)));
m_progressBar.setValue( m_progressBar.setValue(
int(base::clamp(v*100.0f, 0.0f, 100.0f))); int(std::clamp(v*100.0f, 0.0f, 100.0f)));
} }
} }
}); });

View File

@ -47,7 +47,6 @@
#include "app/util/layer_boundaries.h" #include "app/util/layer_boundaries.h"
#include "app/util/layer_utils.h" #include "app/util/layer_utils.h"
#include "app/util/readable_time.h" #include "app/util/readable_time.h"
#include "base/clamp.h"
#include "base/convert_to.h" #include "base/convert_to.h"
#include "base/memory.h" #include "base/memory.h"
#include "base/scoped_value.h" #include "base/scoped_value.h"
@ -292,7 +291,7 @@ Timeline::~Timeline()
void Timeline::setZoom(const double zoom) void Timeline::setZoom(const double zoom)
{ {
m_zoom = base::clamp(zoom, 1.0, 10.0); m_zoom = std::clamp(zoom, 1.0, 10.0);
m_thumbnailsOverlayDirection = gfx::Point(int(frameBoxWidth()*1.0), int(frameBoxWidth()*0.5)); m_thumbnailsOverlayDirection = gfx::Point(int(frameBoxWidth()*1.0), int(frameBoxWidth()*0.5));
m_thumbnailsOverlayVisible = false; m_thumbnailsOverlayVisible = false;
} }
@ -964,7 +963,7 @@ bool Timeline::onProcessMessage(Message* msg)
if (selectedLayersBounds(selectedLayers(), if (selectedLayersBounds(selectedLayers(),
&layerFirst, &layerLast)) { &layerFirst, &layerLast)) {
layer_t layerIdx = m_clk.layer; layer_t layerIdx = m_clk.layer;
layerIdx = base::clamp(layerIdx, layerFirst, layerLast); layerIdx = std::clamp(layerIdx, layerFirst, layerLast);
m_clk.layer = layerIdx; m_clk.layer = layerIdx;
} }
} }
@ -1198,10 +1197,10 @@ bool Timeline::onProcessMessage(Message* msg)
if (tag) { if (tag) {
switch (m_state) { switch (m_state) {
case STATE_RESIZING_TAG_LEFT: case STATE_RESIZING_TAG_LEFT:
m_resizeTagData.from = base::clamp(hit.frame, 0, tag->toFrame()); m_resizeTagData.from = std::clamp(hit.frame, 0, tag->toFrame());
break; break;
case STATE_RESIZING_TAG_RIGHT: case STATE_RESIZING_TAG_RIGHT:
m_resizeTagData.to = base::clamp(hit.frame, tag->fromFrame(), m_sprite->lastFrame()); m_resizeTagData.to = std::clamp(hit.frame, tag->fromFrame(), m_sprite->lastFrame());
break; break;
} }
invalidate(); invalidate();
@ -2013,11 +2012,11 @@ void Timeline::getDrawableLayers(layer_t* firstDrawableLayer,
{ {
layer_t i = lastLayer() layer_t i = lastLayer()
- ((viewScroll().y + getCelsBounds().h) / layerBoxHeight()); - ((viewScroll().y + getCelsBounds().h) / layerBoxHeight());
i = base::clamp(i, firstLayer(), lastLayer()); i = std::clamp(i, firstLayer(), lastLayer());
layer_t j = lastLayer() - viewScroll().y / layerBoxHeight();; layer_t j = lastLayer() - viewScroll().y / layerBoxHeight();;
if (!m_rows.empty()) if (!m_rows.empty())
j = base::clamp(j, firstLayer(), lastLayer()); j = std::clamp(j, firstLayer(), lastLayer());
else else
j = -1; j = -1;
@ -2374,7 +2373,7 @@ void Timeline::drawCel(ui::Graphics* g, layer_t layerIndex, frame_t frame, Cel*
if (!thumb_bounds.isEmpty()) { if (!thumb_bounds.isEmpty()) {
if (os::SurfaceRef surface = thumb::get_cel_thumbnail(cel, thumb_bounds.size())) { if (os::SurfaceRef surface = thumb::get_cel_thumbnail(cel, thumb_bounds.size())) {
const int t = base::clamp(thumb_bounds.w/8, 4, 16); const int t = std::clamp(thumb_bounds.w/8, 4, 16);
draw_checked_grid(g, thumb_bounds, gfx::Size(t, t), docPref()); draw_checked_grid(g, thumb_bounds, gfx::Size(t, t), docPref());
g->drawRgbaSurface(surface.get(), g->drawRgbaSurface(surface.get(),
@ -3252,11 +3251,11 @@ Timeline::Hit Timeline::hitTest(ui::Message* msg, const gfx::Point& mousePos)
hit.veryBottom = true; hit.veryBottom = true;
if (hasCapture()) { if (hasCapture()) {
hit.layer = base::clamp(hit.layer, firstLayer(), lastLayer()); hit.layer = std::clamp(hit.layer, firstLayer(), lastLayer());
if (isMovingCel()) if (isMovingCel())
hit.frame = std::max(firstFrame(), hit.frame); hit.frame = std::max(firstFrame(), hit.frame);
else else
hit.frame = base::clamp(hit.frame, firstFrame(), lastFrame()); hit.frame = std::clamp(hit.frame, firstFrame(), lastFrame());
} }
else { else {
if (hit.layer > lastLayer()) hit.layer = -1; if (hit.layer > lastLayer()) hit.layer = -1;
@ -3462,7 +3461,7 @@ Timeline::Hit Timeline::hitTestCel(const gfx::Point& mousePos)
- m_separator_w - m_separator_w
+ scroll.x) / frameBoxWidth()); + scroll.x) / frameBoxWidth());
hit.layer = base::clamp(hit.layer, firstLayer(), lastLayer()); hit.layer = std::clamp(hit.layer, firstLayer(), lastLayer());
hit.frame = std::max(firstFrame(), hit.frame); hit.frame = std::max(firstFrame(), hit.frame);
return hit; return hit;
@ -3983,8 +3982,8 @@ void Timeline::setViewScroll(const gfx::Point& pt)
const gfx::Point oldScroll = viewScroll(); const gfx::Point oldScroll = viewScroll();
const gfx::Point maxPos = getMaxScrollablePos(); const gfx::Point maxPos = getMaxScrollablePos();
gfx::Point newScroll = pt; gfx::Point newScroll = pt;
newScroll.x = base::clamp(newScroll.x, 0, maxPos.x); newScroll.x = std::clamp(newScroll.x, 0, maxPos.x);
newScroll.y = base::clamp(newScroll.y, 0, maxPos.y); newScroll.y = std::clamp(newScroll.y, 0, maxPos.y);
if (newScroll.y != oldScroll.y) { if (newScroll.y != oldScroll.y) {
gfx::Rect rc; gfx::Rect rc;
@ -4450,7 +4449,7 @@ void Timeline::setLayerCollapsedFlag(const layer_t l, const bool state)
int Timeline::separatorX() const int Timeline::separatorX() const
{ {
return base::clamp(m_separator_x, headerBoxWidth(), bounds().w-guiscale()); return std::clamp(m_separator_x, headerBoxWidth(), bounds().w-guiscale());
} }
void Timeline::setSeparatorX(int newValue) void Timeline::setSeparatorX(int newValue)
@ -4465,9 +4464,9 @@ gfx::Color Timeline::highlightColor(const gfx::Color color)
r = gfx::getr(color)+64; // TODO make this customizable in the theme XML? r = gfx::getr(color)+64; // TODO make this customizable in the theme XML?
g = gfx::getg(color)+64; g = gfx::getg(color)+64;
b = gfx::getb(color)+64; b = gfx::getb(color)+64;
r = base::clamp(r, 0, 255); r = std::clamp(r, 0, 255);
g = base::clamp(g, 0, 255); g = std::clamp(g, 0, 255);
b = base::clamp(b, 0, 255); b = std::clamp(b, 0, 255);
return gfx::rgba(r, g, b, gfx::geta(color)); return gfx::rgba(r, g, b, gfx::geta(color));
} }

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2017 David Capello // Copyright (C) 2017 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -12,7 +12,8 @@
#include "app/util/wrap_point.h" #include "app/util/wrap_point.h"
#include "app/util/wrap_value.h" #include "app/util/wrap_value.h"
#include "base/clamp.h"
#include <algorithm>
namespace app { namespace app {
@ -26,14 +27,14 @@ gfx::Point wrap_point(const filters::TiledMode tiledMode,
if (int(tiledMode) & int(filters::TiledMode::X_AXIS)) if (int(tiledMode) & int(filters::TiledMode::X_AXIS))
out.x = wrap_value(pt.x, spriteSize.w); out.x = wrap_value(pt.x, spriteSize.w);
else if (clamp) else if (clamp)
out.x = base::clamp(pt.x, 0, spriteSize.w-1); out.x = std::clamp(pt.x, 0, spriteSize.w-1);
else else
out.x = pt.x; out.x = pt.x;
if (int(tiledMode) & int(filters::TiledMode::Y_AXIS)) if (int(tiledMode) & int(filters::TiledMode::Y_AXIS))
out.y = wrap_value(pt.y, spriteSize.h); out.y = wrap_value(pt.y, spriteSize.h);
else if (clamp) else if (clamp)
out.y = base::clamp(pt.y, 0, spriteSize.h-1); out.y = std::clamp(pt.y, 0, spriteSize.h-1);
else else
out.y = pt.y; out.y = pt.y;

View File

@ -1,5 +1,5 @@
// Aseprite Document Library // Aseprite Document Library
// Copyright (c) 2018-2021 Igara Studio S.A. // Copyright (c) 2018-2022 Igara Studio S.A.
// Copyright (c) 2001-2018 David Capello // Copyright (c) 2001-2018 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -11,7 +11,6 @@
#include "doc/algo.h" #include "doc/algo.h"
#include "base/clamp.h"
#include "base/debug.h" #include "base/debug.h"
#include <algorithm> #include <algorithm>
@ -412,7 +411,7 @@ static void draw_rotated_ellipse_rect(int x0, int y0, int x1, int y1, double zd,
if (w != 0.0) if (w != 0.0)
w = (w-zd) / (w+w); // squared weight of P1 w = (w-zd) / (w+w); // squared weight of P1
w = base::clamp(w, 0.0, 1.0); w = std::clamp(w, 0.0, 1.0);
xd = std::floor(w*xd + 0.5); xd = std::floor(w*xd + 0.5);
yd = std::floor(w*yd + 0.5); yd = std::floor(w*yd + 0.5);
@ -448,7 +447,7 @@ void fill_rotated_ellipse(int cx, int cy, int a, int b, double angle, void* data
Rows(int y0, int nrows) Rows(int y0, int nrows)
: y0(y0), row(nrows, std::make_pair(1, -1)) { } : y0(y0), row(nrows, std::make_pair(1, -1)) { }
void update(int x, int y) { void update(int x, int y) {
int i = base::clamp(y-y0, 0, int(row.size()-1)); int i = std::clamp(y-y0, 0, int(row.size()-1));
auto& r = row[i]; auto& r = row[i];
if (r.first > r.second) { if (r.first > r.second) {
r.first = r.second = x; r.first = r.second = x;

View File

@ -1,4 +1,5 @@
// Aseprite Document Library // Aseprite Document Library
// Copyright (c) 2022 Igara Studio S.A.
// Copyright (c) 2001-2016 David Capello // Copyright (c) 2001-2016 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -10,7 +11,6 @@
#include "base/base.h" #include "base/base.h"
#include "base/cfile.h" #include "base/cfile.h"
#include "base/clamp.h"
#include "doc/color_scales.h" #include "doc/color_scales.h"
#include "doc/image.h" #include "doc/image.h"
#include "doc/palette.h" #include "doc/palette.h"
@ -59,9 +59,9 @@ Palette* load_col_file(const char* filename)
if (ferror(f)) if (ferror(f))
break; break;
pal->setEntry(c, rgba(scale_6bits_to_8bits(base::clamp(r, 0, 63)), pal->setEntry(c, rgba(scale_6bits_to_8bits(std::clamp(r, 0, 63)),
scale_6bits_to_8bits(base::clamp(g, 0, 63)), scale_6bits_to_8bits(std::clamp(g, 0, 63)),
scale_6bits_to_8bits(base::clamp(b, 0, 63)), 255)); scale_6bits_to_8bits(std::clamp(b, 0, 63)), 255));
} }
} }
// Animator Pro format // Animator Pro format
@ -87,9 +87,9 @@ Palette* load_col_file(const char* filename)
if (ferror(f)) if (ferror(f))
break; break;
pal->setEntry(c, rgba(base::clamp(r, 0, 255), pal->setEntry(c, rgba(std::clamp(r, 0, 255),
base::clamp(g, 0, 255), std::clamp(g, 0, 255),
base::clamp(b, 0, 255), 255)); std::clamp(b, 0, 255), 255));
} }
} }

View File

@ -1,5 +1,5 @@
// Aseprite Document Library // Aseprite Document Library
// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello // Copyright (C) 2001-2016 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -11,7 +11,6 @@
#include "doc/handle_anidir.h" #include "doc/handle_anidir.h"
#include "base/clamp.h"
#include "doc/frame.h" #include "doc/frame.h"
#include "doc/sprite.h" #include "doc/sprite.h"
#include "doc/tag.h" #include "doc/tag.h"
@ -37,8 +36,8 @@ frame_t calculate_next_frame(
loopFrom = tag->fromFrame(); loopFrom = tag->fromFrame();
loopTo = tag->toFrame(); loopTo = tag->toFrame();
loopFrom = base::clamp(loopFrom, first, last); loopFrom = std::clamp(loopFrom, first, last);
loopTo = base::clamp(loopTo, first, last); loopTo = std::clamp(loopTo, first, last);
first = loopFrom; first = loopFrom;
last = loopTo; last = loopTo;

View File

@ -1,5 +1,5 @@
// Aseprite Document Library // Aseprite Document Library
// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -11,7 +11,6 @@
#include "doc/mask.h" #include "doc/mask.h"
#include "base/clamp.h"
#include "base/memory.h" #include "base/memory.h"
#include "doc/image_impl.h" #include "doc/image_impl.h"
@ -392,10 +391,10 @@ void Mask::crop(const Image *image)
beg_x2 = beg_x1 + m_bounds.w - 1; beg_x2 = beg_x1 + m_bounds.w - 1;
beg_y2 = beg_y1 + m_bounds.h - 1; beg_y2 = beg_y1 + m_bounds.h - 1;
beg_x1 = base::clamp(beg_x1, 0, m_bounds.w-1); beg_x1 = std::clamp(beg_x1, 0, m_bounds.w-1);
beg_y1 = base::clamp(beg_y1, 0, m_bounds.h-1); beg_y1 = std::clamp(beg_y1, 0, m_bounds.h-1);
beg_x2 = base::clamp(beg_x2, beg_x1, m_bounds.w-1); beg_x2 = std::clamp(beg_x2, beg_x1, m_bounds.w-1);
beg_y2 = base::clamp(beg_y2, beg_y1, m_bounds.h-1); beg_y2 = std::clamp(beg_y2, beg_y1, m_bounds.h-1);
/* left */ /* left */
ADVANCE(x1, x2, y2, <=, ++, ADVANCE(x1, x2, y2, <=, ++,

View File

@ -1,5 +1,5 @@
// Aseprite Document Library // Aseprite Document Library
// Copyright (C) 2018-2021 Igara Studio S.A. // Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -11,7 +11,6 @@
#include "doc/sprite.h" #include "doc/sprite.h"
#include "base/clamp.h"
#include "base/memory.h" #include "base/memory.h"
#include "base/remove_from_container.h" #include "base/remove_from_container.h"
#include "doc/cel.h" #include "doc/cel.h"
@ -93,7 +92,7 @@ Sprite::Sprite(const ImageSpec& spec,
case ColorMode::BITMAP: case ColorMode::BITMAP:
for (int c=0; c<ncolors; c++) { for (int c=0; c<ncolors; c++) {
int g = 255 * c / (ncolors-1); int g = 255 * c / (ncolors-1);
g = base::clamp(g, 0, 255); g = std::clamp(g, 0, 255);
pal.setEntry(c, rgba(g, g, g, 255)); pal.setEntry(c, rgba(g, g, g, 255));
} }
break; break;
@ -472,19 +471,19 @@ int Sprite::totalAnimationDuration() const
void Sprite::setFrameDuration(frame_t frame, int msecs) void Sprite::setFrameDuration(frame_t frame, int msecs)
{ {
if (frame >= 0 && frame < m_frames) if (frame >= 0 && frame < m_frames)
m_frlens[frame] = base::clamp(msecs, 1, 65535); m_frlens[frame] = std::clamp(msecs, 1, 65535);
} }
void Sprite::setFrameRangeDuration(frame_t from, frame_t to, int msecs) void Sprite::setFrameRangeDuration(frame_t from, frame_t to, int msecs)
{ {
std::fill( std::fill(
m_frlens.begin()+(std::size_t)from, m_frlens.begin()+(std::size_t)from,
m_frlens.begin()+(std::size_t)to+1, base::clamp(msecs, 1, 65535)); m_frlens.begin()+(std::size_t)to+1, std::clamp(msecs, 1, 65535));
} }
void Sprite::setDurationForAllFrames(int msecs) void Sprite::setDurationForAllFrames(int msecs)
{ {
std::fill(m_frlens.begin(), m_frlens.end(), base::clamp(msecs, 1, 65535)); std::fill(m_frlens.begin(), m_frlens.end(), std::clamp(msecs, 1, 65535));
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2017 David Capello // Copyright (C) 2017 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -11,7 +11,6 @@
#include "filters/brightness_contrast_filter.h" #include "filters/brightness_contrast_filter.h"
#include "base/clamp.h"
#include "doc/image.h" #include "doc/image.h"
#include "doc/palette.h" #include "doc/palette.h"
#include "doc/rgbmap.h" #include "doc/rgbmap.h"
@ -186,7 +185,7 @@ void BrightnessContrastFilter::updateMap()
double x = double(u) / double(max-1); double x = double(u) / double(max-1);
double y = (m_contrast+1.0) * (x - 0.5) + 0.5; double y = (m_contrast+1.0) * (x - 0.5) + 0.5;
y = y*(1.0+m_brightness); y = y*(1.0+m_brightness);
y = base::clamp(y, 0.0, 1.0); y = std::clamp(y, 0.0, 1.0);
m_cmap[u] = int(255.5 * y); m_cmap[u] = int(255.5 * y);
} }
} }

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello // Copyright (C) 2001-2016 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -11,7 +11,6 @@
#include "filters/color_curve_filter.h" #include "filters/color_curve_filter.h"
#include "base/clamp.h"
#include "filters/color_curve.h" #include "filters/color_curve.h"
#include "filters/filter_indexed_data.h" #include "filters/filter_indexed_data.h"
#include "filters/filter_manager.h" #include "filters/filter_manager.h"
@ -42,7 +41,7 @@ void ColorCurveFilter::generateMap()
// Generate the color convertion map // Generate the color convertion map
m_curve.getValues(0, 255, m_cmap); m_curve.getValues(0, 255, m_cmap);
for (int c=0; c<256; c++) for (int c=0; c<256; c++)
m_cmap[c] = base::clamp(m_cmap[c], 0, 255); m_cmap[c] = std::clamp(m_cmap[c], 0, 255);
} }
const char* ColorCurveFilter::getName() const char* ColorCurveFilter::getName()
@ -145,7 +144,7 @@ void ColorCurveFilter::applyToIndexed(FilterManager* filterMgr)
c = rgbmap->mapColor(r, g, b, a); c = rgbmap->mapColor(r, g, b, a);
} }
*(dst_address++) = base::clamp(c, 0, pal->size()-1); *(dst_address++) = std::clamp(c, 0, pal->size()-1);
} }
} }

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello // Copyright (C) 2001-2016 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -11,7 +11,6 @@
#include "filters/convolution_matrix_filter.h" #include "filters/convolution_matrix_filter.h"
#include "base/clamp.h"
#include "filters/convolution_matrix.h" #include "filters/convolution_matrix.h"
#include "filters/filter_indexed_data.h" #include "filters/filter_indexed_data.h"
#include "filters/filter_manager.h" #include "filters/filter_manager.h"
@ -168,28 +167,28 @@ void ConvolutionMatrixFilter::applyToRgba(FilterManager* filterMgr)
if (target & TARGET_RED_CHANNEL) { if (target & TARGET_RED_CHANNEL) {
delegate.r = delegate.r / delegate.div + m_matrix->getBias(); delegate.r = delegate.r / delegate.div + m_matrix->getBias();
delegate.r = base::clamp(delegate.r, 0, 255); delegate.r = std::clamp(delegate.r, 0, 255);
} }
else else
delegate.r = rgba_getr(color); delegate.r = rgba_getr(color);
if (target & TARGET_GREEN_CHANNEL) { if (target & TARGET_GREEN_CHANNEL) {
delegate.g = delegate.g / delegate.div + m_matrix->getBias(); delegate.g = delegate.g / delegate.div + m_matrix->getBias();
delegate.g = base::clamp(delegate.g, 0, 255); delegate.g = std::clamp(delegate.g, 0, 255);
} }
else else
delegate.g = rgba_getg(color); delegate.g = rgba_getg(color);
if (target & TARGET_BLUE_CHANNEL) { if (target & TARGET_BLUE_CHANNEL) {
delegate.b = delegate.b / delegate.div + m_matrix->getBias(); delegate.b = delegate.b / delegate.div + m_matrix->getBias();
delegate.b = base::clamp(delegate.b, 0, 255); delegate.b = std::clamp(delegate.b, 0, 255);
} }
else else
delegate.b = rgba_getb(color); delegate.b = rgba_getb(color);
if (target & TARGET_ALPHA_CHANNEL) { if (target & TARGET_ALPHA_CHANNEL) {
delegate.a = delegate.a / m_matrix->getDiv() + m_matrix->getBias(); delegate.a = delegate.a / m_matrix->getDiv() + m_matrix->getBias();
delegate.a = base::clamp(delegate.a, 0, 255); delegate.a = std::clamp(delegate.a, 0, 255);
} }
else else
delegate.a = rgba_geta(color); delegate.a = rgba_geta(color);
@ -235,14 +234,14 @@ void ConvolutionMatrixFilter::applyToGrayscale(FilterManager* filterMgr)
if (target & TARGET_GRAY_CHANNEL) { if (target & TARGET_GRAY_CHANNEL) {
delegate.v = delegate.v / delegate.div + m_matrix->getBias(); delegate.v = delegate.v / delegate.div + m_matrix->getBias();
delegate.v = base::clamp(delegate.v, 0, 255); delegate.v = std::clamp(delegate.v, 0, 255);
} }
else else
delegate.v = graya_getv(color); delegate.v = graya_getv(color);
if (target & TARGET_ALPHA_CHANNEL) { if (target & TARGET_ALPHA_CHANNEL) {
delegate.a = delegate.a / m_matrix->getDiv() + m_matrix->getBias(); delegate.a = delegate.a / m_matrix->getDiv() + m_matrix->getBias();
delegate.a = base::clamp(delegate.a, 0, 255); delegate.a = std::clamp(delegate.a, 0, 255);
} }
else else
delegate.a = graya_geta(color); delegate.a = graya_geta(color);
@ -290,7 +289,7 @@ void ConvolutionMatrixFilter::applyToIndexed(FilterManager* filterMgr)
if (target & TARGET_INDEX_CHANNEL) { if (target & TARGET_INDEX_CHANNEL) {
delegate.index = delegate.index / m_matrix->getDiv() + m_matrix->getBias(); delegate.index = delegate.index / m_matrix->getDiv() + m_matrix->getBias();
delegate.index = base::clamp(delegate.index, 0, 255); delegate.index = std::clamp(delegate.index, 0, 255);
*(dst_address++) = delegate.index; *(dst_address++) = delegate.index;
} }
@ -299,28 +298,28 @@ void ConvolutionMatrixFilter::applyToIndexed(FilterManager* filterMgr)
if (target & TARGET_RED_CHANNEL) { if (target & TARGET_RED_CHANNEL) {
delegate.r = delegate.r / delegate.div + m_matrix->getBias(); delegate.r = delegate.r / delegate.div + m_matrix->getBias();
delegate.r = base::clamp(delegate.r, 0, 255); delegate.r = std::clamp(delegate.r, 0, 255);
} }
else else
delegate.r = rgba_getr(color); delegate.r = rgba_getr(color);
if (target & TARGET_GREEN_CHANNEL) { if (target & TARGET_GREEN_CHANNEL) {
delegate.g = delegate.g / delegate.div + m_matrix->getBias(); delegate.g = delegate.g / delegate.div + m_matrix->getBias();
delegate.g = base::clamp(delegate.g, 0, 255); delegate.g = std::clamp(delegate.g, 0, 255);
} }
else else
delegate.g = rgba_getg(color); delegate.g = rgba_getg(color);
if (target & TARGET_BLUE_CHANNEL) { if (target & TARGET_BLUE_CHANNEL) {
delegate.b = delegate.b / delegate.div + m_matrix->getBias(); delegate.b = delegate.b / delegate.div + m_matrix->getBias();
delegate.b = base::clamp(delegate.b, 0, 255); delegate.b = std::clamp(delegate.b, 0, 255);
} }
else else
delegate.b = rgba_getb(color); delegate.b = rgba_getb(color);
if (target & TARGET_ALPHA_CHANNEL) { if (target & TARGET_ALPHA_CHANNEL) {
delegate.a = delegate.a / delegate.div + m_matrix->getBias(); delegate.a = delegate.a / delegate.div + m_matrix->getBias();
delegate.a = base::clamp(delegate.a, 0, 255); delegate.a = std::clamp(delegate.a, 0, 255);
} }
else else
delegate.a = rgba_geta(color); delegate.a = rgba_geta(color);

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2017-2018 David Capello // Copyright (C) 2017-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -11,7 +11,6 @@
#include "filters/hue_saturation_filter.h" #include "filters/hue_saturation_filter.h"
#include "base/clamp.h"
#include "doc/image.h" #include "doc/image.h"
#include "doc/palette.h" #include "doc/palette.h"
#include "doc/palette_picks.h" #include "doc/palette_picks.h"
@ -125,7 +124,7 @@ void HueSaturationFilter::applyToGrayscale(FilterManager* filterMgr)
gfx::Hsl hsl(gfx::Rgb(k, k, k)); gfx::Hsl hsl(gfx::Rgb(k, k, k));
double l = hsl.lightness()*(1.0+m_l); double l = hsl.lightness()*(1.0+m_l);
l = base::clamp(l, 0.0, 1.0); l = std::clamp(l, 0.0, 1.0);
hsl.lightness(l); hsl.lightness(l);
gfx::Rgb rgb(hsl); gfx::Rgb rgb(hsl);
@ -134,7 +133,7 @@ void HueSaturationFilter::applyToGrayscale(FilterManager* filterMgr)
if (a && (target & TARGET_ALPHA_CHANNEL)) { if (a && (target & TARGET_ALPHA_CHANNEL)) {
a = a*(1.0+m_a); a = a*(1.0+m_a);
a = base::clamp(a, 0, 255); a = std::clamp(a, 0, 255);
} }
} }
@ -214,11 +213,11 @@ void HueSaturationFilter::applyFilterToRgbT(const Target target,
double s = (multiply ? hsl.saturation()*(1.0+m_s): double s = (multiply ? hsl.saturation()*(1.0+m_s):
hsl.saturation() + m_s); hsl.saturation() + m_s);
s = base::clamp(s, 0.0, 1.0); s = std::clamp(s, 0.0, 1.0);
double l = (multiply ? (hsl.*get_lightness)()*(1.0+m_l): double l = (multiply ? (hsl.*get_lightness)()*(1.0+m_l):
(hsl.*get_lightness)() + m_l); (hsl.*get_lightness)() + m_l);
l = base::clamp(l, 0.0, 1.0); l = std::clamp(l, 0.0, 1.0);
hsl.hue(h); hsl.hue(h);
hsl.saturation(s); hsl.saturation(s);
@ -230,7 +229,7 @@ void HueSaturationFilter::applyFilterToRgbT(const Target target,
if (target & TARGET_BLUE_CHANNEL ) b = rgb.blue(); if (target & TARGET_BLUE_CHANNEL ) b = rgb.blue();
if (a && (target & TARGET_ALPHA_CHANNEL)) { if (a && (target & TARGET_ALPHA_CHANNEL)) {
a = a*(1.0+m_a); a = a*(1.0+m_a);
a = base::clamp(a, 0, 255); a = std::clamp(a, 0, 255);
} }
c = rgba(r, g, b, a); c = rgba(r, g, b, a);

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello // Copyright (C) 2001-2016 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -11,7 +11,6 @@
#include "filters/replace_color_filter.h" #include "filters/replace_color_filter.h"
#include "base/clamp.h"
#include "doc/image.h" #include "doc/image.h"
#include "doc/palette.h" #include "doc/palette.h"
#include "doc/rgbmap.h" #include "doc/rgbmap.h"
@ -40,7 +39,7 @@ void ReplaceColorFilter::setTo(const color_t to)
void ReplaceColorFilter::setTolerance(int tolerance) void ReplaceColorFilter::setTolerance(int tolerance)
{ {
m_tolerance = base::clamp(tolerance, 0, 255); m_tolerance = std::clamp(tolerance, 0, 255);
} }
const char* ReplaceColorFilter::getName() const char* ReplaceColorFilter::getName()

View File

@ -1,5 +1,5 @@
// Aseprite Render Library // Aseprite Render Library
// Copyright (c) 2019-2020 Igara Studio S.A // Copyright (c) 2019-2022 Igara Studio S.A
// Copyright (c) 2017 David Capello // Copyright (c) 2017 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -68,7 +68,7 @@ doc::color_t ErrorDiffusionDither::ditherRgbToIndex2D(
}; };
for (int i=0; i<kChannels; ++i) { for (int i=0; i<kChannels; ++i) {
v[i] += m_err[i][x+1]; v[i] += m_err[i][x+1];
v[i] = base::clamp(v[i], 0, 255); v[i] = std::clamp(v[i], 0, 255);
} }
const doc::color_t index = const doc::color_t index =

View File

@ -1,5 +1,5 @@
// Aseprite Render Library // Aseprite Render Library
// Copyright (c) 2019-2020 Igara Studio S.A. // Copyright (c) 2019-2022 Igara Studio S.A.
// Copyright (c) 2017 David Capello // Copyright (c) 2017 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -11,7 +11,6 @@
#include "render/ordered_dither.h" #include "render/ordered_dither.h"
#include "base/clamp.h"
#include "render/dithering.h" #include "render/dithering.h"
#include "render/dithering_matrix.h" #include "render/dithering_matrix.h"
@ -83,10 +82,10 @@ doc::color_t OrderedDither::ditherRgbPixelToIndex(
int g2 = g - (g1-g); int g2 = g - (g1-g);
int b2 = b - (b1-b); int b2 = b - (b1-b);
int a2 = a - (a1-a); int a2 = a - (a1-a);
r2 = base::clamp(r2, 0, 255); r2 = std::clamp(r2, 0, 255);
g2 = base::clamp(g2, 0, 255); g2 = std::clamp(g2, 0, 255);
b2 = base::clamp(b2, 0, 255); b2 = std::clamp(b2, 0, 255);
a2 = base::clamp(a2, 0, 255); a2 = std::clamp(a2, 0, 255);
doc::color_t nearest2idx = doc::color_t nearest2idx =
(rgbmap ? rgbmap->mapColor(r2, g2, b2, a2): (rgbmap ? rgbmap->mapColor(r2, g2, b2, a2):
palette->findBestfit(r2, g2, b2, a2, m_transparentIndex)); palette->findBestfit(r2, g2, b2, a2, m_transparentIndex));
@ -201,7 +200,7 @@ doc::color_t OrderedDither2::ditherRgbPixelToIndex(
if (mix) { if (mix) {
if (div) if (div)
mix /= div; mix /= div;
mix = base::clamp(mix, 0, maxMixValue); mix = std::clamp(mix, 0, maxMixValue);
} }
const int rM = r0 + (r1-r0) * mix / maxMixValue; const int rM = r0 + (r1-r0) * mix / maxMixValue;

View File

@ -1,5 +1,5 @@
// Aseprite Render Library // Aseprite Render Library
// Copyright (C) 2019-2021 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -11,7 +11,6 @@
#include "render/render.h" #include "render/render.h"
#include "base/clamp.h"
#include "doc/blend_internals.h" #include "doc/blend_internals.h"
#include "doc/blend_mode.h" #include "doc/blend_mode.h"
#include "doc/doc.h" #include "doc/doc.h"
@ -894,7 +893,7 @@ void Render::renderOnionskin(
m_globalOpacity = m_onionskin.opacityBase() - m_onionskin.opacityStep() * ((frameOut - frame)-1); m_globalOpacity = m_onionskin.opacityBase() - m_onionskin.opacityStep() * ((frameOut - frame)-1);
} }
m_globalOpacity = base::clamp(m_globalOpacity, 0, 255); m_globalOpacity = std::clamp(m_globalOpacity, 0, 255);
if (m_globalOpacity > 0) { if (m_globalOpacity > 0) {
BlendMode blendMode = BlendMode::UNSPECIFIED; BlendMode blendMode = BlendMode::UNSPECIFIED;
if (m_onionskin.type() == OnionskinType::MERGE) if (m_onionskin.type() == OnionskinType::MERGE)

View File

@ -1,5 +1,5 @@
// Aseprite Render Library // Aseprite Render Library
// Copyright (c) 2020 Igara Studio S.A. // Copyright (c) 2020-2022 Igara Studio S.A.
// Copyright (c) 2001-2016 David Capello // Copyright (c) 2001-2016 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -9,10 +9,11 @@
#include "config.h" #include "config.h"
#endif #endif
#include "base/clamp.h"
#include "base/debug.h" #include "base/debug.h"
#include "render/zoom.h" #include "render/zoom.h"
#include <algorithm>
namespace render { namespace render {
static int scales[][2] = { static int scales[][2] = {
@ -105,7 +106,7 @@ Zoom Zoom::fromScale(double scale)
// static // static
Zoom Zoom::fromLinearScale(int i) Zoom Zoom::fromLinearScale(int i)
{ {
i = base::clamp(i, 0, scales_size-1); i = std::clamp(i, 0, scales_size-1);
return Zoom(scales[i][0], scales[i][1]); return Zoom(scales[i][0], scales[i][1]);
} }

View File

@ -1,5 +1,5 @@
// Aseprite UI Library // Aseprite UI Library
// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -35,7 +35,6 @@
#include "ui/alert.h" #include "ui/alert.h"
#include "base/clamp.h"
#include "base/string.h" #include "base/string.h"
#include "ui/box.h" #include "ui/box.h"
#include "ui/button.h" #include "ui/button.h"
@ -46,6 +45,7 @@
#include "ui/slider.h" #include "ui/slider.h"
#include "ui/theme.h" #include "ui/theme.h"
#include <algorithm>
#include <cstdio> #include <cstdio>
namespace ui { namespace ui {
@ -143,7 +143,7 @@ CheckBox* Alert::addCheckBox(const std::string& text)
void Alert::setProgress(double progress) void Alert::setProgress(double progress)
{ {
ASSERT(m_progress); ASSERT(m_progress);
m_progress->setValue(int(base::clamp(progress * 100.0, 0.0, 100.0))); m_progress->setValue(int(std::clamp(progress * 100.0, 0.0, 100.0)));
} }
// static // static

View File

@ -1,5 +1,5 @@
// Aseprite UI Library // Aseprite UI Library
// Copyright (C) 2018-2019 Igara Studio S.A. // Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2017 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -9,7 +9,6 @@
#include "config.h" #include "config.h"
#endif #endif
#include "base/clamp.h"
#include "gfx/size.h" #include "gfx/size.h"
#include "ui/box.h" #include "ui/box.h"
#include "ui/message.h" #include "ui/message.h"
@ -117,8 +116,8 @@ void Box::onResize(ResizeEvent& ev)
} \ } \
\ \
Rect childPos = defChildPos; \ Rect childPos = defChildPos; \
childPos.w = size = base::clamp(size, child->minSize().w, child->maxSize().w); \ childPos.w = size = std::clamp(size, child->minSize().w, child->maxSize().w); \
childPos.h = base::clamp(childPos.h, child->minSize().h, child->maxSize().h); \ childPos.h = std::clamp(childPos.h, child->minSize().h, child->maxSize().h); \
child->setBounds(childPos); \ child->setBounds(childPos); \
\ \
defChildPos.x += size + childSpacing(); \ defChildPos.x += size + childSpacing(); \

View File

@ -11,7 +11,6 @@
#include "ui/combobox.h" #include "ui/combobox.h"
#include "base/clamp.h"
#include "gfx/size.h" #include "gfx/size.h"
#include "os/font.h" #include "os/font.h"
#include "ui/button.h" #include "ui/button.h"
@ -658,7 +657,7 @@ void ComboBox::openListBox()
const int maxVal = const int maxVal =
std::max(entryBounds.y, display()->size().h - entryBounds.y2()) std::max(entryBounds.y, display()->size().h - entryBounds.y2())
- 8*guiscale(); - 8*guiscale();
size.h = base::clamp(size.h, textHeight(), maxVal); size.h = std::clamp(size.h, textHeight(), maxVal);
} }
viewport->setMinSize(size); viewport->setMinSize(size);

View File

@ -11,7 +11,6 @@
#include "ui/entry.h" #include "ui/entry.h"
#include "base/clamp.h"
#include "base/string.h" #include "base/string.h"
#include "os/draw_text.h" #include "os/draw_text.h"
#include "os/font.h" #include "os/font.h"
@ -121,8 +120,8 @@ void Entry::setCaretPos(int pos)
{ {
gfx::Size caretSize = theme()->getEntryCaretSize(this); gfx::Size caretSize = theme()->getEntryCaretSize(this);
int textlen = lastCaretPos(); int textlen = lastCaretPos();
m_caret = base::clamp(pos, 0, textlen); m_caret = std::clamp(pos, 0, textlen);
m_scroll = base::clamp(m_scroll, 0, textlen); m_scroll = std::clamp(m_scroll, 0, textlen);
// Backward scroll // Backward scroll
if (m_caret < m_scroll) if (m_caret < m_scroll)
@ -580,7 +579,7 @@ int Entry::getCaretFromMouse(MouseMessage* mousemsg)
break; break;
} }
return base::clamp(i, 0, lastPos); return std::clamp(i, 0, lastPos);
} }
void Entry::executeCmd(EntryCmd cmd, int unicodeChar, bool shift_pressed) void Entry::executeCmd(EntryCmd cmd, int unicodeChar, bool shift_pressed)
@ -826,7 +825,7 @@ void Entry::backwardWord()
Entry::Range Entry::wordRange(int pos) Entry::Range Entry::wordRange(int pos)
{ {
const int last = lastCaretPos(); const int last = lastCaretPos();
pos = base::clamp(pos, 0, last); pos = std::clamp(pos, 0, last);
int i, j; int i, j;
i = j = pos; i = j = pos;

View File

@ -11,7 +11,6 @@
#include "ui/fit_bounds.h" #include "ui/fit_bounds.h"
#include "base/clamp.h"
#include "gfx/rect.h" #include "gfx/rect.h"
#include "os/screen.h" #include "os/screen.h"
#include "os/system.h" #include "os/system.h"
@ -20,6 +19,8 @@
#include "ui/system.h" #include "ui/system.h"
#include "ui/window.h" #include "ui/window.h"
#include <algorithm>
namespace ui { namespace ui {
#if 0 // TODO unused function, referenced in a comment in this file #if 0 // TODO unused function, referenced in a comment in this file
@ -78,8 +79,8 @@ int fit_bounds(Display* display, int arrowAlign, const gfx::Rect& target, gfx::R
} }
gfx::Size displaySize = display->size(); gfx::Size displaySize = display->size();
bounds.x = base::clamp(bounds.x, 0, displaySize.w-bounds.w); bounds.x = std::clamp(bounds.x, 0, displaySize.w-bounds.w);
bounds.y = base::clamp(bounds.y, 0, displaySize.h-bounds.h); bounds.y = std::clamp(bounds.y, 0, displaySize.h-bounds.h);
if (target.intersects(bounds)) { if (target.intersects(bounds)) {
switch (trycount) { switch (trycount) {
@ -127,8 +128,8 @@ void fit_bounds(const Display* parentDisplay,
if (fitLogic) if (fitLogic)
fitLogic(workarea, frame, [](Widget* widget){ return widget->boundsOnScreen(); }); fitLogic(workarea, frame, [](Widget* widget){ return widget->boundsOnScreen(); });
frame.x = base::clamp(frame.x, workarea.x, workarea.x2() - frame.w); frame.x = std::clamp(frame.x, workarea.x, workarea.x2() - frame.w);
frame.y = base::clamp(frame.y, workarea.y, workarea.y2() - frame.h); frame.y = std::clamp(frame.y, workarea.y, workarea.y2() - frame.h);
// Set frame bounds directly // Set frame bounds directly
window->setBounds(gfx::Rect(0, 0, frame.w / scale, frame.h / scale)); window->setBounds(gfx::Rect(0, 0, frame.w / scale, frame.h / scale));
@ -146,8 +147,8 @@ void fit_bounds(const Display* parentDisplay,
if (fitLogic) if (fitLogic)
fitLogic(displayBounds, frame, [](Widget* widget){ return widget->bounds(); }); fitLogic(displayBounds, frame, [](Widget* widget){ return widget->bounds(); });
frame.x = base::clamp(frame.x, 0, displayBounds.w - frame.w); frame.x = std::clamp(frame.x, 0, displayBounds.w - frame.w);
frame.y = base::clamp(frame.y, 0, displayBounds.h - frame.h); frame.y = std::clamp(frame.y, 0, displayBounds.h - frame.h);
window->setBounds(frame); window->setBounds(frame);
} }

View File

@ -11,7 +11,6 @@
#include "ui/int_entry.h" #include "ui/int_entry.h"
#include "base/clamp.h"
#include "base/scoped_value.h" #include "base/scoped_value.h"
#include "gfx/rect.h" #include "gfx/rect.h"
#include "gfx/region.h" #include "gfx/region.h"
@ -55,12 +54,12 @@ IntEntry::~IntEntry()
int IntEntry::getValue() const int IntEntry::getValue() const
{ {
int value = m_slider.convertTextToValue(text()); int value = m_slider.convertTextToValue(text());
return base::clamp(value, m_min, m_max); return std::clamp(value, m_min, m_max);
} }
void IntEntry::setValue(int value) void IntEntry::setValue(int value)
{ {
value = base::clamp(value, m_min, m_max); value = std::clamp(value, m_min, m_max);
setText(m_slider.convertValueToText(value)); setText(m_slider.convertValueToText(value));
@ -76,7 +75,7 @@ bool IntEntry::onProcessMessage(Message* msg)
// Reset value if it's out of bounds when focus is lost // Reset value if it's out of bounds when focus is lost
case kFocusLeaveMessage: case kFocusLeaveMessage:
setValue(base::clamp(getValue(), m_min, m_max)); setValue(std::clamp(getValue(), m_min, m_max));
deselectText(); deselectText();
break; break;
@ -111,7 +110,7 @@ bool IntEntry::onProcessMessage(Message* msg)
int newValue = oldValue int newValue = oldValue
+ static_cast<MouseMessage*>(msg)->wheelDelta().x + static_cast<MouseMessage*>(msg)->wheelDelta().x
- static_cast<MouseMessage*>(msg)->wheelDelta().y; - static_cast<MouseMessage*>(msg)->wheelDelta().y;
newValue = base::clamp(newValue, m_min, m_max); newValue = std::clamp(newValue, m_min, m_max);
if (newValue != oldValue) { if (newValue != oldValue) {
setValue(newValue); setValue(newValue);
selectAllText(); selectAllText();

View File

@ -11,7 +11,6 @@
#include "ui/listbox.h" #include "ui/listbox.h"
#include "base/clamp.h"
#include "base/fs.h" #include "base/fs.h"
#include "ui/display.h" #include "ui/display.h"
#include "ui/listitem.h" #include "ui/listitem.h"
@ -345,7 +344,7 @@ bool ListBox::onProcessMessage(Message* msg)
return Widget::onProcessMessage(msg); return Widget::onProcessMessage(msg);
} }
selectIndex(base::clamp(select, 0, bottom), msg); selectIndex(std::clamp(select, 0, bottom), msg);
return true; return true;
} }
break; break;
@ -421,7 +420,7 @@ int ListBox::advanceIndexThroughVisibleItems(
const int sgn = SGN(delta); const int sgn = SGN(delta);
int index = startIndex; int index = startIndex;
startIndex = base::clamp(startIndex, 0, bottom); startIndex = std::clamp(startIndex, 0, bottom);
int lastVisibleIndex = startIndex; int lastVisibleIndex = startIndex;
bool cycle = false; bool cycle = false;

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