dialogs.cpp 19 KB

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