AG_HSVPal
— agar
HSV color picker
#include <agar/core.h>
#include <agar/gui.h>
The AG_HSVPal
widget is a HSV (Hue,
Saturation, Value) color editor which allows the user to edit a color's hue,
saturation, value and alpha components. The widget can bind directly to
different color representations:
- A native Agar
AG_Color(3).
- Single-precision Hue, Saturation, Value and Alpha.
- 8- or 16-bit integer RGBA components.
- Floating-point RGBA components.
- A 32- or 64-bit packed pixel (with corresponding
AG_PixelFormat(3)).
AG_HSVPal *
AG_HSVPalNew
(AG_Widget
*parent, Uint
flags);
The
AG_HSVPalNew
()
function allocates, initializes, and attaches a new
AG_HSVPal
widget. Acceptable
flags include:
- AG_HSVPAL_SHOW_RGB
- Show the RGB value in text form.
- AG_HSVPAL_SHOW_HSV
- Show the HSV value in text form.
- AG_HSVPAL_NOALPHA
- (Read-only) Transparency control is disabled. Set (or cleared) when
pixel-format is bound to a pixel format with (or
without) alpha.
- AG_HSVPAL_FORCE_NOALPHA
- Disable the transparency control.
- AG_HSVPAL_NOPREVIEW
- Disable the color preview band.
- AG_HSVPAL_HFILL
- Expand horizontally in parent container.
- AG_HSVPAL_VFILL
- Expand vertically in parent container.
- AG_HSVPAL_EXPAND
- Shorthand for
AG_HSVPAL_HFILL
|
AG_HSVPAL_VFILL
.
void
AG_HSVPalUpdateHue
(AG_HSVPal
*pal, int x,
int y);
void
AG_HSVPalUpdateSV
(AG_HSVPal
*pal, int x,
int y);
AG_HSVPalUpdateHue
()
sets the hue to that closest to cursor coordinates x,
y and triggers a refresh.
AG_HSVPalUpdateSV
() sets the saturation and value to
that at cursor coordinates x, y
and triggers a refresh.
The AG_HSVPal
widget provides the
following bindings:
- AG_Color *agcolor
- A native
AG_Color(3)
structure.
- float *hue
- Hue (0..1).
- float *saturation
- Saturation (0..1).
- float *value
- Value (0..1).
- float *alpha
- Single-precision component value (0..1).
- AG_PixelFormat
**pixel-format
- Pointer to
AG_PixelFormat(3)
describing the packed-pixel format of pixel and
pixel64. Note that
pixel-format should be set first. If the format has
an alpha component,
AG_HSVPAL_NOALPHA will be set
accordingly
(use AG_HSVPAL_FORCE_NOALPHA
to
disable).
- Uint32 *pixel
- 32-bit packed pixel value.
- Uint64 *pixel64
- 64-bit packed pixel value. Available in
AG_LARGE
build.
- void *RGBv
- A three-element array containing the RGB components. Acceptable binding
types include FLOAT and DOUBLE, INT and UINT8. For floating point types,
the values are scaled to 0.0-1.0. For integral types, the values are
scaled to 0-255.
- void *RGBAv
- Same as above, except that the array has 4 elements where the last element
is the alpha component.
The AG_HSVPal
widget generates the
following events:
h-changed
(void)
- The hue has changed.
sv-changed
(void)
- The saturation or the value has changed.
Conversion between integer RGB and HSV triplets incurs loss of
precision. In cases where it is desirable to maintain the same hue
throughout changes in saturation, the color should be stored in HSV
format.
The AG_HSVPal
widget first appeared in
Agar 1.0. The pixel64 binding,
AG_HSVPalUpdateHue
() and
AG_HSVPalUpdateSV
() appeared in Agar 1.6.0.