void App::chkGhampRev(WP wp) { pSet->gui.champ_rev = !pSet->gui.champ_rev; ButtonPtr chk = wp->castType<MyGUI::Button>(); chk->setStateSelected(pSet->gui.champ_rev); ChampsListUpdate(); }
ButtonPtr Button::create(const std::string& normalImage, const std::string& selectedImage, const std::string& pressedImage, const std::string& disabledImage, const std::string& label, const graphics::Color& labelColor, const std::string& font) { ButtonPtr result = std::make_shared<Button>(); result->init(normalImage, selectedImage, pressedImage, disabledImage, label, labelColor, font); return result; }
Button* Interpreter::AddButton( const ButtonClickedSignature::Delegate& listener ) { ButtonPtr control = new Button (); control->ButtonClickedEvent().Add( listener ); m_ContainerStack.Get().top()->AddChild(control); return control; }
ButtonPtr ReflectStlVectorInterpreter::AddAddButton( List* list ) { ButtonPtr addButton =CreateControl< Button >(); addButton->ButtonClickedEvent().Add( ButtonClickedSignature::Delegate ( this, &ReflectStlVectorInterpreter::OnAdd ) ); addButton->SetClientData( new ClientData( list ) ); addButton->a_Label.Set( TXT( "Add" ) ); addButton->a_HelpText.Set( TXT( "Add an item to the list." ) ); return addButton; }
ButtonPtr ReflectStlVectorInterpreter::AddRemoveButton( List* list ) { ButtonPtr removeButton = CreateControl< Button >(); removeButton->a_Label.Set( TXT( "Remove" ) ); removeButton->ButtonClickedEvent().Add( ButtonClickedSignature::Delegate ( this, &ReflectStlVectorInterpreter::OnRemove ) ); removeButton->SetClientData( new ClientData( list ) ); removeButton->a_HelpText.Set( TXT( "Remove the selected item(s) from the list." ) ); return removeButton; }
ButtonPtr ReflectStlVectorInterpreter::AddMoveDownButton( List* list ) { ButtonPtr downButton = CreateControl< Button >(); downButton->a_Icon.Set( TXT( "actions/go-down" ) ); downButton->ButtonClickedEvent().Add( ButtonClickedSignature::Delegate ( this, &ReflectStlVectorInterpreter::OnMoveDown ) ); downButton->SetClientData( new ClientData( list ) ); downButton->a_HelpText.Set( TXT( "Move the selected item(s) down the list." ) ); return downButton; }
JoiningGameWindow::JoiningGameWindow() { using namespace phui; setTitle("Joining Game..."); setLayout(new BoxLayout(BoxLayout::VERTICAL)); setSize(400, 150); ButtonPtr cancel = new Button("Cancel"); cancel->addListener(this, &JoiningGameWindow::onCancel); add(new phui::Label("Joining Game...")); add(cancel); }
void MenuBar::insertItem(size_t _index, const Ogre::UTFString & _item) { MYGUI_ASSERT(_index < mVectorMenuItemInfo.size() || _index == ITEM_NONE, "index '" << _index << "' out of range"); if (_index == ITEM_NONE) _index = mVectorMenuItemInfo.size(); ButtonPtr button = mWidgetClient->createWidget<Button>(mButtonSkinName, IntCoord(), ALIGN_DEFAULT); button->eventMouseButtonPressed = newDelegate(this, &MenuBar::eventMouseButtonPressed); button->setCaption(_item); PopupMenuPtr menu = Gui::getInstance().createWidget<PopupMenu>("PopupMenu", IntCoord(), ALIGN_DEFAULT, "Popup"); menu->eventPopupMenuClose = newDelegate(this, &MenuBar::notifyPopupMenuClose); menu->eventPopupMenuAccept = newDelegate(this, &MenuBar::notifyPopupMenuAccept); menu->_setOwner(this); mVectorMenuItemInfo.insert(mVectorMenuItemInfo.begin() + _index, MenuItemInfo(button, menu)); update(); }
bool SettingsDialog::initDialog() { // set this to IDH_STARTPAGE so that clicking in an empty space of the dialog generates a WM_HELP message with no error; then SettingsDialog::handleHelp will convert IDH_STARTPAGE to the current page's help id setHelpId(IDH_STARTPAGE); WinUtil::setHelpIds(this, helpItems); setText(T_("Settings")); attachChild(pageTree, IDC_SETTINGS_PAGES); pageTree->onSelectionChanged(std::tr1::bind(&SettingsDialog::handleSelectionChanged, this)); { ButtonPtr button = attachChild<Button>(IDOK); button->setText(T_("OK")); button->onClicked(std::tr1::bind(&SettingsDialog::handleOKClicked, this)); button = attachChild<Button>(IDCANCEL); button->setText(T_("Cancel")); button->onClicked(std::tr1::bind(&SettingsDialog::endDialog, this, IDCANCEL)); button = attachChild<Button>(IDHELP); button->setText(T_("Help")); button->onClicked(std::tr1::bind(&SettingsDialog::handleHelp, this, handle(), IDH_STARTPAGE)); } addPage(T_("Personal information"), new GeneralPage(this)); addPage(T_("Connection settings"), new NetworkPage(this)); { HTREEITEM item = addPage(T_("Downloads"), new DownloadPage(this)); addPage(T_("Favorites"), new FavoriteDirsPage(this), item); addPage(T_("Queue"), new QueuePage(this), item); } addPage(T_("Sharing"), new UploadPage(this)); { HTREEITEM item = addPage(T_("Appearance"), new AppearancePage(this)); addPage(T_("Colors and sounds"), new Appearance2Page(this), item); addPage(T_("Tabs"), new TabsPage(this), item); addPage(T_("Windows"), new WindowsPage(this), item); } { HTREEITEM item = addPage(T_("Advanced"), new AdvancedPage(this)); addPage(T_("Logs"), new LogPage(this), item); addPage(T_("Experts only"), new Advanced3Page(this), item); addPage(T_("User Commands"), new UCPage(this), item); addPage(T_("Security Certificates"), new CertificatesPage(this), item); } addPage(TSTRING(SETTINGS_APPEARANCE_PAGE), new FdmAppearancePage(this)); addPage(TSTRING(SETTINGS_BANDWIDTH), new BandwidthLimitPage(this)); addPage(TSTRING(SETTINGS_SPAM), new FdmSpamPage(this)); updateTitle(); return false; }
/***************************************************************************\ * Instance methods * \***************************************************************************/ ComponentPtr DefaultDialogComponentGenerator::getResponseComponent(DialogInterfacePtr Parent, const boost::any& Value) { std::string responseString(""); try { responseString = lexical_cast(Value); } catch (boost::bad_lexical_cast &) { std::cout<<"Unable to display response"<<std::endl; } ButtonPtr TheResponseButton = Button::Ptr::dcast(getResponseButtonPrototype()->shallowCopy()); beginEditCP(TheResponseButton, Button::TextFieldMask); TheResponseButton->setText(responseString); endEditCP(TheResponseButton, Button::TextFieldMask); return TheResponseButton; }
FdmAppearancePage::FdmAppearancePage(dwt::Widget* parent) : PropPage(parent) { createDialog(IDD_FDM_APPEARANCE_PAGE); PropPage::fdmTranslate(handle(), texts); PropPage::fdmRead(handle(), items, listItems, ::GetDlgItem(handle(), IDC_FDM_APPEARANCE_BOOLEANS)); opSpoke = SETTING(OP_SPOKE_COLOUR); notOpSpoke = SETTING(NOT_OP_SPOKE_COLOUR); iSpoke = SETTING(I_SPOKE_COLOUR); myNickSpoken = SETTING(MY_NICK_SPOKEN_COLOUR); ButtonPtr button = attachChild<Button>(IDC_FDM_SETTINGS_BROWSE); button->onClicked(std::tr1::bind(&FdmAppearancePage::handleBrowse, this)); button = attachChild<Button>(IDC_FDM_SETTINGS_OP_SPOKE); button->onClicked(std::tr1::bind(&FdmAppearancePage::handleOpSpoke, this)); button = attachChild<Button>(IDC_FDM_SETTINGS_NOT_OP_SPOKE); button->onClicked(std::tr1::bind(&FdmAppearancePage::handleNotOpSpoke, this)); button = attachChild<Button>(IDC_FDM_SETTINGS_I_SPOKE); button->onClicked(std::tr1::bind(&FdmAppearancePage::handleISpoke, this)); button = attachChild<Button>(IDC_FDM_SETTINGS_MY_NICK_SPOKEN); button->onClicked(std::tr1::bind(&FdmAppearancePage::handleMyNickSpoken, this)); ::EnableWindow(GetDlgItem(handle(), IDC_FDM_SETTINGS_OP_SPOKE), false); ::EnableWindow(GetDlgItem(handle(), IDC_FDM_SETTINGS_NOT_OP_SPOKE), false); ::EnableWindow(GetDlgItem(handle(), IDC_FDM_SETTINGS_I_SPOKE), false); ::EnableWindow(GetDlgItem(handle(), IDC_FDM_SETTINGS_MY_NICK_SPOKEN), false); }
void IconManager::applyIconSet(ButtonPtr TheButton, const std::string& IconSetName, Vec2f Size) { IconSetPtr TheSet(getIconSet(IconSetName)); if(TheSet != NULL && TheButton != NullFC) { TheButton->setTexture(TheSet->getTexture(IconSet::ICON_NORMAL), Size); if(TheSet->getTexture(IconSet::ICON_ROLLOVER) != NullFC) { TheButton->setRolloverTexture(TheSet->getTexture(IconSet::ICON_ROLLOVER), Size); } else { TheButton->setRolloverTexture(TheSet->getTexture(IconSet::ICON_NORMAL), Size); } if(TheSet->getTexture(IconSet::ICON_FOCUSED) != NullFC) { TheButton->setFocusedTexture(TheSet->getTexture(IconSet::ICON_FOCUSED), Size); } else { TheButton->setFocusedTexture(TheSet->getTexture(IconSet::ICON_NORMAL), Size); } if(TheSet->getTexture(IconSet::ICON_DISABLED) != NullFC) { TheButton->setDisabledTexture(TheSet->getTexture(IconSet::ICON_DISABLED), Size); } else { TheButton->setDisabledTexture(TheSet->getTexture(IconSet::ICON_NORMAL), Size); } if(TheSet->getTexture(IconSet::ICON_ACTIVE) != NullFC) { TheButton->setActiveTexture(TheSet->getTexture(IconSet::ICON_ACTIVE), Size); } else { TheButton->setActiveTexture(TheSet->getTexture(IconSet::ICON_NORMAL), Size); } } }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindowEventProducer = createDefaultWindowEventProducer(); WindowPtr MainWindow = TutorialWindowEventProducer->initWindow(); TutorialWindowEventProducer->setDisplayCallback(display); TutorialWindowEventProducer->setReshapeCallback(reshape); TutorialKeyListener TheKeyListener; TutorialWindowEventProducer->addKeyListener(&TheKeyListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(MainWindow); // Make Torus Node (creates Torus in background of scene) NodePtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus NodePtr scene = osg::Node::create(); beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); scene->setCore(osg::Group::create()); scene->addChild(TorusGeometryNode); endEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); // Create the Graphics GraphicsPtr TutorialGraphics = osg::Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); /****************************************************** Create an Button Component and a simple Font. See 17Label_Font for more information about Fonts. ******************************************************/ ButtonPtr ExampleButton = osg::Button::create(); UIFontPtr ExampleFont = osg::UIFont::create(); beginEditCP(ExampleFont, UIFont::SizeFieldMask); ExampleFont->setSize(16); endEditCP(ExampleFont, UIFont::SizeFieldMask); /****************************************************** Edit the Button's characteristics. Note: the first 4 functions can be used with any Component and are not specific to Button. -setMinSize(Vec2f): Determine the Minimum Size of the Component. Some Layouts will automatically resize Components; this prevents the Size from going below a certain value. -setMaxSize(Vec2f): Determine the Maximum Size of the Component. -setPreferredSize(Vec2f): Determine the Preferred Size of the Component. This is what the Component will be displayed at unless changed by another Component (such as a Layout). -setToolTipText("Text"): Determine what text is displayed while Mouse is hovering above Component. The word Text will be displayed in this case. Functions specfic to Button: -setText("DesiredText"): Determine the Button's text. It will read DesiredText in this case. -setFont(FontName): Determine the Font to be used on the Button. -setTextColor(Color4f): Determine the Color for the text. -setRolloverTextColor(Color4f): Determine what the text Color will be when the Mouse Cursor is above the Button. -setActiveTextColor(Color4f): Determine what the text Color will be when the Button is pressed (denoted by Active). -setAlignment(Vec2f): Determine the Vertical Alignment of the text. The value is in [0.0, 1.0]. ******************************************************/ beginEditCP(ExampleButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); ExampleButton->setMinSize(Vec2f(50, 25)); ExampleButton->setMaxSize(Vec2f(200, 100)); ExampleButton->setPreferredSize(Vec2f(100, 50)); ExampleButton->setToolTipText("Button 1 ToolTip"); ExampleButton->setText("Button 1"); ExampleButton->setFont(ExampleFont); ExampleButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); ExampleButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0)); ExampleButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); ExampleButton->setAlignment(Vec2f(1.0,0.0)); endEditCP(ExampleButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); // Create an ActionListener and assign it to ExampleButton // This Class is defined above, and will cause the output // window to display "Button 1 Action" when pressed ExampleButtonActionListener TheExampleButtonActionListener; ExampleButton->addActionListener(&TheExampleButtonActionListener); /****************************************************** Create a ToggleButton and determine its characteristics. ToggleButton inherits off of Button, so all characteristsics used above can be used with ToggleButtons as well. The only difference is that when pressed, ToggleButton remains pressed until pressed again. -setSelected(bool): Determine whether the ToggleButton is Selected (true) or deselected (false). ******************************************************/ ToggleButtonPtr ExampleToggleButton = osg::ToggleButton::create(); beginEditCP(ExampleToggleButton, ToggleButton::SelectedFieldMask | ToggleButton::TextFieldMask | ToggleButton::ToolTipTextFieldMask); ExampleToggleButton->setSelected(false); ExampleToggleButton->setText("ToggleMe"); ExampleToggleButton->setToolTipText("Toggle Button ToolTip"); endEditCP(ExampleToggleButton, ToggleButton::SelectedFieldMask | ToggleButton::TextFieldMask | ToggleButton::ToolTipTextFieldMask); //Button with Image ButtonPtr ExampleDrawObjectButton = osg::Button::create(); beginEditCP(ExampleDrawObjectButton, Button::DrawObjectToTextAlignmentFieldMask | Button::TextFieldMask); ExampleDrawObjectButton->setDrawObjectToTextAlignment(Button::ALIGN_DRAW_OBJECT_RIGHT_OF_TEXT); ExampleDrawObjectButton->setText("Icon"); endEditCP(ExampleDrawObjectButton, Button::DrawObjectToTextAlignmentFieldMask | Button::TextFieldMask); ExampleDrawObjectButton->setImage(std::string("Data/Icon.png")); ExampleDrawObjectButton->setActiveImage(std::string("Data/Icon.png")); ExampleDrawObjectButton->setFocusedImage(std::string("Data/Icon.png")); ExampleDrawObjectButton->setRolloverImage(std::string("Data/Icon.png")); ExampleDrawObjectButton->setDisabledImage(std::string("Data/Icon.png")); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerPtr MainInternalWindowBackground = osg::ColorLayer::create(); beginEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); endEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask); InternalWindowPtr MainInternalWindow = osg::InternalWindow::create(); LayoutPtr MainInternalWindowLayout = osg::FlowLayout::create(); beginEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask); MainInternalWindow->getChildren().push_back(ExampleButton); MainInternalWindow->getChildren().push_back(ExampleToggleButton); MainInternalWindow->getChildren().push_back(ExampleDrawObjectButton); 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); endEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask); // Create the Drawing Surface UIDrawingSurfacePtr TutorialDrawingSurface = UIDrawingSurface::create(); beginEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindowEventProducer); endEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundPtr TutorialUIForeground = osg::UIForeground::create(); beginEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); endEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask); mgr->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportPtr TutorialViewport = mgr->getWindow()->getPort(0); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); TutorialViewport->getForegrounds().push_back(TutorialUIForeground); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); // Show the whole Scene mgr->showAll(); //Open Window Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "01RubberBandCamera"); //Enter main Loop TutorialWindowEventProducer->mainLoop(); osgExit(); return 0; }
/////////////////////////////////////////////////////////////////////////////// // Creates UI for the field variable specified. // void ReflectStlSetInterpreter::InterpretField( const Reflect::Field* field, const std::vector<Reflect::Object*>& instances, Container* parent ) { if ( field->m_Flags & Reflect::FieldFlags::Hide ) { return; } // create the container ContainerPtr container = CreateControl< Container >(); parent->AddChild( container ); tstring temp; field->GetProperty( TXT( "UIName" ), temp ); if ( temp.empty() ) { bool converted = Helium::ConvertString( field->m_Name, temp ); HELIUM_ASSERT( converted ); } container->a_Name.Set( temp ); // create the data objects std::vector< Reflect::Object* >::const_iterator itr = instances.begin(); std::vector< Reflect::Object* >::const_iterator end = instances.end(); for ( ; itr != end; ++itr ) { Reflect::DataPtr ser = Reflect::AssertCast< Reflect::Data >( Reflect::Registry::GetInstance()->CreateInstance( field->m_DataClass ) ); uintptr_t fieldAddress = ( uintptr_t )( *itr ) + field->m_Offset; ser->ConnectData( ( void* )fieldAddress ); m_Datas.push_back( ser ); } // create the list ListPtr list = CreateControl< List >(); list->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) ); container->AddChild( list ); // bind the ui to the serialiers list->Bind( new MultiStringFormatter< Reflect::Data >( (std::vector<Reflect::Data*>&)m_Datas ) ); // create the buttons if we are not read only if ( !( field->m_Flags & Reflect::FieldFlags::ReadOnly ) ) { ContainerPtr buttonContainer = CreateControl< Container >(); container->AddChild( buttonContainer ); ButtonPtr buttonAdd = CreateControl< Button >(); buttonContainer->AddChild( buttonAdd ); buttonAdd->a_Label.Set( TXT( "Add" ) ); buttonAdd->a_HelpText.Set( TXT( "Add an item to the list." ) ); buttonAdd->ButtonClickedEvent().Add( ButtonClickedSignature::Delegate ( this, &ReflectStlSetInterpreter::OnAdd ) ); buttonAdd->SetClientData( new ClientData( list ) ); ButtonPtr buttonRemove = CreateControl< Button >(); buttonContainer->AddChild( buttonRemove ); buttonRemove->a_Label.Set( TXT( "Remove" ) ); buttonRemove->a_HelpText.Set( TXT( "Remove the selected item(s) from the list." ) ); buttonRemove->ButtonClickedEvent().Add( ButtonClickedSignature::Delegate ( this, &ReflectStlSetInterpreter::OnRemove ) ); buttonRemove->SetClientData( new ClientData( list ) ); } // for now let's just disable this container if there is more than one item selected. I'm not sure if it will behave properly in this case. if ( instances.size() > 1 ) { container->a_IsEnabled.Set( false ); } }
// Initialize GLUT & OpenSG and set up the scene int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindowEventProducer = createDefaultWindowEventProducer(); WindowPtr MainWindow = TutorialWindowEventProducer->initWindow(); TutorialWindowEventProducer->setDisplayCallback(display); TutorialWindowEventProducer->setReshapeCallback(reshape); //Add Window Listener TutorialKeyListener TheKeyListener; TutorialWindowEventProducer->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindowEventProducer->addMouseListener(&TheTutorialMouseListener); TutorialWindowEventProducer->addMouseMotionListener(&TheTutorialMouseMotionListener); TutorialUpdateListener TheTutorialUpdateListener; TutorialWindowEventProducer->addUpdateListener(&TheTutorialUpdateListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindowEventProducer->getWindow()); //////////////// // Create the Graphics GraphicsPtr TutorialGraphics = osg::Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); /****************************************************** Create an Button Component and a simple Font. See 17Label_Font for more information about Fonts. ******************************************************/ ButtonPtr ExampleButton = osg::Button::create(); UIFontPtr ExampleFont = osg::UIFont::create(); beginEditCP(ExampleButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); ExampleButton->setMinSize(Vec2f(50, 25)); ExampleButton->setMaxSize(Vec2f(200, 100)); ExampleButton->setPreferredSize(Vec2f(100, 50)); ExampleButton->setToolTipText("Click to start/pause"); ExampleButton->setText("start/pause"); ExampleButton->setFont(ExampleFont); ExampleButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); ExampleButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0)); ExampleButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); ExampleButton->setAlignment(Vec2f(.5,0.5)); endEditCP(ExampleButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); // Create an ActionListener and assign it to ExampleButton // This Class is defined above, and will cause the output // window to display "Button 1 Action" when pressed ExampleButtonActionListener TheExampleButtonActionListener; ExampleButton->addActionListener(&TheExampleButtonActionListener); ////////////////// //Torus Material TheTorusMaterial = SimpleMaterial::create(); beginEditCP(TheTorusMaterial); SimpleMaterialPtr::dcast(TheTorusMaterial)->setAmbient(Color3f(0.3,0.3,0.3)); SimpleMaterialPtr::dcast(TheTorusMaterial)->setDiffuse(Color3f(0.7,0.7,0.7)); SimpleMaterialPtr::dcast(TheTorusMaterial)->setSpecular(Color3f(1.0,1.0,1.0)); endEditCP(TheTorusMaterial); //Torus Geometry GeometryPtr TorusGeometry = makeTorusGeo(.5, 2, 32, 32); beginEditCP(TorusGeometry); TorusGeometry->setMaterial(TheTorusMaterial); endEditCP (TorusGeometry); NodePtr TorusGeometryNode = Node::create(); beginEditCP(TorusGeometryNode, Node::CoreFieldMask); TorusGeometryNode->setCore(TorusGeometry); endEditCP (TorusGeometryNode, Node::CoreFieldMask); //Make Torus Node NodePtr TorusNode = Node::create(); TransformPtr TorusNodeTrans; TorusNodeTrans = Transform::create(); setName(TorusNodeTrans, std::string("TorusNodeTransformationCore")); beginEditCP(TorusNode, Node::CoreFieldMask | Node::ChildrenFieldMask); TorusNode->setCore(TorusNodeTrans); TorusNode->addChild(TorusGeometryNode); endEditCP (TorusNode, Node::CoreFieldMask | Node::ChildrenFieldMask); //Make Main Scene Node NodePtr scene = Node::create(); ComponentTransformPtr Trans; Trans = ComponentTransform::create(); setName(Trans, std::string("MainTransformationCore")); beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); { scene->setCore(Trans); // add the torus as a child scene->addChild(TorusNode); } endEditCP (scene, Node::CoreFieldMask | Node::ChildrenFieldMask); setupAnimation(); // Create Background to be used with the Main InternalWindow ColorLayerPtr MainInternalWindowBackground = osg::ColorLayer::create(); beginEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); endEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask); InternalWindowPtr MainInternalWindow = osg::InternalWindow::create(); LayoutPtr MainInternalWindowLayout = osg::FlowLayout::create(); beginEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask); MainInternalWindow->getChildren().push_back(ExampleButton); 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); endEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask); // Create the Drawing Surface UIDrawingSurfacePtr TutorialDrawingSurface = UIDrawingSurface::create(); beginEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindowEventProducer); endEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundPtr TutorialUIForeground = osg::UIForeground::create(); beginEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); endEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask); mgr->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportPtr TutorialViewport = mgr->getWindow()->getPort(0); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); TutorialViewport->getForegrounds().push_back(TutorialUIForeground); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); // show the whole scene mgr->showAll(); TheAnimationAdvancer->start(); Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "24AnimationAction"); //Enter main Loop TutorialWindowEventProducer->mainLoop(); osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindowEventProducer = createDefaultWindowEventProducer(); WindowPtr MainWindow = TutorialWindowEventProducer->initWindow(); TutorialWindowEventProducer->setDisplayCallback(display); TutorialWindowEventProducer->setReshapeCallback(reshape); TutorialKeyListener TheKeyListener; TutorialWindowEventProducer->addKeyListener(&TheKeyListener); TutorialUpdateListener TheTutorialUpdateListener; TutorialWindowEventProducer->addUpdateListener(&TheTutorialUpdateListener); //Create Start and stop buttons for the caption ButtonPtr StartButton = osg::Button::create(); ButtonPtr StopButton = osg::Button::create(); ButtonPtr PauseButton = osg::Button::create(); UIFontPtr ButtonFont = osg::UIFont::create(); beginEditCP(ButtonFont, UIFont::SizeFieldMask); ButtonFont->setSize(16); endEditCP(ButtonFont, UIFont::SizeFieldMask); beginEditCP(StartButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); StartButton->setMinSize(Vec2f(50, 25)); StartButton->setMaxSize(Vec2f(200, 100)); StartButton->setPreferredSize(Vec2f(100, 50)); StartButton->setToolTipText("This will start playing the caption!"); StartButton->setText("START"); StartButton->setFont(ButtonFont); StartButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); StartButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0)); StartButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); StartButton->setAlignment(Vec2f(0.25,0.5)); endEditCP(StartButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); beginEditCP(StopButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); StopButton->setMinSize(Vec2f(50, 25)); StopButton->setMaxSize(Vec2f(200, 100)); StopButton->setPreferredSize(Vec2f(100, 50)); StopButton->setToolTipText("This will stop the caption and reset it!"); StopButton->setText("STOP"); StopButton->setFont(ButtonFont); StopButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); StopButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0)); StopButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); StopButton->setAlignment(Vec2f(0.75,0.5)); endEditCP(StopButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); beginEditCP(PauseButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); PauseButton->setMinSize(Vec2f(50, 25)); PauseButton->setMaxSize(Vec2f(200, 100)); PauseButton->setPreferredSize(Vec2f(100, 50)); PauseButton->setToolTipText("This will Pause the caption!"); PauseButton->setText("PAUSE"); PauseButton->setFont(ButtonFont); PauseButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); PauseButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0)); PauseButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); PauseButton->setAlignment(Vec2f(0.5,0.5)); endEditCP(PauseButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); StartButtonActionListener TheStartButtonActionListener; StartButton->addActionListener(&TheStartButtonActionListener); StopButtonActionListener TheStopButtonActionListener; StopButton->addActionListener(&TheStopButtonActionListener); PauseButtonActionListener ThePauseButtonActionListener; PauseButton->addActionListener(&ThePauseButtonActionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(MainWindow); // Make Torus Node (creates Torus in background of scene) NodePtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus scene = osg::Node::create(); beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); scene->setCore(osg::Group::create()); scene->addChild(TorusGeometryNode); endEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); // Create the Graphics GraphicsPtr TutorialGraphics = osg::Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); LayoutPtr MainInternalWindowLayout = osg::FlowLayout::create(); PanelPtr CaptionContainer = osg::Panel::create(); beginEditCP(CaptionContainer, Panel::PreferredSizeFieldMask | Panel::LayoutFieldMask); CaptionContainer->setPreferredSize(Pnt2f(250.0,30.0)); CaptionContainer->setLayout(MainInternalWindowLayout); endEditCP(CaptionContainer, Panel::PreferredSizeFieldMask | Panel::LayoutFieldMask); //Initialize the Sound Manager SoundManager::the()->attachUpdateProducer(TutorialWindowEventProducer); TutorialSound = SoundManager::the()->createSound(); beginEditCP(TutorialSound, Sound::FileFieldMask | Sound::VolumeFieldMask | Sound::StreamingFieldMask | Sound::LoopingFieldMask); TutorialSound->setFile(Path("./Data/captionSoundFile.ogg")); TutorialSound->setVolume(1.0); TutorialSound->setStreaming(true); TutorialSound->setLooping(0); endEditCP(TutorialSound, Sound::FileFieldMask | Sound::VolumeFieldMask | Sound::StreamingFieldMask | Sound::LoopingFieldMask); // Create the Caption TutorialCaption = osg::Caption::create(); //Add the segments of text to be displayed TutorialCaption->captionSegment("Listeners can be used for a variety",1.7,3.4); TutorialCaption->captionSegment("of different applications.",3.4,4.7); TutorialCaption->captionSegment("In this tutorial we will",5.0,6.35); TutorialCaption->captionSegment("simply be changing the background though.",6.35,8.0); TutorialCaption->captionSegment("First we will change the",8.8,10.2); TutorialCaption->captionSegment("torus on screen to a sphere.",10.2,11.75); TutorialCaption->captionSegment("By timing things correctly we can make",12.7,14.6); TutorialCaption->captionSegment("the changes right as the word is spoken.",14.6,16.75); TutorialCaption->captionSegment("Such as changing the sphere to a cube",17.3,20.0); TutorialCaption->captionSegment("but personally I would prefer",20.33,21.65); TutorialCaption->captionSegment("the background to be blank.",21.65,22.8); TutorialCaption->captionSegment("Much better!",23.8,25.0); //Add the tutorial Caption Listener to the Caption that was set up for the tutorial TutorialCaptionListener TheCaptionListener; TutorialCaption->addCaptionListener(&TheCaptionListener); //Create the Caption component Generator TutorialCapGen = DefaultCaptionComponentGenerator::create(); TutorialCaption->attachWindowEventProducer(TutorialWindowEventProducer); beginEditCP(TutorialCaption, Caption::ParentContainerFieldMask | Caption::ComponentGeneratorFieldMask | Caption::CaptionDialogSoundFieldMask); TutorialCaption->setParentContainer(CaptionContainer); TutorialCaption->setComponentGenerator(TutorialCapGen); TutorialCaption->setCaptionDialogSound(TutorialSound); endEditCP(TutorialCaption, Caption::ParentContainerFieldMask | Caption::ComponentGeneratorFieldMask | Caption::CaptionDialogSoundFieldMask); //Create and modify the Label prototype that will be used for the caption LabelPtr LabelPrototype = Label::create(); LabelPrototype->setAlignment(Pnt2f(0.5f,0.5f)); LabelPrototype->setPreferredSize(Pnt2f(250.0,30.0)); //Add the prototype to the Generator for use beginEditCP(TutorialCapGen, DefaultCaptionComponentGenerator::CaptionSegmentPrototypeFieldMask); TutorialCapGen->setCaptionSegmentPrototype(LabelPrototype); endEditCP(TutorialCapGen, DefaultCaptionComponentGenerator::CaptionSegmentPrototypeFieldMask); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerPtr MainInternalWindowBackground = osg::ColorLayer::create(); MainInternalWindow = osg::InternalWindow::create(); beginEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); endEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask); beginEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask); 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); MainInternalWindow->getChildren().push_back(CaptionContainer); MainInternalWindow->getChildren().push_back(StartButton); MainInternalWindow->getChildren().push_back(StopButton); MainInternalWindow->getChildren().push_back(PauseButton); endEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask); // Create the Drawing Surface UIDrawingSurfacePtr TutorialDrawingSurface = UIDrawingSurface::create(); beginEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindowEventProducer); endEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundPtr TutorialUIForeground = osg::UIForeground::create(); beginEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); endEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask); mgr->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportPtr TutorialViewport = mgr->getWindow()->getPort(0); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); TutorialViewport->getForegrounds().push_back(TutorialUIForeground); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); // Show the whole Scene mgr->showAll(); SoundManager::the()->setCamera(mgr->getCamera()); Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "05Caption"); //Enter main Loop TutorialWindowEventProducer->mainLoop(); osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindowEventProducer = createDefaultWindowEventProducer(); WindowPtr MainWindow = TutorialWindowEventProducer->initWindow(); TutorialWindowEventProducer->setDisplayCallback(display); TutorialWindowEventProducer->setReshapeCallback(reshape); TutorialKeyListener TheKeyListener; TutorialWindowEventProducer->addKeyListener(&TheKeyListener); TutorialUpdateListener TheTutorialUpdateListener; TutorialWindowEventProducer->addUpdateListener(&TheTutorialUpdateListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(MainWindow); // Make Torus Node (creates Torus in background of scene) NodePtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus scene = osg::Node::create(); beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); scene->setCore(osg::Group::create()); scene->addChild(TorusGeometryNode); endEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); // Create the Graphics GraphicsPtr TutorialGraphics = osg::Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); DefaultDialogComponentGeneratorPtr TutorialDialogGenerator = DefaultDialogComponentGenerator::create(); ButtonFont = osg::UIFont::create(); beginEditCP(ButtonFont, UIFont::SizeFieldMask); ButtonFont->setSize(16); endEditCP(ButtonFont, UIFont::SizeFieldMask); ButtonPtr Response = osg::Button::create(); beginEditCP(Response, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask ); Response->setMinSize(Vec2f(50, 25)); Response->setMaxSize(Vec2f(200, 100)); Response->setPreferredSize(Vec2f(100, 50)); Response->setToolTipText("These buttons are for selecting a response!"); Response->setFont(ButtonFont); Response->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); Response->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0)); Response->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); endEditCP(Response, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask ); LabelPtr LabelPrototype = Label::create(); LabelPrototype->setAlignment(Pnt2f(0.5f,0.5f)); LabelPrototype->setPreferredSize(Pnt2f(250.0,30.0)); DialogInterfacePtr TutorialDialogInterface = osg::DialogInterface::create(); beginEditCP(TutorialDialogGenerator, DefaultDialogComponentGenerator::ResponseButtonPrototypeFieldMask | DefaultDialogComponentGenerator::QuestionPrototypeFieldMask); TutorialDialogGenerator->setResponseButtonPrototype(Response); TutorialDialogGenerator->setQuestionPrototype(LabelPrototype); endEditCP(TutorialDialogGenerator, DefaultDialogComponentGenerator::ResponseButtonPrototypeFieldMask | DefaultDialogComponentGenerator::QuestionPrototypeFieldMask); TutorialDialog = osg::DialogHierarchy::create(); beginEditCP(TutorialDialog, DialogHierarchy::DualNodeStyleFieldMask); TutorialDialog->setDualNodeStyle(true); endEditCP(TutorialDialog, DialogHierarchy::DualNodeStyleFieldMask); DialogPtr rootDialog = TutorialDialog->addDialog("Which do you prefer?", 0.0, NullFC, true, NullFC); DialogPtr RootDialogChildA = TutorialDialog->addDialog("Foreground", 0.0, NullFC, false, rootDialog); DialogPtr RootDialogChildB = TutorialDialog->addDialog("Background", 0.0, NullFC, false, rootDialog); DialogPtr SelectableDialogChildA = TutorialDialog->addDialog("What color would you like the forground to be?", 0.0, NullFC, true, RootDialogChildA); DialogPtr SelectableDialogChildB = TutorialDialog->addDialog("What object do you want to be in the background?", 0.0, NullFC, true, RootDialogChildB); ADialogChildA = TutorialDialog->addDialog("Blue", 0.0, NullFC, false, SelectableDialogChildA); ADialogChildB = TutorialDialog->addDialog("Red", 0.0, NullFC, false, SelectableDialogChildA); BDialogChildA = TutorialDialog->addDialog("Square", 0.0, NullFC, false, SelectableDialogChildB); BDialogChildB = TutorialDialog->addDialog("Sphere", 0.0, NullFC, false, SelectableDialogChildB); DialogPtr RestartEnd1 = TutorialDialog->addDialog("What would you like to do?", 0.0, NullFC, true, ADialogChildA); DialogPtr RestartEnd2 = TutorialDialog->addDialog("What would you like to do?", 0.0, NullFC, true, ADialogChildB); DialogPtr RestartEnd3 = TutorialDialog->addDialog("What would you like to do?", 0.0, NullFC, true, BDialogChildA); DialogPtr RestartEnd4 = TutorialDialog->addDialog("What would you like to do?", 0.0, NullFC, true, BDialogChildB); Restart1 = TutorialDialog->addDialog("Restart", 0.0, NullFC, false, RestartEnd1); End1 = TutorialDialog->addDialog("End", 0.0, NullFC, false, RestartEnd1); Restart2 = TutorialDialog->addDialog("Restart", 0.0, NullFC, false, RestartEnd2); End2 = TutorialDialog->addDialog("End", 0.0, NullFC, false, RestartEnd2); Restart3 = TutorialDialog->addDialog("Restart", 0.0, NullFC, false, RestartEnd3); End3 = TutorialDialog->addDialog("End", 0.0, NullFC, false, RestartEnd3); Restart4 = TutorialDialog->addDialog("Restart", 0.0, NullFC, false, RestartEnd4); End4 = TutorialDialog->addDialog("End", 0.0, NullFC, false, RestartEnd4); TutorialDialogListener TheTutorialDialogListener; rootDialog->addDialogListener(&TheTutorialDialogListener); RootDialogChildA->addDialogListener(&TheTutorialDialogListener); RootDialogChildB->addDialogListener(&TheTutorialDialogListener); ADialogChildA->addDialogListener(&TheTutorialDialogListener); ADialogChildB->addDialogListener(&TheTutorialDialogListener); BDialogChildA->addDialogListener(&TheTutorialDialogListener); BDialogChildB->addDialogListener(&TheTutorialDialogListener); Restart1->addDialogListener(&TheTutorialDialogListener); End1->addDialogListener(&TheTutorialDialogListener); Restart2->addDialogListener(&TheTutorialDialogListener); End2->addDialogListener(&TheTutorialDialogListener); Restart3->addDialogListener(&TheTutorialDialogListener); End3->addDialogListener(&TheTutorialDialogListener); Restart4->addDialogListener(&TheTutorialDialogListener); End4->addDialogListener(&TheTutorialDialogListener); SelectableDialogChildA->addDialogListener(&TheTutorialDialogListener); SelectableDialogChildB->addDialogListener(&TheTutorialDialogListener); RestartEnd1->addDialogListener(&TheTutorialDialogListener); RestartEnd2->addDialogListener(&TheTutorialDialogListener); RestartEnd3->addDialogListener(&TheTutorialDialogListener); RestartEnd4->addDialogListener(&TheTutorialDialogListener); LayoutPtr MainInternalWindowLayout = osg::FlowLayout::create(); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow MainInternalWindowBackground = osg::ColorLayer::create(); MainInternalWindow = osg::InternalWindow::create(); beginEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); endEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask); beginEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask); 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); endEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask); beginEditCP(TutorialDialogInterface, DialogInterface::ComponentGeneratorFieldMask | DialogInterface::ParentContainerFieldMask | DialogInterface::SourceDialogHierarchyFieldMask); TutorialDialogInterface->setComponentGenerator(TutorialDialogGenerator); TutorialDialogInterface->setParentContainer(MainInternalWindow); TutorialDialogInterface->setSourceDialogHierarchy(TutorialDialog); endEditCP(TutorialDialogInterface, DialogInterface::ComponentGeneratorFieldMask | DialogInterface::ParentContainerFieldMask | DialogInterface::SourceDialogHierarchyFieldMask); // Create the Drawing Surface UIDrawingSurfacePtr TutorialDrawingSurface = UIDrawingSurface::create(); beginEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindowEventProducer); endEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundPtr TutorialUIForeground = osg::UIForeground::create(); beginEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); endEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask); mgr->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportPtr TutorialViewport = mgr->getWindow()->getPort(0); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); TutorialViewport->getForegrounds().push_back(TutorialUIForeground); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); // Show the whole Scene mgr->showAll(); SoundManager::the()->setCamera(mgr->getCamera()); TutorialDialog->start(); Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "07DialogTypeTwo"); //Enter main Loop TutorialWindowEventProducer->mainLoop(); osgExit(); return 0; }
void ReflectInterpreter::InterpretFilePathField( const std::vector< Reflect::Pointer >& pointers, Reflect::Translator* translator, const Reflect::Field* field, Container* parent ) { #if INSPECT_REFACTOR if (field->m_Flags & FieldFlags::Hide) { return; } // // Create the ui we are generating // std::vector< ContainerPtr > groups; ContainerPtr container = CreateControl<Container>(); groups.push_back( container ); bool pathField = field->m_DataClass == Reflect::GetMetaClass< PathData >(); bool readOnly = ( field->m_Flags & FieldFlags::ReadOnly ) == FieldFlags::ReadOnly; DataChangingSignature::Delegate changingDelegate; FileDialogButtonPtr fileDialogButton; // // Parse // std::string fieldUI; field->GetProperty( TXT( "UIScript" ), fieldUI ); bool result = Script::Parse(fieldUI, this, parent->GetCanvas(), container, field->m_Flags); if (!result) { if ( pathField || field->m_DataClass == Reflect::GetMetaClass<StlStringData>() ) { ContainerPtr valueContainer = CreateControl<Container>(); ValuePtr value = CreateControl< Value >(); value->a_Justification.Set( Justifications::Right ); value->a_IsReadOnly.Set( readOnly ); value->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) ); valueContainer->AddChild( value ); groups.push_back( valueContainer ); if ( !readOnly ) { changingDelegate = DataChangingSignature::Delegate(this, &PathInterpreter::DataChanging); // File dialog button fileDialogButton = CreateControl< FileDialogButton >(); fileDialogButton->a_HelpText.Set( TXT( "Open a file dialog to choose a new file." ) ); field->GetProperty( TXT( "FileFilter" ), m_FileFilter ); if ( !m_FileFilter.empty() ) { fileDialogButton->a_Filter.Set( m_FileFilter ); } container->AddChild( fileDialogButton ); value->SetProperty( TXT( "FileFilter" ), m_FileFilter ); } if ( objects.size() == 1 ) { // File edit button ButtonPtr editButton = CreateControl< Button >(); editButton->ButtonClickedEvent().Add( ButtonClickedSignature::Delegate ( this, &PathInterpreter::Edit ) ); editButton->a_Label.Set( TXT( "Edit" ) ); editButton->a_HelpText.Set( TXT( "Attempt to edit the file using its associated default application." ) ); container->AddChild( editButton ); } } } else { ValuePtr value = CreateControl< Value >(); value->a_IsReadOnly.Set( readOnly ); value->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) ); container->AddChild( value ); } // // Setup label // LabelPtr label = NULL; { std::vector< ControlPtr >::const_iterator itr = container->GetChildren().begin(); std::vector< ControlPtr >::const_iterator end = container->GetChildren().end(); for( ; itr != end; ++itr ) { Label* label = Reflect::SafeCast<Label>( *itr ); if (label) { break; } } } if (!label.ReferencesObject()) { label = CreateControl< Label >(); std::string temp; field->GetProperty( TXT( "UIName" ), temp ); if ( temp.empty() ) { bool converted = Helium::ConvertString( field->m_Name, temp ); HELIUM_ASSERT( converted ); } label->BindText( temp ); label->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) ); container->InsertChild(0, label); } // // Create type m_FinderSpecific data bound to this and additional objects // std::vector<Data*> datas; { std::vector<Reflect::Object*>::const_iterator itr = objects.begin(); std::vector<Reflect::Object*>::const_iterator end = objects.end(); for ( ; itr != end; ++itr ) { Data s = field->CreateData(); if (s->IsA(Reflect::GetMetaClass<ContainerData>())) { return; } s->ConnectField(*itr, field); datas.push_back(s); m_Datas.push_back(s); } } // // Create data and bind // Helium::SmartPtr< MultiStringFormatter<Data> > data = new MultiStringFormatter<Data>( datas ); if (changingDelegate.Valid()) { data->AddChangingListener( changingDelegate ); } { std::vector<ContainerPtr>::const_iterator itr = groups.begin(); std::vector<ContainerPtr>::const_iterator end = groups.end(); for ( ; itr != end; ++itr ) { (*itr)->Bind( data ); } } // // Set default // Data defaultData = field->CreateDefaultData(); if (defaultData.ReferencesObject()) { std::stringstream defaultStream; *defaultData >> defaultStream; container->a_Default.Set( defaultStream.str() ); }
bool CommandDlg::handleInitDialog() { setHelpId(IDH_USER_COMMAND); WinUtil::setHelpIds(this, helpItems); // Translate setText(T_("Create / Modify User Command")); setItemText(IDC_SETTINGS_TYPE, T_("Command Type")); setItemText(IDC_SETTINGS_CONTEXT, T_("Context")); setItemText(IDC_SETTINGS_PARAMETERS, T_("Parameters")); setItemText(IDC_SETTINGS_NAME, T_("Name")); setItemText(IDC_SETTINGS_COMMAND, T_("Command")); setItemText(IDC_SETTINGS_HUB, T_("Hub IP / DNS (empty = all, 'op' = where operator)")); setItemText(IDC_SETTINGS_TO, T_("To")); setItemText(IDC_USER_CMD_PREVIEW, T_("Text sent to hub")); attachChild(separator, IDC_SETTINGS_SEPARATOR); separator->setText(T_("Separator")); separator->onClicked(std::tr1::bind(&CommandDlg::handleTypeChanged, this)); attachChild(raw, IDC_SETTINGS_RAW); raw->setText(T_("Raw")); raw->onClicked(std::tr1::bind(&CommandDlg::handleTypeChanged, this)); attachChild(chat, IDC_SETTINGS_CHAT); chat->setText(T_("Chat")); chat->onClicked(std::tr1::bind(&CommandDlg::handleTypeChanged, this)); attachChild(PM, IDC_SETTINGS_PM); PM->setText(T_("PM")); PM->onClicked(std::tr1::bind(&CommandDlg::handleTypeChanged, this)); hubMenu = attachChild<CheckBox>(IDC_SETTINGS_HUB_MENU); hubMenu->setText(T_("Hub Menu")); userMenu = attachChild<CheckBox>(IDC_SETTINGS_USER_MENU); userMenu->setText(T_("User Menu")); searchMenu = attachChild<CheckBox>(IDC_SETTINGS_SEARCH_MENU); searchMenu->setText(T_("Search Menu")); fileListMenu = attachChild<CheckBox>(IDC_SETTINGS_FILELIST_MENU); fileListMenu->setText(T_( "Filelist Menu")); nameBox = attachChild<TextBox>(IDC_NAME); commandBox = attachChild<TextBox>(IDC_COMMAND); commandBox->onUpdated(std::tr1::bind(&CommandDlg::updateCommand, this)); hubBox = attachChild<TextBox>(IDC_HUB); nick = attachChild<TextBox>(IDC_NICK); nick->onUpdated(std::tr1::bind(&CommandDlg::updateCommand, this)); once = attachChild<CheckBox>(IDC_SETTINGS_ONCE); once->setText(T_("Send once per nick")); result = attachChild<TextBox>(IDC_RESULT); openHelp = attachChild<CheckBox>(IDC_USER_CMD_OPEN_HELP); openHelp->setText(T_("Always open help file with this dialog")); bool bOpenHelp = BOOLSETTING(OPEN_USER_CMD_HELP); openHelp->setChecked(bOpenHelp); { ButtonPtr button = attachChild<Button>(IDOK); button->setText(T_("OK")); button->onClicked(std::tr1::bind(&CommandDlg::handleOKClicked, this)); button = attachChild<Button>(IDCANCEL); button->setText(T_("Cancel")); button->onClicked(std::tr1::bind(&CommandDlg::endDialog, this, IDCANCEL)); button = attachChild<Button>(IDHELP); button->setText(T_("Help")); button->onClicked(std::tr1::bind(&WinUtil::help, handle(), IDH_USER_COMMAND)); } if(bOpenHelp) { // launch the help file, instead of having the help in the dialog WinUtil::help(handle(), IDH_USER_COMMAND); } if(type == UserCommand::TYPE_SEPARATOR) { separator->setChecked(true); } else { // More difficult, determine type by what it seems to be... if((_tcsncmp(command.c_str(), _T("$To: "), 5) == 0) && (command.find(_T(" From: %[myNI] $<%[myNI]> ")) != string::npos || command.find(_T(" From: %[mynick] $<%[mynick]> ")) != string::npos) && command.find(_T('|')) == command.length() - 1) // if it has | anywhere but the end, it is raw { string::size_type i = command.find(_T(' '), 5); dcassert(i != string::npos); tstring to = command.substr(5, i-5); string::size_type cmd_pos = command.find(_T('>'), 5) + 2; tstring cmd = Text::toT(NmdcHub::validateMessage(Text::fromT(command.substr(cmd_pos, command.length()-cmd_pos-1)), true)); PM->setChecked(true); nick->setText(to); commandBox->setText(cmd.c_str()); } else if(((_tcsncmp(command.c_str(), _T("<%[mynick]> "), 12) == 0) || (_tcsncmp(command.c_str(), _T("<%[myNI]> "), 10) == 0)) && command[command.length()-1] == '|') { // Looks like a chat thing... string::size_type cmd_pos = command.find(_T('>')) + 2; tstring cmd = Text::toT(NmdcHub::validateMessage(Text::fromT(command.substr(cmd_pos, command.length()-cmd_pos-1)), true)); chat->setChecked(true); commandBox->setText(cmd); } else { tstring cmd = command; raw->setChecked(true); commandBox->setText(cmd); } if(type == UserCommand::TYPE_RAW_ONCE) { once->setChecked(true); type = 1; } } hubBox->setText(hub); nameBox->setText(name); if(ctx & UserCommand::CONTEXT_HUB) hubMenu->setChecked(true); if(ctx & UserCommand::CONTEXT_CHAT) userMenu->setChecked(true); if(ctx & UserCommand::CONTEXT_SEARCH) searchMenu->setChecked(true); if(ctx & UserCommand::CONTEXT_FILELIST) fileListMenu->setChecked(true); updateControls(); updateCommand(); separator->setFocus(); centerWindow(); return false; }
ReviewDialog::ReviewDialog(MWWorld::Environment& environment) : WindowBase("openmw_chargen_review_layout.xml", environment) , lastPos(0) { // Centre dialog center(); WindowManager *wm = environment.mWindowManager; // Setup static stats ButtonPtr button; getWidget(nameWidget, "NameText"); getWidget(button, "NameButton"); button->setCaption(wm->getGameSettingString("sName", "")); button->eventMouseButtonClick = MyGUI::newDelegate(this, &ReviewDialog::onNameClicked);; getWidget(raceWidget, "RaceText"); getWidget(button, "RaceButton"); button->setCaption(wm->getGameSettingString("sRace", "")); button->eventMouseButtonClick = MyGUI::newDelegate(this, &ReviewDialog::onRaceClicked);; getWidget(classWidget, "ClassText"); getWidget(button, "ClassButton"); button->setCaption(wm->getGameSettingString("sClass", "")); button->eventMouseButtonClick = MyGUI::newDelegate(this, &ReviewDialog::onClassClicked);; getWidget(birthSignWidget, "SignText"); getWidget(button, "SignButton"); button->setCaption(wm->getGameSettingString("sBirthSign", "")); button->eventMouseButtonClick = MyGUI::newDelegate(this, &ReviewDialog::onBirthSignClicked);; // Setup dynamic stats getWidget(health, "Health"); health->setTitle(wm->getGameSettingString("sHealth", "")); health->setValue(45, 45); getWidget(magicka, "Magicka"); magicka->setTitle(wm->getGameSettingString("sMagic", "")); magicka->setValue(50, 50); getWidget(fatigue, "Fatigue"); fatigue->setTitle(wm->getGameSettingString("sFatigue", "")); fatigue->setValue(160, 160); // Setup attributes MWAttributePtr attribute; for (int idx = 0; idx < ESM::Attribute::Length; ++idx) { getWidget(attribute, std::string("Attribute") + boost::lexical_cast<std::string>(idx)); attributeWidgets.insert(std::make_pair(static_cast<int>(ESM::Attribute::attributeIds[idx]), attribute)); attribute->setWindowManager(wm); attribute->setAttributeId(ESM::Attribute::attributeIds[idx]); attribute->setAttributeValue(MWAttribute::AttributeValue(0, 0)); } // Setup skills getWidget(skillAreaWidget, "Skills"); getWidget(skillClientWidget, "SkillClient"); getWidget(skillScrollerWidget, "SkillScroller"); skillScrollerWidget->eventScrollChangePosition = MyGUI::newDelegate(this, &ReviewDialog::onScrollChangePosition); updateScroller(); for (int i = 0; i < ESM::Skill::Length; ++i) { skillValues.insert(std::pair<int, MWMechanics::Stat<float> >(i, MWMechanics::Stat<float>())); skillWidgetMap.insert(std::pair<int, MyGUI::StaticTextPtr>(i, nullptr)); } static_cast<MyGUI::WindowPtr>(mMainWidget)->eventWindowChangeCoord = MyGUI::newDelegate(this, &ReviewDialog::onWindowResize); // TODO: These buttons should be managed by a Dialog class MyGUI::ButtonPtr backButton; getWidget(backButton, "BackButton"); backButton->eventMouseButtonClick = MyGUI::newDelegate(this, &ReviewDialog::onBackClicked); MyGUI::ButtonPtr okButton; getWidget(okButton, "OKButton"); okButton->eventMouseButtonClick = MyGUI::newDelegate(this, &ReviewDialog::onOkClicked); }