1 | ;+ |
---|
2 | ; |
---|
3 | ; @file_comments |
---|
4 | ; Choose the best foreground and background colors for |
---|
5 | ; the current color maps and set !P appropriately. |
---|
6 | ; |
---|
7 | ; @returns |
---|
8 | ; 1 if the colors changed, 0 otherwise. |
---|
9 | r; |
---|
10 | ; @hidden |
---|
11 | ; |
---|
12 | ;- |
---|
13 | ; |
---|
14 | function xp_new_colors |
---|
15 | ; |
---|
16 | compile_opt idl2, strictarrsubs |
---|
17 | ; |
---|
18 | common xp_com, xpw, state |
---|
19 | |
---|
20 | res = 0 |
---|
21 | junk = CT_LUMINANCE(dark=dark_col, bright=bright_col) |
---|
22 | |
---|
23 | if (bright_col ne !p.color) then begin |
---|
24 | !p.color = bright_col |
---|
25 | res = 1 |
---|
26 | endif |
---|
27 | |
---|
28 | if (dark_col ne !p.background) then begin |
---|
29 | !p.background = dark_col |
---|
30 | res = 1 |
---|
31 | endif |
---|
32 | |
---|
33 | return, res |
---|
34 | end |
---|
35 | |
---|
36 | ;+ |
---|
37 | ; @hidden |
---|
38 | ;- |
---|
39 | pro xp_alert_caller |
---|
40 | ; |
---|
41 | compile_opt idl2, strictarrsubs |
---|
42 | ; |
---|
43 | |
---|
44 | common xp_com, xpw, state |
---|
45 | |
---|
46 | ErrorStatus = 0 |
---|
47 | CATCH, ErrorStatus |
---|
48 | if (ErrorStatus NE 0) then begin |
---|
49 | CATCH, /CANCEL |
---|
50 | v = DIALOG_MESSAGE(['Unexpected error in XPAL:', $ |
---|
51 | '!ERR_STRING = ' + !ERR_STRING], $ |
---|
52 | /ERROR) |
---|
53 | return |
---|
54 | endif |
---|
55 | if (STRLEN(state.updt_callback) gt 0) then begin |
---|
56 | if (PTR_VALID(state.p_updt_cb_data)) then begin |
---|
57 | CALL_PROCEDURE, state.updt_callback, DATA=*(state.p_updt_cb_data) |
---|
58 | endif else begin |
---|
59 | CALL_PROCEDURE, state.updt_callback |
---|
60 | endelse |
---|
61 | endif |
---|
62 | end |
---|
63 | ; XP_XLCTCALLBACK: For visuals with static colormaps, update the graphics |
---|
64 | ; after a change by XLOADCT. |
---|
65 | ;+ |
---|
66 | ; @hidden |
---|
67 | ;- |
---|
68 | pro xp_xlctcallback |
---|
69 | ; |
---|
70 | compile_opt idl2, strictarrsubs |
---|
71 | ; |
---|
72 | if ((COLORMAP_APPLICABLE(redrawRequired) GT 0) and $ |
---|
73 | (redrawRequired GT 0)) then begin |
---|
74 | XP_REDRAW |
---|
75 | endif |
---|
76 | |
---|
77 | end |
---|
78 | |
---|
79 | ;+ |
---|
80 | ; @hidden |
---|
81 | ;- |
---|
82 | pro xp_redraw |
---|
83 | ; |
---|
84 | compile_opt idl2, strictarrsubs |
---|
85 | ; |
---|
86 | |
---|
87 | common xp_com, xpw, state |
---|
88 | |
---|
89 | junk = XP_NEW_COLORS() |
---|
90 | WIDGET_CONTROL, xpw.colorsel, set_value=-1 |
---|
91 | XP_REPLOT, !p.color, 'F' ; Update the plots of RGB |
---|
92 | ; Let the caller of XPAL know that the color table was modified |
---|
93 | XP_ALERT_CALLER |
---|
94 | end |
---|
95 | |
---|
96 | ; XP_REPLOT: Re-draw the RGB plots. Type has the following possible values. |
---|
97 | ; - 'D': Draw the data part of all three plots |
---|
98 | ; - 'F': draw all three plots |
---|
99 | ; - 'R': Draw the data part of the Red plot |
---|
100 | ; - 'G': Draw the data part of the Green plot |
---|
101 | ; - 'B': Draw the data part of the Blue plot |
---|
102 | ;+ |
---|
103 | ; @param color_index |
---|
104 | ; ??? |
---|
105 | ; @param type |
---|
106 | ; ??? |
---|
107 | ; |
---|
108 | ; @hidden |
---|
109 | ;- |
---|
110 | pro xp_replot, color_index, type |
---|
111 | ; |
---|
112 | compile_opt idl2, strictarrsubs |
---|
113 | ; |
---|
114 | |
---|
115 | common xp_com, xpw, state |
---|
116 | common colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr |
---|
117 | common pscale, r_x_s, r_y_s, g_x_s, g_y_s, b_x_s, b_y_s |
---|
118 | |
---|
119 | ; Update the plots of RGB |
---|
120 | save_win = !D.WINDOW |
---|
121 | wset, state.plot_win |
---|
122 | save_p_region = !p.region |
---|
123 | save_x_margin = !x.margin |
---|
124 | save_y_margin = !y.margin |
---|
125 | save_x_s = !x.s |
---|
126 | save_y_s = !y.s |
---|
127 | save_x_type = !x.type |
---|
128 | save_y_type = !y.type |
---|
129 | |
---|
130 | !y.margin= [2, 2] |
---|
131 | !x.margin= [6, 2] |
---|
132 | |
---|
133 | if (type eq 'F') then begin |
---|
134 | !p.region = [0,.6667, 1, 1] |
---|
135 | plot,xstyle=2, ystyle=3, yrange=[0, 260], r_curr, title='Red' |
---|
136 | r_x_s = !x.s |
---|
137 | r_y_s = !y.s |
---|
138 | |
---|
139 | !p.region = [0,.333, 1, .6667] |
---|
140 | plot,/noerase, xstyle=2,ystyle=3, yrange=[0, 260], g_curr, title='Green' |
---|
141 | g_x_s = !x.s |
---|
142 | g_y_s = !y.s |
---|
143 | |
---|
144 | !p.region = [0,0, 1, .333] |
---|
145 | plot,/noerase, xstyle=2,ystyle=3, yrange=[0, 260], b_curr, title='Blue' |
---|
146 | |
---|
147 | b_x_s = !x.s |
---|
148 | b_y_s = !y.s |
---|
149 | endif else begin |
---|
150 | if ((type eq 'D') or (type eq 'R')) then begin |
---|
151 | !p.region = [0,.6667, 1, 1] |
---|
152 | !x.s = r_x_s |
---|
153 | !y.s = r_y_s |
---|
154 | oplot, r_curr, color=color_index |
---|
155 | endif |
---|
156 | if ((type eq 'D') or (type eq 'G')) then begin |
---|
157 | !p.region = [0,.333, 1, .6667] |
---|
158 | !x.s = g_x_s |
---|
159 | !y.s = g_y_s |
---|
160 | oplot, g_curr, color=color_index |
---|
161 | endif |
---|
162 | if ((type eq 'D') or (type eq 'B')) then begin |
---|
163 | !p.region = [0,0, 1, .333] |
---|
164 | !x.s = b_x_s |
---|
165 | !y.s = b_y_s |
---|
166 | oplot, b_curr, color=color_index |
---|
167 | endif |
---|
168 | endelse |
---|
169 | |
---|
170 | empty |
---|
171 | WSET, save_win |
---|
172 | !p.region = save_p_region |
---|
173 | !x.margin = save_x_margin |
---|
174 | !y.margin = save_y_margin |
---|
175 | !x.s = save_x_s |
---|
176 | !y.s = save_y_s |
---|
177 | !x.type = save_x_type |
---|
178 | !y.type = save_y_type |
---|
179 | |
---|
180 | end |
---|
181 | |
---|
182 | |
---|
183 | |
---|
184 | ; XP_CHANGE_COLOR: Change current color. Type has the following possible values. |
---|
185 | ; - 'R': Change the R part of the current color |
---|
186 | ; - 'G': ... |
---|
187 | ; - 'B': ... |
---|
188 | ;+ |
---|
189 | ; |
---|
190 | ; @param type |
---|
191 | ; ??? |
---|
192 | ; @param value |
---|
193 | ; ??? |
---|
194 | ; |
---|
195 | ; @hidden |
---|
196 | ;- |
---|
197 | pro xp_change_color, type, value |
---|
198 | ; |
---|
199 | compile_opt idl2, strictarrsubs |
---|
200 | ; |
---|
201 | common xp_com, xpw, state |
---|
202 | common colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr |
---|
203 | |
---|
204 | |
---|
205 | cur_idx = state.cur_idx |
---|
206 | |
---|
207 | XP_REPLOT, !p.background, type |
---|
208 | |
---|
209 | if (type eq 'R') then r_curr[cur_idx] = value; |
---|
210 | if (type eq 'G') then g_curr[cur_idx] = value; |
---|
211 | if (type eq 'B') then b_curr[cur_idx] = value; |
---|
212 | |
---|
213 | tvlct, r_curr[cur_idx], g_curr[cur_idx], b_curr[cur_idx], cur_idx |
---|
214 | |
---|
215 | if (XP_NEW_COLORS()) then begin |
---|
216 | ; Highlight the current position using the marker |
---|
217 | WIDGET_CONTROL, xpw.colorsel, set_value=-1 ; Re-initialize |
---|
218 | XP_REPLOT, !p.color, 'F' |
---|
219 | endif else begin |
---|
220 | XP_REPLOT, !p.color, type |
---|
221 | endelse |
---|
222 | |
---|
223 | ; For visuals with static colormaps, update the graphics |
---|
224 | ; of the current color. |
---|
225 | if ((COLORMAP_APPLICABLE(redrawRequired) GT 0) and $ |
---|
226 | (redrawRequired GT 0)) then begin |
---|
227 | ; Mark new square |
---|
228 | tmp = !D.WINDOW |
---|
229 | wset, state.cur_color_win |
---|
230 | erase, color=state.cur_idx |
---|
231 | wset, tmp |
---|
232 | endif |
---|
233 | |
---|
234 | ; Let the caller of XPAL know that the color table was modified |
---|
235 | xp_alert_caller |
---|
236 | |
---|
237 | end |
---|
238 | ;+ |
---|
239 | ; @param event |
---|
240 | ; ??? |
---|
241 | ; @hidden |
---|
242 | ;- |
---|
243 | pro xp_button_event, event |
---|
244 | ; |
---|
245 | compile_opt idl2, strictarrsubs |
---|
246 | ; |
---|
247 | |
---|
248 | common xp_com, xpw, state |
---|
249 | common colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr |
---|
250 | |
---|
251 | ; NOTE: The value of these tags depend on the order of the buttons |
---|
252 | ; in the base. |
---|
253 | case (event.value) of |
---|
254 | |
---|
255 | ; DONE |
---|
256 | 0: begin |
---|
257 | empty |
---|
258 | r_orig = r_curr & g_orig = g_curr & b_orig = b_curr ;new orig color tbl |
---|
259 | WIDGET_CONTROL, /DESTROY, event.top |
---|
260 | !p = state.old_p |
---|
261 | end |
---|
262 | |
---|
263 | ; PREDEFINED |
---|
264 | 1: xlct, /silent, group=xpw.base, UPDATECALLBACK='XP_XLCTCALLBACK' |
---|
265 | |
---|
266 | ; HELP |
---|
267 | 2: XDisplayFile, FILEPATH("xpal.txt", subdir=['help', 'widget']), $ |
---|
268 | TITLE = "Xpal Help", GROUP = event.top, WIDTH = 55, HEIGHT = 16 |
---|
269 | |
---|
270 | ; REDRAW |
---|
271 | 3: XP_REDRAW |
---|
272 | |
---|
273 | ; SET MARK |
---|
274 | 4: begin |
---|
275 | state.mark_idx = state.cur_idx |
---|
276 | WIDGET_CONTROL, xpw.mark_label, $ |
---|
277 | set_value=strcompress(state.mark_idx, /REMOVE) |
---|
278 | end |
---|
279 | |
---|
280 | ; SWITCH MARK |
---|
281 | 5 : if (state.mark_idx ne state.cur_idx) then begin |
---|
282 | tmp = state.mark_idx |
---|
283 | state.mark_idx = state.cur_idx |
---|
284 | state.cur_idx = tmp |
---|
285 | WIDGET_CONTROL, xpw.colorsel, set_value=tmp |
---|
286 | WIDGET_CONTROL, xpw.idx_label, $ |
---|
287 | set_value=strcompress(state.cur_idx, /REMOVE) |
---|
288 | WIDGET_CONTROL, xpw.mark_label, $ |
---|
289 | set_value=strcompress(state.mark_idx, /REMOVE) |
---|
290 | endif |
---|
291 | |
---|
292 | ; COPY CURRENT |
---|
293 | 6 : begin |
---|
294 | do_copy: |
---|
295 | cur_idx = state.cur_idx |
---|
296 | if (state.mark_idx le cur_idx) then begin |
---|
297 | s = state.mark_idx |
---|
298 | e = cur_idx |
---|
299 | endif else begin |
---|
300 | s = cur_idx |
---|
301 | e = state.mark_idx |
---|
302 | endelse |
---|
303 | n = e-s+1 |
---|
304 | XP_REPLOT, !p.background, 'D' |
---|
305 | if (event.value eq 6) then begin |
---|
306 | r_curr[s:e] = r_curr[cur_idx] |
---|
307 | g_curr[s:e] = g_curr[cur_idx] |
---|
308 | b_curr[s:e] = b_curr[cur_idx] |
---|
309 | endif else begin ; Interpolate |
---|
310 | scale = findgen(n)/float(n-1) |
---|
311 | r_curr[s:e] = r_curr[s] + (fix(r_curr[e]) - fix(r_curr[s])) * scale |
---|
312 | g_curr[s:e] = g_curr[s] + (fix(g_curr[e]) - fix(g_curr[s])) * scale |
---|
313 | b_curr[s:e] = b_curr[s] + (fix(b_curr[e]) - fix(b_curr[s])) * scale |
---|
314 | endelse |
---|
315 | tvlct, r_curr[s:e], g_curr[s:e], b_curr[s:e], s |
---|
316 | if (XP_NEW_COLORS()) then begin |
---|
317 | WIDGET_CONTROL, xpw.colorsel, SET_VALUE=-1 |
---|
318 | XP_REPLOT, !p.color, 'F' |
---|
319 | endif else begin |
---|
320 | XP_REPLOT, !p.color, 'D' |
---|
321 | endelse |
---|
322 | ; Let the caller of XPAL know that the color table was modified |
---|
323 | xp_alert_caller |
---|
324 | end |
---|
325 | |
---|
326 | 7: goto, do_copy |
---|
327 | 8: BEGIN |
---|
328 | COMMON basecommon, bas212, bas222, bas232 |
---|
329 | base = WIDGET_BASE(/COLUMN, /FRAME) |
---|
330 | bas1 = WIDGET_LABEL(base, value = 'Save') |
---|
331 | bas2 = WIDGET_BASE(base, /COLUMN) |
---|
332 | bas21 = WIDGET_BASE(bas2, /COLUMN) |
---|
333 | bas211 = WIDGET_LABEL(bas21, value = 'Palette Name : ') |
---|
334 | bas212 = WIDGET_TEXT(bas21, value = 'Noname', /editable) |
---|
335 | bas22 = WIDGET_BASE(bas2, /COLUMN) |
---|
336 | bas221 = WIDGET_LABEL(bas22, value = ' Overwrite palette number : ') |
---|
337 | bas222 = WIDGET_TEXT(bas22, value = '', /editable) |
---|
338 | bas23 = WIDGET_BASE(bas2, /COLUMN) |
---|
339 | bas231 = WIDGET_LABEL(bas23, value = 'file name : ') |
---|
340 | bas232 = WIDGET_TEXT(bas23, value = 'palette.tbl', /editable) |
---|
341 | bas3 = WIDGET_BASE(base, /ROW) |
---|
342 | ok = WIDGET_BUTTON(bas3, value = 'OK',$ |
---|
343 | /ALIGN_LEFT, /FRAME, UVALUE = 'ok') |
---|
344 | cancel = WIDGET_BUTTON(bas3, value = 'CANCEL',$ |
---|
345 | /ALIGN_RIGHT, /FRAME, UVALUE = 'cancel') |
---|
346 | WIDGET_CONTROL, base, /REALIZE |
---|
347 | ; WIDGET_CONTROL, base, SET_UVALUE = drawID |
---|
348 | XMANAGER, 'xp_button_event', base |
---|
349 | |
---|
350 | |
---|
351 | |
---|
352 | END |
---|
353 | else: |
---|
354 | endcase |
---|
355 | |
---|
356 | end |
---|
357 | |
---|
358 | ;+ |
---|
359 | ; @hidden |
---|
360 | ; @param ev |
---|
361 | ; ??? |
---|
362 | ;- |
---|
363 | PRO xp_button_event_event, ev |
---|
364 | ; |
---|
365 | compile_opt idl2, strictarrsubs |
---|
366 | ; |
---|
367 | COMMON basecommon, bas212, bas222, bas232 |
---|
368 | WIDGET_CONTROL, ev.id, GET_UVALUE = uval |
---|
369 | IF(TAG_NAMES(ev, /STRUCTURE_NAME) EQ 'WIDGET_BUTTON')$ |
---|
370 | THEN BEGIN |
---|
371 | CASE uval OF |
---|
372 | 'ok' :BEGIN |
---|
373 | WIDGET_CONTROL, bas212, GET_VALUE = palname |
---|
374 | WIDGET_CONTROL, bas222, GET_VALUE = over |
---|
375 | WIDGET_CONTROL, bas232, GET_VALUE = fichname |
---|
376 | if over[0] EQ '' then over = 255 ELSE over = long(over) |
---|
377 | newpalette,palname[0], OVER = over[0], file = fichname[0] |
---|
378 | WIDGET_CONTROL, ev.top, /DESTROY |
---|
379 | END |
---|
380 | 'cancel': WIDGET_CONTROL, ev.top, /DESTROY |
---|
381 | ENDCASE |
---|
382 | ENDIF |
---|
383 | |
---|
384 | END |
---|
385 | |
---|
386 | |
---|
387 | |
---|
388 | |
---|
389 | ;+ |
---|
390 | ; @param event |
---|
391 | ; ??? |
---|
392 | ; @hidden |
---|
393 | ;- |
---|
394 | |
---|
395 | pro xp_event, event |
---|
396 | ; |
---|
397 | compile_opt idl2, strictarrsubs |
---|
398 | ; |
---|
399 | |
---|
400 | common xp_com, xpw, state |
---|
401 | common colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr |
---|
402 | |
---|
403 | case (event.id) of |
---|
404 | |
---|
405 | xpw.button_base: XP_BUTTON_EVENT, event |
---|
406 | |
---|
407 | xpw.rgb_base: begin |
---|
408 | cur_idx = state.cur_idx |
---|
409 | if (event.r ne r_curr[cur_idx]) then XP_CHANGE_COLOR, "R", event.r |
---|
410 | if (event.g ne g_curr[cur_idx]) then XP_CHANGE_COLOR, "G", event.g |
---|
411 | if (event.b ne b_curr[cur_idx]) then XP_CHANGE_COLOR, "B", event.b |
---|
412 | end |
---|
413 | |
---|
414 | xpw.colorsel: begin |
---|
415 | cur_idx = state.cur_idx |
---|
416 | new_pos = event.value ne cur_idx |
---|
417 | ; Update the RBG sliders |
---|
418 | if (event.value ne cur_idx) then begin |
---|
419 | state.cur_idx = (cur_idx = event.value) |
---|
420 | WIDGET_CONTROL, xpw.idx_label, $ |
---|
421 | set_value=strcompress(cur_idx, /REMOVE_ALL) |
---|
422 | ; Mark new square |
---|
423 | tmp = !D.WINDOW |
---|
424 | wset, state.cur_color_win |
---|
425 | erase, color=cur_idx |
---|
426 | wset, tmp |
---|
427 | |
---|
428 | WIDGET_CONTROL, xpw.rgb_base, $ |
---|
429 | set_value=[r_curr[cur_idx], g_curr[cur_idx], b_curr[cur_idx]] |
---|
430 | endif |
---|
431 | end |
---|
432 | |
---|
433 | else: |
---|
434 | endcase |
---|
435 | |
---|
436 | END |
---|
437 | |
---|
438 | ;+ |
---|
439 | ; |
---|
440 | ; @file_comments |
---|
441 | ; like xpalette but shorter to write and, moreover, |
---|
442 | ; possess a hotkey save which (thanks to the newpalette routine) |
---|
443 | ; allows to save the routine that we have just done. Comment: when we |
---|
444 | ; press the predefined hotkey, it calls xlct instead of xloadct |
---|
445 | ; No explicit inputs. The current color table is used as a starting point. |
---|
446 | ; |
---|
447 | ; @categories |
---|
448 | ; Color, Widget |
---|
449 | ; |
---|
450 | ; @uses XP_COM: Private to this module. |
---|
451 | ; |
---|
452 | ; @restrictions |
---|
453 | ; XPAL uses two colors from the current color table as |
---|
454 | ; drawing foreground and background colors. These are used |
---|
455 | ; for the RGB plots on the left, and the current index marker on |
---|
456 | ; the right. This means that if the user set these two colors |
---|
457 | ; to the same value, the XPAL display could become unreadable |
---|
458 | ; (like writing on black paper with black ink). XPAL minimizes |
---|
459 | ; this possibility by noting changes to the color map and always |
---|
460 | ; using the brightest available color for the foreground color |
---|
461 | ; and the darkest for the background. Thus, the only way |
---|
462 | ; to make XPAL's display unreadable is to set the entire color |
---|
463 | ; map to a single color, which is highly unlikely. The only side |
---|
464 | ; effect of this policy is that you may notice XPAL redrawing |
---|
465 | ; the entire display after you've modified the current color. |
---|
466 | ; This simply means that the change has made XPAL pick new |
---|
467 | ; drawing colors. |
---|
468 | ; |
---|
469 | ; The new color tables are saved in the COLORS common and loaded |
---|
470 | ; to the display. |
---|
471 | ; |
---|
472 | ; @examples |
---|
473 | ; The XPAL widget has the following controls: |
---|
474 | ; |
---|
475 | ; Left: Three plots showing the current Red, Green, and Blue vectors. |
---|
476 | ; |
---|
477 | ; Center: A status region containing: |
---|
478 | ; 1) The total number of colors. |
---|
479 | ; 2) The current color. XPAL allows changing |
---|
480 | ; one color at a time. This color is known as |
---|
481 | ; the "current color" and is indicated in the |
---|
482 | ; color spectrum display with a special marker. |
---|
483 | ; 3) The current mark index. The mark is used to |
---|
484 | ; remember a color index. It is established by |
---|
485 | ; pressing the "Set Mark Button" while the current |
---|
486 | ; color index is the desired mark index. |
---|
487 | ; 4) The current color. The special marker used in |
---|
488 | ; color spectrum display prevents the user from seeing |
---|
489 | ; the color of the current index, but it is visible |
---|
490 | ; here. |
---|
491 | ; |
---|
492 | ; A panel of control buttons, which do the following when |
---|
493 | ; pressed: |
---|
494 | ; |
---|
495 | ; Done: Exits XPAL. |
---|
496 | ; |
---|
497 | ; Predefined: Starts XLOADCT to allow selection of one of the |
---|
498 | ; predefined color tables. |
---|
499 | ; |
---|
500 | ; Help: Supplies help information similar to this header. |
---|
501 | ; |
---|
502 | ; Redraw: Completely redraws the display using the current |
---|
503 | ; state of the color map. |
---|
504 | ; |
---|
505 | ; Set Mark: Set the value of the mark index to the |
---|
506 | ; current index. |
---|
507 | ; |
---|
508 | ; Switch Mark: Exchange the mark and the current index. |
---|
509 | ; |
---|
510 | ; Copy Current: Every color lying between the current |
---|
511 | ; index and the mark index (inclusive) is given |
---|
512 | ; the current color. |
---|
513 | ; |
---|
514 | ; Interpolate: The colors lying between the current |
---|
515 | ; index and the mark index are interpolated linearly |
---|
516 | ; to lie between the colors of two endpoints. |
---|
517 | ; save: Allows to save the palette which is currently |
---|
518 | ; on the screen. When we press this hotkey, there is a |
---|
519 | ; widget who appear and ask: |
---|
520 | ; 1) the name of the palette we want to save. |
---|
521 | ; 2) The number of the palette we may want to erase |
---|
522 | ; by the new palette. If there is not any number |
---|
523 | ; specified, the new palette is add to elders. |
---|
524 | ; 3) The name of the file containing palettes. |
---|
525 | ; Comment: May follow instructions gave by the prompter. |
---|
526 | ; |
---|
527 | ; |
---|
528 | ; Three sliders (R, G, and B) that allow the user to modify the |
---|
529 | ; current color. |
---|
530 | ; |
---|
531 | ; Right: A display which shows the current color map as a series of |
---|
532 | ; squares. Color index 0 is at the upper left. The color index |
---|
533 | ; increases monotonically by rows going left to right and top |
---|
534 | ; to bottom. The current color index is indicated by a special |
---|
535 | ; marker symbol. There are 4 ways to change the current color: |
---|
536 | ; 1) Press any mouse button while the mouse |
---|
537 | ; pointer is over the color map display. |
---|
538 | ; 2) Use the "By Index" slider to move to |
---|
539 | ; the desired color index. |
---|
540 | ; 3) Use the "Row" Slider to move the marker |
---|
541 | ; vertically. |
---|
542 | ; 4) Use the "Column" Slider to move the marker |
---|
543 | ; horizontally. |
---|
544 | ; |
---|
545 | ; @keyword GROUP |
---|
546 | ; The widget ID of the widget that calls xpal. When this ID is |
---|
547 | ; specified, a death of the caller results in a death of xpal |
---|
548 | ; |
---|
549 | ; @keyword BLOCK {default=1} |
---|
550 | ; Set this keyword to have XMANAGER block when this |
---|
551 | ; application is registered. By default the Xmanager |
---|
552 | ; keyword NO_BLOCK is set to 1 to provide access to the |
---|
553 | ; command line if active command line processing is available. |
---|
554 | ; Note that setting BLOCK for this application will cause |
---|
555 | ; all widget applications to block, not only this |
---|
556 | ; application. For more information see the NO_BLOCK keyword |
---|
557 | ; to XMANAGER. |
---|
558 | ; |
---|
559 | ; @keyword UPDATECALLBACK |
---|
560 | ; Set this keyword to a string containing the name of |
---|
561 | ; a user-supplied procedure that will be called when the color |
---|
562 | ; table is updated by XLOADCT. The procedure may optionally |
---|
563 | ; accept a keyword called DATA, which will be automatically |
---|
564 | ; set to the value specified by the optional UPDATECBDATA |
---|
565 | ; keyword. |
---|
566 | ; |
---|
567 | ; @keyword UPDATECBDATA |
---|
568 | ; Set this keyword to a value of any type. It will be |
---|
569 | ; passed via the DATA keyword to the user-supplied procedure |
---|
570 | ; specified via the UPDATECALLBACK keyword, if any. If the |
---|
571 | ; UPDATECBDATA keyword is not set the value accepted by the |
---|
572 | ; DATA keyword to the procedure specified by UPDATECALLBACK |
---|
573 | ; will be undefined. |
---|
574 | ; |
---|
575 | ; @history |
---|
576 | ; Adaptation of xpalette to add a save button by |
---|
577 | ; Grima Nicolas (nglod\@ipsl.jussieu.fr) and by Masson |
---|
578 | ; Sebastien (smlod\@ipsl.jussieu.fr) |
---|
579 | ; |
---|
580 | ; @version |
---|
581 | ; $Id$ |
---|
582 | ; |
---|
583 | ;- |
---|
584 | pro xpal, GROUP=group, BLOCK=block, UPDATECALLBACK=updt_cb_name, $ |
---|
585 | UPDATECBDATA=updt_cb_data |
---|
586 | ; |
---|
587 | compile_opt idl2, strictarrsubs |
---|
588 | ; |
---|
589 | |
---|
590 | |
---|
591 | common xp_com, xpw, state |
---|
592 | common colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr |
---|
593 | |
---|
594 | IF N_ELEMENTS(updt_cb_name) EQ 0 THEN updt_callback="" $ |
---|
595 | ELSE updt_callback=updt_cb_name |
---|
596 | IF N_ELEMENTS(updt_cb_data) GT 0 THEN p_updt_cb_data=PTR_NEW(updt_cb_data) $ |
---|
597 | ELSE p_updt_cb_data=PTR_NEW() |
---|
598 | |
---|
599 | xpw = { xp_widgets, base:0L, $ |
---|
600 | colorsel:0L, mark_label:0L, idx_label:0L, button_base:0L, rgb_base:0L} |
---|
601 | |
---|
602 | state = {old_p:!p, $ ; Original value of !P |
---|
603 | mark_idx:0, $ ; Current mark index |
---|
604 | cur_idx:0, $ ; Current index |
---|
605 | cur_color_win:0, $ ; Current Color draw window index |
---|
606 | plot_win:0, $ ; RGB plot draw window index |
---|
607 | updt_callback: updt_callback, $ ; user-defined callback (optional) |
---|
608 | p_updt_cb_data:p_updt_cb_data} ; data for callback (optional) |
---|
609 | |
---|
610 | if (XREGISTERED('XPAL')) then return ; Only one copy at a time |
---|
611 | |
---|
612 | IF N_ELEMENTS(block) EQ 0 THEN block=0 |
---|
613 | |
---|
614 | on_error,2 ;Return to caller if an error occurs |
---|
615 | |
---|
616 | nc = !d.table_size ;# of colors avail |
---|
617 | if nc eq 0 then message, "Device has static color tables. Can't modify." |
---|
618 | if (nc eq 2) then message, 'Unable to work with monochrome system.' |
---|
619 | |
---|
620 | state.old_p = !p ;Save !p |
---|
621 | !p.noclip = 1 ;No clipping |
---|
622 | !p.color = nc -1 ;Foreground color |
---|
623 | !p.font = 0 ;Hdw font |
---|
624 | save_win = !d.window ;Previous window |
---|
625 | |
---|
626 | IF N_ELEMENTS(r_orig) LE 0 THEN BEGIN ;If no common, use current colors |
---|
627 | TVLCT, r_orig, g_orig, b_orig, /GET |
---|
628 | r_curr = r_orig |
---|
629 | b_curr = b_orig |
---|
630 | g_curr = g_orig |
---|
631 | ENDIF |
---|
632 | |
---|
633 | ; Create widgets |
---|
634 | xpw.base=WIDGET_BASE(title='Xpal', /ROW, space=30) |
---|
635 | ; This is a little tricky. Setting the managed attribute indicates |
---|
636 | ; our intention to put this app under the control of XMANAGER, and |
---|
637 | ; prevents our draw widgets from becoming candidates for becoming |
---|
638 | ; the default window on WSET, -1. XMANAGER sets this, but doing it here |
---|
639 | ; prevents our own WSETs at startup from having that problem. |
---|
640 | WIDGET_CONTROL, /MANAGED, xpw.base |
---|
641 | |
---|
642 | version = WIDGET_INFO(/VERSION) |
---|
643 | if (version.style='Motif') then junk=510 else junk = 580 |
---|
644 | plot_frame = WIDGET_DRAW(xpw.base, xsize=200, ysize=junk) |
---|
645 | |
---|
646 | c1 = WIDGET_BASE(xpw.base, /COLUMN, space=20) |
---|
647 | status = WIDGET_BASE(c1, /COLUMN, /FRAME) |
---|
648 | ncw = WIDGET_LABEL(WIDGET_BASE(status), /DYNAMIC_RESIZE) |
---|
649 | xpw.idx_label = CW_FIELD(status, title='Current Index: ', value='0', $ |
---|
650 | xsize=20, /STRING) |
---|
651 | xpw.mark_label = CW_FIELD(status, title='Mark Index: ', value='0', $ |
---|
652 | xsize=20, /STRING) |
---|
653 | c1_1 = widget_base(status, /ROW) |
---|
654 | junk = WIDGET_LABEL(c1_1, value="Current Color: ") |
---|
655 | cur_color = WIDGET_DRAW(c1_1, xsize = 125, ysize=50, /frame) |
---|
656 | names = [ 'Done', 'Predefined', 'Help', 'Redraw', 'Set Mark', $ |
---|
657 | 'Switch Mark', 'Copy Current', 'Interpolate', 'save'] |
---|
658 | xpw.button_base = CW_BGROUP(c1, names, COLUMN=3, /FRAME) |
---|
659 | xpw.rgb_base = CW_RGBSLIDER(c1, /FRAME, /DRAG) |
---|
660 | |
---|
661 | junk = WIDGET_BASE(xpw.base) ; Responds to YOFFSET |
---|
662 | if (version.style='Motif') then junk2=30 else junk2 = 50 |
---|
663 | xpw.colorsel = CW_COLORSEL(junk, yoffset=junk2) |
---|
664 | |
---|
665 | state.cur_idx = 0 |
---|
666 | state.mark_idx = 0 |
---|
667 | |
---|
668 | ; Position RGB slider appropriately |
---|
669 | WIDGET_CONTROL, xpw.rgb_base, SET_VALUE=[r_curr[0], g_curr[0], b_curr[0]] |
---|
670 | WIDGET_CONTROL, /REALIZE, xpw.base |
---|
671 | |
---|
672 | WIDGET_CONTROL, ncw, $ |
---|
673 | set_value='Number Of Colors: ' + strcompress(!d.n_colors, /REMOVE_ALL) |
---|
674 | WIDGET_CONTROL, get_value=tmp, cur_color |
---|
675 | state.cur_color_win = tmp |
---|
676 | WIDGET_CONTROL, get_value=tmp, plot_frame |
---|
677 | state.plot_win = tmp |
---|
678 | |
---|
679 | |
---|
680 | ; Update the plots of RGB |
---|
681 | junk = XP_NEW_COLORS() |
---|
682 | XP_REPLOT, !p.color, 'F' |
---|
683 | |
---|
684 | WSET, save_win |
---|
685 | |
---|
686 | XMANAGER, 'Xpal', xpw.base, event_handler='XP_EVENT', group=group, $ |
---|
687 | NO_BLOCK=(NOT(FLOAT(block))) |
---|
688 | end |
---|