Skip to content

Commit a3ea63a

Browse files
committed
add emoji.pl
1 parent 595128f commit a3ea63a

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ examples/dock.pl
9595
examples/drivecombo.pl
9696
examples/edit.pl
9797
examples/editor.pl
98+
examples/emoji.pl
9899
examples/exif.pl
99100
examples/extlist.pl
100101
examples/eyes.pl

examples/emoji.pl

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
=head1 NAME
2+
3+
examples/emoji.pl - displays color glyphs of an emoji font
4+
5+
=cut
6+
7+
8+
use strict;
9+
use warnings;
10+
use Prima qw(Application Lists);
11+
12+
my $font;
13+
if ( @ARGV ) {
14+
$font = $ARGV[0];
15+
} else {
16+
for ( @{$::application->fonts} ) {
17+
next unless $_->{name} =~ /emoji/i;
18+
$font = $_->{name};
19+
last;
20+
}
21+
warn "You don't seem to have an emoji font\n" unless $font;
22+
}
23+
24+
my @glyphs;
25+
$::application->begin_paint_info;
26+
$::application->font( {name => $font, encoding => '' } );
27+
my $ranges = $::application-> get_font_ranges;
28+
for ( my $i = 0; $i < @$ranges; $i += 2 ) {
29+
next if $ranges->[$i] < 0x100;
30+
push @glyphs, $ranges->[$i] .. $ranges->[$i+1];
31+
}
32+
$::application->end_paint_info;
33+
34+
my $w = Prima::MainWindow->new(
35+
text => 'Emojis',
36+
packPropagate => 0,
37+
font => { name => $font, encoding => '' },
38+
);
39+
40+
my $ih = $w->font->height * 4;
41+
my $cr;
42+
my $dx;
43+
my $dy;
44+
$w->insert( AbstractListViewer =>
45+
pack => { fill => 'both', expand => 1 },
46+
multiColumn => 1,
47+
itemWidth => $ih,
48+
itemHeight => $ih,
49+
hScroll => 1,
50+
vScroll => 1,
51+
drawGrid => 0,
52+
onPaint => sub {
53+
my ( $self, $canvas ) = @_;
54+
$self->clear;
55+
$self->on_paint($canvas);
56+
undef $cr;
57+
},
58+
onDrawItem => sub {
59+
my ( $self, $canvas, $index, $x1, $y1, $x2, $y2, $selected, $focused, $prelight ) = @_;
60+
my @cs;
61+
if ( $focused || $prelight) {
62+
@cs = ( $canvas-> color, $canvas-> backColor);
63+
my $fo = $focused ? $canvas-> hiliteColor : $canvas-> color ;
64+
my $bk = $focused ? $canvas-> hiliteBackColor : $canvas-> backColor ;
65+
$canvas-> set( color => $fo, backColor => $bk );
66+
67+
}
68+
$self-> draw_item_background( $canvas, $x1, $y1, $x2, $y2, $prelight );
69+
$canvas->font->size( 25 );
70+
$dx //= ($ih - $canvas->font->width) / 2;
71+
$dy //= ($ih - $canvas->font->height) / 2 + $canvas->font->descent;
72+
$canvas->text_out(chr($glyphs[$index]) , $x1 + $dx, $y1 + $dy);
73+
$canvas->font->size( 8 );
74+
my $tx = sprintf("%x", $glyphs[$index] );
75+
$canvas-> text_out( $tx, $x1 + ( $x2 - $x1 - $canvas->get_text_width($tx)) / 2, $y1);
76+
$canvas-> set( color => $cs[0], backColor => $cs[1]) if $focused || $prelight;
77+
},
78+
)->count(scalar @glyphs);
79+
80+
run Prima;

0 commit comments

Comments
 (0)