ImageEditView.st
changeset 1084 87c661e6c333
parent 1060 690045fd9032
child 1103 62fb33e2e17b
--- a/ImageEditView.st	Thu Aug 20 20:19:01 1998 +0200
+++ b/ImageEditView.st	Fri Aug 21 20:36:25 1998 +0200
@@ -394,7 +394,6 @@
 !ImageEditView methodsFor:'event handling'!
 
 buttonMotion:state x:x y:y
-
     self drawCursorAt: x@y.
     state ~~ 0 ifTrue: [
         (self selectedColor notNil and: [(self imageContainsPoint: x@y) and: [editMode = 'point']])
@@ -407,7 +406,7 @@
         ]
     ]
 
-    "Modified: / 27.7.1998 / 17:45:20 / cg"
+    "Modified: / 21.8.1998 / 20:16:01 / cg"
 !
 
 buttonPress:button x:x y:y
@@ -470,6 +469,114 @@
 
 !ImageEditView methodsFor:'image - dragging & info'!
 
+dragRectangleStartingAt: aPoint emphasis: emphasis
+    "drag a rectangle (filled or unfilled)"
+
+    |currentPoint currentExtent firstPoint lastCurrentPoint gridCorrection 
+     mp lastMp p whichQuarter scrollX scrollY|
+
+    firstPoint := currentPoint := lastCurrentPoint := aPoint//magnification*magnification.
+    magnification >= GridMagnification ifFalse: [gridCorrection := 0] ifTrue: [gridCorrection := 1].
+
+    [device anyButtonPressed] whileTrue: [                                                  
+        mp := self sensor mousePoint.
+        mp = lastMp ifTrue:[
+            Delay waitForSeconds:0.05
+        ] ifFalse:[
+            lastMp := mp.
+            mp := device translatePoint:mp from:device rootView id to:self id.
+
+            scrollX := 0.
+            mp x > width ifTrue:[
+                scrollX := mp x - width.
+            ] ifFalse:[
+                mp x < 0 ifTrue:[
+                    scrollX := mp x.
+                ]
+            ].
+            scrollY := 0.
+            mp y > height ifTrue:[
+                scrollY := mp y - height.
+            ] ifFalse:[
+                mp y < 0 ifTrue:[
+                    scrollY := mp y.
+                ]
+            ].
+            (scrollX + scrollY) ~~ 0 ifTrue:[
+                self scrollTo:(self viewOrigin + (scrollX @ scrollY)).
+                lastMp := nil.
+            ].
+
+            currentPoint := (0@0) max: (image extent * magnification min: (p :=  self translation negated + mp)).
+            currentPoint := currentPoint//magnification*magnification.
+            currentExtent := (firstPoint - currentPoint) abs.
+            whichQuarter := (firstPoint x - currentPoint x) > 0 
+                 ifTrue:  [(firstPoint y - currentPoint y) > 0 ifTrue: ["4"1@1] ifFalse: ["3"1@0]]
+                 ifFalse: [(firstPoint y - currentPoint y) > 0 ifTrue: ["1"0@1] ifFalse: ["2"0@0]].
+
+            self drawCursorAt: p withLabel: 
+                ((firstPoint//magnification - whichQuarter + 1) printString, 
+                ' to: ', 
+                (currentPoint//magnification + whichQuarter) printString),
+                ' (extent: ',
+                (currentExtent//magnification) printString, ')'.
+
+            currentPoint ~= lastCurrentPoint ifTrue:
+            [   
+                emphasis = #inverseFilledBox
+                ifTrue:
+                [
+                    self redraw: ((firstPoint min: lastCurrentPoint) - 1 extent: (firstPoint - lastCurrentPoint) abs + 2).
+                    self xoring: [self fillRectangle: ((firstPoint min: currentPoint) + margin 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]. 
+                    origin := (firstPoint min: currentPoint) + margin.
+                    extent := currentExtent - gridCorrection.
+                    lineWidthY := extent y min: magnification y.
+                    lineWidthX := extent x min: magnification x.
+                    (lineWidthY > 0 and: [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].
+                    self fillRectangle: ((firstPoint min: currentPoint) + margin extent: currentExtent - gridCorrection).
+                ].
+            ]. 
+            lastCurrentPoint := currentPoint.
+        ].                  
+    ].                  
+
+    ^((0@0) max: (firstPoint min: currentPoint)) extent: (firstPoint - currentPoint) abs
+
+    "Created: / 21.8.1998 / 20:17:07 / cg"
+    "Modified: / 21.8.1998 / 20:34:42 / cg"
+!
+
 drawCursorAt: aPoint
     |clr|
 
@@ -591,11 +698,13 @@
 copyAt: aPoint
 
     |choosedBox|
-    choosedBox := self drawRectangleStartingAt: aPoint emphasis: #inverseFilledBox.
+
+    choosedBox := self dragRectangleStartingAt: aPoint emphasis: #inverseFilledBox.
     ClipboardMagnification := nil.
     Clipboard := image subImageIn: (choosedBox origin//magnification extent: (choosedBox extent//magnification)).
-    self redraw: (choosedBox expandedBy: 1)    
+    self redraw: (choosedBox expandedBy: 1)
 
+    "Modified: / 21.8.1998 / 20:16:41 / cg"
 !
 
 drawPasteRectangleAt: aPoint
@@ -631,80 +740,6 @@
     "Modified: / 29.7.1998 / 02:18:11 / cg"
 !
 
-drawRectangleStartingAt: aPoint emphasis: emphasis
-
-    |currentPoint currentExtent firstPoint lastCurrentPoint gridCorrection p whichQuarter|
-    firstPoint := currentPoint := lastCurrentPoint := aPoint//magnification*magnification.
-    magnification >= GridMagnification ifFalse: [gridCorrection := 0] ifTrue: [gridCorrection := 1].
-    [device anyButtonPressed]
-    whileTrue:
-    [                                                  
-        currentPoint := (0@0) max: (image extent * magnification min: (p :=  self translation negated + (device translatePoint: self sensor mousePoint from:device rootView id to:self id))).
-        currentPoint := currentPoint//magnification*magnification.
-        currentExtent := (firstPoint - currentPoint) abs.
-        whichQuarter := (firstPoint x - currentPoint x) > 0 
-             ifTrue:  [(firstPoint y - currentPoint y) > 0 ifTrue: ["4"1@1] ifFalse: ["3"1@0]]
-             ifFalse: [(firstPoint y - currentPoint y) > 0 ifTrue: ["1"0@1] ifFalse: ["2"0@0]].
-
-        self drawCursorAt: p withLabel: 
-            ((firstPoint//magnification - whichQuarter + 1) printString, 
-            ' to: ', 
-            (currentPoint//magnification + whichQuarter) printString),
-            ' (extent: ',
-            (currentExtent//magnification) printString, ')'.
-
-        currentPoint ~= lastCurrentPoint ifTrue:
-        [   
-            emphasis = #inverseFilledBox
-            ifTrue:
-            [
-                self redraw: ((firstPoint min: lastCurrentPoint) - 1 extent: (firstPoint - lastCurrentPoint) abs + 2).
-                self xoring: [self fillRectangle: ((firstPoint min: currentPoint) + margin 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]. 
-                origin := (firstPoint min: currentPoint) + margin.
-                extent := currentExtent - gridCorrection.
-                lineWidthY := extent y min: magnification y.
-                lineWidthX := extent x min: magnification x.
-                (lineWidthY > 0 and: [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].
-                self fillRectangle: ((firstPoint min: currentPoint) + margin extent: currentExtent - gridCorrection).
-            ].
-        ]. 
-        lastCurrentPoint := currentPoint.
-    ].                  
-
-    ^((0@0) max: (firstPoint min: currentPoint)) extent: (firstPoint - currentPoint) abs
-!
-
 fillAt: aPoint
 
     windowGroup withExecuteCursorDo:
@@ -816,7 +851,7 @@
             |choosedBox imagePoint imgX imgY copiedImage imageBox presentClr newColorMap|
 
 
-            choosedBox := self drawRectangleStartingAt: aPoint emphasis: #inverseFilledBox.
+            choosedBox := self dragRectangleStartingAt: aPoint emphasis: #inverseFilledBox.
 
             imagePoint := choosedBox origin//magnification.
 
@@ -891,7 +926,7 @@
         ]
    ]
 
-    "Modified: / 31.7.1998 / 20:12:49 / cg"
+    "Modified: / 21.8.1998 / 20:16:50 / cg"
 !
 
 pasteUnderAt: aPoint
@@ -1431,5 +1466,5 @@
 !ImageEditView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.99 1998-08-07 14:51:57 tz Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.100 1998-08-21 18:36:25 cg Exp $'
 ! !