ColourPicker

References
public sealed class ColourPicker : IResponsive
Represents the core functionality of the Grasshopper colour picker.

Constructors

ColourPicker

#
public ColourPicker(PickerLayout layout, Color colour)
Create a new colour picker, centered on a specific colour using the most recent model and palette constraints.
layout (PickerLayout)Ui layout.
colour (Color)Initial colour.

ColourPicker

#
public ColourPicker(PickerLayout layout, Colour colour, Space space, string palette, bool discrete)
Create a new colour picker, centered on a specific colour.
layout (PickerLayout)Ui layout.
colour (Colour)Initial colour.
space (Space)Space override.
palette (string)Palette override.
discrete (bool)Discrete mode override.

ColourPicker

#
public ColourPicker(PickerLayout layout, Colour colour)
Create a new colour picker, centered on a specific colour using the most recent model and palette constraints.
layout (PickerLayout)Ui layout.
colour (Colour)Initial colour.

Fields

ButtonSize

#
public const int ButtonSize = 32
Specifies the height of the Accept/Revert buttons.

ButtonSpacing

#
public const int ButtonSpacing = 5
The spacing between the sliders and the buttons.

DiagramSize

#
public const int DiagramSize = 300
Specifies the ideal width and height of the colour space diagram.

LabelSize

#
public const int LabelSize = 20
Specifies the height of a textual label.

SamplerSize

#
public const int SamplerSize = 24
Specifies the radius of the sampler button.

SliderSize

#
public const int SliderSize = 22
Specifies the height of channel sliders.

ToolbarSize

#
public const int ToolbarSize = 24
Specifies the height of toolbars and buttons.

Properties

AcceptButton

#
public RectangleF AcceptButton { get; }
Gets the region for the Accept button.

AcceptButtonInfo

#
public string AcceptButtonInfo { get; set; }
Gets or set the text for the accept button tooltip.

AcceptButtonText

#
public string AcceptButtonText { get; set; }
Gets or sets the text on the accept button.

AvailableSpaces

#
public IEnumerable<Space> AvailableSpaces { get; }
Enumerate over all colour spaces available in this picker.

Bounds

#
public RectangleF Bounds { get; }
Gets the bounding rectangle for all UI elements in the picker.

Channel1

#
public RectangleF Channel1 { get; }
Gets the bounding rectangle for the first channel slider.

Channel2

#
public RectangleF Channel2 { get; }
Gets the bounding rectangle for the second channel slider.

Channel3

#
public RectangleF Channel3 { get; }
Gets the bounding rectangle for the third channel slider.

ChannelA

#
public RectangleF ChannelA { get; }
Gets the bounding rectangle for the alpha channel slider.

ChildResponsives

#
public IEnumerable<IResponsive> ChildResponsives { get; }
Sliders this picker hosts as standalone responsive children. The hosting control should register each of these as an IResponsive so the FlexControl dispatcher routes slider drags through their own Responsive instances instead of going through the picker.

ColourInfo

#
public RectangleF ColourInfo { get; }
Gets the bounding rectangle of the colour code label.

CurrentColour

#
public Colour CurrentColour { get; }
Gets the currently selected colour within the current colour model. This does not take discretisation into account. You *probably* want to use the ImpliedColour property.

Diagram

#
public RectangleF Diagram { get; }
Gets the bounding rectangle of the colour space diagram.

DisplayDiscrete

#
public bool DisplayDiscrete { get; set; }
Gets or sets whether to limit the colours in the model space to the currently loaded palette.

Format

#
public ColourPickerFormat Format { get; set; }
Gets or sets the textual format in which colours are displayed. Caller is responsible for triggering a redraw of the control.

Height

#
public int Height { get; }
Gets the ideal height of this colour picker in the UI.

ImpliedColour

#
public Color ImpliedColour { get; }
Gets the currently implied colour, taking into account discretisation.

IncludeContextuals

#
public bool IncludeContextuals { get; }
Gets whether the layout specifies the inclusion of the contextual icon colour model.

InitialColour

#
public Colour InitialColour { get; }
Gets the initial (original) colour this colour picker was constructed with.

Layout

#
public PickerLayout Layout { get; }
Gets whether this picker includes UI for transparency.

ModelName

#
public RectangleF ModelName { get; }
Gets the bounding rectangle of the colour space name label.

ModelToolbar

#
public RectangleF ModelToolbar { get; }
Gets the bounding rectangle of the toolbar containing all colour spaces.

MostRecentDiscrete

#
public static bool MostRecentDiscrete { get; set; }
Gets or sets the most recently used discrete mode. This will be the default for any new colour picker.

MostRecentFormat

#
public static ColourPickerFormat MostRecentFormat { get; set; }
Gets or sets the most recently selected colour format. This will be the default for any new colour picker.

MostRecentPalette

#
public static string MostRecentPalette { get; set; }
Gets or sets the most recently selected colour space. This will be the default for any new colour picker.

MostRecentSpace

#
public static Space MostRecentSpace { get; set; }
Gets or sets the most recently selected colour space. This will be the default for any new colour picker.

Palette

#
public NamedPalette Palette { get; }
Gets the palette indicated buy the PaletteName property.

PaletteName

#
public string PaletteName { get; }
Gets the name of the palette currently loaded in the picker.

Responder

#
public Responses Responder { get; }
Responder

RevertButton

#
public RectangleF RevertButton { get; }
Gets the region for the Revert button.

SamplerButton

#
public RectangleF SamplerButton { get; }
Gets the region for the Screen Sampler button.

Space

#
public Space Space { get; }
Gets the colour space currently on display.

Width

#
public int Width { get; }
Gets the ideal width of this colour picker in the UI.

Methods

ComputeBounds

#
public static Size ComputeBounds(PickerLayout layout)
Compute the bounds based on a specific layout.
layout (PickerLayout)Layout.
Dimensions of resulting picker.

Draw

#
public void Draw(Context context, PointF anchor)
Draw this colour picker to a graphics context.
context (Context)Graphics context.
anchor (PointF)Anchor point (upper left corner of colour picker)

ModelButton

#
public RectangleF ModelButton(Space space)
Resolve the bounds for the specific space button on the space toolbar.
space (Space)

PerformLayout

#
public void PerformLayout(PointF anchor)
Perform layout of the picker. This happens automatically within each Draw iteration, but you can call it specifically if you need to examine the boundaries prior to a draw operation.
anchor (PointF)Layout anchor for top left corner.

SpaceInstance

#
public IColourSpace SpaceInstance(Space space)
Gets the instance of the given space. Do not modify these instances unless you understand what consequences that might have to the validity of the picker state.
space (Space)Space to retrieve.
Instance of space or null.

Events

ColourAccepted

#
public event EventHandler<EventArgs> ColourAccepted
Raised when the current colour is accepted.

DisplayExpired

#
public event EventHandler<EventArgs> DisplayExpired
Raised whenever the picker needs to be redrawn.

ImpliedColourChanged

#
public event EventHandler<BeforeAfterEventArgs<ColourPicker, Color>> ImpliedColourChanged
Raised when the implied colour is changed.

SpaceChanged

#
Raised when a different model is selected.

SpatialColourChanged

#
public event EventHandler<BeforeAfterEventArgs<ColourPicker, Colour>> SpatialColourChanged
Raised when a new colour is picked.