Re: Text with transparent background

Dirk van der Walt said:
I'm currently trying to learn more on GDK.
How will I go about displaying text on the screen without
any background?

Could you clarify what you mean by "without any background"?  Is that text
overlaid on a window regardless of the contents of the window, or something
like OSD text, which shows only the text and no background at all?

To achieve OSD-style display with conventional X, you must use shaped windows,
which means rendering the text to a pixmap, converting the text to a bitmap,
and using the bitmap as a mask for the window's shape
(Gtk2::Gdk::Window::combine_mask, IIRC).  I don't have any clue how you'd do
that with state-of-the-art cool alpha transparency X.

A simple sample script will be most appreciated. :)

Not exactly what you're looking for, but the old gtk-perl tutorial has a
section on using pixmaps to create shaped windows.

It should be quite straightforward to port that example to Gtk2.

As for how to create a shape mask from text...  A pixmap is a drawable.  A
pixbuf is a client-side image.  You can use standard gdk drawing to draw text
on a drawable[1].  You can create a pixbuf from a drawable[2].  You can render
a pixbuf to a pixmap and mask[3].  Somewhere in there is the magic combination
you need.

[1] Gtk2::Gdk::Drawable::draw_layout().
Getting the required Gtk2::Pango::Layout, Gtk2::Gdk::GC, and
Gtk2::Gdk::Drawable is left as an exercise for you.

[2] Gtk2::Gdk::Pixbuf::get_from_drawable(), a.k.a.

[3] Gtk2::Gdk::Pixbuf::render_pixmap_and_mask(), a.k.a.

muppet <scott at asofyet dot org>

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