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.

297 lines
9.0 KiB

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <windows.h>
  4. #include <memory.h>
  5. #include "hugetest.h"
  6. #include "pntlist.h"
  7. #include "primtest.h"
  8. #include "UI_huge.h"
  9. #include "resource.h"
  10. #include "macros.h"
  11. typedef BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
  12. DlgProc PrimativeDlgProc;
  13. extern HINSTANCE hInstance;
  14. PrimativeTest::PrimativeTest()
  15. {
  16. PROPSHEETPAGE pspage;
  17. SetThisType("Primative");
  18. SetThisVersion("1.0");
  19. sprintf(td.acName,"Primatives");
  20. afDrawColor[0] = 1.0;
  21. afDrawColor[1] = 1.0;
  22. afDrawColor[2] = 0.0;
  23. fClr4 = 0.0f,
  24. fClr5 = 1.0f,
  25. fClr6 = 0.0f;
  26. bRotCol = TRUE;
  27. // Zero out property PAGE data
  28. bzero (&pspage, sizeof(pspage)) ;
  29. pspage.dwSize = sizeof(PROPSHEETPAGE);
  30. pspage.dwFlags = PSP_USECALLBACK;
  31. pspage.hInstance = hInstance;
  32. pspage.pszTemplate = MAKEINTRESOURCE (IDD_PRIMATIVES);
  33. pspage.pfnDlgProc = (DLGPROC) PrimativeDlgProc;
  34. pspage.lParam = (LPARAM) aPntLst;
  35. AddPropertyPages(1, &pspage);
  36. }
  37. static PointList prim_pl[NUMBEROFPRIMATIVES];
  38. // optimize this
  39. void PrimativeTest::SaveData()
  40. {
  41. for (int i = 0 ; i < NUMBEROFPRIMATIVES ; i++)
  42. prim_pl[i].Duplicate(&(aPntLst[i]));
  43. parent::SaveData();
  44. }
  45. // optimize this
  46. void PrimativeTest::RestoreSaved()
  47. {
  48. for (int i = 0 ; i < NUMBEROFPRIMATIVES ; i++) {
  49. aPntLst[i].Duplicate(&(prim_pl[i]));
  50. prim_pl[i].ResetPoints();
  51. }
  52. parent::RestoreSaved();
  53. }
  54. // optimize this
  55. void PrimativeTest::ForgetSaved()
  56. {
  57. for (int i = 0 ; i < NUMBEROFPRIMATIVES ; i++)
  58. prim_pl[i].ResetPoints();
  59. parent::ForgetSaved();
  60. }
  61. int PrimativeTest::Save(HANDLE hFile)
  62. {
  63. ulong ul,p;
  64. int i,j;
  65. p = parent::Save(hFile);
  66. if (p < 0) return p;
  67. ul = 0;
  68. for (i = 0 ; i < NUMBEROFPRIMATIVES ; i++) {
  69. ul += j = aPntLst[i].Save(hFile);
  70. if (j == -1) return -1;
  71. }
  72. j = ul;
  73. FlushFileBuffers(hFile);
  74. return j + p;
  75. }
  76. int PrimativeTest::Load(HANDLE hFile)
  77. {
  78. ulong ul,p;
  79. int i,j;
  80. p = parent::Load(hFile);
  81. if (p < 0) return p;
  82. ul = 0;
  83. for (i = 0 ; i < NUMBEROFPRIMATIVES ; i++) {
  84. ul += j = aPntLst[i].Load(hFile);
  85. if (j == -2) return -2;
  86. }
  87. j = ul;
  88. return j + p;
  89. }
  90. void PrimativeTest::IDLEFUNCTION()
  91. {
  92. GLfloat fClr;
  93. if (bRotCol) {
  94. fClr = afDrawColor[0];
  95. afDrawColor[0] = afDrawColor[1];
  96. afDrawColor[1] = afDrawColor[2];
  97. afDrawColor[2] = fClr4;
  98. fClr4 = fClr5;
  99. fClr5 = fClr6;
  100. fClr6 = fClr;
  101. }
  102. }
  103. void PrimativeTest::RENDFUNCTION()
  104. {
  105. static int iType[NUMBEROFPRIMATIVES] = {
  106. GL_POINTS, GL_LINES, GL_POLYGON, GL_TRIANGLES, GL_QUADS, GL_LINE_STRIP,
  107. GL_LINE_LOOP, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUAD_STRIP
  108. };
  109. int i, j;
  110. glClearColor(bd.fClearColor[0],bd.fClearColor[1],
  111. bd.fClearColor[2],bd.fClearColor[3]);
  112. glClear(bd.uiClear);
  113. for (j = 0; j < NUMBEROFPRIMATIVES; j++) {
  114. glBegin(iType[j]); {
  115. glColor3f(afDrawColor[0],afDrawColor[1],afDrawColor[2]);
  116. for (i = 0 ; i < aPntLst[j].iNum ; i++) {
  117. glVertex3f(aPntLst[j].aPoints[i][0],aPntLst[j].aPoints[i][1],
  118. aPntLst[j].aPoints[i][2]);
  119. }
  120. }
  121. glEnd();
  122. }
  123. glFlush();
  124. } // PrimativeTest::RENDFUNCTION()
  125. #ifndef NO_UI_IN_CNFG
  126. BOOL CALLBACK PrimativeDlgProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)
  127. {
  128. static PointList *aPntLst;
  129. static PointList *pPntLst;
  130. char szBuffer[100];
  131. char szBuf1[20],szBuf2[20],szBuf3[20];
  132. int i;
  133. switch (msg)
  134. {
  135. case WM_INITDIALOG:
  136. SetDlgItemInt(hDlg, P_IDC_POINT1, 0, TRUE);
  137. SetDlgItemInt(hDlg, P_IDC_POINT2, 0, TRUE);
  138. SetDlgItemInt(hDlg, P_IDC_POINT3, 0, TRUE);
  139. SendDlgItemMessage(hDlg, IDC_POINTS, BM_SETCHECK, 1, 0);
  140. aPntLst = (PointList*) (((PROPSHEETPAGE*)lParam)->lParam);
  141. pPntLst = aPntLst;
  142. pPntLst->DisplayPointList(hDlg, P_IDC_POINTLIST);
  143. sprintf(szBuffer,"Polygons (%d Points)", pPntLst->QueryNumber());
  144. SetDlgItemText(hDlg, P_IDC_POLY, szBuffer);
  145. return TRUE;
  146. case WM_COMMAND:
  147. {
  148. int iControl, iNote;
  149. GLfloat f1, f2, f3;
  150. iControl = LOWORD(wParam);
  151. iNote = HIWORD(wParam); // notification code for edit boxes
  152. switch (iControl)
  153. {
  154. case P_IDC_POINT1:
  155. case P_IDC_POINT2:
  156. case P_IDC_POINT3:
  157. if (EN_KILLFOCUS == iNote) {
  158. VerifyEditboxFloat(hDlg,iControl);
  159. }
  160. break;
  161. case P_IDC_ADD: // ADD
  162. i =SendDlgItemMessage(hDlg,P_IDC_POINTLIST,LB_GETCURSEL,0,0);
  163. if (i == LB_ERR) i = -1;
  164. GetDlgItemText(hDlg, P_IDC_POINT1, szBuf1, sizeof(szBuf1));
  165. GetDlgItemText(hDlg, P_IDC_POINT2, szBuf2, sizeof(szBuf2));
  166. GetDlgItemText(hDlg, P_IDC_POINT3, szBuf3, sizeof(szBuf3));
  167. f1 = (GLfloat) atof(szBuf1);
  168. f2 = (GLfloat) atof(szBuf2);
  169. f3 = (GLfloat) atof(szBuf3);
  170. sprintf(szBuffer,"(%g, %g, %g)", f1, f2, f3);
  171. SendDlgItemMessage(hDlg,P_IDC_POINTLIST, LB_INSERTSTRING,
  172. i, (LPARAM) szBuffer);
  173. pPntLst->AddPoint(f1,f2,f3);
  174. pPntLst->SwapPoints(-1,i);
  175. sprintf(szBuffer,"Polygons (%d Points)",
  176. pPntLst->QueryNumber());
  177. SetDlgItemText(hDlg, P_IDC_POLY, szBuffer);
  178. PropSheet_Changed(GetParent(hDlg),hDlg);
  179. break; // P_IDC_ADD
  180. case P_IDC_REMOVE:
  181. i =SendDlgItemMessage(hDlg,P_IDC_POINTLIST,LB_GETCURSEL,0,0);
  182. if (i != LB_ERR) {
  183. SendDlgItemMessage(hDlg,P_IDC_POINTLIST,
  184. LB_DELETESTRING,i,0);
  185. pPntLst->RemovePoint(i);
  186. }
  187. sprintf(szBuffer,"Polygons (%d Points)",
  188. pPntLst->QueryNumber());
  189. SetDlgItemText(hDlg, P_IDC_POLY, szBuffer);
  190. PropSheet_Changed(GetParent(hDlg),hDlg);
  191. break; // P_IDC_REMOVE
  192. case P_IDC_MOVEUP:
  193. i =SendDlgItemMessage(hDlg,P_IDC_POINTLIST,LB_GETCURSEL,0,0);
  194. if ((i == LB_ERR) || (i == 0))
  195. break;
  196. SendDlgItemMessage(hDlg, P_IDC_POINTLIST, LB_GETTEXT,
  197. i, (LPARAM)szBuffer);
  198. SendDlgItemMessage(hDlg,P_IDC_POINTLIST,LB_DELETESTRING,i,0);
  199. i--;
  200. SendDlgItemMessage(hDlg, P_IDC_POINTLIST, LB_INSERTSTRING,
  201. i, (LPARAM) szBuffer);
  202. SendDlgItemMessage(hDlg, P_IDC_POINTLIST, LB_SETCURSEL, i,0);
  203. pPntLst->SwapPoints(i,i+1);
  204. PropSheet_Changed(GetParent(hDlg),hDlg);
  205. break; // P_IDC_MOVEUP
  206. case P_IDC_MOVEDOWN:
  207. i =SendDlgItemMessage(hDlg,P_IDC_POINTLIST,LB_GETCURSEL,0,0);
  208. if ((i == LB_ERR) ||
  209. (i==SendDlgItemMessage(hDlg,P_IDC_POINTLIST,
  210. LB_GETCOUNT,0,0)-1))
  211. break;
  212. SendDlgItemMessage(hDlg, P_IDC_POINTLIST, LB_GETTEXT,
  213. i, (LPARAM)szBuffer);
  214. SendDlgItemMessage(hDlg,P_IDC_POINTLIST,LB_DELETESTRING,i,0);
  215. i++;
  216. SendDlgItemMessage(hDlg, P_IDC_POINTLIST, LB_INSERTSTRING,
  217. i, (LPARAM) szBuffer);
  218. SendDlgItemMessage(hDlg, P_IDC_POINTLIST, LB_SETCURSEL, i,0);
  219. pPntLst->SwapPoints(i,i-1);
  220. PropSheet_Changed(GetParent(hDlg),hDlg);
  221. break; // P_IDC_MOVEDOWN
  222. default:
  223. if ((IDC_POINTS <= iControl) &&
  224. (iControl < IDC_POINTS + NUMBEROFPRIMATIVES)) {
  225. i = iControl - IDC_POINTS;
  226. pPntLst = &(aPntLst[i]);
  227. pPntLst->DisplayPointList(hDlg, P_IDC_POINTLIST);
  228. sprintf(szBuffer,"Polygons (%d Points)",
  229. pPntLst->QueryNumber());
  230. SetDlgItemText(hDlg, P_IDC_POLY, szBuffer);
  231. }
  232. break;
  233. }
  234. }
  235. break;
  236. case WM_NOTIFY:
  237. {
  238. LPNMHDR pnmh = (LPNMHDR) lParam;
  239. switch (pnmh->code)
  240. {
  241. case PSN_APPLY: // user clicked on OK or Apply
  242. break;
  243. case PSN_RESET: // user clicked on Cancel
  244. break;
  245. case PSN_HELP: // user clicked help
  246. break;
  247. }
  248. }
  249. break;
  250. default:
  251. return FALSE;
  252. }
  253. return TRUE;
  254. }
  255. #else
  256. #endif // NO_UI_IN_CNFG