本文整理汇总了C++中sfg::window::Ptr类的典型用法代码示例。如果您正苦于以下问题:C++ Ptr类的具体用法?C++ Ptr怎么用?C++ Ptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Run
void DesktopExample::Run() {
sf::RenderWindow render_window( sf::VideoMode( SCREEN_WIDTH, SCREEN_HEIGHT ), "SFGUI Desktop Example" );
sf::Event event;
// We have to do this because we don't use SFML to draw.
render_window.resetGLStates();
//// Main window ////
// Widgets.
m_window->SetTitle( "SFGUI Desktop Example" );
sfg::Label::Ptr intro_label( sfg::Label::Create( "Click on \"Create window\" to create any number of new windows." ) );
sfg::Button::Ptr create_window_button( sfg::Button::Create( "Create window" ) );
create_window_button->SetId( "create_window" );
// Layout.
sfg::Box::Ptr main_box( sfg::Box::Create( sfg::Box::VERTICAL, 5.f ) );
main_box->Pack( intro_label, false );
main_box->Pack( create_window_button, false );
m_window->Add( main_box );
m_desktop.Add( m_window );
// Signals.
create_window_button->GetSignal( sfg::Widget::OnLeftClick ).Connect( &DesktopExample::OnCreateWindowClick, this );
// Init.
m_desktop.SetProperty( "Button#create_window", "FontSize", 18.f );
while( render_window.isOpen() ) {
while( render_window.pollEvent( event ) ) {
if(
(event.type == sf::Event::Closed) ||
(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
) {
render_window.close();
}
else if( event.type == sf::Event::Resized ) {
m_desktop.UpdateViewRect(
sf::FloatRect(
0,
0,
static_cast<float>( render_window.getSize().x ),
static_cast<float>( render_window.getSize().y )
)
);
}
else {
m_desktop.HandleEvent( event );
}
}
m_desktop.Update( 0.f );
render_window.clear();
m_sfgui.Display( render_window );
render_window.display();
}
}
示例2: refreshPropertiesWindow
void refreshPropertiesWindow()
{
clearPropertiesWindow();
propertiesBox = sfg::Box::Create(sfg::Box::Orientation::VERTICAL, 2.0f);
windowProperties->Add(propertiesBox);
//windowProperties->SetRequisition(sf::Vector2f(150.0f,400.0f));
for (unsigned int i = 0; i < properties.size(); i++)
{
sfg::Label::Ptr label = sfg::Label::Create();
sfg::Entry::Ptr textbox = sfg::Entry::Create();
sfg::Box::Ptr box = sfg::Box::Create(sfg::Box::Orientation::HORIZONTAL, 5.0f);
box->SetRequisition(sf::Vector2f(300.0f, 28.0f));
textbox->SetRequisition(sf::Vector2f(200.0f,25.0f));
label->SetRequisition(sf::Vector2f(100.0f, 25.0f));
label->SetText(properties.at(i).Name);
textbox->SetText(properties.at(i).Value);
windowPropertiesBox.push_back(box);
windowPropertiesLabel.push_back(label);
windowPropertiesTextbox.push_back(textbox);
box->Pack(label,false,false);
box->Pack(textbox,false,false);
propertiesBox->Pack(box,false,false);
}
}
示例3: refreshToolsWindow
void refreshToolsWindow()
{
clearToolsWindow();
toolsBox = sfg::Box::Create(sfg::Box::Orientation::VERTICAL, 5.0f);
for (unsigned int i = 0; i < tools.size(); i++)
{
Tool tool = tools.at(i);
bool loaded = false;
if (!tool.Loaded)
{
if (tool.load())
{
loaded = true;
}
}
else
{
loaded = true;
}
sfg::ToggleButton::Ptr button = sfg::ToggleButton::Create();
button->SetLabel("");
if (loaded)
{
button->SetImage(tool.Image);
}
else
{
button->SetLabel(tool.Name);
}
button->GetSignal(sfg::ToggleButton::OnLeftClick).Connect(std::bind(&InterfaceWorldEditor::onButtonTool, this));
if (i == 0)
{
button->SetActive(true);
}
toolButtons.push_back(button);
toolsBox->Pack(button,false,false);
}
windowTool->Add(toolsBox);
}
示例4: Run
void ButtonsExample::Run() {
// Create the main SFML window
sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Buttons Example", sf::Style::Titlebar | sf::Style::Close );
// We have to do this because we don't use SFML to draw.
app_window.resetGLStates();
// Create our main SFGUI window
m_window = sfg::Window::Create();
m_window->SetTitle( "Title" );
// Create a Box to contain all our fun buttons ;)
sfg::Box::Ptr box = sfg::Box::Create( sfg::Box::VERTICAL, 5.f );
// Create the Button itself.
m_button = sfg::Button::Create( "Click me" );
// Add the Button to the Box
box->Pack( m_button );
// So that our Button has a meaningful purpose
// (besides just looking awesome :P) we need to tell it to connect
// to a callback of our choosing to notify us when it is clicked.
m_button->GetSignal( sfg::Widget::OnLeftClick ).Connect( &ButtonsExample::ButtonClick, this );
// If attempting to connect to a class method you need to provide
// a pointer to it as the second parameter after the function address.
// Refer to the Signals example for more information.
// Create the ToggleButton itself.
m_toggle_button = sfg::ToggleButton::Create( "Toggle me" );
// Connect the OnToggle signal to our handler.
m_toggle_button->GetSignal( sfg::ToggleButton::OnToggle ).Connect( &ButtonsExample::ButtonToggle, this );
// Add the ToggleButton to the Box
box->Pack( m_toggle_button );
// Create the CheckButton itself.
m_check_button = sfg::CheckButton::Create( "Check me" );
// Since a CheckButton is also a ToggleButton we can use
// ToggleButton signals to handle events for CheckButtons.
m_check_button->GetSignal( sfg::ToggleButton::OnToggle ).Connect( &ButtonsExample::ButtonCheck, this );
// Add the CheckButton to the Box
box->Pack( m_check_button );
// Just to keep things tidy ;)
box->Pack( sfg::Separator::Create() );
// Create our RadioButtons.
// RadioButtons each have a group they belong to. If not specified,
// a new group is created by default for each RadioButton. You can
// then use RadioButton::SetGroup() to set the group of a RadioButton
// after you create them. If you already know which buttons will belong
// to the same group you can just pass the group of the first button
// to the following buttons when you construct them as we have done here.
m_radio_button1 = sfg::RadioButton::Create( "Either this" );
m_radio_button2 = sfg::RadioButton::Create( "Or this", m_radio_button1->GetGroup() );
m_radio_button3 = sfg::RadioButton::Create( "Or maybe even this", m_radio_button1->GetGroup() );
// Set the third RadioButton to be the active one.
// By default none of the RadioButtons are active at start.
m_radio_button3->SetActive( true );
// Here we use the same handler for all three RadioButtons.
// RadioButtons are CheckButtons and therefore also ToggleButtons,
// hence we can use ToggleButton signals with RadioButtons as well.
m_radio_button1->GetSignal( sfg::ToggleButton::OnToggle ).Connect( &ButtonsExample::ButtonSelect, this );
m_radio_button2->GetSignal( sfg::ToggleButton::OnToggle ).Connect( &ButtonsExample::ButtonSelect, this );
m_radio_button3->GetSignal( sfg::ToggleButton::OnToggle ).Connect( &ButtonsExample::ButtonSelect, this );
// Add the RadioButtons to the Box
box->Pack( m_radio_button1 );
box->Pack( m_radio_button2 );
box->Pack( m_radio_button3 );
// Finally add the Box to the window.
m_window->Add( box );
// Start the game loop
while ( app_window.isOpen() ) {
// Process events
sf::Event event;
while ( app_window.pollEvent( event ) ) {
// Handle events
m_window->HandleEvent( event );
// Close window : exit
if ( event.type == sf::Event::Closed ) {
app_window.close();
}
}
// Update the GUI, note that you shouldn't normally
// pass 0 seconds to the update method.
m_window->Update( 0.f );
//.........这里部分代码省略.........
示例5: Run
void Application::Run() {
sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Button Example", sf::Style::Titlebar | sf::Style::Close );
// We have to do this because we don't use SFML to draw.
app_window.resetGLStates();
window = sfg::Window::Create();
window->SetTitle( "Title" );
sfg::Box::Ptr box = sfg::Box::Create( sfg::Box::VERTICAL );
window->Add( box );
// Possibility 1, normal function
sfg::Button::Ptr button1 = sfg::Button::Create();
button1->SetLabel( "Clicky 1" );
button1->OnLeftClick.Connect( &Foo );
box->Pack( button1, false );
// Possibility 2, this class
sfg::Button::Ptr button2 = sfg::Button::Create();
button2->SetLabel( "Clicky 2" );
button2->OnLeftClick.Connect( &Application::Bar, this );
box->Pack( button2, false );
// Possibility 3, objects
BazClass baz_array[3] = { BazClass( 1 ), BazClass( 2 ), BazClass( 3 ) };
for( int i = 0; i < 3; i++ ) {
std::stringstream sstr;
sstr << "Clicky " << i + 3;
sfg::Button::Ptr button = sfg::Button::Create();
button->SetLabel( sstr.str() );
// This is just a more complicated way of passing a pointer to a
// BazClass to Connect() when the BazClass object is part of an array.
// Passing normal pointers such as &baz1 would also work.
button->OnLeftClick.Connect( &BazClass::Baz, &( baz_array[i] ) );
box->Pack( button, false );
}
// Notice that with possibility 3 you can do very advanced things. The tricky
// part of implementing it this way is that the method address has to be
// known at compile time, which means that only the instanciated object itself
// is able to pick how it will behave when that method is called on it. This
// way you can also connect signals to dynamically determined behavior.
// For further reading on this topic refer to Design Patterns and as
// specialized cases similar to the one in this example the
// Factory Method Pattern and Abstract Factory Pattern.
while ( app_window.isOpen() ) {
sf::Event event;
while ( app_window.pollEvent( event ) ) {
window->HandleEvent( event );
if ( event.type == sf::Event::Closed ) {
app_window.close();
}
}
// Update the GUI, note that you shouldn't normally
// pass 0 seconds to the update method.
window->Update( 0.f );
// Clear screen
app_window.clear();
// Draw the GUI
m_sfgui.Display( app_window );
// Update the window
app_window.display();
}
// If you have any global or static widgets,
// you need to reset their pointers before your
// application exits.
window.reset();
}
示例6: Run
void SampleApp::Run() {
sf::Event event;
//m_window.SetFramerateLimit( 60 );
//m_window.EnableVerticalSync( true );
// Tune Renderer
sfg::Renderer::Get().TuneDepthTest( sfg::Renderer::ALTERNATE_DEPTH );
sfg::Renderer::Get().TuneAlphaThreshold( .2f );
sfg::Renderer::Get().TunePrecomputeBlending( true );
sfg::Renderer::Get().TuneCull( true );
// Create widgets.
m_wndmain = sfg::Window::Create( sfg::Window::TITLEBAR | sfg::Window::BACKGROUND | sfg::Window::RESIZE );
m_wndmain->SetTitle( L"Example application" );
sfg::Button::Ptr btnaddbuttonh( sfg::Button::Create( L"Add button horizontally" ) );
sfg::Button::Ptr btnaddbuttonv( sfg::Button::Create( L"Add button vertically" ) );
m_titlebar_toggle = sfg::ToggleButton::Create( "Toggle titlebar" );
m_titlebar_toggle->SetActive( true );
{
sf::Image add_image;
if( add_image.loadFromFile( "data/add.png" ) ) {
sfg::Image::Ptr image( sfg::Image::Create( add_image ) );
btnaddbuttonh->SetImage( image );
image = sfg::Image::Create( add_image );
btnaddbuttonv->SetImage( image );
}
}
sfg::Button::Ptr btnhidewindow( sfg::Button::Create( L"Close window" ) );
btnhidewindow->SetId( "close" );
{
sf::Image close_image;
if( close_image.loadFromFile( "data/delete.png" ) ) {
sfg::Image::Ptr image( sfg::Image::Create( close_image ) );
btnhidewindow->SetImage( image );
}
}
sfg::Button::Ptr btntogglespace( sfg::Button::Create( L"Box Spacing") );
sfg::Button::Ptr btnloadstyle( sfg::Button::Create( L"Load theme") );
m_entry = sfg::Entry::Create( L"Type" );
m_entry->SetRequisition( sf::Vector2f( 100.f, .0f ) );
m_entry->AppendText( L" something!" );
m_limit_check = sfg::CheckButton::Create( L"Limit to 4 chars" );
m_limit_check->SetId( "limit_check" );
sfg::Entry::Ptr password( sfg::Entry::Create() );
password->HideText( '*' );
// Layout.
sfg::Box::Ptr boxtoolbar( sfg::Box::Create( sfg::Box::HORIZONTAL ) );
boxtoolbar->SetSpacing( 5.f );
boxtoolbar->Pack( btnaddbuttonh, false );
boxtoolbar->Pack( btnaddbuttonv, false );
boxtoolbar->Pack( m_titlebar_toggle, false );
boxtoolbar->Pack( btnhidewindow, false );
boxtoolbar->Pack( m_entry, true );
boxtoolbar->Pack( m_limit_check, false );
sfg::Frame::Ptr frame1( sfg::Frame::Create( L"Toolbar 1" ) );
frame1->Add( boxtoolbar );
sfg::Box::Ptr boxtoolbar2( sfg::Box::Create( sfg::Box::HORIZONTAL ) );
boxtoolbar2->SetSpacing( 5.f );
boxtoolbar2->Pack( btntogglespace, false );
boxtoolbar2->Pack( btnloadstyle, false );
m_boxbuttonsh = sfg::Box::Create( sfg::Box::HORIZONTAL );
m_boxbuttonsh->SetSpacing( 5.f );
m_boxbuttonsv = sfg::Box::Create( sfg::Box::VERTICAL );
m_boxbuttonsv->SetSpacing( 5.f );
sfg::Entry::Ptr username_entry( sfg::Entry::Create() );
username_entry->SetMaximumLength( 8 );
m_progress = sfg::ProgressBar::Create( sfg::ProgressBar::HORIZONTAL );
m_progress->SetRequisition( sf::Vector2f( 0.f, 20.f ) );
m_progress_vert = sfg::ProgressBar::Create( sfg::ProgressBar::VERTICAL );
m_progress_vert->SetRequisition( sf::Vector2f( 20.f, 0.f ) );
sfg::Separator::Ptr separatorv( sfg::Separator::Create( sfg::Separator::VERTICAL ) );
m_table = sfg::Table::Create();
m_table->Attach( sfg::Label::Create( L"Please login using your username and password (span example)." ), sf::Rect<sf::Uint32>( 0, 0, 2, 1 ), sfg::Table::FILL, sfg::Table::FILL | sfg::Table::EXPAND );
m_table->Attach( sfg::Label::Create( L"Username:" ), sf::Rect<sf::Uint32>( 0, 1, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL );
m_table->Attach( username_entry, sf::Rect<sf::Uint32>( 1, 1, 1, 1 ), sfg::Table::EXPAND | sfg::Table::FILL, sfg::Table::FILL );
m_table->Attach( sfg::Label::Create( L"Password:" ), sf::Rect<sf::Uint32>( 0, 2, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL );
m_table->Attach( password, sf::Rect<sf::Uint32>( 1, 2, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL );
m_table->Attach( sfg::Button::Create( L"Login" ), sf::Rect<sf::Uint32>( 2, 1, 1, 2 ), sfg::Table::FILL, sfg::Table::FILL );
m_table->Attach( separatorv, sf::Rect<sf::Uint32>( 3, 0, 1, 3 ), sfg::Table::FILL, sfg::Table::FILL );
m_table->Attach( m_progress_vert, sf::Rect<sf::Uint32>( 4, 0, 1, 3 ), sfg::Table::FILL, sfg::Table::FILL );
//.........这里部分代码省略.........
示例7: Run
void SampleApp::Run() {
sf::Event event;
//m_window.SetFramerateLimit( 60 );
//m_window.EnableVerticalSync( true );
// Tune Renderer
m_sfgui.TuneUseFBO( true );
m_sfgui.TuneAlphaThreshold( .2f );
m_sfgui.TuneCull( true );
// Create widgets.
m_wndmain = sfg::Window::Create( sfg::Window::TITLEBAR | sfg::Window::BACKGROUND | sfg::Window::RESIZE );
m_wndmain->SetTitle( L"Example application" );
sfg::Button::Ptr btnaddbuttonh( sfg::Button::Create( L"Add button horizontally" ) );
sfg::Button::Ptr btnaddbuttonv( sfg::Button::Create( L"Add button vertically" ) );
m_titlebar_toggle = sfg::ToggleButton::Create( "Toggle titlebar" );
m_titlebar_toggle->SetActive( true );
{
sf::Image add_image;
if( add_image.loadFromFile( "data/add.png" ) ) {
sfg::Image::Ptr image( sfg::Image::Create( add_image ) );
btnaddbuttonh->SetImage( image );
image = sfg::Image::Create( add_image );
btnaddbuttonv->SetImage( image );
}
}
sfg::Button::Ptr btnhidewindow( sfg::Button::Create( L"Close window" ) );
btnhidewindow->SetId( "close" );
{
sf::Image close_image;
if( close_image.loadFromFile( "data/delete.png" ) ) {
sfg::Image::Ptr image( sfg::Image::Create( close_image ) );
btnhidewindow->SetImage( image );
}
}
sfg::Button::Ptr btntogglespace( sfg::Button::Create( L"Box Spacing") );
sfg::Button::Ptr btnloadstyle( sfg::Button::Create( L"Load theme") );
m_entry = sfg::Entry::Create( L"Type" );
m_entry->SetRequisition( sf::Vector2f( 100.f, .0f ) );
m_entry->AppendText( L" something!" );
m_limit_check = sfg::CheckButton::Create( L"Limit to 4 chars" );
m_limit_check->SetId( "limit_check" );
sfg::Entry::Ptr password( sfg::Entry::Create() );
password->HideText( '*' );
// Layout.
sfg::Box::Ptr boxtoolbar( sfg::Box::Create( sfg::Box::HORIZONTAL ) );
boxtoolbar->SetSpacing( 5.f );
boxtoolbar->Pack( btnaddbuttonh, false );
boxtoolbar->Pack( btnaddbuttonv, false );
boxtoolbar->Pack( m_titlebar_toggle, false );
boxtoolbar->Pack( btnhidewindow, false );
boxtoolbar->Pack( m_entry, true );
boxtoolbar->Pack( m_limit_check, false );
sfg::Frame::Ptr frame1( sfg::Frame::Create( L"Toolbar 1" ) );
frame1->Add( boxtoolbar );
sfg::Box::Ptr boxtoolbar2( sfg::Box::Create( sfg::Box::HORIZONTAL ) );
boxtoolbar2->SetSpacing( 5.f );
boxtoolbar2->Pack( btntogglespace, false );
boxtoolbar2->Pack( btnloadstyle, false );
m_boxbuttonsh = sfg::Box::Create( sfg::Box::HORIZONTAL );
m_boxbuttonsh->SetSpacing( 5.f );
m_boxbuttonsv = sfg::Box::Create( sfg::Box::VERTICAL );
m_boxbuttonsv->SetSpacing( 5.f );
sfg::Entry::Ptr username_entry( sfg::Entry::Create() );
username_entry->SetMaximumLength( 8 );
m_progress = sfg::ProgressBar::Create( sfg::ProgressBar::HORIZONTAL );
m_progress->SetRequisition( sf::Vector2f( 0.f, 20.f ) );
m_progress_vert = sfg::ProgressBar::Create( sfg::ProgressBar::VERTICAL );
m_progress_vert->SetRequisition( sf::Vector2f( 20.f, 0.f ) );
sfg::Separator::Ptr separatorv( sfg::Separator::Create( sfg::Separator::VERTICAL ) );
m_table = sfg::Table::Create();
m_table->Attach( sfg::Label::Create( L"Please login using your username and password (span example)." ), sf::Rect<sf::Uint32>( 0, 0, 2, 1 ), sfg::Table::FILL, sfg::Table::FILL | sfg::Table::EXPAND );
m_table->Attach( sfg::Label::Create( L"Username:" ), sf::Rect<sf::Uint32>( 0, 1, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL );
m_table->Attach( username_entry, sf::Rect<sf::Uint32>( 1, 1, 1, 1 ), sfg::Table::EXPAND | sfg::Table::FILL, sfg::Table::FILL );
m_table->Attach( sfg::Label::Create( L"Password:" ), sf::Rect<sf::Uint32>( 0, 2, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL );
m_table->Attach( password, sf::Rect<sf::Uint32>( 1, 2, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL );
m_table->Attach( sfg::Button::Create( L"Login" ), sf::Rect<sf::Uint32>( 2, 1, 1, 2 ), sfg::Table::FILL, sfg::Table::FILL );
m_table->Attach( separatorv, sf::Rect<sf::Uint32>( 3, 0, 1, 3 ), sfg::Table::FILL, sfg::Table::FILL );
m_table->Attach( m_progress_vert, sf::Rect<sf::Uint32>( 4, 0, 1, 3 ), sfg::Table::FILL, sfg::Table::FILL );
m_table->SetRowSpacings( 5.f );
//.........这里部分代码省略.........
示例8: ButtonCheck
void ButtonsExample::ButtonCheck() {
// When the CheckButton is active hide the window's background.
if( m_check_button->IsActive() ) {
m_window->SetStyle( m_window->GetStyle() & ~sfg::Window::BACKGROUND );
}
else {
m_window->SetStyle( m_window->GetStyle() | sfg::Window::BACKGROUND );
}
}
示例9: ButtonToggle
void ButtonsExample::ButtonToggle() {
// When the ToggleButton is active hide the window's titlebar.
if( m_toggle_button->IsActive() ) {
m_window->SetStyle( m_window->GetStyle() & ~sfg::Window::TITLEBAR );
}
else {
m_window->SetStyle( m_window->GetStyle() | sfg::Window::TITLEBAR );
}
}
示例10: ButtonSelect
void ButtonsExample::ButtonSelect() {
// Depending on which RadioButton is active
// we set the window title accordingly.
if( m_radio_button1->IsActive() ) {
m_window->SetTitle( "First button selected" );
}
else if( m_radio_button2->IsActive() ) {
m_window->SetTitle( "Second button selected" );
}
else if( m_radio_button3->IsActive() ) {
m_window->SetTitle( "Third button selected" );
}
}
示例11: clearPropertiesWindow
void clearPropertiesWindow()
{
windowProperties->RemoveAll();
windowPropertiesLabel.clear();
windowPropertiesTextbox.clear();
windowPropertiesBox.clear();
}
示例12: Baz
void BazClass::Baz() {
// This is where the object picks how it is going to behave
// based on it's type.
switch( m_type ) {
case 1:
window->SetTitle( "Baz1" );
break;
case 2:
window->SetTitle( "Baz2" );
break;
case 3:
window->SetTitle( "Baz3" );
break;
default:
break;
}
}
示例13: setProperties
void setProperties(const vector<Property>& list)
{
properties = list;
// Find a name
for (unsigned int i = 0; i < properties.size(); i++)
{
if (properties.at(i).Name == "name")
{
windowProperties->SetTitle("Properties for '" + properties.at(i).Value + "'");
break;
}
}
refreshPropertiesWindow();
}
示例14: OnToggleTitlebarClick
void SampleApp::OnToggleTitlebarClick() {
m_wndmain->SetStyle( m_wndmain->GetStyle() ^ sfg::Window::TITLEBAR );
}
示例15: Bar
// The definition of the second possibility
void Application::Bar() {
window->SetTitle( "Bar" );
}