GuiEditor improvements: Select Parent, Resize, etc
by Orion Elenzil · 03/04/2007 (12:31 pm) · 10 comments
THE FIRST IMPROVEMENT: Select Parent

Often times you'll have a control filling up most of a container control, and it can be difficult to select the container. For example a text control inside a scroll control.
This simple script-only addition lets you select the parent of the currently selected control.
If there is no currently selected control, it will select the the current "add set", this making the new add set the parent of the current one.
(If you don't know what that is, don't worry kid, you're in good hands)
Use "ctrl-p" or the Edit menu to get select parent.
additions to GuiEditorGui.gui - based on TGE 1.3.5
find the lines
and down at the bottom, add this:
THE SECOND IMPROVEMENT: Selected To Add Set
Added a sort of inverse of Select Parent, which takes the currently selected control and promotes it to the current Add Set. So the following is optional.
more additions to GuiEditorGui.gui
add the following in the logical place:
and down at the bottom, add this:
THE THIRD IMPROVEMENT: Resize with Keyboard
.. this allows you to resize controls with either the keyboard or menu items.
Additions to GuiEditorGui.gui:
find the line "Canvas.setContent(GuiEditorGui);",
and right *before* it, add this section:
additions to guiEditCtrl.h
find "void MoveSelection", and add this line after it:
additions to guiEditCtrl.cc
add this console function:
{
Vector::iterator i;
for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
(*i)->resize((*i)->mBounds.point, (*i)->mBounds.extent + delta);
if (mSelectedControls.size() == 1)
Con::executef(this, 2, "onSelect", avar("%d", mSelectedControls[0]->getId()));
}
[/b][/code]
THE FOURTH IMPROVEMENT: Select None
additions to guiEditCtrl.h
re-written functions in guiEditCtrl.cc
add this function:
[b]
change the top of GuiEditCtrl::setSelection() so it looks like this:
[b]
changes to [b]GuiEditorGui.gui:
add these lines at the appropriate spot:
change GuiEditorTreeView::onSelect() so it looks like this:
[b]
add this function:
[b]

Often times you'll have a control filling up most of a container control, and it can be difficult to select the container. For example a text control inside a scroll control.
This simple script-only addition lets you select the parent of the currently selected control.
If there is no currently selected control, it will select the the current "add set", this making the new add set the parent of the current one.
(If you don't know what that is, don't worry kid, you're in good hands)
Use "ctrl-p" or the Edit menu to get select parent.
additions to GuiEditorGui.gui - based on TGE 1.3.5
find the lines
GuiEditorMenuBar.addMenuItem("Edit", "Select All", 6, "Ctrl A");
GuiEditorMenuBar.scriptCommand["Edit", 6] = "GuiEditor.selectAll();";and right after them, add[b]
GuiEditorMenuBar.addMenuItem("Edit", "Select Parent", 7, "Ctrl P");
GuiEditorMenuBar.scriptCommand["Edit", 7] = "GuiEditor.selectParent();";
[/b]and down at the bottom, add this:
[b]
//----------------------------------------
function GuiEditor::selectParent(%this)
{
%selected = %this.getSelected();
if (isObject(%selected))
%newSelect = %selected.getParent();
else
%newSelect = %this.getCurrentAddSet();
if (!isObject(%newSelect))
return;
// stuff crashes if we do onSelect() of the canvas.
if (%newSelect == Canvas.getId())
return;
GuiEditorTreeView.onSelect(%newSelect);
}
[/b]THE SECOND IMPROVEMENT: Selected To Add Set
Added a sort of inverse of Select Parent, which takes the currently selected control and promotes it to the current Add Set. So the following is optional.
more additions to GuiEditorGui.gui
add the following in the logical place:
[b]
GuiEditorMenuBar.addMenuItem("Edit", "Selected --> Add Set", 8, "Ctrl O");
GuiEditorMenuBar.scriptCommand["Edit", 8] = "GuiEditor.selectedToAddSet();";
[/b]and down at the bottom, add this:
[b]
//----------------------------------------
function GuiEditor::selectedToAddSet(%this)
{
%selected = %this.getSelected();
if (!isObject(%selected))
return;
%this.setCurrentAddSet(%selected);
GuiEditorTreeView.onSelect(0);
}
[/b]THE THIRD IMPROVEMENT: Resize with Keyboard
.. this allows you to resize controls with either the keyboard or menu items.Additions to GuiEditorGui.gui:
find the line "Canvas.setContent(GuiEditorGui);",
and right *before* it, add this section:
[b]
GuiEditorMenuBar.addMenu("Size", 4);
%n = 1;
GuiEditorMenuBar.addMenuItem ("Size", "Wider", %n, "Ctrl Right");
GuiEditorMenuBar.scriptCommand["Size", %n] = "GuiEditor.sizeSelection(1, 0);";
%n++;
GuiEditorMenuBar.addMenuItem ("Size", "Narrower", %n, "Ctrl Left");
GuiEditorMenuBar.scriptCommand["Size", %n] = "GuiEditor.sizeSelection(-1, 0);";
%n++;
GuiEditorMenuBar.addMenuItem ("Size", "Taller", %n, "Ctrl Down");
GuiEditorMenuBar.scriptCommand["Size", %n] = "GuiEditor.sizeSelection(0, 1);";
%n++;
GuiEditorMenuBar.addMenuItem ("Size", "Shorter", %n, "Ctrl Up");
GuiEditorMenuBar.scriptCommand["Size", %n] = "GuiEditor.sizeSelection(0, -1);";
%n++;
GuiEditorMenuBar.addMenuItem ("Size", "-", 0);
GuiEditorMenuBar.addMenuItem ("Size", "Much Wider", %n, "Alt Right");
GuiEditorMenuBar.scriptCommand["Size", %n] = "GuiEditor.sizeSelection(10, 0);";
%n++;
GuiEditorMenuBar.addMenuItem ("Size", "Much Narrower", %n, "Alt Left");
GuiEditorMenuBar.scriptCommand["Size", %n] = "GuiEditor.sizeSelection(-10, 0);";
%n++;
GuiEditorMenuBar.addMenuItem ("Size", "Much Taller", %n, "Alt Down");
GuiEditorMenuBar.scriptCommand["Size", %n] = "GuiEditor.sizeSelection(0, 10);";
%n++;
GuiEditorMenuBar.addMenuItem ("Size", "Much Shorter", %n, "Alt Up");
GuiEditorMenuBar.scriptCommand["Size", %n] = "GuiEditor.sizeSelection(0, -10);";
%n++;
[/b]additions to guiEditCtrl.h
find "void MoveSelection", and add this line after it:
[b] void sizeSelection(const Point2I &delta); [/b]
additions to guiEditCtrl.cc
add this console function:
[b]
ConsoleMethod( GuiEditCtrl, sizeSelection, void, 4, 4, "(int deltax, int deltay)")
{
object->sizeSelection(Point2I(dAtoi(argv[2]), dAtoi(argv[3])));
}
[b][code]
and add this method:
[/b]void GuiEditCtrl::sizeSelection(const Point2I &delta){
Vector
for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
(*i)->resize((*i)->mBounds.point, (*i)->mBounds.extent + delta);
if (mSelectedControls.size() == 1)
Con::executef(this, 2, "onSelect", avar("%d", mSelectedControls[0]->getId()));
}
[/b][/code]
THE FOURTH IMPROVEMENT: Select None
additions to guiEditCtrl.h
[b] void resetCurrentAddSet(); [/b]
re-written functions in guiEditCtrl.cc
[b]
ConsoleMethod( GuiEditCtrl, select, void, 3, 3, "(GuiControl ctrl)")
{
GuiControl *ctrl = NULL;
Sim::findObject(argv[2], ctrl);
object->setSelection(ctrl, false);
}
[/b]ConsoleMethod( GuiEditCtrl, setCurrentAddSet, void, 3, 3, "(GuiControl ctrl)")
{
GuiControl *addSet = NULL;
if (dAtoi(argv[2]) == 0)
object->resetCurrentAddSet();
if (!Sim::findObject(argv[2], addSet))
{
Con::printf("%s(): Invalid control: %s", argv[0], argv[2]);
return;
}
object->setCurrentAddSet(addSet);
}
[/b]add this function:
[b]
void GuiEditCtrl::resetCurrentAddSet()
{
setCurrentAddSet(mContentControl);
}
[/b]change the top of GuiEditCtrl::setSelection() so it looks like this:
[b]
if (! ctrl)
{
clearSelection();
return;
}
[/b]changes to [b]GuiEditorGui.gui:
add these lines at the appropriate spot:
[b]
GuiEditorMenuBar.addMenuItem("Edit", "Selected None", 9, "Ctrl D");
GuiEditorMenuBar.scriptCommand["Edit", 9] = "GuiEditor.selectNone();";
[/b]change GuiEditorTreeView::onSelect() so it looks like this:
[b]
function GuiEditorTreeView::onSelect(%this, %obj)
{
if (isObject(%obj))
%name = %obj.getName();
else
%name = "";
GuiEditorInspectFields.inspect(%obj);
GuiEditorInspectName.setValue(%name);
GuiEditor.select(%obj);
}
[/b]add this function:
[b]
function GuiEditor::selectNone(%this)
{
GuiEditorTreeView.onSelect(0);
%this.setCurrentAddSet(0);
}
[/b]About the author
#2
i wanted to use shift + ctrl but that didn't seem to fly.
maybe i'll look more into that.
03/02/2007 (9:00 am)
hey Frank -i wanted to use shift + ctrl but that didn't seem to fly.
maybe i'll look more into that.
#3
03/02/2007 (1:42 pm)
heh. the list of improvements grows. added "select none" - ctrl D. (Ctrl D may seem like an odd choice, but that's what photoshop, PSP, etc use)
#4
03/02/2007 (2:03 pm)
thanks a lot! very good and useful improvements! :)
#5
Above this line (Last Line in file):
GlobalActionMap.bind(keyboard, "f10", GuiEdit);
Add:
//----------------------------------------
function GuiEditor::selectNone()
{
GuiEditor.clearSelection();
}
no engine changes required (Torque Version: 1.4.2)
03/09/2007 (10:43 am)
For the Select None you can streamline the script function easily, just use this function, add it to the bottom of the GuiEditorGui.guiAbove this line (Last Line in file):
GlobalActionMap.bind(keyboard, "f10", GuiEdit);
Add:
//----------------------------------------
function GuiEditor::selectNone()
{
GuiEditor.clearSelection();
}
no engine changes required (Torque Version: 1.4.2)
#6
03/09/2007 (10:44 am)
oh yeah forgot to mention that function along with the menu addition in this resource.
#7
which requires the mods above.
03/09/2007 (11:16 am)
yes, but i also wanted to clear the current add set,which requires the mods above.
#8
It is a good resource, i never thought about adding these in until i saw it in the resources list. So good job.
Any idea as to creating the editor in the missino editor to be ortho? as in modeller view with 4 view ports? i have been looking for a resource like that for a while but still have yet to find one. I am a modeler at heart and it woudl be easier to work with the mission editor in that fashion. or maybe you have some thoughts on how to approarch do it?
I am not affraid of c++ or anything, i am good at it, just prefer doing the 3d end of game development more so than the code end, i find it more gratifying. anyway sorry for hijacking your resource here. Good job on it. i will finish intigrating it over the next few days as i have time. I really likethe KB short cuts, i woudl not be able to use my computer properly with out them :p and this resource will save alot of otherwise wasted time.
03/09/2007 (7:12 pm)
well then in that case then yeah lol, guess i should a actually read it right. It is a good resource, i never thought about adding these in until i saw it in the resources list. So good job.
Any idea as to creating the editor in the missino editor to be ortho? as in modeller view with 4 view ports? i have been looking for a resource like that for a while but still have yet to find one. I am a modeler at heart and it woudl be easier to work with the mission editor in that fashion. or maybe you have some thoughts on how to approarch do it?
I am not affraid of c++ or anything, i am good at it, just prefer doing the 3d end of game development more so than the code end, i find it more gratifying. anyway sorry for hijacking your resource here. Good job on it. i will finish intigrating it over the next few days as i have time. I really likethe KB short cuts, i woudl not be able to use my computer properly with out them :p and this resource will save alot of otherwise wasted time.
#9
12/04/2007 (8:15 am)
Very useful.
#10
08/09/2008 (5:29 am)
Very good... 
Torque Owner Demolishun
DemolishunConsulting Rocks!
Thanks,
Frank