#UI_ENHANCEMENT
authorClaus Gittinger <cg@exept.de>
Mon, 05 Oct 2015 09:18:43 +0200
changeset 6965 066bfdfbb5b3
parent 6964 a459b5a03d9c
child 6966 37711d94a0c0
#UI_ENHANCEMENT class: MacFlatButtonBorder class definition added:6 methods removed: #insideColor: comment/format in: #color: changed: #displayOn:forDisplayBox: #makeImages
MacFlatButtonBorder.st
--- a/MacFlatButtonBorder.st	Mon Oct 05 09:18:32 2015 +0200
+++ b/MacFlatButtonBorder.st	Mon Oct 05 09:18:43 2015 +0200
@@ -5,7 +5,8 @@
 "{ NameSpace: Smalltalk }"
 
 SimpleBorder subclass:#MacFlatButtonBorder
-	instanceVariableNames:'insideColor imgTopLeft imgTopRight imgBottomLeft imgBottomRight'
+	instanceVariableNames:'backgroundColor1 backgroundColor2 imgTopLeft imgTopRight
+		imgBottomLeft imgBottomRight'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Graphics-Support'
@@ -23,6 +24,12 @@
 
 !MacFlatButtonBorder class methodsFor:'instance creation'!
 
+color:color1 backgroundColor:color2
+    "create a new instance of the receiver with a border of the given color."
+
+    ^ self new color:color1; backgroundColor:color2
+!
+
 color:color1 insideColor:color2
     "create a new instance of the receiver with a border of the given color."
 
@@ -129,22 +136,61 @@
     ^Icon
         constantNamed:'MacOSXRoundButtonBorder topLeftImageUnfilledMasked3'
         ifAbsentPut:[(Depth2Image width:4 height:4) bits:(ByteArray fromPackedString:'HH  @@@a') colorMapFromArray:#[183 183 183 201 201 201 224 224 224 255 255 255] mask:((ImageMask width:4 height:4) bits:(ByteArray fromPackedString:'\NC@ @@a'); yourself); yourself]
+!
+
+topLeftImageUnfilledMasked4
+    "This resource specification was automatically generated
+     by the ImageEditor of ST/X."
+
+    "Do not manually edit this!! If it is corrupted,
+     the ImageEditor may not be able to read the specification."
+
+    "
+     self topLeftImageUnfilledMasked4 inspect
+     ImageEditor openOnClass:self andSelector:#topLeftImageUnfilledMasked4
+     Icon flushCachedIcons
+    "
+
+    <resource: #image>
+
+    ^Icon
+        constantNamed:'MacFlatButtonBorder topLeftImageUnfilledMasked4'
+        ifAbsentPut:[(Depth2Image width:4 height:4) bits:(ByteArray fromPackedString:'8H  @@@a') colorMapFromArray:#[183 183 183 201 201 201 224 224 224 255 255 255] mask:((ImageMask width:4 height:4) bits:(ByteArray fromPackedString:'<NC@ @@a'); yourself); yourself]
 ! !
 
 !MacFlatButtonBorder methodsFor:'accessing'!
 
+backgroundColor1
+    "the first gradient color"
+
+    ^ backgroundColor1
+!
+
+backgroundColor1:something
+    "the first gradient color"
+
+    backgroundColor1 := something.
+!
+
+backgroundColor2
+    "the second gradient color"
+
+    ^ backgroundColor2
+!
+
+backgroundColor2:something
+    "the second gradient color"
+
+    backgroundColor2 := something.
+!
+
 color:newColor
+    "the color of the border"
+    
     color ~= newColor ifTrue:[        
         color := newColor.
         imgTopLeft := imgTopRight := imgBottomLeft := imgBottomRight := nil.
     ].
-!
-
-insideColor:newColor
-    insideColor ~= newColor ifTrue:[        
-        insideColor := newColor.
-        imgTopLeft := imgTopRight := imgBottomLeft := imgBottomRight := nil.
-    ].
 ! !
 
 !MacFlatButtonBorder methodsFor:'displaying'!
@@ -155,7 +201,6 @@
     color isNil ifTrue:[ ^ self].
 
     oldPaint := aGC paint.
-    aGC paint:color.
 
     boxLeft := aRectangle left.
     boxTop := aRectangle top.
@@ -167,13 +212,23 @@
     
     imgTopLeft isNil ifTrue:[
         self makeImages.
+        imgTopLeft isNil ifTrue:[
+            ^ self
+        ].    
     ].    
 
+    aGC paint:(aGC viewBackground).
+    aGC fillRectangleX:boxLeft y:boxTop width:4 height:4.
+    aGC fillRectangleX:boxRight-4 y:boxTop width:4 height:4.
+    aGC fillRectangleX:boxRight-4 y:boxBottom-4 width:4 height:4.
+    aGC fillRectangleX:boxLeft y:boxBottom-4 width:4 height:4.
+
     aGC displayImage:imgTopLeft x:boxLeft y:boxTop.
     aGC displayImage:imgTopRight x:boxRight-4 y:boxTop.
     aGC displayImage:imgBottomRight x:boxRight-4 y:boxBottom-4.
     aGC displayImage:imgBottomLeft x:boxLeft y:boxBottom-4.
 
+    aGC paint:color.
     aGC displayLineFromX:boxLeft+4 y:boxTop toX:boxRight-4 y:boxTop.
     aGC displayLineFromX:boxLeft+4 y:boxBottom-1 toX:boxRight-4 y:boxBottom-1.
     aGC displayLineFromX:boxLeft y:boxTop+4 toX:boxLeft y:boxBottom-4.
@@ -186,7 +241,7 @@
 
      v1 := TopView new.
      v2 := View origin:10@10 corner:100@30 in:v1.
-     v2 border:(MacOSXRoundButtonBorder color:Color red).
+     v2 border:(MacFlatButtonBorder color:Color red).
      v1 open.
     "
     "
@@ -194,7 +249,7 @@
 
      v1 := TopView new.
      v2 := View origin:10@10 corner:100@30 in:v1.
-     v2 border:(MacOSXRoundButtonBorder color:Color red insideColor:Color blue).
+     v2 border:((MacFlatButtonBorder color:Color red) backgroundColor1:Color blue; backgroundColor2:Color green).
      v1 open.
     "
 ! !
@@ -202,41 +257,33 @@
 !MacFlatButtonBorder methodsFor:'private'!
 
 makeImages
-    |protoImage img hue light sat innerHue innerLight innerSat|
+    |protoImage img hue light sat|
     
     hue := color hue.
     light := color light.
     sat := color saturation.
 
-    insideColor isNil ifTrue:[
-        protoImage := self class topLeftImageUnfilledMasked3.
-    ] ifFalse:[    
-        insideColor hue isNil ifTrue:[
-            protoImage := self class topLeftImageUnfilled.
-        ] ifFalse:[    
-            protoImage := self class topLeftImageFilled.
-            innerHue := insideColor hue.
-            innerLight := insideColor light.
-            innerSat := insideColor saturation.
-        ].
-    ].
+    protoImage := self class topLeftImageUnfilledMasked4.
     img := protoImage copy.
 
-    innerHue notNil ifTrue:[
-        img colorMap at:1 put:insideColor.
-        img colorMap at:2 put:color.
-        img colorMap at:3 put:(Color hue:hue light:light+8 saturation:sat-12).
-        img colorMap at:4 put:(Color hue:hue light:light+20 saturation:sat-40).
-    ] ifFalse:[
-        img colorMap at:1 put:color.
+    img colorMap at:1 put:color.
+    hue notNil ifTrue:[
         img colorMap at:2 put:(Color hue:hue light:light+15 saturation:sat-12).
         img colorMap at:3 put:(Color hue:hue light:light+30 saturation:sat-40).
     ].    
-    
     imgTopLeft := img.
     imgTopRight := img rotated:90.
     imgBottomLeft := img rotated:-90.
     imgBottomRight := img rotated:180.
+
+    backgroundColor1 notNil ifTrue:[ 
+        imgTopLeft colorMap at:4 put:backgroundColor1. 
+        imgTopRight colorMap at:4 put:backgroundColor1. 
+    ].
+    backgroundColor2 notNil ifTrue:[ 
+        imgBottomLeft colorMap at:4 put:backgroundColor2. 
+        imgBottomRight colorMap at:4 put:backgroundColor2. 
+    ].
 ! !
 
 !MacFlatButtonBorder class methodsFor:'documentation'!