XWorkstation.st
changeset 3536 76666aacfefb
parent 3487 5f28d7335961
child 3537 28f502c27715
--- a/XWorkstation.st	Tue Nov 06 09:41:46 2001 +0100
+++ b/XWorkstation.st	Thu Nov 08 11:21:34 2001 +0100
@@ -3125,19 +3125,35 @@
      && __isExternalAddress(aDrawableId)
      && __bothSmallInteger(x0, y0)
      && __bothSmallInteger(x1, y1)) {
-	Display *dpy = myDpy;
-	gc = __GCVal(aGCId);
-	win = __WindowVal(aDrawableId);
-
-	ENTER_XLIB();
-	if ((x0 == x1) && (y0 == y1)) {
-	    XDrawPoint(dpy, win, gc, __intVal(x0), __intVal(y0));
-	} else {
-	    XDrawLine(dpy, win, gc, __intVal(x0), __intVal(y0),
-				    __intVal(x1), __intVal(y1));
-	}
-	LEAVE_XLIB();
-	RETURN ( self );
+        Display *dpy = myDpy;
+        int ix0, iy0, ix1, iy1;
+        gc = __GCVal(aGCId);
+        win = __WindowVal(aDrawableId);
+
+        ix0 = __intVal(x0);
+        iy0 = __intVal(y0);
+        ix1 = __intVal(x1);
+        iy1 = __intVal(y1);
+
+        /* attention: coordinates in X are shorts and wrap; clamp here. */
+        if (ix0 > 0x7FFF) ix0 = 0x7FFF;
+        else if (ix0 < -0x8000) ix0 = -0x8000;
+        if (iy0 > 0x7FFF) iy0 = 0x7FFF;
+        else if (iy0 < -0x8000) iy0 = -0x8000;
+        if (ix1 > 0x7FFF) ix1 = 0x7FFF;
+        else if (ix1 < -0x8000) ix1 = -0x8000;
+        if (iy1 > 0x7FFF) iy1 = 0x7FFF;
+        else if (iy1 < -0x8000) iy1 = -0x8000;
+
+        ENTER_XLIB();
+        if ((ix0 == ix1) && (iy0 == iy1)) {
+            /* little bit shorter X-lib message (better with slow connections...) */
+            XDrawPoint(dpy, win, gc, ix0, iy0);
+        } else {
+            XDrawLine(dpy, win, gc, ix0, iy0, ix1, iy1);
+        }
+        LEAVE_XLIB();
+        RETURN ( self );
     }
 %}.
     "badGC, badDrawable or coordinates not integer"
@@ -3154,7 +3170,7 @@
     |noY|
 
     (noY := yValues size) < 2 ifTrue:[
-	^ self
+        ^ self
     ].
 
 %{
@@ -3171,99 +3187,110 @@
     if (ISCONNECTED
      && __isExternalAddress(aGCId)
      && __isExternalAddress(aDrawableId) ) {
-	gc = __GCVal(aGCId);
-	win = __WindowVal(aDrawableId);
-
-	if( __isSmallInteger(scaleY) ) 
-	    sY = (float) __intVal( scaleY );
-	else if (__isFloat(scaleY)) 
-	    sY = __floatVal( scaleY );
-	else if (__isShortFloat(scaleY)) 
-	    sY = __shortFloatVal( scaleY );
-	else {
-	    t = __SSEND0(scaleY, @symbol(asFloat), 0);
-	    if (! __isFloat(t)) goto fail;
-	    sY = __floatVal( t );
-	}
-
-	if( __isSmallInteger(transY) ) 
-	    tY = (float) __intVal( transY );
-	else if (__isFloat(transY)) 
-	    tY = __floatVal( transY );
-	else if (__isShortFloat(transY)) 
-	    tY = __shortFloatVal( transY );
-	else {
-	    t = __SSEND0(transY, @symbol(asFloat), 0);
-	    if (! __isFloat(t)) goto fail;
-	    tY = __floatVal( t );
-	}
-
-	if( __isSmallInteger(startX) ) 
-	    x = (float) __intVal( startX );
-	else if (__isFloat(startX)) 
-	    x = __floatVal( startX );
-	else if (__isShortFloat(startX)) 
-	    x = __shortFloatVal( startX );
-	else {
-	    t = __SSEND0(startX, @symbol(asFloat), 0);
-	    if (! __isFloat(t)) goto fail;
-	    x = __floatVal( t );
-	}
-
-	if( __isSmallInteger(stepX) ) 
-	    step = (float) __intVal( stepX );
-	else if (__isFloat(stepX)) 
-	    step = __floatVal( stepX );
-	else if (__isShortFloat(stepX)) 
-	    step = __shortFloatVal( stepX );
-	else {
-	    t = __SSEND0(stepX, @symbol(asFloat), 0);
-	    if (! __isFloat(t)) goto fail;
-	    step = __floatVal( t );
-	}
-
-	num = __intVal( noY );
-
-	if( num > 200 ) {
-	    if( ! (points = (XPoint *) malloc ( sizeof(XPoint) * num )) )
-		goto fail;
-	    mustFree = 1;
-	} else {
-	    points = qPoints;
-	}
-	for( i = 0; i < num; ++i ) {
-	    yA  = __AT_(yValues, __MKSMALLINT(i+1) );
-
-	    if( __isFloat(yA) )
-		y = __floatVal( yA );
-	    else if( __isSmallInteger(yA) )
-		y = (float) __intVal( yA );
-	    else if( __isShortFloat( yA) )
-		y = __shortFloatVal( yA );
-	    else {
-		t = __SSEND0(yA, @symbol(asFloat), 0);
-		if (! __isFloat(t)) goto fail;
-		y = __floatVal( t );
-	    }
-
-	    points[i].x = (int) (x + 0.5);
-	    points[i].y = (int) ((y * sY) + tY + 0.5);
-	    x = x + step;
-	}
-
-	ENTER_XLIB();
-	XDrawLines(myDpy, win, gc, points, num, CoordModeOrigin);
-	LEAVE_XLIB();
-
-	if( mustFree ) {
-	    free( points );
-	}
-	RETURN ( self );
+        gc = __GCVal(aGCId);
+        win = __WindowVal(aDrawableId);
+
+        if( __isSmallInteger(scaleY) ) 
+            sY = (float) __intVal( scaleY );
+        else if (__isFloat(scaleY)) 
+            sY = __floatVal( scaleY );
+        else if (__isShortFloat(scaleY)) 
+            sY = __shortFloatVal( scaleY );
+        else {
+            t = __SSEND0(scaleY, @symbol(asFloat), 0);
+            if (! __isFloat(t)) goto fail;
+            sY = __floatVal( t );
+        }
+
+        if( __isSmallInteger(transY) ) 
+            tY = (float) __intVal( transY );
+        else if (__isFloat(transY)) 
+            tY = __floatVal( transY );
+        else if (__isShortFloat(transY)) 
+            tY = __shortFloatVal( transY );
+        else {
+            t = __SSEND0(transY, @symbol(asFloat), 0);
+            if (! __isFloat(t)) goto fail;
+            tY = __floatVal( t );
+        }
+
+        if( __isSmallInteger(startX) ) 
+            x = (float) __intVal( startX );
+        else if (__isFloat(startX)) 
+            x = __floatVal( startX );
+        else if (__isShortFloat(startX)) 
+            x = __shortFloatVal( startX );
+        else {
+            t = __SSEND0(startX, @symbol(asFloat), 0);
+            if (! __isFloat(t)) goto fail;
+            x = __floatVal( t );
+        }
+
+        if( __isSmallInteger(stepX) ) 
+            step = (float) __intVal( stepX );
+        else if (__isFloat(stepX)) 
+            step = __floatVal( stepX );
+        else if (__isShortFloat(stepX)) 
+            step = __shortFloatVal( stepX );
+        else {
+            t = __SSEND0(stepX, @symbol(asFloat), 0);
+            if (! __isFloat(t)) goto fail;
+            step = __floatVal( t );
+        }
+
+        num = __intVal( noY );
+
+        if( num > 200 ) {
+            if( ! (points = (XPoint *) malloc ( sizeof(XPoint) * num )) )
+                goto fail;
+            mustFree = 1;
+        } else {
+            points = qPoints;
+        }
+        for( i = 0; i < num; ++i ) {
+            int px, py;
+
+            yA  = __AT_(yValues, __MKSMALLINT(i+1) );
+
+            if( __isFloat(yA) )
+                y = __floatVal( yA );
+            else if( __isSmallInteger(yA) )
+                y = (float) __intVal( yA );
+            else if( __isShortFloat( yA) )
+                y = __shortFloatVal( yA );
+            else {
+                t = __SSEND0(yA, @symbol(asFloat), 0);
+                if (! __isFloat(t)) goto fail;
+                y = __floatVal( t );
+            }
+
+            px = (int) (x + 0.5);
+            py = (int) ((y * sY) + tY + 0.5);
+
+            /* attention: coordinates in X are shorts and wrap; clamp here. */
+            if (px > 0x7FFF) px = 0x7FFF;
+            else if (px < -0x8000) px = -0x8000;
+            if (py > 0x7FFF) py = 0x7FFF;
+            else if (py < -0x8000) py = -0x8000;
+
+            points[i].x = px;
+            points[i].y = py;
+            x = x + step;
+        }
+
+        ENTER_XLIB();
+        XDrawLines(myDpy, win, gc, points, num, CoordModeOrigin);
+        LEAVE_XLIB();
+
+        if( mustFree ) {
+            free( points );
+        }
+        RETURN ( self );
     }
 
 fail:
     if( mustFree )
-	free( points );
+        free( points );
 %}.
     ^ super displayLinesFromX:startX step:stepX yValues:yValues scaleY:scaleY transY:transY in:aDrawableId with:aGCId
 
@@ -11572,6 +11599,6 @@
 !XWorkstation class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/XWorkstation.st,v 1.398 2001-09-11 20:49:36 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/XWorkstation.st,v 1.399 2001-11-08 10:21:34 cg Exp $'
 ! !
 XWorkstation initialize!