示例#1
0
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

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

        // Create the SimpleSceneManager helper
        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);

        TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1));

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

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

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

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


        // Create a simple Font to be used with the PasswordField
        UIFontRecPtr ExampleFont = UIFont::create();
        ExampleFont->setSize(16);

        /******************************************************


          Create and edit a PasswordField.

          A PasswordField is a TextField 
          which allows for text to be
          entered secretly.

          -setEchoCar("char"): Determine
          which character replaces text in the 
          PasswordField.

          See 16TextField for more information.

         ******************************************************/

        TextFieldRecPtr ExampleTextField = TextField::create();
        ExampleTextField->setText("");
        ExampleTextField->setEmptyDescText("username");
        ExampleTextField->setPreferredSize(Vec2f(130.0f,ExampleTextField->getPreferredSize().y()));

        PasswordFieldRecPtr ExamplePasswordField = PasswordField::create();

        ExamplePasswordField->setPreferredSize(Vec2f(130, ExamplePasswordField->getPreferredSize().y()));
        ExamplePasswordField->setTextColor(Color4f(0.0, 0.0, 0.0, 1.0));
        ExamplePasswordField->setSelectionBoxColor(Color4f(0.0, 0.0, 1.0, 1.0));
        ExamplePasswordField->setSelectionTextColor(Color4f(1.0, 1.0, 1.0, 1.0));
        //ExamplePasswordField->setText("Text");
        // "Text" will be replaced by "####" in the PasswordField
        ExamplePasswordField->setEchoChar("#");
        ExamplePasswordField->setEditable(true);
        ExamplePasswordField->setFont(ExampleFont);
        ExamplePasswordField->setSelectionStart(2);
        ExamplePasswordField->setSelectionEnd(3);
        ExamplePasswordField->setAlignment(Vec2f(0.0,0.5));

        ExamplePasswordField->setEmptyDescText("password");

        // Create The Main InternalWindow
        // Create Background to be used with the Main InternalWindow
        ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create();
        MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));

        FlowLayoutRecPtr MainInternalWindowLayout = FlowLayout::create();
        MainInternalWindowLayout->setOrientation(FlowLayout::VERTICAL_ORIENTATION);

        InternalWindowRecPtr MainInternalWindow = InternalWindow::create();
        MainInternalWindow->pushToChildren(ExampleTextField);
        MainInternalWindow->pushToChildren(ExamplePasswordField);
        MainInternalWindow->setLayout(MainInternalWindowLayout);
        MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
        MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
        MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f));
        MainInternalWindow->setDrawTitlebar(false);
        MainInternalWindow->setResizable(false);

        // Create the Drawing Surface
        UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create();
        TutorialDrawingSurface->setGraphics(TutorialGraphics);
        TutorialDrawingSurface->setEventProducer(TutorialWindow);

        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,
                                   "24PasswordField");

        //Enter main Loop
        TutorialWindow->mainLoop();
    }

    osgExit();

    return 0;
}
示例#2
0
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

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

        // Create the SimpleSceneManager helper
        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);

        TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1));

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

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

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

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

        // Create a simple Font to be used with the TextField
        UIFontRecPtr sampleFont = UIFont::create();
        sampleFont->setSize(16);

        /******************************************************


          Create and edit the TextField.  A TextField is 
          a Component which allows a single line of text
          to be displayed.  Text can be entered via the
          keyboard, and selected with arrow keys or
          the Mouse.

          -setTextColor(Color4f): Determine the 
          Text Color.
          setSelectionBoxColor(Color4f): Determine
          the Color of highlighting around
          selected Text.
          -setSelectionTextColor(Color4f): Determine
          the Color of selected Text.
          -setText("TextToBeDisplayed"): Determine
          initial Text within TextField.
          -setFont(FontName): Determine the Font
          used within TextField.
          -setSelectionStart(StartCharacterNumber):
          Determine the character with which  
          the selection will initially start.
          -setSelectionEnd(EndCharacterNumber): 
          Determine the character which the
          selection ends before.
          -setAlignment(float): Determine 
          the alignment of the text.  
          The float is a percentage is from the 
          top of the text [0.0-1.0].  Note: be 
          sure to visually verify this, as due
          to font size and line size this does
          not always place it exactly
          at the percentage point.

         ******************************************************/

        // Create a TextField component
        TextFieldRecPtr ExampleTextField = TextField::create();

        ExampleTextField->setPreferredSize(Vec2f(100, 50));
        ExampleTextField->setTextColor(Color4f(0.0, 0.0, 0.0, 1.0));
        ExampleTextField->setSelectionBoxColor(Color4f(0.0, 0.0, 1.0, 1.0));
        ExampleTextField->setSelectionTextColor(Color4f(1.0, 1.0, 1.0, 1.0));
        ExampleTextField->setText("What");
        ExampleTextField->setFont(sampleFont);
        // The next two functions will select the "a" from above
        ExampleTextField->setSelectionStart(2);
        ExampleTextField->setSelectionEnd(3);
        ExampleTextField->setAlignment(Vec2f(0.0,0.5));

        // Create another TextField Component
        TextFieldRecPtr ExampleTextField2 = TextField::create();
        ExampleTextField2->setText("");
        ExampleTextField2->setEmptyDescText("Write in me, please");
        ExampleTextField2->setPreferredSize(Vec2f(200.0f,ExampleTextField2->getPreferredSize().y()));


        // Create The Main InternalWindow
        // Create Background to be used with the Main InternalWindow
        ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create();
        MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));

        LayoutRecPtr MainInternalWindowLayout = FlowLayout::create();

        InternalWindowRecPtr MainInternalWindow = InternalWindow::create();
        MainInternalWindow->pushToChildren(ExampleTextField);
        MainInternalWindow->pushToChildren(ExampleTextField2);
        MainInternalWindow->setLayout(MainInternalWindowLayout);
        MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
        MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
        MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f));
        MainInternalWindow->setDrawTitlebar(false);
        MainInternalWindow->setResizable(false);

        // Create the Drawing Surface
        UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create();
        TutorialDrawingSurface->setGraphics(TutorialGraphics);
        TutorialDrawingSurface->setEventProducer(TutorialWindow);

        TutorialDrawingSurface->openWindow(MainInternalWindow);

        // Create the UI Foreground Object
        UIForegroundRecPtr TutorialUIForeground = UIForeground::create();

        TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);


        // Tell the Manager what to manage
        sceneManager.setRoot(scene);

        // Add the UI Foreground Object to the Scene
        ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0);
        TutorialViewport->addForeground(TutorialUIForeground);

        // Show the whole Scene
        sceneManager.showAll();


        //Open Window
        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "16TextField");

        //Enter main Loop
        TutorialWindow->mainLoop();
    }

    osgExit();

    return 0;
}
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);
}