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.

161 lines
5.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef PANELANIMATIONVAR_H
  7. #define PANELANIMATIONVAR_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier1/utlvector.h"
  12. #include <vgui_controls/Panel.h>
  13. #define DECLARE_PANELANIMATION( className ) \
  14. static void AddToAnimationMap( char const *scriptname, char const *type, char const *var, \
  15. char const *defaultvalue, bool array, PANELLOOKUPFUNC func ) \
  16. { \
  17. PanelAnimationMap *map = FindOrAddPanelAnimationMap( GetPanelClassName() ); \
  18. \
  19. PanelAnimationMapEntry entry; \
  20. entry.m_pszScriptName = scriptname; \
  21. entry.m_pszVariable = var; \
  22. entry.m_pszType = type; \
  23. entry.m_pszDefaultValue = defaultvalue; \
  24. entry.m_pfnLookup = func; \
  25. entry.m_bArray = array; \
  26. \
  27. map->entries.AddToTail( entry ); \
  28. } \
  29. \
  30. static void ChainToAnimationMap( void ) \
  31. { \
  32. static bool chained = false; \
  33. if ( chained ) \
  34. return; \
  35. chained = true; \
  36. PanelAnimationMap *map = FindOrAddPanelAnimationMap( GetPanelClassName() ); \
  37. map->pfnClassName = GetPanelClassName; \
  38. if ( map && GetPanelBaseClassName() && GetPanelBaseClassName()[0] ) \
  39. { \
  40. map->baseMap = FindOrAddPanelAnimationMap( GetPanelBaseClassName() ); \
  41. } \
  42. } \
  43. \
  44. class className##_Register; \
  45. friend class className##_Register; \
  46. class className##_Register \
  47. { \
  48. public: \
  49. className##_Register() \
  50. { \
  51. className::ChainToAnimationMap(); \
  52. } \
  53. }; \
  54. className##_Register m_RegisterAnimationClass; \
  55. \
  56. virtual PanelAnimationMap *GetAnimMap() \
  57. { \
  58. return FindOrAddPanelAnimationMap( GetPanelClassName() ); \
  59. }
  60. typedef void *( *PANELLOOKUPFUNC )( vgui::Panel *panel );
  61. // Use this macro to define a variable which hudanimations.txt and hudlayout.res scripts can access
  62. #define CPanelAnimationVarAliasType( type, name, scriptname, defaultvalue, typealias ) \
  63. class PanelAnimationVar_##name; \
  64. friend class PanelAnimationVar_##name; \
  65. static void *GetVar_##name( vgui::Panel *panel ) \
  66. { \
  67. return &(( ThisClass *)panel)->name; \
  68. } \
  69. class PanelAnimationVar_##name \
  70. { \
  71. public: \
  72. static void InitVar() \
  73. { \
  74. static bool bAdded = false; \
  75. if ( !bAdded ) \
  76. { \
  77. bAdded = true; \
  78. AddToAnimationMap( scriptname, typealias, #name, defaultvalue, false, ThisClass::GetVar_##name ); \
  79. } \
  80. } \
  81. PanelAnimationVar_##name() \
  82. { \
  83. PanelAnimationVar_##name::InitVar(); \
  84. } \
  85. }; \
  86. PanelAnimationVar_##name m_##name##_register; \
  87. type name;
  88. #define CPanelAnimationVar( type, name, scriptname, defaultvalue ) \
  89. CPanelAnimationVarAliasType( type, name, scriptname, defaultvalue, #type )
  90. // Use this macro to define a variable which hudanimations.txt and hudlayout.res scripts can access
  91. #define CPanelAnimationStringVarAliasType( count, name, scriptname, defaultvalue, typealias ) \
  92. class PanelAnimationVar_##name; \
  93. friend class PanelAnimationVar_##name; \
  94. static void *GetVar_##name( vgui::Panel *panel ) \
  95. { \
  96. return &(( ThisClass *)panel)->name; \
  97. } \
  98. class PanelAnimationVar_##name \
  99. { \
  100. public: \
  101. static void InitVar() \
  102. { \
  103. static bool bAdded = false; \
  104. if ( !bAdded ) \
  105. { \
  106. bAdded = true; \
  107. AddToAnimationMap( scriptname, typealias, #name, defaultvalue, true, ThisClass::GetVar_##name ); \
  108. } \
  109. } \
  110. PanelAnimationVar_##name() \
  111. { \
  112. PanelAnimationVar_##name::InitVar(); \
  113. } \
  114. }; \
  115. PanelAnimationVar_##name m_##name##_register; \
  116. char name[ count ];
  117. #define CPanelAnimationStringVar( count, name, scriptname, defaultvalue ) \
  118. CPanelAnimationStringVarAliasType( count, name, scriptname, defaultvalue, "string" )
  119. struct PanelAnimationMapEntry
  120. {
  121. char const *name() { return m_pszScriptName; }
  122. char const *type() { return m_pszType; }
  123. char const *defaultvalue() { return m_pszDefaultValue; }
  124. bool isarray() { return m_bArray; }
  125. char const *m_pszScriptName;
  126. char const *m_pszVariable;
  127. char const *m_pszType;
  128. char const *m_pszDefaultValue;
  129. bool m_bArray;
  130. PANELLOOKUPFUNC m_pfnLookup;
  131. };
  132. struct PanelAnimationMap
  133. {
  134. PanelAnimationMap()
  135. {
  136. baseMap = NULL;
  137. pfnClassName = NULL;
  138. }
  139. CUtlVector< PanelAnimationMapEntry > entries;
  140. PanelAnimationMap *baseMap;
  141. char const *(*pfnClassName)( void );
  142. };
  143. PanelAnimationMap *FindPanelAnimationMap( char const *className );
  144. PanelAnimationMap *FindOrAddPanelAnimationMap( char const *className );
  145. void PanelAnimationDumpVars( char const *className );
  146. #endif // PANELANIMATIONVAR_H