GridSettings.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: GridSettings.cpp /////////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Westwood Studios Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2001 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // Project: GUIEdit
  34. //
  35. // File name: GridSettings.cpp
  36. //
  37. // Created: Colin Day, July 2001
  38. //
  39. // Desc: New layout dialog procedure
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  44. #include <windows.h>
  45. // USER INCLUDES //////////////////////////////////////////////////////////////
  46. #include "Lib/BaseType.h"
  47. #include "Resource.h"
  48. #include "EditWindow.h"
  49. #include "GUIEdit.h"
  50. // DEFINES ////////////////////////////////////////////////////////////////////
  51. // PRIVATE TYPES //////////////////////////////////////////////////////////////
  52. ///////////////////////////////////////////////////////////////////////////////
  53. // PRIVATE DATA ///////////////////////////////////////////////////////////////
  54. ///////////////////////////////////////////////////////////////////////////////
  55. static RGBColorInt gridColor = { 0 };
  56. // PUBLIC DATA ////////////////////////////////////////////////////////////////
  57. // PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
  58. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  59. ///////////////////////////////////////////////////////////////////////////////
  60. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  61. ///////////////////////////////////////////////////////////////////////////////
  62. // initGridSettings ===========================================================
  63. /** Initialize the dialog values */
  64. //=============================================================================
  65. static void initGridSettings( HWND hWndDialog )
  66. {
  67. // set resolution
  68. SetDlgItemInt( hWndDialog, EDIT_RESOLUTION,
  69. TheEditor->getGridResolution(), FALSE );
  70. // check box for on/off
  71. if( TheEditor->isGridVisible() == TRUE )
  72. CheckDlgButton( hWndDialog, CHECK_VISIBLE, BST_CHECKED );
  73. // check box for grid snap on/off
  74. if( TheEditor->isGridSnapOn() == TRUE )
  75. CheckDlgButton( hWndDialog, CHECK_SNAP_TO_GRID, BST_CHECKED );
  76. // style
  77. CheckDlgButton( hWndDialog, RADIO_LINES, BST_CHECKED );
  78. // color
  79. RGBColorInt *color = TheEditor->getGridColor();
  80. gridColor = *color;
  81. } // end initGridSettings
  82. // GridSettingsDialogProc =====================================================
  83. /** Dialog procedure for grid settings dialog */
  84. //=============================================================================
  85. BOOL CALLBACK GridSettingsDialogProc( HWND hWndDialog, UINT message,
  86. WPARAM wParam, LPARAM lParam )
  87. {
  88. switch( message )
  89. {
  90. // ------------------------------------------------------------------------
  91. case WM_INITDIALOG:
  92. {
  93. // initialize the values for the the dialog
  94. initGridSettings( hWndDialog );
  95. return TRUE;
  96. } // end init dialog
  97. // ------------------------------------------------------------------------
  98. case WM_DRAWITEM:
  99. {
  100. UINT controlID = (UINT)wParam; // control identifier
  101. LPDRAWITEMSTRUCT drawItem = (LPDRAWITEMSTRUCT)lParam; // item drawing
  102. RGBColorInt *color = &gridColor;
  103. // we only care about color button controls
  104. if( color )
  105. {
  106. HBRUSH hBrushNew, hBrushOld;
  107. RECT rect;
  108. HWND hWndControl = GetDlgItem( hWndDialog, controlID );
  109. // if this control is disabled just let windows handle drawing
  110. if( IsWindowEnabled( hWndControl ) == FALSE )
  111. return FALSE;
  112. // Get the area we have to draw in
  113. GetClientRect( hWndControl, &rect );
  114. // create a new brush and select it into DC
  115. hBrushNew = CreateSolidBrush (RGB ((BYTE)color->red,
  116. (BYTE)color->green,
  117. (BYTE)color->blue));
  118. hBrushOld = (HBRUSH)SelectObject( drawItem->hDC, hBrushNew );
  119. // draw the rectangle
  120. Rectangle( drawItem->hDC, rect.left, rect.top, rect.right, rect.bottom );
  121. // put the old brush back and delete the new one
  122. SelectObject( drawItem->hDC, hBrushOld );
  123. DeleteObject( hBrushNew );
  124. // validate this new area
  125. ValidateRect( hWndControl, NULL );
  126. // we have taken care of it
  127. return TRUE;
  128. } // end if
  129. return FALSE;
  130. } // end draw item
  131. // ------------------------------------------------------------------------
  132. case WM_COMMAND:
  133. {
  134. // Int notifyCode = HIWORD( wParam ); // notification code
  135. // Int controlID = LOWORD( wParam ); // control ID
  136. HWND hWndControl = (HWND)lParam; // control window handle
  137. switch( LOWORD( wParam ) )
  138. {
  139. // --------------------------------------------------------------------
  140. case BUTTON_COLOR:
  141. {
  142. RGBColorInt *currColor = &gridColor;
  143. // bring up color selector for this color control at the mouse
  144. if( currColor )
  145. {
  146. RGBColorInt *newColor;
  147. POINT mouse;
  148. GetCursorPos( &mouse );
  149. newColor = SelectColor( currColor->red, currColor->green,
  150. currColor->blue, currColor->alpha,
  151. mouse.x, mouse.y );
  152. if( newColor )
  153. {
  154. gridColor = *newColor;
  155. InvalidateRect( hWndControl, NULL, TRUE );
  156. } // end if
  157. } // end if
  158. break;
  159. } // end color buttons
  160. // --------------------------------------------------------------------
  161. case IDOK:
  162. {
  163. Int value;
  164. // get the pixels between marks
  165. value = GetDlgItemInt( hWndDialog, EDIT_RESOLUTION, NULL, FALSE );
  166. TheEditor->setGridResolution( value );
  167. // get grid on/off flag
  168. value = IsDlgButtonChecked( hWndDialog, CHECK_VISIBLE );
  169. TheEditor->setGridVisible( value );
  170. // get snap on/off flag
  171. value = IsDlgButtonChecked( hWndDialog, CHECK_SNAP_TO_GRID );
  172. TheEditor->setGridSnap( value );
  173. // grid color
  174. TheEditor->setGridColor( &gridColor );
  175. // end this dialog
  176. EndDialog( hWndDialog, TRUE );
  177. break;
  178. } // end ok
  179. // --------------------------------------------------------------------
  180. case IDCANCEL:
  181. {
  182. EndDialog( hWndDialog, FALSE );
  183. break;
  184. } // end cancel
  185. } // end switch( LOWORD( wParam ) )
  186. return 0;
  187. } // end of WM_COMMAND
  188. // ------------------------------------------------------------------------
  189. case WM_CLOSE:
  190. {
  191. EndDialog( hWndDialog, FALSE );
  192. return 0;
  193. } // end close
  194. // ------------------------------------------------------------------------
  195. default:
  196. return 0;
  197. } // end of switch
  198. } // end GridSettingsDialogProc