KF2-Server-Extension/ServerExt/Classes/KFGUI_ScrollBarBase.uc

114 lines
2.5 KiB
Ucode
Raw Normal View History

2017-10-20 02:00:49 +00:00
Class KFGUI_ScrollBarBase extends KFGUI_Clickable
abstract;
var() int MaxRange,ScrollStride,PageStep;
var() float ButtonScale; // Button width (scaled by default font height).
var int CurrentScroll;
// In-runtime values.
var transient float CalcButtonScale;
var transient int SliderScale,ButtonOffset,GrabbedOffset;
var transient bool bGrabbedScroller;
var bool bVertical;
2020-11-28 20:04:55 +00:00
final function UpdateScrollSize(int Current, int MxRange, int Stride, int StepStride)
2017-10-20 02:00:49 +00:00
{
MaxRange = MxRange;
ScrollStride = Stride;
PageStep = StepStride;
SetValue(Current);
}
2020-11-28 20:04:55 +00:00
final function AddValue(int V)
2017-10-20 02:00:49 +00:00
{
SetValue(CurrentScroll+V);
}
2020-11-28 20:04:55 +00:00
final function SetValue(int V)
2017-10-20 02:00:49 +00:00
{
CurrentScroll = Clamp((V / ScrollStride) * ScrollStride,0,MaxRange);
OnScrollChange(Self,CurrentScroll);
}
final function int GetValue()
{
return CurrentScroll;
}
2020-11-28 20:04:55 +00:00
Delegate OnScrollChange(KFGUI_ScrollBarBase Sender, int Value);
2017-10-20 02:00:49 +00:00
// Get UI width.
function float GetWidth()
{
CalcButtonScale = ButtonScale*Owner.CurrentStyle.DefaultHeight;
return CalcButtonScale / (bVertical ? InputPos[2] : InputPos[3]);
}
function PreDraw()
{
// Auto scale to match width to screen size.
2020-11-28 20:04:55 +00:00
if(bVertical)
2017-10-20 02:00:49 +00:00
XSize = GetWidth();
else YSize = GetWidth();
Super.PreDraw();
}
function DrawMenu()
{
Owner.CurrentStyle.RenderScrollBar(Self);
}
2020-11-28 20:04:55 +00:00
function MouseClick(bool bRight)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:04:55 +00:00
if(bRight || bDisabled)
2017-10-20 02:00:49 +00:00
return;
bPressedDown = true;
PlayMenuSound(MN_ClickButton);
2020-11-28 20:04:55 +00:00
if(bVertical)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:04:55 +00:00
if(Owner.MousePosition.Y>=(CompPos[1]+ButtonOffset) && Owner.MousePosition.Y<=(CompPos[1]+ButtonOffset+SliderScale)) // Grabbed scrollbar!
2017-10-20 02:00:49 +00:00
{
GrabbedOffset = Owner.MousePosition.Y - (CompPos[1]+ButtonOffset);
bGrabbedScroller = true;
GetInputFocus();
}
2020-11-28 20:04:55 +00:00
else if(Owner.MousePosition.Y<(CompPos[1]+ButtonOffset)) // Page up.
2017-10-20 02:00:49 +00:00
AddValue(-PageStep);
else AddValue(PageStep);
}
else
{
2020-11-28 20:04:55 +00:00
if(Owner.MousePosition.X>=(CompPos[0]+ButtonOffset) && Owner.MousePosition.X<=(CompPos[0]+ButtonOffset+SliderScale)) // Grabbed scrollbar!
2017-10-20 02:00:49 +00:00
{
GrabbedOffset = Owner.MousePosition.X - (CompPos[0]+ButtonOffset);
bGrabbedScroller = true;
GetInputFocus();
}
2020-11-28 20:04:55 +00:00
else if(Owner.MousePosition.X<(CompPos[0]+ButtonOffset)) // Page left.
2017-10-20 02:00:49 +00:00
AddValue(-PageStep);
else AddValue(PageStep);
}
}
2020-11-28 20:04:55 +00:00
function MouseRelease(bool bRight)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:04:55 +00:00
if(!bRight)
2017-10-20 02:00:49 +00:00
DropInputFocus();
}
function LostInputFocus()
{
bGrabbedScroller = false;
bPressedDown = false;
}
2020-11-28 20:04:55 +00:00
function ScrollMouseWheel(bool bUp)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:04:55 +00:00
if(bDisabled)
2017-10-20 02:00:49 +00:00
return;
2020-11-28 20:04:55 +00:00
if(bUp)
2017-10-20 02:00:49 +00:00
AddValue(-ScrollStride);
else AddValue(ScrollStride);
}
defaultproperties
{
MaxRange=100
ScrollStride=1
PageStep=10
ButtonScale=1
}