UI: desaturate toolbar icons that the mouse is not over.
This does not look great with light toolbar buttons as in the default, so consider this a work in progress.
This commit is contained in:
@@ -76,6 +76,7 @@ void UI_icon_draw_preview_aspect_size(float x, float y, int icon_id, float aspec
|
||||
void UI_icon_draw_aspect(float x, float y, int icon_id, float aspect, float alpha);
|
||||
void UI_icon_draw_aspect_color(float x, float y, int icon_id, float aspect, const float rgb[3]);
|
||||
void UI_icon_draw_size(float x, float y, int size, int icon_id, float alpha);
|
||||
void UI_icon_draw_desaturate(float x, float y, int icon_id, float aspect, float alpha);
|
||||
void UI_icons_free(void);
|
||||
void UI_icons_free_drawinfo(void *drawinfo);
|
||||
|
||||
|
||||
@@ -977,7 +977,7 @@ PreviewImage *UI_icon_to_preview(int icon_id)
|
||||
}
|
||||
|
||||
static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect), int rw, int rh,
|
||||
unsigned int *rect, float alpha, const float rgb[3], const bool UNUSED(is_preview))
|
||||
unsigned int *rect, float alpha, const float rgb[3], const bool desaturate)
|
||||
{
|
||||
ImBuf *ima = NULL;
|
||||
int draw_w = w;
|
||||
@@ -1026,7 +1026,8 @@ static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect),
|
||||
UI_widgetbase_draw_cache_flush();
|
||||
|
||||
/* draw */
|
||||
IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
|
||||
GPUBuiltinShader shader = (desaturate) ? GPU_SHADER_2D_IMAGE_DESATURATE_COLOR : GPU_SHADER_2D_IMAGE_COLOR;
|
||||
IMMDrawPixelsTexState state = immDrawPixelsTexSetup(shader);
|
||||
immDrawPixelsTex(&state, draw_x, draw_y, draw_w, draw_h, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect,
|
||||
1.0f, 1.0f, col);
|
||||
|
||||
@@ -1192,7 +1193,7 @@ static int get_draw_size(enum eIconSizes size)
|
||||
|
||||
static void icon_draw_size(
|
||||
float x, float y, int icon_id, float aspect, float alpha, const float rgb[3],
|
||||
enum eIconSizes size, int draw_size, const bool UNUSED(nocreate), const bool is_preview)
|
||||
enum eIconSizes size, int draw_size, const bool desaturate)
|
||||
{
|
||||
bTheme *btheme = UI_GetTheme();
|
||||
Icon *icon = NULL;
|
||||
@@ -1250,7 +1251,7 @@ static void icon_draw_size(
|
||||
di->data.geom.image_cache = ibuf;
|
||||
}
|
||||
glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
icon_draw_rect(x, y, w, h, aspect, w, h, ibuf->rect, alpha, rgb, is_preview);
|
||||
icon_draw_rect(x, y, w, h, aspect, w, h, ibuf->rect, alpha, rgb, desaturate);
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
else if (di->type == ICON_TYPE_TEXTURE) {
|
||||
@@ -1269,7 +1270,7 @@ static void icon_draw_size(
|
||||
if (!iimg->rect) return; /* something has gone wrong! */
|
||||
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, rgb, is_preview);
|
||||
icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, rgb, desaturate);
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
else if (di->type == ICON_TYPE_PREVIEW) {
|
||||
@@ -1282,7 +1283,7 @@ static void icon_draw_size(
|
||||
/* preview images use premul alpha ... */
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
icon_draw_rect(x, y, w, h, aspect, pi->w[size], pi->h[size], pi->rect[size], alpha, rgb, is_preview);
|
||||
icon_draw_rect(x, y, w, h, aspect, pi->w[size], pi->h[size], pi->rect[size], alpha, rgb, desaturate);
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
}
|
||||
@@ -1528,21 +1529,26 @@ int UI_idcode_icon_get(const int idcode)
|
||||
|
||||
static void icon_draw_at_size(
|
||||
float x, float y, int icon_id, float aspect, float alpha,
|
||||
enum eIconSizes size, const bool nocreate)
|
||||
enum eIconSizes size, const bool desaturate)
|
||||
{
|
||||
int draw_size = get_draw_size(size);
|
||||
icon_draw_size(x, y, icon_id, aspect, alpha, NULL, size, draw_size, nocreate, false);
|
||||
icon_draw_size(x, y, icon_id, aspect, alpha, NULL, size, draw_size, desaturate);
|
||||
}
|
||||
|
||||
void UI_icon_draw_aspect(float x, float y, int icon_id, float aspect, float alpha)
|
||||
{
|
||||
icon_draw_at_size(x, y, icon_id, aspect, alpha, ICON_SIZE_ICON, 0);
|
||||
icon_draw_at_size(x, y, icon_id, aspect, alpha, ICON_SIZE_ICON, false);
|
||||
}
|
||||
|
||||
void UI_icon_draw_aspect_color(float x, float y, int icon_id, float aspect, const float rgb[3])
|
||||
{
|
||||
int draw_size = get_draw_size(ICON_SIZE_ICON);
|
||||
icon_draw_size(x, y, icon_id, aspect, 1.0f, rgb, ICON_SIZE_ICON, draw_size, false, false);
|
||||
icon_draw_size(x, y, icon_id, aspect, 1.0f, rgb, ICON_SIZE_ICON, draw_size, false);
|
||||
}
|
||||
|
||||
void UI_icon_draw_desaturate(float x, float y, int icon_id, float aspect, float alpha)
|
||||
{
|
||||
icon_draw_at_size(x, y, icon_id, aspect, alpha, ICON_SIZE_ICON, true);
|
||||
}
|
||||
|
||||
/* draws icon with dpi scale factor */
|
||||
@@ -1558,21 +1564,21 @@ void UI_icon_draw_alpha(float x, float y, int icon_id, float alpha)
|
||||
|
||||
void UI_icon_draw_size(float x, float y, int size, int icon_id, float alpha)
|
||||
{
|
||||
icon_draw_size(x, y, icon_id, 1.0f, alpha, NULL, ICON_SIZE_ICON, size, true, false);
|
||||
icon_draw_size(x, y, icon_id, 1.0f, alpha, NULL, ICON_SIZE_ICON, size, false);
|
||||
}
|
||||
|
||||
void UI_icon_draw_preview(float x, float y, int icon_id)
|
||||
{
|
||||
icon_draw_at_size(x, y, icon_id, 1.0f, 1.0f, ICON_SIZE_PREVIEW, 0);
|
||||
icon_draw_at_size(x, y, icon_id, 1.0f, 1.0f, ICON_SIZE_PREVIEW, false);
|
||||
}
|
||||
|
||||
void UI_icon_draw_preview_aspect(float x, float y, int icon_id, float aspect)
|
||||
{
|
||||
icon_draw_at_size(x, y, icon_id, aspect, 1.0f, ICON_SIZE_PREVIEW, 0);
|
||||
icon_draw_at_size(x, y, icon_id, aspect, 1.0f, ICON_SIZE_PREVIEW, false);
|
||||
}
|
||||
|
||||
void UI_icon_draw_preview_aspect_size(float x, float y, int icon_id, float aspect, float alpha, int size)
|
||||
{
|
||||
icon_draw_size(x, y, icon_id, aspect, alpha, NULL, ICON_SIZE_PREVIEW, size, false, true);
|
||||
icon_draw_size(x, y, icon_id, aspect, alpha, NULL, ICON_SIZE_PREVIEW, size, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -1317,14 +1317,18 @@ static void widget_draw_icon_ex(
|
||||
xs = (int)(xs + 0.1f);
|
||||
ys = (int)(ys + 0.1f);
|
||||
}
|
||||
|
||||
|
||||
/* to indicate draggable */
|
||||
if (but->dragpoin && (but->flag & UI_ACTIVE)) {
|
||||
float rgb[3] = {1.25f, 1.25f, 1.25f};
|
||||
UI_icon_draw_aspect_color(xs, ys, icon, aspect, rgb);
|
||||
}
|
||||
else
|
||||
else if ((but->flag & (UI_ACTIVE | UI_SELECT | UI_SELECT_DRAW)) || !UI_but_is_tool(but)) {
|
||||
UI_icon_draw_aspect(xs, ys, icon, aspect, alpha);
|
||||
}
|
||||
else {
|
||||
UI_icon_draw_desaturate(xs, ys, icon, aspect, alpha);
|
||||
}
|
||||
}
|
||||
|
||||
if (show_menu_icon) {
|
||||
|
||||
@@ -147,6 +147,7 @@ data_to_c_simple(shaders/gpu_shader_2D_image_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_2D_image_rect_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_2D_image_multi_rect_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_image_frag.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_image_desaturate_frag.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_image_linear_frag.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_image_shuffle_color_frag.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_image_mask_uniform_color_frag.glsl SRC)
|
||||
|
||||
@@ -114,6 +114,7 @@ typedef enum GPUBuiltinShader {
|
||||
GPU_SHADER_2D_SMOOTH_COLOR_DITHER,
|
||||
GPU_SHADER_2D_IMAGE,
|
||||
GPU_SHADER_2D_IMAGE_COLOR,
|
||||
GPU_SHADER_2D_IMAGE_DESATURATE_COLOR,
|
||||
GPU_SHADER_2D_IMAGE_ALPHA_COLOR,
|
||||
GPU_SHADER_2D_IMAGE_ALPHA,
|
||||
GPU_SHADER_2D_IMAGE_RECT_COLOR,
|
||||
|
||||
@@ -81,6 +81,7 @@ extern char datatoc_gpu_shader_3D_image_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_image_frag_glsl[];
|
||||
extern char datatoc_gpu_shader_image_linear_frag_glsl[];
|
||||
extern char datatoc_gpu_shader_image_color_frag_glsl[];
|
||||
extern char datatoc_gpu_shader_image_desaturate_frag_glsl[];
|
||||
extern char datatoc_gpu_shader_image_varying_color_frag_glsl[];
|
||||
extern char datatoc_gpu_shader_image_alpha_color_frag_glsl[];
|
||||
extern char datatoc_gpu_shader_image_shuffle_color_frag_glsl[];
|
||||
@@ -709,6 +710,8 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
|
||||
datatoc_gpu_shader_image_frag_glsl },
|
||||
[GPU_SHADER_2D_IMAGE_COLOR] = { datatoc_gpu_shader_2D_image_vert_glsl,
|
||||
datatoc_gpu_shader_image_color_frag_glsl },
|
||||
[GPU_SHADER_2D_IMAGE_DESATURATE_COLOR] = { datatoc_gpu_shader_2D_image_vert_glsl,
|
||||
datatoc_gpu_shader_image_desaturate_frag_glsl },
|
||||
[GPU_SHADER_2D_IMAGE_ALPHA_COLOR] = { datatoc_gpu_shader_2D_image_vert_glsl,
|
||||
datatoc_gpu_shader_image_alpha_color_frag_glsl },
|
||||
[GPU_SHADER_2D_IMAGE_ALPHA] = { datatoc_gpu_shader_2D_image_vert_glsl,
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
in vec2 texCoord_interp;
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform vec4 color;
|
||||
uniform sampler2D image;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 tex = texture(image, texCoord_interp);
|
||||
tex.rgb = 0.3333333 * vec3(tex.r + tex.g + tex.b);
|
||||
fragColor = tex * color;
|
||||
}
|
||||
Reference in New Issue
Block a user