NAME

Gtk2::Ex::Lasso -- drag the mouse to lasso a rectangular region

SYNOPSIS

use Gtk2::Ex::Lasso;
my $lasso = Gtk2::Ex::Lasso->new (widget => $widget);
$lasso->signal_connect (ended => sub { some_code() });
$lasso->start ($event);

OBJECT HIERARCHY

Gtk2::Ex::Lasso is a subclass of Glib::Object.

Glib::Object
  Gtk2::Ex::Lasso

DESCRIPTION

A Gtk2::Ex::Lasso object implements a "lasso" style user selection of a rectangular region in a widget window, drawing dashed lines as visual feedback while selecting.

+-------------------------+
|                         |
|   +-----------+         |
|   |           |         |
|   |           |         |
|   +-----------*         |
|                \mouse   |
|                         |
|                         |
+-------------------------+

The lasso is activated by the start function (see "FUNCTIONS" below). You setup your button press or keypress code to call that. When started from a button the lasso is active while the button is held down, ie. a drag. This is the usual way, but you can also begin from a keypress, or even something strange like a menu entry.

The following keys are recognised while lassoing,

Return      end selection
Esc         abort the selection
Space       swap the mouse pointer to the opposite corner

Other keys are propagated to normal processing. The space to "swap" lets you move the initial corner if you didn't start at the right spot or change your mind.

FUNCTIONS

Gtk2::Ex::Lasso->new (key => value, ...)

Create and return a new Lasso object. Optional key/value pairs set initial properties as per Glib::Object->new. Eg.

my $ch = Gtk2::Ex::Lasso->new (widget => $widget);
$lasso->start ()
$lasso->start ($event)

Start a lasso selection on $lasso. If $event is a Gtk2::Gdk::Event::Button then releasing that button ends the selection. For other event types or for undef or omitted the selection ends only with the Return key or an end call.

$lasso->end ()
$lasso->end ($event)

End the $lasso selection and emit the ended signal, or if $lasso is already inactive then do nothing. This is the user Return key or button release.

If you end a lasso in response to a button release, another button press, a motion notify, or similar, then pass the Gtk2::Gdk::Event as the optional $event parameter. end will use it for a final X,Y position, and for a server timestamp if ungrabbing. This is important if event processing is a bit lagged.

$lasso->abort ()

Abort the $lasso selection and emit the aborted signal, or if $lasso is already inactive then do nothing. This is the user Esc key.

$lasso->swap_corners()

Swap the mouse pointer to the opposite corner of the selection, by a "warp" of the pointer (ie. a forcible movement). This is the user Space key.

PROPERTIES

widget (a Gtk2::Widget, or undef)

The target widget to act on. This can be changed even when the lasso is active, though doing so stands a good chance of confusing the user.

active (boolean, default false)

True while lasso selection is in progress. Turning this on or off is the same as calling start or end above (except you can't pass events).

foreground (scalar, default undef)

The foreground colour to draw the lasso. This can be a string name (including hex "#RRGGBB"), a Gtk2::Gdk::Color object with an allocated pixel value, or undef for the widget's Gtk2::Style foreground.

cursor (scalar, default "hand1")

The mouse cursor type to display while lassoing. This can be any string or object understood by Gtk2::Ex::WidgetCursor, or undef for no cursor change.

A different cursor is highly desirable because when starting a lasso it's normally too small for the user to see and so really needs another visual indication that selection has begun. The default "hand1" is meant to be reasonable.

The cursor can be changed while the lasso is active. Doing so is probably unusual, but it works, and might be used for something creative like further visual feedback or maybe keeping an arrow outwards so as not to obscure the selected region.

SIGNALS

moved, parameters: lasso, x1, y1, x2, y2, userdata

Emitted whenever the in-progress selected region changes (but not when it ends). x2,y2 is the corner with the mouse.

ended, parameters: lasso, x1, y1, x2, y2, userdata

Emitted when a selection is complete and accepted by the user (as opposed to aborted). x2,y2 is the corner where the mouse finished (though it's unusual to care which is which).

aborted, parameters: lasso, userdata

Emitted when a region selection ends by the user wanting to abort, meaning basically wanting no action on the region.

OTHER NOTES

The lasso is drawn using xors in the widget window. See Gtk2::Ex::Xor for notes on this.

Keypresses are obtained from the Gtk "snooper" mechanism, so they work even if the lasso target widget doesn't have the focus. Keys not for the lasso are propagated in the usual way.

When the lasso is started from a keypress etc, not a button drag, an explicit pointer grab is used so motion events outside the widget window are seen. In the current code a further start call with a button press event will switch to drag mode, so the corresponding release has the expected effect. But maybe that's a bit obscure, so perhaps in the future this will change.

SEE ALSO

Gtk2::Ex::CrossHair, Gtk2::Ex::Xor, Glib::Object, Gtk2::Ex::WidgetCursor

HOME PAGE

http://user42.tuxfamily.org/gtk2-ex-xor/index.html

LICENSE

Copyright 2007, 2008, 2009 Kevin Ryde

Gtk2-Ex-Xor is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

Gtk2-Ex-Xor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Gtk2-Ex-Xor. If not, see http://www.gnu.org/licenses/.