Game Development Community

dev|Pro Game Development Curriculum

Selecting non-modal GuiControls in the GuiEditor

by Orion Elenzil · 02/15/2008 (12:24 pm) · 0 comments

This has bugged me for ages.

If you have a non-modal GuiControl
("non-modal" in this context means "invisible to mouse events"),
it's modeless even in the GuiEditor, which means you can't select it.

Frustrating !

This resource introduces a new method on GuiCanvas, "SetSelectNonModal()",
which does what you might think, and changes the GuiEditor uses it.

This is based on a TGE 1.3 codebase,
but should work with all known versions of TGE, TGEA, TGB, anything with the GuiControl system.

This resource assumes familiarity w/ C++ programming and the TGE engine.


GuiCanvas.h
add a private field:
bool                       mSelectNonModal;        ///< bool if this is true, then mouseClicks register even for non-modal children.

add these public methods:
/// Returns whether we're current able to select non-modal (ie event-see-through) controls
   bool getSelectNonModal()               { return mSelectNonModal;       }
   void setSelectNonModal(bool val)       { mSelectNonModal = val;        }

GuiCanvas.cc
in the constructor, add:
mSelectNonModal = false;

add these console methods:
ConsoleMethod(GuiCanvas, setSelectNonModal, void, 3, 3, "(bool on/off)")
{
   object->setSelectNonModal(dAtob(argv[2]));
}

ConsoleMethod(GuiCanvas, getSelectNonModal, bool, 2, 2, "")
{
   return object->getSelectNonModal();
}

in GuiCanvas::rootMouseDown(),
change these lines:
//see if the controlHit is a modeless dialog...
            if ((! controlHit->mActive) && (! controlHit->mProfile->mModal))
to these:
//see if the controlHit is a modeless dialog...
            if ((! mSelectNonModal) && (! controlHit->mActive) && (! controlHit->mProfile->mModal))


GuiControl.cc
in GuiControl::findHitControl(),
add these lines at the begining:
GuiCanvas* root = getRoot();
   bool selectNonModal = (root == NULL) ? false : root->getSelectNonModal();
and change this line:
if(hitCtrl->mProfile->mModal)
to this:
if(hitCtrl && (selectNonModal || hitCtrl->mProfile->mModal))


GuiEditorGui.gui (the world's most redundantly-named file!)
in the "true" branch of if(%content == GuiEditorGui.getId()),
add this:
Canvas.setSelectNonModal(false);
and in the "false" branch,
add this:
Canvas.setSelectNonModal(true);





disclaimer:
i actually implemented this on a codebase which has other modifications not included here,
so i haven't literally actually compiled/tested this exact code, but i'll bet a deep-friend twinky it works.