Getaspectratio: Difference between revisions

From ZDoom Wiki
Jump to navigation Jump to search
Content deleted Content added
Agent ME (talk | contribs)
Updated to support vid_aspect cvar, and uses accurate values for #defines
Blzut3 (talk | contribs)
m Optimize away all the FixedMul and FixedDiv. Not sure where the double abs came from (CheckRatio doesn't do it), but can't be bothered to test enough to remove them.
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:getaspectratio}}
{{DISPLAYTITLE:getaspectratio}}
Returns the aspect ratio of the user's resolution by using nearly the same method ZDoom uses internally. Requires the [[abs]] function.
Returns the aspect ratio of the user's resolution by using nearly the same method ZDoom uses internally. Requires the [[abs]] function.
<pre>#define ASPECT_4_3 (4.0 / 3)
#define ASPECT_5_4 1.25
#define ASPECT_16_9 (16.0 / 9)
#define ASPECT_16_10 1.6


#define ASPECT_4_3 (4.0 / 3)
function int getaspectratio(void)
#define ASPECT_5_4 1.25
{
#define ASPECT_16_9 (16.0 / 9)
int width = getcvar("vid_defwidth");
#define ASPECT_16_10 1.6
int height = getcvar("vid_defheight");
#define ASPECT_17_10 1.7
int nowidescreen = getcvar("vid_nowidescreen");
int tft = getcvar("vid_tft");
function int getaspectratio(void)
int aspect = getcvar("vid_aspect");
{
switch(aspect)
int width = [[GetCVar]]("vid_defwidth");
{
int height = [[GetCVar]]("vid_defheight");
case 1: return ASPECT_16_9;
int nowidescreen = [[GetCVar]]("vid_nowidescreen");
case 2: return ASPECT_16_10;
int tft = [[GetCVar]]("vid_tft");
case 3: return ASPECT_4_3;
int aspect = [[GetCVar]]("vid_aspect");
case 4: return ASPECT_5_4;
switch(aspect)
}
{
if(nowidescreen)
case 1: return ASPECT_16_9;
{
case 2: return ASPECT_16_10;
if(!tft)
return ASPECT_4_3;
case 3: return ASPECT_4_3;
case 4: return ASPECT_5_4;
if(fixedmul(height<<16, fixeddiv(5.0, 4.0)) == width<<16)
return ASPECT_5_4;
case 5: return ASPECT_17_10;
}
else
if(nowidescreen)
return ASPECT_4_3;
{
}
if(!tft)
if(abs((abs(fixedmul(height<<16, fixeddiv(16.0, 9.0)))>>16) - width) < 10)
return ASPECT_4_3;
{
if(height * ASPECT_5_4 == width<<16)
return ASPECT_16_9;
return ASPECT_5_4;
}
else
if(abs((abs(fixedmul(height<<16, fixeddiv(16.0, 10.0)))>>16) - width) < 60)
return ASPECT_4_3;
{
}
if((width == 320 && height == 200) || (width == 640 && height == 400))
if(abs((abs(height * ASPECT_16_9)>>16) - width) < 10)
return ASPECT_4_3;
{
return ASPECT_16_10;
return ASPECT_16_9;
}
}
if(fixedmul(height<<16, fixeddiv(5.0, 4.0))>>16 == width && tft)
if(abs((abs(height * ASPECT_17_10)>>16) - width) < 10)
{
{
return ASPECT_5_4;
return ASPECT_17_10;
}
}
return ASPECT_4_3;
if(abs((abs(height * ASPECT_16_10)>>16) - width) < 60)
}</pre>
{
if((width == 320 && height == 200) || (width == 640 && height == 400))
return ASPECT_4_3;
return ASPECT_16_10;
}
if((height * ASPECT_5_4)>>16 == width && tft)
{
return ASPECT_5_4;
}
return ASPECT_4_3;
}

[[category:Sample ACS functions]]

Latest revision as of 07:11, 7 December 2015

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 (4.0 / 3)
#define ASPECT_5_4 1.25
#define ASPECT_16_9 (16.0 / 9)
#define ASPECT_16_10 1.6
#define ASPECT_17_10 1.7

function int getaspectratio(void)
{
	int width = GetCVar("vid_defwidth");
	int height = GetCVar("vid_defheight");
	int nowidescreen = GetCVar("vid_nowidescreen");
	int tft = GetCVar("vid_tft");
	int aspect = GetCVar("vid_aspect");
	switch(aspect)
	{
		case 1:	return ASPECT_16_9;
		case 2:	return ASPECT_16_10;
		case 3:	return ASPECT_4_3;
		case 4:	return ASPECT_5_4;
		case 5: return ASPECT_17_10;
	}
	if(nowidescreen)
	{
		if(!tft)
			return ASPECT_4_3;
		if(height * ASPECT_5_4 == width<<16)
			return ASPECT_5_4;
		else
			return ASPECT_4_3;
	}
	if(abs((abs(height * ASPECT_16_9)>>16) - width) < 10)
	{
		return ASPECT_16_9;
	}
	if(abs((abs(height * ASPECT_17_10)>>16) - width) < 10)
	{
		return ASPECT_17_10;
	}
	if(abs((abs(height * ASPECT_16_10)>>16) - width) < 60)
	{
		if((width == 320 && height == 200) || (width == 640 && height == 400))
			return ASPECT_4_3;
		return ASPECT_16_10;
	}
	if((height * ASPECT_5_4)>>16 == width && tft)
	{
		return ASPECT_5_4;
	}
	return ASPECT_4_3;
}