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.253 by sf-exg, Sun Dec 30 15:52:37 2012 UTC vs.
Revision 1.258 by root, Thu May 22 18:54:32 2014 UTC

7 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> 7 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net>
8 * Copyright (c) 2010-2012 Emanuele Giaquinta <e.giaquinta@glauco.it> 8 * Copyright (c) 2010-2012 Emanuele Giaquinta <e.giaquinta@glauco.it>
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version. 13 * (at your option) any later version.
14 * 14 *
15 * This program is distributed in the hope that it will be useful, 15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42 42
43bool 43bool
44rxvt_term::bg_window_size_sensitive () 44rxvt_term::bg_window_size_sensitive ()
45{ 45{
46# if BG_IMAGE_FROM_ROOT 46# if BG_IMAGE_FROM_ROOT
47 if (option (Opt_transparent)) 47 if (root_img)
48 return true; 48 return true;
49# endif 49# endif
50 50
51# if BG_IMAGE_FROM_FILE 51# if BG_IMAGE_FROM_FILE
52 if (fimage.img) 52 if (fimage.img)
63 63
64bool 64bool
65rxvt_term::bg_window_position_sensitive () 65rxvt_term::bg_window_position_sensitive ()
66{ 66{
67# if BG_IMAGE_FROM_ROOT 67# if BG_IMAGE_FROM_ROOT
68 if (option (Opt_transparent)) 68 if (root_img)
69 return true; 69 return true;
70# endif 70# endif
71 71
72# if BG_IMAGE_FROM_FILE 72# if BG_IMAGE_FROM_FILE
73 if (fimage.img) 73 if (fimage.img)
252 252
253 return changed; 253 return changed;
254} 254}
255 255
256void 256void
257rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y) 257rxvt_term::render_image (rxvt_image &image)
258{ 258{
259 int image_width = image.img->w; 259 int image_width = image.img->w;
260 int image_height = image.img->h; 260 int image_height = image.img->h;
261 int parent_width = szHint.width; 261 int parent_width = szHint.width;
262 int parent_height = szHint.height; 262 int parent_height = szHint.height;
263 int h_scale = min (image.h_scale, 32767 * 100 / parent_width); 263 int h_scale = min (image.h_scale, 32767 * 100 / parent_width);
264 int v_scale = min (image.v_scale, 32767 * 100 / parent_height); 264 int v_scale = min (image.v_scale, 32767 * 100 / parent_height);
265 265
266 int w;
267 int h;
268 int x;
269 int y;
270
266 w = h_scale * parent_width / 100; 271 w = h_scale * parent_width / 100;
267 h = v_scale * parent_height / 100; 272 h = v_scale * parent_height / 100;
268 273
269 if (image.flags & IM_KEEP_ASPECT) 274 if (image.flags & IM_KEEP_ASPECT)
270 { 275 {
285 else 290 else
286 { 291 {
287 x = make_align_position (image.h_align, parent_width, w); 292 x = make_align_position (image.h_align, parent_width, w);
288 y = make_align_position (image.v_align, parent_height, h); 293 y = make_align_position (image.v_align, parent_height, h);
289 } 294 }
290}
291
292bool
293rxvt_term::render_image (rxvt_image &image)
294{
295 int parent_width = szHint.width;
296 int parent_height = szHint.height;
297
298 int x = 0;
299 int y = 0;
300 int w = 0;
301 int h = 0;
302
303 get_image_geometry (image, w, h, x, y);
304 295
305 if (!(image.flags & IM_ROOT_ALIGN) 296 if (!(image.flags & IM_ROOT_ALIGN)
306 && (x >= parent_width 297 && (x >= parent_width
307 || y >= parent_height 298 || y >= parent_height
308 || x + w <= 0 299 || x + w <= 0
309 || y + h <= 0)) 300 || y + h <= 0))
310 return false; 301 return;
311 302
312 rxvt_img *img = image.img->scale (w, h); 303 rxvt_img *img = image.img->scale (w, h);
313 304
314 if (image.flags & IM_TILE) 305 if (image.flags & IM_TILE)
315 img->repeat_mode (RepeatNormal); 306 img->repeat_mode (RepeatNormal);
323 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 314 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
324 img->convert_format (format, pix_colors [Color_bg])->replace (img); 315 img->convert_format (format, pix_colors [Color_bg])->replace (img);
325 316
326 delete bg_img; 317 delete bg_img;
327 bg_img = img; 318 bg_img = img;
328
329 return true;
330} 319}
331 320
332rxvt_image::rxvt_image () 321rxvt_image::rxvt_image ()
333{ 322{
334 alpha = 0xffff; 323 alpha = 0xffff;
440/* 429/*
441 * Builds a pixmap of the same size as the terminal window that contains 430 * Builds a pixmap of the same size as the terminal window that contains
442 * the tiled portion of the root pixmap that is supposed to be covered by 431 * the tiled portion of the root pixmap that is supposed to be covered by
443 * our window. 432 * our window.
444 */ 433 */
445bool 434void
446rxvt_term::render_root_image () 435rxvt_term::render_root_image ()
447{ 436{
448 /* root dimensions may change from call to call - but Display structure should 437 /* root dimensions may change from call to call - but Display structure should
449 * be always up-to-date, so let's use it : 438 * be always up-to-date, so let's use it :
450 */ 439 */
456 int sx, sy; 445 int sx, sy;
457 446
458 sx = parent_x; 447 sx = parent_x;
459 sy = parent_y; 448 sy = parent_y;
460 449
461 if (!root_img)
462 return false;
463
464 /* check if we are outside of the visible part of the virtual screen : */ 450 /* check if we are outside of the visible part of the virtual screen : */
465 if (sx + parent_width <= 0 || sy + parent_height <= 0 451 if (sx + parent_width <= 0 || sy + parent_height <= 0
466 || sx >= root_width || sy >= root_height) 452 || sx >= root_width || sy >= root_height)
467 return 0; 453 return;
468 454
469 while (sx < 0) sx += root_img->w; 455 while (sx < 0) sx += root_img->w;
470 while (sy < 0) sy += root_img->h; 456 while (sy < 0) sy += root_img->h;
471 457
472 rxvt_img *img = root_img->sub_rect (sx, sy, parent_width, parent_height); 458 rxvt_img *img = root_img->sub_rect (sx, sy, parent_width, parent_height);
473 459
474 if (root_effects.need_blur ()) 460 if (root_effects.need_blur ())
475 img->blur (root_effects.h_blurRadius, root_effects.v_blurRadius)->replace (img); 461 img->blur (root_effects.h_blurRadius, root_effects.v_blurRadius)->replace (img);
476 462
477 if (root_effects.need_tint ()) 463 if (root_effects.need_tint ())
478 tint_image (img, root_effects.tint, root_effects.tint_set, root_effects.shade); 464 {
465 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
466
467 if (root_effects.tint_set)
468 root_effects.tint.get (c);
469 rxvt_img::nv factor = root_effects.shade / 100. - 1.;
470 img->shade (factor, c)->replace (img);
471 }
479 472
480 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 473 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
481 img->convert_format (format, pix_colors [Color_bg])->replace (img); 474 img->convert_format (format, pix_colors [Color_bg])->replace (img);
482 475
483 delete bg_img; 476 delete bg_img;
484 bg_img = img; 477 bg_img = img;
485
486 return true;
487}
488
489void
490rxvt_term::bg_set_root_pixmap ()
491{
492 delete root_img;
493 root_img = rxvt_img::new_from_root (this);
494} 478}
495# endif /* BG_IMAGE_FROM_ROOT */ 479# endif /* BG_IMAGE_FROM_ROOT */
496 480
497void 481void
498rxvt_term::bg_render () 482rxvt_term::bg_render ()
506 490
507 if (!mapped) 491 if (!mapped)
508 return; 492 return;
509 493
510# if BG_IMAGE_FROM_ROOT 494# if BG_IMAGE_FROM_ROOT
511 if (option (Opt_transparent)) 495 if (root_img)
496 {
512 if (render_root_image ()) 497 render_root_image ();
513 bg_flags |= BG_IS_TRANSPARENT; 498 bg_flags |= BG_IS_TRANSPARENT;
499 }
514# endif 500# endif
515 501
516# if BG_IMAGE_FROM_FILE 502# if BG_IMAGE_FROM_FILE
517 if (fimage.img) 503 if (fimage.img)
518 render_image (fimage); 504 render_image (fimage);
537 root_effects.set_tint (pix_colors_focused [Color_tint]); 523 root_effects.set_tint (pix_colors_focused [Color_tint]);
538 524
539 if (rs [Rs_shade]) 525 if (rs [Rs_shade])
540 root_effects.set_shade (rs [Rs_shade]); 526 root_effects.set_shade (rs [Rs_shade]);
541 527
542 bg_set_root_pixmap (); 528 rxvt_img::new_from_root (this)->replace (root_img);
543 XSelectInput (dpy, display->root, PropertyChangeMask); 529 XSelectInput (dpy, display->root, PropertyChangeMask);
544 rootwin_ev.start (display, display->root); 530 rootwin_ev.start (display, display->root);
545 } 531 }
546#endif 532#endif
547 533
553 update_background (); 539 update_background ();
554 } 540 }
555#endif 541#endif
556} 542}
557 543
558void
559rxvt_term::tint_image (rxvt_img *img, rxvt_color &tint, bool tint_set, int shade)
560{
561 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
562
563 if (tint_set)
564 tint.get (c);
565
566 if (shade > 100)
567 {
568 c.r = c.r * (200 - shade) / 100;
569 c.g = c.g * (200 - shade) / 100;
570 c.b = c.b * (200 - shade) / 100;
571 }
572 else
573 {
574 c.r = c.r * shade / 100;
575 c.g = c.g * shade / 100;
576 c.b = c.b * shade / 100;
577 }
578
579 img->contrast (c.r, c.g, c.b, c.a);
580
581 if (shade > 100)
582 {
583 c.a = 0xffff;
584 c.r =
585 c.g =
586 c.b = 0xffff * (shade - 100) / 100;
587 img->brightness (c.r, c.g, c.b, c.a);
588 }
589}
590
591#endif /* HAVE_BG_PIXMAP */ 544#endif /* HAVE_BG_PIXMAP */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines