… | |
… | |
202 | |
202 | |
203 | =back |
203 | =back |
204 | |
204 | |
205 | =cut |
205 | =cut |
206 | |
206 | |
207 | our %_IMGCACHE; |
207 | our %_IMG_CACHE; |
|
|
208 | our %_ONCE_CACHE; |
208 | our $HOME; |
209 | our $HOME; |
209 | our ($self, $old, $new); |
210 | our ($self, $old, $new); |
210 | our ($x, $y, $w, $h); |
211 | our ($x, $y, $w, $h); |
211 | |
212 | |
212 | # enforce at least this interval between updates |
213 | # enforce at least this interval between updates |
… | |
… | |
250 | |
251 | |
251 | =cut |
252 | =cut |
252 | |
253 | |
253 | sub root() { |
254 | sub root() { |
254 | $new->{rootpmap_sensitive} = 1; |
255 | $new->{rootpmap_sensitive} = 1; |
255 | die "root op not supported, exg, we need you"; |
256 | $self->new_img_from_root |
256 | } |
257 | } |
257 | |
258 | |
258 | =item solid $colour |
259 | =item solid $colour |
259 | |
260 | |
260 | =item solid $width, $height, $colour |
261 | =item solid $width, $height, $colour |
… | |
… | |
283 | =cut |
284 | =cut |
284 | |
285 | |
285 | sub clone($) { |
286 | sub clone($) { |
286 | $_[0]->clone |
287 | $_[0]->clone |
287 | } |
288 | } |
288 | |
|
|
289 | =back |
|
|
290 | |
289 | |
291 | =head2 TILING MODES |
290 | =head2 TILING MODES |
292 | |
291 | |
293 | The following operators modify the tiling mode of an image, that is, the |
292 | The following operators modify the tiling mode of an image, that is, the |
294 | way that pixels outside the image area are painted when the image is used. |
293 | way that pixels outside the image area are painted when the image is used. |
… | |
… | |
630 | |
629 | |
631 | sub rootalign($) { |
630 | sub rootalign($) { |
632 | move -TX, -TY, $_[0] |
631 | move -TX, -TY, $_[0] |
633 | } |
632 | } |
634 | |
633 | |
|
|
634 | =item rotate $center_x, $center_y, $degrees, $new_width, $new_height |
|
|
635 | |
|
|
636 | Rotates the image by C<$degrees> degrees, counter-clockwise, around the |
|
|
637 | pointer at C<$center_x> and C<$center_y> (specified as factor of image |
|
|
638 | width/height), generating a new image with width C<$new_width> and height |
|
|
639 | C<$new_height>. |
|
|
640 | |
|
|
641 | #TODO# new width, height, maybe more operators? |
|
|
642 | |
|
|
643 | Example: rotate the image by 90 degrees |
|
|
644 | |
|
|
645 | =cut |
|
|
646 | |
|
|
647 | sub rotate($$$$$$) { |
|
|
648 | my $img = pop; |
|
|
649 | $img->rotate ( |
|
|
650 | $_[0] * $img->w, |
|
|
651 | $_[1] * $img->h, |
|
|
652 | $_[2] * (3.14159265 / 180), |
|
|
653 | $_[3], |
|
|
654 | $_[4], |
|
|
655 | ) |
|
|
656 | } |
|
|
657 | |
635 | =back |
658 | =back |
636 | |
659 | |
637 | =head2 COLOUR MODIFICATIONS |
660 | =head2 COLOUR MODIFICATIONS |
638 | |
661 | |
639 | The following operators change the pixels of the image. |
662 | The following operators change the pixels of the image. |
… | |
… | |
721 | sub blur($$;$) { |
744 | sub blur($$;$) { |
722 | my $img = pop; |
745 | my $img = pop; |
723 | $img->blur ($_[0], @_ >= 2 ? $_[1] : $_[0]) |
746 | $img->blur ($_[0], @_ >= 2 ? $_[1] : $_[0]) |
724 | } |
747 | } |
725 | |
748 | |
726 | =item rotate $new_width, $new_height, $center_x, $center_y, $degrees |
749 | =back |
727 | |
750 | |
728 | Rotates the image by C<$degrees> degrees, counter-clockwise, around the |
751 | =head2 OTHER STUFF |
729 | pointer at C<$center_x> and C<$center_y> (specified as factor of image |
|
|
730 | width/height), generating a new image with width C<$new_width> and height |
|
|
731 | C<$new_height>. |
|
|
732 | |
752 | |
733 | #TODO# new width, height, maybe more operators? |
753 | Anything that didn't fit any of the other categories, even after appliyng |
|
|
754 | force and closing our eyes. |
734 | |
755 | |
735 | Example: rotate the image by 90 degrees |
756 | =over 4 |
736 | |
757 | |
737 | =cut |
758 | =item once { ... } |
738 | |
759 | |
739 | sub rotate($$$$$$) { |
760 | This function takes a code block as argument, that is, one or more |
740 | my $img = pop; |
761 | statements enclosed by braces. |
741 | $img->rotate ( |
762 | |
742 | $_[0], |
763 | The trick is that this code block is only evaluated once - future calls |
743 | $_[1], |
764 | will simply return the original image (yes, it should only be used with |
744 | $_[2] * $img->w, |
765 | images). |
745 | $_[3] * $img->h, |
766 | |
746 | $_[4] * (3.14159265 / 180), |
767 | This can be extremely useful to avoid redoign the same slow operations |
747 | ) |
768 | again and again- for example, if your background expression takes the root |
|
|
769 | background, blurs it and then root-aligns it it would have to blur the |
|
|
770 | root background on every window move or resize. |
|
|
771 | |
|
|
772 | Putting the blur into a C<once> block will make sure the blur is only done |
|
|
773 | once: |
|
|
774 | |
|
|
775 | rootlign once { blur 10, root } |
|
|
776 | |
|
|
777 | This leaves the question of how to force reevaluation of the block, in |
|
|
778 | case the root background changes: Right now, all once blocks forget that |
|
|
779 | they ahve been executed before each time the root background changes (if |
|
|
780 | the expression is sensitive to that) or when C<once_again> is called. |
|
|
781 | |
|
|
782 | =item once_again |
|
|
783 | |
|
|
784 | Resets all C<once> block as if they had never been called, i.e. on the |
|
|
785 | next call they will be reevaluated again. |
|
|
786 | |
|
|
787 | =cut |
|
|
788 | |
|
|
789 | sub once(&) { |
|
|
790 | $_ONCE_CACHE{$_[0]+0} ||= $_[0]() |
|
|
791 | } |
|
|
792 | |
|
|
793 | sub once_again() { |
|
|
794 | %_ONCE_CACHE = (); |
748 | } |
795 | } |
749 | |
796 | |
750 | =back |
797 | =back |
751 | |
798 | |
752 | =cut |
799 | =cut |