PluggableView.st
author Claus Gittinger <cg@exept.de>
Sat, 12 May 2018 14:23:45 +0200
changeset 4088 bbf9b58f99c8
parent 1683 669504c9453c
child 3855 1db7742d33ad
permissions -rw-r--r--
#FEATURE by cg class: MIMETypes class changed: #initializeFileInfoMappings class: MIMETypes::MIMEType added: #asMimeType #isCHeaderType #isCPPSourceType #isCSourceType

"{ 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.
    v viewBackground:Color black.
    v redrawAction:[
        |offsX offsY scaleX scaleY|

        scaleX := v width - 10 // 2.
        scaleY := v height - 10 // 2.
        offsX := v width // 2.
        offsY := v height // 2.

        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 open.
                                                                [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
    ]
!

sizeChanged:how
    super sizeChanged:how.
    self clear.
    self redraw.
! !

!PluggableView class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libview2/PluggableView.st,v 1.2 2003-01-09 16:58:22 cg Exp $'
! !