예제 #1
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->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
        TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
        TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
        TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
        TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1));

        // Make Main Scene Node
        NodeRecPtr Scene = makeCoredNode<Group>();
        
        NodeRecPtr TorusNode  = createTorus();
        NodeRecPtr SphereNode = createSphere();
        NodeRecPtr ConeNode   = createCone();
        NodeRecPtr BoxNode    = createBox();

        Scene->addChild(TorusNode);
        Scene->addChild(SphereNode);
        Scene->addChild(ConeNode);
        Scene->addChild(BoxNode);

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

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


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

          Create a Background

         ******************************************************/
        ColorLayerRecPtr GreyBackground = ColorLayer::create();

        GreyBackground->setColor(Color4f(.93,.93,.93,1.0));


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

          Create some Borders

         ******************************************************/
        LineBorderRecPtr PanelBorder = LineBorder::create();
        EmptyBorderRecPtr Panel1Border = EmptyBorder::create();
        EmptyBorderRecPtr Panel2Border = EmptyBorder::create();
        EmptyBorderRecPtr emptyBorder = EmptyBorder::create();

        PanelBorder->setColor(Color4f(0.0,0.0,0.0,1.0));
        PanelBorder->setWidth(1);

        Panel1Border->setTopWidth(0);
        Panel1Border->setBottomWidth(6);
        Panel1Border->setLeftWidth(0);
        Panel1Border->setRightWidth(0);
        Panel2Border->setTopWidth(0);
        Panel2Border->setBottomWidth(0);
        Panel2Border->setLeftWidth(0);
        Panel2Border->setRightWidth(0);


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

          Create some Labels and stuff to go 
          with them

         ******************************************************/
        LabelRecPtr LeftPanelLabel1 = Label::create();
        UIFontRecPtr LeftPanelLabel1Font = UIFont::create();

        LeftPanelLabel1Font->setSize(50);

        LeftPanelLabel1->setBorders(emptyBorder);
        LeftPanelLabel1->setBackgrounds(GreyBackground);
        LeftPanelLabel1->setFont(LeftPanelLabel1Font);
        LeftPanelLabel1->setText("OSG Gui");
        LeftPanelLabel1->setPreferredSize(Vec2f(300, 100));
        LeftPanelLabel1->setAlignment(Vec2f(0.0f, 0.5f));

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

          Create some Layouts

         ******************************************************/
        BoxLayoutRecPtr MainInternalWindowLayout = BoxLayout::create();
        FlowLayoutRecPtr LeftPanelLayout = FlowLayout::create();
        BoxLayoutRecPtr RightPanelLayout = BoxLayout::create();
        MainInternalWindowLayout->setOrientation(BoxLayout::HORIZONTAL_ORIENTATION);

        LeftPanelLayout->setOrientation(FlowLayout::HORIZONTAL_ORIENTATION);
        LeftPanelLayout->setMinorAxisAlignment(1.0f);

        RightPanelLayout->setOrientation(BoxLayout::VERTICAL_ORIENTATION);


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

          Create MainFrame and Panels

         ******************************************************/
        PanelRecPtr LeftPanel = Panel::createEmpty();
        PanelRecPtr RightPanel = Panel::createEmpty();

        // LeftPanel stuff
        LeftPanel->setPreferredSize(Vec2f(400, 500));
        LeftPanel->pushToChildren(LeftPanelLabel1);
        PanelRecPtr LeftPanelButtonPanel = createLeftPanelButtonPanel();
        LeftPanel->pushToChildren(LeftPanelButtonPanel);
        PanelRecPtr LeftPanelRadioTextPanel = createLeftPanelRadioTextPanel();
        LeftPanel->pushToChildren(LeftPanelRadioTextPanel);
        LeftPanel->setLayout(LeftPanelLayout);
        LeftPanel->setBackgrounds(GreyBackground);
        LeftPanel->setBorders(Panel1Border);

        //RightPanel stuff
        RightPanel->setPreferredSize(Vec2f(200, 620));
        PanelRecPtr RightPanelButtonPanel = createRightPanelButtonPanel();
        RightPanel->pushToChildren(RightPanelButtonPanel);
        PanelRecPtr RightPanelCheckPanel = createRightPanelCheckPanel(TorusNode,
                                                                      SphereNode,
                                                                      ConeNode,  
                                                                      BoxNode);  
        RightPanel->pushToChildren(RightPanelCheckPanel);
        RightPanel->setLayout(RightPanelLayout);
        RightPanel->setBackgrounds(GreyBackground);
        RightPanel->setBorders(Panel2Border);

        // Create The Main InternalWindow
        InternalWindowRecPtr MainInternalWindow = InternalWindow::create();
        MainInternalWindow->pushToChildren(LeftPanel);
        MainInternalWindow->pushToChildren(RightPanel);
        MainInternalWindow->setLayout(MainInternalWindowLayout);
        MainInternalWindow->setBackgrounds(GreyBackground);
        MainInternalWindow->setBorders(PanelBorder);
        MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
        MainInternalWindow->setScalingInDrawingSurface(Vec2f(1.0f,1.0f));
        MainInternalWindow->setDrawTitlebar(false);
        MainInternalWindow->setResizable(false);
        //MainInternalWindow->setOpacity(0.7f);

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

        TutorialDrawingSurface->openWindow(MainInternalWindow);

        // Make A 3D Rectangle to draw the UI on
        UIRectangleRecPtr UIRectCore = UIRectangle::create();
        UIRectCore->setPoint(Pnt3f(-310.0,-310.0,370.0));
        UIRectCore->setWidth(620);
        UIRectCore->setHeight(620);
        UIRectCore->setDrawingSurface(TutorialDrawingSurface);

        NodeRecPtr UIRectNode = Node::create();
        UIRectNode->setCore(UIRectCore);

        // add the UIRect as a child
        Scene->addChild(UIRectNode);


        sceneManager.setRoot(Scene);

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

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

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

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

    osgExit();

    return 0;
}
예제 #2
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));

        TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, sceneManager));
        TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, sceneManager));
        TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, sceneManager));
        TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, sceneManager));
        TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1));

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

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

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

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

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

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

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

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

        UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create();
        TutorialDrawingSurface->setGraphics(TutorialGraphics);
        TutorialDrawingSurface->setEventProducer(TutorialWindow);
        TutorialDrawingSurface->setCursorAsImage(WindowEventProducer::CURSOR_POINTER,
                                                 BoostPath("./Data/cursor.png"),
                                                 Vec2f(-1.0f,-1.0f),
                                                 Vec2f(-12.0f,-20.0f));

        InternalWindowRecPtr MainUIWindow = createMainInternalWindow();
        TutorialDrawingSurface->openWindow(MainUIWindow);

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

          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
        UIRectangleRecPtr ExampleUIRectangle = UIRectangle::create();
        ExampleUIRectangle->setPoint(Pnt3f(-250,-250,200));
        ExampleUIRectangle->setWidth(500.0);
        ExampleUIRectangle->setHeight(500.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).

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

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


        // Tell the Manager what to manage
        sceneManager->setRoot(scene);
        //sceneManager->setRoot(ExampleUIRectangleNode);

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

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


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

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

    osgExit();

    return 0;
}