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 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. ******************************************************/ GridLayoutRefPtr MainInternalWindowLayout = OSG::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). ******************************************************/ ButtonRefPtr ExampleButton1 = OSG::Button::create(); ButtonRefPtr ExampleButton2 = OSG::Button::create(); ButtonRefPtr ExampleButton3 = OSG::Button::create(); ButtonRefPtr ExampleButton4 = OSG::Button::create(); ButtonRefPtr ExampleButton5 = OSG::Button::create(); ButtonRefPtr ExampleButton6 = OSG::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 ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); InternalWindowRefPtr MainInternalWindow = OSG::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 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, "07GridLayout"); //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); NodeRefPtr Root(NULL); if(argc == 2) { Root = SceneFileHandler::the()->read(argv[1]); } if(Root == NULL) { // Make Torus Node (creates Torus in background of Root) NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); setName(TorusGeometryNode, std::string("Torus")); NodeRefPtr TorusNode = Node::create(); TorusNode->setCore(OSG::Transform::create()); TorusNode->addChild(TorusGeometryNode); setName(TorusNode, std::string("Torus Transform")); NodeRefPtr SphereGeometryNode = makeSphere(2,1.0f); setName(SphereGeometryNode, std::string("Sphere")); NodeRefPtr 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 = OSG::Node::create(); Root->setCore(OSG::Group::create()); Root->addChild(TorusNode); Root->addChild(SphereGeometryNode); Root->addChild(BoxGeometryNode); setName(Root, std::string("Root")); } // Create the Graphics GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); //Tree Model TheTreeModel = SceneGraphTreeModel::create(); TheTreeModel->setRoot(Root); //TheFileSystemTreeModel = FileSystemTreeModel::create(); //TheFileSystemTreeModel->setRoot(BoostPath("C:\\")); //TheFileSystemTreeModel->setRoot(BoostPath("/")); //Create the Tree TheTree = Tree::create(); TheTree->setPreferredSize(Vec2f(100, 500)); TheTree->setModel(TheTreeModel); //TheTree->setModel(TheFileSystemTreeModel); TutorialTreeSelectionListener TheTutorialTreeSelectionListener; TheTree->getSelectionModel()->addTreeSelectionListener(&TheTutorialTreeSelectionListener); // Create a ScrollPanel for easier viewing of the List (see 27ScrollPanel) BorderLayoutConstraintsRefPtr SceneTreeConstraints = OSG::BorderLayoutConstraints::create(); SceneTreeConstraints->setRegion(BorderLayoutConstraints::BORDER_WEST); ScrollPanelRefPtr 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 LabelRefPtr NodeNameLabel = Label::create(); NodeNameLabel->setText("Name"); NodeNameLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); NodeNameValueLabel = Label::create(); NodeNameValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRefPtr NodeCoreTypeLabel = Label::create(); NodeCoreTypeLabel->setText("Core Type"); NodeCoreTypeLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); NodeCoreTypeValueLabel = Label::create(); NodeCoreTypeValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRefPtr NodeMinLabel = Label::create(); NodeMinLabel->setText("Min"); NodeMinLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); NodeMinValueLabel = Label::create(); NodeMinValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRefPtr NodeMaxLabel = Label::create(); NodeMaxLabel->setText("Max"); NodeMaxLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); NodeMaxValueLabel = Label::create(); NodeMaxValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRefPtr NodeCenterLabel = Label::create(); NodeCenterLabel->setText("Center"); NodeCenterLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); NodeCenterValueLabel = Label::create(); NodeCenterValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRefPtr NodeTriCountLabel = Label::create(); NodeTriCountLabel->setText("TriCount"); NodeTriCountLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); NodeTriCountValueLabel = Label::create(); NodeTriCountValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRefPtr NodeTravMaskLabel = Label::create(); NodeTravMaskLabel->setText("Traversal Mask"); NodeTravMaskLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); NodeTravMaskValueLabel = Label::create(); NodeTravMaskValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRefPtr NodeOcclusionMaskLabel = Label::create(); NodeOcclusionMaskLabel->setText("Occlusion Mask"); NodeOcclusionMaskLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); NodeOcclusionMaskValueLabel = Label::create(); NodeOcclusionMaskValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRefPtr NodeActiveLabel = Label::create(); NodeActiveLabel->setText("Active"); NodeActiveLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); NodeActiveValueLabel = Label::create(); NodeActiveValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); //Details Panel BorderLayoutConstraintsRefPtr NodeDetailPanelConstraints = OSG::BorderLayoutConstraints::create(); NodeDetailPanelConstraints->setRegion(BorderLayoutConstraints::BORDER_SOUTH); GridLayoutRefPtr NodeDetailPanelLayout = OSG::GridLayout::create(); NodeDetailPanelLayout->setRows(9); NodeDetailPanelLayout->setColumns(2); NodeDetailPanelLayout->setHorizontalGap(2); NodeDetailPanelLayout->setVerticalGap(2); PanelRefPtr 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); NodeDetailPanel->pushToChildren(NodeOcclusionMaskLabel); NodeDetailPanel->pushToChildren(NodeOcclusionMaskValueLabel); NodeDetailPanel->pushToChildren(NodeActiveLabel); NodeDetailPanel->pushToChildren(NodeActiveValueLabel); // 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::BorderLayout::create(); InternalWindowRefPtr MainInternalWindow = OSG::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 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(Root); // 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, "52SceneGraphTree"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
ComponentTransitPtr PanelListComponentGenerator::getListComponent(List* const Parent, const boost::any& Value, UInt32 Index, bool IsSelected, bool HasFocus) { if(Value.empty()){ return ComponentTransitPtr(NULL); } std::string ValueString; try { ValueString = lexical_cast(Value); PanelRefPtr theComponent = Panel::create(); GridLayoutRefPtr PanelLayout = OSG::GridLayout::create(); PanelLayout->setRows(3); PanelLayout->setColumns(1); PanelLayout->setHorizontalGap(0); PanelLayout->setVerticalGap(2); std::stringstream is; is<<Index; std::string iss; is>>iss; TextFieldRefPtr theName = TextField::create(); theName->setText("Group"+iss); theName->setPreferredSize(Vec2f(146,20)); PanelRefPtr rangePanel = Panel::create(); GridLayoutRefPtr rangePanelLayout = OSG::GridLayout::create(); rangePanelLayout->setRows(1); rangePanelLayout->setColumns(4); rangePanelLayout->setHorizontalGap(2); rangePanelLayout->setVerticalGap(0); LabelRefPtr rangeLabel = Label::create(); rangeLabel->setText("Range:"); rangeLabel->setPreferredSize(Vec2f(35,20)); TextFieldRefPtr from = TextField::create(); from->setEmptyDescText("From"); from->setPreferredSize(Vec2f(35,20)); LabelRefPtr hiphenLabel = Label::create(); hiphenLabel->setText(" - "); hiphenLabel->setPreferredSize(Vec2f(35,20)); TextFieldRefPtr to = TextField::create(); to->setPreferredSize(Vec2f(35,20)); to->setEmptyDescText("To"); rangePanel->pushToChildren(rangeLabel); rangePanel->pushToChildren(from); rangePanel->pushToChildren(hiphenLabel); rangePanel->pushToChildren(to); rangePanel->setLayout(rangePanelLayout); rangePanel->setPreferredSize(Vec2f(146,20)); DefaultMutableComboBoxModelRefPtr TheComboBoxModel = DefaultMutableComboBoxModel::create(); TheComboBoxModel->addElement(boost::any(Color4f(1.0,0.0,0.0,1.0))); TheComboBoxModel->addElement(boost::any(Color4f(0.0,1.0,0.0,1.0))); TheComboBoxModel->addElement(boost::any(Color4f(0.0,0.0,1.0,1.0))); TheComboBoxModel->addElement(boost::any(Color4f(0.0,0.0,0.0,1.0))); TheComboBoxModel->addElement(boost::any(Color4f(1.0,1.0,1.0,1.0))); TheComboBoxModel->addElement(boost::any(std::string("More Colors"))); ColorChooserComboBoxComponentGeneratorRefPtr TheColorChooserComboBoxComponentGenerator = ColorChooserComboBoxComponentGenerator::create(); //Create the ComboBox ComboBoxRefPtr TheComboBox = ComboBox::create(); TheComboBox->setModel(TheComboBoxModel); TheComboBox->setCellGenerator(TheColorChooserComboBoxComponentGenerator); TheComboBox->setEditable(false); TheComboBox->setSelectedIndex(0); TheComboBox->setPreferredSize(Vec2f(146,20)); theComponent->pushToChildren(theName); theComponent->pushToChildren(rangePanel); theComponent->pushToChildren(TheComboBox); theComponent->setLayout(PanelLayout); theComponent->setPreferredSize(Vec2f(146,66)); Parent->setCellMajorAxisLength(66); return ComponentTransitPtr(theComponent.get()); } catch (boost::bad_lexical_cast &) { return ComponentTransitPtr(NULL); } }