From 6b5d17a6d4af5bee28719b2c1907e1a248602aa0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 25 Mar 2003 12:44:50 +0000 Subject: [PATCH] Added text input field to the osgkeyboard demo. --- examples/osgkeyboard/osgkeyboard.cpp | 137 +++++++++++++++++++-------- 1 file changed, 99 insertions(+), 38 deletions(-) diff --git a/examples/osgkeyboard/osgkeyboard.cpp b/examples/osgkeyboard/osgkeyboard.cpp index 3da6165c6..0cc0ff585 100644 --- a/examples/osgkeyboard/osgkeyboard.cpp +++ b/examples/osgkeyboard/osgkeyboard.cpp @@ -28,7 +28,8 @@ protected: ~KeyboardModel() {} - void addKey(osg::Vec3& pos, int key,const std::string& text,float width, float height); + osg::Switch* addKey(osg::Vec3& pos, int key,const std::string& text,float width, float height); + osg::Switch* addKey(int key,osg::Switch* sw); void createKeyboard(); @@ -36,21 +37,50 @@ protected: osg::ref_ptr _scene; KeyModelMap _keyModelMap; + osg::ref_ptr _inputText; }; void KeyboardModel::keyChange(int key,int value) { - std::cout << std::hex << key << "\t"<< value << std::dec << std::endl; + std::cout << "key value change, code="<',addKey(pos,'.',".",1.0f,1.0f)); + addKey('?',addKey(pos,'/',"/",1.0f,1.0f)); addKey(pos,osgGA::GUIEventAdapter::KEY_Shift_R,"Shift",2.0f,0.5f); pos.x() = 0.0f; pos.z() += 1.0f; addKey(pos,osgGA::GUIEventAdapter::KEY_Caps_Lock,"Caps",2.0f,0.5f); - addKey(pos,'a',"A",1.0f,1.0f); - addKey(pos,'s',"S",1.0f,1.0f); - addKey(pos,'d',"D",1.0f,1.0f); - addKey(pos,'f',"F",1.0f,1.0f); - addKey(pos,'g',"G",1.0f,1.0f); - addKey(pos,'h',"H",1.0f,1.0f); - addKey(pos,'j',"J",1.0f,1.0f); - addKey(pos,'k',"K",1.0f,1.0f); - addKey(pos,'l',"L",1.0f,1.0f); - addKey(pos,';',";",1.0f,1.0f); - addKey(pos,'\'',"'",1.0f,1.0f); - addKey(pos,'#',"#",1.0f,1.0f); + addKey('A',addKey(pos,'a',"A",1.0f,1.0f)); + addKey('S',addKey(pos,'s',"S",1.0f,1.0f)); + addKey('D',addKey(pos,'d',"D",1.0f,1.0f)); + addKey('F',addKey(pos,'f',"F",1.0f,1.0f)); + addKey('G',addKey(pos,'g',"G",1.0f,1.0f)); + addKey('H',addKey(pos,'h',"H",1.0f,1.0f)); + addKey('J',addKey(pos,'j',"J",1.0f,1.0f)); + addKey('K',addKey(pos,'k',"K",1.0f,1.0f)); + addKey('L',addKey(pos,'l',"L",1.0f,1.0f)); + addKey(':',addKey(pos,';',";",1.0f,1.0f)); + addKey('@',addKey(pos,'\'',"'",1.0f,1.0f)); + addKey('~',addKey(pos,'#',"#",1.0f,1.0f)); addKey(pos,osgGA::GUIEventAdapter::KEY_Return,"Return",4.0f,0.5f); pos.x() = 0.0f; pos.z() += 1.0f; addKey(pos,osgGA::GUIEventAdapter::KEY_Tab,"Tab",2.0f,0.5f); - addKey(pos,'q',"Q",1.0f,1.0f); - addKey(pos,'w',"W",1.0f,1.0f); - addKey(pos,'e',"E",1.0f,1.0f); - addKey(pos,'r',"R",1.0f,1.0f); - addKey(pos,'t',"T",1.0f,1.0f); - addKey(pos,'y',"Y",1.0f,1.0f); - addKey(pos,'u',"U",1.0f,1.0f); - addKey(pos,'i',"I",1.0f,1.0f); - addKey(pos,'o',"O",1.0f,1.0f); - addKey(pos,'p',"P",1.0f,1.0f); - addKey(pos,'[',"[",1.0f,1.0f); - addKey(pos,']',"]",1.0f,1.0f); + addKey('Q',addKey(pos,'q',"Q",1.0f,1.0f)); + addKey('W',addKey(pos,'w',"W",1.0f,1.0f)); + addKey('E',addKey(pos,'e',"E",1.0f,1.0f)); + addKey('R',addKey(pos,'r',"R",1.0f,1.0f)); + addKey('T',addKey(pos,'t',"T",1.0f,1.0f)); + addKey('Y',addKey(pos,'y',"Y",1.0f,1.0f)); + addKey('U',addKey(pos,'u',"U",1.0f,1.0f)); + addKey('I',addKey(pos,'i',"I",1.0f,1.0f)); + addKey('O',addKey(pos,'o',"O",1.0f,1.0f)); + addKey('P',addKey(pos,'p',"P",1.0f,1.0f)); + addKey('{',addKey(pos,'[',"[",1.0f,1.0f)); + addKey('}',addKey(pos,']',"]",1.0f,1.0f)); pos.x() = 0.0f; pos.z() += 1.0f; @@ -270,6 +309,28 @@ void KeyboardModel::createKeyboard() addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Divide,"/",1.0f,1.0f); addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Multiply,"*",1.0f,1.0f); addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Subtract,"-",1.0f,1.0f); + + float totalWidth = pos.x()-origin.x(); + pos = origin; + pos.z() += -1.5f; + + osg::Geode* geodeInput = new osg::Geode; + { + _inputText = new osgText::Text; + _inputText->setFont("fonts/arial.ttf"); + _inputText->setColor(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); + _inputText->setCharacterSize(1.0f); + _inputText->setMaximumWidth(totalWidth); + _inputText->setPosition(pos); + _inputText->setDrawMode(osgText::Text::TEXT/*||osgText::Text::BOUNDINGBOX*/); + _inputText->setAlignment(osgText::Text::BASE_LINE); + _inputText->setAxisAlignment(osgText::Text::XZ_PLANE); + _inputText->setText("Press some keys..."); + + geodeInput->addDrawable(_inputText.get()); + + _scene->addChild(geodeInput); + } }