PanelUnrecPtr createSinglePtrFieldPanel(void)
{
    SinglePtrFieldLabel = OSG::Label::create();

    SinglePtrFieldLabel->setText("Changable");
    SinglePtrFieldLabel->setBorders(NULL);
    
    ButtonRefPtr SinglePtrFieldCreateBackgroundButton = OSG::Button::create();
    SinglePtrFieldCreateBackgroundButton->setText("Create Background");
    SinglePtrFieldCreateBackgroundButton->setPreferredSize(Vec2f(175.0f,SinglePtrFieldCreateBackgroundButton->getPreferredSize().y()));
    SinglePtrFieldCreateActionListener* TheCreateBackgroundActionListener = new SinglePtrFieldCreateActionListener();
    SinglePtrFieldCreateBackgroundButton->addActionListener(TheCreateBackgroundActionListener);

    LayoutRefPtr ThePanelLayout = OSG::FlowLayout::create();

    PanelRefPtr ThePanel = Panel::createEmpty();
    ThePanel->setLayout(ThePanelLayout);
    ThePanel->pushToChildren(SinglePtrFieldLabel);
    ThePanel->pushToChildren(SinglePtrFieldCreateBackgroundButton);

    return ThePanel;
    
}
Esempio n. 2
0
void LuaDebuggerInterface::createEditorToolbar(void)
{
    BoostPath OpenIconPath(_BaseIconDir / BoostPath("open.png"));
    ButtonRefPtr OpenButton = Button::create();
    OpenButton->setToolTipText("Open");
    OpenButton->setPreferredSize(_ToolButtonSize);
    OpenButton->setImages(OpenIconPath.string());
    setName(OpenButton,"Open Button");
    OpenButton->connectActionPerformed(boost::bind(&LuaDebuggerInterface::openScriptButtonAction,this));

    BoostPath SaveIconPath(_BaseIconDir / BoostPath("Save.png"));
    ButtonRefPtr SaveButton = Button::create();
    SaveButton->setPreferredSize(_ToolButtonSize);
    SaveButton->setToolTipText("Save");
    setName(SaveButton,"Save Button");
    SaveButton->setImages(SaveIconPath.string());
    SaveButton->connectActionPerformed(boost::bind(&LuaDebuggerInterface::saveScriptButtonAction,this));

    BoostPath ClearIconPath(_BaseIconDir / BoostPath("clear.png"));
    ButtonRefPtr ClearButton = Button::create();
    ClearButton->setPreferredSize(_ToolButtonSize);
    ClearButton->setToolTipText("Clear");
    setName(ClearButton,"Clear Button");
    ClearButton->setImages(ClearIconPath.string());
    ClearButton->connectActionPerformed(boost::bind(&LuaDebuggerInterface::clearScriptButtonAction,this));



    BoostPath SplitHorzIconPath(_BaseIconDir / BoostPath("view-split-left-right.png"));
    BoostPath SplitVertIconPath(_BaseIconDir / BoostPath("view-split-top-bottom.png"));
    BoostPath SplitNoneIconPath(_BaseIconDir / BoostPath("view-split-none.png"));

    //Split Options Component Generator
    FunctorListComponentGeneratorRecPtr SplitOptionsCompGenerator =
        FunctorListComponentGenerator::create();

    SplitOptionsCompGenerator->setGenerateFunction(boost::bind(&LuaDebuggerInterface::generateSplitOptionListComponent,
                                                               this,
                                                               _1, _2, _3, _4, _5));

    //Split Options List Model
    DefaultListModelRecPtr SplitOptionsListModel = DefaultListModel::create();
    SplitOptionsListModel->pushBack(boost::any(std::string("None")));
    SplitOptionsListModel->pushBack(boost::any(std::string("Horizontal")));
    SplitOptionsListModel->pushBack(boost::any(std::string("Vertical")));

    _SplitButton = MenuButton::create();
    _SplitButton->setToolTipText("Split Options");
    _SplitButton->setPreferredSize(_ToolButtonSize);
    _SplitButton->setImages(SplitNoneIconPath.string());
    _SplitButton->setModel(SplitOptionsListModel);
    _SplitButton->setCellGenerator(SplitOptionsCompGenerator);
    setName(_SplitButton,"Split Button");
    _SplitButton->connectMenuActionPerformed(boost::bind(&LuaDebuggerInterface::handleSplitMenuAction,
                                                         this,
                                                         _1));

    //Make the Button Panel
    FlowLayoutRefPtr ButtonPanelLayout = FlowLayout::create();
    ButtonPanelLayout->setOrientation(FlowLayout::HORIZONTAL_ORIENTATION);
    ButtonPanelLayout->setHorizontalGap(3.0f);
    ButtonPanelLayout->setMajorAxisAlignment(0.0f);
    ButtonPanelLayout->setMinorAxisAlignment(0.5);

    _EditorButtonPanel = Panel::createEmpty();
    _EditorButtonPanel->setPreferredSize(Vec2f(200.0f, 45.0f));
    _EditorButtonPanel->pushToChildren(OpenButton);
    _EditorButtonPanel->pushToChildren(SaveButton);
    _EditorButtonPanel->pushToChildren(ClearButton);
    _EditorButtonPanel->pushToChildren(_SplitButton);
    _EditorButtonPanel->setLayout(ButtonPanelLayout);
    setName(_EditorButtonPanel,"Button Panel");
}
Esempio n. 3
0
DialogWindowUnrecPtr DialogWindow::createColorChooserDialog(const std::string& Title, 
                                                           const std::string& Message, 
                                                           bool showAlpha,
                                                           ColorSelectionModelPtr colorModel,
                                                           bool showCancel, 
                                                           const std::string& ConfirmBtnText, 
                                                           const std::string& CancelBtnText)
{
    ButtonRefPtr ConfirmationButton = OSG::Button::create();
    ButtonRefPtr CancelButton;

    //Confirm Button
    ConfirmationButton->setText(ConfirmBtnText);
    ConfirmationButton->setMinSize(ConfirmationButton->getPreferredSize());
    ConfirmationButton->setPreferredSize(ConfirmationButton->getRequestedSize());

    if(showCancel)
    {
        //Cancel Button
        CancelButton = OSG::Button::create();
        CancelButton->setText(CancelBtnText);
        CancelButton->setMinSize(CancelButton->getPreferredSize());
        CancelButton->setPreferredSize(CancelButton->getRequestedSize());
    }

    // Create Panel for top half of SplitPanel
    TextAreaRefPtr MessagePanelText = OSG::TextArea::create();

    MessagePanelText->setBorders(NULL);
    MessagePanelText->setPreferredSize(Vec2f(100.0f, 100.0f));
    MessagePanelText->setBackgrounds(NULL);
    MessagePanelText->setWrapStyleWord(true);
    MessagePanelText->setText(Message);
    MessagePanelText->setEditable(false);

    // Create Panel for bottom half of SplitPanel
    PanelRefPtr MessageButtonPanel = OSG::Panel::createEmpty();
    FlowLayoutRefPtr MessagePanelBottomLayout = OSG::FlowLayout::create();
    MessageButtonPanel->pushToChildren(ConfirmationButton);
    if(showCancel) 
        MessageButtonPanel->pushToChildren(CancelButton);
    MessageButtonPanel->setLayout(MessagePanelBottomLayout);
    MessageButtonPanel->setPreferredSize(Vec2f(450,75));

    PanelRefPtr MessagePanel = OSG::Panel::createEmpty();
    SpringLayoutRefPtr MessagePanelLayout = SpringLayout::create();
    MessagePanel->pushToChildren(MessagePanelText);
    MessagePanel->pushToChildren(MessageButtonPanel);
    MessagePanel->setLayout(MessagePanelLayout);


    ColorChooserRefPtr TheColorChooser = ColorChooser::create();
    TheColorChooser->setSelectionModel(colorModel);

    //Internals Layout and constraints

    DialogWindowUnrecPtr TheDialog = DialogWindow::create();
    SpringLayoutRefPtr DialogLayout = SpringLayout::create();

    //Message Text
    DialogLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, MessagePanelText, 5, SpringLayoutConstraints::NORTH_EDGE, TheDialog);
    DialogLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, MessagePanelText, -5, SpringLayoutConstraints::EAST_EDGE, TheDialog);
    DialogLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, MessagePanelText, 5, SpringLayoutConstraints::WEST_EDGE, TheDialog);

    //Color Chooser
    DialogLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, TheColorChooser, 5, SpringLayoutConstraints::SOUTH_EDGE, MessagePanelText);
    DialogLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, TheColorChooser, -5, SpringLayoutConstraints::EAST_EDGE, TheDialog);
    DialogLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, TheColorChooser, 5, SpringLayoutConstraints::WEST_EDGE, TheDialog);
    DialogLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, TheColorChooser, -5, SpringLayoutConstraints::NORTH_EDGE, MessageButtonPanel);

    //Button Panel
    DialogLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, MessageButtonPanel, 0, SpringLayoutConstraints::WEST_EDGE, TheDialog);
    DialogLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, MessageButtonPanel, 0, SpringLayoutConstraints::EAST_EDGE, TheDialog);
    DialogLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, MessageButtonPanel, 20, SpringLayoutConstraints::SOUTH_EDGE, TheDialog);

    //Create the Dialog box
    TheDialog->setLayout(DialogLayout);
    TheDialog->setPreferredSize(Vec2f(350,400));
    TheDialog->pushToChildren(MessagePanelText);
    TheDialog->pushToChildren(TheColorChooser);
    TheDialog->pushToChildren(MessageButtonPanel);
    TheDialog->setTitle(Title);

    //Attach listener to the Confirm button
    ConfirmationButton->addActionListener(&TheDialog->_ConfirmButtonListener);

    if(showCancel)
    {
        //Attach listener to the Cancel button
        CancelButton->addActionListener(&TheDialog->_CancelButtonListener);
    }

    return DialogWindowTransitPtr(TheDialog);
}
Esempio n. 4
0
DialogWindowUnrecPtr DialogWindow::createMessageDialog(const std::string& Title, const std::string& Message, const int& Type, const bool& showCancel, const std::string& ConfirmBtnText, const std::string& CancelBtnText)
{
    ImageComponentRefPtr TheIcon = ImageComponent::create();
    LineBorderRefPtr TempIconBorder = OSG::LineBorder::create();
    TheIcon->setPreferredSize(Vec2f(45,45));
    TheIcon->setBorders(TempIconBorder);

    ButtonRefPtr ConfirmationButton = OSG::Button::create();
    ButtonRefPtr CancelButton;

    //Confirm Button
    ConfirmationButton->setText(ConfirmBtnText);
    ConfirmationButton->setMinSize(ConfirmationButton->getPreferredSize());
    ConfirmationButton->setPreferredSize(ConfirmationButton->getRequestedSize());

    if(showCancel)
    {
        //Cancel Button
        CancelButton = OSG::Button::create();
        CancelButton->setText(CancelBtnText);
        CancelButton->setMinSize(CancelButton->getPreferredSize());
        CancelButton->setPreferredSize(CancelButton->getRequestedSize());
    }

    // Create Panel for top half of SplitPanel
    TextAreaRefPtr MessagePanelText = createTransparentTextArea(Message);

    // Create Panel for bottom half of SplitPanel
    PanelRefPtr MessageButtonPanel = OSG::Panel::createEmpty();
    FlowLayoutRefPtr MessagePanelBottomLayout = OSG::FlowLayout::create();
    MessageButtonPanel->pushToChildren(ConfirmationButton);
    if(showCancel) 
        MessageButtonPanel->pushToChildren(CancelButton);
    MessageButtonPanel->setLayout(MessagePanelBottomLayout);
    MessageButtonPanel->setPreferredSize(Vec2f(450,75));

    // Create SplitPanel itself
    PanelRefPtr MessagePanel = OSG::Panel::createEmpty();
    SpringLayoutRefPtr MessagePanelLayout = SpringLayout::create();
    MessagePanel->pushToChildren(MessagePanelText);
    MessagePanel->pushToChildren(TheIcon);
    MessagePanel->pushToChildren(MessageButtonPanel);
    MessagePanel->setLayout(MessagePanelLayout);


    //MessagePanelLayout
    //Icon
    MessagePanelLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, TheIcon, 10, SpringLayoutConstraints::NORTH_EDGE, MessagePanel);
    MessagePanelLayout->putConstraint(SpringLayoutConstraints::WIDTH_EDGE, TheIcon, LayoutSpring::width(TheIcon));
    MessagePanelLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, TheIcon, 10, SpringLayoutConstraints::WEST_EDGE, MessagePanel);
    MessagePanelLayout->putConstraint(SpringLayoutConstraints::HEIGHT_EDGE, TheIcon, LayoutSpring::height(TheIcon));

    //Message
    MessagePanelLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, MessagePanelText, 5, SpringLayoutConstraints::NORTH_EDGE, MessagePanel);
    MessagePanelLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, MessagePanelText, -5, SpringLayoutConstraints::EAST_EDGE, MessagePanel);
    MessagePanelLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, MessagePanelText, 10, SpringLayoutConstraints::EAST_EDGE, TheIcon);
    MessagePanelLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, MessagePanelText, -30, SpringLayoutConstraints::SOUTH_EDGE, MessagePanel);

    //Button Panel
    MessagePanelLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, MessageButtonPanel, 0, SpringLayoutConstraints::WEST_EDGE, MessagePanel);
    MessagePanelLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, MessageButtonPanel, 0, SpringLayoutConstraints::EAST_EDGE, MessagePanel);
    MessagePanelLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, MessageButtonPanel, 20, SpringLayoutConstraints::SOUTH_EDGE, MessagePanel);

    //Internals Layout and constraints
    BorderLayoutConstraintsRefPtr MessagePanelConstraints = BorderLayoutConstraints::create();
    MessagePanelConstraints->setRegion(BorderLayoutConstraints::BORDER_CENTER);

    MessagePanel->setConstraints(MessagePanelConstraints);

    BorderLayoutRefPtr DialogLayout = BorderLayout::create();

    //Create the Dialog box
    DialogWindowRefPtr TheDialog = DialogWindow::create();
    TheDialog->setLayout(DialogLayout);
    TheDialog->setPreferredSize(Vec2f(350,150));
    TheDialog->pushToChildren(MessagePanel);
    TheDialog->setTitle(Title);

    //Attach listener to the Confirm button
    ConfirmationButton->addActionListener(&TheDialog->_ConfirmButtonListener);

    if(showCancel)
    {
        //Attach listener to the Cancel button
        CancelButton->addActionListener(&TheDialog->_CancelButtonListener);
    }

    return TheDialog;
}
Esempio n. 5
0
DialogWindowUnrecPtr DialogWindow::createInputDialog(const std::string& Title, const std::string& Message, const int& Type, const bool& showCancel, const std::vector<std::string>& InputValues, const std::string& ConfirmBtnText, const std::string& CancelBtnText)
{
    int DialogHeight = 175;
    DialogWindowRefPtr TheDialog = DialogWindow::create();

    ImageComponentRefPtr TheIcon = ImageComponent::create();
    LineBorderRefPtr TempIconBorder = OSG::LineBorder::create();
    TheIcon->setPreferredSize(Vec2f(45,45));
    TheIcon->setBorders(TempIconBorder);

    // Create Panel for input
    PanelRefPtr InputPanel = OSG::Panel::createEmpty();
    FlowLayoutRefPtr InputPanelLayout = OSG::FlowLayout::create();
    InputPanel->setLayout(InputPanelLayout);
    InputPanel->setPreferredSize(Vec2f(450,75));

    ButtonRefPtr InputButton;
    switch (Type) {
        case INPUT_TEXT:
            TheDialog->_InputTextField = OSG::TextField::create();
            TheDialog->_InputTextField->setText(InputValues[0]);
            TheDialog->_InputTextField->setPreferredSize(Vec2f(200,25));
            InputPanel->pushToChildren(TheDialog->_InputTextField);
            break;
        case INPUT_BTNS:	
            DialogHeight = 150;
            for (std::vector<std::string>::const_iterator it = InputValues.begin(); it!=InputValues.end(); ++it)
            {
                InputButton = OSG::Button::create();
                InputButton->setText(*it);
                InputButton->setMinSize(InputButton->getPreferredSize());
                InputButton->setPreferredSize(InputButton->getRequestedSize());
                InputButton->addActionListener(&TheDialog->_InputButtonListener);
                InputPanel->pushToChildren(InputButton);
            }				
            break;
        case INPUT_COMBO:
        default:
            TheDialog->_InputComboBox = OSG::ComboBox::create();
            DefaultMutableComboBoxModelRefPtr _InputComboBoxModel;
            _InputComboBoxModel = DefaultMutableComboBoxModel::create();

            for (std::vector<std::string>::const_iterator it = InputValues.begin(); it!=InputValues.end(); ++it)
            {
                _InputComboBoxModel->addElement(boost::any(std::string(*it)));
            }

            TheDialog->_InputComboBox->setPreferredSize(Vec2f(150, 23));
            TheDialog->_InputComboBox->setModel(_InputComboBoxModel);
            TheDialog->_InputComboBox->setSelectedIndex(0);

            InputPanel->pushToChildren(TheDialog->_InputComboBox);
            break;
    }

    FlowLayoutRefPtr MessagePanelBottomLayout;
    PanelRefPtr MessageButtonPanel;
    ButtonRefPtr ConfirmationButton;
    ButtonRefPtr CancelButton;


    if(Type != INPUT_BTNS)
    {
        ConfirmationButton = OSG::Button::create();
        //Confirm Button
        ConfirmationButton->setText(ConfirmBtnText);
        ConfirmationButton->setMinSize(ConfirmationButton->getPreferredSize());
        ConfirmationButton->setPreferredSize(ConfirmationButton->getRequestedSize());

        if(Type == INPUT_TEXT)
        {
            ConfirmationButton->addActionListener(&TheDialog->_TextButtonListener);
        }
        else
        {
            ConfirmationButton->addActionListener(&TheDialog->_ComboButtonListener);
        }
    }

    if(showCancel)
    {
        CancelButton = OSG::Button::create();
        //Cancel Button
        CancelButton->setText(CancelBtnText);
        CancelButton->setMinSize(CancelButton->getPreferredSize());
        CancelButton->setPreferredSize(CancelButton->getRequestedSize());

        //Attach listener to the Cancel button
        CancelButton->addActionListener(&TheDialog->_CancelButtonListener);
    }

    // Create Panel for top half of SplitPanel
    TextAreaRefPtr MessagePanelText = createTransparentTextArea(Message);

    //If the type of input is buttons and showCancel is true, just push the cancel button onto the input panel
    if(Type == INPUT_BTNS && showCancel)
    {
        InputPanel->pushToChildren(CancelButton);
    }
    else if(Type != INPUT_BTNS)
    {
        // Create Panel for bottom half of SplitPanel
        MessageButtonPanel = OSG::Panel::createEmpty();
        MessagePanelBottomLayout = OSG::FlowLayout::create();
        MessageButtonPanel->pushToChildren(ConfirmationButton);
        if(showCancel) 
            MessageButtonPanel->pushToChildren(CancelButton);
        MessageButtonPanel->setLayout(MessagePanelBottomLayout);
        MessageButtonPanel->setPreferredSize(Vec2f(450,75));
    } 

    // Create SplitPanel itself
    PanelRefPtr MessagePanel = OSG::Panel::createEmpty();
    SpringLayoutRefPtr MessagePanelLayout = SpringLayout::create();
    MessagePanel->pushToChildren(MessagePanelText);
    MessagePanel->pushToChildren(TheIcon);
    MessagePanel->pushToChildren(InputPanel);
    if(Type != INPUT_BTNS)
        MessagePanel->pushToChildren(MessageButtonPanel);
    MessagePanel->setLayout(MessagePanelLayout);


    //MessagePanelLayout
    //Icon
    MessagePanelLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, TheIcon, 10, SpringLayoutConstraints::NORTH_EDGE, MessagePanel);
    MessagePanelLayout->putConstraint(SpringLayoutConstraints::WIDTH_EDGE, TheIcon, LayoutSpring::width(TheIcon));
    MessagePanelLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, TheIcon, 10, SpringLayoutConstraints::WEST_EDGE, MessagePanel);
    MessagePanelLayout->putConstraint(SpringLayoutConstraints::HEIGHT_EDGE, TheIcon, LayoutSpring::height(TheIcon));

    //Message
    MessagePanelLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, MessagePanelText, 5, SpringLayoutConstraints::NORTH_EDGE, MessagePanel);
    MessagePanelLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, MessagePanelText, -5, SpringLayoutConstraints::EAST_EDGE, MessagePanel);
    MessagePanelLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, MessagePanelText, 10, SpringLayoutConstraints::EAST_EDGE, TheIcon);
    MessagePanelLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, MessagePanelText, 20, SpringLayoutConstraints::NORTH_EDGE, InputPanel);

    //Input Panel
    MessagePanelLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, InputPanel, 0, SpringLayoutConstraints::WEST_EDGE, MessagePanel);
    MessagePanelLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, InputPanel, 0, SpringLayoutConstraints::EAST_EDGE, MessagePanel);

    if(Type != INPUT_BTNS)
    {
        MessagePanelLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, InputPanel, 40, SpringLayoutConstraints::NORTH_EDGE, MessageButtonPanel);
        //Button Panel
        MessagePanelLayout->putConstraint(SpringLayoutConstraints::HEIGHT_EDGE, MessageButtonPanel, LayoutSpring::height(MessageButtonPanel));
        MessagePanelLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, MessageButtonPanel, 0, SpringLayoutConstraints::WEST_EDGE, MessagePanel);
        MessagePanelLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, MessageButtonPanel, 0, SpringLayoutConstraints::EAST_EDGE, MessagePanel);
        MessagePanelLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, MessageButtonPanel, 20, SpringLayoutConstraints::SOUTH_EDGE, MessagePanel);
    }
    else
    {
        MessagePanelLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, InputPanel, 20, SpringLayoutConstraints::SOUTH_EDGE, MessagePanel);
    }

    //Internals Layout and constraints
    BorderLayoutConstraintsRefPtr MessagePanelConstraints = BorderLayoutConstraints::create();
    MessagePanelConstraints->setRegion(BorderLayoutConstraints::BORDER_CENTER);

    MessagePanel->setConstraints(MessagePanelConstraints);

    BorderLayoutRefPtr DialogLayout = BorderLayout::create();

    //Create the Dialog box
    TheDialog->setLayout(DialogLayout);
    TheDialog->setPreferredSize(Vec2f(350,DialogHeight));
    TheDialog->pushToChildren(MessagePanel);
    TheDialog->setTitle(Title);

    return TheDialog;
}
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);

    // Make Torus Node (creates Torus in background of scene)
    NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);

    // Make Main Scene Node and add the Torus
    NodeRefPtr scene = OSG::Node::create();
    scene->setCore(OSG::Group::create());
    scene->addChild(TorusGeometryNode);

    // Create the Graphics
    GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create();

    // Initialize the LookAndFeelManager to enable default settings
    LookAndFeelManager::the()->getLookAndFeel()->init();

    /******************************************************

      Create an Button Component and
      a simple Font.
      See 17Label_Font for more
      information about Fonts.

     ******************************************************/
    ButtonRefPtr ExampleButton = OSG::Button::create();

    UIFontRefPtr ExampleFont = OSG::UIFont::create();
    ExampleFont->setSize(16);

    ExampleButton->setMinSize(Vec2f(50, 25));
    ExampleButton->setMaxSize(Vec2f(200, 100));
    ExampleButton->setPreferredSize(Vec2f(100, 50));
    ExampleButton->setToolTipText("Button 1 ToolTip");

    ExampleButton->setText("Button 1");
    ExampleButton->setFont(ExampleFont);
    ExampleButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
    ExampleButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0));
    ExampleButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
    ExampleButton->setAlignment(Vec2f(1.0,0.0));


    /******************************************************

      Create a ToggleButton and determine its
      characteristics.  ToggleButton inherits
      off of Button, so all characteristsics
      used above can be used with ToggleButtons
      as well.

      The only difference is that when pressed,
      ToggleButton remains pressed until pressed
      again.

      -setSelected(bool): Determine whether the
      ToggleButton is Selected (true) or
      deselected (false).

     ******************************************************/
    ToggleButtonRefPtr ExampleToggleButton = OSG::ToggleButton::create();

    ExampleToggleButton->setSelected(false);
    ExampleToggleButton->setText("ToggleMe");
    ExampleToggleButton->setToolTipText("Toggle Button ToolTip");


    // Create Background to be used with the MainInternalWindow
    ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create();
    MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));

    // Create The Internal Window
    InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create();
    LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create();
    // Assign the Button to the MainInternalWindow so it will be displayed
    // when the view is rendered.
    MainInternalWindow->pushToChildren(ExampleButton);
    MainInternalWindow->setLayout(MainInternalWindowLayout);
    MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
    MainInternalWindow->setPosition(Pnt2f(50,50));
    MainInternalWindow->setPreferredSize(Vec2f(300,300));
    MainInternalWindow->setTitle(std::string("Internal Window 1"));

    // Create The Internal Window
    InternalWindowRefPtr MainInternalWindow2 = OSG::InternalWindow::create();
    LayoutRefPtr MainInternalWindowLayout2 = OSG::FlowLayout::create();
    // Assign the Button to the MainInternalWindow so it will be displayed
    // when the view is rendered.
    MainInternalWindow2->pushToChildren(ExampleToggleButton);
    MainInternalWindow2->setLayout(MainInternalWindowLayout2);
    MainInternalWindow2->setBackgrounds(MainInternalWindowBackground);
    MainInternalWindow2->setPosition(Pnt2f(150,150));
    MainInternalWindow2->setPreferredSize(Vec2f(300,300));
    MainInternalWindow2->setTitle(std::string("Internal Window 2"));
    MainInternalWindow2->setIconable(false);
    MainInternalWindow2->setAllwaysOnTop(true);

    // Create the Drawing Surface
    UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create();
    TutorialDrawingSurface->setGraphics(TutorialGraphics);
    TutorialDrawingSurface->setEventProducer(TutorialWindow);

    TutorialDrawingSurface->openWindow(MainInternalWindow);
    TutorialDrawingSurface->openWindow(MainInternalWindow2);
    // Create the UI Foreground Object
    UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create();
    TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);
    mgr->setRoot(scene);

    // Add the UI Foreground Object to the Scene
    ViewportRefPtr TutorialViewport = mgr->getWindow()->getPort(0);
    TutorialViewport->addForeground(TutorialUIForeground);

    // Show the whole Scene
    mgr->showAll();


    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
                               WinSize,
                               "37InternalWindow");

    //Enter main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}
ForegroundRefPtr ApplicationStartScreen::createInterface(void)
{
    // Create the Graphics
    GraphicsRefPtr StartScreenUIGraphics = OSG::Graphics2D::create();



    UIFontRefPtr ButtonFont = OSG::UIFont::create();
    ButtonFont->setSize(32);

    ButtonRefPtr BuilderButton = ::OSG::Button::create();
    BuilderButton->setPreferredSize(Vec2f(200, 75));
    BuilderButton->setText("Builder");
    BuilderButton->setFont(ButtonFont);
    BuilderButton->addActionListener(&_BuilderButtonActionListener); 

    ButtonRefPtr PlayerButton = ::OSG::Button::create();
    PlayerButton->setPreferredSize(Vec2f(200, 75));
    PlayerButton->setText("Player");
    PlayerButton->setFont(ButtonFont);
    PlayerButton->addActionListener(&_PlayerButtonActionListener); 

    ButtonRefPtr ExitButton = ::OSG::Button::create();
    ExitButton->setPreferredSize(Vec2f(200, 75));
    ExitButton->setText("Exit");
    ExitButton->setFont(ButtonFont);
    ExitButton->addActionListener(&_ExitButtonActionListener); 

    //ButtonPanel
    PanelRefPtr ButtonPanel = Panel::createEmpty();
    LayoutRefPtr ButtonPanelLayout = OSG::FlowLayout::create();
    ButtonPanel->pushToChildren(BuilderButton);
    ButtonPanel->pushToChildren(PlayerButton);
    ButtonPanel->pushToChildren(ExitButton);
    ButtonPanel->setLayout(ButtonPanelLayout);

    //Font
    UIFontRefPtr LabelFont = UIFont::create();
    LabelFont->setSize(16);

    //Version Label
    LabelRefPtr VersionLabel = OSG::Label::create();
    VersionLabel->setText("Version:");
    VersionLabel->setAlignment(Vec2f(1.0f,0.5f));
    VersionLabel->setPreferredSize(Vec2f(100,20));
    VersionLabel->setTextColors(Color4f(1.0f,1.0f,1.0f,1.0f));
    VersionLabel->setBackgrounds(NULL);
    VersionLabel->setBorders(NULL);
    VersionLabel->setFont(LabelFont);

    //Version Value Label
    LabelRefPtr VersionValueLabel = OSG::Label::create();
    VersionValueLabel->setText(getKabalaEngineVersion() + " - " + getKabalaEngineBuildType());
    VersionValueLabel->setPreferredSize(Vec2f(110,20));
    VersionValueLabel->setTextColors(Color4f(1.0f,1.0f,1.0f,1.0f));
    VersionValueLabel->setBackgrounds(NULL);
    VersionValueLabel->setBorders(NULL);
    VersionValueLabel->setFont(LabelFont);

    //Author Value Label
    LabelRefPtr AuthorValueLabel = OSG::Label::create();
    AuthorValueLabel->setText(getKabalaEngineAuthors());
    AuthorValueLabel->setPreferredSize(Vec2f(300,20));
    AuthorValueLabel->setTextColors(Color4f(1.0f,1.0f,1.0f,1.0f));
    AuthorValueLabel->setBackgrounds(NULL);
    AuthorValueLabel->setBorders(NULL);
    AuthorValueLabel->setFont(LabelFont);

    // Create The Main InternalWindow
    InternalWindowRefPtr StartScreenInternalWindow = OSG::InternalWindow::create();

    //Layout
    SpringLayoutRefPtr StartScreenInternalWindowLayout = OSG::SpringLayout::create();
    //::OSG::Button Panel
    StartScreenInternalWindowLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, ButtonPanel, 0, SpringLayoutConstraints::WEST_EDGE, StartScreenInternalWindow);
    StartScreenInternalWindowLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, ButtonPanel, 0, SpringLayoutConstraints::EAST_EDGE, StartScreenInternalWindow);
    StartScreenInternalWindowLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, ButtonPanel, 0, SpringLayoutConstraints::NORTH_EDGE, StartScreenInternalWindow);
    StartScreenInternalWindowLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, ButtonPanel, 0, SpringLayoutConstraints::SOUTH_EDGE, StartScreenInternalWindow);

    //Version Label
    StartScreenInternalWindowLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, VersionLabel, 0, SpringLayoutConstraints::WEST_EDGE, VersionValueLabel);
    StartScreenInternalWindowLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, VersionLabel, 0, SpringLayoutConstraints::SOUTH_EDGE, StartScreenInternalWindow);
    StartScreenInternalWindowLayout->putConstraint(SpringLayoutConstraints::HEIGHT_EDGE, VersionLabel, LayoutSpring::height(VersionLabel));
    StartScreenInternalWindowLayout->putConstraint(SpringLayoutConstraints::WIDTH_EDGE, VersionLabel, LayoutSpring::width(VersionLabel));

    //Version Value Label
    StartScreenInternalWindowLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, VersionValueLabel, 0, SpringLayoutConstraints::EAST_EDGE, StartScreenInternalWindow);
    StartScreenInternalWindowLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, VersionValueLabel, 0, SpringLayoutConstraints::SOUTH_EDGE, StartScreenInternalWindow);
    StartScreenInternalWindowLayout->putConstraint(SpringLayoutConstraints::HEIGHT_EDGE, VersionValueLabel, LayoutSpring::height(VersionValueLabel));
    StartScreenInternalWindowLayout->putConstraint(SpringLayoutConstraints::WIDTH_EDGE, VersionValueLabel, LayoutSpring::width(VersionValueLabel));

    //Author Value Label
    StartScreenInternalWindowLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, AuthorValueLabel, 0, SpringLayoutConstraints::WEST_EDGE, StartScreenInternalWindow);
    StartScreenInternalWindowLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, AuthorValueLabel, 0, SpringLayoutConstraints::SOUTH_EDGE, StartScreenInternalWindow);
    StartScreenInternalWindowLayout->putConstraint(SpringLayoutConstraints::HEIGHT_EDGE, AuthorValueLabel, LayoutSpring::height(AuthorValueLabel));
    StartScreenInternalWindowLayout->putConstraint(SpringLayoutConstraints::WIDTH_EDGE, AuthorValueLabel, LayoutSpring::width(AuthorValueLabel));

    StartScreenInternalWindow->pushToChildren(ButtonPanel);
    StartScreenInternalWindow->pushToChildren(AuthorValueLabel);
    StartScreenInternalWindow->pushToChildren(VersionLabel);
    StartScreenInternalWindow->pushToChildren(VersionValueLabel);
    StartScreenInternalWindow->setLayout(StartScreenInternalWindowLayout);
    StartScreenInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
    StartScreenInternalWindow->setScalingInDrawingSurface(Vec2f(1.0f,1.0f));
    StartScreenInternalWindow->setDrawTitlebar(false);
    StartScreenInternalWindow->setDrawDecorations(false);
    StartScreenInternalWindow->setResizable(false);

    // Create the Drawing Surface
    _TheUIDrawingSurface = UIDrawingSurface::create();
    _TheUIDrawingSurface->setGraphics(StartScreenUIGraphics);

    _TheUIDrawingSurface->openWindow(StartScreenInternalWindow);

    // Create the UI Foreground Object
    UIForegroundRefPtr StartScreenUIForeground = OSG::UIForeground::create();

    StartScreenUIForeground->setDrawingSurface(_TheUIDrawingSurface);

    return StartScreenUIForeground;
}
Esempio n. 8
0
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);
    
    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
        TutorialWindow->initWindow();

        // Create the SimpleSceneManager helper
        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
        TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);


        // Make Torus Node (creates Torus in background of scene)
        NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);

        // Make Main Scene Node and add the Torus
        NodeRefPtr scene = OSG::Node::create();
        scene->setCore(OSG::Group::create());
        scene->addChild(TorusGeometryNode);

        // Create the Graphics
        GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create();

        // Initialize the LookAndFeelManager to enable default settings
        LookAndFeelManager::the()->getLookAndFeel()->init();

        /******************************************************

          Create an Button Component and
          a simple Font.
          See 17Label_Font for more
          information about Fonts.

         ******************************************************/
        ButtonRefPtr ExampleButton = OSG::Button::create();

        UIFontRefPtr ExampleFont = OSG::UIFont::create();
        ExampleFont->setSize(16);

        /******************************************************

          Edit the Button's characteristics.
            Note: the first 4 functions can
            be used with any Component and 
            are not specific to Button.

            -setMinSize(Vec2f): Determine the 
            Minimum Size of the Component.
            Some Layouts will automatically
            resize Components; this prevents
            the Size from going below a
            certain value.
            -setMaxSize(Vec2f): Determine the 
            Maximum Size of the Component.
            -setPreferredSize(Vec2f): Determine
            the Preferred Size of the Component.
            This is what the Component will
            be displayed at unless changed by
            another Component (such as a 
            Layout).
            -setToolTipText("Text"): Determine
            what text is displayed while
            Mouse is hovering above Component.
            The word Text will be displayed
            in this case.

            Functions specfic to Button:
            -setText("DesiredText"): Determine 
            the Button's text.  It will read
            DesiredText in this case.
            -setFont(FontName): Determine the 
            Font to be used on the Button.
            -setTextColor(Color4f): Determine the
            Color for the text.
            -setRolloverTextColor(Color4f): Determine
            what the text Color will be when
            the Mouse Cursor is above the 
            Button.
            -setActiveTextColor(Color4f): Determine
            what the text Color will be when
            the Button is pressed (denoted by
            Active).
            -setAlignment(Vec2f):
            Determine the Vertical Alignment
            of the text.  The value is 
            in [0.0, 1.0].

         ******************************************************/
        ExampleButton->setMinSize(Vec2f(50, 25));
        ExampleButton->setMaxSize(Vec2f(200, 100));
        ExampleButton->setPreferredSize(Vec2f(100, 50));
        ExampleButton->setToolTipText("Button 1 ToolTip");

        ExampleButton->setText("Button 1");
        ExampleButton->setFont(ExampleFont);
        ExampleButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
        ExampleButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0));
        ExampleButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
        ExampleButton->setAlignment(Vec2f(1.0,0.0));

        // Create an Action and assign it to ExampleButton
        // This Class is defined above, and will cause the output
        // window to display "Button 1 Action" when pressed
        ExampleButton->connectActionPerformed(boost::bind(actionPerformed, _1));

        /******************************************************

          Create a ToggleButton and determine its 
          characteristics.  ToggleButton inherits
          off of Button, so all characteristsics
          used above can be used with ToggleButtons
          as well.

          The only difference is that when pressed,
          ToggleButton remains pressed until pressed 
          again.

          -setSelected(bool): Determine whether the 
          ToggleButton is Selected (true) or
          deselected (false).  

         ******************************************************/
        ToggleButtonRefPtr ExampleToggleButton = OSG::ToggleButton::create();

        ExampleToggleButton->setSelected(false);
        ExampleToggleButton->setText("ToggleMe");
        ExampleToggleButton->setToolTipText("Toggle Button ToolTip");

        //Button with Image
        ButtonRefPtr ExampleDrawObjectButton = OSG::Button::create();
        ExampleDrawObjectButton->setDrawObjectToTextAlignment(Button::ALIGN_DRAW_OBJECT_RIGHT_OF_TEXT);
        ExampleDrawObjectButton->setText("Icon");

        ExampleDrawObjectButton->setImage(std::string("./Data/Icon.png"));
        ExampleDrawObjectButton->setActiveImage(std::string("./Data/Icon.png"));
        ExampleDrawObjectButton->setFocusedImage(std::string("./Data/Icon.png"));
        ExampleDrawObjectButton->setRolloverImage(std::string("./Data/Icon.png"));
        ExampleDrawObjectButton->setDisabledImage(std::string("./Data/Icon.png"));

        // Create The Main InternalWindow
        // Create Background to be used with the Main InternalWindow
        ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create();
        MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
        InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create();
        LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create();
        MainInternalWindow->pushToChildren(ExampleButton);
        MainInternalWindow->pushToChildren(ExampleToggleButton);
        MainInternalWindow->pushToChildren(ExampleDrawObjectButton);
        MainInternalWindow->setLayout(MainInternalWindowLayout);
        MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
        MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
        MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f));
        MainInternalWindow->setDrawTitlebar(false);
        MainInternalWindow->setResizable(false);

        // Create the Drawing Surface
        UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create();
        TutorialDrawingSurface->setGraphics(TutorialGraphics);
        TutorialDrawingSurface->setEventProducer(TutorialWindow);

        TutorialDrawingSurface->openWindow(MainInternalWindow);

        // Create the UI Foreground Object
        UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create();

        TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);

        sceneManager.setRoot(scene);

        // Add the UI Foreground Object to the Scene
        ViewportRefPtr TutorialViewport = sceneManager.getWindow()->getPort(0);
        TutorialViewport->addForeground(TutorialUIForeground);


        //Create the Documentation Foreground and add it to the viewport
        SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);

        // Show the whole Scene
        sceneManager.showAll();

        //Attach key controls

        //Open Window
        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "01Button");

        commitChanges();

        //Enter main Loop
        TutorialWindow->mainLoop();
    }

    osgExit();

    return 0;
}
Esempio n. 9
0
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);

    // Make Torus Node (creates Torus in background of scene)
    NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);

    // Make Main Scene Node and add the Torus
    NodeRefPtr scene = OSG::Node::create();
        scene->setCore(OSG::Group::create());
        scene->addChild(TorusGeometryNode);

    // Create the Graphics
    GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create();

    // Initialize the LookAndFeelManager to enable default settings
    LookAndFeelManager::the()->getLookAndFeel()->init();

    /******************************************************
            
                Create PopupMenu Components
        
        -MenuItem: These are items that are contained
            within a Menu; they are the things you click
            on to cause something to occur
        -SeperatorMenuItem:  These place a seperator 
            line between items in a Menu
        -Menu: These are sub-menus within another Menu;
            MenuItems and SeperatorMenuItems
            are added to a Menu

    ******************************************************/

    MenuItemRefPtr MenuItem1 = MenuItem::create();
    MenuItemRefPtr MenuItem2 = MenuItem::create();
    MenuItemRefPtr MenuItem3 = MenuItem::create();
    MenuItemRefPtr MenuItem4 = MenuItem::create();
    MenuItemRefPtr SubMenuItem1 = MenuItem::create();
    MenuItemRefPtr SubMenuItem2 = MenuItem::create();
    MenuItemRefPtr SubMenuItem3 = MenuItem::create();
    MenuRefPtr ExampleSubMenu = Menu::create();
    
    /******************************************************
            
            Edit the MenuItems

            -setText("TEXT"): Sets the text on the 
                item to be TEXT
            -setEnabled(Boolean): sets the menu item
                to be either enabled or disabled

    ******************************************************/

        MenuItem1->setText("Menu Item 1");
    
        MenuItem2->setText("Menu Item 2");
    
        MenuItem3->setText("Menu Item 3");
    
        MenuItem4->setText("Menu Item 4");
        MenuItem4->setEnabled(false);
    
        SubMenuItem1->setText("SubMenu Item 1");
    
        SubMenuItem2->setText("SubMenu Item 2");
    
        SubMenuItem3->setText("SubMenu Item 3");
    
        ExampleSubMenu->setText("Sub Menu");

    // This adds three MenuItems to the Menu,
    // creating a submenu.  Note this does not
    // involve begin/endEditCPs to do

    ExampleSubMenu->addItem(SubMenuItem1);
    ExampleSubMenu->addItem(SubMenuItem2);
    ExampleSubMenu->addItem(SubMenuItem3);
    
    /******************************************************
            
            Create the PopupMenu itself.

            Items are added in the order in which
            they will be displayed (top to bottom)
            via addItem(ItemToBeAdded)

            The PopupMenu is attached to a 
			Button below using 
			setPopupMenu(PopupMenuName).  
			
			Note: PopupMenus can be added to any
			Component.

    ******************************************************/
    PopupMenuRefPtr ExamplePopupMenu = PopupMenu::create();
    ExamplePopupMenu->addItem(MenuItem1);
    ExamplePopupMenu->addItem(MenuItem2);
    ExamplePopupMenu->addItem(MenuItem3);
    ExamplePopupMenu->addSeparator();
    ExamplePopupMenu->addItem(ExampleSubMenu);
    ExamplePopupMenu->addItem(MenuItem4);
    
    // Create a Button and Font
    UIFontRefPtr PopupMenuButtonFont = OSG::UIFont::create();
        PopupMenuButtonFont->setSize(16);

    ButtonRefPtr PopupMenuButton = OSG::Button::create();
        PopupMenuButton->setText("RightClickMe!");
        // Add the PopupMenu to PopupMenuButton so that when right clicked,
        // the PopupMenu will appear
        PopupMenuButton->setPopupMenu(ExamplePopupMenu);
        PopupMenuButton->setPreferredSize(Vec2f(200,100));
        PopupMenuButton->setFont(PopupMenuButtonFont);


    // Create The Main InternalWindow
    // Create Background to be used with the Main InternalWindow
    ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create();
        MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));

    LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create();

    InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create();
       MainInternalWindow->pushToChildren(PopupMenuButton);
       MainInternalWindow->setLayout(MainInternalWindowLayout);
       MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
	   MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
	   MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f));
	   MainInternalWindow->setDrawTitlebar(false);
	   MainInternalWindow->setResizable(false);

    // Create the Drawing Surface
    UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create();
        TutorialDrawingSurface->setGraphics(TutorialGraphics);
        TutorialDrawingSurface->setEventProducer(TutorialWindow);
	
	TutorialDrawingSurface->openWindow(MainInternalWindow);

    // Create the UI Foreground Object
    UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create();

        TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);
    mgr->setRoot(scene);

    // Add the UI Foreground Object to the Scene
    ViewportRefPtr TutorialViewport = mgr->getWindow()->getPort(0);
        TutorialViewport->addForeground(TutorialUIForeground);

    // Show the whole Scene
    mgr->showAll();

    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
            WinSize,
            "01RubberBandCamera");

    //Enter main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}
Esempio n. 10
0
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
        TutorialWindow->initWindow();

        // Create the SimpleSceneManager helper
        SimpleSceneManagerRefPtr sceneManager = SimpleSceneManager::create();
        TutorialWindow->setDisplayCallback(boost::bind(display, sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, sceneManager));

        // Tell the Manager what to manage
        sceneManager->setWindow(TutorialWindow);

        TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1));

        // Make Torus Node (creates Torus in background of scene)
        NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);
       
        // Make Main Scene Node and add the Torus
        NodeRefPtr scene = OSG::Node::create();
            scene->setCore(OSG::Group::create());
            scene->addChild(TorusGeometryNode);

        // Create the Graphics
        GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create();

        // Initialize the LookAndFeelManager to enable default settings
        LookAndFeelManager::the()->getLookAndFeel()->init();

        /******************************************************

                Create the Layers.

        ******************************************************/

        ColorLayerRefPtr ExampleColorLayer = OSG::ColorLayer::create();
        CompoundLayerRefPtr ExampleCompoundLayer = OSG::CompoundLayer::create();
        EmptyLayerRefPtr ExampleEmptyLayer = OSG::EmptyLayer::create();
        GradientLayerRefPtr ExampleGradientLayer = OSG::GradientLayer::create();
        MaterialLayerRefPtr ExampleMaterialLayer = OSG::MaterialLayer::create();
        TextureLayerRefPtr ExampleTextureLayer = OSG::TextureLayer::create();
        PatternLayerRefPtr ExamplePatternLayer = OSG::PatternLayer::create();
        GlassLayerRefPtr ExampleGlassLayer = OSG::GlassLayer::create();
        CompoundLayerRefPtr ExampleGlassCompoundLayer = OSG::CompoundLayer::create();

        /******************************************************

            The ColorLayer is a simple Layer
            having just a Color to it.

            -setColor(Color4f): Determine the Color of
                the Layer.

        ******************************************************/

            ExampleColorLayer->setColor(Color4f(1.0,0.0,0.0,1.0));
        
        /******************************************************

                The CompoundLayer allows you to 
                combine multiple Backgrounds into one.

                The Backgrounds are added sequentially;
                so in this example the 
                ExampleTextureLayer would be added 
                first, and the ExampleGradientLayer
                rendered on top of it.  

                -getBackgrounds().push_back(BackgroundName):
                    Adds a Background to the 
                    CompoundBackground.

        ******************************************************/

            ExampleCompoundLayer->pushToBackgrounds(ExampleTextureLayer);
            ExampleCompoundLayer->pushToBackgrounds(ExampleGradientLayer);
        
        /******************************************************

                The EmptyLayer is a Background
                with no attributes.

        ******************************************************/

            // Nothing!
            
        /******************************************************

                The GradientLayer is a Background
                which displays a gradient of Color.

                -getColors().push_back(Color4f): Determines the 
                    starting Color for the gradient.
                -getColors().push_back(Color4f): Determines the
                    ending Color for the gradient.
                -setOrientation(ENUM): Determines the
                    gradient alignment.  Takes 
                    HORIZONTAL_ORIENTATION or 
                    VERTICAL_ORIENTATION arguments.

        ******************************************************/


            ExampleGradientLayer->editMFColors()->push_back(Color4f(1.0, 0.0, 0.0, 1.0));
            ExampleGradientLayer->editMFStops()->push_back(0.0);
            ExampleGradientLayer->editMFColors()->push_back(Color4f(0.0, 1.0, 0.0, 0.75));
            ExampleGradientLayer->editMFStops()->push_back(0.5);
            ExampleGradientLayer->editMFColors()->push_back(Color4f(0.0, 0.0, 1.0, 0.5));
            ExampleGradientLayer->editMFStops()->push_back(1.0);
            ExampleGradientLayer->setStartPosition(Vec2f(0.2f,0.2f));
            ExampleGradientLayer->setEndPosition(Vec2f(.6f,0.6f));
            ExampleGradientLayer->setSpreadMethod(GradientLayer::SPREAD_REFLECT);
            
        /******************************************************

                The MaterialLayer is a Background
                which is created using a Material (also
                created here).

                -setMaterial(MaterialName): Determine
                    which Material will be used to 
                    create the Background.

        ******************************************************/    
        // Creates Material
        ChunkMaterialRefPtr LayerMaterial = ChunkMaterial::create();
        MaterialChunkRefPtr LayerMaterialChunk = MaterialChunk::create();
          LayerMaterialChunk->setAmbient(Color4f(1.0,0.0,0.0,1.0));
          LayerMaterialChunk->setDiffuse(Color4f(0.0,1.0,0.0,1.0));
          LayerMaterialChunk->setSpecular(Color4f(0.0,0.0,1.0,1.0));

            LayerMaterial->addChunk(LayerMaterialChunk);

        // Edit MaterialLayer
            ExampleMaterialLayer->setMaterial(LayerMaterial);
            
        /******************************************************

                The TextureLayer is a Background
                which is created using a Texture (also
                created here).

                -setTexture(TextureName): Determine
                    which Texture will be used to 
                    create the Background.

        ******************************************************/   
        // Creates Texture from Image
        TextureObjChunkRefPtr LayerTextureObjChunk = TextureObjChunk::create();
        ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/Checker.jpg");    
            LayerTextureObjChunk->setImage(LoadedImage);

        // Edit TextureLayer
            ExampleTextureLayer->setTexture(LayerTextureObjChunk);

        /******************************************************

                The PatternLayer is a Background
                which is created using a Texture (also
                created here).

                -setTexture(TextureName): Determine
                    which Texture will be used to 
                    create the Background.
                -setPatternSize(Vec2f):
                -setVerticalAlignment():
                -setHorizontalAlignment():
                -setHorizontalRepeat():
                -setVerticalRepeat():
                -setHorizontalRepeatValue():
                -setVerticalRepeatValue():

        ******************************************************/  
        
       TextureObjChunkRefPtr LayerPatternChunk = TextureObjChunk::create();
       //ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/Checker.jpg");    
            LayerPatternChunk->setImage(LoadedImage);
            LayerPatternChunk->setWrapS(GL_REPEAT);
            LayerPatternChunk->setWrapT(GL_CLAMP_TO_EDGE);

            ExamplePatternLayer->setTexture(LayerPatternChunk);
            ExamplePatternLayer->setPatternSize(Vec2f(50.0f,50.0f));
            ExamplePatternLayer->setVerticalAlignment(0.5);
            ExamplePatternLayer->setHorizontalAlignment(0.0);
            ExamplePatternLayer->setHorizontalRepeat(PatternLayer::PATTERN_REPEAT_BY_POINT);
            ExamplePatternLayer->setVerticalRepeat(PatternLayer::PATTERN_REPEAT_ABSOLUTE);
            ExamplePatternLayer->setHorizontalRepeatValue(1.0);
            ExamplePatternLayer->setVerticalRepeatValue(2.0);
        /******************************************************

        ******************************************************/
        ExampleGlassLayer->setCenterColor(Color4f(1.0f,1.0f,1.0f,0.0f));
        ExampleGlassLayer->setEdgeColor(Color4f(1.0f,1.0f,1.0f,0.7f));

        /******************************************************

        ******************************************************/
        ExampleGlassCompoundLayer->pushToBackgrounds(ExampleColorLayer);
        ExampleGlassCompoundLayer->pushToBackgrounds(ExampleGlassLayer);
        
        /******************************************************

                Create and edit Button Components to
                display the Layers.

        ******************************************************/

        ButtonRefPtr ExampleColorLayerButton = OSG::Button::create();
        ButtonRefPtr ExampleCompoundLayerButton = OSG::Button::create();
        ButtonRefPtr ExampleEmptyLayerButton = OSG::Button::create();
        ButtonRefPtr ExampleGradientLayerButton = OSG::Button::create();    
        ButtonRefPtr ExampleMaterialLayerButton = OSG::Button::create();
        ButtonRefPtr ExampleTextureLayerButton = OSG::Button::create();
        ButtonRefPtr ExamplePatternLayerButton = OSG::Button::create();
        ButtonRefPtr ExampleGlassLayerButton = OSG::Button::create();
        ButtonRefPtr ExampleGlassCompoundLayerButton = OSG::Button::create();
        

            ExampleColorLayerButton->setText("Color Layer");
            ExampleColorLayerButton->setBackground(ExampleColorLayer);
            ExampleColorLayerButton->setActiveBackground(ExampleColorLayer);
            ExampleColorLayerButton->setRolloverBackground(ExampleColorLayer);
            ExampleColorLayerButton->setPreferredSize(Vec2f(150,50));

            ExampleCompoundLayerButton->setText("Compound Layer");
            ExampleCompoundLayerButton->setBackground(ExampleCompoundLayer);
            ExampleCompoundLayerButton->setActiveBackground(ExampleCompoundLayer);
            ExampleCompoundLayerButton->setRolloverBackground(ExampleCompoundLayer);
            ExampleCompoundLayerButton->setPreferredSize(Vec2f(150,50));

            ExampleEmptyLayerButton->setText("Empty Layer");
            ExampleEmptyLayerButton->setBackground(ExampleEmptyLayer);
            ExampleEmptyLayerButton->setActiveBackground(ExampleEmptyLayer);
            ExampleEmptyLayerButton->setRolloverBackground(ExampleEmptyLayer);
            ExampleEmptyLayerButton->setPreferredSize(Vec2f(150,50));

            ExampleGradientLayerButton->setText("Gradient Layer");
            ExampleGradientLayerButton->setBackground(ExampleGradientLayer);
            ExampleGradientLayerButton->setActiveBackground(ExampleGradientLayer);
            ExampleGradientLayerButton->setRolloverBackground(ExampleGradientLayer);
            ExampleGradientLayerButton->setPreferredSize(Vec2f(150,50));
        
            ExampleMaterialLayerButton->setText("Material Layer");
            ExampleMaterialLayerButton->setBackground(ExampleMaterialLayer);
            ExampleMaterialLayerButton->setActiveBackground(ExampleMaterialLayer);
            ExampleMaterialLayerButton->setRolloverBackground(ExampleMaterialLayer);
            ExampleMaterialLayerButton->setPreferredSize(Vec2f(150,50));
            ExampleMaterialLayerButton->setTextColor(Color4f(1.0,1.0,1.0,1.0));
            ExampleMaterialLayerButton->setRolloverTextColor(Color4f(1.0,1.0,1.0,1.0));
            ExampleMaterialLayerButton->setActiveTextColor(Color4f(1.0,1.0,1.0,1.0));

            ExampleTextureLayerButton->setText("Texture Layer");
            ExampleTextureLayerButton->setBackground(ExampleTextureLayer);
            ExampleTextureLayerButton->setActiveBackground(ExampleTextureLayer);
            ExampleTextureLayerButton->setRolloverBackground(ExampleTextureLayer);
            ExampleTextureLayerButton->setPreferredSize(Vec2f(150,50));
            ExampleTextureLayerButton->setTextColor(Color4f(0.0,1.0,0.0,1.0));
            ExampleTextureLayerButton->setRolloverTextColor(Color4f(0.0,1.0,0.0,1.0));
            ExampleTextureLayerButton->setActiveTextColor(Color4f(0.0,1.0,0.0,1.0));
        
            ExamplePatternLayerButton->setText("Pattern Layer");
            ExamplePatternLayerButton->setBackground(ExamplePatternLayer);
            ExamplePatternLayerButton->setActiveBackground(ExamplePatternLayer);
            ExamplePatternLayerButton->setRolloverBackground(ExamplePatternLayer);
            ExamplePatternLayerButton->setPreferredSize(Vec2f(150,50));
            ExamplePatternLayerButton->setTextColor(Color4f(0.0,1.0,0.0,1.0));
            ExamplePatternLayerButton->setRolloverTextColor(Color4f(0.0,1.0,0.0,1.0));
            ExamplePatternLayerButton->setActiveTextColor(Color4f(0.0,1.0,0.0,1.0));
        
            ExampleGlassLayerButton->setText("Glass Layer");
            ExampleGlassLayerButton->setBackground(ExampleGlassLayer);
            ExampleGlassLayerButton->setActiveBackground(ExampleGlassLayer);
            ExampleGlassLayerButton->setRolloverBackground(ExampleGlassLayer);
            ExampleGlassLayerButton->setPreferredSize(Vec2f(150,50));
            ExampleGlassLayerButton->setTextColor(Color4f(0.0,0.0,0.0,1.0));
            ExampleGlassLayerButton->setRolloverTextColor(Color4f(0.0,0.0,0.0,1.0));
            ExampleGlassLayerButton->setActiveTextColor(Color4f(0.0,0.0,0.0,1.0));
        
            ExampleGlassCompoundLayerButton->setText("GlassCompound Layer");
            ExampleGlassCompoundLayerButton->setBackground(ExampleGlassCompoundLayer);
            ExampleGlassCompoundLayerButton->setActiveBackground(ExampleGlassCompoundLayer);
            ExampleGlassCompoundLayerButton->setRolloverBackground(ExampleGlassCompoundLayer);
            ExampleGlassCompoundLayerButton->setPreferredSize(Vec2f(150,50));
            ExampleGlassCompoundLayerButton->setTextColor(Color4f(0.0,0.0,0.0,1.0));
            ExampleGlassCompoundLayerButton->setRolloverTextColor(Color4f(0.0,0.0,0.0,1.0));
            ExampleGlassCompoundLayerButton->setActiveTextColor(Color4f(0.0,0.0,0.0,1.0));


        
        /******************************************************

                Create a MainFrameBackground.  For almost
                all Tutorials, this is simply a 
                ColorLayer with a semi-transparent
                white Background.

        ******************************************************/

        // Create The Main InternalWindow
        // Create Background to be used with the Main InternalWindow
        ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create();
            MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));

        //InternalWindow Layout
        LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create();

        InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create();

           MainInternalWindow->pushToChildren(ExampleColorLayerButton);
           MainInternalWindow->pushToChildren(ExampleCompoundLayerButton);
           MainInternalWindow->pushToChildren(ExampleEmptyLayerButton);
           MainInternalWindow->pushToChildren(ExampleGradientLayerButton);
           MainInternalWindow->pushToChildren(ExampleMaterialLayerButton);
           MainInternalWindow->pushToChildren(ExampleTextureLayerButton);
           MainInternalWindow->pushToChildren(ExamplePatternLayerButton);
           MainInternalWindow->pushToChildren(ExampleGlassLayerButton);
           MainInternalWindow->pushToChildren(ExampleGlassCompoundLayerButton);
           MainInternalWindow->setLayout(MainInternalWindowLayout);
           MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
           MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
           MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f));
           MainInternalWindow->setDrawTitlebar(false);
           MainInternalWindow->setResizable(false);
        
        // Create the Drawing Surface
        UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create();
            TutorialDrawingSurface->setGraphics(TutorialGraphics);
            TutorialDrawingSurface->setEventProducer(TutorialWindow);
        
        TutorialDrawingSurface->openWindow(MainInternalWindow);

        // Create the UI Foreground Object
        UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create();

            TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);


        // Create the SimpleSceneManager helper
        sceneManager->setRoot(scene);

        // Add the UI Foreground Object to the Scene
        ViewportRefPtr TutorialViewport = sceneManager->getWindow()->getPort(0);
        TutorialViewport->addForeground(TutorialUIForeground);

        //Create the Documentation Foreground and add it to the viewport
        SimpleScreenDoc TheSimpleScreenDoc(sceneManager, TutorialWindow);

        // Show the whole Scene
        sceneManager->showAll();

        //Open Window
        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                WinSize,
                "04Background");

        //Enter main Loop
        TutorialWindow->mainLoop();
    }

    osgExit();

    return 0;
}
Esempio n. 11
0
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);
    
    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
        TutorialWindow->initWindow();

        // Create the SimpleSceneManager helper
        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);

        TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1));

        // Make Torus Node (creates Torus in background of scene)
        NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);

        // Make Main Scene Node and add the Torus
        NodeRefPtr scene = OSG::Node::create();
        scene->setCore(OSG::Group::create());
        scene->addChild(TorusGeometryNode);

        // Create the Graphics
        GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create();

        // Initialize the LookAndFeelManager to enable default settings
        LookAndFeelManager::the()->getLookAndFeel()->init();

        ButtonRefPtr ExampleButton = OSG::Button::create();
        ExampleButton->setMinSize(Vec2f(50, 25));
        ExampleButton->setMaxSize(Vec2f(200, 100));
        ExampleButton->setPreferredSize(Vec2f(100, 50));
        ExampleButton->setText("Button 1");

        // Create an ActionListener and assign it to ExampleButton
        // This Class is defined above, and will cause the output
        // window to display "Button 1 Action" when pressed
        ExampleButton->connectActionPerformed(boost::bind(actionPerformed, _1));

        //Toggle Button
        ToggleButtonRefPtr ExampleToggleButton = OSG::ToggleButton::create();
        ExampleToggleButton->setSelected(false);
        ExampleToggleButton->setText("ToggleMe");


        //Text Field
        TextFieldRefPtr ExampleTextField = OSG::TextField::create();
        
        //Password Field
        PasswordFieldRefPtr ExamplePasswordField = OSG::PasswordField::create();

        LayoutRefPtr MainLayout = OSG::FlowLayout::create();

        //Panel
        PanelRecPtr ExamplePanel = Panel::create();
        ExamplePanel->setPreferredSize(Vec2f(200.0f,200.0f));
        ExamplePanel->setLayout(MainLayout);
        ExamplePanel->pushToChildren(ExampleTextField);
        ExamplePanel->pushToChildren(ExamplePasswordField);

        //Text Field 2
        TextFieldRefPtr ExampleTextField2 = OSG::TextField::create();

        // Create The Main InternalWindow
        // Create Background to be used with the Main InternalWindow
        ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create();
        MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));

        InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create();
        MainInternalWindow->pushToChildren(ExampleButton);
        MainInternalWindow->pushToChildren(ExampleToggleButton);
        MainInternalWindow->pushToChildren(ExamplePanel);
        MainInternalWindow->pushToChildren(ExampleTextField2);

        MainInternalWindow->setLayout(MainLayout);
        MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
        MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
        MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f));
        MainInternalWindow->setDrawTitlebar(false);
        MainInternalWindow->setResizable(false);

        // Create the Drawing Surface
        UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create();
        TutorialDrawingSurface->setGraphics(TutorialGraphics);
        TutorialDrawingSurface->setEventProducer(TutorialWindow);

        TutorialDrawingSurface->openWindow(MainInternalWindow);

        // Create the UI Foreground Object
        UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create();

        TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);

        sceneManager.setRoot(scene);

        // Add the UI Foreground Object to the Scene
        ViewportRefPtr TutorialViewport = sceneManager.getWindow()->getPort(0);
        TutorialViewport->addForeground(TutorialUIForeground);

        //Create the Documentation Foreground and add it to the viewport
        SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);

        // Show the whole Scene
        sceneManager.showAll();


        //Open Window
        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5f);
        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "54FocusProgession");

        commitChanges();

        //Enter main Loop
        TutorialWindow->mainLoop();
    }

    osgExit();

    return 0;
}
Esempio n. 12
0
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);
    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
        TutorialWindow->initWindow();

        // Create the SimpleSceneManager helper
        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);


        // Make Torus Node (creates Torus in background of scene)
        NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);

        // Make Main Scene Node and add the Torus
        NodeRefPtr scene = Node::create();
        scene->setCore(Group::create());
        scene->addChild(TorusGeometryNode);

        // Create the Graphics
        GraphicsRefPtr TutorialGraphics = Graphics2D::create();

        // Initialize the LookAndFeelManager to enable default settings
        LookAndFeelManager::the()->getLookAndFeel()->init();

	    TextEditorRefPtr theTextEditor = TextEditor::create();
	    theTextEditor->setPreferredSize(Vec2f(1000,700));
        theTextEditor->setIsSplit(false);
        theTextEditor->setClipboardVisible(false);

        //Toggle Button for clipboard
        ToggleButtonRefPtr ClipboardButton = ToggleButton::create();
        ClipboardButton->setPreferredSize(Vec2f(80, 40));
        ClipboardButton->setText("Clipboard");
        ClipboardButton->connectButtonSelected(boost::bind(handleClipboardSelected,
                                                           _1,
                                                           theTextEditor.get()));
        ClipboardButton->connectButtonDeselected(boost::bind(handleClipboardDeselected,
                                                           _1,
                                                           theTextEditor.get()));
        
        //Toggle Button for split panel
        ToggleButtonRefPtr SplitButton = ToggleButton::create();
        SplitButton->setPreferredSize(Vec2f(80, 40));
        SplitButton->setText("Split");
        SplitButton->connectButtonSelected(boost::bind(handleSplitSelected,
                                                           _1,
                                                           theTextEditor.get()));
        SplitButton->connectButtonDeselected(boost::bind(handleSplitDeselected,
                                                           _1,
                                                           theTextEditor.get()));
        
        ButtonRefPtr LoadButton = Button::create();

	    LoadButton->setMinSize(Vec2f(50, 25));
        LoadButton->setMaxSize(Vec2f(200, 100));
        LoadButton->setPreferredSize(Vec2f(80, 40));
        LoadButton->setToolTipText("Click to open a file browser window");
        LoadButton->setText("Load File");

        LoadButton->connectActionPerformed(boost::bind(handleLoadButtonAction, _1, TutorialWindow.get(), theTextEditor.get()));

    	  
	    ButtonRefPtr SaveButton = Button::create();

	    SaveButton->setMinSize(Vec2f(50, 25));
        SaveButton->setMaxSize(Vec2f(200, 100));
        SaveButton->setPreferredSize(Vec2f(80, 40));
        SaveButton->setToolTipText("Click to save the currently opened file");
        SaveButton->setText("Save File");

        SaveButton->connectActionPerformed(boost::bind(handleSaveButtonAction, _1, TutorialWindow.get(),theTextEditor.get()));

        //Button Panel
        LayoutRefPtr ButtonPanelLayout = FlowLayout::create();

        PanelRecPtr ButtonPanel = Panel::createEmpty();
        ButtonPanel->setPreferredSize(Vec2f(300, 300));
        ButtonPanel->setLayout(ButtonPanelLayout);
        ButtonPanel->pushToChildren(LoadButton);
        ButtonPanel->pushToChildren(SaveButton);
        ButtonPanel->pushToChildren(SplitButton);
        ButtonPanel->pushToChildren(ClipboardButton);

        // Create The Main InternalWindow
        // Create Background to be used with the Main InternalWindow
        ColorLayerRefPtr MainInternalWindowBackground = ColorLayer::create();
        MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));

        LayoutRefPtr MainInternalWindowLayout = FlowLayout::create();

        InternalWindowRefPtr MainInternalWindow = InternalWindow::create();
        //MainInternalWindow->pushToChildren(TextAreaScrollPanel);
        MainInternalWindow->pushToChildren(theTextEditor);
        MainInternalWindow->pushToChildren(ButtonPanel);
        MainInternalWindow->setLayout(MainInternalWindowLayout);
        MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
        MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
        MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.95f,0.95f));
        //MainInternalWindow->setDrawTitlebar(true);
        //MainInternalWindow->setResizable(true);

        // Create the Drawing Surface
        UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create();
        TutorialDrawingSurface->setGraphics(TutorialGraphics);
        TutorialDrawingSurface->setEventProducer(TutorialWindow);
    	
	    TutorialDrawingSurface->openWindow(MainInternalWindow);

        // Create the UI Foreground Object
        UIForegroundRefPtr TutorialUIForeground = UIForeground::create();

        TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);


        sceneManager.setRoot(scene);

        // Add the UI Foreground Object to the Scene
        ViewportRefPtr TutorialViewport = sceneManager.getWindow()->getPort(0);
        TutorialViewport->addForeground(TutorialUIForeground);
    		

        // Show the whole Scene
        sceneManager.showAll();

    	
        //Open Window
        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.95f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "06Editor");
        TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, theTextEditor.get()));

        commitChanges();

        //Enter main Loop
        TutorialWindow->mainLoop();
    }

    osgExit();

    return 0;
}
Esempio n. 13
0
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    /******************************************************

             Add MouseListeners and WindowListeners
             to the WindowEvent.

    ******************************************************/

    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseListener1 BasicListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindow->addMouseListener(&TheTutorialMouseListener);
    TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);
    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);

    // Make Torus Node (creates Torus in background of scene)
    NodeRefPtr TorusGeometryNode = makeTorus(90, 270, 16, 16);

    // Make Main Scene Node and add the Torus
    NodeRefPtr scene = OSG::Node::create();
    scene->setCore(OSG::Group::create());
    scene->addChild(TorusGeometryNode);

    // Create the Graphics
    GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create();

    // Initialize the LookAndFeelManager to enable default settings
    LookAndFeelManager::the()->getLookAndFeel()->init();


    LoadButton = Button::create();

    LoadButton->setMinSize(Vec2f(50, 25));
    LoadButton->setMaxSize(Vec2f(200, 100));
    LoadButton->setPreferredSize(Vec2f(100, 50));
    LoadButton->setToolTipText("Click to open a file browser window");
    LoadButton->setText("Load File");

    LoadButton->addActionListener(&BasicListener);

    SaveButton = Button::create();

    SaveButton->setMinSize(Vec2f(50, 25));
    SaveButton->setMaxSize(Vec2f(200, 100));
    SaveButton->setPreferredSize(Vec2f(100, 50));
    SaveButton->setToolTipText("Click to save the currently opened file");
    SaveButton->setText("Save File");

    SaveButton->addActionListener(&BasicListener);

    theTextEditor = TextEditor::create();
    theTextEditor->setPreferredSize(Vec2f(600,400));

    /*

    UIFontRefPtr _Font = UIFont::create();
    _Font->setFamily("SANS");
    _Font->setGap(3);
    _Font->setGlyphPixelSize(46);
    _Font->setSize(15);
    _Font->setTextureWidth(0);
    _Font->setStyle(TextFace::STYLE_PLAIN);

    ExampleTextDomArea->setPreferredSize(Vec2f(600, 400));
    ExampleTextDomArea->setWrapStyleWord(false);
    ExampleTextDomArea->setMinSize(Vec2f(600,400));
    ExampleTextDomArea->setFont(_Font);

    ExampleAdvancedTextDomArea = OSG::AdvancedTextDomArea::create();
    ExampleAdvancedTextDomArea->setPreferredSize(Vec2f(600,400));
    ExampleAdvancedTextDomArea->setMinSize(Vec2f(600,400));
    ExampleAdvancedTextDomArea->setGutterVisible(true);
    ExampleAdvancedTextDomArea->pushToChildren(ExampleTextDomArea);
    ExampleAdvancedTextDomArea->setLayout(LayoutRefPtr(OSG::FlowLayout::create()));
    ExampleAdvancedTextDomArea->setPreferredSize(Vec2f(600,400));
    ExampleAdvancedTextDomArea->setMinSize(Vec2f(600,400));

    ScrollPanelRefPtr TextAreaScrollPanel = ScrollPanel::create();
    TextAreaScrollPanel->setPreferredSize(Vec2f(600,400));
    TextAreaScrollPanel->setMinSize(Vec2f(600,400));
    TextAreaScrollPanel->setViewComponent(ExampleAdvancedTextDomArea);

    */

    ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create();
    MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));

    LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create();

    InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create();
    MainInternalWindow->pushToChildren(theTextEditor);
    MainInternalWindow->pushToChildren(LoadButton);
    MainInternalWindow->pushToChildren(SaveButton);
    MainInternalWindow->setLayout(MainInternalWindowLayout);
    MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
    MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
    MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.85f,0.85f));
    MainInternalWindow->setDrawTitlebar(true);
    MainInternalWindow->setResizable(false);


    /******************************************************

             The Drawing Surface is created the
             same as with previous Tutorials
             (however the MainInternalWindow is created
             in a function below).

    ******************************************************/

    UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create();
    TutorialDrawingSurface->setGraphics(TutorialGraphics);
    TutorialDrawingSurface->setEventProducer(TutorialWindow);

    TutorialDrawingSurface->openWindow(MainInternalWindow);

    /******************************************************

            Create the 3D UIRectangle.  This allows
            the DrawingSurface to be rotated relative
            to the screen, allowing a 3D aspect to
            the DrawingSurface.  The Surface
            can still be interacted with, so Buttons,
            Menus, etc. all will still function
            normally.

            -setPoint(Pnt3f): Determine the location
                of the UIRectangle in 3D space.  Keep
                in mind that (0,0,0) is located
                directly in the center of the sceen.
                (For our purposes it is the center
                of the tori.) The point is located
                on the lower left corner of the
                rectangle.
            -setWidth(float): Determine the Width
                of the UIRectangle.  This may
                physically appear different depending
                on where the UIRectangle is placed
                as above (due to it being located
                further away, etc).
            -setHeight(float): Determine the Height
                of the UIRectangle.  This may
                physically appear different depending
                on where the UIRectangle is placed
                as above (due to it being located
                further away, etc).
            -setDrawingSurface(DrawingSurface):
                Determine what DrawingSurface is
                drawn on the UIRectangle.  This
                will typically be the main
                DrawingSurface, however, multiple
                DrawingSurfaces can be used with
                multiple UIRectangles.


    ******************************************************/

    //Make A 3D Rectangle to draw the UI on
    UIRectangleRefPtr ExampleUIRectangle = UIRectangle::create();
    ExampleUIRectangle->setPoint(Pnt3f(-400,-400,200));
    ExampleUIRectangle->setWidth(800.0);
    ExampleUIRectangle->setHeight(800.0);
    ExampleUIRectangle->setDrawingSurface(TutorialDrawingSurface);

    /******************************************************

            Because the previous Tutorials used a
            Viewport to view the scene, which is
            no longer being used, the UIRectangle
            must be added to the scene for it to
            be displayed (identical to how the
            Torus is added).

            First, create a Node, and set its
            core to be the UIRectangle.  Then,
            add that to the scene Node which
            is created above.  This scene is
            then set as the Root for the view.
            It is possible to change this Root
            to be just the UIRectangle (as
            commented out below).

    ******************************************************/
    NodeRefPtr ExampleUIRectangleNode = OSG::Node::create();
    ExampleUIRectangleNode->setCore(ExampleUIRectangle);

    // Add the UIRectangle as a child to the scene
    scene->addChild(ExampleUIRectangleNode);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);
    mgr->setRoot(scene);
    //mgr->setRoot(ExampleUIRectangleNode);

    // Show the whole Scene
    mgr->showAll();


    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
                               WinSize,
                               "3DNotepad!!");

    //Enter main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}