Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
5.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: This is a panel which is rendered image on top of an entity
  4. //
  5. // $Revision: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #pragma warning (disable: 4514)
  10. #include "vgui_bitmappanel.h"
  11. #include <keyvalues.h>
  12. #include "panelmetaclassmgr.h"
  13. #include "vgui_bitmapimage.h"
  14. #ifdef INVASION_CLIENT_DLL
  15. #include "hud_commander_statuspanel.h"
  16. #endif
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include "tier0/memdbgon.h"
  19. //-----------------------------------------------------------------------------
  20. // Constructor
  21. //-----------------------------------------------------------------------------
  22. CBitmapPanel::CBitmapPanel( ) : BaseClass( NULL, "CBitmapPanel" ), m_pImage( NULL )
  23. {
  24. SetPaintBackgroundEnabled( false );
  25. m_szMouseOverText[ 0 ] = 0;
  26. m_r = m_g = m_b = m_a = 255;
  27. m_bOwnsImage = true;
  28. }
  29. CBitmapPanel::CBitmapPanel( vgui::Panel *pParent, const char *pName ) :
  30. BaseClass( pParent, pName ), m_pImage( NULL )
  31. {
  32. SetPaintBackgroundEnabled( false );
  33. m_szMouseOverText[ 0 ] = 0;
  34. m_r = m_g = m_b = m_a = 255;
  35. m_bOwnsImage = true;
  36. }
  37. CBitmapPanel::~CBitmapPanel()
  38. {
  39. if (m_pImage && m_bOwnsImage)
  40. {
  41. delete m_pImage;
  42. m_pImage = NULL;
  43. }
  44. }
  45. //-----------------------------------------------------------------------------
  46. // initialization
  47. //-----------------------------------------------------------------------------
  48. bool CBitmapPanel::Init( KeyValues* pInitData )
  49. {
  50. Assert( pInitData );
  51. // modulation color
  52. if (!ParseRGBA( pInitData, "color", m_r, m_g, m_b, m_a ))
  53. return false;
  54. int x, y, w, h;
  55. if (!ParseRect( pInitData, "position", x, y, w, h ))
  56. return false;
  57. const char *mouseover = pInitData->GetString( "mousehint", "" );
  58. if ( mouseover && mouseover[ 0 ] )
  59. {
  60. Q_strncpy( m_szMouseOverText, mouseover, sizeof( m_szMouseOverText ) );
  61. }
  62. // Set the size...
  63. SetPos( x, y );
  64. SetSize( w, h );
  65. char const* pClassImage = pInitData->GetString( "material" );
  66. if ( !pClassImage || !pClassImage[ 0 ] )
  67. return false;
  68. // hook in the bitmap
  69. m_pImage = new BitmapImage( GetVPanel(), pClassImage );
  70. m_bOwnsImage = true;
  71. return true;
  72. }
  73. //-----------------------------------------------------------------------------
  74. // initialization from build-mode dialog style .res files
  75. //-----------------------------------------------------------------------------
  76. void CBitmapPanel::ApplySettings(KeyValues *pInitData)
  77. {
  78. BaseClass::ApplySettings(pInitData);
  79. if (m_pImage && m_bOwnsImage)
  80. {
  81. delete m_pImage;
  82. m_pImage = NULL;
  83. }
  84. // modulation color. Can't use ParseRGBA since this uses a vgui::KeyValues (feh)
  85. m_r = m_g = m_b = m_a = 255;
  86. const char *pColorString = pInitData->GetString( "color", "255 255 255 255" );
  87. if ( pColorString && pColorString[ 0 ] )
  88. {
  89. // Try and scan them in
  90. int r, g, b, a;
  91. int scanned;
  92. scanned = sscanf( pColorString, "%i %i %i %i", &r, &g, &b, &a );
  93. if ( scanned == 4 )
  94. {
  95. m_r = r; m_g = g; m_b = b; m_a = a;
  96. }
  97. else
  98. {
  99. Warning( "Couldn't scan four color values from %s\n", pColorString );
  100. }
  101. }
  102. m_szMouseOverText[0] = 0;
  103. char const* pClassImage = pInitData->GetString( "material" );
  104. if ( pClassImage && pClassImage[ 0 ] && m_bOwnsImage )
  105. {
  106. // hook in the bitmap
  107. m_pImage = new BitmapImage( GetVPanel(), pClassImage );
  108. }
  109. }
  110. //-----------------------------------------------------------------------------
  111. // Draws the puppy
  112. //-----------------------------------------------------------------------------
  113. void CBitmapPanel::Paint( void )
  114. {
  115. if ( !m_pImage )
  116. return;
  117. Color color;
  118. color.SetColor( m_r, m_g, m_b, m_a );
  119. m_pImage->SetColor( color );
  120. m_pImage->DoPaint( GetVPanel() );
  121. }
  122. //-----------------------------------------------------------------------------
  123. // Purpose:
  124. //-----------------------------------------------------------------------------
  125. void CBitmapPanel::OnCursorEntered()
  126. {
  127. #ifdef INVASION_CLIENT_DLL
  128. if ( m_szMouseOverText[ 0 ] )
  129. {
  130. StatusPrint( TYPE_HINT, "%s", m_szMouseOverText );
  131. }
  132. #endif
  133. }
  134. //-----------------------------------------------------------------------------
  135. // Purpose:
  136. //-----------------------------------------------------------------------------
  137. void CBitmapPanel::OnCursorExited()
  138. {
  139. #ifdef INVASION_CLIENT_DLL
  140. if ( m_szMouseOverText[ 0 ] )
  141. {
  142. StatusClear();
  143. }
  144. #endif
  145. }
  146. //-----------------------------------------------------------------------------
  147. // Purpose:
  148. // Output : char const
  149. //-----------------------------------------------------------------------------
  150. const char *CBitmapPanel::GetMouseOverText( void )
  151. {
  152. return m_szMouseOverText;
  153. }
  154. //-----------------------------------------------------------------------------
  155. // Purpose: Sets up the panel
  156. // Used by panels that aren't created by the commander overlay factory (i.e. aren't parsed from a keyvalues file)
  157. //-----------------------------------------------------------------------------
  158. void CBitmapPanel::SetImage( BitmapImage *pImage )
  159. {
  160. if ( m_pImage && m_bOwnsImage )
  161. {
  162. delete m_pImage;
  163. }
  164. m_pImage = pImage;
  165. m_bOwnsImage = (pImage == NULL);
  166. // Get the color from the image
  167. if ( m_pImage )
  168. {
  169. m_pImage->GetColor( m_r, m_g, m_b, m_a );
  170. }
  171. }