Added support for changing background colour of LineEdit widget when focus changes
git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14385 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
@@ -27,12 +27,14 @@ public:
|
||||
LineEdit(const LineEdit& label, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
META_Node(osgUI, LineEdit);
|
||||
|
||||
virtual bool handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event);
|
||||
|
||||
void setText(const std::string& text);
|
||||
const std::string& getText() const { return _text; }
|
||||
|
||||
virtual bool handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event);
|
||||
virtual void createGraphicsImplementation();
|
||||
virtual void enterImplementation();
|
||||
virtual void leaveImplementation();
|
||||
|
||||
|
||||
protected:
|
||||
virtual ~LineEdit() {}
|
||||
@@ -40,6 +42,7 @@ protected:
|
||||
std::string _text;
|
||||
|
||||
// implementation detail
|
||||
osg::ref_ptr<osg::Switch> _backgroundSwitch;
|
||||
osg::ref_ptr<osgText::Text> _textDrawable;
|
||||
};
|
||||
|
||||
|
||||
@@ -72,6 +72,18 @@ void LineEdit::setText(const std::string& text)
|
||||
if (_textDrawable) _textDrawable->setText(_text);
|
||||
}
|
||||
|
||||
void LineEdit::enterImplementation()
|
||||
{
|
||||
OSG_NOTICE<<"PushButton enter"<<std::endl;
|
||||
if (_backgroundSwitch.valid()) _backgroundSwitch->setSingleChildOn(1);
|
||||
}
|
||||
|
||||
|
||||
void LineEdit::leaveImplementation()
|
||||
{
|
||||
OSG_NOTICE<<"PushButton leave"<<std::endl;
|
||||
if (_backgroundSwitch.valid()) _backgroundSwitch->setSingleChildOn(0);
|
||||
}
|
||||
|
||||
|
||||
void LineEdit::createGraphicsImplementation()
|
||||
@@ -81,7 +93,11 @@ void LineEdit::createGraphicsImplementation()
|
||||
osg::ref_ptr<osg::Group> group = new osg::Group;
|
||||
|
||||
osg::BoundingBox extents(_extents);
|
||||
osg::Vec4 frameColor(1.0f,1.0f,1.0f,1.0f);
|
||||
float unFocused = 0.92;
|
||||
float withFocus = 0.97;
|
||||
float pressed = 0.75;
|
||||
|
||||
osg::Vec4 frameColor(unFocused,unFocused,unFocused,1.0f);
|
||||
|
||||
bool requiresFrame = (getFrameSettings() && getFrameSettings()->getShape()!=osgUI::FrameSettings::NO_FRAME);
|
||||
if (requiresFrame)
|
||||
@@ -94,7 +110,12 @@ void LineEdit::createGraphicsImplementation()
|
||||
}
|
||||
|
||||
// clear background of edit region
|
||||
group->addChild(style->createPanel(extents, frameColor));
|
||||
_backgroundSwitch = new osg::Switch;
|
||||
_backgroundSwitch->addChild(style->createPanel(extents, osg::Vec4(unFocused, unFocused,unFocused, 1.0)));
|
||||
_backgroundSwitch->addChild(style->createPanel(extents, osg::Vec4(withFocus,withFocus,withFocus,1.0)));
|
||||
_backgroundSwitch->addChild(style->createPanel(extents, osg::Vec4(pressed,pressed,pressed,1.0)));
|
||||
_backgroundSwitch->setSingleChildOn(0);
|
||||
group->addChild(_backgroundSwitch.get());
|
||||
|
||||
osg::ref_ptr<Node> node = style->createText(extents, getAlignmentSettings(), getTextSettings(), _text);
|
||||
_textDrawable = dynamic_cast<osgText::Text*>(node.get());
|
||||
|
||||
@@ -75,11 +75,9 @@ void PushButton::createGraphicsImplementation()
|
||||
|
||||
Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();
|
||||
|
||||
_buttonSwitch = new osg::Switch;
|
||||
|
||||
float unFocused = 0.92;
|
||||
float withFocus = 0.97;
|
||||
float pressed = 0.75;
|
||||
|
||||
osg::Vec4 frameColor(unFocused,unFocused,unFocused,1.0f);
|
||||
|
||||
@@ -95,9 +93,9 @@ void PushButton::createGraphicsImplementation()
|
||||
extents.yMax() -= getFrameSettings()->getLineWidth();
|
||||
}
|
||||
|
||||
_buttonSwitch = new osg::Switch;
|
||||
_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);
|
||||
|
||||
group->addChild(_buttonSwitch.get());
|
||||
|
||||
Reference in New Issue
Block a user