author | ca |
Tue, 08 Oct 2002 08:35:50 +0200 | |
changeset 2254 | ebd685bcba77 |
parent 2186 | 05b16a66bb3d |
child 2497 | 0beadb2a951c |
permissions | -rw-r--r-- |
422 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by 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 |
" |
|
12 |
||
13 |
||
14 |
||
1803 | 15 |
"{ Package: 'stx:libtool2' }" |
16 |
||
412 | 17 |
MenuPanel subclass:#ColorMenu |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
18 |
instanceVariableNames:'enabledChannel labelsAreColored' |
666 | 19 |
classVariableNames:'' |
412 | 20 |
poolDictionaries:'' |
21 |
category:'Interface-UIPainter' |
|
22 |
! |
|
23 |
||
1057 | 24 |
SimpleDialog subclass:#DefineColor |
2045 | 25 |
instanceVariableNames:'red green blue hue light saturation colorNameHolder' |
1057 | 26 |
classVariableNames:'' |
27 |
poolDictionaries:'' |
|
28 |
privateIn:ColorMenu |
|
29 |
! |
|
30 |
||
412 | 31 |
!ColorMenu class methodsFor:'documentation'! |
32 |
||
422 | 33 |
copyright |
34 |
" |
|
35 |
COPYRIGHT (c) 1995 by eXept Software AG |
|
36 |
All Rights Reserved |
|
37 |
||
38 |
This software is furnished under a license and may be used |
|
39 |
only in accordance with the terms of that license and with the |
|
40 |
inclusion of the above copyright notice. This software may not |
|
41 |
be provided or otherwise made available to, or used by, any |
|
42 |
other person. No title to or ownership of the software is |
|
43 |
hereby transferred. |
|
44 |
" |
|
45 |
||
46 |
||
47 |
! |
|
48 |
||
412 | 49 |
documentation |
50 |
" |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
51 |
A simple ColorMenu used by the UIPainter |
412 | 52 |
|
53 |
[see also:] |
|
54 |
UIPainter |
|
55 |
ColorMenuSpec |
|
422 | 56 |
|
57 |
[author:] |
|
58 |
Claus Atzkern |
|
412 | 59 |
" |
60 |
! |
|
61 |
||
62 |
examples |
|
63 |
" |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
64 |
very simple example |
412 | 65 |
[exBegin] |
66 |
|tool top channel| |
|
67 |
||
68 |
top := StandardSystemView new. |
|
69 |
top extent:250@30. |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
70 |
|
412 | 71 |
channel := (Color red) asValue. |
72 |
tool := self origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
73 |
tool model:channel. |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
74 |
|
412 | 75 |
top open. |
76 |
[exEnd] |
|
77 |
" |
|
78 |
! ! |
|
79 |
||
80 |
!ColorMenu class methodsFor:'menu spec'! |
|
81 |
||
666 | 82 |
colorDefinition |
83 |
"color definitions used to build a color menu |
|
412 | 84 |
" |
583 | 85 |
|
666 | 86 |
^ #( |
668 | 87 |
#( gray |
666 | 88 |
gray: |
89 |
#( white |
|
90 |
veryLightGray |
|
91 |
lightGray |
|
92 |
gray |
|
93 |
darkGray |
|
94 |
veryDarkGray |
|
95 |
black |
|
96 |
) |
|
412 | 97 |
) |
666 | 98 |
|
668 | 99 |
#( red |
666 | 100 |
red: |
854 | 101 |
#( lightened 100 87 67 50 33) |
666 | 102 |
) |
103 |
||
668 | 104 |
#( green |
666 | 105 |
green: |
854 | 106 |
#( lightened 100 87 67 50 33) |
666 | 107 |
) |
108 |
||
668 | 109 |
#( blue |
666 | 110 |
blue: |
854 | 111 |
#( lightened 100 87 67 50 33) |
666 | 112 |
) |
113 |
||
668 | 114 |
#( cyan |
854 | 115 |
cyan: |
116 |
#( lightened 100 87 67 50 33) |
|
664 | 117 |
) |
666 | 118 |
|
668 | 119 |
#( magenta |
854 | 120 |
magenta: |
121 |
#( lightened 100 87 67 50 33) |
|
412 | 122 |
) |
666 | 123 |
|
668 | 124 |
#( yellow |
854 | 125 |
yellow: |
126 |
#( lightened 100 87 67 50 33) |
|
412 | 127 |
) |
806 | 128 |
|
412 | 129 |
) |
666 | 130 |
! |
131 |
||
132 |
colorMenu:labelAreColored value:aValue |
|
133 |
"returns a color menu |
|
134 |
" |
|
1410 | 135 |
|menu mainCol style e| |
666 | 136 |
|
137 |
menu := Menu new. |
|
1372
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
138 |
style := (labelAreColored == false) |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
139 |
ifTrue:[#backgroundColor] |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
140 |
ifFalse:[#color]. |
666 | 141 |
|
142 |
self colorDefinition do:[:aSlice| |
|
143 |
|size colOp color item smenu| |
|
144 |
||
668 | 145 |
mainCol := Color perform:(aSlice at:1). |
146 |
item := MenuItem labeled:(Text string:' ' emphasis:(#backgroundColor->mainCol)). |
|
666 | 147 |
smenu := Menu new. |
668 | 148 |
colOp := aSlice at:2. |
412 | 149 |
|
668 | 150 |
(aSlice at:3) do:[:el||sitem label| |
666 | 151 |
el isSymbol ifTrue:[ |
152 |
color := el == #lightened ifTrue:[mainCol perform:el] ifFalse:[Color perform:el]. |
|
854 | 153 |
self colorDefinition first ~~ aSlice |
154 |
ifTrue: [label := (colOp upTo: $:), ' ', el] |
|
155 |
ifFalse:[label := el]. |
|
666 | 156 |
] ifFalse:[ |
157 |
el isNumber ifTrue:[ |
|
158 |
color := Color perform:colOp with:el. |
|
159 |
label := colOp, ' ', el printString. |
|
160 |
] ifFalse:[ |
|
161 |
color := Color perform:colOp with:(el at:1) with:(el at:2) with:(el at:3). |
|
162 |
label := ''. |
|
163 |
colOp keywords keysAndValuesDo:[:i :c| label := label, ' ', c, ' ' , (el at:i) printString ]. |
|
164 |
] |
|
165 |
]. |
|
1372
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
166 |
e := style->color. |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
167 |
style == #backgroundColor ifTrue:[ |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
168 |
color brightness < 0.5 ifTrue:[ |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
169 |
e := Array with:e |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
170 |
with:(#color->Color white) |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
171 |
] |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
172 |
]. |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
173 |
sitem := MenuItem |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
174 |
labeled:(Text |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
175 |
string:('Color ', label) |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
176 |
emphasis:e). |
666 | 177 |
sitem argument:color. |
178 |
sitem value:aValue. |
|
179 |
smenu addItem:sitem. |
|
180 |
]. |
|
181 |
item submenu:smenu. |
|
182 |
item value:nil. |
|
183 |
menu addItem:item |
|
184 |
]. |
|
185 |
^ menu |
|
186 |
" |
|
187 |
(ColorMenu colorMenu:true value:nil) startUp |
|
188 |
(ColorMenu colorMenu:false value:#aSelector:) startUp |
|
189 |
" |
|
592 | 190 |
! ! |
191 |
||
1808 | 192 |
!ColorMenu methodsFor:'accepting'! |
412 | 193 |
|
194 |
accept:anItem |
|
664 | 195 |
"accept current selected item" |
196 |
||
412 | 197 |
|item holder color| |
198 |
||
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
199 |
((item := super accept:anItem) notNil and: [item nameKey ~~ #def]) |
664 | 200 |
ifTrue: |
201 |
[ |
|
202 |
(holder := self colorHolder) == item ifTrue: |
|
203 |
[ |
|
412 | 204 |
enabledChannel value ifTrue:[color := self color] |
664 | 205 |
] |
206 |
ifFalse: |
|
1057 | 207 |
[ |
666 | 208 |
color := item argument. |
692 | 209 |
holder label:(Text string:' ' emphasis:(#backgroundColor->color)). |
412 | 210 |
]. |
211 |
model notNil ifTrue:[model value:color] |
|
212 |
] |
|
213 |
! ! |
|
214 |
||
215 |
!ColorMenu methodsFor:'accessing'! |
|
216 |
||
217 |
color |
|
664 | 218 |
"get current color" |
219 |
||
220 |
|firstEmphasis| |
|
221 |
(firstEmphasis := (self colorHolder label emphasis at:1)) isAssociation ifTrue: [^firstEmphasis value]. |
|
222 |
^(firstEmphasis at: 1) value |
|
412 | 223 |
! |
224 |
||
225 |
color:aColor |
|
664 | 226 |
"set current color" |
227 |
||
412 | 228 |
|holder label| |
229 |
||
2184 | 230 |
aColor isColor ifFalse:[ |
412 | 231 |
enabledChannel value:false |
2184 | 232 |
] ifTrue:[ |
233 |
self |
|
234 |
disabledRedrawDo: |
|
235 |
[ |
|
236 |
holder := self colorHolder. |
|
237 |
label := Text string: ' ' emphasis:(#backgroundColor->aColor). |
|
238 |
enabledChannel value:true. |
|
239 |
holder label:label. |
|
240 |
model value: aColor |
|
241 |
] |
|
412 | 242 |
] |
664 | 243 |
! |
244 |
||
245 |
labelsAreColored: aBoolean |
|
246 |
"sets whether labels or their backgrounds will be colored" |
|
247 |
||
248 |
labelsAreColored := aBoolean ? false. |
|
249 |
self setupMenu |
|
250 |
||
412 | 251 |
! ! |
252 |
||
1818 | 253 |
!ColorMenu methodsFor:'accessing-channels'! |
412 | 254 |
|
255 |
model:aValueHolder |
|
664 | 256 |
"set my color channel" |
257 |
||
2184 | 258 |
super model:aValueHolder. |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
259 |
model notNil ifTrue:[ |
2186 | 260 |
self updateFromModel |
664 | 261 |
] |
412 | 262 |
! ! |
263 |
||
264 |
!ColorMenu methodsFor:'change & update'! |
|
265 |
||
2186 | 266 |
updateFromModel |
2184 | 267 |
self color:(model value) |
412 | 268 |
! ! |
269 |
||
270 |
!ColorMenu methodsFor:'initialization'! |
|
271 |
||
272 |
destroy |
|
664 | 273 |
"release color channel dependency" |
274 |
||
412 | 275 |
self model:nil. |
664 | 276 |
super destroy |
412 | 277 |
|
278 |
! |
|
279 |
||
280 |
initialize |
|
664 | 281 |
"setup menu" |
282 |
||
412 | 283 |
super initialize. |
2254 | 284 |
labelsAreColored := false. |
285 |
verticalLayout := false. |
|
286 |
||
412 | 287 |
self fitFirstPanel:false. |
895 | 288 |
enabledChannel := ValueHolder with:false. |
412 | 289 |
self setupMenu. |
895 | 290 |
|
291 |
"Modified: / 21.5.1998 / 03:07:26 / cg" |
|
412 | 292 |
! |
293 |
||
294 |
setupMenu |
|
664 | 295 |
"setup menu" |
666 | 296 |
|menu item| |
412 | 297 |
|
666 | 298 |
menu := self class colorMenu:labelsAreColored value:nil. |
299 |
menu itemsDo:[:el| el isButton:true]. |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
300 |
menu |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
301 |
addItem:( |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
302 |
(MenuItem labeled:'...') |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
303 |
value: |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
304 |
[ |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
305 |
|defineColor| |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
306 |
defineColor := DefineColor new color: self color. |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
307 |
defineColor open. |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
308 |
defineColor accept value ifTrue: [self color: defineColor color] |
1057 | 309 |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
310 |
]; |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
311 |
nameKey:#def; |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
312 |
isButton: true) |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
313 |
beforeIndex:8. |
1057 | 314 |
menu addItem:(MenuItem labeled:'') beforeIndex:8. |
806 | 315 |
menu addItem:(MenuItem labeled:' ') beforeIndex:5. |
316 |
menu addItem:(MenuItem labeled:' ') beforeIndex:2. |
|
317 |
menu addItem:(MenuItem labeled:' ') beforeIndex:1. |
|
318 |
||
666 | 319 |
item := MenuItem labeled:(Text string:' ' emphasis:(#backgroundColor->DefaultViewBackgroundColor)). |
320 |
item value:#selection. |
|
321 |
menu addItem:item beforeIndex:1. |
|
806 | 322 |
|
412 | 323 |
self menu:menu. |
324 |
||
666 | 325 |
self do:[:anItem| |
326 |
(anItem submenu) notNil ifTrue:[ |
|
412 | 327 |
anItem enabled:enabledChannel. |
666 | 328 |
] ifFalse:[ |
329 |
anItem value == #selection ifTrue:[anItem indication:enabledChannel] |
|
1057 | 330 |
ifFalse:[anItem enabled:false]. |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
331 |
anItem nameKey == #def ifTrue:[anItem enabled:enabledChannel] |
412 | 332 |
] |
664 | 333 |
] |
412 | 334 |
! ! |
335 |
||
336 |
!ColorMenu methodsFor:'private'! |
|
337 |
||
338 |
colorHolder |
|
339 |
"returns the item which keeps the selected color in its label |
|
340 |
" |
|
341 |
^ self itemAt:#selection |
|
342 |
! ! |
|
343 |
||
1057 | 344 |
!ColorMenu::DefineColor class methodsFor:'interface specs'! |
345 |
||
346 |
windowSpec |
|
347 |
"This resource specification was automatically generated |
|
348 |
by the UIPainter of ST/X." |
|
349 |
||
350 |
"Do not manually edit this!! If it is corrupted, |
|
351 |
the UIPainter may not be able to read the specification." |
|
352 |
||
353 |
" |
|
354 |
UIPainter new openOnClass:ColorMenu::DefineColor andSelector:#windowSpec |
|
355 |
ColorMenu::DefineColor new openInterface:#windowSpec |
|
356 |
ColorMenu::DefineColor open |
|
357 |
" |
|
358 |
||
359 |
<resource: #canvas> |
|
360 |
||
1816 | 361 |
^ |
362 |
#(#FullSpec |
|
363 |
#name: #windowSpec |
|
364 |
#window: |
|
365 |
#(#WindowSpec |
|
366 |
#label: 'Define Color' |
|
367 |
#name: 'Define Color' |
|
2045 | 368 |
#min: #(#Point 340 260) |
369 |
#max: #(#Point nil 260) |
|
370 |
#bounds: #(#Rectangle 16 46 469 298) |
|
1816 | 371 |
) |
372 |
#component: |
|
373 |
#(#SpecCollection |
|
374 |
#collection: #( |
|
375 |
#(#VerticalPanelViewSpec |
|
2045 | 376 |
#name: 'RGBLabelPanel' |
377 |
#layout: #(#LayoutFrame 0 0 0 0 58 0 76 0) |
|
1816 | 378 |
#horizontalLayout: #fit |
379 |
#verticalLayout: #spreadSpace |
|
380 |
#horizontalSpace: 3 |
|
381 |
#verticalSpace: 3 |
|
382 |
#component: |
|
383 |
#(#SpecCollection |
|
384 |
#collection: #( |
|
385 |
#(#LabelSpec |
|
386 |
#label: 'Red:' |
|
387 |
#name: 'RedLabel' |
|
388 |
#translateLabel: true |
|
389 |
#adjust: #right |
|
390 |
#useDefaultExtent: true |
|
391 |
) |
|
392 |
#(#LabelSpec |
|
393 |
#label: 'Green:' |
|
394 |
#name: 'GreenLabel' |
|
395 |
#translateLabel: true |
|
396 |
#adjust: #right |
|
397 |
#useDefaultExtent: true |
|
398 |
) |
|
1057 | 399 |
#(#LabelSpec |
1816 | 400 |
#label: 'Blue:' |
401 |
#name: 'BlueLabel' |
|
1057 | 402 |
#translateLabel: true |
1816 | 403 |
#adjust: #right |
404 |
#useDefaultExtent: true |
|
405 |
) |
|
406 |
) |
|
407 |
||
408 |
) |
|
409 |
) |
|
410 |
#(#VerticalPanelViewSpec |
|
2045 | 411 |
#name: 'RGBSliderPanel' |
412 |
#layout: #(#LayoutFrame 62 0 0 0 -166 1 76 0) |
|
1816 | 413 |
#horizontalLayout: #fit |
414 |
#verticalLayout: #spreadSpace |
|
415 |
#horizontalSpace: 3 |
|
416 |
#verticalSpace: 3 |
|
417 |
#component: |
|
418 |
#(#SpecCollection |
|
419 |
#collection: #( |
|
420 |
#(#SliderSpec |
|
421 |
#name: 'RedSlider' |
|
422 |
#tabable: true |
|
423 |
#model: #red |
|
424 |
#orientation: #horizontal |
|
425 |
#stop: 255 |
|
426 |
#step: 1 |
|
427 |
#backgroundColor: #(#Color 100.0 0.0 0.0) |
|
2045 | 428 |
#extent: #(#Point 225 16) |
1816 | 429 |
) |
430 |
#(#SliderSpec |
|
431 |
#name: 'GreenSlider' |
|
432 |
#tabable: true |
|
433 |
#model: #green |
|
434 |
#orientation: #horizontal |
|
435 |
#stop: 255 |
|
436 |
#step: 1 |
|
437 |
#backgroundColor: #(#Color 0.0 100.0 0.0) |
|
2045 | 438 |
#extent: #(#Point 225 16) |
1816 | 439 |
) |
440 |
#(#SliderSpec |
|
441 |
#name: 'BlueSlider' |
|
442 |
#tabable: true |
|
443 |
#model: #blue |
|
444 |
#orientation: #horizontal |
|
445 |
#stop: 255 |
|
446 |
#step: 1 |
|
447 |
#backgroundColor: #(#Color 0.0 0.0 100.0) |
|
2045 | 448 |
#extent: #(#Point 225 16) |
1816 | 449 |
) |
450 |
) |
|
451 |
||
1057 | 452 |
) |
1816 | 453 |
) |
454 |
#(#VerticalPanelViewSpec |
|
2045 | 455 |
#name: 'RGBFieldPanel' |
456 |
#layout: #(#LayoutFrame -161 1 0 0 -123 1 76 0) |
|
1816 | 457 |
#horizontalLayout: #fit |
458 |
#verticalLayout: #spreadSpace |
|
459 |
#horizontalSpace: 3 |
|
460 |
#verticalSpace: 3 |
|
461 |
#component: |
|
462 |
#(#SpecCollection |
|
463 |
#collection: #( |
|
464 |
#(#InputFieldSpec |
|
465 |
#name: 'RedField' |
|
466 |
#model: #red |
|
467 |
#type: #numberInRange |
|
468 |
#numChars: 3 |
|
469 |
#minValue: 0 |
|
470 |
#maxValue: 255 |
|
471 |
#acceptOnPointerLeave: false |
|
472 |
#extent: #(#Point 38 20) |
|
473 |
) |
|
474 |
#(#InputFieldSpec |
|
475 |
#name: 'GreenField' |
|
476 |
#model: #green |
|
477 |
#type: #numberInRange |
|
478 |
#numChars: 3 |
|
479 |
#minValue: 0 |
|
480 |
#maxValue: 255 |
|
481 |
#acceptOnPointerLeave: false |
|
482 |
#extent: #(#Point 38 20) |
|
483 |
) |
|
484 |
#(#InputFieldSpec |
|
485 |
#name: 'BlueField' |
|
486 |
#model: #blue |
|
487 |
#type: #numberInRange |
|
488 |
#numChars: 3 |
|
489 |
#minValue: 0 |
|
490 |
#maxValue: 255 |
|
491 |
#acceptOnPointerLeave: false |
|
492 |
#extent: #(#Point 38 20) |
|
493 |
) |
|
494 |
) |
|
495 |
||
496 |
) |
|
497 |
) |
|
2045 | 498 |
#(#VerticalPanelViewSpec |
499 |
#name: 'HLSLabelPanel' |
|
500 |
#layout: #(#LayoutFrame 0 0 86 0 58 0 163 0) |
|
501 |
#horizontalLayout: #fit |
|
502 |
#verticalLayout: #spreadSpace |
|
503 |
#horizontalSpace: 3 |
|
504 |
#verticalSpace: 3 |
|
505 |
#component: |
|
506 |
#(#SpecCollection |
|
507 |
#collection: #( |
|
508 |
#(#LabelSpec |
|
509 |
#label: 'Hue:' |
|
510 |
#name: 'Label1' |
|
511 |
#translateLabel: true |
|
512 |
#adjust: #right |
|
513 |
#useDefaultExtent: true |
|
514 |
) |
|
515 |
#(#LabelSpec |
|
516 |
#label: 'Light:' |
|
517 |
#name: 'Label2' |
|
518 |
#translateLabel: true |
|
519 |
#adjust: #right |
|
520 |
#useDefaultExtent: true |
|
521 |
) |
|
522 |
#(#LabelSpec |
|
523 |
#label: 'Sat:' |
|
524 |
#name: 'Label3' |
|
525 |
#translateLabel: true |
|
526 |
#adjust: #right |
|
527 |
#useDefaultExtent: true |
|
528 |
) |
|
529 |
) |
|
530 |
||
531 |
) |
|
532 |
) |
|
533 |
#(#VerticalPanelViewSpec |
|
534 |
#name: 'HLSSliderPanel' |
|
535 |
#layout: #(#LayoutFrame 62 0 86 0 -166 1 163 0) |
|
536 |
#horizontalLayout: #fit |
|
537 |
#verticalLayout: #spreadSpace |
|
538 |
#horizontalSpace: 3 |
|
539 |
#verticalSpace: 3 |
|
540 |
#component: |
|
541 |
#(#SpecCollection |
|
542 |
#collection: #( |
|
543 |
#(#SliderSpec |
|
544 |
#name: 'Slider1' |
|
545 |
#tabable: true |
|
546 |
#model: #hue |
|
547 |
#orientation: #horizontal |
|
548 |
#stop: 359 |
|
549 |
#step: 1 |
|
550 |
#keyboardStep: 1 |
|
551 |
#extent: #(#Point 225 16) |
|
552 |
) |
|
553 |
#(#SliderSpec |
|
554 |
#name: 'Slider2' |
|
555 |
#tabable: true |
|
556 |
#model: #light |
|
557 |
#orientation: #horizontal |
|
558 |
#step: 1 |
|
559 |
#backgroundColor: #(#Color 66.9993 66.9993 66.9993) |
|
560 |
#keyboardStep: 1 |
|
561 |
#extent: #(#Point 225 16) |
|
562 |
) |
|
563 |
#(#SliderSpec |
|
564 |
#name: 'Slider3' |
|
565 |
#tabable: true |
|
566 |
#model: #saturation |
|
567 |
#orientation: #horizontal |
|
568 |
#step: 1 |
|
569 |
#backgroundColor: #(#Color 66.9993 66.9993 66.9993) |
|
570 |
#keyboardStep: 1 |
|
571 |
#extent: #(#Point 225 16) |
|
572 |
) |
|
573 |
) |
|
574 |
||
575 |
) |
|
576 |
) |
|
577 |
#(#VerticalPanelViewSpec |
|
578 |
#name: 'HLSFieldPanel' |
|
579 |
#layout: #(#LayoutFrame -161 1 86 0 -123 1 163 0) |
|
580 |
#horizontalLayout: #fit |
|
581 |
#verticalLayout: #spreadSpace |
|
582 |
#horizontalSpace: 3 |
|
583 |
#verticalSpace: 3 |
|
584 |
#component: |
|
585 |
#(#SpecCollection |
|
586 |
#collection: #( |
|
587 |
#(#InputFieldSpec |
|
588 |
#name: 'EntryField1' |
|
589 |
#model: #hue |
|
590 |
#type: #numberInRange |
|
591 |
#numChars: 3 |
|
592 |
#minValue: 0 |
|
593 |
#maxValue: 359 |
|
594 |
#acceptOnPointerLeave: false |
|
595 |
#extent: #(#Point 38 20) |
|
596 |
) |
|
597 |
#(#InputFieldSpec |
|
598 |
#name: 'EntryField2' |
|
599 |
#model: #light |
|
600 |
#type: #numberInRange |
|
601 |
#numChars: 3 |
|
602 |
#minValue: 0 |
|
603 |
#maxValue: 100 |
|
604 |
#acceptOnPointerLeave: false |
|
605 |
#extent: #(#Point 38 20) |
|
606 |
) |
|
607 |
#(#InputFieldSpec |
|
608 |
#name: 'EntryField3' |
|
609 |
#model: #saturation |
|
610 |
#type: #numberInRange |
|
611 |
#numChars: 3 |
|
612 |
#minValue: 0 |
|
613 |
#maxValue: 100 |
|
614 |
#acceptOnPointerLeave: false |
|
615 |
#extent: #(#Point 38 20) |
|
616 |
) |
|
617 |
) |
|
618 |
||
619 |
) |
|
620 |
) |
|
621 |
#(#ViewSpec |
|
622 |
#name: 'Box1' |
|
623 |
#layout: #(#LayoutFrame -117 1 4 0.0 -3 1.0 -39 1.0) |
|
624 |
#level: 1 |
|
625 |
#component: |
|
626 |
#(#SpecCollection |
|
627 |
#collection: #( |
|
628 |
#(#LabelSpec |
|
629 |
#label: 'Preview' |
|
630 |
#name: 'PreviewBox' |
|
631 |
#layout: #(#LayoutFrame 2 0.0 2 0.0 -2 1.0 -2 1.0) |
|
632 |
#level: -1 |
|
633 |
#translateLabel: true |
|
634 |
) |
|
635 |
) |
|
636 |
||
637 |
) |
|
1816 | 638 |
) |
639 |
#(#HorizontalPanelViewSpec |
|
640 |
#name: 'HorizontalPanel1' |
|
641 |
#layout: #(#LayoutFrame 0 0.0 -32 1 0 1.0 0 1.0) |
|
642 |
#horizontalLayout: #fitSpace |
|
643 |
#verticalLayout: #centerMax |
|
644 |
#horizontalSpace: 3 |
|
645 |
#verticalSpace: 3 |
|
646 |
#reverseOrderIfOKAtLeft: true |
|
647 |
#component: |
|
648 |
#(#SpecCollection |
|
649 |
#collection: #( |
|
650 |
#(#ActionButtonSpec |
|
651 |
#label: 'Cancel' |
|
652 |
#name: 'CancelButton' |
|
653 |
#translateLabel: true |
|
654 |
#resizeForLabel: false |
|
655 |
#tabable: true |
|
656 |
#model: #cancel |
|
657 |
#useDefaultExtent: true |
|
658 |
) |
|
659 |
#(#ActionButtonSpec |
|
660 |
#label: 'OK' |
|
661 |
#name: 'OKButton' |
|
662 |
#translateLabel: true |
|
663 |
#resizeForLabel: false |
|
664 |
#tabable: true |
|
665 |
#model: #accept |
|
666 |
#isDefault: true |
|
667 |
#defaultable: true |
|
668 |
#useDefaultExtent: true |
|
669 |
) |
|
670 |
) |
|
671 |
||
672 |
) |
|
673 |
) |
|
2045 | 674 |
#(#InputFieldSpec |
675 |
#name: 'ColorNameField' |
|
676 |
#layout: #(#LayoutFrame 110 0 190 0 -123 1 212 0) |
|
677 |
#model: #colorNameHolder |
|
678 |
#immediateAccept: true |
|
679 |
#acceptOnReturn: true |
|
680 |
#acceptOnTab: true |
|
681 |
#acceptOnLostFocus: true |
|
682 |
#acceptOnPointerLeave: false |
|
683 |
) |
|
684 |
#(#LabelSpec |
|
685 |
#label: 'Color Name:' |
|
686 |
#name: 'Label4' |
|
687 |
#layout: #(#LayoutFrame 0 0 190 0 106 0 212 0) |
|
688 |
#translateLabel: true |
|
689 |
#adjust: #right |
|
690 |
) |
|
1816 | 691 |
) |
692 |
||
693 |
) |
|
1057 | 694 |
) |
695 |
! ! |
|
696 |
||
697 |
!ColorMenu::DefineColor methodsFor:'accessing'! |
|
698 |
||
699 |
color |
|
2045 | 700 |
^Color redByte:(red value) greenByte:(green value) blueByte:(blue value) |
1057 | 701 |
! |
702 |
||
703 |
color: aColor |
|
704 |
||
705 |
aColor notNil |
|
706 |
ifTrue: |
|
707 |
[ |
|
708 |
self red value: aColor redByte. |
|
709 |
self green value: aColor greenByte. |
|
710 |
self blue value: aColor blueByte. |
|
711 |
] |
|
712 |
||
2045 | 713 |
! |
714 |
||
715 |
colorName |
|
716 |
^ colorNameHolder value |
|
717 |
! ! |
|
718 |
||
719 |
!ColorMenu::DefineColor methodsFor:'actions'! |
|
720 |
||
721 |
colorChanged |
|
722 |
|box clr| |
|
723 |
||
2167
675c1cd59a80
builder componentAt: -> self componentAt:
Claus Gittinger <cg@exept.de>
parents:
2057
diff
changeset
|
724 |
box := self componentAt: #PreviewBox. |
2057 | 725 |
box isNil ifTrue:[^ self "called before setup"]. |
726 |
||
2045 | 727 |
clr := self color. |
728 |
box backgroundColor:clr. |
|
729 |
||
730 |
clr brightness < 0.5 ifTrue:[ |
|
731 |
box foregroundColor:Color white |
|
732 |
] ifFalse:[ |
|
733 |
box foregroundColor:Color black |
|
734 |
]. |
|
735 |
! |
|
736 |
||
737 |
colorNameChanged |
|
738 |
"compute rgb and hls (if possible)" |
|
739 |
||
740 |
|clr h| |
|
741 |
||
742 |
clr := Color name:colorNameHolder value ifIllegal:nil. |
|
743 |
clr isNil ifTrue:[ |
|
744 |
^ self |
|
745 |
]. |
|
746 |
||
747 |
red value:clr redByte withoutNotifying:self. |
|
748 |
green value:clr greenByte withoutNotifying:self. |
|
749 |
blue value:clr blueByte withoutNotifying:self. |
|
750 |
||
751 |
h := clr hue. |
|
752 |
h notNil ifTrue:[ |
|
753 |
hue value:(h rounded) withoutNotifying:self. |
|
754 |
]. |
|
755 |
light value:(clr light rounded) withoutNotifying:self. |
|
756 |
saturation value:(clr saturation rounded) withoutNotifying:self. |
|
757 |
||
758 |
self colorChanged |
|
759 |
! |
|
760 |
||
761 |
hlsSliderChanged |
|
762 |
"compute rgb" |
|
763 |
||
764 |
Color withRGBFromHue:hue value light:light value saturation:saturation value do:[:r :g :b | |
|
765 |
red value:(r * 255 / 100) rounded withoutNotifying:self. |
|
766 |
green value:(g * 255 / 100) rounded withoutNotifying:self. |
|
767 |
blue value:(b * 255 / 100) rounded withoutNotifying:self. |
|
768 |
]. |
|
769 |
colorNameHolder value:'' withoutNotifying:self. |
|
770 |
self colorChanged |
|
771 |
! |
|
772 |
||
773 |
rgbSliderChanged |
|
774 |
"compute hls" |
|
775 |
||
776 |
|r g b| |
|
777 |
||
2057 | 778 |
r := self red value. |
779 |
g := self green value. |
|
780 |
b := self blue value. |
|
2045 | 781 |
|
782 |
Color withHLSFromRed:(r * 100 / 255) green:(g * 100 / 255) blue:(b * 100 / 255) do:[:h :l :s | |
|
783 |
h isNil ifTrue:[ |
|
784 |
"/ achromatic |
|
785 |
] ifFalse:[ |
|
2057 | 786 |
self hue value:(h rounded) withoutNotifying:self. |
2045 | 787 |
]. |
2057 | 788 |
self light value:(l rounded) withoutNotifying:self. |
789 |
self saturation value:(s rounded) withoutNotifying:self. |
|
2045 | 790 |
]. |
2057 | 791 |
self colorNameHolder value:'' withoutNotifying:self. |
2045 | 792 |
self colorChanged |
1057 | 793 |
! ! |
794 |
||
795 |
!ColorMenu::DefineColor methodsFor:'aspects'! |
|
796 |
||
797 |
blue |
|
798 |
blue isNil ifTrue:[ |
|
2045 | 799 |
blue := 0 asValue. |
800 |
blue addDependent:self. |
|
1057 | 801 |
]. |
802 |
^blue |
|
803 |
! |
|
804 |
||
2045 | 805 |
colorNameHolder |
806 |
colorNameHolder isNil ifTrue:[ |
|
807 |
colorNameHolder := '' asValue. |
|
808 |
colorNameHolder addDependent:self. |
|
809 |
]. |
|
810 |
^colorNameHolder |
|
811 |
! |
|
1057 | 812 |
|
2045 | 813 |
green |
1057 | 814 |
green isNil ifTrue:[ |
2045 | 815 |
green := 0 asValue. |
816 |
green addDependent:self. |
|
1057 | 817 |
]. |
818 |
^green |
|
819 |
! |
|
820 |
||
2045 | 821 |
hue |
822 |
hue isNil ifTrue:[ |
|
823 |
hue := 0 asValue. |
|
824 |
hue addDependent:self. |
|
825 |
]. |
|
826 |
^hue |
|
827 |
! |
|
1057 | 828 |
|
2045 | 829 |
light |
830 |
light isNil ifTrue:[ |
|
831 |
light := 0 asValue. |
|
832 |
light addDependent:self. |
|
833 |
]. |
|
834 |
^light |
|
835 |
! |
|
836 |
||
837 |
red |
|
1057 | 838 |
red isNil ifTrue:[ |
2045 | 839 |
red := 0 asValue. |
840 |
red addDependent:self. |
|
1057 | 841 |
]. |
842 |
^red |
|
2045 | 843 |
! |
844 |
||
845 |
saturation |
|
846 |
saturation isNil ifTrue:[ |
|
847 |
saturation := 0 asValue. |
|
848 |
saturation addDependent:self. |
|
849 |
]. |
|
850 |
^saturation |
|
851 |
! ! |
|
852 |
||
853 |
!ColorMenu::DefineColor methodsFor:'change & update'! |
|
854 |
||
855 |
update:something with:aParameter from:changedObject |
|
856 |
(changedObject == red |
|
857 |
or:[changedObject == green |
|
858 |
or:[changedObject == blue]]) ifTrue:[ |
|
859 |
^ self rgbSliderChanged |
|
860 |
]. |
|
861 |
||
862 |
(changedObject == hue |
|
863 |
or:[changedObject == light |
|
864 |
or:[changedObject == saturation]]) ifTrue:[ |
|
865 |
^ self hlsSliderChanged |
|
866 |
]. |
|
867 |
||
868 |
(changedObject == colorNameHolder) ifTrue:[ |
|
869 |
^ self colorNameChanged |
|
870 |
]. |
|
871 |
||
872 |
^ super update:something with:aParameter from:changedObject |
|
1057 | 873 |
! ! |
874 |
||
875 |
!ColorMenu::DefineColor methodsFor:'startup / release'! |
|
876 |
||
877 |
postBuildWith:aBuilder |
|
878 |
super postBuildWith:aBuilder. |
|
2045 | 879 |
self colorChanged. |
1057 | 880 |
|
1119
11cd3ce5171b
colorMenu: change labelColor to white for dark preview colors;
Claus Gittinger <cg@exept.de>
parents:
1058
diff
changeset
|
881 |
"Modified: / 6.9.1998 / 22:55:25 / cg" |
1057 | 882 |
! ! |
883 |
||
412 | 884 |
!ColorMenu class methodsFor:'documentation'! |
885 |
||
886 |
version |
|
2254 | 887 |
^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.31 2002-10-08 06:35:50 ca Exp $' |
412 | 888 |
! ! |