Removed unused constants

This was a weird menu thing that I added about 2 years ago, and it is
not very useable, and not used :)
master
Mark 2018-12-21 09:10:33 +01:00
parent ed514b7716
commit b35a58a7fc
1 changed files with 0 additions and 221 deletions

View File

@ -5,60 +5,6 @@
@author Zapper
*/
/* -- constants used for layout -- */
static const GUI_AlignLeft = -1;
static const GUI_AlignCenter = 0;
static const GUI_AlignRight = +1;
static const GUI_AlignTop = -1;
static const GUI_AlignBottom = +1;
/*
Prototype for the alternative layout:
Propterties:
- Align: proplist, defines the alignment via alignment constnats GUI_Align*
- X: Horizontal alignment: Left, Center, Right
- Y: Vertical alginment: Top, Center, Bottom
- Margin: proplist, defines the margin of the GUI element
- Left: Margin on the left side of the element
- Right: Margin on the right side of the element
- Top: Margin on top of the element
- Bottom: Margin on the bottom of the element
Note: The margin dimension is defined by the property "Dimension"
- Width: int, width of the element
- Height: int, height of the element
- Dimension: function, defines the unit for the properties "Margin", "Width", and "Height";
Should be one of: Global.ToPercentString (default), or Global.ToEmString
*/
static const GUI_BoxLayout = new Global {
Align = { X = GUI_AlignLeft, Y = GUI_AlignTop,},
Margin = { Left = 0, Right = 0, Top = 0, Bottom = 0,},
Width = 0,
Height = 0,
Dimension = Global.ToPercentString,
};
/*
Prototype for grid layout:
Properties:
- Grid: proplist, as GUI_BoxLayout; additional properties:
- Rows (default = 1): The number of rows in the grid
- Columns (default = 1): The nnumber of columns in the grid
Defines the layout for the box that contains the grid
- Cell: proplist, as GUI_BoxLayout
Defines the layout for individual cells in the grid
*/
static const GUI_GridCellLayout = new Global {
Grid = { Prototype = GUI_BoxLayout, Rows = 1, Columns = 1},
Cell = { Prototype = GUI_BoxLayout, },
};
/* -- menu functions -- */
// documented in /docs/sdk/script/fn
global func GuiAction_Call(proplist target, string function, value)
@ -181,170 +127,3 @@ global func GetDefaultCancelSymbol()
{
return _inherited(...);
}
/* -- layout functions -- */
/*
Checks a layout for errors, and throw a fatal error if the layout is wrong.
@par layout A proplist with prototype GUI_BoxLayout.
It is checked that:
- Width is not 0
- Height is not 0
- Dimension is Global.ToPercentString or Global.ToEmString
*/
global func GuiCheckLayout(proplist layout)
{
var errors = [];
if (layout.Width == 0)
{
PushBack(errors, "property 'Width' must not be 0");
}
if (layout.Height == 0)
{
PushBack(errors, "property 'Height' must not be 0");
}
if (layout.Dimension != Global.ToEmString && layout.Dimension != Global.ToPercentString)
{
PushBack(errors, Format("property 'Dimension' must be Global.ToEmString, or Global.ToPerccentString, but it is %v", layout.Dimension));
}
if (GetLength(errors) > 0)
{
var message = "Error in layout";
for (var error in errors)
{
message = Format("%s, %s", message, error);
}
FatalError(message);
}
}
/*
Calculates the position for a box element.
This function returns a proplist with the properties: Left, Right, Top, Bottom.
The proplist can be added to a GUI proplist in order to define the position
of said GUI element - simply merge with AddProperties(element, position);
@par layout A proplist with prototype GUI_BoxLayout;
*/
global func GuiCalculateBoxElementPosition(proplist layout)
{
GuiCheckLayout(layout);
var element_width = layout.Width + layout.Margin.Left + layout.Margin.Right;
var element_height = layout.Height + layout.Margin.Top + layout.Margin.Bottom;
// determine alignment on x axis
var align_x;
var offset_x;
if (layout.Align.X == GUI_AlignLeft)
{
align_x = "0%";
offset_x = 0;
}
else if (layout.Align.X == GUI_AlignCenter)
{
align_x = "50%";
offset_x = -element_width / 2;
}
else if (layout.Align.X == GUI_AlignRight)
{
align_x = "100%";
offset_x = -element_width;
}
// determine alignment on y axis
var align_y;
var offset_y;
if (layout.Align.Y == GUI_AlignTop)
{
align_y = "0%";
offset_y = 0;
}
else if (layout.Align.Y == GUI_AlignCenter)
{
align_y = "50%";
offset_y = -element_height / 2;
}
else if (layout.Align.Y == GUI_AlignBottom)
{
align_y = "100%";
offset_y = -element_height;
}
// determine actual dimensions
var element_x = offset_x + layout.Margin.Left;
var element_y = offset_y + layout.Margin.Top;
return
{
Left = Format("%s%s", align_x, Call(layout.Dimension, element_x)),
Top = Format("%s%s", align_y, Call(layout.Dimension, element_y)),
Right = Format("%s%s", align_x, Call(layout.Dimension, element_x + layout.Width)),
Bottom = Format("%s%s", align_y, Call(layout.Dimension, element_y + layout.Height))
};
}
/*
Calculates the position for a box element inside a grid of elements.
For example, the buttons in the inventory bar could be modeled as a grid
with 1 row and x columns - this function calculates the position of a single
button in that grid, based on the layout.
This function returns a proplist with the properties: Left, Right, Top, Bottom.
The proplist can be added to a GUI proplist in order to define the position
of said GUI element - simply merge with AddProperties(element, position);
@par layout A proplist with prototype GUI_GridCellLayout; Alternatively,
you can use a the prototype GUI_BoxLayout (In that case, however,
the margin and alignment are shared between cells and the grid,
and you need two additional properties "Rows" and "Columns")
@par row The vertical position of the element in the grid. First row is 0.
@par column The horizontal position of the element in the grid. First column is 0.
*/
global func GuiCalculateGridElementPosition(proplist layout, int row, int column)
{
// determine internal layout
var grid_layout, cell_layout;
if (layout["Grid"] && layout["Cell"])
{
grid_layout = layout["Grid"];
cell_layout = layout["Cell"];
}
else
{
grid_layout = {Prototype = layout};
cell_layout = {Prototype = layout};
grid_layout.Rows = grid_layout.Rows;
grid_layout.Columns = grid_layout.Columns;
}
// determine position of the cell in the grid
var cell_width = cell_layout.Width + cell_layout.Margin.Left + cell_layout.Margin.Right;
var cell_height = cell_layout.Height + cell_layout.Margin.Top + cell_layout.Margin.Bottom;
var cell_pos_x = cell_layout.Margin.Left + column * cell_width;
var cell_pos_y = cell_layout.Margin.Top + row * cell_height;
// determine position of the grid
var grid_width = cell_width * (grid_layout.Columns ?? 1);
var grid_height = cell_height * (grid_layout.Rows ?? 1);
var grid_position = GuiCalculateBoxElementPosition({Prototype = grid_layout, Width = grid_width, Height = grid_height});
// merge everything into one
return
{
Left = Format("%s%s", grid_position.Left, Call(cell_layout.Dimension, cell_pos_x)),
Top = Format("%s%s", grid_position.Top, Call(cell_layout.Dimension, cell_pos_y)),
Right = Format("%s%s", grid_position.Left, Call(cell_layout.Dimension, cell_pos_x + cell_layout.Width)),
Bottom = Format("%s%s", grid_position.Top, Call(cell_layout.Dimension, cell_pos_y + cell_layout.Height))
};
}