예제 #1
0
파일: shape2d.cpp 프로젝트: finalJ2/ClanLib
void Shape2D::add_rounded_line(const Pointf &start, const Pointf &end, float line_width, float cap_rounding, bool reverse)
{
	float distance = start.distance(end);
	Sizef size(distance, line_width);

	Angle angle(start.angle_line(end));

	Pointf center(start.x + size.width / 2.0f,  start.y + size.height / 2.0f );
	Vec2f rotated = start;
	rotated.rotate(center, angle);

	Vec2f origin( start.x + (start.x - rotated.x), start.y + (start.y - rotated.y));
	rotated = Vec2f(0.0f, line_width/2.0f);
	rotated.rotate(Vec2f(), angle);
	origin.x -= rotated.x;
	origin.y -= rotated.y;

	add_rounded_rect(origin, size, cap_rounding, angle, reverse);
}
예제 #2
0
파일: canvas.cpp 프로젝트: punkkeks/ClanLib
void Canvas::fill_circle(const Pointf &center, const Pointf &centergradient, float radius, const Gradient &gradient)
{
	float offset_x = 0;
	float offset_y = 0;

	float rotationcount = max(5.0f, (radius - 3.0f));
	float halfpi = 1.5707963267948966192313216916398f;
	float turn = halfpi / rotationcount;

	if(center.distance(center + centergradient) < radius)
	{
		offset_x = centergradient.x;
		offset_y = -centergradient.y;
	}

	Vec4f colors[3] =
	{
		Vec4f(gradient.top_left.get_red(), gradient.top_left.get_green(), gradient.top_left.get_blue(), gradient.top_left.get_alpha()),
		Vec4f(gradient.bottom_right.get_red(), gradient.bottom_right.get_green(), gradient.bottom_right.get_blue(), gradient.bottom_right.get_alpha()),
		Vec4f(gradient.bottom_right.get_red(), gradient.bottom_right.get_green(), gradient.bottom_right.get_blue(), gradient.bottom_right.get_alpha())
	};

	Vec4f triangle_colors[4*3];
	for (int i=0; i<3; i++)
	{
		triangle_colors[0*3+i] = colors[i];
		triangle_colors[1*3+i] = colors[i];
		triangle_colors[2*3+i] = colors[i];
		triangle_colors[3*3+i] = colors[i];
	}

	RenderBatchTriangle *batcher = impl->batcher.get_triangle_batcher();

	for(float i = 0; i < rotationcount ; i++)
	{
		float pos1 = cos(i * turn);
		float pos2 = sin(i * turn);
		float pos3 = cos((i+1) * turn);
		float pos4 = sin((i+1) * turn);

		Vec2f positions[4*3] =
		{
			// 90 triangle:
			Vec2f(center.x + offset_x , center.y + offset_y),
			Vec2f(center.x + ((float)radius * pos1), center.y + ((float)radius * pos2)),
			Vec2f(center.x + ((float)radius * pos3), center.y + ((float)radius * pos4)),

			// 0 triangle:
			Vec2f(center.x + offset_x , center.y + offset_y),
			Vec2f(center.x + ((float)radius * pos2), center.y - ((float)radius * pos1)),
			Vec2f(center.x + ((float)radius * pos4), center.y - ((float)radius * pos3)),

			// 270 triangle:
			Vec2f(center.x + offset_x , center.y + offset_y),
			Vec2f(center.x - ((float)radius * pos1), center.y - ((float)radius * pos2)),
			Vec2f(center.x - ((float)radius * pos3), center.y - ((float)radius * pos4)),

			// 180 triangle:
			Vec2f(center.x + offset_x , center.y + offset_y),
			Vec2f(center.x - ((float)radius * pos2), center.y + ((float)radius * pos1)),
			Vec2f(center.x - ((float)radius * pos4), center.y + ((float)radius * pos3))
		};

		batcher->fill_triangle(*this, positions, triangle_colors, 4*3);

	}
}