vxldbg.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. ** Command & Conquer Generals(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. /* $Header: /Commando/Code/Tools/max2w3d/vxldbg.cpp 3 10/28/97 6:08p Greg_h $ */
  19. /***********************************************************************************************
  20. *** Confidential - Westwood Studios ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Commando / G 3D Engine *
  24. * *
  25. * $Archive:: /Commando/Code/Tools/max2w3d/vxldbg.cpp $*
  26. * *
  27. * $Author:: Greg_h $*
  28. * *
  29. * $Modtime:: 10/14/97 3:07p $*
  30. * *
  31. * $Revision:: 3 $*
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #include "vxldbg.h"
  37. #include "resource.h"
  38. #include "dllmain.h"
  39. /*
  40. ** Static functions
  41. */
  42. static BOOL CALLBACK _dialog_proc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
  43. static PaletteClass _VoxelPalette;
  44. VoxelDebugWindowClass::VoxelDebugWindowClass(VoxelClass * vxl) :
  45. CurLayer(0),
  46. Bitmap(NULL),
  47. Voxel(vxl),
  48. WindowHWND(0),
  49. ViewportHWND(0),
  50. LayerSpin(NULL)
  51. {
  52. _VoxelPalette[0] = RGBClass(0,0,0);
  53. _VoxelPalette[1] = RGBClass(128,255,128);
  54. }
  55. VoxelDebugWindowClass::~VoxelDebugWindowClass(void)
  56. {
  57. ReleaseISpinner(LayerSpin);
  58. }
  59. void VoxelDebugWindowClass::Display_Window(void)
  60. {
  61. DialogBoxParam
  62. (
  63. AppInstance,
  64. MAKEINTRESOURCE (IDD_VOXEL_DEBUG_DIALOG),
  65. NULL,
  66. (DLGPROC) _dialog_proc,
  67. (LPARAM) this
  68. );
  69. }
  70. bool VoxelDebugWindowClass::Dialog_Proc
  71. (
  72. HWND hWnd,
  73. UINT message,
  74. WPARAM wParam,
  75. LPARAM
  76. )
  77. {
  78. RECT crect;
  79. switch (message ) {
  80. /*******************************************************************
  81. * WM_INITDIALOG
  82. *
  83. * Initialize all of the custom controls for the dialog box
  84. *
  85. *******************************************************************/
  86. case WM_INITDIALOG:
  87. // keep a handle to the window
  88. WindowHWND = hWnd;
  89. // keep a handle to the control that I'm using for the voxel viewport.
  90. ViewportHWND = GetDlgItem(WindowHWND,IDC_VOXEL_VIEWPORT);
  91. // create a DIB that will be drawn on top of the VOXEL_VIEWPORT control.
  92. GetClientRect(ViewportHWND,&crect);
  93. Bitmap = new SimpleDIBClass(ViewportHWND,Voxel->Get_Width(),Voxel->Get_Height(),_VoxelPalette);
  94. // initialize the layer spinner
  95. LayerSpin = SetupIntSpinner
  96. (
  97. hWnd,
  98. IDC_LAYER_SPIN,
  99. IDC_LAYER_EDIT,
  100. 0,
  101. Voxel->Num_Layers(),
  102. 0
  103. );
  104. update_display();
  105. SetCursor(LoadCursor (NULL, IDC_ARROW));
  106. return 1;
  107. /*******************************************************************
  108. * WM_COMMAND
  109. *
  110. *
  111. *******************************************************************/
  112. case WM_COMMAND:
  113. switch (LOWORD(wParam))
  114. {
  115. case IDOK:
  116. // done!
  117. SetCursor(LoadCursor (NULL, IDC_WAIT));
  118. EndDialog(hWnd, 1);
  119. break;
  120. }
  121. return 1;
  122. /*******************************************************************
  123. * CC_SPINNER_CHANGE
  124. *
  125. * Max custom spinner controls
  126. *
  127. *******************************************************************/
  128. case CC_SPINNER_CHANGE:
  129. switch (LOWORD(wParam) )
  130. {
  131. case IDC_LAYER_SPIN:
  132. CurLayer = LayerSpin->GetIVal();
  133. update_display();
  134. break;
  135. }
  136. /*******************************************************************
  137. * WM_PAINT
  138. *
  139. *
  140. *******************************************************************/
  141. case WM_PAINT:
  142. update_display();
  143. GetClientRect(ViewportHWND,&crect);
  144. ValidateRect(ViewportHWND,&crect);
  145. break;
  146. }
  147. return 0;
  148. }
  149. void VoxelDebugWindowClass::update_display(void)
  150. {
  151. int i,j;
  152. /*
  153. ** Bail out if everything isn't right
  154. */
  155. if ((Bitmap == NULL) || (Voxel == NULL)) {
  156. return;
  157. }
  158. /*
  159. ** Update the contents of the DIB based on
  160. ** the contents of the current voxel layer.
  161. */
  162. Bitmap->Clear(0);
  163. for (j=0; j < Voxel->Get_Height(); j++) {
  164. for (i=0; i < Voxel->Get_Width(); i++) {
  165. if (Voxel->Is_Solid(i,j,CurLayer)) {
  166. Bitmap->Set_Pixel(i,j,1);
  167. }
  168. }
  169. }
  170. /*
  171. ** Blit the DIB onto the dialog box.
  172. */
  173. HDC hdcwindow = GetDC(ViewportHWND);
  174. HDC hdcdib = CreateCompatibleDC(hdcwindow);
  175. HBITMAP holdbitmap = (HBITMAP)SelectObject(hdcdib, Bitmap->Get_Handle());
  176. RECT crect;
  177. GetClientRect(ViewportHWND,&crect);
  178. int cx = (crect.right - crect.left) / 2;
  179. int cy = (crect.bottom - crect.top) / 2;
  180. int x0 = 0; //cx - Bitmap->Get_Width();
  181. int y0 = 0; //cy - Bitmap->Get_Height();
  182. int x1 = 2 * Bitmap->Get_Width(); //cx + Bitmap->Get_Width();
  183. int y1 = 2 * Bitmap->Get_Height(); //cy + Bitmap->Get_Height();
  184. // BitBlt(hdcwindow,0,0,Bitmap->Get_Width(),Bitmap->Get_Height(),hdcdib,0,0,SRCCOPY);
  185. StretchBlt( hdcwindow, x0, y0, x1, y1,
  186. hdcdib, 0, 0, Bitmap->Get_Width(), Bitmap->Get_Height(), SRCCOPY);
  187. SelectObject(hdcdib, holdbitmap);
  188. ReleaseDC(WindowHWND, hdcwindow);
  189. DeleteDC(hdcdib);
  190. }
  191. BOOL CALLBACK _dialog_proc
  192. (
  193. HWND hWnd,
  194. UINT message,
  195. WPARAM wParam,
  196. LPARAM lParam
  197. )
  198. {
  199. static VoxelDebugWindowClass * window = NULL;
  200. if (message == WM_INITDIALOG) {
  201. window = (VoxelDebugWindowClass *) lParam;
  202. }
  203. if (window) {
  204. return window->Dialog_Proc(hWnd, message, wParam, lParam);
  205. } else {
  206. return FALSE;
  207. }
  208. }