aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp
blob: 315b00e65f1483f3fc4b19e097863b5d15517bf8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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;
   };
}