diff options
author | Hop311 <Hop3114@gmail.com> | 2023-11-17 21:17:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-17 21:17:55 +0100 |
commit | 9165f5980c5cfe75b3bad4303a5822340f6adcfc (patch) | |
tree | 79a69cb7601bf1367e4ee4f10ebf61b698319bf3 /extension/src/openvic-extension/utility/Utilities.hpp | |
parent | 72d893d55d26ae9dc6739a853d1773b3cb286123 (diff) | |
parent | aefc61a1aff091e31436c60d004531b5905cecba (diff) |
Merge pull request #166 from OpenVicProject/gui
GUI elements -> Godot UI nodes generator
Diffstat (limited to 'extension/src/openvic-extension/utility/Utilities.hpp')
-rw-r--r-- | extension/src/openvic-extension/utility/Utilities.hpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/extension/src/openvic-extension/utility/Utilities.hpp b/extension/src/openvic-extension/utility/Utilities.hpp new file mode 100644 index 0000000..752f495 --- /dev/null +++ b/extension/src/openvic-extension/utility/Utilities.hpp @@ -0,0 +1,59 @@ +#pragma once + +#include <godot_cpp/classes/font_file.hpp> +#include <godot_cpp/classes/image.hpp> + +#include <openvic-simulation/types/Colour.hpp> +#include <openvic-simulation/types/Vector.hpp> + +#define ERR(x) ((x) ? OK : FAILED) + +namespace OpenVic::Utilities { + + inline std::string godot_to_std_string(godot::String const& str) { + return str.ascii().get_data(); + } + + inline godot::String std_to_godot_string(std::string const& str) { + return str.c_str(); + } + + inline godot::String std_view_to_godot_string(std::string_view str) { + return std_to_godot_string(static_cast<std::string>(str)); + } + + inline godot::StringName std_to_godot_string_name(std::string const& str) { + return str.c_str(); + } + + inline godot::StringName std_view_to_godot_string_name(std::string_view str) { + return std_to_godot_string_name(static_cast<std::string>(str)); + } + + inline godot::Color to_godot_color(colour_t colour) { + return { + colour_byte_to_float((colour >> 16) & 0xFF), + colour_byte_to_float((colour >> 8) & 0xFF), + colour_byte_to_float(colour & 0xFF) + }; + } + + inline godot::Vector2i to_godot_ivec2(ivec2_t vec) { + return { vec.x, vec.y }; + } + + inline godot::Vector2 to_godot_fvec2(fvec2_t vec) { + return { vec.x, vec.y }; + } + + godot::Ref<godot::Image> load_godot_image(godot::String const& path); + + godot::Ref<godot::FontFile> load_godot_font(godot::String const& fnt_path, godot::Ref<godot::Image> const& image); + + void draw_pie_chart( + godot::Ref<godot::Image> image, godot::Array const& stopAngles, godot::Array const& colours, float radius, + godot::Vector2 shadow_displacement, float shadow_tightness, float shadow_radius, float shadow_thickness, + godot::Color trim_colour, float trim_size, float gradient_falloff, float gradient_base, bool donut, + bool donut_inner_trim, float donut_inner_radius + ); +} |