int main(int argc, char **argv) { // OSG init osgInit(argc,argv); 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(); GradientBackgroundRefPtr TheBackground = GradientBackground::create(); TheBackground->addLine(Color3f(1.0,0.0,0.0), 0.0); TheBackground->addLine(Color3f(0.0,1.0,0.0), 0.2); TheBackground->addLine(Color3f(0.0,0.0,1.0), 0.4); TheBackground->addLine(Color3f(0.0,1.0,1.0), 0.6); TheBackground->addLine(Color3f(1.0,1.0,0.0), 0.8); TheBackground->addLine(Color3f(1.0,1.0,1.0), 1.0); /****************************************************** Create a List. A List has several parts to it: -ListModel: Contains the data which is to be displayed in the List. Data is added as shown below -ListCellRenderer: Creates the Components to be used within the List (the default setting is to create Labels using the desired text). -ListSelectionModel: Determines how the List may be selected. To add values to the list: First, create SFStrings and use the .setValue("Value") function to set their values. Then, use the .pushBack(&SFStringName) to add them to the List. Next, create the CellRenderer and ListSelectionModel defaults. Finally, actually create the List. Set its Model, CellRenderer, and SelectionModel as shown below. Finally, choose the type of display for the List (choices outlined below). ******************************************************/ // Add data to it ExampleListModel = MFieldListModel::create(); ExampleListModel->setContainer(TheBackground); ExampleListModel->setFieldId(GradientBackground::ColorFieldId); /****************************************************** Create ListCellRenderer and ListSelectionModel. Most often the defauls will be used. Note: the ListSelectionModel was created above and is referenced by the ActionListeners. ******************************************************/ /****************************************************** Create List itself and assign its Model, CellRenderer, and SelectionModel to it. -setOrientation(ENUM): Determine the Layout of the cells (Horizontal or Vertical). Takes List::VERTICAL_ORIENTATION and List::HORIZONTAL_ORIENTATION arguments. ******************************************************/ ExampleList = List::create(); ExampleList->setPreferredSize(Vec2f(200, 300)); ExampleList->setOrientation(List::VERTICAL_ORIENTATION); //ExampleList->setOrientation(List::HORIZONTAL_ORIENTATION); ExampleList->setModel(ExampleListModel); ExampleList->setSelectionModel(ExampleListSelectionModel); /****************************************************** Determine the SelectionModel -SINGLE_SELECTION lets you select ONE item via a single mouse click -SINGLE_INTERVAL_SELECTION lets you select one interval via mouse and SHIFT key -MULTIPLE_INTERVAL_SELECTION lets you select via mouse, and SHIFT and CONTRL keys Note: this tutorial is currently set up to allow for this to be changed via TogggleButtons with ActionListeners attached to them so this code is commented out. ******************************************************/ //SelectionModel.setMode(DefaultListSelectionModel::SINGLE_SELECTION); //SelectionModel.setMode(DefaultListSelectionModel::SINGLE_INTERVAL_SELECTION); //SelectionModel.setMode(DefaultListSelectionModel::MULTIPLE_INTERVAL_SELECTION); // Create a ScrollPanel for easier viewing of the List (see 27ScrollPanel) ScrollPanelRefPtr ExampleScrollPanel = ScrollPanel::create(); ExampleScrollPanel->setPreferredSize(Vec2f(200,300)); ExampleScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); //ExampleScrollPanel->setVerticalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); ExampleScrollPanel->setViewComponent(ExampleList); // Create MainFramelayout FlowLayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create(); MainInternalWindowLayout->setOrientation(FlowLayout::VERTICAL_ORIENTATION); MainInternalWindowLayout->setMajorAxisAlignment(0.5f); MainInternalWindowLayout->setMinorAxisAlignment(0.5f); LabelRefPtr ListLabel = Label::create(); ListLabel->setText("Background Colors List"); ListLabel->setPreferredSize(Vec2f(200.0f, ListLabel->getPreferredSize().y())); // 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(ListLabel); MainInternalWindow->pushToChildren(ExampleScrollPanel); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.7f,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); TutorialViewport->setBackground(TheBackground); // 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, "44MFieldList"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
PanelUnrecPtr createMultiFieldPanel(void) { //Popup Menu MenuItemRefPtr RemoveIndexMenuItem = MenuItem::create(); RemoveIndexMenuItem->setText("Remove Index"); RemoveIndexMenuItem->addActionListener(new RemoveMultiFieldActionListener()); MenuItemRefPtr SetValueMenuItem = MenuItem::create(); SetValueMenuItem->setText("Set Value"); SetValueMenuItem->addActionListener(new SetMultiFieldActionListener()); MenuItemRefPtr AddValueMenuItem = MenuItem::create(); AddValueMenuItem->setText("Add Value"); AddValueMenuItem->addActionListener(new AddMultiFieldActionListener()); MenuItemRefPtr InsertIndexMenuItem = MenuItem::create(); InsertIndexMenuItem->setText("Insert Value"); InsertIndexMenuItem->addActionListener(new InsertMultiFieldActionListener()); MenuItemRefPtr MoveIndexMenuItem = MenuItem::create(); MoveIndexMenuItem->setText("Move Value"); MoveIndexMenuItem->addActionListener(new MoveMultiFieldActionListener()); MenuItemRefPtr SwapIndexMenuItem = MenuItem::create(); SwapIndexMenuItem->setText("Swap Value"); SwapIndexMenuItem->addActionListener(new SwapMultiFieldActionListener()); PopupMenuRefPtr MultiFieldListPopupMenu = PopupMenu::create(); MultiFieldListPopupMenu->addItem(SetValueMenuItem); MultiFieldListPopupMenu->addItem(AddValueMenuItem); MultiFieldListPopupMenu->addItem(InsertIndexMenuItem); MultiFieldListPopupMenu->addItem(MoveIndexMenuItem); MultiFieldListPopupMenu->addItem(SwapIndexMenuItem); MultiFieldListPopupMenu->addItem(RemoveIndexMenuItem); //Multi-field List Model MultiFieldListModel = MFieldListModel::create(); MultiFieldListModel->setContainer(TutorialBackground); MultiFieldListModel->setFieldId(GradientBackground::ColorFieldId); //MultiFieldListModel->setFieldId(GradientBackground::PositionFieldId); //List MultiFieldList = List::create(); MultiFieldList->setPreferredSize(Vec2f(200, 300)); MultiFieldList->setOrientation(List::VERTICAL_ORIENTATION); MultiFieldList->setModel(MultiFieldListModel); ListSelectionModelPtr MultiFieldListSelectionModel(new DefaultListSelectionModel()); MultiFieldList->setSelectionModel(MultiFieldListSelectionModel); MultiFieldList->setPopupMenu(MultiFieldListPopupMenu); // Create a ScrollPanel for easier viewing of the List ScrollPanelRefPtr ExampleScrollPanel = ScrollPanel::create(); ExampleScrollPanel->setPreferredSize(Vec2f(200,300)); ExampleScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); ExampleScrollPanel->setViewComponent(MultiFieldList); // Create MainFramelayout FlowLayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create(); MainInternalWindowLayout->setOrientation(FlowLayout::VERTICAL_ORIENTATION); MainInternalWindowLayout->setMajorAxisAlignment(0.5f); MainInternalWindowLayout->setMinorAxisAlignment(0.5f); //Label LabelRefPtr ListLabel = Label::create(); ListLabel->setText("Background Colors List"); ListLabel->setPreferredSize(Vec2f(200.0f, ListLabel->getPreferredSize().y())); //Panel FlowLayoutRefPtr ThePanelLayout = OSG::FlowLayout::create(); ThePanelLayout->setOrientation(FlowLayout::VERTICAL_ORIENTATION); ThePanelLayout->setMajorAxisAlignment(0.5f); ThePanelLayout->setMinorAxisAlignment(0.5f); PanelRefPtr ThePanel = Panel::createEmpty(); ThePanel->setLayout(ThePanelLayout); ThePanel->pushToChildren(ListLabel); ThePanel->pushToChildren(ExampleScrollPanel); return ThePanel; }
void LuaDebuggerInterface::createEditorToolbar(void) { BoostPath OpenIconPath(_BaseIconDir / BoostPath("open.png")); ButtonRefPtr OpenButton = Button::create(); OpenButton->setToolTipText("Open"); OpenButton->setPreferredSize(_ToolButtonSize); OpenButton->setImages(OpenIconPath.string()); setName(OpenButton,"Open Button"); OpenButton->connectActionPerformed(boost::bind(&LuaDebuggerInterface::openScriptButtonAction,this)); BoostPath SaveIconPath(_BaseIconDir / BoostPath("Save.png")); ButtonRefPtr SaveButton = Button::create(); SaveButton->setPreferredSize(_ToolButtonSize); SaveButton->setToolTipText("Save"); setName(SaveButton,"Save Button"); SaveButton->setImages(SaveIconPath.string()); SaveButton->connectActionPerformed(boost::bind(&LuaDebuggerInterface::saveScriptButtonAction,this)); BoostPath ClearIconPath(_BaseIconDir / BoostPath("clear.png")); ButtonRefPtr ClearButton = Button::create(); ClearButton->setPreferredSize(_ToolButtonSize); ClearButton->setToolTipText("Clear"); setName(ClearButton,"Clear Button"); ClearButton->setImages(ClearIconPath.string()); ClearButton->connectActionPerformed(boost::bind(&LuaDebuggerInterface::clearScriptButtonAction,this)); BoostPath SplitHorzIconPath(_BaseIconDir / BoostPath("view-split-left-right.png")); BoostPath SplitVertIconPath(_BaseIconDir / BoostPath("view-split-top-bottom.png")); BoostPath SplitNoneIconPath(_BaseIconDir / BoostPath("view-split-none.png")); //Split Options Component Generator FunctorListComponentGeneratorRecPtr SplitOptionsCompGenerator = FunctorListComponentGenerator::create(); SplitOptionsCompGenerator->setGenerateFunction(boost::bind(&LuaDebuggerInterface::generateSplitOptionListComponent, this, _1, _2, _3, _4, _5)); //Split Options List Model DefaultListModelRecPtr SplitOptionsListModel = DefaultListModel::create(); SplitOptionsListModel->pushBack(boost::any(std::string("None"))); SplitOptionsListModel->pushBack(boost::any(std::string("Horizontal"))); SplitOptionsListModel->pushBack(boost::any(std::string("Vertical"))); _SplitButton = MenuButton::create(); _SplitButton->setToolTipText("Split Options"); _SplitButton->setPreferredSize(_ToolButtonSize); _SplitButton->setImages(SplitNoneIconPath.string()); _SplitButton->setModel(SplitOptionsListModel); _SplitButton->setCellGenerator(SplitOptionsCompGenerator); setName(_SplitButton,"Split Button"); _SplitButton->connectMenuActionPerformed(boost::bind(&LuaDebuggerInterface::handleSplitMenuAction, this, _1)); //Make the Button Panel FlowLayoutRefPtr ButtonPanelLayout = FlowLayout::create(); ButtonPanelLayout->setOrientation(FlowLayout::HORIZONTAL_ORIENTATION); ButtonPanelLayout->setHorizontalGap(3.0f); ButtonPanelLayout->setMajorAxisAlignment(0.0f); ButtonPanelLayout->setMinorAxisAlignment(0.5); _EditorButtonPanel = Panel::createEmpty(); _EditorButtonPanel->setPreferredSize(Vec2f(200.0f, 45.0f)); _EditorButtonPanel->pushToChildren(OpenButton); _EditorButtonPanel->pushToChildren(SaveButton); _EditorButtonPanel->pushToChildren(ClearButton); _EditorButtonPanel->pushToChildren(_SplitButton); _EditorButtonPanel->setLayout(ButtonPanelLayout); setName(_EditorButtonPanel,"Button Panel"); }
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 and edit a few Button Components. ******************************************************/ 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(200, 50)); ExampleButton4->setPreferredSize(Vec2f(50, 50)); /****************************************************** Create Flow Layout. Flow Layout arranges objects automatically within the Frame, so that depending on Frame size, the objects may appear in a vertical line, horizontal line, or multiple lines. Objects fill from the upper left hand corner of the Frame across, then down (when the line becomes full) while arranged Horizontally, or from the upper left hand corner across when arranged Vertically, starting a new column when necessary. You can experiment with this by changing the window size, changing the orientation, changing the PreferredSize of the Buttons, or adding more Buttons to the view. Note that if the Frame is too small or resized too much, the FlowLayout will become slightly distorted. For Layouts which will often be dynamically changed, FlowLayout is not the best choice. -setHorizontalGap(int): Determine the Horizontal gap in pixels between Components in FlowLayout. -setVerticalGap(int): Determine the Vertical gap in pixels between Components in FlowLayout. -setOrientation(ENUM): Determine whether the Layout is arranged Vertically or Horizontally. Takes HORIZONTAL_ORIENTATION or VERTICAL_ORIENTATION arguments. -setMajorAxisAlignment(ENUM): Determines the alignment of the entire Layout within its ComponentContainer. See below. -setMinorAxistAlignment(ENUM): Determines the alignment of Components within the Layout. See below. Both of the last two functions take the following arguments: AXIS_MAX_ALIGNMENT, AXIS_CENTER_ALIGNMENT, and AXIS_MIN_ALIGNMENT. MAX puts it to the bottom/right, CENTER centers it, and MIN puts it to the top/left (for Vertical/Horizontal as set above, respectively). ******************************************************/ FlowLayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create(); MainInternalWindowLayout->setHorizontalGap(3.0f); MainInternalWindowLayout->setVerticalGap(3.0f); MainInternalWindowLayout->setOrientation(FlowLayout::VERTICAL_ORIENTATION); MainInternalWindowLayout->setMajorAxisAlignment(0.5f); MainInternalWindowLayout->setMinorAxisAlignment(1.0f); // 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); // Add a 10 pixel "padding" inside the MainFrame MainInternalWindow->setAllInsets(10); //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, "05FlowLayout"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }