Re: XORing the GC
- From: Tony Denault <denault hawaii edu>
- To: Donald G Plugge <plugge usa net>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: XORing the GC
- Date: Fri, 23 Mar 2001 17:08:35 -1000 (HST)
On Mon, 19 Mar 2001, Donald G Plugge wrote:
I'm testing out Gtk+ on the VMS environment. The source code was
recently ported to VMS and I've been messing around with the example
programs. I took the simple-scribble.c program and modified it to
perform rubberbanding, however I'm having trouble with XORing the
results. I want to eliminate the artifacts that result from simply
negating the old line with the background color and rather flip it back
to whatever it was originally.
I am doing this in my GTK image viewer. I use rubbberbanding to allow the
user to specify a group of pixel by rubberbanding a box. My code looks
like:
1. When creating my application widgetw, I also create an GC used for
the rubbingbanding draw routines. The set_line_attributes make the line 3
pixel wide:
/* Xor gc for all stats box */
if( (Xor_gc = gdk_gc_new(base_window->window)) == NULL )
printf("Error unable to obtain new GC: Xor_gc\n");
gdk_gc_set_function( Xor_gc, GDK_XOR);
gdk_gc_set_line_attributes( Xor_gc, 3, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
2. I have a function that draws an XOR rectangle on a drawing area:
void draw_xor_box_on_canvas( dpinx, x, y, wid, hgt )
int dpinx; /* Identifies canvas to xor on */
int x, y, wid, hgt; /* Draw a box around these pixels */
{
int box_x, box_y, box_wid, box_hgt;
float pixel_wid;
struct dpy_t *dp = &Dpy[dpinx];
/* determine position of upper-left pixel */
pixel_wid = dp->image_zoom > 0 ? dp->image_zoom : 1.0/(1.0+abs(dp->image_zoom));
box_x = ((x - dp->image_offx) * pixel_wid) + 0.5;
box_y = ((y - dp->image_offy) * pixel_wid) + 0.5;
box_wid = wid * pixel_wid;
box_hgt = hgt * pixel_wid;
/* Adjust values so rectangle is draw around the pixels */
box_x--; box_y--; box_wid++; box_hgt++;
/* Draw it */
gdk_gc_set_foreground( Xor_gc, &CM.colors[CM_GREEN] );
gdk_draw_rectangle( dp->data_drawingarea->window, Xor_gc, FALSE, box_x, box_y, box_wid, box_hgt);
}
Notice I gdk_gc_set_foregound color. In 8 bit mode, I don't think it does
anything, but in 32-bit mode black pixel XOR to green. I mostly view
images in grayscale so I the green XOR rubberbanding is nice.
3. When first rendering the image I put the xor box on it:
draw_xor_box_on_canvas( dpinx, x, y, wid, hgt);
4. When application notice the user rubberbanding it erase the old box,
and put a new one on:
draw_xor_box_on_canvas( dpinx, oldx, oldy, oldwid, oldhgt);
draw_xor_box_on_canvas( dpinx, x, y, wid, hgt);
Hope this helps,
Tony
/-----------------------------------------------------------------------------\
| Tony Denault | Internet: denault irtf ifa hawaii edu |
| NASA IRTF, Institute of Astronomy | Phone: (808) 974-4206 |
| 1175 Manono St., Bldg 393 | Fax: (808) 974-4207 |
| Hilo, Hawaii 96720 | |
\-----------------------------------------------------------------------------/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]