ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/background.C
(Generate patch)

Comparing rxvt-unicode/src/background.C (file contents):
Revision 1.157 by sf-exg, Tue Aug 9 21:48:00 2011 UTC vs.
Revision 1.164 by sf-exg, Sun Aug 14 22:01:25 2011 UTC

46 * W and H are percentages of the terminal window size. 46 * W and H are percentages of the terminal window size.
47 * X and Y are also percentages; e.g., +50+50 centers 47 * X and Y are also percentages; e.g., +50+50 centers
48 * the image in the window. 48 * the image in the window.
49 * 49 *
50 * Pixmap Operations : (should be prepended by a colon) 50 * Pixmap Operations : (should be prepended by a colon)
51 * tile Tile image. Scaling/position modifiers above will affect
52 * the tile size and origin.
53 * propscale When scaling, scale proportionally. That is, maintain the
54 * proper aspect ratio for the image. Any portion of the
55 * background not covered by the image is filled with the
56 * current background color.
57 * hscale Scale horizontally, tile vertically ?
58 * vscale Tile horizontally, scale vertically ?
59 * scale Scale both up and down
60 */ 51 */
61 52
62#ifdef HAVE_BG_PIXMAP 53#ifdef HAVE_BG_PIXMAP
63void 54void
64rxvt_term::bg_destroy () 55rxvt_term::bg_destroy ()
206{ 197{
207 bool changed = false; 198 bool changed = false;
208 int geom_flags = 0; 199 int geom_flags = 0;
209 int x = 0, y = 0; 200 int x = 0, y = 0;
210 unsigned int w = 0, h = 0; 201 unsigned int w = 0, h = 0;
211 unsigned int n;
212 unsigned long new_flags = (bg_flags & (~BG_GEOMETRY_FLAGS)); 202 unsigned long new_flags = (bg_flags & (~BG_GEOMETRY_FLAGS));
213 const char *ops;
214 203
215 if (geom == NULL) 204 if (geom == NULL)
216 return false; 205 return false;
217 206
218 char str[256]; 207 if (geom[0])
219
220 ops = strchr (geom, ':');
221 if (ops == NULL)
222 n = strlen (geom);
223 else
224 n = ops - geom;
225
226 if (n >= sizeof (str))
227 return false;
228
229 memcpy (str, geom, n);
230 str[n] = '\0';
231 rxvt_strtrim (str);
232
233 if (str[0])
234 { 208 {
235 /* we have geometry string - let's handle it prior to applying ops */ 209 char **arr = rxvt_strsplit (':', geom);
210
211 for (int i = 0; arr[i]; i++)
212 {
213 if (!strcasecmp (arr[i], "style=tiled"))
214 {
215 new_flags = BG_TILE;
216 w = h = noScale;
217 x = y = 0;
218 geom_flags = WidthValue|HeightValue|XValue|YValue;
219 }
220 else if (!strcasecmp (arr[i], "style=aspect-stretched"))
221 {
222 new_flags = BG_PROP_SCALE;
223 w = h = windowScale;
224 x = y = centerAlign;
225 geom_flags = WidthValue|HeightValue|XValue|YValue;
226 }
227 else if (!strcasecmp (arr[i], "style=stretched"))
228 {
229 new_flags = 0;
230 w = h = windowScale;
231 geom_flags = WidthValue|HeightValue;
232 }
233 else if (!strcasecmp (arr[i], "style=centered"))
234 {
235 new_flags = 0;
236 w = h = noScale;
237 x = y = centerAlign;
238 geom_flags = WidthValue|HeightValue|XValue|YValue;
239 }
240 else if (!strcasecmp (arr[i], "style=root-tiled"))
241 {
242 new_flags = BG_TILE|BG_ROOT_ALIGN;
243 w = h = noScale;
244 geom_flags = WidthValue|HeightValue;
245 }
246 else if (!strcasecmp (arr[i], "op=tile"))
247 new_flags |= BG_TILE;
248 else if (!strcasecmp (arr[i], "op=pscale"))
249 new_flags |= BG_PROP_SCALE;
250 else if (!strcasecmp (arr[i], "op=root"))
251 new_flags |= BG_ROOT_ALIGN;
252
253 // deprecated
254 else if (!strcasecmp (arr[i], "tile"))
255 {
256 new_flags |= BG_TILE;
257 w = h = noScale;
258 geom_flags |= WidthValue|HeightValue;
259 }
260 else if (!strcasecmp (arr[i], "propscale"))
261 {
262 new_flags |= BG_PROP_SCALE;
263 }
264 else if (!strcasecmp (arr[i], "hscale"))
265 {
266 new_flags |= BG_TILE;
267 w = windowScale;
268 h = noScale;
269 geom_flags |= WidthValue|HeightValue;
270 }
271 else if (!strcasecmp (arr[i], "vscale"))
272 {
273 new_flags |= BG_TILE;
274 h = windowScale;
275 w = noScale;
276 geom_flags |= WidthValue|HeightValue;
277 }
278 else if (!strcasecmp (arr[i], "scale"))
279 {
280 w = h = windowScale;
281 geom_flags |= WidthValue|HeightValue;
282 }
283 else if (!strcasecmp (arr[i], "auto"))
284 {
285 w = h = windowScale;
286 x = y = centerAlign;
287 geom_flags |= WidthValue|HeightValue|XValue|YValue;
288 }
289 else if (!strcasecmp (arr[i], "root"))
290 {
291 new_flags |= BG_TILE|BG_ROOT_ALIGN;
292 w = h = noScale;
293 geom_flags |= WidthValue|HeightValue;
294 }
295
296 else
236 geom_flags = XParseGeometry (str, &x, &y, &w, &h); 297 geom_flags |= XParseGeometry (arr[i], &x, &y, &w, &h);
237 } /* done parsing geometry string */ 298 } /* done parsing ops */
299
300 rxvt_free_strsplit (arr);
301 }
238 302
239 if (!update) 303 if (!update)
240 { 304 {
241 if (!(geom_flags & XValue)) 305 if (!(geom_flags & XValue))
242 x = y = defaultAlign; 306 x = y = defaultAlign;
251 w = h; 315 w = h;
252 316
253 geom_flags |= WidthValue|HeightValue|XValue|YValue; 317 geom_flags |= WidthValue|HeightValue|XValue|YValue;
254 } 318 }
255 319
256 if (ops)
257 {
258 char **arr = rxvt_strsplit (':', ops + 1);
259
260 for (int i = 0; arr[i]; i++)
261 {
262 if (!strcasecmp (arr[i], "tile"))
263 {
264 new_flags |= BG_TILE;
265 w = h = noScale;
266 geom_flags |= WidthValue|HeightValue;
267 }
268 else if (!strcasecmp (arr[i], "propscale"))
269 {
270 new_flags |= BG_PROP_SCALE;
271 }
272 else if (!strcasecmp (arr[i], "hscale"))
273 {
274 if (w == 0) w = windowScale;
275
276 h = noScale;
277 geom_flags |= WidthValue|HeightValue;
278 }
279 else if (!strcasecmp (arr[i], "vscale"))
280 {
281 if (h == 0) h = windowScale;
282
283 w = noScale;
284 geom_flags |= WidthValue|HeightValue;
285 }
286 else if (!strcasecmp (arr[i], "scale"))
287 {
288 if (h == 0) h = windowScale;
289 if (w == 0) w = windowScale;
290
291 geom_flags |= WidthValue|HeightValue;
292 }
293 else if (!strcasecmp (arr[i], "root"))
294 {
295 new_flags |= BG_TILE|BG_ROOT_ALIGN;
296 w = h = noScale;
297 geom_flags |= WidthValue|HeightValue;
298 }
299 } /* done parsing ops */
300
301 rxvt_free_strsplit (arr);
302 }
303
304 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; 320 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true;
305 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; 321 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true;
306 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; 322 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true;
307 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true; 323 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true;
308 324
319rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) 335rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
320{ 336{
321 int target_width = szHint.width; 337 int target_width = szHint.width;
322 int target_height = szHint.height; 338 int target_height = szHint.height;
323 339
340 w = h_scale * target_width / 100;
341 h = v_scale * target_height / 100;
342
324 if (bg_flags & BG_PROP_SCALE) 343 if (bg_flags & BG_PROP_SCALE)
325 { 344 {
326 float scale = (float)target_width / image_width; 345 float scale = (float)w / image_width;
327 min_it (scale, (float)target_height / image_height); 346 min_it (scale, (float)h / image_height);
328 w = image_width * scale + 0.5; 347 w = image_width * scale + 0.5;
329 h = image_height * scale + 0.5; 348 h = image_height * scale + 0.5;
330 } 349 }
331 else
332 {
333 w = h_scale * target_width / 100;
334 h = v_scale * target_height / 100;
335 }
336 350
337 if (!w) w = image_width; 351 if (!w) w = image_width;
338 if (!h) h = image_height; 352 if (!h) h = image_height;
339 353
340 if (bg_flags & BG_ROOT_ALIGN) 354 if (bg_flags & BG_ROOT_ALIGN)
348 y = make_align_position (v_align, target_height, h); 362 y = make_align_position (v_align, target_height, h);
349 } 363 }
350 364
351 bg_flags &= ~BG_IS_SIZE_SENSITIVE; 365 bg_flags &= ~BG_IS_SIZE_SENSITIVE;
352 if (!(bg_flags & BG_TILE) 366 if (!(bg_flags & BG_TILE)
353 || (bg_flags & BG_PROP_SCALE) || h_scale || v_scale 367 || h_scale || v_scale
354 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) 368 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align))
355 || w > target_width || h > target_height) 369 || w > target_width || h > target_height)
356 bg_flags |= BG_IS_SIZE_SENSITIVE; 370 bg_flags |= BG_IS_SIZE_SENSITIVE;
357} 371}
358 372

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines