#UI_ENHANCEMENT
authorClaus Gittinger <cg@exept.de>
Mon, 05 Oct 2015 09:18:32 +0200
changeset 6964 a459b5a03d9c
parent 6963 26d226d61d32
child 6965 066bfdfbb5b3
#UI_ENHANCEMENT class: MacButtonBorder class definition added:7 methods removed:6 methods comment/format in: #examples changed: #displayOn:forDisplayBox: #initialize
MacButtonBorder.st
--- a/MacButtonBorder.st	Sun Oct 04 23:45:34 2015 +0200
+++ b/MacButtonBorder.st	Mon Oct 05 09:18:32 2015 +0200
@@ -5,7 +5,8 @@
 "{ NameSpace: Smalltalk }"
 
 AbstractBorder subclass:#MacButtonBorder
-	instanceVariableNames:''
+	instanceVariableNames:'topLeftEdge topRightEdge bottomLeftEdge bottomRightEdge
+		viewBackgroundColor'
 	classVariableNames:'TopLeftEdge TopRightEdge BottomLeftEdge BottomRightEdge'
 	poolDictionaries:''
 	category:'Graphics-Support'
@@ -26,7 +27,6 @@
                                                 [exBegin]
      |top v b|
 
-
      top := StandardSystemView extent:100@100.
      v := View origin:10@10 corner:90@30 in:top.
      top openAndWait.
@@ -53,10 +53,14 @@
 !MacButtonBorder class methodsFor:'initialization'!
 
 initialize
-    TopLeftEdge := self topLeftImage2.
-    TopRightEdge := self topRightImage2.
-    BottomLeftEdge := self bottomLeftImage2.
-    BottomRightEdge := self bottomRightImage2.
+    "/ self initializeImages. -- done lazy
+!
+
+initializeImages
+    TopLeftEdge := self topLeftImage.
+    TopRightEdge := TopLeftEdge copy flipHorizontal.
+    BottomLeftEdge := self bottomLeftImage.
+    BottomRightEdge := BottomLeftEdge copy flipHorizontal.
 ! !
 
 !MacButtonBorder class methodsFor:'image specs'!
@@ -78,69 +82,8 @@
 
     ^Icon
         constantNamed:'MacButtonBorder bottomLeftImage'
-        ifAbsentPut:[(Depth8Image new) width:4; height:4; bits:(ByteArray fromPackedString:'BP A@P@F@PD@APXH@@@DA0@a') ; colorMapFromArray:#[184 184 184 255 255 255 226 226 226 224 224 224 181 181 181 162 162 162 211 211 211 158 158 158 248 248 248 159 159 159]; mask:((Depth1Image new) width:4; height:4; bits:(ByteArray fromPackedString:'<OA0L@@a') ; yourself); yourself]
-!
-
-bottomLeftImage2
-    "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 bottomLeftImage2 inspect
-     ImageEditor openOnClass:self andSelector:#bottomLeftImage2
-     Icon flushCachedIcons
-    "
-
-    <resource: #image>
-
-    ^Icon
-        constantNamed:'MacButtonBorder bottomLeftImage2'
-        ifAbsentPut:[(Depth8Image new) width:9; height:10; bits:(ByteArray fromPackedString:'E@4VHRD!!HRD!!E0XUHRD!!HRD!!GP0QG"D!!HRD!!H!!@EGBD!!HRD!!IQ,IB!!<!!HRD!!HRLSAP,$HRD!!HRD D@PBFRD!!HRD%HAHH@@LNHRD!!HRHXC0\AHRD!!HRD%HA(T
-') ; colorMapFromArray:#[45 45 45 56 56 56 66 66 66 70 70 70 72 72 72 76 76 76 89 89 89 92 92 92 93 93 93 103 103 103 110 110 110 111 111 111 112 112 112 121 121 121 147 147 147 150 150 150 165 165 165 169 169 169 176 176 176 181 181 181 186 186 186 192 192 192 197 197 197 198 198 198 199 199 199 200 200 200 204 204 204 206 206 206 209 209 209 212 212 212 216 216 216 222 222 222 224 224 224 226 226 226 229 229 229 231 231 231 233 233 233 235 235 235]; mask:((ImageMask new) width:9; height:10; bits:(ByteArray fromPackedString:'8G? _?A?<G?8_71?O''<??0??A?<b') ; yourself); yourself]
-!
-
-bottomRightImage
-    "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 bottomRightImage inspect
-     ImageEditor openOnClass:self andSelector:#bottomRightImage
-     Icon flushCachedIcons
-    "
-
-    <resource: #image>
-
-    ^Icon
-        constantNamed:'MacButtonBorder bottomRightImage'
-        ifAbsentPut:[(Depth8Image new) width:4; height:4; bits:(ByteArray fromPackedString:'@PDHBPDAA @HA T@A0P@@@@a') ; colorMapFromArray:#[184 184 184 255 255 255 226 226 226 224 224 224 181 181 181 162 162 162 211 211 211 158 158 158 248 248 248 159 159 159]; mask:((Depth1Image new) width:4; height:4; bits:(ByteArray fromPackedString:'<OC 0@@a') ; yourself); yourself]
-!
-
-bottomRightImage2
-    "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 bottomRightImage2 inspect
-     ImageEditor openOnClass:self andSelector:#bottomRightImage2
-     Icon flushCachedIcons
-    "
-
-    <resource: #image>
-
-    ^Icon
-        constantNamed:'MacButtonBorder bottomRightImage2'
-        ifAbsentPut:[(Depth8Image new) width:9; height:10; bits:(ByteArray fromPackedString:'CP4MCP4 F@4TCP4MCP4!!EP\VCP4MCP4]DP,[CP4MCP4\A!!@!!CP4MCR@KB!!(#CP4MI@0ED2HMCP4Y@ PPG04MC L@BQH^CP4M@P OE2DMCP4MEA$^H04MCP4M
-') ; colorMapFromArray:#[45 45 45 56 56 56 68 68 68 70 70 70 72 72 72 76 76 76 78 78 78 89 89 89 92 92 92 93 93 93 103 103 103 112 112 112 115 115 115 122 122 122 148 148 148 150 150 150 165 165 165 175 175 175 176 176 176 181 181 181 186 186 186 196 196 196 198 198 198 199 199 199 200 200 200 204 204 204 206 206 206 212 212 212 214 214 214 220 220 220 224 224 224 226 226 226 228 228 228 229 229 229 231 231 231 235 235 235 237 237 237]; mask:((ImageMask new) width:9; height:10; bits:(ByteArray fromPackedString:'A?<G?0_?A?<O?1=?O''?<_?!!?<G<b') ; yourself); yourself]
+        ifAbsentPut:[(Depth8Image width:9 height:10) bits:(ByteArray fromPackedString:'EP8WH"H"H"H"F@\VH"H"H"H"G 4R@RH"H"H"H1DFGRH"H"H"I!!0JB2@"H"H"@BPTA 0%H"H"@@@!!DPTCF"H"@@@@HQLI@PPO@@@@@BLYD@ B@@@@@@@&HQ,U
+') colorMapFromArray:#[0 0 0 45 45 45 56 56 56 66 66 66 70 70 70 72 72 72 76 76 76 89 89 89 92 92 92 93 93 93 103 103 103 110 110 110 111 111 111 112 112 112 121 121 121 147 147 147 150 150 150 165 165 165 169 169 169 176 176 176 181 181 181 186 186 186 192 192 192 197 197 197 198 198 198 199 199 199 200 200 200 204 204 204 206 206 206 209 209 209 212 212 212 216 216 216 222 222 222 224 224 224 226 226 226 229 229 229 231 231 231 233 233 233 235 235 235] mask:((ImageMask width:9 height:10) bits:(ByteArray fromPackedString:'8G? _>A?<G?8_71?O''<_?0??A?<b'); yourself); yourself]
 !
 
 topLeftImage
@@ -160,69 +103,27 @@
 
     ^Icon
         constantNamed:'MacButtonBorder topLeftImage'
-        ifAbsentPut:[(Depth8Image new) width:4; height:4; bits:(ByteArray fromPackedString:'@@@DA0@EA  @A DABP A@P@a') ; colorMapFromArray:#[184 184 184 255 255 255 226 226 226 224 224 224 181 181 181 162 162 162 211 211 211 158 158 158 248 248 248 159 159 159]; mask:((Depth1Image new) width:4; height:4; bits:(ByteArray fromPackedString:'LGC0<@@a') ; yourself); yourself]
-!
-
-topLeftImage2
-    "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."
+        ifAbsentPut:[(Depth8Image width:9 height:10) bits:(ByteArray fromPackedString:'@@@@@@@_G1@C@@@@@A<Q@P,T@@@@G0\DGQ8^@@@_BP _G!!8^@A<OA!!\^G!!8^G1,BD10^G!!8^G08LFQ8^G!!8^GPTRG!!8^G!!8^F@(VG!!8^G!!8^EP4ZG!!8^G!!8^
+') colorMapFromArray:#[0 0 0 91 91 91 102 102 102 104 104 104 109 109 109 110 110 110 115 115 115 117 117 117 118 118 118 119 119 119 121 121 121 123 123 123 139 139 139 143 143 143 146 146 146 153 153 153 155 155 155 158 158 158 169 169 169 174 174 174 187 187 187 191 191 191 192 192 192 199 199 199 203 203 203 204 204 204 207 207 207 217 217 217 219 219 219 221 221 221 224 224 224 229 229 229] mask:((ImageMask width:9 height:10) bits:(ByteArray fromPackedString:'A?<O?19?OG=8_?!!?<G? _>A?8G<b'); yourself); yourself]
+! !
 
-    "
-     self topLeftImage2 inspect
-     ImageEditor openOnClass:self andSelector:#topLeftImage2
-     Icon flushCachedIcons
-    "
+!MacButtonBorder methodsFor:'accessing'!
 
-    <resource: #image>
-
-    ^Icon
-        constantNamed:'MacButtonBorder topLeftImage2'
-        ifAbsentPut:[(Depth8Image new) width:9; height:10; bits:(ByteArray fromPackedString:'GQ4]GQ4]GP<BGQ4]GQ4P@@(SGQ4]GPXCGA4]GQ4]B@\^GQ4]GQ4NAQX]GQ4]GQ(AD!!,]GQ4]GP4KFA4]GQ4]G@PQGQ4]GQ4]E0$UGQ4]GQ4]E@0YGQ4]GQ4]
-') ; colorMapFromArray:#[91 91 91 102 102 102 104 104 104 109 109 109 110 110 110 115 115 115 117 117 117 118 118 118 119 119 119 121 121 121 123 123 123 139 139 139 143 143 143 146 146 146 153 153 153 155 155 155 158 158 158 169 169 169 174 174 174 187 187 187 191 191 191 192 192 192 199 199 199 203 203 203 204 204 204 207 207 207 217 217 217 219 219 219 221 221 221 224 224 224 229 229 229]; mask:((ImageMask new) width:9; height:10; bits:(ByteArray fromPackedString:'@_<G?09?GG<8_7!!?\G? _>A?8G<b') ; yourself); yourself]
+backgroundColor1:aColor
 !
 
-topRightImage
-    "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 topRightImage inspect
-     ImageEditor openOnClass:self andSelector:#topRightImage
-     Icon flushCachedIcons
-    "
-
-    <resource: #image>
-
-    ^Icon
-        constantNamed:'MacButtonBorder topRightImage'
-        ifAbsentPut:[(Depth8Image new) width:4; height:4; bits:(ByteArray fromPackedString:'A0P@@@ FAP@A@PX@@PDHBP@a') ; colorMapFromArray:#[184 184 184 255 255 255 226 226 226 224 224 224 181 181 181 162 162 162 211 211 211 158 158 158 248 248 248 159 159 159]; mask:((Depth1Image new) width:4; height:4; bits:(ByteArray fromPackedString:'0NC0<@@a') ; yourself); yourself]
+backgroundColor2:aColor
 !
 
-topRightImage2
-    "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."
+viewBackgroundColor
+    ^ viewBackgroundColor
+!
 
-    "
-     self topRightImage2 inspect
-     ImageEditor openOnClass:self andSelector:#topRightImage2
-     Icon flushCachedIcons
-    "
-
-    <resource: #image>
-
-    ^Icon
-        constantNamed:'MacButtonBorder topRightImage2'
-        ifAbsentPut:[(Depth8Image new) width:9; height:10; bits:(ByteArray fromPackedString:'B!!\@@@@@@@@@IPD[I @@@@@@@@@1B!!L@@@@@@@@@KPTI@@@@@@@@@@XI@@@@@@@@@@0QJBL@@@@@@@@HF"8@@@@@@@@@L08@@@@@@@@@IB$O@@@@@@@@GQ<%
-') ; colorMapFromArray:#[153 153 153 127 127 127 227 227 227 254 254 254 242 243 242 115 115 115 202 202 202 229 229 229 205 205 205 119 119 119 106 106 106 237 237 237 215 215 215 220 220 220 114 114 114 203 203 203 241 241 241 177 177 177 233 233 233 116 116 116 236 236 236 212 212 212 250 250 250 155 155 155 246 246 246 231 231 231 145 145 145 90 90 90 221 221 221 208 208 208 224 224 224 147 147 147 216 216 216 243 243 243 230 230 230 217 217 217 195 195 195 191 191 191 156 156 156 245 245 245 108 108 108 126 126 126 235 235 235 240 240 240 247 247 247 223 223 223 148 148 148 228 228 228 226 225 225 222 222 222 249 249 249 174 174 174]; mask:((ImageMask new) width:9; height:10; bits:(ByteArray fromPackedString:'0G?0_3!!?GG<N_0=?A7<C_0O?@?<b') ; yourself); yourself]
+viewBackgroundColor:aColor
+    viewBackgroundColor ~= aColor ifTrue:[
+        viewBackgroundColor := aColor.
+        topLeftEdge := topRightEdge := bottomLeftEdge := bottomRightEdge := nil.
+    ].
 ! !
 
 !MacButtonBorder methodsFor:'displaying'!
@@ -231,7 +132,7 @@
     "display the borders represented by the receiver in the specified rectangle.
      The gc is restored after the draw."
 
-    |left right top bottom savedPaint|
+    |left right top bottom savedPaint lw th rw bh|
 
     left := aRectangle left.
     right := aRectangle right.
@@ -240,35 +141,61 @@
 
     savedPaint := aGC paint.
 
-    TopLeftEdge displayOn:aGC x:left y:top.
-    aGC paint:(Color redByte:104 greenByte:104 blueByte:104).
-    aGC displayLineFromX:left+(TopLeftEdge width) y:top toX:right-(TopRightEdge width) y:top.
-    aGC paint:(Color redByte:186 greenByte:186 blueByte:186).
-    aGC displayLineFromX:left+(TopLeftEdge width) y:top+1 toX:right-(TopRightEdge width) y:top+1.
+    topLeftEdge isNil ifTrue:[
+        self initializeImages
+    ].
+    
+    lw := topLeftEdge width.
+    rw := topRightEdge width.
+    th := topLeftEdge height.
+    bh := bottomLeftEdge height.
+    
+    aGC paint:(aGC viewBackground).
+    aGC fillRectangleX:left y:top width:5 height:5.
+    aGC fillRectangleX:right-5 y:top width:5 height:5.
+    aGC fillRectangleX:right-5 y:bottom-5 width:5 height:5.
+    aGC fillRectangleX:left y:bottom-5 width:5 height:5.
 
-    TopRightEdge displayOn:aGC x:(right-TopRightEdge width) y:top.
-    aGC paint:(Color redByte:208 greenByte:208 blueByte:208).
-    aGC displayLineFromX:right-3 y:(top+TopRightEdge height) toX:right-3 y:(bottom-BottomRightEdge height).
-    aGC paint:(Color redByte:147 greenByte:147 blueByte:147).
-    aGC displayLineFromX:right-2 y:(top+TopRightEdge height) toX:right-2 y:(bottom-BottomRightEdge height).
-    aGC paint:(Color redByte:191 greenByte:191 blueByte:191).
-    aGC displayLineFromX:right-1 y:(top+TopRightEdge height) toX:right-1 y:(bottom-BottomRightEdge height).
+    topLeftEdge displayOn:aGC x:left y:top.
+    aGC paint:(Color redByte:104 greenByte:104 blueByte:104).
+    aGC displayLineFromX:left+lw y:top toX:right-rw y:top.
+    aGC paint:(Color redByte:186 greenByte:186 blueByte:186).
+    aGC displayLineFromX:left+lw y:top+1 toX:right-rw y:top+1.
 
-    BottomLeftEdge displayOn:aGC x:left y:(bottom-BottomLeftEdge height).
+    topRightEdge displayOn:aGC x:(right-rw) y:top.
+    aGC paint:(Color redByte:208 greenByte:208 blueByte:208).
+    aGC displayLineFromX:right-3 y:(top+th) toX:right-3 y:(bottom-bh).
+    aGC paint:(Color redByte:147 greenByte:147 blueByte:147).
+    aGC displayLineFromX:right-2 y:(top+th) toX:right-2 y:(bottom-bh).
+    aGC paint:(Color redByte:191 greenByte:191 blueByte:191).
+    aGC displayLineFromX:right-1 y:(top+th) toX:right-1 y:(bottom-bh).
+
+    bottomLeftEdge displayOn:aGC x:left y:(bottom-bh).
     aGC paint:(Color redByte:148 greenByte:148 blueByte:148).
-    aGC displayLineFromX:left+(BottomLeftEdge width) y:bottom-1-2 toX:right-(BottomRightEdge width) y:bottom-1-2.
+    aGC displayLineFromX:left+lw y:bottom-1-2 toX:right-rw y:bottom-1-2.
     aGC paint:(Color redByte:56 greenByte:56 blueByte:56).
-    aGC displayLineFromX:left+(BottomLeftEdge width) y:bottom-1-1 toX:right-(BottomRightEdge width) y:bottom-1-1.
+    aGC displayLineFromX:left+lw y:bottom-1-1 toX:right-rw y:bottom-1-1.
     aGC paint:(Color redByte:186 greenByte:186 blueByte:186).
-    aGC displayLineFromX:left+(BottomLeftEdge width) y:bottom-1 toX:right-(BottomRightEdge width) y:bottom-1.
+    aGC displayLineFromX:left+lw y:bottom-1 toX:right-rw y:bottom-1.
 
-    BottomRightEdge displayOn:aGC x:(right-BottomRightEdge width) y:(bottom-BottomRightEdge height).
+    bottomRightEdge displayOn:aGC x:(right-rw) y:(bottom-bh).
     aGC paint:(Color redByte:186 greenByte:186 blueByte:186).
-    aGC displayLineFromX:left y:(top+TopLeftEdge height) toX:left y:(bottom-BottomLeftEdge height).
+    aGC displayLineFromX:left y:(top+th) toX:left y:(bottom-bh).
     aGC paint:(Color redByte:121 greenByte:121 blueByte:121).
-    aGC displayLineFromX:left+1 y:(top+TopLeftEdge height) toX:left+1 y:(bottom-BottomLeftEdge height).
+    aGC displayLineFromX:left+1 y:(top+th) toX:left+1 y:(bottom-bh).
 
     aGC paint:savedPaint.
+!
+
+initializeImages
+    TopLeftEdge isNil ifTrue:[
+        self class initializeImages
+    ].
+    
+    topLeftEdge := TopLeftEdge copy.
+    topRightEdge := TopRightEdge copy.
+    bottomLeftEdge := BottomLeftEdge copy.
+    bottomRightEdge := BottomRightEdge copy.
 ! !
 
 !MacButtonBorder methodsFor:'queries'!