BusyPixmap.C 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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: BusyPixmap.C /main/3 1996/04/21 19:32:02 drk $ */
  24. /*
  25. *+SNOTICE
  26. *
  27. * RESTRICTED CONFIDENTIAL INFORMATION:
  28. *
  29. * The information in this document is subject to special
  30. * restrictions in a confidential disclosure agreement bertween
  31. * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
  32. * document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
  33. * Sun's specific written approval. This documment and all copies
  34. * and derivative works thereof must be returned or destroyed at
  35. * Sun's request.
  36. *
  37. * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
  38. *
  39. *+ENOTICE
  40. */
  41. ///////////////////////////////////////////////////////////////////////////////
  42. //////////////////////////////////////////////////////////////////////////////
  43. // This example code is from the book:
  44. //
  45. // Object-Oriented Programming with C++ and OSF/Motif
  46. // by
  47. // Douglas Young
  48. // Prentice Hall, 1992
  49. // ISBN 0-13-630252-1
  50. //
  51. // Copyright 1991 by Prentice Hall
  52. // All Rights Reserved
  53. //
  54. // Permission to use, copy, modify, and distribute this software for
  55. // any purpose except publication and without fee is hereby granted, provided
  56. // that the above copyright notice appear in all copies of the software.
  57. ///////////////////////////////////////////////////////////////////////////////
  58. //////////////////////////////////////////////////////////////////////////////
  59. ///////////////////////////////////////////////////
  60. // BusyPixmap.C
  61. ///////////////////////////////////////////////////
  62. #include "BusyPixmap.h"
  63. #include <Xm/Xm.h>
  64. #define NUMPIXMAPS 8
  65. #define PIXMAPSIZE 50
  66. BusyPixmap::BusyPixmap ( Widget w ) :
  67. PixmapCycler ( NUMPIXMAPS, PIXMAPSIZE, PIXMAPSIZE ),
  68. _gc(NULL),
  69. _inverseGC(NULL)
  70. {
  71. _w = w;
  72. }
  73. void BusyPixmap::createPixmaps()
  74. {
  75. int angle, delta, i;
  76. XGCValues gcv;
  77. // Create a graphics context used to draw each pixmap,
  78. // based on the colors of the given widget
  79. XtVaGetValues ( _w,
  80. XmNforeground, &gcv.foreground,
  81. XmNbackground, &gcv.background,
  82. NULL );
  83. _gc = XtGetGC ( _w, GCForeground | GCBackground, &gcv );
  84. // Create a second GC used to fill the pixmap with
  85. // the background color of the widget
  86. XtVaGetValues ( _w,
  87. XmNforeground, &gcv.background,
  88. XmNbackground, &gcv.foreground,
  89. NULL );
  90. _inverseGC = XtGetGC ( _w, GCForeground | GCBackground, &gcv );
  91. // Define the starting increment, and a slice of the pie.
  92. // The size of the pie slice depends on the number of pixmaps
  93. // to be created.
  94. angle = 360;
  95. delta = 360 / NUMPIXMAPS;
  96. for ( i = 0; i < NUMPIXMAPS; i++)
  97. {
  98. // Create a pixmap for each slice of the pie. X measures
  99. // counterclockwise, so subtract the size of each slice
  100. // so the sequence moves clockwise.
  101. _pixmapList[i] = createBusyPixmap ( angle, delta );
  102. angle -= delta;
  103. }
  104. // Release the GCs after all pixmaps have been created
  105. XtReleaseGC ( _w, _gc );
  106. XtReleaseGC ( _w, _inverseGC );
  107. }
  108. Pixmap BusyPixmap::createBusyPixmap ( int start,
  109. int end )
  110. {
  111. Pixmap pm;
  112. const int margin = 1;
  113. // Create a pixmap. Use the root window used by the widget,
  114. // because the widget may not be realized, or may be a gadget
  115. pm = XCreatePixmap ( XtDisplay ( _w ),
  116. RootWindowOfScreen ( XtScreen ( _w ) ),
  117. _width, _height,
  118. DefaultDepthOfScreen ( XtScreen ( _w ) ) );
  119. // Pixmaps have to be cleared by filling them with a background color
  120. XFillRectangle ( XtDisplay ( _w ),
  121. pm,
  122. _inverseGC,
  123. 0, 0, _width, _height );
  124. // Draw a complete circle just inside the bounds of the pxmap
  125. XDrawArc ( XtDisplay ( _w ),
  126. pm,
  127. _gc,
  128. margin, margin,
  129. _width - 2 * margin,
  130. _height - 2 * margin,
  131. 0, 360 * 64 );
  132. // Draw the pie slice as a solid color
  133. XFillArc ( XtDisplay ( _w ),
  134. pm,
  135. _gc,
  136. margin, margin,
  137. _width - 2 * margin,
  138. _height - 2 * margin,
  139. start * 64, end * 64 );
  140. return pm;
  141. }