Re: DrawingArea and stuff
- From: muppet <scott asofyet org>
- To: David lacravate <lacravate mongueurs net>
- Cc: gtk-perl-list gnome org
- Subject: Re: DrawingArea and stuff
- Date: Fri, 2 Jun 2006 13:19:23 -0400
On Jun 2, 2006, at 2:44 AM, David lacravate wrote:
Now , i'd like to have help with the drawable and drawing area . I
clearly don't understand the concepts and didn't manage to go
anywhere .
Here's my need , explanations and code examples very much welcome :
i want to put a picture in an area where the user can select a part of
this picture with the usual dotted rectangle and get the selection
in a
usable form , noticeably to save it on disk .
Because every app needs something different, there is no built-in or
standard way to do it. For example, do you just need to display the
image pixel-for-pixel, or do you want zooming and scrolling? Should
your drag rectangle persist or is it only needed while dragging? Do
you need the pixels from the selection or just the coordinates?
These considerations will help decide whether you should use a
Gtk2::Image in a Gtk2::EventBox, or a bare Gtk2::DrawingArea, or a
full-fledged Gnome2::Canvas.
Without knowing those constraints, it's hard to give relevant example
code, but here are some general principles...
In order to handle mouse events, the widget must have a GdkWindow;
this means mouse handling must happen on either a DrawingArea or
EventBox. (The Canvas does things a different way.) The
histogram_plot.pl example that comes with the Gtk2 source handles
mouse events on a DrawingArea, with XOR drawing directly on the
screen, though it does not create a rubberband box.
You can get pixels from a Gtk2::Gdk::Pixbuf with the get_pixels()
method; if you know the coordinates of a selection rectangle, you can
easily get a new Pixbuf containing only that region's pixels with
Gtk2::Gdk::Pixbuf::new_subpixbuf(). You can save pixbufs in any
format for which your gtk+ has a pixbuf saver module (usually JPG and
PNG, depending on the version). The color_snooper.pl example that
comes with the Gtk2 source shows a simple way to use perl's unpack()
to get at the pixel data from your perl code, as well as handling
mouse events on an EventBox and mapping those coordinates to an Image
inside the EventBox.
--
Jolt is my co-pilot.
-- Slogan on a giant paper airplane hung in Lobby 7 at MIT.
http://hacks.mit.edu/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]