void VideoFieldContainerEditor::onCreate(const VideoFieldContainerEditor *Id) { Inherited::onCreate(Id); if(GlobalSystemState != Startup) { //Create the Panel for the video preview PanelRecPtr VideoPanel = createVideoPreviewPanel(); ScrollPanelRecPtr EditorScrollPanel = ScrollPanel::create(); EditorScrollPanel->setViewComponent(_GenericEditor); _MainSplitPanel = SplitPanel::create(); _MainSplitPanel->setOrientation(SplitPanel::VERTICAL_ORIENTATION); _MainSplitPanel->setDividerPosition(350.0f); _MainSplitPanel->setMinComponent(VideoPanel); _MainSplitPanel->setMaxComponent(EditorScrollPanel); //Add the SplitPanel pushToChildren(_MainSplitPanel); //Set the layout constraints for the SplitPanel BorderLayoutConstraintsRecPtr CenterConstraints = BorderLayoutConstraints::create(); CenterConstraints->setRegion(BorderLayoutConstraints::BORDER_CENTER); _MainSplitPanel->setConstraints(CenterConstraints); //Set the layout BorderLayoutRecPtr MainLayout = BorderLayout::create(); setLayout(MainLayout); } }
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)); // 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 a Panel containing Buttons to add to ScrollPanel using a function (located at bottom of this file) ******************************************************/ PanelRecPtr ExampleViewablePanel = createPanelWithButtons(); /****************************************************** Create a UIViewport to use with the ScrollPanel. This sets up a secondary TutorialViewport inside the ScrollPanel. Without this, the ScrollPanel would not function correctly. The Panel created above is added to be viewed in the UIViewport and the size and position are set. ******************************************************/ UIViewportRecPtr ScrollPanelUIViewport = UIViewport::create(); ScrollPanelUIViewport->setViewComponent(ExampleViewablePanel); ScrollPanelUIViewport->setViewPosition(Pnt2f(150,150)); ScrollPanelUIViewport->setPreferredSize(Vec2f(200,200)); /****************************************************** Create the ScrollPanel itself. -setHorizontalResizePolicy(ScrollPanel:: ENUM): Determines the Horizontal resize policy. The ScrollPanel will automatically resize itself to the Size of its Component within for RESIZE_TO_VIEW, or add a ScrollBar as needed for NO_RESIZE. Takes NO_RESIZE and RESIZE_TO_VIEW arguments. -setVerticalResizePolicy(ScrollPanel:: ENUM): Determines the Vertical resize policy. The ScrollPanel will automatically resize itself to the Size of its Component within for RESIZE_TO_VIEW, or add a ScrollBar as needed for NO_RESIZE. Takes NO_RESIZE and RESIZE_TO_VIEW arguments. -setViewComponent(Component): Determine which Component will be added into the ScrollPanel. Note that this must be the same as the UIViewport created above and does not require a begin/endEditCP. ******************************************************/ ScrollPanelRecPtr ExampleScrollPanel = ScrollPanel::create(); ExampleScrollPanel->setPreferredSize(Vec2f(100,100)); ExampleScrollPanel->setVerticalScrollBarAlignment(ScrollPanel::SCROLLBAR_ALIGN_LEFT); ExampleScrollPanel->setHorizontalScrollBarAlignment(ScrollPanel::SCROLLBAR_ALIGN_BOTTOM); //ExampleScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); //ExampleScrollPanel->setVerticalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); ExampleScrollPanel->setViewComponent(ExampleViewablePanel); /****************************************************** Create two ScrollBars. First, create a DefaultBoundedRangeModel. This determines some characteristics of the Scrollbar. Note that you can link several ScollBars to the same DefaultBoundedRangeModel; this will cause them to move at the same time. -.setMinimum(int): Determine a numeric value for the beginning of the ScrollBar. Note that the visible size will be set separately. -.setMaximum(int): Determine a numeric value for the end of the ScrollBar. -.setValue(int): Determine the initial location of the Bar on the ScrollBar. This is determined from the Min/Max values. -.setExtent(int): Determine the size of the Bar on the ScrollBar as a fraction of the total size (which is determined from the Min/Max values) as well. Second, create the ScrollBar itself. -setOrientation(ENUM): Determine the orientation of the ScrollBar. Takes VERTICAL_ORIENTATION and HORIZONTAL_ORIENTATION arguments. -setUnitIncrement(int): Determines how much the Scoller moves per click on its end arrows. References to the Min/Max values as well. -setBlockIncrement(int): Determine how many units the ScrollBar moves when the "non-scroller" is clicked. This references the Min/Max values above as well (so if the Min/Max range was 0 to 100, and this was 100, then each click would move the scoller to the opposite end). It would also be impossible to directly click the scroller to a middle location. Note that while in this tutorial both ScrollBars use the same BoundedRangeModel (which causes them to be linked), each ScrollBar individually has these last two settings uniquely set. So while the Scrollers move together (because they use the same Model), using each will cause them to move at different speeds due to these settings being different. ******************************************************/ // Create a DefaultBoundedRangeModel DefaultBoundedRangeModelRecPtr TheBoundedRangeModel = DefaultBoundedRangeModel::create(); TheBoundedRangeModel->setMinimum(10); TheBoundedRangeModel->setMaximum(100); TheBoundedRangeModel->setValue(10); TheBoundedRangeModel->setExtent(20); ScrollBarRecPtr ExampleVerticalScrollBar = ScrollBar::create(); //ExampleScrollPanel->getHorizontalScrollBar() ExampleVerticalScrollBar->setOrientation(ScrollBar::VERTICAL_ORIENTATION); ExampleVerticalScrollBar->setPreferredSize(Vec2f(20,200)); ExampleVerticalScrollBar->setEnabled(false); ExampleVerticalScrollBar->setUnitIncrement(10); ExampleVerticalScrollBar->setBlockIncrement(100); ExampleVerticalScrollBar->setRangeModel(TheBoundedRangeModel); ScrollBarRecPtr ExampleHorizontalScrollBar = ScrollBar::create(); ExampleHorizontalScrollBar->setOrientation(ScrollBar::HORIZONTAL_ORIENTATION); ExampleHorizontalScrollBar->setPreferredSize(Vec2f(400,20)); ExampleHorizontalScrollBar->setRangeModel(TheBoundedRangeModel); // Creates another DefaultBoundedRangeModel to use // for separating the two ScrollBars from each other. // Make sure to comment out the addition of the // previous setModel above. /* DefaultBoundedRangeModel TheBoundedRangeModel2; TheBoundedRangeModel2.setMinimum(0); TheBoundedRangeModel2.setMaximum(100); TheBoundedRangeModel2.setValue(10); TheBoundedRangeModel2.setExtent(20); ExampleHorizontalScrollBar->setModel(&TheBoundedRangeModel2); */ // 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 = FlowLayout::create(); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleHorizontalScrollBar); MainInternalWindow->pushToChildren(ExampleVerticalScrollBar); MainInternalWindow->pushToChildren(ExampleScrollPanel); 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); // 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, "27ScrollPanel"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 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(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 an Button Component and a simple Font. See 17Label_Font for more information about Fonts. ******************************************************/ LineBorderRecPtr ChangableBorder = LineBorder::create(); ChangableBorder->setColor(Color4f(0.0,0.0,0.0,1.0)); ColorLayerRecPtr ChangableBackground = ColorLayer::create(); ChangableBackground->setColor(Color4f(1.0,1.0,1.0,1.0)); LabelRecPtr ChangableLabel = Label::create(); ChangableLabel->setText("Changable"); ChangableLabel->setBorders(ChangableBorder); ChangableLabel->setBackgrounds(ChangableBackground); //Command Buttons UndoManagerPtr TheUndoManager = UndoManager::create(); CommandManagerPtr TheCommandManager = CommandManager::create(TheUndoManager); ButtonRecPtr BorderRedButton = Button::create(); BorderRedButton->setText("Border Red"); BorderRedButton->setPreferredSize(Vec2f(85, 20)); BorderRedButton->connectActionPerformed(boost::bind(handleSetBorderColorAction, _1, TheCommandManager, ChangableBorder.get(), Color4f(1.0,0.0,0.0,1.0))); ButtonRecPtr BorderGreenButton = Button::create(); BorderGreenButton->setText("Border Green"); BorderGreenButton->setPreferredSize(Vec2f(85, 20)); BorderGreenButton->connectActionPerformed(boost::bind(handleSetBorderColorAction, _1, TheCommandManager, ChangableBorder.get(), Color4f(0.0,1.0,0.0,1.0))); ButtonRecPtr BorderBlueButton = Button::create(); BorderBlueButton->setText("Border Blue"); BorderBlueButton->setPreferredSize(Vec2f(85, 20)); BorderBlueButton->connectActionPerformed(boost::bind(handleSetBorderColorAction, _1, TheCommandManager, ChangableBorder.get(), Color4f(0.0,0.0,1.0,1.0))); //Background ButtonRecPtr BackgroundRedButton = Button::create(); BackgroundRedButton->setText("Background Red"); BackgroundRedButton->setPreferredSize(Vec2f(105, 20)); BackgroundRedButton->connectActionPerformed(boost::bind(handleSetBackgroundColorAction, _1, TheCommandManager, ChangableBackground.get(), Color4f(1.0,0.0,0.0,1.0))); ButtonRecPtr BackgroundGreenButton = Button::create(); BackgroundGreenButton->setText("Background Green"); BackgroundGreenButton->setPreferredSize(Vec2f(105, 20)); BackgroundGreenButton->connectActionPerformed(boost::bind(handleSetBackgroundColorAction, _1, TheCommandManager, ChangableBackground.get(), Color4f(0.0,1.0,0.0,1.0))); ButtonRecPtr BackgroundBlueButton = Button::create(); BackgroundBlueButton->setText("Background Blue"); BackgroundBlueButton->setPreferredSize(Vec2f(105, 20)); BackgroundBlueButton->connectActionPerformed(boost::bind(handleSetBackgroundColorAction, _1, TheCommandManager, ChangableBackground.get(), Color4f(0.0,0.0,1.0,1.0))); //UndoList DefaultListModelRecPtr UndoRedoListModel = DefaultListModel::create(); UndoRedoListModel->pushBack(boost::any(std::string("Top"))); ListRecPtr UndoRedoList = List::create(); UndoRedoList->setPreferredSize(Vec2f(200, 300)); UndoRedoList->setOrientation(List::VERTICAL_ORIENTATION); UndoRedoList->setModel(UndoRedoListModel); UndoRedoList->getSelectionModel()->connectSelectionChanged(boost::bind(handleUndoRedoListSelectionChanged, _1, UndoRedoList.get(), TheUndoManager)); ButtonRecPtr UndoButton = Button::create(); UndoButton->setText("Undo"); UndoButton->setEnabled(TheUndoManager->numberOfUndos() != 0); UndoButton->connectActionPerformed(boost::bind(handleUndoButtonAction, _1, TheUndoManager)); ButtonRecPtr RedoButton = Button::create(); RedoButton->setText("Redo"); RedoButton->setEnabled(TheUndoManager->numberOfRedos() != 0); RedoButton->connectActionPerformed(boost::bind(handleRedoButtonAction, _1, TheUndoManager)); // Create a ScrollPanel for easier viewing of the List (see 27ScrollPanel) ScrollPanelRecPtr UndoRedoScrollPanel = ScrollPanel::create(); UndoRedoScrollPanel->setPreferredSize(Vec2f(200,200)); UndoRedoScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); UndoRedoScrollPanel->setViewComponent(UndoRedoList); // 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(); LayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); MainInternalWindow->pushToChildren(BorderRedButton); MainInternalWindow->pushToChildren(BorderGreenButton); MainInternalWindow->pushToChildren(BorderBlueButton); MainInternalWindow->pushToChildren(BackgroundRedButton); MainInternalWindow->pushToChildren(BackgroundGreenButton); MainInternalWindow->pushToChildren(BackgroundBlueButton); MainInternalWindow->pushToChildren(ChangableLabel); MainInternalWindow->pushToChildren(UndoRedoScrollPanel); MainInternalWindow->pushToChildren(UndoButton); MainInternalWindow->pushToChildren(RedoButton); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.95f,0.95f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); TheUndoManager->connectStateChanged(boost::bind(handleUndoManagerStateChanged, _1, UndoRedoListModel.get(), TheUndoManager, UndoButton.get(), RedoButton.get())); // 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, "40UndoableCommand"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 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(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 a simple Font to be used with the ExampleTextArea UIFontRecPtr ExampleFont = 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 TextAreaRecPtr ExampleTextArea = 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 ScrollPanelRecPtr 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 ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); LayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); InternalWindowRecPtr MainInternalWindow = 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 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); // 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, "22TextArea"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 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(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; }
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); NodeRecPtr TorusNode = Node::create(); TorusNode->setCore(Transform::create()); TorusNode->addChild(TorusGeometryNode); NodeRecPtr SphereGeometryNode = makeSphere(2,1.0f); NodeRecPtr BoxGeometryNode = makeBox(1.0,1.0,1.0,1,1,1); // Make Main Scene Node and add the Torus Root = Node::create(); Root->setCore(Group::create()); Root->addChild(TorusNode); Root->addChild(SphereGeometryNode); Root->addChild(BoxGeometryNode); } // Create the Graphics GraphicsRecPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); // 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 = FlowLayout::create(); //Import InternalWindow(s) from XML file std::vector<InternalWindowRecPtr> StoreWindows; FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(BoostPath("./Data/55ComponentTree.xml")); //Store each window found in the XML in the vector FCFileType::FCPtrStore::iterator Itor; for(Itor = NewContainers.begin(); Itor != NewContainers.end(); ++Itor) { if( (*Itor)->getType() == (InternalWindow::getClassType())) { StoreWindows.push_back(dynamic_pointer_cast<InternalWindow>(*Itor)); } } //Tree Model FieldContainerTreeModelRecPtr TheTreeModel = FieldContainerTreeModel::create(); TheTreeModel->setRoot(StoreWindows.front()); //TheTreeModel->setShowPtrFields(false); //TheTreeModel->setShowDataFields(false); //TheTreeModel->setShowParentPtrFields(false); //TheTreeModel->setShowChildPtrFields(false); TheTreeModel->setShowAttachments(false); //TheTreeModel->setShowCallbackFunctors(false); //Tree Component Generator FieldContainerFieldPathComponentGeneratorRecPtr TheTreeComponentGenerator = FieldContainerFieldPathComponentGenerator::create(); //Create the Tree TreeRecPtr TheTree = Tree::create(); TheTree->setPreferredSize(Vec2f(100, 500)); TheTree->setRootVisible(true); TheTree->setModel(TheTreeModel); TheTree->setCellGenerator(TheTreeComponentGenerator); setName(TheTree, std::string("TheTree")); // Create a ScrollPanel for easier viewing of the List (see 27ScrollPanel) ScrollPanelRecPtr ExampleScrollPanel = ScrollPanel::create(); ExampleScrollPanel->setPreferredSize(Vec2f(350,500)); //ExampleScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); //ExampleScrollPanel->setVerticalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); ExampleScrollPanel->setViewComponent(TheTree); setName(ExampleScrollPanel, std::string("ExampleScrollPanel")); //Show Buttons CheckboxButtonRecPtr ShowMultiFieldsButton = CheckboxButton::create(); CheckboxButtonRecPtr ShowSingleFieldsButton = CheckboxButton::create(); CheckboxButtonRecPtr ShowPtrFieldsButton = CheckboxButton::create(); CheckboxButtonRecPtr ShowDataFieldsButton = CheckboxButton::create(); CheckboxButtonRecPtr ShowParentPtrFieldsButton = CheckboxButton::create(); CheckboxButtonRecPtr ShowChildPtrFieldsButton = CheckboxButton::create(); CheckboxButtonRecPtr ShowAttachmentsButton = CheckboxButton::create(); CheckboxButtonRecPtr ShowCallbackFunctorsButton = CheckboxButton::create(); CheckboxButtonRecPtr ShowInternalFieldsButton = CheckboxButton::create(); ShowMultiFieldsButton->setText("Multi Fields"); ShowMultiFieldsButton->setPreferredSize(Vec2f(120.0f,ShowMultiFieldsButton->getPreferredSize().y())); ShowMultiFieldsButton->setAlignment(Vec2f(0.0f,0.5f)); ShowSingleFieldsButton->setText("Single Fields"); ShowSingleFieldsButton->setPreferredSize(Vec2f(120.0f,ShowSingleFieldsButton->getPreferredSize().y())); ShowSingleFieldsButton->setAlignment(Vec2f(0.0f,0.5f)); ShowPtrFieldsButton->setText("Ptr Fields"); ShowPtrFieldsButton->setPreferredSize(Vec2f(120.0f,ShowPtrFieldsButton->getPreferredSize().y())); ShowPtrFieldsButton->setAlignment(Vec2f(0.0f,0.5f)); ShowDataFieldsButton->setText("Data Fields"); ShowDataFieldsButton->setPreferredSize(Vec2f(120.0f,ShowDataFieldsButton->getPreferredSize().y())); ShowDataFieldsButton->setAlignment(Vec2f(0.0f,0.5f)); ShowParentPtrFieldsButton->setText("ParentPtr Fields"); ShowParentPtrFieldsButton->setPreferredSize(Vec2f(120.0f,ShowParentPtrFieldsButton->getPreferredSize().y())); ShowParentPtrFieldsButton->setAlignment(Vec2f(0.0f,0.5f)); ShowChildPtrFieldsButton->setText("ChildPtr Fields"); ShowChildPtrFieldsButton->setPreferredSize(Vec2f(120.0f,ShowChildPtrFieldsButton->getPreferredSize().y())); ShowChildPtrFieldsButton->setAlignment(Vec2f(0.0f,0.5f)); ShowAttachmentsButton->setText("Attachments"); ShowAttachmentsButton->setPreferredSize(Vec2f(120.0f,ShowAttachmentsButton->getPreferredSize().y())); ShowAttachmentsButton->setAlignment(Vec2f(0.0f,0.5f)); ShowCallbackFunctorsButton->setText("Callback Functors"); ShowCallbackFunctorsButton->setPreferredSize(Vec2f(120.0f,ShowCallbackFunctorsButton->getPreferredSize().y())); ShowCallbackFunctorsButton->setAlignment(Vec2f(0.0f,0.5f)); ShowInternalFieldsButton->setText("Internal Fields"); ShowInternalFieldsButton->setPreferredSize(Vec2f(120.0f,ShowInternalFieldsButton->getPreferredSize().y())); ShowInternalFieldsButton->setAlignment(Vec2f(0.0f,0.5f)); ShowCheckboxesController CheckboxesController(TheTreeModel, ShowMultiFieldsButton, ShowSingleFieldsButton, ShowPtrFieldsButton, ShowDataFieldsButton, ShowParentPtrFieldsButton, ShowChildPtrFieldsButton, ShowAttachmentsButton, ShowCallbackFunctorsButton, ShowInternalFieldsButton); PanelRecPtr OptionsPanel = Panel::create(); FlowLayoutRecPtr OptionsPanelLayout = FlowLayout::create(); OptionsPanel->setLayout(OptionsPanelLayout); OptionsPanel->setPreferredSize(Vec2f(250.0f, 300.0f)); OptionsPanel->pushToChildren(ShowMultiFieldsButton); OptionsPanel->pushToChildren(ShowSingleFieldsButton); OptionsPanel->pushToChildren(ShowPtrFieldsButton); OptionsPanel->pushToChildren(ShowDataFieldsButton); OptionsPanel->pushToChildren(ShowInternalFieldsButton); OptionsPanel->pushToChildren(ShowParentPtrFieldsButton); OptionsPanel->pushToChildren(ShowChildPtrFieldsButton); OptionsPanel->pushToChildren(ShowAttachmentsButton); OptionsPanel->pushToChildren(ShowCallbackFunctorsButton); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleScrollPanel); MainInternalWindow->pushToChildren(OptionsPanel); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.85f,0.85f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); setName(MainInternalWindow, std::string("MainInternalWindow")); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); TutorialDrawingSurface->openWindow(StoreWindows.back()); // 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); // 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, "56FieldContainerTree"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }