diff --git a/docs/CODING_STYLE.md b/docs/CODING_STYLE.md index 007b52165..d353bae5b 100644 --- a/docs/CODING_STYLE.md +++ b/docs/CODING_STYLE.md @@ -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) -## 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 `auto` for complex types, iterators, or when the variable type @@ -141,7 +141,8 @@ We are using some modern C++ (C++11, C++14, etc.) features, mainly: * Use template alias (`template alias = orig;`) * Use non-generic lambda functions * Use `std::shared_ptr`, `std::unique_ptr`, or `base::Ref` -* Use `base::clamp` (no `std::clamp` yet) +* Use `std::clamp` +* Use `std::optional` * Use `static constexpr T v = ...;` * You can use ``, ``, ``, and `` * Prefer `using T = ...;` instead of `typedef ... T` diff --git a/laf b/laf index 8e8712200..395a74c99 160000 --- a/laf +++ b/laf @@ -1 +1 @@ -Subproject commit 8e87122007f9e0eafbfd824bfece7ab29118a926 +Subproject commit 395a74c990f4df3889df0b7e140998ba68ea49af diff --git a/src/app/cli/cli_processor.cpp b/src/app/cli/cli_processor.cpp index 3f28ad532..ae38e5b74 100644 --- a/src/app/cli/cli_processor.cpp +++ b/src/app/cli/cli_processor.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2021 Igara Studio S.A. +// Copyright (C) 2018-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -23,7 +23,6 @@ #include "app/filename_formatter.h" #include "app/restore_visible_layers.h" #include "app/ui_context.h" -#include "base/clamp.h" #include "base/convert_to.h" #include "base/fs.h" #include "base/split_string.h" @@ -665,8 +664,8 @@ bool CliProcessor::openFile(Context* ctx, CliOpenFile& cof) // --frame-range with --frame-tag if (tag) { selFrames.insert( - tag->fromFrame()+base::clamp(cof.fromFrame, 0, tag->frames()-1), - tag->fromFrame()+base::clamp(cof.toFrame, 0, tag->frames()-1)); + tag->fromFrame()+std::clamp(cof.fromFrame, 0, tag->frames()-1), + tag->fromFrame()+std::clamp(cof.toFrame, 0, tag->frames()-1)); } // --frame-range without --frame-tag else { diff --git a/src/app/cmd/background_from_layer.cpp b/src/app/cmd/background_from_layer.cpp index 457cf642f..2949f994e 100644 --- a/src/app/cmd/background_from_layer.cpp +++ b/src/app/cmd/background_from_layer.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2020 Igara Studio S.A. +// Copyright (C) 2020-2022 Igara Studio S.A. // Copyright (C) 2001-2016 David Capello // // This program is distributed under the terms of @@ -18,7 +18,6 @@ #include "app/cmd/set_cel_opacity.h" #include "app/cmd/set_cel_position.h" #include "app/doc.h" -#include "base/clamp.h" #include "doc/cel.h" #include "doc/image.h" #include "doc/layer.h" @@ -64,7 +63,7 @@ void BackgroundFromLayer::onExecute() bg_image.get(), cel_image, sprite->palette(cel->frame()), cel->x(), cel->y(), - base::clamp(cel->opacity(), 0, 255), + std::clamp(cel->opacity(), 0, 255), static_cast(layer)->blendMode()); // now we have to copy the new image (bg_image) to the cel... diff --git a/src/app/color.cpp b/src/app/color.cpp index cb9a5c7d9..3a3deaa4c 100644 --- a/src/app/color.cpp +++ b/src/app/color.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2020 Igara Studio S.A. +// Copyright (C) 2020-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -13,7 +13,6 @@ #include "app/color_utils.h" #include "app/modules/palettes.h" -#include "base/clamp.h" #include "base/debug.h" #include "doc/image.h" #include "doc/palette.h" @@ -204,8 +203,8 @@ std::string Color::toString() const << std::setprecision(2) << std::fixed << m_value.hsv.h << "," - << base::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.s*100.0, 0.0, 100.0) << "," + << std::clamp(m_value.hsv.v*100.0, 0.0, 100.0) << "," << m_value.hsv.a << "}"; break; @@ -214,8 +213,8 @@ std::string Color::toString() const << std::setprecision(2) << std::fixed << m_value.hsl.h << "," - << base::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.s*100.0, 0.0, 100.0) << "," + << std::clamp(m_value.hsl.l*100.0, 0.0, 100.0) << "," << m_value.hsl.a << "}"; break; @@ -268,8 +267,8 @@ std::string Color::toHumanReadableString(PixelFormat pixelFormat, HumanReadableS else { result << "HSV " << int(m_value.hsv.h) << "\xc2\xb0 " - << base::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.s*100.0), 0, 100) << "% " + << std::clamp(int(m_value.hsv.v*100.0), 0, 100) << "%"; if (pixelFormat == IMAGE_INDEXED) result << " Index " << color_utils::color_for_image(*this, IMAGE_INDEXED); @@ -288,8 +287,8 @@ std::string Color::toHumanReadableString(PixelFormat pixelFormat, HumanReadableS else { result << "HSL " << int(m_value.hsl.h) << "\xc2\xb0 " - << base::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.s*100.0), 0, 100) << "% " + << std::clamp(int(m_value.hsl.l*100.0), 0, 100) << "%"; if (pixelFormat == IMAGE_INDEXED) result << " Index " << color_utils::color_for_image(*this, IMAGE_INDEXED); @@ -358,8 +357,8 @@ std::string Color::toHumanReadableString(PixelFormat pixelFormat, HumanReadableS } else { result << int(m_value.hsv.h) << "\xc2\xb0" - << base::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.s*100.0), 0, 100) << "," + << std::clamp(int(m_value.hsv.v*100.0), 0, 100); } break; @@ -369,8 +368,8 @@ std::string Color::toHumanReadableString(PixelFormat pixelFormat, HumanReadableS } else { result << int(m_value.hsl.h) << "\xc2\xb0" - << base::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.s*100.0), 0, 100) << "," + << std::clamp(int(m_value.hsl.l*100.0), 0, 100); } break; @@ -908,7 +907,7 @@ int Color::getAlpha() const void Color::setAlpha(int alpha) { - alpha = base::clamp(alpha, 0, 255); + alpha = std::clamp(alpha, 0, 255); switch (getType()) { diff --git a/src/app/commands/cmd_canvas_size.cpp b/src/app/commands/cmd_canvas_size.cpp index 09f86f1f4..0bcf5667f 100644 --- a/src/app/commands/cmd_canvas_size.cpp +++ b/src/app/commands/cmd_canvas_size.cpp @@ -23,7 +23,6 @@ #include "app/ui/editor/select_box_state.h" #include "app/ui/skin/skin_theme.h" #include "app/ui_context.h" -#include "base/clamp.h" #include "doc/image.h" #include "doc/mask.h" #include "doc/sprite.h" diff --git a/src/app/commands/cmd_cel_opacity.cpp b/src/app/commands/cmd_cel_opacity.cpp index c8da4ebf8..6a3ec9c3b 100644 --- a/src/app/commands/cmd_cel_opacity.cpp +++ b/src/app/commands/cmd_cel_opacity.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2020 Igara Studio S.A. +// Copyright (C) 2020-2022 Igara Studio S.A. // Copyright (C) 2018 David Capello // // This program is distributed under the terms of @@ -19,7 +19,6 @@ #include "app/modules/gui.h" #include "app/tx.h" #include "app/ui/timeline/timeline.h" -#include "base/clamp.h" #include "doc/cel.h" #include "doc/cels_range.h" #include "doc/sprite.h" @@ -53,7 +52,7 @@ CelOpacityCommand::CelOpacityCommand() void CelOpacityCommand::onLoadParams(const Params& params) { m_opacity = params.get_as("opacity"); - m_opacity = base::clamp(m_opacity, 0, 255); + m_opacity = std::clamp(m_opacity, 0, 255); } bool CelOpacityCommand::onEnabled(Context* context) diff --git a/src/app/commands/cmd_export_sprite_sheet.cpp b/src/app/commands/cmd_export_sprite_sheet.cpp index 04ea2e988..22828172f 100644 --- a/src/app/commands/cmd_export_sprite_sheet.cpp +++ b/src/app/commands/cmd_export_sprite_sheet.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -32,7 +32,6 @@ #include "app/ui/optional_alert.h" #include "app/ui/status_bar.h" #include "app/ui/timeline/timeline.h" -#include "base/clamp.h" #include "base/convert_to.h" #include "base/fs.h" #include "base/string.h" @@ -184,9 +183,9 @@ Doc* generate_sprite_sheet_from_params( const std::string filenameFormat = params.filenameFormat(); const std::string layerName = params.layer(); const std::string tagName = params.tag(); - const int borderPadding = base::clamp(params.borderPadding(), 0, 100); - const int shapePadding = base::clamp(params.shapePadding(), 0, 100); - const int innerPadding = base::clamp(params.innerPadding(), 0, 100); + const int borderPadding = std::clamp(params.borderPadding(), 0, 100); + const int shapePadding = std::clamp(params.shapePadding(), 0, 100); + const int innerPadding = std::clamp(params.innerPadding(), 0, 100); const bool trimSprite = params.trimSprite(); const bool trimCels = params.trim(); const bool trimByGrid = params.trimByGrid(); @@ -666,17 +665,17 @@ private: int borderPaddingValue() const { int value = borderPadding()->textInt(); - return base::clamp(value, 0, 100); + return std::clamp(value, 0, 100); } int shapePaddingValue() const { int value = shapePadding()->textInt(); - return base::clamp(value, 0, 100); + return std::clamp(value, 0, 100); } int innerPaddingValue() const { int value = innerPadding()->textInt(); - return base::clamp(value, 0, 100); + return std::clamp(value, 0, 100); } bool trimSpriteValue() const { diff --git a/src/app/commands/cmd_goto_frame.cpp b/src/app/commands/cmd_goto_frame.cpp index ffeb3307a..d214dc156 100644 --- a/src/app/commands/cmd_goto_frame.cpp +++ b/src/app/commands/cmd_goto_frame.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -18,7 +18,6 @@ #include "app/ui/editor/editor.h" #include "app/ui/editor/editor_customization_delegate.h" #include "app/ui/search_entry.h" -#include "base/clamp.h" #include "doc/sprite.h" #include "doc/tag.h" #include "ui/combobox.h" @@ -257,7 +256,7 @@ private: } } - return base::clamp( + return std::clamp( m_frame-docPref.timeline.firstFrame(), 0, editor->sprite()->lastFrame()); } diff --git a/src/app/commands/cmd_layer_opacity.cpp b/src/app/commands/cmd_layer_opacity.cpp index d4a56ab0a..96cf7e2b1 100644 --- a/src/app/commands/cmd_layer_opacity.cpp +++ b/src/app/commands/cmd_layer_opacity.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2020 Igara Studio S.A. +// Copyright (C) 2020-2022 Igara Studio S.A. // Copyright (C) 2016-2018 David Capello // // This program is distributed under the terms of @@ -19,7 +19,6 @@ #include "app/modules/gui.h" #include "app/tx.h" #include "app/ui/timeline/timeline.h" -#include "base/clamp.h" #include "doc/layer.h" #include "fmt/format.h" @@ -51,7 +50,7 @@ LayerOpacityCommand::LayerOpacityCommand() void LayerOpacityCommand::onLoadParams(const Params& params) { m_opacity = params.get_as("opacity"); - m_opacity = base::clamp(m_opacity, 0, 255); + m_opacity = std::clamp(m_opacity, 0, 255); } bool LayerOpacityCommand::onEnabled(Context* context) diff --git a/src/app/commands/cmd_modify_selection.cpp b/src/app/commands/cmd_modify_selection.cpp index 399ed222d..1342f42ba 100644 --- a/src/app/commands/cmd_modify_selection.cpp +++ b/src/app/commands/cmd_modify_selection.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2015-2018 David Capello // // This program is distributed under the terms of @@ -18,7 +18,6 @@ #include "app/modules/gui.h" #include "app/pref/preferences.h" #include "app/tx.h" -#include "base/clamp.h" #include "base/convert_to.h" #include "doc/algorithm/modify_selection.h" #include "doc/brush_type.h" @@ -113,7 +112,7 @@ void ModifySelectionCommand::onExecute(Context* context) return; quantity = window.quantity()->textInt(); - quantity = base::clamp(quantity, 1, 100); + quantity = std::clamp(quantity, 1, 100); brush = (window.circle()->isSelected() ? doc::kCircleBrushType: doc::kSquareBrushType); diff --git a/src/app/commands/cmd_new_file.cpp b/src/app/commands/cmd_new_file.cpp index 83d327c9f..0d9373c4d 100644 --- a/src/app/commands/cmd_new_file.cpp +++ b/src/app/commands/cmd_new_file.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2020 Igara Studio S.A. +// Copyright (C) 2018-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -27,7 +27,6 @@ #include "app/util/clipboard.h" #include "app/util/clipboard.h" #include "app/util/pixel_ratio.h" -#include "base/clamp.h" #include "doc/cel.h" #include "doc/image.h" #include "doc/layer.h" @@ -128,7 +127,7 @@ void NewFileCommand::onExecute(Context* ctx) int w = pref.newFile.width(); int h = pref.newFile.height(); 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 // clipboard as default image size. @@ -190,10 +189,10 @@ void NewFileCommand::onExecute(Context* ctx) static_assert(int(ColorMode::RGB) == 0, "RGB pixel format should be 0"); static_assert(int(ColorMode::INDEXED) == 2, "Indexed pixel format should be 2"); - colorMode = base::clamp(colorMode, ColorMode::RGB, ColorMode::INDEXED); - w = base::clamp(w, 1, DOC_SPRITE_MAX_WIDTH); - h = base::clamp(h, 1, DOC_SPRITE_MAX_HEIGHT); - bg = base::clamp(bg, 0, 2); + colorMode = std::clamp(colorMode, ColorMode::RGB, ColorMode::INDEXED); + w = std::clamp(w, 1, DOC_SPRITE_MAX_WIDTH); + h = std::clamp(h, 1, DOC_SPRITE_MAX_HEIGHT); + bg = std::clamp(bg, 0, 2); // Select the background color if (bg >= 0 && bg <= 3) { diff --git a/src/app/commands/cmd_options.cpp b/src/app/commands/cmd_options.cpp index 286a45963..0403c524f 100644 --- a/src/app/commands/cmd_options.cpp +++ b/src/app/commands/cmd_options.cpp @@ -32,7 +32,6 @@ #include "app/ui/sampling_selector.h" #include "app/ui/separator_in_view.h" #include "app/ui/skin/skin_theme.h" -#include "base/clamp.h" #include "base/convert_to.h" #include "base/fs.h" #include "base/string.h" @@ -724,7 +723,7 @@ public: int undo_size_limit_value; 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.gotoModified(undoGotoModified()->isSelected()); diff --git a/src/app/commands/cmd_palette_size.cpp b/src/app/commands/cmd_palette_size.cpp index ff6fb21cb..3975a56e3 100644 --- a/src/app/commands/cmd_palette_size.cpp +++ b/src/app/commands/cmd_palette_size.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -14,7 +14,6 @@ #include "app/commands/params.h" #include "app/context_access.h" #include "app/tx.h" -#include "base/clamp.h" #include "doc/palette.h" #include "doc/sprite.h" @@ -70,7 +69,7 @@ void PaletteSizeCommand::onExecute(Context* context) if (ncolors == palette.size()) return; - palette.resize(base::clamp(ncolors, 1, std::numeric_limits::max())); + palette.resize(std::clamp(ncolors, 1, std::numeric_limits::max())); ContextWriter writer(reader); Tx tx(context, "Palette Size", ModifyDocument); diff --git a/src/app/commands/cmd_paste_text.cpp b/src/app/commands/cmd_paste_text.cpp index fdbc7fb70..92950611e 100644 --- a/src/app/commands/cmd_paste_text.cpp +++ b/src/app/commands/cmd_paste_text.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -21,7 +21,6 @@ #include "app/ui/font_popup.h" #include "app/ui/timeline/timeline.h" #include "app/util/freetype_utils.h" -#include "base/clamp.h" #include "base/fs.h" #include "base/string.h" #include "doc/image.h" @@ -80,7 +79,7 @@ public: int sizeValue() const { int size = fontSize()->textInt(); - size = base::clamp(size, 1, 5000); + size = std::clamp(size, 1, 5000); return size; } @@ -165,7 +164,7 @@ void PasteTextCommand::onExecute(Context* ctx) bool antialias = window.antialias()->isSelected(); std::string faceName = window.faceValue(); int size = window.sizeValue(); - size = base::clamp(size, 1, 999); + size = std::clamp(size, 1, 999); pref.textTool.fontFace(faceName); pref.textTool.fontSize(size); pref.textTool.antialias(antialias); diff --git a/src/app/commands/cmd_sprite_size.cpp b/src/app/commands/cmd_sprite_size.cpp index 98dd7aa6a..1adac4622 100644 --- a/src/app/commands/cmd_sprite_size.cpp +++ b/src/app/commands/cmd_sprite_size.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -20,7 +20,6 @@ #include "app/modules/palettes.h" #include "app/sprite_job.h" #include "app/util/resize_image.h" -#include "base/clamp.h" #include "base/convert_to.h" #include "doc/algorithm/resize_image.h" #include "doc/cel.h" @@ -386,8 +385,8 @@ void SpriteSizeCommand::onExecute(Context* context) } #endif // ENABLE_UI - new_width = base::clamp(new_width, 1, DOC_SPRITE_MAX_WIDTH); - new_height = base::clamp(new_height, 1, DOC_SPRITE_MAX_HEIGHT); + new_width = std::clamp(new_width, 1, DOC_SPRITE_MAX_WIDTH); + new_height = std::clamp(new_height, 1, DOC_SPRITE_MAX_HEIGHT); { SpriteSizeJob job(reader, new_width, new_height, resize_method); diff --git a/src/app/commands/debugger.cpp b/src/app/commands/debugger.cpp index 16ad7bffe..32d6ebbfd 100644 --- a/src/app/commands/debugger.cpp +++ b/src/app/commands/debugger.cpp @@ -18,7 +18,6 @@ #include "app/context.h" #include "app/script/engine.h" #include "app/ui/skin/skin_theme.h" -#include "base/clamp.h" #include "base/convert_to.h" #include "base/file_content.h" #include "base/fs.h" diff --git a/src/app/commands/filters/cmd_despeckle.cpp b/src/app/commands/filters/cmd_despeckle.cpp index 1f479f215..6231bcda1 100644 --- a/src/app/commands/filters/cmd_despeckle.cpp +++ b/src/app/commands/filters/cmd_despeckle.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -21,7 +21,6 @@ #include "app/ini_file.h" #include "app/load_widget.h" #include "app/pref/preferences.h" -#include "base/clamp.h" #include "doc/mask.h" #include "doc/sprite.h" #include "filters/median_filter.h" @@ -78,8 +77,8 @@ private: m_heightEntry->textInt()); // Avoid negative numbers - newSize.w = base::clamp(newSize.w, 1, 100); - newSize.h = base::clamp(newSize.h, 1, 100); + newSize.w = std::clamp(newSize.w, 1, 100); + newSize.h = std::clamp(newSize.h, 1, 100); // If we had a previous filter preview running in the background, // we explicitly request it be stopped. Otherwise, changing the diff --git a/src/app/commands/filters/color_curve_editor.cpp b/src/app/commands/filters/color_curve_editor.cpp index 637156694..135d619fe 100644 --- a/src/app/commands/filters/color_curve_editor.cpp +++ b/src/app/commands/filters/color_curve_editor.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -11,7 +11,6 @@ #include "app/commands/filters/color_curve_editor.h" -#include "base/clamp.h" #include "filters/color_curve.h" #include "ui/alert.h" #include "ui/entry.h" @@ -140,8 +139,8 @@ bool ColorCurveEditor::onProcessMessage(Message* msg) if (m_editPoint) { gfx::Point mousePos = static_cast(msg)->position(); *m_editPoint = screenToView(mousePos); - m_editPoint->x = base::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->x = std::clamp(m_editPoint->x, m_viewBounds.x, m_viewBounds.x2()-1); + m_editPoint->y = std::clamp(m_editPoint->y, m_viewBounds.y, m_viewBounds.y2()-1); // TODO this should be optional CurveEditorChange(); @@ -209,9 +208,9 @@ void ColorCurveEditor::onPaint(ui::PaintEvent& ev) // Draw curve for (c = client.x; c < client.x+client.w; ++c) { 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 = 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); 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()) { viewPt.x = window.x()->textInt(); viewPt.y = window.y()->textInt(); - viewPt.x = base::clamp(viewPt.x, 0, 255); - viewPt.y = base::clamp(viewPt.y, 0, 255); + viewPt.x = std::clamp(viewPt.x, 0, 255); + viewPt.y = std::clamp(viewPt.y, 0, 255); return true; } else if (window.closer() == window.deleteButton()) { diff --git a/src/app/crash/read_document.cpp b/src/app/crash/read_document.cpp index fd41c45f3..920428b7e 100644 --- a/src/app/crash/read_document.cpp +++ b/src/app/crash/read_document.cpp @@ -14,7 +14,6 @@ #include "app/console.h" #include "app/crash/internals.h" #include "app/doc.h" -#include "base/clamp.h" #include "base/convert_to.h" #include "base/exception.h" #include "base/fs.h" @@ -540,8 +539,8 @@ Doc* read_document_with_raw_images(const std::string& dir, info.height = 256; info.filename = "Unknown"; } - info.width = base::clamp(info.width, 1, 99999); - info.height = base::clamp(info.height, 1, 99999); + info.width = std::clamp(info.width, 1, 99999); + info.height = std::clamp(info.height, 1, 99999); Sprite* spr = new Sprite(ImageSpec(info.mode, info.width, info.height), 256); // Load each image as a new frame diff --git a/src/app/doc_exporter.cpp b/src/app/doc_exporter.cpp index 925fde0e0..5385394ef 100644 --- a/src/app/doc_exporter.cpp +++ b/src/app/doc_exporter.cpp @@ -20,7 +20,6 @@ #include "app/restore_visible_layers.h" #include "app/snap_to_grid.h" #include "app/util/autocrop.h" -#include "base/clamp.h" #include "base/convert_to.h" #include "base/fs.h" #include "base/fstream_path.h" @@ -127,7 +126,7 @@ int DocExporter::Item::frames() const return selFrames->size(); else if (tag) { int result = tag->toFrame() - tag->fromFrame() + 1; - return base::clamp(result, 1, doc->sprite()->totalFrames()); + return std::clamp(result, 1, doc->sprite()->totalFrames()); } else return doc->sprite()->totalFrames(); @@ -140,8 +139,8 @@ doc::SelectedFrames DocExporter::Item::getSelectedFrames() const doc::SelectedFrames frames; if (tag) { - frames.insert(base::clamp(tag->fromFrame(), 0, doc->sprite()->lastFrame()), - base::clamp(tag->toFrame(), 0, doc->sprite()->lastFrame())); + frames.insert(std::clamp(tag->fromFrame(), 0, doc->sprite()->lastFrame()), + std::clamp(tag->toFrame(), 0, doc->sprite()->lastFrame())); } else { frames.insert(0, doc->sprite()->lastFrame()); diff --git a/src/app/file/ase_format.cpp b/src/app/file/ase_format.cpp index 155a24942..b2663923c 100644 --- a/src/app/file/ase_format.cpp +++ b/src/app/file/ase_format.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2020 Igara Studio S.A. +// Copyright (C) 2018-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -16,7 +16,6 @@ #include "app/file/format_options.h" #include "app/pref/preferences.h" #include "base/cfile.h" -#include "base/clamp.h" #include "base/exception.h" #include "base/file_handle.h" #include "base/fs.h" @@ -964,8 +963,8 @@ static void ase_file_write_tags_chunk(FILE* f, tag->toFrame() < fromFrame) continue; - frame_t from = base::clamp(tag->fromFrame()-fromFrame, 0, toFrame-fromFrame); - frame_t to = base::clamp(tag->toFrame()-fromFrame, from, toFrame-fromFrame); + frame_t from = std::clamp(tag->fromFrame()-fromFrame, 0, toFrame-fromFrame); + frame_t to = std::clamp(tag->toFrame()-fromFrame, from, toFrame-fromFrame); fputw(from, f); fputw(to, f); diff --git a/src/app/file/jpeg_format.cpp b/src/app/file/jpeg_format.cpp index 274417b4e..3d7e55dde 100644 --- a/src/app/file/jpeg_format.cpp +++ b/src/app/file/jpeg_format.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2021 Igara Studio S.A. +// Copyright (C) 2018-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -19,7 +19,6 @@ #include "app/find_widget.h" #include "app/load_widget.h" #include "app/pref/preferences.h" -#include "base/clamp.h" #include "base/file_handle.h" #include "base/memory.h" #include "doc/doc.h" @@ -358,7 +357,7 @@ bool JpegFormat::onSave(FileOp* fop) JDIMENSION buffer_height; const auto jpeg_options = std::static_pointer_cast(fop->formatOptions()); 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); int c; diff --git a/src/app/file/palette_file.cpp b/src/app/file/palette_file.cpp index 56ad98fb2..fa52799bb 100644 --- a/src/app/file/palette_file.cpp +++ b/src/app/file/palette_file.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2021 Igara Studio S.A. +// Copyright (C) 2018-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -14,7 +14,6 @@ #include "app/file/file.h" #include "app/file/file_format.h" #include "app/file/file_formats_manager.h" -#include "base/clamp.h" #include "base/fs.h" #include "base/string.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)) 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); Context tmpContext; diff --git a/src/app/file/png_format.cpp b/src/app/file/png_format.cpp index 0b0a9ecf8..3f456dd2b 100644 --- a/src/app/file/png_format.cpp +++ b/src/app/file/png_format.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2020 Igara Studio S.A. +// Copyright (C) 2018-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -16,7 +16,6 @@ #include "app/file/format_options.h" #include "app/file/png_format.h" #include "app/file/png_options.h" -#include "base/clamp.h" #include "base/file_handle.h" #include "doc/doc.h" #include "gfx/color_space.h" @@ -614,7 +613,7 @@ bool PngFormat::onSave(FileOp* fop) if (color_type == PNG_COLOR_TYPE_PALETTE) { int c, r, g, b; 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 #error PNG_MAX_PALETTE_LENGTH should be 256 diff --git a/src/app/file/svg_format.cpp b/src/app/file/svg_format.cpp index f12fb4d9a..6e49cfc15 100644 --- a/src/app/file/svg_format.cpp +++ b/src/app/file/svg_format.cpp @@ -1,5 +1,5 @@ // 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 // the End-User License Agreement for Aseprite. @@ -17,7 +17,6 @@ #include "app/file/format_options.h" #include "app/pref/preferences.h" #include "base/cfile.h" -#include "base/clamp.h" #include "base/file_handle.h" #include "doc/doc.h" #include "ui/window.h" @@ -85,7 +84,7 @@ bool SvgFormat::onSave(FileOp* fop) const Image* image = fop->sequenceImage(); int x, y, c, r, g, b, a, alpha; const auto svg_options = std::static_pointer_cast(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")); FILE* f = handle.get(); auto printcol = [f](int x, int y,int r, int g, int b, int a, int pxScale) { diff --git a/src/app/file/webp_format.cpp b/src/app/file/webp_format.cpp index c1713d64f..8b4906ab6 100644 --- a/src/app/file/webp_format.cpp +++ b/src/app/file/webp_format.cpp @@ -1,5 +1,5 @@ // 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 Gabriel Rauter // @@ -20,7 +20,6 @@ #include "app/file/webp_options.h" #include "app/ini_file.h" #include "app/pref/preferences.h" -#include "base/clamp.h" #include "base/convert_to.h" #include "base/file_handle.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); 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); if (fop->isStop()) diff --git a/src/app/modules/gui.cpp b/src/app/modules/gui.cpp index f7216a14e..66636f74c 100644 --- a/src/app/modules/gui.cpp +++ b/src/app/modules/gui.cpp @@ -37,7 +37,6 @@ #include "app/ui/toolbar.h" #include "app/ui_context.h" #include "app/util/open_batch.h" -#include "base/clamp.h" #include "base/fs.h" #include "base/memory.h" #include "base/string.h" @@ -130,7 +129,7 @@ static bool create_main_window(bool gpuAccel, try { if (!spec.frame().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); } } @@ -395,16 +394,16 @@ void load_window_pos(Widget* window, const char* section, pos = get_config_rect(section, "WindowPos", pos); if (limitMinSize) { - pos.w = base::clamp(pos.w, orig_pos.w, ui::display_w()); - pos.h = base::clamp(pos.h, orig_pos.h, ui::display_h()); + pos.w = std::clamp(pos.w, orig_pos.w, ui::display_w()); + pos.h = std::clamp(pos.h, orig_pos.h, ui::display_h()); } else { pos.w = std::min(pos.w, ui::display_w()); pos.h = std::min(pos.h, ui::display_h()); } - pos.setOrigin(Point(base::clamp(pos.x, 0, ui::display_w()-pos.w), - base::clamp(pos.y, 0, ui::display_h()-pos.h))); + pos.setOrigin(Point(std::clamp(pos.x, 0, ui::display_w()-pos.w), + std::clamp(pos.y, 0, ui::display_h()-pos.h))); window->setBounds(pos); } diff --git a/src/app/script/app_object.cpp b/src/app/script/app_object.cpp index cbb93d882..c2323904f 100644 --- a/src/app/script/app_object.cpp +++ b/src/app/script/app_object.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2021 Igara Studio S.A. +// Copyright (C) 2018-2022 Igara Studio S.A. // Copyright (C) 2015-2018 David Capello // // This program is distributed under the terms of @@ -37,7 +37,6 @@ #include "app/ui/editor/tool_loop_impl.h" #include "app/ui/timeline/timeline.h" #include "app/ui_context.h" -#include "base/clamp.h" #include "base/fs.h" #include "base/replace_string.h" #include "base/version.h" @@ -370,14 +369,14 @@ int App_useTool(lua_State* L) type = lua_getfield(L, 1, "opacity"); if (type != LUA_TNIL) { 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); type = lua_getfield(L, 1, "tolerance"); if (type != LUA_TNIL) { 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); diff --git a/src/app/script/layer_class.cpp b/src/app/script/layer_class.cpp index ed1844fd5..eb397bbc4 100644 --- a/src/app/script/layer_class.cpp +++ b/src/app/script/layer_class.cpp @@ -19,7 +19,6 @@ #include "app/script/luacpp.h" #include "app/script/userdata.h" #include "app/tx.h" -#include "base/clamp.h" #include "doc/layer.h" #include "doc/sprite.h" @@ -272,7 +271,7 @@ int Layer_set_stackIndex(lua_State* L) } 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 { beforeThis = nullptr; diff --git a/src/app/site.cpp b/src/app/site.cpp index 29ec340b1..a8aa66b53 100644 --- a/src/app/site.cpp +++ b/src/app/site.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -12,7 +12,6 @@ #include "app/site.h" #include "app/pref/preferences.h" -#include "base/clamp.h" #include "doc/cel.h" #include "doc/layer.h" #include "doc/sprite.h" @@ -57,7 +56,7 @@ Image* Site::image(int* x, int* y, int* opacity) const image = cel->image(); if (x) *x = cel->x(); if (y) *y = cel->y(); - if (opacity) *opacity = base::clamp(cel->opacity(), 0, 255); + if (opacity) *opacity = std::clamp(cel->opacity(), 0, 255); } } diff --git a/src/app/thumbnail_generator.cpp b/src/app/thumbnail_generator.cpp index 725ef3c84..c8c0942f2 100644 --- a/src/app/thumbnail_generator.cpp +++ b/src/app/thumbnail_generator.cpp @@ -17,7 +17,6 @@ #include "app/file/file.h" #include "app/file_system.h" #include "app/util/conversion_to_surface.h" -#include "base/clamp.h" #include "base/thread.h" #include "doc/algorithm/rotate.h" #include "doc/image.h" @@ -126,8 +125,8 @@ private: thumb_w = w; thumb_h = h; } - thumb_w = base::clamp(thumb_w, 1, MAX_THUMBNAIL_SIZE); - thumb_h = base::clamp(thumb_h, 1, MAX_THUMBNAIL_SIZE); + thumb_w = std::clamp(thumb_w, 1, MAX_THUMBNAIL_SIZE); + thumb_h = std::clamp(thumb_h, 1, MAX_THUMBNAIL_SIZE); // Stretch the 'image' thumbnailImage.reset( diff --git a/src/app/tools/ink_processing.h b/src/app/tools/ink_processing.h index df2b4564b..a9fd4aa3c 100644 --- a/src/app/tools/ink_processing.h +++ b/src/app/tools/ink_processing.h @@ -8,7 +8,6 @@ #include "app/color_utils.h" #include "app/util/wrap_point.h" #include "app/util/wrap_value.h" -#include "base/clamp.h" #include "doc/blend_funcs.h" #include "doc/blend_internals.h" #include "doc/image_impl.h" @@ -678,8 +677,8 @@ private: m_srcImageHeight), pt, false); - pt.x = base::clamp(pt.x, 0, m_srcImageWidth-1); - pt.y = base::clamp(pt.y, 0, m_srcImageHeight-1); + pt.x = std::clamp(pt.x, 0, m_srcImageWidth-1); + pt.y = std::clamp(pt.y, 0, m_srcImageHeight-1); m_color = get_pixel(m_srcImage, pt.x, pt.y); } diff --git a/src/app/tools/point_shapes.h b/src/app/tools/point_shapes.h index e2e95a911..21373001e 100644 --- a/src/app/tools/point_shapes.h +++ b/src/app/tools/point_shapes.h @@ -139,8 +139,8 @@ public: } // Dynamic size and angle - int size = base::clamp(int(pt.size), int(Brush::kMinBrushSize), int(Brush::kMaxBrushSize)); - int angle = base::clamp(int(pt.angle), -180, 180); + int size = std::clamp(int(pt.size), int(Brush::kMinBrushSize), int(Brush::kMaxBrushSize)); + int angle = std::clamp(int(pt.angle), -180, 180); if ((brush->size() != size) || (brush->angle() != angle && m_origBrushType != kCircleBrushType) || (m_hasDynamicGradient && pt.gradient != m_lastGradientValue)) { diff --git a/src/app/tools/tool_loop_manager.cpp b/src/app/tools/tool_loop_manager.cpp index a925677f8..591ad0a3d 100644 --- a/src/app/tools/tool_loop_manager.cpp +++ b/src/app/tools/tool_loop_manager.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -20,7 +20,6 @@ #include "app/tools/symmetry.h" #include "app/tools/tool_loop.h" #include "app/tools/velocity.h" -#include "base/clamp.h" #include "doc/brush.h" #include "doc/image.h" #include "doc/primitives.h" @@ -29,6 +28,7 @@ #include "gfx/rect_io.h" #include "gfx/region.h" +#include #include #define TOOL_TRACE(...) // TRACEARGS @@ -421,11 +421,11 @@ void ToolLoopManager::adjustPointWithDynamics(const Pointer& pointer, } } ASSERT(p >= 0.0f && p <= 1.0f); - p = base::clamp(p, 0.0f, 1.0f); + p = std::clamp(p, 0.0f, 1.0f); // Velocity 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) { v = 0.0f; } @@ -440,7 +440,7 @@ void ToolLoopManager::adjustPointWithDynamics(const Pointer& pointer, (m_dynamics.maxVelocityThreshold - m_dynamics.minVelocityThreshold); } 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) { case DynamicSensor::Pressure: @@ -469,8 +469,8 @@ void ToolLoopManager::adjustPointWithDynamics(const Pointer& pointer, break; } - pt.size = base::clamp(size, int(Brush::kMinBrushSize), int(Brush::kMaxBrushSize)); - pt.angle = base::clamp(angle, -180, 180); + pt.size = std::clamp(size, int(Brush::kMinBrushSize), int(Brush::kMaxBrushSize)); + pt.angle = std::clamp(angle, -180, 180); } } // namespace tools diff --git a/src/app/tools/velocity.cpp b/src/app/tools/velocity.cpp index 4d3548612..461d3d3db 100644 --- a/src/app/tools/velocity.cpp +++ b/src/app/tools/velocity.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2020 Igara Studio S.A. +// Copyright (C) 2020-2022 Igara Studio S.A. // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -10,7 +10,7 @@ #include "app/tools/velocity.h" -#include "base/clamp.h" +#include namespace app { namespace tools { @@ -39,7 +39,7 @@ void VelocitySensor::updateWithScreenPoint(const gfx::Point& screenPoint) else { 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.y = (1.0f-a)*m_velocity.y + a*newVelocity.y; } diff --git a/src/app/ui/color_bar.cpp b/src/app/ui/color_bar.cpp index 38e5b4e14..98bfb4313 100644 --- a/src/app/ui/color_bar.cpp +++ b/src/app/ui/color_bar.cpp @@ -50,7 +50,6 @@ #include "app/ui_context.h" #include "app/ui_context.h" #include "app/util/clipboard.h" -#include "base/clamp.h" #include "base/scoped_value.h" #include "doc/cel.h" #include "doc/cels_range.h" @@ -1232,7 +1231,7 @@ void ColorBar::fixColorIndex(ColorButton& colorButton) if (color.getType() == Color::IndexType) { 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) { color = Color::fromIndex(newIndex); colorButton.setColor(color); diff --git a/src/app/ui/color_button.cpp b/src/app/ui/color_button.cpp index 19b2e6301..56cd4c05e 100644 --- a/src/app/ui/color_button.cpp +++ b/src/app/ui/color_button.cpp @@ -23,7 +23,6 @@ #include "app/ui/skin/skin_theme.h" #include "app/ui/status_bar.h" #include "app/ui_context.h" -#include "base/clamp.h" #include "doc/layer.h" #include "doc/sprite.h" #include "gfx/rect_io.h" @@ -312,7 +311,7 @@ void ColorButton::openPopup(const bool forcePinned) if (!pinned || (forcePinned && m_hiddenPopupBounds.isEmpty())) { winBounds = gfx::Rect(m_window->bounds().origin(), m_window->sizeHint()); - winBounds.x = base::clamp(bounds().x, 0, ui::display_w()-winBounds.w); + winBounds.x = std::clamp(bounds().x, 0, ui::display_w()-winBounds.w); if (bounds().y2() <= ui::display_h()-winBounds.h) winBounds.y = std::max(0, bounds().y2()); else @@ -324,8 +323,8 @@ void ColorButton::openPopup(const bool forcePinned) else { winBounds = m_windowDefaultBounds; } - winBounds.x = base::clamp(winBounds.x, 0, ui::display_w()-winBounds.w); - winBounds.y = base::clamp(winBounds.y, 0, ui::display_h()-winBounds.h); + winBounds.x = std::clamp(winBounds.x, 0, ui::display_w()-winBounds.w); + winBounds.y = std::clamp(winBounds.y, 0, ui::display_h()-winBounds.h); m_window->setBounds(winBounds); m_window->manager()->dispatchMessages(); diff --git a/src/app/ui/color_selector.cpp b/src/app/ui/color_selector.cpp index 50ca45476..58c263f47 100644 --- a/src/app/ui/color_selector.cpp +++ b/src/app/ui/color_selector.cpp @@ -21,7 +21,6 @@ #include "app/ui/skin/skin_theme.h" #include "app/ui/status_bar.h" #include "app/util/shader_helpers.h" -#include "base/clamp.h" #include "base/concurrent_queue.h" #include "base/scoped_value.h" #include "base/thread.h" @@ -299,7 +298,7 @@ app::Color ColorSelector::getAlphaBarColor(const int u, const int umax) { int alpha = (255 * u / umax); app::Color color = m_color; - color.setAlpha(base::clamp(alpha, 0, 255)); + color.setAlpha(std::clamp(alpha, 0, 255)); return color; } diff --git a/src/app/ui/color_shades.cpp b/src/app/ui/color_shades.cpp index 5d5c5971e..29598156d 100644 --- a/src/app/ui/color_shades.cpp +++ b/src/app/ui/color_shades.cpp @@ -17,7 +17,6 @@ #include "app/shade.h" #include "app/ui/color_bar.h" #include "app/ui/skin/skin_theme.h" -#include "base/clamp.h" #include "doc/color_mode.h" #include "doc/palette.h" #include "doc/palette_picks.h" @@ -27,8 +26,8 @@ #include "ui/paint_event.h" #include "ui/size_hint_event.h" #include "ui/system.h" -#include +#include namespace app { @@ -213,7 +212,7 @@ bool ColorShades::onProcessMessage(ui::Message* msg) int count = std::max(1, size()); int boxWidth = std::max(1, bounds.w / count); hot = (mousePos.x - bounds.x) / boxWidth; - hot = base::clamp(hot, 0, count-1); + hot = std::clamp(hot, 0, count-1); } if (m_hotIndex != hot) { diff --git a/src/app/ui/color_sliders.cpp b/src/app/ui/color_sliders.cpp index 9773e2df4..7bec9ac41 100644 --- a/src/app/ui/color_sliders.cpp +++ b/src/app/ui/color_sliders.cpp @@ -185,7 +185,7 @@ namespace { else ++value; - setTextf("%d", base::clamp(value, minValue(), maxValue())); + setTextf("%d", std::clamp(value, minValue(), maxValue())); selectAllText(); onChange(); @@ -461,7 +461,7 @@ void ColorSliders::onEntryChange(const Channel i) Slider* slider = (m_mode == Mode::Absolute ? m_items[i].absSlider: m_items[i].relSlider); - value = base::clamp(value, slider->getMinValue(), slider->getMaxValue()); + value = std::clamp(value, slider->getMinValue(), slider->getMaxValue()); slider->setValue(value); onControlChange(i); diff --git a/src/app/ui/color_spectrum.cpp b/src/app/ui/color_spectrum.cpp index 8d8619012..704e84645 100644 --- a/src/app/ui/color_spectrum.cpp +++ b/src/app/ui/color_spectrum.cpp @@ -15,7 +15,6 @@ #include "app/ui/skin/skin_theme.h" #include "app/ui/status_bar.h" #include "app/util/shader_helpers.h" -#include "base/clamp.h" #include "os/surface.h" #include "ui/graphics.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 lit = 1.0 - (double(v)/double(vmax)); return app::Color::fromHsl( - base::clamp(hue, 0.0, 360.0), + std::clamp(hue, 0.0, 360.0), m_color.getHslSaturation(), - base::clamp(lit, 0.0, 1.0), + std::clamp(lit, 0.0, 1.0), getCurrentAlphaForNewColor()); } @@ -99,7 +98,7 @@ app::Color ColorSpectrum::getBottomBarColor(const int u, const int umax) double sat = double(u) / double(umax); return app::Color::fromHsl( m_color.getHslHue(), - base::clamp(sat, 0.0, 1.0), + std::clamp(sat, 0.0, 1.0), m_color.getHslLightness(), getCurrentAlphaForNewColor()); } @@ -147,9 +146,9 @@ void ColorSpectrum::onPaintSurfaceInBgThread( gfx::Color color = color_utils::color_for_ui( app::Color::fromHsl( - base::clamp(hue, 0.0, 360.0), + std::clamp(hue, 0.0, 360.0), sat, - base::clamp(lit, 0.0, 1.0))); + std::clamp(lit, 0.0, 1.0))); s->putPixel(color, main.x+x, main.y+y); } diff --git a/src/app/ui/color_tint_shade_tone.cpp b/src/app/ui/color_tint_shade_tone.cpp index 84f9305a7..fd9660a95 100644 --- a/src/app/ui/color_tint_shade_tone.cpp +++ b/src/app/ui/color_tint_shade_tone.cpp @@ -14,7 +14,6 @@ #include "app/color_utils.h" #include "app/ui/skin/skin_theme.h" #include "app/util/shader_helpers.h" -#include "base/clamp.h" #include "ui/graphics.h" #include @@ -84,8 +83,8 @@ app::Color ColorTintShadeTone::getMainAreaColor(const int u, const int umax, double val = (1.0 - double(v) / double(vmax)); return app::Color::fromHsv( m_color.getHsvHue(), - base::clamp(sat, 0.0, 1.0), - base::clamp(val, 0.0, 1.0), + std::clamp(sat, 0.0, 1.0), + std::clamp(val, 0.0, 1.0), getCurrentAlphaForNewColor()); } @@ -93,7 +92,7 @@ app::Color ColorTintShadeTone::getBottomBarColor(const int u, const int umax) { double hue = (360.0 * u / umax); return app::Color::fromHsv( - base::clamp(hue, 0.0, 360.0), + std::clamp(hue, 0.0, 360.0), m_color.getHsvSaturation(), m_color.getHsvValue(), getCurrentAlphaForNewColor()); @@ -141,8 +140,8 @@ void ColorTintShadeTone::onPaintSurfaceInBgThread( gfx::Color color = color_utils::color_for_ui( app::Color::fromHsv( hue, - base::clamp(sat, 0.0, 1.0), - base::clamp(val, 0.0, 1.0))); + std::clamp(sat, 0.0, 1.0), + std::clamp(val, 0.0, 1.0))); s->putPixel(color, main.x+x, main.y+y); } diff --git a/src/app/ui/color_wheel.cpp b/src/app/ui/color_wheel.cpp index 9961f7f74..739ce3955 100644 --- a/src/app/ui/color_wheel.cpp +++ b/src/app/ui/color_wheel.cpp @@ -16,7 +16,6 @@ #include "app/ui/skin/skin_theme.h" #include "app/ui/status_bar.h" #include "app/util/shader_helpers.h" -#include "base/clamp.h" #include "base/pi.h" #include "os/surface.h" #include "ui/graphics.h" @@ -236,9 +235,9 @@ app::Color ColorWheel::getMainAreaColor(const int _u, const int umax, int b = 255 - di; if (d <= m_wheelRadius) { return app::Color::fromRgb( - base::clamp(r, 0, 255), - base::clamp(g, 0, 255), - base::clamp(b, 128, 255)); + std::clamp(r, 0, 255), + std::clamp(g, 0, 255), + std::clamp(b, 128, 255)); } else { 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( - base::clamp(hue, 0, 360), - base::clamp(sat / 100.0, 0.0, 1.0), + std::clamp(hue, 0, 360), + std::clamp(sat / 100.0, 0.0, 1.0), (m_color.getType() != Color::MaskType ? m_color.getHsvValue(): 1.0), getCurrentAlphaForNewColor()); } @@ -287,7 +286,7 @@ app::Color ColorWheel::getBottomBarColor(const int u, const int umax) return app::Color::fromHsv( m_color.getHsvHue(), m_color.getHsvSaturation(), - base::clamp(val, 0.0, 1.0), + std::clamp(val, 0.0, 1.0), getCurrentAlphaForNewColor()); } @@ -306,7 +305,7 @@ void ColorWheel::onPaintMainArea(ui::Graphics* g, const gfx::Rect& rc) double angle = std::atan2(m_color.getGreen()-128, m_color.getRed()-128); 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 = m_wheelBounds.center() + @@ -450,18 +449,18 @@ void ColorWheel::setHarmony(Harmony harmony) 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; } app::Color ColorWheel::getColorInHarmony(int j) const { - int i = base::clamp((int)m_harmony, 0, (int)Harmony::LAST); - j = base::clamp(j, 0, harmonies[i].n-1); + int i = std::clamp((int)m_harmony, 0, (int)Harmony::LAST); + j = std::clamp(j, 0, harmonies[i].n-1); double hue = convertHueAngle(m_color.getHsvHue(), -1) + harmonies[i].hues[j]; double sat = m_color.getHsvSaturation() * harmonies[i].sats[j] / 100.0; 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()); } diff --git a/src/app/ui/context_bar.cpp b/src/app/ui/context_bar.cpp index 08f3c4ec3..07799a509 100644 --- a/src/app/ui/context_bar.cpp +++ b/src/app/ui/context_bar.cpp @@ -47,7 +47,6 @@ #include "app/ui/selection_mode_field.h" #include "app/ui/skin/skin_theme.h" #include "app/ui_context.h" -#include "base/clamp.h" #include "base/fs.h" #include "base/scoped_value.h" #include "doc/brush.h" @@ -643,7 +642,7 @@ private: char buf[32]; 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(msg); const gfx::Rect rc = bounds(); 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) { case Capture::Min: m_minThreshold = u; @@ -434,7 +433,7 @@ bool DynamicsPopup::onProcessMessage(Message* msg) float v = m_velocity.velocity().magnitude() / tools::VelocitySensor::kScreenPixelsForFullVelocity; - v = base::clamp(v, 0.0f, 1.0f); + v = std::clamp(v, 0.0f, 1.0f); m_velocityThreshold->setSensorValue(v); } diff --git a/src/app/ui/editor/editor.cpp b/src/app/ui/editor/editor.cpp index 823d50d16..7b2523ab4 100644 --- a/src/app/ui/editor/editor.cpp +++ b/src/app/ui/editor/editor.cpp @@ -54,7 +54,6 @@ #include "app/util/conversion_to_surface.h" #include "app/util/layer_utils.h" #include "base/chrono.h" -#include "base/clamp.h" #include "base/convert_to.h" #include "doc/doc.h" #include "doc/mask_boundaries.h" @@ -596,8 +595,8 @@ void Editor::drawOneSpriteUnclippedRect(ui::Graphics* g, const gfx::Rect& sprite const int maxw = std::max(0, m_sprite->width()-expose.x); const int maxh = std::max(0, m_sprite->height()-expose.y); - expose.w = base::clamp(expose.w, 0, maxw); - expose.h = base::clamp(expose.h, 0, maxh); + expose.w = std::clamp(expose.w, 0, maxw); + expose.h = std::clamp(expose.h, 0, maxh); if (expose.isEmpty()) return; @@ -773,7 +772,7 @@ void Editor::drawOneSpriteUnclippedRect(ui::Graphics* g, const gfx::Rect& sprite if (m_docPref.pixelGrid.autoOpacity()) { 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), @@ -795,7 +794,7 @@ void Editor::drawOneSpriteUnclippedRect(ui::Graphics* g, const gfx::Rect& sprite double len = (m_proj.applyX(gridrc.w) + m_proj.applyY(gridrc.h)) / 2.; alpha = int(alpha * len / 32.); - alpha = base::clamp(alpha, 0, 255); + alpha = std::clamp(alpha, 0, 255); } if (alpha > 8) { @@ -1379,8 +1378,8 @@ gfx::Point Editor::autoScroll(const ui::MouseMessage* msg, m_oldPos = mousePos; mousePos = gfx::Point( - base::clamp(mousePos.x, vp.x, vp.x2()-1), - base::clamp(mousePos.y, vp.y, vp.y2()-1)); + std::clamp(mousePos.x, vp.x, vp.x2()-1), + std::clamp(mousePos.y, vp.y, vp.y2()-1)); } else m_oldPos = mousePos; @@ -2422,8 +2421,8 @@ void Editor::setZoomAndCenterInMouse(const Zoom& zoom, // extra space for the zoom) gfx::Rect visibleBounds = editorToScreen( getViewportBounds().createIntersection(gfx::Rect(gfx::Point(0, 0), canvasSize()))); - screenPos.x = base::clamp(screenPos.x, visibleBounds.x, visibleBounds.x2()-1); - screenPos.y = base::clamp(screenPos.y, visibleBounds.y, visibleBounds.y2()-1); + screenPos.x = std::clamp(screenPos.x, visibleBounds.x, visibleBounds.x2()-1); + screenPos.y = std::clamp(screenPos.y, visibleBounds.y, visibleBounds.y2()-1); spritePos = screenToEditor(screenPos); @@ -2509,7 +2508,7 @@ void Editor::pasteImage(const Image* image, const Mask* mask) // In other case, if the center is visible, we put the pasted // image in its original location. 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 || @@ -2517,7 +2516,7 @@ void Editor::pasteImage(const Image* image, const Mask* mask) y = visibleBounds.y + visibleBounds.h/2 - image->height()/2; } 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. @@ -2525,13 +2524,13 @@ void Editor::pasteImage(const Image* image, const Mask* mask) sprite->height() <= image->height()) { // TODO review this (I think limits are wrong and high limit can // be negative here) - x = base::clamp(x, 0, sprite->width() - image->width()); - y = base::clamp(y, 0, sprite->height() - image->height()); + x = std::clamp(x, 0, sprite->width() - image->width()); + y = std::clamp(y, 0, sprite->height() - image->height()); } else { // Also we always limit the 1 image pixel inside the sprite's bounds. - x = base::clamp(x, -image->width()+1, sprite->width()-1); - y = base::clamp(y, -image->height()+1, sprite->height()-1); + x = std::clamp(x, -image->width()+1, sprite->width()-1); + y = std::clamp(y, -image->height()+1, sprite->height()-1); } } diff --git a/src/app/ui/editor/moving_symmetry_state.cpp b/src/app/ui/editor/moving_symmetry_state.cpp index 78203af3b..dbb23155f 100644 --- a/src/app/ui/editor/moving_symmetry_state.cpp +++ b/src/app/ui/editor/moving_symmetry_state.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2020 Igara Studio S.A. +// Copyright (C) 2020-2022 Igara Studio S.A. // Copyright (C) 2015-2016 David Capello // // This program is distributed under the terms of @@ -13,7 +13,6 @@ #include "app/ui/editor/editor.h" #include "app/ui/status_bar.h" -#include "base/clamp.h" #include "fmt/format.h" #include "ui/message.h" @@ -51,12 +50,12 @@ bool MovingSymmetryState::onMouseMove(Editor* editor, MouseMessage* msg) case app::gen::SymmetryMode::HORIZONTAL: pos = m_symmetryAxisStart + delta.x; 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; case app::gen::SymmetryMode::VERTICAL: pos = m_symmetryAxisStart + delta.y; 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; } m_symmetryAxis(pos); diff --git a/src/app/ui/editor/state_with_wheel_behavior.cpp b/src/app/ui/editor/state_with_wheel_behavior.cpp index dd79a7213..c91e37482 100644 --- a/src/app/ui/editor/state_with_wheel_behavior.cpp +++ b/src/app/ui/editor/state_with_wheel_behavior.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2020 Igara Studio S.A. +// Copyright (C) 2020-2022 Igara Studio S.A. // Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of @@ -24,7 +24,6 @@ #include "app/ui/keyboard_shortcuts.h" #include "app/ui/toolbar.h" #include "app/ui_context.h" -#include "base/clamp.h" #include "base/string.h" #include "doc/brush.h" #include "doc/layer.h" @@ -117,7 +116,7 @@ bool StateWithWheelBehavior::onMouseWheel(Editor* editor, MouseMessage* msg) case WheelAction::FgColor: { int lastIndex = get_current_palette()->size()-1; int newIndex = ColorBar::instance()->getFgColor().getIndex() + int(dz); - newIndex = base::clamp(newIndex, 0, lastIndex); + newIndex = std::clamp(newIndex, 0, lastIndex); ColorBar::instance()->setFgColor(app::Color::fromIndex(newIndex)); break; } @@ -125,7 +124,7 @@ bool StateWithWheelBehavior::onMouseWheel(Editor* editor, MouseMessage* msg) case WheelAction::BgColor: { int lastIndex = get_current_palette()->size()-1; int newIndex = ColorBar::instance()->getBgColor().getIndex() + int(dz); - newIndex = base::clamp(newIndex, 0, lastIndex); + newIndex = std::clamp(newIndex, 0, lastIndex); ColorBar::instance()->setBgColor(app::Color::fromIndex(newIndex)); break; } @@ -203,7 +202,7 @@ bool StateWithWheelBehavior::onMouseWheel(Editor* editor, MouseMessage* msg) dz = -dz; brush.size( - base::clamp( + std::clamp( int(brush.size()+dz), // If we use the "static const int" member directly here, // we'll get a linker error (when compiling without @@ -224,7 +223,7 @@ bool StateWithWheelBehavior::onMouseWheel(Editor* editor, MouseMessage* msg) angle += 180; angle %= 181; - brush.angle(base::clamp(angle, 0, 180)); + brush.angle(std::clamp(angle, 0, 180)); break; } @@ -295,7 +294,7 @@ bool StateWithWheelBehavior::onMouseWheel(Editor* editor, MouseMessage* msg) tools::Tool* tool = getActiveTool(); auto& toolPref = Preferences::instance().tool(tool); int opacity = toolPref.opacity(); - opacity = base::clamp(int(opacity+dz*255/10), 0, 255); + opacity = std::clamp(int(opacity+dz*255/10), 0, 255); toolPref.opacity(opacity); break; } @@ -308,7 +307,7 @@ bool StateWithWheelBehavior::onMouseWheel(Editor* editor, MouseMessage* msg) Command* command = Commands::instance()->byId(CommandId::LayerOpacity()); if (command) { int opacity = static_cast(site.layer())->opacity(); - opacity = base::clamp(int(opacity+dz*255/10), 0, 255); + opacity = std::clamp(int(opacity+dz*255/10), 0, 255); Params params; params.set("opacity", @@ -328,7 +327,7 @@ bool StateWithWheelBehavior::onMouseWheel(Editor* editor, MouseMessage* msg) Command* command = Commands::instance()->byId(CommandId::CelOpacity()); if (command) { int opacity = site.cel()->opacity(); - opacity = base::clamp(int(opacity+dz*255/10), 0, 255); + opacity = std::clamp(int(opacity+dz*255/10), 0, 255); Params params; params.set("opacity", base::convert_to(opacity).c_str()); @@ -344,7 +343,7 @@ bool StateWithWheelBehavior::onMouseWheel(Editor* editor, MouseMessage* msg) ColorBar* colorBar = ColorBar::instance(); Color c = colorBar->getFgColor(); int a = c.getAlpha(); - a = base::clamp(int(a+dz*255/10), 0, 255); + a = std::clamp(int(a+dz*255/10), 0, 255); c.setAlpha(a); colorBar->setFgColor(c); break; @@ -366,9 +365,9 @@ bool StateWithWheelBehavior::onMouseWheel(Editor* editor, MouseMessage* msg) case WheelAction::HslSaturation: s = s+dz/10.0; break; case WheelAction::HslLightness: l = l+dz/10.0; break; } - colorBar->setFgColor(Color::fromHsl(base::clamp(h, 0.0, 360.0), - base::clamp(s, 0.0, 1.0), - base::clamp(l, 0.0, 1.0))); + colorBar->setFgColor(Color::fromHsl(std::clamp(h, 0.0, 360.0), + std::clamp(s, 0.0, 1.0), + std::clamp(l, 0.0, 1.0))); break; } @@ -388,9 +387,9 @@ bool StateWithWheelBehavior::onMouseWheel(Editor* editor, MouseMessage* msg) case WheelAction::HsvSaturation: s = s+dz/10.0; break; case WheelAction::HsvValue: v = v+dz/10.0; break; } - colorBar->setFgColor(Color::fromHsv(base::clamp(h, 0.0, 360.0), - base::clamp(s, 0.0, 1.0), - base::clamp(v, 0.0, 1.0))); + colorBar->setFgColor(Color::fromHsv(std::clamp(h, 0.0, 360.0), + std::clamp(s, 0.0, 1.0), + std::clamp(v, 0.0, 1.0))); break; } diff --git a/src/app/ui/file_list.cpp b/src/app/ui/file_list.cpp index ec2bdac66..3e4f85d46 100644 --- a/src/app/ui/file_list.cpp +++ b/src/app/ui/file_list.cpp @@ -14,7 +14,6 @@ #include "app/modules/gfx.h" #include "app/thumbnail_generator.h" #include "app/ui/skin/skin_theme.h" -#include "base/clamp.h" #include "base/string.h" #include "base/time.h" #include "os/font.h" @@ -159,7 +158,7 @@ void FileList::goUp() 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; // if (auto view = View::getView(this)) @@ -358,7 +357,7 @@ bool FileList::onProcessMessage(Message* msg) } if (bottom > 0) - selectIndex(base::clamp(select, 0, bottom-1)); + selectIndex(std::clamp(select, 0, bottom-1)); return true; } @@ -620,7 +619,7 @@ gfx::Rect FileList::mainThumbnailBounds() gfx::Rect vp = view->viewportBounds(); int x = vp.x+vp.w - 2*guiscale() - thumbnail->width(); 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; y -= bounds().y; return gfx::Rect(x, y, thumbnail->width(), thumbnail->height()); diff --git a/src/app/ui/file_selector.cpp b/src/app/ui/file_selector.cpp index 9729e6389..09c74208d 100644 --- a/src/app/ui/file_selector.cpp +++ b/src/app/ui/file_selector.cpp @@ -24,7 +24,6 @@ #include "app/ui/separator_in_view.h" #include "app/ui/skin/skin_theme.h" #include "app/widget_loader.h" -#include "base/clamp.h" #include "base/convert_to.h" #include "base/fs.h" #include "base/paths.h" @@ -128,7 +127,7 @@ void adjust_navigation_history(IFileItem* item) } 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); FILESEL_TRACE("FILESEL: New navigation pos [%d] = %s\n", diff --git a/src/app/ui/palette_view.cpp b/src/app/ui/palette_view.cpp index fc49b2d6e..f7718a39c 100644 --- a/src/app/ui/palette_view.cpp +++ b/src/app/ui/palette_view.cpp @@ -23,7 +23,6 @@ #include "app/ui/status_bar.h" #include "app/util/clipboard.h" #include "app/util/pal_ops.h" -#include "base/clamp.h" #include "base/convert_to.h" #include "doc/image.h" #include "doc/palette.h" @@ -221,7 +220,7 @@ int PaletteView::getBoxSize() const void PaletteView::setBoxSize(double boxsize) { - m_boxsize = base::clamp(boxsize, 4.0, 32.0); + m_boxsize = std::clamp(boxsize, 4.0, 32.0); if (m_delegate) m_delegate->onPaletteViewChangeSize(int(m_boxsize)); @@ -349,7 +348,7 @@ bool PaletteView::onProcessMessage(Message* msg) if (m_state == State::SELECTING_COLOR && m_hot.part == Hit::COLOR) { int idx = m_hot.color; - idx = base::clamp(idx, 0, currentPalette()->size()-1); + idx = std::clamp(idx, 0, currentPalette()->size()-1); const MouseButton button = mouseMsg->button(); @@ -790,7 +789,7 @@ PaletteView::Hit PaletteView::hitTest(const gfx::Point& pos) int colsLimit = m_columns; if (m_state == State::DRAGGING_OUTLINE) --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; return Hit(Hit::POSSIBLE_COLOR, i); } diff --git a/src/app/ui/skin/skin_theme.cpp b/src/app/ui/skin/skin_theme.cpp index af2f7d095..9814055d6 100644 --- a/src/app/ui/skin/skin_theme.cpp +++ b/src/app/ui/skin/skin_theme.cpp @@ -25,7 +25,6 @@ #include "app/ui/skin/skin_slider_property.h" #include "app/xml_document.h" #include "app/xml_exception.h" -#include "base/clamp.h" #include "base/fs.h" #include "base/log.h" #include "base/string.h" @@ -1694,7 +1693,7 @@ void SkinTheme::paintProgressBar(ui::Graphics* g, const gfx::Rect& rc0, double p rc.shrink(1); int u = (int)((double)rc.w*progress); - u = base::clamp(u, 0, rc.w); + u = std::clamp(u, 0, rc.w); if (u > 0) g->fillRect(colors.selected(), gfx::Rect(rc.x, rc.y, u, rc.h)); diff --git a/src/app/ui/slider2.cpp b/src/app/ui/slider2.cpp index 85f66bf92..9033b214e 100644 --- a/src/app/ui/slider2.cpp +++ b/src/app/ui/slider2.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2020 Igara Studio S.A. +// Copyright (C) 2020-2022 Igara Studio S.A. // Copyright (C) 2017 David Capello // // This program is distributed under the terms of @@ -12,7 +12,6 @@ #include "app/ui/slider2.h" #include "app/ui/skin/skin_property.h" -#include "base/clamp.h" #include "ui/manager.h" #include "ui/message.h" @@ -56,7 +55,7 @@ bool Slider2::Slider2Entry::onProcessMessage(ui::Message* msg) else ++value; - setTextf("%d", base::clamp(value, minValue(), maxValue())); + setTextf("%d", std::clamp(value, minValue(), maxValue())); selectAllText(); onChange(); @@ -119,7 +118,7 @@ void Slider2::onSliderChange() void Slider2::onEntryChange() { 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); onChange(); diff --git a/src/app/ui/tabs.cpp b/src/app/ui/tabs.cpp index 9009d2249..6e39b33bc 100644 --- a/src/app/ui/tabs.cpp +++ b/src/app/ui/tabs.cpp @@ -15,7 +15,6 @@ #include "app/modules/gui.h" #include "app/ui/editor/editor_view.h" #include "app/ui/skin/skin_theme.h" -#include "base/clamp.h" #include "os/font.h" #include "os/surface.h" #include "os/system.h" @@ -259,7 +258,7 @@ void Tabs::setDropViewPreview(const gfx::Point& pos, TabView* view) if (!m_list.empty()) { 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 newIndex = 0; @@ -430,7 +429,7 @@ bool Tabs::onProcessMessage(Message* msg) if (it != m_list.end()) { int index = (it - m_list.begin()); 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) { selectTabInternal(m_list[newIndex]); } @@ -997,14 +996,14 @@ void Tabs::updateDragTabIndexes(int mouseX, bool startAni) int i = (mouseX - m_border*guiscale() - bounds().x) / m_dragTab->width; 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) { m_dragCopyIndex = i; startAni = true; } } 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) { m_list.erase(m_list.begin()+m_dragTabIndex); m_list.insert(m_list.begin()+i, m_selected); diff --git a/src/app/ui/tag_window.cpp b/src/app/ui/tag_window.cpp index 9e2a71cf4..678458147 100644 --- a/src/app/ui/tag_window.cpp +++ b/src/app/ui/tag_window.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2016 David Capello // // This program is distributed under the terms of @@ -14,7 +14,6 @@ #include "app/doc.h" #include "app/pref/preferences.h" #include "app/ui/layer_frame_comboboxes.h" -#include "base/clamp.h" #include "doc/sprite.h" #include "doc/tag.h" @@ -54,8 +53,8 @@ void TagWindow::rangeValue(doc::frame_t& from, doc::frame_t& to) from = this->from()->textInt()-m_base; to = this->to()->textInt()-m_base; - from = base::clamp(from, first, last); - to = base::clamp(to, from, last); + from = std::clamp(from, first, last); + to = std::clamp(to, from, last); } doc::color_t TagWindow::colorValue() diff --git a/src/app/ui/task_widget.cpp b/src/app/ui/task_widget.cpp index 849ee08c1..343f3c6c2 100644 --- a/src/app/ui/task_widget.cpp +++ b/src/app/ui/task_widget.cpp @@ -13,7 +13,6 @@ #include "app/i18n/strings.h" #include "app/modules/gui.h" #include "app/ui/skin/skin_theme.h" -#include "base/clamp.h" #include "ui/scale.h" #include @@ -56,9 +55,9 @@ TaskWidget::TaskWidget(const Type type, float v = m_task.progress(); if (v > 0.0f) { 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( - int(base::clamp(v*100.0f, 0.0f, 100.0f))); + int(std::clamp(v*100.0f, 0.0f, 100.0f))); } } }); diff --git a/src/app/ui/timeline/timeline.cpp b/src/app/ui/timeline/timeline.cpp index c02d7a545..bafdad592 100644 --- a/src/app/ui/timeline/timeline.cpp +++ b/src/app/ui/timeline/timeline.cpp @@ -44,7 +44,6 @@ #include "app/util/layer_boundaries.h" #include "app/util/layer_utils.h" #include "app/util/readable_time.h" -#include "base/clamp.h" #include "base/convert_to.h" #include "base/memory.h" #include "base/scoped_value.h" @@ -285,7 +284,7 @@ Timeline::~Timeline() 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_thumbnailsOverlayVisible = false; } @@ -958,7 +957,7 @@ bool Timeline::onProcessMessage(Message* msg) if (selectedLayersBounds(selectedLayers(), &layerFirst, &layerLast)) { layer_t layerIdx = m_clk.layer; - layerIdx = base::clamp(layerIdx, layerFirst, layerLast); + layerIdx = std::clamp(layerIdx, layerFirst, layerLast); m_clk.layer = layerIdx; } } @@ -1905,11 +1904,11 @@ void Timeline::getDrawableLayers(layer_t* firstDrawableLayer, { layer_t i = lastLayer() - ((viewScroll().y + getCelsBounds().h) / layerBoxHeight()); - i = base::clamp(i, firstLayer(), lastLayer()); + i = std::clamp(i, firstLayer(), lastLayer()); layer_t j = lastLayer() - viewScroll().y / layerBoxHeight();; if (!m_rows.empty()) - j = base::clamp(j, firstLayer(), lastLayer()); + j = std::clamp(j, firstLayer(), lastLayer()); else j = -1; @@ -2254,7 +2253,7 @@ void Timeline::drawCel(ui::Graphics* g, layer_t layerIndex, frame_t frame, Cel* if (!thumb_bounds.isEmpty()) { 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()); g->drawRgbaSurface(surface.get(), @@ -2490,9 +2489,9 @@ void Timeline::drawTags(ui::Graphics* g) r = gfx::getr(bg)+32; g = gfx::getg(bg)+32; b = gfx::getb(bg)+32; - r = base::clamp(r, 0, 255); - g = base::clamp(g, 0, 255); - b = base::clamp(b, 0, 255); + r = std::clamp(r, 0, 255); + g = std::clamp(g, 0, 255); + b = std::clamp(b, 0, 255); bg = gfx::rgba(r, g, b, gfx::geta(bg)); } g->fillRect(bg, bounds); @@ -3090,11 +3089,11 @@ Timeline::Hit Timeline::hitTest(ui::Message* msg, const gfx::Point& mousePos) hit.veryBottom = true; if (hasCapture()) { - hit.layer = base::clamp(hit.layer, firstLayer(), lastLayer()); + hit.layer = std::clamp(hit.layer, firstLayer(), lastLayer()); if (isMovingCel()) hit.frame = std::max(firstFrame(), hit.frame); else - hit.frame = base::clamp(hit.frame, firstFrame(), lastFrame()); + hit.frame = std::clamp(hit.frame, firstFrame(), lastFrame()); } else { if (hit.layer > lastLayer()) hit.layer = -1; @@ -3268,7 +3267,7 @@ Timeline::Hit Timeline::hitTestCel(const gfx::Point& mousePos) - m_separator_w + 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); return hit; @@ -3789,8 +3788,8 @@ void Timeline::setViewScroll(const gfx::Point& pt) const gfx::Point oldScroll = viewScroll(); const gfx::Point maxPos = getMaxScrollablePos(); gfx::Point newScroll = pt; - newScroll.x = base::clamp(newScroll.x, 0, maxPos.x); - newScroll.y = base::clamp(newScroll.y, 0, maxPos.y); + newScroll.x = std::clamp(newScroll.x, 0, maxPos.x); + newScroll.y = std::clamp(newScroll.y, 0, maxPos.y); if (newScroll.y != oldScroll.y) { gfx::Rect rc; @@ -4254,7 +4253,7 @@ void Timeline::setLayerCollapsedFlag(const layer_t l, const bool state) 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) diff --git a/src/app/util/wrap_point.cpp b/src/app/util/wrap_point.cpp index d079fca92..af0afb256 100644 --- a/src/app/util/wrap_point.cpp +++ b/src/app/util/wrap_point.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2017 David Capello // // This program is distributed under the terms of @@ -12,7 +12,8 @@ #include "app/util/wrap_point.h" #include "app/util/wrap_value.h" -#include "base/clamp.h" + +#include namespace app { @@ -26,14 +27,14 @@ gfx::Point wrap_point(const filters::TiledMode tiledMode, if (int(tiledMode) & int(filters::TiledMode::X_AXIS)) out.x = wrap_value(pt.x, spriteSize.w); else if (clamp) - out.x = base::clamp(pt.x, 0, spriteSize.w-1); + out.x = std::clamp(pt.x, 0, spriteSize.w-1); else out.x = pt.x; if (int(tiledMode) & int(filters::TiledMode::Y_AXIS)) out.y = wrap_value(pt.y, spriteSize.h); else if (clamp) - out.y = base::clamp(pt.y, 0, spriteSize.h-1); + out.y = std::clamp(pt.y, 0, spriteSize.h-1); else out.y = pt.y; diff --git a/src/doc/algo.cpp b/src/doc/algo.cpp index 2fac7b517..2e226250c 100644 --- a/src/doc/algo.cpp +++ b/src/doc/algo.cpp @@ -1,5 +1,5 @@ // 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 // // This file is released under the terms of the MIT license. @@ -11,7 +11,6 @@ #include "doc/algo.h" -#include "base/clamp.h" #include "base/debug.h" #include @@ -412,7 +411,7 @@ static void draw_rotated_ellipse_rect(int x0, int y0, int x1, int y1, double zd, if (w != 0.0) 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); 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) : y0(y0), row(nrows, std::make_pair(1, -1)) { } 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]; if (r.first > r.second) { r.first = r.second = x; diff --git a/src/doc/file/col_file.cpp b/src/doc/file/col_file.cpp index 9728902e8..a2ecefc45 100644 --- a/src/doc/file/col_file.cpp +++ b/src/doc/file/col_file.cpp @@ -1,4 +1,5 @@ // Aseprite Document Library +// Copyright (c) 2022 Igara Studio S.A. // Copyright (c) 2001-2016 David Capello // // This file is released under the terms of the MIT license. @@ -10,7 +11,6 @@ #include "base/base.h" #include "base/cfile.h" -#include "base/clamp.h" #include "doc/color_scales.h" #include "doc/image.h" #include "doc/palette.h" @@ -59,9 +59,9 @@ Palette* load_col_file(const char* filename) if (ferror(f)) break; - pal->setEntry(c, rgba(scale_6bits_to_8bits(base::clamp(r, 0, 63)), - scale_6bits_to_8bits(base::clamp(g, 0, 63)), - scale_6bits_to_8bits(base::clamp(b, 0, 63)), 255)); + pal->setEntry(c, rgba(scale_6bits_to_8bits(std::clamp(r, 0, 63)), + scale_6bits_to_8bits(std::clamp(g, 0, 63)), + scale_6bits_to_8bits(std::clamp(b, 0, 63)), 255)); } } // Animator Pro format @@ -87,9 +87,9 @@ Palette* load_col_file(const char* filename) if (ferror(f)) break; - pal->setEntry(c, rgba(base::clamp(r, 0, 255), - base::clamp(g, 0, 255), - base::clamp(b, 0, 255), 255)); + pal->setEntry(c, rgba(std::clamp(r, 0, 255), + std::clamp(g, 0, 255), + std::clamp(b, 0, 255), 255)); } } diff --git a/src/doc/handle_anidir.cpp b/src/doc/handle_anidir.cpp index 2a427ff87..6ccf383a9 100644 --- a/src/doc/handle_anidir.cpp +++ b/src/doc/handle_anidir.cpp @@ -1,5 +1,5 @@ // 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 // // This file is released under the terms of the MIT license. @@ -11,7 +11,6 @@ #include "doc/handle_anidir.h" -#include "base/clamp.h" #include "doc/frame.h" #include "doc/sprite.h" #include "doc/tag.h" @@ -37,8 +36,8 @@ frame_t calculate_next_frame( loopFrom = tag->fromFrame(); loopTo = tag->toFrame(); - loopFrom = base::clamp(loopFrom, first, last); - loopTo = base::clamp(loopTo, first, last); + loopFrom = std::clamp(loopFrom, first, last); + loopTo = std::clamp(loopTo, first, last); first = loopFrom; last = loopTo; diff --git a/src/doc/mask.cpp b/src/doc/mask.cpp index c12b8b8a9..1e72821c3 100644 --- a/src/doc/mask.cpp +++ b/src/doc/mask.cpp @@ -1,5 +1,5 @@ // 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 // // This file is released under the terms of the MIT license. @@ -11,7 +11,6 @@ #include "doc/mask.h" -#include "base/clamp.h" #include "base/memory.h" #include "doc/image_impl.h" @@ -387,10 +386,10 @@ void Mask::crop(const Image *image) beg_x2 = beg_x1 + m_bounds.w - 1; beg_y2 = beg_y1 + m_bounds.h - 1; - beg_x1 = base::clamp(beg_x1, 0, m_bounds.w-1); - beg_y1 = base::clamp(beg_y1, 0, m_bounds.h-1); - beg_x2 = base::clamp(beg_x2, beg_x1, m_bounds.w-1); - beg_y2 = base::clamp(beg_y2, beg_y1, m_bounds.h-1); + beg_x1 = std::clamp(beg_x1, 0, m_bounds.w-1); + beg_y1 = std::clamp(beg_y1, 0, m_bounds.h-1); + beg_x2 = std::clamp(beg_x2, beg_x1, m_bounds.w-1); + beg_y2 = std::clamp(beg_y2, beg_y1, m_bounds.h-1); /* left */ ADVANCE(x1, x2, y2, <=, ++, diff --git a/src/doc/sprite.cpp b/src/doc/sprite.cpp index f9b430ce2..f52ad6d65 100644 --- a/src/doc/sprite.cpp +++ b/src/doc/sprite.cpp @@ -1,5 +1,5 @@ // Aseprite Document Library -// Copyright (C) 2018-2020 Igara Studio S.A. +// Copyright (C) 2018-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This file is released under the terms of the MIT license. @@ -11,7 +11,6 @@ #include "doc/sprite.h" -#include "base/clamp.h" #include "base/memory.h" #include "base/remove_from_container.h" #include "doc/cel.h" @@ -77,7 +76,7 @@ Sprite::Sprite(const ImageSpec& spec, case ColorMode::BITMAP: for (int c=0; c= 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) { std::fill( 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) { - 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)); } ////////////////////////////////////////////////////////////////////// diff --git a/src/filters/brightness_contrast_filter.cpp b/src/filters/brightness_contrast_filter.cpp index 30b2b5a2f..516935546 100644 --- a/src/filters/brightness_contrast_filter.cpp +++ b/src/filters/brightness_contrast_filter.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2017 David Capello // // This program is distributed under the terms of @@ -11,7 +11,6 @@ #include "filters/brightness_contrast_filter.h" -#include "base/clamp.h" #include "doc/image.h" #include "doc/palette.h" #include "doc/rgbmap.h" @@ -189,7 +188,7 @@ void BrightnessContrastFilter::updateMap() double x = double(u) / double(max-1); double y = (m_contrast+1.0) * (x - 0.5) + 0.5; 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); } } diff --git a/src/filters/color_curve_filter.cpp b/src/filters/color_curve_filter.cpp index 7d28fecd2..f434085b9 100644 --- a/src/filters/color_curve_filter.cpp +++ b/src/filters/color_curve_filter.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2016 David Capello // // This program is distributed under the terms of @@ -11,7 +11,6 @@ #include "filters/color_curve_filter.h" -#include "base/clamp.h" #include "filters/color_curve.h" #include "filters/filter_indexed_data.h" #include "filters/filter_manager.h" @@ -42,7 +41,7 @@ void ColorCurveFilter::generateMap() // Generate the color convertion map m_curve.getValues(0, 255, m_cmap); 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() @@ -145,7 +144,7 @@ void ColorCurveFilter::applyToIndexed(FilterManager* filterMgr) 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); } } diff --git a/src/filters/convolution_matrix_filter.cpp b/src/filters/convolution_matrix_filter.cpp index d7fa53312..910c1aa3b 100644 --- a/src/filters/convolution_matrix_filter.cpp +++ b/src/filters/convolution_matrix_filter.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2016 David Capello // // This program is distributed under the terms of @@ -11,7 +11,6 @@ #include "filters/convolution_matrix_filter.h" -#include "base/clamp.h" #include "filters/convolution_matrix.h" #include "filters/filter_indexed_data.h" #include "filters/filter_manager.h" @@ -168,28 +167,28 @@ void ConvolutionMatrixFilter::applyToRgba(FilterManager* filterMgr) if (target & TARGET_RED_CHANNEL) { 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 delegate.r = rgba_getr(color); if (target & TARGET_GREEN_CHANNEL) { 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 delegate.g = rgba_getg(color); if (target & TARGET_BLUE_CHANNEL) { 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 delegate.b = rgba_getb(color); if (target & TARGET_ALPHA_CHANNEL) { 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 delegate.a = rgba_geta(color); @@ -235,14 +234,14 @@ void ConvolutionMatrixFilter::applyToGrayscale(FilterManager* filterMgr) if (target & TARGET_GRAY_CHANNEL) { 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 delegate.v = graya_getv(color); if (target & TARGET_ALPHA_CHANNEL) { 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 delegate.a = graya_geta(color); @@ -290,7 +289,7 @@ void ConvolutionMatrixFilter::applyToIndexed(FilterManager* filterMgr) if (target & TARGET_INDEX_CHANNEL) { 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; } @@ -299,28 +298,28 @@ void ConvolutionMatrixFilter::applyToIndexed(FilterManager* filterMgr) if (target & TARGET_RED_CHANNEL) { 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 delegate.r = rgba_getr(color); if (target & TARGET_GREEN_CHANNEL) { 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 delegate.g = rgba_getg(color); if (target & TARGET_BLUE_CHANNEL) { 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 delegate.b = rgba_getb(color); if (target & TARGET_ALPHA_CHANNEL) { 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 delegate.a = rgba_geta(color); diff --git a/src/filters/hue_saturation_filter.cpp b/src/filters/hue_saturation_filter.cpp index f3cd8ee0f..1001a5562 100644 --- a/src/filters/hue_saturation_filter.cpp +++ b/src/filters/hue_saturation_filter.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2017-2018 David Capello // // This program is distributed under the terms of @@ -11,7 +11,6 @@ #include "filters/hue_saturation_filter.h" -#include "base/clamp.h" #include "doc/image.h" #include "doc/palette.h" #include "doc/palette_picks.h" @@ -125,7 +124,7 @@ void HueSaturationFilter::applyToGrayscale(FilterManager* filterMgr) gfx::Hsl hsl(gfx::Rgb(k, k, k)); 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); gfx::Rgb rgb(hsl); @@ -134,7 +133,7 @@ void HueSaturationFilter::applyToGrayscale(FilterManager* filterMgr) if (a && (target & TARGET_ALPHA_CHANNEL)) { a = a*(1.0+m_a); - a = base::clamp(a, 0, 255); + a = std::clamp(a, 0, 255); } } @@ -217,11 +216,11 @@ void HueSaturationFilter::applyFilterToRgbT(const Target target, double s = (multiply ? hsl.saturation()*(1.0+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): (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.saturation(s); @@ -233,7 +232,7 @@ void HueSaturationFilter::applyFilterToRgbT(const Target target, if (target & TARGET_BLUE_CHANNEL ) b = rgb.blue(); if (a && (target & TARGET_ALPHA_CHANNEL)) { a = a*(1.0+m_a); - a = base::clamp(a, 0, 255); + a = std::clamp(a, 0, 255); } c = rgba(r, g, b, a); diff --git a/src/filters/replace_color_filter.cpp b/src/filters/replace_color_filter.cpp index fd0bd4458..0ab66a9f8 100644 --- a/src/filters/replace_color_filter.cpp +++ b/src/filters/replace_color_filter.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2016 David Capello // // This program is distributed under the terms of @@ -11,7 +11,6 @@ #include "filters/replace_color_filter.h" -#include "base/clamp.h" #include "doc/image.h" #include "doc/palette.h" #include "doc/rgbmap.h" @@ -40,7 +39,7 @@ void ReplaceColorFilter::setTo(const color_t to) void ReplaceColorFilter::setTolerance(int tolerance) { - m_tolerance = base::clamp(tolerance, 0, 255); + m_tolerance = std::clamp(tolerance, 0, 255); } const char* ReplaceColorFilter::getName() diff --git a/src/render/error_diffusion.cpp b/src/render/error_diffusion.cpp index feb86c3f3..5a2ec2999 100644 --- a/src/render/error_diffusion.cpp +++ b/src/render/error_diffusion.cpp @@ -1,5 +1,5 @@ // Aseprite Render Library -// Copyright (c) 2019-2020 Igara Studio S.A +// Copyright (c) 2019-2022 Igara Studio S.A // Copyright (c) 2017 David Capello // // This file is released under the terms of the MIT license. @@ -68,7 +68,7 @@ doc::color_t ErrorDiffusionDither::ditherRgbToIndex2D( }; for (int i=0; imapColor(r2, g2, b2, a2): palette->findBestfit(r2, g2, b2, a2, m_transparentIndex)); @@ -201,7 +200,7 @@ doc::color_t OrderedDither2::ditherRgbPixelToIndex( if (mix) { if (div) mix /= div; - mix = base::clamp(mix, 0, maxMixValue); + mix = std::clamp(mix, 0, maxMixValue); } const int rM = r0 + (r1-r0) * mix / maxMixValue; diff --git a/src/render/render.cpp b/src/render/render.cpp index 7f4bb4184..905a948e0 100644 --- a/src/render/render.cpp +++ b/src/render/render.cpp @@ -1,5 +1,5 @@ // Aseprite Render Library -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This file is released under the terms of the MIT license. @@ -11,7 +11,6 @@ #include "render/render.h" -#include "base/clamp.h" #include "doc/blend_internals.h" #include "doc/blend_mode.h" #include "doc/doc.h" @@ -883,7 +882,7 @@ void Render::renderOnionskin( 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) { BlendMode blendMode = BlendMode::UNSPECIFIED; if (m_onionskin.type() == OnionskinType::MERGE) diff --git a/src/render/zoom.cpp b/src/render/zoom.cpp index 47b7549c0..49d7d7ab5 100644 --- a/src/render/zoom.cpp +++ b/src/render/zoom.cpp @@ -1,5 +1,5 @@ // Aseprite Render Library -// Copyright (c) 2020 Igara Studio S.A. +// Copyright (c) 2020-2022 Igara Studio S.A. // Copyright (c) 2001-2016 David Capello // // This file is released under the terms of the MIT license. @@ -9,10 +9,11 @@ #include "config.h" #endif -#include "base/clamp.h" #include "base/debug.h" #include "render/zoom.h" +#include + namespace render { static int scales[][2] = { @@ -105,7 +106,7 @@ Zoom Zoom::fromScale(double scale) // static 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]); } diff --git a/src/ui/alert.cpp b/src/ui/alert.cpp index f2c59281c..4bfb360fc 100644 --- a/src/ui/alert.cpp +++ b/src/ui/alert.cpp @@ -1,5 +1,5 @@ // 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 // // This file is released under the terms of the MIT license. @@ -35,7 +35,6 @@ #include "ui/alert.h" -#include "base/clamp.h" #include "base/string.h" #include "ui/box.h" #include "ui/button.h" @@ -46,6 +45,7 @@ #include "ui/slider.h" #include "ui/theme.h" +#include #include namespace ui { @@ -143,7 +143,7 @@ CheckBox* Alert::addCheckBox(const std::string& text) void Alert::setProgress(double 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 diff --git a/src/ui/box.cpp b/src/ui/box.cpp index e80a3ac94..e6422a369 100644 --- a/src/ui/box.cpp +++ b/src/ui/box.cpp @@ -1,5 +1,5 @@ // 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 // // This file is released under the terms of the MIT license. @@ -9,7 +9,6 @@ #include "config.h" #endif -#include "base/clamp.h" #include "gfx/size.h" #include "ui/box.h" #include "ui/message.h" @@ -117,8 +116,8 @@ void Box::onResize(ResizeEvent& ev) } \ \ Rect childPos = defChildPos; \ - childPos.w = size = base::clamp(size, child->minSize().w, child->maxSize().w); \ - childPos.h = base::clamp(childPos.h, child->minSize().h, child->maxSize().h); \ + childPos.w = size = std::clamp(size, child->minSize().w, child->maxSize().w); \ + childPos.h = std::clamp(childPos.h, child->minSize().h, child->maxSize().h); \ child->setBounds(childPos); \ \ defChildPos.x += size + childSpacing(); \ diff --git a/src/ui/combobox.cpp b/src/ui/combobox.cpp index 2d277ad6a..f6423dc51 100644 --- a/src/ui/combobox.cpp +++ b/src/ui/combobox.cpp @@ -11,7 +11,6 @@ #include "ui/combobox.h" -#include "base/clamp.h" #include "gfx/size.h" #include "os/font.h" #include "ui/button.h" @@ -628,7 +627,7 @@ void ComboBox::openListBox() size.h += item->sizeHint().h; int max = std::max(entryBounds.y, ui::display_h() - entryBounds.y2()) - 8*guiscale(); - size.h = base::clamp(size.h, textHeight(), max); + size.h = std::clamp(size.h, textHeight(), max); viewport->setMinSize(size); } diff --git a/src/ui/entry.cpp b/src/ui/entry.cpp index d331ce470..dccf2bb99 100644 --- a/src/ui/entry.cpp +++ b/src/ui/entry.cpp @@ -11,7 +11,6 @@ #include "ui/entry.h" -#include "base/clamp.h" #include "base/string.h" #include "os/draw_text.h" #include "os/font.h" @@ -121,8 +120,8 @@ void Entry::setCaretPos(int pos) { gfx::Size caretSize = theme()->getEntryCaretSize(this); int textlen = lastCaretPos(); - m_caret = base::clamp(pos, 0, textlen); - m_scroll = base::clamp(m_scroll, 0, textlen); + m_caret = std::clamp(pos, 0, textlen); + m_scroll = std::clamp(m_scroll, 0, textlen); // Backward scroll if (m_caret < m_scroll) @@ -577,7 +576,7 @@ int Entry::getCaretFromMouse(MouseMessage* mousemsg) break; } - return base::clamp(i, 0, lastPos); + return std::clamp(i, 0, lastPos); } void Entry::executeCmd(EntryCmd cmd, int unicodeChar, bool shift_pressed) @@ -823,7 +822,7 @@ void Entry::backwardWord() Entry::Range Entry::wordRange(int pos) { const int last = lastCaretPos(); - pos = base::clamp(pos, 0, last); + pos = std::clamp(pos, 0, last); int i, j; i = j = pos; diff --git a/src/ui/fit_bounds.cpp b/src/ui/fit_bounds.cpp index 3614eeaa9..52b1ae5a2 100644 --- a/src/ui/fit_bounds.cpp +++ b/src/ui/fit_bounds.cpp @@ -1,5 +1,5 @@ // Aseprite UI Library -// Copyright (C) 2019 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2016 David Capello // // This file is released under the terms of the MIT license. @@ -9,11 +9,12 @@ #include "config.h" #endif -#include "base/clamp.h" #include "gfx/rect.h" #include "ui/base.h" #include "ui/system.h" +#include + namespace ui { int fit_bounds(int arrowAlign, const gfx::Rect& target, gfx::Rect& bounds) @@ -58,8 +59,8 @@ int fit_bounds(int arrowAlign, const gfx::Rect& target, gfx::Rect& bounds) break; } - bounds.x = base::clamp(bounds.x, 0, ui::display_w()-bounds.w); - bounds.y = base::clamp(bounds.y, 0, ui::display_h()-bounds.h); + bounds.x = std::clamp(bounds.x, 0, ui::display_w()-bounds.w); + bounds.y = std::clamp(bounds.y, 0, ui::display_h()-bounds.h); if (target.intersects(bounds)) { switch (trycount) { diff --git a/src/ui/int_entry.cpp b/src/ui/int_entry.cpp index 94fd72028..b21c54d12 100644 --- a/src/ui/int_entry.cpp +++ b/src/ui/int_entry.cpp @@ -11,7 +11,6 @@ #include "ui/int_entry.h" -#include "base/clamp.h" #include "base/scoped_value.h" #include "gfx/rect.h" #include "gfx/region.h" @@ -54,12 +53,12 @@ IntEntry::~IntEntry() int IntEntry::getValue() const { 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) { - value = base::clamp(value, m_min, m_max); + value = std::clamp(value, m_min, m_max); setText(m_slider.convertValueToText(value)); @@ -75,7 +74,7 @@ bool IntEntry::onProcessMessage(Message* msg) // Reset value if it's out of bounds when focus is lost case kFocusLeaveMessage: - setValue(base::clamp(getValue(), m_min, m_max)); + setValue(std::clamp(getValue(), m_min, m_max)); deselectText(); break; @@ -106,7 +105,7 @@ bool IntEntry::onProcessMessage(Message* msg) int newValue = oldValue + static_cast(msg)->wheelDelta().x - static_cast(msg)->wheelDelta().y; - newValue = base::clamp(newValue, m_min, m_max); + newValue = std::clamp(newValue, m_min, m_max); if (newValue != oldValue) { setValue(newValue); selectAllText(); diff --git a/src/ui/listbox.cpp b/src/ui/listbox.cpp index 2a2737839..1ba6ba848 100644 --- a/src/ui/listbox.cpp +++ b/src/ui/listbox.cpp @@ -11,7 +11,6 @@ #include "ui/listbox.h" -#include "base/clamp.h" #include "base/fs.h" #include "ui/listitem.h" #include "ui/message.h" @@ -341,7 +340,7 @@ bool ListBox::onProcessMessage(Message* msg) return Widget::onProcessMessage(msg); } - selectIndex(base::clamp(select, 0, bottom), msg); + selectIndex(std::clamp(select, 0, bottom), msg); return true; } break; @@ -417,7 +416,7 @@ int ListBox::advanceIndexThroughVisibleItems( const int sgn = SGN(delta); int index = startIndex; - startIndex = base::clamp(startIndex, 0, bottom); + startIndex = std::clamp(startIndex, 0, bottom); int lastVisibleIndex = startIndex; bool cycle = false; diff --git a/src/ui/manager.cpp b/src/ui/manager.cpp index 1f17a4449..774dd1940 100644 --- a/src/ui/manager.cpp +++ b/src/ui/manager.cpp @@ -18,7 +18,6 @@ #include "ui/manager.h" -#include "base/clamp.h" #include "base/concurrent_queue.h" #include "base/scoped_value.h" #include "base/time.h" @@ -1354,8 +1353,8 @@ void Manager::onInitTheme(InitThemeEvent& ev) gfx::Rect bounds = window->bounds(); bounds *= newUIScale; bounds /= oldUIScale; - bounds.x = base::clamp(bounds.x, 0, m_display->width() - bounds.w); - bounds.y = base::clamp(bounds.y, 0, m_display->height() - bounds.h); + bounds.x = std::clamp(bounds.x, 0, m_display->width() - bounds.w); + bounds.y = std::clamp(bounds.y, 0, m_display->height() - bounds.h); window->setBounds(bounds); } } diff --git a/src/ui/menu.cpp b/src/ui/menu.cpp index d920d3b32..3b6f07594 100644 --- a/src/ui/menu.cpp +++ b/src/ui/menu.cpp @@ -11,7 +11,6 @@ #include "ui/menu.h" -#include "base/clamp.h" #include "gfx/size.h" #include "os/font.h" #include "ui/intern.h" @@ -326,8 +325,8 @@ void Menu::showPopup(const gfx::Point& pos) // Menubox position window->positionWindow( - base::clamp(pos.x, 0, ui::display_w() - window->bounds().w), - base::clamp(pos.y, 0, ui::display_h() - window->bounds().h)); + std::clamp(pos.x, 0, ui::display_w() - window->bounds().w), + std::clamp(pos.y, 0, ui::display_h() - window->bounds().h)); add_scrollbars_if_needed(window.get()); @@ -861,7 +860,7 @@ bool MenuItem::onProcessMessage(Message* msg) Rect pos = window->bounds(); if (inBar()) { - pos.x = base::clamp(bounds().x, 0, ui::display_w()-pos.w); + pos.x = std::clamp(bounds().x, 0, ui::display_w()-pos.w); pos.y = std::max(0, bounds().y2()); } else { @@ -870,9 +869,9 @@ bool MenuItem::onProcessMessage(Message* msg) int x, y = bounds().y-3*guiscale(); Rect r1(0, 0, pos.w, pos.h), r2(0, 0, pos.w, pos.h); - r1.x = x_left = base::clamp(x_left, 0, ui::display_w()-pos.w); - r2.x = x_right = base::clamp(x_right, 0, ui::display_w()-pos.w); - r1.y = r2.y = y = base::clamp(y, 0, ui::display_h()-pos.h); + r1.x = x_left = std::clamp(x_left, 0, ui::display_w()-pos.w); + r2.x = x_right = std::clamp(x_right, 0, ui::display_w()-pos.w); + r1.y = r2.y = y = std::clamp(y, 0, ui::display_h()-pos.h); // Calculate both intersections gfx::Rect s1 = r1.createIntersection(old_pos); diff --git a/src/ui/scroll_bar.cpp b/src/ui/scroll_bar.cpp index 6a870ce43..f86be28d8 100644 --- a/src/ui/scroll_bar.cpp +++ b/src/ui/scroll_bar.cpp @@ -1,5 +1,5 @@ // Aseprite UI Library -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2017 David Capello // // This file is released under the terms of the MIT license. @@ -9,7 +9,6 @@ #include "config.h" #endif -#include "base/clamp.h" #include "gfx/size.h" #include "ui/message.h" #include "ui/paint_event.h" @@ -148,13 +147,13 @@ bool ScrollBar::onProcessMessage(Message* msg) if (align() & HORIZONTAL) { pos = (m_wherepos + mousePos.x - m_whereclick); - pos = base::clamp(pos, 0, bar_size - len); + pos = std::clamp(pos, 0, bar_size - len); scroll.x = (m_size - viewport_size) * pos / (bar_size - len); } else { pos = (m_wherepos + mousePos.y - m_whereclick); - pos = base::clamp(pos, 0, bar_size - len); + pos = std::clamp(pos, 0, bar_size - len); scroll.y = (m_size - viewport_size) * pos / (bar_size - len); } @@ -222,9 +221,9 @@ void ScrollBar::getScrollBarInfo(int *_pos, int *_len, int *_bar_size, int *_vie } else if (m_size > 0) { len = bar_size * viewport_size / m_size; - len = base::clamp(len, theme()->getScrollbarSize()*2-border_width, bar_size); + len = std::clamp(len, theme()->getScrollbarSize()*2-border_width, bar_size); pos = (bar_size-len) * m_pos / (m_size-viewport_size); - pos = base::clamp(pos, 0, bar_size-len); + pos = std::clamp(pos, 0, bar_size-len); } else { len = pos = 0; diff --git a/src/ui/slider.cpp b/src/ui/slider.cpp index 01897a0f6..cf4c44233 100644 --- a/src/ui/slider.cpp +++ b/src/ui/slider.cpp @@ -1,5 +1,5 @@ // Aseprite UI Library -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2016 David Capello // // This file is released under the terms of the MIT license. @@ -11,7 +11,6 @@ #include "ui/slider.h" -#include "base/clamp.h" #include "os/font.h" #include "ui/manager.h" #include "ui/message.h" @@ -34,7 +33,7 @@ Slider::Slider(int min, int max, int value, SliderDelegate* delegate) : Widget(kSliderWidget) , m_min(min) , m_max(max) - , m_value(base::clamp(value, min, max)) + , m_value(std::clamp(value, min, max)) , m_readOnly(false) , m_delegate(delegate) { @@ -46,7 +45,7 @@ void Slider::setRange(int min, int max) { m_min = min; m_max = max; - m_value = base::clamp(m_value, min, max); + m_value = std::clamp(m_value, min, max); invalidate(); } @@ -55,7 +54,7 @@ void Slider::setValue(int value) { int old_value = m_value; - m_value = base::clamp(value, m_min, m_max); + m_value = std::clamp(value, m_min, m_max); if (m_value != old_value) invalidate(); @@ -132,13 +131,13 @@ bool Slider::onProcessMessage(Message* msg) } // With right click else { - accuracy = base::clamp(rc.w / range, 1, rc.w); + accuracy = std::clamp(rc.w / range, 1, rc.w); value = slider_press_value + (mousePos.x - slider_press_x) / accuracy; } - value = base::clamp(value, m_min, m_max); + value = std::clamp(value, m_min, m_max); if (m_value != value) { setValue(value); onChange(); @@ -180,7 +179,7 @@ bool Slider::onProcessMessage(Message* msg) goto not_used; } - value = base::clamp(value, m_min, m_max); + value = std::clamp(value, m_min, m_max); if (m_value != value) { setValue(value); onChange(); @@ -196,7 +195,7 @@ bool Slider::onProcessMessage(Message* msg) + static_cast(msg)->wheelDelta().x - static_cast(msg)->wheelDelta().y; - value = base::clamp(value, m_min, m_max); + value = std::clamp(value, m_min, m_max); if (m_value != value) { this->setValue(value); diff --git a/src/ui/splitter.cpp b/src/ui/splitter.cpp index 0fe373eec..c1c6ac9b3 100644 --- a/src/ui/splitter.cpp +++ b/src/ui/splitter.cpp @@ -1,5 +1,5 @@ // Aseprite UI Library -// Copyright (C) 2019-2021 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2017 David Capello // // This file is released under the terms of the MIT license. @@ -11,7 +11,6 @@ #include "ui/splitter.h" -#include "base/clamp.h" #include "ui/load_layout_event.h" #include "ui/manager.h" #include "ui/message.h" @@ -359,22 +358,22 @@ void Splitter::calcPos() if (align() & HORIZONTAL) { switch (m_type) { case ByPercentage: - m_pos = base::clamp(m_userPos, 0, 100); + m_pos = std::clamp(m_userPos, 0, 100); break; case ByPixel: if (isVisible()) - m_pos = base::clamp(m_userPos, 0, bounds().w); + m_pos = std::clamp(m_userPos, 0, bounds().w); break; } } else { switch (m_type) { case ByPercentage: - m_pos = base::clamp(m_userPos, 0, 100); + m_pos = std::clamp(m_userPos, 0, 100); break; case ByPixel: if (isVisible()) - m_pos = base::clamp(m_userPos, 0, bounds().h); + m_pos = std::clamp(m_userPos, 0, bounds().h); break; } } diff --git a/src/ui/tooltips.cpp b/src/ui/tooltips.cpp index e108589f8..83e9ffa3a 100644 --- a/src/ui/tooltips.cpp +++ b/src/ui/tooltips.cpp @@ -1,5 +1,5 @@ // Aseprite UI Library -// Copyright (C) 2018-2020 Igara Studio S.A. +// Copyright (C) 2018-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This file is released under the terms of the MIT license. @@ -11,7 +11,6 @@ #include "ui/tooltips.h" -#include "base/clamp.h" #include "gfx/size.h" #include "ui/graphics.h" #include "ui/intern.h" @@ -212,8 +211,8 @@ bool TipWindow::pointAt(int arrowAlign, const gfx::Rect& target) break; } - x = base::clamp(x, 0, ui::display_w()-w); - y = base::clamp(y, 0, ui::display_h()-h); + x = std::clamp(x, 0, ui::display_w()-w); + y = std::clamp(y, 0, ui::display_h()-h); if (m_target.intersects(gfx::Rect(x, y, w, h))) { switch (trycount) { diff --git a/src/ui/view.cpp b/src/ui/view.cpp index 8b5f8c290..ff76e225a 100644 --- a/src/ui/view.cpp +++ b/src/ui/view.cpp @@ -1,5 +1,5 @@ // Aseprite UI Library -// Copyright (C) 2018-2021 Igara Studio S.A. +// Copyright (C) 2018-2022 Igara Studio S.A. // Copyright (C) 2001-2017 David Capello // // This file is released under the terms of the MIT license. @@ -11,7 +11,6 @@ #include "config.h" #endif -#include "base/clamp.h" #include "gfx/size.h" #include "ui/intern.h" #include "ui/manager.h" @@ -390,8 +389,8 @@ gfx::Point View::limitScrollPosToViewport(const gfx::Point& pt) const { const Size maxSize = getScrollableSize(); const Size visible = visibleSize(); - return Point(base::clamp(pt.x, 0, std::max(0, maxSize.w - visible.w)), - base::clamp(pt.y, 0, std::max(0, maxSize.h - visible.h))); + return Point(std::clamp(pt.x, 0, std::max(0, maxSize.w - visible.w)), + std::clamp(pt.y, 0, std::max(0, maxSize.h - visible.h))); } } // namespace ui diff --git a/src/ui/widget.cpp b/src/ui/widget.cpp index 096a56b55..c664cec82 100644 --- a/src/ui/widget.cpp +++ b/src/ui/widget.cpp @@ -13,7 +13,6 @@ #include "ui/widget.h" -#include "base/clamp.h" #include "base/memory.h" #include "base/string.h" #include "base/utf8_decode.h" @@ -614,7 +613,7 @@ void Widget::insertChild(int index, Widget* child) ASSERT_VALID_WIDGET(this); ASSERT_VALID_WIDGET(child); - index = base::clamp(index, 0, int(m_children.size())); + index = std::clamp(index, 0, int(m_children.size())); auto it = m_children.begin() + index; it = m_children.insert(it, child); @@ -1298,8 +1297,8 @@ Size Widget::sizeHint() onSizeHint(ev); Size sz(ev.sizeHint()); - sz.w = base::clamp(sz.w, m_minSize.w, m_maxSize.w); - sz.h = base::clamp(sz.h, m_minSize.h, m_maxSize.h); + sz.w = std::clamp(sz.w, m_minSize.w, m_maxSize.w); + sz.h = std::clamp(sz.h, m_minSize.h, m_maxSize.h); return sz; } } @@ -1327,8 +1326,8 @@ Size Widget::sizeHint(const Size& fitIn) onSizeHint(ev); Size sz(ev.sizeHint()); - sz.w = base::clamp(sz.w, m_minSize.w, m_maxSize.w); - sz.h = base::clamp(sz.h, m_minSize.h, m_maxSize.h); + sz.w = std::clamp(sz.w, m_minSize.w, m_maxSize.w); + sz.h = std::clamp(sz.h, m_minSize.h, m_maxSize.h); return sz; } }