ImageView.st
author claus
Sat, 08 Jan 1994 18:27:48 +0100
changeset 7 19b36b78ee01
parent 1 c6ca7bfedf31
child 9 96ccafc3b23d
permissions -rw-r--r--
*** empty log message ***

"
 COPYRIGHT (c) 1993 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:#ImageView
         instanceVariableNames:'image'
         classVariableNames:''
         poolDictionaries:''
         category:'Views-Misc'
!

ImageView comment:'

COPYRIGHT (c) 1993 by Claus Gittinger
              All Rights Reserved

$Header: /cvs/stx/stx/libwidg2/ImageView.st,v 1.2 1994-01-08 17:27:23 claus Exp $
'!

!ImageView class methodsFor:'startup'!

startOn:aFileName
    "startup an image viewer"

    |top v imageView img icnW icnH icn magX magY mag wg|

    top := StandardSystemView label:aFileName.
    top iconLabel:aFileName asFilename baseName.

    v := HVScrollableView for:self in:top.
    v origin:0@0 extent:1.0@1.0. 
    imageView := v scrolledView.

    img := Image fromFile:aFileName.
    img notNil ifTrue:[
        imageView image:img.

        "define an icon view showing little version of image.
         Since some window managers cannot handle this correctly (twm),
         this is only done when running on an IRIS"

        ((OperatingSystem getSystemType = 'iris') and:[self defaultStyle == #iris]) ifTrue:[
            icn := self new.

            "for now; should somehow get access to preferred iconview extent ..."
            icnW := 86.
            icnH := 68.

            ((img width <= icnW) and:[img height <= icnH]) ifTrue:[
                icn extent:(img width @ img height).
                mag := 1 @ 1
            ] ifFalse:[
                magX := icnW / img width.
                magY := icnH / img height.

                "scale image"
"
                mag := magX @ magY.
"
                "preserve ratio"
" 
                mag := (magX min:magY) asPoint.
" 
" "
                mag := (magX max:magY) asPoint.
" "

                icn extent:((img width @ img height) * mag) rounded.
            ].
            "start icon as a low prio bg process -
             so megnification and color allocation will not hurt us ..."

            ProcessorScheduler isPureEventDriven ifFalse:[
                wg := WindowGroup new.
                icn windowGroup:wg.
                wg addTopView:icn.
                wg startup.
                wg process priority:4.
            ].
            top iconView:icn.
        ].
    ].

    top open.

    icn notNil ifTrue:[
        [ 
            icn image:(img magnifyBy:mag).
        ] forkAt:4
    ].

    "ImageView startOn:'bitmaps/garfield.gif'"
! !

!ImageView class methodsFor:'documentation'!

documentation
"
This View knows how to display an image (or form).

You can display an image with:

        (ImageView new image:anImage) realize

        i.e.

        (ImageView new image:(Image fromFile:''bitmaps/garfield.gif'')) realize
        (ImageView new image:(Image fromFile:''bitmaps/dano.tiff'')) realize
        (ImageView new image:(Form fromFile:''SBrowser.xbm'')) realize

        or simply by:

        ImageView startOn:''bitmaps/garfield.gif''

"
! !

!ImageView methodsFor:'release'!

destroy
    image := nil.
    super destroy.
! !

!ImageView methodsFor:'drawing'!

redraw
    image notNil ifTrue:[
        image := image on:device.
        self clear.
        self foreground:Black background:White.
        self function:#copy.
        self drawOpaqueForm:image x:(0 - viewOrigin x) y:(0 - viewOrigin y)
    ]
! !

!ImageView methodsFor:'accessing'!

image:anImage
    "set the image - show a wait cursor, since image dithering may take a while"

    image := anImage.
    anImage notNil ifTrue:[
        self cursor:Cursor wait.
        shown ifTrue:[
            self redraw
        ].
        self contentsChanged.
        self cursor:(Cursor normal).
    ].

    "ImageView new realize image:(Image fromFile:'bitmaps/claus.gif')"
!

image
    "return the image"

    ^ image
! !

!ImageView methodsFor:'queries'!

widthOfContents
    "return the images width - scrollbar needs this info"

    image isNil ifTrue:[^ 0].
    ^ image width
!

heightOfContents
    "return the images height - scrollbar needs this info"

    image isNil ifTrue:[^ 0].
    ^ image height
! !