Core.Object | +--UWindow.UWindowBase | +--UWindow.UWindowWindow | +--UWindow.UWindowHScrollBar
float
DragX
UWindowSBLeftButton
LeftButton
MaxPos
MaxVisible
MinPos
NextClickTime
Pos
UWindowSBRightButton
RightButton
ScrollAmount
ThumbStart,
ThumbWidth
bool
bDisabled
bDragging
void
BeforePaint(Canvas C, float X, float Y)
CheckRange()
Created()
LMouseDown(float X, float Y)
MouseMove(float X, float Y)
Paint(Canvas C, float X, float Y)
Scroll(float Delta)
SetRange(float NewMinPos, float NewMaxPos, float NewMaxVisible, optional float)
Show(float P)
Tick(float Delta)
00001 //============================================================================= 00002 // UWindowHScrollBar - A horizontal scrollbar 00003 //============================================================================= 00004 class UWindowHScrollBar extends UWindowWindow; 00005 00006 var UWindowSBLeftButton LeftButton; 00007 var UWindowSBRightButton RightButton; 00008 var bool bDisabled; 00009 var float MinPos; 00010 var float MaxPos; 00011 var float MaxVisible; 00012 var float Pos; // offset to WinTop 00013 var float ThumbStart, ThumbWidth; 00014 var float NextClickTime; 00015 var float DragX; 00016 var bool bDragging; 00017 var float ScrollAmount; 00018 00019 function Show(float P) 00020 { 00021 if(P < 0) return; 00022 if(P > MaxPos + MaxVisible) return; 00023 00024 while(P < Pos) 00025 if(!Scroll(-1)) 00026 break; 00027 while(P - Pos > MaxVisible - 1) 00028 if(!Scroll(1)) 00029 break; 00030 } 00031 00032 function bool Scroll(float Delta) 00033 { 00034 local float OldPos; 00035 00036 OldPos = Pos; 00037 Pos = Pos + Delta; 00038 CheckRange(); 00039 return Pos == OldPos + Delta; 00040 } 00041 00042 function SetRange(float NewMinPos, float NewMaxPos, float NewMaxVisible, optional float NewScrollAmount) 00043 { 00044 if(NewScrollAmount == 0) 00045 NewScrollAmount = 1; 00046 00047 ScrollAmount = NewScrollAmount; 00048 MinPos = NewMinPos; 00049 MaxPos = NewMaxPos - NewMaxVisible; 00050 MaxVisible = NewMaxVisible; 00051 00052 CheckRange(); 00053 } 00054 00055 function CheckRange() 00056 { 00057 if(Pos < MinPos) 00058 { 00059 Pos = MinPos; 00060 } 00061 else 00062 { 00063 if(Pos > MaxPos) Pos = MaxPos; 00064 } 00065 00066 bDisabled = (MaxPos <= MinPos); 00067 LeftButton.bDisabled = bDisabled; 00068 RightButton.bDisabled = bDisabled; 00069 00070 if(bDisabled) 00071 { 00072 Pos = 0; 00073 } 00074 else 00075 { 00076 ThumbStart = ((Pos - MinPos) * (WinWidth - (2*LookAndFeel.Size_ScrollbarButtonHeight))) / (MaxPos + MaxVisible - MinPos); 00077 ThumbWidth = (MaxVisible * (WinWidth - (2*LookAndFeel.Size_ScrollbarButtonHeight))) / (MaxPos + MaxVisible - MinPos); 00078 00079 if(ThumbWidth < LookAndFeel.Size_MinScrollbarHeight) 00080 ThumbWidth = LookAndFeel.Size_MinScrollbarHeight; 00081 00082 if(ThumbWidth + ThumbStart > WinWidth - 2*LookAndFeel.Size_ScrollbarButtonHeight) 00083 { 00084 ThumbStart = WinWidth - 2*LookAndFeel.Size_ScrollbarButtonHeight - ThumbWidth; 00085 } 00086 00087 ThumbStart = ThumbStart + LookAndFeel.Size_ScrollbarButtonHeight; 00088 } 00089 } 00090 00091 function Created() 00092 { 00093 Super.Created(); 00094 LeftButton = UWindowSBLeftButton(CreateWindow(class'UWindowSBLeftButton', 0, 0, 10, 12)); 00095 RightButton = UWindowSBRightButton(CreateWindow(class'UWindowSBRightButton', WinWidth-10, 0, 10, 12)); 00096 } 00097 00098 00099 function BeforePaint(Canvas C, float X, float Y) 00100 { 00101 LeftButton.WinTop = 0; 00102 LeftButton.WinLeft = 0; 00103 LeftButton.WinWidth = LookAndFeel.Size_ScrollbarButtonHeight; 00104 LeftButton.WinHeight = LookAndFeel.Size_ScrollbarWidth; 00105 00106 RightButton.WinTop = 0; 00107 RightButton.WinLeft = WinWidth - LookAndFeel.Size_ScrollbarButtonHeight; 00108 RightButton.WinWidth = LookAndFeel.Size_ScrollbarButtonHeight; 00109 RightButton.WinHeight = LookAndFeel.Size_ScrollbarWidth; 00110 00111 CheckRange(); 00112 } 00113 00114 function Paint(Canvas C, float X, float Y) 00115 { 00116 LookAndFeel.SB_HDraw(Self, C); 00117 } 00118 00119 function LMouseDown(float X, float Y) 00120 { 00121 Super.LMouseDown(X, Y); 00122 00123 if(bDisabled) return; 00124 00125 if(X < ThumbStart) 00126 { 00127 Scroll(-(MaxVisible-1)); 00128 NextClickTime = GetLevel().TimeSeconds + 0.5; 00129 return; 00130 } 00131 if(X > ThumbStart + ThumbWidth) 00132 { 00133 Scroll(MaxVisible-1); 00134 NextClickTime = GetLevel().TimeSeconds + 0.5; 00135 return; 00136 } 00137 00138 if((X >= ThumbStart) && (X <= ThumbStart + ThumbWidth)) 00139 { 00140 DragX = X - ThumbStart; 00141 bDragging = True; 00142 Root.CaptureMouse(); 00143 return; 00144 } 00145 } 00146 00147 00148 function Tick(float Delta) 00149 { 00150 local bool bLeft, bRight; 00151 local float X, Y; 00152 00153 if(bDragging) return; 00154 00155 bLeft = False; 00156 bRight = False; 00157 00158 if(bMouseDown) 00159 { 00160 GetMouseXY(X, Y); 00161 bLeft = (X < ThumbStart); 00162 bRight = (X > ThumbStart + ThumbWidth); 00163 } 00164 00165 if(bMouseDown && (NextClickTime > 0) && (NextClickTime < GetLevel().TimeSeconds) && bLeft) 00166 { 00167 Scroll(-(MaxVisible-1)); 00168 NextClickTime = GetLevel().TimeSeconds + 0.1; 00169 } 00170 00171 if(bMouseDown && (NextClickTime > 0) && (NextClickTime < GetLevel().TimeSeconds) && bRight) 00172 { 00173 Scroll(MaxVisible-1); 00174 NextClickTime = GetLevel().TimeSeconds + 0.1; 00175 } 00176 00177 if(!bMouseDown || (!bLeft && !bRight)) 00178 { 00179 NextClickTime = 0; 00180 } 00181 } 00182 00183 function MouseMove(float X, float Y) 00184 { 00185 if(bDragging && bMouseDown && !bDisabled) 00186 { 00187 while(X < (ThumbStart+DragX) && Pos > MinPos) 00188 { 00189 Scroll(-1); 00190 } 00191 00192 while(X > (ThumbStart+DragX) && Pos < MaxPos) 00193 { 00194 Scroll(1); 00195 } 00196 } 00197 else 00198 bDragging = False; 00199 } 00200 00201 defaultproperties 00202 { 00203 }