示例#1
0
文件: cs.c 项目: Eltechs/wine
static void wined3d_cs_exec_draw(struct wined3d_cs *cs, const void *data)
{
    const struct wined3d_cs_draw *op = data;

    draw_primitive(cs->device, op->start_idx, op->index_count,
            op->start_instance, op->instance_count, op->indexed);
}
示例#2
0
void RayCast2D::_notification(int p_what) {

	switch (p_what) {

		case NOTIFICATION_ENTER_TREE: {

			if (enabled && !get_tree()->is_editor_hint())
				set_fixed_process(true);
			else
				set_fixed_process(false);

			if (get_parent()->cast_to<PhysicsBody2D>()) {
				if (exclude_parent_body)
					exclude.insert(get_parent()->cast_to<PhysicsBody2D>()->get_rid());
				else
					exclude.erase(get_parent()->cast_to<PhysicsBody2D>()->get_rid());
			}
		} break;
		case NOTIFICATION_EXIT_TREE: {

			if (enabled)
				set_fixed_process(false);

		} break;

		case NOTIFICATION_DRAW: {

			if (!get_tree()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint())
				break;
			Transform2D xf;
			xf.rotate(cast_to.angle());
			xf.translate(Vector2(cast_to.length(), 0));

			//Vector2 tip = Vector2(0,s->get_length());
			Color dcol = get_tree()->get_debug_collisions_color(); //0.9,0.2,0.2,0.4);
			draw_line(Vector2(), cast_to, dcol, 3);
			Vector<Vector2> pts;
			float tsize = 4;
			pts.push_back(xf.xform(Vector2(tsize, 0)));
			pts.push_back(xf.xform(Vector2(0, 0.707 * tsize)));
			pts.push_back(xf.xform(Vector2(0, -0.707 * tsize)));
			Vector<Color> cols;
			for (int i = 0; i < 3; i++)
				cols.push_back(dcol);

			draw_primitive(pts, cols, Vector<Vector2>()); //small arrow

		} break;

		case NOTIFICATION_FIXED_PROCESS: {

			if (!enabled)
				break;

			_update_raycast_state();

		} break;
	}
}
示例#3
0
 void visitPrimitive(Primitive *p) {
     draw_primitive("Primitive",p);
 }
示例#4
0
void RayCast2D::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_ENTER_TREE: {

			if (enabled && !get_tree()->is_editor_hint())
				set_fixed_process(true);
			else
				set_fixed_process(false);

		} break;
		case NOTIFICATION_EXIT_TREE: {

			if (enabled)
				set_fixed_process(false);

		} break;
#ifdef TOOLS_ENABLED
		case NOTIFICATION_DRAW: {

			if (!get_tree()->is_editor_hint())
				break;
			Matrix32 xf;
			xf.rotate(cast_to.atan2());
			xf.translate(Vector2(0,cast_to.length()));

			//Vector2 tip = Vector2(0,s->get_length());
			Color dcol(0.9,0.2,0.2,0.4);
			draw_line(Vector2(),cast_to,dcol,3);
			Vector<Vector2> pts;
			float tsize=4;
			pts.push_back(xf.xform(Vector2(0,tsize)));
			pts.push_back(xf.xform(Vector2(0.707*tsize,0)));
			pts.push_back(xf.xform(Vector2(-0.707*tsize,0)));
			Vector<Color> cols;
			for(int i=0;i<3;i++)
				cols.push_back(dcol);

			draw_primitive(pts,cols,Vector<Vector2>()); //small arrow

		} break;
#endif

		case NOTIFICATION_FIXED_PROCESS: {

			if (!enabled)
				break;



			Ref<World2D> w2d = get_world_2d();
			ERR_BREAK( w2d.is_null() );

			Physics2DDirectSpaceState *dss = Physics2DServer::get_singleton()->space_get_direct_state(w2d->get_space());
			ERR_BREAK( !dss );

			Matrix32 gt = get_global_transform();

			Vector2 to = cast_to;
			if (to==Vector2())
				to=Vector2(0,0.01);

			Physics2DDirectSpaceState::RayResult rr;

			if (dss->intersect_ray(gt.get_origin(),gt.xform(to),rr,exclude,layer_mask)) {

				collided=true;
				against=rr.collider_id;
				collision_point=rr.position;
				collision_normal=rr.normal;
				against_shape=rr.shape;
			} else {
				collided=false;
			}



		} break;
	}
}
示例#5
0
void ColorRampEdit::_notification(int p_what) {

	if (p_what==NOTIFICATION_ENTER_TREE) {
		if (!picker->is_connected("color_changed",this,"_color_changed")) {
			picker->connect("color_changed",this,"_color_changed");
		}
	}
	if (p_what==NOTIFICATION_DRAW) {

		int w = get_size().x;
		int h = get_size().y;

		if (w == 0 || h == 0)
			return; //Safety check. We have division by 'h'. And in any case there is nothing to draw with such size

		int total_w = get_size().width-get_size().height-3;

		//Draw checker pattern for ramp
		_draw_checker(0,0, total_w, h);

		//Draw color ramp
		ColorRamp::Point prev;
		prev.offset=0;
		if(points.size() == 0)
			prev.color=Color(0,0,0); //Draw black rectangle if we have no points
		else
			prev.color = points[0].color;  //Extend color of first point to the beginning.

		for(int i=-1;i<points.size();i++) {

			ColorRamp::Point next;
			//If there is no next point
			if (i+1 == points.size()) {
				if(points.size() == 0)
					next.color=Color(0,0,0); //Draw black rectangle if we have no points
				else
					next.color=points[i].color; //Extend color of last point to the end.
				next.offset=1;
			} else {
				next=points[i+1];
			}

			if (prev.offset==next.offset) {
				prev=next;
				continue;
			}

			Vector<Vector2> points;
			Vector<Color> colors;
			points.push_back(Vector2(prev.offset*total_w,h));
			points.push_back(Vector2(prev.offset*total_w,0));
			points.push_back(Vector2(next.offset*total_w,0));
			points.push_back(Vector2(next.offset*total_w,h));
			colors.push_back(prev.color);
			colors.push_back(prev.color);
			colors.push_back(next.color);
			colors.push_back(next.color);
			draw_primitive(points,colors,Vector<Point2>());
			prev=next;
		}

		//Draw point markers
		for(int i=0;i<points.size();i++) {

			Color col = i==grabbed?Color(1,0.0,0.0,0.9):points[i].color.contrasted();
			col.a = 0.9;

			draw_line(Vector2(points[i].offset*total_w,0),Vector2(points[i].offset*total_w,h/2),col);
			draw_rect(Rect2(points[i].offset*total_w-POINT_WIDTH/2, h/2, POINT_WIDTH, h/2), Color(0.6, 0.6, 0.6, i==grabbed?0.9:0.4));
			draw_line(Vector2(points[i].offset*total_w-POINT_WIDTH/2,h/2),Vector2(points[i].offset*total_w-POINT_WIDTH/2,h-1),col);
			draw_line(Vector2(points[i].offset*total_w+POINT_WIDTH/2,h/2),Vector2(points[i].offset*total_w+POINT_WIDTH/2,h-1),col);
			draw_line(Vector2(points[i].offset*total_w-POINT_WIDTH/2,h/2),Vector2(points[i].offset*total_w+POINT_WIDTH/2,h/2),col);
			draw_line(Vector2(points[i].offset*total_w-POINT_WIDTH/2,h-1),Vector2(points[i].offset*total_w+POINT_WIDTH/2,h-1),col);

		}


		//Draw "button" for color selector
		_draw_checker(total_w+3,0, h, h);
		if (grabbed!=-1) {
			//Draw with selection color
			draw_rect(Rect2(total_w+3,0,h,h),points[grabbed].color);
		} else {
			//if no color selected draw grey color with 'X' on top.
			draw_rect(Rect2(total_w+3,0,h,h), Color(0.5, 0.5, 0.5, 1));
			draw_line(Vector2(total_w+3,0),Vector2(total_w+3+h,h),Color(1,1,1,0.6));
			draw_line(Vector2(total_w+3,h),Vector2(total_w+3+h,0),Color(1,1,1,0.6));
		}

		//Draw borders around color ramp if in focus
		if (has_focus()) {

			draw_line(Vector2(-1,-1),Vector2(total_w+1,-1),Color(1,1,1,0.6));
			draw_line(Vector2(total_w+1,-1),Vector2(total_w+1,h+1),Color(1,1,1,0.6));
			draw_line(Vector2(total_w+1,h+1),Vector2(-1,h+1),Color(1,1,1,0.6));
			draw_line(Vector2(-1,-1),Vector2(-1,h+1),Color(1,1,1,0.6));
		}

	}
}
示例#6
0
void CollisionShape2D::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {

			if (!is_inside_scene())
				break;
			_update_parent();

		} break;
		/*
		case NOTIFICATION_TRANSFORM_CHANGED: {

			if (!is_inside_scene())
				break;
			_update_parent();

		} break;*/
		case NOTIFICATION_DRAW: {

			rect=Rect2();

			Color draw_col=Color(0,0.6,0.7,0.5);

			if (shape->cast_to<LineShape2D>()) {

				LineShape2D *l = shape->cast_to<LineShape2D>();
				Vector2 point = l->get_d() * l->get_normal();

				Vector2 l1[2]={point-l->get_normal().tangent()*100,point+l->get_normal().tangent()*100};
				draw_line(l1[0],l1[1],draw_col,3);
				Vector2 l2[2]={point,point+l->get_normal()*30};
				draw_line(l2[0],l2[1],draw_col,3);
				rect.pos=l1[0];
				rect.expand_to(l1[1]);
				rect.expand_to(l2[0]);
				rect.expand_to(l2[1]);

			} else if (shape->cast_to<SegmentShape2D>()) {

				SegmentShape2D *s = shape->cast_to<SegmentShape2D>();
				draw_line(s->get_a(),s->get_b(),draw_col,3);
				rect.pos=s->get_a();
				rect.expand_to(s->get_b());

			} else if (shape->cast_to<RayShape2D>()) {

				RayShape2D *s = shape->cast_to<RayShape2D>();

				Vector2 tip = Vector2(0,s->get_length());
				draw_line(Vector2(),tip,draw_col,3);
				Vector<Vector2> pts;
				float tsize=4;
				pts.push_back(tip+Vector2(0,tsize));
				pts.push_back(tip+Vector2(0.707*tsize,0));
				pts.push_back(tip+Vector2(-0.707*tsize,0));
				Vector<Color> cols;
				for(int i=0;i<3;i++)
					cols.push_back(draw_col);

				draw_primitive(pts,cols,Vector<Vector2>()); //small arrow

				rect.pos=Vector2();
				rect.expand_to(tip);
				rect=rect.grow(0.707*tsize);

			} else if (shape->cast_to<CircleShape2D>()) {

				CircleShape2D *s = shape->cast_to<CircleShape2D>();
				Vector<Vector2> points;
				for(int i=0;i<24;i++) {

					points.push_back(Vector2(Math::cos(i*Math_PI*2/24.0),Math::sin(i*Math_PI*2/24.0))*s->get_radius());
				}

				draw_colored_polygon(points,draw_col);
				rect.pos=-Point2(s->get_radius(),s->get_radius());
				rect.size=Point2(s->get_radius(),s->get_radius())*2.0;

			} else if (shape->cast_to<RectangleShape2D>()) {

				RectangleShape2D *s = shape->cast_to<RectangleShape2D>();
				Vector2 he = s->get_extents();
				rect=Rect2(-he,he*2.0);
				draw_rect(rect,draw_col);;

			} else if (shape->cast_to<CapsuleShape2D>()) {

				CapsuleShape2D *s = shape->cast_to<CapsuleShape2D>();

				Vector<Vector2> points;
				for(int i=0;i<24;i++) {
					Vector2 ofs = Vector2(0,(i>6 && i<=18) ? -s->get_height()*0.5 : s->get_height()*0.5);

					points.push_back(Vector2(Math::sin(i*Math_PI*2/24.0),Math::cos(i*Math_PI*2/24.0))*s->get_radius() + ofs);
					if (i==6 || i==18)
						points.push_back(Vector2(Math::sin(i*Math_PI*2/24.0),Math::cos(i*Math_PI*2/24.0))*s->get_radius() - ofs);
				}

				draw_colored_polygon(points,draw_col);
				Vector2 he=Point2(s->get_radius(),s->get_radius()+s->get_height()*0.5);
				rect.pos=-he;
				rect.size=he*2.0;

			} else if (shape->cast_to<ConvexPolygonShape2D>()) {

				ConvexPolygonShape2D *s = shape->cast_to<ConvexPolygonShape2D>();

				Vector<Vector2> points = s->get_points();
				for(int i=0;i<points.size();i++) {
					if (i==0)
						rect.pos=points[i];
					else
						rect.expand_to(points[i]);
				}

				draw_colored_polygon(points,draw_col);

			}

			rect=rect.grow(3);

		} break;

	}

}