IDL 中的新颜色选择器
原文链接: https://www.nv5geospatialsoftware.com/Learn/Blogs/Blog-Details/new-color-picker-in-idl
8209 为文章评分:
5.0
IDL 中的新颜色选择器
Anonym 2015年8月13日,星期四
IDL 8.5 引入了一个新的颜色选择器,它不仅用于组件属性表(Widget Property Sheet),用户也可以通过编程方式轻松调用对话框来选取颜色。
以下是一个将被放入属性表中用于选取颜色的对象示例:
pro propsheet_color::SetProperty, BASE_COLOR=baseColor, OUTLINE_COLOR=outlineColor, _REF_EXTRA=extra
if N_Elements(baseColor) eq 3 then begin
self.baseColor = baseColor
endif
if N_Elements(outlineColor) eq 3 then begin
self.outlineColor = outlineColor
endif
if N_Elements(extra) gt 0 then begin
self.IDLitComponent::SetProperty, _EXTRA=extra
endif
end
pro propsheet_color::GetProperty, BASE_COLOR=baseColor, OUTLINE_COLOR=outlineColor, _REF_EXTRA=extra
if Arg_Present(baseColor) then begin
baseColor = self.baseColor
endif
if Arg_Present(outlineColor) then begin
outlineColor = self.outlineColor
endif
if N_Elements(extra) gt 0 then begin
self.IDLitComponent::GetProperty, _EXTRA=extra
endif
end
pro propsheet_color__Define
!null = {propsheet_color, $
inherits IDLitComponent, $
baseColor:[0b,0b,0b], $
outlineColor:[0b,0b,0b]}
end
要使用此对象创建组件(widget),可调用以下代码(这是一个非常基础的示例;属性表可以嵌入到更复杂的组件中):
o = Obj_New('propsheet_color')
o.RegisterProperty, 'BASE_COLOR', /COLOR, NAME='Base Color'
o.RegisterProperty, 'OUTLINE_COLOR', /COLOR, NAME='Outline Color'
base = Widget_Base()
propsheet = Widget_Propertysheet(base, VALUE=o)
Widget_Control, base, /REALIZE
当用户点击其中一个颜色时,组件显示如下:

你也可以直接从 IDL 命令行或代码中调用颜色选择器:
result = dialog_colorpicker(TITLE='Pick Fill')

此函数提供了多个关键字(keywords)来控制大小、自定义颜色、添加回调对象等。
返回值将是一个包含三个元素的字节数组,分别代表红、绿、蓝的值。
下次你需要选择颜色时,不妨试试它!