ImageView.st
changeset 5387 278d666f9267
parent 5268 b490144a4971
child 5398 3c4304d0d819
--- a/ImageView.st	Mon Dec 12 18:16:05 2016 +0100
+++ b/ImageView.st	Mon Dec 12 22:42:36 2016 +0100
@@ -288,6 +288,19 @@
 
 !ImageView methodsFor:'accessing'!
 
+adjust
+    "get the adjust (how the image is displayed);
+     currently, only support #topLeft, #center, #fitBig, #fitSmall and #fit:
+            #topLeft    - image is displayed as usual
+            #center     - image is shown centered
+            #fitBig     - big images are shrunk to make it fit the view
+            #fitSmall   - small images are magnified to make it fit the view,
+            #fit        - all images are magnified to fit the view
+    "
+
+    ^ adjust ? #topLeft
+!
+
 adjust:layoutSymbol
     "set the adjust (how the image is displayed);
      currently, only support #topLeft, #center, #fitBig, #fitSmall and #fit:
@@ -343,6 +356,23 @@
     ^ magnifiedImage extent / image extent
 !
 
+magnificationFactor
+    ^ magnificationFactor ? 1
+!
+
+magnificationFactor:aNumber
+    magnificationFactor := aNumber.
+"/    magnificationFactor fractionPart < 0.1 ifTrue:[
+"/        "magnifying by integer factor is faster"
+"/        magnificationFactor := magnificationFactor truncated.
+"/    ].
+    magnifiedImage := nil.
+    magnificationFactor = 1 ifTrue:[
+        self contentsChanged.
+    ].    
+    self invalidate.
+!
+
 model:aValueHolder
     super model:aValueHolder.
     self updateFromModel.
@@ -495,6 +525,7 @@
             magnifiedImage := image
         ].
     ].
+    self contentsChanged.
 
     "Modified: / 06-05-2012 / 12:17:23 / cg"
 !
@@ -624,14 +655,7 @@
     ] ifFalse:[
         mul := 0.8.
     ].
-
-    magnificationFactor := ((magnificationFactor ? 1) * mul).
-    magnificationFactor fractionPart < 0.1 ifTrue:[
-        "magnifying by integer factor is faster"
-        magnificationFactor := magnificationFactor truncated.
-    ].
-    magnifiedImage := nil.
-    self invalidate.
+    self magnificationFactor:((magnificationFactor ? 1) * mul).
 
     "Created: / 06-05-2012 / 12:18:06 / cg"
 !
@@ -640,10 +664,7 @@
     (#(fit fitBig fitSmall) includes:adjust) ifTrue:[
         magnifiedImage notNil ifTrue:[
             DoNotMagnifyQuery query ifFalse:[
-                magnifiedImage := nil.
-                self generateMagnifiedImage.
-                self clear.
-                self invalidate.
+                self pushEvent:#updateImageAfterSizeChange.
             ]
         ].
     ] ifFalse:[
@@ -653,6 +674,13 @@
         ].
     ].
     super sizeChanged:how
+!
+
+updateImageAfterSizeChange
+    magnifiedImage := nil.
+    self generateMagnifiedImage.
+    self clear.
+    self invalidate.
 ! !
 
 !ImageView methodsFor:'initialization & release'!
@@ -672,14 +700,14 @@
 !ImageView methodsFor:'queries'!
 
 heightOfContents
-    "return the images height - scrollbar needs this info"
+    "return the image's height - scrollbar needs this info"
 
     image isNil ifTrue:[^ 0].
     ^ (magnifiedImage ? image) height
 !
 
 widthOfContents
-    "return the images width - scrollbar needs this info"
+    "return the image's width - scrollbar needs this info"
 
     image isNil ifTrue:[^ 0].
     ^ (magnifiedImage ? image) width