color: make darker/brighter
authorClaus Gittinger <cg@exept.de>
Fri, 21 Feb 2003 13:20:17 +0100
changeset 1682 f1b2491c9dc2
parent 1681 7a8e5df3f07d
child 1683 f95658463570
color: make darker/brighter new-from-clipBoard
ImageEditor.st
--- a/ImageEditor.st	Fri Feb 21 11:25:12 2003 +0100
+++ b/ImageEditor.st	Fri Feb 21 13:20:17 2003 +0100
@@ -1563,6 +1563,24 @@
                 #value: #addColorToColormap
             )
              #(#MenuItem
+                #label: 'Pick and Add Color'
+                #translateLabel: true
+                #value: #pickAndAddColorToColormap
+            )
+             #(#MenuItem
+                #label: '-'
+            )
+             #(#MenuItem
+                #label: 'Darker'
+                #translateLabel: true
+                #value: #makeSelectedColorDarker
+            )
+             #(#MenuItem
+                #label: 'Brighter'
+                #translateLabel: true
+                #value: #makeSelectedColorBrighter
+            )
+             #(#MenuItem
                 #label: '-'
             )
              #(#MenuItem
@@ -1618,6 +1636,12 @@
                   #translateLabel: true
                 )
                #(#MenuItem
+                  #activeHelpKey: #fileNewImage
+                  #label: 'New from ClipBoard'
+                  #itemValue: #doNewImageFromClipboard
+                  #translateLabel: true
+                )
+               #(#MenuItem
                   #label: '-'
                 )
                #(#MenuItem
@@ -2596,12 +2620,14 @@
 !
 
 selectionOfColor
-    "returns current selection of the edit color as an AspectAdaptor"
+    "returns a valueHolder for the current selection of the edit color.
+     Here, an AspectAdaptor which accesses selectedColorIndex is returned."
 
     |holder|
+
     (holder := builder bindingAt:#selectionOfColor) isNil ifTrue:[
         builder aspectAt:#selectionOfColor put:(
-        holder := AspectAdaptor new subject:self; forAspect:#selectedColorIndex).
+        holder := AspectAdaptor new subject:self; forAspect:#selectedColorIndex ).
     ].
     ^ holder
 !
@@ -3179,6 +3205,10 @@
 !ImageEditor methodsFor:'user actions - colormap'!
 
 addColorToColormap
+    self addColorToColormap:(Color black)
+!
+
+addColorToColormap:newColor
     |depth img cMap newColorMap newImage oldCListSize newMode listOfColors|
 
     img := self image.
@@ -3194,7 +3224,7 @@
             self information:'Image has no colormap.\The shown colorMap is for drawing only.' withCRs.
             drawingColormap := OrderedCollection new.
         ].
-        drawingColormap add:(Color black).
+        drawingColormap add:newColor.
         self listOfColors contents:drawingColormap.
         self selectionOfColor value:(drawingColormap size).
 
@@ -3235,7 +3265,7 @@
 "/    ].
 "/
 
-    newColorMap := cMap copyWith:(Color black).
+    newColorMap := cMap copyWith:newColor.
 
     newImage := img species new
                     width:img width
@@ -3705,16 +3735,13 @@
 !
 
 inspectColor
-    | img clrIndex|
-
-    img := self image.
-    img isNil ifTrue:[
-        self warn:'No Image.'.
+    |clrIndex|
+
+    clrIndex := self selectedColorIndexOrNil.
+    clrIndex isNil ifTrue:[
         ^ self
     ].
-    clrIndex := self selectionOfColor value.
-    img mask notNil ifTrue: [ clrIndex := clrIndex - 1 ].
-    (img colorFromValue:clrIndex-1) inspect
+    (self image colorFromValue:clrIndex-1) inspect
 !
 
 makeBrighter
@@ -3770,76 +3797,11 @@
 !
 
 makeSelectedColorBrighter
-    |img cMap newImage clr|
-
-    img := self image.
-    cMap := img colorMap.
-    cMap isNil ifTrue:[
-        self warn:'Image has no colormap\change colorMap mode first.' withCRs.
-        ^ self
-    ].
-
-    imageEditView makeUndo.
-
-    cMap := cMap asArray.
-    clr := cMap at:imageEditView selectedColorIndex.
-    cMap at:imageEditView selectedColorIndex put:clr lightened.
-
-    newImage := img species new
-                    width:img width
-                    height:img height
-                    depth:nil
-                    fromArray:img bits.
-
-    newImage colorMap:cMap.  
-    newImage fileName:img fileName.
-    newImage mask:(img mask copy).
-
-    (imageEditView image:newImage) notNil ifTrue:[
-        self fetchImageData.
-"/        self listOfColors contents: newImage colorMap.
-"/        self findColorMapMode.
-"/        self updateLabelsAndHistory.
-    ]
-
-    "Created: / 12.3.1999 / 00:20:28 / cg"
-    "Modified: / 16.3.1999 / 21:57:26 / cg"
+    self processSelectedColorWith:[:clr | clr lightened]
 !
 
 makeSelectedColorDarker
-    |img cMap clr newImage|
-
-    img := self image.
-    cMap := img colorMap.
-    cMap isNil ifTrue:[
-        self warn:'Image has no colormap\change colorMap mode first.' withCRs.
-        ^ self
-    ].
-    imageEditView makeUndo.
-
-    cMap := cMap asArray.
-    clr := cMap at:imageEditView selectedColorIndex.
-    cMap at:imageEditView selectedColorIndex put:clr darkened.
-
-    newImage := img species new
-                    width:img width
-                    height:img height
-                    depth:nil
-                    fromArray:img bits.
-
-    newImage colorMap:cMap.  
-    newImage fileName:img fileName.
-    newImage mask:(img mask copy).
-
-    (imageEditView image:newImage) notNil ifTrue:[
-        self fetchImageData.
-"/        self listOfColors contents: newImage colorMap.
-"/        self findColorMapMode.
-"/        self updateLabelsAndHistory.
-    ]
-
-    "Created: / 12.3.1999 / 00:20:28 / cg"
-    "Modified: / 16.3.1999 / 21:57:26 / cg"
+    self processSelectedColorWith:[:clr | clr darkened]
 !
 
 pasteMask
@@ -3862,6 +3824,52 @@
     ]
 !
 
+pickAndAddColorToColormap
+    self addColorToColormap:(Color fromUser)
+!
+
+processSelectedColorWith:aBlock
+    |img cMap clr newImage selectedColorIndex oldSelection|
+
+    selectedColorIndex := self selectedColorIndexOrNil.
+    selectedColorIndex isNil ifTrue:[^ self].
+
+    img := self image.
+    cMap := img colorMap.
+    cMap isNil ifTrue:[
+        self warn:'Image has no colormap\change colorMap mode first.' withCRs.
+        ^ self
+    ].
+    imageEditView makeUndo.
+
+    cMap := cMap asArray.
+    clr := cMap at:selectedColorIndex.
+    cMap at:selectedColorIndex put:(aBlock value:clr).
+
+    newImage := img species new
+                    width:img width
+                    height:img height
+                    depth:nil
+                    fromArray:img bits.
+
+    newImage colorMap:cMap.  
+    newImage fileName:img fileName.
+    newImage mask:(img mask copy).
+
+    oldSelection := self selectionOfColor value.
+
+    (imageEditView image:newImage) notNil ifTrue:[
+        self fetchImageData.
+"/        self listOfColors contents: newImage colorMap.
+"/        self findColorMapMode.
+"/        self updateLabelsAndHistory.
+    ].
+    self selectionOfColor value:oldSelection.
+
+    "Created: / 12.3.1999 / 00:20:28 / cg"
+    "Modified: / 16.3.1999 / 21:57:26 / cg"
+!
+
 reduceNumberOfColors
     |s n anyChange img|
 
@@ -3890,6 +3898,19 @@
     ].
 !
 
+selectedColorIndexOrNil
+    | img clrIndex|
+
+    img := self image.
+    img isNil ifTrue:[
+        self warn:'No Image.'.
+        ^ nil
+    ].
+    clrIndex := self selectionOfColor value.
+    img mask notNil ifTrue: [ clrIndex := clrIndex - 1 ].
+    ^ clrIndex
+!
+
 sortColorMap
     "calculates a new color map for the image, sorting colors"
 
@@ -4428,6 +4449,19 @@
     ]
 !
 
+doNewImageFromClipboard
+    |image|
+
+    image := imageEditView clipBoard.
+
+    (imageEditView image:image) notNil
+    ifTrue:[
+        self listOfColors contents:(image colorMap).
+        self findColorMapMode.
+        self updateLabelsAndHistory.
+    ]
+!
+
 grabScreenImage
     "let user choose an area and grab that are for editing"