KF2-YetAnotherScoreboard/YAS/Classes/KFGUI_ScrollBarBase.uc

123 lines
2.7 KiB
Ucode
Raw Normal View History

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