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

Function main

examples/Window.cpp:9–73  ·  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 Window 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
21 // Almost everything in SFGUI is handled through smart pointers
22 // for automatic resource management purposes. You create them
23 // and they will automatically be destroyed when the time comes.
24
25 // Creation of widgets is always done with it's Create() method
26 // which will return a smart pointer owning the new widget.
27 auto window = sfg::Window::Create();
28
29 // Here we can set the window's title bar text.
30 window->SetTitle( "A really really really really long title" );
31
32 // For more things to set around the window refer to the
33 // API documentation.
34
35 // Start the game loop
36 while ( app_window.isOpen() ) {
37 // Process events
38 while ( const std::optional event = app_window.pollEvent() ) {
39 // Every frame we have to send SFML events to the window
40 // to enable user interactivity. Without doing this your
41 // GUI is nothing but a big colorful picture ;)
42 window->HandleEvent( *event );
43
44 // Close window : exit
45 if ( event->is<sf::Event::Closed>() ) {
46 return EXIT_SUCCESS;
47 }
48 }
49
50 // Update the GUI, note that you shouldn't normally
51 // pass 0 seconds to the update method.
52 window->Update( 0.f );
53
54 // Clear screen
55 app_window.clear();
56
57 // After drawing the rest of your game, you have to let the GUI
58 // render itself. If you don't do this you will never be able
59 // to see it ;)
60 sfgui.Display( app_window );
61
62 // NOTICE
63 // Because the window doesn't have any children it will shrink to
64 // it's minimum size of (0,0) resulting in you not seeing anything
65 // except the title bar text ;) Don't worry, in the Label example
66 // you'll get to see more.

Callers

nothing calls this directly

Calls 5

SetTitleMethod · 0.80
HandleEventMethod · 0.45
UpdateMethod · 0.45
clearMethod · 0.45
DisplayMethod · 0.45

Tested by

no test coverage detected