Skip to content

Commit

Permalink
better button paint with autoShaping=1
Browse files Browse the repository at this point in the history
  • Loading branch information
dk committed Oct 15, 2023
1 parent 4b7b625 commit 7f93824
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
8 changes: 5 additions & 3 deletions Prima/Buttons.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
13 changes: 1 addition & 12 deletions examples/layered.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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',
Expand Down Expand Up @@ -116,7 +105,7 @@ sub icon

my $btn = $w-> insert( Button =>
origin => [10,10],
shape => $i,
autoShaping => 1,
text => '~Quit',
onClick => sub { $::application-> close },
);
Expand Down

0 comments on commit 7f93824

Please sign in to comment.