diff options
author | Hop311 <Hop3114@gmail.com> | 2023-12-11 12:08:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-11 12:08:55 +0100 |
commit | 0b3a162d3db840996c3d89e65dfe9270faebffe5 (patch) | |
tree | b22d464dbf8e0e2569b9be5aa130e4def2e51207 /extension/src/openvic-extension/classes/GFXPieChartTexture.hpp | |
parent | a6952efba078e49d6555b0586230986a2cb7ed40 (diff) | |
parent | fd375bdb35d8a7b2ac9cf3dd02cdb0f197451a0b (diff) |
Merge pull request #169 from OpenVicProject/guinode
Big UI commit - GUINode, MaskedFlag, PieChart, etc
Diffstat (limited to 'extension/src/openvic-extension/classes/GFXPieChartTexture.hpp')
-rw-r--r-- | extension/src/openvic-extension/classes/GFXPieChartTexture.hpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp b/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp new file mode 100644 index 0000000..315b00e --- /dev/null +++ b/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp @@ -0,0 +1,49 @@ +#pragma once + +#include <godot_cpp/classes/image_texture.hpp> + +#include <openvic-simulation/interface/GFX.hpp> + +namespace OpenVic { + class GFXPieChartTexture : public godot::ImageTexture { + GDCLASS(GFXPieChartTexture, godot::ImageTexture) + + using slice_t = std::pair<godot::Color, float>; + + GFX::PieChart const* PROPERTY(gfx_pie_chart); + std::vector<slice_t> slices; + float total_weight; + godot::Ref<godot::Image> pie_chart_image; + + godot::Error _generate_pie_chart_image(); + + protected: + static void _bind_methods(); + + public: + GFXPieChartTexture(); + + /* Set slices given new_slices, an Array of Dictionaries, each with the following keys: + * - colour: Color + * - weight: float + */ + godot::Error set_slices(godot::Array const& new_slices); + + /* Create a GFXPieChartTexture using the specific GFX::PieChart. + * Returns nullptr if setting gfx_pie_chart fails. */ + static godot::Ref<GFXPieChartTexture> make_gfx_pie_chart_texture(GFX::PieChart const* gfx_pie_chart); + + /* Reset gfx_pie_chart, flag_country and flag_type to nullptr/an empty string, and unreference all images. + * This does not affect the godot::ImageTexture, which cannot be reset to a null or empty image. */ + void clear(); + + /* Set the GFX::PieChart and regenerate the pie chart image. */ + godot::Error set_gfx_pie_chart(GFX::PieChart const* new_gfx_pie_chart); + + /* Search for a GFX::PieChart with the specfied name and, if successful, set it using set_gfx_pie_chart. */ + godot::Error set_gfx_pie_chart_name(godot::String const& gfx_pie_chart_name); + + /* Return the name of the GFX::PieChart, or an empty String if it's null */ + godot::String get_gfx_pie_chart_name() const; + }; +} |