Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
widgets.c File Reference

Drawlayer widget helpers (picker, swatch, color history). More...

#include "iop/drawlayer/widgets.h"
#include "iop/drawlayer/paint.h"
#include "gui/gtk.h"
#include <float.h>
#include <math.h>
#include <string.h>
+ Include dependency graph for widgets.c:

Data Structures

struct  dt_drawlayer_widgets_t
 Runtime state for drawlayer custom color widgets. More...
 

Macros

#define DT_DRAWLAYER_PICKER_U_MAX   0.70710678f
 
#define DT_DRAWLAYER_PICKER_V_MAX   0.81649658f
 
#define DT_DRAWLAYER_PICKER_C_MAX   0.81649658f
 

Typedefs

typedef enum dt_drawlayer_color_drag_mode_t dt_drawlayer_color_drag_mode_t
 Active drag target in picker UI.
 

Enumerations

enum  dt_drawlayer_color_drag_mode_t {
  DT_DRAWLAYER_COLOR_DRAG_NONE = 0 ,
  DT_DRAWLAYER_COLOR_DRAG_DISC = 1 ,
  DT_DRAWLAYER_COLOR_DRAG_PLANE = 2
}
 Active drag target in picker UI. More...
 

Functions

static float _clamp01 (const float value)
 Clamp scalar to [0,1].
 
static gboolean _display_rgb_equal (const float a[3], const float b[3])
 Compare display-RGB triplets with tiny epsilon tolerance.
 
static void _picker_update_polar_from_uv (dt_drawlayer_widgets_t *widgets)
 Update hue/chroma from current U/V components.
 
static void _picker_update_uv_from_polar (dt_drawlayer_widgets_t *widgets)
 Update U/V from current hue/chroma components.
 
static int _picker_project_opponent_to_display_rgb (const float m, const float u, const float v, float display_rgb[3])
 Project opponent-space color to display RGB; fail when out of gamut.
 
static float _picker_max_chroma_for_m_hue (const float m, const float hue)
 Compute max reachable chroma at given lightness/hue within display gamut.
 
static void _picker_clamp_state_to_gamut (dt_drawlayer_widgets_t *widgets)
 Clamp picker state so projected display RGB always remains valid.
 
static void _sync_picker_from_display_rgb (dt_drawlayer_widgets_t *widgets, const float display_rgb[3])
 Initialize picker opponent coordinates from display RGB color.
 
static void _clear_color_picker_surface (dt_drawlayer_widgets_t *widgets)
 Destroy cached picker surface and reset cache metadata.
 
static void _clear_profile_surface (dt_drawlayer_widgets_t *widgets)
 Destroy cached brush-profile preview surface and reset cache metadata.
 
static void _brush_profile_geometry (const GtkWidget *widget, float *x, float *y, float *width, float *height, float *gap, int *cell_count)
 Compute profile-row geometry inside widget.
 
static gboolean _brush_profile_cell_rect (const GtkWidget *widget, const int index, float *x, float *y, float *width, float *height)
 Compute one profile-cell rectangle.
 
static uint8_t _linear_channel_to_u8 (const float x)
 Convert linear float channel to display-encoded 8-bit channel.
 
static void _render_brush_profile_cell (unsigned char *dst, const int stride, const int width, const int height, float *rgba_scratch, const dt_drawlayer_widgets_t *widgets, const int shape)
 Render one brush preview cell into ARGB8 memory.
 
static void _color_picker_geometry (const GtkWidget *widget, float *uv_x, float *uv_y, float *uv_size, float *plane_x, float *plane_y, float *plane_w, float *plane_h)
 Compute picker-disc and value/chroma-plane geometry inside widget.
 
static float _color_picker_hit_margin (void)
 Hit-margin in device-independent pixels for drag continuity.
 
static gboolean _rect_contains_with_margin (const float x, const float y, const float rx, const float ry, const float rw, const float rh, const float margin)
 Rectangle hit-test with configurable margin expansion.
 
dt_drawlayer_widgets_tdt_drawlayer_widgets_init (void)
 Allocate and initialize widget runtime state.
 
void dt_drawlayer_widgets_cleanup (dt_drawlayer_widgets_t **widgets)
 Free widget runtime state and owned cairo resources.
 
void dt_drawlayer_widgets_set_display_color (dt_drawlayer_widgets_t *widgets, const float display_rgb[3])
 Set current color and synchronize picker internals.
 
gboolean dt_drawlayer_widgets_get_display_color (const dt_drawlayer_widgets_t *widgets, float display_rgb[3])
 Get current color projected to display RGB.
 
void dt_drawlayer_widgets_mark_picker_dirty (dt_drawlayer_widgets_t *widgets)
 Mark picker surface dirty for regeneration on next draw.
 
void dt_drawlayer_widgets_set_color_history (dt_drawlayer_widgets_t *widgets, const float history[DT_DRAWLAYER_COLOR_HISTORY_COUNT][3], const gboolean valid[DT_DRAWLAYER_COLOR_HISTORY_COUNT])
 Replace full color-history content and validity flags.
 
void dt_drawlayer_widgets_get_color_history (const dt_drawlayer_widgets_t *widgets, float history[DT_DRAWLAYER_COLOR_HISTORY_COUNT][3], gboolean valid[DT_DRAWLAYER_COLOR_HISTORY_COUNT])
 Copy full color-history content and validity flags out.
 
gboolean dt_drawlayer_widgets_push_color_history (dt_drawlayer_widgets_t *widgets, const float display_rgb[3])
 Push one color to history head if different from current head.
 
gboolean dt_drawlayer_widgets_update_from_picker_position (dt_drawlayer_widgets_t *widgets, GtkWidget *widget, float x, float y, float display_rgb[3])
 Update picker state from mouse position and return selected color.
 
gboolean dt_drawlayer_widgets_finish_picker_drag (dt_drawlayer_widgets_t *widgets, float display_rgb[3])
 End picker drag mode and optionally output current color.
 
gboolean dt_drawlayer_widgets_is_picker_dragging (const dt_drawlayer_widgets_t *widgets)
 Tell whether picker drag interaction is currently active.
 
gboolean dt_drawlayer_widgets_pick_history_color (const dt_drawlayer_widgets_t *widgets, GtkWidget *widget, float x, float y, float display_rgb[3])
 Pick one history swatch color from widget coordinates.
 
gboolean dt_drawlayer_widgets_draw_picker (dt_drawlayer_widgets_t *widgets, GtkWidget *widget, cairo_t *cr, double pixels_per_dip)
 Draw color picker map, controls and selection markers.
 
gboolean dt_drawlayer_widgets_draw_swatch (const dt_drawlayer_widgets_t *widgets, GtkWidget *widget, cairo_t *cr)
 Draw compact color-history swatch grid.
 
void dt_drawlayer_widgets_set_brush_profile_preview (dt_drawlayer_widgets_t *widgets, const float opacity, const float hardness, const float sprinkles, const float sprinkle_size, const float sprinkle_coarseness, const int selected_shape)
 Update cached brush-profile preview parameters and selected profile.
 
int dt_drawlayer_widgets_get_brush_profile_selection (const dt_drawlayer_widgets_t *widgets)
 Read currently selected brush profile.
 
gboolean dt_drawlayer_widgets_draw_brush_profiles (dt_drawlayer_widgets_t *widgets, GtkWidget *widget, cairo_t *cr, const double pixels_per_dip)
 Draw selectable row of brush-profile previews.
 
gboolean dt_drawlayer_widgets_pick_brush_profile (dt_drawlayer_widgets_t *widgets, GtkWidget *widget, const float x, const float y, int *shape)
 Hit-test and select one brush profile from the preview row.
 

Detailed Description

Drawlayer widget helpers (picker, swatch, color history).

Macro Definition Documentation

◆ DT_DRAWLAYER_PICKER_C_MAX

#define DT_DRAWLAYER_PICKER_C_MAX   0.81649658f

◆ DT_DRAWLAYER_PICKER_U_MAX

#define DT_DRAWLAYER_PICKER_U_MAX   0.70710678f

◆ DT_DRAWLAYER_PICKER_V_MAX

#define DT_DRAWLAYER_PICKER_V_MAX   0.81649658f

Typedef Documentation

◆ dt_drawlayer_color_drag_mode_t

Active drag target in picker UI.

Enumeration Type Documentation

◆ dt_drawlayer_color_drag_mode_t

Active drag target in picker UI.

Enumerator
DT_DRAWLAYER_COLOR_DRAG_NONE 
DT_DRAWLAYER_COLOR_DRAG_DISC 
DT_DRAWLAYER_COLOR_DRAG_PLANE 

Function Documentation

◆ _brush_profile_cell_rect()

static gboolean _brush_profile_cell_rect ( const GtkWidget widget,
const int  index,
float *  x,
float *  y,
float *  width,
float *  height 
)
static

Compute one profile-cell rectangle.

References _brush_profile_geometry(), FALSE, height, TRUE, width, and x.

Referenced by dt_drawlayer_widgets_draw_brush_profiles(), and dt_drawlayer_widgets_pick_brush_profile().

◆ _brush_profile_geometry()

static void _brush_profile_geometry ( const GtkWidget widget,
float *  x,
float *  y,
float *  width,
float *  height,
float *  gap,
int *  cell_count 
)
static

Compute profile-row geometry inside widget.

References DT_PIXEL_APPLY_DPI, height, width, and x.

Referenced by _brush_profile_cell_rect(), and dt_drawlayer_widgets_draw_brush_profiles().

◆ _clamp01()

◆ _clear_color_picker_surface()

◆ _clear_profile_surface()

◆ _color_picker_geometry()

static void _color_picker_geometry ( const GtkWidget widget,
float *  uv_x,
float *  uv_y,
float *  uv_size,
float *  plane_x,
float *  plane_y,
float *  plane_w,
float *  plane_h 
)
static

Compute picker-disc and value/chroma-plane geometry inside widget.

References DT_PIXEL_APPLY_DPI, height, size, and width.

Referenced by dt_drawlayer_widgets_draw_picker(), and dt_drawlayer_widgets_update_from_picker_position().

◆ _color_picker_hit_margin()

static float _color_picker_hit_margin ( void  )
static

Hit-margin in device-independent pixels for drag continuity.

References darktable, DT_PIXEL_APPLY_DPI, darktable_t::gui, and dt_gui_gtk_t::ppd.

Referenced by dt_drawlayer_widgets_update_from_picker_position().

◆ _display_rgb_equal()

static gboolean _display_rgb_equal ( const float  a[3],
const float  b[3] 
)
static

Compare display-RGB triplets with tiny epsilon tolerance.

References a, and b.

Referenced by dt_drawlayer_widgets_push_color_history().

◆ _linear_channel_to_u8()

static uint8_t _linear_channel_to_u8 ( const float  x)
inlinestatic

Convert linear float channel to display-encoded 8-bit channel.

References _clamp01(), v, and x.

Referenced by _render_brush_profile_cell().

◆ _picker_clamp_state_to_gamut()

◆ _picker_max_chroma_for_m_hue()

static float _picker_max_chroma_for_m_hue ( const float  m,
const float  hue 
)
static

Compute max reachable chroma at given lightness/hue within display gamut.

References c, and m.

Referenced by _picker_clamp_state_to_gamut().

◆ _picker_project_opponent_to_display_rgb()

static int _picker_project_opponent_to_display_rgb ( const float  m,
const float  u,
const float  v,
float  display_rgb[3] 
)
static

Project opponent-space color to display RGB; fail when out of gamut.

References b, g, m, r, and v.

Referenced by dt_drawlayer_widgets_draw_picker(), dt_drawlayer_widgets_finish_picker_drag(), dt_drawlayer_widgets_get_display_color(), and dt_drawlayer_widgets_update_from_picker_position().

◆ _picker_update_polar_from_uv()

static void _picker_update_polar_from_uv ( dt_drawlayer_widgets_t widgets)
static

◆ _picker_update_uv_from_polar()

static void _picker_update_uv_from_polar ( dt_drawlayer_widgets_t widgets)
static

◆ _rect_contains_with_margin()

static gboolean _rect_contains_with_margin ( const float  x,
const float  y,
const float  rx,
const float  ry,
const float  rw,
const float  rh,
const float  margin 
)
static

Rectangle hit-test with configurable margin expansion.

References x.

Referenced by dt_drawlayer_widgets_update_from_picker_position().

◆ _render_brush_profile_cell()

static void _render_brush_profile_cell ( unsigned char *  dst,
const int  stride,
const int  width,
const int  height,
float *  rgba_scratch,
const dt_drawlayer_widgets_t widgets,
const int  shape 
)
static

◆ _sync_picker_from_display_rgb()

static void _sync_picker_from_display_rgb ( dt_drawlayer_widgets_t widgets,
const float  display_rgb[3] 
)
static

◆ dt_drawlayer_widgets_cleanup()

void dt_drawlayer_widgets_cleanup ( dt_drawlayer_widgets_t **  widgets)

Free widget runtime state and owned cairo resources.

Destroy widget runtime state and owned surfaces.

References _clear_color_picker_surface(), _clear_profile_surface(), and dt_free.

Referenced by gui_cleanup().

◆ dt_drawlayer_widgets_draw_brush_profiles()

◆ dt_drawlayer_widgets_draw_picker()

◆ dt_drawlayer_widgets_draw_swatch()

gboolean dt_drawlayer_widgets_draw_swatch ( const dt_drawlayer_widgets_t widgets,
GtkWidget widget,
cairo_t *  cr 
)

◆ dt_drawlayer_widgets_finish_picker_drag()

gboolean dt_drawlayer_widgets_finish_picker_drag ( dt_drawlayer_widgets_t widgets,
float  display_rgb[3] 
)

◆ dt_drawlayer_widgets_get_brush_profile_selection()

int dt_drawlayer_widgets_get_brush_profile_selection ( const dt_drawlayer_widgets_t widgets)

Read currently selected brush profile.

References DT_DRAWLAYER_BRUSH_SHAPE_LINEAR, and dt_drawlayer_widgets_t::profile_selected_shape.

Referenced by _sync_params_from_gui().

◆ dt_drawlayer_widgets_get_color_history()

void dt_drawlayer_widgets_get_color_history ( const dt_drawlayer_widgets_t widgets,
float  history[DT_DRAWLAYER_COLOR_HISTORY_COUNT][3],
gboolean  valid[DT_DRAWLAYER_COLOR_HISTORY_COUNT] 
)

Copy full color-history content and validity flags out.

References dt_drawlayer_widgets_t::color_history, dt_drawlayer_widgets_t::color_history_valid, DT_DRAWLAYER_COLOR_HISTORY_COUNT, and i.

Referenced by _store_color_history().

◆ dt_drawlayer_widgets_get_display_color()

gboolean dt_drawlayer_widgets_get_display_color ( const dt_drawlayer_widgets_t widgets,
float  display_rgb[3] 
)

Get current color projected to display RGB.

Get current display RGB color.

References _picker_project_opponent_to_display_rgb(), FALSE, dt_drawlayer_widgets_t::picker_m, dt_drawlayer_widgets_t::picker_u, and dt_drawlayer_widgets_t::picker_v.

◆ dt_drawlayer_widgets_init()

◆ dt_drawlayer_widgets_is_picker_dragging()

gboolean dt_drawlayer_widgets_is_picker_dragging ( const dt_drawlayer_widgets_t widgets)

Tell whether picker drag interaction is currently active.

Query whether picker drag is currently active.

References DT_DRAWLAYER_COLOR_DRAG_NONE, and dt_drawlayer_widgets_t::picker_drag_mode.

Referenced by _color_picker_motion().

◆ dt_drawlayer_widgets_mark_picker_dirty()

void dt_drawlayer_widgets_mark_picker_dirty ( dt_drawlayer_widgets_t widgets)

Mark picker surface dirty for regeneration on next draw.

Mark picker backing surface dirty for redraw/rebuild.

References dt_drawlayer_widgets_t::color_surface_dirty, and TRUE.

◆ dt_drawlayer_widgets_pick_brush_profile()

gboolean dt_drawlayer_widgets_pick_brush_profile ( dt_drawlayer_widgets_t widgets,
GtkWidget widget,
const float  x,
const float  y,
int *  shape 
)

◆ dt_drawlayer_widgets_pick_history_color()

gboolean dt_drawlayer_widgets_pick_history_color ( const dt_drawlayer_widgets_t widgets,
GtkWidget widget,
float  x,
float  y,
float  display_rgb[3] 
)

Pick one history swatch color from widget coordinates.

Hit-test and pick color from history swatches.

References dt_drawlayer_widgets_t::color_history, dt_drawlayer_widgets_t::color_history_valid, DT_DRAWLAYER_COLOR_HISTORY_COLS, DT_DRAWLAYER_COLOR_HISTORY_COUNT, DT_DRAWLAYER_COLOR_HISTORY_ROWS, FALSE, height, row, TRUE, width, and x.

Referenced by _color_swatch_button_press().

◆ dt_drawlayer_widgets_push_color_history()

gboolean dt_drawlayer_widgets_push_color_history ( dt_drawlayer_widgets_t widgets,
const float  display_rgb[3] 
)

Push one color to history head if different from current head.

Push one color in history if it differs from current head.

References _clamp01(), _display_rgb_equal(), dt_drawlayer_widgets_t::color_history, dt_drawlayer_widgets_t::color_history_valid, DT_DRAWLAYER_COLOR_HISTORY_COUNT, FALSE, i, and TRUE.

Referenced by _remember_display_color().

◆ dt_drawlayer_widgets_set_brush_profile_preview()

void dt_drawlayer_widgets_set_brush_profile_preview ( dt_drawlayer_widgets_t widgets,
const float  opacity,
const float  hardness,
const float  sprinkles,
const float  sprinkle_size,
const float  sprinkle_coarseness,
const int  selected_shape 
)

◆ dt_drawlayer_widgets_set_color_history()

void dt_drawlayer_widgets_set_color_history ( dt_drawlayer_widgets_t widgets,
const float  history[DT_DRAWLAYER_COLOR_HISTORY_COUNT][3],
const gboolean  valid[DT_DRAWLAYER_COLOR_HISTORY_COUNT] 
)

Replace full color-history content and validity flags.

References _clamp01(), dt_drawlayer_widgets_t::color_history, dt_drawlayer_widgets_t::color_history_valid, DT_DRAWLAYER_COLOR_HISTORY_COUNT, and i.

Referenced by _load_color_history().

◆ dt_drawlayer_widgets_set_display_color()

void dt_drawlayer_widgets_set_display_color ( dt_drawlayer_widgets_t widgets,
const float  display_rgb[3] 
)

Set current color and synchronize picker internals.

Set current display RGB color and refresh picker state.

References _sync_picker_from_display_rgb(), dt_drawlayer_widgets_t::color_surface_dirty, and TRUE.

Referenced by _apply_display_brush_color(), and _sync_color_picker_from_conf().

◆ dt_drawlayer_widgets_update_from_picker_position()