diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 51fc0fac..e8ce781d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -52,7 +52,7 @@ jobs: tidy-checks: '' step-summary: true file-annotations: true - ignore: subprojects|build|android|assets|recordings|docs|toolchains|platforms|wrapper|src/libs/core/hash-library|src/lobby/curl_client.* + ignore: subprojects|build|android|assets|recordings|docs|toolchains|platforms|wrapper|src/libs/core/hash-library|tests|src/lobby/curl_client.* - name: Fail CI run if linter checks failed if: steps.linter.outputs.checks-failed != 0 diff --git a/src/discord/core.hpp b/src/discord/core.hpp index d9e5a347..2e00b567 100644 --- a/src/discord/core.hpp +++ b/src/discord/core.hpp @@ -110,7 +110,7 @@ struct DiscordInstance { std::unique_ptr m_core; std::unique_ptr m_current_user; - DiscordInstance(discord::Core* core); + explicit DiscordInstance(discord::Core* core); public: OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] static helper::expected initialize(); diff --git a/src/executables/game/application.cpp b/src/executables/game/application.cpp index 6d67b577..1c3a29e1 100644 --- a/src/executables/game/application.cpp +++ b/src/executables/game/application.cpp @@ -183,7 +183,7 @@ void Application::update() { if (scene_change) { std::visit( - helper::overloaded{ + helper::Overloaded{ [this, index](const scenes::Scene::Pop&) { m_scene_stack.erase( m_scene_stack.begin() @@ -201,10 +201,11 @@ void Application::update() { }, [this](const scenes::Scene::Switch& scene_switch) { spdlog::info( - "switching to scene {}", magic_enum::enum_name(scene_switch.target_scene) + "switching to scene {}", magic_enum::enum_name(scene_switch.m_target_scene) + ); + auto scene = scenes::create_scene( + *this, scene_switch.m_target_scene, scene_switch.m_layout ); - auto scene = - scenes::create_scene(*this, scene_switch.target_scene, scene_switch.layout); // only clear, after the construction was successful m_scene_stack.clear(); diff --git a/src/executables/game/application.hpp b/src/executables/game/application.hpp index 53597acd..b4fbaab9 100644 --- a/src/executables/game/application.hpp +++ b/src/executables/game/application.hpp @@ -45,7 +45,8 @@ struct Application final : public EventListener, public ServiceProvider { #endif protected: - EventDispatcher m_event_dispatcher; + EventDispatcher + m_event_dispatcher; //NOLINT(misc-non-private-member-variables-in-classes,cppcoreguidelines-non-private-member-variables-in-classes) private: std::vector> m_scene_stack; diff --git a/src/executables/utility/main.cpp b/src/executables/utility/main.cpp index 2315bf8c..a4c4e50c 100644 --- a/src/executables/utility/main.cpp +++ b/src/executables/utility/main.cpp @@ -7,50 +7,51 @@ #include #include -void print_info(const recorder::RecordingReader& recording_reader) noexcept { - //TODO(Totto): Implement, print basic information and final result for each simulation - UNUSED(recording_reader); - std::cerr << "NOT IMPLEMENTED\n"; -} +namespace { + void print_info(const recorder::RecordingReader& recording_reader) noexcept { + //TODO(Totto): Implement, print basic information and final result for each simulation + UNUSED(recording_reader); + std::cerr << "NOT IMPLEMENTED\n"; + } -void dump_json(const recorder::RecordingReader& recording_reader, bool pretty_print, bool ensure_ascii) noexcept { + void dump_json(const recorder::RecordingReader& recording_reader, bool pretty_print, bool ensure_ascii) noexcept { - auto result = json::try_convert_to_json(recording_reader); + auto result = json::try_convert_to_json(recording_reader); - if (not result.has_value()) { - std::cerr << fmt::format("An error occurred during converting to json: {}\n", result.error()); - std::exit(1); - } + if (not result.has_value()) { + std::cerr << fmt::format("An error occurred during converting to json: {}\n", result.error()); + std::exit(1); + } - int indent = -1; - char indent_char = ' '; + int indent = -1; + char indent_char = ' '; - if (pretty_print) { - indent = 1; - indent_char = '\t'; - } + if (pretty_print) { + indent = 1; + indent_char = '\t'; + } - try { + try { - std::cout << result.value().dump(indent, indent_char, ensure_ascii); + std::cout << result.value().dump(indent, indent_char, ensure_ascii); - } catch (const std::exception& error) { - std::cerr << error.what(); - std::exit(1); - } + } catch (const std::exception& error) { + std::cerr << error.what(); + std::exit(1); + } - if (pretty_print) { - std::cout << "\n"; + if (pretty_print) { + std::cout << "\n"; + } } -} +} // namespace int main(int argc, char** argv) noexcept { try { - auto arguments_result = CommandLineArguments::from_args(argc, argv); if (not arguments_result.has_value()) { @@ -80,7 +81,7 @@ int main(int argc, char** argv) noexcept { const auto recording_reader = std::move(parsed.value()); std::visit( - helper::overloaded{ [&recording_reader](const Dump& dump) { + helper::Overloaded{ [&recording_reader](const Dump& dump) { dump_json(recording_reader, dump.pretty_print, dump.ensure_ascii); }, [&recording_reader](const Info& /* info */) { print_info(recording_reader); } }, diff --git a/src/game/bag.cpp b/src/game/bag.cpp index 90f1d6b1..1f431cdf 100644 --- a/src/game/bag.cpp +++ b/src/game/bag.cpp @@ -3,7 +3,9 @@ Bag::Bag(Random& random) : m_tetromino_sequence{} { // initialize array with invalid tetromino type for (helper::TetrominoType& type : m_tetromino_sequence) { - type = static_cast(static_cast(helper::TetrominoType::LastType) + 1); + type = static_cast( //NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) + static_cast(helper::TetrominoType::LastType) + 1 + ); } // fill in the sequence with random order diff --git a/src/game/grid.cpp b/src/game/grid.cpp index 942f350c..f9b443d7 100644 --- a/src/game/grid.cpp +++ b/src/game/grid.cpp @@ -6,7 +6,7 @@ Grid::Grid(const ui::Layout& layout, bool is_top_level) : ui::Widget{ layout, ui::WidgetType::Component, is_top_level } { - const u32 total_x_tiles = grid::preview_extends.x * 2 + 2 + grid::width_in_tiles; + const u32 total_x_tiles = (grid::preview_extends.x * 2) + 2 + grid::width_in_tiles; constexpr u32 total_y_tiles = grid::height_in_tiles; const u32 tile_size_x = layout.get_rect().width() / total_x_tiles; @@ -86,7 +86,7 @@ void Grid::draw_background(const ServiceProvider& service_provider, GridRect gri for (u32 column = 0; column <= grid_rect.width(); ++column) { const auto start = top_left + shapes::UPoint{ column * m_tile_size, 0 }; - const auto end = shapes::UPoint{ start.x, start.y + grid_rect.height() * m_tile_size }; + const auto end = shapes::UPoint{ start.x, start.y + (grid_rect.height() * m_tile_size) }; service_provider.renderer().draw_line(start, end, grid_color); service_provider.renderer().draw_line(start - shapes::UPoint{ 1, 0 }, end - shapes::UPoint{ 1, 0 }, grid_color); } @@ -100,8 +100,8 @@ void Grid::draw_background(const ServiceProvider& service_provider, GridRect gri const auto outline_top_left = top_left - shapes::UPoint{ 2, 2 }; const auto outline_bottom_right = shapes::UPoint{ - top_left.x + grid_rect.width() * m_tile_size + 1, - top_left.y + grid_rect.height() * m_tile_size + 1, + top_left.x + (grid_rect.width() * m_tile_size) + 1, + top_left.y + (grid_rect.height() * m_tile_size) + 1, }; const auto outline_rect = shapes::URect{ diff --git a/src/game/tetrion.cpp b/src/game/tetrion.cpp index 177a775c..a6b7b263 100644 --- a/src/game/tetrion.cpp +++ b/src/game/tetrion.cpp @@ -24,7 +24,7 @@ Tetrion::Tetrion( : ui::Widget{ layout , ui::WidgetType::Component ,is_top_level}, SimulatedTetrion{tetrion_index,random_seed,starting_level, service_provider,std::move(recording_writer)}, m_main_layout{ - utils::size_t_identity<2>(), + utils::SizeIdentity<2>(), 0, ui::Direction::Vertical, { 0.85 }, diff --git a/src/graphics/rect.hpp b/src/graphics/rect.hpp index bd955d70..cf930672 100644 --- a/src/graphics/rect.hpp +++ b/src/graphics/rect.hpp @@ -17,9 +17,9 @@ namespace shapes { constexpr AbstractRect(Point top_left, Point bottom_right) // NOLINT(bugprone-easily-swappable-parameters) : top_left{ top_left }, bottom_right{ bottom_right } { } - constexpr AbstractRect(T x, T y, T width, T height) - : top_left{ x, y }, - bottom_right{ x + width - 1, y + height - 1 } { } + constexpr AbstractRect(T x_pos, T y_pos, T width, T height) + : top_left{ x_pos, y_pos }, + bottom_right{ x_pos + width - 1, y_pos + height - 1 } { } [[nodiscard]] constexpr T width() const { return static_cast(bottom_right.x - top_left.x + 1); diff --git a/src/graphics/renderer.cpp b/src/graphics/renderer.cpp index 78a8cc46..5eb09c8f 100644 --- a/src/graphics/renderer.cpp +++ b/src/graphics/renderer.cpp @@ -91,35 +91,36 @@ void Renderer::draw_self_computed_circle_impl(const shapes::IPoint& center, i32 const i32 radius = diameter / 2; - i32 x = radius - 1; - i32 y = 0; - i32 tx = 1; - i32 ty = 1; - i32 error = tx - diameter; + i32 x_pos = radius - 1; + i32 y_pos = 0; + i32 tx_pos = 1; + i32 ty_pos = 1; + i32 error = tx_pos - diameter; - while (x >= y) { + while (x_pos >= y_pos) { // Each of the following renders an octant of the circle SDL_RenderDrawPoint( - m_renderer, center_x + x, center_y - y // NOLINT(clang-analyzer-core.UndefinedBinaryOperatorResult) + m_renderer, center_x + x_pos, // NOLINT(clang-analyzer-core.UndefinedBinaryOperatorResult) + center_y - y_pos ); - SDL_RenderDrawPoint(m_renderer, center_x + x, center_y + y); - SDL_RenderDrawPoint(m_renderer, center_x - x, center_y - y); - SDL_RenderDrawPoint(m_renderer, center_x - x, center_y + y); - SDL_RenderDrawPoint(m_renderer, center_x + y, center_y - x); - SDL_RenderDrawPoint(m_renderer, center_x + y, center_y + x); - SDL_RenderDrawPoint(m_renderer, center_x - y, center_y - x); - SDL_RenderDrawPoint(m_renderer, center_x - y, center_y + x); + SDL_RenderDrawPoint(m_renderer, center_x + x_pos, center_y + y_pos); + SDL_RenderDrawPoint(m_renderer, center_x - x_pos, center_y - y_pos); + SDL_RenderDrawPoint(m_renderer, center_x - x_pos, center_y + y_pos); + SDL_RenderDrawPoint(m_renderer, center_x + y_pos, center_y - x_pos); + SDL_RenderDrawPoint(m_renderer, center_x + y_pos, center_y + x_pos); + SDL_RenderDrawPoint(m_renderer, center_x - y_pos, center_y - x_pos); + SDL_RenderDrawPoint(m_renderer, center_x - y_pos, center_y + x_pos); if (error <= 0) { - ++y; - error += ty; - ty += 2; + ++y_pos; + error += ty_pos; + ty_pos += 2; } if (error > 0) { - --x; - tx += 2; - error += (tx - diameter); + --x_pos; + tx_pos += 2; + error += (tx_pos - diameter); } } } diff --git a/src/graphics/renderer.hpp b/src/graphics/renderer.hpp index faf412a8..13dd0d96 100644 --- a/src/graphics/renderer.hpp +++ b/src/graphics/renderer.hpp @@ -73,9 +73,9 @@ struct Renderer final { } template - void draw_texture(const Texture& texture, const shapes::AbstractRect& from, const shapes::AbstractRect& to) + void draw_texture(const Texture& texture, const shapes::AbstractRect& from, const shapes::AbstractRect& dest) const { - texture.render(m_renderer, from, to); + texture.render(m_renderer, from, dest); } OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] Texture load_image(const std::filesystem::path& image_path) const; diff --git a/src/graphics/texture.hpp b/src/graphics/texture.hpp index 8db232f3..d2b18c0e 100644 --- a/src/graphics/texture.hpp +++ b/src/graphics/texture.hpp @@ -56,9 +56,9 @@ struct Texture { } template - void render(SDL_Renderer* renderer, const shapes::AbstractRect& from, const shapes::URect& to) const { + void render(SDL_Renderer* renderer, const shapes::AbstractRect& from, const shapes::URect& dest) const { const SDL_Rect from_rect_sdl = from.to_sdl_rect(); - const SDL_Rect to_rect_sdl = to.to_sdl_rect(); + const SDL_Rect to_rect_sdl = dest.to_sdl_rect(); SDL_RenderCopy(renderer, m_raw_texture, &from_rect_sdl, &to_rect_sdl); } diff --git a/src/helper/message_box.hpp b/src/helper/message_box.hpp index 7b53c3c7..fce6f43d 100644 --- a/src/helper/message_box.hpp +++ b/src/helper/message_box.hpp @@ -2,6 +2,8 @@ #pragma once +#include + #include #include diff --git a/src/helper/music_utils.hpp b/src/helper/music_utils.hpp index 8482c976..ab5af63e 100644 --- a/src/helper/music_utils.hpp +++ b/src/helper/music_utils.hpp @@ -5,11 +5,11 @@ namespace utils { - template + template constexpr auto get_supported_music_extension( const char( // NOLINT(modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) &name - )[data_size] + )[DataSize] ) { #if not defined(AUDIO_PREFER_MP3) and not defined(AUDIO_PREFER_FLAC) diff --git a/src/helper/nfd.cpp b/src/helper/nfd.cpp index ffdbf135..a6287031 100644 --- a/src/helper/nfd.cpp +++ b/src/helper/nfd.cpp @@ -56,7 +56,7 @@ namespace { auto* extensions = new nfdu8char_t[extension_list_size]; // NOLINT(cppcoreguidelines-owning-memory) std::memcpy(extensions, extension_list.c_str(), extension_list_size * sizeof(nfdu8char_t)); - filter_item.get()[i] = { name, extensions }; + filter_item.get()[i] = { .name = name, .spec = extensions }; } } @@ -68,7 +68,7 @@ namespace { } // namespace -helper::expected helper::openFileDialog( +helper::expected helper::open_file_dialog( const std::vector& allowed_files, std::optional default_path ) { @@ -108,7 +108,7 @@ helper::expected helper::openFileDialog( } -[[nodiscard]] helper::expected, std::string> helper::openMultipleFilesDialog( +[[nodiscard]] helper::expected, std::string> helper::open_multiple_files_dialog( const std::vector& allowed_files, std::optional default_path ) { @@ -160,7 +160,7 @@ helper::expected helper::openFileDialog( return helper::unexpected{ "Error: " + std::string{ NFD::GetError() } }; } -[[nodiscard]] helper::expected helper::openFolderDialog( +[[nodiscard]] helper::expected helper::open_folder_dialog( std::optional default_path ) { diff --git a/src/helper/nfd_include.hpp b/src/helper/nfd_include.hpp index 7b8117e3..417b9ec3 100644 --- a/src/helper/nfd_include.hpp +++ b/src/helper/nfd_include.hpp @@ -27,17 +27,17 @@ namespace helper { //NOTE: this API is blocking and can't be asynchronous, due to os (linux, windows, macos) restrictions, it HAS to be launched in the same thread NFD_Init() was launched /the main thread) - [[nodiscard]] helper::expected openFileDialog( + [[nodiscard]] helper::expected open_file_dialog( const std::vector& allowed_files = {}, std::optional default_path = std::nullopt ); - [[nodiscard]] helper::expected, std::string> openMultipleFilesDialog( + [[nodiscard]] helper::expected, std::string> open_multiple_files_dialog( const std::vector& allowed_files = {}, std::optional default_path = std::nullopt ); - [[nodiscard]] helper::expected openFolderDialog( + [[nodiscard]] helper::expected open_folder_dialog( std::optional default_path = std::nullopt ); diff --git a/src/input/guid.cpp b/src/input/guid.cpp index 0ec5105e..40ab78bf 100644 --- a/src/input/guid.cpp +++ b/src/input/guid.cpp @@ -1,4 +1,5 @@ +#include #include #include "guid.hpp" @@ -7,7 +8,7 @@ #include sdl::GUID::GUID(const SDL_GUID& data) : m_guid{} { - std::copy(std::begin(data.data), std::end(data.data), std::begin(m_guid)); + std::ranges::copy(data.data, std::begin(m_guid)); } [[nodiscard]] helper::expected sdl::GUID::from_string(const std::string& value) { diff --git a/src/input/input.cpp b/src/input/input.cpp index 90b34c49..fc3923ba 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -211,7 +211,7 @@ namespace { auto result = std::visit( - helper::overloaded{ + helper::Overloaded{ [service_provider](const input::KeyboardSettings& keyboard_settings) mutable -> ReturnType { auto* const event_dispatcher = &(service_provider->event_dispatcher()); return std::make_shared(keyboard_settings, event_dispatcher); diff --git a/src/libs/core/helper/color.cpp b/src/libs/core/helper/color.cpp index 51b24a72..e83ad01f 100644 --- a/src/libs/core/helper/color.cpp +++ b/src/libs/core/helper/color.cpp @@ -119,13 +119,13 @@ namespace { } // use custom fmod, that always result in a positive value - const FloatType h = h_temp * static_cast(60.0); //degrees + const FloatType hue = h_temp * static_cast(60.0); //degrees - const FloatType s = max == static_cast(0.0) ? static_cast(0.0) : delta / max; + const FloatType saturation = max == static_cast(0.0) ? static_cast(0.0) : delta / max; //v = max - return HSVColor{ static_cast(h), static_cast(s), static_cast(max), a }; + return HSVColor{ static_cast(hue), static_cast(saturation), static_cast(max), a }; } //Note: this output formats are all deserializable by the from_string method! diff --git a/src/libs/core/helper/color.hpp b/src/libs/core/helper/color.hpp index f4cd2220..12019903 100644 --- a/src/libs/core/helper/color.hpp +++ b/src/libs/core/helper/color.hpp @@ -87,7 +87,7 @@ namespace { //NOLINT(cert-dcl59-cpp,google-build-namespaces) return std::fmod(value, divisor); } - return value - static_cast(static_cast(value / divisor)) * divisor; + return value - (static_cast(static_cast(value / divisor)) * divisor); } template diff --git a/src/libs/core/helper/date.cpp b/src/libs/core/helper/date.cpp index 16c7bba1..1af602ac 100644 --- a/src/libs/core/helper/date.cpp +++ b/src/libs/core/helper/date.cpp @@ -8,9 +8,9 @@ date::ISO8601Date::ISO8601Date(u64 value) : m_value{ value } { } -date::ISO8601Date::ISO8601Date(std::tm tm) { +date::ISO8601Date::ISO8601Date(std::tm time_struct) { - const std::time_t time = std::mktime(&tm); + const std::time_t time = std::mktime(&time_struct); if (time < 0) { throw std::runtime_error("Couldn't convert std::tm to std::time_t"); @@ -30,14 +30,14 @@ date::ISO8601Date date::ISO8601Date::now() { helper::expected date::ISO8601Date::from_string(const std::string& input) { - std::tm tm = {}; + std::tm time_struct = {}; #if defined(_MSC_VER) || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) \ || defined(__SERENITY__) std::istringstream input_stream{ input }; - input_stream >> std::get_time(&tm, ISO8601Date::iso_8601_format_string); + input_stream >> std::get_time(&time_struct, ISO8601Date::iso_8601_format_string); if (input_stream.fail()) { return helper::unexpected{ "error calling std::get_time(): unable to convert input" }; @@ -46,7 +46,7 @@ helper::expected date::ISO8601Date::from_string( } #else - auto* const result = strptime(input.c_str(), ISO8601Date::iso_8601_format_string, &tm); + auto* const result = strptime(input.c_str(), ISO8601Date::iso_8601_format_string, &time_struct); if (result == nullptr) { return helper::unexpected{ fmt::format("error calling strptime: {}", std::strerror(errno)) }; @@ -59,35 +59,35 @@ helper::expected date::ISO8601Date::from_string( #endif // see why this is set: https://en.cppreference.com/w/cpp/chrono/c/mktime#Notes - tm.tm_isdst = 0; // Not daylight saving + time_struct.tm_isdst = 0; // Not daylight saving - return ISO8601Date{ tm }; + return ISO8601Date{ time_struct }; } [[nodiscard]] helper::expected date::ISO8601Date::get_tm_struct(std::time_t value) { - std::tm tm{}; + std::tm time_struct{}; #if defined(_MSC_VER) || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) - if (gmtime_s(&tm, &value) != 0) { + if (gmtime_s(&time_struct, &value) != 0) { return helper::unexpected{ "error calling gmtime_s" }; } #else - if (gmtime_r(&value, &tm) == nullptr) { + if (gmtime_r(&value, &time_struct) == nullptr) { return helper::unexpected{ fmt::format("error calling gmtime_r: {}", std::strerror(errno)) }; } #endif - return tm; + return time_struct; } [[nodiscard]] helper::expected -date::ISO8601Date::format_tm_struct(std::tm tm, const char* format_string) { +date::ISO8601Date::format_tm_struct(std::tm time_struct, const char* format_string) { static constexpr auto buffer_size = usize{ 100 }; std::array buffer{}; - const auto result = std::strftime(buffer.data(), buffer.size(), format_string, &tm); + const auto result = std::strftime(buffer.data(), buffer.size(), format_string, &time_struct); if (result == 0) { return helper::unexpected{ "error calling std::strftime" }; } @@ -97,12 +97,12 @@ date::ISO8601Date::format_tm_struct(std::tm tm, const char* format_string) { [[nodiscard]] helper::expected date::ISO8601Date::to_string() const { - const auto tm = get_tm_struct(static_cast(m_value)); - if (not tm.has_value()) { - return helper::unexpected{ tm.error() }; + const auto time_struct = get_tm_struct(static_cast(m_value)); + if (not time_struct.has_value()) { + return helper::unexpected{ time_struct.error() }; } - const auto formatted = format_tm_struct(tm.value(), ISO8601Date::iso_8601_format_string); + const auto formatted = format_tm_struct(time_struct.value(), ISO8601Date::iso_8601_format_string); if (not formatted.has_value()) { return helper::unexpected{ formatted.error() }; } diff --git a/src/libs/core/helper/date.hpp b/src/libs/core/helper/date.hpp index 8f744680..1f487812 100644 --- a/src/libs/core/helper/date.hpp +++ b/src/libs/core/helper/date.hpp @@ -13,7 +13,7 @@ namespace date { private: u64 m_value; - ISO8601Date(std::tm tm); + explicit ISO8601Date(std::tm time_struct); static constexpr const char* iso_8601_format_string = "%Y%m%dT%H%M%S"; @@ -31,7 +31,7 @@ namespace date { [[nodiscard]] static helper::expected get_tm_struct(std::time_t value); [[nodiscard]] static helper::expected - format_tm_struct(std::tm tm, const char* format_string); + format_tm_struct(std::tm time_struct, const char* format_string); }; diff --git a/src/libs/core/helper/errors.hpp b/src/libs/core/helper/errors.hpp index 91ffc084..525cfb1a 100644 --- a/src/libs/core/helper/errors.hpp +++ b/src/libs/core/helper/errors.hpp @@ -5,6 +5,8 @@ #include "./types.hpp" #include "./windows.hpp" +#include + #include #include diff --git a/src/libs/core/helper/expected.hpp b/src/libs/core/helper/expected.hpp index 74d74321..f7208fc6 100644 --- a/src/libs/core/helper/expected.hpp +++ b/src/libs/core/helper/expected.hpp @@ -12,17 +12,17 @@ namespace helper { #ifdef _USE_TL_EXPECTED template - using expected = tl::expected; + using expected = tl::expected; //NOLINT(readability-identifier-naming) template - using unexpected = tl::unexpected; + using unexpected = tl::unexpected; //NOLINT(readability-identifier-naming) #else template - using expected = std::expected; + using expected = std::expected; //NOLINT(readability-identifier-naming) template - using unexpected = std::unexpected; + using unexpected = std::unexpected; //NOLINT(readability-identifier-naming) #endif diff --git a/src/libs/core/helper/meson.build b/src/libs/core/helper/meson.build index 6c87202e..543f4079 100644 --- a/src/libs/core/helper/meson.build +++ b/src/libs/core/helper/meson.build @@ -6,6 +6,7 @@ core_src_files += files( 'random.cpp', 'sleep.cpp', 'string_manipulation.cpp', + 'timer.cpp', ) _header_files = files( diff --git a/src/libs/core/helper/point.hpp b/src/libs/core/helper/point.hpp index d7443388..be8717b3 100644 --- a/src/libs/core/helper/point.hpp +++ b/src/libs/core/helper/point.hpp @@ -15,7 +15,9 @@ namespace shapes { T y; constexpr AbstractPoint() : AbstractPoint{ 0, 0 } { } - constexpr AbstractPoint(T x, T y) : x{ x }, y{ y } { } // NOLINT(bugprone-easily-swappable-parameters) + constexpr AbstractPoint(T x_pos, T y_pos) + : x{ x_pos }, + y{ y_pos } { } // NOLINT(bugprone-easily-swappable-parameters) static constexpr AbstractPoint zero() { return AbstractPoint{ 0, 0 }; @@ -46,7 +48,7 @@ namespace shapes { } constexpr AbstractPoint operator-(AbstractPoint rhs) const { - if constexpr (std::is_signed::value) { + if constexpr (std::is_signed_v) { return *this + (-rhs); } else { assert(x >= rhs.x && y >= rhs.y && "underflow in subtraction"); @@ -66,11 +68,61 @@ namespace shapes { template constexpr AbstractPoint cast() const { - if constexpr (std::is_signed::value and not std::is_signed::value) { - assert(x >= 0 && y >= 0 && "Not allowed to cast away negative number into an unsigned type"); + +#if !defined(NDEBUG) + if constexpr (std::is_signed_v != std::is_signed_v) { + if constexpr (std::is_signed_v and not std::is_signed_v) { + // source is signed, destination is unsigned, so both checks are necessary + + assert(x >= static_cast(0) && y >= static_cast(0) && "cast invalid, value to small"); + assert(static_cast(x) <= std::numeric_limits::max() + && static_cast(y) <= std::numeric_limits::max() && "cast invalid, value to big"); + + } else { + // source is unsigned, destination is signed, so only the max check is necessary + + assert(x <= std::numeric_limits::max() && y <= std::numeric_limits::max() + && "cast invalid, value to big"); + } } else { - return AbstractPoint{ static_cast(x), static_cast(y) }; + if constexpr (std::is_signed_v and std::is_signed_v) { + // both are signed, so both checks are necessary + + assert(x >= std::numeric_limits::min() && y >= std::numeric_limits::min() + && "cast invalid, value to small"); + assert(static_cast(x) <= std::numeric_limits::max() + && static_cast(y) <= std::numeric_limits::max() && "cast invalid, value to big"); + } else { + // both are unsigned, so no min check is necessary + assert(x <= std::numeric_limits::max() && y <= std::numeric_limits::max() + && "cast invalid, value to big"); + } } +#endif + + return AbstractPoint{ static_cast(x), static_cast(y) }; + } + + template + constexpr AbstractPoint cast_truncate() const { + + auto x_final = x; + + if (x < std::numeric_limits::min()) { + x_final = std::numeric_limits::min(); + } else if (x > std::numeric_limits::max()) { + x_final = std::numeric_limits::max(); + } + + auto y_final = y; + + if (y < std::numeric_limits::min()) { + y_final = std::numeric_limits::min(); + } else if (y > std::numeric_limits::max()) { + y_final = std::numeric_limits::max(); + } + + return AbstractPoint{ static_cast(x_final), static_cast(y_final) }; } }; diff --git a/src/libs/core/helper/random.hpp b/src/libs/core/helper/random.hpp index 16b0b7d3..ced8f629 100644 --- a/src/libs/core/helper/random.hpp +++ b/src/libs/core/helper/random.hpp @@ -18,7 +18,7 @@ struct Random { OOPETRIS_CORE_EXPORTED Random(); OOPETRIS_CORE_EXPORTED explicit Random(std::mt19937_64::result_type seed); - template + template [[nodiscard]] Integer random(const Integer upper_bound_exclusive) { auto distribution = std::uniform_int_distribution{ 0, upper_bound_exclusive - 1 }; return distribution(m_generator); diff --git a/src/libs/core/helper/static_string.hpp b/src/libs/core/helper/static_string.hpp index f279ad83..aea84fd2 100644 --- a/src/libs/core/helper/static_string.hpp +++ b/src/libs/core/helper/static_string.hpp @@ -9,21 +9,22 @@ #include #include -template +template struct StaticString { private: - std::array m_data; + std::array m_data; constexpr StaticString() : m_data{} { } public: - constexpr StaticString(const char (&chars // NOLINT(modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) - )[data_size]) { - std::copy(chars, chars + data_size, begin()); + constexpr explicit StaticString(const char( // NOLINT(modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) + &chars + )[DataSize]) { + std::copy(chars, chars + DataSize, begin()); } [[nodiscard]] constexpr usize size() const { - return data_size - 1; + return DataSize - 1; } [[nodiscard]] constexpr usize length() const { @@ -80,8 +81,8 @@ struct StaticString { return m_data.back(); } - template> - [[nodiscard]] constexpr Result operator+(const StaticString& other) const { + template> + [[nodiscard]] constexpr Result operator+(const StaticString& other) const { auto concatenated = Result{}; std::ranges::copy(*this, concatenated.begin()); std::ranges::copy(other, concatenated.begin() + size()); @@ -101,21 +102,21 @@ struct StaticString { return std::string_view{ cbegin(), cend() }; } - template + template [[nodiscard]] friend constexpr bool - operator==(const StaticString& self, const StaticString& other) { + operator==(const StaticString& self, const StaticString& other) { return self.m_data == other.m_data; } - template + template [[nodiscard]] friend constexpr bool - operator!=(const StaticString& self, const StaticString& other) { + operator!=(const StaticString& self, const StaticString& other) { return not(self == other); } - template + template [[nodiscard]] constexpr auto - join(const StaticString& first, const StaticString&... rest) const { + join(const StaticString& first, const StaticString&... rest) const { if constexpr (sizeof...(rest) == 0) { return first; } else { @@ -123,24 +124,24 @@ struct StaticString { } } - [[nodiscard]] constexpr operator const char*() const { + [[nodiscard]] constexpr operator const char*() const { //NOLINT(google-explicit-constructor) return c_str(); } - [[nodiscard]] constexpr operator std::string_view() const { + [[nodiscard]] constexpr operator std::string_view() const { //NOLINT(google-explicit-constructor) return string_view(); } - [[nodiscard]] operator std::string() const { + [[nodiscard]] operator std::string() const { //NOLINT(google-explicit-constructor) return string(); } - [[nodiscard]] operator std::filesystem::path() const { + [[nodiscard]] operator std::filesystem::path() const { //NOLINT(google-explicit-constructor) return string(); } // make all template instantiations of this template a friend - template + template friend struct StaticString; }; diff --git a/src/libs/core/helper/timer.cpp b/src/libs/core/helper/timer.cpp new file mode 100644 index 00000000..78f48d58 --- /dev/null +++ b/src/libs/core/helper/timer.cpp @@ -0,0 +1,32 @@ + + +#include "./timer.hpp" + + +helper::Timer::Timer(Callback callback, const Duration& interval) + : m_callback{ std::move(callback) }, + m_interval{ interval } { } + +void helper::Timer::start() { + m_running = true; + m_last_measured = Clock::now(); +} + +void helper::Timer::stop() { + m_running = false; +} + +void helper::Timer::check() { + if (not m_running) { + return; + } + + const auto now = Clock::now(); + + const auto difference = now - m_last_measured; + + if (difference >= m_interval) { + m_callback(); + m_last_measured = now; + } +} diff --git a/src/libs/core/helper/timer.hpp b/src/libs/core/helper/timer.hpp index f1d17092..3879bee1 100644 --- a/src/libs/core/helper/timer.hpp +++ b/src/libs/core/helper/timer.hpp @@ -5,6 +5,8 @@ #include #include +#include "./windows.hpp" + namespace helper { struct Timer { @@ -14,39 +16,19 @@ namespace helper { using Duration = std::chrono::nanoseconds; bool m_running{ false }; - std::chrono::time_point last_measured; + std::chrono::time_point m_last_measured; Callback m_callback; Duration m_interval; public: - Timer(Callback callback, const Duration& interval) - : m_callback{ std::move(callback) }, - m_interval{ interval } { } - - void start() { - m_running = true; - last_measured = Clock::now(); - } - - void stop() { - m_running = false; - } - - void check() { - if (not m_running) { - return; - } + OOPETRIS_CORE_EXPORTED Timer(Callback callback, const Duration& interval); - const auto now = Clock::now(); + OOPETRIS_CORE_EXPORTED void start(); - const auto difference = now - last_measured; + OOPETRIS_CORE_EXPORTED void stop(); - if (difference >= m_interval) { - m_callback(); - last_measured = now; - } - } + OOPETRIS_CORE_EXPORTED void check(); }; diff --git a/src/libs/core/helper/types.hpp b/src/libs/core/helper/types.hpp index 943fc369..2fe8af00 100644 --- a/src/libs/core/helper/types.hpp +++ b/src/libs/core/helper/types.hpp @@ -3,14 +3,14 @@ #include #include -using usize = std::size_t; -using u8 = std::uint8_t; -using u16 = std::uint16_t; -using u32 = std::uint32_t; -using u64 = std::uint64_t; -using i8 = std::int8_t; -using i16 = std::int16_t; -using i32 = std::int32_t; -using i64 = std::int64_t; +using usize = std::size_t; //NOLINT(readability-identifier-naming) +using u8 = std::uint8_t; //NOLINT(readability-identifier-naming) +using u16 = std::uint16_t; //NOLINT(readability-identifier-naming) +using u32 = std::uint32_t; //NOLINT(readability-identifier-naming) +using u64 = std::uint64_t; //NOLINT(readability-identifier-naming) +using i8 = std::int8_t; //NOLINT(readability-identifier-naming) +using i16 = std::int16_t; //NOLINT(readability-identifier-naming) +using i32 = std::int32_t; //NOLINT(readability-identifier-naming) +using i64 = std::int64_t; //NOLINT(readability-identifier-naming) using SimulationStep = u64; diff --git a/src/libs/core/helper/utils.hpp b/src/libs/core/helper/utils.hpp index 2260b841..a2289f5c 100644 --- a/src/libs/core/helper/utils.hpp +++ b/src/libs/core/helper/utils.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -17,23 +18,19 @@ namespace helper { template - struct overloaded : Ts... { + struct Overloaded : Ts... { using Ts::operator()...; }; template - overloaded(Ts...) -> overloaded; + Overloaded(Ts...) -> Overloaded; } // namespace helper namespace utils { - // taken from llvm: https://github.com/llvm/llvm-project/blob/main/libcxx/include/__concepts/arithmetic.h#L27-L30 - // [concepts.arithmetic], arithmetic concepts - template - concept integral = std::is_integral_v; - template + template [[nodiscard]] constexpr Integral byte_swap(Integral value) noexcept { - // based on source: slartibartswift + // Note: based on source: slartibartswift auto result = Integral{}; for (usize i = 0; i < sizeof(Integral); ++i) { result <<= CHAR_BIT; @@ -43,7 +40,7 @@ namespace utils { return result; } - [[nodiscard]] constexpr auto to_little_endian(integral auto value) { + [[nodiscard]] constexpr auto to_little_endian(std::integral auto value) { if constexpr (std::endian::native == std::endian::little) { return value; } else { @@ -51,13 +48,13 @@ namespace utils { } } - [[nodiscard]] constexpr auto from_little_endian(integral auto value) { + [[nodiscard]] constexpr auto from_little_endian(std::integral auto value) { return to_little_endian(value); } template - [[nodiscard]] constexpr std::underlying_type_t to_underlying(Enum enum_) noexcept { - return static_cast>(enum_); + [[nodiscard]] constexpr std::underlying_type_t to_underlying(Enum enum_value) noexcept { + return static_cast>(enum_value); } #if __cpp_lib_unreachable >= 202202L @@ -74,7 +71,7 @@ namespace utils { } #endif template - struct size_t_identity { + struct SizeIdentity { //using type = T; }; diff --git a/src/libs/recordings/utility/additional_information.cpp b/src/libs/recordings/utility/additional_information.cpp index 1321b094..e4104f31 100644 --- a/src/libs/recordings/utility/additional_information.cpp +++ b/src/libs/recordings/utility/additional_information.cpp @@ -9,7 +9,7 @@ [[nodiscard]] std::string recorder::InformationValue::to_string(u32 recursion_depth // NOLINT(misc-no-recursion) ) const { return std::visit( - helper::overloaded{ + helper::Overloaded{ [](const std::string& value) { return value; }, [](const float& value) { return std::to_string(value); }, [](const double& value) { return std::to_string(value); }, diff --git a/src/libs/recordings/utility/additional_information.hpp b/src/libs/recordings/utility/additional_information.hpp index 31a3c1cb..eb29dae6 100644 --- a/src/libs/recordings/utility/additional_information.hpp +++ b/src/libs/recordings/utility/additional_information.hpp @@ -81,7 +81,7 @@ namespace recorder { [[nodiscard]] bool operator==(const InformationValue& other) const { // NOLINT(misc-no-recursion) return std::visit( - helper::overloaded{ + helper::Overloaded{ [this](const std::string& value) { return *this == value; }, [this](const float& value) { return *this == value; }, [this](const double& value) { return *this == value; }, diff --git a/src/libs/recordings/utility/checksum_helper.hpp b/src/libs/recordings/utility/checksum_helper.hpp index 33504f34..53ddcd32 100644 --- a/src/libs/recordings/utility/checksum_helper.hpp +++ b/src/libs/recordings/utility/checksum_helper.hpp @@ -18,7 +18,7 @@ struct Sha256Stream { Sha256Stream(); - template + template Sha256Stream& operator<<(const Integral value) { library_object.add( diff --git a/src/libs/recordings/utility/helper.hpp b/src/libs/recordings/utility/helper.hpp index 3f50c671..d5f362b5 100644 --- a/src/libs/recordings/utility/helper.hpp +++ b/src/libs/recordings/utility/helper.hpp @@ -29,7 +29,7 @@ namespace helper { template using ReadResult = helper::expected; - template + template [[nodiscard]] ReadResult> read_integral_from_file(std::ifstream& file) { if (not file) { return helper::unexpected{ @@ -78,7 +78,7 @@ namespace helper { return result; } - template + template [[nodiscard]] std::optional read_from_istream(std::istream& istream) { if (not istream) { return std::nullopt; @@ -123,7 +123,7 @@ namespace helper { namespace writer { - template + template helper::expected write_integral_to_file(std::ofstream& file, const Integral data) { if (not file) { return helper::unexpected{ fmt::format("failed to write data \"{}\"", data) }; @@ -154,7 +154,7 @@ namespace helper { } - template + template void append_value(std::vector& vector, const Integral value) { const auto little_endian_value = utils::to_little_endian(value); const char* const start = diff --git a/src/libs/recordings/utility/recording_json_wrapper.hpp b/src/libs/recordings/utility/recording_json_wrapper.hpp index 277da647..628ff6cb 100644 --- a/src/libs/recordings/utility/recording_json_wrapper.hpp +++ b/src/libs/recordings/utility/recording_json_wrapper.hpp @@ -21,7 +21,7 @@ namespace nlohmann { static void to_json(json& obj, const recorder::InformationValue& information) { // NOLINT(misc-no-recursion) std::visit( - helper::overloaded{ + helper::Overloaded{ [&obj](const std::string& value) { obj = value; }, [&obj](const float& value) { obj = value; }, [&obj](const double& value) { obj = value; }, [&obj](const bool& value) { obj = value; }, [&obj](const u8& value) { obj = value; }, diff --git a/src/libs/recordings/utility/recording_writer.hpp b/src/libs/recordings/utility/recording_writer.hpp index 7e6f4fc7..50a9db82 100644 --- a/src/libs/recordings/utility/recording_writer.hpp +++ b/src/libs/recordings/utility/recording_writer.hpp @@ -51,7 +51,7 @@ namespace recorder { const AdditionalInformation& information ); - template + template helper::expected write(Integral data) { const auto result = helper::writer::write_integral_to_file(m_output_file, data); if (not result.has_value()) { diff --git a/src/manager/event_dispatcher.hpp b/src/manager/event_dispatcher.hpp index a66dfed1..f6f4510a 100644 --- a/src/manager/event_dispatcher.hpp +++ b/src/manager/event_dispatcher.hpp @@ -85,7 +85,7 @@ struct EventDispatcher final { } if (rect.has_value()) { - SDL_Rect sdl_rect = rect.value().to_sdl_rect(); + const SDL_Rect sdl_rect = rect.value().to_sdl_rect(); SDL_SetTextInputRect(&sdl_rect); } diff --git a/src/manager/font.hpp b/src/manager/font.hpp index 855646e3..3390d62c 100644 --- a/src/manager/font.hpp +++ b/src/manager/font.hpp @@ -9,13 +9,13 @@ struct FontLoadingError final : public std::exception { private: - std::string message; + std::string m_message; public: - OOPETRIS_GRAPHICS_EXPORTED explicit FontLoadingError(std::string message) : message{ std::move(message) } { } + OOPETRIS_GRAPHICS_EXPORTED explicit FontLoadingError(std::string message) : m_message{ std::move(message) } { } [[nodiscard]] const char* what() const noexcept override { - return message.c_str(); + return m_message.c_str(); } }; diff --git a/src/manager/music_manager.cpp b/src/manager/music_manager.cpp index b7865bbb..0f86404c 100644 --- a/src/manager/music_manager.cpp +++ b/src/manager/music_manager.cpp @@ -20,10 +20,10 @@ MusicManager::MusicManager(ServiceProvider* service_provider, u8 channel_size) m_channel_size{ channel_size }, m_chunk_map{ std::unordered_map{} }, m_volume{ service_provider->command_line_arguments().silent ? std::nullopt : std::optional{ 1.0F } } { - if (s_instance != nullptr) { + if (m_s_instance != nullptr) { spdlog::error( "it's not allowed to create more than one MusicManager instance: {} != {}", - static_cast(s_instance), static_cast(this) + static_cast(m_s_instance), static_cast(this) ); return; } @@ -65,7 +65,7 @@ MusicManager::MusicManager(ServiceProvider* service_provider, u8 channel_size) throw helper::InitializationError{ fmt::format("Failed to open an audio device: {}", SDL_GetError()) }; } - s_instance = this; + m_s_instance = this; set_volume(m_volume, true); } @@ -97,7 +97,7 @@ MusicManager::~MusicManager() noexcept { Mix_CloseAudio(); Mix_Quit(); - s_instance = nullptr; + m_s_instance = nullptr; } std::optional MusicManager::load_and_play_music(const std::filesystem::path& location, const usize delay) { @@ -159,11 +159,11 @@ std::optional MusicManager::load_and_play_music(const std::filesyst m_delay = delay; Mix_HookMusicFinished([]() { // this can happen on e.g. android, where if we exit the application, we don't close the window, so its reused, but the music manager is destroyed, but the hook is called later xD - /* if (s_instance == nullptr) { + /* if (m_s_instance == nullptr) { return; } */ - s_instance->hook_music_finished(); + m_s_instance->hook_music_finished(); }); // this wasn't block, so we have to wait for the callback to be called @@ -252,10 +252,10 @@ void MusicManager::hook_music_finished() { } [[nodiscard]] bool MusicManager::validate_instance() { - if (s_instance != this) { + if (m_s_instance != this) { spdlog::error( "this MusicManager instance is not the instance that is used globally: {} != {}", - static_cast(s_instance), static_cast(this) + static_cast(m_s_instance), static_cast(this) ); return false; } @@ -340,7 +340,7 @@ std::optional MusicManager::change_volume(const std::int8_t steps) { return 1.0F; } - new_volume = current_volume.value() + MusicManager::step_width * static_cast(steps); + new_volume = current_volume.value() + (MusicManager::step_width * static_cast(steps)); } if (new_volume >= 1.0F) { diff --git a/src/manager/music_manager.hpp b/src/manager/music_manager.hpp index 7650f8e4..9020cab6 100644 --- a/src/manager/music_manager.hpp +++ b/src/manager/music_manager.hpp @@ -20,7 +20,7 @@ struct MusicManager final { private: - static inline MusicManager* s_instance{ nullptr }; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) + static inline MusicManager* m_s_instance{ nullptr }; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) static const constexpr double step_width = 0.05F; using VolumeChangeFunction = std::function volume)>; diff --git a/src/manager/settings.hpp b/src/manager/settings.hpp index 0a83415b..d77943bc 100644 --- a/src/manager/settings.hpp +++ b/src/manager/settings.hpp @@ -41,7 +41,7 @@ namespace nlohmann { static void to_json(json& obj, Controls controls) { // NOLINT(misc-no-recursion) std::visit( - helper::overloaded{ + helper::Overloaded{ [&](const input::KeyboardSettings& keyboard_settings) { // NOLINT(misc-no-recursion) nlohmann::adl_serializer::to_json(obj, keyboard_settings); obj["type"] = "keyboard"; diff --git a/src/scenes/about_page/about_page.cpp b/src/scenes/about_page/about_page.cpp index 8e47c0ee..39c5aefa 100644 --- a/src/scenes/about_page/about_page.cpp +++ b/src/scenes/about_page/about_page.cpp @@ -67,7 +67,7 @@ namespace scenes { const auto tile_layout_index = m_main_grid.add( - utils::size_t_identity<2>(), focus_helper.focus_id(), ui::Direction::Horizontal, + utils::SizeIdentity<2>(), focus_helper.focus_id(), ui::Direction::Horizontal, std::array{ 0.85 }, ui::AbsolutMargin{ 0 }, std::pair{ 0.05, 0.03 } ); diff --git a/src/scenes/loading_screen/loading_screen.cpp b/src/scenes/loading_screen/loading_screen.cpp index 5fe75625..4c16b646 100644 --- a/src/scenes/loading_screen/loading_screen.cpp +++ b/src/scenes/loading_screen/loading_screen.cpp @@ -84,7 +84,7 @@ void scenes::LoadingScreen::update() { const auto offset = std::numbers::pi_v * 2.0 * static_cast(length - i - 1) / length_d; - scale = std::min(amplitude * std::sin(time * speed + offset) + scale_offset, 1.0); + scale = std::min((amplitude * std::sin((time * speed) + offset)) + scale_offset, 1.0); } // } @@ -122,6 +122,6 @@ void scenes::LoadingScreen::render(const ServiceProvider& service_provider) cons [[nodiscard]] shapes::UPoint scenes::LoadingScreen::to_screen_coords(const Mino::GridPoint& point, u32 tile_size) const { const auto start_edge = m_start_offset + point.cast() * m_tile_size; - const auto inner_offset = m_tile_size - tile_size / 2; + const auto inner_offset = m_tile_size - (tile_size / 2); return start_edge + shapes::UPoint{ inner_offset, inner_offset }; } diff --git a/src/scenes/online_lobby/online_lobby.cpp b/src/scenes/online_lobby/online_lobby.cpp index abbc16d8..072f3340 100644 --- a/src/scenes/online_lobby/online_lobby.cpp +++ b/src/scenes/online_lobby/online_lobby.cpp @@ -19,7 +19,7 @@ namespace scenes { OnlineLobby::OnlineLobby(ServiceProvider* service_provider, const ui::Layout& layout) : Scene{ service_provider, layout }, m_main_layout{ - utils::size_t_identity<3>(), + utils::SizeIdentity<3>(), 0, ui::Direction::Vertical, { 0.1, 0.9 }, diff --git a/src/scenes/recording_selector/recording_chooser.cpp b/src/scenes/recording_selector/recording_chooser.cpp index 6541469a..4ea7d2b0 100644 --- a/src/scenes/recording_selector/recording_chooser.cpp +++ b/src/scenes/recording_selector/recording_chooser.cpp @@ -31,13 +31,13 @@ custom_ui::RecordingFileChooser::RecordingFileChooser( [service_provider, this](const ui::TextButton&) -> bool { this->prepare_dialog(service_provider); - const auto result = helper::openMultipleFilesDialog({ - { "OOPetris Recording", { constants::recording::extension } } + const auto result = helper::open_multiple_files_dialog({ + { .name = "OOPetris Recording", .extension_list = { constants::recording::extension } } }); if (result.has_value()) { for (const auto& path : result.value()) { - this->currently_chosen_files.push_back(path); + this->m_currently_chosen_files.push_back(path); } } else { spdlog::warn("error in dialog: {}", result.error()); @@ -58,7 +58,7 @@ custom_ui::RecordingFileChooser::RecordingFileChooser( [this, service_provider](const ui::TextButton&) -> bool { this->prepare_dialog(service_provider); - const auto result = helper::openFolderDialog(); + const auto result = helper::open_folder_dialog(); if (result.has_value()) { @@ -66,7 +66,7 @@ custom_ui::RecordingFileChooser::RecordingFileChooser( for (const auto& file : std::filesystem::recursive_directory_iterator(result.value())) { auto header_value = recorder::RecordingReader::is_header_valid(file.path()); if (header_value.has_value()) { - this->currently_chosen_files.push_back(file.path()); + this->m_currently_chosen_files.push_back(file.path()); } } } @@ -116,14 +116,14 @@ helper::BoolWrapper> custom_ui::Reco [[nodiscard]] const std::vector& custom_ui::RecordingFileChooser::get_currently_chosen_files( ) const { - return currently_chosen_files; + return m_currently_chosen_files; } //TODO(Totto): solve in another way, that is better void custom_ui::RecordingFileChooser::prepare_dialog(ServiceProvider* service_provider) { //TODO(Totto): show scene on top, that hints of the dialog - this->currently_chosen_files.clear(); + this->m_currently_chosen_files.clear(); service_provider->event_dispatcher().disable(); } diff --git a/src/scenes/recording_selector/recording_chooser.hpp b/src/scenes/recording_selector/recording_chooser.hpp index c15f682c..c8082764 100644 --- a/src/scenes/recording_selector/recording_chooser.hpp +++ b/src/scenes/recording_selector/recording_chooser.hpp @@ -16,7 +16,7 @@ namespace custom_ui { struct RecordingFileChooser final : public ui::Widget, public ui::Focusable, public ui::Hoverable { private: ui::GridLayout m_main_grid; - std::vector currently_chosen_files{}; + std::vector m_currently_chosen_files; public: OOPETRIS_GRAPHICS_EXPORTED explicit RecordingFileChooser( diff --git a/src/scenes/recording_selector/recording_component.cpp b/src/scenes/recording_selector/recording_component.cpp index 17fc7421..ba8c87a3 100644 --- a/src/scenes/recording_selector/recording_component.cpp +++ b/src/scenes/recording_selector/recording_component.cpp @@ -19,7 +19,7 @@ custom_ui::RecordingComponent::RecordingComponent( ):ui::Widget{layout, ui::WidgetType::Component, is_top_level}, ui::Focusable{focus_helper.focus_id()}, ui::Hoverable{layout.get_rect()}, - m_main_layout{ utils::size_t_identity<2>(), focus_helper.focus_id(), + m_main_layout{ utils::SizeIdentity<2>(), focus_helper.focus_id(), ui::Direction::Vertical, std::array{ 0.6 }, ui::RelativeMargin{layout.get_rect(), ui::Direction::Vertical,0.05}, std::pair{ 0.05, 0.03 }, layout,false @@ -32,7 +32,7 @@ custom_ui::RecordingComponent::RecordingComponent( ); const auto information_layout_index = m_main_layout.add( - utils::size_t_identity<3>(), focus_helper.focus_id(), ui::Direction::Horizontal, + utils::SizeIdentity<3>(), focus_helper.focus_id(), ui::Direction::Horizontal, std::array{ 0.33, 0.66 }, ui::AbsolutMargin{ 10 }, std::pair{ 0.05, 0.03 } ); diff --git a/src/scenes/recording_selector/recording_selector.cpp b/src/scenes/recording_selector/recording_selector.cpp index 373e504c..9f82116b 100644 --- a/src/scenes/recording_selector/recording_selector.cpp +++ b/src/scenes/recording_selector/recording_selector.cpp @@ -25,12 +25,12 @@ namespace scenes { - using namespace details::recording::selector; + using namespace details::recording::selector; //NOLINT(google-build-using-namespace) RecordingSelector::RecordingSelector(ServiceProvider* service_provider, const ui::Layout& layout) : Scene{ service_provider, layout }, m_main_layout{ - utils::size_t_identity<3>(), + utils::SizeIdentity<3>(), 0, ui::Direction::Vertical, { 0.1, 0.9 }, @@ -79,7 +79,7 @@ namespace scenes { if (m_next_command.has_value()) { return std::visit( - helper::overloaded{ + helper::Overloaded{ [](const Return&) { return UpdateResult{ SceneUpdate::StopUpdating, Scene::Pop{} }; }, [this](const Action& action) { if (auto recording_component = diff --git a/src/scenes/scene.hpp b/src/scenes/scene.hpp index 16ef8d15..d9fad46d 100644 --- a/src/scenes/scene.hpp +++ b/src/scenes/scene.hpp @@ -19,12 +19,12 @@ namespace scenes { struct Scene { public: struct Switch { - SceneId target_scene; - ui::Layout layout; + SceneId m_target_scene; + ui::Layout m_layout; Switch(const SceneId target_scene, const ui::Layout& layout) - : target_scene{ target_scene }, - layout{ layout } { } + : m_target_scene{ target_scene }, + m_layout{ layout } { } }; struct RawSwitch { @@ -62,7 +62,8 @@ namespace scenes { using UpdateResult = std::pair>; protected: - ServiceProvider* m_service_provider; + ServiceProvider* + m_service_provider; //NOLINT(misc-non-private-member-variables-in-classes,cppcoreguidelines-non-private-member-variables-in-classes) private: ui::Layout m_layout; diff --git a/src/scenes/settings_menu/color_setting_row.cpp b/src/scenes/settings_menu/color_setting_row.cpp index e0f42c5f..cfe8d981 100644 --- a/src/scenes/settings_menu/color_setting_row.cpp +++ b/src/scenes/settings_menu/color_setting_row.cpp @@ -146,7 +146,7 @@ custom_ui::ColorSettingRow::ColorSettingRow( ui::Focusable{ focus_id }, ui::Hoverable{ layout.get_rect() }, m_service_provider{ service_provider }, - m_main_layout{ utils::size_t_identity<2>(), + m_main_layout{ utils::SizeIdentity<2>(), ui::FocusHelper::focus_id_unused(), ui::Direction::Horizontal, std::array{ 0.7 }, diff --git a/src/scenes/settings_menu/settings_details.hpp b/src/scenes/settings_menu/settings_details.hpp index 04f8bb0a..db7572eb 100644 --- a/src/scenes/settings_menu/settings_details.hpp +++ b/src/scenes/settings_menu/settings_details.hpp @@ -8,7 +8,7 @@ namespace settings { struct SettingsDetails { [[nodiscard]] virtual scenes::Scene::Change get_details_scene() = 0; - virtual inline ~SettingsDetails() = default; + virtual ~SettingsDetails() = default; }; diff --git a/src/scenes/settings_menu/settings_menu.cpp b/src/scenes/settings_menu/settings_menu.cpp index 8be0bf90..85796462 100644 --- a/src/scenes/settings_menu/settings_menu.cpp +++ b/src/scenes/settings_menu/settings_menu.cpp @@ -17,7 +17,7 @@ namespace scenes { - using namespace details::settings::menu; + using namespace details::settings::menu; // NOLINT(google-build-using-namespace) SettingsMenu::SettingsMenu(ServiceProvider* service_provider, const ui::Layout& layout) : SettingsMenu{ service_provider, layout, std::nullopt } { } @@ -30,7 +30,7 @@ namespace scenes { : SettingsMenu{ service_provider, layout, std::optional>{ game_input } } { } SettingsMenu::SettingsMenu(ServiceProvider* service_provider, const ui::Layout& layout, const std::optional>& game_input) : Scene{service_provider, layout} - , m_main_layout{ utils::size_t_identity<3>(), + , m_main_layout{ utils::SizeIdentity<3>(), 0, ui::Direction::Vertical, { 0.1, 0.9 }, @@ -133,7 +133,7 @@ namespace scenes { scroll_layout->add( ui::RelativeItemSize{ scroll_layout->layout(), 0.2 }, service_provider, - //TODO use real settings name + //TODO(Totto): use real settings name fmt::format("Color {}", color_index), color, [this, color_index](const Color& updated_color) { this->m_colors.at(color_index) = updated_color; }, focus_helper.focus_id() @@ -180,7 +180,7 @@ namespace scenes { if (m_next_command.has_value()) { return std::visit( - helper::overloaded{ + helper::Overloaded{ [this](const Return& ret) { const auto return_type = ret.type; diff --git a/src/ui/components/color_picker.cpp b/src/ui/components/color_picker.cpp index d7bca826..7d52d150 100644 --- a/src/ui/components/color_picker.cpp +++ b/src/ui/components/color_picker.cpp @@ -39,15 +39,15 @@ detail::ColorSlider::ColorSlider( service_provider->renderer().set_render_target(*m_texture); - const auto w = bar_rect().width(); - const auto h = bar_rect().height(); + const auto width = bar_rect().width(); + const auto height = bar_rect().height(); - for (u32 x = 0; x < w; x++) { + for (u32 x = 0; x < width; x++) { const Color color = - HSVColor((static_cast(x) / static_cast(w)) * 360.0, 1.0, 1.0).to_rgb_color(); + HSVColor((static_cast(x) / static_cast(width)) * 360.0, 1.0, 1.0).to_rgb_color(); service_provider->renderer().draw_line( - shapes::UPoint{ x, 0 }, shapes::UPoint{ x, static_cast(h - 1) }, color + shapes::UPoint{ x, 0 }, shapes::UPoint{ x, static_cast(height - 1) }, color ); } @@ -204,7 +204,7 @@ detail::ColorCanvas::handle_event(const std::shared_ptr& in m_current_color.v = 0.0; } else { const double percentage = - 1.0 - static_cast(y - fill_rect.top_left.y) / static_cast(fill_rect.height()); + 1.0 - (static_cast(y - fill_rect.top_left.y) / static_cast(fill_rect.height())); m_current_color.v = percentage; } diff --git a/src/ui/components/color_picker.hpp b/src/ui/components/color_picker.hpp index 8825683c..da72564d 100644 --- a/src/ui/components/color_picker.hpp +++ b/src/ui/components/color_picker.hpp @@ -45,7 +45,7 @@ namespace detail { private: ServiceProvider* m_service_provider; - std::unique_ptr m_texture{}; + std::unique_ptr m_texture; HSVColor m_current_color; Callback m_callback; bool m_is_dragging{ false }; diff --git a/src/ui/components/textinput.hpp b/src/ui/components/textinput.hpp index f494e9fa..0354c384 100644 --- a/src/ui/components/textinput.hpp +++ b/src/ui/components/textinput.hpp @@ -17,7 +17,7 @@ namespace ui { struct TextInput final : public Widget, public Focusable, public Hoverable { private: - std::string m_text{}; + std::string m_text; u32 m_cursor_position{ 0 }; ServiceProvider* m_service_provider; Font m_font; diff --git a/src/ui/layouts/focus_layout.cpp b/src/ui/layouts/focus_layout.cpp index 55db9e98..aa87dd5e 100644 --- a/src/ui/layouts/focus_layout.cpp +++ b/src/ui/layouts/focus_layout.cpp @@ -212,10 +212,10 @@ ui::FocusLayout::handle_event_result(const std::optional } } -[[nodiscard]] u32 ui::FocusLayout::focusable_index_by_id(const u32 id) const { - const auto find_iterator = std::ranges::find_if(m_widgets, [id](const std::unique_ptr& widget) { +[[nodiscard]] u32 ui::FocusLayout::focusable_index_by_id(const u32 focus_id) const { + const auto find_iterator = std::ranges::find_if(m_widgets, [focus_id](const std::unique_ptr& widget) { const auto focusable = as_focusable(widget.get()); - return focusable.has_value() and focusable.value()->focus_id() == id; + return focusable.has_value() and focusable.value()->focus_id() == focus_id; }); assert(find_iterator != m_widgets.end()); const auto index = static_cast(std::distance(m_widgets.begin(), find_iterator)); diff --git a/src/ui/layouts/focus_layout.hpp b/src/ui/layouts/focus_layout.hpp index e810091a..a437363e 100644 --- a/src/ui/layouts/focus_layout.hpp +++ b/src/ui/layouts/focus_layout.hpp @@ -125,7 +125,7 @@ namespace ui { [[nodiscard]] std::optional handle_event_result(const std::optional& result, Widget* widget); - [[nodiscard]] u32 focusable_index_by_id(u32 id) const; + [[nodiscard]] u32 focusable_index_by_id(u32 focus_id) const; [[nodiscard]] std::vector focusable_ids_sorted() const; diff --git a/src/ui/layouts/grid_layout.cpp b/src/ui/layouts/grid_layout.cpp index f351e4b0..f2d21ea0 100644 --- a/src/ui/layouts/grid_layout.cpp +++ b/src/ui/layouts/grid_layout.cpp @@ -11,16 +11,16 @@ ui::GridLayout::GridLayout( const Layout& layout, bool is_top_level ) - : FocusLayout{ layout, focus_id, FocusOptions{ is_top_level, is_top_level }, is_top_level }, - size{ size }, - direction{ direction }, - gap{ gap }, - margin{ static_cast(margin.first * layout.get_rect().width()), + : FocusLayout{ layout, focus_id, FocusOptions{ .wrap_around=is_top_level, .allow_tab=is_top_level }, is_top_level }, + m_size{ size }, + m_direction{ direction }, + m_gap{ gap }, + m_margin{ static_cast(margin.first * layout.get_rect().width()), static_cast(margin.second * layout.get_rect().height()) } { } [[nodiscard]] u32 ui::GridLayout::total_size() const { - return size; + return m_size; } void ui::GridLayout::render(const ServiceProvider& service_provider) const { @@ -31,33 +31,33 @@ void ui::GridLayout::render(const ServiceProvider& service_provider) const { [[nodiscard]] ui::Layout ui::GridLayout::get_layout_for_index(u32 index) { - if (index >= this->size) { + if (index >= this->m_size) { throw std::runtime_error("GridLayout is already full"); } const auto start_point = layout().get_rect().top_left; - u32 x_pos = start_point.x + margin.first; - u32 y_pos = start_point.y + margin.second; - u32 width = layout().get_rect().width() - (margin.first * 2); - u32 height = layout().get_rect().height() - (margin.second * 2); + u32 x_pos = start_point.x + m_margin.first; + u32 y_pos = start_point.y + m_margin.second; + u32 width = layout().get_rect().width() - (m_margin.first * 2); + u32 height = layout().get_rect().height() - (m_margin.second * 2); - if (direction == Direction::Horizontal) { - const u32 total_margin = this->size <= 1 ? 0 : (this->size - 1) * gap.get_margin(); - assert(layout().get_rect().width() > (total_margin + (margin.first * 2)) + if (m_direction == Direction::Horizontal) { + const u32 total_margin = this->m_size <= 1 ? 0 : (this->m_size - 1) * m_gap.get_margin(); + assert(layout().get_rect().width() > (total_margin + (m_margin.first * 2)) && "width has to be greater than the margins"); - width = (layout().get_rect().width() - total_margin - (margin.first * 2)) / this->size; + width = (layout().get_rect().width() - total_margin - (m_margin.first * 2)) / this->m_size; - const u32 margin_x = index * gap.get_margin(); + const u32 margin_x = index * m_gap.get_margin(); const u32 total_width = width * index; x_pos += margin_x + total_width; } else { - const u32 total_margin = this->size <= 1 ? 0 : (this->size - 1) * gap.get_margin(); - assert(layout().get_rect().height() > (total_margin - (margin.second * 2)) + const u32 total_margin = this->m_size <= 1 ? 0 : (this->m_size - 1) * m_gap.get_margin(); + assert(layout().get_rect().height() > (total_margin - (m_margin.second * 2)) && "height has to be greater than the margins"); - height = (layout().get_rect().height() - total_margin - (margin.second * 2)) / this->size; + height = (layout().get_rect().height() - total_margin - (m_margin.second * 2)) / this->m_size; - const u32 margin_y = index * gap.get_margin(); + const u32 margin_y = index * m_gap.get_margin(); const u32 total_height = height * index; y_pos += margin_y + total_height; } diff --git a/src/ui/layouts/grid_layout.hpp b/src/ui/layouts/grid_layout.hpp index 7c15b95c..14029214 100644 --- a/src/ui/layouts/grid_layout.hpp +++ b/src/ui/layouts/grid_layout.hpp @@ -7,10 +7,10 @@ namespace ui { struct GridLayout : public FocusLayout { private: - u32 size; - Direction direction; - Margin gap; - std::pair margin; + u32 m_size; + Direction m_direction; + Margin m_gap; + std::pair m_margin; public: OOPETRIS_GRAPHICS_EXPORTED explicit GridLayout( diff --git a/src/ui/layouts/scroll_layout.cpp b/src/ui/layouts/scroll_layout.cpp index 6dd029be..8e46ce69 100644 --- a/src/ui/layouts/scroll_layout.cpp +++ b/src/ui/layouts/scroll_layout.cpp @@ -37,8 +37,8 @@ ui::ScrollLayout::ScrollLayout( bool is_top_level ) : FocusLayout{ - layout, focus_id, FocusOptions{ is_top_level, is_top_level }, is_top_level}, // if on top, we support tab and wrap around, otherwise not - gap{ gap }, + layout, focus_id, FocusOptions{ .wrap_around=is_top_level, .allow_tab=is_top_level }, is_top_level}, // if on top, we support tab and wrap around, otherwise not + m_gap{ gap }, m_texture{ std::nullopt }, m_service_provider{ service_provider }, m_step_size{ static_cast(layout.get_rect().height() * 0.05) } { @@ -54,13 +54,13 @@ ui::ScrollLayout::ScrollLayout( const u32 start_x = layout_rect.top_left.x + absolut_margin.first; const u32 start_y = layout_rect.top_left.y + absolut_margin.second; - const u32 new_width = layout_rect.width() - absolut_margin.first * 2; - const u32 new_height = layout_rect.height() - absolut_margin.second * 2; + const u32 new_width = layout_rect.width() - (absolut_margin.first * 2); + const u32 new_height = layout_rect.height() - (absolut_margin.second * 2); - main_rect = shapes::URect{ start_x, start_y, new_width - scroll_bar_width - absolut_gap, new_height }; - scrollbar_rect = shapes::URect{ start_x + new_width - scroll_bar_width, start_y, scroll_bar_width, new_height }; - scrollbar_mover_rect = scrollbar_rect; // NOLINT(cppcoreguidelines-prefer-member-initializer) + m_main_rect = shapes::URect{ start_x, start_y, new_width - scroll_bar_width - absolut_gap, new_height }; + m_scrollbar_rect = shapes::URect{ start_x + new_width - scroll_bar_width, start_y, scroll_bar_width, new_height }; + m_scrollbar_mover_rect = m_scrollbar_rect; // NOLINT(cppcoreguidelines-prefer-member-initializer) m_viewport = shapes::URect{ 0, 0, 0, 0 }; } @@ -90,10 +90,10 @@ void ui::ScrollLayout::render(const ServiceProvider& service_provider) const { renderer.reset_render_target(); - auto to_rect = main_rect; + auto to_rect = m_main_rect; // if we don't need to fill-up the whole main_rect, we need a special to_rect - if (total_widgets_height < scrollbar_rect.height()) { - to_rect = shapes::URect{ main_rect.top_left.x, main_rect.top_left.y, main_rect.width(), + if (total_widgets_height < m_scrollbar_rect.height()) { + to_rect = shapes::URect{ m_main_rect.top_left.x, m_main_rect.top_left.y, m_main_rect.width(), total_widgets_height }; } @@ -101,9 +101,9 @@ void ui::ScrollLayout::render(const ServiceProvider& service_provider) const { } // render the scrollbar when it makes sense - if (total_widgets_height > scrollbar_rect.height()) { - renderer.draw_rect_filled(scrollbar_rect, "#A19797"_c); - renderer.draw_rect_filled(scrollbar_mover_rect, is_dragging ? "#666161"_c : "#524F4F"_c); + if (total_widgets_height > m_scrollbar_rect.height()) { + renderer.draw_rect_filled(m_scrollbar_rect, "#A19797"_c); + renderer.draw_rect_filled(m_scrollbar_mover_rect, m_is_dragging ? "#666161"_c : "#524F4F"_c); } } @@ -127,20 +127,21 @@ ui::ScrollLayout::handle_event(const std::shared_ptr& input auto desired_scroll_height = 0; - if (y <= static_cast(scrollbar_rect.top_left.y)) { + if (y <= static_cast(m_scrollbar_rect.top_left.y)) { desired_scroll_height = 0; - } else if (y >= static_cast(scrollbar_rect.bottom_right.y)) { + } else if (y >= static_cast(m_scrollbar_rect.bottom_right.y)) { // this is to high, but recalculate_sizes reset it to the highest possible value! desired_scroll_height = static_cast(total_widgets_height); } else { - const double percentage = - static_cast(y - scrollbar_rect.top_left.y) / static_cast(scrollbar_rect.height()); + const double percentage = static_cast(y - m_scrollbar_rect.top_left.y) + / static_cast(m_scrollbar_rect.height()); // we want the final point to be in the middle, but desired_scroll_height expects the top position. - desired_scroll_height = - static_cast(static_cast(percentage * total_widgets_height) - scrollbar_rect.height() / 2); - is_dragging = true; + desired_scroll_height = static_cast( + static_cast(percentage * total_widgets_height) - (m_scrollbar_rect.height() / 2) + ); + m_is_dragging = true; } @@ -151,22 +152,22 @@ ui::ScrollLayout::handle_event(const std::shared_ptr& input if (pointer_event == input::PointerEvent::PointerDown) { // note: this behaviour is intentional, namely, clicking into the scroll slider doesn't move it, it just "grabs" it for dragging - if (pointer_event->is_in(scrollbar_mover_rect)) { - is_dragging = true; + if (pointer_event->is_in(m_scrollbar_mover_rect)) { + m_is_dragging = true; handled = true; - } else if (pointer_event->is_in(scrollbar_rect)) { + } else if (pointer_event->is_in(m_scrollbar_rect)) { change_value_on_scroll(pointer_event.value()); handled = true; } } else if (pointer_event == input::PointerEvent::PointerUp) { - is_dragging = false; + m_is_dragging = false; handled = true; } else if (pointer_event == input::PointerEvent::Motion) { - if (is_dragging) { + if (m_is_dragging) { change_value_on_scroll(pointer_event.value()); handled = true; @@ -202,12 +203,12 @@ ui::ScrollLayout::handle_event(const std::shared_ptr& input if (pointer_event.has_value()) { - const auto offset_distance = main_rect.top_left.cast() - m_viewport.top_left.cast(); + const auto offset_distance = m_main_rect.top_left.cast() - m_viewport.top_left.cast(); for (auto& widget : m_widgets) { const auto& layout_rect = widget->layout().get_rect(); const auto& offset_rect = (layout_rect.cast()) >> offset_distance; - if (not handled and pointer_event->is_in(main_rect) and pointer_event->is_in(offset_rect)) { + if (not handled and pointer_event->is_in(m_main_rect) and pointer_event->is_in(offset_rect)) { const auto offset_event = input_manager->offset_pointer_event(event, -offset_distance); if (const auto event_result = widget->handle_event(input_manager, offset_event); event_result) { handled = { true, handle_event_result(event_result.get_additional(), widget.get()) }; @@ -260,7 +261,7 @@ ui::Widget::EventHandleResult ui::ScrollLayout::handle_focus_change_events( if (const auto pointer_event = input_manager->get_pointer_event(event); pointer_event.has_value()) { - const auto offset_distance = main_rect.top_left.cast() - m_viewport.top_left.cast(); + const auto offset_distance = m_main_rect.top_left.cast() - m_viewport.top_left.cast(); new_event = input_manager->offset_pointer_event(event, -offset_distance); } @@ -289,7 +290,7 @@ void ui::ScrollLayout::clear_widgets() { recalculate_sizes(0); } -[[nodiscard]] ui::Layout ui::ScrollLayout::get_layout_for_index(u32) { +[[nodiscard]] ui::Layout ui::ScrollLayout::get_layout_for_index(u32 /*index*/) { // see TODO comment over handle_event in header file throw std::runtime_error("NOT SUPPORTED"); } @@ -302,9 +303,9 @@ void ui::ScrollLayout::clear_widgets() { start_point_y += static_cast(widget_rect.height()); } - start_point_y += gap.get_margin() * static_cast(m_widgets.size()); + start_point_y += m_gap.get_margin() * static_cast(m_widgets.size()); - const auto width = static_cast(main_rect.width()); + const auto width = static_cast(m_main_rect.width()); const auto height = size.get_height(); return AbsolutLayout{ @@ -324,7 +325,7 @@ void ui::ScrollLayout::auto_move_after_focus_change() { const auto total_widgets_height = m_widgets.empty() ? 0 : m_widgets.back()->layout().get_rect().bottom_right.y; // if we don't need to fill-up the whole main_rect, we need a special viewport, but top position is always 0 - if (total_widgets_height < scrollbar_rect.height()) { + if (total_widgets_height < m_scrollbar_rect.height()) { recalculate_sizes(0); return; } @@ -357,34 +358,35 @@ void ui::ScrollLayout::recalculate_sizes(i32 desired_scroll_height) { const auto total_widgets_height = m_widgets.empty() ? 0 : m_widgets.back()->layout().get_rect().bottom_right.y; // if we don't need to fill-up the whole main_rect, we need a special viewport - if (total_widgets_height < scrollbar_rect.height()) { - m_viewport = shapes::URect{ 0, 0, main_rect.width(), total_widgets_height }; + if (total_widgets_height < m_scrollbar_rect.height()) { + m_viewport = shapes::URect{ 0, 0, m_main_rect.width(), total_widgets_height }; } else { // check if desired_scroll_height is valid: auto scroll_height = desired_scroll_height; if (desired_scroll_height < 0) { scroll_height = 0; - } else if (desired_scroll_height + main_rect.height() > total_widgets_height) { - scroll_height = static_cast(total_widgets_height - main_rect.height()); + } else if (desired_scroll_height + m_main_rect.height() > total_widgets_height) { + scroll_height = static_cast(total_widgets_height - m_main_rect.height()); } - m_viewport = shapes::URect{ 0, static_cast(scroll_height), main_rect.width(), main_rect.height() }; + m_viewport = shapes::URect{ 0, static_cast(scroll_height), m_main_rect.width(), m_main_rect.height() }; } // recalculate scrollbar mover rect const auto current_start_height = static_cast( - scrollbar_rect.height() + m_scrollbar_rect.height() * (static_cast(m_viewport.top_left.y) / static_cast(total_widgets_height)) ); const auto current_end_height = static_cast( - scrollbar_rect.height() - * (static_cast(m_viewport.top_left.y + scrollbar_rect.height()) + m_scrollbar_rect.height() + * (static_cast(m_viewport.top_left.y + m_scrollbar_rect.height()) / static_cast(total_widgets_height)) ); - scrollbar_mover_rect = shapes::URect{ scrollbar_rect.top_left.x, scrollbar_rect.top_left.y + current_start_height, - scrollbar_rect.width(), current_end_height - current_start_height }; + m_scrollbar_mover_rect = + shapes::URect{ m_scrollbar_rect.top_left.x, m_scrollbar_rect.top_left.y + current_start_height, + m_scrollbar_rect.width(), current_end_height - current_start_height }; } diff --git a/src/ui/layouts/scroll_layout.hpp b/src/ui/layouts/scroll_layout.hpp index 39125824..ce6b6efd 100644 --- a/src/ui/layouts/scroll_layout.hpp +++ b/src/ui/layouts/scroll_layout.hpp @@ -43,14 +43,14 @@ namespace ui { struct ScrollLayout : public FocusLayout { private: - Margin gap; + Margin m_gap; std::optional m_texture; ServiceProvider* m_service_provider; - shapes::URect main_rect; - shapes::URect scrollbar_rect; - shapes::URect scrollbar_mover_rect; + shapes::URect m_main_rect; + shapes::URect m_scrollbar_rect; + shapes::URect m_scrollbar_mover_rect; shapes::URect m_viewport; - bool is_dragging{ false }; + bool m_is_dragging{ false }; u32 m_step_size; public: @@ -100,7 +100,7 @@ namespace ui { private: - [[nodiscard]] Layout get_layout_for_index(u32) override; + [[nodiscard]] Layout get_layout_for_index(u32 index) override; [[nodiscard]] Layout get_layout_for_new(ItemSize size); diff --git a/src/ui/layouts/tile_layout.cpp b/src/ui/layouts/tile_layout.cpp index 9b59f2b7..2a4baaa5 100644 --- a/src/ui/layouts/tile_layout.cpp +++ b/src/ui/layouts/tile_layout.cpp @@ -10,38 +10,38 @@ void ui::TileLayout::render(const ServiceProvider& service_provider) const { [[nodiscard]] ui::Layout ui::TileLayout::get_layout_for_index(u32 index) { - if (index >= this->size) { + if (index >= this->m_size) { throw std::runtime_error("TileLayout is already full"); } const auto start_point = layout().get_rect().top_left; - u32 x_pos = start_point.x + margin.first; - u32 y_pos = start_point.y + margin.second; - u32 width = layout().get_rect().width() - (margin.first * 2); - u32 height = layout().get_rect().height() - (margin.second * 2); + u32 x_pos = start_point.x + m_margin.first; + u32 y_pos = start_point.y + m_margin.second; + u32 width = layout().get_rect().width() - (m_margin.first * 2); + u32 height = layout().get_rect().height() - (m_margin.second * 2); - if (direction == Direction::Horizontal) { + if (m_direction == Direction::Horizontal) { const auto previous_start = - index == 0 ? 0 : static_cast(width * steps.at(index - 1)) + gap.get_margin() / 2; + index == 0 ? 0 : static_cast(width * m_steps.at(index - 1)) + (m_gap.get_margin() / 2); - const auto current_end = - index == this->size - 1 - ? width - : (steps.size() <= index ? width - : static_cast(width * steps.at(index)) - gap.get_margin() / 2); + const auto current_end = index == this->m_size - 1 + ? width + : (m_steps.size() <= index ? width + : static_cast(width * m_steps.at(index)) + - (m_gap.get_margin() / 2)); width = current_end - previous_start; x_pos += previous_start; } else { const auto previous_start = - index == 0 ? 0 : static_cast(height * steps.at(index - 1)) + gap.get_margin() / 2; + index == 0 ? 0 : static_cast(height * m_steps.at(index - 1)) + (m_gap.get_margin() / 2); - const auto current_end = - index == this->size - 1 - ? height - : (steps.size() <= index ? height - : static_cast(height * steps.at(index)) - gap.get_margin() / 2); + const auto current_end = index == this->m_size - 1 + ? height + : (m_steps.size() <= index ? height + : static_cast(height * m_steps.at(index)) + - (m_gap.get_margin() / 2)); height = current_end - previous_start; y_pos += previous_start; diff --git a/src/ui/layouts/tile_layout.hpp b/src/ui/layouts/tile_layout.hpp index fb7ce61b..98c8876a 100644 --- a/src/ui/layouts/tile_layout.hpp +++ b/src/ui/layouts/tile_layout.hpp @@ -19,17 +19,17 @@ namespace ui { struct TileLayout : public FocusLayout { private: - u32 size; - Direction direction; - std::vector steps; - Margin gap; - std::pair margin; + u32 m_size; + Direction m_direction; + std::vector m_steps; + Margin m_gap; + std::pair m_margin; public: - // see here, why utils::size_t_identity is needed: https://stackoverflow.com/questions/2786946/c-invoke-explicit-template-constructor + // see here, why utils::SizeIdentity is needed: https://stackoverflow.com/questions/2786946/c-invoke-explicit-template-constructor template explicit TileLayout( - utils::size_t_identity, + utils::SizeIdentity /*unused*/, u32 focus_id, Direction direction, std::array steps, @@ -38,12 +38,12 @@ namespace ui { const Layout& layout, bool is_top_level = true ) - : FocusLayout{ layout, focus_id,FocusOptions{ is_top_level, is_top_level }, is_top_level }, - size{ S }, - direction{ direction }, - steps{ steps.cbegin(), steps.cend() }, - gap{ gap }, - margin{ static_cast(margin.first * layout.get_rect().width()), + : FocusLayout{ layout, focus_id,FocusOptions{ .wrap_around=is_top_level, .allow_tab=is_top_level }, is_top_level }, + m_size{ S }, + m_direction{ direction }, + m_steps{ steps.cbegin(), steps.cend() }, + m_gap{ gap }, + m_margin{ static_cast(margin.first * layout.get_rect().width()), static_cast(margin.second * layout.get_rect().height()) } { static_assert(S != 0 and "TileLayout has to hold at least one child"); } diff --git a/tests/core/color.cpp b/tests/core/color.cpp index 38442a7f..ae4b42a1 100644 --- a/tests/core/color.cpp +++ b/tests/core/color.cpp @@ -26,24 +26,27 @@ namespace { } // namespace + // helper thought just for the tests -[[nodiscard]] constexpr bool operator==(const HSVColor& value1, const HSVColor& value2) { +[[nodiscard]] constexpr bool +operator==(const HSVColor& value1, const HSVColor& value2) { //NOLINT(misc-use-internal-linkage) return value1.to_rgb_color() == value2.to_rgb_color(); } // make colors printable -void PrintTo(const Color& color, std::ostream* os) { +void PrintTo(const Color& color, std::ostream* os) { //NOLINT(misc-use-internal-linkage) *os << color.to_string(); } -void PrintTo(const HSVColor& color, std::ostream* os) { +void PrintTo(const HSVColor& color, std::ostream* os) { //NOLINT(misc-use-internal-linkage) *os << color.to_string(); } + namespace color { - void PrintTo(const SerializeMode& value, std::ostream* os) { + void PrintTo(const SerializeMode& value, std::ostream* os) { //NOLINT(misc-use-internal-linkage) *os << magic_enum::enum_name(value); } diff --git a/tests/graphics/sdl_key.cpp b/tests/graphics/sdl_key.cpp index 45229c81..26c610ba 100644 --- a/tests/graphics/sdl_key.cpp +++ b/tests/graphics/sdl_key.cpp @@ -13,12 +13,12 @@ namespace sdl { // make keys printable - void PrintTo(const Key& key, std::ostream* os) { + void PrintTo(const Key& key, std::ostream* os) { //NOLINT(misc-use-internal-linkage) *os << key.to_string(); } - std::ostream& operator<<(std::ostream& os, const Key& value) { + std::ostream& operator<<(std::ostream& os, const Key& value) { //NOLINT(misc-use-internal-linkage) os << value.to_string(); return os; }