Advertisement
Guest User

GWEN/SFML Sample

a guest
Nov 26th, 2012
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <cmath>
  3.  
  4. #include "Gwen/Renderers/SFML.h"
  5. #include "Gwen/Input/SFML.h"
  6.  
  7. #include "Gwen/Skins/Simple.h"
  8. #include "Gwen/Skins/TexturedBase.h"
  9. #include "Gwen/UnitTest/UnitTest.h"
  10.  
  11. ////////////////////////////////////////////////////////////
  12. /// Entry point of application
  13. ///
  14. /// \return Application exit code
  15. ///
  16. ////////////////////////////////////////////////////////////
  17. int main()
  18. {
  19.     // Create the window of the application
  20.     sf::RenderWindow App( sf::VideoMode( 1004, 650, 32 ), "GWEN: SFML", sf::Style::Close );
  21.  
  22.     Gwen::Renderer::SFML GwenRenderer( App );
  23.  
  24.     //
  25.     // Create a GWEN skin
  26.     //
  27.     //Gwen::Skin::Simple skin;
  28.     //skin.SetRender( &GwenRenderer );
  29.  
  30.     Gwen::Skin::TexturedBase skin;
  31.     skin.SetRender( &GwenRenderer );
  32.     skin.Init( "DefaultSkin.png" );
  33.  
  34.     // The fonts work differently in SFML - it can't use
  35.     // system fonts. So force the skin to use a local one.
  36.     skin.SetDefaultFont( L"OpenSans.ttf", 11 );
  37.  
  38.  
  39.     //
  40.     // Create a Canvas (it's root, on which all other GWEN panels are created)
  41.     //
  42.     Gwen::Controls::Canvas* pCanvas = new Gwen::Controls::Canvas( &skin );
  43.     pCanvas->SetSize( App.getSize().x, App.getSize().y );
  44.     pCanvas->SetDrawBackground( true );
  45.     pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) );
  46.  
  47.  
  48.     //
  49.     // Create our unittest control (which is a Window with controls in it)
  50.     //
  51.     UnitTest* pUnit = new UnitTest( pCanvas );
  52.     //pUnit->SetPos( 10, 10 );
  53.  
  54.     //
  55.     // Create an input processor
  56.     //
  57.     Gwen::Input::SFML GwenInput;
  58.     GwenInput.Initialize( pCanvas );
  59.    
  60.     while ( App.isOpen() )
  61.     {
  62.         // Handle events
  63.         sf::Event Event;
  64.  
  65.         while ( App.pollEvent(Event) )
  66.         {
  67.             // Window closed or escape key pressed : exit
  68.             if ((Event.type == sf::Event::Closed) ||
  69.                 ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape)))
  70.             {
  71.                 App.close();
  72.                 break;
  73.             }
  74.  
  75.             GwenInput.ProcessMessage( Event );
  76.         }
  77.  
  78.         // Clear the window
  79.         App.clear();
  80.        
  81.         pCanvas->RenderCanvas();
  82.        
  83.         App.display();
  84.     }
  85.  
  86.     return EXIT_SUCCESS;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement