[Gtk-sharp-list] A text view widget with a transparent background, and some other pure evil.

Greg Lowe greg at vis.net.nz
Sun Mar 21 04:52:49 EDT 2010


Hello all,

I'm experimenting with a way to implement a simple text tool for a GTK
painting application.

What I've got so far is an custom container widget which uses cairo to paint
the background on expose. When the user clicks on the container widget, a
text view widget is added on top and given keyboard focus.

When the text entry is completed, it's drawn to a cairo image surface, and
the text view widget is destroyed.

This works pretty well. The one caveat, is that the text view must have a
solid background colour. Ideally, I'd like to be able to give it a
transparent background. And that's when it starts to get tricky.

I'd like to be able to do something like:

    text_view.ModifyBase (StateType.Normal, new Gdk.Color (r,g,b,_alpha_))

But the problem is that Gdk.Color doesn't support alpha.

I understand it is possible to use alpha compositing for child widgets. From
what I've read, I think I need to get the rgba colour map from the GDK
screen, and then set it on the widget. But then I also need to pass in an
alpha value for the text view's background colour, at which point I'm stuck.

So now, dear reader, you've made it this far, and it's time for the
questions...

 - Is it currently possible to set the alpha channel of the text view
widget's background colour, or make the background completely transparent?

 - Or, is there a better way to achieve the same effect?

 - If not, are there any plans to add a function that does this to GTK (and
GtkSharp)? Is that likely to happen within the next year or so?

 - If there isn't a solution at the moment, are there any good workarounds?

(For example, I could potentially use "pure evil" [1], and skip alpha
compositing all together, just i.e. re-render the background. Actually I
tried this in GTK#, and not only did my demo app crash, but it also took
MonoDevelop down with it. And I thought the pure evil bit was just a joke.
[1] http://dannipenguin.livejournal.com/283590.html )

Anyways, thanks for your time, and hopefully someone out there has cracked
this nut already... would love to hear from you!

Cheers,
Greg.


Here's the source code for my text tool demo:

http://github.com/xxgreg/code-examples/blob/master/gtksharp-text-tool-example/TextToolTest/ScalableTextToolExample.cs


Here's some other links that I looked at while working on this:

http://www.go-mono.com/docs/index.aspx?link=P:Gdk.Screen.RgbaColormap
http://www.go-mono.com/docs/index.aspx?link=P:Gtk.Widget.Colormap

http://library.gnome.org/devel/gtk/stable/GtkWidget.html#gtk-widget-set-colormap
http://library.gnome.org/devel/gdk/stable/GdkScreen.html#gdk-screen-get-rgba-colormap


And a related thread on the Pinta list:

http://groups.google.com/group/pinta/browse_thread/thread/ceb7c9d1076825f6
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20100321/e800da6d/attachment-0001.html 


More information about the Gtk-sharp-list mailing list