… | |
… | |
285 | =cut |
285 | =cut |
286 | |
286 | |
287 | sub solid($;$$) { |
287 | sub solid($;$$) { |
288 | my $colour = pop; |
288 | my $colour = pop; |
289 | |
289 | |
290 | my $img = $self->new_img (urxvt::PictStandardARGB32, $_[0] || 1, $_[1] || 1); |
290 | my $img = $self->new_img (urxvt::PictStandardARGB32, 0, 0, $_[0] || 1, $_[1] || 1); |
291 | $img->fill ($colour); |
291 | $img->fill ($colour); |
292 | $img |
292 | $img |
293 | } |
293 | } |
294 | |
294 | |
295 | =item clone $img |
295 | =item clone $img |
… | |
… | |
306 | =item merge $img ... |
306 | =item merge $img ... |
307 | |
307 | |
308 | Takes any number of images and merges them together, creating a single |
308 | Takes any number of images and merges them together, creating a single |
309 | image containing them all. |
309 | image containing them all. |
310 | |
310 | |
|
|
311 | This function is called automatically when an expression returns multiple |
|
|
312 | images. |
|
|
313 | |
311 | =cut |
314 | =cut |
312 | |
315 | |
313 | sub merge(@) { |
316 | sub merge(@) { |
|
|
317 | return $_[0] unless $#_; |
|
|
318 | |
314 | # rather annoyingly clumsy, but optimisation is for another time |
319 | # rather annoyingly clumsy, but optimisation is for another time |
315 | |
320 | |
316 | my $x0 = 1e9; |
321 | my $x0 = +1e9; |
317 | my $y0 = 1e9; |
322 | my $y0 = +1e9; |
318 | my $x1 = -1e9; |
323 | my $x1 = -1e9; |
319 | my $y1 = -1e9; |
324 | my $y1 = -1e9; |
320 | |
325 | |
321 | for (@_) { |
326 | for (@_) { |
322 | my ($x, $y, $w, $h) = $_->geometry; |
327 | my ($x, $y, $w, $h) = $_->geometry; |
… | |
… | |
325 | $y0 = $y if $y0 > $y; |
330 | $y0 = $y if $y0 > $y; |
326 | |
331 | |
327 | $x += $w; |
332 | $x += $w; |
328 | $y += $h; |
333 | $y += $h; |
329 | |
334 | |
330 | $x1 = $x if $x1 > $x; |
335 | $x1 = $x if $x1 < $x; |
331 | $y1 = $y if $y1 > $y; |
336 | $y1 = $y if $y1 < $y; |
332 | } |
337 | } |
333 | |
338 | |
334 | my $base = $self->new_img ($x0, $y0, $x1 - $x0, $y1 - $y0); |
339 | my $base = $self->new_img (urxvt::PictStandardARGB32, $x0, $y0, $x1 - $x0, $y1 - $y0); |
335 | $base->fill ([0, 0, 0, 0]); |
340 | $base->fill ([0, 0, 0, 0]); |
336 | |
341 | |
337 | $base->blend (1., $_) |
342 | $base->draw ($_) |
338 | for @_; |
343 | for @_; |
339 | |
344 | |
340 | $base |
345 | $base |
341 | } |
346 | } |
342 | |
347 | |
… | |
… | |
697 | =cut |
702 | =cut |
698 | |
703 | |
699 | sub rotate($$$$) { |
704 | sub rotate($$$$) { |
700 | my $img = pop; |
705 | my $img = pop; |
701 | $img->rotate ( |
706 | $img->rotate ( |
702 | $_[0] * $img->w, |
707 | $_[0] * ($img->w + $img->x), |
703 | $_[1] * $img->h, |
708 | $_[1] * ($img->h + $img->y), |
704 | $_[2] * (3.14159265 / 180), |
709 | $_[2] * (3.14159265 / 180), |
705 | ) |
710 | ) |
706 | } |
711 | } |
707 | |
712 | |
708 | =back |
713 | =back |
… | |
… | |
905 | ($x, $y, $w, $h) = |
910 | ($x, $y, $w, $h) = |
906 | $self->background_geometry ($self->{border}); |
911 | $self->background_geometry ($self->{border}); |
907 | |
912 | |
908 | # evaluate user expression |
913 | # evaluate user expression |
909 | |
914 | |
910 | my $img = eval { $self->{expr}->() }; |
915 | my $img = eval { urxvt::bgdsl::merge $self->{expr}->() }; |
911 | warn $@ if $@;#d# |
916 | die $@ if $@; |
912 | die "background-expr did not return an image.\n" if !UNIVERSAL::isa $img, "urxvt::img"; |
917 | die "background-expr did not return an image.\n" if !UNIVERSAL::isa $img, "urxvt::img"; |
913 | |
918 | |
914 | # if the expression is sensitive to external events, prepare reevaluation then |
919 | # if the expression is sensitive to external events, prepare reevaluation then |
915 | |
920 | |
916 | my $again = delete $state->{again}; |
921 | my $again = delete $state->{again}; |