Resizing GUI dialogs (solution)
by Vern Jensen · in Torque Game Builder · 09/03/2009 (6:45 pm) · 0 replies
In my game, the GUI dialog boxes were designed at 1650x1080 resolution, and were too big for smaller resolutions. But the built-in Torque stuff for resizing dialogs caused all sorts of problems for me. They just don't work right.
So I wrote my own function. Thought I'd share it in case anyone else finds it useful. This does, however, require GUI profiles that have "Tiny" added to the name, for every custom profile you use. You change the fontSize in these profiles, or just leave them as-is otherwise.
For example, in my game, I here is a snippet:
It's a hassle,, but the results work beautifully.
Here is the resizing function I use:
So I wrote my own function. Thought I'd share it in case anyone else finds it useful. This does, however, require GUI profiles that have "Tiny" added to the name, for every custom profile you use. You change the fontSize in these profiles, or just leave them as-is otherwise.
For example, in my game, I here is a snippet:
if(!isObject(GameEditTextFieldProfileTiny)) new GuiControlProfile (GameEditTextFieldProfileTiny : GameEditTextFieldProfile) {};
if(!isObject(GameEditPlainTextFieldProfileTiny)) new GuiControlProfile (GameEditPlainTextFieldProfileTiny : GameEditPlainTextFieldProfile) {};
if(!isObject(GameEditTextFieldYellowProfileTiny)) new GuiControlProfile (GameEditTextFieldYellowProfileTiny : GameEditTextFieldYellowProfile) {};
if(!isObject(GameDialogWindowProfileTiny)) new GuiControlProfile (GameDialogWindowProfileTiny: GameDialogWindowProfile) {};
if(!isObject(GameTabBookProfileTiny)) new GuiControlProfile (GameTabBookProfileTiny: GameTabBookProfile) {};
if(!isObject(GameTabPageProfileTiny)) new GuiControlProfile (GameTabPageProfileTiny : GameTabPageProfile ) {};
if(!isObject(GameSliderProfileTiny)) new GuiControlProfile (GameSliderProfileTiny: GameSliderProfile) {};
if(!isObject(GamePopUpMenuDefaultTiny)) new GuiControlProfile (GamePopUpMenuDefaultTiny : GamePopUpMenuDefault )
{
fontSize = 12; // 16
profileForChildren = GamePopUpMenuDefaultTiny;
};
if(!isObject(GamePopUpMenuProfileTiny)) new GuiControlProfile (GamePopUpMenuProfileTiny : GamePopUpMenuProfile)
{
fontSize = 12; // 16
profileForChildren = GamePopUpMenuDefaultTiny;
};
if(!isObject(GameControlsButtonProfileTiny)) new GuiControlProfile (GameControlsButtonProfileTiny : GameControlsButtonProfile)
{
fontSize = 16; // 20
};It's a hassle,, but the results work beautifully.
Here is the resizing function I use:
function resizeDialogForCurrentWindowSize( %theDialog )
{
%windowSize = getRes();
%width = getWord(%windowSize, 0);
%height = getWord(%windowSize, 1);
if (%width <= 840)
%factor = 0.8;
else
%factor = 1.0;
if (%theDialog.curFactor != %factor)
{
saveAllControlSizes(%theDialog);
resizeControl( %theDialog, %factor );
%theDialog.curFactor = %factor;
%theDialog.setPosition(200,200);
}
}
function resizeControl( %theDialog, %factor )
{
%count = %theDialog.getCount();
for(%i = 0; %i < %count; %i++)
{
%ctrl = %theDialog.getObject(%i);
%position = %ctrl.Position; //i.e. "162 159";
%extent = %ctrl.extent; // i.e. "475 282";
%ctrl.setExtent( %ctrl.origExtentX * %factor, %ctrl.origExtentY * %factor );
%ctrl.setPosition( %ctrl.origPositionX * %factor, %ctrl.origPositionY * %factor);
%ctrl.profile = %ctrl.origProfile;
%newProfileName = %ctrl.profile @ "Tiny";
if (%factor <= 0.9)
%ctrl.profile = %newProfileName;
// Resize children AFTER resizing the parent control, so that restoring to original
// size works properly.
if (%ctrl.getCount() > 0)
resizeControl(%ctrl, %factor);
}
}
function saveAllControlSizes( %theDialog )
{
%count = %theDialog.getCount();
for(%i = 0; %i < %count; %i++)
{
%ctrl = %theDialog.getObject(%i);
if (%ctrl.getCount() > 0)
saveAllControlSizes(%ctrl);
%ctrl.savePositionX = mFloor(getWord(%ctrl.Position, 0));
%ctrl.savePositionY = mFloor(getWord(%ctrl.Position, 1));
%ctrl.mySaveExtentX = mFloor(getWord(%ctrl.extent, 0));
%ctrl.mySaveExtentY = mFloor(getWord(%ctrl.extent, 1));
if (%ctrl.didSaveOriginalValues == false)
{
%ctrl.origExtentX = %ctrl.mySaveExtentX;
%ctrl.origExtentY = %ctrl.mySaveExtentY;
%ctrl.origPositionX = %ctrl.savePositionX;
%ctrl.origPositionY = %ctrl.savePositionY;
%ctrl.origProfile = %ctrl.profile;
%ctrl.didSaveOriginalValues = true;
}
}
}