Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed centered text display #229

Closed
wants to merge 1 commit into from

2 participants

Dominique Dumont Jeffrey T. Palmer
Dominique Dumont
Collaborator

Display of centered text was wrong: the first line was drawn offcenter on
the left. Each consecutive line was drawn even more on the left.

Like that:

Hello

world

This patch fixes the centered text.

Dominique Dumont dod38fr Display of centered text was wrong: the first line was drawn offcente…
…r on

the left. Each consecutive line was drawn even more on the left.

Like that:

    Hello
  world

This patch fixes the centered text.
dcc1fc1
Jeffrey T. Palmer
Owner

Merged into experimental.

Jeffrey T. Palmer jtpalmer closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 27, 2012
  1. Dominique Dumont

    Display of centered text was wrong: the first line was drawn offcente…

    dod38fr authored
    …r on
    
    the left. Each consecutive line was drawn even more on the left.
    
    Like that:
    
        Hello
      world
    
    This patch fixes the centered text.
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 4 deletions.
  1. +8 −4 lib/SDLx/Text.pm
12 lib/SDLx/Text.pm
View
@@ -342,16 +342,20 @@ sub write_xy {
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
@@ -361,14 +365,14 @@ sub write_xy {
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++;
Something went wrong with that request. Please try again.