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