ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/background
(Generate patch)

Comparing rxvt-unicode/src/perl/background (file contents):
Revision 1.33 by root, Thu Jun 7 16:30:58 2012 UTC vs.
Revision 1.35 by root, Fri Jun 8 08:06:38 2012 UTC

1#! perl 1#! perl
2 2
3#:META:X_RESOURCE:%.expr:string:background expression 3#:META:X_RESOURCE:%.expr:string:background expression
4#:META:X_RESOURCE:%.border.:boolean:respect the terminal border 4#:META:X_RESOURCE:%.border.:boolean:respect the terminal border
5
6#TODO: once, rootalign
5 7
6=head1 background - manage terminal background 8=head1 background - manage terminal background
7 9
8=head2 SYNOPSIS 10=head2 SYNOPSIS
9 11
194=item tile $img 196=item tile $img
195 197
196Tiles the whole plane with the image and returns this new image - or in 198Tiles the whole plane with the image and returns this new image - or in
197other words, it returns a copy of the image in plane tiling mode. 199other words, it returns a copy of the image in plane tiling mode.
198 200
201Example: load an image and tile it over the background, without
202resizing. The C<tile> call is superfluous because C<load> already defaults
203to tiling mode.
204
205 tile load "mybg.png"
206
199=item mirror $img 207=item mirror $img
200 208
201Similar to tile, but reflects the image each time it uses a new copy, so 209Similar to tile, but reflects the image each time it uses a new copy, so
202that top edges always touch top edges, right edges always touch right 210that top edges always touch top edges, right edges always touch right
203edges and so on (with normal tiling, left edges always touch right edges 211edges and so on (with normal tiling, left edges always touch right edges
204and top always touch bottom edges). 212and top always touch bottom edges).
205 213
214Exmaple: load an image and mirror it over the background, avoiding sharp
215edges at the image borders at the expense of mirroring the image itself
216
217 mirror load "mybg.png"
218
206=item pad $img 219=item pad $img
207 220
208Takes an image and modifies it so that all pixels outside the image area 221Takes an image and modifies it so that all pixels outside the image area
209become transparent. This mode is most useful when you want to place an 222become transparent. This mode is most useful when you want to place an
210image over another image or the background colour while leaving all 223image over another image or the background colour while leaving all
211background pixels outside the image unchanged. 224background pixels outside the image unchanged.
212 225
226Example: load an image and display it in the upper left corner. The rets
227of the space is left "empty" (transparent or wahtever your compisotr does
228in alpha mode, else background colour).
229
230 pad load "mybg.png"
231
213=item extend $img 232=item extend $img
214 233
215Extends the image over the whole plane, using the closest pixel in the 234Extends the image over the whole plane, using the closest pixel in the
216area outside the image. This mode is mostly useful when you more complex 235area outside the image. This mode is mostly useful when you more complex
217filtering operations and want the pixels outside the image to have the 236filtering operations and want the pixels outside the image to have the
218same values as the pixels near the edge. 237same values as the pixels near the edge.
238
239Example: just for curiosity, how does this pixel extension stuff work?
240
241 extend move 50, 50, load "mybg.png"
219 242
220=cut 243=cut
221 244
222 sub pad($) { 245 sub pad($) {
223 my $img = $_[0]->clone; 246 my $img = $_[0]->clone;
421 444
422 my $img = eval { $self->{expr}->() }; 445 my $img = eval { $self->{expr}->() };
423 warn $@ if $@;#d# 446 warn $@ if $@;#d#
424 die if !UNIVERSAL::isa $img, "urxvt::img"; 447 die if !UNIVERSAL::isa $img, "urxvt::img";
425 448
449 $state->{size_sensitive} = 1
450 if $img->repeat_mode != urxvt::RepeatNormal;
451
426 # if the expression is sensitive to external events, prepare reevaluation then 452 # if the expression is sensitive to external events, prepare reevaluation then
427 453
428 my $repeat; 454 my $repeat;
429 455
430 if (my $again = $state->{again}) { 456 if (my $again = $state->{again}) {
431 $repeat = 1; 457 $repeat = 1;
458 my $self = $self;
432 $state->{timer} = $again == $old->{again} 459 $state->{timer} = $again == $old->{again}
433 ? $old->{timer} 460 ? $old->{timer}
434 : urxvt::timer->new->after ($again)->interval ($again)->cb (sub { 461 : urxvt::timer->new->after ($again)->interval ($again)->cb (sub {
435 ++$self->{counter}; 462 ++$self->{counter};
436 $self->recalculate 463 $self->recalculate
465 unless ($repeat) { 492 unless ($repeat) {
466 delete $self->{state}; 493 delete $self->{state};
467 delete $self->{expr}; 494 delete $self->{expr};
468 } 495 }
469 496
470 # prepare and set background pixmap 497 # set background pixmap
471
472 $img = $img->sub_rect (0, 0, $w, $h)
473 if $img->w != $w || $img->h != $h;
474 498
475 $self->set_background ($img, $self->{border}); 499 $self->set_background ($img, $self->{border});
476 $self->scr_recolour (0); 500 $self->scr_recolour (0);
477 $self->want_refresh; 501 $self->want_refresh;
478} 502}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines