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.

355 lines
10 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: sspipes.c
  3. *
  4. * Message loop and dialog box for the OpenGL-based 3D Pipes screen saver.
  5. *
  6. * Copyright (c) 1994 Microsoft Corporation
  7. *
  8. \**************************************************************************/
  9. #include <nt.h>
  10. #include <ntrtl.h>
  11. #include <nturtl.h>
  12. #include <windows.h>
  13. #include <commdlg.h>
  14. #include <scrnsave.h>
  15. #include <GL\gl.h>
  16. #include <math.h>
  17. #include <memory.h>
  18. #include <string.h>
  19. #include <stdarg.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <malloc.h>
  23. #include <sys\timeb.h>
  24. #include <time.h>
  25. #include <commctrl.h>
  26. #include "sscommon.h"
  27. #include "sspipes.h"
  28. #include "dlgs.h"
  29. #include "dialog.h"
  30. //#define NEW_TEXTURE 1
  31. BOOL bFlexMode;
  32. BOOL bMultiPipes;
  33. // ulJointType controls the style of the elbows.
  34. ULONG ulJointType = JOINT_ELBOW;
  35. // ulSurfStyle determines whether the pipe surfaces are textured.
  36. ULONG ulSurfStyle = SURFSTYLE_SOLID;
  37. // ulTexQuality control the texture quality.
  38. ULONG ulTexQuality = TEXQUAL_DEFAULT;
  39. // fTesselFact controls the how finely the surface is tesselated. It
  40. // varies from very course (0.0) to very fine (2.0).
  41. float fTesselFact = 1.0f;
  42. // If ulSurfStyle indicates a textured surface, szTexPathname specifies
  43. // the bitmap chosen as the texture.
  44. // Texture file(s)
  45. TEXFILE gTexFile[MAX_TEXTURES] = {0};
  46. int gnTextures = 0;
  47. static void updateDialogControls(HWND hDlg);
  48. /******************************Public*Routine******************************\
  49. * getIniSettings
  50. *
  51. * Get the screen saver configuration options from .INI file/registry.
  52. *
  53. * Apr. 95 [marcfo]
  54. * - Use ss_GetDefaultBmpFile
  55. *
  56. \**************************************************************************/
  57. void
  58. getIniSettings()
  59. {
  60. TCHAR szDefaultBitmap[MAX_PATH];
  61. int tessel;
  62. int idsTexture;
  63. int idsTexOffset;
  64. int i;
  65. // Load resources
  66. LoadString(hMainInstance, IDS_GENNAME, szScreenSaver,
  67. sizeof(szScreenSaver) / sizeof(TCHAR));
  68. // Load resource strings for texture processing
  69. ss_LoadTextureResourceStrings();
  70. // Get registry settings
  71. if( ss_RegistrySetup( hMainInstance, IDS_SAVERNAME, IDS_INIFILE ) )
  72. {
  73. ulJointType = ss_GetRegistryInt( IDS_JOINTTYPE, JOINT_ELBOW );
  74. ulSurfStyle = ss_GetRegistryInt( IDS_SURFSTYLE, SURFSTYLE_SOLID );
  75. ulTexQuality = ss_GetRegistryInt( IDS_TEXQUAL, TEXQUAL_DEFAULT );
  76. tessel = ss_GetRegistryInt( IDS_TESSELATION, 0 );
  77. SS_CLAMP_TO_RANGE2( tessel, 0, 200 );
  78. fTesselFact = (float)tessel / 100.0f;
  79. bFlexMode = ss_GetRegistryInt( IDS_FLEX, 0 );
  80. bMultiPipes = ss_GetRegistryInt( IDS_MULTIPIPES, 0 );
  81. // Get any textures
  82. #ifndef NEW_TEXTURE
  83. // Just get one texture with old registry names
  84. ss_GetRegistryString( IDS_TEXTURE, 0, gTexFile[0].szPathName, MAX_PATH);
  85. gTexFile[0].nOffset = ss_GetRegistryInt( IDS_TEXTURE_FILE_OFFSET, 0 );
  86. gnTextures = 1;
  87. #else
  88. gnTextures = ss_GetRegistryInt( IDS_TEXTURE_COUNT, 0 );
  89. SS_CLAMP_TO_RANGE2( gnTextures, 0, MAX_TEXTURES );
  90. idsTexture = IDS_TEXTURE0;
  91. idsTexOffset = IDS_TEXOFFSET0;
  92. for( i = 0; i < gnTextures; i++, idsTexture++, idsTexOffset++ ) {
  93. ss_GetRegistryString( idsTexture, 0, gTexFile[i].szPathName,
  94. MAX_PATH);
  95. gTexFile[i].nOffset = ss_GetRegistryInt( idsTexOffset, 0 );
  96. }
  97. #endif
  98. }
  99. }
  100. /**************************************************************************\
  101. * ConfigInit
  102. *
  103. \**************************************************************************/
  104. BOOL
  105. ss_ConfigInit( HWND hDlg )
  106. {
  107. return TRUE;
  108. }
  109. /******************************Public*Routine******************************\
  110. * saveIniSettings
  111. *
  112. * Save the screen saver configuration option to the .INI file/registry.
  113. *
  114. \**************************************************************************/
  115. static void saveIniSettings(HWND hDlg)
  116. {
  117. if( ss_RegistrySetup( hMainInstance, IDS_SAVERNAME, IDS_INIFILE ) )
  118. {
  119. int idsTexture;
  120. int idsTexOffset;
  121. int i;
  122. ss_WriteRegistryInt( IDS_JOINTTYPE, ulJointType );
  123. ss_WriteRegistryInt( IDS_SURFSTYLE, ulSurfStyle );
  124. ss_WriteRegistryInt( IDS_TEXQUAL, ulTexQuality );
  125. ss_WriteRegistryInt( IDS_TESSELATION,
  126. ss_GetTrackbarPos(hDlg, DLG_SETUP_TESSEL) );
  127. ss_WriteRegistryInt( IDS_FLEX, bFlexMode );
  128. ss_WriteRegistryInt( IDS_MULTIPIPES, bMultiPipes );
  129. #ifndef NEW_TEXTURE
  130. ss_WriteRegistryString( IDS_TEXTURE, gTexFile[0].szPathName );
  131. ss_WriteRegistryInt( IDS_TEXTURE_FILE_OFFSET, gTexFile[0].nOffset );
  132. #else
  133. idsTexture = IDS_TEXTURE0;
  134. idsTexOffset = IDS_TEXOFFSET0;
  135. for( i = 0; i < gnTextures; i++, idsTexture++, idsTexOffset++ ) {
  136. ss_WriteRegistryString( idsTexture, gTexFile[i].szPathName );
  137. ss_WriteRegistryInt( idsTexOffset, gTexFile[i].nOffset );
  138. }
  139. #endif
  140. }
  141. }
  142. /******************************Public*Routine******************************\
  143. * setupDialogControls
  144. *
  145. * Do initial setup of dialog controls.
  146. *
  147. * History:
  148. * Jan. 95 -by- Marc Fortier [marcfo]
  149. * Wrote it.
  150. \**************************************************************************/
  151. static void
  152. setupDialogControls(HWND hDlg)
  153. {
  154. int pos;
  155. int wTmp;
  156. TCHAR szStr[GEN_STRING_SIZE];
  157. int idsJointType;
  158. InitCommonControls();
  159. pos = (int)(fTesselFact * 100.0f);
  160. ss_SetupTrackbar( hDlg, DLG_SETUP_TESSEL, 0, 200, 1, 10, pos );
  161. // setup jointType combo box
  162. idsJointType = IDS_JOINT_ELBOW;
  163. for (wTmp = 0; wTmp < NUM_JOINTTYPES; wTmp++, idsJointType++) {
  164. LoadString(hMainInstance, idsJointType, szStr,
  165. GEN_STRING_SIZE);
  166. SendDlgItemMessage(hDlg, DLG_COMBO_JOINTTYPE, CB_ADDSTRING, 0,
  167. (LPARAM) szStr);
  168. }
  169. SendDlgItemMessage(hDlg, DLG_COMBO_JOINTTYPE, CB_SETCURSEL,
  170. ulJointType, 0);
  171. updateDialogControls( hDlg );
  172. }
  173. /******************************Public*Routine******************************\
  174. * updateDialogControls
  175. *
  176. * Setup the dialog controls based on the current global state.
  177. *
  178. \**************************************************************************/
  179. static void updateDialogControls(HWND hDlg)
  180. {
  181. BOOL bTexture = (ulSurfStyle == SURFSTYLE_TEX);
  182. CheckDlgButton( hDlg, IDC_RADIO_SOLID, ulSurfStyle == SURFSTYLE_SOLID );
  183. CheckDlgButton( hDlg, IDC_RADIO_TEX , bTexture );
  184. #ifdef NEED_THESE_LATER
  185. CheckDlgButton( hDlg, IDC_RADIO_WIREFRAME, ulSurfStyle == SURFSTYLE_WIREFRAME );
  186. CheckDlgButton( hDlg, IDC_RADIO_TEXQUAL_DEFAULT ,
  187. bTexture && ulTexQuality == TEXQUAL_DEFAULT);
  188. CheckDlgButton( hDlg, IDC_RADIO_TEXQUAL_HIGH,
  189. bTexture && ulTexQuality == TEXQUAL_HIGH);
  190. #endif
  191. CheckDlgButton( hDlg, IDC_RADIO_NORMAL, !bFlexMode);
  192. CheckDlgButton( hDlg, IDC_RADIO_FLEX, bFlexMode);
  193. CheckDlgButton( hDlg, IDC_RADIO_SINGLE_PIPE, !bMultiPipes);
  194. CheckDlgButton( hDlg, IDC_RADIO_MULTIPLE_PIPES, bMultiPipes);
  195. EnableWindow( GetDlgItem(hDlg, DLG_COMBO_JOINTTYPE), !bFlexMode);
  196. EnableWindow( GetDlgItem(hDlg, IDC_STATIC_JOINTTYPE), !bFlexMode);
  197. EnableWindow( GetDlgItem(hDlg, DLG_SETUP_TEXTURE), bTexture );
  198. EnableWindow( GetDlgItem(hDlg, IDC_RADIO_TEXQUAL_DEFAULT), bTexture );
  199. EnableWindow( GetDlgItem(hDlg, IDC_RADIO_TEXQUAL_HIGH), bTexture );
  200. EnableWindow( GetDlgItem(hDlg, IDC_STATIC_TEXQUAL_GRP), bTexture );
  201. EnableWindow(GetDlgItem(hDlg, DLG_SETUP_TESSEL), TRUE);
  202. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_TESS_MIN), TRUE);
  203. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_TESS_MAX), TRUE);
  204. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_TESS_GRP), TRUE);
  205. }
  206. BOOL WINAPI RegisterDialogClasses(HANDLE hinst)
  207. {
  208. return TRUE;
  209. }
  210. /******************************Public*Routine******************************\
  211. * ScreenSaverConfigureDialog
  212. *
  213. * Screen saver setup dialog box procedure.
  214. * Apr. 95 [marcfo]
  215. * - Use ss_SelectTextureFile
  216. *
  217. \**************************************************************************/
  218. BOOL ScreenSaverConfigureDialog(HWND hDlg, UINT message,
  219. WPARAM wParam, LPARAM lParam)
  220. {
  221. int wTmp;
  222. int optMask = 1;
  223. switch (message)
  224. {
  225. case WM_INITDIALOG:
  226. getIniSettings();
  227. setupDialogControls(hDlg);
  228. return TRUE;
  229. case WM_COMMAND:
  230. switch (LOWORD(wParam))
  231. {
  232. case IDC_RADIO_SOLID:
  233. case IDC_RADIO_TEX:
  234. case IDC_RADIO_WIREFRAME:
  235. ulSurfStyle = IDC_TO_SURFSTYLE(LOWORD(wParam));
  236. break;
  237. case IDC_RADIO_TEXQUAL_DEFAULT:
  238. case IDC_RADIO_TEXQUAL_HIGH:
  239. ulTexQuality = IDC_TO_TEXQUAL(LOWORD(wParam));
  240. break;
  241. case IDC_RADIO_NORMAL:
  242. bFlexMode = FALSE;
  243. break;
  244. case IDC_RADIO_FLEX:
  245. bFlexMode = TRUE;
  246. break;
  247. case IDC_RADIO_SINGLE_PIPE:
  248. bMultiPipes = FALSE;
  249. break;
  250. case IDC_RADIO_MULTIPLE_PIPES:
  251. bMultiPipes = TRUE;
  252. break;
  253. case DLG_SETUP_TEXTURE:
  254. // Run choose texture dialog
  255. #if 1
  256. ss_SelectTextureFile( hDlg, &gTexFile[0] );
  257. #else
  258. ss_SelectTextureFile( hDlg, &gTexFile[0] );
  259. // NEW_TEXTURE dialog box
  260. #endif
  261. break;
  262. case DLG_COMBO_JOINTTYPE:
  263. switch (HIWORD(wParam))
  264. {
  265. case CBN_EDITCHANGE:
  266. case CBN_SELCHANGE:
  267. ulJointType =
  268. (ULONG)SendDlgItemMessage(hDlg, DLG_COMBO_JOINTTYPE,
  269. CB_GETCURSEL, 0, 0);
  270. break;
  271. default:
  272. return FALSE;
  273. }
  274. break;
  275. case IDOK:
  276. saveIniSettings(hDlg);
  277. EndDialog(hDlg, TRUE);
  278. break;
  279. case IDCANCEL:
  280. EndDialog(hDlg, FALSE);
  281. break;
  282. default:
  283. break;
  284. }
  285. updateDialogControls(hDlg);
  286. return TRUE;
  287. default:
  288. return 0;
  289. }
  290. return 0;
  291. }