Utils.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /////////////////////////////////////////////////////////////////////////////
  19. //
  20. // Utils.H
  21. //
  22. // Module containing usefull misc. utility functions
  23. //
  24. #ifndef __UTILS_H
  25. #define __UTILS_H
  26. #include "Vector.H"
  27. // Forward declarations
  28. class RenderObjClass;
  29. /////////////////////////////////////////////////////////////////////////////
  30. //
  31. // Macros
  32. //
  33. #define SAFE_DELETE(pobject) \
  34. if (pobject) { \
  35. delete pobject; \
  36. pobject = NULL; \
  37. } \
  38. #define SAFE_DELETE_ARRAY(pobject) \
  39. if (pobject) { \
  40. delete [] pobject; \
  41. pobject = NULL; \
  42. } \
  43. #define SAFE_ADD_REF(pobject) \
  44. if (pobject) { \
  45. pobject->Add_Ref (); \
  46. } \
  47. #define SAFE_RELEASE_REF(pobject) \
  48. if (pobject) { \
  49. pobject->Release_Ref (); \
  50. } \
  51. #define MEMBER_RELEASE(pmember) \
  52. SAFE_RELEASE_REF(pmember); \
  53. pmember = NULL; \
  54. #define MEMBER_ADD(pmember, pnew) \
  55. MEMBER_RELEASE (pmember); \
  56. pmember = pnew; \
  57. SAFE_ADD_REF (pmember); \
  58. #define COM_RELEASE(pobject) \
  59. if (pobject) { \
  60. pobject->Release (); \
  61. } \
  62. pobject = NULL; \
  63. #define SAFE_CLOSE(handle) \
  64. if (handle != INVALID_HANDLE_VALUE) { \
  65. ::CloseHandle (handle); \
  66. handle = INVALID_HANDLE_VALUE; \
  67. } \
  68. #define SANITY_CHECK(expr) \
  69. ASSERT (expr); \
  70. if (!expr)
  71. /////////////////////////////////////////////////////////////////////////////
  72. //
  73. // Inlines
  74. //
  75. /////////////////////////////////////////////////////////////////////////////
  76. __inline void Delimit_Path (LPTSTR path)
  77. {
  78. if (::lstrlen (path) > 0 && path[::lstrlen (path) - 1] != '\\') {
  79. ::lstrcat (path, "\\");
  80. }
  81. return ;
  82. }
  83. __inline void Delimit_Path (CString &path)
  84. {
  85. if (path[::lstrlen (path) - 1] != '\\') {
  86. path += CString ("\\");
  87. }
  88. return ;
  89. }
  90. // Forward declarations
  91. class TextureClass;
  92. class CGraphicView;
  93. /////////////////////////////////////////////////////////////////////////////
  94. //
  95. // Prototypes
  96. //
  97. class CW3DViewDoc * GetCurrentDocument (void);
  98. CGraphicView * Get_Graphic_View (void);
  99. void Paint_Gradient (HWND hWnd, BYTE baseRed, BYTE baseGreen, BYTE baseBlue);
  100. void CenterDialogAroundTreeView (HWND hDlg);
  101. //
  102. // Dialog routines
  103. //
  104. void SetDlgItemFloat (HWND hdlg, UINT child_id, float value);
  105. float GetDlgItemFloat (HWND hdlg, UINT child_id);
  106. void SetWindowFloat (HWND hwnd, float value);
  107. float GetWindowFloat (HWND hwnd);
  108. void Initialize_Spinner (CSpinButtonCtrl &ctrl, float pos = 0, float min = 0, float max = 1);
  109. void Update_Spinner_Buddy (CSpinButtonCtrl &ctrl);
  110. void Update_Spinner_Buddy (HWND hspinner, int delta);
  111. void Enable_Dialog_Controls (HWND dlg,bool onoff);
  112. //
  113. // String manipulation routines
  114. //
  115. CString Get_Filename_From_Path (LPCTSTR path);
  116. CString Strip_Filename_From_Path (LPCTSTR path);
  117. CString Asset_Name_From_Filename (LPCTSTR filename);
  118. CString Filename_From_Asset_Name (LPCTSTR asset_name);
  119. //
  120. // File routines
  121. //
  122. bool Get_File_Time (LPCTSTR path, LPFILETIME pcreation_time, LPFILETIME paccess_time = NULL, LPFILETIME pwrite_time = NULL);
  123. bool Are_Glide_Drivers_Acceptable (void);
  124. bool Copy_File (LPCTSTR existing_filename, LPCTSTR new_filename, bool bforce_copy = false);
  125. //
  126. // Texture routines
  127. //
  128. HBITMAP Make_Bitmap_From_Texture (TextureClass &texture, int width, int height);
  129. CString Get_Texture_Name (TextureClass &texture);
  130. TextureClass * Load_RC_Texture (LPCTSTR resource_name);
  131. void Find_Missing_Textures (DynamicVectorClass<CString> &list, LPCTSTR filename, int frame_count = 1);
  132. // Emitter routines
  133. void Build_Emitter_List (RenderObjClass &render_obj, DynamicVectorClass<CString> &list);
  134. // Identification routines
  135. bool Is_Aggregate (const char *asset_name);
  136. bool Is_Real_LOD (const char *asset_name);
  137. // Prototype routines
  138. void Rename_Aggregate_Prototype (const char *old_name, const char *new_name);
  139. #endif //__UTILS_H