1 /*************************************************************************/
2 /* dialogs.cpp */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /*************************************************************************/
30
31 #include "dialogs.h"
32 #include "core/print_string.h"
33 #include "core/translation.h"
34 #include "line_edit.h"
35
36 #ifdef TOOLS_ENABLED
37 #include "editor/editor_node.h"
38 #include "editor/editor_scale.h"
39 #include "scene/main/viewport.h" // Only used to check for more modals when dimming the editor.
40 #endif
41
42 // WindowDialog
43
_post_popup()44 void WindowDialog::_post_popup() {
45
46 drag_type = DRAG_NONE; // just in case
47 }
48
_fix_size()49 void WindowDialog::_fix_size() {
50
51 // Perhaps this should be called when the viewport resizes as well or windows go out of bounds...
52
53 // Ensure the whole window is visible.
54 Point2i pos = get_global_position();
55 Size2i size = get_size();
56 Size2i viewport_size = get_viewport_rect().size;
57
58 // Windows require additional padding to keep the window chrome visible.
59 Ref<StyleBox> panel = get_stylebox("panel", "WindowDialog");
60 float top = 0;
61 float left = 0;
62 float bottom = 0;
63 float right = 0;
64 // Check validity, because the theme could contain a different type of StyleBox.
65 if (panel->get_class() == "StyleBoxTexture") {
66 Ref<StyleBoxTexture> panel_texture = Object::cast_to<StyleBoxTexture>(*panel);
67 top = panel_texture->get_expand_margin_size(MARGIN_TOP);
68 left = panel_texture->get_expand_margin_size(MARGIN_LEFT);
69 bottom = panel_texture->get_expand_margin_size(MARGIN_BOTTOM);
70 right = panel_texture->get_expand_margin_size(MARGIN_RIGHT);
71 } else if (panel->get_class() == "StyleBoxFlat") {
72 Ref<StyleBoxFlat> panel_flat = Object::cast_to<StyleBoxFlat>(*panel);
73 top = panel_flat->get_expand_margin_size(MARGIN_TOP);
74 left = panel_flat->get_expand_margin_size(MARGIN_LEFT);
75 bottom = panel_flat->get_expand_margin_size(MARGIN_BOTTOM);
76 right = panel_flat->get_expand_margin_size(MARGIN_RIGHT);
77 }
78
79 pos.x = MAX(left, MIN(pos.x, viewport_size.x - size.x - right));
80 pos.y = MAX(top, MIN(pos.y, viewport_size.y - size.y - bottom));
81 set_global_position(pos);
82
83 if (resizable) {
84 size.x = MIN(size.x, viewport_size.x - left - right);
85 size.y = MIN(size.y, viewport_size.y - top - bottom);
86 set_size(size);
87 }
88 }
89
has_point(const Point2 & p_point) const90 bool WindowDialog::has_point(const Point2 &p_point) const {
91
92 Rect2 r(Point2(), get_size());
93
94 // Enlarge upwards for title bar.
95 int title_height = get_constant("title_height", "WindowDialog");
96 r.position.y -= title_height;
97 r.size.y += title_height;
98
99 // Inflate by the resizable border thickness.
100 if (resizable) {
101 int scaleborder_size = get_constant("scaleborder_size", "WindowDialog");
102 r.position.x -= scaleborder_size;
103 r.size.width += scaleborder_size * 2;
104 r.position.y -= scaleborder_size;
105 r.size.height += scaleborder_size * 2;
106 }
107
108 return r.has_point(p_point);
109 }
110
_gui_input(const Ref<InputEvent> & p_event)111 void WindowDialog::_gui_input(const Ref<InputEvent> &p_event) {
112
113 Ref<InputEventMouseButton> mb = p_event;
114
115 if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT) {
116
117 if (mb->is_pressed()) {
118 // Begin a possible dragging operation.
119 drag_type = _drag_hit_test(Point2(mb->get_position().x, mb->get_position().y));
120 if (drag_type != DRAG_NONE)
121 drag_offset = get_global_mouse_position() - get_position();
122 drag_offset_far = get_position() + get_size() - get_global_mouse_position();
123 } else if (drag_type != DRAG_NONE && !mb->is_pressed()) {
124 // End a dragging operation.
125 drag_type = DRAG_NONE;
126 }
127 }
128
129 Ref<InputEventMouseMotion> mm = p_event;
130
131 if (mm.is_valid()) {
132
133 if (drag_type == DRAG_NONE) {
134 // Update the cursor while moving along the borders.
135 CursorShape cursor = CURSOR_ARROW;
136 if (resizable) {
137 int preview_drag_type = _drag_hit_test(Point2(mm->get_position().x, mm->get_position().y));
138 switch (preview_drag_type) {
139 case DRAG_RESIZE_TOP:
140 case DRAG_RESIZE_BOTTOM:
141 cursor = CURSOR_VSIZE;
142 break;
143 case DRAG_RESIZE_LEFT:
144 case DRAG_RESIZE_RIGHT:
145 cursor = CURSOR_HSIZE;
146 break;
147 case DRAG_RESIZE_TOP + DRAG_RESIZE_LEFT:
148 case DRAG_RESIZE_BOTTOM + DRAG_RESIZE_RIGHT:
149 cursor = CURSOR_FDIAGSIZE;
150 break;
151 case DRAG_RESIZE_TOP + DRAG_RESIZE_RIGHT:
152 case DRAG_RESIZE_BOTTOM + DRAG_RESIZE_LEFT:
153 cursor = CURSOR_BDIAGSIZE;
154 break;
155 }
156 }
157 if (get_cursor_shape() != cursor)
158 set_default_cursor_shape(cursor);
159 } else {
160 // Update while in a dragging operation.
161 Point2 global_pos = get_global_mouse_position();
162 global_pos.y = MAX(global_pos.y, 0); // Ensure title bar stays visible.
163
164 Rect2 rect = get_rect();
165 Size2 min_size = get_combined_minimum_size();
166
167 if (drag_type == DRAG_MOVE) {
168 rect.position = global_pos - drag_offset;
169 } else {
170 if (drag_type & DRAG_RESIZE_TOP) {
171 int bottom = rect.position.y + rect.size.height;
172 int max_y = bottom - min_size.height;
173 rect.position.y = MIN(global_pos.y - drag_offset.y, max_y);
174 rect.size.height = bottom - rect.position.y;
175 } else if (drag_type & DRAG_RESIZE_BOTTOM) {
176 rect.size.height = global_pos.y - rect.position.y + drag_offset_far.y;
177 }
178 if (drag_type & DRAG_RESIZE_LEFT) {
179 int right = rect.position.x + rect.size.width;
180 int max_x = right - min_size.width;
181 rect.position.x = MIN(global_pos.x - drag_offset.x, max_x);
182 rect.size.width = right - rect.position.x;
183 } else if (drag_type & DRAG_RESIZE_RIGHT) {
184 rect.size.width = global_pos.x - rect.position.x + drag_offset_far.x;
185 }
186 }
187
188 set_size(rect.size);
189 set_position(rect.position);
190 }
191 }
192 }
193
_notification(int p_what)194 void WindowDialog::_notification(int p_what) {
195
196 switch (p_what) {
197 case NOTIFICATION_DRAW: {
198 RID canvas = get_canvas_item();
199
200 // Draw the background.
201 Ref<StyleBox> panel = get_stylebox("panel");
202 Size2 size = get_size();
203 panel->draw(canvas, Rect2(0, 0, size.x, size.y));
204
205 // Draw the title bar text.
206 Ref<Font> title_font = get_font("title_font", "WindowDialog");
207 Color title_color = get_color("title_color", "WindowDialog");
208 int title_height = get_constant("title_height", "WindowDialog");
209 int font_height = title_font->get_height() - title_font->get_descent() * 2;
210 int x = (size.x - title_font->get_string_size(xl_title).x) / 2;
211 int y = (-title_height + font_height) / 2;
212 title_font->draw(canvas, Point2(x, y), xl_title, title_color, size.x - panel->get_minimum_size().x);
213 } break;
214
215 case NOTIFICATION_THEME_CHANGED:
216 case NOTIFICATION_ENTER_TREE: {
217 close_button->set_normal_texture(get_icon("close", "WindowDialog"));
218 close_button->set_pressed_texture(get_icon("close", "WindowDialog"));
219 close_button->set_hover_texture(get_icon("close_highlight", "WindowDialog"));
220 close_button->set_anchor(MARGIN_LEFT, ANCHOR_END);
221 close_button->set_begin(Point2(-get_constant("close_h_ofs", "WindowDialog"), -get_constant("close_v_ofs", "WindowDialog")));
222 } break;
223
224 case NOTIFICATION_TRANSLATION_CHANGED: {
225 String new_title = tr(title);
226 if (new_title != xl_title) {
227 xl_title = new_title;
228 minimum_size_changed();
229 update();
230 }
231 } break;
232
233 case NOTIFICATION_MOUSE_EXIT: {
234 // Reset the mouse cursor when leaving the resizable window border.
235 if (resizable && !drag_type) {
236 if (get_default_cursor_shape() != CURSOR_ARROW)
237 set_default_cursor_shape(CURSOR_ARROW);
238 }
239 } break;
240
241 #ifdef TOOLS_ENABLED
242 case NOTIFICATION_POST_POPUP: {
243 if (get_tree() && Engine::get_singleton()->is_editor_hint() && EditorNode::get_singleton()) {
244 was_editor_dimmed = EditorNode::get_singleton()->is_editor_dimmed();
245 EditorNode::get_singleton()->dim_editor(true);
246 }
247 } break;
248
249 case NOTIFICATION_POPUP_HIDE: {
250 if (get_tree() && Engine::get_singleton()->is_editor_hint() && EditorNode::get_singleton() && !was_editor_dimmed) {
251 EditorNode::get_singleton()->dim_editor(false);
252 set_pass_on_modal_close_click(false);
253 }
254 } break;
255 #endif
256 }
257 }
258
_closed()259 void WindowDialog::_closed() {
260
261 _close_pressed();
262 hide();
263 }
264
_drag_hit_test(const Point2 & pos) const265 int WindowDialog::_drag_hit_test(const Point2 &pos) const {
266 int drag_type = DRAG_NONE;
267
268 if (resizable) {
269 int title_height = get_constant("title_height", "WindowDialog");
270 int scaleborder_size = get_constant("scaleborder_size", "WindowDialog");
271
272 Rect2 rect = get_rect();
273
274 if (pos.y < (-title_height + scaleborder_size))
275 drag_type = DRAG_RESIZE_TOP;
276 else if (pos.y >= (rect.size.height - scaleborder_size))
277 drag_type = DRAG_RESIZE_BOTTOM;
278 if (pos.x < scaleborder_size)
279 drag_type |= DRAG_RESIZE_LEFT;
280 else if (pos.x >= (rect.size.width - scaleborder_size))
281 drag_type |= DRAG_RESIZE_RIGHT;
282 }
283
284 if (drag_type == DRAG_NONE && pos.y < 0)
285 drag_type = DRAG_MOVE;
286
287 return drag_type;
288 }
289
set_title(const String & p_title)290 void WindowDialog::set_title(const String &p_title) {
291
292 if (title != p_title) {
293 title = p_title;
294 xl_title = tr(p_title);
295 minimum_size_changed();
296 update();
297 }
298 }
get_title() const299 String WindowDialog::get_title() const {
300
301 return title;
302 }
303
set_resizable(bool p_resizable)304 void WindowDialog::set_resizable(bool p_resizable) {
305 resizable = p_resizable;
306 }
get_resizable() const307 bool WindowDialog::get_resizable() const {
308 return resizable;
309 }
310
get_minimum_size() const311 Size2 WindowDialog::get_minimum_size() const {
312
313 Ref<Font> font = get_font("title_font", "WindowDialog");
314
315 const int button_width = close_button->get_combined_minimum_size().x;
316 const int title_width = font->get_string_size(xl_title).x;
317 const int padding = button_width / 2;
318 const int button_area = button_width + padding;
319
320 // As the title gets centered, title_width + close_button_width is not enough.
321 // We want a width w, such that w / 2 - title_width / 2 >= button_area, i.e.
322 // w >= 2 * button_area + title_width
323
324 return Size2(2 * button_area + title_width, 1);
325 }
326
get_close_button()327 TextureButton *WindowDialog::get_close_button() {
328
329 return close_button;
330 }
331
_bind_methods()332 void WindowDialog::_bind_methods() {
333
334 ClassDB::bind_method(D_METHOD("_gui_input"), &WindowDialog::_gui_input);
335 ClassDB::bind_method(D_METHOD("set_title", "title"), &WindowDialog::set_title);
336 ClassDB::bind_method(D_METHOD("get_title"), &WindowDialog::get_title);
337 ClassDB::bind_method(D_METHOD("set_resizable", "resizable"), &WindowDialog::set_resizable);
338 ClassDB::bind_method(D_METHOD("get_resizable"), &WindowDialog::get_resizable);
339 ClassDB::bind_method(D_METHOD("_closed"), &WindowDialog::_closed);
340 ClassDB::bind_method(D_METHOD("get_close_button"), &WindowDialog::get_close_button);
341
342 ADD_PROPERTY(PropertyInfo(Variant::STRING, "window_title", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT_INTL), "set_title", "get_title");
343 ADD_PROPERTY(PropertyInfo(Variant::BOOL, "resizable", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT_INTL), "set_resizable", "get_resizable");
344 }
345
WindowDialog()346 WindowDialog::WindowDialog() {
347
348 drag_type = DRAG_NONE;
349 resizable = false;
350 close_button = memnew(TextureButton);
351 add_child(close_button);
352 close_button->connect("pressed", this, "_closed");
353
354 #ifdef TOOLS_ENABLED
355 was_editor_dimmed = false;
356 #endif
357 }
358
~WindowDialog()359 WindowDialog::~WindowDialog() {
360 }
361
362 // PopupDialog
363
_notification(int p_what)364 void PopupDialog::_notification(int p_what) {
365
366 if (p_what == NOTIFICATION_DRAW) {
367 RID ci = get_canvas_item();
368 get_stylebox("panel")->draw(ci, Rect2(Point2(), get_size()));
369 }
370 }
371
PopupDialog()372 PopupDialog::PopupDialog() {
373 }
374
~PopupDialog()375 PopupDialog::~PopupDialog() {
376 }
377
378 // AcceptDialog
379
_post_popup()380 void AcceptDialog::_post_popup() {
381
382 WindowDialog::_post_popup();
383 get_ok()->grab_focus();
384 }
385
_notification(int p_what)386 void AcceptDialog::_notification(int p_what) {
387
388 switch (p_what) {
389 case NOTIFICATION_MODAL_CLOSE: {
390 cancel_pressed();
391 } break;
392
393 case NOTIFICATION_READY:
394 case NOTIFICATION_RESIZED: {
395 _update_child_rects();
396 } break;
397 }
398 }
399
_builtin_text_entered(const String & p_text)400 void AcceptDialog::_builtin_text_entered(const String &p_text) {
401
402 _ok_pressed();
403 }
404
_ok_pressed()405 void AcceptDialog::_ok_pressed() {
406
407 if (hide_on_ok)
408 hide();
409 ok_pressed();
410 emit_signal("confirmed");
411 }
_close_pressed()412 void AcceptDialog::_close_pressed() {
413
414 cancel_pressed();
415 }
416
get_text() const417 String AcceptDialog::get_text() const {
418
419 return label->get_text();
420 }
set_text(String p_text)421 void AcceptDialog::set_text(String p_text) {
422
423 label->set_text(p_text);
424 minimum_size_changed();
425 _update_child_rects();
426 }
427
set_hide_on_ok(bool p_hide)428 void AcceptDialog::set_hide_on_ok(bool p_hide) {
429
430 hide_on_ok = p_hide;
431 }
get_hide_on_ok() const432 bool AcceptDialog::get_hide_on_ok() const {
433
434 return hide_on_ok;
435 }
436
set_autowrap(bool p_autowrap)437 void AcceptDialog::set_autowrap(bool p_autowrap) {
438
439 label->set_autowrap(p_autowrap);
440 }
has_autowrap()441 bool AcceptDialog::has_autowrap() {
442
443 return label->has_autowrap();
444 }
445
register_text_enter(Node * p_line_edit)446 void AcceptDialog::register_text_enter(Node *p_line_edit) {
447
448 ERR_FAIL_NULL(p_line_edit);
449 LineEdit *line_edit = Object::cast_to<LineEdit>(p_line_edit);
450 if (line_edit)
451 line_edit->connect("text_entered", this, "_builtin_text_entered");
452 }
453
_update_child_rects()454 void AcceptDialog::_update_child_rects() {
455
456 Size2 label_size = label->get_minimum_size();
457 if (label->get_text().empty()) {
458 label_size.height = 0;
459 }
460 int margin = get_constant("margin", "Dialogs");
461 Size2 size = get_size();
462 Size2 hminsize = hbc->get_combined_minimum_size();
463
464 Vector2 cpos(margin, margin + label_size.height);
465 Vector2 csize(size.x - margin * 2, size.y - margin * 3 - hminsize.y - label_size.height);
466
467 for (int i = 0; i < get_child_count(); i++) {
468 Control *c = Object::cast_to<Control>(get_child(i));
469 if (!c)
470 continue;
471
472 if (c == hbc || c == label || c == get_close_button() || c->is_set_as_toplevel())
473 continue;
474
475 c->set_position(cpos);
476 c->set_size(csize);
477 }
478
479 cpos.y += csize.y + margin;
480 csize.y = hminsize.y;
481
482 hbc->set_position(cpos);
483 hbc->set_size(csize);
484 }
485
get_minimum_size() const486 Size2 AcceptDialog::get_minimum_size() const {
487
488 int margin = get_constant("margin", "Dialogs");
489 Size2 minsize = label->get_combined_minimum_size();
490
491 for (int i = 0; i < get_child_count(); i++) {
492 Control *c = Object::cast_to<Control>(get_child(i));
493 if (!c)
494 continue;
495
496 if (c == hbc || c == label || c == const_cast<AcceptDialog *>(this)->get_close_button() || c->is_set_as_toplevel())
497 continue;
498
499 Size2 cminsize = c->get_combined_minimum_size();
500 minsize.x = MAX(cminsize.x, minsize.x);
501 minsize.y = MAX(cminsize.y, minsize.y);
502 }
503
504 Size2 hminsize = hbc->get_combined_minimum_size();
505 minsize.x = MAX(hminsize.x, minsize.x);
506 minsize.y += hminsize.y;
507 minsize.x += margin * 2;
508 minsize.y += margin * 3; //one as separation between hbc and child
509
510 Size2 wmsize = WindowDialog::get_minimum_size();
511 minsize.x = MAX(wmsize.x, minsize.x);
512 return minsize;
513 }
514
_custom_action(const String & p_action)515 void AcceptDialog::_custom_action(const String &p_action) {
516
517 emit_signal("custom_action", p_action);
518 custom_action(p_action);
519 }
520
add_button(const String & p_text,bool p_right,const String & p_action)521 Button *AcceptDialog::add_button(const String &p_text, bool p_right, const String &p_action) {
522
523 Button *button = memnew(Button);
524 button->set_text(p_text);
525 if (p_right) {
526 hbc->add_child(button);
527 hbc->add_spacer();
528 } else {
529
530 hbc->add_child(button);
531 hbc->move_child(button, 0);
532 hbc->add_spacer(true);
533 }
534
535 if (p_action != "") {
536 button->connect("pressed", this, "_custom_action", varray(p_action));
537 }
538
539 return button;
540 }
541
add_cancel(const String & p_cancel)542 Button *AcceptDialog::add_cancel(const String &p_cancel) {
543
544 String c = p_cancel;
545 if (p_cancel == "")
546 c = RTR("Cancel");
547 Button *b = swap_ok_cancel ? add_button(c, true) : add_button(c);
548 b->connect("pressed", this, "_closed");
549 return b;
550 }
551
_bind_methods()552 void AcceptDialog::_bind_methods() {
553
554 ClassDB::bind_method(D_METHOD("_ok"), &AcceptDialog::_ok_pressed);
555 ClassDB::bind_method(D_METHOD("get_ok"), &AcceptDialog::get_ok);
556 ClassDB::bind_method(D_METHOD("get_label"), &AcceptDialog::get_label);
557 ClassDB::bind_method(D_METHOD("set_hide_on_ok", "enabled"), &AcceptDialog::set_hide_on_ok);
558 ClassDB::bind_method(D_METHOD("get_hide_on_ok"), &AcceptDialog::get_hide_on_ok);
559 ClassDB::bind_method(D_METHOD("add_button", "text", "right", "action"), &AcceptDialog::add_button, DEFVAL(false), DEFVAL(""));
560 ClassDB::bind_method(D_METHOD("add_cancel", "name"), &AcceptDialog::add_cancel);
561 ClassDB::bind_method(D_METHOD("_builtin_text_entered"), &AcceptDialog::_builtin_text_entered);
562 ClassDB::bind_method(D_METHOD("register_text_enter", "line_edit"), &AcceptDialog::register_text_enter);
563 ClassDB::bind_method(D_METHOD("_custom_action"), &AcceptDialog::_custom_action);
564 ClassDB::bind_method(D_METHOD("set_text", "text"), &AcceptDialog::set_text);
565 ClassDB::bind_method(D_METHOD("get_text"), &AcceptDialog::get_text);
566 ClassDB::bind_method(D_METHOD("set_autowrap", "autowrap"), &AcceptDialog::set_autowrap);
567 ClassDB::bind_method(D_METHOD("has_autowrap"), &AcceptDialog::has_autowrap);
568
569 ADD_SIGNAL(MethodInfo("confirmed"));
570 ADD_SIGNAL(MethodInfo("custom_action", PropertyInfo(Variant::STRING, "action")));
571
572 ADD_GROUP("Dialog", "dialog");
573 ADD_PROPERTY(PropertyInfo(Variant::STRING, "dialog_text", PROPERTY_HINT_MULTILINE_TEXT, "", PROPERTY_USAGE_DEFAULT_INTL), "set_text", "get_text");
574 ADD_PROPERTY(PropertyInfo(Variant::BOOL, "dialog_hide_on_ok"), "set_hide_on_ok", "get_hide_on_ok");
575 ADD_PROPERTY(PropertyInfo(Variant::BOOL, "dialog_autowrap"), "set_autowrap", "has_autowrap");
576 }
577
578 bool AcceptDialog::swap_ok_cancel = false;
set_swap_ok_cancel(bool p_swap)579 void AcceptDialog::set_swap_ok_cancel(bool p_swap) {
580
581 swap_ok_cancel = p_swap;
582 }
583
AcceptDialog()584 AcceptDialog::AcceptDialog() {
585
586 int margin = get_constant("margin", "Dialogs");
587 int button_margin = get_constant("button_margin", "Dialogs");
588
589 label = memnew(Label);
590 label->set_anchor(MARGIN_RIGHT, ANCHOR_END);
591 label->set_anchor(MARGIN_BOTTOM, ANCHOR_END);
592 label->set_begin(Point2(margin, margin));
593 label->set_end(Point2(-margin, -button_margin - 10));
594 add_child(label);
595
596 hbc = memnew(HBoxContainer);
597 add_child(hbc);
598
599 hbc->add_spacer();
600 ok = memnew(Button);
601 ok->set_text(RTR("OK"));
602 hbc->add_child(ok);
603 hbc->add_spacer();
604
605 ok->connect("pressed", this, "_ok");
606 set_as_toplevel(true);
607
608 hide_on_ok = true;
609 set_title(RTR("Alert!"));
610 }
611
~AcceptDialog()612 AcceptDialog::~AcceptDialog() {
613 }
614
615 // ConfirmationDialog
616
_bind_methods()617 void ConfirmationDialog::_bind_methods() {
618
619 ClassDB::bind_method(D_METHOD("get_cancel"), &ConfirmationDialog::get_cancel);
620 }
621
get_cancel()622 Button *ConfirmationDialog::get_cancel() {
623
624 return cancel;
625 }
626
ConfirmationDialog()627 ConfirmationDialog::ConfirmationDialog() {
628
629 set_title(RTR("Please Confirm..."));
630 #ifdef TOOLS_ENABLED
631 set_custom_minimum_size(Size2(200, 70) * EDSCALE);
632 #endif
633 cancel = add_cancel();
634 }
635