Thank you for your simple GUI(QuickGUI)...^^
I register an event handler for a Text Box's OnEnterPressed.
But I can't receive any event from it.
The creation code is below...Is there something wrong?
I use QuickGUI 0.9.4 Version.
chattingTextBox=mSheet->createTextBox(Ogre::Vector4(0.05,0.8,0.9,0.05));
chattingTextBox->addOnEnterPressedEventHandler(&RoomState::evtHndlr_chattingTextBoxOnEnter, this);
bool RoomState::evtHndlr_chattingTextBoxOnEnter(const QuickGUI::EventArgs& args){
printf("Enter Pressed");
return true;
}
Help me...
I solved it ... and more....
OnEnterPress Event doesn't work because of some code absence in the QuickGUI::TextBox...
I append the code below in the body...it works fine...
bool TextBox::onKeyUp(KeyEventArgs& e){
if((e.scancode==QuickGUI::KC_BACK) && !mReadOnly) mBackSpaceDown=false;
else if(e.scancode==QuickGUI::KC_LEFT) mLeftArrowDown=false;
else if(e.scancode==QuickGUI::KC_RIGHT) mRightArrowDown=false;
else if(e.scancode==QuickGUI::KC_DELETE) mDeleteDown=false;
//this line is what I append===========================
else if(e.scancode==QuickGUI::KC_RETURN) onEnterPressed(e);
//===========================================
return Widget::onKeyUp(e);
}
And I make a new member function for the TextBox...very frequently used by UI programming...setFocus...that I can't find in the member functions of the TextBox...T.T
Append the below to QuickGUITextBox.h.
void setFocus();
and append the below to QuickGUITextBox.cpp
void TextBox::setFocus(){
Ogre::Vector2 pos=QuickGUI::GUIManager::getSingletonPtr()->getMouseCursor()->getPixelPosition();
QuickGUI::GUIManager::getSingletonPtr()->getMouseCursor()->setPosition(getPixelPosition().x+getPixelDimensions().z-2, getPixelPosition().y+3);
QuickGUI::GUIManager::getSingletonPtr()->injectMouseMove(0, 0);
QuickGUI::GUIManager::getSingletonPtr()->injectMouseButtonDown(QuickGUI::MB_Left);
QuickGUI::GUIManager::getSingletonPtr()->getMouseCursor()->setPosition(pos.x, pos.y);
QuickGUI::GUIManager::getSingletonPtr()->injectMouseMove(0, 0);
}
Have a fun Game Programming...^^
kungfoomasta
02-07-2007 07:54:23
Good find! Sorry about not firing the Enter Pressed Event, it looks like I forgot to add that in (from what you're showing me).
Also, a focus function does sound like a useful function. I'll add your changes in to the current version. I will probably make some changes in your focus function, hope there are no problems with that.
I plan on revisiting the TextBox widget, I want it to be as flexible and bug free as possible, since I plan on using it to derive other text widgets.
Thanks for digging into the code, hope it wasn't too painful.
kungfoomasta
06-07-2007 01:32:32
I have applied the changes to my code.
- Firing of the onEnterPressed event
- Added QuickGUI::GUIManager::setActiveWidget function
- Added QuickGUI::Widget::focus function, which calls setActiveWidget
- QuickGUI::TextBox::focus, which overrides to position the text cursor, and then call Widget::focus.
I will address other bugfixes and throw up a fixed version. Thanks for pointing this out, and thanks for the focus idea!