|
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 "{ Package: 'stx:libtool2' }" |
|
14 |
|
15 SimpleDialog subclass:#ColorEditDialog |
|
16 instanceVariableNames:'red green blue hue light saturation colorNameHolder' |
|
17 classVariableNames:'' |
|
18 poolDictionaries:'' |
|
19 category:'Interface-UIPainter' |
|
20 ! |
|
21 |
|
22 !ColorEditDialog class methodsFor:'documentation'! |
|
23 |
|
24 copyright |
|
25 " |
|
26 COPYRIGHT (c) 1995 by eXept Software AG |
|
27 All Rights Reserved |
|
28 |
|
29 This software is furnished under a license and may be used |
|
30 only in accordance with the terms of that license and with the |
|
31 inclusion of the above copyright notice. This software may not |
|
32 be provided or otherwise made available to, or used by, any |
|
33 other person. No title to or ownership of the software is |
|
34 hereby transferred. |
|
35 " |
|
36 ! |
|
37 |
|
38 documentation |
|
39 " |
|
40 An edit-dialog for colors. |
|
41 " |
|
42 ! |
|
43 |
|
44 examples |
|
45 " |
|
46 [exBegin] |
|
47 |editor color| |
|
48 |
|
49 editor := ColorEditor new. |
|
50 editor color:(Color green). |
|
51 editor open. |
|
52 editor accepted ifTrue:[ |
|
53 editor color inspect. |
|
54 ] |
|
55 [exEnd] |
|
56 " |
|
57 ! ! |
|
58 |
|
59 !ColorEditDialog class methodsFor:'interface specs'! |
|
60 |
|
61 windowSpec |
|
62 "This resource specification was automatically generated |
|
63 by the UIPainter of ST/X." |
|
64 |
|
65 "Do not manually edit this!! If it is corrupted, |
|
66 the UIPainter may not be able to read the specification." |
|
67 |
|
68 " |
|
69 UIPainter new openOnClass:ColorEditor andSelector:#windowSpec |
|
70 ColorEditor new openInterface:#windowSpec |
|
71 ColorEditor open |
|
72 " |
|
73 |
|
74 <resource: #canvas> |
|
75 |
|
76 ^ |
|
77 #(FullSpec |
|
78 name: windowSpec |
|
79 window: |
|
80 (WindowSpec |
|
81 label: 'Define Color' |
|
82 name: 'Define Color' |
|
83 min: (Point 340 260) |
|
84 max: (Point nil 260) |
|
85 bounds: (Rectangle 0 0 453 260) |
|
86 ) |
|
87 component: |
|
88 (SpecCollection |
|
89 collection: ( |
|
90 (VerticalPanelViewSpec |
|
91 name: 'RGBLabelPanel' |
|
92 layout: (LayoutFrame 0 0 0 0 58 0 76 0) |
|
93 horizontalLayout: fit |
|
94 verticalLayout: spreadSpace |
|
95 horizontalSpace: 3 |
|
96 verticalSpace: 3 |
|
97 component: |
|
98 (SpecCollection |
|
99 collection: ( |
|
100 (LabelSpec |
|
101 label: 'Red:' |
|
102 name: 'RedLabel' |
|
103 translateLabel: true |
|
104 adjust: right |
|
105 useDefaultExtent: true |
|
106 ) |
|
107 (LabelSpec |
|
108 label: 'Green:' |
|
109 name: 'GreenLabel' |
|
110 translateLabel: true |
|
111 adjust: right |
|
112 useDefaultExtent: true |
|
113 ) |
|
114 (LabelSpec |
|
115 label: 'Blue:' |
|
116 name: 'BlueLabel' |
|
117 translateLabel: true |
|
118 adjust: right |
|
119 useDefaultExtent: true |
|
120 ) |
|
121 ) |
|
122 |
|
123 ) |
|
124 ) |
|
125 (VerticalPanelViewSpec |
|
126 name: 'RGBSliderPanel' |
|
127 layout: (LayoutFrame 62 0 0 0 -166 1 76 0) |
|
128 horizontalLayout: fit |
|
129 verticalLayout: spreadSpace |
|
130 horizontalSpace: 3 |
|
131 verticalSpace: 3 |
|
132 component: |
|
133 (SpecCollection |
|
134 collection: ( |
|
135 (SliderSpec |
|
136 name: 'RedSlider' |
|
137 tabable: false |
|
138 model: red |
|
139 orientation: horizontal |
|
140 stop: 255 |
|
141 step: 1 |
|
142 backgroundColor: (Color 100.0 0.0 0.0) |
|
143 extent: (Point 225 16) |
|
144 ) |
|
145 (SliderSpec |
|
146 name: 'GreenSlider' |
|
147 tabable: false |
|
148 model: green |
|
149 orientation: horizontal |
|
150 stop: 255 |
|
151 step: 1 |
|
152 backgroundColor: (Color 0.0 100.0 0.0) |
|
153 extent: (Point 225 16) |
|
154 ) |
|
155 (SliderSpec |
|
156 name: 'BlueSlider' |
|
157 tabable: false |
|
158 model: blue |
|
159 orientation: horizontal |
|
160 stop: 255 |
|
161 step: 1 |
|
162 backgroundColor: (Color 0.0 0.0 100.0) |
|
163 extent: (Point 225 16) |
|
164 ) |
|
165 ) |
|
166 |
|
167 ) |
|
168 ) |
|
169 (VerticalPanelViewSpec |
|
170 name: 'RGBFieldPanel' |
|
171 layout: (LayoutFrame -161 1 0 0 -123 1 76 0) |
|
172 horizontalLayout: fit |
|
173 verticalLayout: spreadSpace |
|
174 horizontalSpace: 3 |
|
175 verticalSpace: 3 |
|
176 component: |
|
177 (SpecCollection |
|
178 collection: ( |
|
179 (InputFieldSpec |
|
180 name: 'RedField' |
|
181 model: red |
|
182 type: numberInRange |
|
183 numChars: 3 |
|
184 minValue: 0 |
|
185 maxValue: 255 |
|
186 acceptOnPointerLeave: false |
|
187 extent: (Point 38 20) |
|
188 ) |
|
189 (InputFieldSpec |
|
190 name: 'GreenField' |
|
191 model: green |
|
192 type: numberInRange |
|
193 numChars: 3 |
|
194 minValue: 0 |
|
195 maxValue: 255 |
|
196 acceptOnPointerLeave: false |
|
197 extent: (Point 38 20) |
|
198 ) |
|
199 (InputFieldSpec |
|
200 name: 'BlueField' |
|
201 model: blue |
|
202 type: numberInRange |
|
203 numChars: 3 |
|
204 minValue: 0 |
|
205 maxValue: 255 |
|
206 acceptOnPointerLeave: false |
|
207 extent: (Point 38 20) |
|
208 ) |
|
209 ) |
|
210 |
|
211 ) |
|
212 ) |
|
213 (VerticalPanelViewSpec |
|
214 name: 'HLSLabelPanel' |
|
215 layout: (LayoutFrame 0 0 86 0 58 0 163 0) |
|
216 horizontalLayout: fit |
|
217 verticalLayout: spreadSpace |
|
218 horizontalSpace: 3 |
|
219 verticalSpace: 3 |
|
220 component: |
|
221 (SpecCollection |
|
222 collection: ( |
|
223 (LabelSpec |
|
224 label: 'Hue:' |
|
225 name: 'Label1' |
|
226 translateLabel: true |
|
227 adjust: right |
|
228 useDefaultExtent: true |
|
229 ) |
|
230 (LabelSpec |
|
231 label: 'Light:' |
|
232 name: 'Label2' |
|
233 translateLabel: true |
|
234 adjust: right |
|
235 useDefaultExtent: true |
|
236 ) |
|
237 (LabelSpec |
|
238 label: 'Sat:' |
|
239 name: 'Label3' |
|
240 translateLabel: true |
|
241 adjust: right |
|
242 useDefaultExtent: true |
|
243 ) |
|
244 ) |
|
245 |
|
246 ) |
|
247 ) |
|
248 (VerticalPanelViewSpec |
|
249 name: 'HLSSliderPanel' |
|
250 layout: (LayoutFrame 62 0 86 0 -166 1 163 0) |
|
251 horizontalLayout: fit |
|
252 verticalLayout: spreadSpace |
|
253 horizontalSpace: 3 |
|
254 verticalSpace: 3 |
|
255 component: |
|
256 (SpecCollection |
|
257 collection: ( |
|
258 (SliderSpec |
|
259 name: 'Slider1' |
|
260 tabable: false |
|
261 model: hue |
|
262 orientation: horizontal |
|
263 stop: 359 |
|
264 step: 1 |
|
265 keyboardStep: 1 |
|
266 extent: (Point 225 16) |
|
267 ) |
|
268 (SliderSpec |
|
269 name: 'Slider2' |
|
270 tabable: false |
|
271 model: light |
|
272 orientation: horizontal |
|
273 step: 1 |
|
274 backgroundColor: (Color 66.9993 66.9993 66.9993) |
|
275 keyboardStep: 1 |
|
276 extent: (Point 225 16) |
|
277 ) |
|
278 (SliderSpec |
|
279 name: 'Slider3' |
|
280 tabable: false |
|
281 model: saturation |
|
282 orientation: horizontal |
|
283 step: 1 |
|
284 backgroundColor: (Color 66.9993 66.9993 66.9993) |
|
285 keyboardStep: 1 |
|
286 extent: (Point 225 16) |
|
287 ) |
|
288 ) |
|
289 |
|
290 ) |
|
291 ) |
|
292 (VerticalPanelViewSpec |
|
293 name: 'HLSFieldPanel' |
|
294 layout: (LayoutFrame -161 1 86 0 -123 1 163 0) |
|
295 horizontalLayout: fit |
|
296 verticalLayout: spreadSpace |
|
297 horizontalSpace: 3 |
|
298 verticalSpace: 3 |
|
299 component: |
|
300 (SpecCollection |
|
301 collection: ( |
|
302 (InputFieldSpec |
|
303 name: 'EntryField1' |
|
304 model: hue |
|
305 type: numberInRange |
|
306 numChars: 3 |
|
307 minValue: 0 |
|
308 maxValue: 359 |
|
309 acceptOnPointerLeave: false |
|
310 extent: (Point 38 20) |
|
311 ) |
|
312 (InputFieldSpec |
|
313 name: 'EntryField2' |
|
314 model: light |
|
315 type: numberInRange |
|
316 numChars: 3 |
|
317 minValue: 0 |
|
318 maxValue: 100 |
|
319 acceptOnPointerLeave: false |
|
320 extent: (Point 38 20) |
|
321 ) |
|
322 (InputFieldSpec |
|
323 name: 'EntryField3' |
|
324 model: saturation |
|
325 type: numberInRange |
|
326 numChars: 3 |
|
327 minValue: 0 |
|
328 maxValue: 100 |
|
329 acceptOnPointerLeave: false |
|
330 extent: (Point 38 20) |
|
331 ) |
|
332 ) |
|
333 |
|
334 ) |
|
335 ) |
|
336 (ViewSpec |
|
337 name: 'Box1' |
|
338 layout: (LayoutFrame -117 1 4 0.0 -3 1.0 -39 1.0) |
|
339 level: 1 |
|
340 component: |
|
341 (SpecCollection |
|
342 collection: ( |
|
343 (LabelSpec |
|
344 label: 'Preview' |
|
345 name: 'PreviewBox' |
|
346 layout: (LayoutFrame 2 0.0 2 0.0 -2 1.0 -2 1.0) |
|
347 level: -1 |
|
348 translateLabel: true |
|
349 ) |
|
350 ) |
|
351 |
|
352 ) |
|
353 ) |
|
354 (LabelSpec |
|
355 label: 'Color Name:' |
|
356 name: 'ColorNameLabel' |
|
357 layout: (LayoutFrame 0 0 190 0 106 0 212 0) |
|
358 translateLabel: true |
|
359 adjust: right |
|
360 ) |
|
361 (InputFieldSpec |
|
362 name: 'ColorNameField' |
|
363 layout: (LayoutFrame 110 0 190 0 -123 1 212 0) |
|
364 model: colorNameHolder |
|
365 immediateAccept: true |
|
366 acceptOnReturn: true |
|
367 acceptOnTab: true |
|
368 acceptOnLostFocus: true |
|
369 acceptOnPointerLeave: false |
|
370 ) |
|
371 (HorizontalPanelViewSpec |
|
372 name: 'HorizontalPanel1' |
|
373 layout: (LayoutFrame 0 0.0 -32 1 0 1.0 0 1.0) |
|
374 horizontalLayout: fitSpace |
|
375 verticalLayout: centerMax |
|
376 horizontalSpace: 3 |
|
377 verticalSpace: 3 |
|
378 reverseOrderIfOKAtLeft: true |
|
379 component: |
|
380 (SpecCollection |
|
381 collection: ( |
|
382 (ActionButtonSpec |
|
383 label: 'Cancel' |
|
384 name: 'CancelButton' |
|
385 translateLabel: true |
|
386 resizeForLabel: false |
|
387 tabable: true |
|
388 model: cancel |
|
389 useDefaultExtent: true |
|
390 ) |
|
391 (ActionButtonSpec |
|
392 label: 'OK' |
|
393 name: 'OKButton' |
|
394 translateLabel: true |
|
395 resizeForLabel: false |
|
396 tabable: true |
|
397 model: accept |
|
398 isDefault: true |
|
399 defaultable: true |
|
400 useDefaultExtent: true |
|
401 ) |
|
402 ) |
|
403 |
|
404 ) |
|
405 ) |
|
406 ) |
|
407 |
|
408 ) |
|
409 ) |
|
410 ! ! |
|
411 |
|
412 !ColorEditDialog methodsFor:'accessing'! |
|
413 |
|
414 color |
|
415 ^Color redByte:(red value) greenByte:(green value) blueByte:(blue value) |
|
416 ! |
|
417 |
|
418 color:aColor |
|
419 aColor notNil ifTrue:[ |
|
420 self red value:aColor redByte. |
|
421 self green value:aColor greenByte. |
|
422 self blue value:aColor blueByte. |
|
423 ] |
|
424 ! |
|
425 |
|
426 colorName |
|
427 ^ colorNameHolder value |
|
428 ! ! |
|
429 |
|
430 !ColorEditDialog methodsFor:'actions'! |
|
431 |
|
432 colorChanged |
|
433 |box clr| |
|
434 |
|
435 box := self componentAt: #PreviewBox. |
|
436 box isNil ifTrue:[^ self "called before setup"]. |
|
437 |
|
438 clr := self color. |
|
439 box backgroundColor:clr. |
|
440 box foregroundColor:(clr brightness < 0.5 |
|
441 ifTrue:[Color white] |
|
442 ifFalse:[Color black]). |
|
443 ! |
|
444 |
|
445 colorNameChanged |
|
446 "compute rgb and hls (if possible)" |
|
447 |
|
448 |clr h| |
|
449 |
|
450 clr := Color name:colorNameHolder value ifIllegal:nil. |
|
451 clr isNil ifTrue:[ |
|
452 ^ self |
|
453 ]. |
|
454 |
|
455 red value:clr redByte withoutNotifying:self. |
|
456 green value:clr greenByte withoutNotifying:self. |
|
457 blue value:clr blueByte withoutNotifying:self. |
|
458 |
|
459 h := clr hue. |
|
460 h notNil ifTrue:[ |
|
461 hue value:(h rounded) withoutNotifying:self. |
|
462 ]. |
|
463 light value:(clr light rounded) withoutNotifying:self. |
|
464 saturation value:(clr saturation rounded) withoutNotifying:self. |
|
465 |
|
466 self colorChanged |
|
467 ! |
|
468 |
|
469 hlsSliderChanged |
|
470 "compute rgb" |
|
471 |
|
472 Color withRGBFromHue:hue value light:light value saturation:saturation value do:[:r :g :b | |
|
473 red value:(r * 255 / 100) rounded withoutNotifying:self. |
|
474 green value:(g * 255 / 100) rounded withoutNotifying:self. |
|
475 blue value:(b * 255 / 100) rounded withoutNotifying:self. |
|
476 ]. |
|
477 colorNameHolder value:'' withoutNotifying:self. |
|
478 self colorChanged |
|
479 ! |
|
480 |
|
481 rgbSliderChanged |
|
482 "compute hls" |
|
483 |
|
484 |r g b| |
|
485 |
|
486 r := self red value. |
|
487 g := self green value. |
|
488 b := self blue value. |
|
489 |
|
490 Color withHLSFromRed:(r * 100 / 255) green:(g * 100 / 255) blue:(b * 100 / 255) do:[:h :l :s | |
|
491 h isNil ifTrue:[ |
|
492 "/ achromatic |
|
493 ] ifFalse:[ |
|
494 self hue value:(h rounded) withoutNotifying:self. |
|
495 ]. |
|
496 self light value:(l rounded) withoutNotifying:self. |
|
497 self saturation value:(s rounded) withoutNotifying:self. |
|
498 ]. |
|
499 self colorNameHolder value:'' withoutNotifying:self. |
|
500 self colorChanged |
|
501 ! ! |
|
502 |
|
503 !ColorEditDialog methodsFor:'aspects'! |
|
504 |
|
505 blue |
|
506 blue isNil ifTrue:[ |
|
507 blue := 0 asValue. |
|
508 blue addDependent:self. |
|
509 ]. |
|
510 ^blue |
|
511 ! |
|
512 |
|
513 colorNameHolder |
|
514 colorNameHolder isNil ifTrue:[ |
|
515 colorNameHolder := '' asValue. |
|
516 colorNameHolder addDependent:self. |
|
517 ]. |
|
518 ^colorNameHolder |
|
519 ! |
|
520 |
|
521 green |
|
522 green isNil ifTrue:[ |
|
523 green := 0 asValue. |
|
524 green addDependent:self. |
|
525 ]. |
|
526 ^green |
|
527 ! |
|
528 |
|
529 hue |
|
530 hue isNil ifTrue:[ |
|
531 hue := 0 asValue. |
|
532 hue addDependent:self. |
|
533 ]. |
|
534 ^hue |
|
535 ! |
|
536 |
|
537 light |
|
538 light isNil ifTrue:[ |
|
539 light := 0 asValue. |
|
540 light addDependent:self. |
|
541 ]. |
|
542 ^light |
|
543 ! |
|
544 |
|
545 red |
|
546 red isNil ifTrue:[ |
|
547 red := 0 asValue. |
|
548 red addDependent:self. |
|
549 ]. |
|
550 ^red |
|
551 ! |
|
552 |
|
553 saturation |
|
554 saturation isNil ifTrue:[ |
|
555 saturation := 0 asValue. |
|
556 saturation addDependent:self. |
|
557 ]. |
|
558 ^saturation |
|
559 ! ! |
|
560 |
|
561 !ColorEditDialog methodsFor:'change & update'! |
|
562 |
|
563 update:something with:aParameter from:changedObject |
|
564 (changedObject == red |
|
565 or:[changedObject == green |
|
566 or:[changedObject == blue]]) ifTrue:[ |
|
567 ^ self rgbSliderChanged |
|
568 ]. |
|
569 |
|
570 (changedObject == hue |
|
571 or:[changedObject == light |
|
572 or:[changedObject == saturation]]) ifTrue:[ |
|
573 ^ self hlsSliderChanged |
|
574 ]. |
|
575 |
|
576 (changedObject == colorNameHolder) ifTrue:[ |
|
577 ^ self colorNameChanged |
|
578 ]. |
|
579 |
|
580 ^ super update:something with:aParameter from:changedObject |
|
581 ! ! |
|
582 |
|
583 !ColorEditDialog methodsFor:'startup & release'! |
|
584 |
|
585 postBuildWith:aBuilder |
|
586 super postBuildWith:aBuilder. |
|
587 self colorChanged. |
|
588 |
|
589 "Modified: / 6.9.1998 / 22:55:25 / cg" |
|
590 ! ! |
|
591 |
|
592 !ColorEditDialog class methodsFor:'documentation'! |
|
593 |
|
594 version |
|
595 ^ '$Header$' |
|
596 ! ! |