All pastes #765508 Raw Edit

Something

public cpp v1 · immutable
·published 2007-11-08 02:32 UTC
rendered paste body
#include <windows.h>#include <d3d9.h>#include <d3dx9.h>#include <vector>#include "d3dfont.h"#include "AppTools.h"using namespace std;struct gui_color{	int r, g, b, a;};struct color_scheme_s{	gui_color bg, boarder, textLight, textDark, pressed, not_pressed;};struct sq_vector{	int left_x, right_x;	int top_y, bottom_y;};struct window_info_s{	char szTitle[ 256 ];		sq_vector entire_window;	color_scheme_s colors;	int x, y, width, height;	bool m_bDrawWindow;		bool m_bIsMinimized;};struct mouse_data{	int x, y;	bool m_bIsLeftClicked, m_bIsRightClicked, m_bIsMiddleClicked;};#define VAR_STR( x ) #x#define SET_VALUE( n, t ) void n( t val ){ t* pval = ( t* )m_Value; pval[ 0 ] = val; }#define GET_VALUE( n, t ) t n( ){ return *( t* )m_Value; }class cGuiVar{public:	cGuiVar( )	{		m_Value = malloc( 8 );	}	//get data types	GET_VALUE( GetBool, bool );	GET_VALUE( GetInteger, int );	GET_VALUE( GetFloat, float );	GET_VALUE( GetShort, short );	//set data	SET_VALUE( SetBool, bool );	SET_VALUE( SetInteger, int );	SET_VALUE( SetFloat, float );	SET_VALUE( SetShort, short );	//other misc	char* GetBoolString( ){ return *( bool* )m_Value ? "true" : "false"; }	~cGuiVar( )	{		free( m_Value );	}	void* m_Value;};class cGui{public:	cGui( LPDIRECT3DDEVICE9 pDevice )	{		m_bIsActive = false;		D3DXCreateLine( pDevice, &pLine );				m_pFont = new CD3DFont( "Visitor TT2 BRK", "gui\\visitor2.ttf", 10, 0, true );		m_pFont->InitDeviceObjects( pDevice );		m_pFont->RestoreDeviceObjects( );	}	void DrawText( int x, int y, DWORD color, char *szFormat, ... )	{		if( !szFormat )return;		if( !m_pFont )return;		va_list va_alist;		char logbuf[256] = { 0 };		va_start (va_alist, szFormat);		_vsnprintf(logbuf+strlen(logbuf), sizeof(logbuf) - strlen(logbuf), szFormat, va_alist);		va_end (va_alist);		RECT font_rect;		SetRect( &font_rect, x, y, 0, 0 );		m_pFont->DrawText( ( FLOAT )x, ( FLOAT )y, color, logbuf, 0 );	}	void FillArea( int x, int y, int w, int h, gui_color colors )	{		if( !pLine )return;		D3DXVECTOR2 vLine[2];		pLine->SetWidth( ( FLOAT )w );		pLine->SetAntialias( false );		pLine->SetGLLines( true );		vLine[0].x = ( FLOAT )( x + w / 2 );		vLine[0].y = ( FLOAT )( y );		vLine[1].x = ( FLOAT )( x + w / 2 );		vLine[1].y = ( FLOAT )( y + h );		pLine->Begin( );		pLine->Draw( vLine, 2, D3DCOLOR_RGBA( colors.r, colors.g, colors.b, colors.a ) );		pLine->End( );	}	int AddWindow( char *m_szTitle, color_scheme_s *colors, int x_pos, int y_pos, int initial_width, int initial_height )	{		window_info_s pwin;		//set the input data		strcpy( pwin.szTitle, m_szTitle );		pwin.colors = colors[ 0 ];		pwin.x = x_pos;		pwin.y = y_pos;		pwin.width = initial_width;		pwin.height = initial_height;				//predict the window size in its entirety		pwin.entire_window.left_x = x_pos;		pwin.entire_window.right_x = ( x_pos + initial_width );		pwin.entire_window.top_y = y_pos;		pwin.entire_window.bottom_y = ( y_pos + initial_height );		//set default window params		pwin.m_bIsMinimized = false;		pwin.m_bDrawWindow = true;		//add the struct to the vector		vGuiWindows.push_back( pwin );		//return the window index		return ( int )vGuiWindows.size( );	}	void AddWindowCaption( int m_iWindowHandle, int x, int y, char *szCaption, gui_color *pcolor )	{		DrawText( vGuiWindows[ m_iWindowHandle ].x + x, vGuiWindows[ m_iWindowHandle ].y + y, D3DCOLOR_ARGB( pcolor[ 0 ].a, pcolor[ 0 ].r, pcolor[ 0 ].g, pcolor[ 0 ].b ), szCaption );	}	void RenderWindows( LPDIRECT3DDEVICE9 pDevice )	{		if( !m_bIsActive )return;		for( int i = 0; i < ( int )vGuiWindows.size( ); i++ )		{			if( vGuiWindows[ i ].m_bIsMinimized )			{				//draw minimized ->				//boarder				FillArea(					vGuiWindows[ i ].x, 					vGuiWindows[ i ].y,					vGuiWindows[ i ].width, 					14,					vGuiWindows[ i ].colors.boarder 					);				//small bg				FillArea( 					vGuiWindows[ i ].x + 2,						vGuiWindows[ i ].y + 2,							vGuiWindows[ i ].width - 4, 					10, 					vGuiWindows[ i ].colors.bg 					);				//title				DrawText( 					vGuiWindows[ i ].x + 2,						vGuiWindows[ i ].y + 2,							D3DCOLOR_ARGB( 						vGuiWindows[ i ].colors.textLight.a, 						vGuiWindows[ i ].colors.textLight.r, 						vGuiWindows[ i ].colors.textLight.g, 						vGuiWindows[ i ].colors.textLight.b 					), 					" %s ( %i )", 					vGuiWindows[ i ].szTitle, i );				continue;			}			//draw full windows ->			//boarder			FillArea(				vGuiWindows[ i ].x, 				vGuiWindows[ i ].y,				vGuiWindows[ i ].width, 				vGuiWindows[ i ].height,				vGuiWindows[ i ].colors.boarder 				);						//background			FillArea( 				vGuiWindows[ i ].x + 2,					vGuiWindows[ i ].y + 2,						vGuiWindows[ i ].width - 4, 				10, 				vGuiWindows[ i ].colors.bg 				);			FillArea( 				vGuiWindows[ i ].x + 2,					vGuiWindows[ i ].y + 14,				vGuiWindows[ i ].width - 4, 				vGuiWindows[ i ].height - 16, 				vGuiWindows[ i ].colors.bg 				);						//title			DrawText( 				vGuiWindows[ i ].x + 2,					vGuiWindows[ i ].y + 2,						D3DCOLOR_ARGB( 					vGuiWindows[ i ].colors.textLight.a, 					vGuiWindows[ i ].colors.textLight.r, 					vGuiWindows[ i ].colors.textLight.g, 					vGuiWindows[ i ].colors.textLight.b 				), 				" %s ( %i )", 				vGuiWindows[ i ].szTitle, i );		}	}	void SetActiveMode( bool m_bMode )	{		m_bIsActive = m_bMode;	}	void HandleKey( WPARAM wParams )	{		switch( wParams )		{		case VK_INSERT:			{				SetActiveMode( !m_bIsActive );				break;			}		}	}	void RenderMouseData( void )	{		DrawText( 10, 10, D3DCOLOR_ARGB( 255, 255, 0, 0 ), "Mouse ( X = %i // Y = %i )", m_mouse.x, m_mouse.y );	}	//render the mouse on the screen	void RenderMouse( void )	{//		if( !m_bActive )return;		gui_color color;		color.r = 255;		color.g = 0;		color.b = 0;		color.a = 255;		FillArea( m_mouse.x, m_mouse.y, 5, 5, color );	}	//handle mouse/window movement relations movement	void HandleWindowMovement( void )	{		if( !m_bIsActive )return;		if( GetAsyncKeyState( VK_LBUTTON )&1 )		{			for( int i = 0; i < ( int )vGuiWindows.size( ); i++ )			{				if( m_mouse.x >= vGuiWindows[ i ].entire_window.left_x		&&					m_mouse.x <= vGuiWindows[ i ].entire_window.right_x		&&					m_mouse.y >= vGuiWindows[ i ].entire_window.top_y		&&					m_mouse.y <= vGuiWindows[ i ].entire_window.top_y + 15					)				{					vGuiWindows[ i ].m_bIsMinimized = !vGuiWindows[ i ].m_bIsMinimized;				}			}		}		if( m_mouse.m_bIsRightClicked )		{			for( int i = 0; i < ( int )vGuiWindows.size( ); i++ )			{				if( m_bIsDraggingWindow && m_iDraggingWindow != i )					continue;				if( !vGuiWindows[ i ].m_bIsMinimized )				{					if( m_mouse.x >= vGuiWindows[ i ].entire_window.left_x		&&						m_mouse.x <= vGuiWindows[ i ].entire_window.right_x		&&												m_mouse.y <= vGuiWindows[ i ].entire_window.bottom_y	&&						m_mouse.y >= vGuiWindows[ i ].entire_window.top_y )					{						//move the window because it fits the criteria						m_bIsDraggingWindow = true;						m_iDraggingWindow = i;						vGuiWindows[ i ].x = ( m_mouse.x - 20 );						vGuiWindows[ i ].y = ( m_mouse.y - 20 );					}				}				else				{					//minimized					if( m_mouse.x >= vGuiWindows[ i ].entire_window.left_x		&&						m_mouse.x <= vGuiWindows[ i ].entire_window.right_x		&&						m_mouse.y >= vGuiWindows[ i ].entire_window.top_y		&&						m_mouse.y <= vGuiWindows[ i ].entire_window.top_y + 15						)					{						//move the window because it fits the criteria						m_bIsDraggingWindow = true;						m_iDraggingWindow = i;						vGuiWindows[ i ].x = ( m_mouse.x - 10 );						vGuiWindows[ i ].y = ( m_mouse.y - 10 );					}				}				//update the window params				vGuiWindows[ i ].entire_window.left_x =	vGuiWindows[ i ].x;				vGuiWindows[ i ].entire_window.right_x = ( vGuiWindows[ i ].x + vGuiWindows[ i ].width );				vGuiWindows[ i ].entire_window.top_y = vGuiWindows[ i ].y;				vGuiWindows[ i ].entire_window.bottom_y = ( vGuiWindows[ i ].y + vGuiWindows[ i ].height );			}		}		//we are done here		m_bIsDraggingWindow = false;	}	vector<window_info_s>	vGuiWindows;		CD3DFont*				m_pFont;	ID3DXLine *pLine;	bool m_bIsActive;	bool m_bIsDraggingWindow;	int m_iDraggingWindow;		mouse_data m_mouse;	~cGui( )	{			}};