| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  dialogs.cpp                                                          */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							|  |  |  | /*                    http://www.godotengine.org                         */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2017-01-01 22:01:57 +01:00
										 |  |  | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							| 
									
										
										
										
											2017-04-08 00:11:42 +02:00
										 |  |  | /* Copyright (c) 2014-2017 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.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | #include "dialogs.h"
 | 
					
						
							|  |  |  | #include "line_edit.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "print_string.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #include "translation.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-06 20:11:56 +01:00
										 |  |  | #ifdef TOOLS_ENABLED
 | 
					
						
							|  |  |  | #include "editor/editor_node.h"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-12 15:11:44 +02:00
										 |  |  | // WindowDialog
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void WindowDialog::_post_popup() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 	drag_type = DRAG_NONE; // just in case
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 22:43:56 +01:00
										 |  |  | void WindowDialog::_fix_size() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-24 21:45:31 +01:00
										 |  |  | 	// Perhaps this should be called when the viewport resizes as well or windows go out of bounds...
 | 
					
						
							| 
									
										
										
										
											2017-03-02 22:43:56 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Ensure the whole window is visible.
 | 
					
						
							| 
									
										
										
										
											2017-03-29 11:29:38 -04:00
										 |  |  | 	Point2i pos = get_global_position(); | 
					
						
							| 
									
										
										
										
											2017-03-02 22:43:56 +01:00
										 |  |  | 	Size2i size = get_size(); | 
					
						
							|  |  |  | 	Size2i viewport_size = get_viewport_rect().size; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 22:43:56 +01:00
										 |  |  | 	// Windows require additional padding to keep the window chrome visible.
 | 
					
						
							| 
									
										
										
										
											2017-05-03 05:13:12 +09:00
										 |  |  | 	Ref<StyleBox> panel = get_stylebox("panel", "WindowDialog"); | 
					
						
							|  |  |  | 	float top = 0; | 
					
						
							|  |  |  | 	float left = 0; | 
					
						
							|  |  |  | 	float bottom = 0; | 
					
						
							|  |  |  | 	float right = 0; | 
					
						
							| 
									
										
										
										
											2017-05-02 02:18:13 +02:00
										 |  |  | 	// Check validity, because the theme could contain a different type of StyleBox
 | 
					
						
							| 
									
										
										
										
											2017-05-03 05:13:12 +09:00
										 |  |  | 	if (panel->get_class() == "StyleBoxTexture") { | 
					
						
							| 
									
										
										
										
											2017-08-24 22:58:51 +02:00
										 |  |  | 		Ref<StyleBoxTexture> panel_texture = Object::cast_to<StyleBoxTexture>(*panel); | 
					
						
							| 
									
										
										
										
											2017-05-03 05:13:12 +09:00
										 |  |  | 		top = panel_texture->get_expand_margin_size(MARGIN_TOP); | 
					
						
							|  |  |  | 		left = panel_texture->get_expand_margin_size(MARGIN_LEFT); | 
					
						
							|  |  |  | 		bottom = panel_texture->get_expand_margin_size(MARGIN_BOTTOM); | 
					
						
							|  |  |  | 		right = panel_texture->get_expand_margin_size(MARGIN_RIGHT); | 
					
						
							|  |  |  | 	} else if (panel->get_class() == "StyleBoxFlat") { | 
					
						
							| 
									
										
										
										
											2017-08-24 22:58:51 +02:00
										 |  |  | 		Ref<StyleBoxFlat> panel_flat = Object::cast_to<StyleBoxFlat>(*panel); | 
					
						
							| 
									
										
										
										
											2017-06-10 11:40:45 -07:00
										 |  |  | 		top = panel_flat->get_expand_margin_size(MARGIN_TOP); | 
					
						
							|  |  |  | 		left = panel_flat->get_expand_margin_size(MARGIN_LEFT); | 
					
						
							|  |  |  | 		bottom = panel_flat->get_expand_margin_size(MARGIN_BOTTOM); | 
					
						
							|  |  |  | 		right = panel_flat->get_expand_margin_size(MARGIN_RIGHT); | 
					
						
							| 
									
										
										
										
											2017-05-03 05:13:12 +09:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pos.x = MAX(left, MIN(pos.x, viewport_size.x - size.x - right)); | 
					
						
							|  |  |  | 	pos.y = MAX(top, MIN(pos.y, viewport_size.y - size.y - bottom)); | 
					
						
							|  |  |  | 	set_global_position(pos); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (resizable) { | 
					
						
							|  |  |  | 		size.x = MIN(size.x, viewport_size.x - left - right); | 
					
						
							|  |  |  | 		size.y = MIN(size.y, viewport_size.y - top - bottom); | 
					
						
							|  |  |  | 		set_size(size); | 
					
						
							| 
									
										
										
										
											2017-03-02 22:43:56 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | bool WindowDialog::has_point(const Point2 &p_point) const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 	Rect2 r(Point2(), get_size()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 	// Enlarge upwards for title bar.
 | 
					
						
							| 
									
										
										
										
											2017-04-12 15:11:44 +02:00
										 |  |  | 	int title_height = get_constant("title_height", "WindowDialog"); | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 	r.position.y -= title_height; | 
					
						
							| 
									
										
										
										
											2017-04-12 15:11:44 +02:00
										 |  |  | 	r.size.y += title_height; | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Inflate by the resizable border thickness.
 | 
					
						
							|  |  |  | 	if (resizable) { | 
					
						
							|  |  |  | 		int scaleborder_size = get_constant("scaleborder_size", "WindowDialog"); | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 		r.position.x -= scaleborder_size; | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 		r.size.width += scaleborder_size * 2; | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 		r.position.y -= scaleborder_size; | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 		r.size.height += scaleborder_size * 2; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 	return r.has_point(p_point); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | void WindowDialog::_gui_input(const Ref<InputEvent> &p_event) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	Ref<InputEventMouseButton> mb = p_event; | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (mb->is_pressed()) { | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 			// Begin a possible dragging operation.
 | 
					
						
							| 
									
										
										
										
											2017-06-03 10:54:24 +02:00
										 |  |  | 			drag_type = _drag_hit_test(Point2(mb->get_position().x, mb->get_position().y)); | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 			if (drag_type != DRAG_NONE) | 
					
						
							| 
									
										
										
										
											2017-03-29 11:29:38 -04:00
										 |  |  | 				drag_offset = get_global_mouse_position() - get_position(); | 
					
						
							|  |  |  | 			drag_offset_far = get_position() + get_size() - get_global_mouse_position(); | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 		} else if (drag_type != DRAG_NONE && !mb->is_pressed()) { | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 			// End a dragging operation.
 | 
					
						
							|  |  |  | 			drag_type = DRAG_NONE; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	Ref<InputEventMouseMotion> mm = p_event; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (mm.is_valid()) { | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (drag_type == DRAG_NONE) { | 
					
						
							|  |  |  | 			// Update the cursor while moving along the borders.
 | 
					
						
							|  |  |  | 			CursorShape cursor = CURSOR_ARROW; | 
					
						
							|  |  |  | 			if (resizable) { | 
					
						
							| 
									
										
										
										
											2017-06-03 10:54:24 +02:00
										 |  |  | 				int preview_drag_type = _drag_hit_test(Point2(mm->get_position().x, mm->get_position().y)); | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 				switch (preview_drag_type) { | 
					
						
							|  |  |  | 					case DRAG_RESIZE_TOP: | 
					
						
							|  |  |  | 					case DRAG_RESIZE_BOTTOM: | 
					
						
							|  |  |  | 						cursor = CURSOR_VSIZE; | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					case DRAG_RESIZE_LEFT: | 
					
						
							|  |  |  | 					case DRAG_RESIZE_RIGHT: | 
					
						
							|  |  |  | 						cursor = CURSOR_HSIZE; | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					case DRAG_RESIZE_TOP + DRAG_RESIZE_LEFT: | 
					
						
							|  |  |  | 					case DRAG_RESIZE_BOTTOM + DRAG_RESIZE_RIGHT: | 
					
						
							|  |  |  | 						cursor = CURSOR_FDIAGSIZE; | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					case DRAG_RESIZE_TOP + DRAG_RESIZE_RIGHT: | 
					
						
							|  |  |  | 					case DRAG_RESIZE_BOTTOM + DRAG_RESIZE_LEFT: | 
					
						
							|  |  |  | 						cursor = CURSOR_BDIAGSIZE; | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (get_cursor_shape() != cursor) | 
					
						
							|  |  |  | 				set_default_cursor_shape(cursor); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			// Update while in a dragging operation.
 | 
					
						
							| 
									
										
										
										
											2017-03-29 11:29:38 -04:00
										 |  |  | 			Point2 global_pos = get_global_mouse_position(); | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 			global_pos.y = MAX(global_pos.y, 0); // Ensure title bar stays visible.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			Rect2 rect = get_rect(); | 
					
						
							|  |  |  | 			Size2 min_size = get_minimum_size(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (drag_type == DRAG_MOVE) { | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 				rect.position = global_pos - drag_offset; | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				if (drag_type & DRAG_RESIZE_TOP) { | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 					int bottom = rect.position.y + rect.size.height; | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 					int max_y = bottom - min_size.height; | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 					rect.position.y = MIN(global_pos.y - drag_offset.y, max_y); | 
					
						
							|  |  |  | 					rect.size.height = bottom - rect.position.y; | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 				} else if (drag_type & DRAG_RESIZE_BOTTOM) { | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 					rect.size.height = global_pos.y - rect.position.y + drag_offset_far.y; | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				if (drag_type & DRAG_RESIZE_LEFT) { | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 					int right = rect.position.x + rect.size.width; | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 					int max_x = right - min_size.width; | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 					rect.position.x = MIN(global_pos.x - drag_offset.x, max_x); | 
					
						
							|  |  |  | 					rect.size.width = right - rect.position.x; | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 				} else if (drag_type & DRAG_RESIZE_RIGHT) { | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 					rect.size.width = global_pos.x - rect.position.x + drag_offset_far.x; | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			set_size(rect.size); | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 			set_position(rect.position); | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void WindowDialog::_notification(int p_what) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 	switch (p_what) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		case NOTIFICATION_DRAW: { | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 			RID canvas = get_canvas_item(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-12 15:11:44 +02:00
										 |  |  | 			// Draw the background.
 | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 			Ref<StyleBox> panel = get_stylebox("panel", "WindowDialog"); | 
					
						
							| 
									
										
										
										
											2017-04-12 15:11:44 +02:00
										 |  |  | 			Size2 size = get_size(); | 
					
						
							|  |  |  | 			panel->draw(canvas, Rect2(0, 0, size.x, size.y)); | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-12 15:11:44 +02:00
										 |  |  | 			// Draw the title bar text.
 | 
					
						
							|  |  |  | 			Ref<Font> title_font = get_font("title_font", "WindowDialog"); | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 			Color title_color = get_color("title_color", "WindowDialog"); | 
					
						
							| 
									
										
										
										
											2017-04-12 15:11:44 +02:00
										 |  |  | 			int title_height = get_constant("title_height", "WindowDialog"); | 
					
						
							|  |  |  | 			int font_height = title_font->get_height() - title_font->get_descent() * 2; | 
					
						
							|  |  |  | 			int x = (size.x - title_font->get_string_size(title).x) / 2; | 
					
						
							|  |  |  | 			int y = (-title_height + font_height) / 2; | 
					
						
							|  |  |  | 			title_font->draw(canvas, Point2(x, y), title, title_color, size.x - panel->get_minimum_size().x); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		case NOTIFICATION_THEME_CHANGED: | 
					
						
							| 
									
										
										
										
											2014-11-05 21:20:42 -03:00
										 |  |  | 		case NOTIFICATION_ENTER_TREE: { | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 			close_button->set_normal_texture(get_icon("close", "WindowDialog")); | 
					
						
							|  |  |  | 			close_button->set_pressed_texture(get_icon("close", "WindowDialog")); | 
					
						
							| 
									
										
										
										
											2017-05-03 05:13:12 +09:00
										 |  |  | 			close_button->set_hover_texture(get_icon("close_highlight", "WindowDialog")); | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 			close_button->set_anchor(MARGIN_LEFT, ANCHOR_END); | 
					
						
							| 
									
										
										
										
											2017-07-06 09:16:27 +02:00
										 |  |  | 			close_button->set_begin(Point2(-get_constant("close_h_ofs", "WindowDialog"), -get_constant("close_v_ofs", "WindowDialog"))); | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 		case NOTIFICATION_MOUSE_EXIT: { | 
					
						
							|  |  |  | 			// Reset the mouse cursor when leaving the resizable window border.
 | 
					
						
							|  |  |  | 			if (resizable && !drag_type) { | 
					
						
							|  |  |  | 				if (get_default_cursor_shape() != CURSOR_ARROW) | 
					
						
							|  |  |  | 					set_default_cursor_shape(CURSOR_ARROW); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2017-03-06 20:11:56 +01:00
										 |  |  | #ifdef TOOLS_ENABLED
 | 
					
						
							|  |  |  | 		case NOTIFICATION_POST_POPUP: { | 
					
						
							| 
									
										
										
										
											2017-08-19 01:02:56 +02:00
										 |  |  | 			if (get_tree() && Engine::get_singleton()->is_editor_hint() && EditorNode::get_singleton()) | 
					
						
							| 
									
										
										
										
											2017-03-06 20:11:56 +01:00
										 |  |  | 				EditorNode::get_singleton()->dim_editor(true); | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case NOTIFICATION_POPUP_HIDE: { | 
					
						
							| 
									
										
										
										
											2017-08-19 01:02:56 +02:00
										 |  |  | 			if (get_tree() && Engine::get_singleton()->is_editor_hint() && EditorNode::get_singleton()) | 
					
						
							| 
									
										
										
										
											2017-03-06 20:11:56 +01:00
										 |  |  | 				EditorNode::get_singleton()->dim_editor(false); | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void WindowDialog::_closed() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_close_pressed(); | 
					
						
							|  |  |  | 	hide(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | int WindowDialog::_drag_hit_test(const Point2 &pos) const { | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 	int drag_type = DRAG_NONE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (resizable) { | 
					
						
							| 
									
										
										
										
											2017-04-12 15:11:44 +02:00
										 |  |  | 		int title_height = get_constant("title_height", "WindowDialog"); | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 		int scaleborder_size = get_constant("scaleborder_size", "WindowDialog"); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 		Rect2 rect = get_rect(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-12 15:11:44 +02:00
										 |  |  | 		if (pos.y < (-title_height + scaleborder_size)) | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 			drag_type = DRAG_RESIZE_TOP; | 
					
						
							|  |  |  | 		else if (pos.y >= (rect.size.height - scaleborder_size)) | 
					
						
							|  |  |  | 			drag_type = DRAG_RESIZE_BOTTOM; | 
					
						
							|  |  |  | 		if (pos.x < scaleborder_size) | 
					
						
							|  |  |  | 			drag_type |= DRAG_RESIZE_LEFT; | 
					
						
							|  |  |  | 		else if (pos.x >= (rect.size.width - scaleborder_size)) | 
					
						
							|  |  |  | 			drag_type |= DRAG_RESIZE_RIGHT; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (drag_type == DRAG_NONE && pos.y < 0) | 
					
						
							|  |  |  | 		drag_type = DRAG_MOVE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return drag_type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void WindowDialog::set_title(const String &p_title) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-18 22:29:15 +02:00
										 |  |  | 	title = tr(p_title); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	update(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | String WindowDialog::get_title() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return title; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void WindowDialog::set_resizable(bool p_resizable) { | 
					
						
							|  |  |  | 	resizable = p_resizable; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | bool WindowDialog::get_resizable() const { | 
					
						
							|  |  |  | 	return resizable; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-30 00:28:29 -03:00
										 |  |  | Size2 WindowDialog::get_minimum_size() const { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Ref<Font> font = get_font("title_font", "WindowDialog"); | 
					
						
							|  |  |  | 	int msx = close_button->get_combined_minimum_size().x; | 
					
						
							|  |  |  | 	msx += font->get_string_size(title).x; | 
					
						
							| 
									
										
										
										
											2016-05-30 00:28:29 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	return Size2(msx, 1); | 
					
						
							| 
									
										
										
										
											2016-05-30 00:28:29 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | TextureButton *WindowDialog::get_close_button() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return close_button; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void WindowDialog::_bind_methods() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_gui_input"), &WindowDialog::_gui_input); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_title", "title"), &WindowDialog::set_title); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_title"), &WindowDialog::get_title); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_resizable", "resizable"), &WindowDialog::set_resizable); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_resizable"), &WindowDialog::get_resizable); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_closed"), &WindowDialog::_closed); | 
					
						
							| 
									
										
										
										
											2017-08-09 13:19:41 +02:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("get_close_button"), &WindowDialog::get_close_button); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::STRING, "window_title", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT_INTL), "set_title", "get_title"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "resizable", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT_INTL), "set_resizable", "get_resizable"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | WindowDialog::WindowDialog() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//title="Hello!";
 | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 	drag_type = DRAG_NONE; | 
					
						
							|  |  |  | 	resizable = false; | 
					
						
							|  |  |  | 	close_button = memnew(TextureButton); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	add_child(close_button); | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | 	close_button->connect("pressed", this, "_closed"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | WindowDialog::~WindowDialog() { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-12 15:11:44 +02:00
										 |  |  | // PopupDialog
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void PopupDialog::_notification(int p_what) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_what == NOTIFICATION_DRAW) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		RID ci = get_canvas_item(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		get_stylebox("panel", "PopupMenu")->draw(ci, Rect2(Point2(), get_size())); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PopupDialog::PopupDialog() { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PopupDialog::~PopupDialog() { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-24 18:21:54 +01:00
										 |  |  | // AcceptDialog
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | void AcceptDialog::_post_popup() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	WindowDialog::_post_popup(); | 
					
						
							|  |  |  | 	get_ok()->grab_focus(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AcceptDialog::_notification(int p_what) { | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_what == NOTIFICATION_MODAL_CLOSE) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		cancel_pressed(); | 
					
						
							| 
									
										
										
										
											2017-07-13 15:57:24 +07:00
										 |  |  | 	} else if (p_what == NOTIFICATION_READY) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		_update_child_rects(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	} else if (p_what == NOTIFICATION_RESIZED) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 01:49:55 -03:00
										 |  |  | 		_update_child_rects(); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void AcceptDialog::_builtin_text_entered(const String &p_text) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	_ok_pressed(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AcceptDialog::_ok_pressed() { | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	if (hide_on_ok) | 
					
						
							|  |  |  | 		hide(); | 
					
						
							|  |  |  | 	ok_pressed(); | 
					
						
							|  |  |  | 	emit_signal("confirmed"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | void AcceptDialog::_close_pressed() { | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	cancel_pressed(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String AcceptDialog::get_text() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return label->get_text(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | void AcceptDialog::set_text(String p_text) { | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	label->set_text(p_text); | 
					
						
							| 
									
										
										
										
											2016-10-31 03:42:30 +09:00
										 |  |  | 	minimum_size_changed(); | 
					
						
							| 
									
										
										
										
											2017-01-10 01:49:55 -03:00
										 |  |  | 	_update_child_rects(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AcceptDialog::set_hide_on_ok(bool p_hide) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	hide_on_ok = p_hide; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool AcceptDialog::get_hide_on_ok() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return hide_on_ok; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AcceptDialog::register_text_enter(Node *p_line_edit) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_NULL(p_line_edit); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	p_line_edit->connect("text_entered", this, "_builtin_text_entered"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 01:49:55 -03:00
										 |  |  | void AcceptDialog::_update_child_rects() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Size2 label_size = label->get_minimum_size(); | 
					
						
							| 
									
										
										
										
											2016-10-31 03:42:30 +09:00
										 |  |  | 	if (label->get_text().empty()) { | 
					
						
							|  |  |  | 		label_size.height = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int margin = get_constant("margin", "Dialogs"); | 
					
						
							| 
									
										
										
										
											2016-10-31 03:40:52 +09:00
										 |  |  | 	Size2 size = get_size(); | 
					
						
							| 
									
										
										
										
											2016-05-30 00:28:29 -03:00
										 |  |  | 	Size2 hminsize = hbc->get_combined_minimum_size(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Vector2 cpos(margin, margin + label_size.height); | 
					
						
							|  |  |  | 	Vector2 csize(size.x - margin * 2, size.y - margin * 3 - hminsize.y - label_size.height); | 
					
						
							| 
									
										
										
										
											2016-05-30 00:28:29 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < get_child_count(); i++) { | 
					
						
							| 
									
										
										
										
											2017-08-24 22:58:51 +02:00
										 |  |  | 		Control *c = Object::cast_to<Control>(get_child(i)); | 
					
						
							| 
									
										
										
										
											2017-01-10 01:49:55 -03:00
										 |  |  | 		if (!c) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (c == hbc || c == label || c == get_close_button() || c->is_set_as_toplevel()) | 
					
						
							| 
									
										
										
										
											2017-01-10 01:49:55 -03:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-29 11:29:38 -04:00
										 |  |  | 		c->set_position(cpos); | 
					
						
							| 
									
										
										
										
											2017-01-10 01:49:55 -03:00
										 |  |  | 		c->set_size(csize); | 
					
						
							| 
									
										
										
										
											2016-05-30 00:28:29 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	cpos.y += csize.y + margin; | 
					
						
							|  |  |  | 	csize.y = hminsize.y; | 
					
						
							| 
									
										
										
										
											2016-05-30 00:28:29 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-29 11:29:38 -04:00
										 |  |  | 	hbc->set_position(cpos); | 
					
						
							| 
									
										
										
										
											2016-10-31 03:40:52 +09:00
										 |  |  | 	hbc->set_size(csize); | 
					
						
							| 
									
										
										
										
											2016-05-30 00:28:29 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Size2 AcceptDialog::get_minimum_size() const { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int margin = get_constant("margin", "Dialogs"); | 
					
						
							| 
									
										
										
										
											2016-05-30 00:28:29 -03:00
										 |  |  | 	Size2 minsize = label->get_combined_minimum_size(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < get_child_count(); i++) { | 
					
						
							| 
									
										
										
										
											2017-08-24 22:58:51 +02:00
										 |  |  | 		Control *c = Object::cast_to<Control>(get_child(i)); | 
					
						
							| 
									
										
										
										
											2017-01-10 01:49:55 -03:00
										 |  |  | 		if (!c) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (c == hbc || c == label || c == const_cast<AcceptDialog *>(this)->get_close_button() || c->is_set_as_toplevel()) | 
					
						
							| 
									
										
										
										
											2017-01-10 01:49:55 -03:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Size2 cminsize = c->get_combined_minimum_size(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		minsize.x = MAX(cminsize.x, minsize.x); | 
					
						
							|  |  |  | 		minsize.y = MAX(cminsize.y, minsize.y); | 
					
						
							| 
									
										
										
										
											2016-05-30 00:28:29 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Size2 hminsize = hbc->get_combined_minimum_size(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	minsize.x = MAX(hminsize.x, minsize.x); | 
					
						
							|  |  |  | 	minsize.y += hminsize.y; | 
					
						
							|  |  |  | 	minsize.x += margin * 2; | 
					
						
							|  |  |  | 	minsize.y += margin * 3; //one as separation between hbc and child
 | 
					
						
							| 
									
										
										
										
											2016-05-30 00:28:29 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Size2 wmsize = WindowDialog::get_minimum_size(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	minsize.x = MAX(wmsize.x, minsize.x); | 
					
						
							| 
									
										
										
										
											2016-05-30 00:28:29 -03:00
										 |  |  | 	return minsize; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void AcceptDialog::_custom_action(const String &p_action) { | 
					
						
							| 
									
										
										
										
											2016-05-30 00:28:29 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	emit_signal("custom_action", p_action); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	custom_action(p_action); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | Button *AcceptDialog::add_button(const String &p_text, bool p_right, const String &p_action) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Button *button = memnew(Button); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	button->set_text(p_text); | 
					
						
							|  |  |  | 	if (p_right) { | 
					
						
							|  |  |  | 		hbc->add_child(button); | 
					
						
							|  |  |  | 		hbc->add_spacer(); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		hbc->add_child(button); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		hbc->move_child(button, 0); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		hbc->add_spacer(true); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_action != "") { | 
					
						
							|  |  |  | 		button->connect("pressed", this, "_custom_action", varray(p_action)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return button; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | Button *AcceptDialog::add_cancel(const String &p_cancel) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	String c = p_cancel; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_cancel == "") | 
					
						
							|  |  |  | 		c = RTR("Cancel"); | 
					
						
							|  |  |  | 	Button *b = swap_ok_cancel ? add_button(c, true) : add_button(c); | 
					
						
							|  |  |  | 	b->connect("pressed", this, "_closed"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	return b; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AcceptDialog::_bind_methods() { | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_ok"), &AcceptDialog::_ok_pressed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_ok"), &AcceptDialog::get_ok); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_label"), &AcceptDialog::get_label); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_hide_on_ok", "enabled"), &AcceptDialog::set_hide_on_ok); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_hide_on_ok"), &AcceptDialog::get_hide_on_ok); | 
					
						
							| 
									
										
										
										
											2017-08-09 13:19:41 +02:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("add_button", "text", "right", "action"), &AcceptDialog::add_button, DEFVAL(false), DEFVAL("")); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("add_cancel", "name"), &AcceptDialog::add_cancel); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_builtin_text_entered"), &AcceptDialog::_builtin_text_entered); | 
					
						
							| 
									
										
										
										
											2017-08-09 13:19:41 +02:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("register_text_enter", "line_edit"), &AcceptDialog::register_text_enter); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_custom_action"), &AcceptDialog::_custom_action); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_text", "text"), &AcceptDialog::set_text); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_text"), &AcceptDialog::get_text); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ADD_SIGNAL(MethodInfo("confirmed")); | 
					
						
							|  |  |  | 	ADD_SIGNAL(MethodInfo("custom_action", PropertyInfo(Variant::STRING, "action"))); | 
					
						
							| 
									
										
										
										
											2015-11-20 18:25:01 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ADD_GROUP("Dialog", "dialog"); | 
					
						
							|  |  |  | 	ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "dialog_text", PROPERTY_HINT_MULTILINE_TEXT, "", PROPERTY_USAGE_DEFAULT_INTL), "set_text", "get_text"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "dialog_hide_on_ok"), "set_hide_on_ok", "get_hide_on_ok"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | bool AcceptDialog::swap_ok_cancel = false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void AcceptDialog::set_swap_ok_cancel(bool p_swap) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	swap_ok_cancel = p_swap; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AcceptDialog::AcceptDialog() { | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int margin = get_constant("margin", "Dialogs"); | 
					
						
							|  |  |  | 	int button_margin = get_constant("button_margin", "Dialogs"); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	label = memnew(Label); | 
					
						
							|  |  |  | 	label->set_anchor(MARGIN_RIGHT, ANCHOR_END); | 
					
						
							|  |  |  | 	label->set_anchor(MARGIN_BOTTOM, ANCHOR_END); | 
					
						
							|  |  |  | 	label->set_begin(Point2(margin, margin)); | 
					
						
							| 
									
										
										
										
											2017-07-06 09:16:27 +02:00
										 |  |  | 	label->set_end(Point2(-margin, -button_margin - 10)); | 
					
						
							| 
									
										
										
										
											2015-02-14 12:09:52 -03:00
										 |  |  | 	//label->set_autowrap(true);
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	add_child(label); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	hbc = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	add_child(hbc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	hbc->add_spacer(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ok = memnew(Button); | 
					
						
							| 
									
										
										
										
											2016-05-30 17:01:56 +08:00
										 |  |  | 	ok->set_text(RTR("OK")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hbc->add_child(ok); | 
					
						
							|  |  |  | 	hbc->add_spacer(); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ok->connect("pressed", this, "_ok"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	set_as_toplevel(true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	hide_on_ok = true; | 
					
						
							| 
									
										
										
										
											2016-05-30 17:01:56 +08:00
										 |  |  | 	set_title(RTR("Alert!")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | AcceptDialog::~AcceptDialog() { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-12 15:11:44 +02:00
										 |  |  | // ConfirmationDialog
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void ConfirmationDialog::_bind_methods() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 13:19:41 +02:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("get_cancel"), &ConfirmationDialog::get_cancel); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Button *ConfirmationDialog::get_cancel() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return cancel; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ConfirmationDialog::ConfirmationDialog() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-30 17:01:56 +08:00
										 |  |  | 	set_title(RTR("Please Confirm...")); | 
					
						
							| 
									
										
										
										
											2017-07-18 14:35:37 -05:00
										 |  |  | #ifdef TOOLS_ENABLED
 | 
					
						
							|  |  |  | 	set_custom_minimum_size(Size2(200, 70) * EDSCALE); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	cancel = add_cancel(); | 
					
						
							|  |  |  | } |