Advertisement
Guest User

no. 26 - Input box

a guest
Sep 11th, 2010
762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.66 KB | None | 0 0
  1. /*
  2. -----------------------------------------
  3. * Game hacking QTS ( Quickie Tip Series )
  4. * no. 26 - Input box
  5. -----------------------------------------
  6. * Author: SEGnosis  - GHAnon.net
  7. * Thanks to:
  8. * bitterbanana      - No known site
  9. * Drunken Cheetah   - No known site
  10. * fatboy88      - No known site
  11. * Geek4Ever         - No known site
  12. * learn_more        - www.uc-forum.com
  13. * Novocaine         - http://ilsken.net/blog/?page_id=64
  14. * Philly0494        - No known site
  15. * Roverturbo        - www.uc-forum.com
  16. * SilentKarma       - www.halocoders.com - offline
  17. * Strife        - www.uc-forum.com
  18. * Wieter20      - No known site
  19. */
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26. class C_InputBox
  27. {
  28.     public:
  29.         void Load()
  30.         {
  31.             m_szInputQueue[ 0 ] = 0;
  32.  
  33.             SetRect( &m_rtClient, 0, 0, 300, 200 );
  34.             SetRect( &m_rtInput, 0, 0, 150, CDraw.m_iListBoxFontHeight + 2 );
  35.             SetRect( &m_rtButton, 0, 0, CDraw.m_iListBoxFontWidth * 4, CDraw.m_iListBoxFontHeight + 2 );
  36.         }
  37.  
  38.         void Input( UINT uiMessage, WPARAM wParam, LPARAM lParam );
  39.  
  40.         void DrawDialog();
  41.         void Move();
  42.  
  43.         bool GetCurrentInput( char* szpQueue )
  44.         {
  45.             if( m_bActive)
  46.                 strcpy( szpQueue, m_szInputQueue );
  47.             return false;
  48.         }
  49.  
  50.     private:
  51.         char m_szInputQueue[ 24 ];
  52.  
  53.         bool m_bActive;
  54.  
  55.         RECT    m_rtClient,
  56.                 m_rtInput,
  57.                 m_rtButton;
  58. }CInputBox;
  59.  
  60. void C_InputBox::Input( UINT uiMessage, WPARAM wParam, LPARAM lParam )
  61. {
  62.     switch( uiMessage )
  63.     {
  64.     case WM_LBUTTONDOWN:
  65.         {
  66.             POINT ptCursor;
  67.             GetCursorPos( &ptCursor );
  68.             ScreenToClient( g_hWnd, &ptCursor );
  69.  
  70.             if( CDraw.IsPointInRect( ptCursor, m_rtButton, true ) )
  71.                 m_bActive = false;     
  72.         }
  73.         break;
  74.  
  75.     case WM_CHAR:
  76.         switch( wParam )
  77.         {
  78.         case VK_BACK:
  79.                 m_szInputQueue[ max( strlen( m_szInputQueue ) - 1, 0 ) ] = 0;
  80.             break;
  81.  
  82.         case VK_RETURN:
  83.                 m_bActive = false;
  84.             break;
  85.  
  86.         case VK_TAB:
  87.             if( !m_bActive )
  88.             {
  89.                 m_bActive = true;
  90.                 m_szInputQueue[ 0 ] = 0;
  91.             }
  92.             break;
  93.  
  94.         default:
  95.             {
  96.                 static char szInput[ 2 ] = { 0 };
  97.  
  98.                 szInput[ 0 ] = ( char )wParam;
  99.  
  100.                 if( strlen( m_szInputQueue ) < 23 && ( isalnum( szInput[ 0 ] ) || szInput[ 0 ] == VK_SPACE ) )
  101.                     strcat( m_szInputQueue, szInput );
  102.             }
  103.             break;
  104.         }
  105.         break;
  106.     }
  107. }
  108.  
  109. void C_InputBox::Move()
  110. {
  111.     SetRect( &m_rtClient, g_rtClient.right/2 - m_rtClient.right/2, g_rtClient.bottom/2 - m_rtClient.bottom/2, m_rtClient.right, m_rtClient.bottom );
  112.     SetRect( &m_rtInput, m_rtClient.left + 75, m_rtClient.top + 50, m_rtInput.right, m_rtInput.bottom );
  113.     SetRect( &m_rtButton, m_rtClient.left + m_rtClient.right/2 - m_rtButton.right/2, m_rtClient.top + m_rtClient.bottom - m_rtButton.bottom - 10, m_rtButton.right, m_rtButton.bottom );
  114. }
  115.  
  116. void C_InputBox::DrawDialog()
  117. {
  118.     if( !m_bActive )
  119.         return;
  120.  
  121.     Move();
  122.  
  123.     const D3DCOLOR coLightGray  = D3DCOLOR_XRGB( 150, 150, 150 );
  124.     const D3DCOLOR coMocha      = D3DCOLOR_XRGB( 63, 41, 4 );
  125.     const D3DCOLOR coMochaBorder= D3DCOLOR_XRGB( 27, 27, 27 );
  126.  
  127.     CDraw.GradientRect( D3DXVECTOR2( m_rtClient.left, m_rtClient.top ), m_rtClient.right, m_rtClient.bottom, CDraw.m_coWhite, coLightGray );
  128.     CDraw.Rect( m_rtInput.left, m_rtInput.top, m_rtInput.right, m_rtInput.bottom, coMocha );
  129.     CDraw.LineRect( m_rtInput.left, m_rtInput.top, m_rtInput.right, m_rtInput.bottom, coMochaBorder );
  130.    
  131.     CDraw.Rect( m_rtButton.left, m_rtButton.top, m_rtButton.right, m_rtButton.bottom, coMocha );
  132.     CDraw.LineRect( m_rtButton.left, m_rtButton.top, m_rtButton.right, m_rtButton.bottom, coMochaBorder );
  133.  
  134.     CDraw.String( m_rtButton.left + CDraw.m_iListBoxFontWidth, m_rtButton.top + 1, CDraw.m_coWhite, FF_DEFAULT, "Ok" );
  135.  
  136.     CDraw.String( m_rtInput.left + 5, m_rtInput.top + 1, CDraw.m_coWhite, FF_DEFAULT, m_szInputQueue );
  137. }
  138.  
  139. CInputBox.Load(); // once
  140. CInputBox.DrawDialog(); // in endscene
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement