ShadowView.st
author claus
Fri, 03 Jun 1994 02:54:39 +0200
changeset 46 7b331e9012fd
parent 12 9f0995fac1fa
child 54 29a6b2f8e042
permissions -rw-r--r--
*** empty log message ***

"
 COPYRIGHT (c) 1991 by Claus Gittinger
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

View subclass:#ShadowView
       instanceVariableNames:'myView shadowLength shadow imageUnderShadow'
       classVariableNames:''
       poolDictionaries:''
       category:'Views-Basic'
!

ShadowView comment:'
COPYRIGHT (c) 1991 by Claus Gittinger
              All Rights Reserved
'!

!ShadowView class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1991 by Claus Gittinger
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

version
"
$Header: /cvs/stx/stx/libview/ShadowView.st,v 1.6 1994-06-03 00:53:37 claus Exp $
"
!

documentation
"
    just to give PopUps and ModalBoxes a shadow. A ShadowView just paints black.
    The instance variable myView is the view, the shadow is for.
"
! !

!ShadowView methodsFor:'initialization'!

initialize
    super initialize.
    borderWidth := 0.
    shadow := Black.

    "the length of the shadow from myView"
    shadowLength := (device pixelPerMillimeter * 1.0) rounded
!

realize
    "realize the shadowView some distance away from myView"

    |root shW shH right bot kludge|

    myView notNil ifTrue:[
        self origin:(myView origin + (myView borderWidth * 2) + shadowLength) extent:(myView extent).

        imageUnderShadow := Form width:width height:height depth:device depth on:device.
        imageUnderShadow initGC.
        device setClipByChildren:false in:imageUnderShadow gcId.

        shW := shadowLength x.
        shH := shadowLength y.
        right := width - shW.
        bot := height - shH.

        root := DisplayRootView new.

        kludge := root device depth == 1.
        (kludge and:[root device blackpixel == 0]) ifTrue:[
            imageUnderShadow foreground:(Color colorId:0)
                             background:(Color colorId:1).
        ].

        imageUnderShadow copyFrom:root x:(self origin x + right) y:(self origin y) 
                                     toX:right y:0 width:shW height:height.

        imageUnderShadow copyFrom:root x:(self origin x) y:(self origin y + bot) 
                                     toX:0 y:bot width:width height:shH.

        "grey out image in area"

        (kludge and:[root device blackpixel == 0]) ifFalse:[
            imageUnderShadow foreground:(Color colorId:0) background:(Color colorId:-1).
            imageUnderShadow mask:(Form mediumGreyFormOn:device).
            imageUnderShadow function:#and.
            imageUnderShadow fillRectangleX:0 y:0 width:width height:height.

            (Color black on:device) colorId == 0 ifFalse:[
                imageUnderShadow foreground:(Color black on:device) background:(Color colorId:0).
                imageUnderShadow function:#or.
                imageUnderShadow fillRectangleX:0 y:0 width:width height:height.
            ]
        ] ifTrue:[
            imageUnderShadow foreground:(Color colorId:1) background:(Color colorId:0).
            imageUnderShadow mask:(Form mediumGreyFormOn:device).
            imageUnderShadow function:#or.
            imageUnderShadow fillRectangleX:0 y:0 width:width height:height.
        ].

        super realize.
        self raise
    ]
!

unrealize
    "realize the shadowView some distance away from myView"

    imageUnderShadow := nil.
    super unrealize.
!

create
    super create.
    self backingStore:false.
    self saveUnder:true
!

recreate
    shadow := Black.

    "the length of the shadow from myView"
    shadowLength := (device pixelPerMillimeter * 1.0) rounded.

    super recreate.
    self backingStore:false.
    self saveUnder:true
! !

!ShadowView methodsFor:'events'!

redraw
    "fill all of myself with black"

    imageUnderShadow isNil ifTrue:[^ self].

"
    self foreground:(Color colorId:-1) background:(Color colorId:0).
    self function:#copy.
"
    self copyFrom:imageUnderShadow x:(width - shadowLength x) y:0 
                                 toX:(width - shadowLength x) y:0 width:shadowLength x height:height.
    self copyFrom:imageUnderShadow x:0 y:(height - shadowLength y) 
                                 toX:0 y:(height - shadowLength y) width:width height:shadowLength y.

" 
    self paint:shadow.
    self fillRectangleX:0 y:0 width:width height:height
" 
! !

!ShadowView methodsFor:'accessing'!

shadowColor:aColor
    "to set the shadow color"

    shadow := aColor
!

for:aView
    "set the view I am for"

    myView := aView
!

createOnTop
    ^ true
! !