Re: DrawingArea and Text display.
- From: Sven Neumann <sven gimp org>
- To: Tony Denault <denault hawaii edu>
- Cc: gtk-list gnome org
- Subject: Re: DrawingArea and Text display.
- Date: 12 Mar 2003 01:46:47 +0100
Hi,
Tony Denault <denault hawaii edu> writes:
> Thanks to all who replied. I'll summaried what I learn for the mailing
> list:
since you post that code here as an example, I'll give some comments
and suggest possible improvements.
> // obtain pango layout object
> context = gtk_widget_create_pango_context (da);
> layout = pango_layout_new (context);
> g_object_unref (context);
as Havoc pointed out, this can be collapsed into
layout = gtk_widget_create_pango_layout (da);
> // Draw some text
> gdk_gc_set_foreground( Nor_gc, &CM.colors[CM_YELLOW] );
> gdk_draw_layout (da->window, Nor_gc, 50, 50, layout);
instead of creating a gc and using the GDK function you can as well
use the widget's style to draw on the widget's window (note that this
is untested code, it might contain errors):
gtk_paint_layout (da->style, da->window, da->state,
FALSE, NULL, da, NULL, x, y, layout);
The rendering function should definitely be in the expose_event
handler of your drawing-area (as any other GDK drawing operation).
Instead of allocating the colors and rendering line by line with
individual layous, you can create a multi-line layout and color it
using a PangoAttributesList. Alternatively to building up such a list,
you can use PangoMarkup:
pango_layout_set_markup (layout,
"<span foreground="yellow">Some text</span>\n"
"<span foreground="green">This is more text</span>\n"
"you get the idea ...",
-1);
Salut, Sven
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]