#include #include "GuiInit.h" //declare the class cGui* m_pGui; //================ //HELPER FUNCTIONS //================ #define D3DCOLOR_GUI( x ) D3DCOLOR_ARGB( x.a, x.r, x.g, x.b ) gui_color GetColor( int r, int g, int b, int a ) { gui_color c; c.r = r; c.g = g; c.b = b; c.a = a; return c; } color_scheme_s* ConstructColorScheme( gui_color bg, gui_color boarder, gui_color not_pressed, gui_color pressed, gui_color textDark, gui_color textLight ) { color_scheme_s *p = ( color_scheme_s* )malloc( sizeof( color_scheme_s ) ); p->bg = bg; p->boarder = boarder; p->not_pressed = not_pressed; p->pressed = pressed; p->textDark = textDark; p->textLight = textLight; return p; } int GetValueFromPercent( int number, int current_percent, int max_percent ) { return ( current_percent * number ) / max_percent; } //================ //-HELPER FUNCTIONS //================ //================ //CALLBACKS //================ #define GetWindowFromIndex( i ) &m_pGui->vGuiWindows[ i ] #define GetCaptionFromIndex( i, c ) &m_pGui->vGuiWindows[ i ].m_vCaptions[ c ] #define GetButtonFromIndex( i, b ) &m_pGui->vGuiWindows[ i ].m_vButtons[ b ] #define GetCheckBoxFromIndex( i, c ) &m_pGui->vGuiWindows[ i ].m_vCheckBoxes[ c ] #define GetStatusBarFromIndex( i, s ) &m_pGui->vGuiWindows[ i ].m_vStatusBars[ s ] void CallBackButton1( int p, int c ) { //grab the parent window and child ( object ) window_info_s* window = GetWindowFromIndex( p ); button_info_s* button = GetButtonFromIndex( p, c ); //switch on/off mouse info m_pGui->m_bDisplayMouseInformation = !m_pGui->m_bDisplayMouseInformation; } void CallbackStatusBar1( int p, int c ) { //grab the parent window and child ( object ) window_info_s* window = GetWindowFromIndex( p ); statusbar_info_s* status = GetStatusBarFromIndex( p, c ); //i decided to handle a click in my callback int m_iNewPercent = m_pGui->GetCompletionFromPoint( window, status, m_pGui->m_mouse.x, m_pGui->m_mouse.y ); //DONT DO BAD THING!!!!!!!!!! 0mgz if( m_iNewPercent < 0 || m_iNewPercent > 100 ) return; //set the status bar completion status->m_iCompletion = m_iNewPercent; //convert 0/100 percent to RGB format color window->colors.bg.r = GetValueFromPercent( 255, status->m_iCompletion, 100 ); } //================ //-CALLBACKS //================ void RenderGui( LPDIRECT3DDEVICE9 pDevice ) { m_pGui->HandleWindowMovement( ); m_pGui->RenderWindows( pDevice ); m_pGui->RenderMouseData( ); //for debugging purposes m_pGui->RenderMouse( ); } void DesignGui( ) { //here you will construct your window( s ) color_scheme_s* m_pScheme = ConstructColorScheme( GetColor( 233, 100, 100, 140 ), GetColor( 0, 0, 0, 255 ), GetColor( 130, 130, 130, 255 ), GetColor( 180, 180, 180, 233 ), GetColor( 0, 0, 0, 255 ), GetColor( 255, 255, 255, 255 ) ); GUI_WINDOW_HANDLE m_iWindowOne = m_pGui->AddWindow( "Mouse Settings", m_pScheme, 10, 30, 200, 300 ); GUI_BUTTON_HANDLE m_iButtonOne = m_pGui->AddWindowButton( m_iWindowOne, 10, 30, 180, 20, ( FARPROC )CallBackButton1, "Show Mouse Information", m_pScheme ); GUI_STATUSBAR_HANDLE m_iStatusBarOne = m_pGui->AddStatusBar( m_iWindowOne, "Complete", 10, 60, 180, 20, 0, ( FARPROC )CallbackStatusBar1, &GetColor( 255, 0, 0, 255 ), &GetColor( 0, 0, 0, 255 ), &GetColor( 222, 222, 222, 255 ) ); m_pGui->m_mouse.color = GetColor( 255, 255, 255, 255 ); } void HandleKeys( UINT message, WPARAM wParam, LPARAM lParam ) { m_pGui->HandleKey( wParam, lParam, message ); } void InitGuiClass( LPDIRECT3DDEVICE9 pDevice ) { m_pGui = new cGui( pDevice ); DesignGui( ); }