virtual void buttonSelected(const ButtonSelectedEventUnrecPtr e) { LeftPanelTextArea->setTextColor(Color4f( 0.0, 1.0 , 0.0, 1.0)); LeftPanelTextArea->setRolloverTextColor(Color4f( 0.0, 1.0 , 0.0, 1.0)); }
void LuaDebuggerInterface::handlLuaError(LuaErrorEventDetails* const details) { std::string ErrorType(""); switch(details->getStatus()) { case LUA_ERRSYNTAX: //Syntax Error ErrorType = "Lua Syntax Error"; break; case LUA_ERRMEM: //Memory Allocation Error ErrorType = "Lua Memory Allocation Error"; break; case LUA_ERRRUN: //Memory Allocation Error ErrorType = "Lua Runtime Error"; break; case LUA_ERRERR: //Memory Allocation Error ErrorType = "Lua Error in Error Handler"; break; default: //Unknown ErrorType = "Lua Unknown Error"; break; } _ErrorTextArea->moveCaretToEnd(); if(_ErrorTextArea->getText().size() != 0) { _ErrorTextArea->write("\n"); } _ErrorTextArea->write(ErrorType + ":\n " + details->getErrorString()); //Select the Error Tab _InfoTabPanel->setSelectedIndex(1); //Fill Stack Trace if(details->getStatus() == LUA_ERRMEM || details->getStatus() == LUA_ERRERR || details->getStatus() == LUA_ERRRUN) { std::stringstream ss; ss << "Lua Stack Trace: " << std::endl << TheLuaManager->getCallStack() << std::endl; _StackTraceTextArea->write(ss.str()); } }
TextAreaRefPtr DialogWindow::createTransparentTextArea(const std::string& Message) { TextAreaRefPtr TransparentTextArea = OSG::TextArea::create(); EmptyLayerRefPtr TransparentTextAreaBackground = OSG::EmptyLayer::create(); EmptyBorderRefPtr TransparentTextAreaBorder = OSG::EmptyBorder::create(); TransparentTextArea->setBorders(TransparentTextAreaBorder); TransparentTextArea->setBackgrounds(TransparentTextAreaBackground); TransparentTextArea->setWrapStyleWord(true); TransparentTextArea->setText(Message); TransparentTextArea->setEditable(false); return TransparentTextArea; }
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; }
void LuaDebuggerInterface::clearError(void) { _ErrorTextArea->setText(""); _StackTraceTextArea->setText(""); }
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"); }
DialogWindowUnrecPtr DialogWindow::createColorChooserDialog(const std::string& Title, const std::string& Message, bool showAlpha, ColorSelectionModelPtr colorModel, bool showCancel, const std::string& ConfirmBtnText, const std::string& CancelBtnText) { ButtonRefPtr ConfirmationButton = OSG::Button::create(); ButtonRefPtr CancelButton; //Confirm Button ConfirmationButton->setText(ConfirmBtnText); ConfirmationButton->setMinSize(ConfirmationButton->getPreferredSize()); ConfirmationButton->setPreferredSize(ConfirmationButton->getRequestedSize()); if(showCancel) { //Cancel Button CancelButton = OSG::Button::create(); CancelButton->setText(CancelBtnText); CancelButton->setMinSize(CancelButton->getPreferredSize()); CancelButton->setPreferredSize(CancelButton->getRequestedSize()); } // Create Panel for top half of SplitPanel TextAreaRefPtr MessagePanelText = OSG::TextArea::create(); MessagePanelText->setBorders(NULL); MessagePanelText->setPreferredSize(Vec2f(100.0f, 100.0f)); MessagePanelText->setBackgrounds(NULL); MessagePanelText->setWrapStyleWord(true); MessagePanelText->setText(Message); MessagePanelText->setEditable(false); // Create Panel for bottom half of SplitPanel PanelRefPtr MessageButtonPanel = OSG::Panel::createEmpty(); FlowLayoutRefPtr MessagePanelBottomLayout = OSG::FlowLayout::create(); MessageButtonPanel->pushToChildren(ConfirmationButton); if(showCancel) MessageButtonPanel->pushToChildren(CancelButton); MessageButtonPanel->setLayout(MessagePanelBottomLayout); MessageButtonPanel->setPreferredSize(Vec2f(450,75)); PanelRefPtr MessagePanel = OSG::Panel::createEmpty(); SpringLayoutRefPtr MessagePanelLayout = SpringLayout::create(); MessagePanel->pushToChildren(MessagePanelText); MessagePanel->pushToChildren(MessageButtonPanel); MessagePanel->setLayout(MessagePanelLayout); ColorChooserRefPtr TheColorChooser = ColorChooser::create(); TheColorChooser->setSelectionModel(colorModel); //Internals Layout and constraints DialogWindowUnrecPtr TheDialog = DialogWindow::create(); SpringLayoutRefPtr DialogLayout = SpringLayout::create(); //Message Text DialogLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, MessagePanelText, 5, SpringLayoutConstraints::NORTH_EDGE, TheDialog); DialogLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, MessagePanelText, -5, SpringLayoutConstraints::EAST_EDGE, TheDialog); DialogLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, MessagePanelText, 5, SpringLayoutConstraints::WEST_EDGE, TheDialog); //Color Chooser DialogLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, TheColorChooser, 5, SpringLayoutConstraints::SOUTH_EDGE, MessagePanelText); DialogLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, TheColorChooser, -5, SpringLayoutConstraints::EAST_EDGE, TheDialog); DialogLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, TheColorChooser, 5, SpringLayoutConstraints::WEST_EDGE, TheDialog); DialogLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, TheColorChooser, -5, SpringLayoutConstraints::NORTH_EDGE, MessageButtonPanel); //Button Panel DialogLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, MessageButtonPanel, 0, SpringLayoutConstraints::WEST_EDGE, TheDialog); DialogLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, MessageButtonPanel, 0, SpringLayoutConstraints::EAST_EDGE, TheDialog); DialogLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, MessageButtonPanel, 20, SpringLayoutConstraints::SOUTH_EDGE, TheDialog); //Create the Dialog box TheDialog->setLayout(DialogLayout); TheDialog->setPreferredSize(Vec2f(350,400)); TheDialog->pushToChildren(MessagePanelText); TheDialog->pushToChildren(TheColorChooser); TheDialog->pushToChildren(MessageButtonPanel); TheDialog->setTitle(Title); //Attach listener to the Confirm button ConfirmationButton->addActionListener(&TheDialog->_ConfirmButtonListener); if(showCancel) { //Attach listener to the Cancel button CancelButton->addActionListener(&TheDialog->_CancelButtonListener); } return DialogWindowTransitPtr(TheDialog); }
ComponentRefPtr createLeftPanelRadioTextPanel(void) { // Create the RadioButton group RadioButtonRefPtr RadioButton1 = OSG::RadioButton::create(); RadioButtonRefPtr RadioButton2 = OSG::RadioButton::create(); RadioButtonRefPtr RadioButton3 = OSG::RadioButton::create(); RadioButtonRefPtr RadioButton4 = OSG::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->addButtonSelectedListener(&RadioButton1Listener); RadioButton2->setAlignment(Vec2f(0.0,0.5)); RadioButton2->setPreferredSize(Vec2f(100, 40)); RadioButton2->setText("Red Text"); RadioButton2->setToolTipText("Set TextArea text red"); RadioButton2->addButtonSelectedListener(&RadioButton2Listener); RadioButton3->setAlignment(Vec2f(0.0,0.5)); RadioButton3->setPreferredSize(Vec2f(100, 40)); RadioButton3->setText("Green Text"); RadioButton3->setToolTipText("Set TextArea text green"); RadioButton3->addButtonSelectedListener(&RadioButton3Listener); RadioButton4->setAlignment(Vec2f(0.0,0.5)); RadioButton4->setPreferredSize(Vec2f(100, 40)); RadioButton4->setText("Blue Text"); RadioButton4->setToolTipText("Set TextArea text blue"); RadioButton4->addButtonSelectedListener(&RadioButton4Listener); buttonGroup = RadioButtonGroup::create(); buttonGroup->addButton(RadioButton1); buttonGroup->addButton(RadioButton2); buttonGroup->addButton(RadioButton3); buttonGroup->addButton(RadioButton4); // Create TextArea LeftPanelTextArea = OSG::TextArea::create(); LeftPanelTextArea->setPreferredSize(Vec2f(125, 200)); // Create Panel and its Background/Border to label TextField LabelRefPtr LeftPanelTextFieldLabel = OSG::Label::create(); EmptyLayerRefPtr LeftPanelTextFieldLabelBackground = OSG::EmptyLayer::create(); EmptyBorderRefPtr LeftPanelTextFieldLabelBorder = OSG::EmptyBorder::create(); LeftPanelTextFieldLabel->setPreferredSize(Vec2f(100, 25)); LeftPanelTextFieldLabel->setBorders(LeftPanelTextFieldLabelBorder); LeftPanelTextFieldLabel->setBackgrounds(LeftPanelTextFieldLabelBackground); LeftPanelTextFieldLabel->setText("Text Field"); // Create TextField TextFieldRefPtr LeftPanelTextField = OSG::TextField::create(); LeftPanelTextField->setPreferredSize(Vec2f(125.0f, 22.0f)); // Create an edit Panel Background ColorLayerRefPtr LeftPanelRadioTextPanelBackground = OSG::ColorLayer::create(); LeftPanelRadioTextPanelBackground->setColor(Color4f(0.93f,0.93f,0.93f,1.0f)); // Create and edit Panel layouts FlowLayoutRefPtr LeftPanelRadioTextPanelLayout = OSG::FlowLayout::create(); FlowLayoutRefPtr LeftPanelRadioTextPanelRadioPanelLayout = OSG::FlowLayout::create(); FlowLayoutRefPtr LeftPanelRadioTextPanelTextPanelLayout = OSG::FlowLayout::create(); LeftPanelRadioTextPanelLayout->setMinorAxisAlignment(0.0f); // Create two Panels for this Panel PanelRefPtr LeftPanelRadioTextPanelRadioPanel = OSG::Panel::create(); PanelRefPtr LeftPanelRadioTextPanelTextPanel = OSG::Panel::create(); // Create some Borders EmptyBorderRefPtr LeftPanelRadioTextPanelRadioPanelBorder = OSG::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 LineBorderRefPtr PanelBorder1 = OSG::LineBorder::create(); PanelBorder1->setColor(Color4f(0.0,0.0,0.0,1.0)); PanelBorder1->setWidth(1); // Create and edit Panel PanelRefPtr LeftPanelRadioTextPanel = OSG::Panel::create(); 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 LeftPanelRadioTextPanel; }