-------------------------------
-- CakeScript Generation 2
-- Author: LuaBanana ( Aka Jake )
-- Project Start: 5/24/2008
--
-- vgui/cakevgui.lua
-- A set of functions for the VGUI Panels
-------------------------------

-- ALL elements that will be rescaled should have been perfected on a 1024x768 resolution, or it will NOT look right.

-- This function was made to rescale and reposition elements for different resolutions.
-- This is to be used only by buttons, frames, and other sizable elements.
-- The only parameter to be passed is the element you want autoscaled.
function AutoScaleGUI( IPanelElement )

	-- Get the current resolution
	local scr_w = ScrW( );
	local scr_h = ScrH( );
	
	-- Calculate the Scale Factor
	local scale_w = scr_w / 1024;
	local scale_h = scr_h / 768;
	
	-- Get the current size of element
	local e_Width, e_Height = IPanelElement:GetSize( );
	
	-- Get the current position of element
	local e_PosX, e_PosY = IPanelElement:GetPos( );
	
	-- Calculate the new size
	e_Width = math.ceil( e_Width * scale_w );
	e_Height = math.ceil( e_Height * scale_h );
	
	-- Calculate the new position
	e_PosX = math.ceil( e_PosX * scale_w );
	e_PosY = math.ceil( e_PosY * scale_h );
	
	-- Set the new size
	IPanelElement:SetSize( e_Width, e_Height );
	
	-- Set the new position
	IPanelElement:SetPos( e_PosX, e_PosY );
	
end

-- This is used for other things that cannot be resized by the SetSize method.
-- It will return a table with an x and y parameter.
function GetScale( )

	local scr_w = ScrW( );
	local scr_h = ScrH( );
	
	-- Calculate the Scale Factor
	local scale = { };
	
	scale.x = scr_w / 1024;
	scale.y = scr_h / 768;
	
	return scale;
	
end

function CalcX( x )

	return math.ceil( x * GetScale( ).x );
	
end

function CalcY( y )

	return math.ceil( y * GetScale( ).y );
	
end