File: ImageToolSelector.xs

package info (click to toggle)
libgtk2-imageview-perl 0.04-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 224 kB
  • ctags: 42
  • sloc: perl: 457; makefile: 52; ansic: 27
file content (131 lines) | stat: -rw-r--r-- 4,480 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "gtkimageviewperl.h"


MODULE = Gtk2::ImageView::Tool::Selector  PACKAGE = Gtk2::ImageView::Tool::Selector  PREFIX = gtk_image_tool_selector_

=for object Gtk2::ImageView::Tool::Selector Image tool for selecting rectangular regions

=head1 DESCRIPTION

Gtk2::ImageView::Tool::Selector is a tool for selecting areas of an image. It is useful for cropping an image, for example. The tool is an implementor of the Gtk2::ImageView::Tool inteface which means that it can be plugged into a Gtk2::ImageView by using the Gtk2::ImageView::Tool::set_tool() method.

Gtk2::ImageView::Tool::Selector changes the default display of the Gtk2::ImageView. It darkens down the unselected region of the image which provides a nice effect and makes it clearer what part of the image that is currently selected. Unfortunately, this effect is somewhat incompatible with how Gtk2::ImageView::Nav behaves because that widget will show the image without darkening it.

The tool also changes the default behaviour of the mouse. When a Gtk2::ImageView::Tool::Selector is set on a Gtk2::ImageView, mouse presses do not "grab" the image and you cannot scroll by dragging. Instead mouse presses and dragging is used to resize and move the selection rectangle. When the mouse drags the selection rectangle to the border of the widget, the view autoscrolls which is a convenient way for a user to position the selection.

Please note that Gtk2::ImageView::Tool::Selector draws the image in two layers. One darkened and the selection rectangle in normal luminosity. Because it uses two draw operations instead one one like Gtk2::ImageView::Tool::Dragger does, it is significantly slower than that tool. Therefore, it makes sense for a user of this library to set the interpolation to GDK_INTERP_NEAREST when using this tool to ensure that performance is acceptable to the users of the program.

=head2 Zoom bug

There is a small bug in Gtk2::ImageView::Tool::Selector that becomes apparent when the zoom factor is greater than about 30. The edge of the selection rectangle may in that case intersect a pixel.

The bug is caused by bug 389832 in gdk-pixbuf. There is no way to solve this bug on Gtk2::ImageView's level (but if someone knows how, I'd really like to know).

=cut


=for apidoc

Creates a new selector tool for the specified view with default values. The default values are:

=over

=item  selection : (0, 0) - [0, 0]

=back

=over

=item view : a Gtk2::ImageView.

=back

=head3 Returns

=over

=item a new Gtk2::ImageView::Tool::Selector

=back

=cut
GtkIImageTool *
gtk_image_tool_selector_new (class, view)
		GtkImageView *	view
	C_ARGS:
		view


=for apidoc

Returns a Gtk2::Gdk::Rectangle with the current selection. If either the width or the height of the selection is zero, then nothing is selected and undef is returned. See "selection-changed" for an example.

=over

=item selector : a Gtk2::ImageView::Tool::Selector

=back

=head3 Returns

=over

=item a Gtk2::Gdk::Rectangle with the current selection.

=back

=cut
## call as $rectangle = $selector->get_selection
## void gtk_image_tool_selector_get_selection (GtkImageToolSelector *selector, GdkRectangle *rect);
GdkRectangle_copy *
gtk_image_tool_selector_get_selection (selector)
		GtkImageToolSelector *	selector
	PREINIT:
		GdkRectangle	rect = { 0, };
	CODE:
		gtk_image_tool_selector_get_selection(selector, &rect);
		if (!rect.width || !rect.height)
			XSRETURN_UNDEF;
		RETVAL = ▭
	OUTPUT:
		RETVAL


=for apidoc

Sets the selection rectangle for the tool. Setting this attribute will cause the widget to immidiately repaint itself if its view is realized.

This method does nothing under the following circumstances:

=over

=item If the views pixbuf is NULL.

=item If rect is wider or taller than the size of the pixbuf

=item If rect equals the current selection rectangle.

=back

If the selection falls outside the pixbufs area, its position is moved so that it is within the pixbuf.

Calling this method causes the ::selection-changed signal to be emitted.

The default selection is (0,0) - [0,0].

=over

=item selector : a Gtk2::ImageView::Tool::Selector

=item rect : Selection rectangle in image space coordinates.

=back

=cut
## call as $selector->set_selection($rectangle)
## void gtk_image_tool_selector_set_selection (GtkImageToolSelector *selector, GdkRectangle *rect);
void
gtk_image_tool_selector_set_selection (selector, rect)
		GtkImageToolSelector *	selector
		GdkRectangle_ornull *	rect