From fd375bdb35d8a7b2ac9cf3dd02cdb0f197451a0b Mon Sep 17 00:00:00 2001 From: hop311 Date: Thu, 7 Dec 2023 22:45:19 +0000 Subject: Big UI commit - GUINode, MaskedFlag, PieChart, etc --- .../classes/GFXPieChartTexture.hpp | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 extension/src/openvic-extension/classes/GFXPieChartTexture.hpp (limited to 'extension/src/openvic-extension/classes/GFXPieChartTexture.hpp') 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 + +#include + +namespace OpenVic { + class GFXPieChartTexture : public godot::ImageTexture { + GDCLASS(GFXPieChartTexture, godot::ImageTexture) + + using slice_t = std::pair; + + GFX::PieChart const* PROPERTY(gfx_pie_chart); + std::vector slices; + float total_weight; + godot::Ref 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 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; + }; +} -- cgit v1.2.3-56-ga3b1