int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
// Create the SimpleSceneManager helper
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1));
// Make Torus Node (creates Torus in background of scene)
NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);
// Make Main Scene Node and add the Torus
NodeRecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(TorusGeometryNode);
// Create the Graphics
GraphicsRecPtr TutorialGraphics = Graphics2D::create();
// Initialize the LookAndFeelManager to enable default settings
LookAndFeelManager::the()->getLookAndFeel()->init();
ColorChooserRecPtr TheColorChooser = ColorChooser::create();
TheColorChooser->setColor(Color4f(1.0f,0.0f,0.0f,1.0f));
// Create Background to be used with the MainInternalWindow
ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create();
MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
// Create The Internal Window
InternalWindowRecPtr MainInternalWindow = InternalWindow::create();
LayoutRecPtr MainInternalWindowLayout = FlowLayout::create();
// Assign the Button to the MainInternalWindow so it will be displayed
// when the view is rendered.
MainInternalWindow->pushToChildren(TheColorChooser);
MainInternalWindow->setLayout(MainInternalWindowLayout);
MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
MainInternalWindow->setPosition(Pnt2f(50,50));
MainInternalWindow->setPreferredSize(Vec2f(400,400));
MainInternalWindow->setTitle(std::string("Internal Window"));
// Create the Drawing Surface
UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create();
TutorialDrawingSurface->setGraphics(TutorialGraphics);
TutorialDrawingSurface->setEventProducer(TutorialWindow);
TutorialDrawingSurface->openWindow(MainInternalWindow);
// Create the UI Foreground Object
UIForegroundRecPtr TutorialUIForeground = UIForeground::create();
TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);
sceneManager.setRoot(scene);
// Add the UI Foreground Object to the Scene
ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0);
TutorialViewport->addForeground(TutorialUIForeground);
//Create the Documentation Foreground and add it to the viewport
SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);
// Show the whole Scene
sceneManager.showAll();
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"39ColorChooser");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
//.........这里部分代码省略.........
use the same Model), using each
will cause them to move at different
speeds due to these settings being
different.
******************************************************/
// Create a DefaultBoundedRangeModel
DefaultBoundedRangeModelRecPtr TheBoundedRangeModel = DefaultBoundedRangeModel::create();
TheBoundedRangeModel->setMinimum(10);
TheBoundedRangeModel->setMaximum(100);
TheBoundedRangeModel->setValue(10);
TheBoundedRangeModel->setExtent(20);
ScrollBarRecPtr ExampleVerticalScrollBar = ScrollBar::create();
//ExampleScrollPanel->getHorizontalScrollBar()
ExampleVerticalScrollBar->setOrientation(ScrollBar::VERTICAL_ORIENTATION);
ExampleVerticalScrollBar->setPreferredSize(Vec2f(20,200));
ExampleVerticalScrollBar->setEnabled(false);
ExampleVerticalScrollBar->setUnitIncrement(10);
ExampleVerticalScrollBar->setBlockIncrement(100);
ExampleVerticalScrollBar->setRangeModel(TheBoundedRangeModel);
ScrollBarRecPtr ExampleHorizontalScrollBar = ScrollBar::create();
ExampleHorizontalScrollBar->setOrientation(ScrollBar::HORIZONTAL_ORIENTATION);
ExampleHorizontalScrollBar->setPreferredSize(Vec2f(400,20));
ExampleHorizontalScrollBar->setRangeModel(TheBoundedRangeModel);
// Creates another DefaultBoundedRangeModel to use
// for separating the two ScrollBars from each other.
// Make sure to comment out the addition of the
// previous setModel above.
/*
DefaultBoundedRangeModel TheBoundedRangeModel2;
TheBoundedRangeModel2.setMinimum(0);
TheBoundedRangeModel2.setMaximum(100);
TheBoundedRangeModel2.setValue(10);
TheBoundedRangeModel2.setExtent(20);
ExampleHorizontalScrollBar->setModel(&TheBoundedRangeModel2);
*/
// Create The Main InternalWindow
// Create Background to be used with the Main InternalWindow
ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create();
MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
LayoutRecPtr MainInternalWindowLayout = FlowLayout::create();
InternalWindowRecPtr MainInternalWindow = InternalWindow::create();
MainInternalWindow->pushToChildren(ExampleHorizontalScrollBar);
MainInternalWindow->pushToChildren(ExampleVerticalScrollBar);
MainInternalWindow->pushToChildren(ExampleScrollPanel);
MainInternalWindow->setLayout(MainInternalWindowLayout);
MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f));
MainInternalWindow->setDrawTitlebar(false);
MainInternalWindow->setResizable(false);
// Create the Drawing Surface
UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create();
TutorialDrawingSurface->setGraphics(TutorialGraphics);
TutorialDrawingSurface->setEventProducer(TutorialWindow);
TutorialDrawingSurface->openWindow(MainInternalWindow);
// Create the UI Foreground Object
UIForegroundRecPtr TutorialUIForeground = UIForeground::create();
TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);
// Tell the Manager what to manage
sceneManager.setRoot(scene);
// Add the UI Foreground Object to the Scene
ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0);
TutorialViewport->addForeground(TutorialUIForeground);
// Show the whole Scene
sceneManager.showAll();
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"27ScrollPanel");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
//.........这里部分代码省略.........
RadioButtonRecPtr ExampleRadioButton1 = RadioButton::create();
RadioButtonRecPtr ExampleRadioButton2 = RadioButton::create();
RadioButtonRecPtr ExampleRadioButton3 = RadioButton::create();
ExampleRadioButton1->setAlignment(Vec2f(0.0,0.5));
ExampleRadioButton1->setPreferredSize(Vec2f(100, 50));
ExampleRadioButton1->setText("Option 1");
ExampleRadioButton2->setAlignment(Vec2f(0.0,0.5));
ExampleRadioButton2->setPreferredSize(Vec2f(100, 50));
ExampleRadioButton2->setText("Option 2");
ExampleRadioButton3->setAlignment(Vec2f(0.0,0.5));
ExampleRadioButton3->setPreferredSize(Vec2f(100, 50));
ExampleRadioButton3->setText("Option 3");
/***************************************************
Create and populate a group of RadioButtons.
Defining the group allows you to pick which
RadioButtons are tied together so that only one
can be selected.
Each RadioButtonGroup can only have ONE
RadioButton selected at a time, and by
selecting this RadioButton, will deselect
all other RadioButtons in the RadioButtonGroup.
******************************************************/
RadioButtonGroupRecPtr ExampleRadioButtonGroup = RadioButtonGroup::create();
ExampleRadioButtonGroup->addButton(ExampleRadioButton1);
ExampleRadioButtonGroup->addButton(ExampleRadioButton2);
ExampleRadioButtonGroup->addButton(ExampleRadioButton3);
ExampleRadioButtonGroup->setSelectedButton(ExampleRadioButton2);
FlowLayoutRecPtr MainInternalWindowLayout = FlowLayout::create();
MainInternalWindowLayout->setOrientation(FlowLayout::VERTICAL_ORIENTATION);
MainInternalWindowLayout->setMajorAxisAlignment(0.5f);
MainInternalWindowLayout->setMinorAxisAlignment(0.5f);
// Create The Main InternalWindow
// Create Background to be used with the Main InternalWindow
ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create();
MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
InternalWindowRecPtr MainInternalWindow = InternalWindow::create();
MainInternalWindow->pushToChildren(ExampleRadioButton1);
MainInternalWindow->pushToChildren(ExampleRadioButton2);
MainInternalWindow->pushToChildren(ExampleRadioButton3);
MainInternalWindow->setLayout(MainInternalWindowLayout);
MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f));
MainInternalWindow->setDrawTitlebar(false);
MainInternalWindow->setResizable(false);
// Create the Drawing Surface
UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create();
TutorialDrawingSurface->setGraphics(TutorialGraphics);
TutorialDrawingSurface->setEventProducer(TutorialWindow);
TutorialDrawingSurface->openWindow(MainInternalWindow);
// Create the UI Foreground Object
UIForegroundRecPtr TutorialUIForeground = UIForeground::create();
TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);
// Tell the Manager what to manage
sceneManager->setRoot(scene);
// Add the UI Foreground Object to the Scene
ViewportRecPtr TutorialViewport = sceneManager->getWindow()->getPort(0);
TutorialViewport->addForeground(TutorialUIForeground);
//Create the Documentation Foreground and add it to the viewport
SimpleScreenDoc TheSimpleScreenDoc(sceneManager, TutorialWindow);
// Show the whole Scene
sceneManager->showAll();
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"14RadioButton");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
//.........这里部分代码省略.........
-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
TextFieldRecPtr ExampleTextField = 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
TextFieldRecPtr ExampleTextField2 = 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
ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create();
MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
LayoutRecPtr MainInternalWindowLayout = FlowLayout::create();
InternalWindowRecPtr MainInternalWindow = InternalWindow::create();
MainInternalWindow->pushToChildren(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
UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create();
TutorialDrawingSurface->setGraphics(TutorialGraphics);
TutorialDrawingSurface->setEventProducer(TutorialWindow);
TutorialDrawingSurface->openWindow(MainInternalWindow);
// Create the UI Foreground Object
UIForegroundRecPtr TutorialUIForeground = UIForeground::create();
TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);
// Tell the Manager what to manage
sceneManager.setRoot(scene);
// Add the UI Foreground Object to the Scene
ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0);
TutorialViewport->addForeground(TutorialUIForeground);
// Show the whole Scene
sceneManager.showAll();
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"16TextField");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
// Create the SimpleSceneManager helper
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1));
// Make Torus Node (creates Torus in background of scene)
NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);
// Make Main Scene Node and add the Torus
NodeRecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(TorusGeometryNode);
// Create the Graphics
GraphicsRecPtr TutorialGraphics = Graphics2D::create();
// Initialize the LookAndFeelManager to enable default settings
LookAndFeelManager::the()->getLookAndFeel()->init();
// Create a simple Font to be used with the PasswordField
UIFontRecPtr ExampleFont = UIFont::create();
ExampleFont->setSize(16);
/******************************************************
Create and edit a PasswordField.
A PasswordField is a TextField
which allows for text to be
entered secretly.
-setEchoCar("char"): Determine
which character replaces text in the
PasswordField.
See 16TextField for more information.
******************************************************/
TextFieldRecPtr ExampleTextField = TextField::create();
ExampleTextField->setText("");
ExampleTextField->setEmptyDescText("username");
ExampleTextField->setPreferredSize(Vec2f(130.0f,ExampleTextField->getPreferredSize().y()));
PasswordFieldRecPtr ExamplePasswordField = PasswordField::create();
ExamplePasswordField->setPreferredSize(Vec2f(130, ExamplePasswordField->getPreferredSize().y()));
ExamplePasswordField->setTextColor(Color4f(0.0, 0.0, 0.0, 1.0));
ExamplePasswordField->setSelectionBoxColor(Color4f(0.0, 0.0, 1.0, 1.0));
ExamplePasswordField->setSelectionTextColor(Color4f(1.0, 1.0, 1.0, 1.0));
//ExamplePasswordField->setText("Text");
// "Text" will be replaced by "####" in the PasswordField
ExamplePasswordField->setEchoChar("#");
ExamplePasswordField->setEditable(true);
ExamplePasswordField->setFont(ExampleFont);
ExamplePasswordField->setSelectionStart(2);
ExamplePasswordField->setSelectionEnd(3);
ExamplePasswordField->setAlignment(Vec2f(0.0,0.5));
ExamplePasswordField->setEmptyDescText("password");
// Create The Main InternalWindow
// Create Background to be used with the Main InternalWindow
ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create();
MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
FlowLayoutRecPtr MainInternalWindowLayout = FlowLayout::create();
MainInternalWindowLayout->setOrientation(FlowLayout::VERTICAL_ORIENTATION);
InternalWindowRecPtr MainInternalWindow = InternalWindow::create();
MainInternalWindow->pushToChildren(ExampleTextField);
MainInternalWindow->pushToChildren(ExamplePasswordField);
MainInternalWindow->setLayout(MainInternalWindowLayout);
MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f));
MainInternalWindow->setDrawTitlebar(false);
MainInternalWindow->setResizable(false);
// Create the Drawing Surface
UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create();
TutorialDrawingSurface->setGraphics(TutorialGraphics);
TutorialDrawingSurface->setEventProducer(TutorialWindow);
//.........这里部分代码省略.........
//.........这里部分代码省略.........
Int32SpinnerModelPtr TheModel(new Int32SpinnerModel());
TheModel->setMaximum(100);
TheModel->setMinimum(-100);
TheModel->setStepSize(1);
TheModel->setValue(boost::any(Int32(0)));
/******************************************************
Create a Spinner and and assign it a
Model.
******************************************************/
SpinnerRecPtr ExampleSpinner = Spinner::create();
ExampleSpinner->setModel(TheModel);
/******************************************************
Create a RadioButtonPanel to allow
for certain characteristics of the
Spinner to be changed dynamically.
See 14RadioButton for more
information about RadioButtons.
******************************************************/
RadioButtonRecPtr SingleIncrementButton = RadioButton::create();
RadioButtonRecPtr DoubleIncrementButton = RadioButton::create();
SingleIncrementButton->setText("Increment by 1");
SingleIncrementButton->setPreferredSize(Vec2f(100, 50));
SingleIncrementButton->connectButtonSelected(boost::bind(handleSingleIncbuttonSelected, _1,
TheModel));
DoubleIncrementButton->setText("Increment by 2");
DoubleIncrementButton->setPreferredSize(Vec2f(100, 50));
DoubleIncrementButton->connectButtonSelected(boost::bind(handleDoubleIncbuttonSelected, _1,
TheModel));
RadioButtonGroupRecPtr SelectionRadioButtonGroup = RadioButtonGroup::create();
SelectionRadioButtonGroup->addButton(SingleIncrementButton);
SelectionRadioButtonGroup->addButton(DoubleIncrementButton);
SingleIncrementButton->setSelected(true);
// Create The Main InternalWindow
// Create Background to be used with the Main InternalWindow
ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create();
MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
LayoutRecPtr MainInternalWindowLayout = FlowLayout::create();
InternalWindowRecPtr MainInternalWindow = InternalWindow::create();
MainInternalWindow->pushToChildren(SingleIncrementButton);
MainInternalWindow->pushToChildren(DoubleIncrementButton);
MainInternalWindow->pushToChildren(ExampleSpinner);
MainInternalWindow->setLayout(MainInternalWindowLayout);
MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f));
MainInternalWindow->setDrawTitlebar(false);
MainInternalWindow->setResizable(false);
// Create the Drawing Surface
UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create();
TutorialDrawingSurface->setGraphics(TutorialGraphics);
TutorialDrawingSurface->setEventProducer(TutorialWindow);
TutorialDrawingSurface->openWindow(MainInternalWindow);
// Create the UI Foreground Object
UIForegroundRecPtr TutorialUIForeground = UIForeground::create();
TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);
// Tell the Manager what to manage
sceneManager.setRoot(scene);
// Add the UI Foreground Object to the Scene
ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0);
TutorialViewport->addForeground(TutorialUIForeground);
// Show the whole Scene
sceneManager.showAll();
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"29Spinner");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
// Initialize WIN32 & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
// Create the SimpleSceneManager helper
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1));
// Make Torus Node (creates Torus in background of scene)
NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);
// Make Main Scene Node and add the Torus
NodeRecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(TorusGeometryNode);
// Create the Graphics
GraphicsRecPtr graphics = Graphics2D::create();
// Initialize the LookAndFeelManager to enable default settings
LookAndFeelManager::the()->getLookAndFeel()->init();
/******************************************************
Create the DerivedFieldContainerComboBoxModel and
add Elements to it (derived FieldContainerTypes
). These will be the data
values shown in the ComboBox.
******************************************************/
DerivedFieldContainerComboBoxModelRecPtr ExampleComboBoxModel = DerivedFieldContainerComboBoxModel::create();
ExampleComboBoxModel->editMFDerivedFieldContainerTypes()->push_back(std::string(Component::getClassType().getCName()));
/******************************************************
Create an editable ComboBox. A ComboBox
has a Model just like various other
Components.
******************************************************/
//Create the ComboBox
ComboBoxRecPtr ExampleUneditableComboBox = ComboBox::create();
// Set it to be uneditable
ExampleUneditableComboBox->setEditable(false);
ExampleUneditableComboBox->setModel(ExampleComboBoxModel);
ExampleUneditableComboBox->setSelectedIndex(0);
ExampleUneditableComboBox->setPreferredSize(Vec2f(160.0f,ExampleUneditableComboBox->getPreferredSize().y()));
// Create The Main InternalWindow
// Create Background to be used with the Main InternalWindow
ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create();
MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
FlowLayoutRecPtr MainInternalWindowLayout = FlowLayout::create();
MainInternalWindowLayout->setMinorAxisAlignment(0.2f);
InternalWindowRecPtr MainInternalWindow = InternalWindow::create();
MainInternalWindow->pushToChildren(ExampleUneditableComboBox);
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
UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create();
TutorialDrawingSurface->setGraphics(graphics);
TutorialDrawingSurface->setEventProducer(TutorialWindow);
TutorialDrawingSurface->openWindow(MainInternalWindow);
// Create the UI Foreground Object
UIForegroundRecPtr foreground = UIForeground::create();
foreground->setDrawingSurface(TutorialDrawingSurface);
// Tell the manager what to manage
sceneManager.setRoot(scene);
// Add the UI Foreground Object to the Scene
ViewportRecPtr viewport = sceneManager.getWindow()->getPort(0);
//.........这里部分代码省略.........
//.........这里部分代码省略.........
//Create the ComboBox
ComboBoxRecPtr ExampleComboBox = ComboBox::create();
// Set the Model created above to the ComboBox
ExampleComboBox->setModel(ExampleComboBoxModel);
// Determine where the ComboBox starts
ExampleComboBox->setSelectedIndex(0);
/******************************************************
Create a non-editable ComboBox.
-setEditable(bool): Determine whether
the user can type in the ComboBox
or if it is uneditable. In this
case, it is set to false.
When creating a non-editable ComboBox,
a Renderer must also be assigned. For
editable ComboBoxes, the ComboBox
automatically shows its text due to the
nature of the ComboBox. However, when
uneditable, this aspect of the ComboBox
is disabled, and so to display the
selection, a renderer must be created and
assigned to the ComboBox.
Note: as with Sliders and ScrollBars,
having the same Model assigned causes
the ComboBoxes to be tied together.
******************************************************/
// Create another ComboBox
ComboBoxRecPtr ExampleUneditableComboBox = ComboBox::create();
// Set it to be uneditable
ExampleUneditableComboBox->setEditable(false);
ExampleUneditableComboBox->setModel(ExampleComboBoxModel);
// Create The Main InternalWindow
// Create Background to be used with the Main InternalWindow
ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create();
MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
LayoutRecPtr MainInternalWindowLayout = FlowLayout::create();
InternalWindowRecPtr MainInternalWindow = InternalWindow::create();
MainInternalWindow->pushToChildren(ExampleComboBox);
MainInternalWindow->pushToChildren(ExampleUneditableComboBox);
MainInternalWindow->setLayout(MainInternalWindowLayout);
MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f));
MainInternalWindow->setDrawTitlebar(false);
MainInternalWindow->setResizable(false);
//Create the Drawing Surface
UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create();
TutorialDrawingSurface->setGraphics(graphics);
TutorialDrawingSurface->setEventProducer(TutorialWindow);
TutorialDrawingSurface->openWindow(MainInternalWindow);
// Create the UI Foreground Object
UIForegroundRecPtr foreground = UIForeground::create();
foreground->setDrawingSurface(TutorialDrawingSurface);
// Tell the manager what to manage
sceneManager.setRoot(scene);
// Add the UI Foreground Object to the Scene
ViewportRecPtr viewport = sceneManager.getWindow()->getPort(0);
viewport->addForeground(foreground);
//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,
"33ComboBox");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
请发表评论