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.

187 lines
5.4 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef C_VGUISCREEN_H
  8. #define C_VGUISCREEN_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <vgui_controls/EditablePanel.h>
  13. #include "c_baseentity.h"
  14. #include "panelmetaclassmgr.h"
  15. class KeyValues;
  16. //-----------------------------------------------------------------------------
  17. // Helper macro to make overlay factories one line of code. Use like this:
  18. // DECLARE_VGUI_SCREEN_FACTORY( CVguiScreenPanel, "image" );
  19. //-----------------------------------------------------------------------------
  20. struct VGuiScreenInitData_t
  21. {
  22. C_BaseEntity *m_pEntity;
  23. VGuiScreenInitData_t() : m_pEntity(NULL) {}
  24. explicit VGuiScreenInitData_t( C_BaseEntity *pEntity ) : m_pEntity(pEntity) {}
  25. };
  26. #define DECLARE_VGUI_SCREEN_FACTORY( _PanelClass, _nameString ) \
  27. DECLARE_PANEL_FACTORY( _PanelClass, VGuiScreenInitData_t, _nameString )
  28. //-----------------------------------------------------------------------------
  29. // Base class for vgui screen panels
  30. //-----------------------------------------------------------------------------
  31. class CVGuiScreenPanel : public vgui::EditablePanel
  32. {
  33. DECLARE_CLASS_GAMEROOT( CVGuiScreenPanel, vgui::EditablePanel );
  34. public:
  35. CVGuiScreenPanel( vgui::Panel *parent, const char *panelName );
  36. CVGuiScreenPanel( vgui::Panel *parent, const char *panelName, vgui::HScheme hScheme );
  37. virtual bool Init( KeyValues* pKeyValues, VGuiScreenInitData_t* pInitData );
  38. vgui::Panel *CreateControlByName(const char *controlName);
  39. virtual void OnCommand( const char *command );
  40. protected:
  41. C_BaseEntity *GetEntity() const { return m_hEntity.Get(); }
  42. private:
  43. EHANDLE m_hEntity;
  44. };
  45. //-----------------------------------------------------------------------------
  46. // Purpose:
  47. //-----------------------------------------------------------------------------
  48. class C_VGuiScreen : public C_BaseEntity
  49. {
  50. DECLARE_CLASS( C_VGuiScreen, C_BaseEntity );
  51. public:
  52. DECLARE_CLIENTCLASS();
  53. C_VGuiScreen();
  54. ~C_VGuiScreen();
  55. virtual void PreDataUpdate( DataUpdateType_t updateType );
  56. virtual void OnDataChanged( DataUpdateType_t type );
  57. virtual int DrawModel( int flags, const RenderableInstance_t &instance );
  58. virtual bool ShouldDraw( void );
  59. virtual void ClientThink( );
  60. virtual void GetAimEntOrigin( IClientEntity *pAttachedTo, Vector *pOrigin, QAngle *pAngles );
  61. virtual bool IsVisibleToPlayer( C_BasePlayer *pViewingPlayer );
  62. virtual RenderableTranslucencyType_t ComputeTranslucencyType();
  63. const char *PanelName() const;
  64. // The view screen has the cursor pointing at it
  65. void GainFocus( );
  66. void LoseFocus();
  67. // Button state...
  68. void SetButtonState( int nButtonState );
  69. // Is the screen backfaced given a view position?
  70. bool IsBackfacing( const Vector &viewOrigin );
  71. // Return intersection point of ray with screen in barycentric coords
  72. bool IntersectWithRay( const Ray_t &ray, float *u, float *v, float *t );
  73. // Is the screen turned on?
  74. bool IsActive() const;
  75. // Are we only visible to teammates?
  76. bool IsVisibleOnlyToTeammates() const;
  77. // Are we visible to someone on this team?
  78. bool IsVisibleToTeam( int nTeam );
  79. bool IsAttachedToViewModel() const;
  80. bool AcceptsInput() const;
  81. void SetAcceptsInput( bool acceptsinput );
  82. C_BasePlayer *GetPlayerOwner( void );
  83. bool IsInputOnlyToOwner( void );
  84. int GetScreenFlags( void ) const;
  85. private:
  86. // Vgui screen management
  87. void CreateVguiScreen( const char *pTypeName );
  88. void DestroyVguiScreen( );
  89. // Computes the panel to world transform
  90. void ComputePanelToWorld();
  91. // Computes control points of the quad describing the screen
  92. void ComputeEdges( Vector *pUpperLeft, Vector *pUpperRight, Vector *pLowerLeft );
  93. // Writes the z buffer
  94. void DrawScreenOverlay();
  95. private:
  96. int m_nPixelWidth;
  97. int m_nPixelHeight;
  98. float m_flWidth;
  99. float m_flHeight;
  100. int m_nPanelName; // The name of the panel
  101. int m_nButtonState;
  102. int m_nButtonPressed;
  103. int m_nButtonReleased;
  104. int m_nOldPx;
  105. int m_nOldPy;
  106. int m_nOldButtonState;
  107. int m_nAttachmentIndex;
  108. int m_nOverlayMaterial;
  109. int m_fScreenFlags;
  110. int m_nOldPanelName;
  111. int m_nOldOverlayMaterial;
  112. bool m_bLoseThinkNextFrame;
  113. bool m_bAcceptsInput;
  114. CMaterialReference m_WriteZMaterial;
  115. CMaterialReference m_OverlayMaterial;
  116. VMatrix m_PanelToWorld;
  117. CPanelWrapper m_PanelWrapper;
  118. CHandle<C_BasePlayer> m_hPlayerOwner;
  119. };
  120. //-----------------------------------------------------------------------------
  121. // Returns an entity that is the nearby vgui screen; NULL if there isn't one
  122. //-----------------------------------------------------------------------------
  123. C_BaseEntity *FindNearbyVguiScreen( const Vector &viewPosition, const QAngle &viewAngle, int nTeam = -1 );
  124. //-----------------------------------------------------------------------------
  125. // Activates/Deactivates vgui screen
  126. //-----------------------------------------------------------------------------
  127. void ActivateVguiScreen( C_BaseEntity *pVguiScreen );
  128. void DeactivateVguiScreen( C_BaseEntity *pVguiScreen );
  129. //-----------------------------------------------------------------------------
  130. // Updates vgui screen button state
  131. //-----------------------------------------------------------------------------
  132. void SetVGuiScreenButtonState( C_BaseEntity *pVguiScreen, int nButtonState );
  133. // Called at shutdown.
  134. void ClearKeyValuesCache();
  135. #endif // C_VGUISCREEN_H