home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!elroy.jpl.nasa.gov!ames!agate!ucbvax!hds.UUCP!hdsrjh
- From: hdsrjh@hds.UUCP (Randy Huggins)
- Newsgroups: comp.windows.x.motif
- Subject: Re: [Q] How to do blinking text in XmLabel and XmText?
- Message-ID: <9212232303@hds.COM>
- Date: 23 Dec 92 23:03:19 GMT
- Sender: daemon@ucbvax.BERKELEY.EDU
- Distribution: inet
- Organization: Hierarchical Development Systems, Inc.
- Lines: 130
-
- In <1992Dec15.170029.24003@ninja.csuohio.edu>, Misha writes:
-
- >My application requires an alert message to blink on the screen to
- >attract operator's attention. I didn't find any support for it
- >in the Motif. How are people doing this?
-
- After much fiddling and experimentation, I use a timer with a twist
- to achieve a blinking effect.
-
- I allocate additional colorcells, one for each foreground color I
- wish to blink. Each cell is initially set to the RGB values for that color.
-
- Then, when I want an object to blink, I use the Pixel value for the
- 'blinking' cell, rather than the Pixel value that would provide the
- 'constant' appearance for the same color.
-
- Each time the timer pops, I use a simple XStoreColors call to flip
- the RGB values of all the blinking colorcells between their 'constant'
- color values and the background color value.
-
- The thing I like best about this implementation is that it can support
- blinking of all types of widgets and graphics objects, and it can blink
- a large number of such objects for the cost of one timer, one 'X' call,
- and a few colormap cells. It also synchronizes all of your blinking on
- all of your application's windows.
-
- I suppose this approach's biggest weaknesses shows up if you have a
- large number of different colors to blink or are otherwise already in use.
- Its also not obvious how much of this technique holds up for mono and
- greyscale monitors - the application I built this for runs exclusively
- on color monitors.
-
- -R
-
- ------------------------ Begin included code ---------------------------
-
- #define POSIX
-
- #include <string.h>
- #include <stdio.h>
- #include <sys/types.h>
-
- #include <X11/Intrinsic.h>
- #include <X11/StringDefs.h>
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
-
- #include <Xm/Xm.h>
-
- extern Display *display;
- extern Screen *screen;
- extern XtAppContext app;
- extern Widget main_form;
-
- extern Colormap cmap;
- extern XColor gss_RGB[];
- extern Pixel gss_color[];
- extern GC theGC;
-
- static void do_blink(toggle, iid, dummy)
- int toggle;
- XtIntervalId *iid;
- caddr_t dummy;
- {
-
- /* alternately 'slam' the eight foreground colors or the background
- color into the eight color cells used for blinking */
-
- XStoreColors(display, cmap, &gss_RGB[ toggle ? 17 : 9 ], 8);
-
- /* restart the timer, inverting the 'toggle' argument */
-
- XtAppAddTimeOut(app, 1000, do_blink, (! toggle ) );
- }
-
- void get_colors()
- {
- XWindowAttributes attrs;
- XGCValues theGCValues;
- int i;
- XColor real;
- static char *colornames[] = { "dummy",
- "white", "blue", "yellow", "turquoise",
- "green", "pink", "red", "black" };
-
- /* this routine must be called after the main window is realized */
-
- /* get our colormap, using the main form as the reference window */
-
- XGetWindowAttributes(display, XtWindow(main_form), &attrs);
- cmap = attrs.colormap;
-
- /* determine the background color for gss_color[0] */
-
- XtVaGetValues(main_form, XmNbackground, gss_color, NULL);
-
- gss_RGB[0].pixel = gss_color[0];
- XQueryColor(display, cmap, gss_RGB);
- gss_RGB[0].flags = (DoRed | DoGreen | DoBlue);
-
- /* acquire 8 normal colorcells, and 8 'blinking' colorcells */
-
- XAllocColorCells(display, cmap, FALSE, &i, 0, &gss_color[1], 16);
-
- /* for each colorname, initialize its real, 'blink-foreground' and
- 'blink-background' RGB definitions */
-
- for (i=1; i<9; i++)
- {
- XLookupColor(display, cmap, colornames[i], &real, &gss_RGB[i]);
-
- gss_RGB[i].pixel = gss_color[i];
- gss_RGB[i].flags = (DoRed | DoGreen | DoBlue);
-
- memcpy(&gss_RGB[i+8], &gss_RGB[i], sizeof(XColor));
- gss_RGB[i+8].pixel = gss_color[i+8];
-
- memcpy(&gss_RGB[i+16], &gss_RGB[0], sizeof(XColor));
- gss_RGB[i+16].pixel = gss_color[i+8];
- }
-
- /* now store the 8 normal and 8 blink-foreground RGB definitions
- into the colormap */
-
- XStoreColors(display, cmap, &gss_RGB[1], 16);
-
- /* start the timer that runs forever that does the blinking */
-
- XtAppAddTimeOut(app, 1000, do_blink, FALSE);
- }
-