diff options
author | Spartan322 <Megacake1234@gmail.com> | 2024-05-04 16:22:06 +0200 |
---|---|---|
committer | Spartan322 <Megacake1234@gmail.com> | 2024-05-04 16:22:06 +0200 |
commit | 812d82dee030299b33181c102f906d58781d4fe0 (patch) | |
tree | c9891fc675ed60f2390b5a25f3acaea21143f15f /extension | |
parent | 2fc3f945f22966d209986ab38575aa26e2e6c1fd (diff) |
Update to Godot 4.2.2 Stable Release
Fix UITools.cpp float conversion warning
Add `OpenVic::Utilities::to_real_t(std::floating_point)`
Add _real user defined literal for real_t
Diffstat (limited to 'extension')
-rw-r--r-- | extension/src/openvic-extension/utility/UITools.cpp | 21 | ||||
-rw-r--r-- | extension/src/openvic-extension/utility/Utilities.hpp | 12 |
2 files changed, 25 insertions, 8 deletions
diff --git a/extension/src/openvic-extension/utility/UITools.cpp b/extension/src/openvic-extension/utility/UITools.cpp index 510c6da..6a9384b 100644 --- a/extension/src/openvic-extension/utility/UITools.cpp +++ b/extension/src/openvic-extension/utility/UITools.cpp @@ -128,6 +128,8 @@ static bool add_theme_stylebox(Control* control, StringName const& theme_name, R }; static bool generate_icon(generate_gui_args_t&& args) { + using namespace OpenVic::Utilities::literals; + GUI::Icon const& icon = static_cast<GUI::Icon const&>(args.element); const String icon_name = std_view_to_godot_string(icon.get_name()); @@ -274,7 +276,7 @@ static bool generate_icon(generate_gui_args_t&& args) { godot_texture_rect->set_texture(texture); // TODO - work out why this is needed Vector2 pos = godot_texture_rect->get_position(); - pos.x -= texture->get_width() / 2.0f; + pos.x -= texture->get_width() / 2.0_real; godot_texture_rect->set_position(pos); } else { UtilityFunctions::push_error("Failed to make GFXPieChartTexture for GUI icon ", icon_name); @@ -291,11 +293,11 @@ static bool generate_icon(generate_gui_args_t&& args) { } if (args.result != nullptr) { - const float rotation = icon.get_rotation(); - if (rotation != 0.0f) { + const real_t rotation = icon.get_rotation(); + if (rotation != 0.0_real) { args.result->set_position( args.result->get_position() - args.result->get_custom_minimum_size().height * Vector2 { - sin(rotation), cos(rotation) - 1.0f + Math::sin(rotation), Math::cos(rotation) - 1.0_real } ); args.result->set_rotation(-rotation); @@ -441,6 +443,8 @@ static bool generate_checkbox(generate_gui_args_t&& args) { } static bool generate_text(generate_gui_args_t&& args) { + using namespace OpenVic::Utilities::literals; + GUI::Text const& text = static_cast<GUI::Text const&>(args.element); const String text_name = std_view_to_godot_string(text.get_name()); @@ -451,7 +455,7 @@ static bool generate_text(generate_gui_args_t&& args) { godot_label->set_text(std_view_to_godot_string(text.get_text())); - static const Vector2 default_padding { 1.0f, 0.0f }; + static const Vector2 default_padding { 1.0_real, 0.0_real }; const Vector2 border_size = Utilities::to_godot_fvec2(text.get_border_size()) + default_padding; const Vector2 max_size = Utilities::to_godot_fvec2(text.get_max_size()); godot_label->set_position(godot_label->get_position() + border_size); @@ -553,7 +557,8 @@ static bool generate_placeholder(generate_gui_args_t&& args, Color colour) { } static bool generate_texteditbox(generate_gui_args_t&& args) { - return generate_placeholder<GUI::TextEditBox>(std::move(args), { 0.0f, 1.0f, 0.0f, 0.3f }); + using namespace OpenVic::Utilities::literals; + return generate_placeholder<GUI::TextEditBox>(std::move(args), { 0.0_real, 1.0_real, 0.0_real, 0.3_real }); } static bool generate_scrollbar(generate_gui_args_t&& args) { @@ -578,6 +583,8 @@ static bool generate_scrollbar(generate_gui_args_t&& args) { static bool generate_element(GUI::Element const* element, String const& name, AssetManager& asset_manager, Control*& result); static bool generate_window(generate_gui_args_t&& args) { + using namespace OpenVic::Utilities::literals; + GUI::Window const& window = static_cast<GUI::Window const&>(args.element); // TODO - moveable, fullscreen, dontRender (disable visibility?) @@ -588,7 +595,7 @@ static bool generate_window(generate_gui_args_t&& args) { ERR_FAIL_NULL_V_MSG(godot_panel, false, vformat("Failed to create Panel for GUI window %s", window_name)); godot_panel->set_custom_minimum_size(Utilities::to_godot_fvec2(window.get_size())); - godot_panel->set_self_modulate({ 1.0f, 1.0f, 1.0f, 0.0f }); + godot_panel->set_self_modulate({ 1.0_real, 1.0_real, 1.0_real, 0.0_real }); for (std::unique_ptr<GUI::Element> const& element : window.get_window_elements()) { Control* node = nullptr; diff --git a/extension/src/openvic-extension/utility/Utilities.hpp b/extension/src/openvic-extension/utility/Utilities.hpp index f7a0d67..15ff6b6 100644 --- a/extension/src/openvic-extension/utility/Utilities.hpp +++ b/extension/src/openvic-extension/utility/Utilities.hpp @@ -1,5 +1,7 @@ #pragma once +#include <concepts> + #include <godot_cpp/classes/font_file.hpp> #include <godot_cpp/classes/image_texture.hpp> @@ -35,6 +37,10 @@ namespace OpenVic::Utilities { godot::String float_to_formatted_string(float val, int32_t decimal_places); + constexpr real_t to_real_t(std::floating_point auto val) { + return static_cast<real_t>(val); + } + godot::String date_to_formatted_string(Date date); _FORCE_INLINE_ godot::Color to_godot_color(IsColour auto colour) { @@ -73,4 +79,8 @@ namespace OpenVic::Utilities { godot::Color const& colour, int32_t width, int32_t height, godot::Image::Format format = godot::Image::Format::FORMAT_RGBA8 ); -} + + namespace literals { + constexpr real_t operator""_real(long double val) { return to_real_t(val); } + } +}
\ No newline at end of file |