GraphicsContext.st
changeset 7463 48202ec4ce92
parent 7457 c1b084d31bb9
child 7474 ff35cd980d70
equal deleted inserted replaced
7462:3bcd29332df8 7463:48202ec4ce92
       
     1 "{ Encoding: utf8 }"
       
     2 
     1 "
     3 "
     2  COPYRIGHT (c) 1992 by Claus Gittinger
     4  COPYRIGHT (c) 1992 by Claus Gittinger
     3 	      All Rights Reserved
     5 	      All Rights Reserved
     4 
     6 
     5  This software is furnished under a license and may be used
     7  This software is furnished under a license and may be used
   690 
   692 
   691     "Modified: 12.5.1996 / 22:25:17 / cg"
   693     "Modified: 12.5.1996 / 22:25:17 / cg"
   692 !
   694 !
   693 
   695 
   694 blackColor
   696 blackColor
       
   697     "return the black color on this device.
       
   698      This is the same as 'Color black onDevice:self device', but much faster."
       
   699 
   695     ^ device blackColor
   700     ^ device blackColor
   696 !
   701 !
   697 
   702 
   698 capStyle
   703 capStyle
   699     "return the current cap-style for line-drawing.
   704     "return the current cap-style for line-drawing.
   743     ].
   748     ].
   744 
   749 
   745     "Modified (comment): / 25-01-2012 / 00:29:37 / cg"
   750     "Modified (comment): / 25-01-2012 / 00:29:37 / cg"
   746 !
   751 !
   747 
   752 
   748 clipRect
       
   749     "return the clip-rectangle for drawing (in logical coordinates).
       
   750      If there is currently no active clip, return the underlying
       
   751      displaySurfaces (i.e. views) bounds. Added for ST-80 compatibility."
       
   752 
       
   753     <resource:#obsolete>
       
   754 
       
   755     self obsoleteMethodWarning:'use #clippingBounds'.
       
   756     ^ self clippingBounds.
       
   757 
       
   758     "Modified: 28.5.1996 / 14:14:53 / cg"
       
   759 !
       
   760 
       
   761 clipRect:aRectangle
       
   762     "set the drawing clip-rectangle (in logical coordinates)"
       
   763 
       
   764     <resource:#obsolete>
       
   765 
       
   766     self obsoleteMethodWarning:'use #clippingBounds:'.
       
   767     ^ self clippingBounds:aRectangle
       
   768 
       
   769     "Modified: 28.5.1996 / 14:13:09 / cg"
       
   770 !
       
   771 
       
   772 clippingBounds
   753 clippingBounds
   773     "return the clip-rectangle for drawing (in logical coordinates).
   754     "return the clip-rectangle for drawing (in logical coordinates).
   774      If there is currently no active clip, return the underlying
   755      If there is currently no active clip, return the underlying
   775      medium (i.e. device) bounds. Added for ST-80 compatibility."
   756      medium (i.e. device) bounds. Added for ST-80 compatibility."
   776 
   757 
   812 	^ nil
   793 	^ nil
   813     ].
   794     ].
   814     transformation notNil ifTrue:[
   795     transformation notNil ifTrue:[
   815 	^ transformation applyInverseTo:clipRect.
   796 	^ transformation applyInverseTo:clipRect.
   816     ].
   797     ].
   817     ^ clipRect
       
   818 
       
   819     "Created: 10.4.1996 / 14:32:02 / cg"
       
   820     "Modified: 28.5.1996 / 14:08:19 / cg"
       
   821 !
       
   822 
       
   823 clippingRectangle:aRectangleOrNil
       
   824     <resource: #obsolete>
       
   825     "set the clipping rectangle for drawing (in logical coordinates);
       
   826      a nil argument turn off clipping (i.e. whole view is drawable)"
       
   827 
       
   828     self clippingBounds:aRectangleOrNil.
       
   829 
       
   830     "Modified: 22.5.1996 / 13:12:07 / cg"
       
   831     "Created: 28.5.1996 / 14:09:27 / cg"
       
   832 !
       
   833 
       
   834 clippingRectangleOrNil
       
   835     <resource: #obsolete>
       
   836     "return the clipping rectangle for drawing in logical coordinates, nil if there is none."
       
   837 
       
   838     ^ clipRect
   798     ^ clipRect
   839 
   799 
   840     "Created: 10.4.1996 / 14:32:02 / cg"
   800     "Created: 10.4.1996 / 14:32:02 / cg"
   841     "Modified: 28.5.1996 / 14:08:19 / cg"
   801     "Modified: 28.5.1996 / 14:08:19 / cg"
   842 !
   802 !
  1023     bgPaint := bgColor
   983     bgPaint := bgColor
  1024 
   984 
  1025     "Modified: 12.5.1996 / 19:40:43 / cg"
   985     "Modified: 12.5.1996 / 19:40:43 / cg"
  1026 !
   986 !
  1027 
   987 
  1028 setMaskOrigin:aPoint
       
  1029     <resource: #obsolete>
       
  1030     "set the origin within the mask (used to draw with patterns).
       
  1031      OBSOLETE: use #maskOrigin: or #phase:"
       
  1032 
       
  1033     self obsoleteMethodWarning:'use #maskOrigin:'.
       
  1034     ^ self maskOriginX:aPoint x y:aPoint y
       
  1035 
       
  1036     "Modified: / 26.1.1998 / 18:54:14 / cg"
       
  1037 !
       
  1038 
       
  1039 setMaskOriginX:x y:y
       
  1040     <resource: #obsolete>
       
  1041     "set the origin within the mask (used to draw with patterns).
       
  1042      OBSOLETE: use #maskOriginX:y: or #phase:"
       
  1043 
       
  1044     self obsoleteMethodWarning:'use #maskOriginX:y:'.
       
  1045     ^ self maskOriginX:x y:y
       
  1046 !
       
  1047 
       
  1048 viewOrigin
   988 viewOrigin
  1049     "return the drawables visible origin (for scrolling)"
   989     "return the drawables visible origin (for scrolling)"
  1050 
   990 
  1051     ^ 0@0
   991     ^ 0@0
  1052 !
   992 !
  1053 
   993 
  1054 whiteColor
   994 whiteColor
  1055     "return the white color on this device.
   995     "return the white color on this device.
  1056      This is the same as 'Color white on:self device', but much faster."
   996      This is the same as 'Color white onDevice:self device', but much faster."
  1057 
   997 
  1058     ^ device whiteColor
   998     ^ device whiteColor
  1059 ! !
   999 ! !
  1060 
  1000 
  1061 !GraphicsContext methodsFor:'accessing-transformation'!
  1001 !GraphicsContext methodsFor:'accessing-transformation'!
  1125     ] ifFalse:[
  1065     ] ifFalse:[
  1126 	transformation translation:aPoint.
  1066 	transformation translation:aPoint.
  1127     ]
  1067     ]
  1128 
  1068 
  1129     "Created: 27.4.1996 / 18:47:28 / cg"
  1069     "Created: 27.4.1996 / 18:47:28 / cg"
  1130 ! !
       
  1131 
       
  1132 !GraphicsContext methodsFor:'backward compatibility'!
       
  1133 
       
  1134 withPattern:aPattern do:aBlock
       
  1135     <resource: #obsolete>
       
  1136     |old|
       
  1137 
       
  1138     aPattern isColor ifTrue:[
       
  1139 	old := paint.
       
  1140 	self paint:aPattern.
       
  1141 	aBlock value.
       
  1142 	self paint:old
       
  1143     ] ifFalse:[
       
  1144 	old := mask.
       
  1145 	self mask:aPattern.
       
  1146 	aBlock value.
       
  1147 	self mask:old
       
  1148     ]
       
  1149 
       
  1150     "Modified: 28.5.1996 / 22:45:40 / cg"
       
  1151 ! !
  1070 ! !
  1152 
  1071 
  1153 !GraphicsContext methodsFor:'basic drawing'!
  1072 !GraphicsContext methodsFor:'basic drawing'!
  1154 
  1073 
  1155 displayArcX:x y:y width:width height:height from:startAngle angle:angle
  1074 displayArcX:x y:y width:width height:height from:startAngle angle:angle
  1248 "/                ].
  1167 "/                ].
  1249 "/    h := 3.
  1168 "/    h := 3.
  1250 "/    w := 8.
  1169 "/    w := 8.
  1251 
  1170 
  1252     pattern := #[
  1171     pattern := #[
  1253 		 2r11001100 2r11001100 2r11001100 2r11001100
  1172                  2r11001100 2r11001100 2r11001100 2r11001100
  1254 		 2r00110011 2r00110011 2r00110011 2r00110011
  1173                  2r00110011 2r00110011 2r00110011 2r00110011
  1255 		].
  1174                 ].
  1256     h := 2.
  1175     h := 2.
  1257     w := 32.
  1176     w := 32.
  1258 
  1177 
  1259 "/    pattern := #[
  1178 "/    pattern := #[
  1260 "/                 2r11000000
  1179 "/                 2r11000000
  1263 "/    h := 2.
  1182 "/    h := 2.
  1264 "/    w := 4.
  1183 "/    w := 4.
  1265 
  1184 
  1266     form := Form width:w height:h fromArray:pattern.
  1185     form := Form width:w height:h fromArray:pattern.
  1267 
  1186 
  1268     oldClip := self clippingRectangleOrNil.
  1187     oldClip := self clippingBoundsOrNil.
  1269     self clippingRectangle:((x0 @ y0) corner:(x1 @ (y0+h))).
  1188     self clippingBounds:((x0 @ y0) corner:(x1 @ (y0+h))).
  1270 
  1189 
  1271     x := x0 truncateTo:w.
  1190     x := x0 truncateTo:w.
  1272     [x <= x1] whileTrue:[
  1191     [x <= x1] whileTrue:[
  1273 	self displayForm:form x:x y:y0.
  1192         self displayForm:form x:x y:y0.
  1274 	x := x + w.
  1193         x := x + w.
  1275     ].
  1194     ].
  1276     self clippingRectangle:oldClip
  1195     self clippingBounds:oldClip
  1277 
  1196 
  1278     "Created: / 28-10-1998 / 15:31:41 / cg"
  1197     "Created: / 28-10-1998 / 15:31:41 / cg"
  1279     "Modified: / 24-07-2011 / 21:12:24 / cg"
  1198     "Modified: / 24-07-2011 / 21:12:24 / cg"
  1280 !
  1199 !
  1281 
  1200 
  2264 
  2183 
  2265     "Created: 13.4.1996 / 20:56:56 / cg"
  2184     "Created: 13.4.1996 / 20:56:56 / cg"
  2266     "Modified: 8.5.1996 / 08:42:23 / cg"
  2185     "Modified: 8.5.1996 / 08:42:23 / cg"
  2267 !
  2186 !
  2268 
  2187 
  2269 fillArcX:x y:y w:w h:h from:startAngle angle:angle
       
  2270     "draw a filled arc; apply transformation if nonNil"
       
  2271 
       
  2272     <resource:#obsolete>
       
  2273 
       
  2274     self obsoleteMethodWarning:'use #fillArcX:y:width:height:from:angle:'.
       
  2275     self fillArcX:x y:y width:w height:h from:startAngle angle:angle
       
  2276 
       
  2277     "Modified: 8.5.1996 / 08:47:52 / cg"
       
  2278 !
       
  2279 
       
  2280 fillArcX:x y:y width:w height:h from:startAngle to:endAngle
  2188 fillArcX:x y:y width:w height:h from:startAngle to:endAngle
  2281     "draw a filled arc in a box, given startAngle and endAngle."
  2189     "draw a filled arc in a box, given startAngle and endAngle."
  2282 
  2190 
  2283     self
  2191     self
  2284 	fillArcX:x
  2192 	fillArcX:x
  2443 
  2351 
  2444 clippedTo:aRectangle do:aBlock
  2352 clippedTo:aRectangle do:aBlock
  2445     |oldClip|
  2353     |oldClip|
  2446 
  2354 
  2447     oldClip := clipRect.
  2355     oldClip := clipRect.
  2448     self clippingRectangle:aRectangle.
  2356     self clippingBounds:aRectangle.
  2449 
  2357     aBlock ensure:[
  2450     aBlock
  2358         self clippingBounds:oldClip
  2451 	ensure:[
  2359     ].
  2452 	    self clippingRectangle:oldClip
       
  2453 	]
       
  2454 !
  2360 !
  2455 
  2361 
  2456 flush
  2362 flush
  2457     "send all buffered drawing to the device."
  2363     "send all buffered drawing to the device."
  2458 
  2364