Browse Source

patch issues, merge DrawCircleCorners, DrawOvalCorners into DrawRoundedCorners, move drawing into EllipseBresenham. Ready for merge DrawRoundedCorners & Circle+Ellipse

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@6658 8c9fc860-2736-0410-a75d-ab315db34111
eth.metacore 9 years ago
parent
commit
07800f8317
1 changed files with 83 additions and 114 deletions
  1. 83 114
      source/WMGraphicUtilities.Mod

+ 83 - 114
source/WMGraphicUtilities.Mod

@@ -283,147 +283,116 @@ BEGIN
 	END;
 END Ellipse;
 
-
 PROCEDURE DrawRoundRect*(CONST canvas : WMGraphics.Canvas; rect : WMRectangles.Rectangle; rx, ry : LONGINT; color : WMGraphics.Color; mode : LONGINT);
 	VAR innerRect : WMRectangles.Rectangle;
 BEGIN
-
     IF (rect.r <= rect.l) OR (rect.b <= rect.t) OR (rx <= 0) OR (ry <= 0) THEN RETURN END;
 
-	(* Set the coordinates to reflect the centers of 4 quarter circles *)
+	(* Set coordinates to reflect the centers of 4 quarter circles *)
 	innerRect := rect;
-
-	INC(innerRect.l, rx + 1);
-	INC(innerRect.t, ry + 1);
-	DEC(innerRect.r, rx + 1);
-	DEC(innerRect.b, ry + 1);
+	INC(innerRect.l, rx); INC(innerRect.t, ry);	DEC(innerRect.r, rx); DEC(innerRect.b, ry);
 
 	IF (innerRect.r < innerRect.l) OR (innerRect.b < innerRect.t) THEN RETURN END;
 
-	IF rx = ry THEN
-		DrawCircleCorners( canvas, rect, rx, color, mode) ;
-	ELSE
-		DrawOvalCorners( canvas, rect, rx, ry, color, mode) ;
-	END;
+	EllipseBresenham(canvas, innerRect, rx, ry, color, mode);
 
+	INC(innerRect.l, 1); INC(innerRect.t, 1); DEC(innerRect.r, 1); DEC(innerRect.b, 1);
+	
 	canvas.Fill(WMRectangles.MakeRect(innerRect.l, rect.t,      innerRect.r, rect.t + 1),  color, mode);
 	canvas.Fill(WMRectangles.MakeRect(rect.l,      innerRect.t, rect.l + 1,  innerRect.b), color, mode);
-	canvas.Fill(WMRectangles.MakeRect(rect.r-1,    innerRect.t, rect.r,      innerRect.b), color, mode);
 	canvas.Fill(WMRectangles.MakeRect(innerRect.l, rect.b - 1,  innerRect.r, rect.b),      color, mode);
-	
+	canvas.Fill(WMRectangles.MakeRect(rect.r-1,    innerRect.t, rect.r,      innerRect.b), color, mode);
 END DrawRoundRect;
 
-(* Draw 4 "circle" corners *)
-PROCEDURE DrawCircleCorners*(CONST canvas: WMGraphics.Canvas; rect : WMRectangles.Rectangle; r : LONGINT; color : WMGraphics.Color; mode : LONGINT);
-VAR
-	X, Y : LONGINT;
- 	XChange, YChange : LONGINT;
-	RadiusError : LONGINT;
+PROCEDURE DrawRoundedCorners*(CONST canvas: WMGraphics.Canvas; innerRect : WMRectangles.Rectangle; rx, ry : LONGINT; color : WMGraphics.Color; mode : LONGINT);
 BEGIN
-	X := r;
-	Y := 0;
-	XChange :=  1 - 2*r;
-	YChange := 1;
-	RadiusError := 0;
+	EllipseBresenham(canvas, innerRect, rx, ry, color, mode);
+END DrawRoundedCorners;
 
-	(* resize rectangle *)
-	INC(rect.l, r);
-	INC(rect.t, r);
-	DEC(rect.r, r);
-	DEC(rect.b, r);
-
-	WHILE ( X >= Y ) DO
-			canvas.Fill(WMRectangles.MakeRect(rect.r+X-1, rect.b+Y-1, rect.r+X,   rect.b+Y),   color, mode);
-			canvas.Fill(WMRectangles.MakeRect(rect.l-X,   rect.b+Y-1, rect.l-X+1, rect.b+Y),   color, mode);
-			canvas.Fill(WMRectangles.MakeRect(rect.r+X-1, rect.t-Y,   rect.r+X,   rect.t-Y+1), color, mode);
-			canvas.Fill(WMRectangles.MakeRect(rect.l-X,   rect.t-Y,   rect.l-X+1, rect.t-Y+1), color, mode);
-			
-            IF (X > Y) THEN
-				canvas.Fill(WMRectangles.MakeRect(rect.r+Y-1, rect.b+X-1, rect.r+Y,   rect.b+X),   color, mode);
-				canvas.Fill(WMRectangles.MakeRect(rect.l-Y,   rect.b+X-1, rect.l-Y+1, rect.b+X),   color, mode);
-				canvas.Fill(WMRectangles.MakeRect(rect.r+Y-1, rect.t-X,   rect.r+Y,   rect.t-X+1), color, mode);
-				canvas.Fill(WMRectangles.MakeRect(rect.l-Y,   rect.t-X,   rect.l-Y+1, rect.t-X+1), color, mode);
-			END;
-		
-		INC(Y);
-		INC(RadiusError, YChange);
-		INC(YChange,2);
-		IF (2*RadiusError + XChange > 0) THEN
-			DEC(X);
-			INC(RadiusError, XChange);
-			INC(XChange,2);
-		END;
-	END;
-END DrawCircleCorners;
+PROCEDURE DrawCornerPoints(CONST canvas: WMGraphics.Canvas; rect : WMRectangles.Rectangle; x, y : LONGINT; color : WMGraphics.Color; mode : LONGINT);
+BEGIN
+	canvas.Fill(WMRectangles.MakeRect(rect.l-x,   rect.b+y-1, rect.l-x+1, rect.b+y),   color, mode);
+	canvas.Fill(WMRectangles.MakeRect(rect.r+x-1, rect.b+y-1, rect.r+x,   rect.b+y),   color, mode);
+	canvas.Fill(WMRectangles.MakeRect(rect.r+x-1, rect.t-y,   rect.r+x,   rect.t-y+1), color, mode);
+	canvas.Fill(WMRectangles.MakeRect(rect.l-x,   rect.t-y,   rect.l-x+1, rect.t-y+1), color, mode);
+END DrawCornerPoints;
 
-(* Draw 4 "oval" corners use Bresenham Type Algorithm For Drawing Ellipses *)
-PROCEDURE DrawOvalCorners*(CONST canvas: WMGraphics.Canvas; rect : WMRectangles.Rectangle; rx, ry : LONGINT; color : WMGraphics.Color; mode : LONGINT);
+PROCEDURE EllipseBresenham(CONST canvas: WMGraphics.Canvas; innerRect : WMRectangles.Rectangle; rx, ry : LONGINT; color : WMGraphics.Color; mode : LONGINT);
 VAR
 	X, Y : LONGINT;
 	XChange, YChange : LONGINT;
-	EllipseError : LONGINT;
+	RadiusError : LONGINT;
 	TwoASquare, TwoBSquare : LONGINT;
 	StoppingX, StoppingY : LONGINT;
-BEGIN
-	TwoASquare := 2*rx*rx;
-	TwoBSquare := 2*ry*ry;
-	X := rx;
+	BEGIN
+	RadiusError := 0;
 	Y := 0;
-	XChange :=  ry*ry*(1-2*rx);
-	YChange :=  rx*rx;
-	EllipseError := 0;
-	StoppingX := TwoBSquare*rx;
-	StoppingY := 0;
-
-	INC(rect.l, rx);
-	INC(rect.t, ry);
-	DEC(rect.r, rx);
-	DEC(rect.b, ry);
-
-	WHILE ( StoppingX >= StoppingY ) DO (* 1st set of points, y>1 *)
-
-		canvas.Fill(WMRectangles.MakeRect(rect.r+X-1, rect.b+Y-1, rect.r+X,   rect.b+Y),   color, mode);
-		canvas.Fill(WMRectangles.MakeRect(rect.l-X,   rect.b+Y-1, rect.l-X+1, rect.b+Y),   color, mode);
-		canvas.Fill(WMRectangles.MakeRect(rect.r+X-1, rect.t-Y,   rect.r+X,   rect.t-Y+1), color, mode);
-		canvas.Fill(WMRectangles.MakeRect(rect.l-X,   rect.t-Y,   rect.l-X+1, rect.t-Y+1), color, mode);
+	IF rx = ry THEN (**)
+		X := rx;
+		XChange :=  1 - 2 * rx;
+		YChange := 1;
+
+		WHILE ( X >= Y ) DO
+			DrawCornerPoints(canvas, innerRect, X, Y, color, mode);
+			IF (X > Y) THEN
+				DrawCornerPoints(canvas, innerRect, Y, X, color, mode);
+			END;
 
-		INC(Y);
-		INC(StoppingY, TwoASquare);
-		INC(EllipseError, YChange);
-		INC(YChange,TwoASquare);
-		IF ((2*EllipseError + XChange) > 0 ) THEN
-			DEC(X);
-			DEC(StoppingX, TwoBSquare);
-			INC(EllipseError, XChange);
-			INC(XChange,TwoBSquare)
+			INC(Y);
+			INC(RadiusError, YChange);
+			INC(YChange,2);
+			IF (2*RadiusError + XChange > 0) THEN
+				DEC(X);
+				INC(RadiusError, XChange);
+				INC(XChange,2);
+			END;
 		END;
-	END;
-	(* 1st point set is done; start the 2nd set of points *)
-	X := 0;
-	Y := ry;
-	XChange := ry*ry;
-	YChange := rx*rx*(1-2*ry);
-	EllipseError := 0;
-	StoppingX := 0;
-	StoppingY := TwoASquare*ry;
-	WHILE ( StoppingX<= StoppingY ) DO  (*2nd set of points, y < 1*)
-
-		canvas.Fill(WMRectangles.MakeRect(rect.r+X-1, rect.b+Y-1, rect.r+X,   rect.b+Y),   color, mode);
-		canvas.Fill(WMRectangles.MakeRect(rect.l-X,   rect.b+Y-1, rect.l-X+1, rect.b+Y),   color, mode);
-		canvas.Fill(WMRectangles.MakeRect(rect.r+X-1, rect.t-Y,   rect.r+X,   rect.t-Y+1), color, mode);
-		canvas.Fill(WMRectangles.MakeRect(rect.l-X,   rect.t-Y,   rect.l-X+1, rect.t-Y+1), color, mode);
-
-		INC(X);
-		INC(StoppingX, TwoBSquare);
-		INC(EllipseError, XChange);
-		INC(XChange,TwoBSquare);
-		IF ((2*EllipseError + YChange) > 0 ) THEN
-			DEC(Y);
-			DEC(StoppingY, TwoASquare);
-			INC(EllipseError, YChange);
-			INC(YChange,TwoASquare)
+	ELSE
+		X := rx;
+		TwoASquare := 2*rx*rx;
+		TwoBSquare := 2*ry*ry;
+		XChange :=  ry*ry*(1-2*rx);
+		YChange :=  rx*rx;
+		StoppingX := TwoBSquare*rx;
+		StoppingY := 0;
+
+		WHILE ( StoppingX >= StoppingY ) DO (* 1st set of points, y > 1 *)
+			DrawCornerPoints(canvas, innerRect, X, Y, color, mode);
+
+			INC(Y);
+			INC(StoppingY, TwoASquare);
+			INC(RadiusError, YChange);
+			INC(YChange,TwoASquare);
+			IF ((2*RadiusError + XChange) > 0 ) THEN
+				DEC(X);
+				DEC(StoppingX, TwoBSquare);
+				INC(RadiusError, XChange);
+				INC(XChange,TwoBSquare)
+			END;
+		END;
+		(* 1st point set is done; start the 2nd set of points *)
+		X := 0;
+		Y := ry;
+		XChange := ry*ry;
+		YChange := rx*rx*(1-2*ry);
+		RadiusError := 0;
+		StoppingX := 0;
+		StoppingY := TwoASquare*ry;
+		WHILE ( StoppingX<= StoppingY ) DO  (*2nd set of points, y < 1*)
+			DrawCornerPoints(canvas, innerRect, X, Y, color, mode);
+
+			INC(X);
+			INC(StoppingX, TwoBSquare);
+			INC(RadiusError, XChange);
+			INC(XChange,TwoBSquare);
+			IF ((2*RadiusError + YChange) > 0 ) THEN
+				DEC(Y);
+				DEC(StoppingY, TwoASquare);
+				INC(RadiusError, YChange);
+				INC(YChange,TwoASquare)
+			END;
 		END;
 	END;
-END DrawOvalCorners;
+END EllipseBresenham;
 
 END WMGraphicUtilities.