Browse Source

fix rect normalization
add Canvas.GetPixel()

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@6355 8c9fc860-2736-0410-a75d-ab315db34111

eth.metacore 9 năm trước cách đây
mục cha
commit
e6e628de6e
1 tập tin đã thay đổi với 23 bổ sung3 xóa
  1. 23 3
      source/WMGraphics.Mod

+ 23 - 3
source/WMGraphics.Mod

@@ -201,7 +201,7 @@ TYPE
 		PROCEDURE SetClipRect*(rect : Rectangle);
 		BEGIN
 			INCL(clipMode, ClipRect);
-			rect.r := Max(rect.r, rect.l); rect.b := Max(rect.b, rect.t);
+			Rectangles.Normalize(rect);
 			Rectangles.MoveRel(rect, dx, dy);
 			Rectangles.ClipRect(rect, limits);
 			clipRect := rect
@@ -298,6 +298,11 @@ TYPE
 		BEGIN
 			Fill(MakeRectangle(x, y, x + 1, y + 1), color, mode)
 		END SetPixel;
+		
+		PROCEDURE(*ABSTRACT*) GetPixel*(x, y : LONGINT ) : LONGINT;
+		BEGIN
+			RETURN 0H;
+		END GetPixel;
 
 		(** fill a rectangle within the current clipping rectangle *)
 		PROCEDURE Fill*(rect : Rectangle; color : Color; mode : LONGINT);
@@ -385,7 +390,7 @@ TYPE
 
 		PROCEDURE SetLimits*(r : Rectangle);
 		BEGIN
-			r.r := Max(r.r, r.l); r.b := Max(r.t, r.b);
+			Rectangles.Normalize(r);
 			Rectangles.ClipRect(r, bounds); SetLimits^(r)
 		END SetLimits;
 
@@ -393,6 +398,22 @@ TYPE
 		BEGIN
 		END Line; *)
 
+		PROCEDURE GetPixel*(x, y : LONGINT) : LONGINT;
+		VAR pix : Raster.Pixel;
+			mode : Raster.Mode;
+			r, g, b, a : LONGINT;
+		BEGIN
+			INC( x, dx ); INC( y, dy );
+			IF (x >= 0) & (y >= 0) & (x < img.width) & (y < img.height) THEN
+				Raster.InitMode(mode, Raster.srcCopy);
+				Raster.Get(img, x, y, pix, mode);
+				Raster.GetRGBA(pix, r, g, b, a);
+				RETURN RGBAToColor(r, g, b ,a);
+			ELSE
+				RETURN 0H;
+			END;
+		END GetPixel;
+
 		PROCEDURE Fill*(rect : Rectangle; color : Color; mode : LONGINT);
 		VAR rm : Raster.Mode; pix : Raster.Pixel;
 		BEGIN
@@ -843,7 +864,6 @@ BEGIN
 	imgCache.Clear;
 END ClearCache;
 
-
 BEGIN
  	nofFallbackFonts := 3;
 	NEW(imgCache)