#UI_ENHANCEMENT by cg
authorClaus Gittinger <cg@exept.de>
Thu, 28 Sep 2017 18:27:22 +0200
changeset 5610 72882e1d2bee
parent 5609 8a30b1f720d7
child 5611 8c53817d5e0a
#UI_ENHANCEMENT by cg class: ImageView class definition added: #forceSmoothing #forceSmoothing: #forceSmoothingHolder changed: #adjust: #destroy #generateMagnifiedImage #magnificationFactor: #redrawX:y:width:height: #setImage:scroll:invalidate: #updateImageAfterSizeChange class: ImageView class comment/format in: #middleButtonMenu
ImageView.st
--- a/ImageView.st	Fri Sep 22 18:58:43 2017 +0200
+++ b/ImageView.st	Thu Sep 28 18:27:22 2017 +0200
@@ -14,9 +14,10 @@
 "{ NameSpace: Smalltalk }"
 
 View subclass:#ImageView
-	instanceVariableNames:'image magnifiedImage adjust explicitMagnificationFactor
-		magnificationFactor tileMode tileOffset lastMousePoint
-		adjustHolder imageEditAction'
+	instanceVariableNames:'image magnifiedImage smoothMagnifiedImage adjust
+		explicitMagnificationFactor magnificationFactor tileMode
+		tileOffset lastMousePoint adjustHolder imageEditAction
+		forceSmoothingHolder smoothingProcess'
 	classVariableNames:'DoNotMagnifyQuery'
 	poolDictionaries:''
 	category:'Views-Misc'
@@ -151,6 +152,13 @@
                   itemValue: magnifyBy:
                   argument: 4
                 )
+               (MenuItem
+                  label: '-'
+                )
+               (MenuItem
+                  label: 'Smoothing'
+                  indication: forceSmoothingHolder
+                )
                )
               nil
               nil
@@ -158,7 +166,7 @@
           )
          (MenuItem
             label: '-'
-            isVisible: selfIsNotImageEitor
+            isVisible: selfIsNotImageEditor
           )
          (MenuItem
             label: 'Edit'
@@ -169,8 +177,6 @@
         nil
         nil
       )
-
-    "Modified: / 13-09-2017 / 09:45:43 / cg"
 ! !
 
 !ImageView class methodsFor:'queries-plugin'!
@@ -381,7 +387,7 @@
             adjustHolder value:layoutUsed withoutNotifying:self
         ].    
 
-        magnifiedImage := nil.
+        magnifiedImage := smoothMagnifiedImage := nil.
         shown ifTrue:[
             image notNil ifTrue:[
                 "/ self magnificationFactor ~= 1 ifTrue:[
@@ -395,7 +401,7 @@
         ].
     ].
 
-    "Modified: / 10-09-2017 / 18:19:44 / cg"
+    "Modified: / 28-09-2017 / 18:20:55 / cg"
 !
 
 adjustHolder
@@ -423,6 +429,27 @@
     "Modified (comment): / 10-09-2017 / 17:06:23 / cg"
 !
 
+forceSmoothing
+    ^ self forceSmoothingHolder value
+
+    "Created: / 28-09-2017 / 17:52:38 / cg"
+!
+
+forceSmoothing:aBoolean
+    self forceSmoothingHolder value:aBoolean
+
+    "Created: / 28-09-2017 / 17:52:30 / cg"
+!
+
+forceSmoothingHolder
+    forceSmoothingHolder isNil ifTrue:[
+        forceSmoothingHolder := false asValue
+    ].
+    ^ forceSmoothingHolder
+
+    "Created: / 28-09-2017 / 17:55:51 / cg"
+!
+
 image
     "return the image"
 
@@ -476,7 +503,7 @@
         "/        "magnifying by integer factor is faster"
         "/        magnificationFactor := magnificationFactor truncated.
         "/    ].
-        magnifiedImage := nil.
+        magnifiedImage := smoothMagnifiedImage := nil.
         magnificationFactor = 1 ifTrue:[
             self contentsChanged.
         ].    
@@ -484,6 +511,7 @@
     ].
 
     "Modified: / 06-09-2017 / 12:51:28 / Maren"
+    "Modified: / 28-09-2017 / 18:21:00 / cg"
 !
 
 model:aValueHolder
@@ -517,7 +545,7 @@
     oldSize := image isNil ifTrue:[0@0] ifFalse:[image extent].
 
     image := anImage.
-    magnifiedImage := nil.
+    magnifiedImage := smoothMagnifiedImage := nil.
     self generateMagnifiedImage.
 
     newSize := image isNil ifTrue:[0@0] ifFalse:[(magnifiedImage ? image) extent].
@@ -545,7 +573,7 @@
     ].
     self changed:#image.
 
-    "Modified: / 10.2.2000 / 23:25:51 / cg"
+    "Modified: / 28-09-2017 / 18:21:07 / cg"
 !
 
 sizeToFit:aBoolean
@@ -610,64 +638,97 @@
 generateMagnifiedImage
     |adj smooth doFit innerWidth innerHeight imgWidth imgHeight|
 
-    magnifiedImage notNil ifTrue:[
-        ^ self
-    ].
     image isNil ifTrue:[
         ^ self
     ].
-    doFit := false.
 
-    innerWidth := self innerWidth.
-    innerHeight := self innerHeight.
-
-    imgWidth := image width.
-    imgHeight := image height.
-
+    smoothMagnifiedImage notNil ifTrue:[
+        ^ self
+    ].
+    
     adj := adjust.
     smooth := false.
     (adjust notNil and:[adjust startsWith:#smooth]) ifTrue:[
         adj := (adjust copyFrom:'smooth' size+1) asLowercaseFirst asSymbol.
         smooth := true.
     ].
-    
-    ((adj == #fit) or:[adj == #fitBig or:[adj == #fitSmall]]) ifTrue:[
-        magnificationFactor := explicitMagnificationFactor.
-    ].
+    self forceSmoothing ifTrue:[smooth := true].
+
+    magnifiedImage isNil ifTrue:[
+        doFit := false.
+
+        innerWidth := self innerWidth.
+        innerHeight := self innerHeight.
 
-    tileMode ~~ true ifTrue:[
-        ((imgWidth > innerWidth)
-        or:[imgHeight > innerHeight]) ifTrue:[
-            ((adj == #fit) or:[adj == #fitBig]) ifTrue:[
-                doFit := true
-            ].
-        ] ifFalse:[
-            ((imgWidth < innerWidth)
-            or:[imgHeight < innerHeight]) ifTrue:[
-                ((adj == #fit) or:[adj == #fitSmall]) ifTrue:[
+        imgWidth := image width.
+        imgHeight := image height.
+
+        ((adj == #fit) or:[adj == #fitBig or:[adj == #fitSmall]]) ifTrue:[
+            magnificationFactor := explicitMagnificationFactor.
+        ].
+
+        tileMode ~~ true ifTrue:[
+            ((imgWidth > innerWidth)
+            or:[imgHeight > innerHeight]) ifTrue:[
+                ((adj == #fit) or:[adj == #fitBig]) ifTrue:[
                     doFit := true
                 ].
-            ]
+            ] ifFalse:[
+                ((imgWidth < innerWidth)
+                or:[imgHeight < innerHeight]) ifTrue:[
+                    ((adj == #fit) or:[adj == #fitSmall]) ifTrue:[
+                        doFit := true
+                    ].
+                ]
+            ].
         ].
+
+        doFit ifTrue:[
+            magnifiedImage := image magnifiedPreservingRatioTo:(innerWidth @ innerHeight) smooth:false "smooth".
+            magnificationFactor := magnifiedImage width / imgWidth.
+        ] ifFalse:[
+            (magnificationFactor notNil and:[magnificationFactor ~= 1]) ifTrue:[
+                magnifiedImage := image magnifiedBy:magnificationFactor smooth:false "smooth".
+            ] ifFalse:[
+                magnifiedImage := image.
+            ].
+        ].
+    
+        (magnifiedImage width == 0 or:[magnifiedImage height == 0]) ifTrue:[
+            magnifiedImage := nil.
+        ].    
+
+        smooth ifTrue:[
+            smoothMagnifiedImage := nil.
+        ] ifFalse:[
+            smoothMagnifiedImage := magnifiedImage.
+        ].
+        
+        self contentsChanged.
     ].
     
-    doFit ifTrue:[
-        magnifiedImage := image magnifiedPreservingRatioTo:(innerWidth @ innerHeight) smooth:smooth.
-        magnificationFactor := magnifiedImage width / imgWidth.
-    ] ifFalse:[
-        (magnificationFactor notNil and:[magnificationFactor ~= 1]) ifTrue:[
-            magnifiedImage := image magnifiedBy:magnificationFactor smooth:smooth.
-        ] ifFalse:[
-            magnifiedImage := image
-        ].
+    smooth ifTrue:[
+        magnifiedImage extent = image extent ifTrue:[
+            smoothMagnifiedImage := magnifiedImage
+        ] ifFalse:[    
+            smoothMagnifiedImage := nil.
+            
+            self synchronized:[
+                smoothingProcess notNil ifTrue:[
+                    smoothingProcess terminate.
+                    smoothMagnifiedImage := nil.
+                ].
+                smoothingProcess := 
+                    [
+                        smoothMagnifiedImage := image magnifiedTo:(magnifiedImage extent) smooth:true.
+                        self invalidate.
+                    ] fork.
+            ].        
+        ].    
     ].
-    (magnifiedImage width == 0 or:[magnifiedImage height == 0]) ifTrue:[
-        magnifiedImage := nil.
-    ].
-    self contentsChanged.
 
     "Modified: / 06-09-2017 / 12:52:19 / Maren"
-    "Modified: / 10-09-2017 / 18:21:58 / cg"
+    "Modified: / 28-09-2017 / 18:24:31 / cg"
 !
 
 redrawX:x y:y width:w height:h
@@ -676,7 +737,7 @@
     image notNil ifTrue:[
         self generateMagnifiedImage.
 
-        shownImage := magnifiedImage ? image.
+        shownImage := smoothMagnifiedImage ? magnifiedImage ? image.
         imgWidth := shownImage width.
         imgHeight := shownImage height.
 
@@ -764,8 +825,7 @@
     ].
 
     "Created: / 11-07-1996 / 21:02:12 / cg"
-    "Modified: / 11-04-2017 / 21:05:13 / cg"
-    "Modified (format): / 05-09-2017 / 10:53:40 / cg"
+    "Modified: / 28-09-2017 / 18:19:01 / cg"
 ! !
 
 !ImageView methodsFor:'event handling'!
@@ -843,8 +903,10 @@
     |oldMagnifiedImage|
     
     oldMagnifiedImage := magnifiedImage.
-    magnifiedImage := nil.
+    smoothMagnifiedImage := magnifiedImage := nil.
+
     self generateMagnifiedImage.
+
     (oldMagnifiedImage isNil
       or:[ magnifiedImage isNil
       or:[ oldMagnifiedImage extent ~= magnifiedImage extent ]]
@@ -852,14 +914,18 @@
         "/ self clear.
         self invalidate.
     ].
+
+    "Modified (format): / 28-09-2017 / 18:20:32 / cg"
 ! !
 
 !ImageView methodsFor:'initialization & release'!
 
 destroy
-    magnifiedImage := nil.
+    magnifiedImage := smoothMagnifiedImage := nil.
     "/ image := nil.
     super destroy.
+
+    "Modified: / 28-09-2017 / 18:20:44 / cg"
 !
 
 initialize