ImageEditView.st
changeset 662 61b7601829ea
parent 636 d53428252193
child 674 f24ca336b717
--- a/ImageEditView.st	Fri Jan 16 15:03:28 1998 +0100
+++ b/ImageEditView.st	Sat Jan 17 00:23:50 1998 +0100
@@ -13,7 +13,7 @@
 ImageView subclass:#ImageEditView
 	instanceVariableNames:'magnification gridMagnification selectColors imageReaderClass
 		resourceClass resourceSelector editMode mouseKeyColorMode
-		undoImage modified coordInfoBlock'
+		undoImage modified coordInfoBlock masterApplication'
 	classVariableNames:'Clipboard'
 	poolDictionaries:''
 	category:'Views-Misc'
@@ -83,6 +83,16 @@
     ].
 !
 
+masterApplication
+
+    ^masterApplication
+!
+
+masterApplication: anApplicationModel
+
+    masterApplication := anApplicationModel
+!
+
 resourceClass
 
     ^resourceClass
@@ -91,7 +101,6 @@
 resourceClass: aClassOrSymbol
 
     resourceClass := aClassOrSymbol isClass ifTrue: [aClassOrSymbol name] ifFalse: [aClassOrSymbol asSymbol].
-
 !
 
 resourceMessage
@@ -142,22 +151,28 @@
 
 !ImageEditView methodsFor:'drawing'!
 
+fillFramedRectangle: aRectangle
+
+    self fillRectangle: aRectangle.
+    self drawFramesIn: aRectangle
+!
+
 redrawImageX:x y:y width:w height:h
 
-    |ih iw dotW dotH minX maxX minY maxY color last lastY runW x0 xI yI maskColor|
+    |ih iw magX magY minX maxX minY maxY color lastColor lastY runW x0 xI yI maskColor sizeOfMaskPoint|
 
     ih := image height.
     iw := image width.
-    dotW := magnification x.
-    dotH := magnification y.
+    magX := magnification x.
+    magY := magnification y.
 
-    minX := x // dotW.
+    minX := (x // magX - 1) max: 0.
     minX >= iw ifTrue:[minX := iw - 1].
-    minY := y // dotH.
+    minY := (y // magY - 1) max: 0.
     minY >= ih ifTrue:[minY := ih - 1].
-    maxX := (x + w) // dotW + 1.
+    maxX := (x + w) // magX + 1.
     maxX > iw ifTrue:[maxX := iw].
-    maxY := (y + h) // dotH + 1.
+    maxY := (y + h) // magY + 1.
     maxY > ih ifTrue:[maxY := ih].
 
     lastY := -1.
@@ -165,7 +180,8 @@
     x0 := minX.
     runW := 0.
     maskColor := false.
-    image colorsFromX:minX y:minY toX:maxX-1 y:maxY-1 do:
+    sizeOfMaskPoint := magnification//3.
+    image colorsFromX: minX y: minY toX: maxX-1 y: maxY-1 do:
     [:xx :yy :color|
         yy ~~ lastY
         ifTrue:
@@ -174,12 +190,11 @@
             ifTrue:
             [
                 |origin|
-                origin := (x0 * dotW + margin)@(lastY * dotH + margin).
-                self fillRectangle: (origin extent: (runW@dotH)).                    
-                0 to: runW by: dotW do: [:xxx| self drawFrameAt: ((origin x + xxx) @(origin y))].
+                origin := (x0 * magX + margin)@(lastY * magY + margin).
+                self fillFramedRectangle: (origin extent: (runW@magY)).                    
                 maskColor ifTrue:
                 [
-                    self drawMaskPointAt: origin
+                    self xoring: [self fillRectangle: (origin + sizeOfMaskPoint extent: sizeOfMaskPoint)]
                 ].
                 runW := 0.
             ]. 
@@ -187,48 +202,46 @@
             lastY := yy.
         ]. 
 
-        color ~~ last
+        color ~~ lastColor
         ifTrue:
         [
             runW ~~ 0
             ifTrue:
             [
                 |origin|
-                origin := (x0 * dotW + margin)@(yy * dotH + margin).
-                self fillRectangle: (origin extent: (runW@dotH)).
-                0 to: runW by: dotW do: [:xxx| self drawFrameAt: ((origin x + xxx)@(origin y))].
+                origin := (x0 * magX + margin)@(yy * magY + margin).
+                self fillFramedRectangle: (origin extent: (runW@magY)).
                 maskColor ifTrue:
                 [
-                    self drawMaskPointAt: origin
+                    self xoring: [self fillRectangle: (origin + sizeOfMaskPoint extent: sizeOfMaskPoint)]
                 ].
                 runW := 0.
             ].
 
-            self paint: (last := color).
+            self paint: (lastColor := color).
             image mask notNil ifTrue:
             [  
                 maskColor := false.
                 (image mask colorAt: xx@yy) = Color black ifTrue:
                 [
-                    self paint: (last := self viewBackground).
+                    self paint: (lastColor := self viewBackground).
                     maskColor := true.
                 ].
-                last := nil.
+                lastColor := nil.
             ].
             runW := 0.
             x0 := xx.
         ].  
-        runW := runW + dotW
+        runW := runW + magX
     ].
     runW ~~ 0 ifTrue:
     [
         |origin|
-        origin := (x0 * dotW + margin)@(lastY * dotH + margin).
-        self fillRectangle: (origin extent: runW@dotH).
-        0 to: runW by: dotW do: [:xxx| self drawFrameAt: ((origin x + xxx) @origin y)].
+        origin := (x0 * magX + margin)@(lastY * magY + margin).
+        self fillFramedRectangle: (origin extent: runW@magY).
         maskColor ifTrue:
         [
-            self drawMaskPointAt: origin.
+            self xoring: [self fillRectangle: (origin + sizeOfMaskPoint extent: sizeOfMaskPoint)]
         ].
         runW := 0.
     ].
@@ -238,9 +251,11 @@
 
     |ih iw xI yI|
 
+    magnification = (1@1) ifTrue: [^super redrawX:x y:y width:w height:h].
+
     image isNil ifTrue:[^self].
 
-    self clippingRectangle: (x@y extent: w@h). 
+    self clippingRectangle: (x@y extent: w@h).
 
     self redrawImageX:x y:y width:w height:h.
 
@@ -324,11 +339,17 @@
 
 boxAt: aPoint
 
-    |choosedBox|
+    |choosedBox imageBox|
     choosedBox := self drawRectangleStartingAt: aPoint emphasis: #box.
-    image rectangle: (choosedBox origin//magnification extent: (choosedBox extent//magnification)) withColor: self selectedColor.
+    image rectangle: (imageBox := choosedBox origin//magnification extent: (choosedBox extent//magnification)) withColor: self selectedColor.
     image restored.
-    self redraw: (choosedBox expandedBy: 1).    
+    self redraw: (choosedBox expandedBy: 1).
+    masterApplication notNil
+    ifTrue:
+    [
+        masterApplication imagePreView redraw: imageBox.
+
+    ].
     modified := true.
 !
 
@@ -337,7 +358,7 @@
     |choosedBox|
     choosedBox := self drawRectangleStartingAt: aPoint emphasis: #inverseFilledBox.
     Clipboard := image subImageIn: (choosedBox origin//magnification extent: (choosedBox extent//magnification)).
-    self redraw: choosedBox    
+    self redraw: (choosedBox expandedBy: 1)    
 
 !
 
@@ -351,23 +372,34 @@
         filledPoints size < 300
         ifTrue:
         [
-            filledPoints do: [:p| Delay waitForMilliseconds:0.7. self redraw: ((p * magnification extent: magnification) expandedBy: 1)]
+            filledPoints do: [:p| self redraw: ((p * magnification extent: magnification) expandedBy: 1)]
         ]
         ifFalse:
         [
             self invalidate
         ].
+        masterApplication notNil
+        ifTrue:
+        [
+            masterApplication imagePreView invalidate
+        ].
         modified := true
     ]
 !
 
 filledBoxAt: aPoint
 
-    |choosedBox|
+    |choosedBox imageBox|
     choosedBox := self drawRectangleStartingAt: aPoint emphasis: #filledBox.
-    image fillRectangle: (choosedBox origin//magnification extent: (choosedBox extent//magnification)) withColor: self selectedColor.
+    image fillRectangle: (imageBox := choosedBox origin//magnification extent: (choosedBox extent//magnification)) withColor: self selectedColor.
     image restored.
-    self redraw: (choosedBox expandedBy: 1).    
+    self redraw: (choosedBox expandedBy: 1).
+    masterApplication notNil
+    ifTrue:
+    [
+        masterApplication imagePreView redraw: imageBox
+
+    ].
     modified := true.
 !
 
@@ -417,11 +449,16 @@
     ] 
     do:
     [   
-        |imagePoint|
+        |imagePoint imageBox|
         imagePoint := aPoint//magnification.
         image copyFrom: Clipboard x:0 y:0 toX: imagePoint x y: imagePoint y width: Clipboard width height: Clipboard height.
         image restored.
-        self redraw: ((imagePoint * magnification extent: (Clipboard extent * magnification)) expandedBy: 1@1).
+        self redraw: (imageBox := (imagePoint * magnification extent: (Clipboard extent * magnification)) expandedBy: 1@1).
+        masterApplication notNil
+        ifTrue:
+        [
+            masterApplication imagePreView redraw: imageBox
+        ].
         self drawLabel: imagePoint.
         modified := true.
     ]
@@ -429,11 +466,16 @@
 
 pointAt: aPoint
 
-    |imagePoint|
+    |imagePoint imageBox|
     imagePoint := aPoint//magnification.
     image atImageAndMask: imagePoint put: self selectedColor.
     image restored.
-    self redraw: ((imagePoint * magnification extent: magnification) expandedBy: 1).
+    self redraw: (imageBox := (imagePoint * magnification extent: magnification) expandedBy: 1).
+    masterApplication notNil
+    ifTrue:
+    [
+        masterApplication imagePreView redraw: (imagePoint extent: (1@1))
+    ].
     self drawLabel: imagePoint.
     modified := true.
 
@@ -527,24 +569,29 @@
     self lineWidth:1.
 !
 
-drawFrameAt: aPoint
+drawFramesIn: aRectangle
 
     magnification > gridMagnification
     ifTrue:
     [   
-        |lineStartingPoint lineEndingPoint oldColor|
-        lineStartingPoint := aPoint//magnification*magnification.
-        lineEndingPoint   := aPoint//magnification*magnification + magnification.
+        |origin lineStartingPoint lineEndingPoint oldColor|
+        origin := aRectangle origin - 1.
+        lineStartingPoint := origin + (0@magnification y).
+        lineEndingPoint   := lineStartingPoint + (aRectangle width@0).
         oldColor := self paint.
         self xoring:
         [
-            self displayLineFrom: lineEndingPoint 
-                              to: (lineEndingPoint x)@(lineStartingPoint y).
-            self displayLineFrom: lineEndingPoint 
-                              to: (lineStartingPoint x)@(lineEndingPoint y).
+            self displayLineFrom: lineStartingPoint to: lineEndingPoint.
+            lineStartingPoint x to: lineStartingPoint x + aRectangle width - magnification x by: magnification x do:
+            [:x|   
+                self displayLineFrom: x@(origin y) to: x@(origin y + magnification y)
+            ].
         ].
         self paint: oldColor.
     ]
+
+
+
 !
 
 drawLabel: aLabel
@@ -556,14 +603,6 @@
     ]
 !
 
-drawMaskPointAt: aPoint
-
-    |sizeOfMaskPoint|
-    sizeOfMaskPoint := magnification//3.
-    self xoring: [self fillRectangle: (aPoint + sizeOfMaskPoint extent: sizeOfMaskPoint)].
-   
-!
-
 drawRectangleStartingAt: aPoint emphasis: emphasis
 
     |currentPoint currentExtent firstPoint lastCurrentPoint gridCorrection p|
@@ -579,25 +618,44 @@
 
         currentPoint ~= lastCurrentPoint ifTrue:
         [          
-            self redraw: ((firstPoint min: lastCurrentPoint) - 1 extent: (firstPoint - lastCurrentPoint) abs + 2).
             emphasis = #inverseFilledBox
             ifTrue:
             [
+                self redraw: ((firstPoint min: lastCurrentPoint) - 1 extent: (firstPoint - lastCurrentPoint) abs + 2).
                 self xoring: [self fillRectangle: ((firstPoint min: currentPoint) + 1 extent: currentExtent - gridCorrection)]
             ].
             emphasis = #box
             ifTrue:
             [
+                |origin extent lineWidthY lineWidthX|
+                origin := (firstPoint min: lastCurrentPoint) - 1.
+                extent := (firstPoint - lastCurrentPoint) abs + 2.
+                lineWidthY := extent y min: (magnification y + 2).
+                lineWidthX := extent x min: (magnification x + 2).
+                self redraw: (origin extent: (extent x@lineWidthY)).
+                self redraw: ((origin x@(origin y + extent y - lineWidthY)) extent: (extent x@lineWidthY)).
+                self redraw: ((origin x@(origin y + lineWidthY)) extent: (lineWidthX@(0 max: (extent y - (lineWidthY * 2))))).
+                self redraw: (((origin x + extent x - lineWidthX)@(origin y + lineWidthY)) extent: (lineWidthX@(extent y - (lineWidthY * 2)))).
                 self selectedColor ~= Color noColor
                     ifTrue: [self paint: self selectedColor]
                     ifFalse: [self paint: self viewBackground].
-                self lineWidth: magnification x.
-                self displayRectangle: ((firstPoint min: currentPoint) + (magnification x//2) + 1 extent: (currentExtent - (magnification x)) - gridCorrection + 1).
-                self lineWidth: 1.
+                origin := (firstPoint min: currentPoint) + 1.
+                extent := currentExtent - gridCorrection.
+                lineWidthY := extent y min: magnification y.
+                lineWidthX := extent x min: magnification x.
+                (lineWidthY > 0) & (lineWidthX > 0)
+                ifTrue:
+                [
+                    self fillRectangle: (origin extent: (extent x@lineWidthY)).
+                    self fillRectangle: ((origin x@(origin y + extent y - lineWidthY)) extent: (extent x@lineWidthY)).
+                    self fillRectangle: ((origin x@(origin y + lineWidthY)) extent: (lineWidthX@(0 max: (extent y - (lineWidthY * 2))))).
+                    self fillRectangle: (((origin x + extent x - lineWidthX)@(origin y + lineWidthY)) extent: (lineWidthX@(extent y - (lineWidthY * 2)))).
+                ]
             ].
             emphasis = #filledBox
             ifTrue:
             [
+                self redraw: ((firstPoint min: lastCurrentPoint) - 1 extent: (firstPoint - lastCurrentPoint) abs + 2).
                 self selectedColor ~= Color noColor
                     ifTrue: [self paint: self selectedColor]
                     ifFalse: [self paint: self viewBackground].
@@ -608,7 +666,8 @@
         lastCurrentPoint := currentPoint.
     ].
     Cursor normal show.
-    ^(firstPoint min: currentPoint) extent: (firstPoint - currentPoint) abs
+
+    ^((1@1) max: (firstPoint min: currentPoint)) extent: (firstPoint - currentPoint) abs
 ! !
 
 !ImageEditView methodsFor:'image setting'!
@@ -617,7 +676,8 @@
 
     (anImage isImage and: [image isNil or: [self checkModified]])
     ifTrue:
-    [
+    [    
+        masterApplication notNil ifTrue: [masterApplication imagePreView image: anImage].
         super image: anImage.
         ^self
     ].
@@ -662,7 +722,7 @@
 
 loadfromClass: aClassOrSymbol andSelector: aStringOrSymbol
 
-    |aClass|       
+    |aClass|     
     imageReaderClass := nil.
     self resourceClass: aClassOrSymbol.
     self resourceSelector: aStringOrSymbol.
@@ -672,7 +732,6 @@
     [ 
         ^self image: (aClass perform: resourceSelector) copy
     ].
-    self warn: 'No class or selector for evaluation detected!!'.
     ^nil
 ! !
 
@@ -696,7 +755,7 @@
 
     self loadFromMessage: 
         (ResourceSelectionBrowser
-            request: 'Load From Image Resource Method'
+            request: 'Load Image From Class'
             onSuperclass: aSuperclassOrSymbol
             andClass: self resourceClass
             andSelector: self resourceSelector
@@ -812,6 +871,7 @@
             image mask fileName isNil ifTrue: [^self error: 'No file name for image mask detected!!'].
             fileName := image mask fileName asFilename
         ].
+        fileName size = 0 ifTrue: [^self error: 'No file name detected!!'].
         (fileName suffix = 'tiff') | (fileName suffix = 'tif') ifTrue: [imageReaderClass := TIFFReader].
         fileName suffix = 'xpm' ifTrue: [imageReaderClass := XPMReader].
         fileName suffix = 'xbm' ifTrue: [imageReaderClass := XBMReader].
@@ -913,5 +973,5 @@
 !ImageEditView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.53 1997-12-21 21:59:57 tz Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.54 1998-01-16 23:23:50 tz Exp $'
 ! !