aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic-extension/classes/GFXButtonStateTexture.hpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-02-19 23:35:27 +0100
committer GitHub <noreply@github.com>2024-02-19 23:35:27 +0100
commit5d7c6eafe35e2c6e952bc0b3f91d27d760c8e75e (patch)
tree1912fb231991b53dd638a295bb8d8f84b587885b /extension/src/openvic-extension/classes/GFXButtonStateTexture.hpp
parent275cfbb62fe69828aeb9968110ad822447322a4e (diff)
parentc48d14ca66d47ea7c25bb9a36c3d51f76d8351fc (diff)
Merge pull request #208 from OpenVicProject/sprite-texture
Added multipurpose GFXSpriteTexture + reworked GFXButtonStateTexture
Diffstat (limited to 'extension/src/openvic-extension/classes/GFXButtonStateTexture.hpp')
-rw-r--r--extension/src/openvic-extension/classes/GFXButtonStateTexture.hpp32
1 files changed, 26 insertions, 6 deletions
diff --git a/extension/src/openvic-extension/classes/GFXButtonStateTexture.hpp b/extension/src/openvic-extension/classes/GFXButtonStateTexture.hpp
index 32f4087..c98159d 100644
--- a/extension/src/openvic-extension/classes/GFXButtonStateTexture.hpp
+++ b/extension/src/openvic-extension/classes/GFXButtonStateTexture.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <godot_cpp/classes/atlas_texture.hpp>
#include <godot_cpp/classes/image_texture.hpp>
#include <openvic-simulation/utility/Getters.hpp>
@@ -12,7 +13,8 @@ namespace OpenVic {
enum ButtonState {
HOVER,
PRESSED,
- DISABLED
+ DISABLED,
+ BUTTON_STATE_COUNT
};
private:
@@ -27,20 +29,38 @@ namespace OpenVic {
/* Create a GFXButtonStateTexture using the specified godot::Image. Returns nullptr if generate_state_image fails. */
static godot::Ref<GFXButtonStateTexture> make_gfx_button_state_texture(
- ButtonState button_state, godot::Ref<godot::Image> const& source_image = nullptr
+ ButtonState button_state, godot::Ref<godot::Image> const& source_image, godot::Rect2i const& region
);
/* Set the ButtonState to be generated by this class (calling this does not trigger state image generation). */
void set_button_state(ButtonState new_button_state);
- /* Generate a modified version of source_image and update the underlying godot::ImageTexture to use it. */
- godot::Error generate_state_image(godot::Ref<godot::Image> const& source_image);
-
- static godot::StringName const& get_generate_state_image_func_name();
+ /* Generate a modified version of the given region of source_image
+ * and update the underlying godot::ImageTexture to use it. */
+ godot::Error generate_state_image(godot::Ref<godot::Image> const& source_image, godot::Rect2i const& region);
static godot::StringName const& button_state_to_theme_name(ButtonState button_state);
godot::StringName const& get_button_state_theme() const;
};
+
+ class GFXButtonStateHavingTexture : public godot::AtlasTexture {
+ GDCLASS(GFXButtonStateHavingTexture, godot::AtlasTexture)
+
+ std::array<godot::Ref<GFXButtonStateTexture>, GFXButtonStateTexture::BUTTON_STATE_COUNT> button_state_textures;
+
+ protected:
+ static void _bind_methods();
+
+ godot::Ref<godot::Image> button_image;
+
+ void _update_button_states();
+ void _clear_button_states();
+
+ GFXButtonStateHavingTexture();
+
+ public:
+ godot::Ref<GFXButtonStateTexture> get_button_state_texture(GFXButtonStateTexture::ButtonState button_state);
+ };
}
VARIANT_ENUM_CAST(OpenVic::GFXButtonStateTexture::ButtonState);