PanelUnrecPtr createSinglePtrFieldPanel(void) { SinglePtrFieldLabel = OSG::Label::create(); SinglePtrFieldLabel->setText("Changable"); SinglePtrFieldLabel->setBorders(NULL); ButtonRefPtr SinglePtrFieldCreateBackgroundButton = OSG::Button::create(); SinglePtrFieldCreateBackgroundButton->setText("Create Background"); SinglePtrFieldCreateBackgroundButton->setPreferredSize(Vec2f(175.0f,SinglePtrFieldCreateBackgroundButton->getPreferredSize().y())); SinglePtrFieldCreateActionListener* TheCreateBackgroundActionListener = new SinglePtrFieldCreateActionListener(); SinglePtrFieldCreateBackgroundButton->addActionListener(TheCreateBackgroundActionListener); LayoutRefPtr ThePanelLayout = OSG::FlowLayout::create(); PanelRefPtr ThePanel = Panel::createEmpty(); ThePanel->setLayout(ThePanelLayout); ThePanel->pushToChildren(SinglePtrFieldLabel); ThePanel->pushToChildren(SinglePtrFieldCreateBackgroundButton); return ThePanel; }
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); }
DialogWindowUnrecPtr DialogWindow::createMessageDialog(const std::string& Title, const std::string& Message, const int& Type, const bool& showCancel, const std::string& ConfirmBtnText, const std::string& CancelBtnText) { ImageComponentRefPtr TheIcon = ImageComponent::create(); LineBorderRefPtr TempIconBorder = OSG::LineBorder::create(); TheIcon->setPreferredSize(Vec2f(45,45)); TheIcon->setBorders(TempIconBorder); 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 = createTransparentTextArea(Message); // 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)); // Create SplitPanel itself PanelRefPtr MessagePanel = OSG::Panel::createEmpty(); SpringLayoutRefPtr MessagePanelLayout = SpringLayout::create(); MessagePanel->pushToChildren(MessagePanelText); MessagePanel->pushToChildren(TheIcon); MessagePanel->pushToChildren(MessageButtonPanel); MessagePanel->setLayout(MessagePanelLayout); //MessagePanelLayout //Icon MessagePanelLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, TheIcon, 10, SpringLayoutConstraints::NORTH_EDGE, MessagePanel); MessagePanelLayout->putConstraint(SpringLayoutConstraints::WIDTH_EDGE, TheIcon, LayoutSpring::width(TheIcon)); MessagePanelLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, TheIcon, 10, SpringLayoutConstraints::WEST_EDGE, MessagePanel); MessagePanelLayout->putConstraint(SpringLayoutConstraints::HEIGHT_EDGE, TheIcon, LayoutSpring::height(TheIcon)); //Message MessagePanelLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, MessagePanelText, 5, SpringLayoutConstraints::NORTH_EDGE, MessagePanel); MessagePanelLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, MessagePanelText, -5, SpringLayoutConstraints::EAST_EDGE, MessagePanel); MessagePanelLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, MessagePanelText, 10, SpringLayoutConstraints::EAST_EDGE, TheIcon); MessagePanelLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, MessagePanelText, -30, SpringLayoutConstraints::SOUTH_EDGE, MessagePanel); //Button Panel MessagePanelLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, MessageButtonPanel, 0, SpringLayoutConstraints::WEST_EDGE, MessagePanel); MessagePanelLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, MessageButtonPanel, 0, SpringLayoutConstraints::EAST_EDGE, MessagePanel); MessagePanelLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, MessageButtonPanel, 20, SpringLayoutConstraints::SOUTH_EDGE, MessagePanel); //Internals Layout and constraints BorderLayoutConstraintsRefPtr MessagePanelConstraints = BorderLayoutConstraints::create(); MessagePanelConstraints->setRegion(BorderLayoutConstraints::BORDER_CENTER); MessagePanel->setConstraints(MessagePanelConstraints); BorderLayoutRefPtr DialogLayout = BorderLayout::create(); //Create the Dialog box DialogWindowRefPtr TheDialog = DialogWindow::create(); TheDialog->setLayout(DialogLayout); TheDialog->setPreferredSize(Vec2f(350,150)); TheDialog->pushToChildren(MessagePanel); 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 TheDialog; }
DialogWindowUnrecPtr DialogWindow::createInputDialog(const std::string& Title, const std::string& Message, const int& Type, const bool& showCancel, const std::vector<std::string>& InputValues, const std::string& ConfirmBtnText, const std::string& CancelBtnText) { int DialogHeight = 175; DialogWindowRefPtr TheDialog = DialogWindow::create(); ImageComponentRefPtr TheIcon = ImageComponent::create(); LineBorderRefPtr TempIconBorder = OSG::LineBorder::create(); TheIcon->setPreferredSize(Vec2f(45,45)); TheIcon->setBorders(TempIconBorder); // Create Panel for input PanelRefPtr InputPanel = OSG::Panel::createEmpty(); FlowLayoutRefPtr InputPanelLayout = OSG::FlowLayout::create(); InputPanel->setLayout(InputPanelLayout); InputPanel->setPreferredSize(Vec2f(450,75)); ButtonRefPtr InputButton; switch (Type) { case INPUT_TEXT: TheDialog->_InputTextField = OSG::TextField::create(); TheDialog->_InputTextField->setText(InputValues[0]); TheDialog->_InputTextField->setPreferredSize(Vec2f(200,25)); InputPanel->pushToChildren(TheDialog->_InputTextField); break; case INPUT_BTNS: DialogHeight = 150; for (std::vector<std::string>::const_iterator it = InputValues.begin(); it!=InputValues.end(); ++it) { InputButton = OSG::Button::create(); InputButton->setText(*it); InputButton->setMinSize(InputButton->getPreferredSize()); InputButton->setPreferredSize(InputButton->getRequestedSize()); InputButton->addActionListener(&TheDialog->_InputButtonListener); InputPanel->pushToChildren(InputButton); } break; case INPUT_COMBO: default: TheDialog->_InputComboBox = OSG::ComboBox::create(); DefaultMutableComboBoxModelRefPtr _InputComboBoxModel; _InputComboBoxModel = DefaultMutableComboBoxModel::create(); for (std::vector<std::string>::const_iterator it = InputValues.begin(); it!=InputValues.end(); ++it) { _InputComboBoxModel->addElement(boost::any(std::string(*it))); } TheDialog->_InputComboBox->setPreferredSize(Vec2f(150, 23)); TheDialog->_InputComboBox->setModel(_InputComboBoxModel); TheDialog->_InputComboBox->setSelectedIndex(0); InputPanel->pushToChildren(TheDialog->_InputComboBox); break; } FlowLayoutRefPtr MessagePanelBottomLayout; PanelRefPtr MessageButtonPanel; ButtonRefPtr ConfirmationButton; ButtonRefPtr CancelButton; if(Type != INPUT_BTNS) { ConfirmationButton = OSG::Button::create(); //Confirm Button ConfirmationButton->setText(ConfirmBtnText); ConfirmationButton->setMinSize(ConfirmationButton->getPreferredSize()); ConfirmationButton->setPreferredSize(ConfirmationButton->getRequestedSize()); if(Type == INPUT_TEXT) { ConfirmationButton->addActionListener(&TheDialog->_TextButtonListener); } else { ConfirmationButton->addActionListener(&TheDialog->_ComboButtonListener); } } if(showCancel) { CancelButton = OSG::Button::create(); //Cancel Button CancelButton->setText(CancelBtnText); CancelButton->setMinSize(CancelButton->getPreferredSize()); CancelButton->setPreferredSize(CancelButton->getRequestedSize()); //Attach listener to the Cancel button CancelButton->addActionListener(&TheDialog->_CancelButtonListener); } // Create Panel for top half of SplitPanel TextAreaRefPtr MessagePanelText = createTransparentTextArea(Message); //If the type of input is buttons and showCancel is true, just push the cancel button onto the input panel if(Type == INPUT_BTNS && showCancel) { InputPanel->pushToChildren(CancelButton); } else if(Type != INPUT_BTNS) { // Create Panel for bottom half of SplitPanel MessageButtonPanel = OSG::Panel::createEmpty(); MessagePanelBottomLayout = OSG::FlowLayout::create(); MessageButtonPanel->pushToChildren(ConfirmationButton); if(showCancel) MessageButtonPanel->pushToChildren(CancelButton); MessageButtonPanel->setLayout(MessagePanelBottomLayout); MessageButtonPanel->setPreferredSize(Vec2f(450,75)); } // Create SplitPanel itself PanelRefPtr MessagePanel = OSG::Panel::createEmpty(); SpringLayoutRefPtr MessagePanelLayout = SpringLayout::create(); MessagePanel->pushToChildren(MessagePanelText); MessagePanel->pushToChildren(TheIcon); MessagePanel->pushToChildren(InputPanel); if(Type != INPUT_BTNS) MessagePanel->pushToChildren(MessageButtonPanel); MessagePanel->setLayout(MessagePanelLayout); //MessagePanelLayout //Icon MessagePanelLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, TheIcon, 10, SpringLayoutConstraints::NORTH_EDGE, MessagePanel); MessagePanelLayout->putConstraint(SpringLayoutConstraints::WIDTH_EDGE, TheIcon, LayoutSpring::width(TheIcon)); MessagePanelLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, TheIcon, 10, SpringLayoutConstraints::WEST_EDGE, MessagePanel); MessagePanelLayout->putConstraint(SpringLayoutConstraints::HEIGHT_EDGE, TheIcon, LayoutSpring::height(TheIcon)); //Message MessagePanelLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, MessagePanelText, 5, SpringLayoutConstraints::NORTH_EDGE, MessagePanel); MessagePanelLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, MessagePanelText, -5, SpringLayoutConstraints::EAST_EDGE, MessagePanel); MessagePanelLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, MessagePanelText, 10, SpringLayoutConstraints::EAST_EDGE, TheIcon); MessagePanelLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, MessagePanelText, 20, SpringLayoutConstraints::NORTH_EDGE, InputPanel); //Input Panel MessagePanelLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, InputPanel, 0, SpringLayoutConstraints::WEST_EDGE, MessagePanel); MessagePanelLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, InputPanel, 0, SpringLayoutConstraints::EAST_EDGE, MessagePanel); if(Type != INPUT_BTNS) { MessagePanelLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, InputPanel, 40, SpringLayoutConstraints::NORTH_EDGE, MessageButtonPanel); //Button Panel MessagePanelLayout->putConstraint(SpringLayoutConstraints::HEIGHT_EDGE, MessageButtonPanel, LayoutSpring::height(MessageButtonPanel)); MessagePanelLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, MessageButtonPanel, 0, SpringLayoutConstraints::WEST_EDGE, MessagePanel); MessagePanelLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, MessageButtonPanel, 0, SpringLayoutConstraints::EAST_EDGE, MessagePanel); MessagePanelLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, MessageButtonPanel, 20, SpringLayoutConstraints::SOUTH_EDGE, MessagePanel); } else { MessagePanelLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, InputPanel, 20, SpringLayoutConstraints::SOUTH_EDGE, MessagePanel); } //Internals Layout and constraints BorderLayoutConstraintsRefPtr MessagePanelConstraints = BorderLayoutConstraints::create(); MessagePanelConstraints->setRegion(BorderLayoutConstraints::BORDER_CENTER); MessagePanel->setConstraints(MessagePanelConstraints); BorderLayoutRefPtr DialogLayout = BorderLayout::create(); //Create the Dialog box TheDialog->setLayout(DialogLayout); TheDialog->setPreferredSize(Vec2f(350,DialogHeight)); TheDialog->pushToChildren(MessagePanel); TheDialog->setTitle(Title); return TheDialog; }