author | Claus Gittinger <cg@exept.de> |
Fri, 03 Feb 2017 16:57:58 +0100 | |
changeset 7835 | 019761925559 |
parent 7040 | 9de35e2b291f |
child 7938 | 6b2cbf0d7e12 |
permissions | -rw-r--r-- |
6942 | 1 |
"{ Package: 'stx:libview' }" |
2 |
||
3 |
"{ NameSpace: Smalltalk }" |
|
4 |
||
5 |
SimpleBorder subclass:#MacFlatButtonBorder |
|
6965 | 6 |
instanceVariableNames:'backgroundColor1 backgroundColor2 imgTopLeft imgTopRight |
7 |
imgBottomLeft imgBottomRight' |
|
7835 | 8 |
classVariableNames:'CachedImagesPerColors' |
6942 | 9 |
poolDictionaries:'' |
10 |
category:'Graphics-Support' |
|
11 |
! |
|
12 |
||
6943 | 13 |
!MacFlatButtonBorder class methodsFor:'documentation'! |
14 |
||
15 |
documentation |
|
16 |
" |
|
17 |
an as yet unused and unfinished attempt to provide a mac-osx like |
|
18 |
button border. These will look like mac buttons in yosemite (i.e. ugly old 70s retro flat style). |
|
19 |
To be continued. |
|
20 |
" |
|
21 |
! ! |
|
6942 | 22 |
|
23 |
!MacFlatButtonBorder class methodsFor:'instance creation'! |
|
24 |
||
6965 | 25 |
color:color1 backgroundColor:color2 |
26 |
"create a new instance of the receiver with a border of the given color." |
|
27 |
||
28 |
^ self new color:color1; backgroundColor:color2 |
|
29 |
! |
|
30 |
||
6942 | 31 |
color:color1 insideColor:color2 |
32 |
"create a new instance of the receiver with a border of the given color." |
|
33 |
||
34 |
^ self new color:color1; insideColor:color2 |
|
35 |
! ! |
|
36 |
||
37 |
!MacFlatButtonBorder class methodsFor:'image specs'! |
|
38 |
||
39 |
topLeftImageFilled |
|
40 |
"This resource specification was automatically generated |
|
41 |
by the ImageEditor of ST/X." |
|
42 |
||
43 |
"Do not manually edit this!! If it is corrupted, |
|
44 |
the ImageEditor may not be able to read the specification." |
|
45 |
||
46 |
" |
|
47 |
self topLeftImageFilled inspect |
|
48 |
ImageEditor openOnClass:self andSelector:#topLeftImageFilled |
|
49 |
Icon flushCachedIcons |
|
50 |
" |
|
51 |
||
52 |
<resource: #image> |
|
53 |
||
54 |
^Icon |
|
55 |
constantNamed:'MacOSXRoundButtonBorder topLeftImageFilled' |
|
56 |
ifAbsentPut:[(Depth8Image width:4 height:4) bits:(ByteArray fromPackedString:'@@LB@PLA@P@B@P@@@P@@@@@a') colorMapFromArray:#[44 132 251 49 107 245 95 142 236 175 196 234] mask:((ImageMask width:4 height:4) bits:(ByteArray fromPackedString:'\OC0<@@a'); yourself); yourself] |
|
57 |
! |
|
58 |
||
59 |
topLeftImageUnfilled |
|
60 |
"This resource specification was automatically generated |
|
61 |
by the ImageEditor of ST/X." |
|
62 |
||
63 |
"Do not manually edit this!! If it is corrupted, |
|
64 |
the ImageEditor may not be able to read the specification." |
|
65 |
||
66 |
" |
|
67 |
self topLeftImageUnfilled inspect |
|
68 |
ImageEditor openOnClass:self andSelector:#topLeftImageUnfilled |
|
69 |
Icon flushCachedIcons |
|
70 |
" |
|
71 |
||
72 |
<resource: #image> |
|
73 |
||
74 |
^Icon |
|
75 |
constantNamed:'MacOSXRoundButtonBorder topLeftImageUnfilled' |
|
76 |
ifAbsentPut:[(Depth2Image width:4 height:4) bits:(ByteArray fromPackedString:'9HMOO0@a') colorMapFromArray:#[183 183 183 201 201 201 224 224 224 255 255 255] mask:((ImageMask width:4 height:4) bits:(ByteArray fromPackedString:'\OC0<@@a'); yourself); yourself] |
|
77 |
! |
|
78 |
||
79 |
topLeftImageUnfilledMasked |
|
80 |
"This resource specification was automatically generated |
|
81 |
by the ImageEditor of ST/X." |
|
82 |
||
83 |
"Do not manually edit this!! If it is corrupted, |
|
84 |
the ImageEditor may not be able to read the specification." |
|
85 |
||
86 |
" |
|
87 |
self topLeftImageUnfilledMasked inspect |
|
88 |
ImageEditor openOnClass:self andSelector:#topLeftImageUnfilledMasked |
|
89 |
Icon flushCachedIcons |
|
90 |
" |
|
91 |
||
92 |
<resource: #image> |
|
93 |
||
94 |
^Icon |
|
95 |
constantNamed:'MacOSXRoundButtonBorder topLeftImageUnfilledMasked' |
|
96 |
ifAbsentPut:[(Depth2Image width:4 height:4) bits:(ByteArray fromPackedString:'IHA@@@@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] |
|
97 |
! |
|
98 |
||
99 |
topLeftImageUnfilledMasked2 |
|
100 |
"This resource specification was automatically generated |
|
101 |
by the ImageEditor of ST/X." |
|
102 |
||
103 |
"Do not manually edit this!! If it is corrupted, |
|
104 |
the ImageEditor may not be able to read the specification." |
|
105 |
||
106 |
" |
|
107 |
self topLeftImageUnfilledMasked2 inspect |
|
108 |
ImageEditor openOnClass:self andSelector:#topLeftImageUnfilledMasked2 |
|
109 |
Icon flushCachedIcons |
|
110 |
" |
|
111 |
||
112 |
<resource: #image> |
|
113 |
||
114 |
^Icon |
|
115 |
constantNamed:'MacOSXRoundButtonBorder topLeftImageUnfilledMasked2' |
|
116 |
ifAbsentPut:[(Depth2Image width:4 height:4) bits:(ByteArray fromPackedString:'IH!! @@@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] |
|
117 |
! |
|
118 |
||
119 |
topLeftImageUnfilledMasked3 |
|
120 |
"This resource specification was automatically generated |
|
121 |
by the ImageEditor of ST/X." |
|
122 |
||
123 |
"Do not manually edit this!! If it is corrupted, |
|
124 |
the ImageEditor may not be able to read the specification." |
|
125 |
||
126 |
" |
|
127 |
self topLeftImageUnfilledMasked3 inspect |
|
128 |
ImageEditor openOnClass:self andSelector:#topLeftImageUnfilledMasked3 |
|
129 |
Icon flushCachedIcons |
|
130 |
" |
|
131 |
||
132 |
<resource: #image> |
|
133 |
||
134 |
^Icon |
|
135 |
constantNamed:'MacOSXRoundButtonBorder topLeftImageUnfilledMasked3' |
|
136 |
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] |
|
6965 | 137 |
! |
138 |
||
139 |
topLeftImageUnfilledMasked4 |
|
140 |
"This resource specification was automatically generated |
|
141 |
by the ImageEditor of ST/X." |
|
142 |
||
143 |
"Do not manually edit this!! If it is corrupted, |
|
144 |
the ImageEditor may not be able to read the specification." |
|
145 |
||
146 |
" |
|
147 |
self topLeftImageUnfilledMasked4 inspect |
|
148 |
ImageEditor openOnClass:self andSelector:#topLeftImageUnfilledMasked4 |
|
149 |
Icon flushCachedIcons |
|
150 |
" |
|
151 |
||
152 |
<resource: #image> |
|
153 |
||
154 |
^Icon |
|
155 |
constantNamed:'MacFlatButtonBorder topLeftImageUnfilledMasked4' |
|
6973 | 156 |
ifAbsentPut:[(Depth2Image width:4 height:4) bits:(ByteArray fromPackedString:'HH,/O0@a') colorMapFromArray:#[183 183 183 201 201 201 224 224 224 255 255 255] mask:((ImageMask width:4 height:4) bits:(ByteArray fromPackedString:'\OC0<@@a'); yourself); yourself] |
6982 | 157 |
! |
158 |
||
159 |
topLeftImageUnfilledMasked5 |
|
160 |
"This resource specification was automatically generated |
|
161 |
by the ImageEditor of ST/X." |
|
162 |
||
163 |
"Do not manually edit this!! If it is corrupted, |
|
164 |
the ImageEditor may not be able to read the specification." |
|
165 |
||
166 |
" |
|
167 |
self topLeftImageUnfilledMasked5 inspect |
|
168 |
ImageEditor openOnClass:self andSelector:#topLeftImageUnfilledMasked5 |
|
169 |
Icon flushCachedIcons |
|
170 |
" |
|
171 |
||
172 |
<resource: #image> |
|
173 |
||
174 |
^Icon |
|
175 |
constantNamed:'MacFlatButtonBorder topLeftImageUnfilledMasked5' |
|
176 |
ifAbsentPut:[(Depth2Image width:4 height:4) bits:(ByteArray fromPackedString:'HH<?O0@a') colorMapFromArray:#[183 183 183 201 201 201 224 224 224 255 255 255] mask:((ImageMask width:4 height:4) bits:(ByteArray fromPackedString:'\OC0<@@a'); yourself); yourself] |
|
6985
d5f5ff0cae1a
viewbackground from container
Claus Gittinger <cg@exept.de>
parents:
6982
diff
changeset
|
177 |
! |
d5f5ff0cae1a
viewbackground from container
Claus Gittinger <cg@exept.de>
parents:
6982
diff
changeset
|
178 |
|
d5f5ff0cae1a
viewbackground from container
Claus Gittinger <cg@exept.de>
parents:
6982
diff
changeset
|
179 |
topLeftImageUnfilledMasked6 |
d5f5ff0cae1a
viewbackground from container
Claus Gittinger <cg@exept.de>
parents:
6982
diff
changeset
|
180 |
"This resource specification was automatically generated |
d5f5ff0cae1a
viewbackground from container
Claus Gittinger <cg@exept.de>
parents:
6982
diff
changeset
|
181 |
by the ImageEditor of ST/X." |
d5f5ff0cae1a
viewbackground from container
Claus Gittinger <cg@exept.de>
parents:
6982
diff
changeset
|
182 |
|
d5f5ff0cae1a
viewbackground from container
Claus Gittinger <cg@exept.de>
parents:
6982
diff
changeset
|
183 |
"Do not manually edit this!! If it is corrupted, |
d5f5ff0cae1a
viewbackground from container
Claus Gittinger <cg@exept.de>
parents:
6982
diff
changeset
|
184 |
the ImageEditor may not be able to read the specification." |
d5f5ff0cae1a
viewbackground from container
Claus Gittinger <cg@exept.de>
parents:
6982
diff
changeset
|
185 |
|
d5f5ff0cae1a
viewbackground from container
Claus Gittinger <cg@exept.de>
parents:
6982
diff
changeset
|
186 |
" |
d5f5ff0cae1a
viewbackground from container
Claus Gittinger <cg@exept.de>
parents:
6982
diff
changeset
|
187 |
self topLeftImageUnfilledMasked6 inspect |
d5f5ff0cae1a
viewbackground from container
Claus Gittinger <cg@exept.de>
parents:
6982
diff
changeset
|
188 |
ImageEditor openOnClass:self andSelector:#topLeftImageUnfilledMasked6 |
d5f5ff0cae1a
viewbackground from container
Claus Gittinger <cg@exept.de>
parents:
6982
diff
changeset
|
189 |
Icon flushCachedIcons |
d5f5ff0cae1a
viewbackground from container
Claus Gittinger <cg@exept.de>
parents:
6982
diff
changeset
|
190 |
" |
d5f5ff0cae1a
viewbackground from container
Claus Gittinger <cg@exept.de>
parents:
6982
diff
changeset
|
191 |
|
d5f5ff0cae1a
viewbackground from container
Claus Gittinger <cg@exept.de>
parents:
6982
diff
changeset
|
192 |
<resource: #image> |
d5f5ff0cae1a
viewbackground from container
Claus Gittinger <cg@exept.de>
parents:
6982
diff
changeset
|
193 |
|
d5f5ff0cae1a
viewbackground from container
Claus Gittinger <cg@exept.de>
parents:
6982
diff
changeset
|
194 |
^Icon |
d5f5ff0cae1a
viewbackground from container
Claus Gittinger <cg@exept.de>
parents:
6982
diff
changeset
|
195 |
constantNamed:'MacFlatButtonBorder topLeftImageUnfilledMasked6' |
d5f5ff0cae1a
viewbackground from container
Claus Gittinger <cg@exept.de>
parents:
6982
diff
changeset
|
196 |
ifAbsentPut:[(Depth2Image width:4 height:4) bits:(ByteArray fromPackedString:'@@<?O0@a') colorMapFromArray:#[183 183 183 201 201 201 224 224 224 255 255 255] mask:((ImageMask width:4 height:4) bits:(ByteArray fromPackedString:'LGC0<@@a'); yourself); yourself] |
6942 | 197 |
! ! |
198 |
||
199 |
!MacFlatButtonBorder methodsFor:'accessing'! |
|
200 |
||
6965 | 201 |
backgroundColor1 |
202 |
"the first gradient color" |
|
203 |
||
204 |
^ backgroundColor1 |
|
205 |
! |
|
206 |
||
6976 | 207 |
backgroundColor1:newColor |
6965 | 208 |
"the first gradient color" |
209 |
||
6976 | 210 |
backgroundColor1 ~= newColor ifTrue:[ |
211 |
backgroundColor1 := newColor. |
|
7835 | 212 |
"/ flush cached images |
6976 | 213 |
imgTopLeft := imgTopRight := imgBottomLeft := imgBottomRight := nil. |
214 |
] |
|
7835 | 215 |
|
216 |
"Modified (comment): / 03-02-2017 / 16:43:49 / cg" |
|
6965 | 217 |
! |
218 |
||
219 |
backgroundColor2 |
|
220 |
"the second gradient color" |
|
221 |
||
222 |
^ backgroundColor2 |
|
223 |
! |
|
224 |
||
6976 | 225 |
backgroundColor2:newColor |
6965 | 226 |
"the second gradient color" |
227 |
||
6976 | 228 |
backgroundColor2 ~= newColor ifTrue:[ |
229 |
backgroundColor2 := newColor. |
|
7835 | 230 |
"/ flush cached images |
6976 | 231 |
imgTopLeft := imgTopRight := imgBottomLeft := imgBottomRight := nil. |
232 |
] |
|
7835 | 233 |
|
234 |
"Modified (comment): / 03-02-2017 / 16:43:53 / cg" |
|
6965 | 235 |
! |
236 |
||
6942 | 237 |
color:newColor |
6965 | 238 |
"the color of the border" |
239 |
||
6942 | 240 |
color ~= newColor ifTrue:[ |
241 |
color := newColor. |
|
242 |
imgTopLeft := imgTopRight := imgBottomLeft := imgBottomRight := nil. |
|
243 |
]. |
|
244 |
! ! |
|
245 |
||
246 |
!MacFlatButtonBorder methodsFor:'displaying'! |
|
247 |
||
248 |
displayOn:aGC forDisplayBox:aRectangle |
|
249 |
|oldPaint boxLeft boxRight boxTop boxBottom boxWidth boxHeight| |
|
250 |
||
251 |
color isNil ifTrue:[ ^ self]. |
|
252 |
||
253 |
oldPaint := aGC paint. |
|
254 |
||
255 |
boxLeft := aRectangle left. |
|
256 |
boxTop := aRectangle top. |
|
257 |
boxWidth := aRectangle width. |
|
258 |
boxHeight := aRectangle height. |
|
259 |
||
260 |
boxRight := boxLeft + boxWidth. |
|
261 |
boxBottom := boxTop + boxHeight. |
|
262 |
||
263 |
imgTopLeft isNil ifTrue:[ |
|
264 |
self makeImages. |
|
6965 | 265 |
imgTopLeft isNil ifTrue:[ |
266 |
^ self |
|
267 |
]. |
|
6942 | 268 |
]. |
7040 | 269 |
aGC container isNil ifTrue:[ |
270 |
aGC paint:(aGC viewBackground). |
|
271 |
] ifFalse:[ |
|
272 |
aGC paint:(aGC container viewBackground). |
|
273 |
]. |
|
6973 | 274 |
aGC fillRectangleX:boxLeft y:boxTop width:2 height:2. |
275 |
aGC fillRectangleX:boxRight-2 y:boxTop width:2 height:2. |
|
276 |
aGC fillRectangleX:boxRight-2 y:boxBottom-2 width:2 height:2. |
|
277 |
aGC fillRectangleX:boxLeft y:boxBottom-2 width:2 height:2. |
|
6965 | 278 |
|
6942 | 279 |
aGC displayImage:imgTopLeft x:boxLeft y:boxTop. |
280 |
aGC displayImage:imgTopRight x:boxRight-4 y:boxTop. |
|
281 |
aGC displayImage:imgBottomRight x:boxRight-4 y:boxBottom-4. |
|
282 |
aGC displayImage:imgBottomLeft x:boxLeft y:boxBottom-4. |
|
283 |
||
6965 | 284 |
aGC paint:color. |
6942 | 285 |
aGC displayLineFromX:boxLeft+4 y:boxTop toX:boxRight-4 y:boxTop. |
286 |
aGC displayLineFromX:boxLeft+4 y:boxBottom-1 toX:boxRight-4 y:boxBottom-1. |
|
287 |
aGC displayLineFromX:boxLeft y:boxTop+4 toX:boxLeft y:boxBottom-4. |
|
288 |
aGC displayLineFromX:boxRight-1 y:boxTop+4 toX:boxRight-1 y:boxBottom-4. |
|
289 |
||
290 |
aGC paint:oldPaint. |
|
291 |
||
292 |
" |
|
293 |
|v1 v2| |
|
294 |
||
295 |
v1 := TopView new. |
|
296 |
v2 := View origin:10@10 corner:100@30 in:v1. |
|
6965 | 297 |
v2 border:(MacFlatButtonBorder color:Color red). |
6942 | 298 |
v1 open. |
299 |
" |
|
300 |
" |
|
301 |
|v1 v2| |
|
302 |
||
303 |
v1 := TopView new. |
|
304 |
v2 := View origin:10@10 corner:100@30 in:v1. |
|
6965 | 305 |
v2 border:((MacFlatButtonBorder color:Color red) backgroundColor1:Color blue; backgroundColor2:Color green). |
6942 | 306 |
v1 open. |
307 |
" |
|
308 |
! ! |
|
309 |
||
310 |
!MacFlatButtonBorder methodsFor:'private'! |
|
311 |
||
312 |
makeImages |
|
7835 | 313 |
|cachedImages protoImage img hue light sat| |
314 |
||
315 |
CachedImagesPerColors isNil ifTrue:[ |
|
316 |
CachedImagesPerColors := OrderedDictionary new. |
|
317 |
]. |
|
318 |
cachedImages := CachedImagesPerColors at:{color . backgroundColor1 . backgroundColor2} ifAbsent:nil. |
|
319 |
cachedImages notNil ifTrue:[ |
|
320 |
imgTopLeft := cachedImages at:1. |
|
321 |
imgTopRight := cachedImages at:2. |
|
322 |
imgBottomLeft := cachedImages at:3. |
|
323 |
imgBottomRight := cachedImages at:4. |
|
324 |
^ self. |
|
325 |
]. |
|
6942 | 326 |
|
327 |
hue := color hue. |
|
328 |
light := color light. |
|
329 |
sat := color saturation. |
|
330 |
||
6985
d5f5ff0cae1a
viewbackground from container
Claus Gittinger <cg@exept.de>
parents:
6982
diff
changeset
|
331 |
protoImage := self class topLeftImageUnfilledMasked6. |
6942 | 332 |
img := protoImage copy. |
333 |
||
6965 | 334 |
img colorMap at:1 put:color. |
335 |
hue notNil ifTrue:[ |
|
6942 | 336 |
img colorMap at:2 put:(Color hue:hue light:light+15 saturation:sat-12). |
337 |
img colorMap at:3 put:(Color hue:hue light:light+30 saturation:sat-40). |
|
338 |
]. |
|
339 |
imgTopLeft := img. |
|
340 |
imgTopRight := img rotated:90. |
|
341 |
imgBottomLeft := img rotated:-90. |
|
342 |
imgBottomRight := img rotated:180. |
|
6965 | 343 |
|
344 |
backgroundColor1 notNil ifTrue:[ |
|
345 |
imgTopLeft colorMap at:4 put:backgroundColor1. |
|
346 |
imgTopRight colorMap at:4 put:backgroundColor1. |
|
347 |
]. |
|
348 |
backgroundColor2 notNil ifTrue:[ |
|
349 |
imgBottomLeft colorMap at:4 put:backgroundColor2. |
|
350 |
imgBottomRight colorMap at:4 put:backgroundColor2. |
|
351 |
]. |
|
6976 | 352 |
|
353 |
"/ imgBottomRight colorMap at:1 put:color darkened. |
|
354 |
"/ imgBottomRight colorMap at:2 put:color slightlyDarkened. |
|
7835 | 355 |
"/ imgBottomRight colorMap at:3 put:color slightlyDarkened. |
356 |
||
357 |
CachedImagesPerColors |
|
358 |
at:{color . backgroundColor1 . backgroundColor2} |
|
359 |
put:{imgTopLeft. imgTopRight. imgBottomLeft . imgBottomRight}. |
|
360 |
||
361 |
CachedImagesPerColors size > 20 ifTrue:[ |
|
362 |
CachedImagesPerColors removeFirst |
|
363 |
]. |
|
364 |
||
365 |
"Modified: / 03-02-2017 / 16:49:48 / cg" |
|
6942 | 366 |
! ! |
367 |
||
368 |
!MacFlatButtonBorder class methodsFor:'documentation'! |
|
369 |
||
370 |
version |
|
371 |
^ '$Header$' |
|
372 |
! |
|
373 |
||
374 |
version_CVS |
|
375 |
^ '$Header$' |
|
376 |
! ! |
|
377 |