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(keyPressed, _1)); // Make Torus Node (creates Torus in background of scene) NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 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(); /****************************************************** Create Grid Layout. Grid Layout arranges the objects in a grid, with user specified rows, columns, and gap size (conceptually imagine that an invisible grid is drawn, and components are placed into that grid one per "box"). Objects within the Grid Layout fill from left to right, and top to bottom, filling in each space sequentially. The Grid Layout "boxes" are each the same size as the largest object within the Layout. Smaller objects are automatically resized to fit this size unless they have Max/Min sizes assigned (similar to Box Layout). You can experiment with this by changing the size of the Buttons as shown in 01Button, editing the Max/Min size of the Buttons, or adding more Buttons to the scene. Note that if the Frame is too small, the objects will appear out of the Frame background. -setRows(int): Determine the number of rows in the Layout. -setColumns(int): Determine the number of columns in the Layout. -setHorizontalGap(int): Determine the number of pixels between each column. setVerticalGap(int): Determine the number of pixels between each row. ******************************************************/ GridLayoutRecPtr MainInternalWindowLayout = GridLayout::create(); MainInternalWindowLayout->setRows(3); MainInternalWindowLayout->setColumns(2); MainInternalWindowLayout->setHorizontalGap(4); MainInternalWindowLayout->setVerticalGap(4); /****************************************************** Create and edit some Button Components. Note that as with BoxLayout, Components are resized to fit their respective grid boxes. Unless a MaxSize is set, this will be the case. This will override even PreferredSizes (see ExampleButton3). ******************************************************/ ButtonRecPtr ExampleButton1 = Button::create(); ButtonRecPtr ExampleButton2 = Button::create(); ButtonRecPtr ExampleButton3 = Button::create(); ButtonRecPtr ExampleButton4 = Button::create(); ButtonRecPtr ExampleButton5 = Button::create(); ButtonRecPtr ExampleButton6 = Button::create(); ExampleButton1->setPreferredSize(Vec2f(50,50)); ExampleButton1->setMaxSize(Vec2f(50,50)); //if MaxSize is commented out, this button then will revert to being the same size as the others in the grid. ExampleButton2->setPreferredSize(Vec2f(200,100)); //<---- // | ExampleButton3->setPreferredSize(Vec2f(50,100)); //Notice that even though these two differ in size they appear the same on the grid // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleButton1); MainInternalWindow->pushToChildren(ExampleButton2); MainInternalWindow->pushToChildren(ExampleButton3); MainInternalWindow->pushToChildren(ExampleButton4); MainInternalWindow->pushToChildren(ExampleButton5); MainInternalWindow->pushToChildren(ExampleButton6); 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 UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr 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, "07GridLayout"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
/*----------------------------- class specific ----------------------------*/ void GenericFieldContainerEditor::onCreate(const GenericFieldContainerEditor *Id) { Inherited::onCreate(Id); if(Id != NULL) { _BoldFont = UIFont::create(); UIFontUnrecPtr ProtoFont(dynamic_cast<Label*>(Label::getClassType().getPrototype())->getFont()); _BoldFont->setFamily(ProtoFont->getFamily()); _BoldFont->setGlyphPixelSize(ProtoFont->getGlyphPixelSize()); _BoldFont->setSize(ProtoFont->getSize()); _BoldFont->setStyle(TextFace::STYLE_BOLD); BorderLayoutConstraintsRefPtr WestConstraint = BorderLayoutConstraints::create(); WestConstraint->setRegion(BorderLayoutConstraints::BORDER_WEST); BorderLayoutConstraintsRefPtr NorthConstraint = BorderLayoutConstraints::create(); NorthConstraint->setRegion(BorderLayoutConstraints::BORDER_NORTH); BorderLayoutConstraintsRefPtr CenterConstraint = BorderLayoutConstraints::create(); CenterConstraint->setRegion(BorderLayoutConstraints::BORDER_CENTER); BorderLayoutConstraintsRefPtr SouthConstraint = BorderLayoutConstraints::create(); SouthConstraint->setRegion(BorderLayoutConstraints::BORDER_SOUTH); //Backgournds ColorLayerRefPtr HeaderBgLayer = ColorLayer::create(); HeaderBgLayer->setColor(Color4f(0.7f,0.7f,0.7f,1.0f)); //Type Panel _ContainerTypeLabel = Label::create(); _ContainerTypeLabel->setAlignment(Vec2f(0.5f,0.5f)); _ContainerTypeLabel->setBackgrounds(HeaderBgLayer); _ContainerTypeLabel->setConstraints(WestConstraint); _ContainerTypeLabel->setPreferredSize(Vec2f(160.0f,22.0f)); _ContainerIdLabel = Label::create(); _ContainerIdLabel->setAlignment(Vec2f(0.5f,0.5f)); _ContainerIdLabel->setBackgrounds(HeaderBgLayer); _ContainerIdLabel->setConstraints(CenterConstraint); BorderLayoutRefPtr TheBorderLayout = BorderLayout::create(); PanelRefPtr TypePanel = Panel::createEmpty(); TypePanel->setPreferredSize(Vec2f(160.0f,33.0f)); TypePanel->setInset(Vec4f(1.0f,1.0f,1.0f,10.0f)); TypePanel->pushToChildren(_ContainerIdLabel); TypePanel->pushToChildren(_ContainerTypeLabel); TypePanel->setLayout(TheBorderLayout); TypePanel->setConstraints(NorthConstraint); pushToChildren(TypePanel); //Fields Panel GridBagLayoutRecPtr AllFieldsPanelLayout = GridBagLayout::create(); AllFieldsPanelLayout->setColumns(1); _FieldsContainer = Panel::createEmpty(); _FieldsContainer->setConstraints(CenterConstraint); _FieldsContainer->setLayout(AllFieldsPanelLayout); if(getShowFields()) { pushToChildren(_FieldsContainer); } //Events Panel GridLayoutRecPtr AllProducedEventsPanelLayout = GridLayout::create(); AllProducedEventsPanelLayout->setColumns(1); AllProducedEventsPanelLayout->setHorizontalGap(0.0f); AllProducedEventsPanelLayout->setVerticalGap(0.0f); _ProducedEventsContainer = Panel::createEmpty(); _ProducedEventsContainer->setConstraints(SouthConstraint); _ProducedEventsContainer->setLayout(AllProducedEventsPanelLayout); _ProducedEventsContainer->setInset(Vec4f(0.0f,0.0f,15.0f,0.0f)); if(getShowEvents()) { pushToChildren(_ProducedEventsContainer); } //Main Layout BorderLayoutRefPtr MainLayout = BorderLayout::create(); setLayout(MainLayout); _GenericNameAttachmentEditor = GenericNameAttachmentEditor::create(); } }
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(keyPressed, _1)); NodeRecPtr Root(NULL); if(argc == 2) { Root = SceneFileHandler::the()->read(argv[1]); } if(Root == NULL) { // Make Torus Node (creates Torus in background of Root) NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); setName(TorusGeometryNode, std::string("Torus")); NodeRecPtr TorusNode = Node::create(); TorusNode->setCore(Transform::create()); TorusNode->addChild(TorusGeometryNode); setName(TorusNode, std::string("Torus Transform")); NodeRecPtr SphereGeometryNode = makeSphere(2,1.0f); setName(SphereGeometryNode, std::string("Sphere")); NodeRecPtr BoxGeometryNode = makeBox(1.0,1.0,1.0,1,1,1); setName(BoxGeometryNode, std::string("Box")); // Make Main Scene Node and add the Torus Root = Node::create(); Root->setCore(Group::create()); Root->addChild(TorusNode); Root->addChild(SphereGeometryNode); Root->addChild(BoxGeometryNode); setName(Root, std::string("Root")); } // Create the Graphics GraphicsRecPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); //Tree Model SceneGraphTreeModelRecPtr TheTreeModel = SceneGraphTreeModel::create(); TheTreeModel->setRoot(Root); //Create the Tree TreeRecPtr TheTree = Tree::create(); TheTree->setPreferredSize(Vec2f(100, 500)); TheTree->setModel(TheTreeModel); // Create a ScrollPanel for easier viewing of the List (see 27ScrollPanel) BorderLayoutConstraintsRecPtr SceneTreeConstraints = BorderLayoutConstraints::create(); SceneTreeConstraints->setRegion(BorderLayoutConstraints::BORDER_WEST); ScrollPanelRecPtr ExampleScrollPanel = ScrollPanel::create(); ExampleScrollPanel->setPreferredSize(Vec2f(350,300)); ExampleScrollPanel->setConstraints(SceneTreeConstraints); //ExampleScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); //ExampleScrollPanel->setVerticalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); ExampleScrollPanel->setViewComponent(TheTree); //Details Panel Labels LabelRecPtr NodeNameLabel = Label::create(); NodeNameLabel->setText("Name"); NodeNameLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); LabelRecPtr NodeNameValueLabel = Label::create(); NodeNameValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRecPtr NodeCoreTypeLabel = Label::create(); NodeCoreTypeLabel->setText("Core Type"); NodeCoreTypeLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); LabelRecPtr NodeCoreTypeValueLabel = Label::create(); NodeCoreTypeValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRecPtr NodeMinLabel = Label::create(); NodeMinLabel->setText("Min"); NodeMinLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); LabelRecPtr NodeMinValueLabel = Label::create(); NodeMinValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRecPtr NodeMaxLabel = Label::create(); NodeMaxLabel->setText("Max"); NodeMaxLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); LabelRecPtr NodeMaxValueLabel = Label::create(); NodeMaxValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRecPtr NodeCenterLabel = Label::create(); NodeCenterLabel->setText("Center"); NodeCenterLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); LabelRecPtr NodeCenterValueLabel = Label::create(); NodeCenterValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRecPtr NodeTriCountLabel = Label::create(); NodeTriCountLabel->setText("TriCount"); NodeTriCountLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); LabelRecPtr NodeTriCountValueLabel = Label::create(); NodeTriCountValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRecPtr NodeTravMaskLabel = Label::create(); NodeTravMaskLabel->setText("Traversal Mask"); NodeTravMaskLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); LabelRecPtr NodeTravMaskValueLabel = Label::create(); NodeTravMaskValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); //Details Panel BorderLayoutConstraintsRecPtr NodeDetailPanelConstraints = BorderLayoutConstraints::create(); NodeDetailPanelConstraints->setRegion(BorderLayoutConstraints::BORDER_SOUTH); GridLayoutRecPtr NodeDetailPanelLayout = GridLayout::create(); NodeDetailPanelLayout->setRows(7); NodeDetailPanelLayout->setColumns(2); NodeDetailPanelLayout->setHorizontalGap(2); NodeDetailPanelLayout->setVerticalGap(2); PanelRecPtr NodeDetailPanel = Panel::create(); NodeDetailPanel->setConstraints(NodeDetailPanelConstraints); NodeDetailPanel->setPreferredSize(Vec2f(100.0f, 200.0f)); NodeDetailPanel->setLayout(NodeDetailPanelLayout); NodeDetailPanel->pushToChildren(NodeNameLabel); NodeDetailPanel->pushToChildren(NodeNameValueLabel); NodeDetailPanel->pushToChildren(NodeCoreTypeLabel); NodeDetailPanel->pushToChildren(NodeCoreTypeValueLabel); NodeDetailPanel->pushToChildren(NodeMinLabel); NodeDetailPanel->pushToChildren(NodeMinValueLabel); NodeDetailPanel->pushToChildren(NodeMaxLabel); NodeDetailPanel->pushToChildren(NodeMaxValueLabel); NodeDetailPanel->pushToChildren(NodeCenterLabel); NodeDetailPanel->pushToChildren(NodeCenterValueLabel); NodeDetailPanel->pushToChildren(NodeTriCountLabel); NodeDetailPanel->pushToChildren(NodeTriCountValueLabel); NodeDetailPanel->pushToChildren(NodeTravMaskLabel); NodeDetailPanel->pushToChildren(NodeTravMaskValueLabel); SelectionHandler TheTreeSelectionHandler(TheTree, &sceneManager, NodeNameValueLabel, NodeCoreTypeValueLabel, NodeMinValueLabel, NodeMaxValueLabel, NodeCenterValueLabel, NodeTriCountValueLabel, NodeTravMaskValueLabel); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); LayoutRecPtr MainInternalWindowLayout = BorderLayout::create(); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleScrollPanel); MainInternalWindow->pushToChildren(NodeDetailPanel); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(NULL); MainInternalWindow->setBorders(NULL); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.0f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(1.0,1.0)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager.setRoot(Root); // Add the UI Foreground Object to the Scene ViewportRecPtr 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, "52SceneGraphTree"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }