mate-desktop 1.29.2
Library with common API for various MATE modules
Loading...
Searching...
No Matches
mate-hsv.c File Reference
View source
#include "mate-hsv.h"
#include <math.h>
#include <string.h>
#include <gtk/gtk.h>
Include dependency graph for mate-hsv.c:

Data Structures

struct  _MateHSVPrivate
 

Macros

#define I_(string)   g_intern_static_string (string)
 
#define DEFAULT_SIZE   100
 SECTION:mate-hsv @Short_description: A “color wheel” widget @Title: MateHSV.
 
#define DEFAULT_RING_WIDTH   10
 
#define INTENSITY(r, g, b)   ((r) * 0.30 + (g) * 0.59 + (b) * 0.11)
 
#define SWAP(a, b, t)   ((t) = (a), (a) = (b), (b) = (t))
 
#define LERP(a, b, v1, v2, i)
 
#define PAD   3
 
#define RADIUS   4
 
#define FOCUS_RADIUS   6
 
#define HUE_DELTA   0.002
 

Enumerations

enum  DragMode { DRAG_NONE , DRAG_H , DRAG_SV }
 
enum  { CHANGED , MOVE , LAST_SIGNAL }
 

Functions

static void mate_hsv_destroy (GtkWidget *widget)
 
static void mate_hsv_realize (GtkWidget *widget)
 
static void mate_hsv_unrealize (GtkWidget *widget)
 
static void mate_hsv_get_preferred_width (GtkWidget *widget, gint *minimum, gint *natural)
 
static void mate_hsv_get_preferred_height (GtkWidget *widget, gint *minimum, gint *natural)
 
static void mate_hsv_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
 
static gboolean mate_hsv_button_press (GtkWidget *widget, GdkEventButton *event)
 
static gboolean mate_hsv_button_release (GtkWidget *widget, GdkEventButton *event)
 
static gboolean mate_hsv_motion (GtkWidget *widget, GdkEventMotion *event)
 
static gboolean mate_hsv_draw (GtkWidget *widget, cairo_t *cr)
 
static gboolean mate_hsv_grab_broken (GtkWidget *widget, GdkEventGrabBroken *event)
 
static gboolean mate_hsv_focus (GtkWidget *widget, GtkDirectionType direction)
 
static void mate_hsv_move (MateHSV *hsv, GtkDirectionType dir)
 
static void mate_hsv_class_init (MateHSVClass *class)
 
static void mate_hsv_init (MateHSV *hsv)
 
static void hsv_to_rgb (gdouble *h, gdouble *s, gdouble *v)
 
static void compute_triangle (MateHSV *hsv, gint *hx, gint *hy, gint *sx, gint *sy, gint *vx, gint *vy)
 
static gboolean is_in_ring (MateHSV *hsv, gdouble x, gdouble y)
 
static void compute_sv (MateHSV *hsv, gdouble x, gdouble y, gdouble *s, gdouble *v)
 
static gboolean is_in_triangle (MateHSV *hsv, gdouble x, gdouble y)
 
static double compute_v (MateHSV *hsv, gdouble x, gdouble y)
 
static void set_cross_grab (MateHSV *hsv, GdkDevice *device, guint32 time)
 
static void paint_ring (MateHSV *hsv, cairo_t *cr)
 
static void get_color (gdouble h, gdouble s, gdouble v, gint *r, gint *g, gint *b)
 
static void paint_triangle (MateHSV *hsv, cairo_t *cr, gboolean draw_focus)
 
GtkWidget * mate_hsv_new (void)
 mate_hsv_new:
 
void mate_hsv_set_color (MateHSV *hsv, gdouble h, gdouble s, gdouble v)
 mate_hsv_set_color: @hsv: An HSV color selector @h: Hue @s: Saturation @v: Value
 
void mate_hsv_get_color (MateHSV *hsv, double *h, double *s, double *v)
 mate_hsv_get_color: @hsv: An HSV color selector @h: (out): Return value for the hue @s: (out): Return value for the saturation @v: (out): Return value for the value
 
void mate_hsv_set_metrics (MateHSV *hsv, gint size, gint ring_width)
 mate_hsv_set_metrics: @hsv: An HSV color selector @size: Diameter for the hue ring @ring_width: Width of the hue ring
 
void mate_hsv_get_metrics (MateHSV *hsv, gint *size, gint *ring_width)
 mate_hsv_get_metrics: @hsv: An HSV color selector @size: (out): Return value for the diameter of the hue ring @ring_width: (out): Return value for the width of the hue ring
 
gboolean mate_hsv_is_adjusting (MateHSV *hsv)
 mate_hsv_is_adjusting: @hsv: A MateHSV
 

Variables

static guint hsv_signals [LAST_SIGNAL]
 

Macro Definition Documentation

◆ DEFAULT_RING_WIDTH

#define DEFAULT_RING_WIDTH   10

◆ DEFAULT_SIZE

#define DEFAULT_SIZE   100

SECTION:mate-hsv @Short_description: A “color wheel” widget @Title: MateHSV.

MateHSV is the “color wheel” part of a complete color selector widget. It allows to select a color by determining its HSV components in an intuitive way. Moving the selection around the outer ring changes the hue, and moving the selection point inside the inner triangle changes value and saturation.

◆ FOCUS_RADIUS

#define FOCUS_RADIUS   6

◆ HUE_DELTA

#define HUE_DELTA   0.002

◆ I_

#define I_ (   string)    g_intern_static_string (string)

◆ INTENSITY

#define INTENSITY (   r,
  g,
  b 
)    ((r) * 0.30 + (g) * 0.59 + (b) * 0.11)

◆ LERP

#define LERP (   a,
  b,
  v1,
  v2,
  i 
)
Value:
(((v2) - (v1) != 0) \
? ((a) + ((b) - (a)) * ((i) - (v1)) / ((v2) - (v1))) \
: (a))

◆ PAD

#define PAD   3

◆ RADIUS

#define RADIUS   4

◆ SWAP

#define SWAP (   a,
  b,
  t 
)    ((t) = (a), (a) = (b), (b) = (t))

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
CHANGED 
MOVE 
LAST_SIGNAL 

◆ DragMode

enum DragMode
Enumerator
DRAG_NONE 
DRAG_H 
DRAG_SV 

Function Documentation

◆ compute_sv()

static void compute_sv ( MateHSV *  hsv,
gdouble  x,
gdouble  y,
gdouble *  s,
gdouble *  v 
)
static

References compute_triangle().

Referenced by mate_hsv_button_press(), mate_hsv_button_release(), mate_hsv_motion(), and mate_hsv_move().

Here is the call graph for this function:

◆ compute_triangle()

static void compute_triangle ( MateHSV *  hsv,
gint *  hx,
gint *  hy,
gint *  sx,
gint *  sy,
gint *  vx,
gint *  vy 
)
static

◆ compute_v()

static double compute_v ( MateHSV *  hsv,
gdouble  x,
gdouble  y 
)
static

◆ get_color()

static void get_color ( gdouble  h,
gdouble  s,
gdouble  v,
gint *  r,
gint *  g,
gint *  b 
)
static

References hsv_to_rgb().

Referenced by paint_triangle().

Here is the call graph for this function:

◆ hsv_to_rgb()

static void hsv_to_rgb ( gdouble *  h,
gdouble *  s,
gdouble *  v 
)
static

◆ is_in_ring()

static gboolean is_in_ring ( MateHSV *  hsv,
gdouble  x,
gdouble  y 
)
static

◆ is_in_triangle()

static gboolean is_in_triangle ( MateHSV *  hsv,
gdouble  x,
gdouble  y 
)
static

References compute_triangle().

Referenced by mate_hsv_button_press().

Here is the call graph for this function:

◆ mate_hsv_button_press()

static gint mate_hsv_button_press ( GtkWidget *  widget,
GdkEventButton *  event 
)
static

References compute_sv(), compute_v(), DRAG_H, DRAG_NONE, DRAG_SV, _MateHSVPrivate::focus_on_ring, _MateHSVPrivate::h, is_in_ring(), is_in_triangle(), MATE_HSV, mate_hsv_set_color(), _MateHSVPrivate::mode, _MateHSV::priv, _MateHSVPrivate::s, set_cross_grab(), and _MateHSVPrivate::v.

Referenced by mate_hsv_class_init().

Here is the call graph for this function:

◆ mate_hsv_button_release()

static gint mate_hsv_button_release ( GtkWidget *  widget,
GdkEventButton *  event 
)
static

References compute_sv(), compute_v(), DRAG_H, DRAG_NONE, DRAG_SV, _MateHSVPrivate::h, MATE_HSV, mate_hsv_set_color(), _MateHSVPrivate::mode, _MateHSV::priv, _MateHSVPrivate::s, and _MateHSVPrivate::v.

Referenced by mate_hsv_class_init().

Here is the call graph for this function:

◆ mate_hsv_class_init()

static void mate_hsv_class_init ( MateHSVClass *  class)
static

◆ mate_hsv_destroy()

static void mate_hsv_destroy ( GtkWidget *  widget)
static

Referenced by mate_hsv_class_init().

◆ mate_hsv_draw()

static gboolean mate_hsv_draw ( GtkWidget *  widget,
cairo_t *  cr 
)
static

References _MateHSVPrivate::focus_on_ring, MATE_HSV, paint_ring(), paint_triangle(), and _MateHSV::priv.

Referenced by mate_hsv_class_init().

Here is the call graph for this function:

◆ mate_hsv_focus()

static gboolean mate_hsv_focus ( GtkWidget *  widget,
GtkDirectionType  direction 
)
static

◆ mate_hsv_get_color()

void mate_hsv_get_color ( MateHSV *  hsv,
double *  h,
double *  s,
double *  v 
)

mate_hsv_get_color: @hsv: An HSV color selector @h: (out): Return value for the hue @s: (out): Return value for the saturation @v: (out): Return value for the value

Queries the current color in an HSV color selector. Returned values will be in the [0.0, 1.0] range.

References _MateHSVPrivate::h, MATE_IS_HSV, _MateHSV::priv, _MateHSVPrivate::s, and _MateHSVPrivate::v.

Referenced by hsv_changed().

◆ mate_hsv_get_metrics()

void mate_hsv_get_metrics ( MateHSV *  hsv,
gint *  size,
gint *  ring_width 
)

mate_hsv_get_metrics: @hsv: An HSV color selector @size: (out): Return value for the diameter of the hue ring @ring_width: (out): Return value for the width of the hue ring

Queries the size and ring width of an HSV color selector.

References MATE_IS_HSV, _MateHSV::priv, _MateHSVPrivate::ring_width, and _MateHSVPrivate::size.

◆ mate_hsv_get_preferred_height()

static void mate_hsv_get_preferred_height ( GtkWidget *  widget,
gint *  minimum,
gint *  natural 
)
static

◆ mate_hsv_get_preferred_width()

static void mate_hsv_get_preferred_width ( GtkWidget *  widget,
gint *  minimum,
gint *  natural 
)
static

◆ mate_hsv_grab_broken()

static gboolean mate_hsv_grab_broken ( GtkWidget *  widget,
GdkEventGrabBroken *  event 
)
static

◆ mate_hsv_init()

◆ mate_hsv_is_adjusting()

gboolean mate_hsv_is_adjusting ( MateHSV *  hsv)

mate_hsv_is_adjusting: @hsv: A MateHSV

An HSV color selector can be said to be adjusting if multiple rapid changes are being made to its value, for example, when the user is adjusting the value with the mouse. This function queries whether the HSV color selector is being adjusted or not.

Returns: TRUE if clients can ignore changes to the color value, since they may be transitory, or FALSE if they should consider the color value status to be final.

References DRAG_NONE, MATE_IS_HSV, _MateHSVPrivate::mode, and _MateHSV::priv.

Referenced by mate_color_selection_is_adjusting().

◆ mate_hsv_motion()

static gint mate_hsv_motion ( GtkWidget *  widget,
GdkEventMotion *  event 
)
static

References compute_sv(), compute_v(), DRAG_H, DRAG_NONE, DRAG_SV, _MateHSVPrivate::h, MATE_HSV, mate_hsv_set_color(), _MateHSVPrivate::mode, _MateHSV::priv, _MateHSVPrivate::s, and _MateHSVPrivate::v.

Referenced by mate_hsv_class_init().

Here is the call graph for this function:

◆ mate_hsv_move()

static void mate_hsv_move ( MateHSV *  hsv,
GtkDirectionType  dir 
)
static

References compute_sv(), compute_triangle(), _MateHSVPrivate::focus_on_ring, _MateHSVPrivate::h, HUE_DELTA, mate_hsv_set_color(), _MateHSV::priv, _MateHSVPrivate::s, and _MateHSVPrivate::v.

Referenced by mate_hsv_class_init().

Here is the call graph for this function:

◆ mate_hsv_new()

GtkWidget * mate_hsv_new ( void  )

mate_hsv_new:

Creates a new HSV color selector.

Returns: A newly-created HSV color selector.

References MATE_TYPE_HSV.

Referenced by mate_color_selection_init().

◆ mate_hsv_realize()

static void mate_hsv_realize ( GtkWidget *  widget)
static

◆ mate_hsv_set_color()

void mate_hsv_set_color ( MateHSV *  hsv,
gdouble  h,
gdouble  s,
gdouble  v 
)

mate_hsv_set_color: @hsv: An HSV color selector @h: Hue @s: Saturation @v: Value

Sets the current color in an HSV color selector. Color component values must be in the [0.0, 1.0] range.

References CHANGED, _MateHSVPrivate::h, hsv_signals, MATE_IS_HSV, _MateHSV::priv, _MateHSVPrivate::s, and _MateHSVPrivate::v.

Referenced by mate_hsv_button_press(), mate_hsv_button_release(), mate_hsv_motion(), mate_hsv_move(), and update_color().

◆ mate_hsv_set_metrics()

void mate_hsv_set_metrics ( MateHSV *  hsv,
gint  size,
gint  ring_width 
)

mate_hsv_set_metrics: @hsv: An HSV color selector @size: Diameter for the hue ring @ring_width: Width of the hue ring

Sets the size and ring width of an HSV color selector.

References MATE_IS_HSV, _MateHSV::priv, _MateHSVPrivate::ring_width, and _MateHSVPrivate::size.

Referenced by mate_color_selection_init().

◆ mate_hsv_size_allocate()

static void mate_hsv_size_allocate ( GtkWidget *  widget,
GtkAllocation *  allocation 
)
static

◆ mate_hsv_unrealize()

static void mate_hsv_unrealize ( GtkWidget *  widget)
static

◆ paint_ring()

static void paint_ring ( MateHSV *  hsv,
cairo_t *  cr 
)
static

References _MateHSVPrivate::h, hsv_to_rgb(), INTENSITY, _MateHSV::priv, _MateHSVPrivate::ring_width, and _MateHSVPrivate::size.

Referenced by mate_hsv_draw().

Here is the call graph for this function:

◆ paint_triangle()

static void paint_triangle ( MateHSV *  hsv,
cairo_t *  cr,
gboolean  draw_focus 
)
static

References compute_triangle(), _MateHSVPrivate::focus_on_ring, FOCUS_RADIUS, get_color(), _MateHSVPrivate::h, hsv_to_rgb(), INTENSITY, LERP, PAD, _MateHSV::priv, RADIUS, _MateHSVPrivate::s, SWAP, and _MateHSVPrivate::v.

Referenced by mate_hsv_draw().

Here is the call graph for this function:

◆ set_cross_grab()

static void set_cross_grab ( MateHSV *  hsv,
GdkDevice *  device,
guint32  time 
)
static

Variable Documentation

◆ hsv_signals

guint hsv_signals[LAST_SIGNAL]
static