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.20 by root, Wed Jun 6 22:01:45 2012 UTC vs.
Revision 1.30 by root, Thu Jun 7 13:22:06 2012 UTC

2 2
3#:META:X_RESOURCE:%.expr:string:background expression 3#:META:X_RESOURCE:%.expr:string:background expression
4#:META:X_RESOURCE:%.enable:boolean:some boolean 4#:META:X_RESOURCE:%.enable:boolean:some boolean
5#:META:X_RESOURCE:%.extra.:value:extra config 5#:META:X_RESOURCE:%.extra.:value:extra config
6 6
7our $EXPR;
8#$EXPR = 'move W * 0.1, -H * 0.1, resize W * 0.5, H * 0.5, repeat_none load "opensource.png"';
7our $EXPR = 'move X, Y, load "MagnoliaAlpha.png"'; 9$EXPR = 'move -TX, -TY, load "argb.png"';
8#$EXPR = ' 10#$EXPR = '
9# rotate W, H, 50, 50, counter 1/59.95, repeat_mirror, 11# rotate W, H, 50, 50, counter 1/59.95, repeat_mirror,
10# clip X, Y, W, H, repeat_mirror, 12# clip X, Y, W, H, repeat_mirror,
11# load "/root/pix/das_fette_schwein.jpg" 13# load "/root/pix/das_fette_schwein.jpg"
12#'; 14#';
16#resize load "/root/pix/das_fette_schwein.jpg", w, h 18#resize load "/root/pix/das_fette_schwein.jpg", w, h
17 19
18use Safe; 20use Safe;
19 21
20our ($bgdsl_self, $old, $new); 22our ($bgdsl_self, $old, $new);
21our ($l, $t, $w, $h); 23our ($x, $y, $w, $h);
22 24
23# enforce at least this interval between updates 25# enforce at least this interval between updates
24our $MIN_INTERVAL = 1/100; 26our $MIN_INTERVAL = 1/100;
25 27
26{ 28{
27 package urxvt::bgdsl; # background language 29 package urxvt::bgdsl; # background language
28 30
29# *repeat_empty = \&urxvt::RepeatNone;
30# *repeat_tile = \&urxvt::RepeatNormal;
31# *repeat_pad = \&urxvt::RepeatPad;
32# *repeat_mirror = \&urxvt::RepeatReflect;
33
34=head2 PROVIDERS/GENERATORS 31=head2 PROVIDERS/GENERATORS
35 32
36=over 4 33=over 4
37 34
38=item load $path 35=item load $path
36
37Loads the image at the given C<$path>. The image is set to plane tiling
38mode.
39
40
39 41
40=cut 42=cut
41 43
42 sub load($) { 44 sub load($) {
43 my ($path) = @_; 45 my ($path) = @_;
62 64
63=over 4 65=over 4
64 66
65=cut 67=cut
66 68
67 sub X() { $new->{position_sensitive} = 1; $l } 69 sub TX() { $new->{position_sensitive} = 1; $x }
68 sub Y() { $new->{position_sensitive} = 1; $t } 70 sub TY() { $new->{position_sensitive} = 1; $y }
69 sub W() { $new->{size_sensitive} = 1; $w } 71 sub TW() { $new->{size_sensitive} = 1; $w }
70 sub H() { $new->{size_sensitive} = 1; $h } 72 sub TH() { $new->{size_sensitive} = 1; $h }
71 73
72 sub now() { urxvt::NOW } 74 sub now() { urxvt::NOW }
73 75
74 sub again($) { 76 sub again($) {
75 $new->{again} = $_[0]; 77 $new->{again} = $_[0];
80 $bgdsl_self->{counter} + 0 82 $bgdsl_self->{counter} + 0
81 } 83 }
82 84
83=back 85=back
84 86
85=head2 OPERATORS 87=head2 TILING MODES
88
89The following operators modify the tiling mode of an image, that is, the
90way that pixels outside the image area are painted when the image is used.
86 91
87=over 4 92=over 4
88 93
89=cut 94=item tile $img
90 95
96Tiles the whole plane with the image and returns this new image - or in
97other words, it returns a copy of the image in plane tiling mode.
98
99=item mirror $img
100
101Similar to tile, but reflects the image each time it uses a new copy, so
102that top edges always touch top edges, right edges always touch right
103edges and so on (with normal tiling, left edges always touch right edges
104and top always touch bottom edges).
105
106=item pad $img
107
108Takes an image and modifies it so that all pixels outside the image area
109become transparent. This mode is most useful when you want to place an
110image over another image or the background colour while leaving all
111background pixels outside the image unchanged.
112
113=item extend $img
114
115Extends the image over the whole plane, using the closest pixel in the
116area outside the image. This mode is mostly useful when you more complex
117filtering operations and want the pixels outside the image to have the
118same values as the pixels near the edge.
119
120=cut
121
122 sub pad($) {
123 my $img = $_[0]->clone;
124 $img->repeat_mode (urxvt::RepeatNone);
125 $img
126 }
127
128 sub tile($) {
129 my $img = $_[0]->clone;
130 $img->repeat_mode (urxvt::RepeatNormal);
131 $img
132 }
133
134 sub mirror($) {
135 my $img = $_[0]->clone;
136 $img->repeat_mode (urxvt::RepeatReflect);
137 $img
138 }
139
140 sub extend($) {
141 my $img = $_[0]->clone;
142 $img->repeat_mode (urxvt::RepeatPad);
143 $img
144 }
145
146=back
147
148=head2 PIXEL OPERATORS
149
150The following operators modify the image pixels in various ways.
151
152=over 4
153
154=item clone $img
155
156Returns an exact copy of the image.
157
158=cut
159
91# sub clone($) { 160 sub clone($) {
92# $_[0]->clone 161 $_[0]->clone
93# } 162 }
163
164=item clip $img
165
166=item clip $width, $height, $img
167
168=item clip $x, $y, $width, $height, $img
169
170Clips an image to the given rectangle. If the rectangle is outside the
171image area (e.g. when C<$x> or C<$y> are negative) or the rectangle is
172larger than the image, then the tiling mode defines how the extra pixels
173will be filled.
174
175If C<$x> an C<$y> are missing, then C<0> is assumed for both.
176
177If C<$width> and C<$height> are missing, then the window size will be
178assumed.
179
180Example: load an image, blur it, and clip it to the window size to save
181memory.
182
183 clip blur 10, load "mybg.png"
184
185=cut
94 186
95 sub clip($;$$;$$) { 187 sub clip($;$$;$$) {
96 my $img = pop; 188 my $img = pop;
189 my $h = pop || TH;
190 my $w = pop || TW;
97 $img->sub_rect ($_[0], $_[1], $_[2] || W, $_[3] || H) 191 $img->sub_rect ($_[0], $_[1], $w, $h)
192 }
193
194=item scale $img
195
196=item scale $size_percent, $img
197
198=item scale $width_percent, $height_percent, $img
199
200Scales the image by the given percentages in horizontal
201(C<$width_percent>) and vertical (C<$height_percent>) direction.
202
203If only one percentage is give, it is used for both directions.
204
205If no percentages are given, scales the image to the window size without
206keeping aspect.
207
208=item resize $width, $height, $img
209
210Resizes the image to exactly C<$width> times C<$height> pixels.
211
212=cut
213
214#TODO: maximise, maximise_fill?
215
216 sub scale($$$) {
217 my $img = pop;
218
219 @_ == 2 ? $img->scale ($_[0] * $img->w * 0.01, $_[1] * $img->h * 0.01)
220 : @_ ? $img->scale ($_[0] * $img->w * 0.01, $_[0] * $img->h * 0.01)
221 : $img->scale (TW, TH)
98 } 222 }
99 223
100 sub resize($$$) { 224 sub resize($$$) {
101 my $img = pop; 225 my $img = pop;
102 $img->scale ($_[0], $_[1]) 226 $img->scale ($_[0], $_[1])
103 } 227 }
104 228
105 # TODO: ugly
106 sub move($$;$) { 229 sub move($$;$) {
107 my $img = pop->clone; 230 my $img = pop->clone;
108 $img->move ($_[0], $_[1]); 231 $img->move ($_[0], $_[1]);
109 $img 232 $img
110# my $img = pop;
111# $img->sub_rect (
112# $_[0], $_[1],
113# $img->w, $img->h,
114# $_[2],
115# )
116 } 233 }
117 234
118 sub rotate($$$$$$) { 235 sub rotate($$$$$$) {
119 my $img = pop; 236 my $img = pop;
120 $img->rotate ( 237 $img->rotate (
124 $_[3] * $img->h * .01, 241 $_[3] * $img->h * .01,
125 $_[4] * (3.14159265 / 180), 242 $_[4] * (3.14159265 / 180),
126 ) 243 )
127 } 244 }
128 245
129 sub blur($$$) { 246 sub blur($$;$) {
130 my ($rh, $rv, $img) = @_; 247 my $img = pop;
131 248 $img->blur ($_[0], @_ >= 2 ? $_[1] : $_[0])
132 $img->blur ($rh, $rv);
133 } 249 }
134 250
135 sub contrast($$;$$;$) { 251 sub contrast($$;$$;$) {
136 my $img = pop; 252 my $img = pop;
137 my ($r, $g, $b, $a) = @_; 253 my ($r, $g, $b, $a) = @_;
196 local $bgdsl_self = $self; 312 local $bgdsl_self = $self;
197 313
198 local $old = $self->{state}; 314 local $old = $self->{state};
199 local $new = my $state = $self->{state} = {}; 315 local $new = my $state = $self->{state} = {};
200 316
317 my $border = 0; #d#
318
201 ($l, $t, $w, $h) = 319 ($x, $y, $w, $h) =
202 $self->get_geometry; 320 $self->background_geometry ($border);
203 321
204 # evaluate user expression 322 # evaluate user expression
205 323
206 my $img = eval { $self->{expr}->() }; 324 my $img = eval { $self->{expr}->() };
207 warn $@ if $@;#d# 325 warn $@ if $@;#d#
254 # prepare and set background pixmap 372 # prepare and set background pixmap
255 373
256 $img = $img->sub_rect (0, 0, $w, $h) 374 $img = $img->sub_rect (0, 0, $w, $h)
257 if $img->w != $w || $img->h != $h; 375 if $img->w != $w || $img->h != $h;
258 376
259 $self->set_background ($img); 377 $self->set_background ($img, $border);
260 $self->scr_recolour (0); 378 $self->scr_recolour (0);
261 $self->want_refresh; 379 $self->want_refresh;
262} 380}
263 381
264sub on_start { 382sub on_start {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines