Skip to content

Commit

Permalink
FIXED: ESC key can not exit polygon selec mode
Browse files Browse the repository at this point in the history
CHANGED: polygon selections are grouped separately to
provide more convenient operations.
  • Loading branch information
qindapao committed Dec 4, 2023
1 parent 3bcb0ce commit c948c74
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 25 deletions.
6 changes: 0 additions & 6 deletions lib/App/Asciio.pm
Original file line number Diff line number Diff line change
Expand Up @@ -784,12 +784,6 @@ my $modifiers = $event->{MODIFIERS} ;

if($self->{PREVIOUS_X} != $x || $self->{PREVIOUS_Y} != $y)
{
if (@{$self->{SELECTION_POLYGON}//[]} > 0)
{
push @{$self->{SELECTION_POLYGON}}, [$x, $y];
$self->polygon_selection();
}

delete $self->{BINDINGS_COMPLETION} ;
$self->update_display ;

Expand Down
2 changes: 0 additions & 2 deletions lib/App/Asciio/Actions/Mouse.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ if((defined $self->{EDIT_SEMAPHORE}) && ($self->{EDIT_SEMAPHORE} > 0))
undef $self->{DRAGGING} ;
delete $self->{IN_DRAG_DROP} ;

delete $self->{SELECTION_POLYGON} ;

$self->pop_undo_buffer(1) if defined $self->{MODIFIED_INDEX} && defined $self->{MODIFIED} && $self->{MODIFIED_INDEX} == $self->{MODIFIED} ;
$self->update_display();
}
Expand Down
86 changes: 71 additions & 15 deletions lib/App/Asciio/GTK/Asciio/Selection.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use strict ; use warnings ;
use App::Asciio::ZBuffer ;


my %elements_selection_status ;


#-----------------------------------------------------------------------------

sub all_points_in_polygon
Expand Down Expand Up @@ -51,21 +54,25 @@ return $is_inside;
}

#----------------------------------------------------------------------------------------------
sub mouse_polygon_selection_switch

sub polygon_selection_enter
{
my ($self) = @_ ;

if(@{$self->{SELECTION_POLYGON} // []} == 0)
{
$self->deselect_all_elements();
$self->change_cursor('dot') ;
%elements_selection_status = () ;

}

#----------------------------------------------------------------------------------------------

sub polygon_selection_escape
{
my ($self) = @_ ;

$self->{SELECTION_POLYGON} = [] ;
$self->change_cursor('left_ptr') ;

my ($x, $y) = @{$self}{'MOUSE_X', 'MOUSE_Y'};
$self->{SELECTION_POLYGON} = [[$x, $y]];
}
else
{
$self->{SELECTION_POLYGON} = [];
}
}

#----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -100,9 +107,7 @@ if(@{$self->{SELECTION_POLYGON}//[]} > 0)
#-----------------------------------------------------------------------------
sub polygon_selection
{
my ($self) = @_ ;

$self->deselect_all_elements() ;
my ($self, $select_type) = @_ ;

for my $element (@{$self->{ELEMENTS}})
{
Expand All @@ -114,12 +119,63 @@ for my $element (@{$self->{ELEMENTS}})
}
if(all_points_in_polygon($element->{CACHE}{COORDINATES}, $self->{SELECTION_POLYGON}))
{
$self->select_elements(1, $element);
$self->select_elements($select_type, $element);
$elements_selection_status{$element} = 1 ;
}
else
{
if(exists($elements_selection_status{$element}))
{
$self->select_elements(!$select_type, $element);
delete $elements_selection_status{$element} ;
}
}
}
}

#----------------------------------------------------------------------------------------------

sub polygon_selection_motion
{
my ($self, $select_type, $event) = @_;

my ($x, $y) = @{$event->{COORDINATES}}[0,1] ;

($self->{PREVIOUS_X}, $self->{PREVIOUS_Y}) = ($self->{MOUSE_X}, $self->{MOUSE_Y}) ;
($self->{MOUSE_X}, $self->{MOUSE_Y}) = ($x, $y) ;

if($event->{STATE} eq 'dragging-button1' && ($self->{PREVIOUS_X} != $x || $self->{PREVIOUS_Y} != $y))
{
if(@{$self->{SELECTION_POLYGON} // []} == 0)
{
%elements_selection_status = () ;
$self->{SELECTION_POLYGON} = [[$x, $y]];
$self->change_cursor($select_type == 1 ? "dot" : "tcross") ;
}
else
{
push @{$self->{SELECTION_POLYGON}}, [$x, $y] ;
$self->polygon_selection($select_type) ;
}
}

if($event->{STATE} ne 'dragging-button1')
{
$self->{SELECTION_POLYGON} = [] ;
}
}

#----------------------------------------------------------------------------------------------

sub polygon_selection_button_release
{
my ($self, $event) = @_ ;

$self->{SELECTION_POLYGON} = [] ;
$self->change_cursor('dot') ;
}

#----------------------------------------------------------------------------------------------

1 ;

16 changes: 15 additions & 1 deletion setup/Text/actions/vim_bindings.pl
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,21 @@

'select flip mode' => ['e'],
'select motion' => ['000-motion_notify'],
'Mouse polygon selection' => ['not_set'],
'<< polygon selection >>' => ['not_set'] ,
},

'group_polygon' =>
{
SHORTCUTS => 'group_polygon',
ENTER_GROUP => 'not_set',
ESCAPE_KEYS => 'not_set',

'Polygon selection escape' => ['not_set'],
'Polygon selection escape2' => ['not_set'],
'Polygon select motion' => ['not_set'],
'Polygon deselect motion' => ['not_set'],
'Polygon select left-release' => ['not_set'],
'Polygon select left-release 2' => ['not_set'],
},

'<< eraser leader >>' =>
Expand Down
16 changes: 15 additions & 1 deletion setup/actions/default_bindings.pl
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,21 @@

'select flip mode' => [ '000-e', \&App::Asciio::Actions::Selection::selection_mode_flip ],
'select motion' => [ '000-motion_notify', \&App::Asciio::Actions::Selection::select_elements ],
'Mouse polygon selection' => [ '000-x', \&App::Asciio::GTK::Asciio::mouse_polygon_selection_switch ],
'<< polygon selection >>' => [ '000-x', sub { $_[0]->use_action_group('group_polygon') ; } ] ,
},

'group_polygon' =>
{
SHORTCUTS => 'group_polygon',
ENTER_GROUP => \&App::Asciio::GTK::Asciio::polygon_selection_enter,
ESCAPE_KEYS => [ '000-x', '000-Escape' ],

'Polygon selection escape' => [ '000-x', \&App::Asciio::GTK::Asciio::polygon_selection_escape ],
'Polygon selection escape2' => [ '000-Escape', \&App::Asciio::GTK::Asciio::polygon_selection_escape ],
'Polygon select motion' => [ '000-motion_notify', \&App::Asciio::GTK::Asciio::polygon_selection_motion, 1 ],
'Polygon deselect motion' => [ 'C00-motion_notify', \&App::Asciio::GTK::Asciio::polygon_selection_motion, 0 ],
'Polygon select left-release' => [ '000-button-release-1',\&App::Asciio::GTK::Asciio::polygon_selection_button_release ],
'Polygon select left-release 2' => [ 'C00-button-release-1',\&App::Asciio::GTK::Asciio::polygon_selection_button_release ],
},

'<< eraser leader >>' =>
Expand Down

0 comments on commit c948c74

Please sign in to comment.