aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic-extension/classes/GUIScrollbar.hpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-02-24 23:07:24 +0100
committer GitHub <noreply@github.com>2024-02-24 23:07:24 +0100
commit9e305db5e5090a1a24979c480d64eebfe2de65da (patch)
tree487fea19d42106c08b60f5bba99bc76485073002 /extension/src/openvic-extension/classes/GUIScrollbar.hpp
parent5d7c6eafe35e2c6e952bc0b3f91d27d760c8e75e (diff)
parent843edde55306e3fbdb5e37ef9b7c09c7b53f50c4 (diff)
Merge pull request #209 from OpenVicProject/scrollbar
Added GUIScrollbar and GFXCorneredTileSupportingTexture
Diffstat (limited to 'extension/src/openvic-extension/classes/GUIScrollbar.hpp')
-rw-r--r--extension/src/openvic-extension/classes/GUIScrollbar.hpp102
1 files changed, 102 insertions, 0 deletions
diff --git a/extension/src/openvic-extension/classes/GUIScrollbar.hpp b/extension/src/openvic-extension/classes/GUIScrollbar.hpp
new file mode 100644
index 0000000..7af7b57
--- /dev/null
+++ b/extension/src/openvic-extension/classes/GUIScrollbar.hpp
@@ -0,0 +1,102 @@
+#pragma once
+
+#include <godot_cpp/classes/control.hpp>
+#include <godot_cpp/classes/input_event.hpp>
+
+#include <openvic-simulation/interface/GUI.hpp>
+
+#include "openvic-extension/classes/GFXSpriteTexture.hpp"
+
+namespace OpenVic {
+ class GUIScrollbar : public godot::Control {
+ GDCLASS(GUIScrollbar, godot::Control)
+
+ static godot::StringName const& _signal_value_changed();
+
+ GUI::Scrollbar const* PROPERTY(gui_scrollbar);
+
+ godot::Ref<GFXSpriteTexture> slider_texture;
+ godot::Ref<GFXSpriteTexture> track_texture;
+ godot::Ref<GFXSpriteTexture> less_texture;
+ godot::Ref<GFXSpriteTexture> more_texture;
+
+ godot::Rect2 slider_rect;
+ real_t slider_start, slider_distance;
+ godot::Rect2 track_rect;
+ godot::Rect2 less_rect;
+ godot::Rect2 more_rect;
+
+ godot::Ref<GFXSpriteTexture> range_limit_min_texture;
+ godot::Ref<GFXSpriteTexture> range_limit_max_texture;
+
+ godot::Rect2 range_limit_min_rect;
+ godot::Rect2 range_limit_max_rect;
+
+ godot::Orientation PROPERTY(orientation);
+
+ int32_t PROPERTY(value);
+ int32_t PROPERTY(min_value);
+ int32_t PROPERTY(max_value);
+
+ bool PROPERTY_CUSTOM_PREFIX(range_limited, is);
+ int32_t PROPERTY(range_limit_min);
+ int32_t PROPERTY(range_limit_max);
+
+ bool hover_slider, hover_track, hover_less, hover_more;
+ bool pressed_slider, pressed_track, pressed_less, pressed_more;
+
+ /* The time between value changes while the less/more button is held down (in seconds). */
+ static constexpr double BUTTON_CHANGE_DELAY = 1.0 / 60.0;
+ /* The time between value change rate increases while the less/more button is held down (in seconds). */
+ static constexpr double BUTTON_CHANGE_ACCELERATE_DELAY = 10.0 * BUTTON_CHANGE_DELAY;
+
+ /* When the less/more button is pressed, button_change_value_base is initialised based on the shift and control keys
+ * and button_change_value is initialised to 0. Every BUTTON_CHANGE_ACCELERATE_DELAY seconds button_change_value
+ * increases by button_change_value_base, and every BUTTON_CHANGE_DELAY seconds value changes by button_change_value.
+ * If button_change_value is still 0 when the button is released, then value will be increased by
+ * button_change_value_base so that short clicks still have an effect.*/
+ int32_t button_change_value_base, button_change_value;
+ double button_change_accelerate_timer, button_change_timer;
+
+ void _start_button_change(bool shift_pressed, bool control_pressed);
+ void _stop_button_change();
+
+ /* Changes value by button_change_value with the direction determined by orientation and pressed_less or pressed_more.
+ * Returns true if a change occured, otherwise false. */
+ bool _update_button_change();
+
+ float _value_to_ratio(int32_t val) const;
+
+ void _calculate_rects();
+
+ void _constrain_value();
+ godot::Error _constrain_range_limits();
+ godot::Error _constrain_limits();
+
+ protected:
+ static void _bind_methods();
+ void _notification(int what);
+
+ public:
+ GUIScrollbar();
+
+ godot::Vector2 _get_minimum_size() const override;
+ void _gui_input(godot::Ref<godot::InputEvent> const& event) override;
+
+ void emit_value_changed();
+ godot::Error reset();
+ void clear();
+
+ godot::Error set_gui_scrollbar(GUI::Scrollbar const* new_gui_scrollbar);
+ godot::Error set_gui_scrollbar_name(godot::String const& gui_scene, godot::String const& gui_scrollbar_name);
+ godot::String get_gui_scrollbar_name() const;
+
+ void set_value(int32_t new_value, bool signal = true);
+
+ float get_value_as_ratio() const;
+ void set_value_as_ratio(float new_ratio, bool signal = true);
+
+ godot::Error set_range_limits(int32_t new_range_limit_min, int32_t new_range_limit_max, bool signal = true);
+ godot::Error set_limits(int32_t new_min_value, int32_t new_max_value, bool signal = true);
+ };
+}