ImagePackerProc.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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. // FILE: ImagePackerProc.cpp //////////////////////////////////////////////////
  19. //-----------------------------------------------------------------------------
  20. //
  21. // Westwood Studios Pacific.
  22. //
  23. // Confidential Information
  24. // Copyright (C) 2001 - All Rights Reserved
  25. //
  26. //-----------------------------------------------------------------------------
  27. //
  28. // Project: ImagePacker
  29. //
  30. // File name: ImagePackerProc.cpp
  31. //
  32. // Created: Colin Day, August 2001
  33. //
  34. // Desc: Window procedure for the image packer app
  35. //
  36. //-----------------------------------------------------------------------------
  37. ///////////////////////////////////////////////////////////////////////////////
  38. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  39. #include <windows.h>
  40. #include <io.h>
  41. // USER INCLUDES //////////////////////////////////////////////////////////////
  42. #include "ImagePacker.h"
  43. #include "Resource.h"
  44. #include "WindowProc.h"
  45. #include "WinMain.h"
  46. // DEFINES ////////////////////////////////////////////////////////////////////
  47. // PRIVATE TYPES //////////////////////////////////////////////////////////////
  48. // PRIVATE DATA ///////////////////////////////////////////////////////////////
  49. // PUBLIC DATA ////////////////////////////////////////////////////////////////
  50. // PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
  51. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  52. ///////////////////////////////////////////////////////////////////////////////
  53. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  54. ///////////////////////////////////////////////////////////////////////////////
  55. // ImagePackerProc ============================================================
  56. /** Dialog procedure for the program flow */
  57. //=============================================================================
  58. BOOL CALLBACK ImagePackerProc( HWND hWndDialog, UINT message,
  59. WPARAM wParam, LPARAM lParam )
  60. {
  61. switch( message )
  62. {
  63. // ------------------------------------------------------------------------
  64. case WM_INITDIALOG:
  65. {
  66. // we must have our program interface to continue
  67. if( TheImagePacker == NULL )
  68. {
  69. MessageBox( NULL, "Internal Error, 'TheImagePacker' not initialized",
  70. "Internal Error", MB_OK );
  71. EndDialog( hWndDialog, FALSE );
  72. } // end if
  73. // save our window handlw
  74. TheImagePacker->setWindowHandle( hWndDialog );
  75. // get size of the screen
  76. Int x, y;
  77. x = GetSystemMetrics( SM_CXFULLSCREEN );
  78. y = GetSystemMetrics( SM_CYFULLSCREEN );
  79. // get size of our dialog
  80. RECT rect;
  81. ICoord2D size;
  82. GetWindowRect( hWndDialog, &rect );
  83. size.x = rect.right - rect.left;
  84. size.y = rect.bottom - rect.top;
  85. // center dialog on screen
  86. MoveWindow( hWndDialog,
  87. (x / 2) - (size.x / 2),
  88. (y / 2) - (size.y / 2),
  89. size.x,
  90. size.y,
  91. TRUE );
  92. // setup the status message
  93. TheImagePacker->statusMessage( "Select options and click 'Start'." );
  94. // set gutter size
  95. SetDlgItemInt( hWndDialog, EDIT_GUTTER, TheImagePacker->getGutter(), FALSE );
  96. // set alpha check
  97. if( TheImagePacker->getOutputAlpha() )
  98. CheckDlgButton( hWndDialog, CHECK_ALPHA, BST_CHECKED );
  99. // set the check for preview using the actual texture
  100. if( TheImagePacker->getUseTexturePreview() )
  101. CheckDlgButton( hWndDialog, CHECK_BITMAP_PREVIEW, BST_CHECKED );
  102. // set the check for creating INI definition
  103. if( TheImagePacker->createINIFile() )
  104. CheckDlgButton( hWndDialog, CHECK_INI, BST_CHECKED );
  105. // check the resursive checkbox by default
  106. CheckDlgButton( hWndDialog, CHECK_USE_SUB_FOLDERS, BST_CHECKED );
  107. // check the default image size radio button
  108. CheckDlgButton( hWndDialog, RADIO_512X512, BST_CHECKED );
  109. // fill out a default target filename
  110. SetDlgItemText( hWndDialog, EDIT_FILENAME, "NewImage" );
  111. // limit the size if the filename edit box
  112. SendDlgItemMessage( hWndDialog, EDIT_FILENAME,
  113. EM_LIMITTEXT, MAX_OUTPUT_FILE_LEN, 0 );
  114. // set options for compressed textures
  115. if( TheImagePacker->getCompressTextures() )
  116. CheckDlgButton( hWndDialog, CHECK_COMPRESS, BST_CHECKED );
  117. // set option checks for gap method
  118. UnsignedInt gapOptions = TheImagePacker->getGapMethod();
  119. if( BitTest( gapOptions, ImagePacker::GAP_METHOD_EXTEND_RGB ) )
  120. CheckDlgButton( hWndDialog, CHECK_GAP_EXTEND_RGB, BST_CHECKED );
  121. if( BitTest( gapOptions, ImagePacker::GAP_METHOD_GUTTER ) )
  122. CheckDlgButton( hWndDialog, CHECK_GAP_GUTTER, BST_CHECKED );
  123. return TRUE;
  124. } // end init dialog
  125. // ------------------------------------------------------------------------
  126. case WM_COMMAND:
  127. {
  128. Int notifyCode = HIWORD( wParam );
  129. Int controlID = LOWORD( wParam );
  130. // HWND hWndControl = (HWND)lParam;
  131. switch( controlID )
  132. {
  133. // --------------------------------------------------------------------
  134. case BUTTON_PREVIOUS:
  135. {
  136. Int page = TheImagePacker->getTargetPreviewPage();
  137. // target preview page back one
  138. if( page > 1 )
  139. {
  140. page--;
  141. TheImagePacker->setTargetPreviewPage( page );
  142. UpdatePreviewWindow();
  143. } // end if
  144. break;
  145. } // end previous
  146. // --------------------------------------------------------------------
  147. case BUTTON_NEXT:
  148. {
  149. UnsignedInt page = TheImagePacker->getTargetPreviewPage();
  150. if( page < TheImagePacker->getPageCount() )
  151. {
  152. page++;
  153. TheImagePacker->setTargetPreviewPage( page );
  154. UpdatePreviewWindow();
  155. } // end if
  156. break;
  157. } // end next
  158. // --------------------------------------------------------------------
  159. case CHECK_BITMAP_PREVIEW:
  160. {
  161. Bool useBitmap;
  162. if( IsDlgButtonChecked( hWndDialog, controlID ) == BST_CHECKED )
  163. useBitmap = TRUE;
  164. else
  165. useBitmap = FALSE;
  166. TheImagePacker->setUseTexturePreview( useBitmap );
  167. UpdatePreviewWindow();
  168. break;
  169. } // end preview using image
  170. // --------------------------------------------------------------------
  171. case CHECK_GAP_GUTTER:
  172. {
  173. Bool enable = FALSE;
  174. if( IsDlgButtonChecked( hWndDialog, controlID ) == BST_CHECKED )
  175. enable = TRUE;
  176. EnableWindow( GetDlgItem( hWndDialog, STATIC_GAP_INFO ), enable );
  177. EnableWindow( GetDlgItem( hWndDialog, EDIT_GUTTER ), enable );
  178. break;
  179. } // end transparent gutter
  180. // --------------------------------------------------------------------
  181. case BUTTON_PREVIEW:
  182. {
  183. HWND preview = TheImagePacker->getPreviewWindow();
  184. if( preview )
  185. {
  186. // delete test display window
  187. DestroyWindow( preview );
  188. TheImagePacker->setPreviewWindow( NULL );
  189. SetDlgItemText( hWndDialog, BUTTON_PREVIEW, "Open Preview" );
  190. } // end if
  191. else
  192. {
  193. HWND preview = MakePreviewDisplay();
  194. if( preview )
  195. {
  196. TheImagePacker->setPreviewWindow( preview );
  197. UpdatePreviewWindow();
  198. SetDlgItemText( hWndDialog, BUTTON_PREVIEW, "Close Preview" );
  199. } // end if
  200. } // end else
  201. break;
  202. } // end test
  203. // --------------------------------------------------------------------
  204. case BUTTON_ADD_FOLDER:
  205. {
  206. // bring up the add directory dialog
  207. DialogBox( ApplicationHInstance,
  208. (LPCTSTR)DIRECTORY_SELECT_DIALOG,
  209. TheImagePacker->getWindowHandle(),
  210. (DLGPROC)DirectorySelectProc );
  211. break;
  212. } // end add folder
  213. // --------------------------------------------------------------------
  214. case BUTTON_REMOVE_FOLDER:
  215. {
  216. HWND folderList;
  217. // get the directory listbox
  218. folderList = GetDlgItem( hWndDialog, LIST_FOLDERS );
  219. if( folderList == NULL )
  220. break;;
  221. // get the selected item in the folder listbox
  222. Int selCount;
  223. selCount = SendMessage( folderList, LB_GETSELCOUNT, 0, 0 );
  224. if( selCount == 0 )
  225. {
  226. MessageBox( NULL, "You must first select a folder to remove it",
  227. "Select Folder First", MB_OK | MB_ICONINFORMATION );
  228. break;
  229. } // end if
  230. //
  231. // start at the end of the listbox, delete any items that
  232. // are selected
  233. //
  234. Int itemCount = SendMessage( folderList, LB_GETCOUNT, 0, 0 );
  235. for( Int i = itemCount - 1; i >= 0; i-- )
  236. if( SendMessage( folderList, LB_GETSEL, i, 0 ) > 0 )
  237. SendMessage( folderList, LB_DELETESTRING, i, 0 );
  238. break;
  239. } // end remove folder
  240. // --------------------------------------------------------------------
  241. case RADIO_128X128:
  242. case RADIO_256X256:
  243. case RADIO_512X512:
  244. case RADIO_TARGET_OTHER:
  245. {
  246. Bool enable;
  247. //
  248. // if this is the other button, enable the first edit box for
  249. // user size, if not, disable that section of the UI
  250. //
  251. enable = IsDlgButtonChecked( hWndDialog, RADIO_TARGET_OTHER );
  252. EnableWindow( GetDlgItem( hWndDialog, EDIT_WIDTH ), enable );
  253. EnableWindow( GetDlgItem( hWndDialog, STATIC_X ), enable );
  254. break;
  255. } // end target image size radio buttons
  256. // --------------------------------------------------------------------
  257. case EDIT_WIDTH:
  258. {
  259. switch( notifyCode )
  260. {
  261. // ----------------------------------------------------------------
  262. case EN_UPDATE:
  263. {
  264. char buffer[ 32 ];
  265. //
  266. // the text of the width has changed, since our requirements
  267. // are that the image must be square automatically update
  268. // the height box as well
  269. //
  270. GetDlgItemText( hWndDialog, EDIT_WIDTH, buffer, 32 );
  271. SetDlgItemText( hWndDialog, EDIT_HEIGHT, buffer );
  272. break;
  273. } // end update
  274. } // end switch
  275. break;
  276. } // end user defined width
  277. // --------------------------------------------------------------------
  278. case BUTTON_START:
  279. {
  280. Bool success;
  281. // get all the options from the dialog into the image packer
  282. success = TheImagePacker->getSettingsFromDialog( hWndDialog );
  283. // run the packer if nothing went wrong
  284. if( success )
  285. TheImagePacker->process();
  286. break;
  287. } // end execute
  288. // --------------------------------------------------------------------
  289. case BUTTON_EXIT:
  290. {
  291. // quit the program
  292. EndDialog( hWndDialog, TRUE );
  293. break;
  294. } // end exit
  295. } // end switch
  296. return 0;
  297. } // end command
  298. } // end switch
  299. return 0;
  300. } // end ImagePackerProc