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; }
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 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); //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, "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)); // 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(); /****************************************************** Creates some Button components and edit their Text. ******************************************************/ 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->setText("This"); ExampleButton2->setText("is a"); ExampleButton3->setText("sample"); ExampleButton4->setText("two"); ExampleButton5->setText("Panel"); ExampleButton6->setText("layout"); /****************************************************** Create some Flow and BoxLayouts to be used with the Main Frame and two Panels. ******************************************************/ FlowLayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); FlowLayoutRecPtr ExamplePanel1Layout = FlowLayout::create(); FlowLayoutRecPtr ExamplePanel2Layout = FlowLayout::create(); ExamplePanel1Layout->setOrientation(FlowLayout::VERTICAL_ORIENTATION); /****************************************************** Create two Backgrounds to be used with Panels and MainInternalWindow. ******************************************************/ ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); ColorLayerRecPtr ExamplePanelBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); ExamplePanelBackground->setColor(Color4f(0.0,0.0,0.0,1.0)); /****************************************************** Create a Border to be used with the two Panels. ******************************************************/ LineBorderRecPtr ExamplePanelBorder = LineBorder::create(); ExamplePanelBorder->setColor(Color4f(0.9, 0.9, 0.9, 1.0)); ExamplePanelBorder->setWidth(3); /****************************************************** Create MainInternalWindow and two Panel Components and edit their characteristics. -setPreferredSize(Vec2f): Determine the size of the Panel. -pushToChildren(ComponentName): Adds a Component to the ComponentContainer as a Child (meaning it will be displayed within it). -setLayout(LayoutName): Determines the Layout of the ComponentContainer. ******************************************************/ InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); PanelRecPtr ExamplePanel1 = Panel::create(); PanelRecPtr ExamplePanel2 = Panel::create(); // Edit Panel1, Panel2 ExamplePanel1->setPreferredSize(Vec2f(200, 200)); ExamplePanel1->pushToChildren(ExampleButton1); ExamplePanel1->pushToChildren(ExampleButton2); ExamplePanel1->pushToChildren(ExampleButton3); ExamplePanel1->setLayout(ExamplePanel1Layout); ExamplePanel1->setBackgrounds(ExamplePanelBackground); ExamplePanel1->setBorders(ExamplePanelBorder); ExamplePanel2->setPreferredSize(Vec2f(200, 200)); ExamplePanel2->pushToChildren(ExampleButton4); ExamplePanel2->pushToChildren(ExampleButton5); ExamplePanel2->pushToChildren(ExampleButton6); ExamplePanel2->setLayout(ExamplePanel2Layout); ExamplePanel2->setBackgrounds(ExamplePanelBackground); ExamplePanel2->setBorders(ExamplePanelBorder); // Create The Main InternalWindow MainInternalWindow->pushToChildren(ExamplePanel1); MainInternalWindow->pushToChildren(ExamplePanel2); 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); MainInternalWindow->setAllInsets(5); // 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, "10Container"); //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 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 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 ******************************************************/ MenuItemRecPtr MenuItem1 = MenuItem::create(); MenuItemRecPtr MenuItem2 = MenuItem::create(); MenuItemRecPtr MenuItem3 = MenuItem::create(); MenuItemRecPtr MenuItem4 = MenuItem::create(); MenuItemRecPtr SubMenuItem1 = MenuItem::create(); MenuItemRecPtr SubMenuItem2 = MenuItem::create(); MenuItemRecPtr SubMenuItem3 = MenuItem::create(); MenuRecPtr 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. ******************************************************/ PopupMenuRecPtr ExamplePopupMenu = PopupMenu::create(); ExamplePopupMenu->setMinSize(Vec2f(100.0f, 20.0f)); ExamplePopupMenu->setMaxSize(Vec2f(100.0f, 80.0f)); ExamplePopupMenu->addItem(MenuItem1); ExamplePopupMenu->addItem(MenuItem2); ExamplePopupMenu->addItem(MenuItem3); ExamplePopupMenu->addSeparator(); ExamplePopupMenu->addItem(ExampleSubMenu); ExamplePopupMenu->addItem(MenuItem4); // Create a Button and Font UIFontRecPtr PopupMenuButtonFont = UIFont::create(); PopupMenuButtonFont->setSize(16); ButtonRecPtr PopupMenuButton = 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 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(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 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, "01RubberBandCamera"); //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(keyTyped, _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(); ColorChooserRecPtr TheColorChooser = ColorChooser::create(); TheColorChooser->setColor(Color4f(1.0f,0.0f,0.0f,1.0f)); // Create Background to be used with the MainInternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); // Create The Internal Window InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); LayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); // Assign the Button to the MainInternalWindow so it will be displayed // when the view is rendered. MainInternalWindow->pushToChildren(TheColorChooser); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setPosition(Pnt2f(50,50)); MainInternalWindow->setPreferredSize(Vec2f(400,400)); MainInternalWindow->setTitle(std::string("Internal Window")); // 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); 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, "39ColorChooser"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
InternalWindowTransitPtr createMainInternalWindow(void) { /****************************************************** Create Button Components to be used with TabPanel and specify their characteristics. Note: Buttons are used for simplicity, any Component can be used as Tab content or as a Tab. A Panel with several Buttons within it is also added. ******************************************************/ ButtonRecPtr ExampleTabButton1 = Button::create(); ButtonRecPtr ExampleTabButton2 = Button::create(); ButtonRecPtr ExampleTabButton3 = Button::create(); ButtonRecPtr ExampleTabButton4 = Button::create(); ButtonRecPtr ExampleTabButton5 = Button::create(); ButtonRecPtr ExampleTabButton6 = Button::create(); ButtonRecPtr ExampleTabContentA = Button::create(); ButtonRecPtr ExampleTabContentB = Button::create(); ButtonRecPtr ExampleTabContentC = Button::create(); ButtonRecPtr ExampleTabContentD = Button::create(); ButtonRecPtr ExampleTabContentE = Button::create(); ButtonRecPtr ExampleTabContentF = Button::create(); ExampleTabButton1->setText("Tab1"); ExampleTabButton2->setText("Tab2"); ExampleTabButton3->setText("To Rotate"); ExampleTabButton4->setText("Tab4"); ExampleTabButton5->setText("To Zoom"); ExampleTabButton6->setText("To Move"); ExampleTabContentA->setText("Add another Tab"); ExampleTabContentB->setText("Add a Tab in Tab1!"); ExampleTabContentC->setText("Enable CapsLock, then rotate scene using left Mouse button!"); ExampleTabContentD->setText("Enable CapsLock, then zoom in and out with right Mouse button and dragging"); ExampleTabContentE->setText("Enable CapsLock, then move using center Mouse button"); /****************************************************** Create a Panel to add to the TabPanel ******************************************************/ // Create and edit the Panel Buttons ButtonRecPtr ExampleTabPanelButton1 = Button::create(); ButtonRecPtr ExampleTabPanelButton2 = Button::create(); ButtonRecPtr ExampleTabPanelButton3 = Button::create(); ButtonRecPtr ExampleTabPanelButton4 = Button::create(); ButtonRecPtr ExampleTabPanelButton5 = Button::create(); ButtonRecPtr ExampleTabPanelButton6 = Button::create(); ExampleTabPanelButton1->setText("This is a"); ExampleTabPanelButton2->setText("sample"); ExampleTabPanelButton3->setText("UIRectangle"); ExampleTabPanelButton4->setText("containing"); ExampleTabPanelButton5->setText("interactive"); ExampleTabPanelButton6->setText("components"); // Create and edit Panel Layout BoxLayoutRecPtr TabPanelLayout = BoxLayout::create(); TabPanelLayout->setOrientation(BoxLayout::VERTICAL_ORIENTATION); // Create and edit Panel PanelRecPtr ExampleTabPanelPanel = Panel::create(); ExampleTabPanelPanel->setPreferredSize(Vec2f(180, 500)); ExampleTabPanelPanel->pushToChildren(ExampleTabPanelButton1); ExampleTabPanelPanel->pushToChildren(ExampleTabPanelButton2); ExampleTabPanelPanel->pushToChildren(ExampleTabPanelButton3); ExampleTabPanelPanel->pushToChildren(ExampleTabPanelButton4); ExampleTabPanelPanel->pushToChildren(ExampleTabPanelButton5); ExampleTabPanelPanel->pushToChildren(ExampleTabPanelButton6); ExampleTabPanelPanel->setLayout(TabPanelLayout); TabPanelRecPtr ExampleTabPanel = TabPanel::create(); ExampleTabPanel->setPreferredSize(Vec2f(350,350)); ExampleTabPanel->addTab(ExampleTabButton1, ExampleTabContentA); ExampleTabPanel->addTab(ExampleTabButton2, ExampleTabContentB); ExampleTabPanel->addTab(ExampleTabButton3, ExampleTabContentC); ExampleTabPanel->addTab(ExampleTabButton4, ExampleTabPanelPanel); ExampleTabPanel->addTab(ExampleTabButton5, ExampleTabContentD); ExampleTabPanel->addTab(ExampleTabButton6, ExampleTabContentE); ExampleTabPanel->setTabAlignment(0.5f); ExampleTabPanel->setTabPlacement(TabPanel::PLACEMENT_SOUTH); ExampleTabPanel->setSelectedIndex(3); // 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)); CardLayoutRecPtr MainInternalWindowLayout = CardLayout::create(); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleTabPanel); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(1.0f,1.0f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); ExampleTabContentB->connectActionPerformed(boost::bind(handleRemoveTabAction, _1, ExampleTabPanel.get(), ExampleTabContentA.get(), ExampleTabContentB.get())); ExampleTabContentA->connectActionPerformed(boost::bind(handleAddTabAction, _1, ExampleTabPanel.get(), ExampleTabContentA.get(), ExampleTabContentB.get())); return InternalWindowTransitPtr(MainInternalWindow); }