Re: Drawing colored text efficiently



Dear Chad,

I'm not gonna pretend that Pango isn't difficult to use from the GTK+
consumer point of view.  But, GDK actually has some functions that
interact with Pango and may reduce the code needed to do the things you
are looking for.

Check out this page in the GDK documentation, filed under "Pango
Interaction."

http://developer.gnome.org/doc/API/2.0/gdk/gdk-Pango-Interaction.html

I might also add that Cairo has some primitive text drawing facilities,
and a bit of a cleaner API.  However, from the looks of the way Cairo's
text API is documented (in the docs, the devs call it a "toy API" not
meant for serious text rendering), the Cairo developers want you to use
Pango anyway.

The example in the doc linked above contains ~80 lines of code, and ends
up drawing differently-colored text in a circle.  So I think it has
everything you need in it.

-Andrew

On Mon, 2005-12-19 at 13:56 -0500, Chad Robinson wrote:
I have an application that's a rewrite of an old "green screen" terminal 
application. It presents columns of data much like a table, but this 
information updates VERY rapidly. It's not suitable for display in a table, 
because rows will get deleted and added in a hurry (sometimes dozen of updates 
per second), and there are a LOT of rows. Tables are even worse because 
there's never a need for scrolling, so actually maintaining invisible rows in 
a table would be a waste of CPU time.

The old application worked very well via ncurses by drawing strings - its math 
on where to put things isn't hard at all. We're just trying to move to a 
client/server model, and stay cross-platform. Gtk so far seems the best bet.

So, the question is, how can I quickly draw text in a Gtk application? I see 
draw_text and draw_string functions, and they look like exactly what I need. 
But, they're deprecated. I see references to Pango here, but can't find a 
simple example of what I need to do, and Pango seems horribly obfuscated and 
inefficient for this type of activity.

Basically, I need, on demand, to be able to draw text in location X, Y, in 
color C, background color B, text T.

It's additionally important to know the available space to draw in. Typically 
I'd look to calculate the height of a monospace font, divide that into the 
height of the drawing area, and I'd know how many rows to draw. As the user 
resizes the window I could intelligently draw additional (or fewer) rows.

What's the easiest and most efficient way to do this in Gtk? I'm at the end of 
my rope here, about to switch to something else. I just can't find a clean 
option. (FYI, I explored VteTerminal, but which is close but still not great.)

Regards,
Chad

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list




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