| 1 | /**************************************************************************/ |
| 2 | /* 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 BUTTON_H |
| 32 | #define BUTTON_H |
| 33 | |
| 34 | #include "scene/gui/base_button.h" |
| 35 | #include "scene/resources/text_paragraph.h" |
| 36 | |
| 37 | class Button : public BaseButton { |
| 38 | GDCLASS(Button, BaseButton); |
| 39 | |
| 40 | private: |
| 41 | bool flat = false; |
| 42 | String text; |
| 43 | String xl_text; |
| 44 | Ref<TextParagraph> text_buf; |
| 45 | |
| 46 | String language; |
| 47 | TextDirection text_direction = TEXT_DIRECTION_AUTO; |
| 48 | TextServer::OverrunBehavior overrun_behavior = TextServer::OVERRUN_NO_TRIMMING; |
| 49 | |
| 50 | Ref<Texture2D> icon; |
| 51 | bool expand_icon = false; |
| 52 | bool clip_text = false; |
| 53 | HorizontalAlignment alignment = HORIZONTAL_ALIGNMENT_CENTER; |
| 54 | HorizontalAlignment horizontal_icon_alignment = HORIZONTAL_ALIGNMENT_LEFT; |
| 55 | VerticalAlignment vertical_icon_alignment = VERTICAL_ALIGNMENT_CENTER; |
| 56 | float _internal_margin[4] = {}; |
| 57 | |
| 58 | struct ThemeCache { |
| 59 | Ref<StyleBox> normal; |
| 60 | Ref<StyleBox> normal_mirrored; |
| 61 | Ref<StyleBox> pressed; |
| 62 | Ref<StyleBox> pressed_mirrored; |
| 63 | Ref<StyleBox> hover; |
| 64 | Ref<StyleBox> hover_mirrored; |
| 65 | Ref<StyleBox> hover_pressed; |
| 66 | Ref<StyleBox> hover_pressed_mirrored; |
| 67 | Ref<StyleBox> disabled; |
| 68 | Ref<StyleBox> disabled_mirrored; |
| 69 | Ref<StyleBox> focus; |
| 70 | |
| 71 | Color font_color; |
| 72 | Color font_focus_color; |
| 73 | Color font_pressed_color; |
| 74 | Color font_hover_color; |
| 75 | Color font_hover_pressed_color; |
| 76 | Color font_disabled_color; |
| 77 | |
| 78 | Ref<Font> font; |
| 79 | int font_size = 0; |
| 80 | int outline_size = 0; |
| 81 | Color font_outline_color; |
| 82 | |
| 83 | Color icon_normal_color; |
| 84 | Color icon_focus_color; |
| 85 | Color icon_pressed_color; |
| 86 | Color icon_hover_color; |
| 87 | Color icon_hover_pressed_color; |
| 88 | Color icon_disabled_color; |
| 89 | |
| 90 | Ref<Texture2D> icon; |
| 91 | |
| 92 | int h_separation = 0; |
| 93 | int icon_max_width = 0; |
| 94 | } theme_cache; |
| 95 | |
| 96 | Size2 _fit_icon_size(const Size2 &p_size) const; |
| 97 | |
| 98 | void _shape(Ref<TextParagraph> p_paragraph = Ref<TextParagraph>(), String p_text = "" ); |
| 99 | void _texture_changed(); |
| 100 | |
| 101 | protected: |
| 102 | void _set_internal_margin(Side p_side, float p_value); |
| 103 | virtual void _queue_update_size_cache(); |
| 104 | |
| 105 | void _notification(int p_what); |
| 106 | static void _bind_methods(); |
| 107 | |
| 108 | public: |
| 109 | virtual Size2 get_minimum_size() const override; |
| 110 | |
| 111 | Size2 get_minimum_size_for_text_and_icon(const String &p_text, Ref<Texture2D> p_icon) const; |
| 112 | |
| 113 | void set_text(const String &p_text); |
| 114 | String get_text() const; |
| 115 | |
| 116 | void set_text_overrun_behavior(TextServer::OverrunBehavior p_behavior); |
| 117 | TextServer::OverrunBehavior get_text_overrun_behavior() const; |
| 118 | |
| 119 | void set_text_direction(TextDirection p_text_direction); |
| 120 | TextDirection get_text_direction() const; |
| 121 | |
| 122 | void set_language(const String &p_language); |
| 123 | String get_language() const; |
| 124 | |
| 125 | void set_icon(const Ref<Texture2D> &p_icon); |
| 126 | Ref<Texture2D> get_icon() const; |
| 127 | |
| 128 | void set_expand_icon(bool p_enabled); |
| 129 | bool is_expand_icon() const; |
| 130 | |
| 131 | void set_flat(bool p_enabled); |
| 132 | bool is_flat() const; |
| 133 | |
| 134 | void set_clip_text(bool p_enabled); |
| 135 | bool get_clip_text() const; |
| 136 | |
| 137 | void set_text_alignment(HorizontalAlignment p_alignment); |
| 138 | HorizontalAlignment get_text_alignment() const; |
| 139 | |
| 140 | void set_icon_alignment(HorizontalAlignment p_alignment); |
| 141 | void set_vertical_icon_alignment(VerticalAlignment p_alignment); |
| 142 | HorizontalAlignment get_icon_alignment() const; |
| 143 | VerticalAlignment get_vertical_icon_alignment() const; |
| 144 | |
| 145 | Button(const String &p_text = String()); |
| 146 | ~Button(); |
| 147 | }; |
| 148 | |
| 149 | #endif // BUTTON_H |
| 150 | |