Example #1
0
void Shape2D::add_rect(const Rectf &rect, const Angle &angle, bool reverse)
{
	Path2D path;

	Pointf point_1(rect.left, rect.top);
	Pointf point_2(rect.right, rect.top);
	Pointf point_3(rect.right, rect.bottom);
	Pointf point_4(rect.left, rect.bottom);

	if (angle.to_radians() != 0.0f)
	{
		Pointf center = rect.get_center();
		point_1.rotate(center, angle);
		point_2.rotate(center, angle);
		point_3.rotate(center, angle);
		point_4.rotate(center, angle);
	}

	path.add_line_to(point_1);
	path.add_line_to(point_2);
	path.add_line_to(point_3);
	path.add_line_to(point_4);

	if (reverse)
		path.reverse();

	add_path(path);
}
Example #2
0
void Shape2D::add_rounded_rect(const Pointf &origin, const Sizef &size, float cap_rounding, const Angle &angle, bool reverse)
{
	// sanitize rounding values
	float tmp_rounding = cap_rounding;
	float min_rounding = min(size.width/2.0f, size.height/2.0f);
	if( tmp_rounding >= (min_rounding-0.01f) ) // 0.01: hysterezis for floating point errors
	{
		tmp_rounding = min_rounding-0.01f; // avoid duplicating curve endpoints 
	}

	Path2D path;
	Pointf center(origin.x + size.width / 2.0f,  origin.y + size.height / 2.0f);

	// top right curve
	Shape2D_Impl::add_rotated_curve(path, center, angle,
		Pointf(origin.x + size.width-tmp_rounding, origin.y),
		Pointf(origin.x + size.width, origin.y),
		Pointf(origin.x + size.width, origin.y + tmp_rounding));

	// bottom right curve
	Shape2D_Impl::add_rotated_curve(path, center, angle, 
		Pointf(origin.x + size.width, origin.y + size.height-tmp_rounding),
		Pointf(origin.x + size.width, origin.y + size.height),
		Pointf(origin.x + size.width-tmp_rounding, origin.y + size.height));
	
	// bottom left curve
	Shape2D_Impl::add_rotated_curve(path, center, angle, 
		Pointf(origin.x + tmp_rounding, origin.y + size.height),
		Pointf(origin.x, origin.y + size.height),
		Pointf(origin.x, origin.y + size.height-tmp_rounding));

	// top left curve
	Shape2D_Impl::add_rotated_curve(path, center, angle, 
		Pointf(origin.x, origin.y +tmp_rounding),
		Pointf(origin.x, origin.y),
		Pointf(origin.x + tmp_rounding, origin.y));
	
	if (reverse)
		path.reverse();

	add_path(path);
}
Example #3
0
void Shape2D::add_ellipse(const Pointf &center, const Pointf &radius, bool reverse)
{
	float offset_x = 0;
	float offset_y = 0;

	int max_radius = max(radius.x, radius.y);

	int rotationcount = max(5, (max_radius - 3));
	float halfpi = 1.5707963267948966192313216916398f;
	float turn = halfpi / rotationcount;

	offset_x = center.x;
	offset_y = -center.y;

	Path2D path;

	rotationcount *= 4;

	std::vector<Pointf> points;
	points.resize(rotationcount);

	for(int i = 0; i < rotationcount ; i++)
	{
		float pos1 = radius.x * cos(i * turn);
		float pos2 = radius.y * sin(i * turn);

		points[i].x = (center.x + pos1);
		points[i].y = (center.y + pos2);
	}

	path.add_line_to(points);

	if (reverse)
		path.reverse();

	add_path(path);
}