+spray and circle
authorClaus Gittinger <cg@exept.de>
Mon, 14 Jul 2008 22:22:57 +0200
changeset 3476 4b4dce2bd87b
parent 3475 8ed28a1e4e37
child 3477 00d7bac0b2c4
+spray and circle
ImageEditView.st
--- a/ImageEditView.st	Sat Jul 12 17:23:08 2008 +0200
+++ b/ImageEditView.st	Mon Jul 14 22:22:57 2008 +0200
@@ -16,12 +16,14 @@
 		mouseKeyColorMode undoImages modifiedHolder editMode
 		lastPastePoint imageInfoHolder activityInfoHolder
 		pickedColorHolder drawingColors drawingPixels drawingColorHolders
-		drawingPixelHolders clickInfoCallBack penWidth'
+		drawingPixelHolders clickInfoCallBack penWidth sprayProcess
+		sprayPosition spraySpot'
 	classVariableNames:'Clipboard ClipboardMagnified LastMagnification
 		GridMagnificationLimit MaxUndos LastSaveDirectory LastSaveClass
 		EditModePoint EditModeBox EditModeFilledBox EditModeFill
 		EditModeCopy EditModePasteUnder EditModePaste
-		EditModePasteWithMask EditModeSpecialOperation'
+		EditModePasteWithMask EditModeSpecialOperation EditModeSpray
+		EditModeCircle'
 	poolDictionaries:''
 	category:'Views-Misc'
 !
@@ -63,6 +65,7 @@
 
     EditModePoint := #point.
     EditModeBox := #box.
+    EditModeCircle := #circle.
     EditModePaste := #paste.
     EditModePasteUnder := #pasteUnder.
     EditModePasteWithMask := #pasteWithMask.
@@ -70,6 +73,7 @@
     EditModeFill := #fill.
     EditModeCopy := #copy.
     EditModeSpecialOperation := #specialOperation.
+    EditModeSpray := #spray.
 
     "
      self initialize
@@ -321,6 +325,10 @@
     self modified:true
 !
 
+spraySpot:something
+    spraySpot := something.
+!
+
 undoImages
     ^ undoImages
 ! !
@@ -425,7 +433,7 @@
 
     |ih iw magX magY minX maxX minY maxY 
      color lastColor lastY runW x0 xI yI maskColor mask
-     sizeOfMaskPoint useNearestColor|
+     sizeOfMaskPoint useNearestColor origin|
 
     useNearestColor := device visualType == #PseudoColor.
 
@@ -458,9 +466,7 @@
 
             yy ~~ lastY ifTrue:[
                 runW ~~ 0 ifTrue:[
-                    |origin|
-
-                    origin := (x0 * magX + margin)@(lastY * magY + margin).
+                    origin := (x0 * magX + margin) @ (lastY * magY + margin).
                     (unmaskedOnly not or:[maskColor not]) ifTrue:[
                         self fillFramedRectangle: (origin extent: (runW@magY)).                    
                         maskColor ifTrue:[
@@ -475,7 +481,7 @@
 
             color ~= lastColor ifTrue:[
                 runW ~~ 0 ifTrue:[
-                    |origin|
+
                     origin := (x0 * magX + margin)@(yy * magY + margin).
                     (unmaskedOnly not or:[maskColor not]) ifTrue:[
                         self fillFramedRectangle: (origin extent: (runW@magY)).
@@ -508,8 +514,6 @@
         ].
 
     runW ~~ 0 ifTrue:[
-        |origin|
-
         origin := (x0 * magX + margin)@(lastY * magY + margin).
         (unmaskedOnly not or:[maskColor not]) ifTrue:[
             self fillFramedRectangle: (origin extent: runW@magY).
@@ -546,11 +550,11 @@
         ].
     ].
 
-    self clippingRectangle: (x@y extent:w@h).
+    "/ self clippingRectangle: (x@y extent:w@h).
 
     self redrawImageX:x y:y width:w height:h.
 
-    "/ right of image ?
+    "/ beyond of image ?
     adjust == #center ifTrue:
     [
         xI := (width - ih) // 2 - margin.
@@ -582,6 +586,46 @@
     self clippingRectangle: nil.
 
     "Modified: / 31.7.1998 / 02:22:45 / cg"
+!
+
+startSpray
+    spraySpot isNil ifTrue:[
+        spraySpot := 8
+    ].
+
+    sprayProcess isNil ifTrue:[
+        sprayProcess := [
+                |p rnd norm sprayPoint dly angle x y dist|
+
+                rnd := Random new.
+                norm := Distributions::NormalDistribution mean:0 deviation:0.5.
+                dly := Delay forMilliseconds:5.
+                [true] whileTrue:[
+                    10 timesRepeat:[
+                        p := sprayPosition.
+                        p notNil ifTrue:[
+                            angle := rnd next * 359.999.    "/ the angle is uniformly ditributed
+                            dist := norm next * spraySpot.  "/ the distance is a normalDistribution
+                            sprayPoint := (Point r:dist degrees:angle)*magnification.
+
+                            x := p x + sprayPoint x truncated.
+                            y := p y + sprayPoint y truncated.
+                            self pointAt:(x@y).
+                        ].
+                    ].
+                    dly wait.
+                ].
+        ] fork.
+    ]
+
+    "Modified: 10.4.1997 / 15:21:24 / cg"
+!
+
+stopSpray
+    sprayProcess notNil ifTrue:[
+        sprayProcess terminate.
+        sprayProcess := nil
+    ].
 ! !
 
 !ImageEditView methodsFor:'edit modes'!
@@ -603,6 +647,8 @@
         EditModeFill 
         EditModeCopy 
         EditModeSpecialOperation 
+        EditModeSpray 
+        EditModeCircle 
     "
 
     editMode := anEditModeSymbol
@@ -630,28 +676,34 @@
     p := x@y.
 
     state ~~ 0 ifTrue:[
-        ("self selectedColor notNil" true 
-        and:[(self imageContainsPoint:p) 
-        and:[editMode == EditModePoint]])
-        ifTrue:[
-            self pointAt:p.
-            ^ self
+        "/ button down
+
+        "/ self selectedColor notNil ifTrue:[ 
+        (self imageContainsPoint:p) ifTrue:[
+            (editMode == EditModePoint) ifTrue:[
+                self pointAt:p.
+                ^ self
+            ].
+            sprayProcess notNil ifTrue:[
+                sprayPosition := p.
+               ^ self
+            ].
         ].
         self drawCursorAt:p.
-    ] ifFalse:[
-"/ Transcript showCR:'m'.
-        self drawCursorAt:p.
-        self inPasteMode ifTrue: [
-"/ Transcript show:'p '; showCR:(self imageContainsPastePoint:p).
-            self sensor shiftDown ifTrue:[
-                p := p - Clipboard extent
-            ].
-            ("self selectedColor notNil" true and: [self imageContainsPastePoint:p]) 
-                ifTrue:  [
-                    (self sensor hasButtonMotionEventFor:self) ifFalse:[
-                        self drawPasteRectangleAt:p]]
-                ifFalse: [self cursor:Cursor stop. self releasePasteDrawing]
-        ]
+        ^ self
+    ].
+
+    "/button up (care for paste-mode, dragging the pasted image)
+    self drawCursorAt:p.
+    self inPasteMode ifTrue: [
+        self sensor shiftDown ifTrue:[
+            p := p - Clipboard extent
+        ].
+        ("self selectedColor notNil" true and: [self imageContainsPastePoint:p]) 
+            ifTrue:  [
+                (self sensor hasButtonMotionEventFor:self) ifFalse:[
+                    self drawPasteRectangleAt:p]]
+            ifFalse: [self cursor:Cursor stop. self releasePasteDrawing]
     ]
 
     "Modified: / 20-11-2007 / 17:17:41 / cg"
@@ -718,7 +770,11 @@
     self drawCursorAt: x@y.
 
     ("self selectedColor notNil" true and: [self imageContainsPoint: x@y])
-    ifTrue: [   
+    ifTrue: [
+        sprayProcess notNil ifTrue:[
+            self stopSpray
+        ].
+
         image release.
 
 "/        "/ cg: what a kludge - please change to use a valueHolder,
@@ -779,6 +835,29 @@
     "Modified: / 10.2.2000 / 23:42:08 / cg"
 !
 
+circleAt: aPoint
+    "draw an elliptic outline with the currently selected color"
+
+    |choosenBox imageBox clr|
+
+    (clr := self selectedColor) notNil ifTrue:[
+        choosenBox := self dragRectangleStartingAt: aPoint emphasis: #box.
+        choosenBox notNil ifTrue:[
+            imageBox := choosenBox origin//magnification extent: (choosenBox extent//magnification).
+            image drawEllipse:imageBox withColor:clr.
+            image restored.
+            self redraw: (choosenBox expandedBy: 1).
+
+            "/ cg: still a kludge - but less ugly
+            self changed:#subImageIn with:(imageBox expandedBy: 1).
+
+            self setModified.
+        ].
+    ].
+
+    "Modified: / 10.2.2000 / 23:42:08 / cg"
+!
+
 copyAt: aPoint
     |choosenBox r box copiedImage|
 
@@ -1436,6 +1515,9 @@
     |w draw imagePoint clr pix|
 
     imagePoint := aPoint // magnification.
+    (imagePoint x between:0 and:image width-1) ifFalse:[^ self].
+    (imagePoint y between:0 and:image height-1) ifFalse:[^ self].
+
     draw := [:point |
         image colorMap isNil ifTrue:[
             clr := self selectedColor.
@@ -1443,7 +1525,7 @@
         ] ifFalse:[
             pix := self selectedColorIndex.
             image atImageAndMask:point putValue:pix.
-        ].
+        ].             
         self invalidate:((point * magnification extent: magnification) expandedBy:1).
     ].
     draw value:imagePoint.
@@ -1455,9 +1537,9 @@
         (w//2) negated to:(w-(w//2)) do:[:xOffs |
             (w//2) negated to:(w-(w//2)) do:[:yOffs |
                 imagePoint x + xOffs >= 0 ifTrue:[
-                  imagePoint y + yOffs >= 0 ifTrue:[
-                    draw value:(imagePoint + (xOffs@yOffs)).
-                  ].
+                    imagePoint y + yOffs >= 0 ifTrue:[
+                        draw value:(imagePoint + (xOffs@yOffs)).
+                    ].
                 ].
             ].
         ].
@@ -1594,6 +1676,17 @@
     self setModified.
 !
 
+sprayAt: aPoint
+    "start spraying with the currently selected color"
+
+    |clr|
+
+    (clr := self selectedColor) notNil ifTrue:[
+        sprayPosition := aPoint.
+        self startSpray.
+    ].
+!
+
 text:aString at:aPoint
     "draw a character"
 
@@ -1847,8 +1940,7 @@
                     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:[
+                emphasis = #box ifTrue:[
                     |origin extent lineWidthY lineWidthX|
                     origin := (firstPoint min: lastCurrentPoint) - 1.
                     extent := (firstPoint - lastCurrentPoint) abs + 2.
@@ -1873,8 +1965,7 @@
                         self fillRectangle: (((origin x + extent x - lineWidthX)@(origin y + lineWidthY)) extent: (lineWidthX@(extent y - (lineWidthY * 2)))).
                     ]
                 ].
-                emphasis = #filledBox
-                ifTrue:[
+                emphasis = #filledBox ifTrue:[
                     self redraw: ((firstPoint min: lastCurrentPoint) - 1 extent: (firstPoint - lastCurrentPoint) abs + 2).
                     self selectedColor ~= Color noColor
                         ifTrue: [self paint: self selectedColor]
@@ -2457,7 +2548,7 @@
 !ImageEditView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.225 2008-06-05 12:02:52 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.226 2008-07-14 20:22:57 cg Exp $'
 ! !
 
 ImageEditView initialize!