Ejemplo n.º 1
0
void PushButton::createGraphicsImplementation()
{
    osg::ref_ptr<osg::Group> group = new osg::Group;

    Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();


    float unFocused = 0.92;
    float withFocus = 0.97;

    osg::Vec4 frameColor(unFocused,unFocused,unFocused,1.0f);

    osg::BoundingBox extents(_extents);

    bool requiresFrame = (getFrameSettings() && getFrameSettings()->getShape()!=osgUI::FrameSettings::NO_FRAME);
    if (requiresFrame)
    {
        group->addChild(style->createFrame(_extents, getFrameSettings(), frameColor));
        extents.xMin() += getFrameSettings()->getLineWidth();
        extents.xMax() -= getFrameSettings()->getLineWidth();
        extents.yMin() += getFrameSettings()->getLineWidth();
        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->setSingleChildOn(0);

    group->addChild(_buttonSwitch.get());

    // create label.
    osg::ref_ptr<Node> node = style->createText(extents, getAlignmentSettings(), getTextSettings(), _text);
    _textDrawable = dynamic_cast<osgText::Text*>(node.get());
    _textDrawable->setDataVariance(osg::Object::DYNAMIC);

    group->addChild(_textDrawable.get());

    style->setupClipStateSet(_extents, getOrCreateStateSet());

    setGraphicsSubgraph(0, group.get());
}
Ejemplo n.º 2
0
void Popup::createGraphicsImplementation()
{
   _transform = new osg::PositionAttitudeTransform;

    Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();

    osg::Vec4 dialogBackgroundColor(0.9,0.9,0.9,1.0);

    _transform->addChild( style->createPanel(_extents, dialogBackgroundColor) );

    bool requiresFrame = (getFrameSettings() && getFrameSettings()->getShape()!=osgUI::FrameSettings::NO_FRAME);
    if (requiresFrame) { _transform->addChild(style->createFrame(_extents, getFrameSettings(), dialogBackgroundColor)); }

    style->setupDialogStateSet(getOrCreateStateSet());
    style->setupClipStateSet(_extents, getOrCreateStateSet());


    // render before the subgraph
    setGraphicsSubgraph(-1, _transform.get());

    // render after the subgraph
    setGraphicsSubgraph(1, style->createDepthSetPanel(_extents));
}
Ejemplo n.º 3
0
void Dialog::createGraphicsImplementation()
{
    _group = new osg::Group;

    Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();

    float titleHeight = 10.0;
    osg::BoundingBox titleBarExtents(_extents.xMin(), _extents.yMax(), _extents.zMin(), _extents.xMax()-titleHeight, _extents.yMax()+titleHeight, _extents.zMin());
    osg::BoundingBox closeButtonExtents(_extents.xMax()-titleHeight, _extents.yMax(), _extents.zMin(), _extents.xMax(), _extents.yMax()+titleHeight, _extents.zMin());

    osg::Vec4 dialogBackgroundColor(0.84,0.82,0.82,1.0);
    osg::Vec4 dialogTitleBackgroundColor(0.5,0.5,1.0,1.0);

    _group->addChild( style->createPanel(_extents, dialogBackgroundColor) );

    _group->addChild( style->createPanel(titleBarExtents, dialogTitleBackgroundColor) );

    osg::BoundingBox dialogWithTitleExtents(_extents);
    dialogWithTitleExtents.expandBy(titleBarExtents);
    dialogWithTitleExtents.expandBy(closeButtonExtents);

    bool requiresFrame = (getFrameSettings() && getFrameSettings()->getShape()!=osgUI::FrameSettings::NO_FRAME);
    if (requiresFrame)
    {
        _group->addChild(style->createFrame(dialogWithTitleExtents, getFrameSettings(), dialogBackgroundColor));

        titleBarExtents.xMin() += getFrameSettings()->getLineWidth();
        titleBarExtents.yMax() -= getFrameSettings()->getLineWidth();
        closeButtonExtents.xMax() -= getFrameSettings()->getLineWidth();
        closeButtonExtents.yMax() -= getFrameSettings()->getLineWidth();
    }

    OSG_NOTICE<<"Dialog::_extents ("<<_extents.xMin()<<", "<<_extents.yMin()<<", "<<_extents.zMin()<<"), ("<<_extents.xMax()<<", "<<_extents.yMax()<<", "<<_extents.zMax()<<")"<<std::endl;
    OSG_NOTICE<<"Dialog::titleBarExtents ("<<titleBarExtents.xMin()<<", "<<titleBarExtents.yMin()<<", "<<titleBarExtents.zMin()<<"), ("<<titleBarExtents.xMax()<<", "<<titleBarExtents.yMax()<<", "<<titleBarExtents.zMax()<<")"<<std::endl;
    OSG_NOTICE<<"Dialog::dialogWithTitleExtents ("<<dialogWithTitleExtents.xMin()<<", "<<dialogWithTitleExtents.yMin()<<", "<<dialogWithTitleExtents.zMin()<<"), ("<<dialogWithTitleExtents.xMax()<<", "<<dialogWithTitleExtents.yMax()<<", "<<dialogWithTitleExtents.zMax()<<")"<<std::endl;

#if 0
    osg::ref_ptr<Node> node = style->createText(titleBarExtents, getAlignmentSettings(), getTextSettings(), _title);
    _titleDrawable = dynamic_cast<osgText::Text*>(node.get());
    _titleDrawable->setDataVariance(osg::Object::DYNAMIC);
    _group->addChild(_titleDrawable.get());
#endif

    osg::ref_ptr<PushButton> closeButton = new osgUI::PushButton;
    closeButton->setExtents(closeButtonExtents);
    closeButton->setText("x");
    closeButton->setAlignmentSettings(getAlignmentSettings());
    closeButton->setTextSettings(getTextSettings());
    //closeButton->setFrameSettings(getFrameSettings());
    closeButton->getOrCreateUserDataContainer()->addUserObject(new osgUI::CloseCallback("released", this));

    osg::ref_ptr<Label> titleLabel = new osgUI::Label;
    titleLabel->setExtents(titleBarExtents);
    titleLabel->setText(_title);
    titleLabel->setAlignmentSettings(getAlignmentSettings());
    titleLabel->setTextSettings(getTextSettings());
    titleLabel->setFrameSettings(getFrameSettings());
    titleLabel->getOrCreateUserDataContainer()->addUserObject(new osgUI::DragCallback);

    _group->addChild(closeButton.get());
    _group->addChild(titleLabel.get());

    style->setupDialogStateSet(getOrCreateWidgetStateSet(), 5);
    style->setupClipStateSet(dialogWithTitleExtents, getOrCreateWidgetStateSet());

    // render before the subgraph
    setGraphicsSubgraph(-1, _group.get());

    // render after the subgraph
    setGraphicsSubgraph(1, style->createDepthSetPanel(dialogWithTitleExtents));
}
Ejemplo n.º 4
0
void ComboBox::createGraphicsImplementation()
{
    Style *style = (getStyle() != 0) ? getStyle() : Style::instance().get();

    _buttonSwitch = new osg::Switch;
    _popup        = new osgUI::Popup;
    _popup->setVisible(false);
    _popup->setFrameSettings(getFrameSettings());

    osg::BoundingBox extents(_extents);

    osg::ref_ptr<osg::Group> group         = new osg::Group;
    bool                     requiresFrame = (getFrameSettings() && getFrameSettings()->getShape() != osgUI::FrameSettings::NO_FRAME);
    float                    frameWidth    = 0.0;
    float                    unFocused     = 0.92;
    float                    withFocus     = 0.97;
    osg::Vec4                frameColor(unFocused, unFocused, unFocused, 1.0f);

    if (requiresFrame)
    {
        frameWidth = getFrameSettings()->getLineWidth();

        group->addChild(style->createFrame(_extents, getFrameSettings(), frameColor));
        extents.xMin() += frameWidth;
        extents.xMax() -= frameWidth;
        extents.yMin() += frameWidth;
        extents.yMax() -= frameWidth;
    }


    bool itemsHaveColor = false;

    for (Items::iterator itr = _items.begin();
         itr != _items.end();
         ++itr)
    {
        Item *item = itr->get();
        if (item->getColor().a() != 0.0f)
        {
            itemsHaveColor = true; break;
        }
    }

    // work out position of carat.
    float h            = extents.yMax() - extents.yMin();
    float w            = h * 0.7;
    float minItemWidth = (extents.xMax() - extents.xMin()) * 0.5f;
    if (w > minItemWidth)
        w = minItemWidth;

    float xDivision = extents.xMax() - w;

    osg::BoundingBox backgroundExtents = extents;
    osg::BoundingBox iconExtents       = backgroundExtents;
    iconExtents.xMin() = xDivision;
    extents.xMax()     = xDivision;

    if (itemsHaveColor)
    {
        backgroundExtents.xMin() = xDivision;
    }

    OSG_NOTICE << "itemsHaveColor = " << itemsHaveColor << std::endl;

    // clear background of edit region
    _backgroundSwitch = new osg::Switch;
    _backgroundSwitch->addChild(style->createPanel(backgroundExtents, osg::Vec4(unFocused, unFocused, unFocused, 1.0)));
    _backgroundSwitch->addChild(style->createPanel(backgroundExtents, osg::Vec4(withFocus, withFocus, withFocus, 1.0)));
    _backgroundSwitch->setSingleChildOn(0);


    // assign carat
    group->addChild(_backgroundSwitch.get());

    group->addChild(_buttonSwitch.get());

    // group->addChild(style->createIcon(iconExtents, "cow.osgt", osg::Vec4(withFocus, withFocus, withFocus,1.0)));
    group->addChild(style->createIcon(iconExtents, "Images/osg64.png", osg::Vec4(withFocus, withFocus, withFocus, 1.0)));

    if (!_items.empty())
    {
        float margin = (extents.yMax() - extents.yMin()) * 0.1f;
        // float itemWidth = (_extents.xMax()-_extents.xMin()) - 2.0f*frameWidth;
        float itemHeight  = (_extents.yMax() - _extents.yMin()) - 2.0f * frameWidth;
        float popupHeight = (itemHeight) * _items.size() + margin * static_cast<float>(_items.size() - 1) + 2.0f * frameWidth;
        float popupTop    = _extents.yMin() - frameWidth - margin * 1.0f;
        float popupLeft   = _extents.xMin();
        float popupRight  = _extents.xMax();



        osg::BoundingBox popupExtents(popupLeft, popupTop - popupHeight, _extents.zMin(), popupRight, popupTop, _extents.zMax());
        _popup->setExtents(popupExtents);

        osg::BoundingBox popupItemExtents(popupExtents.xMin() + frameWidth, popupTop - frameWidth - itemHeight, popupExtents.zMin(), popupExtents.xMax() - frameWidth, popupTop - frameWidth, popupExtents.zMax());

        _popupItemOrigin.set(popupItemExtents.xMin(), popupItemExtents.yMax(), popupExtents.zMin());
        _popupItemSize.set(popupItemExtents.xMax() - popupItemExtents.xMin(), -(itemHeight + margin), 0.0);

        unsigned int index = 0;

        for (Items::iterator itr = _items.begin();
             itr != _items.end();
             ++itr, ++index)
        {
            Item *item = itr->get();
            OSG_NOTICE << "Creating item " << item->getText() << ", " << item->getColor() << std::endl;

            // setup graphics for button
            {
                osg::ref_ptr<osg::Group> group = new osg::Group;
                if (item->getColor().a() != 0.0f)
                    group->addChild(style->createPanel(extents, item->getColor()));

                if (!item->getText().empty())
                    group->addChild(style->createText(extents, getAlignmentSettings(), getTextSettings(), item->getText()));

                _buttonSwitch->addChild(group.get());
            }

            // setup graphics for popup
            {
                osg::ref_ptr<osg::Group> group = new osg::Group;

                if (item->getColor().a() != 0.0f)
                    group->addChild(style->createPanel(popupItemExtents, item->getColor()));

                if (!item->getText().empty())
                    group->addChild(style->createText(popupItemExtents, getAlignmentSettings(), getTextSettings(), item->getText()));

                _popup->addChild(group.get());

                popupItemExtents.yMin() -= (itemHeight + margin);
                popupItemExtents.yMax() -= (itemHeight + margin);
            }
        }
    }
    else
    {
        _buttonSwitch->addChild(style->createPanel(_extents, frameColor));
    }

    _buttonSwitch->setSingleChildOn(_currentIndex);

    style->setupClipStateSet(_extents, getOrCreateWidgetStateSet());

    setGraphicsSubgraph(0, group.get());
    addChild(_popup.get());
}