StrokingWrapper.st
changeset 279 bf069aab8a8c
parent 273 f76fb9098814
child 280 39e270e5aa30
--- a/StrokingWrapper.st	Wed May 29 00:43:39 1996 +0200
+++ b/StrokingWrapper.st	Wed May 29 00:43:47 1996 +0200
@@ -11,14 +11,14 @@
 "
 
 
-GeometricWrapper subclass:#StrokingWrapper
-	instanceVariableNames:'lineWidth lineStyle capStyle joinStyle'
+Wrapper subclass:#TranslatingWrapper
+	instanceVariableNames:'origin'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Graphics-Display Objects'
 !
 
-!StrokingWrapper class methodsFor:'documentation'!
+!TranslatingWrapper class methodsFor:'documentation'!
 
 copyright
 "
@@ -37,12 +37,9 @@
 
 documentation
 "
-    a wrapper for a geometric object, which is to be drawn stroked.
-    This allows any geometric thingy to be used as a component in a view.
-
-    (background info: geometrics are mathematical objects - they do not 
-     keep any color or lineStyle attributes. Wrappers add this information
-     and can also be used as components of a view)
+    a wrapper which shifts the origin of its wrapped component.
+    This allows the wrapped thingy to think & draw in its own 0/0 based
+    coordinates.
 
     Notice: 
         this class was implemented using protocol information
@@ -52,7 +49,7 @@
         describing the incompatibility verbal (i.e. no code) to the ST/X team.
 
     [see also:]
-        FillingWrapper Geometric GraphicsContext
+        Wrapper 
 
     [author:]
         Claus Gittinger
@@ -61,73 +58,7 @@
 
 examples
 "
-  wrap an ellipticArc and display it
-  (notice, that no automatic redraw is performed):
-                                                                        [exBegin]
-    |v e component|
-
-    v := (StandardSystemView extent:250@250) openAndWait.
-
-    e := EllipticalArc boundingBox:(10@10 corner:90@90)
-                        startAngle:0 
-                        sweepAngle:270.
-    component := StrokingWrapper on:e.
-
-    component displayOn:v.
-                                                                        [exEnd]
-
-  wrap a rectangle and an ellipticArc,
-  and add them as components to a View
-  (notice, that doing so makes the redraw automatic):
-                                                                        [exBegin]
-    |v e component|
-
-    v := StandardSystemView extent:250@250.
-
-    e := Rectangle origin:10@10 corner:90@90.
-    component := FillingWrapper on:e.
-    component foregroundColor:Color red.
-
-    v addComponent:component.
-
-    e := EllipticalArc boundingBox:(10@10 corner:90@90)
-                     startAngle:0 sweepAngle:360.
-    component := StrokingWrapper on:e.
-    component lineWidth:5.
-
-    v addComponent:component.
-
-    v addComponent:(Button label:'hello').
-
-    v open
-                                                                        [exEnd]
-  with lineWidth & style:
-  (notice, that the redraw is automatic):
-                                                                        [exBegin]
-    |v e|
-
-    v := StandardSystemView extent:250@250.
-
-    e := EllipticalArc boundingBox:(10@10 corner:90@90)
-                        startAngle:0 
-                        sweepAngle:270.
-    v addComponent:((StrokingWrapper on:e)
-                        lineWidth:5;
-                        lineStyle:#dashed;
-                        foregroundColor:(Color red)).
-
-    e := EllipticalArc boundingBox:(30@30 corner:70@70)
-                        startAngle:90 
-                        sweepAngle:270.
-    v addComponent:((StrokingWrapper on:e)
-                        lineWidth:5;
-                        lineStyle:#doubleDashed;
-                        foregroundColor:(Color red);
-                        backgroundColor:(Color green)).
-    v open.
-                                                                        [exEnd]
-
-  scrolling:
+  some components without translatingWrapper
                                                                         [exBegin]
     |t s v e component|
 
@@ -152,7 +83,48 @@
     component lineWidth:2.
     v addComponent:component.
 
-    v addComponent:(Button label:'hello').
+    t open
+                                                                        [exEnd]
+  the same components WITH translatingWrappers
+                                                                        [exBegin]
+    |t s v e component|
+
+    t := StandardSystemView extent:250@200.
+    s := HVScrollableView for:View miniScroller:true in:t.
+    s origin:0.0@0.0 corner:1.0@1.0.
+    v := s scrolledView.
+
+    e := Rectangle origin:0@0 corner:80@80.
+    component := FillingWrapper on:e.
+    component foregroundColor:Color red.
+    v addComponent:(TranslatingWrapper on:component at:10@10).
+
+    e := EllipticalArc boundingBox:(0@0 corner:80@80)
+                     startAngle:0 sweepAngle:360.
+    component := StrokingWrapper on:e.
+    component lineWidth:5.
+    v addComponent:(TranslatingWrapper on:component at:10@10).
+
+    e := Arrow from:0@0 to:50@150.
+    component := StrokingWrapper on:e.
+    component lineWidth:2.
+    v addComponent:(TranslatingWrapper on:component at:100@100).
+
+    v addComponent:(TranslatingWrapper on:(Image fromFile:'SBrowser.xbm') at:0@100).
+
+    t open
+                                                                        [exEnd]
+                                                                        [exBegin]
+    |t s v e component|
+
+    t := StandardSystemView extent:250@200.
+    s := HVScrollableView for:View miniScroller:true in:t.
+    s origin:0.0@0.0 corner:1.0@1.0.
+    v := s scrolledView.
+
+    e := LabelAndIcon icon:(Image fromFile:'bitmaps/SBrowser.xbm')
+                     string:'hello'.
+    v addComponent:(TranslatingWrapper on:e at:10@10).
 
     t open
                                                                         [exEnd]
@@ -160,145 +132,96 @@
 "
 ! !
 
-!StrokingWrapper methodsFor:'accessing'!
-
-bounds
-    "return the boundary rectangle - here, must take care of the lineWidth"
-
-    ^ component bounds insetBy:(lineWidth // 2 + 1) negated
+!TranslatingWrapper class methodsFor:'instance creation'!
 
-    "Created: 8.5.1996 / 23:22:43 / cg"
-    "Modified: 26.5.1996 / 13:03:50 / cg"
-!
+on:aComponent at:originPoint
+    "create and return a translatingWrapper, which positions
+     aComponent at some originPoint"
 
-capStyle
-    "return the capStyle"
-
-    ^ capStyle
+    ^ (self on:aComponent) translation:originPoint
 
-    "Created: 8.5.1996 / 23:22:04 / cg"
-    "Modified: 9.5.1996 / 00:09:12 / cg"
-!
+    "Created: 26.5.1996 / 16:07:29 / cg"
+    "Modified: 26.5.1996 / 16:12:28 / cg"
+! !
 
-capStyle:aSymbol
-    "set the capStyle"
-
-    capStyle := aSymbol
+!TranslatingWrapper methodsFor:'accessing'!
 
-    "Created: 8.5.1996 / 23:22:13 / cg"
-    "Modified: 9.5.1996 / 00:09:17 / cg"
-!
+translation
+    "return the origin offset"
 
-joinStyle
-    "return the joinStyle"
+    ^ origin
 
-    ^ joinStyle
-
-    "Created: 8.5.1996 / 23:22:04 / cg"
-    "Modified: 9.5.1996 / 00:09:12 / cg"
+    "Modified: 26.5.1996 / 16:06:32 / cg"
 !
 
-joinStyle:aSymbol
-    "set the joinStyle"
+translation:originPoint
+    "set the origin offset"
 
-    joinStyle := aSymbol
+    origin := originPoint
 
-    "Created: 8.5.1996 / 23:22:13 / cg"
-    "Modified: 9.5.1996 / 00:09:17 / cg"
-!
+    "Modified: 26.5.1996 / 16:06:32 / cg"
+    "Created: 26.5.1996 / 16:07:47 / cg"
+! !
+
+!TranslatingWrapper methodsFor:'accessing - bounds'!
 
-lineStyle
-    "return the lineStyle"
+bounds
+    ^ component bounds + origin
 
-    ^ lineStyle
-
-    "Created: 8.5.1996 / 23:22:04 / cg"
-    "Modified: 9.5.1996 / 00:09:12 / cg"
+    "Created: 26.5.1996 / 16:13:05 / cg"
+    "Modified: 26.5.1996 / 16:44:26 / cg"
 !
 
-lineStyle:aSymbol
-    "set the lineStyle"
-
-    lineStyle := aSymbol
-
-    "Created: 8.5.1996 / 23:22:13 / cg"
-    "Modified: 9.5.1996 / 00:09:17 / cg"
-!
-
-lineWidth
-    "return the lineWidth"
+bounds:newBounds
+    component bounds:(newBounds - origin).
 
-    ^ lineWidth
-
-    "Created: 8.5.1996 / 23:22:04 / cg"
-    "Modified: 9.5.1996 / 00:09:12 / cg"
-!
-
-lineWidth:aNumber
-    "set the lineWidth"
-
-    lineWidth := aNumber
-
-    "Created: 8.5.1996 / 23:22:13 / cg"
-    "Modified: 9.5.1996 / 00:09:17 / cg"
+    "Created: 26.5.1996 / 16:44:16 / cg"
 !
 
 preferredBounds
-    "return the components bounds as preferredBounds"
+    ^ component preferredBounds + origin
 
-    ^ self bounds
-
-    "Created: 8.5.1996 / 23:23:00 / cg"
-    "Modified: 9.5.1996 / 00:09:31 / cg"
+    "Modified: 26.5.1996 / 16:44:26 / cg"
+    "Created: 26.5.1996 / 16:44:53 / cg"
 ! !
 
-!StrokingWrapper methodsFor:'displaying'!
+!TranslatingWrapper methodsFor:'displaying'!
 
 displayOn:aGC
-    "display myself - here, display the geometric object asStroked"
-
-    |prevLineWidth prevLineStyle prevCapStyle prevJoinStyle 
-     prevFg prevBg|
+    |oldTranslation oldPaint oldBgPaint|
 
-    prevLineWidth := aGC lineWidth.
-    prevLineStyle := aGC lineStyle.
-    prevJoinStyle := aGC joinStyle.
-    prevCapStyle  := aGC capStyle.
-    prevFg := aGC paint.
-    prevBg := aGC backgroundPaint.
+    oldTranslation := aGC translation.
+    oldPaint := aGC paint.
+    oldBgPaint := aGC backgroundPaint.
 
-    aGC lineWidth:lineWidth.
-    aGC lineStyle:lineStyle.
-    aGC joinStyle:joinStyle.
-    aGC capStyle:capStyle.
+    aGC translation:(origin + aGC translation).
     aGC paint:fgColor on:bgColor.
 
-    component displayStrokedOn:aGC.
+    component displayOn:aGC.
 
-    aGC lineWidth:prevLineWidth.
-    aGC lineStyle:prevLineStyle.
-    aGC joinStyle:prevJoinStyle.
-    aGC capStyle:prevCapStyle.
-    aGC paint:prevFg on:prevBg.
+    aGC translation:oldTranslation.
+    aGC paint:oldPaint on:oldBgPaint.
 
-    "Created: 8.5.1996 / 23:24:04 / cg"
-    "Modified: 9.5.1996 / 00:11:17 / cg"
+    "Created: 26.5.1996 / 15:27:54 / cg"
+    "Modified: 26.5.1996 / 16:13:44 / cg"
 ! !
 
-!StrokingWrapper methodsFor:'initialization'!
+!TranslatingWrapper methodsFor:'testing'!
 
-initialize
-    "default my lineWidth to one pixel"
+containsPoint:aPoint
+    ^ component containsPoint:(aPoint - origin)
 
-    super initialize.
-    lineWidth := 1.
+    "Created: 26.5.1996 / 16:48:14 / cg"
+!
 
-    "Created: 8.5.1996 / 23:49:27 / cg"
-    "Modified: 9.5.1996 / 00:11:51 / cg"
+intersects:aRectangle
+    ^ component intersects:(aRectangle - origin)
+
+    "Created: 26.5.1996 / 16:48:33 / cg"
 ! !
 
-!StrokingWrapper class methodsFor:'documentation'!
+!TranslatingWrapper class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/StrokingWrapper.st,v 1.9 1996-05-26 11:09:58 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/StrokingWrapper.st,v 1.10 1996-05-28 22:43:43 cg Exp $'
 ! !