Game Development Community

Fix for GuiMLTextEditCtrl to get input work with Mac

by Thomas Huehn · in Torque Game Engine · 12/07/2008 (5:17 am) · 0 replies

I noticed, that the input does not work for GuiMLTextEditCtrl on Mac because event.ascii is allways "0".
After some hours debugging in macCarbevents I made the following changes to get it work:

1.) GuiMLTextEditCtrl.h
In public section:

void resize(const Point2I &newPosition, const Point2I &newExtent);
[b]
#ifdef TORQUE_OS_MAC
   virtual void setFirstResponder();
   virtual void onLoseFirstResponder();
#endif
[/b]
   DECLARE_CONOBJECT(GuiMLTextEditCtrl);


2.) GuiMLTextEditCtrl.cc

//--------------------------------------------------------------------------
void GuiMLTextEditCtrl::initPersistFields()
{
   Parent::initPersistFields();
   addField( "escapeCommand", TypeString, Offset( mEscapeCommand, GuiMLTextEditCtrl ) );
}
//--------------------------------------------------------------------------
//XXTH MACOS hack:
[b]
#ifdef TORQUE_OS_MAC

void GuiMLTextEditCtrl::setFirstResponder()
{
   Parent::setFirstResponder();
   
   Platform::enableKeyboardTranslation();
}
void GuiMLTextEditCtrl::onLoseFirstResponder()
{
   Platform::disableKeyboardTranslation();
}
#endif
[/b]
//--------------------------------------------------------------------------
// Key events...
bool GuiMLTextEditCtrl::onKeyDown(const GuiEvent& event)
{
	setUpdate();


The ifdefs are maybe not needed, but it worked with windows and X11 so I didnt want to risk to get trouble on other plattforms.