Re: Generating a drawable widget
- From: muppet <scott asofyet org>
- To: Hermann Kaser <hermann kaser gmail com>
- Cc: gtk-perl-list gnome org
- Subject: Re: Generating a drawable widget
- Date: Sun, 9 Jan 2005 22:55:52 -0500
On Jan 9, 2005, at 6:54 PM, Hermann Kaser wrote:
I've spent the past few hours trying to figure out how to create a
drawable area, I'm trying to make a little graph area to make a
network usage timeline. I have the following code:
-----------------------------------------------------
$graph = Gtk2::Gdk::Pixmap->new($drawable,200,100,-1);
$vbox->pack_start($graph,1,1,5);
a GdkPixmap isn't a widget, so it can't be packed into a container.
what you want to do is
a) use a Gtk2::DrawingArea. This is a drawable widget; you could draw
directly to the screen or to a Gtk2::Gdk::Pixmap and copy that to the
screen in expose (which is how the scribble example does it). With
either option you can use the gdk drawing primitives. The drawing area
also has its own GdkWindow, so you can handle mouse events and all
that, e.g., to make an interactive plot (see the histogramplot.pl
example).
b) draw to a Gtk2::Gdk::Pixbuf, and display that in a Gtk2::Image.
This is usually a pretty good option in C, but since a GdkPixbuf is a
24-bit rgb pixel buffer and those aren't too easy to manipulate in
perl, and you can't use the gdk drawing primitives, i tend to avoid
this one.
But I haven't managed to generate a drawable area using
Gtk::GDK::Drawable so that it goes in $drawable and therefore fits
Pixmap.
The documentation for Gtk::GDK::Pixmap says that ->new accepts either
a Gtk2::Gdk::Drawable or a undef, but it always gives me an error when
trying undef.
You can use the GdkWindow of the widget as the drawable, like this:
$pixmap = Gtk2::Gdk::Pixmap->new ($widget->window, $width, $height,
-1); # same depth as window
--
She's obviously your child. She looks like you, she talks a lot, and
most of it is gibberish.
-- Elysse, to me, of Zella.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]