event_result message_dispatcher::fire_on_syncevent(app& the_app, const system_event& se)
	{
		ANativeWindow *wnd;

		read(m_readfd, &wnd, sizeof(wnd));

		LOGI("%s:%d> firing %s, wnd = %p\n", __FILE__, __LINE__, get_sys_event_name(se).c_str(), wnd);

		bool h = false;

		switch (se) {
		case system_event::window_created:
			h = the_app.on_window_created(app_window(wnd));
			m_has_window = true;
			break;
		case system_event::window_destroyed:
			h = the_app.on_window_destroyed(app_window(wnd));
			m_has_window = false;
			break;
		case system_event::window_exposed:
			h = the_app.on_window_exposed(app_window(wnd));
			break;
		case system_event::window_resized:
			h = the_app.on_window_resized(app_window(wnd));
			break;
		default:
			break;
		}
		m_syncevent.up();
		return h ? event_result::handled : event_result::unhandled;
	}
Exemple #2
0
int main() {
	// Create the main SFML window
	sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Image Example", sf::Style::Titlebar | sf::Style::Close );

	// We have to do this because we don't use SFML to draw.
	app_window.resetGLStates();

	// Create an SFGUI. This is required before doing anything with SFGUI.
	sfg::SFGUI sfgui;

	// Create our main SFGUI window
	sfg::Window::Ptr window;
	window = sfg::Window::Create();
	window->SetTitle( "Title" );

	// Our sf::Image source
	sf::Image sfgui_logo;

	// Our sfg::Image
	sfg::Image::Ptr image = sfg::Image::Create();

	// Try to load the image
	if( sfgui_logo.loadFromFile( "data/sfgui.png" ) ) {
		image->SetImage( sfgui_logo );
	}

	// Add the image to the window.
	window->Add( image );

	// Start the game loop
	while ( app_window.isOpen() ) {
		// Process events
		sf::Event event;

		while ( app_window.pollEvent( event ) ) {
			// Handle events
			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.
		window->Update( 0.f );

		// Clear screen
		app_window.clear();

		// Draw the GUI
		sfgui.Display( app_window );

		// Update the window
		app_window.display();
	}

	return EXIT_SUCCESS;
}
Exemple #3
0
int main() {
	// An sf::Window for raw OpenGL rendering.
	sf::Window app_window( sf::VideoMode( 800, 600 ), "SFGUI with OpenGL example", sf::Style::Titlebar | sf::Style::Close );

	// Create an SFGUI. This is required before doing anything with SFGUI.
	sfg::SFGUI sfgui;

	// Set the SFML Window's context back to the active one. SFGUI creates
	// a temporary context on creation that is set active.
	app_window.setActive();

	// Initial OpenGL setup.
	// We have to set up our own OpenGL viewport because we are using an sf::Window.
	glViewport( 0, 0, static_cast<int>( app_window.getSize().x ), static_cast<int>( app_window.getSize().y ) );

	auto red_scale = sfg::Scale::Create( 0.f, 1.f, .01f, sfg::Scale::Orientation::HORIZONTAL );
	auto green_scale = sfg::Scale::Create( 0.f, 1.f, .01f, sfg::Scale::Orientation::HORIZONTAL );
	auto blue_scale = sfg::Scale::Create( 0.f, 1.f, .01f, sfg::Scale::Orientation::HORIZONTAL );
	auto angle_scale = sfg::Scale::Create( 0.f, 360.f, 1.f, sfg::Scale::Orientation::HORIZONTAL );
	auto auto_check = sfg::CheckButton::Create( "Auto" );

	auto table = sfg::Table::Create();
	table->SetRowSpacings( 5.f );
	table->SetColumnSpacings( 5.f );

	table->Attach( sfg::Label::Create( "Change the color of the rect using the scales below." ), sf::Rect<sf::Uint32>( 0, 0, 3, 1 ), sfg::Table::FILL, sfg::Table::FILL );
	table->Attach( sfg::Label::Create( "Red:" ), sf::Rect<sf::Uint32>( 0, 1, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL );
	table->Attach( red_scale, sf::Rect<sf::Uint32>( 1, 1, 1, 1 ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND );
	table->Attach( sfg::Label::Create( "Green:" ), sf::Rect<sf::Uint32>( 0, 2, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL );
	table->Attach( green_scale, sf::Rect<sf::Uint32>( 1, 2, 1, 1 ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND );
	table->Attach( sfg::Label::Create( "Blue:" ), sf::Rect<sf::Uint32>( 0, 3, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL );
	table->Attach( blue_scale, sf::Rect<sf::Uint32>( 1, 3, 1, 1 ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND );
	table->Attach( sfg::Label::Create( "Angle:" ), sf::Rect<sf::Uint32>( 0, 4, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL );
	table->Attach( angle_scale, sf::Rect<sf::Uint32>( 1, 4, 1, 1 ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND );
	table->Attach( auto_check, sf::Rect<sf::Uint32>( 2, 4, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL );

	auto window = sfg::Window::Create();
	window->SetTitle( "SFGUI with OpenGL" );
	window->Add( table );

	sfg::Desktop desktop;
	desktop.Add( window );

	red_scale->SetValue( .2f );
	green_scale->SetValue( .5f );
	blue_scale->SetValue( .8f );

	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();

	static const auto pi = 3.1415926535897932384626433832795f;
	static const auto fov = 90.f;
	static const auto near_distance = .1f;
	static const auto far_distance = 100.f;
	static const auto aspect = 800.f / 600.f;

	auto frustum_height = std::tan( fov / 360 * pi ) * near_distance;
	auto frustum_width = frustum_height * aspect;

	glFrustum( -frustum_width, frustum_width, -frustum_height, frustum_height, near_distance, far_distance );

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();

	sf::Event event;

	sf::Clock clock;

	while( app_window.isOpen() ) {
		auto delta = clock.restart().asSeconds();

		while( app_window.pollEvent( event ) ) {
			if( event.type == sf::Event::Closed ) {
				app_window.close();
			}
			else {
				desktop.HandleEvent( event );
			}
		}

		if( auto_check->IsActive() ) {
			float angle( angle_scale->GetValue() );
			angle += delta * 90.f;

			while( angle >= 360.f ) {
				angle -= 360.f;
			}

			angle_scale->SetValue( angle );
		}

		glClear( GL_COLOR_BUFFER_BIT );

		glMatrixMode( GL_MODELVIEW );

		glLoadIdentity();
		glRotatef( angle_scale->GetValue(), 0.f, 0.f, 1.f );
		glTranslatef( -.5f, -.5f, -5.f );

		glBegin( GL_QUADS );
		glColor3f( red_scale->GetValue(), green_scale->GetValue(), blue_scale->GetValue() );
		glVertex3f( 0.f, 1.f, 0.f );
		glVertex3f( 0.f, 0.f, 0.f );
		glVertex3f( 1.f, 0.f, 0.f );
		glVertex3f( 1.f, 1.f, 0.f );
		glEnd();

		desktop.Update( delta );

		// SFGUI rendering.
		sfgui.Display( app_window );

		app_window.display();
	}

	return 0;
}
Exemple #4
0
int main() {
	// Create the main SFML window
	sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Layout Example", sf::Style::Titlebar | sf::Style::Close );

	// We have to do this because we don't use SFML to draw.
	app_window.resetGLStates();

	// Create an SFGUI. This is required before doing anything with SFGUI.
	sfg::SFGUI sfgui;

	// Create our main SFGUI window
	auto window = sfg::Window::Create();
	window->SetTitle( "Resize me!" );

	// Create a box with 20 pixels spacing.
	auto box = sfg::Box::Create( sfg::Box::Orientation::VERTICAL, 20.f );

	// Create some buttons.
	auto button_aligned = sfg::Button::Create( "Aligned 0.8f right and bottom" );
	auto button_fixed = sfg::Button::Create( "Fixed at (200, 50)" );

	// Create a fixed.
	auto fixed = sfg::Fixed::Create();

	// Add button_fixed to the fixed at (200, 50).
	fixed->Put( button_fixed, sf::Vector2f( 200.f, 50.f ) );

	// Add our fixed to the box and set not to expand.
	box->Pack( fixed, false, true );

	// Create a separator.
	auto separator = sfg::Separator::Create( sfg::Separator::Orientation::HORIZONTAL );

	// Add separator to box and set not to expand.
	box->Pack( separator, false, true );

	// Create an alignment.
	auto alignment = sfg::Alignment::Create();

	// Because we want to align our button horizontally, we need
	// to place our alignment in a horizontal box set to expand and fill.
	auto alignment_box = sfg::Box::Create( sfg::Box::Orientation::HORIZONTAL );
	alignment_box->Pack( alignment, true, true );

	// Add button_aligned to the alignment.
	alignment->Add( button_aligned );

	// Set scaling parameters.
	// Scaling sets how much of the total space in the alignment
	// the child gets to fill up. 1.0f for x and y would mean the
	// child gets to use the whole space. Setting it to 0.0f for
	// x and y makes the child get as little space as possible.
	alignment->SetScale( sf::Vector2f( .0f, .0f ) );

	// Set alignment parameters.
	// Alignment aligns the child widget within the alignment's area.
	// 0.0f for x aligns to the left, 1.0f for x aligns to the right.
	// 0.0f for y aligns to the top, 1.0f for y aligns to the bottom.
	alignment->SetAlignment( sf::Vector2f( .8f, .8f ) );

	// Create our frame.
	auto frame = sfg::Frame::Create( "Frame Title" );

	// We can align the frame title just like an alignment.
	frame->SetAlignment( sf::Vector2f( .8f, .5f ) );

	// Add our alignment box into the frame.
	frame->Add( alignment_box );

	// Add our frame to the box.
	box->Pack( frame, true, true );

	// Add the box to the window.
	window->Add( box );

	// Start the game loop
	while ( app_window.isOpen() ) {
		// Process events
		sf::Event event;

		while ( app_window.pollEvent( event ) ) {
			// Handle events
			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.
		window->Update( 0.f );

		// Clear screen
		app_window.clear();

		// Draw the GUI
		sfgui.Display( app_window );

		// Update the window
		app_window.display();
	}

	return EXIT_SUCCESS;
}
void ScrolledWindowViewportExample::Run() {
	// Create the main SFML window
	sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI ScrolledWindow and Viewport 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
	sfg::Window::Ptr window;
	window = sfg::Window::Create();
	window->SetTitle( "Title" );

	// Create a box with 10 pixel spacing.
	sfg::Box::Ptr box = sfg::Box::Create( sfg::Box::VERTICAL, 10.f );

	// Create a button and connect the click signal.
	sfg::Button::Ptr button = sfg::Button::Create( "Add a button" );
	button->GetSignal( sfg::Widget::OnLeftClick ).Connect( &ScrolledWindowViewportExample::OnButtonClick, this );

	// Create a box for our ScrolledWindow. ScrolledWindows are bins
	// and can only contain 1 child widget.
	m_scrolled_window_box = sfg::Box::Create( sfg::Box::VERTICAL );

	// Create the ScrolledWindow.
	sfg::ScrolledWindow::Ptr scrolledwindow = sfg::ScrolledWindow::Create();

	// Set the ScrolledWindow to always show the horizontal scrollbar
	// and only show the vertical scrollbar when needed.
	scrolledwindow->SetScrollbarPolicy( sfg::ScrolledWindow::HORIZONTAL_ALWAYS | sfg::ScrolledWindow::VERTICAL_AUTOMATIC );

	// Add the ScrolledWindow box to the ScrolledWindow
	// and create a new viewport automatically.
	scrolledwindow->AddWithViewport( m_scrolled_window_box );

	// Always remember to set the minimum size of a ScrolledWindow.
	scrolledwindow->SetRequisition( sf::Vector2f( 500.f, 100.f ) );

	// Create a viewport.
	sfg::Viewport::Ptr viewport = sfg::Viewport::Create();

	// Always remember to set the minimum size of a Viewport.
	viewport->SetRequisition( sf::Vector2f( 500.f, 200.f ) );

	// Set the vertical adjustment values of the Viewport.
	viewport->GetVerticalAdjustment()->SetLower( 0.f );
	viewport->GetVerticalAdjustment()->SetUpper( 100000000.f );

	// Create a box for our Viewport. Viewports are bins
	// as well and can only contain 1 child widget.
	sfg::Box::Ptr viewport_box = sfg::Box::Create( sfg::Box::VERTICAL );

	sf::err() << "Generating random strings, please be patient..." << std::endl;

	// Create some random text.
	for( int i = 0; i < 200; i++ ) {
		std::string str;

		for( int j = 0; j < 20; j++ ) {
			str += static_cast<char>( 65 + rand() % 26 );
		}

		// Add the text to the Viewport box.
		viewport_box->Pack( sfg::Label::Create( str.c_str() ) );
	}

	// Add the Viewport box to the viewport.
	viewport->Add( viewport_box );

	// Add everything to our box.
	box->Pack( button, false, true );
	box->Pack( scrolledwindow, false, true );
	box->Pack( viewport, true, true );

	// Add the box to the window.
	window->Add( box );

	sf::Clock clock;

	// Start the game loop
	while ( app_window.isOpen() ) {
		// Process events
		sf::Event event;

		while ( app_window.pollEvent( event ) ) {
			// Handle events
			window->HandleEvent( event );

			// Close window : exit
			if ( event.type == sf::Event::Closed ) {
				app_window.close();
			}
		}

		// Update the GUI every 1ms
		if( clock.getElapsedTime().asMicroseconds() >= 1000 ) {
			float delta = static_cast<float>( clock.getElapsedTime().asMicroseconds() ) / 1000000.f;

			// Update() takes the elapsed time in seconds.
			window->Update( delta );

			// Add a nice automatic scrolling effect to our viewport ;)
			viewport->GetVerticalAdjustment()->SetValue( viewport->GetVerticalAdjustment()->GetValue() + delta * 10.f );

			clock.restart();
		}

		// Clear screen
		app_window.clear();

		// Draw the GUI
		m_sfgui.Display( app_window );

		// Update the window
		app_window.display();
	}
}
Exemple #6
0
int main() {
	// An sf::Window for raw OpenGL rendering.
	sf::Window app_window( sf::VideoMode( 800, 600 ), "SFGUI with OpenGL example", sf::Style::Titlebar | sf::Style::Close );

	// Create an SFGUI. This is required before doing anything with SFGUI.
	sfg::SFGUI sfgui;

	// Set the SFML Window's context back to the active one. SFGUI creates
	// a temporary context on creation that is set active.
	app_window.setActive();

	// Initial OpenGL setup.
	// We have to set up our own OpenGL viewport because we are using an sf::Window.
	glViewport( 0, 0, app_window.getSize().x, app_window.getSize().y );

	sfg::Scale::Ptr red_scale( sfg::Scale::Create( 0.f, 1.f, .01f, sfg::Scale::HORIZONTAL ) );
	sfg::Scale::Ptr green_scale( sfg::Scale::Create( 0.f, 1.f, .01f, sfg::Scale::HORIZONTAL ) );
	sfg::Scale::Ptr blue_scale( sfg::Scale::Create( 0.f, 1.f, .01f, sfg::Scale::HORIZONTAL ) );
	sfg::Scale::Ptr angle_scale( sfg::Scale::Create( 0.f, 360.f, 1.f, sfg::Scale::HORIZONTAL ) );
	sfg::CheckButton::Ptr auto_check( sfg::CheckButton::Create( "Auto" ) );

	sfg::Table::Ptr table( sfg::Table::Create() );
	table->SetRowSpacings( 5.f );
	table->SetColumnSpacings( 5.f );

	table->Attach( sfg::Label::Create( "Change the color of the rect using the scales below." ), sf::Rect<sf::Uint32>( 0, 0, 3, 1 ), sfg::Table::FILL, sfg::Table::FILL );
	table->Attach( sfg::Label::Create( "Red:" ), sf::Rect<sf::Uint32>( 0, 1, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL );
	table->Attach( red_scale, sf::Rect<sf::Uint32>( 1, 1, 1, 1 ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND );
	table->Attach( sfg::Label::Create( "Green:" ), sf::Rect<sf::Uint32>( 0, 2, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL );
	table->Attach( green_scale, sf::Rect<sf::Uint32>( 1, 2, 1, 1 ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND );
	table->Attach( sfg::Label::Create( "Blue:" ), sf::Rect<sf::Uint32>( 0, 3, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL );
	table->Attach( blue_scale, sf::Rect<sf::Uint32>( 1, 3, 1, 1 ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND );
	table->Attach( sfg::Label::Create( "Angle:" ), sf::Rect<sf::Uint32>( 0, 4, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL );
	table->Attach( angle_scale, sf::Rect<sf::Uint32>( 1, 4, 1, 1 ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND );
	table->Attach( auto_check, sf::Rect<sf::Uint32>( 2, 4, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL );

	sfg::Window::Ptr window( sfg::Window::Create() );
	window->SetTitle( "SFGUI with OpenGL" );
	window->Add( table );

	sfg::Desktop desktop;
	desktop.Add( window );

	red_scale->SetValue( .2f );
	green_scale->SetValue( .5f );
	blue_scale->SetValue( .8f );

	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	gluPerspective( 90.f, 800.f / 600.f, .1f, 100.f );

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();

	sf::Event event;

	sf::Clock clock;

	while( app_window.isOpen() ) {
		while( app_window.pollEvent( event ) ) {
			if( event.type == sf::Event::Closed ) {
				app_window.close();
			}
			else {
				desktop.HandleEvent( event );
			}
		}

		if( auto_check->IsActive() ) {
			float angle( angle_scale->GetValue() );
			angle += static_cast<float>( clock.getElapsedTime().asMicroseconds() ) * .0005f;

			while( angle >= 360.f ) {
				angle -= 360.f;
			}

			angle_scale->SetValue( angle );
		}

		glClear( GL_COLOR_BUFFER_BIT );

		glMatrixMode( GL_MODELVIEW );

		glLoadIdentity();
		glRotatef( angle_scale->GetValue(), 0.f, 0.f, 1.f );
		glTranslatef( -.5f, -.5f, -5.f );

		glBegin( GL_QUADS );
		glColor3f( red_scale->GetValue(), green_scale->GetValue(), blue_scale->GetValue() );
		glVertex3f( 0.f, 1.f, 0.f );
		glVertex3f( 0.f, 0.f, 0.f );
		glVertex3f( 1.f, 0.f, 0.f );
		glVertex3f( 1.f, 1.f, 0.f );
		glEnd();

		desktop.Update( clock.restart().asSeconds() );

		// SFGUI rendering.
		sfgui.Display( app_window );

		app_window.display();

		clock.restart();
	}

	return 0;
}
Exemple #7
0
int main() {
	// Create the main SFML window
	sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Canvas Example", sf::Style::Titlebar | sf::Style::Close );

	// We have to do this because we don't use SFML to draw.
	app_window.resetGLStates();

	// Create an SFGUI. This is required before doing anything with SFGUI.
	sfg::SFGUI sfgui;

	// Create our OpenGL canvas window
	sfg::Window::Ptr opengl_window;
	opengl_window = sfg::Window::Create();
	opengl_window->SetTitle( "OpenGL canvas" );
	opengl_window->SetPosition( sf::Vector2f( 100.f, 100.f ) );

	// Create our SFML canvas window
	sfg::Window::Ptr sfml_window;
	sfml_window = sfg::Window::Create();
	sfml_window->SetTitle( "SFML canvas" );
	sfml_window->SetPosition( sf::Vector2f( 400.f, 100.f ) );

	// Create our Canvas smart pointers.
	sfg::Canvas::Ptr opengl_canvas;
	sfg::Canvas::Ptr sfml_canvas;

	// Create the Canvases themselves.
	// Passing true in to Create() tells SFGUI
	// to create a depth buffer for the canvas.
	// This might be needed for your OpenGL rendering.
	// Specifying nothing defaults to no depth buffer.
	opengl_canvas = sfg::Canvas::Create( true );
	sfml_canvas = sfg::Canvas::Create();

	// Add the Canvases to the windows.
	opengl_window->Add( opengl_canvas );
	sfml_window->Add( sfml_canvas );

	// Create an sf::Sprite for demonstration purposes.
	sf::Texture texture;
	texture.loadFromFile( "data/sfgui.png" );
	sf::Sprite sprite;
	sprite.setTexture( texture );

	// Because Canvases provide a virtual surface to draw
	// on much like a ScrolledWindow, specifying their
	// minimum requisition is necessary.
	opengl_canvas->SetRequisition( sf::Vector2f( 200.f, 150.f ) );
	sfml_canvas->SetRequisition( sf::Vector2f( texture.getSize() ) );

	// Create a desktop to contain our Windows.
	sfg::Desktop desktop;
	desktop.Add( opengl_window );
	desktop.Add( sfml_window );

	sf::Clock clock;

	// Start the game loop
	while ( app_window.isOpen() ) {
		// Process events
		sf::Event event;

		while ( app_window.pollEvent( event ) ) {
			// Handle events
			desktop.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.
		desktop.Update( 0.f );

		// Clear screen
		app_window.clear();

		// We bind the Canvases and draw whatever we want to them.
		// This must occur BEFORE the GUI is displayed.
		// You must not forget to set whatever context was active
		// before to active again after you unbind a Canvas.
		// Clear() takes an RGBA color and a bool which specifies
		// if you want to clear the depth buffer as well. In this
		// case, we do.

		// First the Canvas for OpenGL rendering.
		opengl_canvas->Bind();
		opengl_canvas->Clear( sf::Color( 0, 0, 0, 0 ), true );

		// Do some OpenGL drawing. If you don't intend
		// on drawing with OpenGL just ignore this section.
		glEnable( GL_DEPTH_TEST );
		glDepthMask( GL_TRUE );
		glDisable( GL_TEXTURE_2D );

		glMatrixMode( GL_MODELVIEW );
		glPushMatrix();
		glLoadIdentity();

		glTranslatef( 0.f, 0.f, -2.f );

		glRotatef( clock.getElapsedTime().asSeconds() * 30.f, 0.f, 0.f, 1.f );

		glDisable( GL_TEXTURE_2D );

		glMatrixMode( GL_PROJECTION );
		glPushMatrix();
		glLoadIdentity();

		glViewport( 0, 0, static_cast<int>( opengl_canvas->GetAllocation().width ), static_cast<int>( opengl_canvas->GetAllocation().height ) );

		gluPerspective( 90.f, opengl_canvas->GetAllocation().width / opengl_canvas->GetAllocation().height, 1.f, 20.f );

		glBegin( GL_QUADS );
		glVertex2s( -1, 1 );
		glVertex2s( -1, -1 );
		glVertex2s( 1, -1 );
		glVertex2s( 1, 1 );
		glEnd();

		glPopMatrix();
		glMatrixMode( GL_MODELVIEW );
		glPopMatrix();

		glViewport( 0, 0, app_window.getSize().x, app_window.getSize().y );

		glEnable( GL_TEXTURE_2D );
		glDisable( GL_DEPTH_TEST );

		opengl_canvas->Display();
		opengl_canvas->Unbind();

		// Then the Canvas for SFML rendering.
		sfml_canvas->Bind();
		sfml_canvas->Clear( sf::Color( 0, 0, 0, 0 ) );

		// Draw the SFML Sprite.
		sfml_canvas->Draw( sprite );

		sfml_canvas->Display();
		sfml_canvas->Unbind();

		// This is important.
		app_window.setActive( true );

		// Draw the GUI
		sfgui.Display( app_window );

		// Update the window
		app_window.display();
	}

	return EXIT_SUCCESS;
}
Exemple #8
0
int main() {
	// Create the main SFML window
	sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Combo Box Example", sf::Style::Titlebar | sf::Style::Close );

	// Construct our SFML guard
	// See http://sfgui.sfml-dev.de/forum/topic52-crash-on-close.html for more info.
	sfg::SFGUI sfgui;

	// Create our main SFGUI window
	sfg::Window::Ptr window;
	window = sfg::Window::Create();
	window->SetTitle( "Title" );

	// Create the combo box itself.
	combo_box = sfg::ComboBox::Create();

	// Set the entries of the combo box.
	combo_box->AppendItem( "Bar" );
	combo_box->PrependItem( "Foo" );

	sel_label = sfg::Label::Create( L"Please select an item!" );

	sfg::Button::Ptr button( sfg::Button::Create( L"Add item" ) );

	sfg::Box::Ptr hbox( sfg::Box::Create( sfg::Box::HORIZONTAL, 5 ) );
	hbox->Pack( combo_box );
	hbox->Pack( button, false );

	sfg::Box::Ptr vbox( sfg::Box::Create( sfg::Box::VERTICAL, 5 ) );
	vbox->Pack( hbox, false );
	vbox->Pack( sel_label, true );

	// Add the combo box to the window
	window->Add( vbox );

	// So that our combo box 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.
	combo_box->OnSelect.Connect( &OnComboSelect );

	button->OnClick.Connect( &OnAddItemClick );

	// If attempting to connect to a class method you need to provide
	// a pointer to it as the second parameter after the function address.

	// Start the game loop
	while ( app_window.isOpen() ) {
		// Process events
		sf::Event event;

		while ( app_window.pollEvent( event ) ) {
			// Handle events
			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.
		window->Update( 0.f );

		// Clear screen
		app_window.clear();

		// Draw the GUI
		sfg::Renderer::Get().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.
	combo_box.reset();
	sel_label.reset();

	return EXIT_SUCCESS;
}
Exemple #9
0
void EntryExample::Run() {
    // Create the main SFML window
    sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Entry 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
    auto window = sfg::Window::Create();
    window->SetTitle( "Title" );

    // Create our box.
    auto box = sfg::Box::Create( sfg::Box::Orientation::HORIZONTAL );

    // Create a button.
    auto button = sfg::Button::Create();
    button->SetLabel( "Set" );

    // Connect the button.
    button->GetSignal( sfg::Widget::OnLeftClick ).Connect( std::bind( &EntryExample::ButtonClick, this ) );

    // Create a label.
    m_label = sfg::Label::Create();
    m_label->SetText( "no text yet" );

    // Create our entry widget itself.
    m_entry = sfg::Entry::Create();

    // Until now all widgets only expanded to fit the text inside of it.
    // This is not the case with the entry widget which can be empty
    // but still has to have a reasonable size.
    // To disable the automatic sizing of widgets in general you can
    // use the SetRequisition() method. it takes an sf::Vector as it's
    // parameter. Depending on which side you want to have a minimum size,
    // you set the corresponding value in the vector.
    // Here we chose to set the minimum x size of the widget to 80.
    m_entry->SetRequisition( sf::Vector2f( 80.f, 0.f ) );

    // Setting sizing back to automatic is as easy as setting
    // x and y sizes to 0.

    // Pack into box
    box->Pack( m_entry );
    box->Pack( button );
    box->Pack( m_label );

    // Set box spacing
    box->SetSpacing( 5.f );

    // Add our box to the window
    window->Add( box );

    sf::Clock clock;

    // Update an initial time to construct the GUI before drawing begins.
    // This makes sure that there are no frames in which no GUI is visible.
    window->Update( 0.f );

    // Start the game loop
    while ( app_window.isOpen() ) {
        // Process events
        sf::Event event;

        while ( app_window.pollEvent( event ) ) {
            // Handle events
            window->HandleEvent( event );

            // Close window : exit
            if ( event.type == sf::Event::Closed ) {
                app_window.close();
            }
        }

        // Update the GUI every 5ms
        if( clock.getElapsedTime().asMicroseconds() >= 5000 ) {
            // Update() takes the elapsed time in seconds.
            window->Update( static_cast<float>( clock.getElapsedTime().asMicroseconds() ) / 1000000.f );

            clock.restart();
        }

        // Clear screen
        app_window.clear();

        // Draw the GUI
        m_sfgui.Display( app_window );

        // Update the window
        app_window.display();
    }
}
Exemple #10
0
int main() {
	// Create the main SFML window
	sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Entry Example" );

	// Create our main SFGUI window
	sfg::Window::Ptr window;
	window = sfg::Window::Create();
	window->SetTitle( "Title" );

	// Create our box.
	sfg::Box::Ptr box = sfg::Box::Create( sfg::Box::Horizontal );

	// Create a button.
	sfg::Button::Ptr button = sfg::Button::Create();
	button->SetLabel( "Set" );

	// Connect the button.
	button->OnClick.Connect( &ButtonClick );

	// Create a label.
	label = sfg::Label::Create();
	label->SetText( "no text yet" );

	// Create our entry widget itself.
	entry = sfg::Entry::Create();

	// Until now all widgets only expanded to fit the text inside of it.
	// This is not the case with the entry widget which can be empty
	// but still has to have a reasonable size.
	// To disable the automatic sizing of widgets in general you can
	// use the SetRequisition() method. it takes an sf::Vector as it's
	// parameter. Depending on which side you want to have a minimum size,
	// you set the corresponding value in the vector.
	// Here we chose to set the minimum x size of the widget to 80.
	entry->SetRequisition( sf::Vector2f( 80.f, 0.f ) );

	// Setting sizing back to automatic is as easy as setting
	// x and y sizes to 0.

	// Pack into box
	box->Pack( entry );
	box->Pack( button );
	box->Pack( label );

	// Set box spacing
	box->SetSpacing( 5.f );

	// Add our box to the window
	window->Add( box );
	window->SetBorderWidth( 10.f );

	// Start the game loop
	while ( app_window.IsOpened() ) {
		// Process events
		sf::Event event;

		while ( app_window.PollEvent( event ) ) {
			// Handle events
			window->HandleEvent( event );

			// Close window : exit
			if(
				(event.Type == sf::Event::Closed) ||
				(event.Type == sf::Event::KeyPressed && event.Key.Code == sf::Keyboard::Escape)
			) {
				app_window.Close();
			}
		}

		// Clear screen
		app_window.Clear();

		// Draw the window
		window->Expose( app_window );

		// Update the window
		app_window.Display();
	}

	return EXIT_SUCCESS;
}
Exemple #11
0
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();
}
Exemple #12
0
int main() {
	// Create the main SFML window
	sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Range Example" );

	// Create our main SFGUI window
	sfg::Window::Ptr window;
	window = sfg::Window::Create();
	window->SetTitle( "Title" );

	// Create our box.
	sfg::Box::Ptr box = sfg::Box::Create( sfg::Box::Horizontal );

	// Create a label.
	label = sfg::Label::Create();
	label->SetText( "20" );

	// Scale and Scrollbar widgets are subclasses of the Range class.
	// They have a common data representation object known as an
	// Adjustment. The Adjustment that each range widget is bound to
	// determines it's current state (where the slider is, what max
	// and min values are, how much to scroll per step etc.). Because
	// range widgets share this common data object they can also be
	// linked together by a common Adjustment instance. An Adjustment
	// is created automatically for you when you create a range widget.

	// Create our scale smart pointer.
	sfg::Scale::Ptr scale;

	// Create the scale itself.
	// We want a horizontal scale.
	scale = sfg::Scale::Create( sfg::Scale::Horizontal );

	// Create our scrollbar smart pointer.
	sfg::Scrollbar::Ptr scrollbar;

	// Create the scrollbar itself.
	// We want a vertical scrollbar.
	scrollbar = sfg::Scrollbar::Create( sfg::Scrollbar::Vertical );

	// We can link both widgets together by their adjustments.
	adjustment = scrollbar->GetAdjustment();
	scale->SetAdjustment( adjustment );

	// Tune the adjustment parameters.
	adjustment->SetLower( 20.f );
	adjustment->SetUpper( 100.f );

	// How much it should change when clicked on the stepper.
	adjustment->SetMinorStep( 3.f );

	// How much it should change when clicked on the trough.
	adjustment->SetMajorStep( 12.f );

	// CAUTION:
	// Normally you would only set the page size for scrollbar adjustments.
	// For demonstration purposes we do this for our scale widget too.
	// If page size isn't 0 a scale widget won't be able to be set to it's
	// maximum value. This is in fact also true for scrollbars, however
	// because they are used to scroll the page size must be subtracted from
	// the maximum.
	adjustment->SetPageSize( 20.f );

	// Additionally you can connect to the OnChange signal of an adjustment
	// to get notified when any of it's parameters are changed.
	adjustment->OnChange.Connect( &AdjustmentChange );

	// Just as with the entry widget we set custom requisitions for our
	// range widgets to make sure they don't look strange.
	scale->SetRequisition( sf::Vector2f( 80.f, 20.f ) );
	scrollbar->SetRequisition( sf::Vector2f( 0.f, 80.f ) );

	// To keep our scale's slider from expanding too much we use another box
	// set to verticle orientation.
	sfg::Box::Ptr scalebox = sfg::Box::Create( sfg::Box::Vertical );
	scalebox->Pack( scale, false, false );

	// Pack into box
	box->Pack( scalebox );
	box->Pack( scrollbar );
	box->Pack( label );

	// Set box spacing
	box->SetSpacing( 5.f );

	// Add our box to the window
	window->Add( box );
	window->SetBorderWidth( 10.f );

	// Start the game loop
	while ( app_window.IsOpened() ) {
		// Process events
		sf::Event event;

		while ( app_window.PollEvent( event ) ) {
			// Handle events
			window->HandleEvent( event );

			// Close window : exit
			if(
				(event.Type == sf::Event::Closed) ||
				(event.Type == sf::Event::KeyPressed && event.Key.Code == sf::Keyboard::Escape)
			) {
				app_window.Close();
			}
		}

		// Clear screen
		app_window.Clear();

		// Draw the window
		window->Expose( app_window );

		// Update the window
		app_window.Display();
	}

	return EXIT_SUCCESS;
}
Exemple #13
0
int main() {
	// Create the main SFML window
	sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Window Example", sf::Style::Titlebar | sf::Style::Close );

	// We have to do this because we don't use SFML to draw.
	app_window.resetGLStates();

	// Create an SFGUI. This is required before doing anything with SFGUI.
	sfg::SFGUI sfgui;

	// Create our main SFGUI window

	// Almost everything in SFGUI is handled through smart pointers
	// for automatic resource management purposes. You create them
	// and they will automatically be destroyed when the time comes.
	sfg::Window::Ptr window;

	// Here we do the actual creation of the window. Creation of
	// widgets is always done with it's Create() method.
	window = sfg::Window::Create();

	// Here we can set the window's title bar text.
	window->SetTitle( "A really really really really long title" );

	// For more things to set around the window refer to the
	// API documentation.

	// Start the game loop
	while ( app_window.isOpen() ) {
		// Process events
		sf::Event event;

		while ( app_window.pollEvent( event ) ) {
			// Every frame we have to send SFML events to the window
			// to enable user interactivity. Without doing this your
			// GUI is nothing but a big colorful picture ;)
			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.
		window->Update( 0.f );

		// Clear screen
		app_window.clear();

		// After drawing the rest of your game, you have to let the GUI
		// render itself. If you don't do this you will never be able
		// to see it ;)
		sfgui.Display( app_window );

		// NOTICE
		// Because the window doesn't have any children it will shrink to
		// it's minimum size of (0,0) resulting in you not seeing anything
		// except the title bar text ;) Don't worry, in the Label example
		// you'll get to see more.

		// Update the window
		app_window.display();
	}

	return EXIT_SUCCESS;
}
Exemple #14
0
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 );

		// Clear screen
		app_window.clear();

		// Draw the GUI
		m_sfgui.Display( app_window );

		// Update the window
		app_window.display();
	}
}
Exemple #15
0
int main() {
	// Create the main SFML window
	sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Box Example", sf::Style::Titlebar | sf::Style::Close );

	// Construct our SFML guard
	// See http://sfgui.sfml-dev.de/forum/topic52-crash-on-close.html for more info.
	sfg::SFGUI sfgui;

	// Create our main SFGUI window
	sfg::Window::Ptr window;
	window = sfg::Window::Create();
	window->SetTitle( "Title" );

	// Since only being able to add one widget to a window is very limiting
	// there are Box widgets. They are a subclass of the Container class and
	// can contain an unlimited amount of child widgets. Not only that, they
	// also have the ability to lay out your widgets nicely.

	// Create our box smart pointer.
	sfg::Box::Ptr box;

	// Create the box itself.
	// For layout purposes we must specify in what direction new widgets
	// should be added, horizontally or vertically.
	box = sfg::Box::Create( sfg::Box::HORIZONTAL );

	sfg::Button::Ptr button1 = sfg::Button::Create();
	sfg::Button::Ptr button2 = sfg::Button::Create();
	sfg::Label::Ptr label = sfg::Label::Create();

	button1->SetLabel( "Foo" );
	button2->SetLabel( "Bar" );
	label->SetText( "Baz" );

	// To add our widgets to the box we use the Pack() method instead of the
	// Add() method. This makes sure the widgets are added and layed out
	// properly in the box.
	box->Pack( button1 );
	box->Pack( label );
	box->Pack( button2 );

	// Just as with the window we can set the spacing between widgets
	// withing a box.
	box->SetSpacing( 5.f );

	// Finally we add our box to the window as it's only child.
	// Notice that we don't have to add the children of a box to it's parent
	// Because all children and grandchildren and .... are automatically
	// considered descendents of the parent.
	window->Add( box );

	// Start the game loop
	while ( app_window.isOpen() ) {
		// Process events
		sf::Event event;

		while ( app_window.pollEvent( event ) ) {
			// Handle events
			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.
		window->Update( 0.f );

		// Clear screen
		app_window.clear();

		// Draw the GUI
		sfg::Renderer::Get().Display( app_window );

		// Update the window
		app_window.display();
	}

	return EXIT_SUCCESS;
}
Exemple #16
0
void SpinnerExample::Run() {
	// Create the main SFML window
	sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Spinner 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
	auto window = sfg::Window::Create();
	window->SetTitle( "Title" );

	// Create our spinner
	m_spinner = sfg::Spinner::Create();

	// Set how big the spinner should be
	m_spinner->SetRequisition( sf::Vector2f( 40.f, 40.f ) );

	// Create a button and connect the click signal.
	auto button = sfg::Button::Create( "Toggle" );
	button->GetSignal( sfg::Widget::OnLeftClick ).Connect( std::bind( &SpinnerExample::OnButtonClick, this ) );

	// Create a horizontal box layouter and add widgets to it.
	auto box = sfg::Box::Create( sfg::Box::Orientation::HORIZONTAL, 5.0f );
	box->Pack( m_spinner );
	box->Pack( button, false );

	// Add the box to the window.
	window->Add( box );

	// Our clock to make the spinner spin ;)
	sf::Clock clock;

	// Update an initial time to construct the GUI before drawing begins.
	// This makes sure that there are no frames in which no GUI is visible.
	window->Update( 0.f );

	// Start the game loop
	while ( app_window.isOpen() ) {
		// Process events
		sf::Event event;

		while ( app_window.pollEvent( event ) ) {
			// Handle events
			window->HandleEvent( event );

			// Close window : exit
			if ( event.type == sf::Event::Closed ) {
				app_window.close();
			}
		}

		// Update the GUI every 5ms
		if( clock.getElapsedTime().asMicroseconds() >= 5000 ) {
			// Update() takes the elapsed time in seconds.
			window->Update( static_cast<float>( clock.getElapsedTime().asMicroseconds() ) / 1000000.f );

			clock.restart();
		}

		// Clear screen
		app_window.clear();

		// Draw the GUI
		m_sfgui.Display( app_window );

		// Update the window
		app_window.display();
	}
}
void ProgressBarExample::Run() {
	// Create the main SFML window
	sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Progress Bar 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
	sfg::Window::Ptr window;
	window = sfg::Window::Create();
	window->SetTitle( "Title" );

	// Create our progress bar
	m_progressbar = sfg::ProgressBar::Create();

	// Set how big the progress bar should be
	m_progressbar->SetRequisition( sf::Vector2f( 200.f, 40.f ) );

	// Create a button and connect the click signal.
	sfg::Button::Ptr button( sfg::Button::Create( "Set Random Value" ) );
	button->GetSignal( sfg::Widget::OnLeftClick ).Connect( &ProgressBarExample::OnButtonClick, this );

	// Create a horizontal box layouter and add widgets to it.
	sfg::Box::Ptr box( sfg::Box::Create( sfg::Box::HORIZONTAL, 5.0f ) );
	box->Pack( m_progressbar );
	box->Pack( button, false );

	// Add the box to the window.
	window->Add( box );

	// Our clock
	sf::Clock clock;

	// Start the game loop
	while ( app_window.isOpen() ) {
		// Process events
		sf::Event event;

		while ( app_window.pollEvent( event ) ) {
			// Handle events
			window->HandleEvent( event );

			// Close window : exit
			if ( event.type == sf::Event::Closed ) {
				app_window.close();
			}
		}

		// Update the GUI every 5ms
		if( clock.getElapsedTime().asMicroseconds() >= 5000 ) {
			// Update() takes the elapsed time in seconds.
			window->Update( static_cast<float>( clock.getElapsedTime().asMicroseconds() ) / 1000000.f );

			clock.restart();
		}

		// Clear screen
		app_window.clear();

		// Draw the GUI
		m_sfgui.Display( app_window );

		// Update the window
		app_window.display();
	}
}
Exemple #18
0
void ComboBoxExample::Run() {
	// Create the main SFML window
	sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Combo Box 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
	auto window = sfg::Window::Create();
	window->SetTitle( "Title" );

	// Create the combo box itself.
	m_combo_box = sfg::ComboBox::Create();

	// Set the entries of the combo box.
	m_combo_box->AppendItem( "Bar" );
	m_combo_box->PrependItem( "Foo" );

	m_sel_label = sfg::Label::Create( L"Please select an item!" );

	auto add_button = sfg::Button::Create( L"Add item" );
	auto remove_button = sfg::Button::Create( L"Remove first item" );
	auto clear_button = sfg::Button::Create( L"Clear items" );

	auto hbox = sfg::Box::Create( sfg::Box::Orientation::HORIZONTAL, 5 );
	hbox->Pack( m_combo_box );
	hbox->Pack( add_button, false );
	hbox->Pack( remove_button, false );
	hbox->Pack( clear_button, false );

	auto vbox = sfg::Box::Create( sfg::Box::Orientation::VERTICAL, 5 );
	vbox->Pack( hbox, false );
	vbox->Pack( m_sel_label, true );

	// Add the combo box to the window
	window->Add( vbox );

	// So that our combo box 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_combo_box->GetSignal( sfg::ComboBox::OnSelect ).Connect( std::bind( &ComboBoxExample::OnComboSelect, this ) );

	add_button->GetSignal( sfg::Widget::OnLeftClick ).Connect( std::bind( &ComboBoxExample::OnAddItemClick, this ) );
	remove_button->GetSignal( sfg::Widget::OnLeftClick ).Connect( std::bind( &ComboBoxExample::OnRemoveItemClick, this ) );
	clear_button->GetSignal( sfg::Widget::OnLeftClick ).Connect( std::bind( &ComboBoxExample::OnClearClick, 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.

	// Start the game loop
	while ( app_window.isOpen() ) {
		// Process events
		sf::Event event;

		while ( app_window.pollEvent( event ) ) {
			// Handle events
			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.
		window->Update( 0.f );

		// Clear screen
		app_window.clear();

		// Draw the GUI
		m_sfgui.Display( app_window );

		// Update the window
		app_window.display();
	}
}