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.

83 lines
2.6 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. #include "ViewConeImage.h"
  10. #include <keyvalues.h>
  11. #include <vgui_controls/Panel.h>
  12. #include "VGuiMatSurface/IMatSystemSurface.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. //-----------------------------------------------------------------------------
  16. // initialization
  17. //-----------------------------------------------------------------------------
  18. bool CViewConeImage::Init( vgui::Panel *pParent, KeyValues* pInitData )
  19. {
  20. Assert( pParent );
  21. // Load viewcone material
  22. if (!m_Image.Init( pParent->GetVPanel(), pInitData ))
  23. return false;
  24. // Position the view cone...
  25. int viewconesize = pInitData->GetInt( "size", 32 );
  26. m_Image.SetRenderSize( viewconesize, viewconesize );
  27. int cx, cy;
  28. pParent->GetSize( cx, cy );
  29. m_Image.SetPos( (cx - viewconesize) / 2, (cy - viewconesize) / 2 );
  30. return true;
  31. }
  32. //-----------------------------------------------------------------------------
  33. // Paint the sucka
  34. //-----------------------------------------------------------------------------
  35. void CViewConeImage::Paint( float yaw )
  36. {
  37. g_pMatSystemSurface->DisableClipping( true );
  38. m_Image.DoPaint( NULL, yaw );
  39. g_pMatSystemSurface->DisableClipping( false );
  40. }
  41. void CViewConeImage::SetColor( int r, int g, int b )
  42. {
  43. m_Image.SetColor( Color( r, g, b, 255 ) );
  44. }
  45. //-----------------------------------------------------------------------------
  46. // Helper method to initialize a view cone image from KeyValues data..
  47. // KeyValues contains the bitmap data, pSectionName, if it exists,
  48. // indicates which subsection of pInitData should be looked at to get at the
  49. // image data. The final argument is the bitmap image to initialize.
  50. // The function returns true if it succeeded.
  51. //
  52. // NOTE: This function looks for the key values 'material' and 'color'
  53. // and uses them to set up the material + modulation color of the image
  54. //-----------------------------------------------------------------------------
  55. bool InitializeViewConeImage( KeyValues *pInitData, const char* pSectionName,
  56. vgui::Panel *pParent, CViewConeImage* pViewConeImage )
  57. {
  58. KeyValues *pViewConeImageSection;
  59. if (pSectionName)
  60. {
  61. pViewConeImageSection = pInitData->FindKey( pSectionName );
  62. if ( !pViewConeImageSection )
  63. return false;
  64. }
  65. else
  66. {
  67. pViewConeImageSection = pInitData;
  68. }
  69. return pViewConeImage->Init( pParent, pViewConeImageSection );
  70. }