Пример #1
0
void LuaDebuggerInterface::addIntrospectionTreeTab(TabPanel* const tabPanel)
{
    LuaIntrospectionTreeModelRecPtr LuaIntroTreeModel = LuaIntrospectionTreeModel::create();
    LuaIntroTreeModel->setRoot("");

    LuaIntrospectionComponentGeneratorRecPtr LuaIntroTreeComponentGenerator = LuaIntrospectionComponentGenerator::create();

    //Create the Tree
    TreeRecPtr TheTree = Tree::create();

    TheTree->setPreferredSize(Vec2f(200, 500));
    TheTree->setModel(LuaIntroTreeModel);
    TheTree->setCellGenerator(LuaIntroTreeComponentGenerator);
    TheTree->connectKeyTyped(boost::bind(&LuaDebuggerInterface::handleUpdateTreeEvent,
                                         this,
                                         _1,
                                         TheTree.get(),
                                         LuaIntroTreeModel.get()));

    //Layout Expansion
    TheTree->expandPath(LuaIntroTreeModel->getRootPath());

    // Create a ScrollPanel for easier viewing of the List (see 27ScrollPanel)
    ScrollPanelRefPtr TreeScrollPanel = ScrollPanel::create();
    TreeScrollPanel->setPreferredSize(Vec2f(200,300));
    TreeScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW);
    TreeScrollPanel->setViewComponent(TheTree);

    LabelRefPtr IntrospectionTreeTabLabel = Label::create();
    IntrospectionTreeTabLabel->setText("Variable Introspection");

    tabPanel->addTab(IntrospectionTreeTabLabel, TreeScrollPanel);
}
Пример #2
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 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;
}
Пример #3
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;
}
Пример #4
0
void LuaDebuggerInterface::createUtilTabs(void)
{
    //Create the Error Text Area
    _ErrorTextArea = TextArea::create();

    _ErrorTextArea->setPreferredSize(Vec2f(600, 150));
    _ErrorTextArea->setText("");
    _ErrorTextArea->setMinSize(Vec2f(300, 150));
    _ErrorTextArea->setFont(_CodeFont);
    _ErrorTextArea->setTextColors(Color4f(0.2,0.0,0.0,1.0));
    _ErrorTextArea->setEditable(false);
    setName(_ErrorTextArea,"Error TextArea");
    TheLuaManager->connectLuaError(boost::bind(&LuaDebuggerInterface::handlLuaError,
                                                this,
                                                _1));

    // Create a ScrollPanel
    ScrollPanelRefPtr ErrorAreaScrollPanel = ScrollPanel::create();
    ErrorAreaScrollPanel->setPreferredSize(Vec2f(200,150));
    ErrorAreaScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW);
    // Add the TextArea to the ScrollPanel so it is displayed
    ErrorAreaScrollPanel->setViewComponent(_ErrorTextArea);

    //Create the StackTrace Text Area
    _StackTraceTextArea = TextArea::create();

    _StackTraceTextArea->setPreferredSize(Vec2f(600, 150));
    _StackTraceTextArea->setText("");
    _StackTraceTextArea->setMinSize(Vec2f(300, 150));
    _StackTraceTextArea->setFont(_CodeFont);
    _StackTraceTextArea->setTextColors(Color4f(0.2,0.0,0.0,1.0));
    _StackTraceTextArea->setEditable(false);
    setName(_StackTraceTextArea,"Stack Trace TextArea");

    // Create a ScrollPanel
    ScrollPanelRefPtr StackTraceAreaScrollPanel = ScrollPanel::create();
    StackTraceAreaScrollPanel->setPreferredSize(Vec2f(200,150));
    StackTraceAreaScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW);
    // Add the TextArea to the ScrollPanel so it is displayed
    StackTraceAreaScrollPanel->setViewComponent(_StackTraceTextArea);

    //Create the Message Text Area
    _MessageTextArea = TextArea::create();

    _MessageTextArea->setPreferredSize(Vec2f(600, 150));
    _MessageTextArea->setText("");
    _MessageTextArea->setMinSize(Vec2f(300, 150));
    _MessageTextArea->setFont(_CodeFont);
    _MessageTextArea->setTextColors(Color4f(0.2,0.0,0.0,1.0));
    _MessageTextArea->setEditable(false);
    setName(_MessageTextArea,"Message TextArea");

    // Create a ScrollPanel
    ScrollPanelRefPtr MessageAreaScrollPanel = ScrollPanel::create();
    MessageAreaScrollPanel->setPreferredSize(Vec2f(200,150));
    MessageAreaScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW);
    // Add the TextArea to the ScrollPanel so it is displayed
    MessageAreaScrollPanel->setViewComponent(_MessageTextArea);

    //Create the Message Text Area
    _HelpTextArea = TextArea::create();

    _HelpTextArea->setPreferredSize(Vec2f(600, 150));
    _HelpTextArea->setText("");
    _HelpTextArea->setMinSize(Vec2f(300, 150));
    _HelpTextArea->setFont(_CodeFont);
    _HelpTextArea->setTextColors(Color4f(0.2,0.0,0.0,1.0));
    _HelpTextArea->setEditable(false);
    setName(_HelpTextArea,"Help TextArea");

    // Create a ScrollPanel
    ScrollPanelRefPtr HelpAreaScrollPanel = ScrollPanel::create();
    HelpAreaScrollPanel->setPreferredSize(Vec2f(200,150));
    HelpAreaScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW);
    // Add the TextArea to the ScrollPanel so it is displayed
    HelpAreaScrollPanel->setViewComponent(_HelpTextArea);

    //Tab Panel
    LabelRefPtr MessageTabLabel = Label::create();
    MessageTabLabel->setText("Output");

    LabelRefPtr ErrorTabLabel = Label::create();
    ErrorTabLabel->setText("Error");

    LabelRefPtr StackTraceTabLabel = Label::create();
    StackTraceTabLabel->setText("Stack");

    LabelRefPtr HelpTabLabel = Label::create();
    HelpTabLabel->setText("Help");

    _InfoTabPanel = TabPanel::create();
    _InfoTabPanel->addTab(MessageTabLabel, MessageAreaScrollPanel);
    _InfoTabPanel->addTab(ErrorTabLabel, ErrorAreaScrollPanel);
    _InfoTabPanel->addTab(StackTraceTabLabel, StackTraceAreaScrollPanel);
    _InfoTabPanel->addTab(HelpTabLabel, HelpAreaScrollPanel);
#ifdef OSG_WITH_LUA_DEBUGGER
    addIntrospectionTreeTab(_InfoTabPanel);
#endif
    _InfoTabPanel->setTabAlignment(0.5f);
    _InfoTabPanel->setTabPlacement(TabPanel::PLACEMENT_NORTH);
    _InfoTabPanel->setSelectedIndex(0);
    setName(_InfoTabPanel,"Info Tab Panel");
}
PanelUnrecPtr createMultiFieldPanel(void)
{
    //Popup Menu
    MenuItemRefPtr RemoveIndexMenuItem = MenuItem::create();
    RemoveIndexMenuItem->setText("Remove Index");
    RemoveIndexMenuItem->addActionListener(new RemoveMultiFieldActionListener());

    MenuItemRefPtr SetValueMenuItem = MenuItem::create();
    SetValueMenuItem->setText("Set Value");
    SetValueMenuItem->addActionListener(new SetMultiFieldActionListener());
    
    MenuItemRefPtr AddValueMenuItem = MenuItem::create();
    AddValueMenuItem->setText("Add Value");
    AddValueMenuItem->addActionListener(new AddMultiFieldActionListener());
    
    MenuItemRefPtr InsertIndexMenuItem = MenuItem::create();
    InsertIndexMenuItem->setText("Insert Value");
    InsertIndexMenuItem->addActionListener(new InsertMultiFieldActionListener());
    
    MenuItemRefPtr MoveIndexMenuItem = MenuItem::create();
    MoveIndexMenuItem->setText("Move Value");
    MoveIndexMenuItem->addActionListener(new MoveMultiFieldActionListener());
    
    MenuItemRefPtr SwapIndexMenuItem = MenuItem::create();
    SwapIndexMenuItem->setText("Swap Value");
    SwapIndexMenuItem->addActionListener(new SwapMultiFieldActionListener());

    PopupMenuRefPtr MultiFieldListPopupMenu = PopupMenu::create();
    MultiFieldListPopupMenu->addItem(SetValueMenuItem);
    MultiFieldListPopupMenu->addItem(AddValueMenuItem);
    MultiFieldListPopupMenu->addItem(InsertIndexMenuItem);
    MultiFieldListPopupMenu->addItem(MoveIndexMenuItem);
    MultiFieldListPopupMenu->addItem(SwapIndexMenuItem);
    MultiFieldListPopupMenu->addItem(RemoveIndexMenuItem);

    //Multi-field List Model
	MultiFieldListModel = MFieldListModel::create();
    MultiFieldListModel->setContainer(TutorialBackground);
    MultiFieldListModel->setFieldId(GradientBackground::ColorFieldId);
    //MultiFieldListModel->setFieldId(GradientBackground::PositionFieldId);

    //List
    MultiFieldList = List::create();
    MultiFieldList->setPreferredSize(Vec2f(200, 300));
    MultiFieldList->setOrientation(List::VERTICAL_ORIENTATION);
	MultiFieldList->setModel(MultiFieldListModel);
    ListSelectionModelPtr MultiFieldListSelectionModel(new DefaultListSelectionModel());
    MultiFieldList->setSelectionModel(MultiFieldListSelectionModel);
    MultiFieldList->setPopupMenu(MultiFieldListPopupMenu);

    // Create a ScrollPanel for easier viewing of the List
    ScrollPanelRefPtr ExampleScrollPanel = ScrollPanel::create();
        ExampleScrollPanel->setPreferredSize(Vec2f(200,300));
        ExampleScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW);
    ExampleScrollPanel->setViewComponent(MultiFieldList);

    // Create MainFramelayout
    FlowLayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create();
    MainInternalWindowLayout->setOrientation(FlowLayout::VERTICAL_ORIENTATION);
    MainInternalWindowLayout->setMajorAxisAlignment(0.5f);
    MainInternalWindowLayout->setMinorAxisAlignment(0.5f);

    //Label
    LabelRefPtr ListLabel = Label::create();
    ListLabel->setText("Background Colors List");
    ListLabel->setPreferredSize(Vec2f(200.0f, ListLabel->getPreferredSize().y()));


    //Panel
    FlowLayoutRefPtr ThePanelLayout = OSG::FlowLayout::create();
    ThePanelLayout->setOrientation(FlowLayout::VERTICAL_ORIENTATION);
    ThePanelLayout->setMajorAxisAlignment(0.5f);
    ThePanelLayout->setMinorAxisAlignment(0.5f);

    PanelRefPtr ThePanel = Panel::createEmpty();
    ThePanel->setLayout(ThePanelLayout);
    ThePanel->pushToChildren(ListLabel);
    ThePanel->pushToChildren(ExampleScrollPanel);

    return ThePanel;
    
}
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);

    // Make Torus Node (creates Torus in background of scene)
    NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);

    // Make Main Scene Node and add the Torus
    NodeRefPtr scene = OSG::Node::create();
        scene->setCore(OSG::Group::create());
        scene->addChild(TorusGeometryNode);

    // Create the Graphics
    GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create();

    // Initialize the LookAndFeelManager to enable default settings
    LookAndFeelManager::the()->getLookAndFeel()->init();

    //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;
}
PanelUnrecPtr createMultiPtrFieldPanel(void)
{
    //Buttons for Inner Panel
    ButtonRefPtr AButton = Button::create();
    AButton->setText("A");

    ButtonRefPtr BButton = Button::create();
    BButton->setText("B");

    //Inner Panel
    LayoutRefPtr MultiPtrFieldInnerPanelLayout = OSG::FlowLayout::create();

    MultiPtrFieldInnerPanel = OSG::Panel::create();
    MultiPtrFieldInnerPanel->setLayout(MultiPtrFieldInnerPanelLayout);
    MultiPtrFieldInnerPanel->setPreferredSize(Vec2f(200.0f, 200.0f));
    MultiPtrFieldInnerPanel->pushToChildren(AButton);
    MultiPtrFieldInnerPanel->pushToChildren(BButton);

    //Popup Menu
    MenuItemRefPtr RemoveIndexMenuItem = MenuItem::create();
    RemoveIndexMenuItem->setText("Remove Index");
    RemoveIndexMenuItem->addActionListener(new RemoveMultiPtrFieldActionListener());

    MenuItemRefPtr SetValueMenuItem = MenuItem::create();
    SetValueMenuItem->setText("Set Value");
    SetValueMenuItem->addActionListener(new SetMultiPtrFieldActionListener());
    
    MenuItemRefPtr AddValueMenuItem = MenuItem::create();
    AddValueMenuItem->setText("Add Value");
    AddValueMenuItem->addActionListener(new AddMultiPtrFieldActionListener());
    
    MenuItemRefPtr InsertIndexMenuItem = MenuItem::create();
    InsertIndexMenuItem->setText("Insert Value");
    InsertIndexMenuItem->addActionListener(new InsertMultiPtrFieldActionListener());
    
    MenuItemRefPtr MoveIndexMenuItem = MenuItem::create();
    MoveIndexMenuItem->setText("Move Value");
    MoveIndexMenuItem->addActionListener(new MoveMultiPtrFieldActionListener());
    
    MenuItemRefPtr SwapIndexMenuItem = MenuItem::create();
    SwapIndexMenuItem->setText("Swap Value");
    SwapIndexMenuItem->addActionListener(new SwapMultiPtrFieldActionListener());

    PopupMenuRefPtr MultiPtrFieldListPopupMenu = PopupMenu::create();
    MultiPtrFieldListPopupMenu->addItem(SetValueMenuItem);
    MultiPtrFieldListPopupMenu->addItem(AddValueMenuItem);
    MultiPtrFieldListPopupMenu->addItem(InsertIndexMenuItem);
    MultiPtrFieldListPopupMenu->addItem(MoveIndexMenuItem);
    MultiPtrFieldListPopupMenu->addItem(SwapIndexMenuItem);
    MultiPtrFieldListPopupMenu->addItem(RemoveIndexMenuItem);

    //Multi-field List Model
	MultiPtrFieldListModel = MFieldListModel::create();
    MultiPtrFieldListModel->setContainer(MultiPtrFieldInnerPanel);
    MultiPtrFieldListModel->setFieldId(Panel::ChildrenFieldId);

    //List
    MultiPtrFieldList = List::create();
    MultiPtrFieldList->setPreferredSize(Vec2f(200, 300));
    MultiPtrFieldList->setOrientation(List::VERTICAL_ORIENTATION);
	MultiPtrFieldList->setModel(MultiPtrFieldListModel);
    ListSelectionModelPtr MultiPtrFieldListSelectionModel(new DefaultListSelectionModel());
    MultiPtrFieldList->setSelectionModel(MultiPtrFieldListSelectionModel);
    MultiPtrFieldList->setPopupMenu(MultiPtrFieldListPopupMenu);

    // Create a ScrollPanel for easier viewing of the List
    ScrollPanelRefPtr ExampleScrollPanel = ScrollPanel::create();
        ExampleScrollPanel->setPreferredSize(Vec2f(200,300));
        ExampleScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW);
    ExampleScrollPanel->setViewComponent(MultiPtrFieldList);


    LayoutRefPtr ThePanelLayout = OSG::FlowLayout::create();

    PanelRefPtr ThePanel = Panel::createEmpty();
    ThePanel->setLayout(ThePanelLayout);
    ThePanel->pushToChildren(MultiPtrFieldInnerPanel);
    ThePanel->pushToChildren(ExampleScrollPanel);

    return ThePanel;
    
}
Пример #8
0
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);
}
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;
}