private void PositionMenu()
{
// int i;
if (CurrMenu < 0 || CurrMenu >= Menus.Length)
return;
SingleMenu menu = Menus[CurrMenu];
// HORIZONTAL PLACEMENT: centre the menu in the main window
menuXmin = (Screen.Width - menu.Width) / 2; // menu left edge (border excluded)
menuXmax = menuXmin + menu.Width; // menu right edge (border excluded)
// VERTICAL PLACEMENT: centre the menu in the main window
menuYmin = (Screen.Height- menu.Height)/ 2; // menu top edge (border excluded)
menuYmax = menuYmin + menu.Height; // menu bottom edge (border excluded)
topItemY = menuYmin; // top edge of top item
// assume all items fit in the screen
visibleItems = menu.Items.Length;
// if there are more items than can fit in the screen height,
// (there should be at least room for the menu top border)
if (menuYmin < MenuBorderY)
{
// the number of lines which fit in the screen
int numOfLines = (Screen.Height - MenuBorderY*2) / lineHeight;
visibleItems = numOfLines - 2; // at least an empty line at the top and at the bottom
// split the menu in chunks of 'visibleItems' items
// and display the chunk which contains the currently selected item
menu.TopItem = menu.Selection - (menu.Selection % visibleItems);
visibleItems = menu.Items.Length - menu.TopItem < visibleItems ? // in the last chunk,
menu.Items.Length - menu.TopItem : visibleItems; // display remaining items only
menuYmin = (Screen.Height - numOfLines*lineHeight) / 2;
menuYmax = menuYmin + numOfLines * lineHeight;
// first menu item is drawn on second line (first line is empty
// on first screen and contains an ellipsis on following screens
topItemY = menuYmin + lineHeight;
}
}