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.

250 lines
4.1 KiB

  1. #ifdef PM
  2. #include <cstd.h>
  3. #define INCL_WIN
  4. #define INCL_GPI
  5. #include <os2.h>
  6. INT _acrtused = 0;
  7. #endif
  8. #ifdef WIN
  9. #include <windows.h>
  10. #include <port1632.h>
  11. #endif
  12. #include "std.h"
  13. #include "scrsave.h"
  14. typedef LONG CLR;
  15. InitLines();
  16. Animate(CVS hps);
  17. #ifdef WIN
  18. LONG mppenclr [] =
  19. {
  20. RGB(0x00, 0x00, 0x00),
  21. RGB(0x00, 0x00, 0x80),
  22. RGB(0x00, 0x80, 0x00),
  23. RGB(0x00, 0x80, 0x80),
  24. RGB(0x80, 0x00, 0x00),
  25. RGB(0x80, 0x00, 0x80),
  26. RGB(0x80, 0x80, 0x00),
  27. RGB(0x80, 0x80, 0x80),
  28. RGB(0xc0, 0xc0, 0xc0),
  29. RGB(0x00, 0x00, 0xff),
  30. RGB(0x00, 0xff, 0x00),
  31. RGB(0x00, 0xff, 0xff),
  32. RGB(0xff, 0x00, 0x00),
  33. RGB(0xff, 0x00, 0xff),
  34. RGB(0xff, 0xff, 0x00),
  35. RGB(0xff, 0xff, 0xff)
  36. };
  37. #define CLR_BLACK 0
  38. #endif
  39. WORD PenRand();
  40. VOID DrawLine(CVS cvs, INT x1, INT y1, INT x2, INT y2, CLR clr);
  41. INT dxScreen, dyScreen;
  42. CVS cvs;
  43. BOOL EXPENTRY ScrSaveProc(INT ssm, LPVOID l1, LONG_PTR l2, LONG_PTR l3)
  44. {
  45. CHAR FAR * lpsz;
  46. CHAR FAR * lpch;
  47. switch (ssm)
  48. {
  49. default:
  50. return fFalse;
  51. case SSM_OPEN:
  52. lpsz = (PSZ) l1;
  53. lpch = "Dancing Lines";
  54. while ((*lpsz++ = *lpch++) != '\0')
  55. ;
  56. lpsz = (PSZ) l2;
  57. lpch = "Colored line patterns\n\nby Brad Christian";
  58. while ((*lpsz++ = *lpch++) != '\0')
  59. ;
  60. #ifdef PM
  61. dxScreen = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
  62. dyScreen = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  63. #endif
  64. #ifdef WIN
  65. dxScreen = GetSystemMetrics(SM_CXSCREEN);
  66. dyScreen = GetSystemMetrics(SM_CYSCREEN);
  67. #endif
  68. break;
  69. case SSM_BLANK:
  70. InitLines();
  71. return fFalse;
  72. case SSM_ANIMATE:
  73. Animate((CVS) l1);
  74. break;
  75. }
  76. return fTrue;
  77. }
  78. #define ilinMax 10
  79. typedef struct _lin
  80. {
  81. INT x1, y1, x2, y2;
  82. } LIN;
  83. typedef struct _qix
  84. {
  85. INT x, y, x2, y2;
  86. INT dx1, dy1, dx2, dy2;
  87. INT pen;
  88. LIN rglin [ilinMax];
  89. INT ilinCur;
  90. INT cfrCycle;
  91. INT ifrCycle;
  92. } QIX;
  93. #define iqixMax 4
  94. QIX rgqix [iqixMax];
  95. InitLines()
  96. {
  97. QIX * pqix;
  98. INT iqix;
  99. for (iqix = 0; iqix < iqixMax; iqix += 1)
  100. {
  101. pqix = &rgqix[iqix];
  102. pqix->x = WRand(dxScreen);
  103. pqix->y = WRand(dyScreen);
  104. pqix->x2 = WRand(dxScreen);
  105. pqix->y2 = WRand(dyScreen);
  106. pqix->dx1 = 3 * (WRand(20) - 10);
  107. pqix->dy1 = 3 * (WRand(20) - 10);
  108. pqix->dx2 = 3 * (WRand(20) - 10);
  109. pqix->dy2 = 3 * (WRand(20) - 10);
  110. pqix->pen = PenRand();
  111. pqix->cfrCycle = WRand(100) + 1;
  112. pqix->ifrCycle = 0;
  113. pqix->ilinCur = 0;
  114. }
  115. }
  116. Animate(CVS hps)
  117. {
  118. INT ilin;
  119. INT iqix;
  120. PT pt;
  121. QIX * pqix;
  122. for (iqix = 0; iqix < iqixMax; iqix += 1)
  123. {
  124. LIN * plin;
  125. pqix = &rgqix[iqix];
  126. ilin = (pqix->ilinCur + 1) % ilinMax;
  127. plin = &pqix->rglin[ilin];
  128. DrawLine(hps, plin->x1, plin->y1, plin->x2, plin->y2,
  129. CLR_BLACK);
  130. pqix->x += pqix->dx1;
  131. if (pqix->x < 0 || pqix->x >= dxScreen)
  132. {
  133. pqix->dx1 = -pqix->dx1;
  134. pqix->x += 2 * pqix->dx1;
  135. }
  136. pqix->y += pqix->dy1;
  137. if (pqix->y < 0 || pqix->y >= dyScreen)
  138. {
  139. pqix->dy1 = -pqix->dy1;
  140. pqix->y += 2 * pqix->dy1;
  141. }
  142. pqix->x2 += pqix->dx2;
  143. if (pqix->x2 < 0 || pqix->x2 >= dxScreen)
  144. {
  145. pqix->dx2 = -pqix->dx2;
  146. pqix->x2 += 2 * pqix->dx2;
  147. }
  148. pqix->y2 += pqix->dy2;
  149. if (pqix->y2 < 0 || pqix->y2 >= dyScreen)
  150. {
  151. pqix->dy2 = -pqix->dy2;
  152. pqix->y2 += 2 * pqix->dy2;
  153. }
  154. #ifdef PM
  155. DrawLine(hps, pqix->x, pqix->y, pqix->x2, pqix->y2,
  156. pqix->pen);
  157. #endif
  158. #ifdef WIN
  159. DrawLine(hps, pqix->x, pqix->y, pqix->x2, pqix->y2,
  160. mppenclr[pqix->pen]);
  161. #endif
  162. pqix->rglin[pqix->ilinCur].x1 = pqix->x;
  163. pqix->rglin[pqix->ilinCur].y1 = pqix->y;
  164. pqix->rglin[pqix->ilinCur].x2 = pqix->x2;
  165. pqix->rglin[pqix->ilinCur].y2 = pqix->y2;
  166. pqix->ilinCur += 1;
  167. if (pqix->ilinCur == ilinMax)
  168. pqix->ilinCur = 0;
  169. if (++pqix->ifrCycle >= pqix->cfrCycle)
  170. {
  171. pqix->ifrCycle = 0;
  172. pqix->pen += 1;
  173. if (pqix->pen == 16)
  174. pqix->pen = 0;
  175. }
  176. }
  177. }
  178. WORD PenRand()
  179. {
  180. return WRand(16);
  181. }
  182. VOID DrawLine(CVS cvs, INT x1, INT y1, INT x2, INT y2, CLR clr)
  183. {
  184. #ifdef PM
  185. PT pt;
  186. GpiSetColor(cvs, clr);
  187. pt.x = x1;
  188. pt.y = y1;
  189. GpiMove(cvs, &pt);
  190. pt.x = x2;
  191. pt.y = y2;
  192. GpiLine(cvs, &pt);
  193. #endif
  194. #ifdef WIN
  195. HANDLE hPrev;
  196. hPrev = SelectObject(cvs, CreatePen(PS_SOLID, 1, clr));
  197. (VOID)MMoveTo(cvs, x1, y1);
  198. LineTo(cvs, x2, y2);
  199. DeleteObject(SelectObject(cvs, hPrev));
  200. #endif
  201. }