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