Ejemplo n.º 1
0
void LuaDebuggerInterface::createCodeEditor(void)
{
    //Create the Breakpoint images
    BoostPath BreakpointIconPath(_BaseIconDir / BoostPath("breakpoint.png")),
              BreakpointDisabledIconPath(_BaseIconDir / BoostPath("breakpoint-disabled.png")),
              BreakpointConditionalIconPath(_BaseIconDir / BoostPath("breakpoint-conditional.png")),
              BreakpointConditionalDisabledIconPath(_BaseIconDir / BoostPath("breakpoint-conditional-disabled.png")),
              BreakpointCountIconPath(_BaseIconDir / BoostPath("breakpoint-count.png")),
              BreakpointCountDisabledIconPath(_BaseIconDir / BoostPath("breakpoint-count-disabled.png"));
    
    //Breakpoint Button prototypes
    //Regular Breakpoint
    ButtonRecPtr BreakpointProtoButton = Button::create();
    BreakpointProtoButton->setPreferredSize(Vec2f(18.0f, 18.0f));
    BreakpointProtoButton->setImages(BreakpointIconPath.string());
    BreakpointProtoButton->setDisabledImage(BreakpointDisabledIconPath.string());
    BreakpointProtoButton->setBorders(NULL);
    BreakpointProtoButton->setBackgrounds(NULL);
    BreakpointProtoButton->setForegrounds(NULL);

    //Count Breakpoint
    ButtonRecPtr BreakpointCountProtoButton = Button::create();
    BreakpointCountProtoButton->setPreferredSize(Vec2f(18.0f, 18.0f));
    BreakpointCountProtoButton->setImages(BreakpointCountIconPath.string());
    BreakpointCountProtoButton->setDisabledImage(BreakpointCountDisabledIconPath.string());
    BreakpointCountProtoButton->setBorders(NULL);
    BreakpointCountProtoButton->setBackgrounds(NULL);
    BreakpointCountProtoButton->setForegrounds(NULL);

    //Conditional breakpoint
    ButtonRecPtr BreakpointConditionalProtoButton = Button::create();
    BreakpointConditionalProtoButton->setPreferredSize(Vec2f(18.0f, 18.0f));
    BreakpointConditionalProtoButton->setImages(BreakpointConditionalIconPath.string());
    BreakpointConditionalProtoButton->setDisabledImage(BreakpointConditionalDisabledIconPath.string());
    BreakpointConditionalProtoButton->setBorders(NULL);
    BreakpointConditionalProtoButton->setBackgrounds(NULL);
    BreakpointConditionalProtoButton->setForegrounds(NULL);

    //Create the default font
    _CodeFont = UIFont::create();
    _CodeFont->setFamily("Courier New");
    _CodeFont->setSize(21);
    _CodeFont->setGlyphPixelSize(22);
    _CodeFont->setAntiAliasing(false);

    // Create a TextArea component
    _CodeTextArea = TextEditor::create();
    _CodeTextArea->setIsSplit(false);
    _CodeTextArea->setClipboardVisible(false);
    //_CodeTextArea->getTextDomArea()->setFont(_CodeFont);
    //_CodeTextArea->setGutterWidth(50.0f);
    _CodeTextArea->setText(createDefaultCodeText());

    //_CodeTextArea->connectCaretChanged(boost::bind(&LuaDebuggerInterface::codeAreaCaretChanged,this, _1));
    //_CodeTextArea->connectMouseClicked(boost::bind(&LuaDebuggerInterface::handleCodeAreaMouseClicked,this, _1));

    _MainSplitPanel = SplitPanel::create();
    _MainSplitPanel->setMinComponent(_CodeTextArea);
    _MainSplitPanel->setMaxComponent(_InfoTabPanel);
    _MainSplitPanel->setOrientation(SplitPanel::VERTICAL_ORIENTATION);
    _MainSplitPanel->setDividerPosition(0.7);
    // location from the left/top
    _MainSplitPanel->setDividerSize(4);
    _MainSplitPanel->setMaxDividerPosition(.8);
    _MainSplitPanel->setMinDividerPosition(.2);

    //Code Area Info
    LabelRefPtr LineLabel = Label::create();
    LineLabel->setText("Line:");
    LineLabel->setPreferredSize(Vec2f(40.0f, 30.0f));
    LineLabel->setAlignment(Vec2f(1.0f, 0.5f));

    _LineValueLabel = Label::create();
    _LineValueLabel->setText("");
    _LineValueLabel->setPreferredSize(Vec2f(40.0f, 30.0f));

    LabelRefPtr ColumnLabel = Label::create();
    ColumnLabel->setText("Column:");
    ColumnLabel->setPreferredSize(Vec2f(55.0f, 30.0f));
    ColumnLabel->setAlignment(Vec2f(1.0f, 0.5f));

    _ColumnValueLabel = Label::create();
    _ColumnValueLabel->setText("");
    _ColumnValueLabel->setPreferredSize(Vec2f(40.0f, 30.0f));
    //TextArea Info Panel

    _CodeAreaInfoPanel = Panel::create();

    SpringLayoutRefPtr CodeAreaInfoLayout = SpringLayout::create();

    //ColumnValueLabel
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, _ColumnValueLabel, 0, SpringLayoutConstraints::NORTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _ColumnValueLabel, 0, SpringLayoutConstraints::SOUTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _ColumnValueLabel, 0, SpringLayoutConstraints::EAST_EDGE, _CodeAreaInfoPanel);

    //ColumnLabel    
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, ColumnLabel, 0, SpringLayoutConstraints::NORTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, ColumnLabel, 0, SpringLayoutConstraints::SOUTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, ColumnLabel, -1, SpringLayoutConstraints::WEST_EDGE, _ColumnValueLabel);

    //LineValueLabel    
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, _LineValueLabel, 0, SpringLayoutConstraints::NORTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _LineValueLabel, 0, SpringLayoutConstraints::SOUTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _LineValueLabel, -1, SpringLayoutConstraints::WEST_EDGE, ColumnLabel);

    //LineLabel    
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, LineLabel, 0, SpringLayoutConstraints::NORTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, LineLabel, 0, SpringLayoutConstraints::SOUTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, LineLabel, -1, SpringLayoutConstraints::WEST_EDGE, _LineValueLabel);

    _CodeAreaInfoPanel->setPreferredSize(Vec2f(400.0f, 22.0f));
    _CodeAreaInfoPanel->pushToChildren(LineLabel);
    _CodeAreaInfoPanel->pushToChildren(_LineValueLabel);
    _CodeAreaInfoPanel->pushToChildren(ColumnLabel);
    _CodeAreaInfoPanel->pushToChildren(_ColumnValueLabel);
    _CodeAreaInfoPanel->setBorders(NULL);
    _CodeAreaInfoPanel->setLayout(CodeAreaInfoLayout);
}
Ejemplo n.º 2
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 a simple Font to be used with the ExampleTextArea
    UIFontRefPtr ExampleFont = OSG::UIFont::create();
        ExampleFont->setSize(16);

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


        Create and edit the TextArea and determine its 
        characteristics.  A TextArea is a component 
        that allows you to enter text into the box via 
        keyboard input.  You can select text by    using 
        your mouse or pressing shift and the left and 
        right arrow keys.

        The only difference between a TextArea and
        TextField is that a TextArea can have 
        multiple lines of text 
        within it.

        -setTextColor(Color4f): Determine color of 
            text within TextArea.
        -setSelectionBoxColor(Color4f): Determine the
			color that highlighting around the 
			selected text appears.
        -setSelectionTextColor(Color4f): Determine the 
            color the selected text appears.
        -setText("TextToBeDisplayed"): Determine  
            initial text within TextArea.
        -setFont(FontName): Determine the Font 
			used within TextArea
        -setSelectionStart(StartCharacterNumber):
            Determine the character which the 
            selection will initially start after.
        -setSelectionEnd(EndCharacterNumber): 
            Determine the character which the 
            selection will end before.
        -setCaretPosition(Location): Determine the 
            location of the Caret within the TextArea.
			Note: this does not do too much
            currently because the only way 
            to cause the TextArea to gain focus is
            to click within it, causing the 
            Caret to move.
            
    ******************************************************/

    // Create a TextArea component
    TextAreaRefPtr ExampleTextArea = OSG::TextArea::create();

        ExampleTextArea->setPreferredSize(Vec2f(300, 200));
        ExampleTextArea->setMinSize(Vec2f(300, 200));
        ExampleTextArea->setTextColor(Color4f(0.0, 0.0, 0.0, 1.0));
        ExampleTextArea->setSelectionBoxColor(Color4f(0.0, 0.0, 1.0, 1.0));
        ExampleTextArea->setSelectionTextColor(Color4f(1.0, 1.0, 1.0, 1.0));
        // Determine the font and initial text
        ExampleTextArea->setText("What");
        ExampleTextArea->setFont(ExampleFont);
        // This will select the "a" from above
        ExampleTextArea->setSelectionStart(2);
        ExampleTextArea->setSelectionEnd(3);
        ExampleTextArea->setCaretPosition(2);
        //ExampleTextArea->setLineWrap(false);
        
    // Create a ScrollPanel
    ScrollPanelRefPtr TextAreaScrollPanel = ScrollPanel::create();
        TextAreaScrollPanel->setPreferredSize(Vec2f(200,200));
        TextAreaScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW);
    // Add the TextArea to the ScrollPanel so it is displayed
	TextAreaScrollPanel->setViewComponent(ExampleTextArea);

    
    // 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(TextAreaScrollPanel);
       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,
            "22TextArea");

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

    osgExit();

    return 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 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;
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
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 a simple Font to be used with the TextField
    UIFontRefPtr sampleFont = OSG::UIFont::create();
    sampleFont->setSize(16);

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


        Create and edit the TextField.  A TextField is
    	a Component which allows a single line of text
    	to be displayed.  Text can be entered via the
    	keyboard, and selected with arrow keys or
    	the Mouse.

        -setTextColor(Color4f): Determine the
    		Text Color.
        setSelectionBoxColor(Color4f): Determine
    		the Color of highlighting around
    		selected Text.
        -setSelectionTextColor(Color4f): Determine
    		the Color of selected Text.
        -setText("TextToBeDisplayed"): Determine
    	    initial Text within TextField.
        -setFont(FontName): Determine the Font
            used within TextField.
        -setSelectionStart(StartCharacterNumber):
            Determine the character with which
    		the selection will initially start.
        -setSelectionEnd(EndCharacterNumber):
            Determine the character which the
    		selection ends before.
        -setAlignment(float): Determine
    		the alignment of the text.
    		The float is a percentage is from the
    		top of the text [0.0-1.0].  Note: be
    		sure to visually verify this, as due
            to font size and line size this does
            not always place it exactly
            at the percentage point.

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

    // Create a TextField component
    TextFieldRefPtr ExampleTextField = OSG::TextField::create();

    ExampleTextField->setPreferredSize(Vec2f(100, 50));
    ExampleTextField->setTextColor(Color4f(0.0, 0.0, 0.0, 1.0));
    ExampleTextField->setSelectionBoxColor(Color4f(0.0, 0.0, 1.0, 1.0));
    ExampleTextField->setSelectionTextColor(Color4f(1.0, 1.0, 1.0, 1.0));
    ExampleTextField->setText("What");
    ExampleTextField->setFont(sampleFont);
    // The next two functions will select the "a" from above
    ExampleTextField->setSelectionStart(2);
    ExampleTextField->setSelectionEnd(3);
    ExampleTextField->setAlignment(Vec2f(0.0,0.5));

    // Create another TextField Component
    TextFieldRefPtr ExampleTextField2 = OSG::TextField::create();
    ExampleTextField2->setText("");
    ExampleTextField2->setEmptyDescText("Write in me, please");
    ExampleTextField2->setPreferredSize(Vec2f(200.0f,ExampleTextField2->getPreferredSize().y()));


    // 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(ExampleTextField);
    MainInternalWindow->pushToChildren(ExampleTextField2);
    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,
                               "16TextField");

    //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;
}
Ejemplo n.º 7
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;
}