Browse Source

Add a small workaround to avoid modal tabs to be closed if they are spawned in the same frame, closes #3837

Juan Linietsky 9 years ago
parent
commit
88e28af5e3
3 changed files with 11 additions and 1 deletions
  1. 7 0
      scene/gui/control.cpp
  2. 2 0
      scene/gui/control.h
  3. 2 1
      scene/main/viewport.cpp

+ 7 - 0
scene/gui/control.cpp

@@ -762,6 +762,11 @@ bool Control::is_window_modal_on_top() const {
 	return get_viewport()->_gui_is_modal_on_top(this);
 }
 
+uint64_t Control::get_modal_frame() const {
+
+	return data.modal_frame;
+}
+
 
 
 Size2 Control::get_minimum_size() const {
@@ -1837,6 +1842,7 @@ void Control::show_modal(bool p_exclusive) {
 	raise();
 	data.modal_exclusive=p_exclusive;
 	data.MI=get_viewport()->_gui_show_modal(this);
+	data.modal_frame=OS::get_singleton()->get_frames_drawn();
 
 }
 
@@ -2547,6 +2553,7 @@ Control::Control() {
 	data.parent_canvas_item=NULL;
 	data.scale=Vector2(1,1);
 	data.drag_owner=0;
+	data.modal_frame=0;
 
 
 	for (int i=0;i<4;i++) {

+ 2 - 0
scene/gui/control.h

@@ -132,6 +132,7 @@ private:
 		ObjectID drag_owner;
 		bool modal;
 		bool modal_exclusive;
+		uint64_t modal_frame; //frame used to put something as modal
 		Ref<Theme> theme;
 		Control *theme_owner;
 		String tooltip;
@@ -249,6 +250,7 @@ public:
 	Size2 get_custom_minimum_size() const;
 
 	bool is_window_modal_on_top() const;
+	uint64_t get_modal_frame() const; //frame in which this was made modal
 
 	Control *get_parent_control() const;
 

+ 2 - 1
scene/main/viewport.cpp

@@ -1752,8 +1752,9 @@ void Viewport::_gui_input_event(InputEvent p_event) {
 						Vector2 pos = top->get_global_transform_with_canvas().affine_inverse().xform(mpos);
 						if (!top->has_point(pos)) {
 
-							if (top->data.modal_exclusive) {
+							if (top->data.modal_exclusive || top->data.modal_frame==OS::get_singleton()->get_frames_drawn()) {
 								//cancel event, sorry, modal exclusive EATS UP ALL
+								//alternative, you can't pop out a window the same frame it was made modal (fixes many issues)
 								//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