local PANEL = {}
local MAX_ANGLE_X = 100
local MAX_ANGLE_Y = 100
/*---------------------------------------------------------
Name: Init
---------------------------------------------------------*/
function PANEL:Init()
self.Value = { 0, 0 }
self.UpdateTimer = 0
// Don't update convars straight away.
// The parent will feed mouse presses to us
end
/*---------------------------------------------------------
Name: PerformLayout
---------------------------------------------------------*/
function PANEL:PerformLayout()
end
/*---------------------------------------------------------
Name: SetVarName
---------------------------------------------------------*/
function PANEL:SetVarName( _name_ )
self.VarName = _name_
end
/*---------------------------------------------------------
Name: SetRestrictX
Desc: Restrict movement on the X axis.
---------------------------------------------------------*/
function PANEL:SetRestrictX( bRestrict )
self.RestrictX = bRestrict
end
/*---------------------------------------------------------
Name: IsRestricted
---------------------------------------------------------*/
function PANEL:IsRestricted()
return self.RestrictX
&& ConVar_RestrictFingers:
GetBool()
end
/*---------------------------------------------------------
Name: GetValue
Desc: Returns the normalized value
---------------------------------------------------------*/
return { self.Value[1] / MAX_ANGLE_X, self.Value[2] / MAX_ANGLE_Y }
end
/*---------------------------------------------------------
Name: UpdateConVar
---------------------------------------------------------*/
function PANEL:UpdateConVar()
if (!self.VarName) then return end
if ( self.NextUpdate
> CurTime() ) then return end
local Val
= Format( "%.2f %.2f", self.Value
[1], self.Value
[2] )
end
/*---------------------------------------------------------
Name: SetValue
---------------------------------------------------------*/
function PANEL:SetValue( x, y )
if ( self:IsRestricted() ) then x = 0 end
self.Value = { x, y }
end
/*---------------------------------------------------------
Name: OnMousePressed
---------------------------------------------------------*/
function PANEL:OnMousePressed( mousecode )
if ( mousecode == MOUSE_RIGHT ) then
self:SetValue( 0, 0 )
self:UpdateConVar()
return end
self.Dragging = 1
end
/*---------------------------------------------------------
Name: OnMouseReleased
---------------------------------------------------------*/
function PANEL:OnMouseReleased()
self.Dragging = nil
end
/*---------------------------------------------------------
Name: OnCursorMoved
---------------------------------------------------------*/
function PANEL:OnCursorMoved( x, y )
if (!self.Dragging) then return end
self:SetValue( (x/w) - 0.5, (y/h) - 0.5 )
self:UpdateConVar()
end
/*---------------------------------------------------------
Name: Think
---------------------------------------------------------*/
function PANEL:Think()
if ( self.UpdateTimer
> CurTime() ) then return end
end
/*---------------------------------------------------------
Name: Paint
---------------------------------------------------------*/
function PANEL:Paint()
//surface.SetDrawColor( 0, 0, 0, 100 )
//surface.DrawRect( 0, 0, w, h )
local x = (v[1] * w) + w/2
local y = (v[2] * h) + h/2
end