XOR, was : Drawing text into a drawing area with Pango



On Wed, 18 Feb 2004, Peter Krueger wrote:

[snip]

at first you don't need to create a PangoContext yourself. You can create
the layout directly from your drawingarea widget:
PangoLayout *pLayout = gtk_widget_create_pango_layout(drawing_area, 0);

Then set the text and draw it like you did. After you printed your text
free the PangoLayout with g_object_unref(pLayout).

Thanks, that worked like a charm ... but see below.

From your code snipped I guess you forgot to initialize the gc.

I snipped out the initialization of the gc because it was extraneous to
the problem I was having (I think).  It's actually initialized from the
values in the foreground gc of the drawing area.

This solution raises another issue, however, namely XOR-ing the text in
the layout with the background.  My application used gdk_draw_string (now
deprecated) with gtk 1.2, and worked as follows:

- user inputs the text to be drawn

- user presses the left button -> text is xor'd with the background at the
mouse position

- user drags the mouse -> text is xor'd where it came from to erase it,
then xor'd with the background at its new position

- user releases the left button -> text is xor'd where it came from to
erase it, then stamped into the drawing area at its final position

So what you had was a sort of ghosting of the text against the background
as the user dragged the mouse, then it was finally stamped into the
drawing area when the user released the left button.  This let the user
adjust the positioning before committing the text to the drawing area.

The gc has its function set to GDK_XOR for the ghosting, and it's then set
to GDK_COPY for the final stamping into the drawing area.  This worked
fine with gtk 1.2.  With 2.x and the above layout approach, however, the
XOR-ing isn't happening ... the text is being stamped into the background
with the mouse motion, leaving a swath of text all over the drawing area.

Any suggestions for how to do the ghosting with pango?  I thought using
the GDK_XOR function in the gc would do it, but it doesn't seem to.

Thanks,

Bryan


*---------------------------------------------------------------
* Bryan Brown      <*>              bbrown radix net
* http://www.radix.net/~bbrown
*---------------------------------------------------------------




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]