Skip to content

Commit

Permalink
Set dark background for help text block
Browse files Browse the repository at this point in the history
Makes help text more readable on white images.

Resolves #185.

Signed-off-by: Artem Senichev <artemsen@gmail.com>
  • Loading branch information
artemsen committed Sep 13, 2024
1 parent 7f89292 commit 9ed85af
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ bool app_init(struct config* cfg, const char** sources, size_t num)

// initialize other subsystems
font_init(cfg);
info_init(cfg);
keybind_init(cfg);
info_init(cfg);
loader_init();
viewer_init(cfg, ctx.ehandler == viewer_handle ? first_image : NULL);
gallery_init(cfg, ctx.ehandler == gallery_handle ? first_image : NULL);
Expand Down Expand Up @@ -455,8 +455,8 @@ void app_destroy(void)
viewer_destroy();
ui_destroy();
image_list_destroy();
keybind_destroy();
info_destroy();
keybind_destroy();
font_destroy();

for (size_t i = 0; i < ctx.wfds_num; ++i) {
Expand Down
5 changes: 5 additions & 0 deletions src/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ static void print_help(struct pixmap* window)
top = window->height / 2 - (rows * line_height) / 2;
}

// darken text block background
pixmap_blend(window, left - TEXT_PADDING, top - TEXT_PADDING,
total_width + TEXT_PADDING, rows * line_height + TEXT_PADDING,
ARGB(0xa0, 0, 0, 0));

// put text on window
for (size_t col = 0; col < columns; ++col) {
size_t y = top;
Expand Down
24 changes: 20 additions & 4 deletions src/pixmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ void pixmap_inverse_fill(struct pixmap* pm, ssize_t x, ssize_t y, size_t width,
}
}

void pixmap_blend(struct pixmap* pm, ssize_t x, ssize_t y, size_t width,
size_t height, argb_t color)
{
const ssize_t left = max(0, x);
const ssize_t top = max(0, y);
const ssize_t right = min((ssize_t)pm->width, x + (ssize_t)width);
const ssize_t bottom = min((ssize_t)pm->height, y + (ssize_t)height);

for (y = top; y < bottom; ++y) {
argb_t* line = &pm->data[y * pm->width];
for (x = left; x < right; ++x) {
alpha_blend(color, &line[x]);
}
}
}

void pixmap_hline(struct pixmap* pm, ssize_t x, ssize_t y, size_t width,
argb_t color)
{
Expand Down Expand Up @@ -163,22 +179,22 @@ void pixmap_grid(struct pixmap* pm, ssize_t x, ssize_t y, size_t width,
}
}

void pixmap_apply_mask(struct pixmap* dst, ssize_t x, ssize_t y,
void pixmap_apply_mask(struct pixmap* pm, ssize_t x, ssize_t y,
const uint8_t* mask, size_t width, size_t height,
argb_t color)
{
const ssize_t left = max(0, x);
const ssize_t top = max(0, y);
const ssize_t right = min((ssize_t)dst->width, x + (ssize_t)width);
const ssize_t bottom = min((ssize_t)dst->height, y + (ssize_t)height);
const ssize_t right = min((ssize_t)pm->width, x + (ssize_t)width);
const ssize_t bottom = min((ssize_t)pm->height, y + (ssize_t)height);
const ssize_t dst_width = right - left;
const ssize_t delta_x = left - x;
const ssize_t delta_y = top - y;

for (ssize_t dst_y = top; dst_y < bottom; ++dst_y) {
const size_t src_y = dst_y - top + delta_y;
const uint8_t* mask_line = &mask[src_y * width + delta_x];
argb_t* dst_line = &dst->data[dst_y * dst->width + left];
argb_t* dst_line = &pm->data[dst_y * pm->width + left];

for (x = 0; x < dst_width; ++x) {
const uint8_t alpha_mask = mask_line[x];
Expand Down
14 changes: 12 additions & 2 deletions src/pixmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ void pixmap_fill(struct pixmap* pm, ssize_t x, ssize_t y, size_t width,
void pixmap_inverse_fill(struct pixmap* pm, ssize_t x, ssize_t y, size_t width,
size_t height, argb_t color);

/**
* Blend area with specified color.
* @param pm pixmap context
* @param x,y start coordinates, left top point
* @param width,height region size
* @param color color to set
*/
void pixmap_blend(struct pixmap* pm, ssize_t x, ssize_t y, size_t width,
size_t height, argb_t color);

/**
* Draw horizontal line.
* @param pm pixmap context
Expand Down Expand Up @@ -124,13 +134,13 @@ void pixmap_grid(struct pixmap* pm, ssize_t x, ssize_t y, size_t width,

/**
* Apply mask to pixmap: change color according alpha channel.
* @param dst destination pixmap
* @param pm destination pixmap
* @param x,y destination left top point
* @param mask array with alpha channel mask
* @param width,height mask size
* @param color color to set
*/
void pixmap_apply_mask(struct pixmap* dst, ssize_t x, ssize_t y,
void pixmap_apply_mask(struct pixmap* pm, ssize_t x, ssize_t y,
const uint8_t* mask, size_t width, size_t height,
argb_t color);

Expand Down

0 comments on commit 9ed85af

Please sign in to comment.