diff options
Diffstat (limited to 'scene/gui/control.cpp')
-rw-r--r-- | scene/gui/control.cpp | 178 |
1 files changed, 99 insertions, 79 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index fc24294a70..ce268843b1 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -183,7 +183,7 @@ bool Control::_set(const StringName& p_name, const Variant& p_value) { void Control::_update_minimum_size() { - if (!is_inside_scene()) + if (!is_inside_tree()) return; data.pending_min_size_update=false; @@ -341,7 +341,7 @@ void Control::_notification(int p_notification) { switch(p_notification) { - case NOTIFICATION_ENTER_SCENE: { + case NOTIFICATION_ENTER_TREE: { if (data.window==this) { @@ -365,7 +365,7 @@ void Control::_notification(int p_notification) { window->drag_attempted=false; window->drag_preview=NULL; - if (get_scene()->is_editor_hint()) { + if (get_tree()->is_editor_hint()) { Node *n = this; while(n) { @@ -385,7 +385,7 @@ void Control::_notification(int p_notification) { _size_changed(); } break; - case NOTIFICATION_EXIT_SCENE: { + case NOTIFICATION_EXIT_TREE: { if (data.window) { @@ -630,7 +630,7 @@ void Control::_notification(int p_notification) { } } break; - case SceneMainLoop::NOTIFICATION_WM_UNFOCUS_REQUEST: { + case SceneTree::NOTIFICATION_WM_UNFOCUS_REQUEST: { if (!window) return; @@ -710,7 +710,7 @@ void Control::drop_data(const Point2& p_point,const Variant& p_data){ void Control::force_drag(const Variant& p_data,Control *p_control) { - ERR_FAIL_COND(!is_inside_scene()); + ERR_FAIL_COND(!is_inside_tree()); ERR_FAIL_COND(!data.window); ERR_FAIL_COND(p_data.get_type()==Variant::NIL); @@ -728,8 +728,8 @@ void Control::set_drag_preview(Control *p_control) { ERR_FAIL_NULL(p_control); ERR_FAIL_COND( !((Object*)p_control)->cast_to<Control>()); - ERR_FAIL_COND(!is_inside_scene() || !data.window); - ERR_FAIL_COND(p_control->is_inside_scene()); + ERR_FAIL_COND(!is_inside_tree() || !data.window); + ERR_FAIL_COND(p_control->is_inside_tree()); ERR_FAIL_COND(p_control->get_parent()!=NULL); if (data.window->window->drag_preview) { @@ -963,8 +963,8 @@ void Control::_window_input_event(InputEvent p_event) { if (top->data.modal_exclusive) { //cancel event, sorry, modal exclusive EATS UP ALL - get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); - get_scene()->set_input_as_handled(); + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + get_tree()->set_input_as_handled(); return; // no one gets the event if exclusive NO ONE } @@ -1034,8 +1034,8 @@ void Control::_window_input_event(InputEvent p_event) { _window_call_input(window->mouse_focus,p_event); } - get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); - get_scene()->set_input_as_handled(); + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + get_tree()->set_input_as_handled(); } else { @@ -1079,8 +1079,8 @@ void Control::_window_input_event(InputEvent p_event) { } - get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); - get_scene()->set_input_as_handled(); + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + get_tree()->set_input_as_handled(); } } break; @@ -1126,6 +1126,7 @@ void Control::_window_input_event(InputEvent p_event) { over = _find_control_at_pos(this,pos,parent_xform,window->focus_inv_xform); } + if (window->drag_data.get_type()==Variant::NIL && over && !window->modal_stack.empty()) { Control *top = window->modal_stack.back()->get(); @@ -1147,7 +1148,7 @@ void Control::_window_input_event(InputEvent p_event) { window->mouse_over=over; - get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,"windows","_cancel_tooltip"); + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_tooltip"); if (window->drag_preview) { window->drag_preview->set_pos(pos); @@ -1203,8 +1204,8 @@ void Control::_window_input_event(InputEvent p_event) { - get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); - get_scene()->set_input_as_handled(); + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + get_tree()->set_input_as_handled(); if (window->drag_data.get_type()!=Variant::NIL && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) { @@ -1230,7 +1231,7 @@ void Control::_window_input_event(InputEvent p_event) { if (window->key_event_accepted) { - get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); break; } } @@ -1290,7 +1291,7 @@ void Control::_window_input_event(InputEvent p_event) { if (next) { next->grab_focus(); - get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); } } @@ -1305,7 +1306,7 @@ Control *Control::get_window() const { bool Control::is_window() const { - return (is_inside_scene() && window); + return (is_inside_tree() && window); } @@ -1325,9 +1326,12 @@ Size2 Control::get_minimum_size() const { Ref<Texture> Control::get_icon(const StringName& p_name,const StringName& p_type) const { - const Ref<Texture>* tex = data.icon_override.getptr(p_name); - if (tex) - return *tex; + if (p_type==StringName()) { + + const Ref<Texture>* tex = data.icon_override.getptr(p_name); + if (tex) + return *tex; + } StringName type = p_type?p_type:get_type_name(); @@ -1353,12 +1357,11 @@ Ref<Texture> Control::get_icon(const StringName& p_name,const StringName& p_type Ref<StyleBox> Control::get_stylebox(const StringName& p_name,const StringName& p_type) const { - - const Ref<StyleBox>* style = data.style_override.getptr(p_name); - - - if (style) - return *style; + if (p_type==StringName()) { + const Ref<StyleBox>* style = data.style_override.getptr(p_name); + if (style) + return *style; + } StringName type = p_type?p_type:get_type_name(); @@ -1381,10 +1384,12 @@ Ref<StyleBox> Control::get_stylebox(const StringName& p_name,const StringName& p } Ref<Font> Control::get_font(const StringName& p_name,const StringName& p_type) const { - - const Ref<Font>* font = data.font_override.getptr(p_name); - if (font) - return *font; + + if (p_type==StringName()) { + const Ref<Font>* font = data.font_override.getptr(p_name); + if (font) + return *font; + } StringName type = p_type?p_type:get_type_name(); @@ -1410,10 +1415,12 @@ Ref<Font> Control::get_font(const StringName& p_name,const StringName& p_type) c } Color Control::get_color(const StringName& p_name,const StringName& p_type) const { - - const Color* color = data.color_override.getptr(p_name); - if (color) - return *color; + + if (p_type==StringName()) { + const Color* color = data.color_override.getptr(p_name); + if (color) + return *color; + } StringName type = p_type?p_type:get_type_name(); // try with custom themes @@ -1437,10 +1444,12 @@ Color Control::get_color(const StringName& p_name,const StringName& p_type) cons } int Control::get_constant(const StringName& p_name,const StringName& p_type) const { - - const int* constant = data.constant_override.getptr(p_name); - if (constant) - return *constant; + + if (p_type==StringName()) { + const int* constant = data.constant_override.getptr(p_name); + if (constant) + return *constant; + } StringName type = p_type?p_type:get_type_name(); // try with custom themes @@ -1467,9 +1476,11 @@ int Control::get_constant(const StringName& p_name,const StringName& p_type) con bool Control::has_icon(const StringName& p_name,const StringName& p_type) const { - const Ref<Texture>* tex = data.icon_override.getptr(p_name); - if (tex) - return true; + if (p_type==StringName()) { + const Ref<Texture>* tex = data.icon_override.getptr(p_name); + if (tex) + return true; + } StringName type = p_type?p_type:get_type_name(); @@ -1494,11 +1505,12 @@ bool Control::has_icon(const StringName& p_name,const StringName& p_type) const } bool Control::has_stylebox(const StringName& p_name,const StringName& p_type) const { - - const Ref<StyleBox>* style = data.style_override.getptr(p_name); - - if (style) - return true; + if (p_type==StringName()) { + const Ref<StyleBox>* style = data.style_override.getptr(p_name); + + if (style) + return true; + } StringName type = p_type?p_type:get_type_name(); @@ -1523,9 +1535,11 @@ bool Control::has_stylebox(const StringName& p_name,const StringName& p_type) co } bool Control::has_font(const StringName& p_name,const StringName& p_type) const { - const Ref<Font>* font = data.font_override.getptr(p_name); - if (font) - return true; + if (p_type==StringName()) { + const Ref<Font>* font = data.font_override.getptr(p_name); + if (font) + return true; + } StringName type = p_type?p_type:get_type_name(); @@ -1551,9 +1565,11 @@ bool Control::has_font(const StringName& p_name,const StringName& p_type) const } bool Control::has_color(const StringName& p_name,const StringName& p_type) const { - const Color* color = data.color_override.getptr(p_name); - if (color) - return true; + if (p_type==StringName()) { + const Color* color = data.color_override.getptr(p_name); + if (color) + return true; + } StringName type = p_type?p_type:get_type_name(); @@ -1578,10 +1594,13 @@ bool Control::has_color(const StringName& p_name,const StringName& p_type) const } bool Control::has_constant(const StringName& p_name,const StringName& p_type) const { - - const int* constant = data.constant_override.getptr(p_name); - if (constant) - return true; + + if (p_type==StringName()) { + + const int* constant = data.constant_override.getptr(p_name); + if (constant) + return true; + } StringName type = p_type?p_type:get_type_name(); @@ -1607,7 +1626,7 @@ bool Control::has_constant(const StringName& p_name,const StringName& p_type) co Size2 Control::get_parent_area_size() const { - ERR_FAIL_COND_V(!is_inside_scene(),Size2()); + ERR_FAIL_COND_V(!is_inside_tree(),Size2()); Size2 parent_size; @@ -1624,7 +1643,7 @@ Size2 Control::get_parent_area_size() const { void Control::_size_changed() { - if (!is_inside_scene()) + if (!is_inside_tree()) return; Size2 parent_size = get_parent_area_size(); @@ -1677,7 +1696,7 @@ void Control::_size_changed() { float Control::_get_parent_range(int p_idx) const { - if (!is_inside_scene()) { + if (!is_inside_tree()) { return 1.0; @@ -1748,7 +1767,7 @@ float Control::_a2s(float p_val, AnchorType p_anchor,float p_range) const { void Control::set_anchor(Margin p_margin,AnchorType p_anchor) { - if (!is_inside_scene()) { + if (!is_inside_tree()) { data.anchor[p_margin]=p_anchor; } else { @@ -1980,7 +1999,7 @@ void Control::add_constant_override(const StringName& p_name, int p_constant) { void Control::set_focus_mode(FocusMode p_focus_mode) { - if (is_inside_scene() && p_focus_mode == FOCUS_NONE && data.focus_mode!=FOCUS_NONE && has_focus()) + if (is_inside_tree() && p_focus_mode == FOCUS_NONE && data.focus_mode!=FOCUS_NONE && has_focus()) release_focus(); data.focus_mode=p_focus_mode; @@ -2178,7 +2197,7 @@ bool Control::has_focus() const { void Control::grab_focus() { - ERR_FAIL_COND(!is_inside_scene()); + ERR_FAIL_COND(!is_inside_tree()); ERR_FAIL_COND(!data.window); if (data.focus_mode==FOCUS_NONE) @@ -2188,7 +2207,7 @@ void Control::grab_focus() { if (data.window->window->key_focus && data.window->window->key_focus==this) return; - get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,"windows","_window_remove_focus"); + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_window_remove_focus"); data.window->window->key_focus=this; notification(NOTIFICATION_FOCUS_ENTER); #ifdef DEBUG_ENABLED @@ -2202,13 +2221,13 @@ void Control::grab_focus() { void Control::release_focus() { - ERR_FAIL_COND(!is_inside_scene()); + ERR_FAIL_COND(!is_inside_tree()); ERR_FAIL_COND(!data.window); if (!has_focus()) return; - get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,"windows","_window_remove_focus"); + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_window_remove_focus"); //data.window->window->key_focus=this; //notification(NOTIFICATION_FOCUS_ENTER); update(); @@ -2217,12 +2236,12 @@ void Control::release_focus() { bool Control::is_toplevel_control() const { - return is_inside_scene() && (!data.parent_canvas_item && !window && is_set_as_toplevel()); + return is_inside_tree() && (!data.parent_canvas_item && !window && is_set_as_toplevel()); } void Control::show_modal(bool p_exclusive) { - ERR_FAIL_COND(!is_inside_scene()); + ERR_FAIL_COND(!is_inside_tree()); ERR_FAIL_COND(!data.SI && data.window!=this); ERR_FAIL_COND(!data.window); @@ -2249,6 +2268,7 @@ void Control::_window_sort_subwindows() { return; window->modal_stack.sort_custom<CComparator>(); + window->subwindows.sort_custom<CComparator>(); window->subwindow_order_dirty=false; } @@ -2282,7 +2302,7 @@ void Control::_modal_stack_remove() { if (!pfoc) return; - if (!pfoc->is_inside_scene() || !pfoc->is_visible()) + if (!pfoc->is_inside_tree() || !pfoc->is_visible()) return; pfoc->grab_focus(); } else { @@ -2332,13 +2352,13 @@ void Control::set_theme(const Ref<Theme>& p_theme) { void Control::_window_accept_event() { window->key_event_accepted=true; - if (is_inside_scene()) - get_scene()->set_input_as_handled(); + if (is_inside_tree()) + get_tree()->set_input_as_handled(); } void Control::accept_event() { - if (is_inside_scene() && get_window()) + if (is_inside_tree() && get_window()) get_window()->_window_accept_event(); } @@ -2585,7 +2605,7 @@ float Control::get_stretch_ratio() const { void Control::grab_click_focus() { - ERR_FAIL_COND(!is_inside_scene()); + ERR_FAIL_COND(!is_inside_tree()); if (data.window && data.window->window->mouse_focus) { @@ -2620,7 +2640,7 @@ void Control::grab_click_focus() { void Control::minimum_size_changed() { - if (!is_inside_scene()) + if (!is_inside_tree()) return; if (data.pending_min_size_update) @@ -2663,9 +2683,9 @@ bool Control::is_stopping_mouse() const { Control *Control::get_focus_owner() const { - ERR_FAIL_COND_V(!is_inside_scene(),NULL); - ERR_FAIL_COND_V(!window,NULL); - return window->key_focus; + ERR_FAIL_COND_V(!is_inside_tree(),NULL); + ERR_FAIL_COND_V(!data.window,NULL); + return data.window->window->key_focus; } void Control::_bind_methods() { |