HistogramCtl.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : LevelEdit *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/LevelEdit/HistogramCtl.h $Modtime:: 7/2/99 6:28p $*
  25. * *
  26. * $Revision:: 3 $*
  27. * *
  28. *---------------------------------------------------------------------------------------------*
  29. * Functions: *
  30. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  31. #if defined(_MSC_VER)
  32. #pragma once
  33. #endif
  34. #ifndef __HISTOGRAM_CTL_H
  35. #define __HISTOGRAM_CTL_H
  36. #include "Vector.H"
  37. #include "Vector3.H"
  38. ///////////////////////////////////////////////////////////////////
  39. //
  40. // HistogramCtlClass
  41. //
  42. ///////////////////////////////////////////////////////////////////
  43. class HistogramCtlClass
  44. {
  45. public:
  46. //////////////////////////////////////////////////////////////
  47. // Public constructors/destructors
  48. //////////////////////////////////////////////////////////////
  49. HistogramCtlClass (void);
  50. virtual ~HistogramCtlClass (void);
  51. //////////////////////////////////////////////////////////////
  52. // Public methods
  53. //////////////////////////////////////////////////////////////
  54. void Add_Data_Point (float value);
  55. void Reset_Data_Points (void);
  56. // Selection managment
  57. void Get_Selection (float &range_min, float &range_max);
  58. void Set_Selection (float range_min, float range_max);
  59. void Set_Selection (int min_pixel, int max_pixel);
  60. void Clear_Selection (void);
  61. // Control customization
  62. void Set_X_Axis_Range (float min, float max);
  63. void Set_Y_Axis_Range (float min, float max);
  64. void Set_Dimensions (int width, int height);
  65. void Set_Bk_Color (const Vector3 &low, const Vector3 &high);
  66. void Set_Color (const Vector3 &low, const Vector3 &high);
  67. // Painting methods
  68. bool Is_Dirty (void) const { return m_IsDirty; }
  69. void Set_Dirty (bool dirty = true);
  70. void Allow_Refresh (bool onoff = true);
  71. void Render (HDC hdc, int x_pos, int y_pos);
  72. protected:
  73. //////////////////////////////////////////////////////////////
  74. // Protected methods
  75. //////////////////////////////////////////////////////////////
  76. void Create_DIB_Section (void);
  77. void Destroy_DIB_Section (void);
  78. void Paint_DIB (void);
  79. int Find_Value_Index (float value);
  80. private:
  81. //////////////////////////////////////////////////////////////
  82. // Private data types
  83. //////////////////////////////////////////////////////////////
  84. typedef struct
  85. {
  86. float min;
  87. float max;
  88. } RANGE;
  89. typedef struct _VALUE
  90. {
  91. // Data members
  92. float value;
  93. int count;
  94. // For DynamicVectorClass
  95. _VALUE (void) : value (0), count (0) { }
  96. _VALUE (float _value, DWORD _count) : value (_value), count (_count) { }
  97. bool operator== (const _VALUE &src) { return false; }
  98. bool operator!= (const _VALUE &src) { return true; }
  99. } VALUE;
  100. typedef DynamicVectorClass<VALUE> VALUE_LIST;
  101. //////////////////////////////////////////////////////////////
  102. // Private member data
  103. //////////////////////////////////////////////////////////////
  104. HBITMAP m_hBitmap;
  105. unsigned char *m_pBits;
  106. int m_ScanlineSize;
  107. int m_BMPWidth;
  108. int m_BMPHeight;
  109. bool m_IsDirty;
  110. bool m_AllowRefresh;
  111. Vector3 m_BkLowColor;
  112. Vector3 m_BkHighColor;
  113. Vector3 m_LowColor;
  114. Vector3 m_HighColor;
  115. Vector3 m_SelColor;
  116. Vector3 m_BkSelColor;
  117. RANGE m_XAxis;
  118. RANGE m_YAxis;
  119. RANGE m_Selection;
  120. VALUE_LIST m_ValueList;
  121. };
  122. inline void
  123. HistogramCtlClass::Set_X_Axis_Range (float min, float max)
  124. {
  125. m_XAxis.min = min;
  126. m_XAxis.max = max;
  127. Set_Dirty (true);
  128. return ;
  129. }
  130. inline void
  131. HistogramCtlClass::Set_Y_Axis_Range (float min, float max)
  132. {
  133. m_YAxis.min = min;
  134. m_YAxis.max = max;
  135. Set_Dirty (true);
  136. return ;
  137. }
  138. inline void
  139. HistogramCtlClass::Clear_Selection (void)
  140. {
  141. m_Selection.min = -1;
  142. m_Selection.max = -1;
  143. Set_Dirty (true);
  144. return ;
  145. }
  146. inline void
  147. HistogramCtlClass::Set_Selection (int min_pixel, int max_pixel)
  148. {
  149. float x_range = m_XAxis.max - m_XAxis.min;
  150. //int start_index = Find_Value_Index (m_XAxis.min);
  151. //int end_index = Find_Value_Index (m_XAxis.max);
  152. /*float *x_vector = new float[m_BMPWidth*2];
  153. ::memset (x_vector, 0, sizeof (float) * m_BMPWidth * 2);
  154. if (m_ValueList[)
  155. //
  156. // Loop through all the values and combine pixel-duplicates
  157. //
  158. for (int index = start_index; index <= end_index; index ++) {
  159. VALUE &value = m_ValueList[index];
  160. int x_pos = int((value.value / x_range) * (float)(m_BMPWidth-1));
  161. x_vector[x_pos] = min (x_vector[x_pos], value.value);
  162. x_vector[x_pos*2] = max (x_vector[x_pos*2], value.value);
  163. }
  164. //float value1 = ((float)(min_pixel * x_range) / ((float)m_BMPWidth));
  165. //float value2 = ((float)(max_pixel * x_range) / ((float)m_BMPWidth));
  166. float value1 = x_vector[min_pixel];
  167. float value2 = x_vector[max_pixel*2];
  168. delete [] x_vector;*/
  169. float pixel_range = x_range / (float)m_BMPWidth;
  170. float left = min_pixel * pixel_range;
  171. float right = (max_pixel + 1) * pixel_range;
  172. float value1 = m_XAxis.min + left;
  173. float value2 = m_XAxis.min + right;
  174. m_Selection.min = min (value1, value2);
  175. m_Selection.max = max (value1, value2);
  176. /*if (min_pixel != -1) {
  177. m_Selection.min = min (value1, value2);
  178. }
  179. if (max_pixel != -1) {
  180. m_Selection.max = max (value1, value2);
  181. }*/
  182. /*float real_min = min (value1, value2);
  183. float real_max = max (value1, value2);
  184. m_Selection.min = min (m_Selection.min, real_min);
  185. m_Selection.max = max (m_Selection.max, real_max);*/
  186. Set_Dirty (true);
  187. return ;
  188. }
  189. inline void
  190. HistogramCtlClass::Set_Selection (float min, float max)
  191. {
  192. m_Selection.min = min;
  193. m_Selection.max = max;
  194. Set_Dirty (true);
  195. return ;
  196. }
  197. inline void
  198. HistogramCtlClass::Get_Selection (float &min, float &max)
  199. {
  200. min = m_Selection.min;
  201. max = m_Selection.max;
  202. return ;
  203. }
  204. inline void
  205. HistogramCtlClass::Set_Dirty (bool dirty)
  206. {
  207. m_IsDirty = dirty;
  208. return ;
  209. }
  210. inline void
  211. HistogramCtlClass::Allow_Refresh (bool onoff)
  212. {
  213. m_AllowRefresh = onoff;
  214. return ;
  215. }
  216. #endif //__HISTOGRAM_CTL_H