void MainFrame::runGame() { // Create SFML's window. sf::RenderWindow render_window(sf::VideoMode(600, 400), "Test Windowing Game"); // Main loop! sf::Event event; sf::Clock clock; while (render_window.isOpen()) { // Event processing. while (render_window.pollEvent(event)) { // If window is about to be closed, leave program. if (event.type == sf::Event::Closed) render_window.close(); } //Update the room manager. m_roomManagerRef.update(); // Rendering. render_window.clear(); //Call room manager to update the game. m_roomManagerRef.draw(); //Display to window. render_window.display(); //No rooms are open in the game, end the game. if (m_roomManagerRef.rooms.empty()) render_window.close(); } }
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(); } }
void CustomWidget::Run() { // Create SFML's window. sf::RenderWindow render_window( sf::VideoMode( SCREEN_WIDTH, SCREEN_HEIGHT ), "Custom Widget" ); // Create our custom widget. m_custom_widget = MyCustomWidget::Create( "Custom Text" ); // Create a simple button and connect the click signal. auto button = sfg::Button::Create( "Button" ); button->GetSignal( sfg::Widget::OnLeftClick ).Connect( std::bind( &CustomWidget::OnButtonClick, this ) ); // Create a vertical box layouter with 5 pixels spacing and add our custom widget and button // and button to it. auto box = sfg::Box::Create( sfg::Box::Orientation::VERTICAL, 5.0f ); box->Pack( m_custom_widget ); box->Pack( button, false ); // Create a window and add the box layouter to it. Also set the window's title. auto window = sfg::Window::Create(); window->SetTitle( "Custom Widget" ); window->Add( box ); // Create a desktop and add the window to it. sfg::Desktop desktop; desktop.Add( window ); // We're not using SFML to render anything in this program, so reset OpenGL // states. Otherwise we wouldn't see anything. render_window.resetGLStates(); // Main loop! sf::Event event; sf::Clock clock; while( render_window.isOpen() ) { // Event processing. while( render_window.pollEvent( event ) ) { desktop.HandleEvent( event ); // If window is about to be closed, leave program. if( event.type == sf::Event::Closed ) { render_window.close(); } } // Update SFGUI with elapsed seconds since last call. desktop.Update( clock.restart().asSeconds() ); // Rendering. render_window.clear(); m_sfgui.Display( render_window ); render_window.display(); } }
int main(int ac, char **av) { t_mlx *e; t_obj *obj; if (ac != 2) { printf("Usage: %s [file.obj]\n", av[0]); return (0); } obj = parse_obj(av[1]); e = ft_memalloc(sizeof(t_mlx)); e->mlx = mlx_init(); e->win = mlx_new_opengl_window(e->mlx, WIDTH, HEIGHT, "Scop"); mlx_opengl_window_set_context(e->win); init(); render_window(e, obj); mlx_loop(e->mlx); return (0); }
void GuessMyNumber::Run() { sf::RenderWindow render_window( sf::VideoMode( 1024, 768, 32 ), TITLE, sf::Style::Titlebar | sf::Style::Close ); sf::Event event; // We have to do this because we don't use SFML to draw. render_window.resetGLStates(); // Create widgets. sfg::Window::Ptr window( sfg::Window::Create() ); window->SetTitle( TITLE ); sfg::Button::Ptr new_game_button( sfg::Button::Create( "New game" ) ); new_game_button->GetSignal( sfg::Widget::OnLeftClick ).Connect( &GuessMyNumber::OnNewGameClick, this ); m_guess_button->SetId( "guess" ); m_guess_button->GetSignal( sfg::Widget::OnLeftClick ).Connect( &GuessMyNumber::OnGuessClick, this ); // Layout. sfg::Table::Ptr table( sfg::Table::Create() ); table->Attach( sfg::Label::Create( "Your guess:" ), sf::Rect<sf::Uint32>( 0, 0, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL ); table->Attach( m_number_entry, sf::Rect<sf::Uint32>( 1, 0, 1, 1 ) ); table->Attach( sfg::Label::Create( "Tries:" ), sf::Rect<sf::Uint32>( 0, 1, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL ); table->Attach( m_tries_label, sf::Rect<sf::Uint32>( 1, 1, 1, 1 ) ); table->Attach( sfg::Label::Create( "Hint:" ), sf::Rect<sf::Uint32>( 0, 2, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL ); table->Attach( m_hint_label, sf::Rect<sf::Uint32>( 1, 2, 1, 1 ) ); table->SetColumnSpacings( 5.f ); table->SetRowSpacings( 5.f ); sfg::Box::Ptr buttons_box( sfg::Box::Create( sfg::Box::HORIZONTAL, 5.f ) ); buttons_box->Pack( new_game_button ); buttons_box->Pack( m_guess_button ); sfg::Box::Ptr content_vbox( sfg::Box::Create( sfg::Box::VERTICAL, 5.f ) ); content_vbox->Pack( sfg::Label::Create( "Guess my number, it's from 1 to 100!" ) ); content_vbox->Pack( table ); content_vbox->Pack( buttons_box ); window->Add( content_vbox ); ResetGame(); window->SetPosition( sf::Vector2f( static_cast<float>( render_window.getSize().x / 2 ) - window->GetAllocation().width / 2.f, static_cast<float>( render_window.getSize().y / 2 ) - window->GetAllocation().height / 2.f ) ); // Custom properties. sfg::Context::Get().GetEngine().SetProperty( "Button#guess", "BackgroundColor", sf::Color( 0, 100, 0 ) ); sfg::Context::Get().GetEngine().SetProperty( "Button#guess", "BorderColor", sf::Color( 0, 100, 0 ) ); sfg::Context::Get().GetEngine().SetProperty( "Button#guess:Prelight", "BackgroundColor", sf::Color( 0, 130, 0 ) ); sfg::Context::Get().GetEngine().SetProperty( "Button#guess:Prelight", "BorderColor", sf::Color( 0, 130, 0 ) ); sfg::Context::Get().GetEngine().SetProperty( "Button#guess > Label", "FontSize", 20.f ); // Make sure all properties are applied. window->Refresh(); while( render_window.isOpen() ) { while( render_window.pollEvent( event ) ) { if( (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) || event.type == sf::Event::Closed ) { render_window.close(); } window->HandleEvent( event ); } window->Update( 0.f ); render_window.clear(); m_sfgui.Display( render_window ); render_window.display(); } }