PluggableView.st
changeset 1682 b8da003d700a
child 1683 669504c9453c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PluggableView.st	Thu Jan 09 17:55:11 2003 +0100
@@ -0,0 +1,107 @@
+"{ Package: 'stx:libview2' }"
+
+View subclass:#PluggableView
+	instanceVariableNames:'redrawAction buttonPressAction keyPressAction'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Views-Basic'
+!
+
+!PluggableView class methodsFor:'documentation'!
+
+documentation
+"
+    a view for which the redraw, button and key-actions can be plugged as
+    blocks.
+    Mostly useful for little examples (where we dont want to add a full-blown class
+    for.
+
+    [author:]
+        Claus Gittinger (cg@alan)
+
+    [instance variables:]
+
+    [class variables:]
+
+    [see also:]
+
+"
+!
+
+examples
+"
+
+    a simple lissajous figure
+                                                                [exBegin]
+    |v|
+
+    v := PluggableView new openAndWait.
+    v redrawAction:[
+        |offsX offsY scaleX scaleY|
+
+        scaleX := scaleY := 40.
+        offsX := offsY := 50.
+
+        0 to:360 do:[:degrees |
+            |radians x y|
+
+            radians := degrees degreesToRadians.
+            x := (radians * 3 ) cos.
+            y := (radians * 5 ) sin.
+
+            x := x * scaleX + offsX.
+            y := y * scaleY + offsY.
+            v atX:x y:y put:Color red.
+        ].
+    ].
+    v redraw
+                                                                [exEnd]
+"
+! !
+
+!PluggableView methodsFor:'accessing'!
+
+buttonPressAction:something
+    "set the value of the instance variable 'buttonPressAction' (automatically generated)"
+
+    buttonPressAction := something.
+!
+
+keyPressAction:something
+    "set the value of the instance variable 'keyPressAction' (automatically generated)"
+
+    keyPressAction := something.
+!
+
+redrawAction:something
+    "set the value of the instance variable 'redrawAction' (automatically generated)"
+
+    redrawAction := something.
+! !
+
+!PluggableView methodsFor:'events'!
+
+buttonPress:button x:x y:y
+    buttonPressAction notNil ifTrue:[
+        buttonPressAction value:button value:(x @ y)
+    ]
+!
+
+keyPress:key x:x y:y
+    keyPressAction notNil ifTrue:[
+        keyPressAction value:key value:(x @ y)
+    ]
+!
+
+redraw
+    super redraw.
+    redrawAction notNil ifTrue:[
+        redrawAction value
+    ]
+! !
+
+!PluggableView class methodsFor:'documentation'!
+
+version
+    ^ '$Header: /cvs/stx/stx/libview2/PluggableView.st,v 1.1 2003-01-09 16:55:11 cg Exp $'
+! !