ComponentRefPtr createRightPanelCheckPanel(void) { // Create and edit the CheckBoxes CheckboxButtonRefPtr RightPanelCheck1 = OSG::CheckboxButton::create(); CheckboxButtonRefPtr RightPanelCheck2 = OSG::CheckboxButton::create(); CheckboxButtonRefPtr RightPanelCheck3 = OSG::CheckboxButton::create(); CheckboxButtonRefPtr RightPanelCheck4 = OSG::CheckboxButton::create(); //NOTE HorizontalAlignment needs to be changed to Alignment only with Vec2f arg RightPanelCheck1->setText("Show Torus"); RightPanelCheck1->setPreferredSize(Vec2f(125,50)); RightPanelCheck1->setAlignment(0.0); // Add Listener RightPanelCheck1->addButtonSelectedListener(&RightPanelCheck1Listener); RightPanelCheck2->setText("Show Box"); RightPanelCheck2->setPreferredSize(Vec2f(125,50)); RightPanelCheck2->setAlignment(Vec2f (0.5,0.0)); // Add Listener RightPanelCheck2->addButtonSelectedListener(&RightPanelCheck2Listener); RightPanelCheck3->setText("Show Sphere"); RightPanelCheck3->setPreferredSize(Vec2f(125,50)); RightPanelCheck3->setAlignment(Vec2f(0.0,0.0)); // Add Listener RightPanelCheck3->addButtonSelectedListener(&RightPanelCheck3Listener); RightPanelCheck4->setText("Show Cone"); RightPanelCheck4->setPreferredSize(Vec2f(125,50)); RightPanelCheck4->setAlignment(Vec2f(0.0,0.0)); // Add Listener RightPanelCheck4->addButtonSelectedListener(&RightPanelCheck4Listener); // Create an edit Panel Background ColorLayerRefPtr RightPanelCheckPanelBackground = OSG::ColorLayer::create(); RightPanelCheckPanelBackground->setColor(Color4f(0.93,0.93,0.93,1.0)); // Create and edit Panel layout BoxLayoutRefPtr RightPanelCheckPanelLayout = OSG::BoxLayout::create(); RightPanelCheckPanelLayout->setOrientation(BoxLayout::VERTICAL_ORIENTATION); RightPanelCheckPanelLayout->setMinorAxisAlignment(0.5f); // Create Panel Border LineBorderRefPtr PanelBorder3 = OSG::LineBorder::create(); PanelBorder3->setColor(Color4f(0.0,0.0,0.0,1.0)); PanelBorder3->setWidth(1); // Create and edit Panel PanelRefPtr RightPanelCheckPanel = OSG::Panel::create(); RightPanelCheckPanel->setPreferredSize(Vec2f(200, 300)); RightPanelCheckPanel->pushToChildren(RightPanelCheck1); RightPanelCheckPanel->pushToChildren(RightPanelCheck2); RightPanelCheckPanel->pushToChildren(RightPanelCheck3); RightPanelCheckPanel->pushToChildren(RightPanelCheck4); RightPanelCheckPanel->setLayout(RightPanelCheckPanelLayout); RightPanelCheckPanel->setBackgrounds(RightPanelCheckPanelBackground); RightPanelCheckPanel->setBorders(PanelBorder3); return RightPanelCheckPanel; }
virtual void execute(void) { _HasBeenDone = true; _PreviousColor = _TheBackground->getColor(); _TheBackground->setColor(_ChangeToColor); }
ComponentRefPtr createRightPanelButtonPanel(void) { // Create and edit the Panel Buttons ToggleButtonRefPtr RightPanelButton1 = OSG::ToggleButton::create(); ToggleButtonRefPtr RightPanelButton2 = OSG::ToggleButton::create(); ToggleButtonRefPtr RightPanelButton3 = OSG::ToggleButton::create(); ToggleButtonRefPtr RightPanelButton4 = OSG::ToggleButton::create(); RightPanelButton1->setText("These"); RightPanelButton1->setPreferredSize(Vec2f(100,50)); RightPanelButton2->setText("are"); RightPanelButton2->setPreferredSize(Vec2f(100,50)); RightPanelButton3->setText("toggle"); RightPanelButton3->setPreferredSize(Vec2f(100,50)); RightPanelButton4->setText("buttons"); RightPanelButton4->setPreferredSize(Vec2f(100,50)); // Create an edit Panel Background ColorLayerRefPtr RightPanelButtonPanelBackground = OSG::ColorLayer::create(); RightPanelButtonPanelBackground->setColor(Color4f(0.93,0.93,0.93,1.0)); // Create and edit Panel layout BoxLayoutRefPtr RightPanelButtonPanelLayout = OSG::BoxLayout::create(); RightPanelButtonPanelLayout->setOrientation(BoxLayout::VERTICAL_ORIENTATION); // Create Panel Border LineBorderRefPtr PanelBorder2 = OSG::LineBorder::create(); PanelBorder2->setColor(Color4f(0.0,0.0,0.0,1.0)); PanelBorder2->setWidth(1); // Create and edit Panel PanelRefPtr RightPanelButtonPanel = OSG::Panel::create(); RightPanelButtonPanel->setPreferredSize(Vec2f(200, 300)); RightPanelButtonPanel->pushToChildren(RightPanelButton1); RightPanelButtonPanel->pushToChildren(RightPanelButton2); RightPanelButtonPanel->pushToChildren(RightPanelButton3); RightPanelButtonPanel->pushToChildren(RightPanelButton4); RightPanelButtonPanel->setLayout(RightPanelButtonPanelLayout); RightPanelButtonPanel->setBackgrounds(RightPanelButtonPanelBackground); RightPanelButtonPanel->setBorders(PanelBorder2); return RightPanelButtonPanel; }
LayerRefPtr createComplexBackground(void) { // Create complex Background ColorLayerRefPtr ComplexBackgroundBase = OSG::ColorLayer::create(); GradientLayerRefPtr ComplexBackgroundGradient1 = OSG::GradientLayer::create(); GradientLayerRefPtr ComplexBackgroundGradient2 = OSG::GradientLayer::create(); GradientLayerRefPtr ComplexBackgroundGradient3 = OSG::GradientLayer::create(); CompoundLayerRefPtr ComplexBackgroundCompound1 = OSG::CompoundLayer::create(); CompoundLayerRefPtr ComplexBackgroundCompound2 = OSG::CompoundLayer::create(); CompoundLayerRefPtr ComplexBackground = OSG::CompoundLayer::create(); ComplexBackgroundBase->setColor(Color4f(0.0, 0.0, .25, 1.0)); ComplexBackgroundGradient1->editMFColors()->push_back(Color4f(1.0, 0.0, 0.0, 0.5)); ComplexBackgroundGradient1->editMFStops()->push_back(0.0); ComplexBackgroundGradient1->editMFColors()->push_back(Color4f(0.5, 0.0, 0.0, 0.3)); ComplexBackgroundGradient1->editMFStops()->push_back(1.0); ComplexBackgroundGradient1->setStartPosition(Vec2f(0.0f,0.0f)); ComplexBackgroundGradient1->setEndPosition(Vec2f(1.0f,0.0f)); ComplexBackgroundGradient2->editMFColors()->push_back(Color4f(.6, 0.0, 0.3, 1.0)); ComplexBackgroundGradient2->editMFStops()->push_back(0.0); ComplexBackgroundGradient2->editMFColors()->push_back(Color4f(.2, 0.0, 0.3, 0.5)); ComplexBackgroundGradient2->editMFStops()->push_back(1.0); ComplexBackgroundGradient2->setStartPosition(Vec2f(0.0f,0.0f)); ComplexBackgroundGradient2->setEndPosition(Vec2f(0.0f,1.0f)); ComplexBackgroundGradient3->editMFColors()->push_back(Color4f(0.0, 0.0, 0.2, 0.2)); ComplexBackgroundGradient3->editMFStops()->push_back(0.0); ComplexBackgroundGradient3->editMFColors()->push_back(Color4f(0.0, 0.0, 0.2, 0.3)); ComplexBackgroundGradient3->editMFStops()->push_back(1.0); ComplexBackgroundGradient3->setStartPosition(Vec2f(0.0f,0.0f)); ComplexBackgroundGradient3->setEndPosition(Vec2f(1.0f,0.0f)); ComplexBackgroundCompound1->pushToBackgrounds(ComplexBackgroundBase); ComplexBackgroundCompound1->pushToBackgrounds(ComplexBackgroundGradient1); ComplexBackgroundCompound2->pushToBackgrounds(ComplexBackgroundGradient2); ComplexBackgroundCompound2->pushToBackgrounds(ComplexBackgroundGradient3); ComplexBackground->pushToBackgrounds(ComplexBackgroundCompound1); ComplexBackground->pushToBackgrounds(ComplexBackgroundCompound2); return ComplexBackground; }
ComponentTransitPtr DefaultTableCellEditor::getTableCellEditorComponent(Table* const table, const boost::any& value, bool isSelected, UInt32 row, UInt32 column) { if(value.empty()){ return ComponentTransitPtr(NULL); } TextFieldRefPtr TheTextField = TextField::create(); std::string tempString; try { tempString = lexical_cast(value); } catch (boost::bad_lexical_cast &) { //Could not convert to string } TheTextField->setText(tempString); TheTextField->setPreferredSize(Vec2f(100,30)); TheTextField->setAlignment(Vec2f(0.5,0.5)); TheTextField->selectAll(); TheTextField->setCaretPosition(TheTextField->getText().size()); ColorLayerRefPtr tempBackground; tempBackground = ColorLayer::create(); TheTextField->setBackground(tempBackground); //if(isSelected){ // tempBackground->setColor(Color4f(0.4, 0.4, 1.0, 1.0)); //} //else{ tempBackground->setColor(Color4f(1.0, 1.0, 1.0, 1.0)); //} LineBorderRefPtr tempBorder; tempBorder = LineBorder::create(); tempBorder->setColor(Color4f(0.0, 0.0, 1.0, 1.0)); TheTextField->setBorder(tempBorder); setDefaultStringEditor(TheTextField); _EditorActionConnection = getDefaultStringEditor()->connectActionPerformed(boost::bind(&DefaultTableCellEditor::handleEditorAction, this, _1)); _EditorFocusLostConnection = getDefaultStringEditor()->connectFocusLost(boost::bind(&DefaultTableCellEditor::handleEditorFocusLost, this, _1)); _EditorKeyPressedConnection = getDefaultStringEditor()->connectKeyPressed(boost::bind(&DefaultTableCellEditor::handleEditorKeyPressed, this, _1)); return ComponentTransitPtr(getDefaultStringEditor()); }
OSG_BEGIN_NAMESPACE /***************************************************************************\ * Description * \***************************************************************************/ /*! \class OSG::DefaultStringTableCellRenderer A DefaultStringTableCellRenderer. */ /***************************************************************************\ * Class variables * \***************************************************************************/ /***************************************************************************\ * Class methods * \***************************************************************************/ /***************************************************************************\ * Instance methods * \***************************************************************************/ ComponentRefPtr DefaultStringTableCellRenderer::getTableCellRendererComponent(TableRefPtr table, const boost::any& value, bool isSelected, bool hasFocus, UInt32 row, UInt32 column) { if(value.empty()){ return NULL; } LabelRefPtr TheLabel = Label::create(); std::string tempString; try { tempString = lexical_cast(value); } catch (boost::bad_lexical_cast &) { //Could not convert to string } TheLabel->setText(tempString); TheLabel->setPreferredSize(Vec2f(100,30)); ColorLayerRefPtr tempBackground; tempBackground = ColorLayer::create(); TheLabel->setBackgrounds(tempBackground); if(isSelected){ tempBackground->setColor(Color4f(0.4, 0.4, 1.0, 1.0)); } else{ tempBackground->setColor(Color4f(1.0, 1.0, 1.0, 1.0)); } if(hasFocus){ LineBorderRefPtr tempBorder; tempBorder = LineBorder::create(); TheLabel->setBorders(tempBorder); tempBorder->setColor(Color4f(0.0, 0.0, 1.0, 1.0)); } else{ EmptyBorderRefPtr tempBorder; tempBorder = EmptyBorder::create(); TheLabel->setBorders(tempBorder); } return dynamic_pointer_cast<Component>(TheLabel); }
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(); /****************************************************** Creates some 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(); /****************************************************** Create SpringLayout. This layout simply places all Components within it on top of each other. They are placed in reverse order of how they are added to the MainFrame (Components added first are rendered last, those added last are rendered first). Note: SpringLayout has no options which can be set. ******************************************************/ SpringLayoutRefPtr MainInternalWindowLayout = OSG::SpringLayout::create(); // OverlayLayout has no options to edit! // NOTHING : ) /****************************************************** Create and edit some Button Components. ******************************************************/ ExampleButton1->setPreferredSize(Vec2f(50,50)); ExampleButton1->setText("Button 1"); ExampleButton2->setPreferredSize(Vec2f(50,50)); ExampleButton2->setText("Button 2"); ExampleButton3->setPreferredSize(Vec2f(50,50)); ExampleButton3->setText("Button 3"); ExampleButton4->setPreferredSize(Vec2f(50,50)); ExampleButton4->setText("Button 4"); ExampleButton5->setPreferredSize(Vec2f(50,50)); ExampleButton5->setText("Button 5"); ExampleButton6->setPreferredSize(Vec2f(50,50)); ExampleButton6->setText("Button 6"); InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create(); // SpringLayoutConstraints Information // It is possible to set the constraint for the Y_EDGE, X_EDGE, BASELINE_EDGE, NORTH_EDGE, SOUTH_EDGE, EAST_EDGE, WEST_EDGE, HEIGHT_EDGE, and/or WIDTH_EDGE of a component. // It is possible to constrain a component's edge x pixels above, below, to the right of, or to the left of the edges other components, frames, and/or the MainInternalWindow. // It is possible to constrain a component to the Y_EDGE, X_EDGE, BASELINE_EDGE, NORTH_EDGE, SOUTH_EDGE, EAST_EDGE, WEST_EDGE, HORIZONTAL_CENTER_EDGE, VERTICAL_CENTER_EDGE, HEIGHT_EDGE, and/or WIDTH_EDGE of whatever component to which it is constrained. //Example Button 1 MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, ExampleButton1, 25, SpringLayoutConstraints::NORTH_EDGE, MainInternalWindow); // The North edge of ExampleButton1 is 25 pixels below the North edge of the MainInternalWindow. MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, ExampleButton1, -5, SpringLayoutConstraints::VERTICAL_CENTER_EDGE, MainInternalWindow); // The South edge of ExampleButton1 is 5 pixels above the Vertical Center of the MainInternalWindow. MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, ExampleButton1, -25, SpringLayoutConstraints::EAST_EDGE, MainInternalWindow); // The East edge of ExampleButton1 is 25 pixels to the left of the East edge of the MainInternalWindow. MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, ExampleButton1, 25, SpringLayoutConstraints::WEST_EDGE, MainInternalWindow); // The West edge of ExampleButton1 is 25 pixels to the right of the West edge of the MainInternalWindow. //Example Button 2 MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::HEIGHT_EDGE, ExampleButton2, LayoutSpring::height(ExampleButton2)); // The Height edge of ExampleButton2 is set to the height of ExampleButton2. MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, ExampleButton2, -25, SpringLayoutConstraints::SOUTH_EDGE, MainInternalWindow); // The South edge of ExampleButton2 is 25 pixels above the South edge of the MainInternalWindow. MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, ExampleButton2, -5, SpringLayoutConstraints::HORIZONTAL_CENTER_EDGE, MainInternalWindow); // The East edge of ExampleButton2 is 5 pixels to the left of the Horizontal Center of the MainInternalWindow. MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, ExampleButton2, 25, SpringLayoutConstraints::WEST_EDGE, MainInternalWindow); // The West edge of ExampleButton2 is 25 pixels to the right of the West edge of the MainInternalWindow. //Example Button 3 MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::HEIGHT_EDGE, ExampleButton3, LayoutSpring::height(ExampleButton3)); // The Height edge of ExampleButton3 is set to the height of ExampleButton3. MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, ExampleButton3, -25, SpringLayoutConstraints::SOUTH_EDGE, MainInternalWindow); // The South edge of ExampleButton3 is 25 pixels above the South edge of the MainInternalWindow. MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, ExampleButton3, 5, SpringLayoutConstraints::HORIZONTAL_CENTER_EDGE, MainInternalWindow); // The West edge of ExampleButton3 is 5 pixels to the right of the Horizontal Center of the MainInternalWindow. MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, ExampleButton3, -25, SpringLayoutConstraints::EAST_EDGE, MainInternalWindow); // The East edge of ExampleButton3 is 25 pixels to the left of the East edge of the MainInternalWindow. //Example Button 4 MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, ExampleButton4, 25, SpringLayoutConstraints::SOUTH_EDGE, ExampleButton1); // The North edge of ExampleButton4 is 25 pixels below the South edge of ExampleButton1. MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, ExampleButton4, -25, SpringLayoutConstraints::NORTH_EDGE, ExampleButton2); // The South edge of ExampleButton4 is 25 pixels above the North edge of ExampleButton2. MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, ExampleButton4, 25, SpringLayoutConstraints::WEST_EDGE, MainInternalWindow); // The West edge of ExampleButton4 is 25 pixels to the right of the West edge of the MainInternalWindow. MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, ExampleButton4, -100, SpringLayoutConstraints::HORIZONTAL_CENTER_EDGE, MainInternalWindow); // The East edge of ExampleButton4 is 100 pixels to the left of the Horizontal Center of the MainInternalWindow. //Example Button 5 MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, ExampleButton5, 25, SpringLayoutConstraints::SOUTH_EDGE, ExampleButton1); // The North edge of ExampleButton5 is 25 pixels below the South edge of ExampleButton1. MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::HEIGHT_EDGE, ExampleButton5, 0, SpringLayoutConstraints::HEIGHT_EDGE, ExampleButton4); // The Height of ExampleButton5 is set to the Height of ExampleButton4. MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, ExampleButton5, 75, SpringLayoutConstraints::HORIZONTAL_CENTER_EDGE, MainInternalWindow); // The East edge of ExampleButton5 is 75 pixels to the right of the Horizontal Center of the MainInternalWindow. MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, ExampleButton5, -75, SpringLayoutConstraints::HORIZONTAL_CENTER_EDGE, MainInternalWindow); // The West edge of ExampleButton5 is 75 pixels to the left of the Horizontal Center of the MainInternalWindow. //Example Button 6 MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, ExampleButton6, 25, SpringLayoutConstraints::SOUTH_EDGE, ExampleButton1); // The North edge of ExampleButton6 is 25 pixels below the South edge of ExampleButton1. MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, ExampleButton6, -25, SpringLayoutConstraints::NORTH_EDGE, ExampleButton2); // The South edge of ExampleButton6 is 25 pixels above the North edge of ExampleButton2. MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, ExampleButton6, 100, SpringLayoutConstraints::HORIZONTAL_CENTER_EDGE, MainInternalWindow); // The West edge of ExampleButton6 is 100 pixels to the right of the Horizontal Center of the MainInternalWindow. MainInternalWindowLayout->putConstraint(SpringLayoutConstraints::WIDTH_EDGE, ExampleButton6, 0, SpringLayoutConstraints::WIDTH_EDGE, ExampleButton4); // The Width of ExampleButton6 is set to the Width of ExampleButton4. // 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)); MainInternalWindow->pushToChildren(ExampleButton1); MainInternalWindow->pushToChildren(ExampleButton2); MainInternalWindow->pushToChildren(ExampleButton3); MainInternalWindow->pushToChildren(ExampleButton4); MainInternalWindow->pushToChildren(ExampleButton5); MainInternalWindow->pushToChildren(ExampleButton6); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); mgr->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRefPtr TutorialViewport = mgr->getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); // Show the whole Scene mgr->showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "36SpringLayout"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
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; }
OSG_BEGIN_NAMESPACE /***************************************************************************\ * Description * \***************************************************************************/ /*! \class OSG::DefaultBoolTableCellRenderer A DefaultBoolTableCellRenderer. */ /***************************************************************************\ * Class variables * \***************************************************************************/ /***************************************************************************\ * Class methods * \***************************************************************************/ /***************************************************************************\ * Instance methods * \***************************************************************************/ ComponentTransitPtr DefaultBoolTableCellRenderer::getTableCellRendererComponent(Table* const table, const boost::any& value, bool isSelected, bool hasFocus, UInt32 row, UInt32 column) { if(value.empty()){ return ComponentTransitPtr(NULL); } LabelRefPtr TheLabel = Label::create(); std::string tempString; try { if(boost::any_cast<bool>(value)) { tempString = "True"; } else { tempString = "False"; } } catch (boost::bad_any_cast &) { //Not a bool } TheLabel->setText(tempString); TheLabel->setPreferredSize(Vec2f(100,30)); ColorLayerRefPtr tempBackground; tempBackground = ColorLayer::create(); TheLabel->setBackgrounds(tempBackground); if(isSelected){ tempBackground->setColor(Color4f(0.4, 0.4, 1.0, 1.0)); } else{ tempBackground->setColor(Color4f(1.0, 1.0, 1.0, 1.0)); } if(hasFocus){ LineBorderRefPtr tempBorder; tempBorder = LineBorder::create(); TheLabel->setBorders(tempBorder); tempBorder->setColor(Color4f(0.0, 0.0, 1.0, 1.0)); } else{ EmptyBorderRefPtr tempBorder; tempBorder = EmptyBorder::create(); TheLabel->setBorders(tempBorder); } return ComponentTransitPtr(TheLabel.get()); }
ComponentTransitPtr ColorChooserComboBoxComponentGenerator::getComboBoxComponent(ComboBox* const Parent, const boost::any& Value, UInt32 Index, bool IsSelected, bool HasFocus) { if(Value.empty()){ return ComponentTransitPtr(NULL); } PanelRefPtr TheComponent = Panel::create();//dynamic_pointer_cast<Component>(getDrawObjectPrototype()->shallowCopy()); TheComponent->setLayout(LayoutRefPtr(FlowLayout::create())); LabelRefPtr theColorLabel = Label::create(); //theColorLabel->setPreferredSize(Vec2f(50.0f,50.0f)); theColorLabel->setBorders(NULL); try { Color4f theColor = boost::any_cast<Color4f>(Value); if(theColor != NULL) { ColorLayerRefPtr theColorLabelBackground = ColorLayer::create(); theColorLabelBackground->setColor(theColor); theColorLabel->setBackgrounds(theColorLabelBackground); } } catch(boost::bad_any_cast &) { std::string ValueString; try { ValueString = lexical_cast(Value); } catch (boost::bad_lexical_cast &) { //Could not convert to string SWARNING << "ColorChooserComboBoxComponentGenerator::getComboBoxComponent - The elements should either be a Color4f value or a std::string\n"; } theColorLabel->setText(ValueString); if(IsSelected && HasFocus) { if(getFocusedTextColorHasPriority()) { theColorLabel->setTextColors(getFocusedTextColor()); } else { theColorLabel->setTextColors(getSelectedTextColor()); } } else if(IsSelected) { theColorLabel->setTextColors(getSelectedTextColor()); } else if(HasFocus) { theColorLabel->setTextColors(getFocusedTextColor()); } } TheComponent->pushToChildren(theColorLabel); if(IsSelected && HasFocus) { if(getFocusedBorderHasPriority()) { TheComponent->setBorders(getFocusedBorder()); } else { TheComponent->setBorders(getSelectedBorder()); } if(getFocusedBackgroundHasPriority()) { TheComponent->setBackgrounds(getFocusedBackground()); TheComponent->setForegrounds(getFocusedForeground()); } else { TheComponent->setBackgrounds(getSelectedBackground()); TheComponent->setForegrounds(getSelectedForeground()); } } else if(IsSelected) { TheComponent->setBorders(getSelectedBorder()); TheComponent->setBackgrounds(getSelectedBackground()); TheComponent->setForegrounds(getSelectedForeground()); } else if(HasFocus) { TheComponent->setBorders(getFocusedBorder()); TheComponent->setBackgrounds(getFocusedBackground()); TheComponent->setForegrounds(getFocusedForeground()); } return ComponentTransitPtr(TheComponent.get()); }
PanelUnrecPtr createSingleFieldPanel(void) { ChangableBorder = OSG::LineBorder::create(); ChangableBorder->setColor(Color4f(0.0,0.0,0.0,1.0)); ChangableBackground = OSG::ColorLayer::create(); ChangableBackground->setColor(Color4f(1.0,1.0,1.0,1.0)); LabelRefPtr ChangableLabel = OSG::Label::create(); ChangableLabel->setText("Changable"); ChangableLabel->setBorders(ChangableBorder); ChangableLabel->setBackgrounds(ChangableBackground); //Command Buttons TheCommandManager = CommandManager::create(TheUndoManager); ButtonRefPtr BorderRedButton = OSG::Button::create(); BorderRedButton->setText("Border Red"); SetBorderColorActionListener* TheSetRedBorderColorActionListener = new SetBorderColorActionListener(ChangableBorder, Color4f(1.0,0.0,0.0,1.0), TheCommandManager); BorderRedButton->addActionListener(TheSetRedBorderColorActionListener); ButtonRefPtr BorderGreenButton = OSG::Button::create(); BorderGreenButton->setText("Border Green"); SetBorderColorActionListener* TheSetGreenBorderColorActionListener = new SetBorderColorActionListener(ChangableBorder, Color4f(0.0,1.0,0.0,1.0), TheCommandManager); BorderGreenButton->addActionListener(TheSetGreenBorderColorActionListener); ButtonRefPtr BorderBlueButton = OSG::Button::create(); BorderBlueButton->setText("Border Blue"); SetBorderColorActionListener* TheSetBlueBorderColorActionListener = new SetBorderColorActionListener(ChangableBorder, Color4f(0.0,0.0,1.0,1.0), TheCommandManager); BorderBlueButton->addActionListener(TheSetBlueBorderColorActionListener); //Background ButtonRefPtr BackgroundRedButton = OSG::Button::create(); BackgroundRedButton->setText("Background Red"); SetBackgroundColorActionListener* TheSetRedBackgroundColorActionListener = new SetBackgroundColorActionListener(ChangableBackground, Color4f(1.0,0.0,0.0,1.0), TheCommandManager); BackgroundRedButton->addActionListener(TheSetRedBackgroundColorActionListener); ButtonRefPtr BackgroundGreenButton = OSG::Button::create(); BackgroundGreenButton->setText("Background Green"); SetBackgroundColorActionListener* TheSetGreenBackgroundColorActionListener = new SetBackgroundColorActionListener(ChangableBackground, Color4f(0.0,1.0,0.0,1.0), TheCommandManager); BackgroundGreenButton->addActionListener(TheSetGreenBackgroundColorActionListener); ButtonRefPtr BackgroundBlueButton = OSG::Button::create(); BackgroundBlueButton->setText("Background Blue"); SetBackgroundColorActionListener* TheSetBlueBackgroundColorActionListener = new SetBackgroundColorActionListener(ChangableBackground, Color4f(0.0,0.0,1.0,1.0), TheCommandManager); BackgroundBlueButton->addActionListener(TheSetBlueBackgroundColorActionListener); LayoutRefPtr ThePanelLayout = OSG::FlowLayout::create(); PanelRefPtr ThePanel = Panel::createEmpty(); ThePanel->setLayout(ThePanelLayout); ThePanel->pushToChildren(BorderRedButton); ThePanel->pushToChildren(BorderGreenButton); ThePanel->pushToChildren(BorderBlueButton); ThePanel->pushToChildren(BackgroundRedButton); ThePanel->pushToChildren(BackgroundGreenButton); ThePanel->pushToChildren(BackgroundBlueButton); ThePanel->pushToChildren(ChangableLabel); 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; }
void GenericFieldContainerEditor::updateProducedEventsPanel(FieldContainer* fc) { _ProducedEventsContainer->clearChildren(); UInt32 NumEvents(fc->getNumEvents()); const EventDescription * Desc; LabelUnrecPtr TheLabel; ComponentRecPtr TheToolTip; GridBagLayoutConstraintsRefPtr LayoutConstraints; UInt32 NumRows(0); if(NumEvents != 0) { BorderLayoutRefPtr TheBorderLayout = BorderLayout::create(); BorderLayoutConstraintsRefPtr WestConstraint = BorderLayoutConstraints::create(); WestConstraint->setRegion(BorderLayoutConstraints::BORDER_WEST); BorderLayoutConstraintsRefPtr CenterConstraint = BorderLayoutConstraints::create(); CenterConstraint->setRegion(BorderLayoutConstraints::BORDER_CENTER); //Backgrounds ColorLayerRefPtr HeaderBgLayer = ColorLayer::create(); HeaderBgLayer->setColor(Color4f(0.7f,0.7f,0.7f,1.0f)); ColorLayerRefPtr LightBgLayer = ColorLayer::create(); LightBgLayer->setColor(Color4f(0.9f,0.9f,0.9f,1.0f)); ColorLayerRefPtr DarkBgLayer = ColorLayer::create(); DarkBgLayer->setColor(Color4f(0.8f,0.8f,0.8f,1.0f)); LabelRecPtr EventsLabel = Label::create(); EventsLabel->setAlignment(Vec2f(0.5f,0.5f)); EventsLabel->setText("Events"); EventsLabel->setBackgrounds(HeaderBgLayer); EventsLabel->setFont(_BoldFont); _ProducedEventsContainer->pushToChildren(EventsLabel); ++NumRows; for(UInt32 i(1) ; i<=NumEvents ; ++i) { Desc = fc->getProducerType().getEventDescription(i); if(Desc != NULL) { //Create the Label TheLabel = Label::create(); TheLabel->setText(Desc->getCName()); TheToolTip = createEventToolTip(Desc); TheLabel->setToolTip(TheToolTip); if((i%2) == 0) { TheLabel->setBackgrounds(DarkBgLayer); } else { TheLabel->setBackgrounds(LightBgLayer); } _ProducedEventsContainer->pushToChildren(TheLabel); ++NumRows; } } } //Set the number of rows for the grid layout dynamic_cast<GridLayout*>(_ProducedEventsContainer->getLayout())->setRows(NumRows); _ProducedEventsContainer->setPreferredSize(Vec2f(400.0f, NumRows*24.0f + _ProducedEventsContainer->getTopInset())); }
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(keyTyped, _1)); // 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 the Layers. ******************************************************/ ColorLayerRefPtr ExampleColorLayer = OSG::ColorLayer::create(); CompoundLayerRefPtr ExampleCompoundLayer = OSG::CompoundLayer::create(); EmptyLayerRefPtr ExampleEmptyLayer = OSG::EmptyLayer::create(); GradientLayerRefPtr ExampleGradientLayer = OSG::GradientLayer::create(); MaterialLayerRefPtr ExampleMaterialLayer = OSG::MaterialLayer::create(); TextureLayerRefPtr ExampleTextureLayer = OSG::TextureLayer::create(); PatternLayerRefPtr ExamplePatternLayer = OSG::PatternLayer::create(); GlassLayerRefPtr ExampleGlassLayer = OSG::GlassLayer::create(); CompoundLayerRefPtr ExampleGlassCompoundLayer = OSG::CompoundLayer::create(); /****************************************************** The ColorLayer is a simple Layer having just a Color to it. -setColor(Color4f): Determine the Color of the Layer. ******************************************************/ ExampleColorLayer->setColor(Color4f(1.0,0.0,0.0,1.0)); /****************************************************** The CompoundLayer allows you to combine multiple Backgrounds into one. The Backgrounds are added sequentially; so in this example the ExampleTextureLayer would be added first, and the ExampleGradientLayer rendered on top of it. -getBackgrounds().push_back(BackgroundName): Adds a Background to the CompoundBackground. ******************************************************/ ExampleCompoundLayer->pushToBackgrounds(ExampleTextureLayer); ExampleCompoundLayer->pushToBackgrounds(ExampleGradientLayer); /****************************************************** The EmptyLayer is a Background with no attributes. ******************************************************/ // Nothing! /****************************************************** The GradientLayer is a Background which displays a gradient of Color. -getColors().push_back(Color4f): Determines the starting Color for the gradient. -getColors().push_back(Color4f): Determines the ending Color for the gradient. -setOrientation(ENUM): Determines the gradient alignment. Takes HORIZONTAL_ORIENTATION or VERTICAL_ORIENTATION arguments. ******************************************************/ ExampleGradientLayer->editMFColors()->push_back(Color4f(1.0, 0.0, 0.0, 1.0)); ExampleGradientLayer->editMFStops()->push_back(0.0); ExampleGradientLayer->editMFColors()->push_back(Color4f(0.0, 1.0, 0.0, 0.75)); ExampleGradientLayer->editMFStops()->push_back(0.5); ExampleGradientLayer->editMFColors()->push_back(Color4f(0.0, 0.0, 1.0, 0.5)); ExampleGradientLayer->editMFStops()->push_back(1.0); ExampleGradientLayer->setStartPosition(Vec2f(0.2f,0.2f)); ExampleGradientLayer->setEndPosition(Vec2f(.6f,0.6f)); ExampleGradientLayer->setSpreadMethod(GradientLayer::SPREAD_REFLECT); /****************************************************** The MaterialLayer is a Background which is created using a Material (also created here). -setMaterial(MaterialName): Determine which Material will be used to create the Background. ******************************************************/ // Creates Material ChunkMaterialRefPtr LayerMaterial = ChunkMaterial::create(); MaterialChunkRefPtr LayerMaterialChunk = MaterialChunk::create(); LayerMaterialChunk->setAmbient(Color4f(1.0,0.0,0.0,1.0)); LayerMaterialChunk->setDiffuse(Color4f(0.0,1.0,0.0,1.0)); LayerMaterialChunk->setSpecular(Color4f(0.0,0.0,1.0,1.0)); LayerMaterial->addChunk(LayerMaterialChunk); // Edit MaterialLayer ExampleMaterialLayer->setMaterial(LayerMaterial); /****************************************************** The TextureLayer is a Background which is created using a Texture (also created here). -setTexture(TextureName): Determine which Texture will be used to create the Background. ******************************************************/ // Creates Texture from Image TextureObjChunkRefPtr LayerTextureObjChunk = TextureObjChunk::create(); ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/Checker.jpg"); LayerTextureObjChunk->setImage(LoadedImage); // Edit TextureLayer ExampleTextureLayer->setTexture(LayerTextureObjChunk); /****************************************************** The PatternLayer is a Background which is created using a Texture (also created here). -setTexture(TextureName): Determine which Texture will be used to create the Background. -setPatternSize(Vec2f): -setVerticalAlignment(): -setHorizontalAlignment(): -setHorizontalRepeat(): -setVerticalRepeat(): -setHorizontalRepeatValue(): -setVerticalRepeatValue(): ******************************************************/ TextureObjChunkRefPtr LayerPatternChunk = TextureObjChunk::create(); //ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/Checker.jpg"); LayerPatternChunk->setImage(LoadedImage); LayerPatternChunk->setWrapS(GL_REPEAT); LayerPatternChunk->setWrapT(GL_CLAMP_TO_EDGE); ExamplePatternLayer->setTexture(LayerPatternChunk); ExamplePatternLayer->setPatternSize(Vec2f(50.0f,50.0f)); ExamplePatternLayer->setVerticalAlignment(0.5); ExamplePatternLayer->setHorizontalAlignment(0.0); ExamplePatternLayer->setHorizontalRepeat(PatternLayer::PATTERN_REPEAT_BY_POINT); ExamplePatternLayer->setVerticalRepeat(PatternLayer::PATTERN_REPEAT_ABSOLUTE); ExamplePatternLayer->setHorizontalRepeatValue(1.0); ExamplePatternLayer->setVerticalRepeatValue(2.0); /****************************************************** ******************************************************/ ExampleGlassLayer->setCenterColor(Color4f(1.0f,1.0f,1.0f,0.0f)); ExampleGlassLayer->setEdgeColor(Color4f(1.0f,1.0f,1.0f,0.7f)); /****************************************************** ******************************************************/ ExampleGlassCompoundLayer->pushToBackgrounds(ExampleColorLayer); ExampleGlassCompoundLayer->pushToBackgrounds(ExampleGlassLayer); /****************************************************** Create and edit Button Components to display the Layers. ******************************************************/ ButtonRefPtr ExampleColorLayerButton = OSG::Button::create(); ButtonRefPtr ExampleCompoundLayerButton = OSG::Button::create(); ButtonRefPtr ExampleEmptyLayerButton = OSG::Button::create(); ButtonRefPtr ExampleGradientLayerButton = OSG::Button::create(); ButtonRefPtr ExampleMaterialLayerButton = OSG::Button::create(); ButtonRefPtr ExampleTextureLayerButton = OSG::Button::create(); ButtonRefPtr ExamplePatternLayerButton = OSG::Button::create(); ButtonRefPtr ExampleGlassLayerButton = OSG::Button::create(); ButtonRefPtr ExampleGlassCompoundLayerButton = OSG::Button::create(); ExampleColorLayerButton->setText("Color Layer"); ExampleColorLayerButton->setBackground(ExampleColorLayer); ExampleColorLayerButton->setActiveBackground(ExampleColorLayer); ExampleColorLayerButton->setRolloverBackground(ExampleColorLayer); ExampleColorLayerButton->setPreferredSize(Vec2f(150,50)); ExampleCompoundLayerButton->setText("Compound Layer"); ExampleCompoundLayerButton->setBackground(ExampleCompoundLayer); ExampleCompoundLayerButton->setActiveBackground(ExampleCompoundLayer); ExampleCompoundLayerButton->setRolloverBackground(ExampleCompoundLayer); ExampleCompoundLayerButton->setPreferredSize(Vec2f(150,50)); ExampleEmptyLayerButton->setText("Empty Layer"); ExampleEmptyLayerButton->setBackground(ExampleEmptyLayer); ExampleEmptyLayerButton->setActiveBackground(ExampleEmptyLayer); ExampleEmptyLayerButton->setRolloverBackground(ExampleEmptyLayer); ExampleEmptyLayerButton->setPreferredSize(Vec2f(150,50)); ExampleGradientLayerButton->setText("Gradient Layer"); ExampleGradientLayerButton->setBackground(ExampleGradientLayer); ExampleGradientLayerButton->setActiveBackground(ExampleGradientLayer); ExampleGradientLayerButton->setRolloverBackground(ExampleGradientLayer); ExampleGradientLayerButton->setPreferredSize(Vec2f(150,50)); ExampleMaterialLayerButton->setText("Material Layer"); ExampleMaterialLayerButton->setBackground(ExampleMaterialLayer); ExampleMaterialLayerButton->setActiveBackground(ExampleMaterialLayer); ExampleMaterialLayerButton->setRolloverBackground(ExampleMaterialLayer); ExampleMaterialLayerButton->setPreferredSize(Vec2f(150,50)); ExampleMaterialLayerButton->setTextColor(Color4f(1.0,1.0,1.0,1.0)); ExampleMaterialLayerButton->setRolloverTextColor(Color4f(1.0,1.0,1.0,1.0)); ExampleMaterialLayerButton->setActiveTextColor(Color4f(1.0,1.0,1.0,1.0)); ExampleTextureLayerButton->setText("Texture Layer"); ExampleTextureLayerButton->setBackground(ExampleTextureLayer); ExampleTextureLayerButton->setActiveBackground(ExampleTextureLayer); ExampleTextureLayerButton->setRolloverBackground(ExampleTextureLayer); ExampleTextureLayerButton->setPreferredSize(Vec2f(150,50)); ExampleTextureLayerButton->setTextColor(Color4f(0.0,1.0,0.0,1.0)); ExampleTextureLayerButton->setRolloverTextColor(Color4f(0.0,1.0,0.0,1.0)); ExampleTextureLayerButton->setActiveTextColor(Color4f(0.0,1.0,0.0,1.0)); ExamplePatternLayerButton->setText("Pattern Layer"); ExamplePatternLayerButton->setBackground(ExamplePatternLayer); ExamplePatternLayerButton->setActiveBackground(ExamplePatternLayer); ExamplePatternLayerButton->setRolloverBackground(ExamplePatternLayer); ExamplePatternLayerButton->setPreferredSize(Vec2f(150,50)); ExamplePatternLayerButton->setTextColor(Color4f(0.0,1.0,0.0,1.0)); ExamplePatternLayerButton->setRolloverTextColor(Color4f(0.0,1.0,0.0,1.0)); ExamplePatternLayerButton->setActiveTextColor(Color4f(0.0,1.0,0.0,1.0)); ExampleGlassLayerButton->setText("Glass Layer"); ExampleGlassLayerButton->setBackground(ExampleGlassLayer); ExampleGlassLayerButton->setActiveBackground(ExampleGlassLayer); ExampleGlassLayerButton->setRolloverBackground(ExampleGlassLayer); ExampleGlassLayerButton->setPreferredSize(Vec2f(150,50)); ExampleGlassLayerButton->setTextColor(Color4f(0.0,0.0,0.0,1.0)); ExampleGlassLayerButton->setRolloverTextColor(Color4f(0.0,0.0,0.0,1.0)); ExampleGlassLayerButton->setActiveTextColor(Color4f(0.0,0.0,0.0,1.0)); ExampleGlassCompoundLayerButton->setText("GlassCompound Layer"); ExampleGlassCompoundLayerButton->setBackground(ExampleGlassCompoundLayer); ExampleGlassCompoundLayerButton->setActiveBackground(ExampleGlassCompoundLayer); ExampleGlassCompoundLayerButton->setRolloverBackground(ExampleGlassCompoundLayer); ExampleGlassCompoundLayerButton->setPreferredSize(Vec2f(150,50)); ExampleGlassCompoundLayerButton->setTextColor(Color4f(0.0,0.0,0.0,1.0)); ExampleGlassCompoundLayerButton->setRolloverTextColor(Color4f(0.0,0.0,0.0,1.0)); ExampleGlassCompoundLayerButton->setActiveTextColor(Color4f(0.0,0.0,0.0,1.0)); /****************************************************** Create a MainFrameBackground. For almost all Tutorials, this is simply a ColorLayer with a semi-transparent white Background. ******************************************************/ // 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)); //InternalWindow Layout LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create(); InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleColorLayerButton); MainInternalWindow->pushToChildren(ExampleCompoundLayerButton); MainInternalWindow->pushToChildren(ExampleEmptyLayerButton); MainInternalWindow->pushToChildren(ExampleGradientLayerButton); MainInternalWindow->pushToChildren(ExampleMaterialLayerButton); MainInternalWindow->pushToChildren(ExampleTextureLayerButton); MainInternalWindow->pushToChildren(ExamplePatternLayerButton); MainInternalWindow->pushToChildren(ExampleGlassLayerButton); MainInternalWindow->pushToChildren(ExampleGlassCompoundLayerButton); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Create the SimpleSceneManager helper sceneManager->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRefPtr 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, "04Background"); //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 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 ******************************************************/ MenuItemRefPtr MenuItem1 = MenuItem::create(); MenuItemRefPtr MenuItem2 = MenuItem::create(); MenuItemRefPtr MenuItem3 = MenuItem::create(); MenuItemRefPtr MenuItem4 = MenuItem::create(); MenuItemRefPtr SubMenuItem1 = MenuItem::create(); MenuItemRefPtr SubMenuItem2 = MenuItem::create(); MenuItemRefPtr SubMenuItem3 = MenuItem::create(); MenuRefPtr 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. ******************************************************/ PopupMenuRefPtr ExamplePopupMenu = PopupMenu::create(); ExamplePopupMenu->addItem(MenuItem1); ExamplePopupMenu->addItem(MenuItem2); ExamplePopupMenu->addItem(MenuItem3); ExamplePopupMenu->addSeparator(); ExamplePopupMenu->addItem(ExampleSubMenu); ExamplePopupMenu->addItem(MenuItem4); // Create a Button and Font UIFontRefPtr PopupMenuButtonFont = OSG::UIFont::create(); PopupMenuButtonFont->setSize(16); ButtonRefPtr PopupMenuButton = OSG::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 ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create(); InternalWindowRefPtr MainInternalWindow = OSG::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 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, "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) 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(); //Background SolidBackgroundRefPtr TutorialBackground = SolidBackground::create(); TutorialBackground->setColor(Color3f(1.0,0.0,0.0)); UndoManagerPtr TheUndoManager = UndoManager::create(); CommandManagerPtr TheCommandManager = CommandManager::create(TheUndoManager); //UndoList DefaultListModelRecPtr UndoRedoListModel = DefaultListModel::create(); UndoRedoListModel->pushBack(boost::any(std::string("Top"))); ListRecPtr UndoRedoList = List::create(); UndoRedoList->setPreferredSize(Vec2f(250, 300)); UndoRedoList->setOrientation(List::VERTICAL_ORIENTATION); UndoRedoList->setModel(UndoRedoListModel); UndoRedoList->getSelectionModel()->connectSelectionChanged(boost::bind(&handleUndoRedoListSelectionChanged, _1, TheUndoManager)); ButtonRecPtr UndoButton = OSG::Button::create(); UndoButton->setText("Undo"); UndoButton->setEnabled(false); UndoButton->connectActionPerformed(boost::bind(&handleUndoButtonAction, _1, TheUndoManager)); ButtonRecPtr RedoButton = OSG::Button::create(); RedoButton->setText("Redo"); RedoButton->setEnabled(false); RedoButton->connectActionPerformed(boost::bind(&handleRedoButtonActionPerformed, _1, TheUndoManager)); TheUndoManager->connectStateChanged(boost::bind(&handleUndoManagerStateChanged, _1, UndoButton.get(), RedoButton.get(), UndoRedoListModel.get(), TheUndoManager)); // Create a ScrollPanel for easier viewing of the List (see 27ScrollPanel) ScrollPanelRefPtr UndoRedoScrollPanel = ScrollPanel::create(); UndoRedoScrollPanel->setPreferredSize(Vec2f(200,200)); UndoRedoScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); UndoRedoScrollPanel->setViewComponent(UndoRedoList); //Edited Label LabelRecPtr EditedLabel = Label::create(); EditedLabel->setText("Can be edited"); EditedLabel->setPreferredSize(Vec2f(100.0f,18.0f)); //Editor Field LabelRecPtr TheTextEditorLabel = Label::create(); TheTextEditorLabel->setText("Text"); TheTextEditorLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); FieldEditorComponentRefPtr TheTextEditor = FieldEditorFactory::the()->createDefaultEditor(EditedLabel, Label::TextFieldId, TheCommandManager); TheTextEditor->setPreferredSize(Vec2f(100.0f, 20.0f)); LabelRecPtr ThePreferredSizeEditorLabel = Label::create(); ThePreferredSizeEditorLabel->setText("PreferredSize"); ThePreferredSizeEditorLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); FieldEditorComponentRefPtr ThePreferredSizeEditor = FieldEditorFactory::the()->createDefaultEditor(EditedLabel, Label::PreferredSizeFieldId, TheCommandManager); ThePreferredSizeEditor->setPreferredSize(Vec2f(150.0f, 20.0f)); //Editing Panel LayoutRefPtr EditorPanelLayout = OSG::FlowLayout::create(); PanelRecPtr EditorPanel = Panel::create(); EditorPanel->setPreferredSize(Vec2f(200.0f,200.0f)); EditorPanel->pushToChildren(TheTextEditorLabel); EditorPanel->pushToChildren(TheTextEditor); EditorPanel->pushToChildren(ThePreferredSizeEditorLabel); EditorPanel->pushToChildren(ThePreferredSizeEditor); EditorPanel->setLayout(EditorPanelLayout); //Undo Panel LabelRecPtr UndoPanelLabel = Label::create(); UndoPanelLabel->setText("Undo Panel"); UndoPanelLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); LayoutRefPtr UndoPanelLayout = OSG::FlowLayout::create(); PanelRecPtr UndoPanel = Panel::create(); UndoPanel->setPreferredSize(Vec2f(300.0f,300.0f)); UndoPanel->pushToChildren(UndoPanelLabel); UndoPanel->pushToChildren(UndoRedoScrollPanel); UndoPanel->pushToChildren(UndoButton); UndoPanel->pushToChildren(RedoButton); UndoPanel->setLayout(UndoPanelLayout); // 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(); LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create(); MainInternalWindow->pushToChildren(EditedLabel); MainInternalWindow->pushToChildren(EditorPanel); MainInternalWindow->pushToChildren(UndoPanel); 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); // 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); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRefPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); TutorialViewport->setBackground(TutorialBackground); // 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, "02GenericFieldEditor"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); NodeRefPtr Root(NULL); if(argc == 2) { Root = SceneFileHandler::the()->read(argv[1]); } if(Root == NULL) { // Make Torus Node (creates Torus in background of Root) NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); setName(TorusGeometryNode, std::string("Torus")); NodeRefPtr TorusNode = Node::create(); TorusNode->setCore(OSG::Transform::create()); TorusNode->addChild(TorusGeometryNode); setName(TorusNode, std::string("Torus Transform")); NodeRefPtr SphereGeometryNode = makeSphere(2,1.0f); setName(SphereGeometryNode, std::string("Sphere")); NodeRefPtr BoxGeometryNode = makeBox(1.0,1.0,1.0,1,1,1); setName(BoxGeometryNode, std::string("Box")); // Make Main Scene Node and add the Torus Root = OSG::Node::create(); Root->setCore(OSG::Group::create()); Root->addChild(TorusNode); Root->addChild(SphereGeometryNode); Root->addChild(BoxGeometryNode); setName(Root, std::string("Root")); } // Create the Graphics GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); //Tree Model TheTreeModel = SceneGraphTreeModel::create(); TheTreeModel->setRoot(Root); //TheFileSystemTreeModel = FileSystemTreeModel::create(); //TheFileSystemTreeModel->setRoot(BoostPath("C:\\")); //TheFileSystemTreeModel->setRoot(BoostPath("/")); //Create the Tree TheTree = Tree::create(); TheTree->setPreferredSize(Vec2f(100, 500)); TheTree->setModel(TheTreeModel); //TheTree->setModel(TheFileSystemTreeModel); TutorialTreeSelectionListener TheTutorialTreeSelectionListener; TheTree->getSelectionModel()->addTreeSelectionListener(&TheTutorialTreeSelectionListener); // Create a ScrollPanel for easier viewing of the List (see 27ScrollPanel) BorderLayoutConstraintsRefPtr SceneTreeConstraints = OSG::BorderLayoutConstraints::create(); SceneTreeConstraints->setRegion(BorderLayoutConstraints::BORDER_WEST); ScrollPanelRefPtr ExampleScrollPanel = ScrollPanel::create(); ExampleScrollPanel->setPreferredSize(Vec2f(350,300)); ExampleScrollPanel->setConstraints(SceneTreeConstraints); //ExampleScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); //ExampleScrollPanel->setVerticalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); ExampleScrollPanel->setViewComponent(TheTree); //Details Panel Labels LabelRefPtr NodeNameLabel = Label::create(); NodeNameLabel->setText("Name"); NodeNameLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); NodeNameValueLabel = Label::create(); NodeNameValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRefPtr NodeCoreTypeLabel = Label::create(); NodeCoreTypeLabel->setText("Core Type"); NodeCoreTypeLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); NodeCoreTypeValueLabel = Label::create(); NodeCoreTypeValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRefPtr NodeMinLabel = Label::create(); NodeMinLabel->setText("Min"); NodeMinLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); NodeMinValueLabel = Label::create(); NodeMinValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRefPtr NodeMaxLabel = Label::create(); NodeMaxLabel->setText("Max"); NodeMaxLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); NodeMaxValueLabel = Label::create(); NodeMaxValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRefPtr NodeCenterLabel = Label::create(); NodeCenterLabel->setText("Center"); NodeCenterLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); NodeCenterValueLabel = Label::create(); NodeCenterValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRefPtr NodeTriCountLabel = Label::create(); NodeTriCountLabel->setText("TriCount"); NodeTriCountLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); NodeTriCountValueLabel = Label::create(); NodeTriCountValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRefPtr NodeTravMaskLabel = Label::create(); NodeTravMaskLabel->setText("Traversal Mask"); NodeTravMaskLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); NodeTravMaskValueLabel = Label::create(); NodeTravMaskValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRefPtr NodeOcclusionMaskLabel = Label::create(); NodeOcclusionMaskLabel->setText("Occlusion Mask"); NodeOcclusionMaskLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); NodeOcclusionMaskValueLabel = Label::create(); NodeOcclusionMaskValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRefPtr NodeActiveLabel = Label::create(); NodeActiveLabel->setText("Active"); NodeActiveLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); NodeActiveValueLabel = Label::create(); NodeActiveValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); //Details Panel BorderLayoutConstraintsRefPtr NodeDetailPanelConstraints = OSG::BorderLayoutConstraints::create(); NodeDetailPanelConstraints->setRegion(BorderLayoutConstraints::BORDER_SOUTH); GridLayoutRefPtr NodeDetailPanelLayout = OSG::GridLayout::create(); NodeDetailPanelLayout->setRows(9); NodeDetailPanelLayout->setColumns(2); NodeDetailPanelLayout->setHorizontalGap(2); NodeDetailPanelLayout->setVerticalGap(2); PanelRefPtr NodeDetailPanel = Panel::create(); NodeDetailPanel->setConstraints(NodeDetailPanelConstraints); NodeDetailPanel->setPreferredSize(Vec2f(100.0f, 200.0f)); NodeDetailPanel->setLayout(NodeDetailPanelLayout); NodeDetailPanel->pushToChildren(NodeNameLabel); NodeDetailPanel->pushToChildren(NodeNameValueLabel); NodeDetailPanel->pushToChildren(NodeCoreTypeLabel); NodeDetailPanel->pushToChildren(NodeCoreTypeValueLabel); NodeDetailPanel->pushToChildren(NodeMinLabel); NodeDetailPanel->pushToChildren(NodeMinValueLabel); NodeDetailPanel->pushToChildren(NodeMaxLabel); NodeDetailPanel->pushToChildren(NodeMaxValueLabel); NodeDetailPanel->pushToChildren(NodeCenterLabel); NodeDetailPanel->pushToChildren(NodeCenterValueLabel); NodeDetailPanel->pushToChildren(NodeTriCountLabel); NodeDetailPanel->pushToChildren(NodeTriCountValueLabel); NodeDetailPanel->pushToChildren(NodeTravMaskLabel); NodeDetailPanel->pushToChildren(NodeTravMaskValueLabel); NodeDetailPanel->pushToChildren(NodeOcclusionMaskLabel); NodeDetailPanel->pushToChildren(NodeOcclusionMaskValueLabel); NodeDetailPanel->pushToChildren(NodeActiveLabel); NodeDetailPanel->pushToChildren(NodeActiveValueLabel); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); LayoutRefPtr MainInternalWindowLayout = OSG::BorderLayout::create(); InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleScrollPanel); MainInternalWindow->pushToChildren(NodeDetailPanel); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(NULL); MainInternalWindow->setBorders(NULL); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.0f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(1.0,1.0)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); mgr->setRoot(Root); // Add the UI Foreground Object to the Scene ViewportRefPtr TutorialViewport = mgr->getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); // Show the whole Scene mgr->showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "52SceneGraphTree"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
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) 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(); ButtonRefPtr ExampleButton = OSG::Button::create(); ExampleButton->setMinSize(Vec2f(50, 25)); ExampleButton->setMaxSize(Vec2f(200, 100)); ExampleButton->setPreferredSize(Vec2f(100, 50)); ExampleButton->setText("Button 1"); // Create an ActionListener and assign it to ExampleButton // This Class is defined above, and will cause the output // window to display "Button 1 Action" when pressed ExampleButton->connectActionPerformed(boost::bind(actionPerformed, _1)); //Toggle Button ToggleButtonRefPtr ExampleToggleButton = OSG::ToggleButton::create(); ExampleToggleButton->setSelected(false); ExampleToggleButton->setText("ToggleMe"); //Text Field TextFieldRefPtr ExampleTextField = OSG::TextField::create(); //Password Field PasswordFieldRefPtr ExamplePasswordField = OSG::PasswordField::create(); LayoutRefPtr MainLayout = OSG::FlowLayout::create(); //Panel PanelRecPtr ExamplePanel = Panel::create(); ExamplePanel->setPreferredSize(Vec2f(200.0f,200.0f)); ExamplePanel->setLayout(MainLayout); ExamplePanel->pushToChildren(ExampleTextField); ExamplePanel->pushToChildren(ExamplePasswordField); //Text Field 2 TextFieldRefPtr ExampleTextField2 = OSG::TextField::create(); // 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(ExampleButton); MainInternalWindow->pushToChildren(ExampleToggleButton); MainInternalWindow->pushToChildren(ExamplePanel); MainInternalWindow->pushToChildren(ExampleTextField2); MainInternalWindow->setLayout(MainLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRefPtr 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.5f); TutorialWindow->openWindow(WinPos, WinSize, "54FocusProgession"); commitChanges(); //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 an Button Component and a simple Font. See 17Label_Font for more information about Fonts. ******************************************************/ ButtonRefPtr ExampleButton = OSG::Button::create(); UIFontRefPtr ExampleFont = OSG::UIFont::create(); ExampleFont->setSize(16); ExampleButton->setMinSize(Vec2f(50, 25)); ExampleButton->setMaxSize(Vec2f(200, 100)); ExampleButton->setPreferredSize(Vec2f(100, 50)); ExampleButton->setToolTipText("Button 1 ToolTip"); ExampleButton->setText("Button 1"); ExampleButton->setFont(ExampleFont); ExampleButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); ExampleButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0)); ExampleButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); ExampleButton->setAlignment(Vec2f(1.0,0.0)); /****************************************************** Create a ToggleButton and determine its characteristics. ToggleButton inherits off of Button, so all characteristsics used above can be used with ToggleButtons as well. The only difference is that when pressed, ToggleButton remains pressed until pressed again. -setSelected(bool): Determine whether the ToggleButton is Selected (true) or deselected (false). ******************************************************/ ToggleButtonRefPtr ExampleToggleButton = OSG::ToggleButton::create(); ExampleToggleButton->setSelected(false); ExampleToggleButton->setText("ToggleMe"); ExampleToggleButton->setToolTipText("Toggle Button ToolTip"); // Create Background to be used with the MainInternalWindow ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); // Create The Internal Window InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create(); LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create(); // Assign the Button to the MainInternalWindow so it will be displayed // when the view is rendered. MainInternalWindow->pushToChildren(ExampleButton); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setPosition(Pnt2f(50,50)); MainInternalWindow->setPreferredSize(Vec2f(300,300)); MainInternalWindow->setTitle(std::string("Internal Window 1")); // Create The Internal Window InternalWindowRefPtr MainInternalWindow2 = OSG::InternalWindow::create(); LayoutRefPtr MainInternalWindowLayout2 = OSG::FlowLayout::create(); // Assign the Button to the MainInternalWindow so it will be displayed // when the view is rendered. MainInternalWindow2->pushToChildren(ExampleToggleButton); MainInternalWindow2->setLayout(MainInternalWindowLayout2); MainInternalWindow2->setBackgrounds(MainInternalWindowBackground); MainInternalWindow2->setPosition(Pnt2f(150,150)); MainInternalWindow2->setPreferredSize(Vec2f(300,300)); MainInternalWindow2->setTitle(std::string("Internal Window 2")); MainInternalWindow2->setIconable(false); MainInternalWindow2->setAllwaysOnTop(true); // Create the Drawing Surface UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); TutorialDrawingSurface->openWindow(MainInternalWindow2); // 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, "37InternalWindow"); //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 a simple Font to be used with the TextField UIFontRefPtr sampleFont = OSG::UIFont::create(); sampleFont->setSize(16); /****************************************************** Create and edit the TextField. A TextField is a Component which allows a single line of text to be displayed. Text can be entered via the keyboard, and selected with arrow keys or the Mouse. -setTextColor(Color4f): Determine the Text Color. setSelectionBoxColor(Color4f): Determine the Color of highlighting around selected Text. -setSelectionTextColor(Color4f): Determine the Color of selected Text. -setText("TextToBeDisplayed"): Determine initial Text within TextField. -setFont(FontName): Determine the Font used within TextField. -setSelectionStart(StartCharacterNumber): Determine the character with which the selection will initially start. -setSelectionEnd(EndCharacterNumber): Determine the character which the selection ends before. -setAlignment(float): Determine the alignment of the text. The float is a percentage is from the top of the text [0.0-1.0]. Note: be sure to visually verify this, as due to font size and line size this does not always place it exactly at the percentage point. ******************************************************/ // Create a TextField component TextFieldRefPtr ExampleTextField = OSG::TextField::create(); ExampleTextField->setPreferredSize(Vec2f(100, 50)); ExampleTextField->setTextColor(Color4f(0.0, 0.0, 0.0, 1.0)); ExampleTextField->setSelectionBoxColor(Color4f(0.0, 0.0, 1.0, 1.0)); ExampleTextField->setSelectionTextColor(Color4f(1.0, 1.0, 1.0, 1.0)); ExampleTextField->setText("What"); ExampleTextField->setFont(sampleFont); // The next two functions will select the "a" from above ExampleTextField->setSelectionStart(2); ExampleTextField->setSelectionEnd(3); ExampleTextField->setAlignment(Vec2f(0.0,0.5)); // Create another TextField Component TextFieldRefPtr ExampleTextField2 = OSG::TextField::create(); ExampleTextField2->setText(""); ExampleTextField2->setEmptyDescText("Write in me, please"); ExampleTextField2->setPreferredSize(Vec2f(200.0f,ExampleTextField2->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)); LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create(); InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleTextField); MainInternalWindow->pushToChildren(ExampleTextField2); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); mgr->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRefPtr TutorialViewport = mgr->getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); // Show the whole Scene mgr->showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "16TextField"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
/*-------------------------------------------------------------------------*\ - private - \*-------------------------------------------------------------------------*/ void GenericFieldContainerEditor::updateFieldsPanel(FieldContainer* fc) { _FieldsContainer->clearChildren(); UInt32 NumFields(fc->getType().getNumFieldDescs()); FieldDescriptionBase* Desc; FieldEditorComponentUnrecPtr TheEditor; LabelUnrecPtr TheLabel; ComponentRecPtr TheToolTip; GridBagLayoutConstraintsRefPtr LayoutConstraints; PanelRefPtr FieldPanel; UInt32 NumRows(0),NumRowsForField(1); BorderLayoutRefPtr TheBorderLayout = BorderLayout::create(); BorderLayoutConstraintsRefPtr WestConstraint = BorderLayoutConstraints::create(); WestConstraint->setRegion(BorderLayoutConstraints::BORDER_WEST); BorderLayoutConstraintsRefPtr CenterConstraint = BorderLayoutConstraints::create(); CenterConstraint->setRegion(BorderLayoutConstraints::BORDER_CENTER); //Backgrounds ColorLayerRefPtr HeaderBgLayer = ColorLayer::create(); HeaderBgLayer->setColor(Color4f(0.7f,0.7f,0.7f,1.0f)); ColorLayerRefPtr LightBgLayer = ColorLayer::create(); LightBgLayer->setColor(Color4f(0.9f,0.9f,0.9f,1.0f)); ColorLayerRefPtr DarkBgLayer = ColorLayer::create(); DarkBgLayer->setColor(Color4f(0.8f,0.8f,0.8f,1.0f)); LayoutConstraints = GridBagLayoutConstraints::create(); LayoutConstraints->setGridX(0); LayoutConstraints->setGridY(NumRows); LayoutConstraints->setGridHeight(1); LayoutConstraints->setGridWidth(2); LayoutConstraints->setFill(GridBagLayoutConstraints::FILL_BOTH); LabelRecPtr FieldsLabel = Label::create(); FieldsLabel->setAlignment(Vec2f(0.5f,0.5f)); FieldsLabel->setText("Fields"); FieldsLabel->setBackgrounds(HeaderBgLayer); FieldsLabel->setConstraints(LayoutConstraints); FieldsLabel->setFont(_BoldFont); _FieldsContainer->pushToChildren(FieldsLabel); ++NumRows; if(_GenericNameAttachmentEditor->isTypeEditable(fc->getType())) { //Create the Label TheLabel = Label::create(); TheLabel->setText("Name"); TheLabel->setBackgrounds(NULL); TheLabel->setConstraints(WestConstraint); TheLabel->setPreferredSize(Vec2f(160.0f,22.0f)); //Attach the Generic Name Editor _GenericNameAttachmentEditor->setCommandManager(_CmdManager); _GenericNameAttachmentEditor->attachContainer(fc); _GenericNameAttachmentEditor->setConstraints(CenterConstraint); //Create the Panel LayoutConstraints = GridBagLayoutConstraints::create(); LayoutConstraints->setGridX(0); LayoutConstraints->setGridY(NumRows); LayoutConstraints->setGridHeight(1); LayoutConstraints->setGridWidth(1); LayoutConstraints->setFill(GridBagLayoutConstraints::FILL_BOTH); FieldPanel = Panel::createEmpty(); FieldPanel->setInset(Vec4f(1.0f,1.0f,1.0f,1.0f)); FieldPanel->pushToChildren(TheLabel); FieldPanel->pushToChildren(_GenericNameAttachmentEditor); FieldPanel->setLayout(TheBorderLayout); FieldPanel->setConstraints(LayoutConstraints); FieldPanel->setBackgrounds(LightBgLayer); _FieldsContainer->pushToChildren(FieldPanel); ++NumRows; } UInt32 UsedFieldCount(0); for(UInt32 i(1) ; i<=NumFields ; ++i) { Desc = fc->getFieldDescription(i); if(Desc != NULL && !Desc->isInternal() && Desc->getFieldType().getClass() != FieldType::ParentPtrField && //HACK: Stop the pixel field from being editable on Images !(fc->getType().isDerivedFrom(Image::getClassType()) && Desc->getFieldId() == Image::PixelFieldId)) { //Create the Editor TheEditor = FieldEditorFactory::the()->createDefaultEditor(fc, Desc->getFieldId(), _CmdManager); if(TheEditor != NULL) { NumRowsForField = TheEditor->getNumRequestedRows(); pushToEditors(TheEditor); TheEditor->setConstraints(CenterConstraint); //Create the Label TheLabel = Label::create(); TheLabel->setText(Desc->getCName()); TheLabel->setBackgrounds(NULL); TheLabel->setConstraints(WestConstraint); TheLabel->setPreferredSize(Vec2f(160.0f,22.0f)); TheToolTip = createFieldToolTip(Desc); TheLabel->setToolTip(TheToolTip); //Create the Panel LayoutConstraints = GridBagLayoutConstraints::create(); LayoutConstraints->setGridX(0); LayoutConstraints->setGridY(NumRows); LayoutConstraints->setGridHeight(NumRowsForField); LayoutConstraints->setGridWidth(1); LayoutConstraints->setFill(GridBagLayoutConstraints::FILL_BOTH); FieldPanel = Panel::createEmpty(); FieldPanel->setInset(Vec4f(1.0f,1.0f,1.0f,1.0f)); FieldPanel->pushToChildren(TheLabel); FieldPanel->pushToChildren(TheEditor); FieldPanel->setLayout(TheBorderLayout); FieldPanel->setConstraints(LayoutConstraints); if((UsedFieldCount%2) == 0) { FieldPanel->setBackgrounds(DarkBgLayer); } else { FieldPanel->setBackgrounds(LightBgLayer); } _FieldsContainer->pushToChildren(FieldPanel); NumRows += NumRowsForField; TheEditor->setPreferredSize(Vec2f(50.0f,22.0f * NumRowsForField)); ++UsedFieldCount; } } } //Set the number of rows for the grid layout dynamic_cast<GridBagLayout*>(_FieldsContainer->getLayout())->setRows(NumRows); _FieldsContainer->setPreferredSize(Vec2f(400.0f, NumRows*24.0f)); }
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)); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); // 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 an Button Component and a simple Font. See 17Label_Font for more information about Fonts. ******************************************************/ ButtonRefPtr ExampleButton = OSG::Button::create(); UIFontRefPtr ExampleFont = OSG::UIFont::create(); ExampleFont->setSize(16); /****************************************************** Edit the Button's characteristics. Note: the first 4 functions can be used with any Component and are not specific to Button. -setMinSize(Vec2f): Determine the Minimum Size of the Component. Some Layouts will automatically resize Components; this prevents the Size from going below a certain value. -setMaxSize(Vec2f): Determine the Maximum Size of the Component. -setPreferredSize(Vec2f): Determine the Preferred Size of the Component. This is what the Component will be displayed at unless changed by another Component (such as a Layout). -setToolTipText("Text"): Determine what text is displayed while Mouse is hovering above Component. The word Text will be displayed in this case. Functions specfic to Button: -setText("DesiredText"): Determine the Button's text. It will read DesiredText in this case. -setFont(FontName): Determine the Font to be used on the Button. -setTextColor(Color4f): Determine the Color for the text. -setRolloverTextColor(Color4f): Determine what the text Color will be when the Mouse Cursor is above the Button. -setActiveTextColor(Color4f): Determine what the text Color will be when the Button is pressed (denoted by Active). -setAlignment(Vec2f): Determine the Vertical Alignment of the text. The value is in [0.0, 1.0]. ******************************************************/ ExampleButton->setMinSize(Vec2f(50, 25)); ExampleButton->setMaxSize(Vec2f(200, 100)); ExampleButton->setPreferredSize(Vec2f(100, 50)); ExampleButton->setToolTipText("Button 1 ToolTip"); ExampleButton->setText("Button 1"); ExampleButton->setFont(ExampleFont); ExampleButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); ExampleButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0)); ExampleButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); ExampleButton->setAlignment(Vec2f(1.0,0.0)); // Create an Action and assign it to ExampleButton // This Class is defined above, and will cause the output // window to display "Button 1 Action" when pressed ExampleButton->connectActionPerformed(boost::bind(actionPerformed, _1)); /****************************************************** Create a ToggleButton and determine its characteristics. ToggleButton inherits off of Button, so all characteristsics used above can be used with ToggleButtons as well. The only difference is that when pressed, ToggleButton remains pressed until pressed again. -setSelected(bool): Determine whether the ToggleButton is Selected (true) or deselected (false). ******************************************************/ ToggleButtonRefPtr ExampleToggleButton = OSG::ToggleButton::create(); ExampleToggleButton->setSelected(false); ExampleToggleButton->setText("ToggleMe"); ExampleToggleButton->setToolTipText("Toggle Button ToolTip"); //Button with Image ButtonRefPtr ExampleDrawObjectButton = OSG::Button::create(); ExampleDrawObjectButton->setDrawObjectToTextAlignment(Button::ALIGN_DRAW_OBJECT_RIGHT_OF_TEXT); ExampleDrawObjectButton->setText("Icon"); ExampleDrawObjectButton->setImage(std::string("./Data/Icon.png")); ExampleDrawObjectButton->setActiveImage(std::string("./Data/Icon.png")); ExampleDrawObjectButton->setFocusedImage(std::string("./Data/Icon.png")); ExampleDrawObjectButton->setRolloverImage(std::string("./Data/Icon.png")); ExampleDrawObjectButton->setDisabledImage(std::string("./Data/Icon.png")); // 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(); LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create(); MainInternalWindow->pushToChildren(ExampleButton); MainInternalWindow->pushToChildren(ExampleToggleButton); MainInternalWindow->pushToChildren(ExampleDrawObjectButton); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRefPtr 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(); //Attach key controls //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "01Button"); commitChanges(); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
/*----------------------------- class specific ----------------------------*/ void GenericFieldContainerEditor::onCreate(const GenericFieldContainerEditor *Id) { Inherited::onCreate(Id); if(Id != NULL) { _BoldFont = UIFont::create(); UIFontUnrecPtr ProtoFont(dynamic_cast<Label*>(Label::getClassType().getPrototype())->getFont()); _BoldFont->setFamily(ProtoFont->getFamily()); _BoldFont->setGlyphPixelSize(ProtoFont->getGlyphPixelSize()); _BoldFont->setSize(ProtoFont->getSize()); _BoldFont->setStyle(TextFace::STYLE_BOLD); BorderLayoutConstraintsRefPtr WestConstraint = BorderLayoutConstraints::create(); WestConstraint->setRegion(BorderLayoutConstraints::BORDER_WEST); BorderLayoutConstraintsRefPtr NorthConstraint = BorderLayoutConstraints::create(); NorthConstraint->setRegion(BorderLayoutConstraints::BORDER_NORTH); BorderLayoutConstraintsRefPtr CenterConstraint = BorderLayoutConstraints::create(); CenterConstraint->setRegion(BorderLayoutConstraints::BORDER_CENTER); BorderLayoutConstraintsRefPtr SouthConstraint = BorderLayoutConstraints::create(); SouthConstraint->setRegion(BorderLayoutConstraints::BORDER_SOUTH); //Backgournds ColorLayerRefPtr HeaderBgLayer = ColorLayer::create(); HeaderBgLayer->setColor(Color4f(0.7f,0.7f,0.7f,1.0f)); //Type Panel _ContainerTypeLabel = Label::create(); _ContainerTypeLabel->setAlignment(Vec2f(0.5f,0.5f)); _ContainerTypeLabel->setBackgrounds(HeaderBgLayer); _ContainerTypeLabel->setConstraints(WestConstraint); _ContainerTypeLabel->setPreferredSize(Vec2f(160.0f,22.0f)); _ContainerIdLabel = Label::create(); _ContainerIdLabel->setAlignment(Vec2f(0.5f,0.5f)); _ContainerIdLabel->setBackgrounds(HeaderBgLayer); _ContainerIdLabel->setConstraints(CenterConstraint); BorderLayoutRefPtr TheBorderLayout = BorderLayout::create(); PanelRefPtr TypePanel = Panel::createEmpty(); TypePanel->setPreferredSize(Vec2f(160.0f,33.0f)); TypePanel->setInset(Vec4f(1.0f,1.0f,1.0f,10.0f)); TypePanel->pushToChildren(_ContainerIdLabel); TypePanel->pushToChildren(_ContainerTypeLabel); TypePanel->setLayout(TheBorderLayout); TypePanel->setConstraints(NorthConstraint); pushToChildren(TypePanel); //Fields Panel GridBagLayoutRecPtr AllFieldsPanelLayout = GridBagLayout::create(); AllFieldsPanelLayout->setColumns(1); _FieldsContainer = Panel::createEmpty(); _FieldsContainer->setConstraints(CenterConstraint); _FieldsContainer->setLayout(AllFieldsPanelLayout); if(getShowFields()) { pushToChildren(_FieldsContainer); } //Events Panel GridLayoutRecPtr AllProducedEventsPanelLayout = GridLayout::create(); AllProducedEventsPanelLayout->setColumns(1); AllProducedEventsPanelLayout->setHorizontalGap(0.0f); AllProducedEventsPanelLayout->setVerticalGap(0.0f); _ProducedEventsContainer = Panel::createEmpty(); _ProducedEventsContainer->setConstraints(SouthConstraint); _ProducedEventsContainer->setLayout(AllProducedEventsPanelLayout); _ProducedEventsContainer->setInset(Vec4f(0.0f,0.0f,15.0f,0.0f)); if(getShowEvents()) { pushToChildren(_ProducedEventsContainer); } //Main Layout BorderLayoutRefPtr MainLayout = BorderLayout::create(); setLayout(MainLayout); _GenericNameAttachmentEditor = GenericNameAttachmentEditor::create(); } }
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 BorderLayout and some BorderLayoutConstraints to be used to set up CardLayout. ******************************************************/ BorderLayoutRefPtr MainInternalWindowLayout = OSG::BorderLayout::create(); BorderLayoutConstraintsRefPtr ExampleButton1Constraints = OSG::BorderLayoutConstraints::create(); BorderLayoutConstraintsRefPtr ExampleButton2Constraints = OSG::BorderLayoutConstraints::create(); BorderLayoutConstraintsRefPtr ExampleButton7Constraints = OSG::BorderLayoutConstraints::create(); BorderLayoutConstraintsRefPtr ExampleButton8Constraints = OSG::BorderLayoutConstraints::create(); BorderLayoutConstraintsRefPtr ExampleCardPanelConstraints = OSG::BorderLayoutConstraints::create(); ExampleButton1Constraints->setRegion(BorderLayoutConstraints::BORDER_EAST); ExampleButton2Constraints->setRegion(BorderLayoutConstraints::BORDER_WEST); ExampleButton7Constraints->setRegion(BorderLayoutConstraints::BORDER_NORTH); ExampleButton8Constraints->setRegion(BorderLayoutConstraints::BORDER_SOUTH); ExampleCardPanelConstraints->setRegion(BorderLayoutConstraints::BORDER_CENTER); /****************************************************** Create CardLayout. CardLayout shows a single Component at a time, meaning it is not exactly practical to use it alone for a Layout. This tutorial uses the BorderLayout to include a Panel in the Center Region, and within that Panel using a CardLayout. A single card is displayed at one time within a ComponentContainer using CardLayout. CardLayout has four functions: next, previous, first, and last. ->next(CardContainerName): Causes CardLayout to display the next card. ->previous(CardContainerName): Causes CardLayout to display the previous card. ->first(CardContainerName): Causes CardLayout to display the first card. ->last(CardContainerName): Causes CardLayout to display the last card. These are most useful when combined with ActionListeners, as shown at the top of this Tutorial, to assign actions to the Buttons or Components to allow the user to cycle through the Card Layout and view different ExampleCards. Note that CardContainerName is the name of the ComponentContainer which is using the CardLayout, while the begin/endEditCP is performed on the CardLayout itself. ******************************************************/ ExampleCardLayout = OSG::CardLayout::create(); ExampleCardPanel = OSG::Panel::create(); /****************************************************** Create Button Components to be used with CardLayout to allow for interactivity. ******************************************************/ 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(); ExampleButton1->setText("Next Card"); ExampleButton1->setConstraints(ExampleButton1Constraints); // Add ActionListener NextCardActionListener TheNextCardActionListener; ExampleButton1->addActionListener( &TheNextCardActionListener); ExampleButton2->setText("Previous Card"); ExampleButton2->setConstraints(ExampleButton2Constraints); // Add ActionListener BackCardActionListener TheBackCardActionListener; ExampleButton2->addActionListener( &TheBackCardActionListener); ExampleButton3->setText("This"); ExampleButton4->setText("is"); ExampleButton5->setText("Card"); ExampleButton6->setText("Layout"); ExampleButton7->setText("First Card"); ExampleButton7->setConstraints(ExampleButton7Constraints); // Add ActionListener FirstCardActionListener TheFirstCardActionListener; ExampleButton7->addActionListener( &TheFirstCardActionListener); ExampleButton8->setText("Last Card"); ExampleButton8->setConstraints(ExampleButton8Constraints); // Add ActionListener LastCardActionListener TheLastCardActionListener; ExampleButton8->addActionListener( &TheLastCardActionListener); ExampleCardPanel->setLayout(ExampleCardLayout); ExampleCardPanel->pushToChildren(ExampleButton3); ExampleCardPanel->pushToChildren(ExampleButton4); ExampleCardPanel->pushToChildren(ExampleButton5); ExampleCardPanel->pushToChildren(ExampleButton6); ExampleCardPanel->setConstraints(ExampleCardPanelConstraints); // 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(ExampleButton7); MainInternalWindow->pushToChildren(ExampleButton8); MainInternalWindow->pushToChildren(ExampleCardPanel); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); mgr->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRefPtr TutorialViewport = mgr->getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); // Show the whole Scene mgr->showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "11CardLayout"); //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(); //Background TutorialBackground = GradientBackground::create(); TutorialBackground->addLine(Color3f(1.0,0.0,0.0), 0.0); TutorialBackground->addLine(Color3f(0.0,1.0,0.0), 0.2); TutorialBackground->addLine(Color3f(0.0,0.0,1.0), 0.4); TutorialBackground->addLine(Color3f(0.0,1.0,1.0), 0.6); TutorialBackground->addLine(Color3f(1.0,1.0,0.0), 0.8); TutorialBackground->addLine(Color3f(1.0,1.0,1.0), 1.0); TheUndoManager = UndoManager::create(); UndoManagerChangeListener TheUndoManagerChangeListener; TheUndoManager->addChangeListener(&TheUndoManagerChangeListener); LabelRefPtr SingleFieldLabel = OSG::Label::create(); SingleFieldLabel->setText("Single Field"); SingleFieldLabel->setBorders(NULL); SingleFieldLabel->setBackgrounds(NULL); LabelRefPtr MultiFieldLabel = OSG::Label::create(); MultiFieldLabel->setText("Multi Field"); MultiFieldLabel->setBorders(NULL); MultiFieldLabel->setBackgrounds(NULL); LabelRefPtr SinglePtrFieldLabel = OSG::Label::create(); SinglePtrFieldLabel->setText("Single Ptr Field"); SinglePtrFieldLabel->setBorders(NULL); SinglePtrFieldLabel->setBackgrounds(NULL); LabelRefPtr MultiPtrFieldLabel = OSG::Label::create(); MultiPtrFieldLabel->setText("Multi Ptr Field"); MultiPtrFieldLabel->setBorders(NULL); MultiPtrFieldLabel->setBackgrounds(NULL); TabPanelRefPtr ExampleTabPanel = OSG::TabPanel::create(); ExampleTabPanel->setPreferredSize(Vec2f(600,600)); ExampleTabPanel->addTab(SingleFieldLabel, createSingleFieldPanel()); ExampleTabPanel->addTab(MultiFieldLabel, createMultiFieldPanel()); ExampleTabPanel->addTab(SinglePtrFieldLabel, createSinglePtrFieldPanel()); ExampleTabPanel->addTab(MultiPtrFieldLabel, createMultiPtrFieldPanel()); ExampleTabPanel->setTabAlignment(0.5f); ExampleTabPanel->setTabPlacement(TabPanel::PLACEMENT_NORTH); ExampleTabPanel->setSelectedIndex(0); //UndoList UndoRedoListModel = DefaultListModel::create(); UndoRedoListModel->pushBack(boost::any(std::string("Top"))); ListSelectionModelPtr UndoRedoListSelectionModel(new DefaultListSelectionModel()); UndoRedoList = List::create(); UndoRedoList->setPreferredSize(Vec2f(200, 300)); UndoRedoList->setOrientation(List::VERTICAL_ORIENTATION); UndoRedoList->setModel(UndoRedoListModel); UndoRedoList->setSelectionModel(UndoRedoListSelectionModel); UndoRedoListListener TheUndoRedoListListener; UndoRedoList->getSelectionModel()->addListSelectionListener(&TheUndoRedoListListener); UndoButton = OSG::Button::create(); UndoButton->setText("Undo"); UndoButton->setEnabled(TheUndoManager->numberOfUndos() != 0); UndoButtonActionListener TheUndoButtonActionListener; UndoButton->addActionListener(&TheUndoButtonActionListener); RedoButton = OSG::Button::create(); RedoButton->setText("Redo"); RedoButton->setEnabled(TheUndoManager->numberOfRedos() != 0); RedoButtonActionListener TheRedoButtonActionListener; RedoButton->addActionListener(&TheRedoButtonActionListener); // Create a ScrollPanel for easier viewing of the List (see 27ScrollPanel) ScrollPanelRefPtr 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 ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create(); LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create(); MainInternalWindow->pushToChildren(ExampleTabPanel); 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); // 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(TutorialBackground); // 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, "01ChangeFieldCommands"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
virtual void redo(void) { Inherited::redo(); _TheBackground->setColor(_ChangeToColor); }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { TheLuaManager->init(); // 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); //Setup the Lua Manager BoostPath ModulePath("./Data/"); std::string PackagePath = std::string("?;") + (ModulePath / "?.lua" ).file_string() + ";" + (ModulePath / "?" / "init.lua").file_string(); TheLuaManager->setPackagePath(PackagePath); // Make Torus Node (creates Torus in background of scene) GeometryRefPtr TorusGeometry = makeTorusGeo(.5, 2, 16, 16); setName(TorusGeometry,"Torus Geometry"); //calcVertexTangents(TorusGeometry,0,Geometry::TexCoords7FieldId, Geometry::TexCoords6FieldId); NodeRefPtr TorusGeometryNode = Node::create(); setName(TorusGeometryNode,"Torus Geometry Node"); TorusGeometryNode->setCore(TorusGeometry); //Torus Transformation Node TransformRefPtr TheTorusNodeTransform = Transform::create(); NodeRefPtr TheTorusTransfromNode = Node::create(); TheTorusTransfromNode->setCore(TheTorusNodeTransform); TheTorusTransfromNode->addChild(TorusGeometryNode); setName(TheTorusTransfromNode,"Torus Transform Node"); // Make Main Scene Node and add the Torus NodeRefPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(TheTorusTransfromNode); setName(scene,"Scene Node"); //Light Beacon Node TransformRefPtr TheLightBeaconNodeTransform = Transform::create(); NodeRefPtr TheLightBeaconNode = Node::create(); TheLightBeaconNode->setCore(TheLightBeaconNodeTransform); setName(TheLightBeaconNode,"Light Beacon Node"); //Light Node DirectionalLightRefPtr TheLightCore = DirectionalLight::create(); TheLightCore->setDirection(Vec3f(1.0,0.0,0.0)); TheLightCore->setAmbient(Color4f(1.0,1.0,1.0,1.0)); TheLightCore->setDiffuse(Color4f(1.0,1.0,1.0,1.0)); TheLightCore->setSpecular(Color4f(1.0,1.0,1.0,1.0)); TheLightCore->setBeacon(TheLightBeaconNode); NodeRefPtr TheLightNode = Node::create(); TheLightNode->setCore(TheLightCore); TheLightNode->addChild(scene); setName(TheLightNode,"Light Node"); NodeRefPtr RootNode = Node::create(); RootNode->setCore(Group::create()); RootNode->addChild(TheLightNode); RootNode->addChild(TheLightBeaconNode); setName(RootNode,"Root Node"); // Create the Graphics GraphicsRefPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); //Create the Main interface LuaDebuggerInterface TheLuaDebuggerInterface; // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRefPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); BorderLayoutRefPtr MainInternalWindowLayout = BorderLayout::create(); //Split Panel BorderLayoutConstraintsRefPtr SplitPanelConstraints = BorderLayoutConstraints::create(); SplitPanelConstraints->setRegion(BorderLayoutConstraints::BORDER_CENTER); TheLuaDebuggerInterface.getMainSplitPanel()->setConstraints(SplitPanelConstraints); BorderLayoutConstraintsRefPtr ButtonPanelConstraints = BorderLayoutConstraints::create(); ButtonPanelConstraints->setRegion(BorderLayoutConstraints::BORDER_NORTH); TheLuaDebuggerInterface.getButtonPanel()->setConstraints(ButtonPanelConstraints); BorderLayoutConstraintsRefPtr CodeAreaInfoPanelConstraints = BorderLayoutConstraints::create(); CodeAreaInfoPanelConstraints->setRegion(BorderLayoutConstraints::BORDER_SOUTH); TheLuaDebuggerInterface.getCodeAreaInfoPanel()->setConstraints(CodeAreaInfoPanelConstraints); InternalWindowRefPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(TheLuaDebuggerInterface.getButtonPanel()); MainInternalWindow->pushToChildren(TheLuaDebuggerInterface.getMainSplitPanel()); MainInternalWindow->pushToChildren(TheLuaDebuggerInterface.getCodeAreaInfoPanel()); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setTitle("Lua Debugger"); setName(MainInternalWindow,"Internal Window"); // Create the Drawing Surface UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRefPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); //Scene Background GradientBackgroundRefPtr SceneBackground = GradientBackground::create(); SceneBackground->addLine(Color3f(0.0,0.0,0.0),0.0); setName(SceneBackground,"Scene Background"); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); sceneManager.setRoot(RootNode); //sceneManager.setHeadlight(false); // Add the UI Foreground Object to the Scene ViewportRefPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); TutorialViewport->setBackground(SceneBackground); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, &TheLuaDebuggerInterface)); // 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, "03LuaDebugger"); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setPreferredSize(WinSize * 0.85); //Enter main Loop TutorialWindow->mainLoop(); TheLuaManager->uninit(); } osgExit(); return 0; }
virtual void undo(void) { Inherited::undo(); _TheBackground->setColor(_PreviousColor); }
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 a simple Font to be used with the ExampleTextArea UIFontRefPtr ExampleFont = OSG::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 TextAreaRefPtr ExampleTextArea = OSG::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 ScrollPanelRefPtr 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 ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create(); InternalWindowRefPtr MainInternalWindow = OSG::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 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, "22TextArea"); //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 some 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 two Panels to be used with SplitPanel. ******************************************************/ PanelRefPtr ExampleSplitPanelPanel1 = OSG::Panel::create(); PanelRefPtr ExampleSplitPanelPanel2 = OSG::Panel::create(); FlowLayoutRefPtr PanelFlowLayout = OSG::FlowLayout::create(); PanelFlowLayout->setHorizontalGap(3); PanelFlowLayout->setVerticalGap(3); ExampleSplitPanelPanel1->pushToChildren(ExampleButton1); ExampleSplitPanelPanel1->pushToChildren(ExampleButton2); ExampleSplitPanelPanel1->pushToChildren(ExampleButton3); ExampleSplitPanelPanel1->setLayout(PanelFlowLayout); ExampleSplitPanelPanel2->pushToChildren(ExampleButton4); ExampleSplitPanelPanel2->pushToChildren(ExampleButton5); ExampleSplitPanelPanel2->pushToChildren(ExampleButton6); ExampleSplitPanelPanel2->setLayout(PanelFlowLayout); // Creates a BorderLayout and Constraints (causing the SplitPanel // to automatically fill entire center Frame) BorderLayoutRefPtr MainInternalWindowLayout = OSG::BorderLayout::create(); BorderLayoutConstraintsRefPtr ExampleSplitPanelConstraints = OSG::BorderLayoutConstraints::create(); ExampleSplitPanelConstraints->setRegion(BorderLayoutConstraints::BORDER_CENTER); /****************************************************** Creates and sets up SplitPanel -setMinComponent/setMaxComponent(Component): Add up to two Components to the SplitPanel. Note that if you do not add both an empty Panel will be added automatically. -setOrientation(ENUM): Determines the alignment of the split aspect. The default is Horizontal with an east/west split. The minComponent set previously is the west or north Component of the Panel (depending on the alignment) and the max is the east or west Component. Takes VERTICAL_ORIENTATION and HORIZONTAL_ORIENTATION arguments. -setDividerPosition("smart" REAL): Determines the initial location of the divider. Note that this REAL is a percentage if between 0.0 and 1.0 (inclusive) and absolute is greater than 1.0. Also note that when resizing a window with a percentage, the divider will move, but with absolute, it does not until it no longer fits in the panel. -setDividerSize(SIZE): Determine divider Size in pixels. -setExpandable(bool): Determine whether divider can be moved by user. Default is TRUE (is movable) while FALSE removes the users ability to move the divider. -setMaxDividerPosition("smart" REAL): Determine the Maximum position for the divider. -setMinDividerPosition("smart" REAL): Determine the Minimum position for the divider. Note that for both Max/Min, the "smart" REAL follows same format as in setDividerPosition; it is a percentage if between 0.0 and 1.0 and absolute when > 1.0 ******************************************************/ SplitPanelRefPtr ExampleSplitPanel = OSG::SplitPanel::create(); ExampleSplitPanel->setConstraints(ExampleSplitPanelConstraints); ExampleSplitPanel->setMinComponent(ExampleSplitPanelPanel1); ExampleSplitPanel->setMaxComponent(ExampleSplitPanelPanel2); // ExampleSplitPanel->setOrientation(SplitPanel::VERTICAL_ORIENTATION); // ExampleSplitPanel->setDividerPosition(.25); // this is a percentage ExampleSplitPanel->setDividerPosition(300); // this is an absolute (300 > 1.0) // location from the left/top ExampleSplitPanel->setDividerSize(5); // ExampleSplitPanel->setExpandable(false); ExampleSplitPanel->setMaxDividerPosition(.9); ExampleSplitPanel->setMinDividerPosition(220); // also, if you want to change the way the divider looks, you can always set a // DrawObjectCanvas in place of the default divider // ExampleSplitPanel->setDividerDrawObject(drawObjectName); // 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(ExampleSplitPanel); 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 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, "23SplitPanel"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }