WoColorGrid Function
Creates a grid of color squares from the current color table.
Usage
widget = WoColorGrid(parent)
Input Parameters
parent — A string containing the widget ID of the parent widget.
Returned Value
widget — The widget ID of the color grid.
Keywords
Title — Specifies a string containing the title of the color grid.
Model — Specifies a string containing the color model used for the color grid ('RGB', 'HLS', or 'HSV').
Range — A 2-element integer array specifying the range of color values in the color grid. The default range is [0, (!D.Table_Size – 1)].
Area — If present and nonzero, the drawing area widget ID is returned.
Num_Columns — An integer specifying the number of columns in the color grid. The default configuration is a square grid, where the number of rows and columns is equal.
Cell_Size — A 2-element integer array specifying the size of each color cell, in pixels. The cells must be square. By default, the cells are 20-by-20 pixels.
Attachment Keywords
Bottom — If a widget ID is specified (for example, Bottom=wid), then the bottom of the color grid is attached to the top of the specified widget. If no widget ID is specified (for example, /Bottom), then the bottom of the color grid is attached to the bottom of the parent widget.
Left — If a widget ID is specified (for example, Left=wid), then the left side of the color grid is attached to the right side of the specified widget. If no widget ID is specified (for example, /Left), then the left side of the color grid is attached to the left side of the parent widget.
Right — If a widget ID is specified (for example, Right=wid), then the right side of the color grid is attached to the left side of the specified widget. If no widget ID is specified (for example, /Right), then the right side of the color grid is attached to the right side of the parent widget.
Top — If a widget ID is specified (for example, Top=wid), then the top of the color grid is attached to the bottom of the specified widget. If no widget ID is specified (for example, /Top), then the top of the color grid is attached to the top of the parent widget.
Discussion
This function is used by the WzColorEdit VDA Tool and by the WoColorButton function.
Example
This example code displays a color grid with a button that allows you to cycle through different color hues.
; This is the callback that is called when the "Cycle" or "Quit"
; button is pressed. If "Cycle" is pressed, the hues in the color
; grid are incremented so the colors will change. If the "Quit"
; button is pressed, the shell is destroyed.
PRO ButtonCB, wid, which
DECLARE FUNC, WoColorGridGetValue
; Get the user data that was set earlier.
cb_data = WwGetValue (wid, /Userdata)
CASE which OF
1: BEGIN ; Cycle
; Get the currently-displayed colors.
colors = WoColorGridGetValue (cb_data.grid, 0, $
cb_data.num_colors)
; Add to the hues, so the colors will change. If the new
; values are greater than 360, set them back to a reason
; able value by subtracting 360.
new_hues = colors(0, *) + cb_data.num_colors
too_big_indices = WHERE(new_hues GE 360)
ndim_too_big = SIZE(too_big_indices, /Ndim)
IF ndim_too_big GT 0 THEN $
new_hues(too_big_indices) = $
new_hues(too_big_indices) - 360
colors(0, *) = new_hues
; Change the colors displayed in the color grid.
WoColorGridSetValue, cb_data.grid, 0, colors
END
2: BEGIN ; Quit
status = WwSetValue (cb_data.top, /Close)
END
ENDCASE
END
; This procedure demonstrates the use of the WoColorGrid,
; WoColorGridSetValue, and WoColorGridGetValue functions. It
; displays a shell window containing a color grid, and allows the
; user to cycle the color hues by pressing the "Cycle" button.
PRO WoColorGrid_test
DECLARE FUNC, WoColorGrid
; Load the bottom of the color table with interesting colors.
; tek_color. We'll display 20 colors in the color grid.
num_colors = 20
; Initialize Wave Widgets, and create the color grid and the
; push buttons. Note that we’re using HLS as the color model
; for the color grid.
top = WwInit ('WoColorGrid_test', 'wocolorgrid_test', $
layout, /Vertical, title = 'Color Grid Test')
grid = WoColorGrid (layout, Title = 'Color Grid', $
Model = 'HLS', Range = [0, (num_colors - 1)])
button_wid = WwButtonBox (layout, ['Cycle', 'Quit'], $
'ButtonCB', buttons = buttons)
; Attach user data to the buttons, so we can access it from
; the button callback.
cb_data = {, top: top, grid: grid, num_colors: num_colors}
FOR i=0L, (N_ELEMENTS(buttons)-1) DO BEGIN
status = WwSetValue (buttons(i), Userdata = cb_data)
ENDFOR
; Display the color grid.
status = WwSetValue (top, /Display)
WwLoop, /NoBlock
END