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