ComponentTransitPtr GenericFieldContainerEditor::createFCToolTip(const FieldContainerType &FCType) { std::string FieldDoc(doxygenToPlainFormatting(FCType.getDocumentation())); //TypeName LabelRecPtr TypeLabel = Label::create(); TypeLabel->setText(FCType.getName()); TypeLabel->setAlignment(Vec2f(0.5f,0.5f)); TypeLabel->setBackgrounds(NULL); //Separator SeparatorRecPtr MainSeparator = Separator::create(); MainSeparator->setOrientation(Separator::HORIZONTAL_ORIENTATION); MainSeparator->setSeparatorSize(1.0f); MainSeparator->setPreferredSize(Vec2f(1.0f,5.0f)); MainSeparator->setBackgrounds(NULL); //Inheritance Panel Layout //LabelRecPtr InheritanceLabel = Label::create(); //InheritanceLabel->setText("Inheritance"); //FlowLayoutRecPtr InheritancePanelLayout = FlowLayout::create(); //InheritancePanelLayout->setOrientation(FlowLayout::VERTICAL_ORIENTATION); //InheritancePanelLayout->setVerticalGap(3.0f); //InheritancePanelLayout->setMajorAxisAlignment(0.0f); //InheritancePanelLayout->setMinorAxisAlignment(0.5f); //InheritancePanelLayout->setComponentAlignment(0.5f); ////Inheritance Panel //PanelRecPtr InheritancePanel = Panel::createEmpty(); //InheritancePanel->setAllInsets(5.0f); //InheritancePanel->setLayout(InheritancePanelLayout); //const TypeBase *ParentType(&FCType); ////while() ////{ ////ToolTipPanel->pushToChildren(DescriptionTextArea); ////} //LabelRecPtr TypeNameLabel = Label::create(); //TypeNameLabel->setText(FCType.getName()); //TypeNameLabel->setAlignment(Vec2f(0.5f,0.5f)); //InheritancePanel->pushToChildren(TypeNameLabel); //Set the layout constraints BorderLayoutConstraintsRecPtr CenterConstraints = BorderLayoutConstraints::create(); CenterConstraints->setRegion(BorderLayoutConstraints::BORDER_CENTER); //Description Panel LabelRecPtr DescriptionLabel = Label::create(); DescriptionLabel->setText("Description:"); DescriptionLabel->setBackgrounds(NULL); TextAreaRecPtr DescriptionTextArea = TextArea::create(); DescriptionTextArea->setText(FieldDoc); DescriptionTextArea->setEditable(false); DescriptionTextArea->setBorders(NULL); DescriptionTextArea->setBackgrounds(NULL); DescriptionTextArea->setConstraints(CenterConstraints); //Description Panel PanelRecPtr DescriptionPanel = Panel::create(); BorderLayoutRecPtr DescriptionPanelLayout = BorderLayout::create(); DescriptionPanel->setAllInsets(5.0f); DescriptionPanel->setLayout(DescriptionPanelLayout); DescriptionPanel->pushToChildren(DescriptionTextArea); DescriptionPanel->setBackgrounds(NULL); //ToolTip Layout PanelRecPtr ToolTipPanel = Panel::createEmpty(); SpringLayoutRecPtr MainLayout = SpringLayout::create(); //TypeLabel MainLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, TypeLabel, 5, SpringLayoutConstraints::NORTH_EDGE, ToolTipPanel); MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, TypeLabel, -5, SpringLayoutConstraints::EAST_EDGE, ToolTipPanel); MainLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, TypeLabel, 5, SpringLayoutConstraints::WEST_EDGE, ToolTipPanel); //MainSeparator MainLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, MainSeparator, 1, SpringLayoutConstraints::SOUTH_EDGE, TypeLabel); MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, MainSeparator, -15, SpringLayoutConstraints::EAST_EDGE, ToolTipPanel); MainLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, MainSeparator, 15, SpringLayoutConstraints::WEST_EDGE, ToolTipPanel); ////InheritancePanel //MainLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, InheritanceLabel, 1, //SpringLayoutConstraints::SOUTH_EDGE, MainSeparator); //MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, InheritanceLabel, 0, //SpringLayoutConstraints::EAST_EDGE, ToolTipPanel); //MainLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, InheritanceLabel, 0, //SpringLayoutConstraints::WEST_EDGE, ToolTipPanel); ////InheritancePanel //MainLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, InheritancePanel, 1, //SpringLayoutConstraints::SOUTH_EDGE, InheritanceLabel); //MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, InheritancePanel, 0, //SpringLayoutConstraints::EAST_EDGE, ToolTipPanel); //MainLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, InheritancePanel, 0, //SpringLayoutConstraints::WEST_EDGE, ToolTipPanel); //DescriptionTextArea MainLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, DescriptionLabel, 1, SpringLayoutConstraints::SOUTH_EDGE, MainSeparator); MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, DescriptionLabel, -5, SpringLayoutConstraints::EAST_EDGE, ToolTipPanel); MainLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, DescriptionLabel, 5, SpringLayoutConstraints::WEST_EDGE, ToolTipPanel); //DescriptionTextArea MainLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, DescriptionPanel, 1, SpringLayoutConstraints::SOUTH_EDGE, DescriptionLabel); MainLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, DescriptionPanel, -5, SpringLayoutConstraints::SOUTH_EDGE, ToolTipPanel); MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, DescriptionPanel, -5, SpringLayoutConstraints::EAST_EDGE, ToolTipPanel); MainLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, DescriptionPanel, 5, SpringLayoutConstraints::WEST_EDGE, ToolTipPanel); //ToolTip Panel Component* DefaultToolTip(LookAndFeelManager::the()->getLookAndFeel()->getDefaultToolTip()); ToolTipPanel->setBorders(DefaultToolTip->getBorder()); ToolTipPanel->setBackgrounds(DefaultToolTip->getBackground()); ToolTipPanel->setForegrounds(DefaultToolTip->getForeground()); ToolTipPanel->setLayout(MainLayout); ToolTipPanel->pushToChildren(TypeLabel); ToolTipPanel->pushToChildren(MainSeparator); //ToolTipPanel->pushToChildren(InheritanceLabel); //ToolTipPanel->pushToChildren(InheritancePanel); ToolTipPanel->pushToChildren(DescriptionLabel); ToolTipPanel->pushToChildren(DescriptionPanel); Real32 Height(100.0f + DescriptionTextArea->getLineHeight() * (DescriptionTextArea->getText().size()/40)); ToolTipPanel->setPreferredSize(Vec2f(300.0f,Height)); return ComponentTransitPtr(ToolTipPanel); }
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())); }
ComponentTransitPtr GenericFieldContainerEditor::createEventToolTip(const EventDescription *EventDesc) { std::string FieldDoc(doxygenToPlainFormatting(EventDesc->getDescription())); //TypeName LabelRecPtr TypeLabel = Label::create(); TypeLabel->setText(EventDesc->getName()); TypeLabel->setAlignment(Vec2f(0.5f,0.5f)); TypeLabel->setBackgrounds(NULL); //Separator SeparatorRecPtr MainSeparator = Separator::create(); MainSeparator->setOrientation(Separator::HORIZONTAL_ORIENTATION); MainSeparator->setSeparatorSize(1.0f); MainSeparator->setPreferredSize(Vec2f(1.0f,5.0f)); MainSeparator->setBackgrounds(NULL); //Consumable Label LabelRecPtr ConsumableLabel = Label::create(); ConsumableLabel->setText(EventDesc->getConsumable() ? "Consumable" : "Not Consumable"); ConsumableLabel->setAlignment(Vec2f(0.0f,0.5f)); ConsumableLabel->setBackgrounds(NULL); //Set the layout constraints BorderLayoutConstraintsRecPtr CenterConstraints = BorderLayoutConstraints::create(); CenterConstraints->setRegion(BorderLayoutConstraints::BORDER_CENTER); //Description Panel LabelRecPtr DescriptionLabel = Label::create(); DescriptionLabel->setText("Description:"); DescriptionLabel->setBackgrounds(NULL); TextAreaRecPtr DescriptionTextArea = TextArea::create(); DescriptionTextArea->setText(FieldDoc); DescriptionTextArea->setEditable(false); DescriptionTextArea->setBorders(NULL); DescriptionTextArea->setBackgrounds(NULL); DescriptionTextArea->setConstraints(CenterConstraints); //Description Panel PanelRecPtr DescriptionPanel = Panel::create(); BorderLayoutRecPtr DescriptionPanelLayout = BorderLayout::create(); DescriptionPanel->setAllInsets(5.0f); DescriptionPanel->setLayout(DescriptionPanelLayout); DescriptionPanel->pushToChildren(DescriptionTextArea); DescriptionPanel->setBackgrounds(NULL); //ToolTip Layout PanelRecPtr ToolTipPanel = Panel::createEmpty(); SpringLayoutRecPtr MainLayout = SpringLayout::create(); //TypeLabel MainLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, TypeLabel, 5, SpringLayoutConstraints::NORTH_EDGE, ToolTipPanel); MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, TypeLabel, -5, SpringLayoutConstraints::EAST_EDGE, ToolTipPanel); MainLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, TypeLabel, 5, SpringLayoutConstraints::WEST_EDGE, ToolTipPanel); //MainSeparator MainLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, MainSeparator, 1, SpringLayoutConstraints::SOUTH_EDGE, TypeLabel); MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, MainSeparator, -15, SpringLayoutConstraints::EAST_EDGE, ToolTipPanel); MainLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, MainSeparator, 15, SpringLayoutConstraints::WEST_EDGE, ToolTipPanel); //ConsumableLabel MainLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, ConsumableLabel, 1, SpringLayoutConstraints::NORTH_EDGE, MainSeparator); MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, ConsumableLabel, -5, SpringLayoutConstraints::EAST_EDGE, ToolTipPanel); MainLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, ConsumableLabel, 5, SpringLayoutConstraints::WEST_EDGE, ToolTipPanel); //DescriptionTextArea MainLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, DescriptionLabel, 5, SpringLayoutConstraints::SOUTH_EDGE, ConsumableLabel); MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, DescriptionLabel, -5, SpringLayoutConstraints::EAST_EDGE, ToolTipPanel); MainLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, DescriptionLabel, 5, SpringLayoutConstraints::WEST_EDGE, ToolTipPanel); //DescriptionTextArea MainLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, DescriptionPanel, 1, SpringLayoutConstraints::SOUTH_EDGE, DescriptionLabel); MainLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, DescriptionPanel, -5, SpringLayoutConstraints::SOUTH_EDGE, ToolTipPanel); MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, DescriptionPanel, -5, SpringLayoutConstraints::EAST_EDGE, ToolTipPanel); MainLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, DescriptionPanel, 5, SpringLayoutConstraints::WEST_EDGE, ToolTipPanel); //ToolTip Panel Component* DefaultToolTip(LookAndFeelManager::the()->getLookAndFeel()->getDefaultToolTip()); ToolTipPanel->setBorders(DefaultToolTip->getBorder()); ToolTipPanel->setBackgrounds(DefaultToolTip->getBackground()); ToolTipPanel->setForegrounds(DefaultToolTip->getForeground()); ToolTipPanel->setLayout(MainLayout); ToolTipPanel->pushToChildren(TypeLabel); ToolTipPanel->pushToChildren(MainSeparator); ToolTipPanel->pushToChildren(ConsumableLabel); ToolTipPanel->pushToChildren(DescriptionLabel); ToolTipPanel->pushToChildren(DescriptionPanel); Real32 Height(130.0f + DescriptionTextArea->getLineHeight() * (DescriptionTextArea->getText().size()/40)); ToolTipPanel->setPreferredSize(Vec2f(300.0f,Height)); return ComponentTransitPtr(ToolTipPanel); }
void HelperPanel::createIntrospectionTreeTab(TabPanel* const tabPanel) { BorderLayoutConstraintsRefPtr CenterConstraints = OSG::BorderLayoutConstraints::create(); CenterConstraints->setRegion(BorderLayoutConstraints::BORDER_CENTER); BorderLayoutConstraintsRefPtr NorthConstraints = OSG::BorderLayoutConstraints::create(); NorthConstraints->setRegion(BorderLayoutConstraints::BORDER_NORTH); _GlobalLuaIntroTreeModel = LuaIntrospectionTreeModel::create(); _GlobalLuaIntroTreeModel->setRoot(""); LuaIntrospectionComponentGeneratorRecPtr LuaIntroTreeComponentGenerator = LuaIntrospectionComponentGenerator::create(); //Create the Tree TreeRecPtr TheTree = Tree::create(); TheTree->setPreferredSize(Vec2f(200, 500)); TheTree->setModel(_GlobalLuaIntroTreeModel); TheTree->setCellGenerator(LuaIntroTreeComponentGenerator); //Layout Expansion TheTree->expandPath(_GlobalLuaIntroTreeModel->getRootPath()); //Create a scroll panel for the tree ScrollPanelRefPtr TreeScrollPanel = ScrollPanel::create(); TreeScrollPanel->setPreferredSize(Vec2f(200,300)); TreeScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); TreeScrollPanel->setViewComponent(TheTree); TreeScrollPanel->setConstraints(CenterConstraints); //Global Label LabelRecPtr GlobalTreeLabel = Label::create(); GlobalTreeLabel->setText("Global"); GlobalTreeLabel->setConstraints(NorthConstraints); BorderLayoutRecPtr BorderPanelLayout = BorderLayout::create(); //Global Panel PanelRecPtr GlobalLuaTreePanel = Panel::createEmpty(); GlobalLuaTreePanel->pushToChildren(GlobalTreeLabel); GlobalLuaTreePanel->pushToChildren(TreeScrollPanel); GlobalLuaTreePanel->setLayout(BorderPanelLayout); //Local Label LabelRecPtr LocalTreeLabel = Label::create(); LocalTreeLabel->setText("Local"); LocalTreeLabel->setConstraints(NorthConstraints); //Local Panel PanelRecPtr LocalLuaTreePanel = Panel::createEmpty(); LocalLuaTreePanel->pushToChildren(LocalTreeLabel); LocalLuaTreePanel->setLayout(BorderPanelLayout); //Global/Local Split Panel SplitPanelRecPtr GlocalLocalSplitPanel = SplitPanel::create(); GlocalLocalSplitPanel->setMinComponent(GlobalLuaTreePanel); GlocalLocalSplitPanel->setMaxComponent(LocalLuaTreePanel); GlocalLocalSplitPanel->setDividerPosition(0.5f); GlocalLocalSplitPanel->setDividerSize(5); GlocalLocalSplitPanel->setMinDividerPosition(.1); GlocalLocalSplitPanel->setMaxDividerPosition(.9); //Add the Panel to the TabPanel LabelRefPtr IntrospectionTreeTabLabel = Label::create(); IntrospectionTreeTabLabel->setText("Lua Introspection"); IntrospectionTreeTabLabel->setBorders(NULL); IntrospectionTreeTabLabel->setBackgrounds(NULL); tabPanel->addTab(IntrospectionTreeTabLabel, GlocalLocalSplitPanel); }
/*-------------------------------------------------------------------------*\ - 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)); // 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 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 an Button Component and a simple Font. See 17Label_Font for more information about Fonts. ******************************************************/ LineBorderRecPtr ChangableBorder = LineBorder::create(); ChangableBorder->setColor(Color4f(0.0,0.0,0.0,1.0)); ColorLayerRecPtr ChangableBackground = ColorLayer::create(); ChangableBackground->setColor(Color4f(1.0,1.0,1.0,1.0)); LabelRecPtr ChangableLabel = Label::create(); ChangableLabel->setText("Changable"); ChangableLabel->setBorders(ChangableBorder); ChangableLabel->setBackgrounds(ChangableBackground); //Command Buttons UndoManagerPtr TheUndoManager = UndoManager::create(); CommandManagerPtr TheCommandManager = CommandManager::create(TheUndoManager); ButtonRecPtr BorderRedButton = Button::create(); BorderRedButton->setText("Border Red"); BorderRedButton->setPreferredSize(Vec2f(85, 20)); BorderRedButton->connectActionPerformed(boost::bind(handleSetBorderColorAction, _1, TheCommandManager, ChangableBorder.get(), Color4f(1.0,0.0,0.0,1.0))); ButtonRecPtr BorderGreenButton = Button::create(); BorderGreenButton->setText("Border Green"); BorderGreenButton->setPreferredSize(Vec2f(85, 20)); BorderGreenButton->connectActionPerformed(boost::bind(handleSetBorderColorAction, _1, TheCommandManager, ChangableBorder.get(), Color4f(0.0,1.0,0.0,1.0))); ButtonRecPtr BorderBlueButton = Button::create(); BorderBlueButton->setText("Border Blue"); BorderBlueButton->setPreferredSize(Vec2f(85, 20)); BorderBlueButton->connectActionPerformed(boost::bind(handleSetBorderColorAction, _1, TheCommandManager, ChangableBorder.get(), Color4f(0.0,0.0,1.0,1.0))); //Background ButtonRecPtr BackgroundRedButton = Button::create(); BackgroundRedButton->setText("Background Red"); BackgroundRedButton->setPreferredSize(Vec2f(105, 20)); BackgroundRedButton->connectActionPerformed(boost::bind(handleSetBackgroundColorAction, _1, TheCommandManager, ChangableBackground.get(), Color4f(1.0,0.0,0.0,1.0))); ButtonRecPtr BackgroundGreenButton = Button::create(); BackgroundGreenButton->setText("Background Green"); BackgroundGreenButton->setPreferredSize(Vec2f(105, 20)); BackgroundGreenButton->connectActionPerformed(boost::bind(handleSetBackgroundColorAction, _1, TheCommandManager, ChangableBackground.get(), Color4f(0.0,1.0,0.0,1.0))); ButtonRecPtr BackgroundBlueButton = Button::create(); BackgroundBlueButton->setText("Background Blue"); BackgroundBlueButton->setPreferredSize(Vec2f(105, 20)); BackgroundBlueButton->connectActionPerformed(boost::bind(handleSetBackgroundColorAction, _1, TheCommandManager, ChangableBackground.get(), Color4f(0.0,0.0,1.0,1.0))); //UndoList DefaultListModelRecPtr UndoRedoListModel = DefaultListModel::create(); UndoRedoListModel->pushBack(boost::any(std::string("Top"))); ListRecPtr UndoRedoList = List::create(); UndoRedoList->setPreferredSize(Vec2f(200, 300)); UndoRedoList->setOrientation(List::VERTICAL_ORIENTATION); UndoRedoList->setModel(UndoRedoListModel); UndoRedoList->getSelectionModel()->connectSelectionChanged(boost::bind(handleUndoRedoListSelectionChanged, _1, UndoRedoList.get(), TheUndoManager)); ButtonRecPtr UndoButton = Button::create(); UndoButton->setText("Undo"); UndoButton->setEnabled(TheUndoManager->numberOfUndos() != 0); UndoButton->connectActionPerformed(boost::bind(handleUndoButtonAction, _1, TheUndoManager)); ButtonRecPtr RedoButton = Button::create(); RedoButton->setText("Redo"); RedoButton->setEnabled(TheUndoManager->numberOfRedos() != 0); RedoButton->connectActionPerformed(boost::bind(handleRedoButtonAction, _1, TheUndoManager)); // Create a ScrollPanel for easier viewing of the List (see 27ScrollPanel) ScrollPanelRecPtr 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 ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); LayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); MainInternalWindow->pushToChildren(BorderRedButton); MainInternalWindow->pushToChildren(BorderGreenButton); MainInternalWindow->pushToChildren(BorderBlueButton); MainInternalWindow->pushToChildren(BackgroundRedButton); MainInternalWindow->pushToChildren(BackgroundGreenButton); MainInternalWindow->pushToChildren(BackgroundBlueButton); MainInternalWindow->pushToChildren(ChangableLabel); 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); TheUndoManager->connectStateChanged(boost::bind(handleUndoManagerStateChanged, _1, UndoRedoListModel.get(), TheUndoManager, UndoButton.get(), RedoButton.get())); // 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, "40UndoableCommand"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
PanelTransitPtr createLeftPanelRadioTextPanel(void) { // Create TextArea TextAreaRecPtr LeftPanelTextArea = TextArea::create(); LeftPanelTextArea->setPreferredSize(Vec2f(125, 200)); LeftPanelTextArea->setText("Text Area"); // Create the RadioButton group RadioButtonRecPtr RadioButton1 = RadioButton::create(); RadioButtonRecPtr RadioButton2 = RadioButton::create(); RadioButtonRecPtr RadioButton3 = RadioButton::create(); RadioButtonRecPtr RadioButton4 = RadioButton::create(); RadioButton1->setAlignment(Vec2f(0.0,0.5)); RadioButton1->setPreferredSize(Vec2f(100, 40)); RadioButton1->setText("Black Text"); RadioButton1->setToolTipText("Set TextArea text black"); RadioButton1->connectButtonSelected(boost::bind(setTextColors, LeftPanelTextArea.get(), Color4f(0.0f,0.0f,0.0f,1.0f))); RadioButton2->setAlignment(Vec2f(0.0,0.5)); RadioButton2->setPreferredSize(Vec2f(100, 40)); RadioButton2->setText("Red Text"); RadioButton2->setToolTipText("Set TextArea text red"); RadioButton2->connectButtonSelected(boost::bind(setTextColors, LeftPanelTextArea.get(), Color4f(1.0f,0.0f,0.0f,1.0f))); RadioButton3->setAlignment(Vec2f(0.0,0.5)); RadioButton3->setPreferredSize(Vec2f(100, 40)); RadioButton3->setText("Green Text"); RadioButton3->setToolTipText("Set TextArea text green"); RadioButton3->connectButtonSelected(boost::bind(setTextColors, LeftPanelTextArea.get(), Color4f(0.0f,1.0f,0.0f,1.0f))); RadioButton4->setAlignment(Vec2f(0.0,0.5)); RadioButton4->setPreferredSize(Vec2f(100, 40)); RadioButton4->setText("Blue Text"); RadioButton4->setToolTipText("Set TextArea text blue"); RadioButton4->connectButtonSelected(boost::bind(setTextColors, LeftPanelTextArea.get(), Color4f(0.0f,0.0f,1.0f,1.0f))); RadioButtonGroupRecPtr buttonGroup = RadioButtonGroup::create(); buttonGroup->addButton(RadioButton1); buttonGroup->addButton(RadioButton2); buttonGroup->addButton(RadioButton3); buttonGroup->addButton(RadioButton4); // Create Panel and its Background/Border to label TextField LabelRecPtr LeftPanelTextFieldLabel = Label::create(); EmptyLayerRecPtr LeftPanelTextFieldLabelBackground = EmptyLayer::create(); EmptyBorderRecPtr LeftPanelTextFieldLabelBorder = EmptyBorder::create(); LeftPanelTextFieldLabel->setPreferredSize(Vec2f(100, 25)); LeftPanelTextFieldLabel->setBorders(LeftPanelTextFieldLabelBorder); LeftPanelTextFieldLabel->setBackgrounds(LeftPanelTextFieldLabelBackground); LeftPanelTextFieldLabel->setText("Text Field"); // Create TextField TextFieldRecPtr LeftPanelTextField = TextField::create(); LeftPanelTextField->setPreferredSize(Vec2f(125.0f, 22.0f)); // Create an edit Panel Background ColorLayerRecPtr LeftPanelRadioTextPanelBackground = ColorLayer::create(); LeftPanelRadioTextPanelBackground->setColor(Color4f(0.93f,0.93f,0.93f,1.0f)); // Create and edit Panel layouts FlowLayoutRecPtr LeftPanelRadioTextPanelLayout = FlowLayout::create(); FlowLayoutRecPtr LeftPanelRadioTextPanelRadioPanelLayout = FlowLayout::create(); FlowLayoutRecPtr LeftPanelRadioTextPanelTextPanelLayout = FlowLayout::create(); LeftPanelRadioTextPanelLayout->setMinorAxisAlignment(0.0f); // Create two Panels for this Panel PanelRecPtr LeftPanelRadioTextPanelRadioPanel = Panel::createEmpty(); PanelRecPtr LeftPanelRadioTextPanelTextPanel = Panel::createEmpty(); // Create some Borders EmptyBorderRecPtr LeftPanelRadioTextPanelRadioPanelBorder = EmptyBorder::create(); LeftPanelRadioTextPanelRadioPanel->setBorders(LeftPanelRadioTextPanelRadioPanelBorder); LeftPanelRadioTextPanelRadioPanel->setPreferredSize(Vec2f(125, 200)); LeftPanelRadioTextPanelRadioPanel->setLayout(LeftPanelRadioTextPanelRadioPanelLayout); LeftPanelRadioTextPanelRadioPanel->setBackgrounds(LeftPanelRadioTextPanelBackground); LeftPanelRadioTextPanelRadioPanel->pushToChildren(RadioButton1); LeftPanelRadioTextPanelRadioPanel->pushToChildren(RadioButton2); LeftPanelRadioTextPanelRadioPanel->pushToChildren(RadioButton3); LeftPanelRadioTextPanelRadioPanel->pushToChildren(RadioButton4); // Create Panel Border LineBorderRecPtr PanelBorder1 = LineBorder::create(); PanelBorder1->setColor(Color4f(0.0,0.0,0.0,1.0)); PanelBorder1->setWidth(1); // Create and edit Panel PanelRecPtr LeftPanelRadioTextPanel = Panel::createEmpty(); LeftPanelRadioTextPanel->setPreferredSize(Vec2f(180, 500)); LeftPanelRadioTextPanel->pushToChildren(LeftPanelRadioTextPanelRadioPanel); //LeftPanelRadioTextPanel->pushToChildren(LeftPanelTextArea); LeftPanelRadioTextPanel->pushToChildren(LeftPanelTextFieldLabel); LeftPanelRadioTextPanel->pushToChildren(LeftPanelTextField); LeftPanelRadioTextPanel->setLayout(LeftPanelRadioTextPanelLayout); LeftPanelRadioTextPanel->setBackgrounds(LeftPanelRadioTextPanelBackground); LeftPanelRadioTextPanel->setBorders(PanelBorder1); return PanelTransitPtr(LeftPanelRadioTextPanel); }
PanelTransitPtr createLeftPanelButtonPanel(void) { // Create Label for this Panel LabelRecPtr LeftPanelButtonPanelLabel = Label::create(); LeftPanelButtonPanelLabel->setTextColor(Color4f(1.0,1.0,1.0,1.0)); LeftPanelButtonPanelLabel->setRolloverTextColor(Color4f(1.0,1.0,1.0,1.0)); LayerRecPtr ComplexBackground = createComplexBackground(); LeftPanelButtonPanelLabel->setBackground(ComplexBackground); LeftPanelButtonPanelLabel->setPreferredSize(Vec2f(100, 50)); LeftPanelButtonPanelLabel->setText("Various Options"); LeftPanelButtonPanelLabel->setAlignment(Vec2f(0.5,0.5)); // Create and edit the Panel buttons ButtonRecPtr LeftPanelButton1 = Button::create(); ButtonRecPtr LeftPanelButton2 = Button::create(); ButtonRecPtr LeftPanelButton3 = Button::create(); ButtonRecPtr LeftPanelButton4 = Button::create(); ButtonRecPtr LeftPanelButton5 = Button::create(); ButtonRecPtr LeftPanelButton6 = Button::create(); LeftPanelButton1->setText("This"); LeftPanelButton1->setPreferredSize(Vec2f(100,50)); LeftPanelButton2->setText("is"); LeftPanelButton2->setPreferredSize(Vec2f(100,50)); LeftPanelButton3->setText("an"); LeftPanelButton3->setPreferredSize(Vec2f(100,50)); LeftPanelButton4->setText("example"); LeftPanelButton4->setPreferredSize(Vec2f(100,50)); LeftPanelButton5->setText("user"); LeftPanelButton5->setPreferredSize(Vec2f(100,50)); LeftPanelButton6->setText("interface."); LeftPanelButton6->setPreferredSize(Vec2f(100,50)); // Create and edit Panel layout BoxLayoutRecPtr LeftPanelButtonPanelLayout = BoxLayout::create(); LeftPanelButtonPanelLayout->setOrientation(BoxLayout::VERTICAL_ORIENTATION); // Create an edit Panel Background ColorLayerRecPtr LeftPanelButtonPanelBackground = ColorLayer::create(); LeftPanelButtonPanelBackground->setColor(Color4f(0.93,0.93,0.93,1.0)); // Create Panel Border LineBorderRecPtr LeftPanelBorder = LineBorder::create(); LeftPanelBorder->setColor(Color4f(0.0,0.0,0.0,1.0)); LeftPanelBorder->setWidth(1); // Create and edit Panel PanelRecPtr LeftPanelButtonPanel = Panel::createEmpty(); LeftPanelButtonPanel->setPreferredSize(Vec2f(180, 500)); LeftPanelButtonPanel->pushToChildren(LeftPanelButtonPanelLabel); LeftPanelButtonPanel->pushToChildren(LeftPanelButton1); LeftPanelButtonPanel->pushToChildren(LeftPanelButton2); LeftPanelButtonPanel->pushToChildren(LeftPanelButton3); LeftPanelButtonPanel->pushToChildren(LeftPanelButton4); LeftPanelButtonPanel->pushToChildren(LeftPanelButton5); LeftPanelButtonPanel->pushToChildren(LeftPanelButton6); LeftPanelButtonPanel->setLayout(LeftPanelButtonPanelLayout); LeftPanelButtonPanel->setBackgrounds(LeftPanelButtonPanelBackground); LeftPanelButtonPanel->setBorders(LeftPanelBorder); return PanelTransitPtr(LeftPanelButtonPanel); }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1)); NodeRecPtr Root(NULL); if(argc == 2) { Root = SceneFileHandler::the()->read(argv[1]); } if(Root == NULL) { // Make Torus Node (creates Torus in background of Root) NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); setName(TorusGeometryNode, std::string("Torus")); NodeRecPtr TorusNode = Node::create(); TorusNode->setCore(Transform::create()); TorusNode->addChild(TorusGeometryNode); setName(TorusNode, std::string("Torus Transform")); NodeRecPtr SphereGeometryNode = makeSphere(2,1.0f); setName(SphereGeometryNode, std::string("Sphere")); NodeRecPtr 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 = Node::create(); Root->setCore(Group::create()); Root->addChild(TorusNode); Root->addChild(SphereGeometryNode); Root->addChild(BoxGeometryNode); setName(Root, std::string("Root")); } // Create the Graphics GraphicsRecPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); //Tree Model SceneGraphTreeModelRecPtr TheTreeModel = SceneGraphTreeModel::create(); TheTreeModel->setRoot(Root); //Create the Tree TreeRecPtr TheTree = Tree::create(); TheTree->setPreferredSize(Vec2f(100, 500)); TheTree->setModel(TheTreeModel); // Create a ScrollPanel for easier viewing of the List (see 27ScrollPanel) BorderLayoutConstraintsRecPtr SceneTreeConstraints = BorderLayoutConstraints::create(); SceneTreeConstraints->setRegion(BorderLayoutConstraints::BORDER_WEST); ScrollPanelRecPtr 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 LabelRecPtr NodeNameLabel = Label::create(); NodeNameLabel->setText("Name"); NodeNameLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); LabelRecPtr NodeNameValueLabel = Label::create(); NodeNameValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRecPtr NodeCoreTypeLabel = Label::create(); NodeCoreTypeLabel->setText("Core Type"); NodeCoreTypeLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); LabelRecPtr NodeCoreTypeValueLabel = Label::create(); NodeCoreTypeValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRecPtr NodeMinLabel = Label::create(); NodeMinLabel->setText("Min"); NodeMinLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); LabelRecPtr NodeMinValueLabel = Label::create(); NodeMinValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRecPtr NodeMaxLabel = Label::create(); NodeMaxLabel->setText("Max"); NodeMaxLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); LabelRecPtr NodeMaxValueLabel = Label::create(); NodeMaxValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRecPtr NodeCenterLabel = Label::create(); NodeCenterLabel->setText("Center"); NodeCenterLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); LabelRecPtr NodeCenterValueLabel = Label::create(); NodeCenterValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRecPtr NodeTriCountLabel = Label::create(); NodeTriCountLabel->setText("TriCount"); NodeTriCountLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); LabelRecPtr NodeTriCountValueLabel = Label::create(); NodeTriCountValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); LabelRecPtr NodeTravMaskLabel = Label::create(); NodeTravMaskLabel->setText("Traversal Mask"); NodeTravMaskLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); LabelRecPtr NodeTravMaskValueLabel = Label::create(); NodeTravMaskValueLabel->setPreferredSize(Vec2f(300.0f, 20.0f)); //Details Panel BorderLayoutConstraintsRecPtr NodeDetailPanelConstraints = BorderLayoutConstraints::create(); NodeDetailPanelConstraints->setRegion(BorderLayoutConstraints::BORDER_SOUTH); GridLayoutRecPtr NodeDetailPanelLayout = GridLayout::create(); NodeDetailPanelLayout->setRows(7); NodeDetailPanelLayout->setColumns(2); NodeDetailPanelLayout->setHorizontalGap(2); NodeDetailPanelLayout->setVerticalGap(2); PanelRecPtr 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); SelectionHandler TheTreeSelectionHandler(TheTree, &sceneManager, NodeNameValueLabel, NodeCoreTypeValueLabel, NodeMinValueLabel, NodeMaxValueLabel, NodeCenterValueLabel, NodeTriCountValueLabel, NodeTravMaskValueLabel); // 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 = BorderLayout::create(); InternalWindowRecPtr MainInternalWindow = 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 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(Root); // 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, "52SceneGraphTree"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
void selectedNodeChanged(void) { _mgr->setHighlight(_SelectedNode); //Update Details Panel if(_SelectedNode == NULL) { _NodeNameValueLabel->setText(""); _NodeCoreTypeValueLabel->setText(""); _NodeMinValueLabel->setText(""); _NodeMaxValueLabel->setText(""); _NodeCenterValueLabel->setText(""); _NodeTriCountValueLabel->setText(""); _NodeTravMaskValueLabel->setText(""); } else { const Char8 *NodeName = getName(_SelectedNode); if(NodeName == NULL) { _NodeNameValueLabel->setText("Unnamed Node"); } else { _NodeNameValueLabel->setText(NodeName); } _NodeCoreTypeValueLabel->setText(_SelectedNode->getCore()->getType().getCName()); BoxVolume DyVol; _SelectedNode->getWorldVolume(DyVol); Pnt3f Min,Max,Center; DyVol.getBounds(Min,Max); DyVol.getCenter(Center); std::string TempText(""); TempText = boost::lexical_cast<std::string>(Min.x()) + ", " +boost::lexical_cast<std::string>(Min.x()) + ", " + boost::lexical_cast<std::string>(Min.x()); _NodeMinValueLabel->setText(TempText); TempText = boost::lexical_cast<std::string>(Max.x()) + ", " +boost::lexical_cast<std::string>(Max.x()) + ", " + boost::lexical_cast<std::string>(Max.x()); _NodeMaxValueLabel->setText(TempText); TempText = boost::lexical_cast<std::string>(Center.x()) + ", " +boost::lexical_cast<std::string>(Center.x()) + ", " + boost::lexical_cast<std::string>(Center.x()); _NodeCenterValueLabel->setText(TempText); _NodeTravMaskValueLabel->setText(boost::lexical_cast<std::string>(_SelectedNode->getTravMask())); //Tri Cound TriCountGraphOpRefPtr TheTriGraphOp = TriCountGraphOp::create(); TheTriGraphOp->traverse(_SelectedNode); _NodeTriCountValueLabel->setText(boost::lexical_cast<std::string>(TheTriGraphOp->getNumTri())); } }
PanelTransitPtr VideoFieldContainerEditor::createVideoPreviewPanel(void) { ChunkMaterialUnrecPtr VideoMaterial = ChunkMaterial::create(); //Video MaterialLayer _VideoMaterialLayer = MaterialLayer::create(); _VideoMaterialLayer->setMaterial(VideoMaterial); //Video Panel _VideoPanel = Panel::createEmpty(); _VideoPanel->setBackgrounds(_VideoMaterialLayer); //Filename Label _FileNameLabel = Label::create(); _FileNameLabel->setAlignment(Vec2f(0.5f, 0.5f)); //Total time Label _TotalTimeLabel = Label::create(); _TotalTimeLabel->setAlignment(Vec2f(0.0f, 1.0f)); _TotalTimeLabel->setBorders(NULL); _TotalTimeLabel->setBackgrounds(NULL); _TotalTimeLabel->setPreferredSize(Vec2f(50.0f,_TotalTimeLabel->getPreferredSize().y())); //Playback time Label _PlaybackTimeLabel = Label::create(); _PlaybackTimeLabel->setAlignment(Vec2f(1.0f, 1.0f)); _PlaybackTimeLabel->setPreferredSize(Vec2f(50.0f,_TotalTimeLabel->getPreferredSize().y())); _PlaybackTimeLabel->setBorders(NULL); _PlaybackTimeLabel->setBackgrounds(NULL); LabelRecPtr TimeSeparatorLabel = Label::create(); TimeSeparatorLabel->setAlignment(Vec2f(0.5f, 1.0f)); TimeSeparatorLabel->setPreferredSize(Vec2f(8.0f,_TotalTimeLabel->getPreferredSize().y())); TimeSeparatorLabel->setBorders(NULL); TimeSeparatorLabel->setBackgrounds(NULL); TimeSeparatorLabel->setText("/"); //PlayPause Button _PlayPauseButton = Button::create(); _PlayPauseButton->setText("Play"); _PlayPauseButton->setPreferredSize(Vec2f(40.0f,40.0f)); _PlayPauseButton->connectActionPerformed(boost::bind(&VideoFieldContainerEditor::handlePlayPauseAction, this, _1)); //Stop Button _StopButton = Button::create(); _StopButton->setText("Stop"); _StopButton->setPreferredSize(Vec2f(40.0f,40.0f)); _StopButton->connectActionPerformed(boost::bind(&VideoFieldContainerEditor::handleStopAction, this, _1)); //Load Button ButtonRecPtr LoadButton = Button::create(); LoadButton->setText("Load"); LoadButton->setPreferredSize(Vec2f(40.0f,40.0f)); LoadButton->connectActionPerformed(boost::bind(&VideoFieldContainerEditor::handleLoadAction, this, _1)); //Playback position slider _LocationSlider = Slider::create(); _LocationSlider->setOrientation(Slider::HORIZONTAL_ORIENTATION); _LocationSlider->setDrawLabels(false); _LocationSlider->setDrawMajorTicks(false); _LocationSlider->setDrawMinorTicks(false); _LocationSlider->setBorders(NULL); _LocationSlider->setBackgrounds(NULL); //_LocationSlider->getKnobButton()->setPreferredSize(Vec2f(15.0f, 8.0f)); _LocationSlider->getRangeModel()->connectStateChanged(boost::bind(&VideoFieldContainerEditor::handlePlaybackLocationStateChanged, this, _1)); //Layout PanelRecPtr VideoPanel = Panel::createEmpty(); SpringLayoutRecPtr MainLayout = SpringLayout::create(); //Video Panel MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _VideoPanel, 0, SpringLayoutConstraints::EAST_EDGE, VideoPanel); MainLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, _VideoPanel, 0, SpringLayoutConstraints::WEST_EDGE, VideoPanel); MainLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, _VideoPanel, 0, SpringLayoutConstraints::NORTH_EDGE, VideoPanel); MainLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _VideoPanel, -1, SpringLayoutConstraints::NORTH_EDGE, _PlayPauseButton); //Filename Label MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _FileNameLabel, 0, SpringLayoutConstraints::EAST_EDGE, VideoPanel); MainLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, _FileNameLabel, 0, SpringLayoutConstraints::WEST_EDGE, VideoPanel); MainLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, _FileNameLabel, 0, SpringLayoutConstraints::NORTH_EDGE, VideoPanel); //Play/pause Button MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _PlayPauseButton, -3, SpringLayoutConstraints::WEST_EDGE, _StopButton); MainLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _PlayPauseButton, 0, SpringLayoutConstraints::SOUTH_EDGE, VideoPanel); //Stop Button MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _StopButton, -3, SpringLayoutConstraints::WEST_EDGE, _LocationSlider); MainLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _StopButton, 0, SpringLayoutConstraints::SOUTH_EDGE, VideoPanel); //Playback Slider MainLayout->putConstraint(SpringLayoutConstraints::HORIZONTAL_CENTER_EDGE, _LocationSlider, 0, SpringLayoutConstraints::HORIZONTAL_CENTER_EDGE, VideoPanel); MainLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _LocationSlider, 0, SpringLayoutConstraints::SOUTH_EDGE, VideoPanel); //Total video length label MainLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _TotalTimeLabel, 0, SpringLayoutConstraints::SOUTH_EDGE, LoadButton); MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _TotalTimeLabel, 0, SpringLayoutConstraints::EAST_EDGE, _LocationSlider); //Separator label MainLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, TimeSeparatorLabel, 0, SpringLayoutConstraints::SOUTH_EDGE, LoadButton); MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, TimeSeparatorLabel, -2, SpringLayoutConstraints::WEST_EDGE, _TotalTimeLabel); //Playback time label MainLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _PlaybackTimeLabel, 0, SpringLayoutConstraints::SOUTH_EDGE, LoadButton); MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _PlaybackTimeLabel, -2, SpringLayoutConstraints::WEST_EDGE, TimeSeparatorLabel); //Load Button MainLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, LoadButton, 3, SpringLayoutConstraints::EAST_EDGE, _LocationSlider); MainLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, LoadButton, 0, SpringLayoutConstraints::SOUTH_EDGE, VideoPanel); //Main Video Panel VideoPanel->setLayout(MainLayout); VideoPanel->pushToChildren(_VideoPanel); VideoPanel->pushToChildren(_FileNameLabel); VideoPanel->pushToChildren(_PlayPauseButton); VideoPanel->pushToChildren(_StopButton); VideoPanel->pushToChildren(LoadButton); VideoPanel->pushToChildren(_PlaybackTimeLabel); VideoPanel->pushToChildren(TimeSeparatorLabel); VideoPanel->pushToChildren(_TotalTimeLabel); VideoPanel->pushToChildren(_LocationSlider); return PanelTransitPtr(VideoPanel); }