From 7f93824f16330f06eba315294d80db6485ccd308 Mon Sep 17 00:00:00 2001 From: Dmitry Karasik Date: Sun, 15 Oct 2023 11:50:44 +0200 Subject: [PATCH] better button paint with autoShaping=1 --- Prima/Buttons.pm | 8 +++++--- examples/layered.pl | 13 +------------ 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/Prima/Buttons.pm b/Prima/Buttons.pm index 298919531..a217c5482 100644 --- a/Prima/Buttons.pm +++ b/Prima/Buttons.pm @@ -527,17 +527,19 @@ sub paint_flat } } $canvas-> antialias(1); - my $dw; + my ($dw, $d); if ( $canvas-> antialias ) { $dw = $self->font->height; + $d = 0; } else { $dw = 0; + $d = -1; $lw = int($lw + .5); } $canvas-> lineWidth( $lw ); $canvas-> new_path-> - round_rect( 0 + $lw/2, 0 + $lw/2, $w - $lw/2 - 1, $h - $lw/2 - 1, $dw)-> + round_rect( $d + $lw/2, $d + $lw/2, $d + $w - $lw/2, $d + $h - $lw/2, $dw)-> fill_stroke; }) unless $self-> transparent; } @@ -547,7 +549,7 @@ sub update_shape my $self = shift; my @sz = $self->size; my $shape = $self-> new_path-> round_rect( - -1.5, -1.5, $sz[0]+.5, $sz[1]+.5, + -.5, -.5, $sz[0]-.5, $sz[1]-.5, $self-> font-> height )-> region; $self->shape($shape); diff --git a/examples/layered.pl b/examples/layered.pl index 537224d14..107ed7fb2 100644 --- a/examples/layered.pl +++ b/examples/layered.pl @@ -20,11 +20,9 @@ =head1 FEATURES height => 100, type => im::Byte, ); -$j->begin_paint; $j->backColor(cl::Clear); $j->clear; $j->new_gradient(palette => [cl::Black, cl::White])->ellipse(50, 50, 100, 100); -$j->end_paint; $j->type(im::Byte); sub icon @@ -35,14 +33,12 @@ sub icon height => 100, type => im::RGB, ); - $i->begin_paint; $i->backColor(cl::Clear); $i->clear; $i->new_gradient( palette => [cl::Black, $color], spline => [0.2,0.8], )-> ellipse( 50, 50, 100, 100 ); - $i->end_paint; my $k = Prima::Icon->new; $k->combine($i, $j); @@ -65,13 +61,6 @@ sub icon my $angle = 0; my $pi = 3.14159; -my $i = Prima::Region-> new( box => [ 0, 0, - 96 * $::application-> font-> width / 7, # poor man's calculations of - 36 * $::application-> font-> height / 16, # button size -]); - -$i-> combine( Prima::Drawable->new_path->ellipse( 10, 10, 10 )->region, rgnop::Diff); - my $w = Prima::MainWindow->new( layered => 1, text => 'ARGB example', @@ -116,7 +105,7 @@ sub icon my $btn = $w-> insert( Button => origin => [10,10], - shape => $i, + autoShaping => 1, text => '~Quit', onClick => sub { $::application-> close }, );