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.54 by sf-exg, Wed Sep 1 22:49:35 2010 UTC vs.
Revision 1.55 by sf-exg, Thu Sep 2 15:48:10 2010 UTC

96 // this is basically redundant as bgPixmap_t is only used in 96 // this is basically redundant as bgPixmap_t is only used in
97 // zero_initialised-derived structs 97 // zero_initialised-derived structs
98#ifdef HAVE_AFTERIMAGE 98#ifdef HAVE_AFTERIMAGE
99 original_asim = NULL; 99 original_asim = NULL;
100#endif 100#endif
101#ifdef HAVE_PIXBUF
102 pixbuf = NULL;
103#endif
101#ifdef BG_IMAGE_FROM_FILE 104#ifdef BG_IMAGE_FROM_FILE
102 have_image = false; 105 have_image = false;
103 h_scale = v_scale = 0; 106 h_scale = v_scale = 0;
104 h_align = v_align = 0; 107 h_align = v_align = 0;
105#endif 108#endif
113bgPixmap_t::destroy () 116bgPixmap_t::destroy ()
114{ 117{
115#ifdef HAVE_AFTERIMAGE 118#ifdef HAVE_AFTERIMAGE
116 if (original_asim) 119 if (original_asim)
117 safe_asimage_destroy (original_asim); 120 safe_asimage_destroy (original_asim);
121#endif
122
123#ifdef HAVE_PIXBUF
124 if (pixbuf)
125 g_object_unref (pixbuf);
118#endif 126#endif
119 127
120 if (pixmap && target) 128 if (pixmap && target)
121 XFreePixmap (target->dpy, pixmap); 129 XFreePixmap (target->dpy, pixmap);
122} 130}
705 713
706 return ret; 714 return ret;
707} 715}
708# endif /* HAVE_AFTERIMAGE */ 716# endif /* HAVE_AFTERIMAGE */
709 717
718# ifdef HAVE_PIXBUF
719bool
720bgPixmap_t::render_image (unsigned long background_flags)
721{
722 if (target == NULL)
723 return false;
724
725 if (!pixbuf)
726 return false;
727
728 // TODO: add alpha blending
729 if (background_flags)
730 return false;
731
732 GdkPixbuf *result;
733
734 int image_width = gdk_pixbuf_get_width (pixbuf);
735 int image_height = gdk_pixbuf_get_height (pixbuf);
736
737 int target_width = target->szHint.width;
738 int target_height = target->szHint.height;
739 int new_pmap_width = target_width;
740 int new_pmap_height = target_height;
741
742 int x = 0;
743 int y = 0;
744 int w = h_scale * target_width / 100;
745 int h = v_scale * target_height / 100;
746
747 if (h_align == rootAlign || v_align == rootAlign)
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
760 if (x >= target_width
761 || y >= target_height
762 || (w > 0 && x + w <= 0)
763 || (h > 0 && y + h <= 0))
764 return false;
765
766 result = pixbuf;
767
768 if ((w > 0 && w != image_width)
769 || (h > 0 && h != image_height))
770 {
771 result = gdk_pixbuf_scale_simple (pixbuf,
772 w > 0 ? w : image_width,
773 h > 0 ? h : image_height,
774 GDK_INTERP_BILINEAR);
775 }
776
777 bool ret = false;
778
779 if (result)
780 {
781 XGCValues gcv;
782 GC gc;
783
784 image_width = gdk_pixbuf_get_width (result);
785 image_height = gdk_pixbuf_get_height (result);
786
787 if (h_scale == 0)
788 new_pmap_width = min (image_width, target_width);
789 if (v_scale == 0)
790 new_pmap_height = min (image_height, target_height);
791
792 if (pixmap)
793 {
794 if (pmap_width != new_pmap_width
795 || pmap_height != new_pmap_height
796 || pmap_depth != target->depth)
797 {
798 XFreePixmap (target->dpy, pixmap);
799 pixmap = None;
800 }
801 }
802
803 if (pixmap == None)
804 {
805 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
806 pmap_width = new_pmap_width;
807 pmap_height = new_pmap_height;
808 pmap_depth = target->depth;
809 }
810
811 gcv.foreground = target->pix_colors[Color_bg];
812 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
813
814 if (h_scale == 0 || v_scale == 0)
815 {
816 Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth);
817 gdk_pixbuf_xlib_render_to_drawable (result, tile, gc,
818 0, 0,
819 0, 0,
820 image_width, image_height,
821 XLIB_RGB_DITHER_NONE,
822 0, 0);
823
824 gcv.tile = tile;
825 gcv.fill_style = FillTiled;
826 gcv.ts_x_origin = x;
827 gcv.ts_y_origin = y;
828 XChangeGC (target->dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
829
830 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
831 XFreePixmap (target->dpy, tile);
832 }
833 else
834 {
835 int src_x, src_y, dst_x, dst_y;
836 int dst_width, dst_height;
837
838 src_x = make_clip_rectangle (x, image_width , new_pmap_width , dst_x, dst_width );
839 src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height);
840
841 if (dst_x > 0 || dst_y > 0
842 || dst_x + dst_width < new_pmap_width
843 || dst_y + dst_height < new_pmap_height)
844 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
845
846 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
847 gdk_pixbuf_xlib_render_to_drawable (result, pixmap, gc,
848 src_x, src_y,
849 dst_x, dst_y,
850 dst_width, dst_height,
851 XLIB_RGB_DITHER_NONE,
852 0, 0);
853 }
854
855 if (result != pixbuf)
856 g_object_unref (result);
857
858 XFreeGC (target->dpy, gc);
859
860 ret = true;
861 }
862
863 return ret;
864}
865# endif /* HAVE_PIXBUF */
866
710bool 867bool
711bgPixmap_t::set_file (const char *file) 868bgPixmap_t::set_file (const char *file)
712{ 869{
713 assert (file); 870 assert (file);
714 871
726# ifdef HAVE_AFTERIMAGE 883# ifdef HAVE_AFTERIMAGE
727 if (!target->asimman) 884 if (!target->asimman)
728 target->asimman = create_generic_imageman (target->rs[Rs_path]); 885 target->asimman = create_generic_imageman (target->rs[Rs_path]);
729 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 886 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
730 if (original_asim) 887 if (original_asim)
888 have_image = true;
889 return have_image;
890# endif
891
892# ifdef HAVE_PIXBUF
893 pixbuf = gdk_pixbuf_new_from_file (file, NULL);
894 if (pixbuf)
731 have_image = true; 895 have_image = true;
732 return have_image; 896 return have_image;
733# endif 897# endif
734 } 898 }
735 899

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines