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.56 by sf-exg, Thu Sep 2 23:40:56 2010 UTC vs.
Revision 1.61 by sf-exg, Sun Oct 3 20:48:34 2010 UTC

138# endif 138# endif
139 139
140# ifdef BG_IMAGE_FROM_FILE 140# ifdef BG_IMAGE_FROM_FILE
141 if (have_image) 141 if (have_image)
142 { 142 {
143 if (h_scale != 0 || v_scale != 0 143 if (flags & sizeSensitive)
144 || h_align != 0 || v_align != 0)
145 return true; 144 return true;
146 } 145 }
147# endif 146# endif
148 147
149 return false; 148 return false;
247make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) 246make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size)
248{ 247{
249 int src_pos = 0; 248 int src_pos = 0;
250 dst_pos = 0; 249 dst_pos = 0;
251 dst_size = size; 250 dst_size = size;
252 if (pos < 0 && size > target_size) 251 if (pos < 0)
253 { 252 {
254 src_pos = -pos; 253 src_pos = -pos;
255 dst_size += pos; 254 dst_size += pos;
256 } 255 }
257 else if (pos > 0) 256 else if (pos > 0)
451 //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", 450 //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
452 // flags, h_scale, v_scale, h_align, v_align); 451 // flags, h_scale, v_scale, h_align, v_align);
453 return (changed > 0); 452 return (changed > 0);
454} 453}
455 454
455void
456bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
457{
458 int target_width = target->szHint.width;
459 int target_height = target->szHint.height;
460
461 w = h_scale * target_width / 100;
462 h = v_scale * target_height / 100;
463
464 if (h_align == rootAlign || v_align == rootAlign)
465 {
466 target->get_window_origin (x, y);
467 x = -x;
468 y = -y;
469 }
470
471 if (h_align != rootAlign)
472 x = make_align_position (h_align, target_width, w > 0 ? w : image_width);
473
474 if (v_align != rootAlign)
475 y = make_align_position (v_align, target_height, h > 0 ? h : image_height);
476
477 flags &= ~sizeSensitive;
478 if (h_scale != 0 || v_scale != 0
479 || h_align != 0 || v_align != 0
480 || image_width > target_width || image_height > target_height)
481 flags |= sizeSensitive;
482}
483
456# ifdef HAVE_AFTERIMAGE 484# ifdef HAVE_AFTERIMAGE
457bool 485bool
458bgPixmap_t::render_image (unsigned long background_flags) 486bgPixmap_t::render_image (unsigned long background_flags)
459{ 487{
460 if (target == NULL) 488 if (target == NULL)
504 int new_pmap_width = target_width; 532 int new_pmap_width = target_width;
505 int new_pmap_height = target_height; 533 int new_pmap_height = target_height;
506 534
507 int x = 0; 535 int x = 0;
508 int y = 0; 536 int y = 0;
509 int w = h_scale * target_width / 100; 537 int w = 0;
510 int h = v_scale * target_height / 100; 538 int h = 0;
511 539
512 TIMING_TEST_START (asim); 540 TIMING_TEST_START (asim);
513 541
514 if (original_asim) 542 if (original_asim)
515 { 543 get_image_geometry (original_asim->width, original_asim->height, w, h, x, y);
516 if (h_align == rootAlign || v_align == rootAlign)
517 {
518 target->get_window_origin (x, y);
519 x = -x;
520 y = -y;
521 }
522
523 if (h_align != rootAlign)
524 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width);
525
526 if (v_align != rootAlign)
527 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height);
528 }
529 544
530 if (!original_asim 545 if (!original_asim
531 || x >= target_width 546 || x >= target_width
532 || y >= target_height 547 || y >= target_height
533 || (w > 0 && x + w <= 0) 548 || (w > 0 && x + w <= 0)
565 100, ASIMAGE_QUALITY_DEFAULT); 580 100, ASIMAGE_QUALITY_DEFAULT);
566 } 581 }
567 582
568 if (background == NULL) 583 if (background == NULL)
569 { 584 {
570 /* if tiling - pixmap has to be sized exactly as the image,
571 but there is no need to make it bigger than the window! */
572 if (h_scale == 0)
573 new_pmap_width = min (result->width, target_width);
574 if (v_scale == 0)
575 new_pmap_height = min (result->height, target_height);
576 /* we also need to tile our image in one or both directions */
577 if (h_scale == 0 || v_scale == 0) 585 if (h_scale == 0 || v_scale == 0)
578 { 586 {
587 /* if tiling - pixmap has to be sized exactly as the image,
588 but there is no need to make it bigger than the window! */
589 new_pmap_width = min (result->width, target_width);
590 new_pmap_height = min (result->height, target_height);
591
592 /* we also need to tile our image in both directions */
579 ASImage *tmp = tile_asimage (target->asv, result, 593 ASImage *tmp = tile_asimage (target->asv, result,
580 (h_scale > 0) ? 0 : (int)result->width - x, 594 (int)result->width - x,
581 (v_scale > 0) ? 0 : (int)result->height - y, 595 (int)result->height - y,
582 new_pmap_width, 596 new_pmap_width,
583 new_pmap_height, 597 new_pmap_height,
584 TINT_LEAVE_SAME, ASA_XImage, 598 TINT_LEAVE_SAME, ASA_XImage,
585 100, ASIMAGE_QUALITY_DEFAULT); 599 100, ASIMAGE_QUALITY_DEFAULT);
586 if (tmp) 600 if (tmp)
684 698
685 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; 699 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0;
686 int dst_width = result->width, dst_height = result->height; 700 int dst_width = result->width, dst_height = result->height;
687 if (background == NULL) 701 if (background == NULL)
688 { 702 {
703 if (!(h_scale == 0 || v_scale == 0))
704 {
689 if (h_scale > 0) src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width ); 705 src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width );
690 if (v_scale > 0) src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); 706 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height);
707 }
691 708
692 if (dst_x > 0 || dst_y > 0 709 if (dst_x > 0 || dst_y > 0
693 || dst_x + dst_width < new_pmap_width 710 || dst_x + dst_width < new_pmap_width
694 || dst_y + dst_height < new_pmap_height) 711 || dst_y + dst_height < new_pmap_height)
695 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 712 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
739 int new_pmap_width = target_width; 756 int new_pmap_width = target_width;
740 int new_pmap_height = target_height; 757 int new_pmap_height = target_height;
741 758
742 int x = 0; 759 int x = 0;
743 int y = 0; 760 int y = 0;
744 int w = h_scale * target_width / 100; 761 int w = 0;
745 int h = v_scale * target_height / 100; 762 int h = 0;
746 763
747 if (h_align == rootAlign || v_align == rootAlign) 764 get_image_geometry (image_width, image_height, w, h, x, y);
748 {
749 target->get_window_origin (x, y);
750 x = -x;
751 y = -y;
752 }
753
754 if (h_align != rootAlign)
755 x = make_align_position (h_align, target_width, w > 0 ? w : image_width);
756
757 if (v_align != rootAlign)
758 y = make_align_position (v_align, target_height, h > 0 ? h : image_height);
759 765
760 if (x >= target_width 766 if (x >= target_width
761 || y >= target_height 767 || y >= target_height
762 || (w > 0 && x + w <= 0) 768 || (w > 0 && x + w <= 0)
763 || (h > 0 && y + h <= 0)) 769 || (h > 0 && y + h <= 0))
782 GC gc; 788 GC gc;
783 789
784 image_width = gdk_pixbuf_get_width (result); 790 image_width = gdk_pixbuf_get_width (result);
785 image_height = gdk_pixbuf_get_height (result); 791 image_height = gdk_pixbuf_get_height (result);
786 792
787 if (h_scale == 0) 793 if (h_scale == 0 || v_scale == 0)
794 {
788 new_pmap_width = min (image_width, target_width); 795 new_pmap_width = min (image_width, target_width);
789 if (v_scale == 0)
790 new_pmap_height = min (image_height, target_height); 796 new_pmap_height = min (image_height, target_height);
797 }
791 798
792 if (pixmap) 799 if (pixmap)
793 { 800 {
794 if (pmap_width != new_pmap_width 801 if (pmap_width != new_pmap_width
795 || pmap_height != new_pmap_height 802 || pmap_height != new_pmap_height

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines