--- a/GraphicsContext.st Sun May 08 03:59:02 2016 +0200
+++ b/GraphicsContext.st Sun May 08 03:59:41 2016 +0200
@@ -110,32 +110,32 @@
used like a `pen'.
A few drawing operations (opaqueForm and opaqueString drawing)
use two colors, the paint and a backgroundPaint. For example,
- normal string drawing (#displayString:...) only draws the fonts
+ normal string drawing (#displayString:...) only draws the font's
on-pixels in the current paint, leaving off-pixels unchanged.
In contrast, #drawOpaqueString:.. also changes these to the bgPaint color.
The bgPaint can be changed with #backgroundPaint: or #paint:on: (which modifies both).
lets try it in a view:
- [exBegin]
- |v|
-
- v := View new.
- v openAndWait.
-
- v paint:(Color red).
- v displayString:'hello' x:10 y:50
- [exEnd]
+ [exBegin]
+ |v|
+
+ v := View new.
+ v openAndWait.
+
+ v paint:(Color red).
+ v displayString:'hello' x:10 y:50
+ [exEnd]
the same using opaque drawing:
- [exBegin]
- |v|
-
- v := View new.
- v openAndWait.
-
- v paint:(Color red) on:(Color yellow).
- v displayOpaqueString:'hello' x:10 y:50
- [exEnd]
+ [exBegin]
+ |v|
+
+ v := View new.
+ v openAndWait.
+
+ v paint:(Color red) on:(Color yellow).
+ v displayOpaqueString:'hello' x:10 y:50
+ [exEnd]
@@ -145,65 +145,65 @@
`lineStyle' can be one of #solid, #dashed, #doubleDashed
where: #solid - is for solid lines, drawn with the current paint color
- #dashed - for dashed lines, where only the on-dashes are drawn
- with the current paint color
-
- #doubleDashed - dashed lines, draws on-dashes with paint color,
- off-dashes with bgPaint
+ #dashed - for dashed lines, where only the on-dashes are drawn
+ with the current paint color
+
+ #doubleDashed - dashed lines, draws on-dashes with paint color,
+ off-dashes with bgPaint
for example:
- [exBegin]
- |v|
-
- v := View new.
- v openAndWait.
-
- v paint:(Color red) on:(Color blue).
- v displayLineFrom:(10@10) to:(90@90).
-
- v lineStyle:#dashed.
- v displayLineFrom:(90@10) to:(10@90).
+ [exBegin]
+ |v|
+
+ v := View new.
+ v openAndWait.
+
+ v paint:(Color red) on:(Color blue).
+ v displayLineFrom:(10@10) to:(90@90).
+
+ v lineStyle:#dashed.
+ v displayLineFrom:(90@10) to:(10@90).
- v lineStyle:#doubleDashed.
- v displayRectangle:((5@5) corner:(95@95)).
- [exEnd]
+ v lineStyle:#doubleDashed.
+ v displayRectangle:((5@5) corner:(95@95)).
+ [exEnd]
changing the line-width:
- [exBegin]
- |v|
-
- v := View new.
- v openAndWait.
-
- v paint:(Color red).
- v displayLineFrom:(20@20) to:(80@80).
-
- v lineWidth:5.
- v displayLineFrom:(80@20) to:(20@80).
-
- v lineWidth:8.
- v displayRectangle:((5@5) corner:(95@95)).
- [exEnd]
+ [exBegin]
+ |v|
+
+ v := View new.
+ v openAndWait.
+
+ v paint:(Color red).
+ v displayLineFrom:(20@20) to:(80@80).
+
+ v lineWidth:5.
+ v displayLineFrom:(80@20) to:(20@80).
+
+ v lineWidth:8.
+ v displayRectangle:((5@5) corner:(95@95)).
+ [exEnd]
with wide lines, the corners (of polygons or rectangles) can be
one of the joinStyles: #miter, #bevel, #round. The default is #miter.
- [exBegin]
- |v|
-
- v := View new extent:200@200.
- v openAndWait.
-
- v lineWidth:15.
- v paint:(Color red).
-
- v displayRectangle:((65@65) corner:(135@135)).
-
- v joinStyle:#bevel.
- v displayRectangle:((45@45) corner:(155@155)).
-
- v joinStyle:#round.
- v displayRectangle:((25@25) corner:(175@175)).
- [exEnd]
+ [exBegin]
+ |v|
+
+ v := View new extent:200@200.
+ v openAndWait.
+
+ v lineWidth:15.
+ v paint:(Color red).
+
+ v displayRectangle:((65@65) corner:(135@135)).
+
+ v joinStyle:#bevel.
+ v displayRectangle:((45@45) corner:(155@155)).
+
+ v joinStyle:#round.
+ v displayRectangle:((25@25) corner:(175@175)).
+ [exEnd]
the endPoints look is controlled with capStyle;
@@ -212,128 +212,128 @@
#notLast is mostly useful when exoring (inverting): it will not draw the
endPoint, to allow another line to join the previous line without inverting
this point twice. (See the X manual for more info).
- [exBegin]
- |v|
-
- v := View new extent:200@200.
- v openAndWait.
-
- v lineWidth:15.
- v paint:(Color red).
-
- v displayLineFrom:(25@25) to:(175@25).
-
- v capStyle:#round.
- v displayLineFrom:(25@55) to:(175@55).
-
- v capStyle:#projecting.
- v displayLineFrom:(25@85) to:(175@85).
- [exEnd]
+ [exBegin]
+ |v|
+
+ v := View new extent:200@200.
+ v openAndWait.
+
+ v lineWidth:15.
+ v paint:(Color red).
+
+ v displayLineFrom:(25@25) to:(175@25).
+
+ v capStyle:#round.
+ v displayLineFrom:(25@55) to:(175@55).
+
+ v capStyle:#projecting.
+ v displayLineFrom:(25@85) to:(175@85).
+ [exEnd]
You can use a bitmap as a point color:
(this may be slow on some graphics devices, though)
- [exBegin]
- |v|
-
- v := View new extent:200@200.
- v openAndWait.
-
- v lineWidth:15.
- v paint:(Image fromFile:'granite_small.tiff').
-
- v displayLineFrom:(25@25) to:(175@25).
-
- v capStyle:#round.
- v displayLineFrom:(25@55) to:(175@55).
-
- v capStyle:#projecting.
- v displayLineFrom:(25@85) to:(175@85).
- [exEnd]
+ [exBegin]
+ |v|
+
+ v := View new extent:200@200.
+ v openAndWait.
+
+ v lineWidth:15.
+ v paint:(Image fromFile:'granite_small.tiff').
+
+ v displayLineFrom:(25@25) to:(175@25).
+
+ v capStyle:#round.
+ v displayLineFrom:(25@55) to:(175@55).
+
+ v capStyle:#projecting.
+ v displayLineFrom:(25@85) to:(175@85).
+ [exEnd]
all views support a translation and scale, so you can draw in another
coordinate system:
- [exBegin]
- |v|
-
- v := View new extent:200@200.
- v openAndWait.
-
- v displayForm:(Image fromFile:'SBrowser.xbm') x:10 y:10.
-
- v scale:(2@2); translation:50.
- v displayForm:(Image fromFile:'SBrowser.xbm') x:10 y:10.
-
- v scale:(0.5@0.5); translation:0.
- v displayForm:(Image fromFile:'SBrowser.xbm') x:10 y:10.
- [exEnd]
+ [exBegin]
+ |v|
+
+ v := View new extent:200@200.
+ v openAndWait.
+
+ v displayForm:(Image fromFile:'SBrowser.xbm') x:10 y:10.
+
+ v scale:(2@2); translation:50.
+ v displayForm:(Image fromFile:'SBrowser.xbm') x:10 y:10.
+
+ v scale:(0.5@0.5); translation:0.
+ v displayForm:(Image fromFile:'SBrowser.xbm') x:10 y:10.
+ [exEnd]
if scaling is on, it is often useful to be able to draw individual
things unscaled - this still translates the position, but
uses the unscaled font (for example, to draw strings in a graphic):
- [exBegin]
- |v|
-
- v := View new extent:200@200.
- v openAndWait.
-
- v displayForm:(Image fromFile:'SBrowser.xbm') x:10 y:10.
- v displayString:'hello' x:50 y:40.
-
- v scale:(2@4).
- v displayForm:(Image fromFile:'SBrowser.xbm') x:10 y:10.
- v displayUnscaledString:'hello' x:50 y:40.
- [exEnd]
+ [exBegin]
+ |v|
+
+ v := View new extent:200@200.
+ v openAndWait.
+
+ v displayForm:(Image fromFile:'SBrowser.xbm') x:10 y:10.
+ v displayString:'hello' x:50 y:40.
+
+ v scale:(2@4).
+ v displayForm:(Image fromFile:'SBrowser.xbm') x:10 y:10.
+ v displayUnscaledString:'hello' x:50 y:40.
+ [exEnd]
Filled objects are drawin using the #fillXXX methods; for example,
displayRectangleXXX draws the outline, while fillRectangleXXX draws a
filled one:
- [exBegin]
- |v|
-
- v := View new extent:200@200.
- v openAndWait.
-
- v displayArcIn:(20@20 corner:50@50) from:0 angle:180.
- v paint:Color yellow.
- v fillArcIn:(120@120 corner:150@150) from:0 angle:180.
-
- v paint:Color red.
- v displayCircle:150@50 radius:30.
- v paint:Color blue.
- v fillCircle:50@150 radius:30.
- [exEnd]
+ [exBegin]
+ |v|
+
+ v := View new extent:200@200.
+ v openAndWait.
+
+ v displayArcIn:(20@20 corner:50@50) from:0 angle:180.
+ v paint:Color yellow.
+ v fillArcIn:(120@120 corner:150@150) from:0 angle:180.
+
+ v paint:Color red.
+ v displayCircle:150@50 radius:30.
+ v paint:Color blue.
+ v fillCircle:50@150 radius:30.
+ [exEnd]
polygons:
- [exBegin]
- |v poly1 poly2|
-
- poly1 := OrderedCollection new.
- poly1 add:(10 @ 10).
- poly1 add:(100 @ 50).
- poly1 add:(50 @ 50).
- poly1 add:(20 @ 100).
- poly1 add:(10 @ 100).
-
- poly2 := poly1 copy.
- poly2 add:(poly2 first).
-
- v := View new extent:200@200.
- v openAndWait.
-
- v scale:2.
- v paint:Color red.
- v fillPolygon:poly1.
-
- v scale:1.
- v paint:Color blue.
- v displayPolygon:poly2.
-
- v scale:0.5.
- v paint:Color yellow.
- v fillPolygon:poly1.
-
- [exEnd]
+ [exBegin]
+ |v poly1 poly2|
+
+ poly1 := OrderedCollection new.
+ poly1 add:(10 @ 10).
+ poly1 add:(100 @ 50).
+ poly1 add:(50 @ 50).
+ poly1 add:(20 @ 100).
+ poly1 add:(10 @ 100).
+
+ poly2 := poly1 copy.
+ poly2 add:(poly2 first).
+
+ v := View new extent:200@200.
+ v openAndWait.
+
+ v scale:2.
+ v paint:Color red.
+ v fillPolygon:poly1.
+
+ v scale:1.
+ v paint:Color blue.
+ v displayPolygon:poly2.
+
+ v scale:0.5.
+ v paint:Color yellow.
+ v fillPolygon:poly1.
+
+ [exEnd]
"
! !