ImageView.st
changeset 5387 278d666f9267
parent 5268 b490144a4971
child 5398 3c4304d0d819
equal deleted inserted replaced
5386:4a69442cbcd1 5387:278d666f9267
   286     "Modified: / 01-06-2010 / 18:31:14 / cg"
   286     "Modified: / 01-06-2010 / 18:31:14 / cg"
   287 ! !
   287 ! !
   288 
   288 
   289 !ImageView methodsFor:'accessing'!
   289 !ImageView methodsFor:'accessing'!
   290 
   290 
       
   291 adjust
       
   292     "get the adjust (how the image is displayed);
       
   293      currently, only support #topLeft, #center, #fitBig, #fitSmall and #fit:
       
   294             #topLeft    - image is displayed as usual
       
   295             #center     - image is shown centered
       
   296             #fitBig     - big images are shrunk to make it fit the view
       
   297             #fitSmall   - small images are magnified to make it fit the view,
       
   298             #fit        - all images are magnified to fit the view
       
   299     "
       
   300 
       
   301     ^ adjust ? #topLeft
       
   302 !
       
   303 
   291 adjust:layoutSymbol
   304 adjust:layoutSymbol
   292     "set the adjust (how the image is displayed);
   305     "set the adjust (how the image is displayed);
   293      currently, only support #topLeft, #center, #fitBig, #fitSmall and #fit:
   306      currently, only support #topLeft, #center, #fitBig, #fitSmall and #fit:
   294             #topLeft    - image is displayed as usual
   307             #topLeft    - image is displayed as usual
   295             #center     - image is shown centered
   308             #center     - image is shown centered
   339 !
   352 !
   340 
   353 
   341 magnification
   354 magnification
   342     magnifiedImage isNil ifTrue:[^ 1@1].
   355     magnifiedImage isNil ifTrue:[^ 1@1].
   343     ^ magnifiedImage extent / image extent
   356     ^ magnifiedImage extent / image extent
       
   357 !
       
   358 
       
   359 magnificationFactor
       
   360     ^ magnificationFactor ? 1
       
   361 !
       
   362 
       
   363 magnificationFactor:aNumber
       
   364     magnificationFactor := aNumber.
       
   365 "/    magnificationFactor fractionPart < 0.1 ifTrue:[
       
   366 "/        "magnifying by integer factor is faster"
       
   367 "/        magnificationFactor := magnificationFactor truncated.
       
   368 "/    ].
       
   369     magnifiedImage := nil.
       
   370     magnificationFactor = 1 ifTrue:[
       
   371         self contentsChanged.
       
   372     ].    
       
   373     self invalidate.
   344 !
   374 !
   345 
   375 
   346 model:aValueHolder
   376 model:aValueHolder
   347     super model:aValueHolder.
   377     super model:aValueHolder.
   348     self updateFromModel.
   378     self updateFromModel.
   493             magnifiedImage := image magnifiedBy:magnificationFactor.
   523             magnifiedImage := image magnifiedBy:magnificationFactor.
   494         ] ifFalse:[
   524         ] ifFalse:[
   495             magnifiedImage := image
   525             magnifiedImage := image
   496         ].
   526         ].
   497     ].
   527     ].
       
   528     self contentsChanged.
   498 
   529 
   499     "Modified: / 06-05-2012 / 12:17:23 / cg"
   530     "Modified: / 06-05-2012 / 12:17:23 / cg"
   500 !
   531 !
   501 
   532 
   502 redrawX:x y:y width:w height:h
   533 redrawX:x y:y width:w height:h
   622     amount > 0 ifTrue:[
   653     amount > 0 ifTrue:[
   623         mul := 1.2.
   654         mul := 1.2.
   624     ] ifFalse:[
   655     ] ifFalse:[
   625         mul := 0.8.
   656         mul := 0.8.
   626     ].
   657     ].
   627 
   658     self magnificationFactor:((magnificationFactor ? 1) * mul).
   628     magnificationFactor := ((magnificationFactor ? 1) * mul).
       
   629     magnificationFactor fractionPart < 0.1 ifTrue:[
       
   630         "magnifying by integer factor is faster"
       
   631         magnificationFactor := magnificationFactor truncated.
       
   632     ].
       
   633     magnifiedImage := nil.
       
   634     self invalidate.
       
   635 
   659 
   636     "Created: / 06-05-2012 / 12:18:06 / cg"
   660     "Created: / 06-05-2012 / 12:18:06 / cg"
   637 !
   661 !
   638 
   662 
   639 sizeChanged:how
   663 sizeChanged:how
   640     (#(fit fitBig fitSmall) includes:adjust) ifTrue:[
   664     (#(fit fitBig fitSmall) includes:adjust) ifTrue:[
   641         magnifiedImage notNil ifTrue:[
   665         magnifiedImage notNil ifTrue:[
   642             DoNotMagnifyQuery query ifFalse:[
   666             DoNotMagnifyQuery query ifFalse:[
   643                 magnifiedImage := nil.
   667                 self pushEvent:#updateImageAfterSizeChange.
   644                 self generateMagnifiedImage.
       
   645                 self clear.
       
   646                 self invalidate.
       
   647             ]
   668             ]
   648         ].
   669         ].
   649     ] ifFalse:[
   670     ] ifFalse:[
   650         adjust == #center ifTrue:[
   671         adjust == #center ifTrue:[
   651             self clear.
   672             self clear.
   652             self invalidate.
   673             self invalidate.
   653         ].
   674         ].
   654     ].
   675     ].
   655     super sizeChanged:how
   676     super sizeChanged:how
       
   677 !
       
   678 
       
   679 updateImageAfterSizeChange
       
   680     magnifiedImage := nil.
       
   681     self generateMagnifiedImage.
       
   682     self clear.
       
   683     self invalidate.
   656 ! !
   684 ! !
   657 
   685 
   658 !ImageView methodsFor:'initialization & release'!
   686 !ImageView methodsFor:'initialization & release'!
   659 
   687 
   660 destroy
   688 destroy
   670 ! !
   698 ! !
   671 
   699 
   672 !ImageView methodsFor:'queries'!
   700 !ImageView methodsFor:'queries'!
   673 
   701 
   674 heightOfContents
   702 heightOfContents
   675     "return the images height - scrollbar needs this info"
   703     "return the image's height - scrollbar needs this info"
   676 
   704 
   677     image isNil ifTrue:[^ 0].
   705     image isNil ifTrue:[^ 0].
   678     ^ (magnifiedImage ? image) height
   706     ^ (magnifiedImage ? image) height
   679 !
   707 !
   680 
   708 
   681 widthOfContents
   709 widthOfContents
   682     "return the images width - scrollbar needs this info"
   710     "return the image's width - scrollbar needs this info"
   683 
   711 
   684     image isNil ifTrue:[^ 0].
   712     image isNil ifTrue:[^ 0].
   685     ^ (magnifiedImage ? image) width
   713     ^ (magnifiedImage ? image) width
   686 ! !
   714 ! !
   687 
   715