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

Function main

examples/Canvas.cpp:13–237  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11#include <cstdint>
12
13int main() {
14 // Create the main SFML window
15 sf::RenderWindow app_window( sf::VideoMode( { 800, 600 } ), "SFGUI Canvas Example", sf::Style::Titlebar | sf::Style::Close );
16
17 // We have to do this because we don't use SFML to draw.
18 app_window.resetGLStates();
19
20 // Create an SFGUI. This is required before doing anything with SFGUI.
21 sfg::SFGUI sfgui;
22
23 // Create our OpenGL canvas window
24 auto opengl_window = sfg::Window::Create();
25 opengl_window->SetTitle( "OpenGL canvas" );
26 opengl_window->SetPosition( sf::Vector2f( 50.f, 50.f ) );
27
28 // Create our SFML canvas window
29 auto sfml_window = sfg::Window::Create();
30 sfml_window->SetTitle( "SFML canvas" );
31 sfml_window->SetPosition( sf::Vector2f( 300.f, 50.f ) );
32
33 // Create our SFML scrollable canvas window
34 auto sfml_scrollable_window = sfg::Window::Create( sfg::Window::Style::TITLEBAR | sfg::Window::Style::BACKGROUND );
35 sfml_scrollable_window->SetTitle( "SFML scrollable canvas" );
36 sfml_scrollable_window->SetPosition( sf::Vector2f( 300.f, 200.f ) );
37
38 // Create the Canvases.
39 // Passing true in to Create() tells SFGUI
40 // to create a depth buffer for the canvas.
41 // This might be needed for your OpenGL rendering.
42 // Specifying nothing defaults to no depth buffer.
43 auto opengl_canvas = sfg::Canvas::Create( true );
44 auto sfml_canvas = sfg::Canvas::Create();
45 auto sfml_scrollable_canvas = sfg::Canvas::Create();
46
47 // Create a pair of scrollbars.
48 auto horizontal_scrollbar = sfg::Scrollbar::Create( sfg::Scrollbar::Orientation::HORIZONTAL );
49 auto vertical_scrollbar = sfg::Scrollbar::Create( sfg::Scrollbar::Orientation::VERTICAL );
50
51 // Create a table to put the scrollbars and scrollable canvas in.
52 auto table = sfg::Table::Create();
53 table->Attach( sfml_scrollable_canvas, sf::Rect<std::uint32_t>( { 0, 0 }, { 1, 1 } ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND );
54 table->Attach( vertical_scrollbar, sf::Rect<std::uint32_t>( { 1, 0 }, { 1, 1 } ), 0, sfg::Table::FILL );
55 table->Attach( horizontal_scrollbar, sf::Rect<std::uint32_t>( { 0, 1 }, { 1, 1 } ), sfg::Table::FILL, 0 );
56
57 // Add the Canvases to the windows.
58 opengl_window->Add( opengl_canvas );
59 sfml_window->Add( sfml_canvas );
60 sfml_scrollable_window->Add( table );
61
62 // Create an sf::Sprite for demonstration purposes.
63 const sf::Texture texture( "data/sfgui.png" );
64 const sf::Sprite sprite( texture );
65
66 // Create an sf::RectangleShape for demonstration purposes.
67 sf::RectangleShape rectangle_shape( sf::Vector2f( 218.f * 20, 84.f * 20 ) );
68 rectangle_shape.setTexture( &texture );
69
70 const static auto scrollable_canvas_size = 300.f;

Callers

nothing calls this directly

Calls 15

SetTitleMethod · 0.80
AttachMethod · 0.80
SetLowerMethod · 0.80
SetUpperMethod · 0.80
SetMinorStepMethod · 0.80
SetMajorStepMethod · 0.80
SetPageSizeMethod · 0.80
ConnectMethod · 0.80
SetRequisitionMethod · 0.80
BindMethod · 0.80
UnbindMethod · 0.80
DrawMethod · 0.80

Tested by

no test coverage detected