Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

812 lines
23 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: dialog.cxx
  3. *
  4. * Dialog box functions
  5. *
  6. * Created: 11-16-95 -by- Marc Fortier [marcfo]
  7. *
  8. * Copyright (c) 1995 Microsoft Corporation
  9. \**************************************************************************/
  10. #include "pch.c"
  11. #pragma hdrstop
  12. #include <commdlg.h>
  13. #include <commctrl.h>
  14. #include <scrnsave.h>
  15. #include "mazedlg.h"
  16. #include "sscommon.hxx"
  17. // Global string buffers for message box.
  18. // local funtions
  19. static void updateDialogControls(HWND hDlg);
  20. HWND ghDlg; // main dialog window handle
  21. int giSize;
  22. int giImageQual;
  23. BOOL gbTurboMode;
  24. int gnBitsPerPixel;
  25. static void DrawTexture( int surface );
  26. static void CleanUp( HWND hwnd );
  27. // Texture information for each surface: used in both configure and run mode
  28. TEX_INFO gTexInfo[NUM_SURFACES] = {0};
  29. // default surface texture cache
  30. static TEXTURE gDefTex[NUM_DEF_SURFACE_TEXTURES] = {0};
  31. // Per-surface texture information relevant only to configure mode
  32. typedef struct {
  33. TEXTURE userTex;
  34. int iDefTex;
  35. int defTexIDS;
  36. int fileIDS;
  37. int offsetIDS;
  38. int dlgSpinTexID;
  39. int iPalRot; // texture palette rotation index
  40. SS_TEX_BUTTON *pTexBtn; // GL texture drawing button thing
  41. } TEX_DLG;
  42. static TEX_DLG gTex[NUM_SURFACES] = {
  43. {
  44. {0},
  45. BRICK_TEXTURE,
  46. IDS_DEF_WALL_TEXTURE,
  47. IDS_WALL_TEXTURE_FILE,
  48. IDS_WALL_TEXTURE_OFFSET,
  49. DLG_SPIN_WALLS,
  50. NULL
  51. },
  52. {
  53. {0},
  54. WOOD_TEXTURE,
  55. IDS_DEF_FLOOR_TEXTURE,
  56. IDS_FLOOR_TEXTURE_FILE,
  57. IDS_FLOOR_TEXTURE_OFFSET,
  58. DLG_SPIN_FLOOR,
  59. NULL
  60. },
  61. {
  62. {0},
  63. CASTLE_TEXTURE,
  64. IDS_DEF_CEILING_TEXTURE,
  65. IDS_CEILING_TEXTURE_FILE,
  66. IDS_CEILING_TEXTURE_OFFSET,
  67. DLG_SPIN_CEILING,
  68. NULL
  69. }
  70. };
  71. static UINT idTimer = 0;
  72. static BOOL CALLBACK TextureConfigureDialog(HWND hDlg, UINT message,
  73. WPARAM wParam, LPARAM lParam);
  74. /******************************Public*Routine******************************\
  75. * getIniSettings
  76. *
  77. * - Get the screen saver configuration options from .INI file/registry.
  78. * - Called by both dialog box and screen saver
  79. *
  80. * History:
  81. * Nov. 95 [marcfo]
  82. * - Creation
  83. *
  84. \**************************************************************************/
  85. void
  86. getIniSettings()
  87. {
  88. int option;
  89. int i;
  90. // Load resources
  91. LoadString(hMainInstance, IDS_GENNAME, szScreenSaver,
  92. sizeof(szScreenSaver) / sizeof(TCHAR));
  93. // Get registry settings
  94. if( ss_RegistrySetup( hMainInstance, IDS_SAVERNAME, IDS_INIFILE ) )
  95. {
  96. // get wall/floor/ceiling texture enables
  97. // For now, texturing always on
  98. for( i = 0; i < NUM_SURFACES; i++ )
  99. gTexInfo[i].bTex = TRUE;
  100. option = ss_GetRegistryInt( IDS_DEFAULT_TEXTURE_ENABLE, (1 << NUM_SURFACES)-1 );
  101. for( i = 0; i < NUM_SURFACES; i++, option >>= 1 )
  102. gTexInfo[i].bDefTex = option & 1;
  103. // get default texture indices
  104. for( i = 0; i < NUM_SURFACES; i++ ) {
  105. gTexInfo[i].iDefTex =
  106. ss_GetRegistryInt( gTex[i].defTexIDS, gTex[i].iDefTex );
  107. SS_CLAMP_TO_RANGE2( gTexInfo[i].iDefTex, 0,
  108. NUM_DEF_SURFACE_TEXTURES-1 );
  109. }
  110. // get user texture files
  111. for( i = 0; i < NUM_SURFACES; i++ ) {
  112. ss_GetRegistryString( gTex[i].fileIDS, 0,
  113. gTexInfo[i].texFile.szPathName, MAX_PATH);
  114. gTexInfo[i].texFile.nOffset = ss_GetRegistryInt( gTex[i].offsetIDS, 0 );
  115. }
  116. // get overlay
  117. maze_options.top_view = ss_GetRegistryInt( IDS_OVERLAY, 0 );
  118. // Get rat population
  119. maze_options.nrats = ss_GetRegistryInt(IDS_NRATS, 1);
  120. // get image quality
  121. giImageQual = ss_GetRegistryInt( IDS_IMAGEQUAL, IMAGEQUAL_DEFAULT );
  122. SS_CLAMP_TO_RANGE2( giImageQual, IMAGEQUAL_DEFAULT, IMAGEQUAL_HIGH );
  123. // get size
  124. giSize = ss_GetRegistryInt( IDS_SIZE, 0 );
  125. SS_CLAMP_TO_RANGE2( giSize, MIN_SLIDER, MAX_SLIDER );
  126. // get turbo mode
  127. gbTurboMode = ss_GetRegistryInt( IDS_TURBOMODE, 1 );
  128. }
  129. }
  130. /******************************Public*Routine******************************\
  131. * saveIniSettings
  132. *
  133. * Save the screen saver configuration option to the .INI file/registry.
  134. *
  135. * History:
  136. * Nov. 95 [marcfo]
  137. * - Creation
  138. \**************************************************************************/
  139. static void
  140. saveIniSettings(HWND hDlg)
  141. {
  142. if( ss_RegistrySetup( hMainInstance, IDS_SAVERNAME, IDS_INIFILE ) )
  143. {
  144. int i, option = 0;
  145. // write enables
  146. for( i = NUM_SURFACES-1, option = 0; i >= 0; i--, option <<= 1 )
  147. option |= gTexInfo[i].bDefTex & 1;
  148. ss_WriteRegistryInt( IDS_DEFAULT_TEXTURE_ENABLE, option >>= 1 );
  149. // Write default texture indices
  150. for( i = 0; i < NUM_SURFACES; i++ ) {
  151. ss_WriteRegistryInt( gTex[i].defTexIDS, gTexInfo[i].iDefTex );
  152. }
  153. // write user texture files
  154. for( i = 0; i < NUM_SURFACES; i++ ) {
  155. ss_WriteRegistryString( gTex[i].fileIDS,
  156. gTexInfo[i].texFile.szPathName );
  157. ss_WriteRegistryInt( gTex[i].offsetIDS, gTexInfo[i].texFile.nOffset);
  158. }
  159. // write size
  160. ss_WriteRegistryInt( IDS_SIZE,
  161. ss_GetTrackbarPos(hDlg, DLG_SLIDER_SIZE) );
  162. // write overlay enable
  163. ss_WriteRegistryInt( IDS_OVERLAY, maze_options.top_view );
  164. // Write rat population
  165. ss_WriteRegistryInt( IDS_NRATS, maze_options.nrats );
  166. // write image quality
  167. ss_WriteRegistryInt( IDS_IMAGEQUAL, giImageQual );
  168. // turbot mod
  169. ss_WriteRegistryInt( IDS_TURBOMODE, gbTurboMode );
  170. }
  171. }
  172. /******************************Public*Routine******************************\
  173. * setupDialogControls
  174. *
  175. * Do initial setup of dialog controls.
  176. *
  177. * History:
  178. * Nov. 95 [marcfo]
  179. * - Creation
  180. \**************************************************************************/
  181. static void
  182. setupDialogControls(HWND hDlg)
  183. {
  184. int i;
  185. int idsImageQual;
  186. TCHAR szStr[GEN_STRING_SIZE];
  187. InitCommonControls();
  188. // setup size slider
  189. ss_SetupTrackbar( hDlg, DLG_SLIDER_SIZE, MIN_SLIDER, MAX_SLIDER, 1, 9,
  190. giSize );
  191. // setup default texture spins
  192. for( i = 0; i < NUM_SURFACES; i ++ ) {
  193. SendDlgItemMessage( hDlg, gTex[i].dlgSpinTexID, UDM_SETRANGE, 0,
  194. MAKELONG(NUM_DEF_SURFACE_TEXTURES-1, 0) );
  195. SendDlgItemMessage( hDlg, gTex[i].dlgSpinTexID, UDM_SETPOS, 0,
  196. MAKELONG(gTexInfo[i].iDefTex, 0) );
  197. }
  198. // setup image quality combo box
  199. idsImageQual = IDS_IMAGEQUAL_DEFAULT;
  200. for( i = 0; i < IMAGEQUAL_COUNT; i++, idsImageQual++ ) {
  201. LoadString(hMainInstance, idsImageQual, szStr,
  202. GEN_STRING_SIZE);
  203. SendDlgItemMessage(hDlg, DLG_COMBO_IMAGEQUAL, CB_ADDSTRING, 0,
  204. (LPARAM) szStr);
  205. }
  206. SendDlgItemMessage(hDlg, DLG_COMBO_IMAGEQUAL, CB_SETCURSEL,
  207. giImageQual, 0);
  208. // Disable Quality box when running on > 16 bits per pixel (since it only
  209. // affects dithering)
  210. gnBitsPerPixel = GetDeviceCaps( GetDC(hDlg), BITSPIXEL );
  211. EnableWindow( GetDlgItem(hDlg, DLG_COMBO_IMAGEQUAL), gnBitsPerPixel <= 16 );
  212. EnableWindow( GetDlgItem(hDlg, IDC_STATIC_IMAGEQUAL), gnBitsPerPixel <= 16 );
  213. // set palette rotation index for each surface for a8 textures
  214. for( i = 0; i < NUM_SURFACES; i ++ )
  215. gTex[i].iPalRot = ss_iRand(0xff);
  216. // set state of other controls
  217. CheckDlgButton(hDlg, DLG_CHECK_OVERLAY, maze_options.top_view );
  218. CheckDlgButton(hDlg, DLG_CHECK_TURBOMODE, gbTurboMode );
  219. updateDialogControls(hDlg);
  220. }
  221. /******************************Public*Routine******************************\
  222. * updateDialogControls
  223. *
  224. * Updates dialog controls according to current state
  225. *
  226. * History:
  227. * Nov. 95 [marcfo]
  228. * - Creation
  229. \**************************************************************************/
  230. static void
  231. updateDialogControls(HWND hDlg)
  232. {
  233. int i;
  234. BOOL bDither;
  235. static int dlgSpinTexDef[NUM_SURFACES] = {
  236. DLG_SPIN_WALLS,
  237. DLG_SPIN_FLOOR,
  238. DLG_SPIN_CEILING};
  239. for( i = 0; i < NUM_SURFACES; i ++ ) {
  240. EnableWindow( GetDlgItem(hDlg, gTex[i].dlgSpinTexID), gTexInfo[i].bDefTex );
  241. }
  242. EnableWindow( GetDlgItem(hDlg, DLG_SLIDER_SIZE), !gbTurboMode );
  243. EnableWindow( GetDlgItem(hDlg, IDC_STATIC_SIZE), !gbTurboMode );
  244. EnableWindow( GetDlgItem(hDlg, IDC_STATIC_MIN), !gbTurboMode );
  245. EnableWindow( GetDlgItem(hDlg, IDC_STATIC_MAX), !gbTurboMode );
  246. // Dithering looks bad with turbo mode on and 8 bits/pixel
  247. bDither = (gnBitsPerPixel <= 16) && !gbTurboMode;
  248. EnableWindow( GetDlgItem(hDlg, DLG_COMBO_IMAGEQUAL), bDither );
  249. EnableWindow( GetDlgItem(hDlg, IDC_STATIC_IMAGEQUAL), bDither );
  250. }
  251. /******************************Public*Routine******************************\
  252. * updateGLState
  253. *
  254. \**************************************************************************/
  255. static void
  256. updateGLState()
  257. {
  258. if( (giImageQual == IMAGEQUAL_DEFAULT) || gbTurboMode )
  259. glDisable( GL_DITHER );
  260. else
  261. glEnable( GL_DITHER );
  262. }
  263. /******************************Public*Routine******************************\
  264. * ValidateTexture
  265. *
  266. *
  267. \**************************************************************************/
  268. static TEXTURE *
  269. ValidateTexture( int surface )
  270. {
  271. TEXTURE *pTex = NULL;
  272. TEX_INFO *pTexInfo = &gTexInfo[surface];
  273. extern TEX_RES gTexResSurf[]; // from glmaze.c
  274. if( !pTexInfo->bDefTex ) {
  275. // Try to draw user texture
  276. pTex = &gTex[surface].userTex;
  277. if( !pTex->data ) {
  278. // Load user texture - this can fail!
  279. // If nOffset = 0, we assume user has never specified a texture,
  280. // so we silently switch to the default texture.
  281. // If the load of user texture fails, we use default texture
  282. if( (pTexInfo->texFile.nOffset == 0) ||
  283. (! ss_LoadTextureFile( &pTexInfo->texFile, pTex )) ) {
  284. pTexInfo->bDefTex = TRUE; // draw default texture resource
  285. // Enable the spin control
  286. EnableWindow( GetDlgItem(ghDlg, gTex[surface].dlgSpinTexID),
  287. TRUE );
  288. }
  289. }
  290. }
  291. if( pTexInfo->bDefTex ) {
  292. // Draw default texture resource
  293. pTex = &gDefTex[pTexInfo->iDefTex];
  294. if( !pTex->data ) {
  295. if( !ss_LoadTextureResource( &gTexResSurf[pTexInfo->iDefTex], pTex ))
  296. pTex = NULL;
  297. }
  298. }
  299. return pTex;
  300. }
  301. /******************************Public*Routine******************************\
  302. * DrawTextures
  303. *
  304. * Draw all the textures
  305. *
  306. \**************************************************************************/
  307. static void
  308. DrawTextures()
  309. {
  310. for( int i = 0; i < NUM_SURFACES; i++ ) {
  311. DrawTexture( i );
  312. }
  313. }
  314. /******************************Public*Routine******************************\
  315. * DrawTexture
  316. *
  317. * Draw appropriate texture in supplied window (e.g. a button)
  318. * - Use TEX_INFO state to determine texture
  319. * - Load texture if not in cache
  320. *
  321. \**************************************************************************/
  322. static void
  323. DrawTexture( int surface )
  324. {
  325. TEXTURE *pTex;
  326. // Make sure valid texture loaded for this surface
  327. if( ! (pTex = ValidateTexture( surface )) )
  328. return;
  329. SS_TEX_BUTTON *pTexBtn = gTex[surface].pTexBtn;
  330. // pTexBtn never NULL, else ss_ConfigInit fails
  331. // If palette rotation for this texture, slam in the current rotation,
  332. // to be used by pTexBtn->Draw
  333. if( pTex->pal )
  334. pTex->iPalRot = gTex[surface].iPalRot;
  335. pTexBtn->Draw( pTex );
  336. }
  337. /******************************Public*Routine******************************\
  338. * RegisterDialogClasses
  339. *
  340. \**************************************************************************/
  341. BOOL WINAPI RegisterDialogClasses(HANDLE hinst)
  342. {
  343. return TRUE;
  344. }
  345. /******************************Public*Routine******************************\
  346. * HandlePreviewDraw
  347. *
  348. * History:
  349. * Dec. 95 [marcfo]
  350. * - Creation
  351. \**************************************************************************/
  352. static BOOL
  353. HandlePreviewDraw( UINT idCtl, LPDRAWITEMSTRUCT lpdis )
  354. {
  355. int surface = DLG_PREVIEW_TO_SURFACE( idCtl );
  356. if( lpdis->itemAction == ODA_DRAWENTIRE ) {
  357. DrawTexture( surface );
  358. return TRUE;
  359. }
  360. return FALSE;
  361. }
  362. /******************************Public*Routine******************************\
  363. * HandleTexButtonNewTexture
  364. *
  365. * - Handle when a user selects a new texture
  366. *
  367. * If the new texture fails to load (unlikely, since we validate a good chunk
  368. * of it with the selection dialog), then the current default texture is
  369. * used.
  370. \**************************************************************************/
  371. static void
  372. HandleTexButtonNewTexture( int surface )
  373. {
  374. TEXTURE *pTex = &gTex[surface].userTex;
  375. // Delete the old texture
  376. ss_DeleteTexture( pTex );
  377. // Load up the new texture
  378. if( ! ss_LoadTextureFile( &gTexInfo[surface].texFile, pTex ) )
  379. gTexInfo[surface].bDefTex = TRUE;
  380. }
  381. /******************************Public*Routine******************************\
  382. * MazeDlgTimerProc
  383. *
  384. * Runs off of WM_TIMER message. Used for any gl animation in the dialog
  385. *
  386. * History:
  387. * Jan. 96 [marcfo]
  388. * - Creation
  389. \**************************************************************************/
  390. static void
  391. MazeDlgTimerProc()
  392. {
  393. extern TEX_RES gTexResSurf[]; // from glmaze.c
  394. if( ss_PalettedTextureEnabled() ) {
  395. TEX_INFO *pti = gTexInfo;
  396. int i;
  397. // rotate texture palettes for surfaces with a8 palettes
  398. for( i = 0; i < NUM_SURFACES; i++, pti++ ) {
  399. if( pti->bTex &&
  400. pti->bDefTex &&
  401. ( gTexResSurf[pti->iDefTex].type == TEX_A8 ) )
  402. {
  403. // Increment palette rotation for this surface
  404. gTex[i].iPalRot++;
  405. // Draw texture associated with the surface
  406. DrawTexture( i );
  407. }
  408. }
  409. }
  410. }
  411. /******************************Public*Routine******************************\
  412. * ConfigInit
  413. *
  414. * Do Initialization for Config mode
  415. *
  416. * This is the config equivalent of ss_Init
  417. *
  418. * Setup SS_TEX_BUTTON wrappers for each of the 3 texture preview buttons.
  419. \**************************************************************************/
  420. BOOL
  421. ss_ConfigInit( HWND hDlg )
  422. {
  423. SS_DBGLEVEL1( SS_LEVEL_INFO, "ConfigInit for %d\n", hDlg );
  424. // Create GL texture buttons to draw the surface previews
  425. SS_TEX_BUTTON *pTexBtn;
  426. for( int i = 0; i < NUM_SURFACES; i++ ) {
  427. pTexBtn = new SS_TEX_BUTTON( hDlg,
  428. GetDlgItem(hDlg, DLG_SURFACE_TO_PREVIEW(i)) );
  429. if( !pTexBtn ) {
  430. return FALSE;
  431. }
  432. gTex[i].pTexBtn = pTexBtn;
  433. }
  434. updateGLState();
  435. // Start a timer for animating texture palettes
  436. idTimer = 1;
  437. SetTimer(hDlg, idTimer, 16, 0);
  438. // Note: no textures are loaded here, they are 'demand-loaded'
  439. return TRUE;
  440. }
  441. /******************************Public*Routine******************************\
  442. * ScreenSaverConfigureDialog
  443. *
  444. * Processes messages for the configuration dialog box.
  445. *
  446. * History:
  447. * Nov. 95 [marcfo]
  448. * - Creation
  449. \**************************************************************************/
  450. BOOL ScreenSaverConfigureDialog(HWND hDlg, UINT message,
  451. WPARAM wParam, LPARAM lParam)
  452. {
  453. int wTmp, surface;
  454. static BOOL bInited = 0;
  455. switch (message) {
  456. case WM_INITDIALOG:
  457. getIniSettings();
  458. setupDialogControls(hDlg);
  459. // cache the window handle
  460. ghDlg = hDlg;
  461. return TRUE;
  462. case WM_TIMER:
  463. MazeDlgTimerProc();
  464. return 0;
  465. break;
  466. case WM_DRAWITEM:
  467. switch( (UINT) wParam ) {
  468. case DLG_PREVIEW_WALLS:
  469. case DLG_PREVIEW_FLOOR:
  470. case DLG_PREVIEW_CEILING:
  471. if( HandlePreviewDraw( (UINT) wParam,
  472. (LPDRAWITEMSTRUCT) lParam ) )
  473. return TRUE;
  474. default:
  475. break;
  476. }
  477. break;
  478. case WM_VSCROLL:
  479. switch(LOWORD(wParam))
  480. {
  481. case SB_THUMBPOSITION:
  482. // get new value
  483. wTmp = HIWORD(wParam);
  484. {
  485. int id;
  486. HWND hwndScroll = (HWND) lParam;
  487. id = GetDlgCtrlID( hwndScroll );
  488. surface = DLG_SPIN_TEX_TO_SURFACE( id );
  489. gTexInfo[surface].iDefTex = wTmp;
  490. DrawTexture( surface );
  491. }
  492. break;
  493. default:
  494. break;
  495. }
  496. break;
  497. case WM_COMMAND:
  498. switch (LOWORD(wParam)) {
  499. case DLG_BUTTON_WALLS_TEX:
  500. case DLG_BUTTON_FLOOR_TEX:
  501. case DLG_BUTTON_CEILING_TEX:
  502. surface = DLG_BUTTON_TEX_TO_SURFACE( LOWORD(wParam) );
  503. if( DialogBoxParam(
  504. hMainInstance,
  505. (LPTSTR) MAKEINTRESOURCE( DLG_TEXTURE_CONFIGURE ),
  506. hDlg, (DLGPROC)TextureConfigureDialog, surface ) ) {
  507. //mf: If anything changed here, we have to draw it, as it
  508. // seems when choose texture dialog box terminates, we
  509. // don't get any DRAW_ITEM messages.
  510. // Draw preview area
  511. DrawTexture( surface );
  512. }
  513. break;
  514. case DLG_CHECK_OVERLAY:
  515. maze_options.top_view = !maze_options.top_view;
  516. CheckDlgButton(hDlg, DLG_CHECK_OVERLAY,
  517. maze_options.top_view );
  518. break;
  519. case DLG_CHECK_TURBOMODE:
  520. gbTurboMode = !gbTurboMode;
  521. CheckDlgButton(hDlg, DLG_CHECK_TURBOMODE, gbTurboMode );
  522. updateGLState();
  523. DrawTextures();
  524. break;
  525. case DLG_COMBO_IMAGEQUAL:
  526. switch (HIWORD(wParam))
  527. {
  528. case CBN_EDITCHANGE:
  529. case CBN_SELCHANGE:
  530. {
  531. int oldImageQual = giImageQual;
  532. giImageQual =
  533. (int)SendDlgItemMessage(hDlg, DLG_COMBO_IMAGEQUAL,
  534. CB_GETCURSEL, 0, 0);
  535. if( giImageQual != oldImageQual ) {
  536. // change has occurred - redraw any gl objects
  537. updateGLState();
  538. DrawTextures();
  539. }
  540. }
  541. break;
  542. default:
  543. return FALSE;
  544. }
  545. break;
  546. case IDOK:
  547. saveIniSettings(hDlg);
  548. // fall thru...
  549. case IDCANCEL:
  550. CleanUp( hDlg );
  551. EndDialog(hDlg, FALSE);
  552. break;
  553. default:
  554. return 0;
  555. break;
  556. }
  557. updateDialogControls(hDlg);
  558. return TRUE;
  559. break;
  560. default:
  561. return 0;
  562. }
  563. return 0;
  564. }
  565. /******************************Public*Routine******************************\
  566. * updateTextureConfigControls
  567. *
  568. * Updates dialog controls according to current state
  569. *
  570. * History:
  571. * - Creation
  572. \**************************************************************************/
  573. static void
  574. updateTextureConfigControls(HWND hDlg, BOOL bDefTex )
  575. {
  576. CheckDlgButton(hDlg, IDC_RADIO_TEX_DEFAULT, bDefTex );
  577. CheckDlgButton(hDlg, IDC_RADIO_TEX_CHOOSE, !bDefTex );
  578. EnableWindow(GetDlgItem(hDlg, DLG_BUTTON_TEX_CHOOSE ), !bDefTex );
  579. }
  580. /******************************Public*Routine******************************\
  581. * TextureConfigureDialog
  582. *
  583. * Processes messages for the texture configure dialog box.
  584. *
  585. * - Call EndDialog with TRUE if texture changed, otherwise FALSE
  586. *
  587. * History:
  588. * Dec. 95 [marcfo]
  589. * - Creation
  590. \**************************************************************************/
  591. static BOOL CALLBACK
  592. TextureConfigureDialog(HWND hDlg, UINT message,
  593. WPARAM wParam, LPARAM lParam)
  594. {
  595. // static state ok here, cuz only one of these dialogs can be active
  596. static int surface;
  597. static BOOL bDefTex; // temporary state
  598. switch (message) {
  599. case WM_INITDIALOG:
  600. // Cache some initial values
  601. surface = (int) lParam;
  602. bDefTex = gTexInfo[surface].bDefTex;
  603. updateTextureConfigControls(hDlg, bDefTex );
  604. return TRUE;
  605. case WM_COMMAND:
  606. switch (LOWORD(wParam)) {
  607. case DLG_BUTTON_TEX_CHOOSE:
  608. if( ss_SelectTextureFile( hDlg,
  609. &gTexInfo[surface].texFile ) ) {
  610. // New user texture was selected
  611. HandleTexButtonNewTexture( surface );
  612. // For now, let's end the dialog right here if a
  613. // new one chosen - otherwise we'd have to make the
  614. // new texture discardable if user entered Cancel
  615. gTexInfo[surface].bDefTex = bDefTex;
  616. EndDialog(hDlg, TRUE );
  617. }
  618. break;
  619. case IDC_RADIO_TEX_DEFAULT:
  620. bDefTex = TRUE;
  621. break;
  622. case IDC_RADIO_TEX_CHOOSE:
  623. bDefTex = FALSE;
  624. break;
  625. case IDOK:
  626. // save state
  627. gTexInfo[surface].bDefTex = bDefTex;
  628. EndDialog(hDlg, TRUE);
  629. break;
  630. case IDCANCEL:
  631. EndDialog(hDlg, FALSE);
  632. break;
  633. default:
  634. return 0;
  635. break;
  636. }
  637. updateTextureConfigControls(hDlg, bDefTex );
  638. return TRUE;
  639. break;
  640. default:
  641. return 0;
  642. }
  643. return 0;
  644. }
  645. /******************************Public*Routine******************************\
  646. * CleanUp
  647. *
  648. \**************************************************************************/
  649. static void
  650. CleanUp( HWND hwnd )
  651. {
  652. int i;
  653. if (idTimer) {
  654. KillTimer(hwnd, idTimer);
  655. idTimer = 0;
  656. }
  657. // delete any textures and tex buttons created
  658. for( i = 0; i < NUM_SURFACES; i ++ ) {
  659. if( gTex[i].userTex.data )
  660. ss_DeleteTexture( &gTex[i].userTex );
  661. if( gDefTex[i].data )
  662. ss_DeleteTexture( &gDefTex[i] );
  663. if( gTex[i].pTexBtn )
  664. delete gTex[i].pTexBtn;
  665. }
  666. }