class "opt_video_adv" (CUIWindow)

function opt_video_adv:__init() super()
end

function opt_video_adv:__finalize()
end

--[[
r1		= 0
r2a		= 1
r2		= 2
r2.5	= 3
r3		= 4
]]

-- R1 only
function only_1_mode(ctrl, _id, _ssample_trb_val, _ssample_cb_val)
	local bEnabled	= _id==0
	ctrl:Enable		(bEnabled)
end

--R1 && R2a
function only_12_mode(ctrl, _id, _ssample_trb_val, _ssample_cb_val)
	local bEnabled	= _id<=1
	ctrl:Enable		(bEnabled)
end

-- >=R2a
function only_2a_and_more_mode(ctrl, _id, _ssample_trb_val, _ssample_cb_val)
	local bEnabled	= _id>=1
	ctrl:Enable		(bEnabled)
end

-- >=R2
function only_2_and_more_mode(ctrl, _id, _ssample_trb_val, _ssample_cb_val)
	local bEnabled	= _id>=2
	ctrl:Enable		(bEnabled)
end

-- >=R2.5
function only_25_and_more_mode(ctrl, _id, _ssample_trb_val, _ssample_cb_val)
	local bEnabled	= _id>=3
	ctrl:Enable		(bEnabled)
end

-- >=R3
function only_3_and_more_mode(ctrl, _id, _ssample_trb_val, _ssample_cb_val)
	local bEnabled	= _id>=4
	ctrl:Enable		(bEnabled)
end

function only_r3_and_r3msaa_more_than_zero(ctrl, _id, _ssample_trb_val, _ssample_cb_val)
	local bEnabled	= (_id>=4) and (_ssample_cb_val>0)
	
	
	ctrl:Enable		(bEnabled)
end

function only_3_and_more_mode_visible(ctrl, _id, _ssample_trb_val, _ssample_cb_val)
	local bEnabled	= _id>=4
	ctrl:Enable		(bEnabled)
	ctrl:Show		(bEnabled)
end

function only_3_and_more_mode_invisible(ctrl, _id, _ssample_trb_val, _ssample_cb_val)
	local bEnabled	= _id<4
	ctrl:Enable		(bEnabled)
	ctrl:Show		(bEnabled)
end



function supersample_more_than_1(ctrl, _id, _ssample_trb_val, _ssample_cb_val)
	local bEnabled	= _ssample_trb_val>1
	ctrl:Enable		(bEnabled)
end

function dx_level_ge_655361(ctrl, _id, _ssample_trb_val, _ssample_cb_val)
	local bEnabled	= render_get_dx_level()>=655361
	ctrl:Enable		(bEnabled)
end

function opt_video_adv:InitControls(x, y, xml, handler)
	local ctl

	self:SetWndPos(vector2():set(x,y))
	self:SetWndSize(vector2():set(738,416))
	
	self:SetAutoDelete							(true)
	
	self.bk			= xml:InitFrame				("frame_videoadv", self)
	self.scroll_v	= xml:InitScrollView		("video_adv:scroll_v", self)

	local _st		= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_vis_dist",				_st)
	xml:InitTrackBar							("video_adv:track_vis_dist",			_st)

	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_geometry_lod",			_st)
	xml:InitTrackBar							("video_adv:track_geometry_lod",		_st)


	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_texture_lod",			_st)
	xml:InitTrackBar							("video_adv:track_texture_lod",			_st)
	
	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_aniso",					_st)
	xml:InitTrackBar							("video_adv:track_aniso",				_st)
	
--    
	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_ssample",				_st)
	ctl				= xml:InitTrackBar			("video_adv:track_ssample",				_st)
	handler.ss_trb	= ctl
	handler:Register(ctl, "trb_ssample")
	handler.m_preconditions[ctl]				= only_3_and_more_mode_invisible

	ctl				= xml:InitComboBox			("video_adv:combo_ssample",				_st)
	handler.ss_cb	= ctl
	handler:Register(ctl, "cb_ssample")
	handler.m_preconditions[ctl]				= only_3_and_more_mode_visible
          
	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_detail_density",		_st)
	xml:InitTrackBar							("video_adv:track_detail_density",		_st)


	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_r2_sun",				_st)
	ctl			= xml:InitCheck					("video_adv:check_r2_sun",				_st)
	handler.m_preconditions[ctl]		= only_2_and_more_mode
	
	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_light_distance",		_st)
	ctl				= xml:InitTrackBar			("video_adv:track_light_distance",		_st)
	handler.m_preconditions[ctl]		= only_2a_and_more_mode

	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_particles_distance",	_st)
	ctl				= xml:InitTrackBar			("video_adv:track_particles_distance",	_st)
	handler.m_preconditions[ctl]		= only_2a_and_more_mode

	_st											= xml:InitStatic						("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_npc_torch",				_st)
	xml:InitCheck								("video_adv:check_npc_torch",			_st)

-- r1_no_detail_textures	r1 only
	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_r1_no_detail_textures",	_st)
	ctl			= xml:InitCheck					("video_adv:check_r1_no_detail_textures",_st)
	handler.m_preconditions[ctl]		= only_1_mode

-- r2_detail_bump			=>r2
	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_r2_detail_bump",	_st)
	ctl			= xml:InitCheck					("video_adv:check_r2_detail_bump",_st)
	handler.m_preconditions[ctl]		= only_2_and_more_mode

-- r2_steep_parallax		>r2
	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_r2_steep_parallax",	_st)
	ctl			= xml:InitCheck					("video_adv:check_r2_steep_parallax",_st)
	handler.m_preconditions[ctl]		= only_25_and_more_mode

	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_r2_sun_quality",	_st)
	ctl			= xml:InitComboBox				("video_adv:list_r2_sun_quality",_st)
	handler.m_preconditions[ctl]		= only_25_and_more_mode

	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_sun_shafts",			_st)
	ctl				= xml:InitComboBox			("video_adv:combo_sun_shafts",			_st)
	handler.m_preconditions[ctl]		= only_25_and_more_mode

	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_ssao",					_st)
	ctl				= xml:InitComboBox			("video_adv:combo_ssao",				_st)
	handler.m_preconditions[ctl]		= only_25_and_more_mode

	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_soft_water",			_st)
	ctl				= xml:InitCheck				("video_adv:check_soft_water",			_st)
	handler.m_preconditions[ctl]		= only_25_and_more_mode

	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_soft_particles",		_st)
	ctl				= xml:InitCheck				("video_adv:check_soft_particles",		_st)
	handler.m_preconditions[ctl]		= only_25_and_more_mode

	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_dof",					_st)
	ctl				= xml:InitCheck				("video_adv:check_dof",					_st)
	handler.m_preconditions[ctl]		= only_25_and_more_mode

	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_volumetric_light",		_st)
	ctl				= xml:InitCheck				("video_adv:check_volumetric_light",	_st)
	handler.m_preconditions[ctl]		= only_25_and_more_mode

-- r3_dynamic_wet_surfaces	>r25
	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_r3_dynamic_wet_surfaces",	_st)
	ctl			= xml:InitCheck					("video_adv:check_r3_dynamic_wet_surfaces",_st)
	handler.m_preconditions[ctl]				= only_3_and_more_mode
	
-- r3_volumetric_smoke		>r25
	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_r3_volumetric_smoke",	_st)
	ctl			= xml:InitCheck					("video_adv:check_r3_volumetric_smoke",_st)
	handler.m_preconditions[ctl]				= only_3_and_more_mode
	

	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_r3_msaa_alphatest",	_st)
	ctl			= xml:InitComboBox				("video_adv:combo_r3_msaa_alphatest",_st)
	handler.m_preconditions[ctl]				= only_r3_and_r3msaa_more_than_zero
	handler.r3_msaa_alphatest					= ctl
	
	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_r3_msaa_opt",	_st)
	ctl			= xml:InitCheck					("video_adv:check_r3_msaa_opt",_st)
	handler.m_preconditions[ctl]				= dx_level_ge_655361
	handler.chk_r3_msaa_opt						= ctl
	handler:Register							(ctl, "check_r3_msaa_opt")	


	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_vsync",					_st)
	xml:InitCheck								("video_adv:check_vsync",				_st)
	
	_st				= xml:InitStatic			("video_adv:templ_item",				self.scroll_v)
	xml:InitStatic								("video_adv:cap_60hz",					_st)
	xml:InitCheck								("video_adv:check_60hz",				_st)

	btn		= xml:Init3tButton					("video_adv:btn_to_simply",	self)	
	handler:Register							(btn, "btn_simply_graphic")	
end
