2020-01-10 13:14:11 +00:00
|
|
|
Class KFGUI_ScrollBarBase extends KFGUI_Clickable
|
2021-05-16 09:40:02 +00:00
|
|
|
abstract;
|
2020-01-10 13:14:11 +00:00
|
|
|
|
2021-06-12 20:11:37 +00:00
|
|
|
`include(Build.uci)
|
|
|
|
`include(Logger.uci)
|
|
|
|
|
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
|
|
|
{
|
2021-05-16 09:40:02 +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
|
|
|
{
|
2021-05-16 09:40:02 +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()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
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()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
CalcButtonScale = ButtonScale*Owner.CurrentStyle.DefaultHeight;
|
|
|
|
return CalcButtonScale / (bVertical ? InputPos[2] : InputPos[3]);
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
function PreDraw()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
// Auto scale to match width to screen size.
|
2021-06-13 02:53:33 +00:00
|
|
|
if (bVertical)
|
2021-05-16 09:40:02 +00:00
|
|
|
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)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
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)
|
2021-05-16 09:40:02 +00:00
|
|
|
return;
|
|
|
|
bPressedDown = true;
|
|
|
|
PlayMenuSound(MN_ClickButton);
|
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
if (bVertical)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (Owner.MousePosition.Y >= (CompPos[1]+ButtonOffset) && Owner.MousePosition.Y <= (CompPos[1]+ButtonOffset+SliderScale) ) // Grabbed scrollbar!
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
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.
|
2021-05-16 09:40:02 +00:00
|
|
|
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!
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
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.
|
2021-05-16 09:40:02 +00:00
|
|
|
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)
|
2021-05-16 09:40:02 +00:00
|
|
|
DropInputFocus();
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function LostInputFocus()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
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)
|
2021-05-16 09:40:02 +00:00
|
|
|
return;
|
2021-06-13 02:53:33 +00:00
|
|
|
if (bUp)
|
2021-05-16 09:40:02 +00:00
|
|
|
AddValue(-ScrollStride);
|
|
|
|
else AddValue(ScrollStride);
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function SetVisibility(bool Visible)
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
bHideScrollbar = Visible;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
defaultproperties
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
MaxRange=100
|
|
|
|
ScrollStride=1
|
|
|
|
PageStep=10
|
|
|
|
ButtonScale=1
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|