Improved the handling of updating of text

This commit is contained in:
Robert Osfield 2014-05-20 08:35:39 +00:00
parent d917987938
commit 8346f0ebe1
3 changed files with 23 additions and 7 deletions

View File

@ -29,8 +29,7 @@ public:
virtual bool handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event);
void setText(const std::string& text) { _text = text; dirty(); }
std::string& getText() { return _text; }
void setText(const std::string& text);
const std::string& getText() const { return _text; }
virtual void createGraphicsImplementation();

View File

@ -39,13 +39,15 @@ bool Dialog::handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event)
switch(ea->getEventType())
{
case(osgGA::GUIEventAdapter::KEYDOWN):
//case(osgGA::GUIEventAdapter::KEYDOWN):
case(osgGA::GUIEventAdapter::KEYUP):
OSG_NOTICE<<"Key pressed : "<<ea->getKey()<<std::endl;
if (ea->getKey()==osgGA::GUIEventAdapter::KEY_Escape)
if (ea->getKey()=='c')
{
close();
dirty();
ea->setHandled(true);
return true;
}

View File

@ -43,13 +43,20 @@ bool LineEdit::handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event
if (ea->getKey()==osgGA::GUIEventAdapter::KEY_BackSpace ||
ea->getKey()==osgGA::GUIEventAdapter::KEY_Delete)
{
if (!_text.empty()) _text.erase(_text.size()-1, 1);
if (!_text.empty())
{
_text.erase(_text.size()-1, 1);
if (_textDrawable) _textDrawable->setText(_text);
return true;
}
}
else if (ea->getKey()>=32 && ea->getKey()<=0xff00)
{
_text.push_back(ea->getKey());
if (_textDrawable) _textDrawable->setText(_text);
return true;
}
dirty();
OSG_NOTICE<<"Key pressed : "<<ea->getKey()<<std::endl;
@ -61,6 +68,14 @@ bool LineEdit::handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event
return false;
}
void LineEdit::setText(const std::string& text)
{
_text = text;
if (_textDrawable) _textDrawable->setText(_text);
}
void LineEdit::createGraphicsImplementation()
{