Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_draw.cc
- This file was moved from source/blender/editors/interface/interface_draw.c.
| /* SPDX-License-Identifier: GPL-2.0-or-later | /* SPDX-License-Identifier: GPL-2.0-or-later | ||||
| * Copyright 2001-2002 NaN Holding BV. All rights reserved. */ | * Copyright 2001-2002 NaN Holding BV. All rights reserved. */ | ||||
| /** \file | /** \file | ||||
| * \ingroup edinterface | * \ingroup edinterface | ||||
| */ | */ | ||||
| #include <math.h> | #include <cmath> | ||||
| #include <string.h> | #include <cstring> | ||||
| #include "DNA_color_types.h" | #include "DNA_color_types.h" | ||||
| #include "DNA_curve_types.h" | #include "DNA_curve_types.h" | ||||
| #include "DNA_curveprofile_types.h" | #include "DNA_curveprofile_types.h" | ||||
| #include "DNA_movieclip_types.h" | #include "DNA_movieclip_types.h" | ||||
| #include "DNA_screen_types.h" | #include "DNA_screen_types.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| ▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | void UI_draw_roundbox_4fv_ex(const rctf *rect, | ||||
| const float inner2[4], | const float inner2[4], | ||||
| float shade_dir, | float shade_dir, | ||||
| const float outline[4], | const float outline[4], | ||||
| float outline_width, | float outline_width, | ||||
| float rad) | float rad) | ||||
| { | { | ||||
| /* WATCH: This is assuming the ModelViewProjectionMatrix is area pixel space. | /* WATCH: This is assuming the ModelViewProjectionMatrix is area pixel space. | ||||
| * If it has been scaled, then it's no longer valid. */ | * If it has been scaled, then it's no longer valid. */ | ||||
| uiWidgetBaseParameters widget_params = { | uiWidgetBaseParameters widget_params{}; | ||||
| .recti.xmin = rect->xmin + outline_width, | widget_params.recti.xmin = rect->xmin + outline_width; | ||||
| .recti.ymin = rect->ymin + outline_width, | widget_params.recti.ymin = rect->ymin + outline_width; | ||||
| .recti.xmax = rect->xmax - outline_width, | widget_params.recti.xmax = rect->xmax - outline_width; | ||||
| .recti.ymax = rect->ymax - outline_width, | widget_params.recti.ymax = rect->ymax - outline_width; | ||||
| .rect = *rect, | widget_params.rect = *rect; | ||||
| .radi = rad, | widget_params.radi = rad; | ||||
| .rad = rad, | widget_params.rad = rad; | ||||
| .round_corners[0] = (roundboxtype & UI_CNR_BOTTOM_LEFT) ? 1.0f : 0.0f, | widget_params.round_corners[0] = (roundboxtype & UI_CNR_BOTTOM_LEFT) ? 1.0f : 0.0f; | ||||
| .round_corners[1] = (roundboxtype & UI_CNR_BOTTOM_RIGHT) ? 1.0f : 0.0f, | widget_params.round_corners[1] = (roundboxtype & UI_CNR_BOTTOM_RIGHT) ? 1.0f : 0.0f; | ||||
| .round_corners[2] = (roundboxtype & UI_CNR_TOP_RIGHT) ? 1.0f : 0.0f, | widget_params.round_corners[2] = (roundboxtype & UI_CNR_TOP_RIGHT) ? 1.0f : 0.0f; | ||||
| .round_corners[3] = (roundboxtype & UI_CNR_TOP_LEFT) ? 1.0f : 0.0f, | widget_params.round_corners[3] = (roundboxtype & UI_CNR_TOP_LEFT) ? 1.0f : 0.0f; | ||||
| .color_inner1[0] = inner1 ? inner1[0] : 0.0f, | widget_params.color_inner1[0] = inner1 ? inner1[0] : 0.0f; | ||||
| .color_inner1[1] = inner1 ? inner1[1] : 0.0f, | widget_params.color_inner1[1] = inner1 ? inner1[1] : 0.0f; | ||||
| .color_inner1[2] = inner1 ? inner1[2] : 0.0f, | widget_params.color_inner1[2] = inner1 ? inner1[2] : 0.0f; | ||||
| .color_inner1[3] = inner1 ? inner1[3] : 0.0f, | widget_params.color_inner1[3] = inner1 ? inner1[3] : 0.0f; | ||||
| .color_inner2[0] = inner2 ? inner2[0] : | widget_params.color_inner2[0] = inner2 ? inner2[0] : inner1 ? inner1[0] : 0.0f; | ||||
| inner1 ? inner1[0] : | widget_params.color_inner2[1] = inner2 ? inner2[1] : inner1 ? inner1[1] : 0.0f; | ||||
| 0.0f, | widget_params.color_inner2[2] = inner2 ? inner2[2] : inner1 ? inner1[2] : 0.0f; | ||||
| .color_inner2[1] = inner2 ? inner2[1] : | widget_params.color_inner2[3] = inner2 ? inner2[3] : inner1 ? inner1[3] : 0.0f; | ||||
| inner1 ? inner1[1] : | widget_params.color_outline[0] = outline ? outline[0] : inner1 ? inner1[0] : 0.0f; | ||||
| 0.0f, | widget_params.color_outline[1] = outline ? outline[1] : inner1 ? inner1[1] : 0.0f; | ||||
| .color_inner2[2] = inner2 ? inner2[2] : | widget_params.color_outline[2] = outline ? outline[2] : inner1 ? inner1[2] : 0.0f; | ||||
| inner1 ? inner1[2] : | widget_params.color_outline[3] = outline ? outline[3] : inner1 ? inner1[3] : 0.0f; | ||||
| 0.0f, | widget_params.shade_dir = shade_dir; | ||||
| .color_inner2[3] = inner2 ? inner2[3] : | widget_params.alpha_discard = 1.0f; | ||||
| inner1 ? inner1[3] : | |||||
| 0.0f, | |||||
| .color_outline[0] = outline ? outline[0] : | |||||
| inner1 ? inner1[0] : | |||||
| 0.0f, | |||||
| .color_outline[1] = outline ? outline[1] : | |||||
| inner1 ? inner1[1] : | |||||
| 0.0f, | |||||
| .color_outline[2] = outline ? outline[2] : | |||||
| inner1 ? inner1[2] : | |||||
| 0.0f, | |||||
| .color_outline[3] = outline ? outline[3] : | |||||
| inner1 ? inner1[3] : | |||||
| 0.0f, | |||||
| .shade_dir = shade_dir, | |||||
| .alpha_discard = 1.0f, | |||||
| }; | |||||
| GPUBatch *batch = ui_batch_roundbox_widget_get(); | GPUBatch *batch = ui_batch_roundbox_widget_get(); | ||||
| GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_BASE); | GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_BASE); | ||||
| GPU_batch_uniform_4fv_array(batch, "parameters", 11, (const float(*)[4]) & widget_params); | GPU_batch_uniform_4fv_array(batch, "parameters", 11, (const float(*)[4]) & widget_params); | ||||
| GPU_blend(GPU_BLEND_ALPHA); | GPU_blend(GPU_BLEND_ALPHA); | ||||
| GPU_batch_draw(batch); | GPU_batch_draw(batch); | ||||
| GPU_blend(GPU_BLEND_NONE); | GPU_blend(GPU_BLEND_NONE); | ||||
| } | } | ||||
| void UI_draw_roundbox_3ub_alpha( | void UI_draw_roundbox_3ub_alpha( | ||||
| const rctf *rect, bool filled, float rad, const uchar col[3], uchar alpha) | const rctf *rect, bool filled, float rad, const uchar col[3], uchar alpha) | ||||
| { | { | ||||
| const float colv[4] = { | const float colv[4] = { | ||||
| ((float)col[0]) / 255, | (float(col[0])) / 255.0f, | ||||
| ((float)col[1]) / 255, | (float(col[1])) / 255.0f, | ||||
| ((float)col[2]) / 255, | (float(col[2])) / 255.0f, | ||||
| ((float)alpha) / 255, | (float(alpha)) / 255.0f, | ||||
| }; | }; | ||||
| UI_draw_roundbox_4fv_ex(rect, (filled) ? colv : NULL, NULL, 1.0f, colv, U.pixelsize, rad); | UI_draw_roundbox_4fv_ex(rect, (filled) ? colv : nullptr, nullptr, 1.0f, colv, U.pixelsize, rad); | ||||
| } | } | ||||
| void UI_draw_roundbox_3fv_alpha( | void UI_draw_roundbox_3fv_alpha( | ||||
| const rctf *rect, bool filled, float rad, const float col[3], float alpha) | const rctf *rect, bool filled, float rad, const float col[3], float alpha) | ||||
| { | { | ||||
| const float colv[4] = {col[0], col[1], col[2], alpha}; | const float colv[4] = {col[0], col[1], col[2], alpha}; | ||||
| UI_draw_roundbox_4fv_ex(rect, (filled) ? colv : NULL, NULL, 1.0f, colv, U.pixelsize, rad); | UI_draw_roundbox_4fv_ex(rect, (filled) ? colv : nullptr, nullptr, 1.0f, colv, U.pixelsize, rad); | ||||
| } | } | ||||
| void UI_draw_roundbox_aa(const rctf *rect, bool filled, float rad, const float color[4]) | void UI_draw_roundbox_aa(const rctf *rect, bool filled, float rad, const float color[4]) | ||||
| { | { | ||||
| /* XXX this is to emulate previous behavior of semitransparent fills but that's was a side effect | /* XXX this is to emulate previous behavior of semitransparent fills but that's was a side effect | ||||
| * of the previous AA method. Better fix the callers. */ | * of the previous AA method. Better fix the callers. */ | ||||
| float colv[4] = {color[0], color[1], color[2], color[3]}; | float colv[4] = {color[0], color[1], color[2], color[3]}; | ||||
| if (filled) { | if (filled) { | ||||
| colv[3] *= 0.65f; | colv[3] *= 0.65f; | ||||
| } | } | ||||
| UI_draw_roundbox_4fv_ex(rect, (filled) ? colv : NULL, NULL, 1.0f, colv, U.pixelsize, rad); | UI_draw_roundbox_4fv_ex(rect, (filled) ? colv : nullptr, nullptr, 1.0f, colv, U.pixelsize, rad); | ||||
| } | } | ||||
| void UI_draw_roundbox_4fv(const rctf *rect, bool filled, float rad, const float col[4]) | void UI_draw_roundbox_4fv(const rctf *rect, bool filled, float rad, const float col[4]) | ||||
| { | { | ||||
| /* Exactly the same as UI_draw_roundbox_aa but does not do the legacy transparency. */ | /* Exactly the same as UI_draw_roundbox_aa but does not do the legacy transparency. */ | ||||
| UI_draw_roundbox_4fv_ex(rect, (filled) ? col : NULL, NULL, 1.0f, col, U.pixelsize, rad); | UI_draw_roundbox_4fv_ex(rect, (filled) ? col : nullptr, nullptr, 1.0f, col, U.pixelsize, rad); | ||||
| } | } | ||||
| void UI_draw_text_underline(int pos_x, int pos_y, int len, int height, const float color[4]) | void UI_draw_text_underline(int pos_x, int pos_y, int len, int height, const float color[4]) | ||||
| { | { | ||||
| const int ofs_y = 4 * U.pixelsize; | const int ofs_y = 4 * U.pixelsize; | ||||
| GPUVertFormat *format = immVertexFormat(); | GPUVertFormat *format = immVertexFormat(); | ||||
| const uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); | const uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); | ||||
| ▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | void ui_draw_but_TAB_outline(const rcti *rect, | ||||
| /* back to corner left-top */ | /* back to corner left-top */ | ||||
| immVertex2f(pos, minx, (roundboxtype & UI_CNR_TOP_LEFT) ? (maxy - rad) : maxy); | immVertex2f(pos, minx, (roundboxtype & UI_CNR_TOP_LEFT) ? (maxy - rad) : maxy); | ||||
| immEnd(); | immEnd(); | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| } | } | ||||
| void ui_draw_but_IMAGE(ARegion *UNUSED(region), | void ui_draw_but_IMAGE(ARegion * /*region*/, | ||||
| uiBut *but, | uiBut *but, | ||||
| const uiWidgetColors *UNUSED(wcol), | const uiWidgetColors * /*wcol*/, | ||||
| const rcti *rect) | const rcti *rect) | ||||
| { | { | ||||
| #ifdef WITH_HEADLESS | #ifdef WITH_HEADLESS | ||||
| (void)rect; | (void)rect; | ||||
| (void)but; | (void)but; | ||||
| #else | #else | ||||
| ImBuf *ibuf = (ImBuf *)but->poin; | ImBuf *ibuf = (ImBuf *)but->poin; | ||||
| Show All 23 Lines | # endif | ||||
| float col[4] = {1.0f, 1.0f, 1.0f, 1.0f}; | float col[4] = {1.0f, 1.0f, 1.0f, 1.0f}; | ||||
| if (but->col[3] != 0) { | if (but->col[3] != 0) { | ||||
| /* Optionally use uiBut's col to recolor the image. */ | /* Optionally use uiBut's col to recolor the image. */ | ||||
| rgba_uchar_to_float(col, but->col); | rgba_uchar_to_float(col, but->col); | ||||
| } | } | ||||
| IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_3D_IMAGE_COLOR); | IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_3D_IMAGE_COLOR); | ||||
| immDrawPixelsTexTiled(&state, | immDrawPixelsTexTiled(&state, | ||||
| (float)rect->xmin, | float(rect->xmin), | ||||
| (float)rect->ymin, | float(rect->ymin), | ||||
| ibuf->x, | ibuf->x, | ||||
| ibuf->y, | ibuf->y, | ||||
| GPU_RGBA8, | GPU_RGBA8, | ||||
| false, | false, | ||||
| ibuf->rect, | ibuf->rect, | ||||
| 1.0f, | 1.0f, | ||||
| 1.0f, | 1.0f, | ||||
| col); | col); | ||||
| Show All 36 Lines | |||||
| static void draw_scope_end(const rctf *rect) | static void draw_scope_end(const rctf *rect) | ||||
| { | { | ||||
| GPU_blend(GPU_BLEND_ALPHA); | GPU_blend(GPU_BLEND_ALPHA); | ||||
| /* outline */ | /* outline */ | ||||
| UI_draw_roundbox_corner_set(UI_CNR_ALL); | UI_draw_roundbox_corner_set(UI_CNR_ALL); | ||||
| const float color[4] = {0.0f, 0.0f, 0.0f, 0.5f}; | const float color[4] = {0.0f, 0.0f, 0.0f, 0.5f}; | ||||
| UI_draw_roundbox_4fv( | rctf box_rect{}; | ||||
| &(const rctf){ | box_rect.xmin = rect->xmin - 1; | ||||
| .xmin = rect->xmin - 1, | box_rect.xmax = rect->xmax + 1; | ||||
| .xmax = rect->xmax + 1, | box_rect.ymin = rect->ymin; | ||||
| .ymin = rect->ymin, | box_rect.ymax = rect->ymax + 1; | ||||
| .ymax = rect->ymax + 1, | UI_draw_roundbox_4fv(&box_rect, false, 3.0f, color); | ||||
| }, | |||||
| false, | |||||
| 3.0f, | |||||
| color); | |||||
| } | } | ||||
| static void histogram_draw_one(float r, | static void histogram_draw_one(float r, | ||||
| float g, | float g, | ||||
| float b, | float b, | ||||
| float alpha, | float alpha, | ||||
| float x, | float x, | ||||
| float y, | float y, | ||||
| Show All 17 Lines | static void histogram_draw_one(float r, | ||||
| immUniformColor4fv(color); | immUniformColor4fv(color); | ||||
| if (is_line) { | if (is_line) { | ||||
| /* curve outline */ | /* curve outline */ | ||||
| GPU_line_width(1.5); | GPU_line_width(1.5); | ||||
| immBegin(GPU_PRIM_LINE_STRIP, res); | immBegin(GPU_PRIM_LINE_STRIP, res); | ||||
| for (int i = 0; i < res; i++) { | for (int i = 0; i < res; i++) { | ||||
| const float x2 = x + i * (w / (float)res); | const float x2 = x + i * (w / float(res)); | ||||
| immVertex2f(pos_attr, x2, y + (data[i] * h)); | immVertex2f(pos_attr, x2, y + (data[i] * h)); | ||||
| } | } | ||||
| immEnd(); | immEnd(); | ||||
| GPU_line_width(1.0f); | GPU_line_width(1.0f); | ||||
| } | } | ||||
| else { | else { | ||||
| /* under the curve */ | /* under the curve */ | ||||
| immBegin(GPU_PRIM_TRI_STRIP, res * 2); | immBegin(GPU_PRIM_TRI_STRIP, res * 2); | ||||
| immVertex2f(pos_attr, x, y); | immVertex2f(pos_attr, x, y); | ||||
| immVertex2f(pos_attr, x, y + (data[0] * h)); | immVertex2f(pos_attr, x, y + (data[0] * h)); | ||||
| for (int i = 1; i < res; i++) { | for (int i = 1; i < res; i++) { | ||||
| const float x2 = x + i * (w / (float)res); | const float x2 = x + i * (w / float(res)); | ||||
| immVertex2f(pos_attr, x2, y + (data[i] * h)); | immVertex2f(pos_attr, x2, y + (data[i] * h)); | ||||
| immVertex2f(pos_attr, x2, y); | immVertex2f(pos_attr, x2, y); | ||||
| } | } | ||||
| immEnd(); | immEnd(); | ||||
| /* curve outline */ | /* curve outline */ | ||||
| immUniformColor4f(0.0f, 0.0f, 0.0f, 0.25f); | immUniformColor4f(0.0f, 0.0f, 0.0f, 0.25f); | ||||
| GPU_blend(GPU_BLEND_ALPHA); | GPU_blend(GPU_BLEND_ALPHA); | ||||
| immBegin(GPU_PRIM_LINE_STRIP, res); | immBegin(GPU_PRIM_LINE_STRIP, res); | ||||
| for (int i = 0; i < res; i++) { | for (int i = 0; i < res; i++) { | ||||
| const float x2 = x + i * (w / (float)res); | const float x2 = x + i * (w / float(res)); | ||||
| immVertex2f(pos_attr, x2, y + (data[i] * h)); | immVertex2f(pos_attr, x2, y + (data[i] * h)); | ||||
| } | } | ||||
| immEnd(); | immEnd(); | ||||
| } | } | ||||
| GPU_line_smooth(false); | GPU_line_smooth(false); | ||||
| } | } | ||||
| #define HISTOGRAM_TOT_GRID_LINES 4 | #define HISTOGRAM_TOT_GRID_LINES 4 | ||||
| void ui_draw_but_HISTOGRAM(ARegion *UNUSED(region), | void ui_draw_but_HISTOGRAM(ARegion * /*region*/, | ||||
| uiBut *but, | uiBut *but, | ||||
| const uiWidgetColors *UNUSED(wcol), | const uiWidgetColors * /*wcol*/, | ||||
| const rcti *recti) | const rcti *recti) | ||||
| { | { | ||||
| Histogram *hist = (Histogram *)but->poin; | Histogram *hist = (Histogram *)but->poin; | ||||
| const int res = hist->x_resolution; | const int res = hist->x_resolution; | ||||
| const bool is_line = (hist->flag & HISTO_FLAG_LINE) != 0; | const bool is_line = (hist->flag & HISTO_FLAG_LINE) != 0; | ||||
| rctf rect = { | rctf rect{}; | ||||
| .xmin = (float)recti->xmin + 1, | rect.xmin = float(recti->xmin + 1); | ||||
| .xmax = (float)recti->xmax - 1, | rect.xmax = float(recti->xmax - 1); | ||||
| .ymin = (float)recti->ymin + 1, | rect.ymin = float(recti->ymin + 1); | ||||
| .ymax = (float)recti->ymax - 1, | rect.ymax = float(recti->ymax - 1); | ||||
| }; | |||||
| const float w = BLI_rctf_size_x(&rect); | const float w = BLI_rctf_size_x(&rect); | ||||
| const float h = BLI_rctf_size_y(&rect) * hist->ymax; | const float h = BLI_rctf_size_y(&rect) * hist->ymax; | ||||
| GPU_blend(GPU_BLEND_ALPHA); | GPU_blend(GPU_BLEND_ALPHA); | ||||
| float color[4]; | float color[4]; | ||||
| UI_GetThemeColor4fv(TH_PREVIEW_BACK, color); | UI_GetThemeColor4fv(TH_PREVIEW_BACK, color); | ||||
| UI_draw_roundbox_corner_set(UI_CNR_ALL); | UI_draw_roundbox_corner_set(UI_CNR_ALL); | ||||
| UI_draw_roundbox_4fv( | rctf back_rect{}; | ||||
| &(const rctf){ | back_rect.xmin = rect.xmin - 1; | ||||
| .xmin = rect.xmin - 1, | back_rect.xmax = rect.xmax + 1; | ||||
| .xmax = rect.xmax + 1, | back_rect.ymin = rect.ymin - 1; | ||||
| .ymin = rect.ymin - 1, | back_rect.ymax = rect.ymax + 1; | ||||
| .ymax = rect.ymax + 1, | |||||
| }, | UI_draw_roundbox_4fv(&back_rect, true, 3.0f, color); | ||||
| true, | |||||
| 3.0f, | |||||
| color); | |||||
| /* need scissor test, histogram can draw outside of boundary */ | /* need scissor test, histogram can draw outside of boundary */ | ||||
| int scissor[4]; | int scissor[4]; | ||||
| GPU_scissor_get(scissor); | GPU_scissor_get(scissor); | ||||
| GPU_scissor((rect.xmin - 1), | GPU_scissor((rect.xmin - 1), | ||||
| (rect.ymin - 1), | (rect.ymin - 1), | ||||
| (rect.xmax + 1) - (rect.xmin - 1), | (rect.xmax + 1) - (rect.xmin - 1), | ||||
| (rect.ymax + 1) - (rect.ymin - 1)); | (rect.ymax + 1) - (rect.ymin - 1)); | ||||
| GPUVertFormat *format = immVertexFormat(); | GPUVertFormat *format = immVertexFormat(); | ||||
| const uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | const uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | ||||
| immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); | immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); | ||||
| immUniformColor4f(1.0f, 1.0f, 1.0f, 0.08f); | immUniformColor4f(1.0f, 1.0f, 1.0f, 0.08f); | ||||
| /* draw grid lines here */ | /* draw grid lines here */ | ||||
| for (int i = 1; i <= HISTOGRAM_TOT_GRID_LINES; i++) { | for (int i = 1; i <= HISTOGRAM_TOT_GRID_LINES; i++) { | ||||
| const float fac = (float)i / (float)HISTOGRAM_TOT_GRID_LINES; | const float fac = float(i) / float(HISTOGRAM_TOT_GRID_LINES); | ||||
| /* so we can tell the 1.0 color point */ | /* so we can tell the 1.0 color point */ | ||||
| if (i == HISTOGRAM_TOT_GRID_LINES) { | if (i == HISTOGRAM_TOT_GRID_LINES) { | ||||
| immUniformColor4f(1.0f, 1.0f, 1.0f, 0.5f); | immUniformColor4f(1.0f, 1.0f, 1.0f, 0.5f); | ||||
| } | } | ||||
| immBegin(GPU_PRIM_LINES, 4); | immBegin(GPU_PRIM_LINES, 4); | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | static void waveform_draw_one(float *waveform, int waveform_num, const float col[3]) | ||||
| const uint pos_id = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | const uint pos_id = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | ||||
| GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format); | GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format); | ||||
| GPU_vertbuf_data_alloc(vbo, waveform_num); | GPU_vertbuf_data_alloc(vbo, waveform_num); | ||||
| GPU_vertbuf_attr_fill(vbo, pos_id, waveform); | GPU_vertbuf_attr_fill(vbo, pos_id, waveform); | ||||
| /* TODO: store the #GPUBatch inside the scope. */ | /* TODO: store the #GPUBatch inside the scope. */ | ||||
| GPUBatch *batch = GPU_batch_create_ex(GPU_PRIM_POINTS, vbo, NULL, GPU_BATCH_OWNS_VBO); | GPUBatch *batch = GPU_batch_create_ex(GPU_PRIM_POINTS, vbo, nullptr, GPU_BATCH_OWNS_VBO); | ||||
| GPU_batch_program_set_builtin(batch, GPU_SHADER_3D_UNIFORM_COLOR); | GPU_batch_program_set_builtin(batch, GPU_SHADER_3D_UNIFORM_COLOR); | ||||
| GPU_batch_uniform_4f(batch, "color", col[0], col[1], col[2], 1.0f); | GPU_batch_uniform_4f(batch, "color", col[0], col[1], col[2], 1.0f); | ||||
| GPU_batch_draw(batch); | GPU_batch_draw(batch); | ||||
| GPU_batch_discard(batch); | GPU_batch_discard(batch); | ||||
| } | } | ||||
| void ui_draw_but_WAVEFORM(ARegion *UNUSED(region), | void ui_draw_but_WAVEFORM(ARegion * /*region*/, | ||||
| uiBut *but, | uiBut *but, | ||||
| const uiWidgetColors *UNUSED(wcol), | const uiWidgetColors * /*wcol*/, | ||||
| const rcti *recti) | const rcti *recti) | ||||
| { | { | ||||
| Scopes *scopes = (Scopes *)but->poin; | Scopes *scopes = (Scopes *)but->poin; | ||||
| int scissor[4]; | int scissor[4]; | ||||
| float colors[3][3]; | float colors[3][3]; | ||||
| const float colorsycc[3][3] = {{1, 0, 1}, {1, 1, 0}, {0, 1, 1}}; | const float colorsycc[3][3] = {{1, 0, 1}, {1, 1, 0}, {0, 1, 1}}; | ||||
| /* colors pre multiplied by alpha for speed up */ | /* colors pre multiplied by alpha for speed up */ | ||||
| float colors_alpha[3][3], colorsycc_alpha[3][3]; | float colors_alpha[3][3], colorsycc_alpha[3][3]; | ||||
| float min, max; | float min, max; | ||||
| if (scopes == NULL) { | if (scopes == nullptr) { | ||||
| return; | return; | ||||
| } | } | ||||
| rctf rect = { | rctf rect{}; | ||||
| .xmin = (float)recti->xmin + 1, | rect.xmin = float(recti->xmin + 1); | ||||
| .xmax = (float)recti->xmax - 1, | rect.xmax = float(recti->xmax - 1); | ||||
| .ymin = (float)recti->ymin + 1, | rect.ymin = float(recti->ymin + 1); | ||||
| .ymax = (float)recti->ymax - 1, | rect.ymax = float(recti->ymax - 1); | ||||
| }; | |||||
| if (scopes->wavefrm_yfac < 0.5f) { | if (scopes->wavefrm_yfac < 0.5f) { | ||||
| scopes->wavefrm_yfac = 0.98f; | scopes->wavefrm_yfac = 0.98f; | ||||
| } | } | ||||
| const float w = BLI_rctf_size_x(&rect) - 7; | const float w = BLI_rctf_size_x(&rect) - 7; | ||||
| const float h = BLI_rctf_size_y(&rect) * scopes->wavefrm_yfac; | const float h = BLI_rctf_size_y(&rect) * scopes->wavefrm_yfac; | ||||
| const float yofs = rect.ymin + (BLI_rctf_size_y(&rect) - h) * 0.5f; | const float yofs = rect.ymin + (BLI_rctf_size_y(&rect) - h) * 0.5f; | ||||
| const float w3 = w / 3.0f; | const float w3 = w / 3.0f; | ||||
| Show All 13 Lines | void ui_draw_but_WAVEFORM(ARegion * /*region*/, | ||||
| /* Flush text cache before changing scissors. */ | /* Flush text cache before changing scissors. */ | ||||
| BLF_batch_draw_flush(); | BLF_batch_draw_flush(); | ||||
| GPU_blend(GPU_BLEND_ALPHA); | GPU_blend(GPU_BLEND_ALPHA); | ||||
| float color[4]; | float color[4]; | ||||
| UI_GetThemeColor4fv(TH_PREVIEW_BACK, color); | UI_GetThemeColor4fv(TH_PREVIEW_BACK, color); | ||||
| UI_draw_roundbox_corner_set(UI_CNR_ALL); | UI_draw_roundbox_corner_set(UI_CNR_ALL); | ||||
| UI_draw_roundbox_4fv( | rctf back_rect{}; | ||||
| &(const rctf){ | back_rect.xmin = rect.xmin - 1.0f; | ||||
| .xmin = rect.xmin - 1, | back_rect.xmax = rect.xmax + 1.0f; | ||||
| .xmax = rect.xmax + 1, | back_rect.ymin = rect.ymin - 1.0f; | ||||
| .ymin = rect.ymin - 1, | back_rect.ymax = rect.ymax + 1.0f; | ||||
| .ymax = rect.ymax + 1, | UI_draw_roundbox_4fv(&back_rect, true, 3.0f, color); | ||||
| }, | |||||
| true, | |||||
| 3.0f, | |||||
| color); | |||||
| /* need scissor test, waveform can draw outside of boundary */ | /* need scissor test, waveform can draw outside of boundary */ | ||||
| GPU_scissor_get(scissor); | GPU_scissor_get(scissor); | ||||
| GPU_scissor((rect.xmin - 1), | GPU_scissor((rect.xmin - 1), | ||||
| (rect.ymin - 1), | (rect.ymin - 1), | ||||
| (rect.xmax + 1) - (rect.xmin - 1), | (rect.xmax + 1) - (rect.xmin - 1), | ||||
| (rect.ymax + 1) - (rect.ymin - 1)); | (rect.ymax + 1) - (rect.ymin - 1)); | ||||
| ▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | void ui_draw_but_WAVEFORM(ARegion * /*region*/, | ||||
| /* 7.5 IRE black point level for NTSC */ | /* 7.5 IRE black point level for NTSC */ | ||||
| if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA) { | if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA) { | ||||
| immBegin(GPU_PRIM_LINES, 2); | immBegin(GPU_PRIM_LINES, 2); | ||||
| immVertex2f(pos, rect.xmin, yofs + h * 0.075f); | immVertex2f(pos, rect.xmin, yofs + h * 0.075f); | ||||
| immVertex2f(pos, rect.xmax + 1, yofs + h * 0.075f); | immVertex2f(pos, rect.xmax + 1, yofs + h * 0.075f); | ||||
| immEnd(); | immEnd(); | ||||
| } | } | ||||
| if (scopes->ok && scopes->waveform_1 != NULL) { | if (scopes->ok && scopes->waveform_1 != nullptr) { | ||||
| GPU_blend(GPU_BLEND_ADDITIVE); | GPU_blend(GPU_BLEND_ADDITIVE); | ||||
| GPU_point_size(1.0); | GPU_point_size(1.0); | ||||
| /* LUMA (1 channel) */ | /* LUMA (1 channel) */ | ||||
| if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA) { | if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA) { | ||||
| const float col[3] = {alpha, alpha, alpha}; | const float col[3] = {alpha, alpha, alpha}; | ||||
| GPU_matrix_push(); | GPU_matrix_push(); | ||||
| ▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | static void vectorscope_draw_target( | ||||
| float dangle, dampli, dangle2, dampli2; | float dangle, dampli, dangle2, dampli2; | ||||
| rgb_to_yuv(colf[0], colf[1], colf[2], &y, &u, &v, BLI_YUV_ITU_BT709); | rgb_to_yuv(colf[0], colf[1], colf[2], &y, &u, &v, BLI_YUV_ITU_BT709); | ||||
| if (u > 0 && v >= 0) { | if (u > 0 && v >= 0) { | ||||
| tangle = atanf(v / u); | tangle = atanf(v / u); | ||||
| } | } | ||||
| else if (u > 0 && v < 0) { | else if (u > 0 && v < 0) { | ||||
| tangle = atanf(v / u) + 2.0f * (float)M_PI; | tangle = atanf(v / u) + 2.0f * float(M_PI); | ||||
| } | } | ||||
| else if (u < 0) { | else if (u < 0) { | ||||
| tangle = atanf(v / u) + (float)M_PI; | tangle = atanf(v / u) + float(M_PI); | ||||
| } | } | ||||
| else if (u == 0 && v > 0.0f) { | else if (u == 0 && v > 0.0f) { | ||||
| tangle = M_PI_2; | tangle = M_PI_2; | ||||
| } | } | ||||
| else if (u == 0 && v < 0.0f) { | else if (u == 0 && v < 0.0f) { | ||||
| tangle = -M_PI_2; | tangle = -M_PI_2; | ||||
| } | } | ||||
| tampli = sqrtf(u * u + v * v); | tampli = sqrtf(u * u + v * v); | ||||
| ▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | immVertex2f(pos, | ||||
| polar_to_x(centerx, diam, tampli + dampli, tangle - dangle), | polar_to_x(centerx, diam, tampli + dampli, tangle - dangle), | ||||
| polar_to_y(centery, diam, tampli + dampli, tangle - dangle)); | polar_to_y(centery, diam, tampli + dampli, tangle - dangle)); | ||||
| immVertex2f(pos, | immVertex2f(pos, | ||||
| polar_to_x(centerx, diam, tampli + dampli, tangle - dangle + dangle2), | polar_to_x(centerx, diam, tampli + dampli, tangle - dangle + dangle2), | ||||
| polar_to_y(centery, diam, tampli + dampli, tangle - dangle + dangle2)); | polar_to_y(centery, diam, tampli + dampli, tangle - dangle + dangle2)); | ||||
| immEnd(); | immEnd(); | ||||
| } | } | ||||
| void ui_draw_but_VECTORSCOPE(ARegion *UNUSED(region), | void ui_draw_but_VECTORSCOPE(ARegion * /*region*/, | ||||
| uiBut *but, | uiBut *but, | ||||
| const uiWidgetColors *UNUSED(wcol), | const uiWidgetColors * /*wcol*/, | ||||
| const rcti *recti) | const rcti *recti) | ||||
| { | { | ||||
| const float skin_rad = DEG2RADF(123.0f); /* angle in radians of the skin tone line */ | const float skin_rad = DEG2RADF(123.0f); /* angle in radians of the skin tone line */ | ||||
| Scopes *scopes = (Scopes *)but->poin; | Scopes *scopes = (Scopes *)but->poin; | ||||
| const float colors[6][3] = { | const float colors[6][3] = { | ||||
| {0.75, 0.0, 0.0}, | {0.75, 0.0, 0.0}, | ||||
| {0.75, 0.75, 0.0}, | {0.75, 0.75, 0.0}, | ||||
| {0.0, 0.75, 0.0}, | {0.0, 0.75, 0.0}, | ||||
| {0.0, 0.75, 0.75}, | {0.0, 0.75, 0.75}, | ||||
| {0.0, 0.0, 0.75}, | {0.0, 0.0, 0.75}, | ||||
| {0.75, 0.0, 0.75}, | {0.75, 0.0, 0.75}, | ||||
| }; | }; | ||||
| rctf rect = { | rctf rect{}; | ||||
| .xmin = (float)recti->xmin + 1, | rect.xmin = float(recti->xmin + 1); | ||||
| .xmax = (float)recti->xmax - 1, | rect.xmax = float(recti->xmax - 1); | ||||
| .ymin = (float)recti->ymin + 1, | rect.ymin = float(recti->ymin + 1); | ||||
| .ymax = (float)recti->ymax - 1, | rect.ymax = float(recti->ymax - 1); | ||||
| }; | |||||
| const float w = BLI_rctf_size_x(&rect); | const float w = BLI_rctf_size_x(&rect); | ||||
| const float h = BLI_rctf_size_y(&rect); | const float h = BLI_rctf_size_y(&rect); | ||||
| const float centerx = rect.xmin + w * 0.5f; | const float centerx = rect.xmin + w * 0.5f; | ||||
| const float centery = rect.ymin + h * 0.5f; | const float centery = rect.ymin + h * 0.5f; | ||||
| const float diam = (w < h) ? w : h; | const float diam = (w < h) ? w : h; | ||||
| const float alpha = scopes->vecscope_alpha * scopes->vecscope_alpha * scopes->vecscope_alpha; | const float alpha = scopes->vecscope_alpha * scopes->vecscope_alpha * scopes->vecscope_alpha; | ||||
| GPU_blend(GPU_BLEND_ALPHA); | GPU_blend(GPU_BLEND_ALPHA); | ||||
| float color[4]; | float color[4]; | ||||
| UI_GetThemeColor4fv(TH_PREVIEW_BACK, color); | UI_GetThemeColor4fv(TH_PREVIEW_BACK, color); | ||||
| UI_draw_roundbox_corner_set(UI_CNR_ALL); | UI_draw_roundbox_corner_set(UI_CNR_ALL); | ||||
| UI_draw_roundbox_4fv( | rctf back_rect{}; | ||||
| &(const rctf){ | back_rect.xmin = rect.xmin - 1; | ||||
| .xmin = rect.xmin - 1, | back_rect.xmax = rect.xmax + 1; | ||||
| .xmax = rect.xmax + 1, | back_rect.ymin = rect.ymin - 1; | ||||
| .ymin = rect.ymin - 1, | back_rect.ymax = rect.ymax + 1; | ||||
| .ymax = rect.ymax + 1, | UI_draw_roundbox_4fv(&back_rect, true, 3.0f, color); | ||||
| }, | |||||
| true, | |||||
| 3.0f, | |||||
| color); | |||||
| /* need scissor test, hvectorscope can draw outside of boundary */ | /* need scissor test, hvectorscope can draw outside of boundary */ | ||||
| int scissor[4]; | int scissor[4]; | ||||
| GPU_scissor_get(scissor); | GPU_scissor_get(scissor); | ||||
| GPU_scissor((rect.xmin - 1), | GPU_scissor((rect.xmin - 1), | ||||
| (rect.ymin - 1), | (rect.ymin - 1), | ||||
| (rect.xmax + 1) - (rect.xmin - 1), | (rect.xmax + 1) - (rect.xmin - 1), | ||||
| (rect.ymax + 1) - (rect.ymin - 1)); | (rect.ymax + 1) - (rect.ymin - 1)); | ||||
| Show All 14 Lines | void ui_draw_but_VECTORSCOPE(ARegion * /*region*/, | ||||
| immVertex2f(pos, centerx, centery - (diam * 0.5f) - 5); | immVertex2f(pos, centerx, centery - (diam * 0.5f) - 5); | ||||
| immVertex2f(pos, centerx, centery + (diam * 0.5f) + 5); | immVertex2f(pos, centerx, centery + (diam * 0.5f) + 5); | ||||
| immEnd(); | immEnd(); | ||||
| /* circles */ | /* circles */ | ||||
| for (int j = 0; j < 5; j++) { | for (int j = 0; j < 5; j++) { | ||||
| const int increment = 15; | const int increment = 15; | ||||
| immBegin(GPU_PRIM_LINE_LOOP, (int)(360 / increment)); | immBegin(GPU_PRIM_LINE_LOOP, int(360 / increment)); | ||||
| for (int i = 0; i <= 360 - increment; i += increment) { | for (int i = 0; i <= 360 - increment; i += increment) { | ||||
| const float a = DEG2RADF((float)i); | const float a = DEG2RADF(float(i)); | ||||
| const float r = (j + 1) * 0.1f; | const float r = (j + 1) * 0.1f; | ||||
| immVertex2f(pos, polar_to_x(centerx, diam, r, a), polar_to_y(centery, diam, r, a)); | immVertex2f(pos, polar_to_x(centerx, diam, r, a), polar_to_y(centery, diam, r, a)); | ||||
| } | } | ||||
| immEnd(); | immEnd(); | ||||
| } | } | ||||
| /* skin tone line */ | /* skin tone line */ | ||||
| immUniformColor4f(1.0f, 0.4f, 0.0f, 0.2f); | immUniformColor4f(1.0f, 0.4f, 0.0f, 0.2f); | ||||
| immBegin(GPU_PRIM_LINES, 2); | immBegin(GPU_PRIM_LINES, 2); | ||||
| immVertex2f( | immVertex2f( | ||||
| pos, polar_to_x(centerx, diam, 0.5f, skin_rad), polar_to_y(centery, diam, 0.5f, skin_rad)); | pos, polar_to_x(centerx, diam, 0.5f, skin_rad), polar_to_y(centery, diam, 0.5f, skin_rad)); | ||||
| immVertex2f( | immVertex2f( | ||||
| pos, polar_to_x(centerx, diam, 0.1f, skin_rad), polar_to_y(centery, diam, 0.1f, skin_rad)); | pos, polar_to_x(centerx, diam, 0.1f, skin_rad), polar_to_y(centery, diam, 0.1f, skin_rad)); | ||||
| immEnd(); | immEnd(); | ||||
| /* saturation points */ | /* saturation points */ | ||||
| for (int i = 0; i < 6; i++) { | for (int i = 0; i < 6; i++) { | ||||
| vectorscope_draw_target(pos, centerx, centery, diam, colors[i]); | vectorscope_draw_target(pos, centerx, centery, diam, colors[i]); | ||||
| } | } | ||||
| if (scopes->ok && scopes->vecscope != NULL) { | if (scopes->ok && scopes->vecscope != nullptr) { | ||||
| /* pixel point cloud */ | /* pixel point cloud */ | ||||
| const float col[3] = {alpha, alpha, alpha}; | const float col[3] = {alpha, alpha, alpha}; | ||||
| GPU_blend(GPU_BLEND_ADDITIVE); | GPU_blend(GPU_BLEND_ADDITIVE); | ||||
| GPU_point_size(1.0); | GPU_point_size(1.0); | ||||
| GPU_matrix_push(); | GPU_matrix_push(); | ||||
| GPU_matrix_translate_2f(centerx, centery); | GPU_matrix_translate_2f(centerx, centery); | ||||
| ▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | else { | ||||
| immEnd(); | immEnd(); | ||||
| } | } | ||||
| } | } | ||||
| static void ui_draw_colorband_handle(uint shdr_pos, | static void ui_draw_colorband_handle(uint shdr_pos, | ||||
| const rcti *rect, | const rcti *rect, | ||||
| float x, | float x, | ||||
| const float rgb[3], | const float rgb[3], | ||||
| struct ColorManagedDisplay *display, | ColorManagedDisplay *display, | ||||
| bool active) | bool active) | ||||
| { | { | ||||
| const float sizey = BLI_rcti_size_y(rect); | const float sizey = BLI_rcti_size_y(rect); | ||||
| const float min_width = 3.0f; | const float min_width = 3.0f; | ||||
| float colf[3] = {UNPACK3(rgb)}; | float colf[3] = {UNPACK3(rgb)}; | ||||
| const float half_width = floorf(sizey / 3.5f); | const float half_width = floorf(sizey / 3.5f); | ||||
| const float height = half_width * 1.4f; | const float height = half_width * 1.4f; | ||||
| ▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | if (display) { | ||||
| IMB_colormanagement_scene_linear_to_display_v3(colf, display); | IMB_colormanagement_scene_linear_to_display_v3(colf, display); | ||||
| } | } | ||||
| immUniformColor3fv(colf); | immUniformColor3fv(colf); | ||||
| ui_draw_colorband_handle_box( | ui_draw_colorband_handle_box( | ||||
| shdr_pos, x - (half_width - 2), y1 + 1, x + (half_width - 2), y1 + height - 2, true); | shdr_pos, x - (half_width - 2), y1 + 1, x + (half_width - 2), y1 + height - 2, true); | ||||
| } | } | ||||
| void ui_draw_but_COLORBAND(uiBut *but, const uiWidgetColors *UNUSED(wcol), const rcti *rect) | void ui_draw_but_COLORBAND(uiBut *but, const uiWidgetColors * /*wcol*/, const rcti *rect) | ||||
| { | { | ||||
| struct ColorManagedDisplay *display = ui_block_cm_display_get(but->block); | ColorManagedDisplay *display = ui_block_cm_display_get(but->block); | ||||
| uint pos_id, col_id; | uint pos_id, col_id; | ||||
| uiButColorBand *but_coba = (uiButColorBand *)but; | uiButColorBand *but_coba = (uiButColorBand *)but; | ||||
| ColorBand *coba = (but_coba->edit_coba == NULL) ? (ColorBand *)but->poin : but_coba->edit_coba; | ColorBand *coba = (but_coba->edit_coba == nullptr) ? (ColorBand *)but->poin : | ||||
| but_coba->edit_coba; | |||||
| if (coba == NULL) { | if (coba == nullptr) { | ||||
| return; | return; | ||||
| } | } | ||||
| const float x1 = rect->xmin; | const float x1 = rect->xmin; | ||||
| const float sizex = rect->xmax - x1; | const float sizex = rect->xmax - x1; | ||||
| const float sizey = BLI_rcti_size_y(rect); | const float sizey = BLI_rcti_size_y(rect); | ||||
| const float sizey_solid = sizey * 0.25f; | const float sizey_solid = sizey * 0.25f; | ||||
| const float y1 = rect->ymin; | const float y1 = rect->ymin; | ||||
| Show All 30 Lines | void ui_draw_but_COLORBAND(uiBut *but, const uiWidgetColors * /*wcol*/, const rcti *rect) | ||||
| float v1[2], v2[2]; | float v1[2], v2[2]; | ||||
| float colf[4] = {0, 0, 0, 0}; /* initialize in case the colorband isn't valid */ | float colf[4] = {0, 0, 0, 0}; /* initialize in case the colorband isn't valid */ | ||||
| v1[1] = y1 + sizey_solid; | v1[1] = y1 + sizey_solid; | ||||
| v2[1] = rect->ymax; | v2[1] = rect->ymax; | ||||
| immBegin(GPU_PRIM_TRI_STRIP, (sizex + 1) * 2); | immBegin(GPU_PRIM_TRI_STRIP, (sizex + 1) * 2); | ||||
| for (int a = 0; a <= sizex; a++) { | for (int a = 0; a <= sizex; a++) { | ||||
| const float pos = ((float)a) / sizex; | const float pos = (float(a)) / sizex; | ||||
| BKE_colorband_evaluate(coba, pos, colf); | BKE_colorband_evaluate(coba, pos, colf); | ||||
| if (display) { | if (display) { | ||||
| IMB_colormanagement_scene_linear_to_display_v3(colf, display); | IMB_colormanagement_scene_linear_to_display_v3(colf, display); | ||||
| } | } | ||||
| v1[0] = v2[0] = x1 + a; | v1[0] = v2[0] = x1 + a; | ||||
| immAttr4fv(col_id, colf); | immAttr4fv(col_id, colf); | ||||
| immVertex2fv(pos_id, v1); | immVertex2fv(pos_id, v1); | ||||
| immVertex2fv(pos_id, v2); | immVertex2fv(pos_id, v2); | ||||
| } | } | ||||
| immEnd(); | immEnd(); | ||||
| /* layer: color ramp without alpha for reference when manipulating ramp properties */ | /* layer: color ramp without alpha for reference when manipulating ramp properties */ | ||||
| v1[1] = y1; | v1[1] = y1; | ||||
| v2[1] = y1 + sizey_solid; | v2[1] = y1 + sizey_solid; | ||||
| immBegin(GPU_PRIM_TRI_STRIP, (sizex + 1) * 2); | immBegin(GPU_PRIM_TRI_STRIP, (sizex + 1) * 2); | ||||
| for (int a = 0; a <= sizex; a++) { | for (int a = 0; a <= sizex; a++) { | ||||
| const float pos = ((float)a) / sizex; | const float pos = (float(a)) / sizex; | ||||
| BKE_colorband_evaluate(coba, pos, colf); | BKE_colorband_evaluate(coba, pos, colf); | ||||
| if (display) { | if (display) { | ||||
| IMB_colormanagement_scene_linear_to_display_v3(colf, display); | IMB_colormanagement_scene_linear_to_display_v3(colf, display); | ||||
| } | } | ||||
| v1[0] = v2[0] = x1 + a; | v1[0] = v2[0] = x1 + a; | ||||
| immAttr4f(col_id, colf[0], colf[1], colf[2], 1.0f); | immAttr4f(col_id, colf[0], colf[1], colf[2], 1.0f); | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| /* sphere color */ | /* sphere color */ | ||||
| const float diffuse[3] = {1.0f, 1.0f, 1.0f}; | const float diffuse[3] = {1.0f, 1.0f, 1.0f}; | ||||
| float light[3]; | float light[3]; | ||||
| const float size = 0.5f * min_ff(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)); | const float size = 0.5f * min_ff(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)); | ||||
| /* backdrop */ | /* backdrop */ | ||||
| UI_draw_roundbox_corner_set(UI_CNR_ALL); | UI_draw_roundbox_corner_set(UI_CNR_ALL); | ||||
| UI_draw_roundbox_3ub_alpha( | rctf box_rect{}; | ||||
| &(const rctf){ | box_rect.xmin = rect->xmin; | ||||
| .xmin = rect->xmin, | box_rect.xmax = rect->xmax; | ||||
| .xmax = rect->xmax, | box_rect.ymin = rect->ymin; | ||||
| .ymin = rect->ymin, | box_rect.ymax = rect->ymax; | ||||
| .ymax = rect->ymax, | UI_draw_roundbox_3ub_alpha(&box_rect, true, radius, wcol->inner, 255); | ||||
| }, | |||||
| true, | |||||
| radius, | |||||
| wcol->inner, | |||||
| 255); | |||||
| GPU_face_culling(GPU_CULL_BACK); | GPU_face_culling(GPU_CULL_BACK); | ||||
| /* setup lights */ | /* setup lights */ | ||||
| ui_but_v3_get(but, light); | ui_but_v3_get(but, light); | ||||
| /* transform to button */ | /* transform to button */ | ||||
| GPU_matrix_push(); | GPU_matrix_push(); | ||||
| const bool use_project_matrix = (size >= -GPU_MATRIX_ORTHO_CLIP_NEAR_DEFAULT); | const bool use_project_matrix = (size >= -GPU_MATRIX_ORTHO_CLIP_NEAR_DEFAULT); | ||||
| if (use_project_matrix) { | if (use_project_matrix) { | ||||
| GPU_matrix_push_projection(); | GPU_matrix_push_projection(); | ||||
| GPU_matrix_ortho_set_z(-size, size); | GPU_matrix_ortho_set_z(-size, size); | ||||
| } | } | ||||
| GPU_matrix_translate_2f(rect->xmin + 0.5f * BLI_rcti_size_x(rect), | GPU_matrix_translate_2f(rect->xmin + 0.5f * BLI_rcti_size_x(rect), | ||||
| rect->ymin + 0.5f * BLI_rcti_size_y(rect)); | rect->ymin + 0.5f * BLI_rcti_size_y(rect)); | ||||
| GPU_matrix_scale_1f(size); | GPU_matrix_scale_1f(size); | ||||
| GPUBatch *sphere = GPU_batch_preset_sphere(2); | GPUBatch *sphere = GPU_batch_preset_sphere(2); | ||||
| struct SimpleLightingData simple_lighting_data; | SimpleLightingData simple_lighting_data; | ||||
| copy_v4_fl4(simple_lighting_data.color, diffuse[0], diffuse[1], diffuse[2], 1.0f); | copy_v4_fl4(simple_lighting_data.color, diffuse[0], diffuse[1], diffuse[2], 1.0f); | ||||
| copy_v3_v3(simple_lighting_data.light, light); | copy_v3_v3(simple_lighting_data.light, light); | ||||
| GPUUniformBuf *ubo = GPU_uniformbuf_create_ex( | GPUUniformBuf *ubo = GPU_uniformbuf_create_ex( | ||||
| sizeof(struct SimpleLightingData), &simple_lighting_data, __func__); | sizeof(SimpleLightingData), &simple_lighting_data, __func__); | ||||
| GPU_batch_program_set_builtin(sphere, GPU_SHADER_SIMPLE_LIGHTING); | GPU_batch_program_set_builtin(sphere, GPU_SHADER_SIMPLE_LIGHTING); | ||||
| GPU_batch_uniformbuf_bind(sphere, "simple_lighting_data", ubo); | GPU_batch_uniformbuf_bind(sphere, "simple_lighting_data", ubo); | ||||
| GPU_batch_draw(sphere); | GPU_batch_draw(sphere); | ||||
| GPU_uniformbuf_free(ubo); | GPU_uniformbuf_free(ubo); | ||||
| /* Restore. */ | /* Restore. */ | ||||
| GPU_face_culling(GPU_CULL_NONE); | GPU_face_culling(GPU_CULL_NONE); | ||||
| ▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | static void gl_shaded_color(const uchar *color, int shade) | ||||
| uchar color_shaded[3]; | uchar color_shaded[3]; | ||||
| gl_shaded_color_get(color, shade, color_shaded); | gl_shaded_color_get(color, shade, color_shaded); | ||||
| immUniformColor3ubv(color_shaded); | immUniformColor3ubv(color_shaded); | ||||
| } | } | ||||
| void ui_draw_but_CURVE(ARegion *region, uiBut *but, const uiWidgetColors *wcol, const rcti *rect) | void ui_draw_but_CURVE(ARegion *region, uiBut *but, const uiWidgetColors *wcol, const rcti *rect) | ||||
| { | { | ||||
| uiButCurveMapping *but_cumap = (uiButCurveMapping *)but; | uiButCurveMapping *but_cumap = (uiButCurveMapping *)but; | ||||
| CurveMapping *cumap = (but_cumap->edit_cumap == NULL) ? (CurveMapping *)but->poin : | CurveMapping *cumap = (but_cumap->edit_cumap == nullptr) ? (CurveMapping *)but->poin : | ||||
| but_cumap->edit_cumap; | but_cumap->edit_cumap; | ||||
| const float clip_size_x = BLI_rctf_size_x(&cumap->curr); | const float clip_size_x = BLI_rctf_size_x(&cumap->curr); | ||||
| const float clip_size_y = BLI_rctf_size_y(&cumap->curr); | const float clip_size_y = BLI_rctf_size_y(&cumap->curr); | ||||
| /* zero-sized curve */ | /* zero-sized curve */ | ||||
| if (clip_size_x == 0.0f || clip_size_y == 0.0f) { | if (clip_size_x == 0.0f || clip_size_y == 0.0f) { | ||||
| return; | return; | ||||
| } | } | ||||
| Show All 9 Lines | if (zoomx == 0.0f) { | ||||
| return; | return; | ||||
| } | } | ||||
| CurveMap *cuma = &cumap->cm[cumap->cur]; | CurveMap *cuma = &cumap->cm[cumap->cur]; | ||||
| /* need scissor test, curve can draw outside of boundary */ | /* need scissor test, curve can draw outside of boundary */ | ||||
| int scissor[4]; | int scissor[4]; | ||||
| GPU_scissor_get(scissor); | GPU_scissor_get(scissor); | ||||
| rcti scissor_new = { | rcti scissor_new{}; | ||||
| .xmin = rect->xmin, | scissor_new.xmin = rect->xmin; | ||||
| .ymin = rect->ymin, | scissor_new.ymin = rect->ymin; | ||||
| .xmax = rect->xmax, | scissor_new.xmax = rect->xmax; | ||||
| .ymax = rect->ymax, | scissor_new.ymax = rect->ymax; | ||||
| }; | |||||
| const rcti scissor_region = {0, region->winx, 0, region->winy}; | const rcti scissor_region = {0, region->winx, 0, region->winy}; | ||||
| BLI_rcti_isect(&scissor_new, &scissor_region, &scissor_new); | BLI_rcti_isect(&scissor_new, &scissor_region, &scissor_new); | ||||
| GPU_scissor(scissor_new.xmin, | GPU_scissor(scissor_new.xmin, | ||||
| scissor_new.ymin, | scissor_new.ymin, | ||||
| BLI_rcti_size_x(&scissor_new), | BLI_rcti_size_x(&scissor_new), | ||||
| BLI_rcti_size_y(&scissor_new)); | BLI_rcti_size_y(&scissor_new)); | ||||
| /* Do this first to not mess imm context */ | /* Do this first to not mess imm context */ | ||||
| if (but_cumap->gradient_type == UI_GRAD_H) { | if (but_cumap->gradient_type == UI_GRAD_H) { | ||||
| /* magic trigger for curve backgrounds */ | /* magic trigger for curve backgrounds */ | ||||
| const float col[3] = {0.0f, 0.0f, 0.0f}; /* dummy arg */ | const float col[3] = {0.0f, 0.0f, 0.0f}; /* dummy arg */ | ||||
| rcti grid = { | rcti grid{}; | ||||
| .xmin = rect->xmin + zoomx * (-offsx), | grid.xmin = rect->xmin + zoomx * (-offsx); | ||||
| .xmax = grid.xmin + zoomx, | grid.xmax = grid.xmin + zoomx; | ||||
| .ymin = rect->ymin + zoomy * (-offsy), | grid.ymin = rect->ymin + zoomy * (-offsy); | ||||
| .ymax = grid.ymin + zoomy, | grid.ymax = grid.ymin + zoomy; | ||||
| }; | |||||
| ui_draw_gradient(&grid, col, UI_GRAD_H, 1.0f); | ui_draw_gradient(&grid, col, UI_GRAD_H, 1.0f); | ||||
| } | } | ||||
| GPU_line_width(1.0f); | GPU_line_width(1.0f); | ||||
| GPUVertFormat *format = immVertexFormat(); | GPUVertFormat *format = immVertexFormat(); | ||||
| uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | ||||
| immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); | immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); | ||||
| ▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | else { | ||||
| immVertex2f(pos, rect->xmin + zoomx * (cumap->sample[cumap->cur] - offsx), rect->ymin); | immVertex2f(pos, rect->xmin + zoomx * (cumap->sample[cumap->cur] - offsx), rect->ymin); | ||||
| immVertex2f(pos, rect->xmin + zoomx * (cumap->sample[cumap->cur] - offsx), rect->ymax); | immVertex2f(pos, rect->xmin + zoomx * (cumap->sample[cumap->cur] - offsx), rect->ymax); | ||||
| } | } | ||||
| immEnd(); | immEnd(); | ||||
| } | } | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| if (cuma->table == NULL) { | if (cuma->table == nullptr) { | ||||
| BKE_curvemapping_changed(cumap, false); | BKE_curvemapping_changed(cumap, false); | ||||
| } | } | ||||
| CurveMapPoint *cmp = cuma->table; | CurveMapPoint *cmp = cuma->table; | ||||
| rctf line_range; | rctf line_range; | ||||
| /* First curve point. */ | /* First curve point. */ | ||||
| if ((cumap->flag & CUMA_EXTEND_EXTRAPOLATE) == 0) { | if ((cumap->flag & CUMA_EXTEND_EXTRAPOLATE) == 0) { | ||||
| ▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | |||||
| void ui_draw_but_CURVEPROFILE(ARegion *region, | void ui_draw_but_CURVEPROFILE(ARegion *region, | ||||
| uiBut *but, | uiBut *but, | ||||
| const uiWidgetColors *wcol, | const uiWidgetColors *wcol, | ||||
| const rcti *rect) | const rcti *rect) | ||||
| { | { | ||||
| float fx, fy; | float fx, fy; | ||||
| uiButCurveProfile *but_profile = (uiButCurveProfile *)but; | uiButCurveProfile *but_profile = (uiButCurveProfile *)but; | ||||
| CurveProfile *profile = (but_profile->edit_profile == NULL) ? (CurveProfile *)but->poin : | CurveProfile *profile = (but_profile->edit_profile == nullptr) ? (CurveProfile *)but->poin : | ||||
| but_profile->edit_profile; | but_profile->edit_profile; | ||||
| /* Calculate offset and zoom. */ | /* Calculate offset and zoom. */ | ||||
| const float zoomx = (BLI_rcti_size_x(rect) - 2.0f) / BLI_rctf_size_x(&profile->view_rect); | const float zoomx = (BLI_rcti_size_x(rect) - 2.0f) / BLI_rctf_size_x(&profile->view_rect); | ||||
| const float zoomy = (BLI_rcti_size_y(rect) - 2.0f) / BLI_rctf_size_y(&profile->view_rect); | const float zoomy = (BLI_rcti_size_y(rect) - 2.0f) / BLI_rctf_size_y(&profile->view_rect); | ||||
| const float offsx = profile->view_rect.xmin - (1.0f / zoomx); | const float offsx = profile->view_rect.xmin - (1.0f / zoomx); | ||||
| const float offsy = profile->view_rect.ymin - (1.0f / zoomy); | const float offsy = profile->view_rect.ymin - (1.0f / zoomy); | ||||
| /* Exit early if too narrow. */ | /* Exit early if too narrow. */ | ||||
| if (zoomx == 0.0f) { | if (zoomx == 0.0f) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* Test needed because path can draw outside of boundary. */ | /* Test needed because path can draw outside of boundary. */ | ||||
| int scissor[4]; | int scissor[4]; | ||||
| GPU_scissor_get(scissor); | GPU_scissor_get(scissor); | ||||
| rcti scissor_new = { | rcti scissor_new{}; | ||||
| .xmin = rect->xmin, | scissor_new.xmin = rect->xmin; | ||||
| .ymin = rect->ymin, | scissor_new.ymin = rect->ymin; | ||||
| .xmax = rect->xmax, | scissor_new.xmax = rect->xmax; | ||||
| .ymax = rect->ymax, | scissor_new.ymax = rect->ymax; | ||||
| }; | |||||
| const rcti scissor_region = {0, region->winx, 0, region->winy}; | const rcti scissor_region = {0, region->winx, 0, region->winy}; | ||||
| BLI_rcti_isect(&scissor_new, &scissor_region, &scissor_new); | BLI_rcti_isect(&scissor_new, &scissor_region, &scissor_new); | ||||
| GPU_scissor(scissor_new.xmin, | GPU_scissor(scissor_new.xmin, | ||||
| scissor_new.ymin, | scissor_new.ymin, | ||||
| BLI_rcti_size_x(&scissor_new), | BLI_rcti_size_x(&scissor_new), | ||||
| BLI_rcti_size_y(&scissor_new)); | BLI_rcti_size_y(&scissor_new)); | ||||
| GPU_line_width(1.0f); | GPU_line_width(1.0f); | ||||
| Show All 24 Lines | void ui_draw_but_CURVEPROFILE(ARegion *region, | ||||
| /* 0.25 step grid. */ | /* 0.25 step grid. */ | ||||
| gl_shaded_color((uchar *)wcol->inner, -16); | gl_shaded_color((uchar *)wcol->inner, -16); | ||||
| ui_draw_but_curve_grid(pos, rect, zoomx, zoomy, offsx, offsy, 0.25f); | ui_draw_but_curve_grid(pos, rect, zoomx, zoomy, offsx, offsy, 0.25f); | ||||
| /* 1.0 step grid. */ | /* 1.0 step grid. */ | ||||
| gl_shaded_color((uchar *)wcol->inner, -24); | gl_shaded_color((uchar *)wcol->inner, -24); | ||||
| ui_draw_but_curve_grid(pos, rect, zoomx, zoomy, offsx, offsy, 1.0f); | ui_draw_but_curve_grid(pos, rect, zoomx, zoomy, offsx, offsy, 1.0f); | ||||
| /* Draw the path's fill. */ | /* Draw the path's fill. */ | ||||
| if (profile->table == NULL) { | if (profile->table == nullptr) { | ||||
| BKE_curveprofile_update(profile, PROF_UPDATE_NONE); | BKE_curveprofile_update(profile, PROF_UPDATE_NONE); | ||||
| } | } | ||||
| CurveProfilePoint *pts = profile->table; | CurveProfilePoint *pts = profile->table; | ||||
| /* Also add the last points on the right and bottom edges to close off the fill polygon. */ | /* Also add the last points on the right and bottom edges to close off the fill polygon. */ | ||||
| const bool add_left_tri = profile->view_rect.xmin < 0.0f; | const bool add_left_tri = profile->view_rect.xmin < 0.0f; | ||||
| const bool add_bottom_tri = profile->view_rect.ymin < 0.0f; | const bool add_bottom_tri = profile->view_rect.ymin < 0.0f; | ||||
| int tot_points = BKE_curveprofile_table_size(profile) + 1 + add_left_tri + add_bottom_tri; | int tot_points = BKE_curveprofile_table_size(profile) + 1 + add_left_tri + add_bottom_tri; | ||||
| const uint tot_triangles = tot_points - 2; | const uint tot_triangles = tot_points - 2; | ||||
| /* Create array of the positions of the table's points. */ | /* Create array of the positions of the table's points. */ | ||||
| float(*table_coords)[2] = MEM_mallocN(sizeof(*table_coords) * tot_points, "table x coords"); | float(*table_coords)[2] = static_cast<float(*)[2]>( | ||||
| MEM_mallocN(sizeof(*table_coords) * tot_points, __func__)); | |||||
| for (uint i = 0; i < (uint)BKE_curveprofile_table_size(profile); i++) { | for (uint i = 0; i < (uint)BKE_curveprofile_table_size(profile); i++) { | ||||
| /* Only add the points from the table here. */ | /* Only add the points from the table here. */ | ||||
| table_coords[i][0] = pts[i].x; | table_coords[i][0] = pts[i].x; | ||||
| table_coords[i][1] = pts[i].y; | table_coords[i][1] = pts[i].y; | ||||
| } | } | ||||
| /* Using some extra margin (-1.0f) for the coordinates used to complete the polygon | /* Using some extra margin (-1.0f) for the coordinates used to complete the polygon | ||||
| * avoids the profile line crossing itself in some common situations, which can lead to | * avoids the profile line crossing itself in some common situations, which can lead to | ||||
| * incorrect triangulation. See T841183. */ | * incorrect triangulation. See T841183. */ | ||||
| Show All 23 Lines | void ui_draw_but_CURVEPROFILE(ARegion *region, | ||||
| else { | else { | ||||
| /* Just add the bottom corner point. Side points would be redundant anyway. */ | /* Just add the bottom corner point. Side points would be redundant anyway. */ | ||||
| table_coords[tot_points - 1][0] = -1.0f; | table_coords[tot_points - 1][0] = -1.0f; | ||||
| table_coords[tot_points - 1][1] = -1.0f; | table_coords[tot_points - 1][1] = -1.0f; | ||||
| } | } | ||||
| /* Calculate the table point indices of the triangles for the profile's fill. */ | /* Calculate the table point indices of the triangles for the profile's fill. */ | ||||
| if (tot_triangles > 0) { | if (tot_triangles > 0) { | ||||
| uint(*tri_indices)[3] = MEM_mallocN(sizeof(*tri_indices) * tot_triangles, __func__); | uint(*tri_indices)[3] = static_cast<uint(*)[3]>( | ||||
| MEM_mallocN(sizeof(*tri_indices) * tot_triangles, __func__)); | |||||
| BLI_polyfill_calc(table_coords, tot_points, -1, tri_indices); | BLI_polyfill_calc(table_coords, tot_points, -1, tri_indices); | ||||
| /* Draw the triangles for the profile fill. */ | /* Draw the triangles for the profile fill. */ | ||||
| immUniformColor3ubvAlpha((const uchar *)wcol->item, 128); | immUniformColor3ubvAlpha((const uchar *)wcol->item, 128); | ||||
| GPU_blend(GPU_BLEND_ALPHA); | GPU_blend(GPU_BLEND_ALPHA); | ||||
| GPU_polygon_smooth(false); | GPU_polygon_smooth(false); | ||||
| immBegin(GPU_PRIM_TRIS, 3 * tot_triangles); | immBegin(GPU_PRIM_TRIS, 3 * tot_triangles); | ||||
| for (uint i = 0; i < tot_triangles; i++) { | for (uint i = 0; i < tot_triangles; i++) { | ||||
| ▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | void ui_draw_but_CURVEPROFILE(ARegion *region, | ||||
| pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | ||||
| const uint col = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | const uint col = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | ||||
| immBindBuiltinProgram(GPU_SHADER_3D_FLAT_COLOR); | immBindBuiltinProgram(GPU_SHADER_3D_FLAT_COLOR); | ||||
| /* Calculate vertex colors based on text theme. */ | /* Calculate vertex colors based on text theme. */ | ||||
| float color_vert[4], color_vert_select[4], color_sample[4]; | float color_vert[4], color_vert_select[4], color_sample[4]; | ||||
| UI_GetThemeColor4fv(TH_TEXT_HI, color_vert); | UI_GetThemeColor4fv(TH_TEXT_HI, color_vert); | ||||
| UI_GetThemeColor4fv(TH_TEXT, color_vert_select); | UI_GetThemeColor4fv(TH_TEXT, color_vert_select); | ||||
| color_sample[0] = (float)wcol->item[0] / 255.0f; | color_sample[0] = float(wcol->item[0]) / 255.0f; | ||||
| color_sample[1] = (float)wcol->item[1] / 255.0f; | color_sample[1] = float(wcol->item[1]) / 255.0f; | ||||
| color_sample[2] = (float)wcol->item[2] / 255.0f; | color_sample[2] = float(wcol->item[2]) / 255.0f; | ||||
| color_sample[3] = (float)wcol->item[3] / 255.0f; | color_sample[3] = float(wcol->item[3]) / 255.0f; | ||||
| if (len_squared_v3v3(color_vert, color_vert_select) < 0.1f) { | if (len_squared_v3v3(color_vert, color_vert_select) < 0.1f) { | ||||
| interp_v3_v3v3(color_vert, color_vert_select, color_backdrop, 0.75f); | interp_v3_v3v3(color_vert, color_vert_select, color_backdrop, 0.75f); | ||||
| } | } | ||||
| if (len_squared_v3(color_vert) > len_squared_v3(color_vert_select)) { | if (len_squared_v3(color_vert) > len_squared_v3(color_vert_select)) { | ||||
| /* Ensure brightest text color is used for selection. */ | /* Ensure brightest text color is used for selection. */ | ||||
| swap_v3_v3(color_vert, color_vert_select); | swap_v3_v3(color_vert, color_vert_select); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | void ui_draw_but_CURVEPROFILE(ARegion *region, | ||||
| pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | ||||
| immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); | immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); | ||||
| immUniformColor3ubv((const uchar *)wcol->outline); | immUniformColor3ubv((const uchar *)wcol->outline); | ||||
| imm_draw_box_wire_2d(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax); | imm_draw_box_wire_2d(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax); | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| } | } | ||||
| void ui_draw_but_TRACKPREVIEW(ARegion *UNUSED(region), | void ui_draw_but_TRACKPREVIEW(ARegion * /*region*/, | ||||
| uiBut *but, | uiBut *but, | ||||
| const uiWidgetColors *UNUSED(wcol), | const uiWidgetColors * /*wcol*/, | ||||
| const rcti *recti) | const rcti *recti) | ||||
| { | { | ||||
| bool ok = false; | bool ok = false; | ||||
| MovieClipScopes *scopes = (MovieClipScopes *)but->poin; | MovieClipScopes *scopes = (MovieClipScopes *)but->poin; | ||||
| rctf rect = { | rctf rect{}; | ||||
| .xmin = (float)recti->xmin + 1, | rect.xmin = float(recti->xmin + 1); | ||||
| .xmax = (float)recti->xmax - 1, | rect.xmax = float(recti->xmax - 1); | ||||
| .ymin = (float)recti->ymin + 1, | rect.ymin = float(recti->ymin + 1); | ||||
| .ymax = (float)recti->ymax - 1, | rect.ymax = float(recti->ymax - 1); | ||||
| }; | |||||
| const int width = BLI_rctf_size_x(&rect) + 1; | const int width = BLI_rctf_size_x(&rect) + 1; | ||||
| const int height = BLI_rctf_size_y(&rect); | const int height = BLI_rctf_size_y(&rect); | ||||
| GPU_blend(GPU_BLEND_ALPHA); | GPU_blend(GPU_BLEND_ALPHA); | ||||
| /* need scissor test, preview image can draw outside of boundary */ | /* need scissor test, preview image can draw outside of boundary */ | ||||
| int scissor[4]; | int scissor[4]; | ||||
| GPU_scissor_get(scissor); | GPU_scissor_get(scissor); | ||||
| GPU_scissor((rect.xmin - 1), | GPU_scissor((rect.xmin - 1), | ||||
| (rect.ymin - 1), | (rect.ymin - 1), | ||||
| (rect.xmax + 1) - (rect.xmin - 1), | (rect.xmax + 1) - (rect.xmin - 1), | ||||
| (rect.ymax + 1) - (rect.ymin - 1)); | (rect.ymax + 1) - (rect.ymin - 1)); | ||||
| if (scopes->track_disabled) { | if (scopes->track_disabled) { | ||||
| const float color[4] = {0.7f, 0.3f, 0.3f, 0.3f}; | const float color[4] = {0.7f, 0.3f, 0.3f, 0.3f}; | ||||
| UI_draw_roundbox_corner_set(UI_CNR_ALL); | UI_draw_roundbox_corner_set(UI_CNR_ALL); | ||||
| UI_draw_roundbox_4fv( | rctf disabled_rect{}; | ||||
| &(const rctf){ | disabled_rect.xmin = rect.xmin - 1; | ||||
| .xmin = rect.xmin - 1, | disabled_rect.xmax = rect.xmax + 1; | ||||
| .xmax = rect.xmax + 1, | disabled_rect.ymin = rect.ymin; | ||||
| .ymin = rect.ymin, | disabled_rect.ymax = rect.ymax + 1; | ||||
| .ymax = rect.ymax + 1, | UI_draw_roundbox_4fv(&disabled_rect, true, 3.0f, color); | ||||
| }, | |||||
| true, | |||||
| 3.0f, | |||||
| color); | |||||
| ok = true; | ok = true; | ||||
| } | } | ||||
| else if ((scopes->track_search) && | else if ((scopes->track_search) && | ||||
| ((!scopes->track_preview) || | ((!scopes->track_preview) || | ||||
| (scopes->track_preview->x != width || scopes->track_preview->y != height))) { | (scopes->track_preview->x != width || scopes->track_preview->y != height))) { | ||||
| if (scopes->track_preview) { | if (scopes->track_preview) { | ||||
| IMB_freeImBuf(scopes->track_preview); | IMB_freeImBuf(scopes->track_preview); | ||||
| Show All 31 Lines | if (!ok && scopes->track_preview) { | ||||
| if (width > 0 && height > 0) { | if (width > 0 && height > 0) { | ||||
| ImBuf *drawibuf = scopes->track_preview; | ImBuf *drawibuf = scopes->track_preview; | ||||
| float col_sel[4], col_outline[4]; | float col_sel[4], col_outline[4]; | ||||
| if (scopes->use_track_mask) { | if (scopes->use_track_mask) { | ||||
| const float color[4] = {0.0f, 0.0f, 0.0f, 0.3f}; | const float color[4] = {0.0f, 0.0f, 0.0f, 0.3f}; | ||||
| UI_draw_roundbox_corner_set(UI_CNR_ALL); | UI_draw_roundbox_corner_set(UI_CNR_ALL); | ||||
| UI_draw_roundbox_4fv( | rctf mask_rect{}; | ||||
| &(const rctf){ | mask_rect.xmin = rect.xmin - 1; | ||||
| .xmin = rect.xmin - 1, | mask_rect.xmax = rect.xmax + 1; | ||||
| .xmax = rect.xmax + 1, | mask_rect.ymin = rect.ymin; | ||||
| .ymin = rect.ymin, | mask_rect.ymax = rect.ymax + 1; | ||||
| .ymax = rect.ymax + 1, | UI_draw_roundbox_4fv(&mask_rect, true, 3.0f, color); | ||||
| }, | |||||
| true, | |||||
| 3.0f, | |||||
| color); | |||||
| } | } | ||||
| IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_3D_IMAGE_COLOR); | IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_3D_IMAGE_COLOR); | ||||
| immDrawPixelsTexTiled(&state, | immDrawPixelsTexTiled(&state, | ||||
| rect.xmin, | rect.xmin, | ||||
| rect.ymin + 1, | rect.ymin + 1, | ||||
| drawibuf->x, | drawibuf->x, | ||||
| drawibuf->y, | drawibuf->y, | ||||
| GPU_RGBA8, | GPU_RGBA8, | ||||
| true, | true, | ||||
| drawibuf->rect, | drawibuf->rect, | ||||
| 1.0f, | 1.0f, | ||||
| 1.0f, | 1.0f, | ||||
| NULL); | nullptr); | ||||
| /* draw cross for pixel position */ | /* draw cross for pixel position */ | ||||
| GPU_matrix_translate_2f(rect.xmin + scopes->track_pos[0], rect.ymin + scopes->track_pos[1]); | GPU_matrix_translate_2f(rect.xmin + scopes->track_pos[0], rect.ymin + scopes->track_pos[1]); | ||||
| GPU_scissor(rect.xmin, rect.ymin, BLI_rctf_size_x(&rect), BLI_rctf_size_y(&rect)); | GPU_scissor(rect.xmin, rect.ymin, BLI_rctf_size_x(&rect), BLI_rctf_size_y(&rect)); | ||||
| GPUVertFormat *format = immVertexFormat(); | GPUVertFormat *format = immVertexFormat(); | ||||
| const uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | const uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | ||||
| const uint col = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | const uint col = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | ||||
| Show All 31 Lines | if (!ok && scopes->track_preview) { | ||||
| GPU_matrix_pop(); | GPU_matrix_pop(); | ||||
| ok = true; | ok = true; | ||||
| } | } | ||||
| if (!ok) { | if (!ok) { | ||||
| const float color[4] = {0.0f, 0.0f, 0.0f, 0.3f}; | const float color[4] = {0.0f, 0.0f, 0.0f, 0.3f}; | ||||
| UI_draw_roundbox_corner_set(UI_CNR_ALL); | UI_draw_roundbox_corner_set(UI_CNR_ALL); | ||||
| UI_draw_roundbox_4fv( | rctf box_rect{}; | ||||
| &(const rctf){ | box_rect.xmin = rect.xmin - 1; | ||||
| .xmin = rect.xmin - 1, | box_rect.xmax = rect.xmax + 1; | ||||
| .xmax = rect.xmax + 1, | box_rect.ymin = rect.ymin; | ||||
| .ymin = rect.ymin, | box_rect.ymax = rect.ymax + 1; | ||||
| .ymax = rect.ymax + 1, | UI_draw_roundbox_4fv(&box_rect, true, 3.0f, color); | ||||
| }, | |||||
| true, | |||||
| 3.0f, | |||||
| color); | |||||
| } | } | ||||
| /* Restore scissor test. */ | /* Restore scissor test. */ | ||||
| GPU_scissor(UNPACK4(scissor)); | GPU_scissor(UNPACK4(scissor)); | ||||
| /* outline */ | /* outline */ | ||||
| draw_scope_end(&rect); | draw_scope_end(&rect); | ||||
| GPU_blend(GPU_BLEND_NONE); | GPU_blend(GPU_BLEND_NONE); | ||||
| ▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | void UI_draw_box_shadow(const rctf *rect, uchar alpha) | ||||
| immEnd(); | immEnd(); | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| GPU_blend(GPU_BLEND_NONE); | GPU_blend(GPU_BLEND_NONE); | ||||
| } | } | ||||
| void ui_draw_dropshadow( | void ui_draw_dropshadow(const rctf *rct, float radius, float aspect, float alpha, int /*select*/) | ||||
| const rctf *rct, float radius, float aspect, float alpha, int UNUSED(select)) | |||||
| { | { | ||||
| /* This undoes the scale of the view for higher zoom factors to clamp the shadow size. */ | /* This undoes the scale of the view for higher zoom factors to clamp the shadow size. */ | ||||
| const float clamped_aspect = smoothminf(aspect, 1.0f, 0.5f); | const float clamped_aspect = smoothminf(aspect, 1.0f, 0.5f); | ||||
| const float shadow_softness = 0.6f * U.widget_unit * clamped_aspect; | const float shadow_softness = 0.6f * U.widget_unit * clamped_aspect; | ||||
| const float shadow_offset = 0.5f * U.widget_unit * clamped_aspect; | const float shadow_offset = 0.5f * U.widget_unit * clamped_aspect; | ||||
| const float shadow_alpha = 0.5f * alpha; | const float shadow_alpha = 0.5f * alpha; | ||||
| const float max_radius = (BLI_rctf_size_y(rct) - shadow_offset) * 0.5f; | const float max_radius = (BLI_rctf_size_y(rct) - shadow_offset) * 0.5f; | ||||
| const float rad = min_ff(radius, max_radius); | const float rad = min_ff(radius, max_radius); | ||||
| GPU_blend(GPU_BLEND_ALPHA); | GPU_blend(GPU_BLEND_ALPHA); | ||||
| uiWidgetBaseParameters widget_params = { | uiWidgetBaseParameters widget_params{}; | ||||
| .recti.xmin = rct->xmin, | widget_params.recti.xmin = rct->xmin; | ||||
| .recti.ymin = rct->ymin, | widget_params.recti.ymin = rct->ymin; | ||||
| .recti.xmax = rct->xmax, | widget_params.recti.xmax = rct->xmax; | ||||
| .recti.ymax = rct->ymax - shadow_offset, | widget_params.recti.ymax = rct->ymax - shadow_offset; | ||||
| .rect.xmin = rct->xmin - shadow_softness, | widget_params.rect.xmin = rct->xmin - shadow_softness; | ||||
| .rect.ymin = rct->ymin - shadow_softness, | widget_params.rect.ymin = rct->ymin - shadow_softness; | ||||
| .rect.xmax = rct->xmax + shadow_softness, | widget_params.rect.xmax = rct->xmax + shadow_softness; | ||||
| .rect.ymax = rct->ymax - shadow_offset + shadow_softness, | widget_params.rect.ymax = rct->ymax - shadow_offset + shadow_softness; | ||||
| .radi = rad, | widget_params.radi = rad; | ||||
| .rad = rad + shadow_softness, | widget_params.rad = rad + shadow_softness; | ||||
| .round_corners[0] = (roundboxtype & UI_CNR_BOTTOM_LEFT) ? 1.0f : 0.0f, | widget_params.round_corners[0] = (roundboxtype & UI_CNR_BOTTOM_LEFT) ? 1.0f : 0.0f; | ||||
| .round_corners[1] = (roundboxtype & UI_CNR_BOTTOM_RIGHT) ? 1.0f : 0.0f, | widget_params.round_corners[1] = (roundboxtype & UI_CNR_BOTTOM_RIGHT) ? 1.0f : 0.0f; | ||||
| .round_corners[2] = (roundboxtype & UI_CNR_TOP_RIGHT) ? 1.0f : 0.0f, | widget_params.round_corners[2] = (roundboxtype & UI_CNR_TOP_RIGHT) ? 1.0f : 0.0f; | ||||
| .round_corners[3] = (roundboxtype & UI_CNR_TOP_LEFT) ? 1.0f : 0.0f, | widget_params.round_corners[3] = (roundboxtype & UI_CNR_TOP_LEFT) ? 1.0f : 0.0f; | ||||
| .alpha_discard = 1.0f, | widget_params.alpha_discard = 1.0f; | ||||
| }; | |||||
| GPUBatch *batch = ui_batch_roundbox_shadow_get(); | GPUBatch *batch = ui_batch_roundbox_shadow_get(); | ||||
| GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_SHADOW); | GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_SHADOW); | ||||
| GPU_batch_uniform_4fv_array(batch, "parameters", 4, (const float(*)[4]) & widget_params); | GPU_batch_uniform_4fv_array(batch, "parameters", 4, (const float(*)[4]) & widget_params); | ||||
| GPU_batch_uniform_1f(batch, "alpha", shadow_alpha); | GPU_batch_uniform_1f(batch, "alpha", shadow_alpha); | ||||
| GPU_batch_draw(batch); | GPU_batch_draw(batch); | ||||
| /* outline emphasis */ | /* outline emphasis */ | ||||
| const float color[4] = {0.0f, 0.0f, 0.0f, 0.4f}; | const float color[4] = {0.0f, 0.0f, 0.0f, 0.4f}; | ||||
| UI_draw_roundbox_4fv( | rctf rect{}; | ||||
| &(const rctf){ | rect.xmin = rct->xmin - 0.5f; | ||||
| .xmin = rct->xmin - 0.5f, | rect.xmax = rct->xmax + 0.5f; | ||||
| .xmax = rct->xmax + 0.5f, | rect.ymin = rct->ymin - 0.5f; | ||||
| .ymin = rct->ymin - 0.5f, | rect.ymax = rct->ymax + 0.5f; | ||||
| .ymax = rct->ymax + 0.5f, | UI_draw_roundbox_4fv(&rect, false, radius + 0.5f, color); | ||||
| }, | |||||
| false, | |||||
| radius + 0.5f, | |||||
| color); | |||||
| GPU_blend(GPU_BLEND_NONE); | GPU_blend(GPU_BLEND_NONE); | ||||
| } | } | ||||