GraphicsContext.st
changeset 619 a46cb2ef56bf
parent 611 e0442439a3c6
child 653 0ad3de022f8b
--- a/GraphicsContext.st	Fri Apr 26 16:57:23 1996 +0200
+++ b/GraphicsContext.st	Sat Apr 27 19:53:57 1996 +0200
@@ -101,7 +101,7 @@
     The bgPaint can be changed with #backgroundPaint: or #paint:on: (which modifies both).
 
     lets try it in a view:
-
+                                                                        [exBegin]
         |v|
 
         v := View new.
@@ -109,8 +109,10 @@
 
         v paint:(Color red).
         v displayString:'hello' x:10 y:50
+                                                                        [exEnd]
 
     the same using opaque drawing:
+                                                                        [exBegin]
         |v|
 
         v := View new.
@@ -118,6 +120,7 @@
 
         v paint:(Color red) on:(Color yellow).
         v displayOpaqueString:'hello' x:10 y:50
+                                                                        [exEnd]
 
 
 
@@ -134,7 +137,7 @@
                            off-dashes with bgPaint
 
     for example:
-
+                                                                        [exBegin]
         |v|
 
         v := View new.
@@ -148,9 +151,10 @@
         
         v lineStyle:#doubleDashed.
         v displayRectangle:((5@5) corner:(95@95)).
+                                                                        [exEnd]
 
     changing the line-width:
-
+                                                                        [exBegin]
         |v|
 
         v := View new.
@@ -164,10 +168,11 @@
 
         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.
@@ -183,6 +188,7 @@
 
         v joinStyle:#round.
         v displayRectangle:((25@25) corner:(175@175)).
+                                                                        [exEnd]
 
 
     the endPoints look is controlled with capStyle;
@@ -191,7 +197,7 @@
     #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.
@@ -207,11 +213,12 @@
 
         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.
@@ -227,10 +234,11 @@
 
         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.
@@ -243,11 +251,12 @@
 
         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.
@@ -259,10 +268,12 @@
         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.
@@ -276,6 +287,38 @@
         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]
 "
 ! !
 
@@ -693,11 +736,13 @@
     "set the scale factor of the transformation"
 
     transformation isNil ifTrue:[
-	aPoint = 1 ifTrue:[^ self].
-	transformation := WindowingTransformation scale:aPoint translation:0
-    ].
+        aPoint = 1 ifTrue:[^ self].
+        transformation := WindowingTransformation scale:aPoint translation:0
+    ] ifFalse:[
+        transformation scale:aPoint.
+    ]
 
-    transformation scale:aPoint.
+    "Modified: 27.4.1996 / 18:47:38 / cg"
 !
 
 transformation 
@@ -710,6 +755,28 @@
     "set the transformation"
 
     transformation := aTransformation
+!
+
+translation
+    "return the translation factor (as point) of the transformation"
+
+    transformation isNil ifTrue:[^ 0@0].
+    ^ transformation translation
+
+    "Created: 27.4.1996 / 18:46:41 / cg"
+!
+
+translation:aPoint
+    "set the translation offset of the transformation"
+
+    transformation isNil ifTrue:[
+        aPoint = 0 ifTrue:[^ self].
+        transformation := WindowingTransformation scale:1 translation:aPoint
+    ] ifFalse:[
+        transformation translation:aPoint.
+    ]
+
+    "Created: 27.4.1996 / 18:47:28 / cg"
 ! !
 
 !GraphicsContext methodsFor:'basic displaying'!
@@ -1123,6 +1190,6 @@
 !GraphicsContext class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/GraphicsContext.st,v 1.27 1996-04-25 16:26:07 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/GraphicsContext.st,v 1.28 1996-04-27 17:53:57 cg Exp $'
 ! !
 GraphicsContext initialize!