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.42 by root, Sun Jun 10 10:42:19 2012 UTC vs.
Revision 1.43 by root, Sun Jun 10 11:23:20 2012 UTC

99its result becomes the argument to the C<scale> function. 99its result becomes the argument to the C<scale> function.
100 100
101Many operators also allow some parameters preceding the input image 101Many operators also allow some parameters preceding the input image
102that modify its behaviour. For example, C<scale> without any additional 102that modify its behaviour. For example, C<scale> without any additional
103arguments scales the image to size of the terminal window. If you specify 103arguments scales the image to size of the terminal window. If you specify
104an additional argument, it uses it as a percentage: 104an additional argument, it uses it as a scale factor (multiply by 100 to
105get a percentage):
105 106
106 scale 200, load "$HOME/mypic.png" 107 scale 2, load "$HOME/mypic.png"
107 108
108This enlarges the image by a factor of 2 (200%). As you can see, C<scale> 109This enlarges the image by a factor of 2 (200%). As you can see, C<scale>
109has now two arguments, the C<200> and the C<load> expression, while 110has now two arguments, the C<200> and the C<load> expression, while
110C<load> only has one argument. Arguments are separated from each other by 111C<load> only has one argument. Arguments are separated from each other by
111commas. 112commas.
112 113
113Scale also accepts two arguments, which are then separate factors for both 114Scale also accepts two arguments, which are then separate factors for both
114horizontal and vertical dimensions. For example, this halves the image 115horizontal and vertical dimensions. For example, this halves the image
115width and doubles the image height: 116width and doubles the image height:
116 117
117 scale 50, 200, load "$HOME/mypic.png" 118 scale 0.5, 2, load "$HOME/mypic.png"
118 119
119Other effects than scalign are also readily available, for exmaple, you can 120Other effects than scalign are also readily available, for exmaple, you can
120tile the image to fill the whole window, instead of resizing it: 121tile the image to fill the whole window, instead of resizing it:
121 122
122 tile load "$HOME/mypic.png" 123 tile load "$HOME/mypic.png"
201# enforce at least this interval between updates 202# enforce at least this interval between updates
202our $MIN_INTERVAL = 1/100; 203our $MIN_INTERVAL = 1/100;
203 204
204{ 205{
205 package urxvt::bgdsl; # background language 206 package urxvt::bgdsl; # background language
207
208 use List::Util qw(min max sum shuffle);
206 209
207=head2 PROVIDERS/GENERATORS 210=head2 PROVIDERS/GENERATORS
208 211
209These functions provide an image, by loading it from disk, grabbing it 212These functions provide an image, by loading it from disk, grabbing it
210from the root screen or by simply generating it. They are used as starting 213from the root screen or by simply generating it. They are used as starting
479 $img->sub_rect ($_[0], $_[1], $w, $h) 482 $img->sub_rect ($_[0], $_[1], $w, $h)
480 } 483 }
481 484
482=item scale $img 485=item scale $img
483 486
484=item scale $size_percent, $img 487=item scale $size_factor, $img
485 488
486=item scale $width_percent, $height_percent, $img 489=item scale $width_factor, $height_factor, $img
487 490
488Scales the image by the given percentages in horizontal 491Scales the image by the given factors in horizontal
489(C<$width_percent>) and vertical (C<$height_percent>) direction. 492(C<$width>) and vertical (C<$height>) direction.
490 493
491If only one percentage is give, it is used for both directions. 494If only one factor is give, it is used for both directions.
492 495
493If no percentages are given, scales the image to the window size without 496If no factors are given, scales the image to the window size without
494keeping aspect. 497keeping aspect.
495 498
496=item resize $width, $height, $img 499=item resize $width, $height, $img
497 500
498Resizes the image to exactly C<$width> times C<$height> pixels. 501Resizes the image to exactly C<$width> times C<$height> pixels.
499 502
500=cut 503=item fit $img
501 504
502#TODO: maximise, maximise_fill? 505=item fit $width, $height, $img
506
507Fits the image into the given C<$width> and C<$height> without changing
508aspect, or the terminal size. That means it will be shrunk or grown until
509the whole image fits into the given area, possibly leaving borders.
510
511=item cover $img
512
513=item cover $width, $height, $img
514
515Similar to C<fit>, but shrinks or grows until all of the area is covered
516by the image, so instead of potentially leaving borders, it will cut off
517image data that doesn't fit.
518
519=cut
503 520
504 sub scale($;$;$) { 521 sub scale($;$;$) {
505 my $img = pop; 522 my $img = pop;
506 523
507 @_ == 2 ? $img->scale ($_[0] * $img->w * 0.01, $_[1] * $img->h * 0.01) 524 @_ == 2 ? $img->scale ($_[0] * $img->w, $_[1] * $img->h)
508 : @_ ? $img->scale ($_[0] * $img->w * 0.01, $_[0] * $img->h * 0.01) 525 : @_ ? $img->scale ($_[0] * $img->w, $_[0] * $img->h)
509 : $img->scale (TW, TH) 526 : $img->scale (TW, TH)
510 } 527 }
511 528
512 sub resize($$$) { 529 sub resize($$$) {
513 my $img = pop; 530 my $img = pop;
514 $img->scale ($_[0], $_[1]) 531 $img->scale ($_[0], $_[1])
532 }
533
534 sub fit($;$$) {
535 my $img = pop;
536 my $w = ($_[0] || TW) / $img->w;
537 my $h = ($_[1] || TH) / $img->h;
538 scale +(min $w, $h), $img
539 }
540
541 sub cover($;$$) {
542 my $img = pop;
543 my $w = ($_[0] || TW) / $img->w;
544 my $h = ($_[1] || TH) / $img->h;
545 scale +(max $w, $h), $img
515 } 546 }
516 547
517=item move $dx, $dy, $img 548=item move $dx, $dy, $img
518 549
519Moves the image by C<$dx> pixels in the horizontal, and C<$dy> pixels in 550Moves the image by C<$dx> pixels in the horizontal, and C<$dy> pixels in
615 } 646 }
616 647
617=item rotate $new_width, $new_height, $center_x, $center_y, $degrees 648=item rotate $new_width, $new_height, $center_x, $center_y, $degrees
618 649
619Rotates the image by C<$degrees> degrees, counter-clockwise, around the 650Rotates the image by C<$degrees> degrees, counter-clockwise, around the
620pointer at C<$center_x> and C<$center_y> (specified as percentage of image 651pointer at C<$center_x> and C<$center_y> (specified as factor of image
621width/height), generating a new image with width C<$new_width> and height 652width/height), generating a new image with width C<$new_width> and height
622C<$new_height>. 653C<$new_height>.
623 654
624#TODO# new width, height, maybe more operators? 655#TODO# new width, height, maybe more operators?
625 656
630 sub rotate($$$$$$) { 661 sub rotate($$$$$$) {
631 my $img = pop; 662 my $img = pop;
632 $img->rotate ( 663 $img->rotate (
633 $_[0], 664 $_[0],
634 $_[1], 665 $_[1],
635 $_[2] * $img->w * .01, 666 $_[2] * $img->w,
636 $_[3] * $img->h * .01, 667 $_[3] * $img->h,
637 $_[4] * (3.14159265 / 180), 668 $_[4] * (3.14159265 / 180),
638 ) 669 )
639 } 670 }
640 671
641=back 672=back

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines