The reason I call setEnabled(false) is because I want my text to not receive focus when accidentally clicking inside the clipping rectangle.
However, even when it is disabled it receives focus when clicking on it and after that I can't do anything else (the GUI freezes).
The only workaround I have is to set the focus to the latest focused element, whenever the static text label receives focus.
What is going on here?
Below is my event receiver class with workaround code added:
Code: Select all
class CGUIEventReceiver : public IEventReceiver
{
private:
IrrlichtDevice *device;
CGUIGrid *the_grid;
IGUIStaticText *debugTxt;
IGUIStaticText *debugTxt2;
IGUIElement *lastFocus;
wchar_t debugBuf[100];
wchar_t debugBuf2[100];
public:
CGUIEventReceiver() : device(0), lastFocus(0) { }
CGUIEventReceiver(IrrlichtDevice *d) : device(d) { }
void setDevice(IrrlichtDevice *d) { device = d; }
void registerGrid(CGUIGrid *g) { the_grid = g; }
void registerDebugLabel(IGUIStaticText *t) { debugTxt = t; }
void registerDebugLabel2(IGUIStaticText *t) { debugTxt2 = t; }
virtual bool OnEvent(SEvent event) {
bool eventprocessed = true;
if (event.EventType == EET_GUI_EVENT) {
s32 id = event.GUIEvent.Caller->getID();
/* workaround for static text focus problem */
if (id == 100 || id == 101) {
if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUSED && lastFocus)
device->getGUIEnvironment()->setFocus(lastFocus);
swprintf(debugBuf, 50, L"Event: %d ID: %d", event.GUIEvent.EventType, id);
debugTxt->setText(debugBuf);
return false;
}
/* END workaround */
switch(event.GUIEvent.EventType)
{
case EGET_SCROLL_BAR_CHANGED:
static s32 posX, posY, dx, dy;
if (id == 104) {
dx = posX = ((IGUIScrollBar*)event.GUIEvent.Caller)->getPos();
posX = the_grid->getSnapX()*100 - posX;
the_grid->setOffsetX(posX % the_grid->getSnapX());
lastFocus = device->getGUIEnvironment()->getFocus();
}
if (id == 105) {
dy = posY = ((IGUIScrollBar*)event.GUIEvent.Caller)->getPos();
posY = the_grid->getSnapY()*100 - posY;
the_grid->setOffsetY(posY % the_grid->getSnapY());
lastFocus = device->getGUIEnvironment()->getFocus();
}
swprintf(debugBuf, 50, L"X: %d Y: %d", dx, dy);
swprintf(debugBuf2, 50, L"Event: %d ID: %d", event.GUIEvent.EventType, id);
debugTxt->setText(debugBuf);
debugTxt2->setText(debugBuf2);
eventprocessed = true;
break;
case EGET_BUTTON_CLICKED:
eventprocessed = true;
break;
case EGET_ELEMENT_HOVERED:
eventprocessed = true;
break;
case EGET_ELEMENT_LEFT:
eventprocessed = true;
break;
case EGET_ELEMENT_FOCUS_LOST:
eventprocessed = true;
break;
default:
swprintf(debugBuf2, 50, L"Other: %d ID: %d", event.GUIEvent.EventType, id);
debugTxt2->setText(debugBuf2);
return false;
}
}
if (event.EventType == EET_MOUSE_INPUT_EVENT) {
return true;
}
}
};