Skip to content

Commit

Permalink
ADDED: eraser mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nkh committed Nov 25, 2023
1 parent 74b1c1f commit 0ff9f34
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 50 deletions.
1 change: 1 addition & 0 deletions Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ lib/App/Asciio/Actions/Colors.pm
lib/App/Asciio/Actions/Debug.pm
lib/App/Asciio/Actions/Elements.pm
lib/App/Asciio/Actions/ElementsManipulation.pm
lib/App/Asciio/Actions/Eraser.pm
lib/App/Asciio/Actions/File.pm
lib/App/Asciio/Actions/Git.pm
lib/App/Asciio/Actions/Mouse.pm
Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ lib/App/Asciio/Actions/Colors.pm
lib/App/Asciio/Actions/Debug.pm
lib/App/Asciio/Actions/Elements.pm
lib/App/Asciio/Actions/ElementsManipulation.pm
lib/App/Asciio/Actions/Eraser.pm
lib/App/Asciio/Actions/File.pm
lib/App/Asciio/Actions/Git.pm
lib/App/Asciio/Actions/Mouse.pm
Expand Down
4 changes: 2 additions & 2 deletions documentation/mdbook_asciio/src/for_developers/overlay.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ Hide and show the mouse pointer, useful if you draw objects that are moved aroun

```perl

sub callback_enter { my ($asciio) = @_ ; $asciio->hide_pointer ; ... }
sub callback_enter { my ($asciio) = @_ ; $asciio->hide_cursor ; ... }

sub callback_escape { my ($asciio) = @_ ; $asciio->show_pointer ; ... }
sub callback_escape { my ($asciio) = @_ ; $asciio->show_cursor ; ... }

```

5 changes: 3 additions & 2 deletions lib/App/Asciio.pm
Original file line number Diff line number Diff line change
Expand Up @@ -933,8 +933,9 @@ sub get_overlays { defined $overlays_sub ? $overlays_sub->(@_) : () ; }

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

sub show_pointer { ; }
sub hide_pointer { ; }
sub change_cursor { ; }
sub show_cursor { ; }
sub hide_cursor { ; }

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

Expand Down
4 changes: 2 additions & 2 deletions lib/App/Asciio/Actions/Clone.pm
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ else
clone_set_overlay($asciio, ['Asciio/box', 0]) ;
}

$asciio->hide_pointer ;
$asciio->hide_cursor ;

$asciio->set_overlays_sub(\&clone_get_overlay) ;

$asciio->update_display ;
}

sub clone_escape { my ($asciio) = @_ ; $asciio->set_overlays_sub(undef) ; $asciio->show_pointer ; $asciio->update_display ; }
sub clone_escape { my ($asciio) = @_ ; $asciio->set_overlays_sub(undef) ; $asciio->show_cursor ; $asciio->update_display ; }
sub clone_mouse_motion { my ($asciio, $event) = @_ ; App::Asciio::Actions::Mouse::mouse_motion($asciio, $event) ; $asciio->update_display() ; }

sub clone_add_element
Expand Down
49 changes: 49 additions & 0 deletions lib/App/Asciio/Actions/Eraser.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package App::Asciio::Actions::Eraser ;

use strict ; use warnings ;

use App::Asciio::Actions::Mouse ;

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

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

$self->change_cursor('dot') ;
}

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

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

$self->change_cursor('left_ptr') ;
}

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

if($self->{PREVIOUS_X} != $x || $self->{PREVIOUS_Y} != $y)
{
my @elements = grep { $self->is_over_element($_, $x, $y) } reverse @{$self->{ELEMENTS}} ;

if(@elements)
{
$self->create_undo_snapshot() ;
$self->delete_elements(@elements) ;

$self->update_display();
}
}

App::Asciio::Actions::Mouse::mouse_motion($self, $event) ;
}

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

1 ;

61 changes: 21 additions & 40 deletions lib/App/Asciio/GTK/Asciio.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,45 +32,6 @@ use App::Asciio::String ;
use App::Asciio::Markup ;
use App::Asciio::ZBuffer ;


sub hide_pointer
{
my ($asciio) = @_ ;

my $display = $asciio->{widget}->get_display();
my $cursor = Gtk3::Gdk::Cursor->new_for_display($display, 'blank-cursor');

my $win = $asciio->{widget}->get_parent_window() ;

$asciio->{CACHE}{CURSOR} = $win->get_cursor() ;

$win->set_cursor($cursor);
# fleur
# x_cursor
}

sub show_pointer
{
my ($asciio) = @_ ;

my $display = $asciio->{widget}->get_display();
my $cursor ;

if (exists $asciio->{CACHE}{CURSOR})
{
$cursor = $asciio->{CACHE}{CURSOR} ;
}
else
{
$cursor = Gtk3::Gdk::Cursor->new_for_display($display, 'arrow');
}

my $win = $asciio->{widget}->get_parent_window() ;
$win->set_cursor($cursor);
}

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

our $VERSION = '0.01' ;

#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -926,8 +887,28 @@ for my $element (@{$self->{ELEMENTS}})
delete $self->{CACHE} ;
}

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

sub change_cursor
{
my ($self, $cursor_name) = @_ ;

my $display = $self->{widget}->get_display() ;

my $cursor = Gtk3::Gdk::Cursor->new_for_display($display, $cursor_name) ;

$self->{widget}->get_parent_window()->set_cursor($cursor) ;
}

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

sub hide_cursor { my ($self) = @_ ; $self->change_cursor('blank-cursor') ; }

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

sub show_cursor { my ($self) = @_ ; $self->change_cursor('left_ptr') ; }

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

=head1 DEPENDENCIES
Expand Down
14 changes: 12 additions & 2 deletions setup/Text/actions/vim_bindings.pl
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,26 @@
SHORTCUTS => 'e',

'Shrink box' => ['s'],

'Make element narrower' => ['1'],
'Make element taller' => ['2'],
'Make element shorter' => ['3'],
'Make element wider' => ['4'],

'Make elements Unicode' => ['u'],
'Make elements not Unicode' => ['U'],
},

'<< eraser leader >>' =>
{
SHORTCUTS => '00S-E',
ENTER_GROUP => \&App::Asciio::Actions::Eraser::eraser_enter,
ESCAPE_KEY => '000-Escape',

'Eraser escape' => ['Escape'],
'Eraser motion' => [ '000-motion_notify'],
},

'<< clone leader >>' =>
{
SHORTCUTS => 'c',
Expand Down
15 changes: 13 additions & 2 deletions setup/actions/default_bindings.pl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App::Asciio::Actions::Debug ;
use App::Asciio::Actions::Elements ;
use App::Asciio::Actions::ElementsManipulation ;
use App::Asciio::Actions::Eraser ;
use App::Asciio::Actions::File ;
use App::Asciio::Actions::Git ;
use App::Asciio::Actions::Mouse ;
Expand Down Expand Up @@ -330,16 +331,26 @@
SHORTCUTS => '000-e',

'Shrink box' => ['000-s', \&App::Asciio::Actions::ElementsManipulation::shrink_box ],

'Make element narrower' => ['000-1', \&App::Asciio::Actions::ElementsManipulation::resize_element_offset, [-1, 0] ],
'Make element taller' => ['000-2', \&App::Asciio::Actions::ElementsManipulation::resize_element_offset, [0, 1] ],
'Make element shorter' => ['000-3', \&App::Asciio::Actions::ElementsManipulation::resize_element_offset, [0, -1] ],
'Make element wider' => ['000-4', \&App::Asciio::Actions::ElementsManipulation::resize_element_offset, [1, 0] ],

'Make elements Unicode' => ['C00-u', \&App::Asciio::Actions::Asciio::make_selection_unicode, 1 ],
'Make elements not Unicode' => ['C0S-U', \&App::Asciio::Actions::Asciio::make_selection_unicode, 0 ],
},

'<< eraser leader >>' =>
{
SHORTCUTS => '00S-E',
ENTER_GROUP => \&App::Asciio::Actions::Eraser::eraser_enter,
ESCAPE_KEY => '000-Escape',

'Eraser escape' => [ '000-Escape', \&App::Asciio::Actions::Eraser::eraser_escape ],
'Eraser motion' => [ '000-motion_notify', \&App::Asciio::Actions::Eraser::erase_elements ],
},

'<< clone leader >>' =>
{
SHORTCUTS => '000-c',
Expand Down

0 comments on commit 0ff9f34

Please sign in to comment.