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.

178 lines
4.9 KiB

  1. //====== Copyright 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef VGUI_AVATARIMAGE_H
  7. #define VGUI_AVATARIMAGE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include <vgui_controls/Image.h>
  12. #include <vgui_controls/ImagePanel.h>
  13. #include "steam/steam_api.h"
  14. #include "c_baseplayer.h"
  15. // size of the friend background frame (see texture ico_friend_indicator_avatar)
  16. #define FRIEND_ICON_SIZE_X (55)
  17. #define FRIEND_ICON_SIZE_Y (34)
  18. // offset of avatar within the friend icon
  19. #define FRIEND_ICON_AVATAR_INDENT_X (22)
  20. #define FRIEND_ICON_AVATAR_INDENT_Y (1)
  21. // size of the standard avatar icon (unless override by SetAvatarSize)
  22. #define DEFAULT_AVATAR_SIZE (32)
  23. enum EAvatarSize
  24. {
  25. eAvatarSmall,
  26. eAvatarMedium,
  27. eAvatarLarge
  28. };
  29. //-----------------------------------------------------------------------------
  30. // Purpose:
  31. //-----------------------------------------------------------------------------
  32. class CAvatarImage : public vgui::IImage
  33. {
  34. public:
  35. CAvatarImage( void );
  36. // Call this to set the steam ID associated with the avatar
  37. bool SetAvatarSteamID( CSteamID steamIDUser, EAvatarSize avatarSize = eAvatarSmall );
  38. void UpdateFriendStatus( void );
  39. void ClearAvatarSteamID( void );
  40. // Call to Paint the image
  41. // Image will draw within the current panel context at the specified position
  42. virtual void Paint( void );
  43. // Set the position of the image
  44. virtual void SetPos(int x, int y)
  45. {
  46. m_nX = x;
  47. m_nY = y;
  48. }
  49. // Gets the size of the content
  50. virtual void GetContentSize(int &wide, int &tall)
  51. {
  52. wide = m_wide;
  53. tall = m_tall;
  54. }
  55. // Get the size the image will actually draw in (usually defaults to the content size)
  56. virtual void GetSize(int &wide, int &tall)
  57. {
  58. GetContentSize( wide, tall );
  59. }
  60. // Sets the size of the image
  61. virtual void SetSize(int wide, int tall);
  62. void SetAvatarSize(int wide, int tall);
  63. // Set the draw color
  64. virtual void SetColor(Color col)
  65. {
  66. m_Color = col;
  67. }
  68. bool IsValid() { return m_bValid; }
  69. int GetWide() { return m_wide; }
  70. int GetTall() { return m_tall; }
  71. int GetAvatarWide() { return m_avatarWide; }
  72. int GetAvatarTall() { return m_avatarTall; }
  73. // [tj] simple setter for drawing friend icon
  74. void SetDrawFriend(bool drawFriend) { m_bDrawFriend = drawFriend; }
  75. // [pmf] specify the default (fallback) image
  76. void SetDefaultImage(vgui::IImage* pImage) { m_pDefaultImage = pImage; }
  77. virtual bool Evict( void ) { return false; }
  78. virtual int GetNumFrames( void ) { return 0; }
  79. virtual void SetFrame( int nFrame ) {}
  80. virtual vgui::HTexture GetID( void ) { return m_iTextureID; }
  81. virtual void SetRotation( int iRotation ) {}
  82. protected:
  83. void InitFromRGBA( const byte *rgba, int width, int height );
  84. private:
  85. void LoadAvatarImage();
  86. Color m_Color;
  87. int m_iTextureID;
  88. int m_nX, m_nY;
  89. int m_wide, m_tall;
  90. int m_avatarWide, m_avatarTall;
  91. bool m_bValid;
  92. bool m_bFriend;
  93. bool m_bLoadPending;
  94. float m_fNextLoadTime; // used to throttle load attempts
  95. EAvatarSize m_AvatarSize;
  96. CHudTexture *m_pFriendIcon;
  97. CSteamID m_SteamID;
  98. // [tj] Whether or not we should draw the friend icon
  99. bool m_bDrawFriend;
  100. // [pmf] image to use as a fallback when get from steam fails (or not called)
  101. vgui::IImage* m_pDefaultImage;
  102. };
  103. //-----------------------------------------------------------------------------
  104. // Purpose:
  105. //-----------------------------------------------------------------------------
  106. class CAvatarImagePanel : public vgui::Panel
  107. {
  108. public:
  109. DECLARE_CLASS_SIMPLE( CAvatarImagePanel, vgui::Panel );
  110. CAvatarImagePanel( vgui::Panel *parent, const char *name );
  111. // reset the image to its default value, clearing any info retrieved from Steam
  112. void ClearAvatar();
  113. // Set the player that this Avatar should display for
  114. void SetPlayer( C_BasePlayer *pPlayer, EAvatarSize avatarSize = eAvatarSmall );
  115. void SetPlayerByIndex( int entityIndex, EAvatarSize avatarSize = eAvatarSmall );
  116. void SetPlayerBySteamID( CSteamID steamIDForPlayer, EAvatarSize avatarSize );
  117. // sets whether or not the image should scale to fit the size of the ImagePanel (defaults to false)
  118. void SetShouldScaleImage( bool bScaleImage );
  119. // sets whether to automatically draw the friend icon behind the avatar for Steam friends
  120. void SetShouldDrawFriendIcon( bool bDrawFriend );
  121. // specify the size of the avatar portion of the image (the actual image may be larger than this
  122. // when it incorporates the friend icon)
  123. void SetAvatarSize( int width, int height);
  124. // specify a fallback image to use
  125. void SetDefaultAvatar(vgui::IImage* pDefaultAvatar);
  126. virtual void OnSizeChanged(int newWide, int newTall);
  127. virtual void PaintBackground( void );
  128. bool IsValid() { return ( m_pImage && m_pImage->IsValid() ); }
  129. protected:
  130. CPanelAnimationVar( Color, m_clrOutline, "color_outline", "Black" );
  131. virtual void ApplySettings(KeyValues *inResourceData);
  132. void UpdateSize();
  133. private:
  134. CAvatarImage *m_pImage;
  135. bool m_bScaleImage;
  136. bool m_bSizeDirty;
  137. };
  138. #endif // VGUI_AVATARIMAGE_H