2020-01-10 13:14:11 +00:00
|
|
|
// Do not use this on your own, it is used by ColumnList
|
2022-09-03 17:26:40 +00:00
|
|
|
class KFGUI_ColumnTop extends KFGUI_Base;
|
2021-06-12 20:11:37 +00:00
|
|
|
|
2020-01-10 13:14:11 +00:00
|
|
|
var() float ColumnMinSize; // Minimum pixels width allowed.
|
|
|
|
var KFGUI_ColumnList ListOwner;
|
|
|
|
|
2021-06-13 02:54:35 +00:00
|
|
|
var transient int PrevSortedColumn, MouseColumn, ScalingColumn;
|
2020-01-10 13:14:11 +00:00
|
|
|
var transient byte PressedDown[2];
|
2021-06-13 02:54:35 +00:00
|
|
|
var transient bool bPressedDown, bScaleColumn, bMouseScaler;
|
2020-01-10 13:14:11 +00:00
|
|
|
|
|
|
|
function InitMenu()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
Super.InitMenu();
|
|
|
|
ListOwner = KFGUI_ColumnList(ParentComponent);
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function DrawMenu()
|
|
|
|
{
|
2021-06-13 02:54:35 +00:00
|
|
|
local int i, j;
|
|
|
|
local float X, XS, MouseX, GrabWidth, MinSize, Wd;
|
2021-05-16 09:40:02 +00:00
|
|
|
local bool bCheckMouse;
|
|
|
|
|
|
|
|
bClickable = ListOwner.bClickable;
|
|
|
|
MinSize = ColumnMinSize / CompPos[2];
|
|
|
|
|
|
|
|
// Scale column
|
2021-06-13 02:53:33 +00:00
|
|
|
if (bScaleColumn)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
MouseX = Owner.MousePosition.X - CompPos[0];
|
2021-06-13 02:53:33 +00:00
|
|
|
for (i=0; i < ScalingColumn; ++i)
|
|
|
|
MouseX -= (ListOwner.Columns[i].Width * CompPos[2]);
|
2021-05-16 09:40:02 +00:00
|
|
|
|
|
|
|
ListOwner.Columns[ScalingColumn].Width = MouseX / CompPos[2];
|
|
|
|
|
|
|
|
// Make sure no column is scrolled off screen.
|
|
|
|
X = 0;
|
2021-06-13 02:53:33 +00:00
|
|
|
for (i=0; i < (ListOwner.Columns.Length-1); ++i)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (ListOwner.Columns[i].Width < MinSize)
|
2021-05-16 09:40:02 +00:00
|
|
|
ListOwner.Columns[i].Width = MinSize;
|
|
|
|
X+=ListOwner.Columns[i].Width;
|
2021-06-13 02:53:33 +00:00
|
|
|
if (X >= (1.f-MinSize))
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
MouseX = X-(1.f-MinSize); // Grab overshoot.
|
|
|
|
|
|
|
|
// Then push back!
|
2021-06-13 02:53:33 +00:00
|
|
|
for (j=i; j >= 0; --j)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if ((ListOwner.Columns[j].Width-MouseX) > MinSize ) // This column has enough space to retract.
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
ListOwner.Columns[j].Width -= MouseX;
|
2021-05-16 09:40:02 +00:00
|
|
|
MouseX = 0;
|
|
|
|
break;
|
|
|
|
}
|
2021-06-13 02:53:33 +00:00
|
|
|
else if (ListOwner.Columns[j].Width > MinSize ) // This column has limited space to retract.
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
MouseX -= (ListOwner.Columns[j].Width-MinSize);
|
2021-05-16 09:40:02 +00:00
|
|
|
ListOwner.Columns[j].Width = MinSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
X = (1.f-MinSize); // Continue at maximum size.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init mouse check.
|
|
|
|
MouseColumn = -1;
|
|
|
|
bCheckMouse = (bClickable && bFocused);
|
2021-06-13 02:53:33 +00:00
|
|
|
if (bCheckMouse)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
GrabWidth = CompPos[3]*0.175;
|
|
|
|
MouseX = Owner.MousePosition.X - CompPos[0] - GrabWidth;
|
|
|
|
GrabWidth *= -2.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the columns and compute the scalings.
|
|
|
|
X = 0;
|
|
|
|
j = (ListOwner.bShouldSortList ? ListOwner.LastSortedColumn : -1);
|
2021-06-13 02:53:33 +00:00
|
|
|
for (i=0; i < ListOwner.Columns.Length; ++i)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (ListOwner.Columns[i].Width < MinSize)
|
2021-05-16 09:40:02 +00:00
|
|
|
ListOwner.Columns[i].Width = MinSize;
|
|
|
|
|
|
|
|
Wd = ListOwner.Columns[i].Width * CompPos[2];
|
2021-06-13 02:53:33 +00:00
|
|
|
if (i == (ListOwner.Columns.Length-1) ) // Final column, give infinitive width.
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
Wd = (CompPos[2]-X);
|
|
|
|
}
|
2021-06-13 02:53:33 +00:00
|
|
|
if (Wd <= 0 ) // Impossible.
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
ListOwner.Columns[i].bHidden = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ListOwner.Columns[i].X = X;
|
|
|
|
ListOwner.Columns[i].XSize = Wd;
|
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
if (bCheckMouse && (MouseX -= Wd) <= 0.f)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
MouseColumn = i;
|
|
|
|
bCheckMouse = false;
|
2021-06-13 02:53:33 +00:00
|
|
|
bMouseScaler = (MouseX >= GrabWidth) && ((i+1) < ListOwner.Columns.Length);
|
2021-05-16 09:40:02 +00:00
|
|
|
}
|
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
if (X >= CompPos[2])
|
2021-05-16 09:40:02 +00:00
|
|
|
ListOwner.Columns[i].bHidden = true;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ListOwner.Columns[i].bHidden = false;
|
2021-06-13 02:54:35 +00:00
|
|
|
//Canvas.SetClip(X+Wd, CompPos[1]+CompPos[3]);
|
2021-05-16 09:40:02 +00:00
|
|
|
|
|
|
|
// Draw column.
|
2021-06-13 02:53:33 +00:00
|
|
|
if (i == j)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (MouseColumn == i && !bMouseScaler)
|
2021-06-13 02:54:35 +00:00
|
|
|
Canvas.SetDrawColor(175, 240, 8,255);
|
|
|
|
else Canvas.SetDrawColor(128, 200, 56, 255);
|
2021-05-16 09:40:02 +00:00
|
|
|
}
|
2021-06-13 02:53:33 +00:00
|
|
|
else if (MouseColumn == i && !bMouseScaler)
|
2021-06-13 02:54:35 +00:00
|
|
|
Canvas.SetDrawColor(220, 220, 8,255);
|
2021-05-16 09:40:02 +00:00
|
|
|
|
|
|
|
XS = Owner.CurrentStyle.DefaultHeight*0.5;
|
2021-06-13 02:54:35 +00:00
|
|
|
Canvas.SetPos(X, 0.f);
|
|
|
|
Canvas.DrawTileStretched(Owner.CurrentStyle.TabTextures[`TAB_TOP], Min(Wd, CompPos[2]-X), CompPos[3], 0,0, 128, 16);
|
2021-05-16 09:40:02 +00:00
|
|
|
|
2021-06-13 02:54:35 +00:00
|
|
|
Canvas.SetDrawColor(250, 250, 250, 255);
|
|
|
|
Canvas.SetPos(X+XS, (CompPos[3]-ListOwner.TextHeight)*0.5f);
|
2021-05-16 09:40:02 +00:00
|
|
|
ListOwner.DrawStrClipped(ListOwner.Columns[i].Text);
|
|
|
|
}
|
|
|
|
X+=Wd;
|
|
|
|
}
|
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 (!ListOwner.bDisabled && bClickable)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
PressedDown[byte(bRight)] = 1;
|
|
|
|
bPressedDown = true;
|
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
if (!bRight && bMouseScaler)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
PlayMenuSound(MN_ClickButton);
|
|
|
|
bScaleColumn = true;
|
|
|
|
ScalingColumn = MouseColumn;
|
|
|
|
GetInputFocus();
|
|
|
|
}
|
|
|
|
}
|
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 (bScaleColumn && !bRight)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
bScaleColumn = false;
|
|
|
|
DropInputFocus();
|
|
|
|
return;
|
|
|
|
}
|
2021-06-13 02:53:33 +00:00
|
|
|
if (!bDisabled && bClickable && PressedDown[byte(bRight)] == 1)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
PlayMenuSound(MN_ClickButton);
|
|
|
|
PressedDown[byte(bRight)] = 0;
|
2021-06-13 02:53:33 +00:00
|
|
|
bPressedDown = (PressedDown[0] != 0 || PressedDown[1] != 0);
|
2021-05-16 09:40:02 +00:00
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
if (MouseColumn >= 0)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
2021-06-13 02:54:35 +00:00
|
|
|
ListOwner.SortColumn(MouseColumn, (PrevSortedColumn == MouseColumn));
|
2021-06-13 02:53:33 +00:00
|
|
|
if (PrevSortedColumn == MouseColumn)
|
2021-05-16 09:40:02 +00:00
|
|
|
PrevSortedColumn = -1;
|
|
|
|
else PrevSortedColumn = MouseColumn;
|
|
|
|
}
|
|
|
|
}
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
function byte GetCursorStyle()
|
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (bClickable)
|
2021-05-16 09:40:02 +00:00
|
|
|
return (bMouseScaler ? 2 : 1);
|
|
|
|
return 0;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
function MouseLeave()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
Super.MouseLeave();
|
2021-06-13 02:53:33 +00:00
|
|
|
if (!bScaleColumn)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
PressedDown[0] = 0;
|
|
|
|
PressedDown[1] = 0;
|
|
|
|
bPressedDown = false;
|
|
|
|
}
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
function MouseEnter()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
Super.MouseEnter();
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function LostInputFocus()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
bScaleColumn = false;
|
|
|
|
PressedDown[0] = 0;
|
|
|
|
PressedDown[1] = 0;
|
|
|
|
bPressedDown = false;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
defaultproperties
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
bClickable=true
|
|
|
|
ColumnMinSize=8
|
2023-05-02 19:15:42 +00:00
|
|
|
}
|