## XIDInterf
Class XIIIHSliderControl

source: C:\XIII\XIDInterf\Classes\XIIIHSliderControl.uc

    Core.Object
       |
       +--GUI.GUI
          |
          +--GUI.GUIComponent
             |
             +--GUI.GUILabel
                |
                +--XIDInterf.XIIIGUIBaseButton
                   |
                   +--XIDInterf.XIIIHSliderControl

Direct Known Subclasses:None

class XIIIHSliderControl
extends XIDInterf.XIIIGUIBaseButton

    //===========================================================================

Variables
`TextY,` | `CanvasClipX`
`float` | `CanvasOrgX`
`NotchColor,` | `CursorColor`
`SliderWidth,` | `GlobalSliderX`
`int` | `NbMultiSplit`
`bool` | `bShowBordersOnlyWhenFocused`
`tArrowL,` | `tArrowR`

Function Summary
`void` | `Adjust(float amount)`
`void` | `BeforePaint(Canvas C, float X, float Y)`
`float` | `GetValue()`
`void` | `InitComponent(GUIController MyController, GUIComponent MyOwner)`
    //===========================================================================
`bool` | `InternalCapturedMouseMove(float deltaX, float deltaY)`
`bool` | `InternalOnKeyEvent(out byte, out byte, float delta)`
`void` | `MyDrawLine(Canvas C, float X1, float Y1, float X2, float Y2, Color col)`
`void` | `Paint(Canvas C, float X, float Y)`
`void` | `SetRange(float Min, float Max, float NewStep, optional float)`
`void` | `SetValue(float NewValue)`

Source Code

    00001	//===========================================================================
    00002	class XIIIHSliderControl extends XIIIGUIBaseButton;
    00003
    00004	var float Value, MinValue, MaxValue, Step, SliderPosX, SliderWidth, GlobalSliderX;
    00005	var float TextX, TextY, CanvasClipX;
    00006	var bool bShowBordersOnlyWhenFocused;
    00007	var texture tArrowL, tArrowR;
    00008	var Color NotchColor, CursorColor;
    00009	var int NbMultiSplit;
    00010	VAR float CanvasOrgX;
    00011
    00012	//===========================================================================
    00013	function InitComponent(GUIController MyController, GUIComponent MyOwner)
    00014	{
    00015		Super.InitComponent(MyController, MyOwner);
    00016	    OnKeyEvent = InternalOnKeyEvent;
    00017		TextAlign = TXTA_Center;
    00018	}
    00019
    00020
    00021	function SetValue(float NewValue)
    00022	{
    00023		NewValue = fClamp(NewValue,MinValue,MaxValue);
    00024		Value = NewValue;
    00025	}
    00026
    00027
    00028	function float GetValue()
    00029	{
    00030		return Value;
    00031	}
    00032
    00033
    00034	function SetRange(float Min, float Max, float NewStep, optional float newSlidePos)
    00035	{
    00036		MinValue = Min;
    00037		MaxValue = Max;
    00038		Step = NewStep;
    00039		SliderPosX = NewSlidePos;
    00040	}
    00041
    00042
    00043	function BeforePaint(Canvas C, float X, float Y)
    00044	{
    00045	    local float W, H;
    00046
    00047		SliderWidth = WinWidth*640 - SliderPosX;
    00048		C.TextSize( Text, W, H);
    00049		TextX = (SliderPosX*fRatioX-6-W)*0.5; //*fRatioX;
    00050		TextY = (WinHeight*480*fRatioY - H)/2;
    00051	}
    00052
    00053	FUNCTION MyDrawLine( Canvas C, float X1, float Y1, float X2, float Y2, Color col )
    00054	{
    00055		X1 += C.OrgX;
    00056		X2 += C.OrgX;
    00057		Y1 += C.OrgY;
    00058		Y2 += C.OrgY;
    00059
    00060		C.DrawLine( X1, Y1, X2, Y2, col );
    00061	}
    00062
    00063	function Paint(Canvas C, float X, float Y)
    00064	{
    00065		LOCAL float CursorWidth, PosCursorX, PosCursorY, tmpX;
    00066		LOCAL int i;
    00067
    00068		Super.Paint(C, X, Y);
    00069
    00070		CanvasClipX = C.ClipX;
    00071		CanvasOrgX = C.OrgX;
    00072
    00073		C.Font = font'XIIIFonts.PoliceF16';
    00074		GlobalSliderX = C.OrgX+SliderPosX*fRatioX;
    00075
    00076		// text box and slider display
    00077		if (bHasFocus)
    00078			BackColor.A = 255;
    00079		else
    00080			BackColor.A = 128;
    00081		C.DrawColor = BackColor;
    00082		C.bUseBorder = !bShowBordersOnlyWhenFocused || bHasFocus;
    00083		DrawStretchedTexture(C, 0, 0, (SliderPosX-6)*fRatioX, WinHeight*480*fRatioY, myRoot.FondMenu);
    00084		BackColor.A = 255;
    00085		C.DrawColor = BackColor;
    00086		C.bUseBorder = false;
    00087
    00088	    DrawStretchedTexture(C, (SliderPosX)*fRatioX-1, 40*WinHeight*fRatioY, 16*fRatioX, WinHeight*400*fRatioY, tArrowL);
    00089		C.bUseBorder = true;
    00090	    DrawStretchedTexture(C, (SliderPosX+13)*fRatioX, 40*WinHeight*fRatioY, (SliderWidth-30)*fRatioX, WinHeight*400*fRatioY, myRoot.FondMenu);
    00091		C.bUseBorder = false;
    00092	    DrawStretchedTexture(C, (SliderPosX+SliderWidth-12)*fRatioX+1, 40*WinHeight*fRatioY, 16*fRatioX, WinHeight*400*fRatioY, tArrowR);
    00093
    00094		// text display
    00095		C.DrawColor = TextColor;
    00096		C.Style = 5;
    00097		C.DrawColor.A = 255;
    00098		C.Style = 1;
    00099		C.SetPos(TextX,TextY);
    00100		C.DrawText(/*Caps*/(Text), false);
    00101		C.DrawColor = BackColor;
    00102
    00103		CursorWidth = 6*fMin(1,fRatioX);
    00104		PosCursorY = (WinHeight*90)*fRatioY;
    00105
    00106		MyDrawLine( C, (SliderPosX+13+CursorWidth*0.5)*fRatioX, 240*WinHeight*fRatioY, (SliderPosX+13+SliderWidth-30-CursorWidth*0.5)*fRatioX, 240*WinHeight*fRatioY, NotchColor );
    00107
    00108		for ( i=MinValue; i<=MaxValue; i+=Step )
    00109		{
    00110			tmpX = SliderPosX+13+(i-MinValue)*(SliderWidth-30-CursorWidth) / (MaxValue - MinValue)+CursorWidth*0.5;
    00111
    00112			MyDrawLine( C, tmpX*fRatioX, 160*WinHeight*fRatioY, tmpX*fRatioX, 320*WinHeight*fRatioY, NotchColor );
    00113		}
    00114		// cursor display
    00115		PosCursorX = (SliderPosX+13)*fRatioX + ((SliderWidth-30)*fRatioX-CursorWidth)*( (Value - MinValue) / (MaxValue - MinValue) );
    00116	//        DrawStretchedTexture(C, PosCursorX*fRatioX, PosCursorY, CursorWidth, 20*fRatioY, tCursor);
    00117		C.bUseBorder = true;
    00118		C.DrawColor = CursorColor;
    00119	    DrawStretchedTexture(C, PosCursorX, PosCursorY, CursorWidth, WinHeight*300*fRatioY, myRoot.FondMenu);
    00120		C.DrawColor = C.MakeColor(255,255,255,255);
    00121		C.bUseBorder = false;
    00122	}
    00123
    00124
    00125	function bool InternalCapturedMouseMove(float deltaX, float deltaY)
    00126	{
    00127		LOCAL float Perc, OldValue, RelativeX;
    00128
    00129		RelativeX = ((Controller.MouseX-CanvasOrgX)/fRatioX-SliderPosX-13)/(SliderWidth-30);
    00130
    00131		OldValue = Value;
    00132		if ( RelativeX < 0)
    00133	            Adjust(-Step);
    00134		else if (RelativeX > 1)
    00135	            Adjust(Step);
    00136		else
    00137			Value = (step*int((RelativeX*(MaxValue - MinValue)+0.5*step)/step))+MinValue;
    00138
    00139		Value = FClamp(Value,MinValue,MaxValue);
    00140		if ( Value!=OldValue )
    00141			OnChange( self );
    00142
    00143		return true;
    00144	}
    00145
    00146
    00147	function bool InternalOnKeyEvent(out byte Key, out byte State, float delta)
    00148	{
    00149		if ((Key == 0x01) && ( State==1 ))
    00150			InternalCapturedMouseMove(0,0);
    00151
    00152
    00153		if ( (Key==0x25 /*|| Key==0x64 || Key==0xEC*/) && ((State==1) || (State==2)))	// Left
    00154		{
    00155			Adjust(-Step);
    00156		}
    00157
    00158		if ( (Key==0x27 /*|| Key==0x66 || Key==0xED*/) && ((State==1) || (State==2))) // Right
    00159		{
    00160			Adjust(Step);
    00161		}
    00162
    00163		return false;
    00164	}
    00165
    00166	function Adjust(float amount)
    00167	{
    00168		Value = fClamp(Value+Amount,MinValue,MaxValue);
    00169	}
    00170
    00171
    00172
    00173	defaultproperties
    00174	{
    00175	     tArrowL=Texture'XIIIMenuStart.Control_Console.fleche_gauche'
    00176	     tArrowR=Texture'XIIIMenuStart.Control_Console.fleche_droite'
    00177	     NotchColor=(B=64,G=64,R=64,A=255)
    00178	     CursorColor=(B=224,G=224,R=224,A=255)
    00179	     bRequireReleaseClick=True
    00180	}

End Source Code