예제 #1
0
	void VehicleSim::mouse_move_callback(GLFWwindow* window, double x, double y)
	{
		// Get class instance
		VehicleSim* app = (VehicleSim*)glfwGetWindowUserPointer(window);
		Gwen::Controls::Canvas* canvas = app->_guiCanvas;
		common::Camera& cam = app->_camera;

		float height = (float)app->getHeight();

		// Calculate difference
		double oldX = app->_mouseX;
		double oldY = -app->_mouseY + height;
		double dx = x - app->_mouseX;
		double dy = y - app->_mouseY;
		app->_mouseX = x;
		app->_mouseY = y;

		// Update GUI
		canvas->InputMouseMoved((int)x, (int)y, (int)dx, (int)dy);

		// Update tools
		std::vector<Tool*>& tools = app->_tools;
		for (auto it = tools.begin(); it != tools.end(); ++it)
		{
			(*it)->mousemove_base(x, height - y, dx, dy);
		}
	}
void CustomControlWindowApp::setup()
{
	getWindow()->setTitle( "Gwen CustomControlWindow" );

	// TODO: find a better way..
#if defined( CINDER_COCOA )
	fs::path rootPath = getAppPath().parent_path().parent_path().parent_path().parent_path().parent_path().parent_path();
#else
	fs::path rootPath = getAppPath().parent_path().parent_path().parent_path().parent_path().parent_path();
#endif
	addAssetDirectory( rootPath / "assets" );

	mRenderer = new cigwen::GwenRendererGl();
	mRenderer->Init();

	Gwen::Skin::TexturedBase* skin = new Gwen::Skin::TexturedBase( mRenderer );
	skin->Init( "DefaultSkin.png" );
//	skin->Init( "obscureskin.png" );

	mCanvas = new Gwen::Controls::Canvas( skin );
	mCanvas->SetSize( 998, 650 - 24 );
	mCanvas->SetDrawBackground( true );
	mCanvas->SetBackgroundColor( cigwen::toGwen( Color::gray( 0.2 ) ) );

	mGwenInput = cigwen::GwenInput::create( mCanvas );

	addControls();
}
예제 #3
0
	void VehicleSim::char_callback(GLFWwindow* window,
			unsigned int codepoint)
	{
		// Get class instance
		VehicleSim* app = (VehicleSim*)glfwGetWindowUserPointer(window);
		Gwen::Controls::Canvas* canvas = app->_guiCanvas;

		// Update GUI
		canvas->InputCharacter(codepoint);
	}
예제 #4
0
	void VehicleSim::key_callback(GLFWwindow* window, int key,
		int scancode, int action, int mods)
	{
		// Do default action (exit on esc)
		_default_key_callback(window, key, scancode, action, mods);

		// Get class instance
		VehicleSim* app = (VehicleSim*)glfwGetWindowUserPointer(window);
		Gwen::Controls::Canvas* canvas = app->_guiCanvas;

		// Update GUI
		canvas->InputKey(InputConverter::translateKeyCode(key), action == GLFW_PRESS);

		// Update tools
		std::vector<Tool*>& tools = app->_tools;
		for (auto it = tools.begin(); it != tools.end(); ++it)
		{
			(*it)->key_base(key, scancode, action, mods);
		}
	}
예제 #5
0
	void VehicleSim::scroll_callback(GLFWwindow* window, double x, double y)
	{
		// Get class instance
		VehicleSim* app = (VehicleSim*)glfwGetWindowUserPointer(window);
		Gwen::Controls::Canvas* canvas = app->_guiCanvas;

		// Update GUI
		canvas->InputMouseWheel((int)(y * 60.0));

		// Update app
		//app->_orthoScale -= y;
		//if (app->_orthoScale <= VEHICLESIM_MIN_SCALE)
		//	app->_orthoScale = VEHICLESIM_MIN_SCALE;

		// Update tools
		std::vector<Tool*>& tools = app->_tools;
		for (auto it = tools.begin(); it != tools.end(); ++it)
		{
			(*it)->scroll_base(x, y);
		}
	}
예제 #6
0
	void VehicleSim::mouse_callback(GLFWwindow* window, int button,
		int action, int mods)
	{
		// Get class instance
		VehicleSim* app = (VehicleSim*)glfwGetWindowUserPointer(window);
		Gwen::Controls::Canvas* canvas = app->_guiCanvas;
		b2World& physWorld = app->_physWorld;
		common::Camera& cam = app->_camera;

		// Update GUI
		canvas->InputMouseButton(button, (action == GLFW_PRESS));

		// Get viewport
		common::Viewport viewport = cam.getViewport();

		// Update tools
		std::vector<Tool*>& tools = app->_tools;
		for (auto it = tools.begin(); it != tools.end(); ++it)
		{
			(*it)->click_base(button, action, mods);
		}
	}
예제 #7
0
파일: SFML.cpp 프로젝트: 32bitmicro/GWEN
////////////////////////////////////////////////////////////
/// 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;
}
void CustomControlWindowApp::draw()
{
	gl::clear();
	mCanvas->RenderCanvas();
}
예제 #9
0
int main()
{

	//
	// Create a new window
	//
	g_pHWND = CreateGameWindow();

	//
	// Create a GWEN GDI+ Renderer
	// Note: we're using the buffered version.
	// This version draws to a texture and then draws that texture to the window
	// This prevents all the crazy flickering (test with Gwen::Renderer::GDIPlus to see)
	//
	Gwen::Renderer::GDIPlusBuffered* pRenderer = new Gwen::Renderer::GDIPlusBuffered( g_pHWND );

	//
	// Create a GWEN skin
	//
	//Gwen::Skin::Simple skin;
	Gwen::Skin::TexturedBase* skin = new Gwen::Skin::TexturedBase( pRenderer );
	skin->Init( "DefaultSkin.png" );

	//
	// 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( 998, 650 - 24 );
	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 a Windows Control helper 
	// (Processes Windows MSG's and fires input at GWEN)
	//
	Gwen::Input::Windows GwenInput;
	GwenInput.Initialize( pCanvas );

	//
	// Begin the main game loop
	//
	MSG msg;
	while( true )
	{
		// Skip out if the window is closed
		if ( !IsWindowVisible( g_pHWND ) )
			break;

		// If we have a message from windows..
		if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
		{
			// .. give it to the input handler to process
			GwenInput.ProcessMessage( msg );

			// if it's QUIT then quit..
			if ( msg.message == WM_QUIT )
				break;

			if ( msg.message == WM_PAINT )
			{
				// This doesn't actually draw it, it just marks it
				// so it will redraw when next checked (NeedsRedraw)
				pCanvas->Redraw();
			}

			// Handle the regular window stuff..
			TranslateMessage(&msg);
			DispatchMessage(&msg);

		}

		// If GWEN's Canvas needs a redraw then redraw it
		//
		// In your game you would probably just draw it 
		//  every frame. But we have the option of only
		//  drawing it when it needs it too.
		//
		if ( pCanvas->NeedsRedraw() )
		{
			pCanvas->RenderCanvas();
		}
	}

	delete pCanvas;
	delete skin;
	delete pRenderer;
}
예제 #10
0
//
// Program starts here
//
int main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	//
	// Create a window and attach directx to it
	//
	g_pD3D = Direct3DCreate9( D3D_SDK_VERSION );
	g_pHWND = CreateGameWindow();
	CreateD3DDevice();	

	//
	// Create a GWEN DirectX renderer
	//
	Gwen::Renderer::DirectX9* pRenderer = new Gwen::Renderer::DirectX9( g_pD3DDevice );

	//
	// Create a GWEN skin
	//
	Gwen::Skin::TexturedBase skin;
	skin.SetRender( pRenderer );
	skin.Init( "DefaultSkin.png" );

	//
	// 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( 1000, 622 );
	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 a Windows Control helper 
	// (Processes Windows MSG's and fires input at GWEN)
	//
	Gwen::Input::Windows GwenInput;
	GwenInput.Initialize( pCanvas );

	//
	// Begin the main game loop
	//
	MSG msg;
	while( true )
	{
		// Skip out if the window is closed
		if ( !IsWindowVisible( g_pHWND ) )
			break;

		// If we have a message from windows..
		if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
		{
			// .. give it to the input handler to process
			GwenInput.ProcessMessage( msg );

			// if it's QUIT then quit..
			if ( msg.message == WM_QUIT )
				break;

			// Handle the regular window stuff..
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			// Normal DirectX rendering loop
			g_pD3DDevice->BeginScene();

				g_pD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 0, 0, 0 ), 1, 0 );

				// This is how easy it is to render GWEN!
				pCanvas->RenderCanvas();

			g_pD3DDevice->EndScene();
			g_pD3DDevice->Present( NULL, NULL, NULL, NULL );

		}
	}

	if ( g_pD3DDevice )
	{
		g_pD3DDevice->Release();
		g_pD3DDevice = NULL;
	}

	if ( g_pD3D )
	{
		g_pD3D->Release();
		g_pD3D = NULL;
	}
}
예제 #11
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;
}
예제 #12
0
int main( int argc, const char **argv )
{
	//
	// Create a new window
	//
	g_pHWND = CreateGameWindow();

	//
	// Create OpenGL Device
	//
	HGLRC OpenGLContext = CreateOpenGLDeviceContext();


	//
	// Create a GWEN OpenGL Renderer
	//
	#ifdef USE_DEBUG_FONT
		Gwen::Renderer::OpenGL * pRenderer = new Gwen::Renderer::OpenGL_DebugFont();
	#else
		Gwen::Renderer::OpenGL * pRenderer = new Gwen::Renderer::OpenGL_TruetypeFont();
	#endif

		pRenderer->Init();

	//
	// Create a GWEN skin
	//
	Gwen::Skin::TexturedBase* pSkin = new Gwen::Skin::TexturedBase( pRenderer );
	pSkin->Init("DefaultSkin.png");

	if( argc >= 2 )
		pSkin->SetDefaultFont( Gwen::Utility::StringToUnicode(argv[1]) /* 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( pSkin );
	pCanvas->SetSize( width, height );
	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 a Windows Control helper
	// (Processes Windows MSG's and fires input at GWEN)
	//
	Gwen::Input::Windows* pInput = new Gwen::Input::Windows();
	pInput->Initialize( pCanvas );

	//
	// Begin the main game loop
	//
	MSG msg;
	while( true )
	{
		// Skip out if the window is closed
		if ( !IsWindowVisible( g_pHWND ) )
			break;

		// If we have a message from windows..
		if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
		{
			// .. give it to the input handler to process
			pInput->ProcessMessage( msg );

			// if it's QUIT then quit..
			if ( msg.message == WM_QUIT )
				break;


			// Handle the regular window stuff..
			TranslateMessage(&msg);
			DispatchMessage(&msg);

		}

		// Main OpenGL Render Loop
		{
			glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

			pCanvas->RenderCanvas();

			SwapBuffers( GetDC( g_pHWND ) );
		}
	}

	// Clean up Gwen
	delete pInput;
	delete pUnit;
	delete pCanvas;
	delete pSkin;
	delete pRenderer;

	// Clean up OpenGL
	wglMakeCurrent( NULL, NULL );
	wglDeleteContext( OpenGLContext );

	// Exit
	return 0;
}
예제 #13
0
//
// Program starts here
//
int main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	//
	// Create a window and attach directx to it
	//

	g_pHWND = CreateGameWindow();
	CreateD3DDevice();
	RECT FrameBounds;
	GetClientRect(g_pHWND, &FrameBounds);
	//
	// Create a GWEN DirectX renderer
	//
	Gwen::Renderer::DirectX10* pRenderer = new Gwen::Renderer::DirectX10(g_pd3dDevice);
	//
	// Create a GWEN skin
	//
	Gwen::Skin::TexturedBase* pSkin = new Gwen::Skin::TexturedBase(pRenderer);
	pSkin->Init("DefaultSkin.png");
	//
	// Create a Canvas (it's root, on which all other GWEN panels are created)
	//
	Gwen::Controls::Canvas* pCanvas = new Gwen::Controls::Canvas(pSkin);
	pCanvas->SetSize(FrameBounds.right, FrameBounds.bottom);
	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 a Windows Control helper
	// (Processes Windows MSG's and fires input at GWEN)
	//
	Gwen::Input::Windows GwenInput;
	GwenInput.Initialize(pCanvas);
	//
	// Begin the main game loop
	//
	MSG msg;

	while (true)
	{
		// Skip out if the window is closed
		if (!IsWindowVisible(g_pHWND))
		{
			break;
		}

		// If we have a message from windows..
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			// .. give it to the input handler to process
			GwenInput.ProcessMessage(msg);

			// if it's QUIT then quit..
			if (msg.message == WM_QUIT)
			{
				break;
			}

			// Handle the regular window stuff..
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			float ClearColor[4] = { 0.128f, 0.128f, 0.3f, 1.0f };
			// Normal DirectX rendering loop
			g_pd3dDevice->ClearRenderTargetView(g_pRenderTargetView, ClearColor);

			// This is how easy it is to render GWEN!
			pCanvas->RenderCanvas();

			g_pSwapChain->Present(0, 0);
		}
	}

	delete pCanvas;
	delete pSkin;
	delete pRenderer;

	if (g_pRenderTargetView)
	{
		g_pRenderTargetView->Release();
		g_pRenderTargetView = NULL;
	}

	if (g_pSwapChain)
	{
		g_pSwapChain->Release();
		g_pSwapChain = NULL;
	}

	if (g_pd3dDevice)
	{
		g_pd3dDevice->Release();
		g_pd3dDevice = NULL;
	}
}