]> mj.ucw.cz Git - anim.git/blob - AA/Gfx.pm
Ported to Gtk3
[anim.git] / AA / Gfx.pm
1 package AA::Background;
2
3 @ISA = ('AA');
4
5 sub new($$) {
6         my ($class, $id) = @_;
7         my $b = AA::new($class, $id);
8         $b->DefSet('d', 0);
9         $b->DefSet('color', [1, 1, 1]);
10         return $b;
11 }
12
13 sub Draw($$) {
14         my ($b, $cairo) = @_;
15         $cairo->select_font_face('URW Palladio L', 'normal', 'normal');         # default for all objs
16         $cairo->new_path;
17         $cairo->rectangle(0, 0, 1024, 768);
18         $cairo->set_source_rgb(@{$b->Get('color')});
19         $cairo->fill;
20 }
21
22 package AA::Label;
23
24 @ISA = ('AA');
25
26 sub new($$) {
27         my ($class, $id) = @_;
28         my $t = AA::new($class, $id);
29         $t->DefSet('d', 10);
30         $t->DefSet('x', 100);
31         $t->DefSet('y', 100);
32         $t->DefSet('color', [0, 0, 0]);
33         $t->DefSet('size', 12);
34         $t->DefSet('text', '');
35         return $t;
36 }
37
38 sub Draw($$) {
39         my ($t, $cairo) = @_;
40         my $text = $t->Get('text');
41         $cairo->set_source_rgb(@{$t->Get('color')});
42         $cairo->set_font_size($t->Get('size'));
43         my $xt = $cairo->text_extents($text);
44         $cairo->move_to($t->Get("x") - $xt->{'width'}/2 - $xt->{'x_bearing'},
45                         $t->Get("y") - $xt->{'height'}/2 - $xt->{'y_bearing'});
46         $cairo->show_text($text);
47 }
48
49 1;