1 /*************************************************************************/ 2 /* texture_button.h */ 3 /*************************************************************************/ 4 /* This file is part of: */ 5 /* GODOT ENGINE */ 6 /* https://godotengine.org */ 7 /*************************************************************************/ 8 /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ 9 /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ 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 #ifndef TEXTURE_BUTTON_H 31 #define TEXTURE_BUTTON_H 32 33 #include "scene/gui/base_button.h" 34 #include "scene/resources/bit_mask.h" 35 36 class TextureButton : public BaseButton { 37 38 OBJ_TYPE(TextureButton, BaseButton); 39 40 public: 41 enum ResizeMode { 42 RESIZE_SCALE, // for backwards compatibility 43 RESIZE_STRETCH, 44 }; 45 46 enum StretchMode { 47 STRETCH_SCALE_ON_EXPAND, //default, for backwards compatibility 48 STRETCH_SCALE, 49 STRETCH_TILE, 50 STRETCH_KEEP, 51 STRETCH_KEEP_CENTERED, 52 STRETCH_KEEP_ASPECT, 53 STRETCH_KEEP_ASPECT_CENTERED, 54 STRETCH_KEEP_ASPECT_COVERED, 55 }; 56 57 private: 58 Ref<Texture> normal; 59 Ref<Texture> pressed; 60 Ref<Texture> hover; 61 Ref<Texture> disabled; 62 Ref<Texture> focused; 63 Ref<BitMap> click_mask; 64 Color modulate; 65 ResizeMode resize_mode; 66 Size2 scale; 67 StretchMode stretch_mode; 68 69 protected: 70 virtual bool has_point(const Point2 &p_point) const; 71 virtual Size2 get_minimum_size() const; 72 void _notification(int p_what); 73 static void _bind_methods(); 74 75 public: 76 void set_normal_texture(const Ref<Texture> &p_normal); 77 void set_pressed_texture(const Ref<Texture> &p_pressed); 78 void set_hover_texture(const Ref<Texture> &p_hover); 79 void set_disabled_texture(const Ref<Texture> &p_disabled); 80 void set_focused_texture(const Ref<Texture> &p_focused); 81 void set_click_mask(const Ref<BitMap> &p_image); 82 83 Ref<Texture> get_normal_texture() const; 84 Ref<Texture> get_pressed_texture() const; 85 Ref<Texture> get_hover_texture() const; 86 Ref<Texture> get_disabled_texture() const; 87 Ref<Texture> get_focused_texture() const; 88 Ref<BitMap> get_click_mask() const; 89 90 void set_modulate(const Color &p_modulate); 91 Color get_modulate() const; 92 93 ResizeMode get_resize_mode() const; 94 void set_resize_mode(ResizeMode p_mode); 95 96 void set_texture_scale(Size2 p_scale); 97 Size2 get_texture_scale() const; 98 99 void set_stretch_mode(StretchMode stretch_mode); 100 StretchMode get_stretch_mode() const; 101 102 TextureButton(); 103 }; 104 105 VARIANT_ENUM_CAST(TextureButton::ResizeMode); 106 VARIANT_ENUM_CAST(TextureButton::StretchMode); 107 #endif // TEXTURE_BUTTON_H 108