1 package HTML5TV::Slides;
11 use Data::Dump qw/dump/;
15 my $current_slide = shift || die "need current slide coderef!";
18 current_slide => $current_slide,
25 $self->{current_slide}->( shift );
36 my $n_a = $1 if $a =~ m{(\d+)};
37 my $n_b = $1 if $b =~ m{(\d+)};
38 $n_a <=> $n_b || $a cmp $b
39 } glob("media/_editing/s/1/*")
42 my $slide = SDL::Surface->new( -name => $slide_paths[0] );
43 my $w = $slide->width;
44 my $h = $slide->height;
46 my @factors = ( qw/ 4 4 4 4 1 2 2 4 4 4 4 / );
48 my ( $x, $y ) = ( 0, 0 );
50 my $background = SDL::Color->new( -r => 0, -g => 0, -b => 0 );
51 my $overlay_color = SDL::Color->new( -r => 0xff, -g => 0xff, -b => 0x88 );
53 foreach my $i ( 0 .. $#factors ) {
55 my $factor = $factors[$i] || die "no factor $i in ",dump @factors;
57 my $to = SDL::Rect->new(
58 -width => $w / $factor,
59 -height => $h / $factor,
64 my $pos = $self->current_slide($t) + $i - 5;
65 my $path = $slide_paths[ $pos ];
67 if ( $pos < 0 || ! $path ) {
69 $self->{app}->fill( $to, $background ) if $self->{app};
73 $path =~ s{/s/[124]/(\D*(\d+))}{/s/$factor/$1};
76 my $slide = SDL::Surface->new( -name => $path );
78 my $subtitle_text = $nr;
79 foreach my $s ( @subtitles ) {
80 if ( $s->[2] =~ m/\[(\d+)\]/ && $1 == $nr ) {
81 $subtitle_text = $s->[2];
86 my $font = SDL::Tool::Font->new(
88 -ttfont => 'media/slides.ttf', # FIXME
89 -size => 40 / $factor,
93 $font->print( $slide, 4, 4, $subtitle_text );
94 $font->print( $slide, 4, 6, $subtitle_text );
95 $font->print( $slide, 6, 4, $subtitle_text );
96 $font->print( $slide, 6, 6, $subtitle_text );
97 $font->print( $slide, 5, 5, $subtitle_text );
101 -ttfont => 'media/slides.ttf', # FIXME
102 -size => 40 / $factor,
103 -fg => $overlay_color,
105 )->print( $slide, 5, 5, $subtitle_text );
107 my $rect = SDL::Rect->new(
108 -width => $slide->width(),
109 -height => $slide->height(),
114 # warn "$x $y $path\n";
116 if ( ! $self->{app} ) {
118 $self->{app} = SDL::App->new(
120 -height => ( $h * 2 ) + 20,
127 $slide->blit( $rect, $self->{app}, $to );
131 $self->{app}->update( $to ) if $self->{app};
143 if ( $self->{app} ) {
147 my $w_1s = $w / $length;
150 my $y_bar = int( $h / 4 ) + 1;
152 my $bar_back = SDL::Color->new( -r => 0, -g => 0, -b => 0 );
153 my $rect = SDL::Rect->new(
160 $self->{app}->fill( $rect, $bar_back );
161 # $self->{app}->update( $rect );
163 my $col_slide = SDL::Color->new( -r => 0xcc, -g => 0xcc, -b => 0x00 );
164 my $col_subtitle = SDL::Color->new( -r => 0xcc, -g => 0x00, -b => 0x00 );
165 my $col_pos = SDL::Color->new( -r => 0xff, -g => 0xff, -b => 0xff );
168 foreach my $s ( @subtitles ) {
170 next unless defined $s->[0];
172 my $s_x = int( $s->[0] * $w_1s + 0.9 );
173 my $s_w = int( abs( $s->[1] - $s->[0] ) * $w_1s );
174 $s_w = 1 if $s_w < 1;
176 # warn "$s_x $s_w ", $s->[2];
178 my $rect = SDL::Rect->new(
184 $self->{app}->fill( $rect, $s->[2] =~ m/\[\d+\]/ ? $col_slide : $col_subtitle );
185 # $self->{app}->update( $rect );
188 my $rect = SDL::Rect->new(
191 -x => int( $t * $w_1s - $bar_h / 2 ),
194 $self->{app}->fill( $rect, $col_pos );
195 # $self->{app}->update( $rect );