示例#1
0
/* Drawing::fitTextureWithin
 * Fits [tex] within the rectangle from [x1,y1] to [x2,y2], centered
 * and keeping the correct aspect ratio. If [upscale] is true the
 * texture will be zoomed to fit the rectangle. Returns the resulting
 * texture rectangle coordinates
 *******************************************************************/
frect_t Drawing::fitTextureWithin(GLTexture* tex, double x1, double y1, double x2, double y2, double padding, double max_scale)
{
	// Ignore null texture
	if (!tex)
		return frect_t();

	double width = x2 - x1;
	double height = y2 - y1;

	// Get image dimensions
	double x_dim = (double)tex->getWidth();
	double y_dim = (double)tex->getHeight();

	// Get max scale for x and y (including padding)
	double x_scale = ((double)width - padding) / x_dim;
	double y_scale = ((double)width - padding) / y_dim;

	// Set scale to smallest of the 2 (so that none of the texture will be clipped)
	double scale = MIN(x_scale, y_scale);

	// Clamp scale to maximum desired scale
	if (scale > max_scale)
		scale = max_scale;

	// Return the fitted rectangle
	return frect_t(x1 + width*0.5 - (scale*tex->getWidth()*0.5),
	               y1 + height*0.5 - (scale*tex->getHeight()*0.5),
	               x1 + width*0.5 + (scale*tex->getWidth()*0.5),
	               y1 + height*0.5 + (scale*tex->getHeight()*0.5));
}
示例#2
0
/* MCALineSelection::MCALineSelection
 * MCALineSelection class constructor
 *******************************************************************/
MCALineSelection::MCALineSelection(long start, vector<MapLine*>& lines, bool select) : MCAnimation(start)
{
	// Init variables
	this->select = select;
	this->fade = 1.0f;

	// Go through list of lines
	for (unsigned a = 0; a < lines.size(); a++)
	{
		if (!lines[a]) continue;

		// Add line
		this->lines.push_back(frect_t(lines[a]->x1(), lines[a]->y1(), lines[a]->x2(), lines[a]->y2()));

		// Calculate line direction tab
		fpoint2_t mid = lines[a]->getPoint(MOBJ_POINT_MID);
		fpoint2_t tab = lines[a]->dirTabPoint();

		this->tabs.push_back(frect_t(mid.x, mid.y, tab.x, tab.y));
	}
}