//
// DRAW MENU
//
/// <summary>Draws the current menu as a screen overlay</summary>
internal void Draw()
{
int i;
if (CurrMenu < 0 || CurrMenu >= Menus.Length)
{
return;
}
SingleMenu menu = Menus[CurrMenu];
// overlay background
GL.Color4(overlayColor.R, overlayColor.G, overlayColor.B, overlayColor.A);
Renderer.RenderOverlaySolid(0.0, 0.0, (double)Screen.Width, (double)Screen.Height);
GL.Color4(1.0f, 1.0f, 1.0f, 1.0f);
// HORIZONTAL PLACEMENT: centre the menu in the main window
int itemLeft = (Screen.Width - menu.ItemWidth) / 2; // item left edge
// if menu alignment is left, left-align items, otherwise centre them in the screen
int itemX = (menu.Align & TextAlignment.Left) != 0 ? itemLeft : Screen.Width / 2;
int menuBottomItem = menu.TopItem + visibleItems - 1;
// draw the menu background
GL.Color4(backgroundColor.R, backgroundColor.G, backgroundColor.B, backgroundColor.A);
Renderer.RenderOverlaySolid(menuXmin - MenuBorderX, menuYmin - MenuBorderY,
menuXmax + MenuBorderX, menuYmax + MenuBorderY);
// if not starting from the top of the menu, draw a dimmed ellipsis item
if (menu.Selection == menu.TopItem - 1 && !isCustomisingControl)
{
GL.Color4(highlightColor.R, highlightColor.G, highlightColor.B, highlightColor.A);
Renderer.RenderOverlaySolid(itemLeft - MenuItemBorderX, menuYmin /*-MenuItemBorderY*/,
itemLeft + menu.ItemWidth + MenuItemBorderX, menuYmin + em + MenuItemBorderY * 2);
}
if (menu.TopItem > 0)
{
Renderer.DrawString(MenuFont, "...", new Point(itemX, menuYmin),
menu.Align, ColourDimmed, false);
}
// draw the items
int itemY = topItemY;
for (i = menu.TopItem; i <= menuBottomItem && i < menu.Items.Length; i++)
{
if (menu.Items[i] == null)
{
continue;
}
if (i == menu.Selection)
{
// draw a solid highlight rectangle under the text
// HACK! the highlight rectangle has to be shifted a little down to match
// the text body. OpenGL 'feature'?
GL.Color4(highlightColor.R, highlightColor.G, highlightColor.B, highlightColor.A);
Renderer.RenderOverlaySolid(itemLeft - MenuItemBorderX, itemY /*-MenuItemBorderY*/,
itemLeft + menu.ItemWidth + MenuItemBorderX, itemY + em + MenuItemBorderY * 2);
// draw the text
Renderer.DrawString(MenuFont, menu.Items[i].Text, new Point(itemX, itemY),
menu.Align, ColourHighlight, false);
}
else if (menu.Items[i] is MenuCaption)
{
Renderer.DrawString(MenuFont, menu.Items[i].Text, new Point(itemX, itemY),
menu.Align, ColourCaption, false);
}
else
{
Renderer.DrawString(MenuFont, menu.Items[i].Text, new Point(itemX, itemY),
menu.Align, ColourNormal, false);
}
itemY += lineHeight;
}
if (menu.Selection == menu.TopItem + visibleItems)
{
GL.Color4(highlightColor.R, highlightColor.G, highlightColor.B, highlightColor.A);
Renderer.RenderOverlaySolid(itemLeft - MenuItemBorderX, itemY /*-MenuItemBorderY*/,
itemLeft + menu.ItemWidth + MenuItemBorderX, itemY + em + MenuItemBorderY * 2);
}
// if not at the end of the menu, draw a dimmed ellipsis item at the bottom
if (i < menu.Items.Length - 1)
{
Renderer.DrawString(MenuFont, "...", new Point(itemX, itemY),
menu.Align, ColourDimmed, false);
}
}