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