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); 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; }
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 some Backgrounds ******************************************************/ ColorLayerRefPtr MainFrameBackground = OSG::ColorLayer::create(); ColorLayerRefPtr ExamplePanelBackground = OSG::ColorLayer::create(); ColorLayerRefPtr ExampleSmallPanelBackground = OSG::ColorLayer::create(); ColorLayerRefPtr ExampleLabel1ColorBackground = OSG::ColorLayer::create(); GradientLayerRefPtr ExampleLabel1GradientBackground = OSG::GradientLayer::create(); CompoundLayerRefPtr ExampleLabel1CompoundBackground = OSG::CompoundLayer::create(); MainFrameBackground->setColor(Color4f(0,0,1.0,0.5)); ExamplePanelBackground->setColor(Color4f(0.0,0.0,0.0,0.5)); ExampleSmallPanelBackground->setColor(Color4f(0.0,0.5,0.7,1.0)); ExampleLabel1ColorBackground->setColor(Color4f(0.0, 0.0, 0.0, 1.0)); ExampleLabel1GradientBackground->editMFColors()->push_back(Color4f(1.0, 0.0, 1.0, 0.8)); ExampleLabel1GradientBackground->editMFStops()->push_back(0.0); ExampleLabel1GradientBackground->editMFColors()->push_back(Color4f(0.0, 0.0, 1.0, 0.3)); ExampleLabel1GradientBackground->editMFStops()->push_back(1.0); ExampleLabel1GradientBackground->setStartPosition(Vec2f(0.0f,0.0f)); ExampleLabel1GradientBackground->setEndPosition(Vec2f(1.0f,0.0f)); ExampleLabel1CompoundBackground->pushToBackgrounds(ExampleLabel1ColorBackground); ExampleLabel1CompoundBackground->pushToBackgrounds(ExampleLabel1GradientBackground); /****************************************************** Create some Borders ******************************************************/ EtchedBorderRefPtr ExamplePanelBorder = OSG::EtchedBorder::create(); EmptyBorderRefPtr ExampleLabel1Border = OSG::EmptyBorder::create(); ExamplePanelBorder->setHighlight(Color4f(1.0, 1.0, 1.0, 1.0)); ExamplePanelBorder->setShadow(Color4f(0.8, 0.8, 0.8, 1.0)); ExamplePanelBorder->setWidth(6); /****************************************************** Creates some Button components ******************************************************/ LabelRefPtr ExampleLabel1 = OSG::Label::create(); 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(); ButtonRefPtr ExampleButton7 = OSG::Button::create(); ButtonRefPtr ExampleButton8 = OSG::Button::create(); ButtonRefPtr ExampleButton9 = OSG::Button::create(); ButtonRefPtr ExampleButton10 = OSG::Button::create(); ButtonRefPtr ExampleButton11 = OSG::Button::create(); ExampleLabel1->setPreferredSize(Vec2f(800, 50)); ExampleLabel1->setBackground(ExampleLabel1CompoundBackground); ExampleLabel1->setBorder(ExampleLabel1Border); ExampleButton1->setPreferredSize(Vec2f(800, 50)); ExampleButton1->setMaxSize(Vec2f(50, 50)); ExampleButton1->setText("Resize the Window to Show Diificulties with Using Just One Layout"); ExampleButton2->setPreferredSize(Vec2f(50, 50)); ExampleButton2->setMaxSize(Vec2f(50, 50)); ExampleButton3->setPreferredSize(Vec2f(50, 50)); ExampleButton3->setMaxSize(Vec2f(50, 50)); ExampleButton4->setPreferredSize(Vec2f(100, 50)); ExampleButton4->setMaxSize(Vec2f(100, 50)); ExampleButton5->setPreferredSize(Vec2f(100, 50)); ExampleButton5->setMaxSize(Vec2f(100, 50)); ExampleButton6->setPreferredSize(Vec2f(100, 50)); ExampleButton6->setMaxSize(Vec2f(100, 50)); ExampleButton7->setPreferredSize(Vec2f(100, 50)); ExampleButton7->setMaxSize(Vec2f(100, 50)); ExampleButton8->setPreferredSize(Vec2f(100, 50)); ExampleButton8->setMaxSize(Vec2f(100, 50)); ExampleButton9->setPreferredSize(Vec2f(100, 50)); ExampleButton9->setMaxSize(Vec2f(100, 50)); ExampleButton10->setPreferredSize(Vec2f(100, 50)); ExampleButton10->setMaxSize(Vec2f(100, 50)); ExampleButton11->setPreferredSize(Vec2f(100, 50)); ExampleButton11->setMaxSize(Vec2f(100, 50)); /****************************************************** Create some Layouts ******************************************************/ FlowLayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create(); BoxLayoutRefPtr ExamplePanel1Layout = OSG::BoxLayout::create(); BoxLayoutRefPtr ExamplePanel2Layout = OSG::BoxLayout::create(); BoxLayoutRefPtr ExamplePanel3Layout = OSG::BoxLayout::create(); BoxLayoutRefPtr ExamplePanel4Layout = OSG::BoxLayout::create(); BoxLayoutRefPtr ExamplePanel5Layout = OSG::BoxLayout::create(); BoxLayoutRefPtr ExamplePanel6Layout = OSG::BoxLayout::create(); ExamplePanel1Layout->setOrientation(BoxLayout::VERTICAL_ORIENTATION); ExamplePanel2Layout->setOrientation(BoxLayout::VERTICAL_ORIENTATION); ExamplePanel3Layout->setOrientation(BoxLayout::VERTICAL_ORIENTATION); ExamplePanel4Layout->setOrientation(BoxLayout::VERTICAL_ORIENTATION); ExamplePanel5Layout->setOrientation(BoxLayout::VERTICAL_ORIENTATION); ExamplePanel6Layout->setOrientation(BoxLayout::VERTICAL_ORIENTATION); MainInternalWindowLayout->setOrientation(BoxLayout::HORIZONTAL_ORIENTATION); MainInternalWindowLayout->setMinorAxisAlignment(0.5f); /****************************************************** Create MainFrame and some Panels ******************************************************/ PanelRefPtr ExamplePanel1 = OSG::Panel::create(); PanelRefPtr ExamplePanel2 = OSG::Panel::create(); PanelRefPtr ExamplePanel3 = OSG::Panel::create(); PanelRefPtr ExamplePanel4 = OSG::Panel::create(); PanelRefPtr ExamplePanel5 = OSG::Panel::create(); PanelRefPtr ExamplePanel6 = OSG::Panel::create(); // Edit Panel1, Panel2 ExamplePanel1->setPreferredSize(Vec2f(400, 400)); ExamplePanel1->pushToChildren(ExampleButton2); ExamplePanel1->pushToChildren(ExamplePanel3); ExamplePanel1->pushToChildren(ExamplePanel4); ExamplePanel1->setLayout(ExamplePanel1Layout); ExamplePanel1->setBackgrounds(ExamplePanelBackground); ExamplePanel1->setBorders(ExamplePanelBorder); ExamplePanel2->setPreferredSize(Vec2f(400, 400)); ExamplePanel2->pushToChildren(ExampleButton3); ExamplePanel2->pushToChildren(ExamplePanel5); ExamplePanel2->pushToChildren(ExamplePanel6); ExamplePanel2->setLayout(ExamplePanel2Layout); ExamplePanel2->setBackgrounds(ExamplePanelBackground); ExamplePanel2->setBorders(ExamplePanelBorder); ExamplePanel3->pushToChildren(ExampleButton4); ExamplePanel3->pushToChildren(ExampleButton5); ExamplePanel3->setLayout(ExamplePanel3Layout); ExamplePanel3->setPreferredSize(Vec2f(125, 130)); ExamplePanel3->setBackgrounds(ExampleSmallPanelBackground); ExamplePanel4->pushToChildren(ExampleButton6); ExamplePanel4->pushToChildren(ExampleButton7); ExamplePanel4->setLayout(ExamplePanel4Layout); ExamplePanel4->setPreferredSize(Vec2f(125, 130)); ExamplePanel4->setBackgrounds(ExampleSmallPanelBackground); ExamplePanel5->pushToChildren(ExampleButton8); ExamplePanel5->pushToChildren(ExampleButton9); ExamplePanel5->setLayout(ExamplePanel5Layout); ExamplePanel5->setPreferredSize(Vec2f(125, 130)); ExamplePanel5->setBackgrounds(ExampleSmallPanelBackground); ExamplePanel6->pushToChildren(ExampleButton10); ExamplePanel6->pushToChildren(ExampleButton11); ExamplePanel6->setLayout(ExamplePanel6Layout); ExamplePanel6->setPreferredSize(Vec2f(125, 130)); ExamplePanel6->setBackgrounds(ExampleSmallPanelBackground); // 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->setBorder(ExamplePanelBorder); MainInternalWindow->pushToChildren(ExampleLabel1); MainInternalWindow->pushToChildren(ExampleButton1); MainInternalWindow->pushToChildren(ExamplePanel1); MainInternalWindow->pushToChildren(ExamplePanel2); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.8f,0.8f)); 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, "12ComplexLayout"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
ComponentRefPtr createLeftPanelRadioTextPanel(void) { // Create the RadioButton group RadioButtonRefPtr RadioButton1 = OSG::RadioButton::create(); RadioButtonRefPtr RadioButton2 = OSG::RadioButton::create(); RadioButtonRefPtr RadioButton3 = OSG::RadioButton::create(); RadioButtonRefPtr RadioButton4 = OSG::RadioButton::create(); RadioButton1->setAlignment(Vec2f(0.0,0.5)); RadioButton1->setPreferredSize(Vec2f(100, 40)); RadioButton1->setText("Black Text"); RadioButton1->setToolTipText("Set TextArea text black"); RadioButton1->addButtonSelectedListener(&RadioButton1Listener); RadioButton2->setAlignment(Vec2f(0.0,0.5)); RadioButton2->setPreferredSize(Vec2f(100, 40)); RadioButton2->setText("Red Text"); RadioButton2->setToolTipText("Set TextArea text red"); RadioButton2->addButtonSelectedListener(&RadioButton2Listener); RadioButton3->setAlignment(Vec2f(0.0,0.5)); RadioButton3->setPreferredSize(Vec2f(100, 40)); RadioButton3->setText("Green Text"); RadioButton3->setToolTipText("Set TextArea text green"); RadioButton3->addButtonSelectedListener(&RadioButton3Listener); RadioButton4->setAlignment(Vec2f(0.0,0.5)); RadioButton4->setPreferredSize(Vec2f(100, 40)); RadioButton4->setText("Blue Text"); RadioButton4->setToolTipText("Set TextArea text blue"); RadioButton4->addButtonSelectedListener(&RadioButton4Listener); buttonGroup = RadioButtonGroup::create(); buttonGroup->addButton(RadioButton1); buttonGroup->addButton(RadioButton2); buttonGroup->addButton(RadioButton3); buttonGroup->addButton(RadioButton4); // Create TextArea LeftPanelTextArea = OSG::TextArea::create(); LeftPanelTextArea->setPreferredSize(Vec2f(125, 200)); // Create Panel and its Background/Border to label TextField LabelRefPtr LeftPanelTextFieldLabel = OSG::Label::create(); EmptyLayerRefPtr LeftPanelTextFieldLabelBackground = OSG::EmptyLayer::create(); EmptyBorderRefPtr LeftPanelTextFieldLabelBorder = OSG::EmptyBorder::create(); LeftPanelTextFieldLabel->setPreferredSize(Vec2f(100, 25)); LeftPanelTextFieldLabel->setBorders(LeftPanelTextFieldLabelBorder); LeftPanelTextFieldLabel->setBackgrounds(LeftPanelTextFieldLabelBackground); LeftPanelTextFieldLabel->setText("Text Field"); // Create TextField TextFieldRefPtr LeftPanelTextField = OSG::TextField::create(); LeftPanelTextField->setPreferredSize(Vec2f(125.0f, 22.0f)); // Create an edit Panel Background ColorLayerRefPtr LeftPanelRadioTextPanelBackground = OSG::ColorLayer::create(); LeftPanelRadioTextPanelBackground->setColor(Color4f(0.93f,0.93f,0.93f,1.0f)); // Create and edit Panel layouts FlowLayoutRefPtr LeftPanelRadioTextPanelLayout = OSG::FlowLayout::create(); FlowLayoutRefPtr LeftPanelRadioTextPanelRadioPanelLayout = OSG::FlowLayout::create(); FlowLayoutRefPtr LeftPanelRadioTextPanelTextPanelLayout = OSG::FlowLayout::create(); LeftPanelRadioTextPanelLayout->setMinorAxisAlignment(0.0f); // Create two Panels for this Panel PanelRefPtr LeftPanelRadioTextPanelRadioPanel = OSG::Panel::create(); PanelRefPtr LeftPanelRadioTextPanelTextPanel = OSG::Panel::create(); // Create some Borders EmptyBorderRefPtr LeftPanelRadioTextPanelRadioPanelBorder = OSG::EmptyBorder::create(); LeftPanelRadioTextPanelRadioPanel->setBorders(LeftPanelRadioTextPanelRadioPanelBorder); LeftPanelRadioTextPanelRadioPanel->setPreferredSize(Vec2f(125, 200)); LeftPanelRadioTextPanelRadioPanel->setLayout(LeftPanelRadioTextPanelRadioPanelLayout); LeftPanelRadioTextPanelRadioPanel->setBackgrounds(LeftPanelRadioTextPanelBackground); LeftPanelRadioTextPanelRadioPanel->pushToChildren(RadioButton1); LeftPanelRadioTextPanelRadioPanel->pushToChildren(RadioButton2); LeftPanelRadioTextPanelRadioPanel->pushToChildren(RadioButton3); LeftPanelRadioTextPanelRadioPanel->pushToChildren(RadioButton4); // Create Panel Border LineBorderRefPtr PanelBorder1 = OSG::LineBorder::create(); PanelBorder1->setColor(Color4f(0.0,0.0,0.0,1.0)); PanelBorder1->setWidth(1); // Create and edit Panel PanelRefPtr LeftPanelRadioTextPanel = OSG::Panel::create(); LeftPanelRadioTextPanel->setPreferredSize(Vec2f(180, 500)); LeftPanelRadioTextPanel->pushToChildren(LeftPanelRadioTextPanelRadioPanel); LeftPanelRadioTextPanel->pushToChildren(LeftPanelTextArea); LeftPanelRadioTextPanel->pushToChildren(LeftPanelTextFieldLabel); LeftPanelRadioTextPanel->pushToChildren(LeftPanelTextField); LeftPanelRadioTextPanel->setLayout(LeftPanelRadioTextPanelLayout); LeftPanelRadioTextPanel->setBackgrounds(LeftPanelRadioTextPanelBackground); LeftPanelRadioTextPanel->setBorders(PanelBorder1); return LeftPanelRadioTextPanel; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); TutorialMouseListener mouseListener; TutorialMouseMotionListener mouseMotionListener; TutorialWindow->addMouseListener(&mouseListener); TutorialWindow->addMouseMotionListener(&mouseMotionListener); TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); // Set up Window //Load in File NodeRefPtr LoadedFile = SceneFileHandler::the()->read("C:\\Documents and Settings\\All Users\\Documents\\Cell.osb"); // Make Main Scene Node create3DObjects(); scene = OSG::Node::create(); scene->setCore(OSG::Group::create()); scene->addChild(LoadedFile); // Create the Graphics GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); /****************************************************** Create a Background ******************************************************/ ColorLayerRefPtr GreyBackground = OSG::ColorLayer::create(); GreyBackground->setColor(Color4f(.93,.93,.93,1.0)); /****************************************************** Create some Borders ******************************************************/ LineBorderRefPtr PanelBorder = OSG::LineBorder::create(); EmptyBorderRefPtr Panel1Border = OSG::EmptyBorder::create(); EmptyBorderRefPtr Panel2Border = OSG::EmptyBorder::create(); EmptyBorderRefPtr emptyBorder = OSG::EmptyBorder::create(); PanelBorder->setColor(Color4f(0.0,0.0,0.0,1.0)); PanelBorder->setWidth(1); Panel1Border->setTopWidth(0); Panel1Border->setBottomWidth(6); Panel1Border->setLeftWidth(0); Panel1Border->setRightWidth(0); Panel2Border->setTopWidth(0); Panel2Border->setBottomWidth(0); Panel2Border->setLeftWidth(0); Panel2Border->setRightWidth(0); /****************************************************** Create some Labels and stuff to go with them ******************************************************/ LabelRefPtr LeftPanelLabel1 = OSG::Label::create(); UIFontRefPtr LeftPanelLabel1Font = OSG::UIFont::create(); LeftPanelLabel1Font->setSize(50); LeftPanelLabel1->setBorders(emptyBorder); LeftPanelLabel1->setBackgrounds(GreyBackground); LeftPanelLabel1->setFont(LeftPanelLabel1Font); LeftPanelLabel1->setText("OSG Gui"); LeftPanelLabel1->setPreferredSize(Vec2f(300, 100)); LeftPanelLabel1->setAlignment(Vec2f(0.0f, 0.5f)); /****************************************************** Create some Layouts ******************************************************/ BoxLayoutRefPtr MainInternalWindowLayout = OSG::BoxLayout::create(); FlowLayoutRefPtr LeftPanelLayout = OSG::FlowLayout::create(); BoxLayoutRefPtr RightPanelLayout = OSG::BoxLayout::create(); MainInternalWindowLayout->setOrientation(BoxLayout::HORIZONTAL_ORIENTATION); LeftPanelLayout->setOrientation(FlowLayout::HORIZONTAL_ORIENTATION); LeftPanelLayout->setMinorAxisAlignment(1.0f); RightPanelLayout->setOrientation(BoxLayout::VERTICAL_ORIENTATION); /****************************************************** Create MainFrame and Panels ******************************************************/ PanelRefPtr LeftPanel = OSG::Panel::create(); PanelRefPtr RightPanel = OSG::Panel::create(); // LeftPanel stuff LeftPanel->setPreferredSize(Vec2f(400, 500)); LeftPanel->pushToChildren(LeftPanelLabel1); LeftPanel->pushToChildren(createLeftPanelButtonPanel()); LeftPanel->pushToChildren(createLeftPanelRadioTextPanel()); LeftPanel->setLayout(LeftPanelLayout); LeftPanel->setBackgrounds(GreyBackground); LeftPanel->setBorders(Panel1Border); //RightPanel stuff RightPanel->setPreferredSize(Vec2f(200, 620)); RightPanel->pushToChildren(createRightPanelButtonPanel()); RightPanel->pushToChildren(createRightPanelCheckPanel()); RightPanel->setLayout(RightPanelLayout); RightPanel->setBackgrounds(GreyBackground); RightPanel->setBorders(Panel2Border); // Create The Main InternalWindow InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create(); MainInternalWindow->pushToChildren(LeftPanel); MainInternalWindow->pushToChildren(RightPanel); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(GreyBackground); MainInternalWindow->setBorders(PanelBorder); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(1.0f,1.0f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Make A 3D Rectangle to draw the UI on UIRectangleRefPtr UIRectCore = UIRectangle::create(); UIRectCore->setPoint(Pnt3f(-310.0,-310.0,370.0)); UIRectCore->setWidth(620); UIRectCore->setHeight(620); UIRectCore->setDrawingSurface(TutorialDrawingSurface); NodeRefPtr UIRectNode = OSG::Node::create(); UIRectNode->setCore(UIRectCore); // add the UIRect as a child scene->addChild(UIRectNode); mgr->setRoot(scene); // 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, "21ExampleInterface"); //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); // 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; }