Пример #1
0
void Camera2D::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_FIXED_PROCESS: {

			_update_scroll();

		} break;
		case NOTIFICATION_TRANSFORM_CHANGED: {


			if (!is_fixed_processing())
				_update_scroll();

		} break;
		case NOTIFICATION_ENTER_SCENE: {

			viewport = NULL;
			Node *n=this;
			while(n){

				viewport = n->cast_to<Viewport>();
				if (viewport)
					break;
				n=n->get_parent();
			}

			canvas = get_canvas();

			RID vp = viewport->get_viewport();

			group_name = "__cameras_"+itos(vp.get_id());
			canvas_group_name ="__cameras_c"+itos(canvas.get_id());
			add_to_group(group_name);
			add_to_group(canvas_group_name);

			_update_scroll();
			first=true;


		} break;
		case NOTIFICATION_EXIT_SCENE: {

			if (is_current()) {
				if (viewport) {
					viewport->set_canvas_transform( Matrix32() );
				}
			}
			remove_from_group(group_name);
			remove_from_group(canvas_group_name);
			viewport=NULL;

		} break;
	}
}
Пример #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;
	}
}
Пример #3
0
void Timer::set_timer_process_mode(TimerProcessMode p_mode) {

	if (timer_process_mode == p_mode)
		return;

	switch (timer_process_mode) {
		case TIMER_PROCESS_FIXED:
			if (is_fixed_processing()) {
				set_fixed_process(false);
				set_process(true);
			}
		break;
		case TIMER_PROCESS_IDLE:
			if (is_processing()) {
				set_process(false);
				set_fixed_process(true);
			}
		break;
	}
	timer_process_mode = p_mode;
}
Пример #4
0
void Camera2D::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_FIXED_PROCESS: {

			_update_scroll();

		} break;
		case NOTIFICATION_TRANSFORM_CHANGED: {


			if (!is_fixed_processing())
				_update_scroll();

		} break;
		case NOTIFICATION_ENTER_TREE: {


			viewport = NULL;
			Node *n=this;
			while(n){

				viewport = n->cast_to<Viewport>();
				if (viewport)
					break;
				n=n->get_parent();
			}

			canvas = get_canvas();

			RID vp = viewport->get_viewport();

			group_name = "__cameras_"+itos(vp.get_id());
			canvas_group_name ="__cameras_c"+itos(canvas.get_id());
			add_to_group(group_name);
			add_to_group(canvas_group_name);

			_update_scroll();
			first=true;


		} break;
		case NOTIFICATION_EXIT_TREE: {

			if (is_current()) {
				if (viewport) {
					viewport->set_canvas_transform( Matrix32() );
				}
			}
			remove_from_group(group_name);
			remove_from_group(canvas_group_name);
			viewport=NULL;

		} break;
		case NOTIFICATION_DRAW: {

			if (!is_inside_tree() || !get_tree()->is_editor_hint())
				break;

			Color area_axis_color(0.5, 0.42, 0.87, 0.63);
			float area_axis_width = 1;
			if(current)
				area_axis_width = 3;

			Matrix32 inv_camera_transform = get_camera_transform().affine_inverse();
			Size2 screen_size = get_viewport_rect().size;

			Vector2 screen_endpoints[4]= {
				inv_camera_transform.xform(Vector2(0, 0)),
				inv_camera_transform.xform(Vector2(screen_size.width,0)),
				inv_camera_transform.xform(Vector2(screen_size.width, screen_size.height)),
				inv_camera_transform.xform(Vector2(0, screen_size.height))
			};

			Matrix32 inv_transform = get_transform().affine_inverse(); // undo global space
			draw_set_transform(inv_transform.get_origin(), inv_transform.get_rotation(), inv_transform.get_scale());

			for(int i=0;i<4;i++) {
				draw_line(screen_endpoints[i], screen_endpoints[(i+1)%4], area_axis_color, area_axis_width);
			}

		} break;
	}
}
Пример #5
0
void Camera2D::_notification(int p_what) {

	switch (p_what) {

		case NOTIFICATION_FIXED_PROCESS: {

			_update_scroll();

		} break;
		case NOTIFICATION_TRANSFORM_CHANGED: {

			if (!is_fixed_processing())
				_update_scroll();

		} break;
		case NOTIFICATION_ENTER_TREE: {

			if (custom_viewport && ObjectDB::get_instance(custom_viewport_id)) {
				viewport = custom_viewport;
			} else {
				viewport = get_viewport();
			}

			canvas = get_canvas();

			RID vp = viewport->get_viewport_rid();

			group_name = "__cameras_" + itos(vp.get_id());
			canvas_group_name = "__cameras_c" + itos(canvas.get_id());
			add_to_group(group_name);
			add_to_group(canvas_group_name);

			if (Engine::get_singleton()->is_editor_hint()) {
				set_fixed_process(false);
			}

			_update_scroll();
			first = true;

		} break;
		case NOTIFICATION_EXIT_TREE: {

			if (is_current()) {
				if (viewport && !(custom_viewport && !ObjectDB::get_instance(custom_viewport_id))) {
					viewport->set_canvas_transform(Transform2D());
				}
			}
			remove_from_group(group_name);
			remove_from_group(canvas_group_name);
			viewport = NULL;

		} break;
		case NOTIFICATION_DRAW: {

			if (!is_inside_tree() || !Engine::get_singleton()->is_editor_hint())
				break;

			if (screen_drawing_enabled) {
				Color area_axis_color(0.5, 0.42, 0.87, 0.63);
				float area_axis_width = 1;
				if (is_current()) {
					area_axis_width = 3;
					area_axis_color.a = 0.83;
				}

				Transform2D inv_camera_transform = get_camera_transform().affine_inverse();
				Size2 screen_size = get_viewport_rect().size;

				Vector2 screen_endpoints[4] = {
					inv_camera_transform.xform(Vector2(0, 0)),
					inv_camera_transform.xform(Vector2(screen_size.width, 0)),
					inv_camera_transform.xform(Vector2(screen_size.width, screen_size.height)),
					inv_camera_transform.xform(Vector2(0, screen_size.height))
				};

				Transform2D inv_transform = get_global_transform().affine_inverse(); // undo global space

				for (int i = 0; i < 4; i++) {
					draw_line(inv_transform.xform(screen_endpoints[i]), inv_transform.xform(screen_endpoints[(i + 1) % 4]), area_axis_color, area_axis_width);
				}
			}

			if (limit_drawing_enabled) {
				Color limit_drawing_color(1, 1, 0, 0.63);
				float limit_drawing_width = 1;
				if (is_current()) {
					limit_drawing_color.a = 0.83;
					limit_drawing_width = 3;
				}

				Vector2 camera_origin = get_global_transform().get_origin();
				Vector2 camera_scale = get_global_transform().get_scale().abs();
				Vector2 limit_points[4] = {
					(Vector2(limit[MARGIN_LEFT], limit[MARGIN_TOP]) - camera_origin) / camera_scale,
					(Vector2(limit[MARGIN_RIGHT], limit[MARGIN_TOP]) - camera_origin) / camera_scale,
					(Vector2(limit[MARGIN_RIGHT], limit[MARGIN_BOTTOM]) - camera_origin) / camera_scale,
					(Vector2(limit[MARGIN_LEFT], limit[MARGIN_BOTTOM]) - camera_origin) / camera_scale
				};

				for (int i = 0; i < 4; i++) {
					draw_line(limit_points[i], limit_points[(i + 1) % 4], limit_drawing_color, limit_drawing_width);
				}
			}

			if (margin_drawing_enabled) {
				Color margin_drawing_color(0, 1, 1, 0.63);
				float margin_drawing_width = 1;
				if (is_current()) {
					margin_drawing_width = 3;
					margin_drawing_color.a = 0.83;
				}

				Transform2D inv_camera_transform = get_camera_transform().affine_inverse();
				Size2 screen_size = get_viewport_rect().size;

				Vector2 margin_endpoints[4] = {
					inv_camera_transform.xform(Vector2((screen_size.width / 2) - ((screen_size.width / 2) * drag_margin[MARGIN_LEFT]), (screen_size.height / 2) - ((screen_size.height / 2) * drag_margin[MARGIN_TOP]))),
					inv_camera_transform.xform(Vector2((screen_size.width / 2) + ((screen_size.width / 2) * drag_margin[MARGIN_RIGHT]), (screen_size.height / 2) - ((screen_size.height / 2) * drag_margin[MARGIN_TOP]))),
					inv_camera_transform.xform(Vector2((screen_size.width / 2) + ((screen_size.width / 2) * drag_margin[MARGIN_RIGHT]), (screen_size.height / 2) + ((screen_size.height / 2) * drag_margin[MARGIN_BOTTOM]))),
					inv_camera_transform.xform(Vector2((screen_size.width / 2) - ((screen_size.width / 2) * drag_margin[MARGIN_LEFT]), (screen_size.height / 2) + ((screen_size.height / 2) * drag_margin[MARGIN_BOTTOM])))
				};

				Transform2D inv_transform = get_global_transform().affine_inverse(); // undo global space

				for (int i = 0; i < 4; i++) {
					draw_line(inv_transform.xform(margin_endpoints[i]), inv_transform.xform(margin_endpoints[(i + 1) % 4]), margin_drawing_color, margin_drawing_width);
				}
			}

		} break;
	}
}