MCPcopy Create free account
hub / github.com/TankOs/SFGUI / main

Function main

examples/Multiview.cpp:9–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7#include <SFML/Graphics.hpp>
8
9int main() {
10 // Create the main SFML window
11 sf::RenderWindow app_window( sf::VideoMode( { 800, 600 } ), "SFGUI Multiview Example", sf::Style::Titlebar | sf::Style::Close );
12
13 // We have to do this because we don't use SFML to draw.
14 app_window.resetGLStates();
15
16 // Create an SFGUI. This is required before doing anything with SFGUI.
17 sfg::SFGUI sfgui;
18
19 // Create our main SFGUI window
20 auto window = sfg::Window::Create();
21 window->SetTitle( "Try dragging me to my cousins." );
22 window->SetPosition( sf::Vector2f( 100.f, 100.f ) );
23
24 // Create the button itself.
25 auto button = sfg::Button::Create();
26
27 // Set the label of the button.
28 button->SetLabel( "Foo" );
29
30 // Make the button nice and big
31 button->SetRequisition( sf::Vector2f( 200.f, 20.f ) );
32
33 // Add the button to the window
34 window->Add( button );
35
36 // So that our button has a meaningful purpose
37 // (besides just looking awesome :P) we need to tell it to connect
38 // to a callback of our choosing to notify us when it is clicked.
39 button->GetSignal( sfg::Widget::OnLeftClick ).Connect( [&button] {
40 // When the button is clicked it's label should change.
41 button->SetLabel( "Bar" );
42 } );
43
44 // If attempting to connect to a class method you need to provide
45 // a pointer to it as the second parameter after the function address.
46
47 // Our sf::RenderTexture to draw the GUI on.
48 sf::RenderTexture render_texture( sf::Vector2u( 800, 600 ) );
49 render_texture.resetGLStates();
50
51 // Our 4 viewport Sprites.
52 sf::Sprite sprite0( render_texture.getTexture() );
53 sf::Sprite sprite1( render_texture.getTexture() );
54 sf::Sprite sprite2( render_texture.getTexture() );
55 sf::Sprite sprite3( render_texture.getTexture() );
56
57 sprite0.setPosition( { 0.f, 0.f } );
58 sprite1.setPosition( { 400.f, 0.f } );
59 sprite2.setPosition( { 0.f, 300.f } );
60 sprite3.setPosition( { 400.f, 300.f } );
61
62 // Rectangle to clear the RenderTexture.
63 sf::RectangleShape clear_rect( sf::Vector2f( 400.f, 300.f ) );
64 clear_rect.setFillColor( sf::Color::Black );
65
66 // Start the game loop

Callers

nothing calls this directly

Calls 10

SetTitleMethod · 0.80
SetRequisitionMethod · 0.80
ConnectMethod · 0.80
SetPositionMethod · 0.45
SetLabelMethod · 0.45
AddMethod · 0.45
HandleEventMethod · 0.45
UpdateMethod · 0.45
clearMethod · 0.45
DisplayMethod · 0.45

Tested by

no test coverage detected