void AnimController::_notification(int p_notification) {
    switch (p_notification) {
        case NOTIFICATION_FIXED_PROCESS:
        {
            float fixed_delta = get_fixed_process_delta_time();
            Vector<String> keys;
            for (Map<String, float >::Element *E = remove_counts.front(); E; E = E->next()) {
                float time = E->value();
                time -= fixed_delta;
                if (time <= 0) {
                    keys.push_back(E->key());
                }else {
                    E->value() = time;
                }
            }
            for (int n = 0, t = keys.size(); n < t; n++) {
                remove_status(keys[n]);
            }

            if (_changed) {
                _changed = false;
                _status_changed(added_anims, removed_anims);
                if (get_script_instance()) {
                    get_script_instance()->call_multilevel("_status_changed", added_anims, removed_anims);
                }
                added_anims.clear();
                removed_anims.clear();
            }
        };
    }
}
Beispiel #2
0
void Timer::_notification(int p_what) {

	switch(p_what) {


		case NOTIFICATION_READY: {

			if (autostart) {
#ifdef TOOLS_ENABLED
				if (get_tree()->is_editor_hint() && get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root()==this || get_tree()->get_edited_scene_root()->is_a_parent_of(this)))
					break;
#endif
				start();
				autostart=false;
			}
		} break;
		case NOTIFICATION_PROCESS: {
			if (timer_process_mode == TIMER_PROCESS_FIXED || !is_processing())
				return;
			time_left -= get_process_delta_time();

			if (time_left<0) {
				if (!one_shot)
					//time_left=wait_time+time_left;
					time_left = wait_time;
				else
					stop();

				emit_signal("timeout");
			}

		} break;
		case NOTIFICATION_FIXED_PROCESS: {
			if (timer_process_mode == TIMER_PROCESS_IDLE || !is_fixed_processing())
				return;
			time_left -= get_fixed_process_delta_time();

			if (time_left<0) {
				if (!one_shot)
					//time_left = wait_time + time_left;
					time_left = wait_time;
				else
					stop();
				emit_signal("timeout");
			}

		} break;
	}
}
void AnimationPlayer::_notification(int p_what) {

    switch(p_what) {

    case NOTIFICATION_ENTER_SCENE: {

        if (!processing) {
            //make sure that a previous process state was not saved
            //only process if "processing" is set
            set_fixed_process(false);
            set_process(false);
        }
        //_set_process(false);
        clear_caches();
    }
    break;
    case NOTIFICATION_READY: {

        if (!get_scene()->is_editor_hint() && animation_set.has(autoplay)) {
            play(autoplay);
        }
    }
    break;
    case NOTIFICATION_PROCESS: {
        if (animation_process_mode==ANIMATION_PROCESS_FIXED)
            break;

        if (processing)
            _animation_process( get_process_delta_time() );
    }
    break;
    case NOTIFICATION_FIXED_PROCESS: {

        if (animation_process_mode==ANIMATION_PROCESS_IDLE)
            break;

        if (processing)
            _animation_process( get_fixed_process_delta_time() );
    }
    break;
    case NOTIFICATION_EXIT_SCENE: {

        stop_all();
        clear_caches();
    }
    break;
    }
}
Beispiel #4
0
void Tween::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_ENTER_TREE: {

			if (!processing) {
				//make sure that a previous process state was not saved
				//only process if "processing" is set
				set_fixed_process(false);
				set_process(false);
			}
		} break;
		case NOTIFICATION_READY: {

		} break;
		case NOTIFICATION_PROCESS: {
			if (tween_process_mode==TWEEN_PROCESS_FIXED)
				break;

			if (processing)
				_tween_process( get_process_delta_time() );
		} break;
		case NOTIFICATION_FIXED_PROCESS: {

			if (tween_process_mode==TWEEN_PROCESS_IDLE)
				break;

			if (processing)
				_tween_process( get_fixed_process_delta_time() );
		} break;
		case NOTIFICATION_EXIT_TREE: {

			stop_all();
		} break;
	}
}
Beispiel #5
0
void AnimationTreePlayer::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_ENTER_TREE: {

			if (!processing) {
				//make sure that a previous process state was not saved
				//only process if "processing" is set
				set_fixed_process(false);
				set_process(false);
			}
		} break;
		case NOTIFICATION_READY: {
			dirty_caches=true;
			if (master!=NodePath()) {
				_update_sources();
			}
		} break;
		case NOTIFICATION_PROCESS: {
			if (animation_process_mode==ANIMATION_PROCESS_FIXED)
				break;

			if (processing)
				_process_animation( get_process_delta_time() );
		} break;
		case NOTIFICATION_FIXED_PROCESS: {

			if (animation_process_mode==ANIMATION_PROCESS_IDLE)
				break;

			if (processing)
				_process_animation(get_fixed_process_delta_time());
		} break;
	}

}
Beispiel #6
0
void ScrollBar::_notification(int p_what) {

	if (p_what == NOTIFICATION_DRAW) {

		RID ci = get_canvas_item();

		Ref<Texture> decr = highlight == HIGHLIGHT_DECR ? get_icon("decrement_highlight") : get_icon("decrement");
		Ref<Texture> incr = highlight == HIGHLIGHT_INCR ? get_icon("increment_highlight") : get_icon("increment");
		Ref<StyleBox> bg = has_focus() ? get_stylebox("scroll_focus") : get_stylebox("scroll");

		Ref<StyleBox> grabber;
		if (drag.active)
			grabber = get_stylebox("grabber_pressed");
		else if (highlight == HIGHLIGHT_RANGE)
			grabber = get_stylebox("grabber_highlight");
		else
			grabber = get_stylebox("grabber");

		Point2 ofs;

		VisualServer *vs = VisualServer::get_singleton();

		vs->canvas_item_add_texture_rect(ci, Rect2(Point2(), decr->get_size()), decr->get_rid());

		if (orientation == HORIZONTAL)
			ofs.x += decr->get_width();
		else
			ofs.y += decr->get_height();

		Size2 area = get_size();

		if (orientation == HORIZONTAL)
			area.width -= incr->get_width() + decr->get_width();
		else
			area.height -= incr->get_height() + decr->get_height();

		bg->draw(ci, Rect2(ofs, area));

		if (orientation == HORIZONTAL)
			ofs.width += area.width;
		else
			ofs.height += area.height;

		vs->canvas_item_add_texture_rect(ci, Rect2(ofs, decr->get_size()), incr->get_rid());
		Rect2 grabber_rect;

		if (orientation == HORIZONTAL) {

			grabber_rect.size.width = get_grabber_size();
			grabber_rect.size.height = get_size().height;
			grabber_rect.position.y = 0;
			grabber_rect.position.x = get_grabber_offset() + decr->get_width() + bg->get_margin(MARGIN_LEFT);
		} else {

			grabber_rect.size.width = get_size().width;
			grabber_rect.size.height = get_grabber_size();
			grabber_rect.position.y = get_grabber_offset() + decr->get_height() + bg->get_margin(MARGIN_TOP);
			grabber_rect.position.x = 0;
		}

		grabber->draw(ci, grabber_rect);
	}

	if (p_what == NOTIFICATION_ENTER_TREE) {

		if (has_node(drag_slave_path)) {
			Node *n = get_node(drag_slave_path);
			drag_slave = n->cast_to<Control>();
		}

		if (drag_slave) {
			drag_slave->connect("gui_input", this, "_drag_slave_input");
			drag_slave->connect("tree_exited", this, "_drag_slave_exit", varray(), CONNECT_ONESHOT);
		}
	}
	if (p_what == NOTIFICATION_EXIT_TREE) {

		if (drag_slave) {
			drag_slave->disconnect("gui_input", this, "_drag_slave_input");
			drag_slave->disconnect("tree_exited", this, "_drag_slave_exit");
		}

		drag_slave = NULL;
	}

	if (p_what == NOTIFICATION_FIXED_PROCESS) {

		if (scrolling) {
			if (get_value() != target_scroll) {
				double target = target_scroll - get_value();
				double dist = sqrt(target * target);
				double vel = ((target / dist) * 500) * get_fixed_process_delta_time();

				if (vel >= dist) {
					set_value(target_scroll);
				} else {
					set_value(get_value() + vel);
				}
			} else {
				scrolling = false;
				set_fixed_process(false);
			}
		} else if (drag_slave_touching) {

			if (drag_slave_touching_deaccel) {

				Vector2 pos = Vector2(orientation == HORIZONTAL ? get_value() : 0, orientation == VERTICAL ? get_value() : 0);
				pos += drag_slave_speed * get_fixed_process_delta_time();

				bool turnoff = false;

				if (orientation == HORIZONTAL) {

					if (pos.x < 0) {
						pos.x = 0;
						turnoff = true;
					}

					if (pos.x > (get_max() - get_page())) {
						pos.x = get_max() - get_page();
						turnoff = true;
					}

					set_value(pos.x);

					float sgn_x = drag_slave_speed.x < 0 ? -1 : 1;
					float val_x = Math::abs(drag_slave_speed.x);
					val_x -= 1000 * get_fixed_process_delta_time();

					if (val_x < 0) {
						turnoff = true;
					}

					drag_slave_speed.x = sgn_x * val_x;

				} else {

					if (pos.y < 0) {
						pos.y = 0;
						turnoff = true;
					}

					if (pos.y > (get_max() - get_page())) {
						pos.y = get_max() - get_page();
						turnoff = true;
					}

					set_value(pos.y);

					float sgn_y = drag_slave_speed.y < 0 ? -1 : 1;
					float val_y = Math::abs(drag_slave_speed.y);
					val_y -= 1000 * get_fixed_process_delta_time();

					if (val_y < 0) {
						turnoff = true;
					}
					drag_slave_speed.y = sgn_y * val_y;
				}

				if (turnoff) {
					set_fixed_process(false);
					drag_slave_touching = false;
					drag_slave_touching_deaccel = false;
				}

			} else {

				if (time_since_motion == 0 || time_since_motion > 0.1) {

					Vector2 diff = drag_slave_accum - last_drag_slave_accum;
					last_drag_slave_accum = drag_slave_accum;
					drag_slave_speed = diff / get_fixed_process_delta_time();
				}

				time_since_motion += get_fixed_process_delta_time();
			}
		}
	}

	if (p_what == NOTIFICATION_MOUSE_EXIT) {

		highlight = HIGHLIGHT_NONE;
		update();
	}
}
Beispiel #7
0
Matrix32 Camera2D::get_camera_transform()  {

	if (!get_tree())
		return Matrix32();

	Size2 screen_size = get_viewport_rect().size;
	screen_size=get_viewport_rect().size;


	Point2 new_camera_pos = get_global_transform().get_origin();
	Point2 ret_camera_pos;

	if (!first) {


		if (anchor_mode==ANCHOR_MODE_DRAG_CENTER) {

			if (h_drag_enabled && !get_tree()->is_editor_hint()) {
				camera_pos.x = MIN( camera_pos.x, (new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT]));
				camera_pos.x = MAX( camera_pos.x, (new_camera_pos.x - screen_size.x * 0.5 * drag_margin[MARGIN_LEFT]));
			} else {

				if (h_ofs<0) {
					camera_pos.x = new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT] * h_ofs;
				} else {
					camera_pos.x = new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_LEFT] * h_ofs;
				}
			}

			if (v_drag_enabled && !get_tree()->is_editor_hint()) {

				camera_pos.y = MIN( camera_pos.y, (new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM]));
				camera_pos.y = MAX( camera_pos.y, (new_camera_pos.y - screen_size.y * 0.5 * drag_margin[MARGIN_TOP]));

			} else {

				if (v_ofs<0) {
					camera_pos.y = new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_TOP] * v_ofs;
				} else {
					camera_pos.y = new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM] * v_ofs;
				}
			}

		} else if (anchor_mode==ANCHOR_MODE_FIXED_TOP_LEFT){

			camera_pos=new_camera_pos;
		}



		if (smoothing_enabled && !get_tree()->is_editor_hint()) {

			float c = smoothing*get_fixed_process_delta_time();
			smoothed_camera_pos = ((camera_pos-smoothed_camera_pos)*c)+smoothed_camera_pos;
			ret_camera_pos=smoothed_camera_pos;
			//			camera_pos=camera_pos*(1.0-smoothing)+new_camera_pos*smoothing;
		} else {

			ret_camera_pos=smoothed_camera_pos=camera_pos;

		}



	} else {
		ret_camera_pos=smoothed_camera_pos=camera_pos=new_camera_pos;
		first=false;
	}


	Point2 screen_offset = (anchor_mode==ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5 * zoom) : Point2());

	float angle = get_global_transform().get_rotation();
	if(rotating){
		screen_offset = screen_offset.rotated(angle);
	}

	Rect2 screen_rect(-screen_offset+ret_camera_pos,screen_size*zoom);
	if (screen_rect.pos.x + screen_rect.size.x > limit[MARGIN_RIGHT])
		screen_rect.pos.x = limit[MARGIN_RIGHT] - screen_rect.size.x;

	if (screen_rect.pos.y + screen_rect.size.y > limit[MARGIN_BOTTOM])
		screen_rect.pos.y = limit[MARGIN_BOTTOM] - screen_rect.size.y;


	if (screen_rect.pos.x < limit[MARGIN_LEFT])
		screen_rect.pos.x=limit[MARGIN_LEFT];

	if (screen_rect.pos.y < limit[MARGIN_TOP])
		screen_rect.pos.y =limit[MARGIN_TOP];

	if (offset!=Vector2()) {

		screen_rect.pos+=offset;
		if (screen_rect.pos.x + screen_rect.size.x > limit[MARGIN_RIGHT])
			screen_rect.pos.x = limit[MARGIN_RIGHT] - screen_rect.size.x;

		if (screen_rect.pos.y + screen_rect.size.y > limit[MARGIN_BOTTOM])
			screen_rect.pos.y = limit[MARGIN_BOTTOM] - screen_rect.size.y;


		if (screen_rect.pos.x < limit[MARGIN_LEFT])
			screen_rect.pos.x=limit[MARGIN_LEFT];

		if (screen_rect.pos.y < limit[MARGIN_TOP])
			screen_rect.pos.y =limit[MARGIN_TOP];

	}

	camera_screen_center=screen_rect.pos+screen_rect.size*0.5;

	Matrix32 xform;
	if(rotating){
		xform.set_rotation(angle);
	}
	xform.scale_basis(zoom);
	xform.set_origin(screen_rect.pos/*.floor()*/);


/*
	if (0) {

		xform = get_global_transform() * xform;
	} else {

		xform.elements[2]+=get_global_transform().get_origin();
	}
*/


	return (xform).affine_inverse();
}
Beispiel #8
0
void Node::_notification(int p_notification) {
	
	switch(p_notification) {

		case NOTIFICATION_PROCESS: {

			if (get_script_instance()) {

				Variant time=get_process_delta_time();
				const Variant*ptr[1]={&time};
				Variant::CallError err;
				get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_process,ptr,1);
			}
		} break;
		case NOTIFICATION_FIXED_PROCESS: {

			if (get_script_instance()) {

				Variant time=get_fixed_process_delta_time();
				const Variant*ptr[1]={&time};
				Variant::CallError err;
				get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_fixed_process,ptr,1);
			}

		} break;
		case NOTIFICATION_ENTER_TREE: {

			if (data.pause_mode==PAUSE_MODE_INHERIT) {

				if (data.parent)
					data.pause_owner=data.parent->data.pause_owner;
				else
					data.pause_owner=NULL;
			} else {
				data.pause_owner=this;
			}

			if (data.input)
				add_to_group("_vp_input"+itos(get_viewport()->get_instance_ID()));
			if (data.unhandled_input)
				add_to_group("_vp_unhandled_input"+itos(get_viewport()->get_instance_ID()));
			if (data.unhandled_key_input)
				add_to_group("_vp_unhandled_key_input"+itos(get_viewport()->get_instance_ID()));

			get_tree()->node_count++;

		} break;
		case NOTIFICATION_EXIT_TREE: {

			get_tree()->node_count--;
			if (data.input)
				remove_from_group("_vp_input"+itos(get_viewport()->get_instance_ID()));
			if (data.unhandled_input)
				remove_from_group("_vp_unhandled_input"+itos(get_viewport()->get_instance_ID()));
			if (data.unhandled_key_input)
				remove_from_group("_vp_unhandled_key_input"+itos(get_viewport()->get_instance_ID()));

		} break;
		case NOTIFICATION_READY: {

			if (get_script_instance()) {

				Variant::CallError err;
				get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_ready,NULL,0);
			}
			//emit_signal(SceneStringNames::get_singleton()->enter_tree);

		} break;
		case NOTIFICATION_POSTINITIALIZE: {
			data.in_constructor=false;
		} break;
		case NOTIFICATION_PREDELETE: {

			set_owner(NULL);
			
			while ( data.owned.size() ) {
			
				data.owned.front()->get()->set_owner(NULL);	
			}

			if (data.parent) {
				
				data.parent->remove_child(this);
			}

			// kill children as cleanly as possible
			while( data.children.size() ) {
				
				Node *child = data.children[0];		
				remove_child(child);
				memdelete( child );
			}

		} break;
	}
}
Beispiel #9
0
void ScrollContainer::_notification(int p_what) {

	if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {

		call_deferred("_update_scrollbar_pos");
	};


	if (p_what==NOTIFICATION_SORT_CHILDREN) {

		child_max_size = Size2(0, 0);
		Size2 size = get_size();
		if (h_scroll->is_visible())
			size.y-=h_scroll->get_minimum_size().y;

		if (v_scroll->is_visible())
			size.x-=h_scroll->get_minimum_size().x;

		for(int i=0;i<get_child_count();i++) {

			Control *c = get_child(i)->cast_to<Control>();
			if (!c)
				continue;
			if (c->is_set_as_toplevel())
				continue;
			if (c == h_scroll || c == v_scroll)
				continue;
			Size2 minsize = c->get_combined_minimum_size();
			child_max_size.x = MAX(child_max_size.x, minsize.x);
			child_max_size.y = MAX(child_max_size.y, minsize.y);

			Rect2 r = Rect2(-scroll,minsize);
			if (!(scroll_h || h_scroll->is_visible())) {
				r.pos.x=0;
				if (c->get_h_size_flags()&SIZE_EXPAND)
					r.size.width=MAX(size.width,minsize.width);
				else
					r.size.width=minsize.width;
			}
			if (!(scroll_v || v_scroll->is_visible())) {
				r.pos.y=0;
				r.size.height=size.height;
				if (c->get_v_size_flags()&SIZE_EXPAND)
					r.size.height=MAX(size.height,minsize.height);
				else
					r.size.height=minsize.height;

			}
			fit_child_in_rect(c,r);
		}
		update();
	};

	if (p_what == NOTIFICATION_DRAW) {

		update_scrollbars();

		VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(),true);
	}

	if (p_what==NOTIFICATION_FIXED_PROCESS) {

		if (drag_touching)  {

			if (drag_touching_deaccel) {

				Vector2 pos = Vector2(h_scroll->get_val(),v_scroll->get_val());
				pos+=drag_speed*get_fixed_process_delta_time();

				bool turnoff_h=false;
				bool turnoff_v=false;

				if (pos.x<0) {
					pos.x=0;
					turnoff_h=true;
				}
				if (pos.x > (h_scroll->get_max()-h_scroll->get_page())) {
					pos.x=h_scroll->get_max()-h_scroll->get_page();
					turnoff_h=true;
				}

				if (pos.y<0) {
					pos.y=0;
					turnoff_v=true;
				}
				if (pos.y > (v_scroll->get_max()-v_scroll->get_page())) {
					pos.y=v_scroll->get_max()-v_scroll->get_page();
					turnoff_v=true;
				}

				if (scroll_h)
					h_scroll->set_val(pos.x);
				if (scroll_v)
					v_scroll->set_val(pos.y);

				float sgn_x = drag_speed.x<0? -1 : 1;
				float val_x = Math::abs(drag_speed.x);
				val_x-=1000*get_fixed_process_delta_time();

				if (val_x<0) {
					turnoff_h=true;
				}


				float sgn_y = drag_speed.y<0? -1 : 1;
				float val_y = Math::abs(drag_speed.y);
				val_y-=1000*get_fixed_process_delta_time();

				if (val_y<0) {
					turnoff_v=true;
				}


				drag_speed=Vector2(sgn_x*val_x,sgn_y*val_y);

				if (turnoff_h && turnoff_v) {
					set_fixed_process(false);
					drag_touching=false;
					drag_touching_deaccel=false;
				}


			} else {


				if (time_since_motion==0 || time_since_motion>0.1) {

					Vector2 diff = drag_accum - last_drag_accum;
					last_drag_accum=drag_accum;
					drag_speed=diff/get_fixed_process_delta_time();
				}

				time_since_motion+=get_fixed_process_delta_time();
			}
		}
	}

};