Re: [gtk-list] color handling.




H
<allan@ns.internet.dk> writes:

> What I need is to draw a table of entries something like a spreadsheet
> on a drawing area. I have made the area and I am able to draw rectangles
> and strings using gdk_draw_rectangle and gdk_draw_string, but I can't
> get the background colors to change the way I need. I need only 4-5
> different background colors and the text need only be in black or white.
> Maybe I should do something with gtkstyle but what ???

X (and thus gtk) only draw the foreground portion of the text, so if
you want different background colors, you'll have fill in the area
behind the text explicitly. (possibly by filling a rectangle after
setting the _foreground_ color.)

You can get the size of a string by doing something like:

  gint string_width = gdk_string_width (font,string);
  gint string_height = font->ascent  + font->descent + 2;

(You may need to play around with this a bit to get things the way
you like it.) Using styles doesn't really help in doing the
drawing, but it might help in keeping track of things. It's 
mostly needed if you're writing a widget - the style provides
a way for the user/programmer to control the appearance.

Regards,
                                        Owen

(I found some examples of drawing text and background in the gtktext
widget, but knowing where to look is a function of experience
(and grep.))



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