Пример #1
0
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
	// Create the window of the application
	sf::RenderWindow App( sf::VideoMode( 1004, 650, 32 ), "GWEN: SFML", sf::Style::Close );

	Gwen::Renderer::SFML GwenRenderer( App );

	//
	// Create a GWEN skin
	//
	//Gwen::Skin::Simple skin;
	//skin.SetRender( &GwenRenderer );

	Gwen::Skin::TexturedBase skin( &GwenRenderer );
	skin.Init( "DefaultSkin.png" );

	// The fonts work differently in SFML - it can't use
	// system fonts. So force the skin to use a local one.
	skin.SetDefaultFont( L"OpenSans.ttf", 11 );


	//
	// Create a Canvas (it's root, on which all other GWEN panels are created)
	//
	Gwen::Controls::Canvas* pCanvas = new Gwen::Controls::Canvas( &skin );
	pCanvas->SetSize( App.GetWidth(), App.GetHeight() );
	pCanvas->SetDrawBackground( true );
	pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) );


	//
	// Create our unittest control (which is a Window with controls in it)
	//
	UnitTest* pUnit = new UnitTest( pCanvas );
	//pUnit->SetPos( 10, 10 );

	//
	// Create an input processor
	//
	Gwen::Input::SFML GwenInput;
	GwenInput.Initialize( pCanvas );
	
#if SFML_VERSION_MAJOR == 2
	while ( App.IsOpen() )
#else
	while ( App.IsOpened() )
#endif
	{
		// Handle events
		sf::Event Event;

#if SFML_VERSION_MAJOR == 2
		while ( App.PollEvent(Event) )
#else
		while ( App.GetEvent(Event) )
#endif
		{
			// Window closed or escape key pressed : exit
#if SFML_VERSION_MAJOR == 2
			if ((Event.Type == sf::Event::Closed) || 
				((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Escape)))
#else
			if ((Event.Type == sf::Event::Closed) || 
				((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape)))
#endif
			{
				App.Close();
				break;
			}

			GwenInput.ProcessMessage( Event );
		}

		// Clear the window
		App.Clear();
		
		pCanvas->RenderCanvas();
		
		App.Display();
	}

	return EXIT_SUCCESS;
}
Пример #2
0
int main(int argc, char* argv[])
{
	if(!ParseArguments(argc, argv))
	{
		printf("libdetector Test Application Usage:\n");
		printf("\t--save=STRING\t\tDirectory to save motion videos (if absent, will not save!)\n");
		return 0;
	}

	printf("Loading Skin...\n");

	// Init the Gwen GUI and SFML window
	sf::RenderWindow App( sf::VideoMode( 1366, 690, 32 ), "Detector", sf::Style::Close );
	Gwen::Renderer::SFML GwenRenderer( App );
	Gwen::Skin::TexturedBase skin;
	skin.SetRender( &GwenRenderer );
	skin.Init( "DefaultSkin.png" );
	skin.SetDefaultFont( L"OpenSans.ttf", 11 );

	Gwen::Controls::Canvas* pCanvas = new Gwen::Controls::Canvas( &skin );
	pCanvas->SetSize( App.GetWidth(), App.GetHeight() );
	pCanvas->SetDrawBackground( true );
	pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) );

	Gwen::Input::SFML GwenInput;
	GwenInput.Initialize( pCanvas );

	printf("Canvas created!\n");

	InstanceManager* mgr = new InstanceManager(pCanvas);
	thread t(InstanceThread, mgr);
	//sf::Sleep(1.0);

	while ( App.IsOpened() )
	{
		// Handle events
		sf::Event Event;
		while ( App.GetEvent(Event) )
		{
			if ((Event.Type == sf::Event::Closed) || ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape)))
			{
				App.Close();
				break;
			}
			GwenInput.ProcessMessage( Event );
		}

		App.Clear();

		while(mgr->UsingContext()) // Wait until we don't have the context anymore before retaking it back
		{
			sf::Sleep(0.1);
			printf("Using context!\n");
		}

		pCanvas->RenderCanvas();

		App.Display();
	}

	return 0;
}