| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  texture_button.cpp                                                   */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							| 
									
										
										
										
											2017-08-27 14:16:55 +02:00
										 |  |  | /*                      https://godotengine.org                          */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2021-01-01 20:13:46 +01:00
										 |  |  | /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md).   */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the       */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including   */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,   */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to    */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to */ | 
					
						
							|  |  |  | /* the following conditions:                                             */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be        */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.       */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #include "texture_button.h"
 | 
					
						
							| 
									
										
										
										
											2018-01-19 00:01:23 +01:00
										 |  |  | #include "core/typedefs.h"
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | Size2 TextureButton::get_minimum_size() const { | 
					
						
							| 
									
										
										
										
											2017-02-09 22:46:35 +08:00
										 |  |  | 	Size2 rscale = Control::get_minimum_size(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!expand) { | 
					
						
							|  |  |  | 		if (normal.is_null()) { | 
					
						
							|  |  |  | 			if (pressed.is_null()) { | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 				if (hover.is_null()) { | 
					
						
							|  |  |  | 					if (click_mask.is_null()) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						rscale = Size2(); | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						rscale = click_mask->get_size(); | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					rscale = hover->get_size(); | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				rscale = pressed->get_size(); | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			rscale = normal->get_size(); | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-02-09 22:46:35 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-01-03 00:23:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-09 22:46:35 +08:00
										 |  |  | 	return rscale.abs(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | bool TextureButton::has_point(const Point2 &p_point) const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	if (click_mask.is_valid()) { | 
					
						
							| 
									
										
										
										
											2018-01-19 00:01:23 +01:00
										 |  |  | 		Point2 point = p_point; | 
					
						
							|  |  |  | 		Rect2 rect = Rect2(); | 
					
						
							|  |  |  | 		Size2 mask_size = click_mask->get_size(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-21 17:23:47 +01:00
										 |  |  | 		if (_position_rect.has_no_area()) { | 
					
						
							| 
									
										
										
										
											2019-02-21 00:47:17 +01:00
										 |  |  | 			rect.size = mask_size; | 
					
						
							|  |  |  | 		} else if (_tile) { | 
					
						
							| 
									
										
										
										
											2018-01-19 00:01:23 +01:00
										 |  |  | 			// if the stretch mode is tile we offset the point to keep it inside the mask size
 | 
					
						
							|  |  |  | 			rect.size = mask_size; | 
					
						
							|  |  |  | 			if (_position_rect.has_point(point)) { | 
					
						
							|  |  |  | 				int cols = (int)Math::ceil(_position_rect.size.x / mask_size.x); | 
					
						
							|  |  |  | 				int rows = (int)Math::ceil(_position_rect.size.y / mask_size.y); | 
					
						
							|  |  |  | 				int col = (int)(point.x / mask_size.x) % cols; | 
					
						
							|  |  |  | 				int row = (int)(point.y / mask_size.y) % rows; | 
					
						
							|  |  |  | 				point.x -= mask_size.x * col; | 
					
						
							|  |  |  | 				point.y -= mask_size.y * row; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			// we need to transform the point from our scaled / translated image back to our mask image
 | 
					
						
							|  |  |  | 			Point2 ofs = _position_rect.position; | 
					
						
							|  |  |  | 			Size2 scale = mask_size / _position_rect.size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			switch (stretch_mode) { | 
					
						
							|  |  |  | 				case STRETCH_KEEP_ASPECT_COVERED: { | 
					
						
							|  |  |  | 					// if the stretch mode is aspect covered the image uses a texture region so we need to take that into account
 | 
					
						
							|  |  |  | 					float min = MIN(scale.x, scale.y); | 
					
						
							|  |  |  | 					scale.x = min; | 
					
						
							|  |  |  | 					scale.y = min; | 
					
						
							|  |  |  | 					ofs -= _texture_region.position / min; | 
					
						
							|  |  |  | 				} break; | 
					
						
							| 
									
										
										
										
											2018-09-26 13:13:56 +02:00
										 |  |  | 				default: { | 
					
						
							|  |  |  | 					// FIXME: Why a switch if we only handle one enum value?
 | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-01-19 00:01:23 +01:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// offset and scale the new point position to adjust it to the bitmask size
 | 
					
						
							|  |  |  | 			point -= ofs; | 
					
						
							|  |  |  | 			point *= scale; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// finally, we need to check if the point is inside a rectangle with a position >= 0,0 and a size <= mask_size
 | 
					
						
							|  |  |  | 			rect.position = Point2(MAX(0, _texture_region.position.x), MAX(0, _texture_region.position.y)); | 
					
						
							|  |  |  | 			rect.size = Size2(MIN(mask_size.x, _texture_region.size.x), MIN(mask_size.y, _texture_region.size.y)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!rect.has_point(point)) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			return false; | 
					
						
							| 
									
										
										
										
											2018-01-19 00:01:23 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-19 00:01:23 +01:00
										 |  |  | 		Point2i p = point; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return click_mask->get_bit(p); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return Control::has_point(p_point); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TextureButton::_notification(int p_what) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	switch (p_what) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		case NOTIFICATION_DRAW: { | 
					
						
							|  |  |  | 			DrawMode draw_mode = get_draw_mode(); | 
					
						
							| 
									
										
										
										
											2015-01-03 00:23:14 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			Ref<Texture> texdraw; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			switch (draw_mode) { | 
					
						
							|  |  |  | 				case DRAW_NORMAL: { | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 					if (normal.is_valid()) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						texdraw = normal; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				} break; | 
					
						
							| 
									
										
										
										
											2018-10-06 01:06:32 +02:00
										 |  |  | 				case DRAW_HOVER_PRESSED: | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				case DRAW_PRESSED: { | 
					
						
							|  |  |  | 					if (pressed.is_null()) { | 
					
						
							|  |  |  | 						if (hover.is_null()) { | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 							if (normal.is_valid()) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 								texdraw = normal; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 							} | 
					
						
							|  |  |  | 						} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 							texdraw = hover; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						texdraw = pressed; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				} break; | 
					
						
							|  |  |  | 				case DRAW_HOVER: { | 
					
						
							|  |  |  | 					if (hover.is_null()) { | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 						if (pressed.is_valid() && is_pressed()) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 							texdraw = pressed; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 						} else if (normal.is_valid()) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 							texdraw = normal; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						texdraw = hover; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				} break; | 
					
						
							|  |  |  | 				case DRAW_DISABLED: { | 
					
						
							|  |  |  | 					if (disabled.is_null()) { | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 						if (normal.is_valid()) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 							texdraw = normal; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						texdraw = disabled; | 
					
						
							| 
									
										
										
										
											2021-05-05 12:44:11 +02:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				} break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-01-03 00:23:14 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (texdraw.is_valid()) { | 
					
						
							| 
									
										
										
										
											2017-02-09 22:46:35 +08:00
										 |  |  | 				Point2 ofs; | 
					
						
							|  |  |  | 				Size2 size = texdraw->get_size(); | 
					
						
							| 
									
										
										
										
											2018-01-19 00:01:23 +01:00
										 |  |  | 				_texture_region = Rect2(Point2(), texdraw->get_size()); | 
					
						
							|  |  |  | 				_tile = false; | 
					
						
							| 
									
										
										
										
											2017-02-09 22:46:35 +08:00
										 |  |  | 				if (expand) { | 
					
						
							|  |  |  | 					switch (stretch_mode) { | 
					
						
							| 
									
										
										
										
											2017-02-13 19:41:12 +08:00
										 |  |  | 						case STRETCH_KEEP: | 
					
						
							| 
									
										
										
										
											2017-02-09 22:46:35 +08:00
										 |  |  | 							size = texdraw->get_size(); | 
					
						
							|  |  |  | 							break; | 
					
						
							| 
									
										
										
										
											2017-02-13 19:41:12 +08:00
										 |  |  | 						case STRETCH_SCALE: | 
					
						
							| 
									
										
										
										
											2017-02-09 22:46:35 +08:00
										 |  |  | 							size = get_size(); | 
					
						
							|  |  |  | 							break; | 
					
						
							| 
									
										
										
										
											2017-02-13 19:41:12 +08:00
										 |  |  | 						case STRETCH_TILE: | 
					
						
							| 
									
										
										
										
											2017-02-09 22:46:35 +08:00
										 |  |  | 							size = get_size(); | 
					
						
							| 
									
										
										
										
											2018-01-19 00:01:23 +01:00
										 |  |  | 							_tile = true; | 
					
						
							| 
									
										
										
										
											2017-02-09 22:46:35 +08:00
										 |  |  | 							break; | 
					
						
							| 
									
										
										
										
											2017-02-13 19:41:12 +08:00
										 |  |  | 						case STRETCH_KEEP_CENTERED: | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 							ofs = (get_size() - texdraw->get_size()) / 2; | 
					
						
							| 
									
										
										
										
											2017-02-09 22:46:35 +08:00
										 |  |  | 							size = texdraw->get_size(); | 
					
						
							|  |  |  | 							break; | 
					
						
							| 
									
										
										
										
											2017-02-13 19:41:12 +08:00
										 |  |  | 						case STRETCH_KEEP_ASPECT_CENTERED: | 
					
						
							|  |  |  | 						case STRETCH_KEEP_ASPECT: { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 							Size2 _size = get_size(); | 
					
						
							| 
									
										
										
										
											2017-02-09 22:46:35 +08:00
										 |  |  | 							float tex_width = texdraw->get_width() * _size.height / texdraw->get_height(); | 
					
						
							|  |  |  | 							float tex_height = _size.height; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							if (tex_width > _size.width) { | 
					
						
							|  |  |  | 								tex_width = _size.width; | 
					
						
							|  |  |  | 								tex_height = texdraw->get_height() * tex_width / texdraw->get_width(); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 							if (stretch_mode == STRETCH_KEEP_ASPECT_CENTERED) { | 
					
						
							|  |  |  | 								ofs.x = (_size.width - tex_width) / 2; | 
					
						
							|  |  |  | 								ofs.y = (_size.height - tex_height) / 2; | 
					
						
							| 
									
										
										
										
											2017-02-09 22:46:35 +08:00
										 |  |  | 							} | 
					
						
							|  |  |  | 							size.width = tex_width; | 
					
						
							|  |  |  | 							size.height = tex_height; | 
					
						
							|  |  |  | 						} break; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						case STRETCH_KEEP_ASPECT_COVERED: { | 
					
						
							| 
									
										
										
										
											2017-02-09 22:46:35 +08:00
										 |  |  | 							size = get_size(); | 
					
						
							|  |  |  | 							Size2 tex_size = texdraw->get_size(); | 
					
						
							| 
									
										
										
										
											2019-08-20 13:41:14 -03:00
										 |  |  | 							Size2 scale_size(size.width / tex_size.width, size.height / tex_size.height); | 
					
						
							|  |  |  | 							float scale = scale_size.width > scale_size.height ? scale_size.width : scale_size.height; | 
					
						
							|  |  |  | 							Size2 scaled_tex_size = tex_size * scale; | 
					
						
							|  |  |  | 							Point2 ofs2 = ((scaled_tex_size - size) / scale).abs() / 2.0f; | 
					
						
							| 
									
										
										
										
											2019-02-12 21:10:08 +01:00
										 |  |  | 							_texture_region = Rect2(ofs2, size / scale); | 
					
						
							| 
									
										
										
										
											2017-02-09 22:46:35 +08:00
										 |  |  | 						} break; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2019-08-20 13:41:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-19 00:01:23 +01:00
										 |  |  | 				_position_rect = Rect2(ofs, size); | 
					
						
							| 
									
										
										
										
											2019-08-20 13:41:14 -03:00
										 |  |  | 				if (_tile) { | 
					
						
							| 
									
										
										
										
											2018-01-19 00:01:23 +01:00
										 |  |  | 					draw_texture_rect(texdraw, _position_rect, _tile); | 
					
						
							| 
									
										
										
										
											2019-08-20 13:41:14 -03:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2018-01-19 00:01:23 +01:00
										 |  |  | 					draw_texture_rect_region(texdraw, _position_rect, _texture_region); | 
					
						
							| 
									
										
										
										
											2019-08-20 13:41:14 -03:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2019-02-21 00:47:17 +01:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				_position_rect = Rect2(); | 
					
						
							| 
									
										
										
										
											2015-01-03 00:23:14 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-20 13:41:14 -03:00
										 |  |  | 			if (has_focus() && focused.is_valid()) { | 
					
						
							| 
									
										
										
										
											2019-03-15 01:22:51 -07:00
										 |  |  | 				draw_texture_rect(focused, _position_rect, false); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			}; | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TextureButton::_bind_methods() { | 
					
						
							| 
									
										
										
										
											2017-08-09 13:19:41 +02:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_normal_texture", "texture"), &TextureButton::set_normal_texture); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_pressed_texture", "texture"), &TextureButton::set_pressed_texture); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_hover_texture", "texture"), &TextureButton::set_hover_texture); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_disabled_texture", "texture"), &TextureButton::set_disabled_texture); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_focused_texture", "texture"), &TextureButton::set_focused_texture); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_click_mask", "mask"), &TextureButton::set_click_mask); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_expand", "p_expand"), &TextureButton::set_expand); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_stretch_mode", "p_mode"), &TextureButton::set_stretch_mode); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 13:19:41 +02:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("get_normal_texture"), &TextureButton::get_normal_texture); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_pressed_texture"), &TextureButton::get_pressed_texture); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_hover_texture"), &TextureButton::get_hover_texture); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_disabled_texture"), &TextureButton::get_disabled_texture); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_focused_texture"), &TextureButton::get_focused_texture); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_click_mask"), &TextureButton::get_click_mask); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("get_expand"), &TextureButton::get_expand); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_stretch_mode"), &TextureButton::get_stretch_mode); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ADD_GROUP("Textures", "texture_"); | 
					
						
							| 
									
										
										
										
											2018-11-08 11:30:02 -03:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_normal", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_normal_texture", "get_normal_texture"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_pressed", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_pressed_texture", "get_pressed_texture"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_hover", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_hover_texture", "get_hover_texture"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_disabled", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_disabled_texture", "get_disabled_texture"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_focused", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_focused_texture", "get_focused_texture"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_click_mask", PROPERTY_HINT_RESOURCE_TYPE, "BitMap"), "set_click_mask", "get_click_mask"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "expand", PROPERTY_HINT_RESOURCE_TYPE, "bool"), "set_expand", "get_expand"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::INT, "stretch_mode", PROPERTY_HINT_ENUM, "Scale,Tile,Keep,Keep Centered,Keep Aspect,Keep Aspect Centered,Keep Aspect Covered"), "set_stretch_mode", "get_stretch_mode"); | 
					
						
							| 
									
										
										
										
											2017-02-13 19:41:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 17:45:01 +02:00
										 |  |  | 	BIND_ENUM_CONSTANT(STRETCH_SCALE); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(STRETCH_TILE); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(STRETCH_KEEP); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(STRETCH_KEEP_CENTERED); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(STRETCH_KEEP_ASPECT); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(STRETCH_KEEP_ASPECT_CENTERED); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(STRETCH_KEEP_ASPECT_COVERED); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void TextureButton::set_normal_texture(const Ref<Texture> &p_normal) { | 
					
						
							|  |  |  | 	normal = p_normal; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	update(); | 
					
						
							|  |  |  | 	minimum_size_changed(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void TextureButton::set_pressed_texture(const Ref<Texture> &p_pressed) { | 
					
						
							|  |  |  | 	pressed = p_pressed; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	update(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void TextureButton::set_hover_texture(const Ref<Texture> &p_hover) { | 
					
						
							|  |  |  | 	hover = p_hover; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	update(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void TextureButton::set_disabled_texture(const Ref<Texture> &p_disabled) { | 
					
						
							|  |  |  | 	disabled = p_disabled; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	update(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void TextureButton::set_click_mask(const Ref<BitMap> &p_click_mask) { | 
					
						
							|  |  |  | 	click_mask = p_click_mask; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	update(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Ref<Texture> TextureButton::get_normal_texture() const { | 
					
						
							|  |  |  | 	return normal; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | Ref<Texture> TextureButton::get_pressed_texture() const { | 
					
						
							|  |  |  | 	return pressed; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | Ref<Texture> TextureButton::get_hover_texture() const { | 
					
						
							|  |  |  | 	return hover; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | Ref<Texture> TextureButton::get_disabled_texture() const { | 
					
						
							|  |  |  | 	return disabled; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | Ref<BitMap> TextureButton::get_click_mask() const { | 
					
						
							|  |  |  | 	return click_mask; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Ref<Texture> TextureButton::get_focused_texture() const { | 
					
						
							|  |  |  | 	return focused; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void TextureButton::set_focused_texture(const Ref<Texture> &p_focused) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	focused = p_focused; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-09 22:46:35 +08:00
										 |  |  | bool TextureButton::get_expand() const { | 
					
						
							|  |  |  | 	return expand; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-01-03 00:23:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-09 22:46:35 +08:00
										 |  |  | void TextureButton::set_expand(bool p_expand) { | 
					
						
							|  |  |  | 	expand = p_expand; | 
					
						
							| 
									
										
										
										
											2015-01-03 00:23:14 -03:00
										 |  |  | 	minimum_size_changed(); | 
					
						
							|  |  |  | 	update(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-11 15:10:05 -04:00
										 |  |  | void TextureButton::set_stretch_mode(StretchMode p_stretch_mode) { | 
					
						
							|  |  |  | 	stretch_mode = p_stretch_mode; | 
					
						
							| 
									
										
										
										
											2017-02-09 22:46:35 +08:00
										 |  |  | 	update(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-01-03 00:23:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-09 22:46:35 +08:00
										 |  |  | TextureButton::StretchMode TextureButton::get_stretch_mode() const { | 
					
						
							|  |  |  | 	return stretch_mode; | 
					
						
							| 
									
										
										
										
											2015-01-03 00:23:14 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | TextureButton::TextureButton() { | 
					
						
							| 
									
										
										
										
											2017-02-09 22:46:35 +08:00
										 |  |  | 	expand = false; | 
					
						
							| 
									
										
										
										
											2017-02-13 19:41:12 +08:00
										 |  |  | 	stretch_mode = STRETCH_SCALE; | 
					
						
							| 
									
										
										
										
											2018-01-19 00:01:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	_texture_region = Rect2(); | 
					
						
							|  |  |  | 	_position_rect = Rect2(); | 
					
						
							|  |  |  | 	_tile = false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } |