| 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 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/gui/base_button.h" |
| 34 |
#include "scene/resources/bit_map.h" |
| 35 |
class TextureButton : public BaseButton { |
| 36 |
GDCLASS(TextureButton, BaseButton); |
| 37 |
|
| 38 |
public: |
| 39 |
enum StretchMode { |
| 40 |
STRETCH_SCALE, |
| 41 |
STRETCH_TILE, |
| 42 |
STRETCH_KEEP, |
| 43 |
STRETCH_KEEP_CENTERED, |
| 44 |
STRETCH_KEEP_ASPECT, |
| 45 |
STRETCH_KEEP_ASPECT_CENTERED, |
| 46 |
STRETCH_KEEP_ASPECT_COVERED, |
| 47 |
}; |
| 48 |
|
| 49 |
private: |
| 50 |
Ref<Texture2D> normal; |
| 51 |
Ref<Texture2D> pressed; |
| 52 |
Ref<Texture2D> hover; |
| 53 |
Ref<Texture2D> disabled; |
| 54 |
Ref<Texture2D> focused; |
| 55 |
Ref<BitMap> click_mask; |
| 56 |
bool ignore_texture_size = false; |
| 57 |
StretchMode stretch_mode = STRETCH_KEEP; |
| 58 |
|
| 59 |
Rect2 _texture_region; |
| 60 |
Rect2 _position_rect; |
| 61 |
bool _tile = false; |
| 62 |
|
| 63 |
bool hflip = false; |
| 64 |
bool vflip = false; |
| 65 |
|
| 66 |
void _set_texture(Ref<Texture2D> *p_destination, const Ref<Texture2D> &p_texture); |
| 67 |
void _texture_changed(); |
| 68 |
|
| 69 |
protected: |
| 70 |
virtual Size2 get_minimum_size() const override; |
| 71 |
virtual bool has_point(const Point2 &p_point) const override; |
| 72 |
void _notification(int p_what); |
| 73 |
static void _bind_methods(); |
| 74 |
|
| 75 |
public: |
| 76 |
void set_texture_normal(const Ref<Texture2D> &p_normal); |
| 77 |
void set_texture_pressed(const Ref<Texture2D> &p_pressed); |
| 78 |
void set_texture_hover(const Ref<Texture2D> &p_hover); |
| 79 |
void set_texture_disabled(const Ref<Texture2D> &p_disabled); |
| 80 |
void set_texture_focused(const Ref<Texture2D> &p_focused); |
| 81 |
void set_click_mask(const Ref<BitMap> &p_click_mask); |
| 82 |
|
| 83 |
Ref<Texture2D> get_texture_normal() const; |
| 84 |
Ref<Texture2D> get_texture_pressed() const; |
| 85 |
Ref<Texture2D> get_texture_hover() const; |
| 86 |
Ref<Texture2D> get_texture_disabled() const; |
| 87 |
Ref<Texture2D> get_texture_focused() const; |
| 88 |
Ref<BitMap> get_click_mask() const; |
| 89 |
|
| 90 |
bool get_ignore_texture_size() const; |
| 91 |
void set_ignore_texture_size(bool p_ignore); |
| 92 |
|
| 93 |
void set_stretch_mode(StretchMode p_stretch_mode); |
| 94 |
StretchMode get_stretch_mode() const; |
| 95 |
|
| 96 |
void set_flip_h(bool p_flip); |
| 97 |
bool is_flipped_h() const; |
| 98 |
|
| 99 |
void set_flip_v(bool p_flip); |
| 100 |
bool is_flipped_v() const; |
| 101 |
}; |
| 102 |
|
| 103 |
VARIANT_ENUM_CAST(TextureButton::StretchMode); |