From 9c338693e1f99ec8bf10576ebaf4be7009b3776b Mon Sep 17 00:00:00 2001 From: Artem Senichev Date: Mon, 5 Aug 2024 11:19:30 +0300 Subject: [PATCH] gallery: Add config options for border and shadow Allows to set border and shadow colors for selected item. Relates to #174. Signed-off-by: Artem Senichev --- extra/swayimgrc | 24 ++++++++++++--------- extra/swayimgrc.5 | 7 ++++-- src/gallery.c | 54 ++++++++++++++++++++++++++++++++--------------- 3 files changed, 56 insertions(+), 29 deletions(-) diff --git a/extra/swayimgrc b/extra/swayimgrc index 862eff0..4d946c6 100644 --- a/extra/swayimgrc +++ b/extra/swayimgrc @@ -27,9 +27,9 @@ size = parent # Viewer mode configuration ################################################################################ [viewer] -# Window background color (RGB/RGBA) +# Window background color (RGBA) window = #00000000 -# Background for transparent images (grid/RGB/RGBA) +# Background for transparent images (grid/RGBA) transparency = grid # Default image scale (optimal/fit/width/height/fill/real) scale = optimal @@ -54,12 +54,16 @@ preload = 1 size = 200 # Use anti-aliasing for thumbnails (yes/no) antialiasing = no -# Background color of the window (RGB/RGBA) +# Background color of the window (RGBA) window = #00000000 -# Background color of the tile (RGB/RGBA) -background = #202020 -# Background color of the selected tile (RGB/RGBA) -select = #404040 +# Background color of the tile (RGBA) +background = #202020ff +# Background color of the selected tile (RGBA) +select = #404040ff +# Border color of the selected tile (RGBA) +border = #000000ff +# Shadow color of the selected tile (RGBA) +shadow = #000000ff ################################################################################ # Image list configuration @@ -82,9 +86,9 @@ all = yes name = monospace # Font size (pt) size = 14 -# Font color (RGB/RGBA) -color = #cccccc -# Shadow color (RGB/RGBA) +# Font color (RGBA) +color = #ccccccff +# Shadow color (RGBA) shadow = #000000a0 ################################################################################ diff --git a/extra/swayimgrc.5 b/extra/swayimgrc.5 index ab74640..34930c9 100644 --- a/extra/swayimgrc.5 +++ b/extra/swayimgrc.5 @@ -124,8 +124,11 @@ Background color of the window, default is \fI#00000000\fR. .IP "\fBbackground\fR = \fI#COLOR\fR" Background color of the tile, default is \fI#202020ff\fR. .\" ---------------------------------------------------------------------------- -.IP "\fBselect\fR = \fI#COLOR\fR" -Set window background of the selected tile, default is \fI#404040ff\fR. +.IP "\fBborder\fR = \fI#COLOR\fR" +Border color of the selected tile, default is \fI#000000ff\fR. +.\" ---------------------------------------------------------------------------- +.IP "\fBshadow\fR = \fI#COLOR\fR" +Shadow color of the selected tile, default is \fI#000000ff\fR. .\" **************************************************************************** .\" Image list config section .\" **************************************************************************** diff --git a/src/gallery.c b/src/gallery.c index 2cf1dc3..4f8978f 100644 --- a/src/gallery.c +++ b/src/gallery.c @@ -34,6 +34,8 @@ struct gallery { argb_t clr_window; ///< Window background argb_t clr_background; ///< Tile background argb_t clr_select; ///< Selected tile background + argb_t clr_border; ///< Selected tile border + argb_t clr_shadow; ///< Selected tile shadow size_t top; ///< Index of the first displayed image size_t selected; ///< Index of the selected image @@ -142,8 +144,6 @@ static void draw_thumbnail(struct pixmap* window, ssize_t x, ssize_t y, // currently selected item const size_t thumb_size = THUMB_SELECTED_SCALE * ctx.thumb_size; const size_t thumb_offset = (thumb_size - ctx.thumb_size) / 2; - const size_t shadow_width = max(1, thumb_size / 15); - const size_t alpha_step = 0xff / shadow_width; x = max(0, x - (ssize_t)thumb_offset); y = max(0, y - (ssize_t)thumb_offset); @@ -166,23 +166,33 @@ static void draw_thumbnail(struct pixmap* window, ssize_t x, ssize_t y, } // shadow - for (size_t i = 0; i < shadow_width; ++i) { - const ssize_t lx = i + x + thumb_size; - const ssize_t ly = y + shadow_width; - const ssize_t lh = thumb_size - (shadow_width - i); - const argb_t color = ARGB_SET_A(0xff - i * alpha_step); - pixmap_vline(window, lx, ly, lh, color); - } - for (size_t i = 0; i < shadow_width; ++i) { - const ssize_t lx = x + shadow_width; - const ssize_t ly = y + thumb_size + i; - const ssize_t lw = thumb_size - (shadow_width - i) + 1; - const argb_t color = ARGB_SET_A(0xff - i * alpha_step); - pixmap_hline(window, lx, ly, lw, color); + if (ARGB_GET_A(ctx.clr_shadow)) { + const argb_t base = ctx.clr_shadow & 0x00ffffff; + const uint8_t alpha = ARGB_GET_A(ctx.clr_shadow); + const size_t width = + max(1, (double)thumb_size / 15.0 * ((double)alpha / 255.0)); + const size_t alpha_step = alpha / width; + + for (size_t i = 0; i < width; ++i) { + const ssize_t lx = i + x + thumb_size; + const ssize_t ly = y + width; + const ssize_t lh = thumb_size - (width - i); + const argb_t color = base | ARGB_SET_A(alpha - i * alpha_step); + pixmap_vline(window, lx, ly, lh, color); + } + for (size_t i = 0; i < width; ++i) { + const ssize_t lx = x + width; + const ssize_t ly = y + thumb_size + i; + const ssize_t lw = thumb_size - (width - i) + 1; + const argb_t color = base | ARGB_SET_A(alpha - i * alpha_step); + pixmap_hline(window, lx, ly, lw, color); + } } - // frame - pixmap_rect(window, x, y, thumb_size, thumb_size, ARGB_SET_A(0xff)); + // border + if (ARGB_GET_A(ctx.clr_border)) { + pixmap_rect(window, x, y, thumb_size, thumb_size, ctx.clr_border); + } } } @@ -534,6 +544,14 @@ static enum config_status load_config(const char* key, const char* value) if (config_to_color(value, &ctx.clr_select)) { status = cfgst_ok; } + } else if (strcmp(key, "border") == 0) { + if (config_to_color(value, &ctx.clr_border)) { + status = cfgst_ok; + } + } else if (strcmp(key, "shadow") == 0) { + if (config_to_color(value, &ctx.clr_shadow)) { + status = cfgst_ok; + } } else if (strcmp(key, "antialiasing") == 0) { if (config_to_bool(value, &ctx.thumb_aa)) { status = cfgst_ok; @@ -552,6 +570,8 @@ void gallery_create(void) ctx.selected = IMGLIST_INVALID; ctx.clr_background = 0xff202020; ctx.clr_select = 0xff404040; + ctx.clr_border = 0xff000000; + ctx.clr_shadow = 0xff000000; // register configuration loader config_add_loader("gallery", load_config);