qix.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: qix.c /main/3 1995/11/02 16:08:11 rswiston $ */
  24. /*
  25. */
  26. /* *
  27. * (c) Copyright 1993, 1994 Hewlett-Packard Company *
  28. * (c) Copyright 1993, 1994 International Business Machines Corp. *
  29. * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
  30. * (c) Copyright 1993, 1994 Novell, Inc. *
  31. */
  32. /*-
  33. * qix.c - Vector swirl for dtscreen, the X Window System lockscreen.
  34. *
  35. * Copyright (c) 1991 by Patrick J. Naughton.
  36. *
  37. * See dtscreen.c for copying information.
  38. *
  39. * Revision History:
  40. * 29-Jul-90: support for multiple screens.
  41. * made check_bounds_?() a macro.
  42. * fixed initial parameter setup.
  43. * 15-Dec-89: Fix for proper skipping of {White,Black}Pixel() in colors.
  44. * 08-Oct-89: Fixed bug in memory allocation in initqix().
  45. * Moved seconds() to an extern.
  46. * 23-Sep-89: Switch to random() and fixed bug w/ less than 4 lines.
  47. * 20-Sep-89: Lint.
  48. * 24-Mar-89: Written.
  49. */
  50. #include "dtscreen.h"
  51. #include <stdlib.h>
  52. typedef struct {
  53. int x;
  54. int y;
  55. } point;
  56. typedef struct {
  57. int pix;
  58. long startTime;
  59. int first;
  60. int last;
  61. int dx1;
  62. int dy1;
  63. int dx2;
  64. int dy2;
  65. int x1;
  66. int y1;
  67. int x2;
  68. int y2;
  69. int offset;
  70. int delta;
  71. int width;
  72. int height;
  73. int nlines;
  74. point *lineq;
  75. } qixstruct;
  76. void
  77. initqix(perwindow *pwin)
  78. {
  79. XWindowAttributes xgwa;
  80. qixstruct *qp;
  81. if (pwin->data) free(pwin->data);
  82. pwin->data = (void *)malloc(sizeof(qixstruct));
  83. memset(pwin->data, '\0', sizeof(qixstruct));
  84. qp = (qixstruct *)pwin->data;
  85. qp->startTime = seconds();
  86. qp->nlines = (batchcount + 1) * 2;
  87. qp->lineq = (point *) malloc(qp->nlines * sizeof(point));
  88. memset(qp->lineq, '\0', qp->nlines * sizeof(point));
  89. XGetWindowAttributes(dsp, pwin->w, &xgwa);
  90. qp->width = xgwa.width;
  91. qp->height = xgwa.height;
  92. qp->delta = 16;
  93. if (qp->width < 100) { /* icon window */
  94. qp->nlines /= 4;
  95. qp->delta /= 4;
  96. }
  97. qp->offset = qp->delta / 3;
  98. qp->last = 0;
  99. qp->pix = 0;
  100. qp->dx1 = random() % qp->delta + qp->offset;
  101. qp->dy1 = random() % qp->delta + qp->offset;
  102. qp->dx2 = random() % qp->delta + qp->offset;
  103. qp->dy2 = random() % qp->delta + qp->offset;
  104. qp->x1 = random() % qp->width;
  105. qp->y1 = random() % qp->height;
  106. qp->x2 = random() % qp->width;
  107. qp->y2 = random() % qp->height;
  108. XSetForeground(dsp, pwin->gc, BlackPixelOfScreen(pwin->perscreen->screen));
  109. XFillRectangle(dsp, pwin->w, pwin->gc, 0, 0, qp->width, qp->height);
  110. }
  111. #define check_bounds(qp, val, del, max) \
  112. { \
  113. if ((val) < 0) { \
  114. *(del) = (random() % (qp)->delta) + (qp)->offset; \
  115. } else if ((val) > (max)) { \
  116. *(del) = -(random() % (qp)->delta) - (qp)->offset; \
  117. } \
  118. }
  119. void
  120. drawqix(perwindow *pwin)
  121. {
  122. qixstruct *qp = (qixstruct *)pwin->data;
  123. qp->first = (qp->last + 2) % qp->nlines;
  124. qp->x1 += qp->dx1;
  125. qp->y1 += qp->dy1;
  126. qp->x2 += qp->dx2;
  127. qp->y2 += qp->dy2;
  128. check_bounds(qp, qp->x1, &qp->dx1, qp->width);
  129. check_bounds(qp, qp->y1, &qp->dy1, qp->height);
  130. check_bounds(qp, qp->x2, &qp->dx2, qp->width);
  131. check_bounds(qp, qp->y2, &qp->dy2, qp->height);
  132. XSetForeground(dsp, pwin->gc, BlackPixelOfScreen(pwin->perscreen->screen));
  133. XDrawLine(dsp, pwin->w, pwin->gc,
  134. qp->lineq[qp->first].x, qp->lineq[qp->first].y,
  135. qp->lineq[qp->first + 1].x, qp->lineq[qp->first + 1].y);
  136. if (!mono && pwin->perscreen->npixels > 2) {
  137. XSetForeground(dsp, pwin->gc, pwin->perscreen->pixels[qp->pix]);
  138. if (++qp->pix >= pwin->perscreen->npixels)
  139. qp->pix = 0;
  140. } else
  141. XSetForeground(dsp, pwin->gc, WhitePixelOfScreen(pwin->perscreen->screen));
  142. XDrawLine(dsp, pwin->w, pwin->gc, qp->x1, qp->y1, qp->x2, qp->y2);
  143. qp->lineq[qp->last].x = qp->x1;
  144. qp->lineq[qp->last].y = qp->y1;
  145. qp->last++;
  146. if (qp->last >= qp->nlines)
  147. qp->last = 0;
  148. qp->lineq[qp->last].x = qp->x2;
  149. qp->lineq[qp->last].y = qp->y2;
  150. qp->last++;
  151. if (qp->last >= qp->nlines)
  152. qp->last = 0;
  153. }