limboai/editor/mode_switch_button.h

71 lines
1.8 KiB
C
Raw Normal View History

/**
* mode_switch_button.h
* =============================================================================
2024-03-21 20:38:57 +00:00
* Copyright 2021-2024 Serhii Snitsaruk
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
* =============================================================================
*/
#ifdef TOOLS_ENABLED
#ifndef MODE_SWITCH_BUTTON
#define MODE_SWITCH_BUTTON
2024-01-10 21:45:42 +00:00
#include "../util/limbo_compat.h"
2024-01-07 12:45:27 +00:00
#ifdef LIMBOAI_MODULE
#include "core/typedefs.h"
#include "scene/gui/button.h"
#include "scene/resources/texture.h"
2024-01-13 16:10:42 +00:00
#endif // LIMBOAI_MODULE
2024-01-07 12:45:27 +00:00
#ifdef LIMBOAI_GDEXTENSION
#include <godot_cpp/classes/button.hpp>
#include <godot_cpp/classes/texture2d.hpp>
#include <godot_cpp/templates/vector.hpp>
using namespace godot;
2024-01-13 16:10:42 +00:00
#endif // LIMBOAI_GDEXTENSION
2024-01-07 12:45:27 +00:00
class ModeSwitchButton : public Button {
GDCLASS(ModeSwitchButton, Button);
private:
struct Mode {
int id = 0;
Ref<Texture2D> icon = nullptr;
String tooltip = "";
};
int current_mode_index = -1;
Vector<Mode> modes;
_FORCE_INLINE_ void _set_mode_by_index(int p_index) {
current_mode_index = p_index;
this->set_button_icon(modes[current_mode_index].icon);
if (!modes[current_mode_index].tooltip.is_empty()) {
set_tooltip_text(modes[current_mode_index].tooltip);
}
}
protected:
static void _bind_methods();
2024-01-09 12:34:24 +00:00
void _notification(int p_what);
public:
void add_mode(int p_id, const Ref<Texture2D> &p_icon, const String &p_tooltip = "");
int get_mode() const { return modes.size() > 0 ? modes[current_mode_index].id : -1; }
void set_mode(int p_id, bool p_no_signal = false);
_FORCE_INLINE_ void next_mode() { set_mode((current_mode_index + 1) % modes.size()); };
void clear();
ModeSwitchButton();
};
2024-01-13 16:10:42 +00:00
#endif // MODE_SWITCH_BUTTON_H
#endif // ! TOOLS_ENABLED