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.44 by root, Sun Jun 10 11:31:22 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
520the vertical. 551the vertical.
521 552
522Example: move the image right by 20 pixels and down by 30. 553Example: move the image right by 20 pixels and down by 30.
523 554
524 move 20, 30, ... 555 move 20, 30, ...
556
557=item center $img
558
559=item center $width, $height, $img
560
561Centers the image, i.e. the center of the image is moved to the center of
562the terminal window (or the box specified by C<$width> and C<$height> if
563given).
525 564
526=item rootalign $img 565=item rootalign $img
527 566
528Moves the image so that it appears glued to the screen as opposed to the 567Moves the image so that it appears glued to the screen as opposed to the
529window. This gives the illusion of a larger area behind the window. It is 568window. This gives the illusion of a larger area behind the window. It is
545 my $img = pop->clone; 584 my $img = pop->clone;
546 $img->move ($_[0], $_[1]); 585 $img->move ($_[0], $_[1]);
547 $img 586 $img
548 } 587 }
549 588
589 sub center($;$$) {
590 my $img = pop;
591 my $w = $_[0] || TW;
592 my $h = $_[0] || TH;
593
594 move 0.5 * ($w - $img->w), 0.5 * ($h - $img->h), $img
595 }
596
550 sub rootalign($) { 597 sub rootalign($) {
551 move -TX, -TY, $_[0] 598 move -TX, -TY, $_[0]
552 } 599 }
553 600
554=item contrast $factor, $img 601=item contrast $factor, $img
615 } 662 }
616 663
617=item rotate $new_width, $new_height, $center_x, $center_y, $degrees 664=item rotate $new_width, $new_height, $center_x, $center_y, $degrees
618 665
619Rotates the image by C<$degrees> degrees, counter-clockwise, around the 666Rotates the image by C<$degrees> degrees, counter-clockwise, around the
620pointer at C<$center_x> and C<$center_y> (specified as percentage of image 667pointer 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 668width/height), generating a new image with width C<$new_width> and height
622C<$new_height>. 669C<$new_height>.
623 670
624#TODO# new width, height, maybe more operators? 671#TODO# new width, height, maybe more operators?
625 672
630 sub rotate($$$$$$) { 677 sub rotate($$$$$$) {
631 my $img = pop; 678 my $img = pop;
632 $img->rotate ( 679 $img->rotate (
633 $_[0], 680 $_[0],
634 $_[1], 681 $_[1],
635 $_[2] * $img->w * .01, 682 $_[2] * $img->w,
636 $_[3] * $img->h * .01, 683 $_[3] * $img->h,
637 $_[4] * (3.14159265 / 180), 684 $_[4] * (3.14159265 / 180),
638 ) 685 )
639 } 686 }
640 687
641=back 688=back

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines