From 0ff9f34dfc4494df46dd0a36eefbf64d80ff635b Mon Sep 17 00:00:00 2001 From: Nadim Khemir Date: Sat, 25 Nov 2023 19:03:37 +0100 Subject: [PATCH] ADDED: eraser mode --- Build.PL | 1 + MANIFEST | 1 + .../src/for_developers/overlay.md | 4 +- lib/App/Asciio.pm | 5 +- lib/App/Asciio/Actions/Clone.pm | 4 +- lib/App/Asciio/Actions/Eraser.pm | 49 +++++++++++++++ lib/App/Asciio/GTK/Asciio.pm | 61 +++++++------------ setup/Text/actions/vim_bindings.pl | 14 ++++- setup/actions/default_bindings.pl | 15 ++++- 9 files changed, 104 insertions(+), 50 deletions(-) create mode 100644 lib/App/Asciio/Actions/Eraser.pm diff --git a/Build.PL b/Build.PL index 009fc686..f613c971 100644 --- a/Build.PL +++ b/Build.PL @@ -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 diff --git a/MANIFEST b/MANIFEST index 52053ba4..4c6fefa4 100644 --- a/MANIFEST +++ b/MANIFEST @@ -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 diff --git a/documentation/mdbook_asciio/src/for_developers/overlay.md b/documentation/mdbook_asciio/src/for_developers/overlay.md index 4c19efb9..7f4f9d39 100644 --- a/documentation/mdbook_asciio/src/for_developers/overlay.md +++ b/documentation/mdbook_asciio/src/for_developers/overlay.md @@ -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 ; ... } ``` diff --git a/lib/App/Asciio.pm b/lib/App/Asciio.pm index 53e32cfd..ec0ee74f 100644 --- a/lib/App/Asciio.pm +++ b/lib/App/Asciio.pm @@ -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 { ; } #----------------------------------------------------------------------------- diff --git a/lib/App/Asciio/Actions/Clone.pm b/lib/App/Asciio/Actions/Clone.pm index 191483d3..1882d0a4 100644 --- a/lib/App/Asciio/Actions/Clone.pm +++ b/lib/App/Asciio/Actions/Clone.pm @@ -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 diff --git a/lib/App/Asciio/Actions/Eraser.pm b/lib/App/Asciio/Actions/Eraser.pm new file mode 100644 index 00000000..e27636e1 --- /dev/null +++ b/lib/App/Asciio/Actions/Eraser.pm @@ -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 ; + diff --git a/lib/App/Asciio/GTK/Asciio.pm b/lib/App/Asciio/GTK/Asciio.pm index 437f9213..f9bf4bb0 100644 --- a/lib/App/Asciio/GTK/Asciio.pm +++ b/lib/App/Asciio/GTK/Asciio.pm @@ -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' ; #----------------------------------------------------------------------------- @@ -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 diff --git a/setup/Text/actions/vim_bindings.pl b/setup/Text/actions/vim_bindings.pl index 66740b6e..68b4ed34 100644 --- a/setup/Text/actions/vim_bindings.pl +++ b/setup/Text/actions/vim_bindings.pl @@ -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', diff --git a/setup/actions/default_bindings.pl b/setup/actions/default_bindings.pl index 8a58b4e6..e3d5a74c 100644 --- a/setup/actions/default_bindings.pl +++ b/setup/actions/default_bindings.pl @@ -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 ; @@ -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',