Re: Writing characters to the screen



On Sun, 2006-03-05 at 17:14 -0800, Andy T. Beckenbach wrote:
> Hi all,
> 
>    In order to make the transition from Windows to Linux, I have
> to port one of my most important tools, a molecular sequence editor
> (DNA, RNA, and amino acid) that I have been developing and using
> for the past decade. 

ah reminds me of the bad old days at EMBL in the mid 80's ;)

>    So my question is straight-forward: What is the best way to 
> display a single character in a specified font (mono-spaced in my
> application, since text columns have to align vertically), in a
> specified color (since each residue will have an associated color),
> at a specfic position withing an editing window?

given a drawing area widget, or any widget that has its own window, 
you would use gdk_draw_layout (drawing_area->get_window(), .....)

to create the layout, 

   PangoLayout* layout = gtk_widget_create_layout (drawing_area);
   pango_layout_set_text ("a");

GTK1 provided gdk_draw_text(), but this has been removed (effectively)
because "text" doesn't provide enough representational power for text in
a multi-lingual, bidirectional world.

now, alas, pango is pretty heavyweight for drawing single characters
precisely because it does provide a lot of representational power. so if
you find that this isn't fast enough, you have a way out: you can draw
the chars into pixmaps, and then use gdk_draw_drawable() to render the
pixmaps, which will avoid some pango computation. i would try the
straight layout version first though - there is every change it will
work.

finally, if you're really new at this, a reminder:

	* do not draw into an on-screen drawable (like your drawing area) in
anything other than an expose event handler

        * if something happens that requires a change in the appearance,
call gtk_widget_queue_draw()

sorry if i get any function names wrong,i use gtkmm (C++) not straight
gtk (C)

--p





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