From b76cfb421ebc0b7f29539d99b8d685c99054db08 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Mon, 12 Jan 1998 14:01:25 +0100
Subject: [PATCH] * XImage.pmod (XImage->redraw): Now accepts too small (i.e.
 negative), and clips the area properly.

Rev: lib/modules/Protocols.pmod/X.pmod/XImage.pmod:1.4
---
 lib/modules/Protocols.pmod/X.pmod/XImage.pmod | 29 +++++++++++++------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/lib/modules/Protocols.pmod/X.pmod/XImage.pmod b/lib/modules/Protocols.pmod/X.pmod/XImage.pmod
index 53b20a168a..e039f2b94f 100644
--- a/lib/modules/Protocols.pmod/X.pmod/XImage.pmod
+++ b/lib/modules/Protocols.pmod/X.pmod/XImage.pmod
@@ -153,23 +153,33 @@ class XImage
 
   void redraw(int x, int y, int width, int height)
   {
-    int lheight = height;
+    werror(sprintf("XImage->redraw: %d, %d, %d, %d, %d, %d\n",
+		   x, y, offset_x, offset_y, width, height));
+
     int slice = (window->display->maxRequestSize/depth)*32 / width;
     if(x+width > image->xsize())
       width = image->xsize()-x;
+    if (x<0)
+    {
+      width += x;
+      x = 0;
+    }
     if(width<=0) return;
 
-    if(y+lheight > image->ysize())
-    {
+    if(y+height > image->ysize())
       height = image->ysize()-y;
-      lheight = image->ysize()-y;
+    if (y<0)
+    {
+      height += y;
+      y = 0;
     }
-    if(lheight<=0) return;
 
-    while(lheight>0)
+    if(height<=0) return;
+
+    while(height>0)
     {
-      lheight -= slice;
-      if(lheight < 0) slice += lheight;
+      height -= slice;
+      if(height < 0) slice += height;
       object mimg = image->copy(x,y,x+width-1,y+slice-1);
 
       if(rmask)
@@ -181,7 +191,8 @@ class XImage
       {
 	if(!ccol) ccol = allocate_colortable();
 	string data = converter( mimg, bpp, linepad, depth, ccol );
-	window->PutImage( dgc, bpp, x, y, width, slice, data );
+	window->PutImage( dgc, bpp, x + offset_x, y + offset_y,
+			  width, slice, data );
       }
       y += slice;
     }
-- 
GitLab