home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / windows / x / motif / 8219 < prev    next >
Encoding:
Text File  |  1992-12-24  |  4.2 KB  |  142 lines

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!ames!agate!ucbvax!hds.UUCP!hdsrjh
  2. From: hdsrjh@hds.UUCP (Randy Huggins)
  3. Newsgroups: comp.windows.x.motif
  4. Subject: Re: [Q] How to do blinking text in XmLabel and XmText?
  5. Message-ID: <9212232303@hds.COM>
  6. Date: 23 Dec 92 23:03:19 GMT
  7. Sender: daemon@ucbvax.BERKELEY.EDU
  8. Distribution: inet
  9. Organization: Hierarchical Development Systems, Inc.
  10. Lines: 130
  11.  
  12. In <1992Dec15.170029.24003@ninja.csuohio.edu>, Misha writes:
  13.  
  14. >My application requires an alert message to blink on the screen to
  15. >attract operator's attention. I didn't find any support for it
  16. >in the Motif. How are people doing this?
  17.  
  18. After much fiddling and experimentation, I use a timer with a twist
  19. to achieve a blinking effect.  
  20.  
  21. I allocate additional colorcells, one for each foreground color I 
  22. wish to blink.  Each cell is initially set to the RGB values for that color.
  23.  
  24. Then, when I want an object to blink, I use the Pixel value for the
  25. 'blinking' cell, rather than the Pixel value that would provide the
  26. 'constant' appearance for the same color.
  27.  
  28. Each time the timer pops, I use a simple XStoreColors call to flip
  29. the RGB values of all the blinking colorcells between their 'constant'
  30. color values and the background color value.
  31.  
  32. The thing I like best about this implementation is that it can support
  33. blinking of all types of widgets and graphics objects, and it can blink 
  34. a large number of such objects for the cost of one timer, one 'X' call, 
  35. and a few colormap cells.  It also synchronizes all of your blinking on
  36. all of your application's windows.
  37.  
  38. I suppose this approach's biggest weaknesses shows up if you have a
  39. large number of different colors to blink or are otherwise already in use.
  40. Its also not obvious how much of this technique holds up for mono and
  41. greyscale monitors - the application I built this for runs exclusively
  42. on color monitors.
  43.  
  44. -R
  45.  
  46. ------------------------ Begin included code ---------------------------
  47.  
  48. #define  POSIX
  49.  
  50. #include <string.h>
  51. #include <stdio.h>
  52. #include <sys/types.h>
  53.  
  54. #include <X11/Intrinsic.h>
  55. #include <X11/StringDefs.h>
  56. #include <X11/Xlib.h>
  57. #include <X11/Xutil.h>
  58.  
  59. #include <Xm/Xm.h>
  60.  
  61. extern Display            *display;
  62. extern Screen            *screen;
  63. extern XtAppContext        app;
  64. extern Widget            main_form;
  65.  
  66. extern Colormap            cmap;
  67. extern XColor            gss_RGB[];
  68. extern Pixel            gss_color[];
  69. extern GC                theGC;
  70.  
  71. static void do_blink(toggle, iid, dummy)
  72. int                       toggle;
  73. XtIntervalId           *iid;
  74. caddr_t                   dummy;
  75. {
  76.  
  77. /* alternately 'slam' the eight foreground colors or the background
  78.    color into the eight color cells used for blinking */
  79.  
  80.     XStoreColors(display, cmap, &gss_RGB[ toggle ? 17 : 9 ], 8);
  81.  
  82. /* restart the timer, inverting the 'toggle' argument */
  83.  
  84.     XtAppAddTimeOut(app, 1000, do_blink, (! toggle ) );
  85. }
  86.  
  87. void get_colors()
  88. {
  89.     XWindowAttributes   attrs;
  90.     XGCValues            theGCValues;
  91.     int                    i;
  92.     XColor                real;
  93.     static char            *colornames[] = { "dummy",
  94.                             "white", "blue", "yellow", "turquoise",
  95.                             "green", "pink", "red", "black" };
  96.  
  97. /* this routine must be called after the main window is realized */
  98.  
  99. /* get our colormap, using the main form as the reference window */
  100.  
  101.     XGetWindowAttributes(display, XtWindow(main_form), &attrs);
  102.     cmap = attrs.colormap;
  103.  
  104. /* determine the background color for gss_color[0] */
  105.  
  106.     XtVaGetValues(main_form, XmNbackground, gss_color, NULL);
  107.  
  108.     gss_RGB[0].pixel = gss_color[0];
  109.     XQueryColor(display, cmap, gss_RGB);
  110.     gss_RGB[0].flags = (DoRed | DoGreen | DoBlue);
  111.  
  112. /* acquire 8 normal colorcells, and 8 'blinking' colorcells */
  113.  
  114.     XAllocColorCells(display, cmap, FALSE, &i, 0, &gss_color[1], 16);
  115.  
  116. /* for each colorname, initialize its real, 'blink-foreground' and
  117.    'blink-background' RGB definitions */
  118.  
  119.     for (i=1; i<9; i++)
  120.     {
  121.         XLookupColor(display, cmap, colornames[i], &real, &gss_RGB[i]);
  122.  
  123.         gss_RGB[i].pixel = gss_color[i];
  124.         gss_RGB[i].flags = (DoRed | DoGreen | DoBlue);
  125.  
  126.         memcpy(&gss_RGB[i+8], &gss_RGB[i], sizeof(XColor));
  127.         gss_RGB[i+8].pixel = gss_color[i+8];
  128.         
  129.         memcpy(&gss_RGB[i+16], &gss_RGB[0], sizeof(XColor));
  130.         gss_RGB[i+16].pixel = gss_color[i+8];
  131.     }
  132.  
  133. /* now store the 8 normal and 8 blink-foreground RGB definitions 
  134.    into the colormap */
  135.  
  136.     XStoreColors(display, cmap, &gss_RGB[1], 16);
  137.     
  138. /* start the timer that runs forever that does the blinking */
  139.  
  140.     XtAppAddTimeOut(app, 1000, do_blink, FALSE);
  141. }
  142.