Skip to content

Commit

Permalink
Added click/touch zones with Help and Hints
Browse files Browse the repository at this point in the history
  • Loading branch information
twitham1 committed Sep 19, 2022
1 parent d5b66ac commit 7499455
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 23 deletions.
38 changes: 36 additions & 2 deletions lib/Prima/LPDB/ImageViewer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ sub profile_default
['smaller', 'Zoom ~Out', 'q', ord 'q' =>
sub { $_[0]->smaller }],
['*@autozoom', '~Auto Zoom', 'Enter', kb::Enter, 'autozoom' ],
['help', '~Help', 'h', ord('h') => 'help'],
],
);
@$def{keys %prf} = values %prf;
Expand Down Expand Up @@ -286,8 +287,8 @@ sub on_keydown
}
sub right{my @d=$_[0]->deltas; $_[0]->deltas($d[0] + $_[0]->width/5, $d[1])}
sub left {my @d=$_[0]->deltas; $_[0]->deltas($d[0] - $_[0]->width/5, $d[1])}
sub up {my @d=$_[0]->deltas; $_[0]->deltas($d[0], $d[1] - $_[0]->width/5)}
sub down {my @d=$_[0]->deltas; $_[0]->deltas($d[0], $d[1] + $_[0]->width/5)}
sub up {my @d=$_[0]->deltas; $_[0]->deltas($d[0], $d[1] - $_[0]->height/5)}
sub down {my @d=$_[0]->deltas; $_[0]->deltas($d[0], $d[1] + $_[0]->height/5)}

sub on_mousewheel {
my($self, $mod, $x, $y, $z) = @_;
Expand All @@ -305,6 +306,39 @@ sub on_mousewheel {
return;
}

sub on_mouseclick { # click/touch zones
my($self, $button, $mod, $x, $y) = @_;
my($w, $h) = $self->size;
my @key = reverse([kb::Escape, kb::Up, ord 'q'],
[kb::Left, kb::Enter, kb::Right],
[ord 'm', kb::Down, ord 'z']);
$button == mb::b1 or return;
my $key = $key[int($y / $h * 3)][int($x / $w * 3)];
$self->key_down($key, $key);
}

sub help { # click/touch zone documentation
my($self) = @_;
my($w, $h) = $self->size;
$self->begin_paint;
$self->color(cl::Yellow);
$self->backColor(cl::Black);
$self->lineWidth(3);
my @desc = (
"Escape\nback to Grid", "Up\nPrevious Row", "Q\nZoom Out",
"Left\nPrevious Picture", "Enter\nToggle Zoom", "Right\nNext Picture",
"M\nMenu Options", "Down\nNext Row", "Z\nZoom In");
for my $y ($h * 2 / 3, $h / 3, 0) {
for my $x (0, $w / 3, $w * 2 / 3) {
my $txt = shift @desc; $txt =~ s/(\w+)/<$1>/;
$self->draw_text($txt, $x, $y, $x + $w / 3, $y + $h / 3,
dt::Center | dt::VCenter | dt::NewLineBreak);
$self->rectangle($x, $y, $x + $w / 3, $y + $h / 3);
}
}
$self->end_paint;
}

sub infocycle { # cycle info overlay level, used by i key
my($self) = @_;
my $m = $self->popup;
Expand Down
82 changes: 61 additions & 21 deletions lib/Prima/LPDB/ThumbViewer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -167,27 +167,59 @@ sub init {

$self->packForget; # to get packs around the perimeter of the SUPER widget

my $top = $self->owner->insert('Prima::Label', name => 'NORTH', text => '',
my $top = $self->owner->insert('Prima::Label',
name => 'NORTH',
text => '',
transparent => 1, # hack, using label as container
pack => { side => 'top', fill => 'x', pad => 5 });
$top->insert('Prima::Label', name => 'NW', pack => { side => 'left' },
text => 'Hit ~M for Menu');
$top->insert('Prima::Label', name => 'NE', pack => { side => 'right' },
text => 'Enter = select / Escape = back');
$top->insert('Prima::Label', name => 'N', pack => { side => 'top' },
text => $self->{notice} = 'Use arrow keys to navigate');

$self->pack(expand => 1, fill => 'both');
pack => { side => 'top', fill => 'x', pad => 5 }
);
$top->insert('Prima::Label',
name => 'NW',
pack => { side => 'left' },
text => 'Hit ~M for Menu',
hint => 'Escape to parent',
onMouseClick => sub { $self->hitkey(kb::Escape) },
);
$top->insert('Prima::Label',
name => 'NE',
pack => { side => 'right' },
text => 'Enter = select / Escape = back',
hint => 'Q = Zoom Out',
onMouseClick => sub { $self->hitkey(ord 'q') },
);
$top->insert('Prima::Label',
name => 'N',
pack => { side => 'top' },
text => $self->{notice} = 'Use arrow keys to navigate',
hint => 'Scroll Up',
onMouseClick => sub { $self->hitkey(kb::Up) },
);
$self->pack(expand => 1, fill => 'both'); # pack SUPER in the center

my $bot = $self->owner->insert('Prima::Label', name => 'SOUTH', text => '',
transparent => 1, # hack, using label as container
pack => { side => 'bottom', fill => 'x', pad => 5 });
$bot->insert('Prima::Label', name => 'SW', pack => { side => 'left' },
text => 'beginning date and time');
$bot->insert('Prima::Label', name => 'SE', pack => { side => 'right' },
text => 'end time or image statistics');
$bot->insert('Prima::Label', name => 'S', pack => { side => 'bottom' },
text => 'summary');
$bot->insert('Prima::Label',
name => 'SW',
pack => { side => 'left' },
text => 'beginning date and time',
hint => 'M = Menu',
onMouseClick => sub { $self->hitkey(ord 'm') },
);
$bot->insert('Prima::Label',
name => 'SE',
pack => { side => 'right' },
text => 'end time or image statistics',
hint => 'Z = Zoom In',
onMouseClick => sub { $self->hitkey(ord 'z') },
);
$bot->insert('Prima::Label',
name => 'S',
pack => { side => 'bottom' },
text => 'summary',
hint => 'Scroll Down',
onMouseClick => sub { $self->hitkey(kb::Down) },
);

$self->items($self->children('/'));
$self->focusedItem(0);
Expand All @@ -198,6 +230,11 @@ sub init {
return %profile;
}

sub hitkey {
my($self, $key) = @_;
$self->key_down($key, $key);
}

sub sorter { # applies current sort/filter via children of goto
my($self) = @_;
$self->goto($self->current);
Expand Down Expand Up @@ -647,11 +684,14 @@ sub draw_picture {
$str and
$canvas->draw_text($str, $x1 + $b, $y1 + $b, $x2 - $b, $y2 - $b,
dt::Right|dt::Top|dt::Default);
# if ($sel and $self->popup->checked('cropimages')) { # help see selection
# my $str = $pic->width < $pic->height ? '|' : '=';
# $canvas->draw_text($str x 30, $x1 + $b, $y1 + $b, $x2 - $b, $y2 - $b,
# dt::Center|dt::Bottom|dt::Default);
# }
if ($sel) { # help see selection by showing text
my $str = ' ' . $pic->basename . ' ';
$canvas->draw_text($str, $x1 + $b, $y1 + $b, $x2 - $b, $y2 - $b,
dt::Center|dt::Top|dt::Default);
$str = strftime(' %b %d %Y ', localtime $pic->time);
$canvas->draw_text($str, $x1 + $b, $y1 + $b, $x2 - $b, $y2 - $b,
dt::Center|dt::Bottom|dt::Default);
}

$canvas->textOpaque($b == 10); # highlight caption of selection
$pic->caption and
Expand Down

0 comments on commit 7499455

Please sign in to comment.