Skip to content

Commit

Permalink
Stop making selection floating-point
Browse files Browse the repository at this point in the history
  • Loading branch information
DarthGandalf authored and carygravel committed Oct 9, 2020
1 parent 922d718 commit 15baae3
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ lib/Gtk3/ImageView/Tool/SelectorDragger.pm
t/1_basics.t
t/2_transparent.t
t/3_zoom.t
t/4_select.t
t/90_MANIFEST.t
t/91_critic.t
t/bigpic.svg
Expand Down
1 change: 1 addition & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ WriteMakefile(
Test::Differences => 0,
Image::Magick => 0,
Try::Tiny => 0,
Test::MockObject => 0,
},
clean => { FILES => '$(SOURCE_TIDY)' },
(
Expand Down
9 changes: 8 additions & 1 deletion lib/Gtk3/ImageView/Tool/Selector.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package Gtk3::ImageView::Tool::Selector;
use warnings;
use strict;
use base 'Gtk3::ImageView::Tool';
use POSIX qw(round);
use Glib qw(TRUE FALSE); # To get TRUE and FALSE
use List::Util qw(min);
use Readonly;
Expand Down Expand Up @@ -108,7 +109,13 @@ sub _update_selection {
( $x, $y ) =
$self->view->to_image_coords( min( $x, $x2 ), min( $y, $y2 ) );
$self->view->set_selection(
{ x => $x, y => $y, width => $w, height => $h } );
{
x => round($x),
y => round($y),
width => round($w),
height => round($h)
}
);
return;
}

Expand Down
37 changes: 37 additions & 0 deletions t/4_select.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use warnings;
use strict;
use Try::Tiny;
use File::Temp;
use Test::More tests => 2;
use Test::MockObject;
use Carp::Always;

BEGIN {
use Glib qw/TRUE FALSE/;
use Gtk3 -init;
use_ok('Gtk3::ImageView');
}

#########################

my $window = Gtk3::Window->new('toplevel');
$window->set_size_request( 300, 200 );
my $view = Gtk3::ImageView->new;
$window->add($view);
$view->set_tool('selector');
$view->set_pixbuf( Gtk3::Gdk::Pixbuf->new_from_file('t/transp-green.svg'),
TRUE );
$window->show_all;
$window->hide;

$view->set_zoom(8);
my $event = Test::MockObject->new;
$event->set_always( 'x', 7 );
$event->set_always( 'y', 5 );
$view->get_tool->button_pressed($event);
$event->set_always( 'x', 93 );
$event->set_always( 'y', 67 );
$view->get_tool->button_released($event);
is_deeply( $view->get_selection, { x => 32, y => 38, width => 11, height => 8 },
'get_selection' );

0 comments on commit 15baae3

Please sign in to comment.