File: fix-centered-text

package info (click to toggle)
libsdl-perl 2.548-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 5,904 kB
  • sloc: perl: 13,985; ansic: 582; makefile: 35
file content (46 lines) | stat: -rw-r--r-- 1,649 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Description: Fix centered text
 Centered text was off-center
Forwarded: yes, done
Author: dod
--- a/lib/SDLx/Text.pm
+++ b/lib/SDLx/Text.pm
@@ -344,16 +344,20 @@
 
         foreach my $i ( 0 .. $#{$surfaces}) {
             if (my $surface = $surfaces->[$i]) {
+                my $tx ;
                 $y += ($linebreaks * $surface->h);
                 $linebreaks = 0;
 
                 if ($self->{h_align} eq 'center' ) {
                     # $x = ($target->w / 2) - ($surface->w / 2);
-                    $x -= $surface->w / 2;
+                    $tx = $x + ($self->w -$surface->w) / 2;
                 }
                 elsif ($self->{h_align} eq 'right' ) {
                     # $x = $target->w - $surface->w;
-                    $x -= $surface->w;
+                    $tx = $x + $self->w - $surface->w;
+                }
+                else {
+                    $tx = $x ;
                 }
 
                 # blit the shadow
@@ -363,14 +367,14 @@
 
                     SDL::Video::blit_surface(
                        $shadow, SDL::Rect->new(0,0,$shadow->w, $shadow->h),
-                       $target, SDL::Rect->new($x + $offset, $y + $offset, 0, 0)
+                       $target, SDL::Rect->new($tx + $offset, $y + $offset, 0, 0)
                     );
                 }
 
                 # blit the text
                 SDL::Video::blit_surface(
                     $surface, SDL::Rect->new(0,0,$surface->w, $surface->h),
-                    $target, SDL::Rect->new($x, $y, 0, 0)
+                    $target, SDL::Rect->new($tx, $y, 0, 0)
                 );
             }
             $linebreaks++;