getaspectratio

From ZDoom Wiki

Jump to: navigation, search

Returns the aspect ratio of the user's resolution by using nearly the same method ZDoom uses internally. Requires the abs function.

#define ASPECT_4_3 1.3
#define ASPECT_5_4 1.25
#define ASPECT_16_9 1.7
#define ASPECT_16_10 1.6

function int getaspectratio(void)
{
	int width = getcvar("vid_defwidth");
	int height = getcvar("vid_defheight");
	int nowidescreen = getcvar("vid_nowidescreen");
	int tft = getcvar("vid_tft");
	if(nowidescreen)
	{
		if(!tft)
			return ASPECT_4_3;
		if(fixedmul(height<<16, fixeddiv(5.0, 4.0)) == width<<16)
			return ASPECT_5_4;
		else
			return ASPECT_4_3;
	}
	if(abs((abs(fixedmul(height<<16, fixeddiv(16.0, 9.0)))>>16) - width) < 10)
	{
		return ASPECT_16_9;
	}
	if(abs((abs(fixedmul(height<<16, fixeddiv(16.0, 10.0)))>>16) - width) < 60)
	{
		if((width == 320 && height == 200) || (width == 640 && height == 400))
			return ASPECT_4_3;
		return ASPECT_16_10;
	}
	if(fixedmul(height<<16, fixeddiv(5.0, 4.0))>>16 == width && tft)
	{
		return ASPECT_5_4;
	}
	return ASPECT_4_3;
}
Personal tools