author | Claus Gittinger <cg@exept.de> |
Thu, 12 Sep 2002 15:32:18 +0200 | |
changeset 2183 | 5c69691590eb |
parent 2167 | 675c1cd59a80 |
child 2184 | 16d3b72ca431 |
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 |
||
664 | 230 |
aColor isColor |
231 |
ifFalse: |
|
232 |
[ |
|
412 | 233 |
enabledChannel value:false |
664 | 234 |
] |
235 |
ifTrue: |
|
236 |
[ |
|
237 |
self disabledRedrawDo: |
|
1057 | 238 |
[ |
664 | 239 |
holder := self colorHolder. |
240 |
label := Text string: ' ' emphasis:(#backgroundColor->aColor). |
|
412 | 241 |
enabledChannel value:true. |
1057 | 242 |
holder label:label. |
243 |
model value: aColor |
|
412 | 244 |
] |
245 |
] |
|
664 | 246 |
! |
247 |
||
248 |
labelsAreColored: aBoolean |
|
249 |
"sets whether labels or their backgrounds will be colored" |
|
250 |
||
251 |
labelsAreColored := aBoolean ? false. |
|
252 |
self setupMenu |
|
253 |
||
412 | 254 |
! ! |
255 |
||
1818 | 256 |
!ColorMenu methodsFor:'accessing-channels'! |
412 | 257 |
|
258 |
model |
|
664 | 259 |
"get my color channel" |
260 |
||
261 |
^model |
|
412 | 262 |
|
263 |
||
264 |
||
265 |
! |
|
266 |
||
267 |
model:aValueHolder |
|
664 | 268 |
"set my color channel" |
269 |
||
270 |
model notNil ifTrue:[model removeDependent:self]. |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
271 |
model := aValueHolder. |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
272 |
model notNil ifTrue:[ |
412 | 273 |
model addDependent:self. |
664 | 274 |
self color: model value |
275 |
] |
|
412 | 276 |
! ! |
277 |
||
1818 | 278 |
!ColorMenu methodsFor:'accessing-look'! |
412 | 279 |
|
280 |
showSeparatingLines |
|
664 | 281 |
"no drawing of separating lines here" |
282 |
||
283 |
^true |
|
284 |
||
412 | 285 |
! ! |
286 |
||
287 |
!ColorMenu methodsFor:'change & update'! |
|
288 |
||
289 |
update:something with:aParameter from:changedObject |
|
664 | 290 |
"one of my models changed its value" |
291 |
||
292 |
changedObject == model ifTrue:[^self color: model value]. |
|
412 | 293 |
super update:something with:aParameter from:changedObject |
294 |
||
295 |
||
296 |
||
297 |
||
298 |
! ! |
|
299 |
||
300 |
!ColorMenu methodsFor:'initialization'! |
|
301 |
||
302 |
destroy |
|
664 | 303 |
"release color channel dependency" |
304 |
||
412 | 305 |
self model:nil. |
664 | 306 |
super destroy |
412 | 307 |
|
308 |
! |
|
309 |
||
310 |
initialize |
|
664 | 311 |
"setup menu" |
312 |
||
412 | 313 |
super initialize. |
664 | 314 |
labelsAreColored := false. |
412 | 315 |
self verticalLayout:false. |
316 |
self fitFirstPanel:false. |
|
895 | 317 |
enabledChannel := ValueHolder with:false. |
412 | 318 |
self setupMenu. |
895 | 319 |
|
320 |
"Modified: / 21.5.1998 / 03:07:26 / cg" |
|
412 | 321 |
! |
322 |
||
323 |
setupMenu |
|
664 | 324 |
"setup menu" |
666 | 325 |
|menu item| |
412 | 326 |
|
666 | 327 |
menu := self class colorMenu:labelsAreColored value:nil. |
328 |
menu itemsDo:[:el| el isButton:true]. |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
329 |
menu |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
330 |
addItem:( |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
331 |
(MenuItem labeled:'...') |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
332 |
value: |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
333 |
[ |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
334 |
|defineColor| |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
335 |
defineColor := DefineColor new color: self color. |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
336 |
defineColor open. |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
337 |
defineColor accept value ifTrue: [self color: defineColor color] |
1057 | 338 |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
339 |
]; |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
340 |
nameKey:#def; |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
341 |
isButton: true) |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
342 |
beforeIndex:8. |
1057 | 343 |
menu addItem:(MenuItem labeled:'') beforeIndex:8. |
806 | 344 |
menu addItem:(MenuItem labeled:' ') beforeIndex:5. |
345 |
menu addItem:(MenuItem labeled:' ') beforeIndex:2. |
|
346 |
menu addItem:(MenuItem labeled:' ') beforeIndex:1. |
|
347 |
||
666 | 348 |
item := MenuItem labeled:(Text string:' ' emphasis:(#backgroundColor->DefaultViewBackgroundColor)). |
349 |
item value:#selection. |
|
350 |
menu addItem:item beforeIndex:1. |
|
806 | 351 |
|
412 | 352 |
self menu:menu. |
353 |
||
666 | 354 |
self do:[:anItem| |
355 |
(anItem submenu) notNil ifTrue:[ |
|
412 | 356 |
anItem enabled:enabledChannel. |
666 | 357 |
] ifFalse:[ |
358 |
anItem value == #selection ifTrue:[anItem indication:enabledChannel] |
|
1057 | 359 |
ifFalse:[anItem enabled:false]. |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
360 |
anItem nameKey == #def ifTrue:[anItem enabled:enabledChannel] |
412 | 361 |
] |
664 | 362 |
] |
412 | 363 |
! ! |
364 |
||
365 |
!ColorMenu methodsFor:'private'! |
|
366 |
||
367 |
colorHolder |
|
368 |
"returns the item which keeps the selected color in its label |
|
369 |
" |
|
370 |
^ self itemAt:#selection |
|
371 |
! ! |
|
372 |
||
1057 | 373 |
!ColorMenu::DefineColor class methodsFor:'interface specs'! |
374 |
||
375 |
windowSpec |
|
376 |
"This resource specification was automatically generated |
|
377 |
by the UIPainter of ST/X." |
|
378 |
||
379 |
"Do not manually edit this!! If it is corrupted, |
|
380 |
the UIPainter may not be able to read the specification." |
|
381 |
||
382 |
" |
|
383 |
UIPainter new openOnClass:ColorMenu::DefineColor andSelector:#windowSpec |
|
384 |
ColorMenu::DefineColor new openInterface:#windowSpec |
|
385 |
ColorMenu::DefineColor open |
|
386 |
" |
|
387 |
||
388 |
<resource: #canvas> |
|
389 |
||
1816 | 390 |
^ |
391 |
#(#FullSpec |
|
392 |
#name: #windowSpec |
|
393 |
#window: |
|
394 |
#(#WindowSpec |
|
395 |
#label: 'Define Color' |
|
396 |
#name: 'Define Color' |
|
2045 | 397 |
#min: #(#Point 340 260) |
398 |
#max: #(#Point nil 260) |
|
399 |
#bounds: #(#Rectangle 16 46 469 298) |
|
1816 | 400 |
) |
401 |
#component: |
|
402 |
#(#SpecCollection |
|
403 |
#collection: #( |
|
404 |
#(#VerticalPanelViewSpec |
|
2045 | 405 |
#name: 'RGBLabelPanel' |
406 |
#layout: #(#LayoutFrame 0 0 0 0 58 0 76 0) |
|
1816 | 407 |
#horizontalLayout: #fit |
408 |
#verticalLayout: #spreadSpace |
|
409 |
#horizontalSpace: 3 |
|
410 |
#verticalSpace: 3 |
|
411 |
#component: |
|
412 |
#(#SpecCollection |
|
413 |
#collection: #( |
|
414 |
#(#LabelSpec |
|
415 |
#label: 'Red:' |
|
416 |
#name: 'RedLabel' |
|
417 |
#translateLabel: true |
|
418 |
#adjust: #right |
|
419 |
#useDefaultExtent: true |
|
420 |
) |
|
421 |
#(#LabelSpec |
|
422 |
#label: 'Green:' |
|
423 |
#name: 'GreenLabel' |
|
424 |
#translateLabel: true |
|
425 |
#adjust: #right |
|
426 |
#useDefaultExtent: true |
|
427 |
) |
|
1057 | 428 |
#(#LabelSpec |
1816 | 429 |
#label: 'Blue:' |
430 |
#name: 'BlueLabel' |
|
1057 | 431 |
#translateLabel: true |
1816 | 432 |
#adjust: #right |
433 |
#useDefaultExtent: true |
|
434 |
) |
|
435 |
) |
|
436 |
||
437 |
) |
|
438 |
) |
|
439 |
#(#VerticalPanelViewSpec |
|
2045 | 440 |
#name: 'RGBSliderPanel' |
441 |
#layout: #(#LayoutFrame 62 0 0 0 -166 1 76 0) |
|
1816 | 442 |
#horizontalLayout: #fit |
443 |
#verticalLayout: #spreadSpace |
|
444 |
#horizontalSpace: 3 |
|
445 |
#verticalSpace: 3 |
|
446 |
#component: |
|
447 |
#(#SpecCollection |
|
448 |
#collection: #( |
|
449 |
#(#SliderSpec |
|
450 |
#name: 'RedSlider' |
|
451 |
#tabable: true |
|
452 |
#model: #red |
|
453 |
#orientation: #horizontal |
|
454 |
#stop: 255 |
|
455 |
#step: 1 |
|
456 |
#backgroundColor: #(#Color 100.0 0.0 0.0) |
|
2045 | 457 |
#extent: #(#Point 225 16) |
1816 | 458 |
) |
459 |
#(#SliderSpec |
|
460 |
#name: 'GreenSlider' |
|
461 |
#tabable: true |
|
462 |
#model: #green |
|
463 |
#orientation: #horizontal |
|
464 |
#stop: 255 |
|
465 |
#step: 1 |
|
466 |
#backgroundColor: #(#Color 0.0 100.0 0.0) |
|
2045 | 467 |
#extent: #(#Point 225 16) |
1816 | 468 |
) |
469 |
#(#SliderSpec |
|
470 |
#name: 'BlueSlider' |
|
471 |
#tabable: true |
|
472 |
#model: #blue |
|
473 |
#orientation: #horizontal |
|
474 |
#stop: 255 |
|
475 |
#step: 1 |
|
476 |
#backgroundColor: #(#Color 0.0 0.0 100.0) |
|
2045 | 477 |
#extent: #(#Point 225 16) |
1816 | 478 |
) |
479 |
) |
|
480 |
||
1057 | 481 |
) |
1816 | 482 |
) |
483 |
#(#VerticalPanelViewSpec |
|
2045 | 484 |
#name: 'RGBFieldPanel' |
485 |
#layout: #(#LayoutFrame -161 1 0 0 -123 1 76 0) |
|
1816 | 486 |
#horizontalLayout: #fit |
487 |
#verticalLayout: #spreadSpace |
|
488 |
#horizontalSpace: 3 |
|
489 |
#verticalSpace: 3 |
|
490 |
#component: |
|
491 |
#(#SpecCollection |
|
492 |
#collection: #( |
|
493 |
#(#InputFieldSpec |
|
494 |
#name: 'RedField' |
|
495 |
#model: #red |
|
496 |
#type: #numberInRange |
|
497 |
#numChars: 3 |
|
498 |
#minValue: 0 |
|
499 |
#maxValue: 255 |
|
500 |
#acceptOnPointerLeave: false |
|
501 |
#extent: #(#Point 38 20) |
|
502 |
) |
|
503 |
#(#InputFieldSpec |
|
504 |
#name: 'GreenField' |
|
505 |
#model: #green |
|
506 |
#type: #numberInRange |
|
507 |
#numChars: 3 |
|
508 |
#minValue: 0 |
|
509 |
#maxValue: 255 |
|
510 |
#acceptOnPointerLeave: false |
|
511 |
#extent: #(#Point 38 20) |
|
512 |
) |
|
513 |
#(#InputFieldSpec |
|
514 |
#name: 'BlueField' |
|
515 |
#model: #blue |
|
516 |
#type: #numberInRange |
|
517 |
#numChars: 3 |
|
518 |
#minValue: 0 |
|
519 |
#maxValue: 255 |
|
520 |
#acceptOnPointerLeave: false |
|
521 |
#extent: #(#Point 38 20) |
|
522 |
) |
|
523 |
) |
|
524 |
||
525 |
) |
|
526 |
) |
|
2045 | 527 |
#(#VerticalPanelViewSpec |
528 |
#name: 'HLSLabelPanel' |
|
529 |
#layout: #(#LayoutFrame 0 0 86 0 58 0 163 0) |
|
530 |
#horizontalLayout: #fit |
|
531 |
#verticalLayout: #spreadSpace |
|
532 |
#horizontalSpace: 3 |
|
533 |
#verticalSpace: 3 |
|
534 |
#component: |
|
535 |
#(#SpecCollection |
|
536 |
#collection: #( |
|
537 |
#(#LabelSpec |
|
538 |
#label: 'Hue:' |
|
539 |
#name: 'Label1' |
|
540 |
#translateLabel: true |
|
541 |
#adjust: #right |
|
542 |
#useDefaultExtent: true |
|
543 |
) |
|
544 |
#(#LabelSpec |
|
545 |
#label: 'Light:' |
|
546 |
#name: 'Label2' |
|
547 |
#translateLabel: true |
|
548 |
#adjust: #right |
|
549 |
#useDefaultExtent: true |
|
550 |
) |
|
551 |
#(#LabelSpec |
|
552 |
#label: 'Sat:' |
|
553 |
#name: 'Label3' |
|
554 |
#translateLabel: true |
|
555 |
#adjust: #right |
|
556 |
#useDefaultExtent: true |
|
557 |
) |
|
558 |
) |
|
559 |
||
560 |
) |
|
561 |
) |
|
562 |
#(#VerticalPanelViewSpec |
|
563 |
#name: 'HLSSliderPanel' |
|
564 |
#layout: #(#LayoutFrame 62 0 86 0 -166 1 163 0) |
|
565 |
#horizontalLayout: #fit |
|
566 |
#verticalLayout: #spreadSpace |
|
567 |
#horizontalSpace: 3 |
|
568 |
#verticalSpace: 3 |
|
569 |
#component: |
|
570 |
#(#SpecCollection |
|
571 |
#collection: #( |
|
572 |
#(#SliderSpec |
|
573 |
#name: 'Slider1' |
|
574 |
#tabable: true |
|
575 |
#model: #hue |
|
576 |
#orientation: #horizontal |
|
577 |
#stop: 359 |
|
578 |
#step: 1 |
|
579 |
#keyboardStep: 1 |
|
580 |
#extent: #(#Point 225 16) |
|
581 |
) |
|
582 |
#(#SliderSpec |
|
583 |
#name: 'Slider2' |
|
584 |
#tabable: true |
|
585 |
#model: #light |
|
586 |
#orientation: #horizontal |
|
587 |
#step: 1 |
|
588 |
#backgroundColor: #(#Color 66.9993 66.9993 66.9993) |
|
589 |
#keyboardStep: 1 |
|
590 |
#extent: #(#Point 225 16) |
|
591 |
) |
|
592 |
#(#SliderSpec |
|
593 |
#name: 'Slider3' |
|
594 |
#tabable: true |
|
595 |
#model: #saturation |
|
596 |
#orientation: #horizontal |
|
597 |
#step: 1 |
|
598 |
#backgroundColor: #(#Color 66.9993 66.9993 66.9993) |
|
599 |
#keyboardStep: 1 |
|
600 |
#extent: #(#Point 225 16) |
|
601 |
) |
|
602 |
) |
|
603 |
||
604 |
) |
|
605 |
) |
|
606 |
#(#VerticalPanelViewSpec |
|
607 |
#name: 'HLSFieldPanel' |
|
608 |
#layout: #(#LayoutFrame -161 1 86 0 -123 1 163 0) |
|
609 |
#horizontalLayout: #fit |
|
610 |
#verticalLayout: #spreadSpace |
|
611 |
#horizontalSpace: 3 |
|
612 |
#verticalSpace: 3 |
|
613 |
#component: |
|
614 |
#(#SpecCollection |
|
615 |
#collection: #( |
|
616 |
#(#InputFieldSpec |
|
617 |
#name: 'EntryField1' |
|
618 |
#model: #hue |
|
619 |
#type: #numberInRange |
|
620 |
#numChars: 3 |
|
621 |
#minValue: 0 |
|
622 |
#maxValue: 359 |
|
623 |
#acceptOnPointerLeave: false |
|
624 |
#extent: #(#Point 38 20) |
|
625 |
) |
|
626 |
#(#InputFieldSpec |
|
627 |
#name: 'EntryField2' |
|
628 |
#model: #light |
|
629 |
#type: #numberInRange |
|
630 |
#numChars: 3 |
|
631 |
#minValue: 0 |
|
632 |
#maxValue: 100 |
|
633 |
#acceptOnPointerLeave: false |
|
634 |
#extent: #(#Point 38 20) |
|
635 |
) |
|
636 |
#(#InputFieldSpec |
|
637 |
#name: 'EntryField3' |
|
638 |
#model: #saturation |
|
639 |
#type: #numberInRange |
|
640 |
#numChars: 3 |
|
641 |
#minValue: 0 |
|
642 |
#maxValue: 100 |
|
643 |
#acceptOnPointerLeave: false |
|
644 |
#extent: #(#Point 38 20) |
|
645 |
) |
|
646 |
) |
|
647 |
||
648 |
) |
|
649 |
) |
|
650 |
#(#ViewSpec |
|
651 |
#name: 'Box1' |
|
652 |
#layout: #(#LayoutFrame -117 1 4 0.0 -3 1.0 -39 1.0) |
|
653 |
#level: 1 |
|
654 |
#component: |
|
655 |
#(#SpecCollection |
|
656 |
#collection: #( |
|
657 |
#(#LabelSpec |
|
658 |
#label: 'Preview' |
|
659 |
#name: 'PreviewBox' |
|
660 |
#layout: #(#LayoutFrame 2 0.0 2 0.0 -2 1.0 -2 1.0) |
|
661 |
#level: -1 |
|
662 |
#translateLabel: true |
|
663 |
) |
|
664 |
) |
|
665 |
||
666 |
) |
|
1816 | 667 |
) |
668 |
#(#HorizontalPanelViewSpec |
|
669 |
#name: 'HorizontalPanel1' |
|
670 |
#layout: #(#LayoutFrame 0 0.0 -32 1 0 1.0 0 1.0) |
|
671 |
#horizontalLayout: #fitSpace |
|
672 |
#verticalLayout: #centerMax |
|
673 |
#horizontalSpace: 3 |
|
674 |
#verticalSpace: 3 |
|
675 |
#reverseOrderIfOKAtLeft: true |
|
676 |
#component: |
|
677 |
#(#SpecCollection |
|
678 |
#collection: #( |
|
679 |
#(#ActionButtonSpec |
|
680 |
#label: 'Cancel' |
|
681 |
#name: 'CancelButton' |
|
682 |
#translateLabel: true |
|
683 |
#resizeForLabel: false |
|
684 |
#tabable: true |
|
685 |
#model: #cancel |
|
686 |
#useDefaultExtent: true |
|
687 |
) |
|
688 |
#(#ActionButtonSpec |
|
689 |
#label: 'OK' |
|
690 |
#name: 'OKButton' |
|
691 |
#translateLabel: true |
|
692 |
#resizeForLabel: false |
|
693 |
#tabable: true |
|
694 |
#model: #accept |
|
695 |
#isDefault: true |
|
696 |
#defaultable: true |
|
697 |
#useDefaultExtent: true |
|
698 |
) |
|
699 |
) |
|
700 |
||
701 |
) |
|
702 |
) |
|
2045 | 703 |
#(#InputFieldSpec |
704 |
#name: 'ColorNameField' |
|
705 |
#layout: #(#LayoutFrame 110 0 190 0 -123 1 212 0) |
|
706 |
#model: #colorNameHolder |
|
707 |
#immediateAccept: true |
|
708 |
#acceptOnReturn: true |
|
709 |
#acceptOnTab: true |
|
710 |
#acceptOnLostFocus: true |
|
711 |
#acceptOnPointerLeave: false |
|
712 |
) |
|
713 |
#(#LabelSpec |
|
714 |
#label: 'Color Name:' |
|
715 |
#name: 'Label4' |
|
716 |
#layout: #(#LayoutFrame 0 0 190 0 106 0 212 0) |
|
717 |
#translateLabel: true |
|
718 |
#adjust: #right |
|
719 |
) |
|
1816 | 720 |
) |
721 |
||
722 |
) |
|
1057 | 723 |
) |
724 |
! ! |
|
725 |
||
726 |
!ColorMenu::DefineColor methodsFor:'accessing'! |
|
727 |
||
728 |
color |
|
2045 | 729 |
^Color redByte:(red value) greenByte:(green value) blueByte:(blue value) |
1057 | 730 |
! |
731 |
||
732 |
color: aColor |
|
733 |
||
734 |
aColor notNil |
|
735 |
ifTrue: |
|
736 |
[ |
|
737 |
self red value: aColor redByte. |
|
738 |
self green value: aColor greenByte. |
|
739 |
self blue value: aColor blueByte. |
|
740 |
] |
|
741 |
||
2045 | 742 |
! |
743 |
||
744 |
colorName |
|
745 |
^ colorNameHolder value |
|
746 |
! ! |
|
747 |
||
748 |
!ColorMenu::DefineColor methodsFor:'actions'! |
|
749 |
||
750 |
colorChanged |
|
751 |
|box clr| |
|
752 |
||
2167
675c1cd59a80
builder componentAt: -> self componentAt:
Claus Gittinger <cg@exept.de>
parents:
2057
diff
changeset
|
753 |
box := self componentAt: #PreviewBox. |
2057 | 754 |
box isNil ifTrue:[^ self "called before setup"]. |
755 |
||
2045 | 756 |
clr := self color. |
757 |
box backgroundColor:clr. |
|
758 |
||
759 |
clr brightness < 0.5 ifTrue:[ |
|
760 |
box foregroundColor:Color white |
|
761 |
] ifFalse:[ |
|
762 |
box foregroundColor:Color black |
|
763 |
]. |
|
764 |
! |
|
765 |
||
766 |
colorNameChanged |
|
767 |
"compute rgb and hls (if possible)" |
|
768 |
||
769 |
|clr h| |
|
770 |
||
771 |
clr := Color name:colorNameHolder value ifIllegal:nil. |
|
772 |
clr isNil ifTrue:[ |
|
773 |
^ self |
|
774 |
]. |
|
775 |
||
776 |
red value:clr redByte withoutNotifying:self. |
|
777 |
green value:clr greenByte withoutNotifying:self. |
|
778 |
blue value:clr blueByte withoutNotifying:self. |
|
779 |
||
780 |
h := clr hue. |
|
781 |
h notNil ifTrue:[ |
|
782 |
hue value:(h rounded) withoutNotifying:self. |
|
783 |
]. |
|
784 |
light value:(clr light rounded) withoutNotifying:self. |
|
785 |
saturation value:(clr saturation rounded) withoutNotifying:self. |
|
786 |
||
787 |
self colorChanged |
|
788 |
! |
|
789 |
||
790 |
hlsSliderChanged |
|
791 |
"compute rgb" |
|
792 |
||
793 |
Color withRGBFromHue:hue value light:light value saturation:saturation value do:[:r :g :b | |
|
794 |
red value:(r * 255 / 100) rounded withoutNotifying:self. |
|
795 |
green value:(g * 255 / 100) rounded withoutNotifying:self. |
|
796 |
blue value:(b * 255 / 100) rounded withoutNotifying:self. |
|
797 |
]. |
|
798 |
colorNameHolder value:'' withoutNotifying:self. |
|
799 |
self colorChanged |
|
800 |
! |
|
801 |
||
802 |
rgbSliderChanged |
|
803 |
"compute hls" |
|
804 |
||
805 |
|r g b| |
|
806 |
||
2057 | 807 |
r := self red value. |
808 |
g := self green value. |
|
809 |
b := self blue value. |
|
2045 | 810 |
|
811 |
Color withHLSFromRed:(r * 100 / 255) green:(g * 100 / 255) blue:(b * 100 / 255) do:[:h :l :s | |
|
812 |
h isNil ifTrue:[ |
|
813 |
"/ achromatic |
|
814 |
] ifFalse:[ |
|
2057 | 815 |
self hue value:(h rounded) withoutNotifying:self. |
2045 | 816 |
]. |
2057 | 817 |
self light value:(l rounded) withoutNotifying:self. |
818 |
self saturation value:(s rounded) withoutNotifying:self. |
|
2045 | 819 |
]. |
2057 | 820 |
self colorNameHolder value:'' withoutNotifying:self. |
2045 | 821 |
self colorChanged |
1057 | 822 |
! ! |
823 |
||
824 |
!ColorMenu::DefineColor methodsFor:'aspects'! |
|
825 |
||
826 |
blue |
|
827 |
blue isNil ifTrue:[ |
|
2045 | 828 |
blue := 0 asValue. |
829 |
blue addDependent:self. |
|
1057 | 830 |
]. |
831 |
^blue |
|
832 |
! |
|
833 |
||
2045 | 834 |
colorNameHolder |
835 |
colorNameHolder isNil ifTrue:[ |
|
836 |
colorNameHolder := '' asValue. |
|
837 |
colorNameHolder addDependent:self. |
|
838 |
]. |
|
839 |
^colorNameHolder |
|
840 |
! |
|
1057 | 841 |
|
2045 | 842 |
green |
1057 | 843 |
green isNil ifTrue:[ |
2045 | 844 |
green := 0 asValue. |
845 |
green addDependent:self. |
|
1057 | 846 |
]. |
847 |
^green |
|
848 |
! |
|
849 |
||
2045 | 850 |
hue |
851 |
hue isNil ifTrue:[ |
|
852 |
hue := 0 asValue. |
|
853 |
hue addDependent:self. |
|
854 |
]. |
|
855 |
^hue |
|
856 |
! |
|
1057 | 857 |
|
2045 | 858 |
light |
859 |
light isNil ifTrue:[ |
|
860 |
light := 0 asValue. |
|
861 |
light addDependent:self. |
|
862 |
]. |
|
863 |
^light |
|
864 |
! |
|
865 |
||
866 |
red |
|
1057 | 867 |
red isNil ifTrue:[ |
2045 | 868 |
red := 0 asValue. |
869 |
red addDependent:self. |
|
1057 | 870 |
]. |
871 |
^red |
|
2045 | 872 |
! |
873 |
||
874 |
saturation |
|
875 |
saturation isNil ifTrue:[ |
|
876 |
saturation := 0 asValue. |
|
877 |
saturation addDependent:self. |
|
878 |
]. |
|
879 |
^saturation |
|
880 |
! ! |
|
881 |
||
882 |
!ColorMenu::DefineColor methodsFor:'change & update'! |
|
883 |
||
884 |
update:something with:aParameter from:changedObject |
|
885 |
(changedObject == red |
|
886 |
or:[changedObject == green |
|
887 |
or:[changedObject == blue]]) ifTrue:[ |
|
888 |
^ self rgbSliderChanged |
|
889 |
]. |
|
890 |
||
891 |
(changedObject == hue |
|
892 |
or:[changedObject == light |
|
893 |
or:[changedObject == saturation]]) ifTrue:[ |
|
894 |
^ self hlsSliderChanged |
|
895 |
]. |
|
896 |
||
897 |
(changedObject == colorNameHolder) ifTrue:[ |
|
898 |
^ self colorNameChanged |
|
899 |
]. |
|
900 |
||
901 |
^ super update:something with:aParameter from:changedObject |
|
1057 | 902 |
! ! |
903 |
||
904 |
!ColorMenu::DefineColor methodsFor:'startup / release'! |
|
905 |
||
906 |
postBuildWith:aBuilder |
|
907 |
super postBuildWith:aBuilder. |
|
2045 | 908 |
self colorChanged. |
1057 | 909 |
|
1119
11cd3ce5171b
colorMenu: change labelColor to white for dark preview colors;
Claus Gittinger <cg@exept.de>
parents:
1058
diff
changeset
|
910 |
"Modified: / 6.9.1998 / 22:55:25 / cg" |
1057 | 911 |
! ! |
912 |
||
412 | 913 |
!ColorMenu class methodsFor:'documentation'! |
914 |
||
915 |
version |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
916 |
^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.28 2002-09-12 13:32:18 cg Exp $' |
412 | 917 |
! ! |