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 | |
196 | Tiles the whole plane with the image and returns this new image - or in |
198 | Tiles the whole plane with the image and returns this new image - or in |
197 | other words, it returns a copy of the image in plane tiling mode. |
199 | other words, it returns a copy of the image in plane tiling mode. |
198 | |
200 | |
|
|
201 | Example: load an image and tile it over the background, without |
|
|
202 | resizing. The C<tile> call is superfluous because C<load> already defaults |
|
|
203 | to tiling mode. |
|
|
204 | |
|
|
205 | tile load "mybg.png" |
|
|
206 | |
199 | =item mirror $img |
207 | =item mirror $img |
200 | |
208 | |
201 | Similar to tile, but reflects the image each time it uses a new copy, so |
209 | Similar to tile, but reflects the image each time it uses a new copy, so |
202 | that top edges always touch top edges, right edges always touch right |
210 | that top edges always touch top edges, right edges always touch right |
203 | edges and so on (with normal tiling, left edges always touch right edges |
211 | edges and so on (with normal tiling, left edges always touch right edges |
204 | and top always touch bottom edges). |
212 | and top always touch bottom edges). |
205 | |
213 | |
|
|
214 | Exmaple: load an image and mirror it over the background, avoiding sharp |
|
|
215 | edges 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 | |
208 | Takes an image and modifies it so that all pixels outside the image area |
221 | Takes an image and modifies it so that all pixels outside the image area |
209 | become transparent. This mode is most useful when you want to place an |
222 | become transparent. This mode is most useful when you want to place an |
210 | image over another image or the background colour while leaving all |
223 | image over another image or the background colour while leaving all |
211 | background pixels outside the image unchanged. |
224 | background pixels outside the image unchanged. |
212 | |
225 | |
|
|
226 | Example: load an image and display it in the upper left corner. The rets |
|
|
227 | of the space is left "empty" (transparent or wahtever your compisotr does |
|
|
228 | in alpha mode, else background colour). |
|
|
229 | |
|
|
230 | pad load "mybg.png" |
|
|
231 | |
213 | =item extend $img |
232 | =item extend $img |
214 | |
233 | |
215 | Extends the image over the whole plane, using the closest pixel in the |
234 | Extends the image over the whole plane, using the closest pixel in the |
216 | area outside the image. This mode is mostly useful when you more complex |
235 | area outside the image. This mode is mostly useful when you more complex |
217 | filtering operations and want the pixels outside the image to have the |
236 | filtering operations and want the pixels outside the image to have the |
218 | same values as the pixels near the edge. |
237 | same values as the pixels near the edge. |
|
|
238 | |
|
|
239 | Example: 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 | } |