Ejemplo n.º 1
0
void Canvas::fill_rect(float x1, float y1, float x2, float y2, const Gradient &gradient)
{
	Vec2f positions[6] =
	{
		Vec2f(x1, y1),
		Vec2f(x2, y1),
		Vec2f(x1, y2),
		Vec2f(x2, y1),
		Vec2f(x1, y2),
		Vec2f(x2, y2)
	};

	Vec4f colors[6] =
	{
		Vec4f(gradient.top_left),
		Vec4f(gradient.top_right),
		Vec4f(gradient.bottom_left),
		Vec4f(gradient.top_right),
		Vec4f(gradient.bottom_left),
		Vec4f(gradient.bottom_right)
	};

	RenderBatchTriangle *batcher = impl->batcher.get_triangle_batcher();
	batcher->fill_triangle(*this, positions, colors, 6);

}
Ejemplo n.º 2
0
void Canvas::fill_triangles(const std::vector<Vec2f> &triangles, const Colorf &color)
{
	if (!triangles.empty())
	{
		RenderBatchTriangle *batcher = impl->batcher.get_triangle_batcher();
		batcher->fill_triangle(*this, &triangles[0], color, triangles.size());
	}
}
Ejemplo n.º 3
0
void Canvas::fill_triangles(const std::vector<Vec2f> &triangles, const Gradient &gradient)
{
	if (!triangles.empty())
	{
		std::vector<Colorf> colors;
		Canvas_Impl::get_gradient_colors(&triangles[0], triangles.size(), gradient, colors);

		RenderBatchTriangle *batcher = impl->batcher.get_triangle_batcher();
		batcher->fill_triangle(*this, &triangles[0], &colors[0], triangles.size());

	}
}
Ejemplo n.º 4
0
void Canvas::fill_triangles(const Vec2f *triangle_positions, int num_vertices, const Gradient &gradient)
{
	if (num_vertices)
	{
		std::vector<Colorf> colors;
		Canvas_Impl::get_gradient_colors(triangle_positions, num_vertices, gradient, colors);

		RenderBatchTriangle *batcher = impl->batcher.get_triangle_batcher();
		batcher->fill_triangle(*this, triangle_positions, &colors[0], num_vertices);

	}
}
Ejemplo n.º 5
0
void Canvas::fill_triangle(const Pointf &a, const Pointf &b, const Pointf &c, const Colorf &color)
{
	Vec2f positions[3] =
	{
		Vec2f(a.x, a.y),
		Vec2f(b.x, b.y),
		Vec2f(c.x, c.y)
	};

	RenderBatchTriangle *batcher = impl->batcher.get_triangle_batcher();
	batcher->fill_triangle(*this, positions, color, 3);
}
Ejemplo n.º 6
0
void Canvas::fill_triangles(const Vec2f *triangle_positions, const Colorf *colors, int num_vertices)
{
	RenderBatchTriangle *batcher = impl->batcher.get_triangle_batcher();
	batcher->fill_triangle(*this, triangle_positions, colors, num_vertices);
}
Ejemplo n.º 7
0
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);

	}
}