Debian Codegraph @

lib/Games/FrozenBubble/CStuff.pm

raw
1 package Games::FrozenBubble::CStuff;
2
3 use strict;
4 use vars qw(@ISA);
5 use Games::FrozenBubble;
6 use SDL::Pango;
7 use SDL::Pango::Context;
8 use Alien::SDL;
9
10 require DynaLoader;
11
12 @ISA = qw(DynaLoader);
13
14 # Dynaloader dark magic implemented by kmx, this is needed as we are
15 # using Alien::SDL and required dynamic libraries are saved in Alien::SDL's
16 # distribution share dir - therefore we need to load them explicitely
17 # for more details see SDL::Internal::Loader (code stolen from there)
18 my $shlib_map = Alien::SDL->config('ld_shlib_map');
19 if($shlib_map) {
20 foreach my $n (qw(SDL SDL_mixer)) {
21 my $file = $shlib_map->{$n};
22 next unless $file;
23 my $libref = DynaLoader::dl_load_file($file, 0);
24 push(@DynaLoader::dl_librefs, $libref) if $libref;
25 }
26 }
27
28 bootstrap Games::FrozenBubble::CStuff $Games::FrozenBubble::VERSION;
29
30 sub sdlpango_init{ SDL::Pango::init(); }
31 sub sdlpango_createcontext{
32 my $color = shift || '';
33 my $font_desc = shift;
34 my $context = SDL::Pango::Context->new($font_desc);
35
36
37 #context, fr, fg, fb, fa, br, bg, bb, ba
38 if ($color eq "white")
39 {
40 SDL::Pango::set_default_color($context, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00)
41 }
42 else
43 {
44 SDL::Pango::set_default_color($context, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00)
45 }
46
47 return $context;
48 }
49
50 sub sdlpango_getsize{
51 my $context = shift;
52 my $text = shift;
53 my $width = shift;
54
55 SDL::Pango::set_minimum_size($context, $width, 0);
56 SDL::Pango::set_text($context, $text, -1);
57 my $w = SDL::Pango::get_layout_width($context);
58 my $h = SDL::Pango::get_layout_height($context);
59
60 return [$w, $h];
61 }
62
63 sub sdlpango_draw{ return sdlpango_draw_givenalignment(shift, shift, shift, "left"); }
64 sub sdlpango_draw_givenalignment{
65 my $context = shift;
66 my $text = shift;
67 my $width = shift;
68 my $alignment = shift || '';
69 SDL::Pango::set_minimum_size($context, $width, 0);
70 SDL::Pango::set_text($context, $text, -1, $alignment eq "left" ? SDLPANGO_ALIGN_LEFT
71 : $alignment eq "center" ? SDLPANGO_ALIGN_CENTER
72 : SDLPANGO_ALIGN_RIGHT );
73 return SDL::Pango::create_surface_draw($context);
74 }
75
76 1;