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.

236 lines
5.5 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "vgui_basepanel.h"
  10. #include <keyvalues.h>
  11. #include <vgui/IScheme.h>
  12. #include <vgui/IVGui.h>
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. //-----------------------------------------------------------------------------
  16. // Purpose:
  17. //-----------------------------------------------------------------------------
  18. CBasePanel::CBasePanel( vgui::Panel *pParent, const char *panelName ) : BaseClass( pParent, panelName )
  19. {
  20. m_bTexturedBackground = false;
  21. m_nBackgroundMaterial = -1;
  22. m_szBgTexture[ 0 ] = 0;
  23. m_bTiled = false;
  24. m_nTextureSize[ 0 ] = 0;
  25. m_nTextureSize[ 1 ] = 0;
  26. m_bReflectMouse = false;
  27. }
  28. //-----------------------------------------------------------------------------
  29. // Purpose:
  30. // Input : x -
  31. // y -
  32. // w -
  33. // h -
  34. //-----------------------------------------------------------------------------
  35. CBasePanel::CBasePanel( vgui::Panel *pParent, const char *panelName, int x, int y, int w, int h ) :
  36. Panel( pParent, panelName )
  37. {
  38. SetBounds( x, y, w, h );
  39. m_bTexturedBackground = false;
  40. m_nBackgroundMaterial = -1;
  41. m_szBgTexture[ 0 ] = 0;
  42. m_bTiled = false;
  43. m_nTextureSize[ 0 ] = 0;
  44. m_nTextureSize[ 1 ] = 0;
  45. }
  46. //-----------------------------------------------------------------------------
  47. // Purpose:
  48. //-----------------------------------------------------------------------------
  49. CBasePanel::~CBasePanel( void )
  50. {
  51. }
  52. //-----------------------------------------------------------------------------
  53. // Purpose:
  54. //-----------------------------------------------------------------------------
  55. void CBasePanel::PaintBackground( void )
  56. {
  57. if ( !m_bTexturedBackground )
  58. {
  59. BaseClass::PaintBackground();
  60. return;
  61. }
  62. if ( m_nBackgroundMaterial == -1 )
  63. {
  64. m_nBackgroundMaterial = vgui::surface()->CreateNewTextureID();
  65. vgui::surface()->DrawSetTextureFile( m_nBackgroundMaterial, m_szBgTexture, true, true );
  66. }
  67. vgui::surface()->DrawSetColor( GetFgColor() );
  68. // Draw it with texture
  69. vgui::surface()->DrawSetTexture( m_nBackgroundMaterial );
  70. if ( m_bTiled && ( !m_nTextureSize[ 0 ] ) )
  71. {
  72. vgui::surface()->DrawGetTextureSize( m_nBackgroundMaterial, m_nTextureSize[ 0 ], m_nTextureSize[ 1 ] );
  73. }
  74. int wide, tall;
  75. GetSize( wide, tall );
  76. if ( m_bTiled && m_nTextureSize[ 0 ] && m_nTextureSize[ 1 ] )
  77. {
  78. int x = 0;
  79. int y = 0;
  80. while ( y < tall )
  81. {
  82. vgui::surface()->DrawTexturedRect( 0, 0, m_nTextureSize[ 0 ], m_nTextureSize[ 1 ] );
  83. x += m_nTextureSize[ 0 ];
  84. if ( x >= wide )
  85. {
  86. x = 0;
  87. y += m_nTextureSize[ 1 ];
  88. }
  89. }
  90. }
  91. else
  92. {
  93. vgui::surface()->DrawTexturedRect( 0, 0, wide, tall );
  94. }
  95. }
  96. //-----------------------------------------------------------------------------
  97. // Purpose:
  98. // Input : *texname -
  99. //-----------------------------------------------------------------------------
  100. void CBasePanel::SetTexture( const char *texname, bool tiled /*=false*/ )
  101. {
  102. m_bTexturedBackground = true;
  103. m_bTiled = tiled;
  104. Q_strncpy( m_szBgTexture, texname, sizeof( m_szBgTexture ) );
  105. m_nBackgroundMaterial = vgui::surface()->CreateNewTextureID();
  106. vgui::surface()->DrawSetTextureFile( m_nBackgroundMaterial, m_szBgTexture , true, true);
  107. }
  108. void CBasePanel::SetReflectMouse( bool reflect )
  109. {
  110. m_bReflectMouse = true;
  111. }
  112. void CBasePanel::OnCursorMoved(int x,int y)
  113. {
  114. if ( !m_bReflectMouse )
  115. return;
  116. if ( !GetParent() )
  117. return;
  118. LocalToScreen( x, y );
  119. vgui::ivgui()->PostMessage(
  120. GetParent()->GetVPanel(),
  121. new KeyValues( "CursorMoved", "xpos", x, "ypos", y ),
  122. GetVPanel() );
  123. }
  124. void CBasePanel::OnMousePressed(vgui::MouseCode code)
  125. {
  126. if ( !m_bReflectMouse )
  127. return;
  128. if ( !GetParent() )
  129. return;
  130. vgui::ivgui()->PostMessage(
  131. GetParent()->GetVPanel(),
  132. new KeyValues( "MousePressed", "code", code ),
  133. GetVPanel() );
  134. }
  135. void CBasePanel::OnMouseDoublePressed(vgui::MouseCode code)
  136. {
  137. if ( !m_bReflectMouse )
  138. return;
  139. if ( !GetParent() )
  140. return;
  141. vgui::ivgui()->PostMessage(
  142. GetParent()->GetVPanel(),
  143. new KeyValues( "MouseDoublePressed", "code", code ),
  144. GetVPanel() );
  145. }
  146. void CBasePanel::OnMouseReleased(vgui::MouseCode code)
  147. {
  148. if ( !m_bReflectMouse )
  149. return;
  150. if ( !GetParent() )
  151. return;
  152. vgui::ivgui()->PostMessage(
  153. GetParent()->GetVPanel(),
  154. new KeyValues( "MouseReleased", "code", code ),
  155. GetVPanel() );
  156. }
  157. void CBasePanel::OnMouseWheeled(int delta)
  158. {
  159. if ( !m_bReflectMouse )
  160. return;
  161. if ( !GetParent() )
  162. return;
  163. vgui::ivgui()->PostMessage(
  164. GetParent()->GetVPanel(),
  165. new KeyValues( "MouseWheeled", "delta", delta ),
  166. GetVPanel() );
  167. }
  168. void CBasePanel::OnTick( void )
  169. {
  170. // Nothing
  171. }
  172. //-----------------------------------------------------------------------------
  173. // Purpose:
  174. //-----------------------------------------------------------------------------
  175. CHudLabel::CHudLabel( vgui::Panel *parent, const char *panelName, const char *text) :
  176. vgui::Label( parent,panelName,text )
  177. {
  178. m_bSelected = false;
  179. }
  180. //-----------------------------------------------------------------------------
  181. // Purpose:
  182. //-----------------------------------------------------------------------------
  183. void CHudLabel::ApplySchemeSettings(vgui::IScheme *pScheme)
  184. {
  185. Panel::ApplySchemeSettings(pScheme);
  186. if ( m_bSelected )
  187. {
  188. SetBgColor( GetSchemeColor("HudStatusSelectedBgColor", pScheme) );
  189. }
  190. else
  191. {
  192. SetBgColor( GetSchemeColor("HudStatusBgColor", pScheme) );
  193. }
  194. }