virtual void stateChanged(const ChangeEventUnrecPtr e) { while(UndoRedoListModel->getSize()-1 > TheUndoManager->numberOfRedos() + TheUndoManager->numberOfUndos()) { UndoRedoListModel->popBack(); } //Resize while(UndoRedoListModel->getSize()-1 < TheUndoManager->numberOfRedos() + TheUndoManager->numberOfUndos()) { UndoRedoListModel->pushBack(boost::any(std::string(""))); } UInt32 UndoCount(TheUndoManager->numberOfUndos()); for(UInt32 i(0) ; i<UndoCount ; ++i) { UndoRedoListModel->set(i+1, boost::any(std::string(TheUndoManager->editToBeUndone(i)->getUndoPresentationName()))); } UInt32 RedoCount(TheUndoManager->numberOfRedos()); for(UInt32 i(0) ; i<RedoCount ; ++i) { UndoRedoListModel->set(i+TheUndoManager->numberOfUndos()+1, boost::any(std::string(TheUndoManager->editToBeRedone(i)->getRedoPresentationName()))); } if((UndoCount == 0 && UndoButton->getEnabled()) || (UndoCount != 0 && !UndoButton->getEnabled()) ) { UndoButton->setEnabled(UndoCount != 0); } if((RedoCount == 0 && RedoButton->getEnabled()) || (RedoCount != 0 && !RedoButton->getEnabled()) ) { RedoButton->setEnabled(RedoCount != 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; }