1 | /**************************************************************************/ |
2 | /* texture_button.h */ |
3 | /**************************************************************************/ |
4 | /* This file is part of: */ |
5 | /* GODOT ENGINE */ |
6 | /* https://godotengine.org */ |
7 | /**************************************************************************/ |
8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
10 | /* */ |
11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
12 | /* a copy of this software and associated documentation files (the */ |
13 | /* "Software"), to deal in the Software without restriction, including */ |
14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
17 | /* the following conditions: */ |
18 | /* */ |
19 | /* The above copyright notice and this permission notice shall be */ |
20 | /* included in all copies or substantial portions of the Software. */ |
21 | /* */ |
22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
29 | /**************************************************************************/ |
30 | |
31 | #ifndef TEXTURE_BUTTON_H |
32 | #define TEXTURE_BUTTON_H |
33 | |
34 | #include "scene/gui/base_button.h" |
35 | #include "scene/resources/bit_map.h" |
36 | class TextureButton : public BaseButton { |
37 | GDCLASS(TextureButton, BaseButton); |
38 | |
39 | public: |
40 | enum StretchMode { |
41 | STRETCH_SCALE, |
42 | STRETCH_TILE, |
43 | STRETCH_KEEP, |
44 | STRETCH_KEEP_CENTERED, |
45 | STRETCH_KEEP_ASPECT, |
46 | STRETCH_KEEP_ASPECT_CENTERED, |
47 | STRETCH_KEEP_ASPECT_COVERED, |
48 | }; |
49 | |
50 | private: |
51 | Ref<Texture2D> normal; |
52 | Ref<Texture2D> pressed; |
53 | Ref<Texture2D> hover; |
54 | Ref<Texture2D> disabled; |
55 | Ref<Texture2D> focused; |
56 | Ref<BitMap> click_mask; |
57 | bool ignore_texture_size = false; |
58 | StretchMode stretch_mode = STRETCH_KEEP; |
59 | |
60 | Rect2 _texture_region; |
61 | Rect2 _position_rect; |
62 | bool _tile = false; |
63 | |
64 | bool hflip = false; |
65 | bool vflip = false; |
66 | |
67 | void _set_texture(Ref<Texture2D> *p_destination, const Ref<Texture2D> &p_texture); |
68 | void _texture_changed(); |
69 | |
70 | protected: |
71 | virtual Size2 get_minimum_size() const override; |
72 | virtual bool has_point(const Point2 &p_point) const override; |
73 | void _notification(int p_what); |
74 | static void _bind_methods(); |
75 | |
76 | public: |
77 | void set_texture_normal(const Ref<Texture2D> &p_normal); |
78 | void set_texture_pressed(const Ref<Texture2D> &p_pressed); |
79 | void set_texture_hover(const Ref<Texture2D> &p_hover); |
80 | void set_texture_disabled(const Ref<Texture2D> &p_disabled); |
81 | void set_texture_focused(const Ref<Texture2D> &p_focused); |
82 | void set_click_mask(const Ref<BitMap> &p_click_mask); |
83 | |
84 | Ref<Texture2D> get_texture_normal() const; |
85 | Ref<Texture2D> get_texture_pressed() const; |
86 | Ref<Texture2D> get_texture_hover() const; |
87 | Ref<Texture2D> get_texture_disabled() const; |
88 | Ref<Texture2D> get_texture_focused() const; |
89 | Ref<BitMap> get_click_mask() const; |
90 | |
91 | bool get_ignore_texture_size() const; |
92 | void set_ignore_texture_size(bool p_ignore); |
93 | |
94 | void set_stretch_mode(StretchMode p_stretch_mode); |
95 | StretchMode get_stretch_mode() const; |
96 | |
97 | void set_flip_h(bool p_flip); |
98 | bool is_flipped_h() const; |
99 | |
100 | void set_flip_v(bool p_flip); |
101 | bool is_flipped_v() const; |
102 | |
103 | TextureButton(); |
104 | }; |
105 | |
106 | VARIANT_ENUM_CAST(TextureButton::StretchMode); |
107 | |
108 | #endif // TEXTURE_BUTTON_H |
109 | |