diff options
Diffstat (limited to 'scene/gui/popup.cpp')
-rw-r--r-- | scene/gui/popup.cpp | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index f2ba6bfbc4..5a2a552943 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -28,6 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "popup.h" + +#include "engine.h" #include "os/keyboard.h" void Popup::_gui_input(Ref<InputEvent> p_event) { @@ -48,7 +50,7 @@ void Popup::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { //small helper to make editing of these easier in editor #ifdef TOOLS_ENABLED - if (get_tree()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) { + if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) { set_as_toplevel(false); } #endif @@ -57,17 +59,10 @@ void Popup::_notification(int p_what) { void Popup::_fix_size() { -#if 0 - Point2 pos = get_position(); - Size2 size = get_size(); - Point2 window_size = window==this ? get_parent_area_size() :window->get_size(); -#else - Point2 pos = get_global_position(); Size2 size = get_size(); Point2 window_size = get_viewport_rect().size; -#endif if (pos.x + size.width > window_size.width) pos.x = window_size.width - size.width; if (pos.x < 0) @@ -77,14 +72,8 @@ void Popup::_fix_size() { pos.y = window_size.height - size.height; if (pos.y < 0) pos.y = 0; -#if 0 - if (pos!=get_pos()) - set_position(pos); -#else if (pos != get_position()) set_global_position(pos); - -#endif } void Popup::set_as_minsize() { @@ -93,7 +82,7 @@ void Popup::set_as_minsize() { for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c) continue; if (!c->is_visible()) @@ -127,7 +116,7 @@ void Popup::popup_centered_minsize(const Size2 &p_minsize) { for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c) continue; if (!c->is_visible()) @@ -247,6 +236,7 @@ void Popup::_bind_methods() { ADD_SIGNAL(MethodInfo("popup_hide")); ADD_GROUP("Popup", "popup_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "popup_exclusive"), "set_exclusive", "is_exclusive"); + BIND_CONSTANT(NOTIFICATION_POST_POPUP); BIND_CONSTANT(NOTIFICATION_POPUP_HIDE); } @@ -276,9 +266,10 @@ void PopupPanel::set_child_rect(Control *p_child) { Ref<StyleBox> p = get_stylebox("panel"); p_child->set_area_as_parent_rect(); - for (int i = 0; i < 4; i++) { - p_child->set_margin(Margin(i), p->get_margin(Margin(i))); - } + p_child->set_margin(MARGIN_LEFT, p->get_margin(MARGIN_LEFT)); + p_child->set_margin(MARGIN_RIGHT, -p->get_margin(MARGIN_RIGHT)); + p_child->set_margin(MARGIN_TOP, p->get_margin(MARGIN_TOP)); + p_child->set_margin(MARGIN_BOTTOM, -p->get_margin(MARGIN_BOTTOM)); } void PopupPanel::_notification(int p_what) { |