Added initial shell of PushButton implementation
This commit is contained in:
@@ -12,6 +12,7 @@ SET(TARGET_H
|
||||
${HEADER_PATH}/Widget
|
||||
${HEADER_PATH}/Label
|
||||
${HEADER_PATH}/LineEdit
|
||||
${HEADER_PATH}/PushButton
|
||||
${HEADER_PATH}/Style
|
||||
${HEADER_PATH}/AlignmentSettings
|
||||
${HEADER_PATH}/FrameSettings
|
||||
@@ -22,6 +23,7 @@ SET(TARGET_SRC
|
||||
Widget.cpp
|
||||
Label.cpp
|
||||
LineEdit.cpp
|
||||
PushButton.cpp
|
||||
Style.cpp
|
||||
AlignmentSettings.cpp
|
||||
FrameSettings.cpp
|
||||
|
||||
@@ -33,8 +33,18 @@ void Label::createGraphicsImplementation()
|
||||
{
|
||||
OSG_NOTICE<<"Label::createGraphicsImplementation()"<<std::endl;
|
||||
|
||||
Widget::createGraphicsImplementation();
|
||||
if (_textDrawable.valid())
|
||||
{
|
||||
_textDrawable->setText(_text);
|
||||
_graphicsInitialized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Widget::createGraphicsImplementation();
|
||||
|
||||
Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();
|
||||
addChild(style->createText(_extents, getAlignmentSettings(), getTextSettings(), _text));
|
||||
Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();
|
||||
osg::ref_ptr<Node> node = style->createText(_extents, getAlignmentSettings(), getTextSettings(), _text);
|
||||
_textDrawable = dynamic_cast<osgText::Text*>(node.get());
|
||||
addChild(node.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <osgText/String>
|
||||
#include <osgText/Font>
|
||||
#include <osgText/Text>
|
||||
#include <osg/Notify>
|
||||
|
||||
using namespace osgUI;
|
||||
|
||||
@@ -31,6 +32,8 @@ LineEdit::LineEdit(const osgUI::LineEdit& label, const osg::CopyOp& copyop):
|
||||
|
||||
bool LineEdit::handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event)
|
||||
{
|
||||
OSG_NOTICE<<"LineEdit::handleImplementation"<<std::endl;
|
||||
|
||||
osgGA::GUIEventAdapter* ea = event->asGUIEventAdapter();
|
||||
if (!ea) return false;
|
||||
|
||||
@@ -47,6 +50,9 @@ bool LineEdit::handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event
|
||||
_text.push_back(ea->getKey());
|
||||
}
|
||||
dirty();
|
||||
|
||||
OSG_NOTICE<<"Key pressed : "<<ea->getKey()<<std::endl;
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -57,13 +63,29 @@ bool LineEdit::handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event
|
||||
|
||||
void LineEdit::createGraphicsImplementation()
|
||||
{
|
||||
OSG_NOTICE<<"LineEdit::createGraphicsImplementation()"<<std::endl;
|
||||
|
||||
Widget::createGraphicsImplementation();
|
||||
if (_textDrawable.valid())
|
||||
{
|
||||
OSG_NOTICE<<"LineEdit::createGraphicsImplementation() updating existing TextDrawable"<<std::endl;
|
||||
_textDrawable->setText(_text);
|
||||
_graphicsInitialized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<"LineEdit::createGraphicsImplementation()"<<std::endl;
|
||||
|
||||
Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();
|
||||
Widget::createGraphicsImplementation();
|
||||
|
||||
removeChildren(0, getNumChildren());
|
||||
|
||||
addChild(style->createText(_extents, getAlignmentSettings(), getTextSettings(), _text));
|
||||
Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();
|
||||
osg::ref_ptr<Node> node = style->createText(_extents, getAlignmentSettings(), getTextSettings(), _text);
|
||||
_textDrawable = dynamic_cast<osgText::Text*>(node.get());
|
||||
_textDrawable->setDataVariance(osg::Object::DYNAMIC);
|
||||
#if 0
|
||||
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
|
||||
geode->addDrawable(_textDrawable.get());
|
||||
addChild(geode.get());
|
||||
#else
|
||||
addChild(_textDrawable.get());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
106
src/osgUI/PushButton.cpp
Normal file
106
src/osgUI/PushButton.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
|
||||
#include <osgUI/PushButton>
|
||||
#include <osgText/String>
|
||||
#include <osgText/Font>
|
||||
#include <osgText/Text>
|
||||
#include <osg/Notify>
|
||||
|
||||
using namespace osgUI;
|
||||
|
||||
PushButton::PushButton()
|
||||
{
|
||||
}
|
||||
|
||||
PushButton::PushButton(const osgUI::PushButton& label, const osg::CopyOp& copyop):
|
||||
Widget(label, copyop),
|
||||
_text(label._text)
|
||||
{
|
||||
}
|
||||
|
||||
bool PushButton::handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event)
|
||||
{
|
||||
OSG_NOTICE<<"PushButton::handleImplementation"<<std::endl;
|
||||
|
||||
osgGA::GUIEventAdapter* ea = event->asGUIEventAdapter();
|
||||
if (!ea) return false;
|
||||
|
||||
switch(ea->getEventType())
|
||||
{
|
||||
case(osgGA::GUIEventAdapter::PUSH):
|
||||
OSG_NOTICE<<"Button pressed "<<std::endl;
|
||||
if (_buttonSwitch.valid()) _buttonSwitch->setSingleChildOn(2);
|
||||
break;
|
||||
case(osgGA::GUIEventAdapter::RELEASE):
|
||||
OSG_NOTICE<<"Button release "<<std::endl;
|
||||
if (_buttonSwitch.valid()) _buttonSwitch->setSingleChildOn(1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void PushButton::enterImplementation()
|
||||
{
|
||||
OSG_NOTICE<<"PushButton enter"<<std::endl;
|
||||
if (_buttonSwitch.valid()) _buttonSwitch->setSingleChildOn(1);
|
||||
}
|
||||
|
||||
|
||||
void PushButton::leaveImplementation()
|
||||
{
|
||||
OSG_NOTICE<<"PushButton leave"<<std::endl;
|
||||
if (_buttonSwitch.valid()) _buttonSwitch->setSingleChildOn(0);
|
||||
}
|
||||
|
||||
void PushButton::createGraphicsImplementation()
|
||||
{
|
||||
|
||||
if (_textDrawable.valid())
|
||||
{
|
||||
OSG_NOTICE<<"PushButton::createGraphicsImplementation() updating existing TextDrawable"<<std::endl;
|
||||
_textDrawable->setText(_text);
|
||||
_graphicsInitialized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<"PushButton::createGraphicsImplementation()"<<std::endl;
|
||||
|
||||
Widget::createGraphicsImplementation();
|
||||
|
||||
Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();
|
||||
osg::ref_ptr<Node> node = style->createText(_extents, getAlignmentSettings(), getTextSettings(), _text);
|
||||
_textDrawable = dynamic_cast<osgText::Text*>(node.get());
|
||||
_textDrawable->setDataVariance(osg::Object::DYNAMIC);
|
||||
|
||||
addChild(_textDrawable.get());
|
||||
|
||||
_buttonSwitch = new osg::Switch;
|
||||
|
||||
float unFocused = 0.7;
|
||||
float withFocus = 0.8;
|
||||
float pressed = 0.5;
|
||||
|
||||
_buttonSwitch->addChild(style->createPanel(_extents, osg::Vec4(unFocused, unFocused,unFocused, 1.0)));
|
||||
_buttonSwitch->addChild(style->createPanel(_extents, osg::Vec4(withFocus,withFocus,withFocus,1.0)));
|
||||
_buttonSwitch->addChild(style->createPanel(_extents, osg::Vec4(pressed,pressed,pressed,1.0)));
|
||||
_buttonSwitch->setSingleChildOn(0);
|
||||
|
||||
addChild(_buttonSwitch.get());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,25 @@ Style::Style(const Style& style, const osg::CopyOp& copyop):
|
||||
|
||||
osg::Node* Style::createPanel(const osg::BoundingBox& extents, const osg::Vec4& colour)
|
||||
{
|
||||
return 0;
|
||||
OSG_NOTICE<<"Creating Panel"<<std::endl;
|
||||
osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry;
|
||||
|
||||
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
|
||||
geometry->setVertexArray(vertices.get());
|
||||
|
||||
vertices->push_back( osg::Vec3(extents.xMin(), extents.yMin(), extents.zMin()) );
|
||||
vertices->push_back( osg::Vec3(extents.xMin(), extents.yMax(), extents.zMin()) );
|
||||
vertices->push_back( osg::Vec3(extents.xMax(), extents.yMin(), extents.zMin()) );
|
||||
vertices->push_back( osg::Vec3(extents.xMax(), extents.yMax(), extents.zMin()) );
|
||||
|
||||
osg::ref_ptr<osg::Vec4Array> colours = new osg::Vec4Array;
|
||||
geometry->setColorArray(colours, osg::Array::BIND_OVERALL);
|
||||
|
||||
colours->push_back( colour );
|
||||
|
||||
geometry->addPrimitiveSet( new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, 4) );
|
||||
|
||||
return geometry.release();
|
||||
}
|
||||
|
||||
osg::Node* Style::createFrame(const osg::BoundingBox& extents, const FrameSettings* frameSettings)
|
||||
@@ -46,12 +64,10 @@ osg::Node* Style::createFrame(const osg::BoundingBox& extents, const FrameSettin
|
||||
|
||||
osg::Node* Style::createText(const osg::BoundingBox& extents, const AlignmentSettings* as, const TextSettings* ts, const std::string& text)
|
||||
{
|
||||
osg::ref_ptr<osg::Geode> textGeode = new osg::Geode;
|
||||
osg::ref_ptr<osgText::Text> textDrawable = new osgText::Text;
|
||||
|
||||
textGeode->addDrawable(textDrawable.get());
|
||||
|
||||
textDrawable->setText(text);
|
||||
textDrawable->setPosition( osg::Vec3(extents.xMin(), extents.yMin(), extents.zMin()) );
|
||||
|
||||
if (ts)
|
||||
{
|
||||
@@ -65,7 +81,7 @@ osg::Node* Style::createText(const osg::BoundingBox& extents, const AlignmentSet
|
||||
textDrawable->setAlignment(alignmentType);
|
||||
}
|
||||
|
||||
return textGeode.release();
|
||||
return textDrawable.release();
|
||||
}
|
||||
|
||||
osg::Node* Style::createIcon(const osg::BoundingBox& extents, const std::string& filename)
|
||||
|
||||
@@ -56,6 +56,8 @@ void Widget::updateFocus(osg::NodeVisitor& nv)
|
||||
osgGA::GUIActionAdapter* aa = ev ? ev->getActionAdapter() : 0;
|
||||
if (ev && aa)
|
||||
{
|
||||
// OSG_NOTICE<<"updateFocus"<<std::endl;
|
||||
|
||||
osgGA::EventQueue::Events& events = ev->getEvents();
|
||||
for(osgGA::EventQueue::Events::iterator itr = events.begin();
|
||||
itr != events.end();
|
||||
@@ -167,7 +169,7 @@ void Widget::enter()
|
||||
|
||||
void Widget::enterImplementation()
|
||||
{
|
||||
OSG_NOTICE<<"enter()"<<std::endl;
|
||||
OSG_NOTICE<<"Widget::enter()"<<std::endl;
|
||||
}
|
||||
|
||||
void Widget::leave()
|
||||
@@ -185,7 +187,7 @@ void Widget::leave()
|
||||
|
||||
void Widget::leaveImplementation()
|
||||
{
|
||||
OSG_NOTICE<<"leave()"<<std::endl;
|
||||
OSG_NOTICE<<"Widget::leave()"<<std::endl;
|
||||
}
|
||||
|
||||
void Widget::traverse(osg::NodeVisitor& nv)
|
||||
@@ -215,12 +217,14 @@ void Widget::traverseImplementation(osg::NodeVisitor& nv)
|
||||
{
|
||||
if (!_graphicsInitialized && nv.getVisitorType()!=osg::NodeVisitor::CULL_VISITOR) createGraphics();
|
||||
|
||||
|
||||
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(&nv);
|
||||
if (ev)
|
||||
{
|
||||
|
||||
updateFocus(nv);
|
||||
|
||||
// OSG_NOTICE<<"EventTraversal getHasEventFocus()="<<getHasEventFocus()<<std::endl;
|
||||
|
||||
if (getHasEventFocus())
|
||||
{
|
||||
// signify that event has been taken by widget with focus
|
||||
|
||||
14
src/osgWrappers/serializers/osgUI/PushButton.cpp
Normal file
14
src/osgWrappers/serializers/osgUI/PushButton.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <osgUI/PushButton>
|
||||
#include <osg/ValueObject>
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( PushButton,
|
||||
new osgUI::PushButton,
|
||||
osgUI::PushButton,
|
||||
"osg::Object osg::Node osg::Group osgUI::Widget osgUI::PushButton" )
|
||||
{
|
||||
ADD_STRING_SERIALIZER( Text, std::string());
|
||||
}
|
||||
Reference in New Issue
Block a user