The DIALOG_COLORPICKER function allows you to interactively select a color using a selection dialog. The basic dialog grid includes 64 standard colors. You can set custom and preferred colors using keywords.
Examples
Open the Select Color dialog. Type:
result = DIALOG_COLORPICKER()
This opens the generic Select Color dialog.
Additional Examples
See Additional Examples for additional examples using the DIALOG_COLORPICKER function.
Syntax
Result = DIALOG_COLORPICKER( [, BOX_SIZE=variable] [, COLORS=array] [, CUSTOM_COLORS=array] [, CUSTOM_TITLE=string] [, CUSTOM_OUT=variable] [, DIALOG_PARENT=widget_id] [, /FRAMELESS] [, INITIAL_COLOR=value] [, /MODAL] [, NCOLS=variable] [, NROWS=variable] [, PREFERRED_COLORS=array] [, PREFERRED_TITLE=string] [, TITLE=string] [, WCALLER=variable] [, XOFFSET=variable] [, YOFFSET=variable]
Return Value
DIALOG_COLORPICKER returns the color that was chosen as a three-element vector containing the RGB color.
Keywords
BOX_SIZE
Set the size, in pixels, of each color swatch.
COLORS
To override the 64 colors in the default basic grid with different colors, specify the colors to use in the primary color grid area. This is a 3 x n array, where n is the number of RGB triplets for the colors.
CUSTOM_COLORS
Set this keyword to an array or list of custom colors. This is a 3 x n array, where n is the number of RGB triplets for the colors. If CUSTOM_COLORS is a list, each element must be a three-element vector containing an RGB color.
CUSTOM_TITLE
Set this keyword to a string giving the title of the custom color section.
CUSTOM_OUT
Set this keyword to a named variable that will contain the new array of custom colors if a new custom color was added.
DIALOG_PARENT
Set this keyword to the widget ID of a widget to be used as the parent of this dialog.
FRAMELESS
If set, this dialog will not have a window frame around it. This keyword is ignored if MODAL is set.
Note: This is a suggestion to the windowing system and may be ignored.
INITIAL_COLOR
Set this keyword to a 3-element vector containing the initial RGB color selection. This keyword is useful for specifying a default color.
MODAL
If set, this dialog will be modal. This keyword is ignored if WCALLER is not set. If this keyword is set, FRAMELESS will be ignored.
NCOLS
Specify the number of columns in the color grid. The default is 8.
NROWS
Specify the number of rows in the color grid. The default is 8.
PREFERRED_COLORS
Set an array of preferred colors. This is a 3 x n array, where n is the R,G,B values for the color. These colors will appear in a separate line above the primary system color area.
PREFERRED_TITLE
Set this keyword to a string giving the title of the preferred color section.
TITLE
Set this keyword to a scalar string to be used for the dialog title. If it is not specified, the default title is "Select Color."
WCALLER
If set to the Widget ID of the calling widget, this dialog will try to position itself just below the calling widget. If the calling widget is modal, this will also set the FRAMELESS and MODAL keywords to this dialog. If XOFFSET or YOFFSET are set they will override any positioning based on the calling widget.
XOFFSET
The X offset of the widget in pixels, relative to the screen.
YOFFSET
The Y offset of the widget in pixels, relative to the screen.
Additional Examples
This example shows the use of the WCALLER keyword. By passing the widget ID of the widget button used to call the DIALOG_COLORPICKER, the dialog will appear just below the button.
pro dcp_test_event, ev
wText = WIDGET_INFO(ev.top, FIND_BY_UNAME='text')
WIDGET_CONTROL, wText, SET_VALUE='No color selected'
color = DIALOG_COLORPICKER(WCALLER=ev.id)
if (color.length eq 3) then $
WIDGET_CONTROL, wText, $
SET_VALUE='Color: [' + (color.toString()).join(',') + ']'
end
pro dcp_test
wTlb = WIDGET_BASE(/COLUMN)
wButton = WIDGET_BUTTON(wTlb, value='Select Color')
wText = WIDGET_TEXT(wTlb, value='', XSIZE=50, UNAME='text')
WIDGET_CONTROL, wTlb, /REALIZE
xmanager, 'dcp_test', wTlb, /NO_BLOCK
end
Version History
8.5 |
Introduced |
8.5.1 |
Added INITIAL_COLOR keyword.
|
See Also
COLOR_CONVERT