# HG changeset patch # User Claus Gittinger # Date 1504600870 -7200 # Node ID f54ee88a464db57abb231443488cf9abaad44914 # Parent b831d12998488788a08f1340a063785ec6544f92 #FEATURE by cg class: ImageEditor added: #alphaHolder #alphaText #alphaVisibleHolder #hasAlphaChannel #hasTransparentColorInColorList comment/format in: #open changed: #findColorMapMode (send #hasTransparentColorInColorList instead of #hasMask) #hasMask #makeSelectedColorShifted (send #hasTransparentColorInColorList instead of #hasMask) #postOpenWith: #processSelectedColorsWith: (send #hasTransparentColorInColorList instead of #hasMask) #selectedColorIndexOrNil (send #hasTransparentColorInColorList instead of #hasMask) #update:with:from: (send #hasTransparentColorInColorList instead of #hasMask) #updateAfterImageChange #updateForNoImage #updateListOfColorsAndColormapMode class: ImageEditor class comment/format in: #helpPairs #windowSpec diff -r b831d1299848 -r f54ee88a464d ImageEditor.st --- a/ImageEditor.st Fri Sep 01 14:28:14 2017 +0200 +++ b/ImageEditor.st Tue Sep 05 10:41:10 2017 +0200 @@ -331,6 +331,9 @@ #drawingColor2 'The color associated to the right mouse button.\Also the second color used in gradient fill operations' +#drawingAlpha +'The alpha value to be used in edit operations.\If the "mask"-color is selected, only the alpha value will be changed.\Otherwise, the selected color plus this alpha value will be used for drawing' + #autoCropAll 'Find and remove all borders' @@ -603,7 +606,7 @@ ) - "Modified: / 06-04-2017 / 13:26:57 / cg" + "Modified: / 05-09-2017 / 10:38:06 / cg" ! helpSpec @@ -2471,6 +2474,29 @@ level: 0 menu: menuMouseButtonColors ) + (LabelSpec + label: 'Label' + name: 'Label1' + layout: (LayoutFrame -160 1 0 0 -104 1 22 0) + translateLabel: true + labelChannel: alphaText + visibilityChannel: alphaVisibleHolder + activeHelpKey: drawingAlpha + ) + (InputFieldSpec + name: 'EntryField1' + layout: (LayoutFrame -106 1 2 0 -56 1 22 0) + acceptOnReturn: true + acceptOnTab: true + acceptOnPointerLeave: true + visibilityChannel: alphaVisibleHolder + activeHelpKey: drawingAlpha + model: alphaHolder + type: numberInRange + numChars: 3 + minValue: 0 + maxValue: 100 + ) (ViewSpec name: 'Box1' layout: (LayoutFrame -40 1.0 4 0 -26 1.0 18 0) @@ -2661,6 +2687,8 @@ ) ) + + "Modified: / 05-09-2017 / 10:38:33 / cg" ! ! !ImageEditor class methodsFor:'menu specs'! @@ -4296,6 +4324,36 @@ "Modified: / 29.7.1998 / 18:49:03 / cg" ! +alphaHolder + |holder| + + (holder := builder bindingAt:#alphaHolder) isNil ifTrue:[ + builder aspectAt:#alphaHolder put:(holder := 100 asValue). + holder onChangeEvaluate:[ imageEditView drawingAlpha:holder value ]. + ]. + ^ holder + + "Created: / 05-09-2017 / 00:38:14 / cg" + "Modified: / 05-09-2017 / 10:35:25 / cg" +! + +alphaText + ^ 'alpha:' + + "Created: / 05-09-2017 / 00:32:55 / cg" +! + +alphaVisibleHolder + |holder| + + (holder := builder bindingAt:#alphaVisibleHolder) isNil ifTrue:[ + builder aspectAt:#alphaVisibleHolder put:(holder := false asValue). + ]. + ^ holder + + "Created: / 05-09-2017 / 00:35:36 / cg" +! + canAddColorToColormap |img| @@ -4872,7 +4930,7 @@ drawColor1 := newListOfColors at:1. drawColor2 := newListOfColors at:2 ifAbsent:drawColor1. - self hasMask ifTrue: [ + self hasTransparentColorInColorList ifTrue: [ (newListOfColors includes:(Color colorId:0)) ifFalse:[ newListOfColors addFirst:(Color colorId:0). drawColor1 := newListOfColors at:2. @@ -4888,7 +4946,7 @@ self listOfColors contents:newListOfColors. ]. - "Modified: / 06-04-2017 / 13:20:10 / cg" + "Modified: / 05-09-2017 / 09:03:31 / cg" ! selectedColorsChanged @@ -4932,7 +4990,7 @@ "/ colormap entry changed at aParameter clrIndex := aParameter. - (self hasMask) ifTrue:[ + (self hasTransparentColorInColorList) ifTrue:[ clrIndex := clrIndex - 1. ]. changedColor := changedObject at:aParameter. @@ -4992,7 +5050,7 @@ (aParameter isNil or:[aParameter = (Color colorId:0)]) ifTrue:[ "/ no color/mask */ "/ self halt. - clrIndex := self hasMask ifTrue:[1] ifFalse:[0]. + clrIndex := self hasTransparentColorInColorList ifTrue:[1] ifFalse:[0]. ] ifFalse:[ clrIndex := self listOfColors indexOf:aParameter. ]. @@ -5015,7 +5073,7 @@ super update:something with:aParameter from:changedObject - "Modified: / 24-08-2017 / 17:12:59 / cg" + "Modified: / 05-09-2017 / 09:04:21 / cg" ! updateAfterImageChange @@ -5033,11 +5091,12 @@ self imageHasImageSequenceHolder value:(self imageHasImageSequence). self imageHasNextImageHolder value:(self imageHasNextImage). self imageHasPreviousImageHolder value:(self imageHasPreviousImage). + self alphaVisibleHolder value:(img hasAlphaChannel) ] ifFalse:[ self updateForNoImage ] - "Modified: / 21-10-2010 / 14:40:45 / cg" + "Modified: / 05-09-2017 / 00:44:10 / cg" ! updateColorsFromImage:image @@ -5077,8 +5136,9 @@ self listOfColors removeAll. self imagePreView image: nil. self imageHasImageSequenceHolder value:false. - - "Modified: / 21-10-2010 / 14:39:13 / cg" + self alphaVisibleHolder value:false. + + "Modified: / 05-09-2017 / 00:44:20 / cg" ! updateLabelsAndHistory @@ -5106,23 +5166,24 @@ ! updateListOfColorsAndColormapMode - |selectedColor colorMap image| + |listOfColors selectedColor colorMap image| selectedColor := self selectedColorOrNil. - + listOfColors := self listOfColors. + image := self image. image isNil ifTrue:[ - self listOfColors removeAll. + listOfColors removeAll. ] ifFalse:[ colorMap := image colorMap. colorMap notNil ifTrue:[ (colorMap size <= 4096) ifTrue:[ - image mask notNil ifTrue:[ + (image mask notNil or:[image hasAlphaChannel]) ifTrue:[ colorMap := (Array with:(Color noColor)),colorMap. ]. - self listOfColors contents:colorMap. + listOfColors contents:colorMap. ] ifFalse:[ - self listOfColors removeAll. + listOfColors removeAll. colorMap isFixedPalette ifTrue:[ image colorMap:nil. image photometric:#rgb. @@ -5140,6 +5201,8 @@ selectedColor notNil ifTrue:[ self selectColor:selectedColor. ]. + + "Modified: / 05-09-2017 / 08:25:14 / cg" ! ! !ImageEditor methodsFor:'data access'! @@ -5771,17 +5834,30 @@ !ImageEditor methodsFor:'queries'! +hasAlphaChannel + |img| + + img := self image. + img isNil ifTrue:[^ false]. + ^ img hasAlphaChannel + + "Created: / 05-09-2017 / 08:29:23 / cg" +! + hasLastGrabScreenArea ^ [ lastGrabbedScreenArea notNil ] ! hasMask - self image isNil ifTrue:[^ false]. - self image mask isNil ifTrue:[^ false]. + |img| + + img := self image. + img isNil ifTrue:[^ false]. + img mask isNil ifTrue:[^ false]. ^ colorMapMode value notNil and:[colorMapMode value startsWith:'mask'] "Created: / 18-08-1998 / 17:17:38 / cg" - "Modified: / 18-02-2017 / 00:40:25 / cg" + "Modified: / 05-09-2017 / 08:28:44 / cg" ! hasMaskHolder @@ -5790,6 +5866,12 @@ "Created: / 18-02-2017 / 00:41:19 / cg" ! +hasTransparentColorInColorList + ^ self hasMask or:[self hasAlphaChannel] + + "Created: / 05-09-2017 / 09:03:24 / cg" +! + modified "true if the image was modified" @@ -5910,11 +5992,13 @@ ! open - "after opening, sets the masterApplication of the imageEditView to self" + "after opening, gets the imageEditView" super open. imageEditView := (self componentAt: #imageEditView) subViews first. + + "Modified (comment): / 05-09-2017 / 10:39:45 / cg" ! postOpenWith:aBuilder @@ -5931,8 +6015,9 @@ self drawingColor1Holder valueHolder:(imageEditView drawingColorHolders at:1). self drawingColor2Holder valueHolder:(imageEditView drawingColorHolders at:2). - - "Modified: / 23-02-2017 / 10:19:27 / cg" + imageEditView drawingAlpha:(self alphaHolder value). + + "Modified (format): / 05-09-2017 / 10:40:10 / cg" ! ! !ImageEditor methodsFor:'user actions-colormap'! @@ -6888,11 +6973,11 @@ cMap := self image colorMap. "/ if there is a mask, it is at position 1 in the table - cmapOffset := self hasMask ifTrue:[1] ifFalse:[0]. + cmapOffset := self hasTransparentColorInColorList ifTrue:[1] ifFalse:[0]. colors := self selectedColors value collect:[:idx | cMap at:idx-cmapOffset]. self changeHLSOfColors:colors. - "Modified: / 31-08-2017 / 14:15:03 / cg" + "Modified: / 05-09-2017 / 09:03:47 / cg" ! makeSlightlyBrighter @@ -7070,7 +7155,7 @@ selectedColorIndices isEmptyOrNil ifTrue:[^ self]. img := self image. - self hasMask ifTrue:[ + self hasTransparentColorInColorList ifTrue:[ maskOffset := 1. ] ifFalse:[ maskOffset := 0. @@ -7114,7 +7199,7 @@ ]. self selectedColors value:selectedColorIndices. - "Modified: / 22-02-2017 / 19:45:29 / cg" + "Modified: / 05-09-2017 / 09:03:52 / cg" ! reduceNumberOfColors @@ -7270,13 +7355,15 @@ ^ nil ]. clrIndex := self selectionOfColor value. - self hasMask "img mask notNil" ifTrue: [ + self hasTransparentColorInColorList ifTrue: [ (clrIndex isInteger and:[clrIndex > 1]) ifTrue:[ ^ clrIndex - 1 ]. ^ nil ]. ^ clrIndex + + "Modified: / 05-09-2017 / 09:04:05 / cg" ! selectedColorOrNil