image.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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: image.c /main/3 1995/11/02 16:07:35 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. * image.c - image bouncer 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: Written.
  41. */
  42. #include "dtscreen.h"
  43. #include "xlogo.bit"
  44. #include <stdlib.h>
  45. static XImage logo = {
  46. 0, 0, /* width, height */
  47. 0, XYBitmap, 0, /* xoffset, format, data */
  48. LSBFirst, 8, /* byte-order, bitmap-unit */
  49. LSBFirst, 8, 1 /* bitmap-bit-order, bitmap-pad, depth */
  50. };
  51. #define MAXICONS 256
  52. typedef struct {
  53. int x;
  54. int y;
  55. } point;
  56. typedef struct {
  57. int width;
  58. int height;
  59. int nrows;
  60. int ncols;
  61. int xb;
  62. int yb;
  63. int iconmode;
  64. int iconcount;
  65. point icons[MAXICONS];
  66. long startTime;
  67. } imagestruct;
  68. void
  69. drawimage(perwindow *pwin)
  70. {
  71. imagestruct *ip;
  72. int i;
  73. ip = (imagestruct *)pwin->data;
  74. XSetForeground(dsp, pwin->gc, BlackPixelOfScreen(pwin->perscreen->screen));
  75. for (i = 0; i < ip->iconcount; i++) {
  76. if (!ip->iconmode)
  77. XFillRectangle(dsp, pwin->w, pwin->gc,
  78. ip->xb + xlogo_width * ip->icons[i].x,
  79. ip->yb + xlogo_height * ip->icons[i].y,
  80. xlogo_width, xlogo_height);
  81. ip->icons[i].x = random() % ip->ncols;
  82. ip->icons[i].y = random() % ip->nrows;
  83. }
  84. if (pwin->perscreen->npixels == 2)
  85. XSetForeground(dsp, pwin->gc, WhitePixelOfScreen(pwin->perscreen->screen));
  86. for (i = 0; i < ip->iconcount; i++) {
  87. if (pwin->perscreen->npixels > 2)
  88. XSetForeground(dsp, pwin->gc,
  89. pwin->perscreen->pixels[random() % pwin->perscreen->npixels]);
  90. XPutImage(dsp, pwin->w, pwin->gc, &logo,
  91. 0, 0,
  92. ip->xb + xlogo_width * ip->icons[i].x,
  93. ip->yb + xlogo_height * ip->icons[i].y,
  94. xlogo_width, xlogo_height);
  95. }
  96. }
  97. void
  98. initimage(perwindow *pwin)
  99. {
  100. XWindowAttributes xgwa;
  101. imagestruct *ip;
  102. if (pwin->data) free(pwin->data);
  103. pwin->data = (void *)malloc(sizeof(imagestruct));
  104. memset(pwin->data, '\0', sizeof(imagestruct));
  105. ip = (imagestruct *)pwin->data;
  106. ip->startTime = seconds();
  107. logo.data = (char *) xlogo_bits;
  108. logo.width = xlogo_width;
  109. logo.height = xlogo_height;
  110. logo.bytes_per_line = (xlogo_width + 7) / 8;
  111. XGetWindowAttributes(dsp, pwin->w, &xgwa);
  112. ip->width = xgwa.width;
  113. ip->height = xgwa.height;
  114. ip->ncols = ip->width / xlogo_width;
  115. ip->nrows = ip->height / xlogo_height;
  116. ip->iconmode = (ip->ncols < 2 || ip->nrows < 2);
  117. if (ip->iconmode) {
  118. ip->xb = 0;
  119. ip->yb = 0;
  120. ip->iconcount = 1; /* icon mode */
  121. } else {
  122. ip->xb = (ip->width - xlogo_width * ip->ncols) / 2;
  123. ip->yb = (ip->height - xlogo_height * ip->nrows) / 2;
  124. ip->iconcount = batchcount;
  125. }
  126. XSetForeground(dsp, pwin->gc, BlackPixelOfScreen(pwin->perscreen->screen));
  127. XFillRectangle(dsp, pwin->w, pwin->gc, 0, 0, ip->width, ip->height);
  128. }