how to 'save' and 'recall' colors? - Xwindows
This is a discussion on how to 'save' and 'recall' colors? - Xwindows ; Hello
I fill my rectangle with specified color, but i want to 'save' old color
before filling rectangle with new color, and after filling, restore old
color. How to do it ?
Thanx...
-
how to 'save' and 'recall' colors?
Hello
I fill my rectangle with specified color, but i want to 'save' old color
before filling rectangle with new color, and after filling, restore old
color. How to do it ?
Thanx
-
Re: how to 'save' and 'recall' colors?
In comp.windows.x, vertigo
wrote
on Mon, 24 Nov 2003 15:46:46 +0100
:
> Hello
> I fill my rectangle with specified color, but i want to 'save' old color
> before filling rectangle with new color, and after filling, restore old
> color. How to do it ?
>
> Thanx
>
Your question is slightly unclear. I'm not sure why
you'd want to save the contents of a rectangle (remember
that X is a bitmap-oriented display system, unlike, say,
Display PostScript or (if you're old enough) the old Apollo
DOMAIN Aegis GSR structured graphics system) but if you
want to save such, you can use XGetImage and deal with
the resulting XImage. Once the rectangle is drawn it's
a bunch o' pixels on the screen as far as X is concerned;
the XImage structure is also a bunch o' pixels.
If you are speaking of overlaying your window with some
sort of menu you can try creating and mapping a child
window of your window instead; you'll need to ensure
that your event processing is sophisticated enough to
differentiate between the two windows in that case.
If you want to display a pixmap picture and draw on
it for said menu, another simple method I can think
of is to create a Pixmap of the appropriate depth,
draw on it (rather than a window), and then set the
window's background pixmap, either during the window's
creation or later on using XSetWindowBackgroundPixmap()
or XChangeWindowAttributes(). X should then draw the
background automagically for you; you can scribble on it as
per normal using the usual XDrawLine(),XFillRect(), etc.,
and then erase said scribblings later with XClearArea(),
for a rather neat effect. (Please note that covering the
window with another window will not save the scribblings,
only the background pixmap; of course you can also draw
on the pixmap as well but be advised that the resulting
changes will only show up after the window is forced
to refresh.)
If you're simply referring to the GC foreground/background
color settings, you'll have to cache them somewhere in
local variables or use XGetGCValues (which requires a
round trip to the server and may impede performance).
Note that XFillRectangle uses the *foreground* color,
if you're using solid fill; there are other fill options
such as stipple and tile that you can investigate using
appropriate documentation (on my Debian Linux system I
can say 'man XCreateGC' or 'man XChangeGC', which goes
into quite some detail regarding the GC options in the
XGCValues structure and the associated flags).
--
#191, ewill3@earthlink.net
It's still legal to go .sigless.
-
Re: how to 'save' and 'recall' colors?
vertigo wrote:
> Hello
> I fill my rectangle with specified color, but i want to 'save' old color
> before filling rectangle with new color, and after filling, restore old
> color. How to do it ?
>
> Thanx
If you mean you want to preserve whatever the current GC color is before
filling the rectangle with your new chosen color, which requires you to
change the GC, then you can do it by using XGetGCValues() to get the
current settings for the window's GC.