Toruqe 2D/Reference/Strategy/StrategyMouseSelections/initSelectionMenu
From TDN
|
[edit] The initSelectionMenu() completed function
// --------------------------------------------------------------------
// initSelectionMenu()
//
// This function handles the calculations for dynamically configuring the
// ammount of rows and columns needed to tile our selection buttons inside
// whatever selection menu we use. It stores all of the positions to place
// the buttons so when they need to be placed its a snap
// --------------------------------------------------------------------
function initSelectionMenu(%buttonExtent, %count)
{
// we get the extent, width, and height of the selection box we will add buttons to
%extent = SelectionMenu.getExtent();
%width = getWord(%extent, 0);
%height = getWord(%extent, 1);
// divide up the extent into width and height
%buttonWidth = getWord(%buttonExtent, 0);
%buttonHeight = getWord(%buttonExtent, 1);
// button height plus padding
%calcHeight = %buttonHeight + 1;
// calculation of buttons per column rounded down
%buttonsPerColumn = mFloor(%height / %calcHeight);
// calculation of how many colums it will take to hold the buttons rounded up
%columns = mCeil(%count / %buttonsPerColumn);
// calculate the max columns
%maxColumns = mFloor(%width / (%buttonWidth + 5));
// we have too many buttons to fit
if(%columns > %maxColumns)
error("too many buttons to fit");
// store the max values of how many columns and rows we need
SelectionMenu.columnMax = %columns;
SelectionMenu.rowMax = %buttonsPerColumn;
// start the first column and row with a little buffer
SelectionMenu.xPos[0] = "5";
SelectionMenu.yPos[0] = "5";
// we loop through each of the columns needed and generate the column locations
for(%i=1;%i<%columns;%i++)
{
SelectionMenu.xPos[%i] = SelectionMenu.xPos[%i-1] + %buttonWidth + 5;
}
// we loop through each of the rows needed and generate the row locations
for(%i=1;%i<%buttonsPerColumn;%i++)
{
SelectionMenu.yPos[%i] = SelectionMenu.yPos[%i-1] + %buttonHeight + 5;
}
// we reset the counters we will use to populate the property window with buttons
SelectionMenu.columnCount = 0;
SelectionMenu.rowCount = 0;
}
|



