[Gtk-sharp-list] Widget Background Color 'anomaly', and request for further reading
Hywel Thomas
hywel at controlspecials.demon.co.uk
Thu Jan 22 10:20:40 EST 2009
Hello,
I'm struggling to understand just which Background color Widgets are
drawn with, and how to get the current Background correctly. In the
following example (taken roughly from the Gtk Example on the Mono site)
I need to save the current Background color of the Drawing Area, use a
specific value (black), then restore the original, eg
...(unnecessary code removed)....
ColourExample()
{
win = new Window ("Background Colour Example");
win.SetDefaultSize (400, 300);
win.BorderWidth = 24; // to show parent's color clearly
da = new DrawingArea();
da.ExposeEvent += OnExposed;
win.Add (da);
Gdk.Color bg = da.Style.Backgrounds[(int)StateType.Normal]; // A
da.ModifyBg (StateType.Normal, new Gdk.Color(0,0,0)); // B
//da.ModifyBg(StateType.Normal, bg); // C
//win.ModifyBg(StateType.Normal, bg); // D
win.ShowAll ();
}
void OnExposed (object o, ExposeEventArgs args) {
da.GdkWindow.DrawLine(da.Style.BaseGC(StateType.Normal),
0, 0, 352, 252);
}
At line A I read the current Background color (or so I thought...), at
line B set up the new one, and let the ExposeEvent draw a line.This
works, with the set background color. However, if I uncomment line C,
so that the original background is restored before drawing the line, I
see that the background is NOT the same as the parent's background. Line
A is obviously not the correct call to read the correct background, but
the documentation appears to suggest that this is the way. If I also
uncomment line D, so that the parent's background is set to the same
value bg, both appear the same, but it is not the color that the window
and widget are originally drawn with. I can also get it to work if I use
a call to set the default background ( da.ModifyBg(StateType.Normal) ),
but I'd really like to be able to read this somehow.
The other 'obvious' property for the widget Background is write-only
(why?) so this also won't read back the current value!
I'd be grateful for any enlightenment, or references that I can follow
up, as I seem to have exhausted most avenues so far.
Many thanks,
Hywel Thomas
More information about the Gtk-sharp-list
mailing list