[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: Color in GtkText
- From: sml13 cornell edu
- To: Nigel Gamble <nigel nrg org>
- cc: gtk-app-devel-list redhat com
- Subject: Re: Color in GtkText
- Date: Tue, 24 Nov 1998 23:02:45 -0500 (EST)
I tried what you recommended, Nigel. And (like the last time) the only
thing that it set right was the Font. Nothing else. The text background
is still white and the numbers are still black. Do I have to get at the
GtkTextWidget WITHIN the GtkEntry to set this stuff? That seems kind of
ugly, but I suppose it's possible. Then I have to know about GtkEntry
internals just to set a few properties of it! This can't be a Good Thing
(tm). Any further advice would be greatly appreciated. Here is the
relevant portion of the code that I am using verbatim:
GdkColor c;
GtkStyle *style;
GtkWidget *time;
[snip]
time = gtk_entry_new ();
/* allocate a new color */
c.red = 0;
c.green = 0xffff;
c.blue = 0;
gdk_color_alloc (gtk_widget_get_colormap (time), &c);
/* get a copy of the current widget style */
style = gtk_style_copy (gtk_widget_get_style (time));
/* set the text color */
style->text[GTK_STATE_NORMAL] = c;
/* throw away the old font */
gdk_font_unref (style->font);
/* set the new font */
style->font = gdk_font_load
("-adobe-helvetica-bold-r-normal-*-*-240-*-*-p-*-iso8859-1");
/* set the background to be black */
c.red = 0x000000;
c.green = 0x000000;
c.blue = 0x000000;
gdk_color_alloc (gtk_widget_get_colormap (time), &c);
style->bg[GTK_STATE_NORMAL] = c;
gtk_widget_set_style (time, style);
gtk_entry_set_text (GTK_ENTRY (time), "[0] 00:00.00");
[snip]
On Tue, 24 Nov 1998, Nigel Gamble wrote:
> On Tue, 24 Nov 1998 sml13@cornell.edu wrote:
> > I had a similar problem that I posted to GTK-list a while back, and
> > no-one really gave me a satisfactory response other than "you should use
> > themes to do this." Well, no, I want it to be a static property of
> > the app so themes aren't an option. What I wanted to do is set
> > the color of the text and background of a gtk_entry by doing (I thought):
> >
> > time = gtk_entry_new ();
> > style = gtk_style_new ();
> > style->font = gdk_font_load
> > ("-adobe-helvetica-bold-r-normal-*-*-240-*-*-p-*-iso8859-1");
> > style->text[GTK_STATE_NORMAL].red = 0;
> > style->text[GTK_STATE_NORMAL].green = 1;
> > style->text[GTK_STATE_NORMAL].blue = 0;
> > style->bg[GTK_STATE_NORMAL] = style->black;
> > gtk_widget_set_style (time, style);
> >
> > You see, I want my time display to have alien green digits (this is for a
> > CD Player) on a black background...but this doesn't work! I DO NOT want
> > this to vary with the themes, so theming to this isn't an option. I want
> > to know how to do this (and, generallly, set the attributs of any widget
> > like this) PROGRAMMATICALLY. Any ideas?
>
> You need to call gdk_color_alloc() to get the color, and don't forget
> that the red, green, blue fields are 16 bit quantities. Something
> like this seems to work best for me:
>
> GdkColor c;
>
> /* Create the new widget */
> time = gtk_entry_new();
>
> /* Allocate the new color */
> c.red = 0;
> c.green = 0xffff;
> c.blue = 0;
> gdk_color_alloc(gtk_widget_get_colormap(time), &c);
>
> /* Get a copy of the current style */
> style = gtk_style_copy(gtk_widget_get_style(time));
>
> /* Set the text color */
> style->text[GTK_STATE_NORMAL] = c;
>
> /* Throw away the old font */
> gdk_font_unref(style->font);
>
> /* Set the new font */
> style->font = font;
>
> /* Set the new style */
> gtk_widget_set_style(time, style);
>
>
> Nigel Gamble nigel@nrg.org
> Mountain View, CA, USA. http://www.nrg.org/
>
>
> --
> To unsubscribe: mail gtk-app-devel-list-request@redhat.com with
> "unsubscribe" as the Subject.
>
> Mailing list concerns should be mailed to <listmaster@redhat.com>
>
>
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]