UI: invert toolbar icon colors for light toolbar button background
Fixes T64177. Differential Revision: https://developer.blender.org/D6649
This commit is contained in:
parent
5f056fb742
commit
03a29090b5
|
@ -62,8 +62,8 @@ struct Icon_Geom {
|
|||
int icon_id;
|
||||
int coords_len;
|
||||
int coords_range[2];
|
||||
const unsigned char (*coords)[2];
|
||||
const unsigned char (*colors)[4];
|
||||
unsigned char (*coords)[2];
|
||||
unsigned char (*colors)[4];
|
||||
/* when not NULL, the memory of coords and colors is a sub-region of this pointer. */
|
||||
const void *mem;
|
||||
};
|
||||
|
@ -160,6 +160,7 @@ struct Icon_Geom *BKE_icon_geom_from_file(const char *filename);
|
|||
struct ImBuf *BKE_icon_geom_rasterize(const struct Icon_Geom *geom,
|
||||
const unsigned int size_x,
|
||||
const unsigned int size_y);
|
||||
void BKE_icon_geom_invert_lightness(struct Icon_Geom *geom);
|
||||
|
||||
int BKE_icon_ensure_studio_light(struct StudioLight *sl, int id_type);
|
||||
|
||||
|
|
|
@ -842,8 +842,8 @@ struct Icon_Geom *BKE_icon_geom_from_memory(const uchar *data, size_t data_len)
|
|||
p += 2;
|
||||
|
||||
geom->coords_len = coords_len;
|
||||
geom->coords = (const void *)p;
|
||||
geom->colors = (const void *)(p + (data_len / 3));
|
||||
geom->coords = (void *)p;
|
||||
geom->colors = (void *)(p + (data_len / 3));
|
||||
geom->icon_id = 0;
|
||||
geom->mem = data;
|
||||
return geom;
|
||||
|
|
|
@ -139,3 +139,17 @@ ImBuf *BKE_icon_geom_rasterize(const struct Icon_Geom *geom,
|
|||
IMB_scaleImBuf(ibuf, size_x, size_y);
|
||||
return ibuf;
|
||||
}
|
||||
|
||||
void BKE_icon_geom_invert_lightness(struct Icon_Geom *geom)
|
||||
{
|
||||
const int length = 3 * geom->coords_len;
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
float rgb[3], hsl[3];
|
||||
|
||||
rgb_uchar_to_float(rgb, geom->colors[i]);
|
||||
rgb_to_hsl_v(rgb, hsl);
|
||||
hsl_to_rgb(hsl[0], hsl[1], 1.0f - hsl[2], &rgb[0], &rgb[1], &rgb[2]);
|
||||
rgb_float_to_uchar(geom->colors[i], rgb);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,6 +119,7 @@ typedef struct DrawInfo {
|
|||
} vector;
|
||||
struct {
|
||||
ImBuf *image_cache;
|
||||
bool inverted;
|
||||
} geom;
|
||||
struct {
|
||||
IconImage *image;
|
||||
|
@ -1833,15 +1834,23 @@ static void icon_draw_size(float x,
|
|||
}
|
||||
#endif
|
||||
|
||||
/* If the theme is light, we will adjust the icon colors. */
|
||||
const bool invert = (rgb_to_grayscale_byte(btheme->tui.wcol_toolbar_item.inner) > 128);
|
||||
const bool geom_inverted = di->data.geom.inverted;
|
||||
|
||||
/* This could re-generate often if rendered at different sizes in the one interface.
|
||||
* TODO(campbell): support caching multiple sizes. */
|
||||
ImBuf *ibuf = di->data.geom.image_cache;
|
||||
if ((ibuf == NULL) || (ibuf->x != w) || (ibuf->y != h)) {
|
||||
if ((ibuf == NULL) || (ibuf->x != w) || (ibuf->y != h) || (invert != geom_inverted)) {
|
||||
if (ibuf) {
|
||||
IMB_freeImBuf(ibuf);
|
||||
}
|
||||
if (invert != geom_inverted) {
|
||||
BKE_icon_geom_invert_lightness(icon->obj);
|
||||
}
|
||||
ibuf = BKE_icon_geom_rasterize(icon->obj, w, h);
|
||||
di->data.geom.image_cache = ibuf;
|
||||
di->data.geom.inverted = invert;
|
||||
}
|
||||
|
||||
GPU_blend_set_func_separate(
|
||||
|
|
Loading…
Reference in New Issue