Blender V5.3
interface_draw.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cmath>
10#include <cstring>
11
12#include "DNA_color_types.h"
13#include "DNA_curve_types.h"
15#include "DNA_movieclip_types.h"
16#include "DNA_scene_types.h"
17#include "DNA_screen_types.h"
18
19#include "BLI_math_matrix.hh"
21#include "BLI_polyfill_2d.hh"
22#include "BLI_rect.hh"
23#include "BLI_string_utf8.hh"
24#include "BLI_utildefines.hh"
25
26#include "MEM_guardedalloc.h"
27
28#include "BKE_colorband.hh"
29#include "BKE_colortools.hh"
30#include "BKE_context.hh"
31#include "BKE_curveprofile.h"
32#include "BKE_tracking.hh"
33
35#include "IMB_imbuf.hh"
36#include "IMB_imbuf_types.hh"
37
38#include "OCIO_scope.hh"
39#include "OCIO_view.hh"
40
41#include "BIF_glutil.hh"
42
43#include "BLF_api.hh"
44
45#include "GPU_batch.hh"
46#include "GPU_batch_presets.hh"
47#include "GPU_immediate.hh"
48#include "GPU_immediate_util.hh"
49#include "GPU_matrix.hh"
50#include "GPU_shader_shared.hh"
51#include "GPU_state.hh"
52#include "GPU_uniform_buffer.hh"
53
54/* own include */
55#include "interface_intern.hh"
56
57namespace blender::ui {
58
59static int roundboxtype = CNR_ALL;
60
62{
63 /* Not sure the roundbox function is the best place to change this
64 * if this is undone, it's not that big a deal, only makes curves edges square. */
65 roundboxtype = type;
66}
67
68#if 0 /* unused */
69int draw_roundbox_corner_get()
70{
71 return roundboxtype;
72}
73#endif
74
75void draw_roundbox_4fv_ex(const rctf *rect,
76 const float inner1[4],
77 const float inner2[4],
78 float shade_dir,
79 const float outline[4],
80 float outline_width,
81 float rad)
82{
83 /* WATCH: This is assuming the ModelViewProjectionMatrix is area pixel space.
84 * If it has been scaled, then it's no longer valid. */
85 WidgetBaseParameters widget_params{};
86 widget_params.recti.xmin = rect->xmin + outline_width;
87 widget_params.recti.ymin = rect->ymin + outline_width;
88 widget_params.recti.xmax = rect->xmax - outline_width;
89 widget_params.recti.ymax = rect->ymax - outline_width;
90 widget_params.rect = *rect;
91 widget_params.radi = rad;
92 widget_params.rad = rad;
93 widget_params.round_corners[0] = (roundboxtype & CNR_BOTTOM_LEFT) ? 1.0f : 0.0f;
94 widget_params.round_corners[1] = (roundboxtype & CNR_BOTTOM_RIGHT) ? 1.0f : 0.0f;
95 widget_params.round_corners[2] = (roundboxtype & CNR_TOP_RIGHT) ? 1.0f : 0.0f;
96 widget_params.round_corners[3] = (roundboxtype & CNR_TOP_LEFT) ? 1.0f : 0.0f;
97 widget_params.color_inner1[0] = inner1 ? inner1[0] : 0.0f;
98 widget_params.color_inner1[1] = inner1 ? inner1[1] : 0.0f;
99 widget_params.color_inner1[2] = inner1 ? inner1[2] : 0.0f;
100 widget_params.color_inner1[3] = inner1 ? inner1[3] : 0.0f;
101 widget_params.color_inner2[0] = inner2 ? inner2[0] : inner1 ? inner1[0] : 0.0f;
102 widget_params.color_inner2[1] = inner2 ? inner2[1] : inner1 ? inner1[1] : 0.0f;
103 widget_params.color_inner2[2] = inner2 ? inner2[2] : inner1 ? inner1[2] : 0.0f;
104 widget_params.color_inner2[3] = inner2 ? inner2[3] : inner1 ? inner1[3] : 0.0f;
105 widget_params.color_outline[0] = outline ? outline[0] : inner1 ? inner1[0] : 0.0f;
106 widget_params.color_outline[1] = outline ? outline[1] : inner1 ? inner1[1] : 0.0f;
107 widget_params.color_outline[2] = outline ? outline[2] : inner1 ? inner1[2] : 0.0f;
108 widget_params.color_outline[3] = outline ? outline[3] : inner1 ? inner1[3] : 0.0f;
109 widget_params.shade_dir = shade_dir;
110 widget_params.alpha_discard = 1.0f;
111
112 gpu::Batch *batch = batch_roundbox_widget_get();
114 GPU_batch_uniform_4fv_array(batch, "parameters", 11, (const float (*)[4]) & widget_params);
115 const GPUBlend old_blend = GPU_blend_get();
117 GPU_batch_draw(batch);
118 GPU_blend(old_blend);
119}
120
122 const rctf *rect, bool filled, float rad, const uchar col[3], uchar alpha)
123{
124 const float colv[4] = {
125 float(col[0]) / 255.0f,
126 float(col[1]) / 255.0f,
127 float(col[2]) / 255.0f,
128 float(alpha) / 255.0f,
129 };
130 draw_roundbox_4fv_ex(rect, (filled) ? colv : nullptr, nullptr, 1.0f, colv, U.pixelsize, rad);
131}
132
134 const rctf *rect, bool filled, float rad, const float col[3], float alpha)
135{
136 const float colv[4] = {col[0], col[1], col[2], alpha};
137 draw_roundbox_4fv_ex(rect, (filled) ? colv : nullptr, nullptr, 1.0f, colv, U.pixelsize, rad);
138}
139
140void draw_roundbox_aa(const rctf *rect, bool filled, float rad, const float color[4])
141{
142 /* XXX this is to emulate previous behavior of semitransparent fills but that's was a side effect
143 * of the previous AA method. Better fix the callers. */
144 float colv[4] = {color[0], color[1], color[2], color[3]};
145 if (filled) {
146 colv[3] *= 0.65f;
147 }
148
149 draw_roundbox_4fv_ex(rect, (filled) ? colv : nullptr, nullptr, 1.0f, colv, U.pixelsize, rad);
150}
151
152void draw_roundbox_4fv(const rctf *rect, bool filled, float rad, const float col[4])
153{
154 /* Exactly the same as draw_roundbox_aa but does not do the legacy transparency. */
155 draw_roundbox_4fv_ex(rect, (filled) ? col : nullptr, nullptr, 1.0f, col, U.pixelsize, rad);
156}
157
158void draw_rounded_corners_inverted(const rcti &rect, const float rad, const float4 color)
159{
160 GPUVertFormat *format = immVertexFormat();
161 const uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
162
163 float vec[4][2] = {
164 {0.195, 0.02},
165 {0.55, 0.169},
166 {0.831, 0.45},
167 {0.98, 0.805},
168 };
169 for (int a = 0; a < 4; a++) {
170 mul_v2_fl(vec[a], rad);
171 }
172
175
178 immVertex2f(pos, rect.xmin, rect.ymax);
179 immVertex2f(pos, rect.xmin, rect.ymax - rad);
180 for (int a = 0; a < 4; a++) {
181 immVertex2f(pos, rect.xmin + vec[a][1], rect.ymax - rad + vec[a][0]);
182 }
183 immVertex2f(pos, rect.xmin + rad, rect.ymax);
184 immEnd();
185 }
186
189 immVertex2f(pos, rect.xmax, rect.ymax);
190 immVertex2f(pos, rect.xmax - rad, rect.ymax);
191 for (int a = 0; a < 4; a++) {
192 immVertex2f(pos, rect.xmax - rad + vec[a][0], rect.ymax - vec[a][1]);
193 }
194 immVertex2f(pos, rect.xmax, rect.ymax - rad);
195 immEnd();
196 }
197
200 immVertex2f(pos, rect.xmax, rect.ymin);
201 immVertex2f(pos, rect.xmax, rect.ymin + rad);
202 for (int a = 0; a < 4; a++) {
203 immVertex2f(pos, rect.xmax - vec[a][1], rect.ymin + rad - vec[a][0]);
204 }
205 immVertex2f(pos, rect.xmax - rad, rect.ymin);
206 immEnd();
207 }
208
211 immVertex2f(pos, rect.xmin, rect.ymin);
212 immVertex2f(pos, rect.xmin + rad, rect.ymin);
213 for (int a = 0; a < 4; a++) {
214 immVertex2f(pos, rect.xmin + rad - vec[a][0], rect.ymin + vec[a][1]);
215 }
216 immVertex2f(pos, rect.xmin, rect.ymin + rad);
217 immEnd();
218 }
219
221}
222
223void draw_text_underline(int pos_x, int pos_y, int len, int height, const float color[4])
224{
225 const int ofs_y = 4 * U.pixelsize;
226
227 GPUVertFormat *format = immVertexFormat();
228 const uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
229
232
233 immRectf(pos, pos_x, pos_y - ofs_y, pos_x + len, pos_y - ofs_y + (height * U.pixelsize));
235}
236
237/* ************** SPECIAL BUTTON DRAWING FUNCTIONS ************* */
238
239void draw_but_TAB_outline(const rcti *rect, float rad, uchar highlight[3], uchar highlight_fade[3])
240{
241 /* NOTE: based on `UI_draw_roundbox` functions
242 * check on making a version which allows us to skip some sides. */
243
244 GPUVertFormat *format = immVertexFormat();
245 const uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
246 const uint col = GPU_vertformat_attr_add(format, "color", gpu::VertAttrType::UNORM_8_8_8_8);
247 /* add a 1px offset, looks nicer */
248 const int minx = rect->xmin + U.pixelsize, maxx = rect->xmax - U.pixelsize;
249 const int miny = rect->ymin + U.pixelsize, maxy = rect->ymax - U.pixelsize;
250 int a;
251 float vec[4][2] = {
252 {0.195, 0.02},
253 {0.55, 0.169},
254 {0.831, 0.45},
255 {0.98, 0.805},
256 };
257
258 /* Multiply. */
259 for (a = 0; a < 4; a++) {
260 mul_v2_fl(vec[a], rad);
261 }
262
265
266 immAttr4ub(col, UNPACK3(highlight), 255);
267
268 /* start with corner left-top */
270 immVertex2f(pos, minx, maxy - rad);
271 for (a = 0; a < 4; a++) {
272 immVertex2f(pos, minx + vec[a][1], maxy - rad + vec[a][0]);
273 }
274 immVertex2f(pos, minx + rad, maxy);
275 }
276 else {
277 immVertex2f(pos, minx, maxy);
278 }
279
280 /* corner right-top */
282 immVertex2f(pos, maxx - rad, maxy);
283 for (a = 0; a < 4; a++) {
284 immVertex2f(pos, maxx - rad + vec[a][0], maxy - vec[a][1]);
285 }
286 immVertex2f(pos, maxx, maxy - rad);
287 }
288 else {
289 immVertex2f(pos, maxx, maxy);
290 }
291
292 immAttr4ub(col, UNPACK3(highlight_fade), 255);
293
294 /* corner right-bottom */
296 immVertex2f(pos, maxx, miny + rad);
297 for (a = 0; a < 4; a++) {
298 immVertex2f(pos, maxx - vec[a][1], miny + rad - vec[a][0]);
299 }
300 immVertex2f(pos, maxx - rad, miny);
301 }
302 else {
303 immVertex2f(pos, maxx, miny);
304 }
305
306 /* corner left-bottom */
308 immVertex2f(pos, minx + rad, miny);
309 for (a = 0; a < 4; a++) {
310 immVertex2f(pos, minx + rad - vec[a][0], miny + vec[a][1]);
311 }
312 immVertex2f(pos, minx, miny + rad);
313 }
314 else {
315 immVertex2f(pos, minx, miny);
316 }
317
318 immAttr4ub(col, UNPACK3(highlight), 255);
319
320 /* back to corner left-top */
321 immVertex2f(pos, minx, (roundboxtype & CNR_TOP_LEFT) ? (maxy - rad) : maxy);
322
323 immEnd();
325}
326
327void draw_but_IMAGE(ARegion * /*region*/,
328 Button *but,
329 const uiWidgetColors * /*wcol*/,
330 const rcti *rect)
331{
332#ifdef WITH_HEADLESS
333 (void)rect;
334 (void)but;
335#else
336 const ImBuf *ibuf = reinterpret_cast<const ImBuf *>(but->poin);
337
338 if (!ibuf || ibuf->x <= 0 || ibuf->y <= 0) {
339 return;
340 }
341
342 const int w = BLI_rcti_size_x(rect);
343 const int h = BLI_rcti_size_y(rect);
344
345 /* scissor doesn't seem to be doing the right thing...? */
346# if 0
347 /* prevent drawing outside widget area */
348 int scissor[4];
349 GPU_scissor_get(scissor);
350 GPU_scissor(rect->xmin, rect->ymin, w, h);
351# endif
352
353 /* Combine with premultiplied alpha. */
355
356 /* Scale while drawing, using filtering and mipmaps. Without scaling,
357 * draw unfiltered for exact pixels. */
358 const bool use_filter = (w != ibuf->x || h != ibuf->y);
359
360 float col[4] = {1.0f, 1.0f, 1.0f, 1.0f};
361 if (but->col[3] != 0) {
362 /* Optionally use Button's col to recolor the image. */
363 rgba_uchar_to_float(col, but->col);
364 }
365
367 drawer.draw(float(rect->xmin),
368 float(rect->ymin),
369 ibuf->x,
370 ibuf->y,
371 gpu::TextureFormat::UNORM_8_8_8_8,
372 use_filter,
373 ibuf->byte_data(),
374 float(w) / ibuf->x,
375 float(h) / ibuf->y,
376 col);
377
379
380# if 0
381 /* Restore scissor-test. */
382 GPU_scissor(scissor[0], scissor[1], scissor[2], scissor[3]);
383# endif
384
385#endif
386}
387
389 const rctf *rect,
390 const float title_aspect[2],
391 const float action_aspect[2])
392{
393 const float size_x_half = (rect->xmax - rect->xmin) * 0.5f;
394 const float size_y_half = (rect->ymax - rect->ymin) * 0.5f;
395
396 const float *safe_areas[] = {title_aspect, action_aspect};
397 const int safe_len = ARRAY_SIZE(safe_areas);
398
399 for (int i = 0; i < safe_len; i++) {
400 if (safe_areas[i][0] || safe_areas[i][1]) {
401 const float margin_x = safe_areas[i][0] * size_x_half;
402 const float margin_y = safe_areas[i][1] * size_y_half;
403
404 const float minx = rect->xmin + margin_x;
405 const float miny = rect->ymin + margin_y;
406 const float maxx = rect->xmax - margin_x;
407 const float maxy = rect->ymax - margin_y;
408
409 imm_draw_box_wire_2d(pos, minx, miny, maxx, maxy);
410 }
411 }
412}
413
414static void draw_scope_end(const rctf *rect)
415{
417
418 /* outline */
420 const float color[4] = {0.0f, 0.0f, 0.0f, 0.5f};
421 rctf box_rect{};
422 box_rect.xmin = rect->xmin - 1;
423 box_rect.xmax = rect->xmax + 1;
424 box_rect.ymin = rect->ymin;
425 box_rect.ymax = rect->ymax + 1;
426 draw_roundbox_4fv(&box_rect, false, 3.0f, color);
427}
428
429static void histogram_draw_one(float r,
430 float g,
431 float b,
432 float alpha,
433 float x,
434 float y,
435 float w,
436 float h,
437 const float *data,
438 int res,
439 const bool is_line,
440 uint pos_attr)
441{
442 const float color[4] = {r, g, b, alpha};
443
444 /* that can happen */
445 if (res == 0) {
446 return;
447 }
448
449 GPU_line_smooth(true);
451
453
454 if (is_line) {
455 /* curve outline */
456 GPU_line_width(1.5);
457
459 for (int i = 0; i < res; i++) {
460 const float x2 = x + i * (w / float(res));
461 immVertex2f(pos_attr, x2, y + (data[i] * h));
462 }
463 immEnd();
464
465 GPU_line_width(1.0f);
466 }
467 else {
468 /* under the curve */
470 immVertex2f(pos_attr, x, y);
471 immVertex2f(pos_attr, x, y + (data[0] * h));
472 for (int i = 1; i < res; i++) {
473 const float x2 = x + i * (w / float(res));
474 immVertex2f(pos_attr, x2, y + (data[i] * h));
475 immVertex2f(pos_attr, x2, y);
476 }
477 immEnd();
478
479 /* curve outline */
480 immUniformColor4f(0.0f, 0.0f, 0.0f, 0.25f);
481
484 for (int i = 0; i < res; i++) {
485 const float x2 = x + i * (w / float(res));
486 immVertex2f(pos_attr, x2, y + (data[i] * h));
487 }
488 immEnd();
489 }
490
491 GPU_line_smooth(false);
492}
493
494#define HISTOGRAM_TOT_GRID_LINES 4
495
497 Button *but,
498 const uiWidgetColors * /*wcol*/,
499 const rcti *recti)
500{
501 Histogram *hist = reinterpret_cast<Histogram *>(but->poin);
502 const int res = hist->x_resolution;
503 const bool is_line = (hist->flag & HISTO_FLAG_LINE) != 0;
504
505 rctf rect{};
506 rect.xmin = float(recti->xmin + 1);
507 rect.xmax = float(recti->xmax - 1);
508 rect.ymin = float(recti->ymin + 1);
509 rect.ymax = float(recti->ymax - 1);
510
511 const float w = BLI_rctf_size_x(&rect);
512 const float h = BLI_rctf_size_y(&rect) * hist->ymax;
513
515
516 const float color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
518 rctf back_rect{};
519 back_rect.xmin = rect.xmin - 1;
520 back_rect.xmax = rect.xmax + 1;
521 back_rect.ymin = rect.ymin - 1;
522 back_rect.ymax = rect.ymax + 1;
523
524 draw_roundbox_4fv(&back_rect, true, 3.0f, color);
525
526 /* need scissor test, histogram can draw outside of boundary */
527 int scissor[4];
528 GPU_scissor_get(scissor);
529 rcti scissor_new{};
530 scissor_new.xmin = rect.xmin;
531 scissor_new.ymin = rect.ymin;
532 scissor_new.xmax = rect.xmax;
533 scissor_new.ymax = rect.ymax;
534 const rcti scissor_region = {0, region->winx, 0, region->winy};
535 BLI_rcti_isect(&scissor_new, &scissor_region, &scissor_new);
536 GPU_scissor(scissor_new.xmin,
537 scissor_new.ymin,
538 BLI_rcti_size_x(&scissor_new),
539 BLI_rcti_size_y(&scissor_new));
540
541 GPUVertFormat *format = immVertexFormat();
542 GPU_scissor_test(true);
543 const uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
544
546
547 immUniformColor4f(1.0f, 1.0f, 1.0f, 0.08f);
548 /* draw grid lines here */
549 for (int i = 1; i <= HISTOGRAM_TOT_GRID_LINES; i++) {
550 const float fac = float(i) / float(HISTOGRAM_TOT_GRID_LINES);
551
552 /* so we can tell the 1.0 color point */
553 if (i == HISTOGRAM_TOT_GRID_LINES) {
554 immUniformColor4f(1.0f, 1.0f, 1.0f, 0.5f);
555 }
556
558
559 immVertex2f(pos, rect.xmin, rect.ymin + fac * h);
560 immVertex2f(pos, rect.xmax, rect.ymin + fac * h);
561
562 immVertex2f(pos, rect.xmin + fac * w, rect.ymin);
563 immVertex2f(pos, rect.xmin + fac * w, rect.ymax);
564
565 immEnd();
566 }
567
568 if (hist->mode == HISTO_MODE_LUMA) {
570 1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_luma, res, is_line, pos);
571 }
572 else if (hist->mode == HISTO_MODE_ALPHA) {
574 1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_a, res, is_line, pos);
575 }
576 else {
577 if (ELEM(hist->mode, HISTO_MODE_RGB, HISTO_MODE_R)) {
579 1.0, 0.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_r, res, is_line, pos);
580 }
581 if (ELEM(hist->mode, HISTO_MODE_RGB, HISTO_MODE_G)) {
583 0.0, 1.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_g, res, is_line, pos);
584 }
585 if (ELEM(hist->mode, HISTO_MODE_RGB, HISTO_MODE_B)) {
587 0.0, 0.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_b, res, is_line, pos);
588 }
589 }
590
592
593 /* Restore scissor test. */
594 GPU_scissor_test(false);
595 GPU_scissor(UNPACK4(scissor));
596
597 /* outline */
598 draw_scope_end(&rect);
599}
600
601#undef HISTOGRAM_TOT_GRID_LINES
602
603static void waveform_draw_one(const float *waveform, int waveform_num, const float col[3])
604{
607 "It is not allowed to draw a batch when immediate mode has a shader bound. It will "
608 "use the incorrect shader and is hard to discover.");
609 GPUVertFormat format = {0};
610 const uint pos_id = GPU_vertformat_attr_add(&format, "pos", gpu::VertAttrType::SFLOAT_32_32);
611
612 gpu::VertBuf *vbo = GPU_vertbuf_create_with_format(format);
613 GPU_vertbuf_data_alloc(*vbo, waveform_num);
614
615 GPU_vertbuf_attr_fill(vbo, pos_id, waveform);
616
617 /* TODO: store the #gpu::Batch inside the scope. */
618 gpu::Batch *batch = GPU_batch_create_ex(GPU_PRIM_POINTS, vbo, nullptr, GPU_BATCH_OWNS_VBO);
620 GPU_batch_uniform_4f(batch, "color", col[0], col[1], col[2], 1.0f);
621 GPU_batch_uniform_1f(batch, "size", 1.0f);
622 GPU_batch_draw(batch);
623
624 GPU_batch_discard(batch);
625}
626
631static_assert(sizeof(WaveformColorVertex) == 24);
632
633static void waveform_draw_rgb(const float *waveform,
634 int waveform_num,
635 const float *col,
636 float alpha)
637{
638 GPUVertFormat format = {0};
639 GPU_vertformat_attr_add(&format, "pos", gpu::VertAttrType::SFLOAT_32_32);
640 GPU_vertformat_attr_add(&format, "color", gpu::VertAttrType::SFLOAT_32_32_32_32);
641
642 gpu::VertBuf *vbo = GPU_vertbuf_create_with_format(format);
643
644 GPU_vertbuf_data_alloc(*vbo, waveform_num);
646 for (int i = 0; i < waveform_num; i++) {
647 memcpy(reinterpret_cast<void *>(&data->pos), waveform, sizeof(data->pos));
648 memcpy(reinterpret_cast<void *>(&data->color), col, sizeof(float) * 3);
649 data->color.w = alpha;
650 waveform += 2;
651 col += 3;
652 data++;
653 }
655 GPU_vertbuf_use(vbo);
656
657 gpu::Batch *batch = GPU_batch_create_ex(GPU_PRIM_POINTS, vbo, nullptr, GPU_BATCH_OWNS_VBO);
659 GPU_batch_uniform_1f(batch, "size", 1.0f);
660 GPU_batch_draw(batch);
661 GPU_batch_discard(batch);
662}
663
664static void circle_draw_rgb(float *points, int tot_points, const float *col, GPUPrimType prim)
665{
666 GPUVertFormat format = {0};
667 const uint pos_id = GPU_vertformat_attr_add(&format, "pos", gpu::VertAttrType::SFLOAT_32_32);
668 const uint col_id = GPU_vertformat_attr_add(
669 &format, "color", gpu::VertAttrType::SFLOAT_32_32_32_32);
670
671 gpu::VertBuf *vbo = GPU_vertbuf_create_with_format(format);
672
673 GPU_vertbuf_data_alloc(*vbo, tot_points);
674 GPU_vertbuf_attr_fill(vbo, pos_id, points);
675 GPU_vertbuf_attr_fill(vbo, col_id, col);
676
677 gpu::Batch *batch = GPU_batch_create_ex(prim, vbo, nullptr, GPU_BATCH_OWNS_VBO);
678
680 GPU_batch_draw(batch);
681 GPU_batch_discard(batch);
682}
683
685 ARegion *region,
686 Button *but,
687 const uiWidgetColors * /*wcol*/,
688 const rcti *recti)
689{
690 Scopes *scopes = reinterpret_cast<Scopes *>(but->poin);
691 int scissor[4];
692 float colors[3][3];
693 const float colorsycc[3][3] = {{1, 0, 1}, {1, 1, 0}, {0, 1, 1}};
694 /* Colors pre-multiplied by alpha for speed up. */
695 float colors_alpha[3][3], colorsycc_alpha[3][3];
696 float min, max;
697
698 if (scopes == nullptr) {
699 return;
700 }
701
702 rctf rect{};
703 rect.xmin = float(recti->xmin + 1);
704 rect.xmax = float(recti->xmax - 1);
705 rect.ymin = float(recti->ymin + 1);
706 rect.ymax = float(recti->ymax - 1);
707
708 if (scopes->wavefrm_yfac < 0.5f) {
709 scopes->wavefrm_yfac = 0.98f;
710 }
711 const float w = BLI_rctf_size_x(&rect) - 7;
712 const float h = BLI_rctf_size_y(&rect) * scopes->wavefrm_yfac;
713 const float yofs = rect.ymin + (BLI_rctf_size_y(&rect) - h) * 0.5f;
714 const float w3 = w / 3.0f;
715
716 /* log scale for alpha */
717 const float alpha = scopes->wavefrm_alpha * scopes->wavefrm_alpha;
718
719 unit_m3(colors);
720
721 for (int c = 0; c < 3; c++) {
722 for (int i = 0; i < 3; i++) {
723 colors_alpha[c][i] = colors[c][i] * alpha;
724 colorsycc_alpha[c][i] = colorsycc[c][i] * alpha;
725 }
726 }
727
728 /* Flush text cache before changing scissors. */
730
732
733 const float color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
735 rctf back_rect{};
736 back_rect.xmin = rect.xmin - 1.0f;
737 back_rect.xmax = rect.xmax + 1.0f;
738 back_rect.ymin = rect.ymin - 1.0f;
739 back_rect.ymax = rect.ymax + 1.0f;
740 draw_roundbox_4fv(&back_rect, true, 3.0f, color);
741
742 /* need scissor test, waveform can draw outside of boundary */
743 GPU_scissor_get(scissor);
744 rcti scissor_new{};
745 scissor_new.xmin = rect.xmin;
746 scissor_new.ymin = rect.ymin;
747 scissor_new.xmax = rect.xmax;
748 scissor_new.ymax = rect.ymax;
749 const rcti scissor_region = {0, region->winx, 0, region->winy};
750 BLI_rcti_isect(&scissor_new, &scissor_region, &scissor_new);
751 GPU_scissor(scissor_new.xmin,
752 scissor_new.ymin,
753 BLI_rcti_size_x(&scissor_new),
754 BLI_rcti_size_y(&scissor_new));
755
756 /* Get scope info for the current display/view. */
757 const Scene *scene = CTX_data_scene(C);
759 &scene->view_settings);
760
761 /* Draw labels centered on each grid line, with the line starting after the text.
762 * Font size is chosen so all labels fit without overlap. */
763 const int font_id = BLF_default();
764 float font_size = 8.0f * UI_SCALE_FAC;
765 float min_gap = FLT_MAX;
766 for (int i = 1; i < scope_info.graticules.size(); i++) {
767 min_gap = std::min(min_gap,
768 scope_info.graticules[i].value - scope_info.graticules[i - 1].value);
769 }
770 font_size = std::min(font_size, min_gap * h * 0.8f);
771 BLF_size(font_id, font_size);
772 BLF_color4f(font_id, 1.0f, 1.0f, 1.0f, 0.2f);
773
774 struct GraticuleLine {
775 float x_start, y;
776 };
777 Vector<GraticuleLine> grid_lines;
778
779 for (const ocio::ScopeGraticule &graticule : scope_info.graticules) {
780 const float y = yofs + graticule.value * h;
781 const size_t label_len = strlen(graticule.label);
782
783 float text_width, text_height;
784 BLF_width_and_height(font_id, graticule.label, label_len, &text_width, &text_height);
785 const float gap = text_width + text_height;
786
787 BLF_position(font_id, rect.xmin + (gap - text_width) * 0.5f, y - text_height * 0.5f, 0);
788 BLF_draw(font_id, graticule.label, label_len);
789
790 grid_lines.append({rect.xmin + gap, y});
791 }
792
793 /* Flush text cache before drawing lines on top. */
795
797
798 GPUVertFormat *format = immVertexFormat();
799 GPU_scissor_test(true);
800 const uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
801
803
804 immUniformColor4f(1.0f, 1.0f, 1.0f, 0.2f);
805
806 /* Draw grid lines. */
807 immBegin(GPU_PRIM_LINES, int(grid_lines.size()) * 2);
808 for (const GraticuleLine &line : grid_lines) {
809 immVertex2f(pos, line.x_start, line.y);
810 immVertex2f(pos, rect.xmax, line.y);
811 }
812 immEnd();
813
814 /* separate min max zone on the right */
816 immVertex2f(pos, rect.xmin + w, rect.ymin);
817 immVertex2f(pos, rect.xmin + w, rect.ymax);
818 immEnd();
819
820 /* 16-235-240 level in case of ITU-R BT601/709 */
821 immUniformColor4f(1.0f, 0.4f, 0.0f, 0.2f);
824
825 immVertex2f(pos, rect.xmin + 22, yofs + h * 16.0f / 255.0f);
826 immVertex2f(pos, rect.xmax + 1, yofs + h * 16.0f / 255.0f);
827
828 immVertex2f(pos, rect.xmin + 22, yofs + h * 235.0f / 255.0f);
829 immVertex2f(pos, rect.xmin + w3, yofs + h * 235.0f / 255.0f);
830
831 immVertex2f(pos, rect.xmin + 3 * w3, yofs + h * 235.0f / 255.0f);
832 immVertex2f(pos, rect.xmax + 1, yofs + h * 235.0f / 255.0f);
833
834 immVertex2f(pos, rect.xmin + w3, yofs + h * 240.0f / 255.0f);
835 immVertex2f(pos, rect.xmax + 1, yofs + h * 240.0f / 255.0f);
836
837 immEnd();
838 }
839 /* 7.5 IRE black point level for NTSC */
840 if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA) {
842 immVertex2f(pos, rect.xmin, yofs + h * 0.075f);
843 immVertex2f(pos, rect.xmax + 1, yofs + h * 0.075f);
844 immEnd();
845 }
846
847 if (scopes->ok && scopes->waveform_1 != nullptr) {
849 GPU_point_size(1.0);
850
851 /* LUMA (1 channel) */
852 if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA) {
853 const float col[3] = {alpha, alpha, alpha};
854
856 GPU_matrix_translate_2f(rect.xmin, yofs);
858
860 waveform_draw_one(scopes->waveform_1, scopes->waveform_tot, col);
862
864
865 /* min max */
866 immUniformColor3f(0.5f, 0.5f, 0.5f);
867 min = yofs + scopes->minmax[0][0] * h;
868 max = yofs + scopes->minmax[0][1] * h;
869 CLAMP(min, rect.ymin, rect.ymax);
870 CLAMP(max, rect.ymin, rect.ymax);
871
873 immVertex2f(pos, rect.xmax - 3, min);
874 immVertex2f(pos, rect.xmax - 3, max);
875 immEnd();
876 }
877 /* RGB (3 channel) */
878 else if (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB) {
880 GPU_matrix_translate_2f(rect.xmin, yofs);
883 waveform_draw_one(scopes->waveform_1, scopes->waveform_tot, colors_alpha[0]);
884 waveform_draw_one(scopes->waveform_2, scopes->waveform_tot, colors_alpha[1]);
885 waveform_draw_one(scopes->waveform_3, scopes->waveform_tot, colors_alpha[2]);
888 }
889 /* PARADE / YCC (3 channels) */
890 else if (ELEM(scopes->wavefrm_mode,
895 {
896 const int rgb = (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB_PARADE);
899 GPU_matrix_translate_2f(rect.xmin, yofs);
900 GPU_matrix_scale_2f(w3, h);
901
903 scopes->waveform_1, scopes->waveform_tot, (rgb) ? colors_alpha[0] : colorsycc_alpha[0]);
904
905 GPU_matrix_translate_2f(1.0f, 0.0f);
907 scopes->waveform_2, scopes->waveform_tot, (rgb) ? colors_alpha[1] : colorsycc_alpha[1]);
908
909 GPU_matrix_translate_2f(1.0f, 0.0f);
911 scopes->waveform_3, scopes->waveform_tot, (rgb) ? colors_alpha[2] : colorsycc_alpha[2]);
912
915 }
916
917 /* min max */
918 if (scopes->wavefrm_mode != SCOPES_WAVEFRM_LUMA) {
919 for (int c = 0; c < 3; c++) {
921 immUniformColor3f(colors[c][0] * 0.75f, colors[c][1] * 0.75f, colors[c][2] * 0.75f);
922 }
923 else {
925 colorsycc[c][0] * 0.75f, colorsycc[c][1] * 0.75f, colorsycc[c][2] * 0.75f);
926 }
927 min = yofs + scopes->minmax[c][0] * h;
928 max = yofs + scopes->minmax[c][1] * h;
929 CLAMP(min, rect.ymin, rect.ymax);
930 CLAMP(max, rect.ymin, rect.ymax);
931
933 immVertex2f(pos, rect.xmin + w + 2 + c * 2, min);
934 immVertex2f(pos, rect.xmin + w + 2 + c * 2, max);
935 immEnd();
936 }
937 }
938 }
939
941
942 /* Restore scissor test. */
943 GPU_scissor_test(false);
944 GPU_scissor(UNPACK4(scissor));
945
946 /* outline */
947 draw_scope_end(&rect);
948
950}
951
952static float polar_to_x(float center, float diam, float ampli, float angle)
953{
954 return center + diam * ampli * cosf(angle);
955}
956
957static float polar_to_y(float center, float diam, float ampli, float angle)
958{
959 return center + diam * ampli * sinf(angle);
960}
961
963 float centerx,
964 float centery,
965 float diam,
966 const float colf[3],
967 char label,
968 const float3x3 &yuv_matrix)
969{
970 float tangle = 0.0f, tampli;
971 float dangle, dampli;
972 const char labelstr[2] = {label, '\0'};
973
974 const float3 yuv = yuv_matrix * float3(colf[0], colf[1], colf[2]);
975 const float u = yuv.y;
976 const float v = yuv.z;
977
978 if (u > 0 && v >= 0) {
979 tangle = atanf(v / u);
980 }
981 else if (u > 0 && v < 0) {
982 tangle = atanf(v / u) + 2.0f * float(M_PI);
983 }
984 else if (u < 0) {
985 tangle = atanf(v / u) + float(M_PI);
986 }
987 else if (u == 0 && v > 0.0f) {
988 tangle = M_PI_2;
989 }
990 else if (u == 0 && v < 0.0f) {
991 tangle = -M_PI_2;
992 }
993 tampli = sqrtf(u * u + v * v);
994
995 /* small target vary by 2.5 degree and 2.5 IRE unit */
996 immUniformColor4f(1.0f, 1.0f, 1.0f, 0.12f);
997 dangle = DEG2RADF(2.5f);
998 dampli = 2.5f / 200.0f;
1000 immVertex2f(pos,
1001 polar_to_x(centerx, diam, tampli + dampli, tangle + dangle),
1002 polar_to_y(centery, diam, tampli + dampli, tangle + dangle));
1003 immVertex2f(pos,
1004 polar_to_x(centerx, diam, tampli - dampli, tangle + dangle),
1005 polar_to_y(centery, diam, tampli - dampli, tangle + dangle));
1006 immVertex2f(pos,
1007 polar_to_x(centerx, diam, tampli - dampli, tangle - dangle),
1008 polar_to_y(centery, diam, tampli - dampli, tangle - dangle));
1009 immVertex2f(pos,
1010 polar_to_x(centerx, diam, tampli + dampli, tangle - dangle),
1011 polar_to_y(centery, diam, tampli + dampli, tangle - dangle));
1012
1013 /* draw color letter as text */
1014 BLF_color4f(BLF_default(), 1.0f, 1.0f, 1.0f, 0.3f);
1015 BLF_draw_default(polar_to_x(centerx, diam, tampli, tangle) + 5,
1016 polar_to_y(centery, diam, tampli, tangle),
1017 0,
1018 labelstr,
1019 strlen(labelstr));
1020
1021 immEnd();
1022}
1023
1025 ARegion *region,
1026 Button *but,
1027 const uiWidgetColors * /*wcol*/,
1028 const rcti *recti)
1029{
1030 const float skin_rad = DEG2RADF(123.0f); /* angle in radians of the skin tone line */
1031 const Scopes *scopes = reinterpret_cast<const Scopes *>(but->poin);
1032
1033 const Scene *scene = CTX_data_scene(C);
1035 &scene->view_settings);
1036 const float3x3 &yuv_matrix = scope_info.yuv_matrix;
1037 const float3x3 inv_yuv_to_rec709 = scope_info.scope_gamut_to_rec709 * math::invert(yuv_matrix);
1038
1039 const float colors[6][3] = {
1040 {0.75, 0.0, 0.0}, /* Red */
1041 {0.75, 0.75, 0.0}, /* Yellow */
1042 {0.0, 0.75, 0.0}, /* Green */
1043 {0.0, 0.75, 0.75}, /* Cyan */
1044 {0.0, 0.0, 0.75}, /* Blue */
1045 {0.75, 0.0, 0.75}, /* Magenta */
1046 };
1047
1048 const char color_names[] = {'R', 'Y', 'G', 'C', 'B', 'M'};
1049
1050 rctf rect{};
1051 rect.xmin = float(recti->xmin + 1);
1052 rect.xmax = float(recti->xmax - 1);
1053 rect.ymin = float(recti->ymin + 1);
1054 rect.ymax = float(recti->ymax - 1);
1055
1056 const float w = BLI_rctf_size_x(&rect);
1057 const float h = BLI_rctf_size_y(&rect);
1058 const float centerx = rect.xmin + w * 0.5f;
1059 const float centery = rect.ymin + h * 0.5f;
1060 const float diam = ((w < h) ? w : h) * 0.9f;
1061
1062 const float alpha = scopes->vecscope_alpha;
1063
1064 GPU_line_smooth(true);
1066
1067 const float color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
1069 rctf back_rect{};
1070 back_rect.xmin = rect.xmin - 1;
1071 back_rect.xmax = rect.xmax + 1;
1072 back_rect.ymin = rect.ymin - 1;
1073 back_rect.ymax = rect.ymax + 1;
1074 draw_roundbox_4fv(&back_rect, true, 3.0f, color);
1075
1076 /* need scissor test, vectorscope can draw outside of boundary */
1077 int scissor[4];
1078 GPU_scissor_get(scissor);
1079 rcti scissor_new{};
1080 scissor_new.xmin = rect.xmin;
1081 scissor_new.ymin = rect.ymin;
1082 scissor_new.xmax = rect.xmax;
1083 scissor_new.ymax = rect.ymax;
1084 const rcti scissor_region = {0, region->winx, 0, region->winy};
1085 BLI_rcti_isect(&scissor_new, &scissor_region, &scissor_new);
1086 GPU_scissor(scissor_new.xmin,
1087 scissor_new.ymin,
1088 BLI_rcti_size_x(&scissor_new),
1089 BLI_rcti_size_y(&scissor_new));
1090
1091 GPUVertFormat *format = immVertexFormat();
1092 GPU_scissor_test(true);
1093 const uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
1094
1096 const int increment = 6;
1097 const int tot_points = int(360 / increment);
1098 const float r = 0.5f;
1099 float step = 360.0f / (tot_points - 1);
1100
1101 float circle_fill_points[(tot_points * 2) + 2];
1102 float circle_fill_vertex_colors[(tot_points * 4) + 4];
1103
1104 /* draw filled RGB circle for background, only for LUMA mode */
1105 if (scopes->vecscope_mode == SCOPES_VECSCOPE_LUMA) {
1106 /* Initialize center point and color */
1107 circle_fill_points[0] = centerx;
1108 circle_fill_points[1] = centery;
1109 circle_fill_vertex_colors[0] = 0.2f;
1110 circle_fill_vertex_colors[1] = 0.2f;
1111 circle_fill_vertex_colors[2] = 0.2f;
1112 circle_fill_vertex_colors[3] = 0.8f;
1113
1114 for (int i = 0; i < tot_points; i++) {
1115 float angle = step * i;
1116 const float a = DEG2RADF(angle);
1117
1118 const float x = polar_to_x(centerx, diam, r, a);
1119 const float y = polar_to_y(centery, diam, r, a);
1120
1121 circle_fill_points[(i + 1) * 2] = x;
1122 circle_fill_points[(i + 1) * 2 + 1] = y;
1123
1124 const float cb = (x - centerx) / diam;
1125 const float cr = (y - centery) / diam;
1126 const float3 rgb = inv_yuv_to_rec709 * float3(0.5f, cb, cr);
1127
1128 circle_fill_vertex_colors[(i + 1) * 4] = rgb.x * 0.2f;
1129 circle_fill_vertex_colors[(i + 1) * 4 + 1] = rgb.y * 0.2f;
1130 circle_fill_vertex_colors[(i + 1) * 4 + 2] = rgb.z * 0.2f;
1131 circle_fill_vertex_colors[(i + 1) * 4 + 3] = 0.8f;
1132 }
1133
1136 circle_fill_points, tot_points + 1, circle_fill_vertex_colors, GPU_PRIM_TRI_FAN);
1137 }
1138 /* draw filled Gray circle for background, only for RGB mode */
1139 else if (scopes->vecscope_mode == SCOPES_VECSCOPE_RGB) {
1141 immBegin(GPU_PRIM_TRI_FAN, tot_points + 2);
1142 immUniformColor3f(0.16f, 0.16f, 0.16f);
1143 immVertex2f(pos, centerx, centery);
1144
1145 for (int i = 0; i <= 360; i += increment) {
1146 const float a = DEG2RADF(float(i));
1147 immVertex2f(pos, polar_to_x(centerx, diam, r, a), polar_to_y(centery, diam, r, a));
1148 }
1149 immEnd();
1150 }
1151
1152 /* draw RGB ring */
1153 float circle_points[(tot_points * 2) + 3] = {};
1154 float circle_vertex_colors[(tot_points * 4) + 5] = {};
1155
1156 for (int i = 0; i < tot_points; i++) {
1157 float angle = step * i;
1158 const float a = DEG2RADF(angle);
1159
1160 const float x = polar_to_x(centerx, diam, 0.5f, a);
1161 const float y = polar_to_y(centery, diam, 0.5f, a);
1162 circle_points[i * 2] = x;
1163 circle_points[i * 2 + 1] = y;
1164
1165 const float cb = (x - centerx) / diam;
1166 const float cr = (y - centery) / diam;
1167 const float3 ring_rgb = inv_yuv_to_rec709 * float3(0.5f, cb, cr);
1168
1169 circle_vertex_colors[i * 4] = ring_rgb.x;
1170 circle_vertex_colors[i * 4 + 1] = ring_rgb.y;
1171 circle_vertex_colors[i * 4 + 2] = ring_rgb.z;
1172 circle_vertex_colors[i * 4 + 3] = 0.8f;
1173 }
1174
1176 GPU_line_width(2.5f);
1177 circle_draw_rgb(circle_points, tot_points, circle_vertex_colors, GPU_PRIM_LINE_LOOP);
1178 GPU_line_width(1.5f);
1179
1180 /* inner circles */
1182 for (int j = 0; j < 4; j++) {
1183 float inner_circle_points[(tot_points * 2) + 3] = {};
1184 float inner_circle_colors[(tot_points * 4) + 5] = {};
1185 const float r = (j + 1) * 0.1f;
1186
1187 for (int i = 0; i < tot_points; i++) {
1188 float angle = step * i;
1189 const float a = DEG2RADF(angle);
1190
1191 inner_circle_points[i * 2] = polar_to_x(centerx, diam, r, a);
1192 inner_circle_points[i * 2 + 1] = polar_to_y(centery, diam, r, a);
1193
1194 inner_circle_colors[i * 4] = 0.1f;
1195 inner_circle_colors[i * 4 + 1] = 0.1f;
1196 inner_circle_colors[i * 4 + 2] = 0.1f;
1197 inner_circle_colors[i * 4 + 3] = 0.8f;
1198 }
1199 circle_draw_rgb(inner_circle_points, tot_points, inner_circle_colors, GPU_PRIM_LINE_LOOP);
1200 }
1201
1202 /* draw grid elements */
1203 /* cross */
1204 immUniformColor4f(1.0f, 1.0f, 1.0f, 0.1f);
1206
1207 immVertex2f(pos, centerx - (diam * 0.5f) - 5, centery);
1208 immVertex2f(pos, centerx + (diam * 0.5f) + 5, centery);
1209
1210 immVertex2f(pos, centerx, centery - (diam * 0.5f) - 5);
1211 immVertex2f(pos, centerx, centery + (diam * 0.5f) + 5);
1212
1213 immEnd();
1214
1215 /* skin tone line */
1217 immUniformColor3f(0.25f, 0.25f, 0.25f);
1218
1221 pos, polar_to_x(centerx, diam, 0.5f, skin_rad), polar_to_y(centery, diam, 0.5f, skin_rad));
1223 pos, polar_to_x(centerx, diam, 0.1f, skin_rad), polar_to_y(centery, diam, 0.1f, skin_rad));
1224 immEnd();
1225
1226 /* saturation points */
1227 for (int i = 0; i < 6; i++) {
1228 vectorscope_draw_target(pos, centerx, centery, diam, colors[i], color_names[i], yuv_matrix);
1229 }
1230
1231 if (scopes->ok && scopes->vecscope != nullptr) {
1232 /* pixel point cloud */
1233 GPU_point_size(1.0);
1234
1236 GPU_matrix_translate_2f(centerx, centery);
1237 GPU_matrix_scale_1f(diam);
1238
1239 const float col[3] = {alpha, alpha, alpha};
1240 if (scopes->vecscope_mode == SCOPES_VECSCOPE_RGB) {
1242 waveform_draw_rgb(scopes->vecscope, scopes->waveform_tot, scopes->vecscope_rgb, alpha);
1243 }
1244 else if (scopes->vecscope_mode == SCOPES_VECSCOPE_LUMA) {
1247 waveform_draw_one(scopes->vecscope, scopes->waveform_tot, col);
1249 }
1250
1252 }
1253
1255
1256 /* Restore scissor test. */
1257 GPU_scissor_test(false);
1258 GPU_scissor(UNPACK4(scissor));
1259 /* outline */
1260 draw_scope_end(&rect);
1261
1263}
1264
1265static void draw_colorband_handle_tri(uint pos, float x1, float y1, float halfwidth)
1266{
1267 /* Half-width equals height for better AA with 45 degree slope. */
1269 immVertex2f(pos, x1 + halfwidth, y1);
1270 immVertex2f(pos, x1, y1 + halfwidth);
1271 immVertex2f(pos, x1 - halfwidth, y1);
1272 immEnd();
1273}
1274
1275static void draw_colorband_handle_box(uint pos, float x1, float y1, float x2, float y2)
1276{
1278 immVertex2f(pos, x2, y1);
1279 immVertex2f(pos, x1, y1);
1280 immVertex2f(pos, x2, y2);
1281 immVertex2f(pos, x1, y2);
1282 immEnd();
1283}
1284
1285static void draw_colorband_handle(uint shdr_pos,
1286 const rcti *rect,
1287 float x,
1288 const float rgb[3],
1289 const ColorManagedDisplay *display,
1290 bool active)
1291{
1292 const float sizey = BLI_rcti_size_y(rect);
1293 float colf[3] = {UNPACK3(rgb)};
1294
1295 const float half_width = sizey / 3.5f;
1296 const float height = half_width * 1.4f;
1297
1298 float y1 = rect->ymin;
1299 const float y2 = rect->ymax;
1300
1301 /* align to pixels */
1302 x = floorf(x);
1303
1305
1306 /* Allow the lines to decrease as we get really small. */
1307 float line_width = std::max(std::min(U.pixelsize / 5.0f * fabs(half_width - 4.0f), U.pixelsize),
1308 0.5f);
1309
1310 /* Make things transparent as we get tiny. */
1311 uchar alpha = std::min(int(fabs(half_width - 2.0f) * 50.0f), 255);
1312
1314
1315 float viewport_size[4];
1316 GPU_viewport_size_get_f(viewport_size);
1317 immUniform2f("viewport_size", viewport_size[2] / UI_SCALE_FAC, viewport_size[3] / UI_SCALE_FAC);
1318 immUniform1i("colors_len", 2); /* "advanced" mode */
1319 if (active) {
1320 immUniform4f("color", 1.0f, 1.0f, 1.0f, alpha / 255.0f);
1321 immUniform4f("color2", 0.0f, 0.0f, 0.0f, alpha / 255.0f);
1322 }
1323 else {
1324 immUniform4f("color", 0.7f, 0.7f, 0.7f, alpha / 255.0f);
1325 immUniform4f("color2", 0.4f, 0.4f, 0.4f, alpha / 255.0f);
1326 }
1327 immUniform1f("dash_width", sizey / 6.0f / UI_SCALE_FAC);
1328 immUniform1f("udash_factor", 0.5f);
1329
1331 immVertex2f(shdr_pos, x, y1);
1332 immVertex2f(shdr_pos, x, y2);
1333 immEnd();
1334
1336
1338
1339 /* shift handle down */
1340 y1 -= half_width / 2.0f;
1341
1342 /* Black outline around the lower box. */
1343 immUniformColor4ub(0, 0, 0, alpha);
1344
1346 x - half_width - line_width,
1347 y1 - line_width,
1348 x + half_width + line_width,
1349 y1 + height);
1350
1351 /* Grey box, inset by line width. */
1352 immUniformColor4ub(128, 128, 128, alpha);
1353 draw_colorband_handle_box(shdr_pos, x - half_width, y1, x + half_width, y1 + height);
1354
1355 if (display) {
1357 }
1358
1359 /* Color value, inset by another line width. */
1360 immUniformColor3fvAlpha(colf, alpha);
1362 x - (half_width - line_width),
1363 y1 + line_width,
1364 x + (half_width - line_width),
1365 y1 + height - line_width);
1366
1367 /* Black outline around the top triangle. */
1368 immUniformColor4ub(0, 0, 0, alpha);
1369 draw_colorband_handle_tri(shdr_pos, x, y1 + height, half_width + line_width);
1370
1371 GPU_polygon_smooth(true);
1372
1373 /* Triangle main color. */
1374 if (active) {
1375 immUniformColor4ub(220, 220, 220, alpha);
1376 }
1377 else {
1378 immUniformColor4ub(96, 96, 96, alpha);
1379 }
1380 draw_colorband_handle_tri(shdr_pos, x, y1 + height, half_width - (0.5f * line_width));
1381
1383
1384 GPU_polygon_smooth(false);
1386}
1387
1388void draw_but_COLORBAND(Button *but, const uiWidgetColors *wcol, const rcti *rect)
1389{
1390 const ColorManagedDisplay *display = block_cm_display_get(but->block);
1391 uint pos_id, col_id;
1392
1393 ButtonColorBand *but_coba = static_cast<ButtonColorBand *>(but);
1394 ColorBand *coba = (but_coba->edit_coba == nullptr) ? reinterpret_cast<ColorBand *>(but->poin) :
1395 but_coba->edit_coba;
1396
1397 if (coba == nullptr) {
1398 return;
1399 }
1400
1401 const float x1 = rect->xmin + U.pixelsize;
1402 const float sizex = rect->xmax - x1 - U.pixelsize;
1403 const float y1 = rect->ymin + U.pixelsize;
1404 const float sizey = rect->ymax - y1 - U.pixelsize;
1405 const float sizey_solid = sizey * 0.25f;
1406
1407 /* exit early if too narrow */
1408 if (sizex <= 0) {
1409 return;
1410 }
1411
1413
1414 /* Line width outline. */
1415 GPUVertFormat *format = immVertexFormat();
1416 pos_id = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
1420 immVertex2f(pos_id, rect->xmin, rect->ymin);
1421 immVertex2f(pos_id, rect->xmax, rect->ymin);
1422 immVertex2f(pos_id, rect->xmin, rect->ymax);
1423 immVertex2f(pos_id, rect->xmax, rect->ymax);
1424 immEnd();
1426
1427 /* Drawing the checkerboard. */
1429 const float checker_dark = UI_ALPHA_CHECKER_DARK / 255.0f;
1430 const float checker_light = UI_ALPHA_CHECKER_LIGHT / 255.0f;
1431 immUniform4f("color1", checker_dark, checker_dark, checker_dark, 1.0f);
1432 immUniform4f("color2", checker_light, checker_light, checker_light, 1.0f);
1433 immUniform1i("size", 8);
1434 immRectf(pos_id, x1, y1, x1 + sizex, y1 + sizey);
1436
1437 /* New format */
1438 format = immVertexFormat();
1439 pos_id = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
1440 col_id = GPU_vertformat_attr_add(format, "color", gpu::VertAttrType::SFLOAT_32_32_32_32);
1442
1443 CBData *cbd = coba->data;
1444
1445 float v1[2], v2[2];
1446 float colf[4] = {0, 0, 0, 0}; /* initialize in case the colorband isn't valid */
1447
1448 v1[1] = y1 + sizey_solid;
1449 v2[1] = y1 + sizey;
1450
1451 immBegin(GPU_PRIM_TRI_STRIP, (sizex + 1) * 2);
1452 for (int a = 0; a <= sizex; a++) {
1453 const float pos = float(a) / sizex;
1454 BKE_colorband_evaluate(coba, pos, colf);
1455 if (display) {
1457 }
1458
1459 v1[0] = v2[0] = x1 + a;
1460
1461 immAttr4fv(col_id, colf);
1462 immVertex2fv(pos_id, v1);
1463 immVertex2fv(pos_id, v2);
1464 }
1465 immEnd();
1466
1467 /* layer: color ramp without alpha for reference when manipulating ramp properties */
1468 v1[1] = y1;
1469 v2[1] = y1 + sizey_solid;
1470
1471 immBegin(GPU_PRIM_TRI_STRIP, (sizex + 1) * 2);
1472 for (int a = 0; a <= sizex; a++) {
1473 const float pos = float(a) / sizex;
1474 BKE_colorband_evaluate(coba, pos, colf);
1475 if (display) {
1477 }
1478
1479 v1[0] = v2[0] = x1 + a;
1480
1481 immAttr4f(col_id, colf[0], colf[1], colf[2], 1.0f);
1482 immVertex2fv(pos_id, v1);
1483 immVertex2fv(pos_id, v2);
1484 }
1485 immEnd();
1486
1488
1489 /* New format */
1490 format = immVertexFormat();
1491 pos_id = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
1492
1493 /* layer: draw handles */
1494 for (int a = 0; a < coba->tot; a++, cbd++) {
1495 if (a != coba->cur) {
1496 const float pos = x1 + cbd->pos * (sizex - 1) + 1;
1497 draw_colorband_handle(pos_id, rect, pos, &cbd->r, display, false);
1498 }
1499 }
1500
1501 /* layer: active handle */
1502 if (coba->tot != 0) {
1503 cbd = &coba->data[coba->cur];
1504 const float pos = x1 + cbd->pos * (sizex - 1) + 1;
1505 draw_colorband_handle(pos_id, rect, pos, &cbd->r, display, true);
1506 }
1507}
1508
1510 const uiWidgetColors *wcol,
1511 const rcti *rect,
1512 const float radius)
1513{
1514 /* sphere color */
1515 const float diffuse[3] = {1.0f, 1.0f, 1.0f};
1516 float light[3];
1517 const float size = 0.5f * min_ff(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect));
1518
1519 /* backdrop */
1521 rctf box_rect{};
1522 box_rect.xmin = rect->xmin;
1523 box_rect.xmax = rect->xmax;
1524 box_rect.ymin = rect->ymin;
1525 box_rect.ymax = rect->ymax;
1526 draw_roundbox_3ub_alpha(&box_rect, true, radius, wcol->inner, 255);
1527
1529
1530 /* setup lights */
1531 button_v3_get(but, light);
1532
1533 /* transform to button */
1535
1536 const bool use_project_matrix = (size >= -GPU_MATRIX_ORTHO_CLIP_NEAR_DEFAULT);
1537 if (use_project_matrix) {
1539 GPU_matrix_ortho_set_z(-size, size);
1540 }
1541
1542 GPU_matrix_translate_2f(rect->xmin + 0.5f * BLI_rcti_size_x(rect),
1543 rect->ymin + 0.5f * BLI_rcti_size_y(rect));
1544 GPU_matrix_scale_1f(size);
1545
1546 gpu::Batch *sphere = GPU_batch_preset_sphere(2);
1547 SimpleLightingData simple_lighting_data;
1548 copy_v4_fl4(simple_lighting_data.l_color, diffuse[0], diffuse[1], diffuse[2], 1.0f);
1549 copy_v3_v3(simple_lighting_data.light, light);
1551 sizeof(SimpleLightingData), &simple_lighting_data, __func__);
1552
1554 GPU_batch_uniformbuf_bind(sphere, "simple_lighting_data", ubo);
1555 GPU_batch_draw(sphere);
1557
1558 /* Restore. */
1560
1561 /* AA circle */
1562 GPUVertFormat *format = immVertexFormat();
1563 const uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
1566
1568 GPU_line_smooth(true);
1569 imm_draw_circle_wire_2d(pos, 0.0f, 0.0f, 1.0f, 32);
1571 GPU_line_smooth(false);
1572
1573 if (use_project_matrix) {
1575 }
1576
1577 /* matrix after circle */
1579
1581}
1582
1583static void draw_but_curve_grid(const uint pos,
1584 const rcti *rect,
1585 const float zoom_x,
1586 const float zoom_y,
1587 const float offset_x,
1588 const float offset_y,
1589 const float step)
1590{
1591 const float start_x = (ceilf(offset_x / step) * step - offset_x) * zoom_x + rect->xmin;
1592 const float start_y = (ceilf(offset_y / step) * step - offset_y) * zoom_y + rect->ymin;
1593
1594 const int line_count_x = ceilf((rect->xmax - start_x) / (step * zoom_x));
1595 const int line_count_y = ceilf((rect->ymax - start_y) / (step * zoom_y));
1596
1597 if (line_count_x + line_count_y == 0) {
1598 return;
1599 }
1600
1601 immBegin(GPU_PRIM_LINES, (line_count_x + line_count_y) * 2);
1602 for (int i = 0; i < line_count_x; i++) {
1603 const float x = start_x + i * step * zoom_x;
1604 immVertex2f(pos, x, rect->ymin);
1605 immVertex2f(pos, x, rect->ymax);
1606 }
1607 for (int i = 0; i < line_count_y; i++) {
1608 const float y = start_y + i * step * zoom_y;
1609 immVertex2f(pos, rect->xmin, y);
1610 immVertex2f(pos, rect->xmax, y);
1611 }
1612 immEnd();
1613}
1614
1615void draw_but_CURVE(ARegion *region, Button *but, const uiWidgetColors *wcol, const rcti *rect)
1616{
1617 ButtonCurveMapping *but_cumap = static_cast<ButtonCurveMapping *>(but);
1618 CurveMapping *cumap = (but_cumap->edit_cumap == nullptr) ?
1619 reinterpret_cast<CurveMapping *>(but->poin) :
1620 but_cumap->edit_cumap;
1621
1622 const bool inactive = but->flag & BUT_INACTIVE;
1623 const float fade_factor_float = inactive ? 0.33f : 1.0f;
1624 const uchar fade_factor_uchar = inactive ? 3 : 1;
1625
1626 const float clip_size_x = BLI_rctf_size_x(&cumap->curr);
1627 const float clip_size_y = BLI_rctf_size_y(&cumap->curr);
1628
1629 /* zero-sized curve */
1630 if (clip_size_x == 0.0f || clip_size_y == 0.0f) {
1631 return;
1632 }
1633
1634 /* calculate offset and zoom */
1635 const float zoomx = (BLI_rcti_size_x(rect) - 1.0f) / clip_size_x;
1636 const float zoomy = (BLI_rcti_size_y(rect) - 1.0f) / clip_size_y;
1637 const float offsx = cumap->curr.xmin - (1.0f / zoomx);
1638 const float offsy = cumap->curr.ymin - (1.0f / zoomy);
1639
1640 /* exit early if too narrow */
1641 if (zoomx <= 0.0f) {
1642 return;
1643 }
1644
1645 /* Outline. */
1646 GPUVertFormat *format = immVertexFormat();
1647 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
1649
1650 GPU_line_width(1.8f);
1652 imm_draw_box_wire_2d(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
1653 GPU_line_width(1.0f);
1655
1656 CurveMap *cuma = &cumap->cm[cumap->cur];
1657
1658 /* need scissor test, curve can draw outside of boundary */
1659 int scissor[4];
1660 GPU_scissor_get(scissor);
1661 rcti scissor_new{};
1662 scissor_new.xmin = rect->xmin;
1663 scissor_new.ymin = rect->ymin;
1664 scissor_new.xmax = rect->xmax;
1665 scissor_new.ymax = rect->ymax;
1666 const rcti scissor_region = {0, region->winx, 0, region->winy};
1667 BLI_rcti_isect(&scissor_new, &scissor_region, &scissor_new);
1668 GPU_scissor(scissor_new.xmin,
1669 scissor_new.ymin,
1670 BLI_rcti_size_x(&scissor_new),
1671 BLI_rcti_size_y(&scissor_new));
1672 GPU_scissor_test(true);
1673
1674 /* Do this first to not mess imm context */
1675 if (but_cumap->gradient_type == GRAD_H) {
1676 /* magic trigger for curve backgrounds */
1677 const float col[3] = {0.0f, 0.0f, 0.0f}; /* dummy arg */
1678
1679 rcti grid{};
1680 grid.xmin = rect->xmin + zoomx * (-offsx);
1681 grid.xmax = grid.xmin + zoomx;
1682 grid.ymin = rect->ymin + zoomy * (-offsy);
1683 grid.ymax = grid.ymin + zoomy;
1684
1685 const ColorManagedDisplay *display = block_cm_display_get(but->block);
1686 draw_gradient(&grid, col, GRAD_H, 1.0f, display);
1687 }
1688
1689 GPU_line_width(1.0f);
1690
1691 format = immVertexFormat();
1692 pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
1694
1695 /* backdrop */
1696 float color_backdrop[4] = {0, 0, 0, 1};
1697
1699 if (but_cumap->gradient_type == GRAD_H) {
1700 /* grid, hsv uses different grid */
1701 ARRAY_SET_ITEMS(color_backdrop, 0, 0, 0, 48.0 / 255.0);
1702 immUniformColor4fv(color_backdrop);
1703 draw_but_curve_grid(pos, rect, zoomx, zoomy, offsx, offsy, 0.1666666f);
1704 }
1705 else {
1706 /* Draw backdrop. */
1707 immUniformColor3ubvAlpha(wcol->inner, (wcol->inner[3] / fade_factor_uchar));
1708 immRectf(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
1709
1710 /* Draw an outline around the clipped limits. */
1711 if (cumap->flag & CUMA_DO_CLIP) {
1712 format = immVertexFormat();
1713 pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
1714
1715 immUniformColor3ubvAlpha(wcol->item, (wcol->item[3] / fade_factor_uchar));
1716 GPU_line_width(2.0f);
1718 rect->xmin + zoomx * (cumap->clipr.xmin - offsx),
1719 rect->ymin + zoomy * (cumap->clipr.ymin - offsy),
1720 rect->xmin + zoomx * (cumap->clipr.xmax - offsx),
1721 rect->ymin + zoomy * (cumap->clipr.ymax - offsy));
1722 GPU_line_width(1.0f);
1723 }
1724
1725 /* grid, every 0.25 step */
1726 immUniformColor3ubvAlpha(wcol->outline_sel, 64 / fade_factor_uchar);
1727 draw_but_curve_grid(pos, rect, zoomx, zoomy, offsx, offsy, 0.25f);
1728 /* grid, every 1.0 step */
1729 immUniformColor3ubvAlpha(wcol->outline_sel, 92 / fade_factor_uchar);
1730 draw_but_curve_grid(pos, rect, zoomx, zoomy, offsx, offsy, 1.0f);
1731 /* axes */
1732 uchar col_axis_x[3], col_axis_y[3];
1733 theme::get_color_3ubv(TH_AXIS_X, col_axis_x);
1734 theme::get_color_3ubv(TH_AXIS_Y, col_axis_y);
1735
1737 immUniformColor3ubvAlpha(col_axis_x, 128 / fade_factor_uchar);
1738 immVertex2f(pos, rect->xmin, rect->ymin + zoomy * (-offsy));
1739 immVertex2f(pos, rect->xmax, rect->ymin + zoomy * (-offsy));
1740 immEnd();
1741
1743 immUniformColor3ubvAlpha(col_axis_y, 128 / fade_factor_uchar);
1744 immVertex2f(pos, rect->xmin + zoomx * (-offsx), rect->ymin);
1745 immVertex2f(pos, rect->xmin + zoomx * (-offsx), rect->ymax);
1746 immEnd();
1747 }
1749
1750 /* cfra option */
1751 /* XXX 2.48 */
1752#if 0
1753 if (cumap->flag & CUMA_DRAW_CFRA) {
1754 immUniformColor3ub(0x60, 0xc0, 0x40);
1756 immVertex2f(pos, rect->xmin + zoomx * (cumap->sample[0] - offsx), rect->ymin);
1757 immVertex2f(pos, rect->xmin + zoomx * (cumap->sample[0] - offsx), rect->ymax);
1758 immEnd();
1759 }
1760#endif
1761 /* sample option */
1762
1763 if (cumap->flag & CUMA_DRAW_SAMPLE) {
1764 immBegin(GPU_PRIM_LINES, 2); /* will draw one of the following 3 lines */
1765 if (but_cumap->gradient_type == GRAD_H) {
1766 float tsample[3];
1767 float hsv[3];
1768 linearrgb_to_srgb_v3_v3(tsample, cumap->sample);
1769 rgb_to_hsv_v(tsample, hsv);
1770 immUniformColor3ub(240, 240, 240);
1771
1772 immVertex2f(pos, rect->xmin + zoomx * (hsv[0] - offsx), rect->ymin);
1773 immVertex2f(pos, rect->xmin + zoomx * (hsv[0] - offsx), rect->ymax);
1774 }
1775 else if (cumap->cur == 3) {
1776 const float lum = IMB_colormanagement_get_luminance(cumap->sample);
1777 immUniformColor3ub(240, 240, 240);
1778
1779 immVertex2f(pos, rect->xmin + zoomx * (lum - offsx), rect->ymin);
1780 immVertex2f(pos, rect->xmin + zoomx * (lum - offsx), rect->ymax);
1781 }
1782 else {
1783 if (cumap->cur == 0) {
1784 immUniformColor3ub(240, 100, 100);
1785 }
1786 else if (cumap->cur == 1) {
1787 immUniformColor3ub(100, 240, 100);
1788 }
1789 else {
1790 immUniformColor3ub(100, 100, 240);
1791 }
1792
1793 immVertex2f(pos, rect->xmin + zoomx * (cumap->sample[cumap->cur] - offsx), rect->ymin);
1794 immVertex2f(pos, rect->xmin + zoomx * (cumap->sample[cumap->cur] - offsx), rect->ymax);
1795 }
1796 immEnd();
1797 }
1799
1800 if (cuma->table == nullptr) {
1801 BKE_curvemapping_changed(cumap, false);
1802 }
1803
1804 CurveMapPoint *cmp = cuma->table;
1805 rctf line_range;
1806
1807 /* First curve point. */
1808 if ((cumap->flag & CUMA_EXTEND_EXTRAPOLATE) == 0) {
1809 line_range.xmin = rect->xmin;
1810 line_range.ymin = rect->ymin + zoomy * (cmp[0].y - offsy);
1811 }
1812 else {
1813 line_range.xmin = rect->xmin + zoomx * (cmp[0].x - offsx + cuma->ext_in[0]);
1814 line_range.ymin = rect->ymin + zoomy * (cmp[0].y - offsy + cuma->ext_in[1]);
1815 }
1816 /* Last curve point. */
1817 if ((cumap->flag & CUMA_EXTEND_EXTRAPOLATE) == 0) {
1818 line_range.xmax = rect->xmax;
1819 line_range.ymax = rect->ymin + zoomy * (cmp[CM_TABLE].y - offsy);
1820 }
1821 else {
1822 line_range.xmax = rect->xmin + zoomx * (cmp[CM_TABLE].x - offsx - cuma->ext_out[0]);
1823 line_range.ymax = rect->ymin + zoomy * (cmp[CM_TABLE].y - offsy - cuma->ext_out[1]);
1824 }
1825
1828
1829 /* Curve filled. */
1830 immUniformColor3ubvAlpha(wcol->item, wcol->item[3] / fade_factor_uchar);
1831 immBegin(GPU_PRIM_TRI_STRIP, (CM_TABLE * 2 + 2) + 4);
1832 immVertex2f(pos, line_range.xmin, rect->ymin);
1833 immVertex2f(pos, line_range.xmin, line_range.ymin);
1834 for (int a = 0; a <= CM_TABLE; a++) {
1835 const float fx = rect->xmin + zoomx * (cmp[a].x - offsx);
1836 const float fy = rect->ymin + zoomy * (cmp[a].y - offsy);
1837 immVertex2f(pos, fx, rect->ymin);
1838 immVertex2f(pos, fx, fy);
1839 }
1840 immVertex2f(pos, line_range.xmax, rect->ymin);
1841 immVertex2f(pos, line_range.xmax, line_range.ymax);
1842 immEnd();
1843
1844 /* Curve line. */
1845 GPU_line_width(1.0f);
1846 immUniformColor3ubvAlpha(wcol->inner_sel, wcol->inner_sel[3] / fade_factor_uchar);
1847 GPU_line_smooth(true);
1849 immVertex2f(pos, line_range.xmin, line_range.ymin);
1850 for (int a = 0; a <= CM_TABLE; a++) {
1851 const float fx = rect->xmin + zoomx * (cmp[a].x - offsx);
1852 const float fy = rect->ymin + zoomy * (cmp[a].y - offsy);
1853 immVertex2f(pos, fx, fy);
1854 }
1855 immVertex2f(pos, line_range.xmax, line_range.ymax);
1856 immEnd();
1857
1858 /* Reset state for fill & line. */
1859 GPU_line_smooth(false);
1862
1863 /* The points, use aspect to make them visible on edges. */
1864 format = immVertexFormat();
1865 pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
1867
1869
1870 float color_point[4], color_point_select[4], color_point_active[4], color_point_outline[4];
1871 rgba_uchar_to_float(color_point, wcol->text);
1872 rgba_uchar_to_float(color_point_select, wcol->text_sel);
1873 rgba_uchar_to_float(color_point_active, wcol->text_sel);
1874 rgba_uchar_to_float(color_point_outline, wcol->inner_sel);
1875 color_point[3] = fade_factor_float;
1876 color_point_select[3] = fade_factor_float;
1877 color_point_active[3] = fade_factor_float;
1878 color_point_outline[3] *= fade_factor_float;
1879
1880 cmp = cuma->curve;
1881 const float point_size = max_ff(U.pixelsize * 2.0f,
1882 min_ff(UI_SCALE_FAC / but->block->aspect * 6.0f, 20.0f));
1883
1884 int selected = 0;
1885 int active = -1;
1886 /* Find the total number of selected points. */
1887 for (int i = 0; i < cuma->totpoint; i++) {
1888 if (cmp[i].flag & CUMA_SELECT) {
1889 selected++;
1890 }
1891 if (cmp[i].flag & CUMA_ACTIVE) {
1892 active = i;
1893 }
1894 }
1895
1896 /* Draw curve points over outline. Don't change scissor if view is zoomed and not near edges.
1897 * Draw clipped points in that case. */
1898 rcti scissor_for_points;
1899 scissor_for_points.xmin = std::max(
1900 0, scissor_new.xmin - int(point_size * ((cumap->clipr.xmin == cumap->curr.xmin) ? 1 : 0)));
1901 scissor_for_points.ymin = std::max(
1902 0, scissor_new.ymin - int(point_size * ((cumap->clipr.ymin == cumap->curr.ymin) ? 1 : 0)));
1903 scissor_for_points.xmax = std::max(
1904 0, scissor_new.xmax + int(point_size * ((cumap->clipr.xmax == cumap->curr.xmax) ? 1 : 0)));
1905 scissor_for_points.ymax = std::max(
1906 0, scissor_new.ymax + int(point_size * ((cumap->clipr.ymax == cumap->curr.ymax) ? 1 : 0)));
1907
1908 GPU_scissor(scissor_for_points.xmin,
1909 scissor_for_points.ymin,
1910 BLI_rcti_size_x(&scissor_for_points),
1911 BLI_rcti_size_y(&scissor_for_points));
1912
1913 /* Curve widgets using a gradient background (such as Hue Correct), draw
1914 * an additional point in the back, forming an outline so they stand out. */
1915 if (but_cumap->gradient_type == GRAD_H) {
1916 if ((cuma->totpoint - selected) > 0) {
1917 /* Background (outline) for unselected points. */
1918 immUniform4fv("color", color_point_outline);
1919 immUniform1f("size", point_size * 1.4f);
1920 immBegin(GPU_PRIM_POINTS, cuma->totpoint - selected);
1921 for (int a = 0; a < cuma->totpoint; a++) {
1922 if (cmp[a].flag & CUMA_SELECT) {
1923 continue;
1924 }
1925 const float fx = rect->xmin + zoomx * (cmp[a].x - offsx);
1926 const float fy = rect->ymin + zoomy * (cmp[a].y - offsy);
1927 immVertex2f(pos, fx, fy);
1928 }
1929 immEnd();
1930 }
1931 if (selected > 0) {
1932 /* Background (outline) for selected points. */
1933 immUniform1f("size", point_size * 1.8f);
1934 immBegin(GPU_PRIM_POINTS, selected);
1935 for (int a = 0; a < cuma->totpoint; a++) {
1936 if (!(cmp[a].flag & CUMA_SELECT)) {
1937 continue;
1938 }
1939 const float fx = rect->xmin + zoomx * (cmp[a].x - offsx);
1940 const float fy = rect->ymin + zoomy * (cmp[a].y - offsy);
1941 immVertex2f(pos, fx, fy);
1942 }
1943 immEnd();
1944 }
1945 }
1946
1947 if ((cuma->totpoint - selected) > 0) {
1948 /* Unselected points. */
1949 immUniform1f("size", point_size);
1950 immUniform4fv("color", color_point);
1951 immBegin(GPU_PRIM_POINTS, cuma->totpoint - selected);
1952 for (int a = 0; a < cuma->totpoint; a++) {
1953 if (cmp[a].flag & CUMA_SELECT) {
1954 continue;
1955 }
1956 const float fx = rect->xmin + zoomx * (cmp[a].x - offsx);
1957 const float fy = rect->ymin + zoomy * (cmp[a].y - offsy);
1958 immVertex2f(pos, fx, fy);
1959 }
1960 immEnd();
1961 }
1962
1963 if (selected > 0) {
1964 /* Selected points. */
1965 immUniform1f("size", point_size * 1.2f);
1966 immUniform4fv("color", color_point_select);
1967 immBegin(GPU_PRIM_POINTS, selected);
1968 for (int a = 0; a < cuma->totpoint; a++) {
1969 if (!(cmp[a].flag & CUMA_SELECT)) {
1970 continue;
1971 }
1972 const float fx = rect->xmin + zoomx * (cmp[a].x - offsx);
1973 const float fy = rect->ymin + zoomy * (cmp[a].y - offsy);
1974 immVertex2f(pos, fx, fy);
1975 }
1976 immEnd();
1977 }
1978
1979 if (active != -1) {
1980 /* Active point. */
1981 immUniform1f("size", point_size * 1.4f);
1982 immUniform4fv("color", color_point_active);
1984 const float fx = rect->xmin + zoomx * (cmp[active].x - offsx);
1985 const float fy = rect->ymin + zoomy * (cmp[active].y - offsy);
1986 immVertex2f(pos, fx, fy);
1987 immEnd();
1988 }
1989
1990 GPU_scissor(scissor_new.xmin,
1991 scissor_new.ymin,
1992 BLI_rcti_size_x(&scissor_new),
1993 BLI_rcti_size_y(&scissor_new));
1994
1997
1998 /* Restore scissor-test. */
1999 GPU_scissor_test(false);
2000 GPU_scissor(scissor[0], scissor[1], scissor[2], scissor[3]);
2001}
2002
2007{
2008 return (point->flag & PROF_SELECT &&
2009 (ELEM(point->h1, HD_FREE, HD_ALIGN) || ELEM(point->h2, HD_FREE, HD_ALIGN))) ||
2010 point->flag & PROF_H1_SELECT || point->flag & PROF_H2_SELECT;
2011}
2012
2014 Button *but,
2015 const uiWidgetColors *wcol,
2016 const rcti *rect)
2017{
2018 float fx, fy;
2019
2020 ButtonCurveProfile *but_profile = static_cast<ButtonCurveProfile *>(but);
2021 CurveProfile *profile = (but_profile->edit_profile == nullptr) ?
2022 reinterpret_cast<CurveProfile *>(but->poin) :
2023 but_profile->edit_profile;
2024
2025 /* Calculate offset and zoom. */
2026 const float zoomx = (BLI_rcti_size_x(rect) - 1.0f) / BLI_rctf_size_x(&profile->view_rect);
2027 const float zoomy = (BLI_rcti_size_y(rect) - 1.0f) / BLI_rctf_size_y(&profile->view_rect);
2028 const float offsx = profile->view_rect.xmin - (1.0f / zoomx);
2029 const float offsy = profile->view_rect.ymin - (1.0f / zoomy);
2030
2031 /* Exit early if too narrow. */
2032 if (zoomx <= 0.0f) {
2033 return;
2034 }
2035
2036 /* Outline */
2037 GPUVertFormat *format = immVertexFormat();
2038 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
2040
2041 immUniformColor3ubv(static_cast<const uchar *>(wcol->outline));
2042 imm_draw_box_wire_2d(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
2044
2045 /* Test needed because path can draw outside of boundary. */
2046 int scissor[4];
2047 GPU_scissor_get(scissor);
2048 rcti scissor_new{};
2049 scissor_new.xmin = rect->xmin;
2050 scissor_new.ymin = rect->ymin;
2051 scissor_new.xmax = rect->xmax;
2052 scissor_new.ymax = rect->ymax;
2053
2054 const rcti scissor_region = {0, region->winx, 0, region->winy};
2055 BLI_rcti_isect(&scissor_new, &scissor_region, &scissor_new);
2056 GPU_scissor(scissor_new.xmin,
2057 scissor_new.ymin,
2058 BLI_rcti_size_x(&scissor_new),
2059 BLI_rcti_size_y(&scissor_new));
2060
2061 GPU_line_width(1.0f);
2062 GPU_scissor_test(true);
2063
2064 format = immVertexFormat();
2065 pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
2067
2068 /* Draw the backdrop. */
2070 /* Main backdrop. */
2072 immRectf(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
2073
2074 if (!(profile->flag & PROF_USE_CLIP)) {
2076 immRectf(pos,
2077 rect->xmin + zoomx * (profile->clip_rect.xmin - offsx),
2078 rect->ymin + zoomy * (profile->clip_rect.ymin - offsy),
2079 rect->xmin + zoomx * (profile->clip_rect.xmax - offsx),
2080 rect->ymin + zoomy * (profile->clip_rect.ymax - offsy));
2081 }
2082
2083 /* 0.25 step grid. */
2085 draw_but_curve_grid(pos, rect, zoomx, zoomy, offsx, offsy, 0.25f);
2086 /* 1.0 step grid. */
2088 draw_but_curve_grid(pos, rect, zoomx, zoomy, offsx, offsy, 1.0f);
2090
2091 /* Draw the path's fill. */
2092 if (profile->table == nullptr) {
2094 }
2095 CurveProfilePoint *pts = profile->table;
2096 /* Also add the last points on the right and bottom edges to close off the fill polygon. */
2097 const bool add_left_tri = profile->view_rect.xmin < 0.0f;
2098 const bool add_bottom_tri = profile->view_rect.ymin < 0.0f;
2099 int tot_points = BKE_curveprofile_table_size(profile) + 1 + add_left_tri + add_bottom_tri;
2100 const uint tot_triangles = tot_points - 2;
2101
2102 /* Create array of the positions of the table's points. */
2103 float (*table_coords)[2] = MEM_new_array_uninitialized<float[2]>(tot_points, __func__);
2104 for (uint i = 0; i < uint(BKE_curveprofile_table_size(profile)); i++) {
2105 /* Only add the points from the table here. */
2106 table_coords[i][0] = pts[i].x;
2107 table_coords[i][1] = pts[i].y;
2108 }
2109 /* Using some extra margin (-1.0f) for the coordinates used to complete the polygon
2110 * avoids the profile line crossing itself in some common situations, which can lead to
2111 * incorrect triangulation. See #841183. */
2112 if (add_left_tri && add_bottom_tri) {
2113 /* Add left side, bottom left corner, and bottom side points. */
2114 table_coords[tot_points - 3][0] = profile->view_rect.xmin - 1.0f;
2115 table_coords[tot_points - 3][1] = 1.0f;
2116 table_coords[tot_points - 2][0] = profile->view_rect.xmin - 1.0f;
2117 table_coords[tot_points - 2][1] = profile->view_rect.ymin - 1.0f;
2118 table_coords[tot_points - 1][0] = 1.0f;
2119 table_coords[tot_points - 1][1] = profile->view_rect.ymin - 1.0f;
2120 }
2121 else if (add_left_tri) {
2122 /* Add the left side and bottom left corner points. */
2123 table_coords[tot_points - 2][0] = profile->view_rect.xmin - 1.0f;
2124 table_coords[tot_points - 2][1] = 1.0f;
2125 table_coords[tot_points - 1][0] = profile->view_rect.xmin - 1.0f;
2126 table_coords[tot_points - 1][1] = -1.0f;
2127 }
2128 else if (add_bottom_tri) {
2129 /* Add the bottom side and bottom left corner points. */
2130 table_coords[tot_points - 2][0] = -1.0f;
2131 table_coords[tot_points - 2][1] = profile->view_rect.ymin - 1.0f;
2132 table_coords[tot_points - 1][0] = 1.0f;
2133 table_coords[tot_points - 1][1] = profile->view_rect.ymin - 1.0f;
2134 }
2135 else {
2136 /* Just add the bottom corner point. Side points would be redundant anyway. */
2137 table_coords[tot_points - 1][0] = -1.0f;
2138 table_coords[tot_points - 1][1] = -1.0f;
2139 }
2140
2141 /* Calculate the table point indices of the triangles for the profile's fill. */
2142 if (tot_triangles > 0) {
2143 uint(*tri_indices)[3] = MEM_new_array_uninitialized<uint[3]>(tot_triangles, __func__);
2144 BLI_polyfill_calc(table_coords, tot_points, -1, tri_indices);
2145
2146 /* Draw the triangles for the profile fill. */
2149 GPU_polygon_smooth(false);
2150 immBegin(GPU_PRIM_TRIS, 3 * tot_triangles);
2151 for (uint i = 0; i < tot_triangles; i++) {
2152 const uint *tri = tri_indices[i];
2153 for (uint j = 0; j < 3; j++) {
2154 fx = rect->xmin + zoomx * (table_coords[tri[j]][0] - offsx);
2155 fy = rect->ymin + zoomy * (table_coords[tri[j]][1] - offsy);
2156 immVertex2f(pos, fx, fy);
2157 }
2158 }
2159 immEnd();
2160 MEM_delete(tri_indices);
2161 }
2162
2163 /* Draw the profile's path so the edge stands out a bit. */
2164 tot_points -= (add_left_tri + add_left_tri);
2165 const int edges_len = tot_points - 1;
2166 if (edges_len > 0) {
2167 GPU_line_width(1.0f);
2169 GPU_line_smooth(true);
2170 immBegin(GPU_PRIM_LINE_STRIP, tot_points);
2171 for (int i = 0; i < tot_points; i++) {
2172 fx = rect->xmin + zoomx * (table_coords[i][0] - offsx);
2173 fy = rect->ymin + zoomy * (table_coords[i][1] - offsy);
2174 immVertex2f(pos, fx, fy);
2175 }
2176 immEnd();
2177 }
2178
2179 MEM_SAFE_DELETE(table_coords);
2180
2181 /* Draw the handles for the selected control points. */
2182 pts = profile->path;
2183 const int path_len = tot_points = uint(profile->path_len);
2184 int selected_free_points = 0;
2185 for (int i = 0; i < path_len; i++) {
2186 if (point_draw_handles(&pts[i])) {
2187 selected_free_points++;
2188 }
2189 }
2190 /* Draw the lines to the handles from the points. */
2191 if (selected_free_points > 0) {
2192 GPU_line_width(1.0f);
2194 GPU_line_smooth(true);
2195 immBegin(GPU_PRIM_LINES, selected_free_points * 4);
2196 float ptx, pty;
2197 for (int i = 0; i < path_len; i++) {
2198 if (point_draw_handles(&pts[i])) {
2199 ptx = rect->xmin + zoomx * (pts[i].x - offsx);
2200 pty = rect->ymin + zoomy * (pts[i].y - offsy);
2201
2202 fx = rect->xmin + zoomx * (pts[i].h1_loc[0] - offsx);
2203 fy = rect->ymin + zoomy * (pts[i].h1_loc[1] - offsy);
2204 immVertex2f(pos, ptx, pty);
2205 immVertex2f(pos, fx, fy);
2206
2207 fx = rect->xmin + zoomx * (pts[i].h2_loc[0] - offsx);
2208 fy = rect->ymin + zoomy * (pts[i].h2_loc[1] - offsy);
2209 immVertex2f(pos, ptx, pty);
2210 immVertex2f(pos, fx, fy);
2211 }
2212 }
2213 immEnd();
2214 }
2216
2217 /* New GPU instructions for control points and sampled points. */
2218 format = immVertexFormat();
2219 pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
2221
2223
2224 float color_point[4], color_point_select[4], color_point_active[4], color_sample[4];
2225 rgba_uchar_to_float(color_point, wcol->text);
2226 rgba_uchar_to_float(color_point_select, wcol->text_sel);
2227 rgba_uchar_to_float(color_point_active, wcol->text_sel);
2228 color_point[3] = 1.0f;
2229 color_point_select[3] = 1.0f;
2230 color_point_active[3] = 1.0f;
2231 color_sample[0] = float(wcol->item[0]) / 255.0f;
2232 color_sample[1] = float(wcol->item[1]) / 255.0f;
2233 color_sample[2] = float(wcol->item[2]) / 255.0f;
2234 color_sample[3] = float(wcol->item[3]) / 255.0f;
2235
2236 int selected = 0;
2237 int active = -1;
2238 for (int i = 0; i < path_len; i++) {
2239 if (pts[i].flag & PROF_SELECT) {
2240 selected++;
2241 }
2242 if (pts[i].flag & (PROF_ACTIVE | PROF_H1_ACTIVE | PROF_H2_ACTIVE)) {
2243 active = i;
2244 }
2245 }
2246
2247 const float point_size = max_ff(U.pixelsize * 2.0f,
2248 min_ff(UI_SCALE_FAC / but->block->aspect * 6.0f, 20.0f));
2249
2250 /* Draw curve points over outline. Don't change scissor if view is zoomed and not near edges.
2251 * Draw clipped points in that case. */
2252 rcti scissor_for_points;
2253 scissor_for_points.xmin = std::max(
2254 0,
2255 scissor_new.xmin -
2256 int(point_size * ((profile->clip_rect.xmin == profile->view_rect.xmin) ? 1 : 0)));
2257 scissor_for_points.ymin = std::max(
2258 0,
2259 scissor_new.ymin -
2260 int(point_size * ((profile->clip_rect.ymin == profile->view_rect.ymin) ? 1 : 0)));
2261 scissor_for_points.xmax = std::max(
2262 0,
2263 scissor_new.xmax +
2264 int(point_size * ((profile->clip_rect.xmax == profile->view_rect.xmax) ? 1 : 0)));
2265 scissor_for_points.ymax = std::max(
2266 0,
2267 scissor_new.ymax +
2268 int(point_size * ((profile->clip_rect.ymax == profile->view_rect.ymax) ? 1 : 0)));
2269
2270 GPU_scissor(scissor_for_points.xmin,
2271 scissor_for_points.ymin,
2272 BLI_rcti_size_x(&scissor_for_points),
2273 BLI_rcti_size_y(&scissor_for_points));
2274
2275 GPU_line_smooth(false);
2277
2278 if ((path_len - selected) > 0) {
2279 /* Unselected control points. */
2280 immUniform4fv("color", color_point);
2281 immUniform1f("size", point_size);
2282 immBegin(GPU_PRIM_POINTS, path_len - selected);
2283 for (int i = 0; i < path_len; i++) {
2284 if (pts[i].flag & PROF_SELECT) {
2285 continue;
2286 }
2287 fx = rect->xmin + zoomx * (pts[i].x - offsx);
2288 fy = rect->ymin + zoomy * (pts[i].y - offsy);
2289 immVertex2f(pos, fx, fy);
2290 }
2291 immEnd();
2292 }
2293 if (selected > 0) {
2294 /* Selected control points. */
2295 immUniform4fv("color", color_point_select);
2296 immUniform1f("size", point_size * 1.2f);
2297 immBegin(GPU_PRIM_POINTS, selected);
2298 for (int i = 0; i < path_len; i++) {
2299 if (!(pts[i].flag & PROF_SELECT)) {
2300 continue;
2301 }
2302 fx = rect->xmin + zoomx * (pts[i].x - offsx);
2303 fy = rect->ymin + zoomy * (pts[i].y - offsy);
2304 immVertex2f(pos, fx, fy);
2305 }
2306 immEnd();
2307 }
2308
2309 /* Find the total number of selected handles. */
2310 selected = 0;
2311 for (int i = 0; i < path_len; i++) {
2312 if (point_draw_handles(&pts[i])) {
2313 if (pts[i].flag & PROF_H1_SELECT) {
2314 selected++;
2315 }
2316 if (pts[i].flag & PROF_H2_SELECT) {
2317 selected++;
2318 }
2319 }
2320 }
2321
2322 if (((selected_free_points * 2) - selected) > 0) {
2323 /* Unselected handles. */
2324 immUniform4fv("color", color_point);
2325 immUniform1f("size", point_size);
2326 immBegin(GPU_PRIM_POINTS, (selected_free_points * 2) - selected);
2327 for (int i = 0; i < path_len; i++) {
2328 if (point_draw_handles(&pts[i])) {
2329 if (!(pts[i].flag & PROF_H1_SELECT)) {
2330 fx = rect->xmin + zoomx * (pts[i].h1_loc[0] - offsx);
2331 fy = rect->ymin + zoomy * (pts[i].h1_loc[1] - offsy);
2332 immVertex2f(pos, fx, fy);
2333 }
2334 if (!(pts[i].flag & PROF_H2_SELECT)) {
2335 fx = rect->xmin + zoomx * (pts[i].h2_loc[0] - offsx);
2336 fy = rect->ymin + zoomy * (pts[i].h2_loc[1] - offsy);
2337 immVertex2f(pos, fx, fy);
2338 }
2339 }
2340 }
2341 immEnd();
2342 }
2343
2344 if (selected > 0) {
2345 /* Selected Handles. */
2346 immUniform4fv("color", color_point_select);
2347 immUniform1f("size", point_size * 1.2f);
2348 immBegin(GPU_PRIM_POINTS, selected);
2349 for (int i = 0; i < path_len; i++) {
2350 if (point_draw_handles(&pts[i])) {
2351 if (pts[i].flag & PROF_H1_SELECT) {
2352 fx = rect->xmin + zoomx * (pts[i].h1_loc[0] - offsx);
2353 fy = rect->ymin + zoomy * (pts[i].h1_loc[1] - offsy);
2354 immVertex2f(pos, fx, fy);
2355 }
2356 if (pts[i].flag & PROF_H2_SELECT) {
2357 fx = rect->xmin + zoomx * (pts[i].h2_loc[0] - offsx);
2358 fy = rect->ymin + zoomy * (pts[i].h2_loc[1] - offsy);
2359 immVertex2f(pos, fx, fy);
2360 }
2361 }
2362 }
2363 immEnd();
2364 }
2365
2366 if (active != -1) {
2367 /* Active control point or handle. */
2368 immUniform4fv("color", color_point_active);
2369 immUniform1f("size", point_size * 1.4f);
2371 const short active_type = pts[active].flag & (PROF_ACTIVE | PROF_H1_ACTIVE | PROF_H2_ACTIVE);
2372 if (active_type & PROF_H1_ACTIVE) {
2373 fx = rect->xmin + zoomx * (pts[active].h1_loc[0] - offsx);
2374 fy = rect->ymin + zoomy * (pts[active].h1_loc[1] - offsy);
2375 }
2376 else if (active_type & PROF_H2_ACTIVE) {
2377 fx = rect->xmin + zoomx * (pts[active].h2_loc[0] - offsx);
2378 fy = rect->ymin + zoomy * (pts[active].h2_loc[1] - offsy);
2379 }
2380 else {
2381 fx = rect->xmin + zoomx * (pts[active].x - offsx);
2382 fy = rect->ymin + zoomy * (pts[active].y - offsy);
2383 }
2384 immVertex2f(pos, fx, fy);
2385 immEnd();
2386 }
2387
2388 /* Draw the sampled points in addition to the control points if they have been created */
2389 pts = profile->segments;
2390 const int segments_len = uint(profile->segments_len);
2391 if (segments_len > 0 && pts) {
2392 immUniform4fv("color", color_sample);
2393 immUniform1f("size", point_size);
2394 immBegin(GPU_PRIM_POINTS, segments_len);
2395 for (int i = 0; i < segments_len; i++) {
2396 fx = rect->xmin + zoomx * (pts[i].x - offsx);
2397 fy = rect->ymin + zoomy * (pts[i].y - offsy);
2398 immVertex2f(pos, fx, fy);
2399 }
2400 immEnd();
2401 }
2403
2404 GPU_scissor(scissor_new.xmin,
2405 scissor_new.ymin,
2406 BLI_rcti_size_x(&scissor_new),
2407 BLI_rcti_size_y(&scissor_new));
2408
2409 /* Restore scissor-test. */
2410 GPU_scissor_test(false);
2411 GPU_scissor(scissor[0], scissor[1], scissor[2], scissor[3]);
2412
2414}
2415
2417 Button *but,
2418 const uiWidgetColors * /*wcol*/,
2419 const rcti *recti)
2420{
2421 bool ok = false;
2422 MovieClipScopes *scopes = reinterpret_cast<MovieClipScopes *>(but->poin);
2423
2424 rctf rect{};
2425 rect.xmin = float(recti->xmin + 1);
2426 rect.xmax = float(recti->xmax - 1);
2427 rect.ymin = float(recti->ymin + 1);
2428 rect.ymax = float(recti->ymax - 1);
2429
2430 const int width = BLI_rctf_size_x(&rect) + 1;
2431 const int height = BLI_rctf_size_y(&rect);
2432
2434
2435 /* need scissor test, preview image can draw outside of boundary */
2436 int scissor[4];
2437 GPU_scissor_get(scissor);
2438 rcti scissor_new{};
2439 scissor_new.xmin = rect.xmin;
2440 scissor_new.ymin = rect.ymin;
2441 scissor_new.xmax = rect.xmax;
2442 scissor_new.ymax = rect.ymax;
2443 const rcti scissor_region = {0, region->winx, 0, region->winy};
2444 BLI_rcti_isect(&scissor_new, &scissor_region, &scissor_new);
2445 GPU_scissor(scissor_new.xmin,
2446 scissor_new.ymin,
2447 BLI_rcti_size_x(&scissor_new),
2448 BLI_rcti_size_y(&scissor_new));
2449 GPU_scissor_test(true);
2450
2451 if (scopes->track_disabled) {
2452 const float color[4] = {0.7f, 0.3f, 0.3f, 0.3f};
2454 rctf disabled_rect{};
2455 disabled_rect.xmin = rect.xmin - 1;
2456 disabled_rect.xmax = rect.xmax + 1;
2457 disabled_rect.ymin = rect.ymin;
2458 disabled_rect.ymax = rect.ymax + 1;
2459 draw_roundbox_4fv(&disabled_rect, true, 3.0f, color);
2460
2461 ok = true;
2462 }
2463 else if ((scopes->track_search) &&
2464 ((!scopes->track_preview) ||
2465 (scopes->track_preview->x != width || scopes->track_preview->y != height)))
2466 {
2467 if (scopes->track_preview) {
2469 }
2470
2472 scopes->frame_height,
2473 scopes->track_search,
2474 scopes->track,
2475 &scopes->undist_marker,
2476 true,
2477 scopes->use_track_mask,
2478 width,
2479 height,
2480 scopes->track_pos);
2481 if (tmpibuf) {
2482 if (tmpibuf->float_data()) {
2483 IMB_byte_from_float(tmpibuf);
2484 }
2485
2486 if (tmpibuf->byte_data()) {
2487 scopes->track_preview = tmpibuf;
2488 }
2489 else {
2490 IMB_freeImBuf(tmpibuf);
2491 }
2492 }
2493 }
2494
2495 if (!ok && scopes->track_preview) {
2497
2498 /* draw content of pattern area */
2499 GPU_scissor(rect.xmin, rect.ymin, scissor[2], scissor[3]);
2500
2501 if (width > 0 && height > 0) {
2502 const ImBuf *drawibuf = scopes->track_preview;
2503 float col_sel[4], col_outline[4];
2504
2505 if (scopes->use_track_mask) {
2506 const float color[4] = {0.0f, 0.0f, 0.0f, 0.3f};
2508 rctf mask_rect{};
2509 mask_rect.xmin = rect.xmin - 1;
2510 mask_rect.xmax = rect.xmax + 1;
2511 mask_rect.ymin = rect.ymin;
2512 mask_rect.ymax = rect.ymax + 1;
2513 draw_roundbox_4fv(&mask_rect, true, 3.0f, color);
2514 }
2515
2517 drawer.draw(rect.xmin,
2518 rect.ymin + 1,
2519 drawibuf->x,
2520 drawibuf->y,
2521 gpu::TextureFormat::UNORM_8_8_8_8,
2522 true,
2523 drawibuf->byte_data(),
2524 1.0f,
2525 1.0f,
2526 nullptr);
2527
2528 /* draw cross for pixel position */
2529 GPU_matrix_translate_2f(rect.xmin + scopes->track_pos[0], rect.ymin + scopes->track_pos[1]);
2530 GPU_scissor(rect.xmin, rect.ymin, BLI_rctf_size_x(&rect), BLI_rctf_size_y(&rect));
2531
2532 GPUVertFormat *format = immVertexFormat();
2533 const uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
2534 const uint col = GPU_vertformat_attr_add(
2535 format, "color", gpu::VertAttrType::SFLOAT_32_32_32_32);
2537
2540
2541 /* Do stipple cross with geometry */
2542 immBegin(GPU_PRIM_LINES, 7 * 2 * 2);
2543 const float pos_sel[8] = {-10.0f, -7.0f, -4.0f, -1.0f, 2.0f, 5.0f, 8.0f, 11.0f};
2544 for (int axe = 0; axe < 2; axe++) {
2545 for (int i = 0; i < 7; i++) {
2546 const float x1 = pos_sel[i] * (1 - axe);
2547 const float y1 = pos_sel[i] * axe;
2548 const float x2 = pos_sel[i + 1] * (1 - axe);
2549 const float y2 = pos_sel[i + 1] * axe;
2550
2551 if (i % 2 == 1) {
2552 immAttr4fv(col, col_sel);
2553 }
2554 else {
2555 immAttr4fv(col, col_outline);
2556 }
2557
2558 immVertex2f(pos, x1, y1);
2559 immVertex2f(pos, x2, y2);
2560 }
2561 }
2562 immEnd();
2563
2565 }
2566
2568
2569 ok = true;
2570 }
2571
2572 if (!ok) {
2573 const float color[4] = {0.0f, 0.0f, 0.0f, 0.3f};
2575 rctf box_rect{};
2576 box_rect.xmin = rect.xmin - 1;
2577 box_rect.xmax = rect.xmax + 1;
2578 box_rect.ymin = rect.ymin;
2579 box_rect.ymax = rect.ymax + 1;
2580 draw_roundbox_4fv(&box_rect, true, 3.0f, color);
2581 }
2582
2583 /* Restore scissor test. */
2584 GPU_scissor_test(false);
2585 GPU_scissor(UNPACK4(scissor));
2586 /* outline */
2587 draw_scope_end(&rect);
2588
2590}
2591
2592/* ****************************************************** */
2593
2595 const rctf *rct, const float radius, const float width, const float aspect, const float alpha)
2596{
2597 if (width == 0.0f) {
2598 return;
2599 }
2600
2601 /* This undoes the scale of the view for higher zoom factors to clamp the shadow size. */
2602 const float clamped_aspect = smoothminf(aspect, 1.0f, 0.5f);
2603 const float shadow_width = width * clamped_aspect;
2604 const float shadow_offset = min_ff(shadow_width, BLI_rctf_size_y(rct) - 2.0f * radius);
2605
2606 const float inner_radius = max_ff(radius - U.pixelsize, 0.0);
2607 const float shadow_radius = radius + shadow_width - U.pixelsize;
2608
2610
2611 WidgetBaseParameters widget_params{};
2612 widget_params.recti.xmin = rct->xmin;
2613 widget_params.recti.ymin = rct->ymin;
2614 widget_params.recti.xmax = rct->xmax;
2615 widget_params.recti.ymax = rct->ymax;
2616 widget_params.rect.xmin = rct->xmin - shadow_width;
2617 widget_params.rect.ymin = rct->ymin - shadow_width;
2618 widget_params.rect.xmax = rct->xmax + shadow_width;
2619 widget_params.rect.ymax = rct->ymax + shadow_width - shadow_offset;
2620 widget_params.radi = inner_radius;
2621 widget_params.rad = shadow_radius;
2622 widget_params.round_corners[0] = (roundboxtype & CNR_BOTTOM_LEFT) ? 1.0f : 0.0f;
2623 widget_params.round_corners[1] = (roundboxtype & CNR_BOTTOM_RIGHT) ? 1.0f : 0.0f;
2624 widget_params.round_corners[2] = (roundboxtype & CNR_TOP_RIGHT) ? 1.0f : 0.0f;
2625 widget_params.round_corners[3] = (roundboxtype & CNR_TOP_LEFT) ? 1.0f : 0.0f;
2626 widget_params.alpha_discard = 1.0f;
2627
2628 gpu::Batch *batch = batch_roundbox_shadow_get();
2630 GPU_batch_uniform_4fv_array(batch, "parameters", 4, (const float (*)[4]) & widget_params);
2631 GPU_batch_uniform_1f(batch, "alpha", alpha);
2632 GPU_batch_draw(batch);
2633
2635}
2636
2637} // namespace blender::ui
#define DEG2RADF(_deg)
#define M_PI_2
#define M_PI
#define CM_TABLE
#define UI_SCALE_FAC
#define GPU_batch_uniform_1f(batch, name, x)
Definition GPU_batch.hh:267
#define GPU_batch_uniformbuf_bind(batch, name, ubo)
Definition GPU_batch.hh:282
#define GPU_batch_uniform_4fv_array(batch, name, len, val)
Definition GPU_batch.hh:278
#define GPU_batch_uniform_4f(batch, name, x, y, z, w)
Definition GPU_batch.hh:271
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UI_ALPHA_CHECKER_LIGHT
#define UI_ALPHA_CHECKER_DARK
#define CLAMP(a, b, c)
#define UNPACK4(a)
#define ARRAY_SET_ITEMS(...)
#define UNPACK3(a)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
btScalar max
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
void draw(float x, float y, int img_w, int img_h, gpu::TextureFormat gpu_format, bool use_filter, const void *rect, float scale_x, float scale_y, const float color[4])
Definition glutil.cc:45
void append(const T &value)
MutableSpan< T > data()
#define FLT_MAX
#define point_size
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
#define HISTOGRAM_TOT_GRID_LINES
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
ccl_device_inline dual3 fabs(const ccl_private dual3 &a)
Definition math_dual.h:241
CartesianBasis invert(const CartesianBasis &basis)
void get_color_4fv(int colorid, float col[4])
void get_color_3ubv(int colorid, unsigned char col[3])
static float polar_to_y(float center, float diam, float ampli, float angle)
static void histogram_draw_one(float r, float g, float b, float alpha, float x, float y, float w, float h, const float *data, int res, const bool is_line, uint pos_attr)
gpu::Batch * batch_roundbox_widget_get()
void draw_but_VECTORSCOPE(const bContext *C, ARegion *region, Button *but, const uiWidgetColors *, const rcti *recti)
static float polar_to_x(float center, float diam, float ampli, float angle)
const ColorManagedDisplay * block_cm_display_get(Block *block)
void draw_but_WAVEFORM(const bContext *C, ARegion *region, Button *but, const uiWidgetColors *, const rcti *recti)
static void draw_colorband_handle_tri(uint pos, float x1, float y1, float halfwidth)
void draw_safe_areas(uint pos, const rctf *rect, const float title_aspect[2], const float action_aspect[2])
void draw_but_CURVEPROFILE(ARegion *region, Button *but, const uiWidgetColors *wcol, const rcti *rect)
void draw_dropshadow(const rctf *rct, float radius, float width, float aspect, float alpha)
void draw_but_TAB_outline(const rcti *rect, float rad, uchar highlight[3], uchar highlight_fade[3])
static void draw_colorband_handle_box(uint pos, float x1, float y1, float x2, float y2)
void draw_but_IMAGE(ARegion *, Button *but, const uiWidgetColors *, const rcti *rect)
static void draw_but_curve_grid(const uint pos, const rcti *rect, const float zoom_x, const float zoom_y, const float offset_x, const float offset_y, const float step)
static void draw_colorband_handle(uint shdr_pos, const rcti *rect, float x, const float rgb[3], const ColorManagedDisplay *display, bool active)
static void circle_draw_rgb(float *points, int tot_points, const float *col, GPUPrimType prim)
void draw_but_COLORBAND(Button *but, const uiWidgetColors *wcol, const rcti *rect)
void button_v3_get(Button *but, float vec[3])
void draw_roundbox_corner_set(int type)
void draw_but_UNITVEC(Button *but, const uiWidgetColors *wcol, const rcti *rect, const float radius)
static void waveform_draw_rgb(const float *waveform, int waveform_num, const float *col, float alpha)
void draw_but_TRACKPREVIEW(ARegion *region, Button *but, const uiWidgetColors *, const rcti *recti)
void draw_rounded_corners_inverted(const rcti &rect, const float rad, const float4 color)
void draw_roundbox_aa(const rctf *rect, bool filled, float rad, const float color[4])
void draw_roundbox_4fv_ex(const rctf *rect, const float inner1[4], const float inner2[4], float shade_dir, const float outline[4], float outline_width, float rad)
void draw_roundbox_3fv_alpha(const rctf *rect, bool filled, float rad, const float col[3], float alpha)
void draw_roundbox_3ub_alpha(const rctf *rect, bool filled, float rad, const unsigned char col[3], unsigned char alpha)
static bool point_draw_handles(CurveProfilePoint *point)
void draw_text_underline(int pos_x, int pos_y, int len, int height, const float color[4])
gpu::Batch * batch_roundbox_shadow_get()
static void draw_scope_end(const rctf *rect)
void draw_but_HISTOGRAM(ARegion *region, Button *but, const uiWidgetColors *, const rcti *recti)
static void waveform_draw_one(const float *waveform, int waveform_num, const float col[3])
static void vectorscope_draw_target(uint pos, float centerx, float centery, float diam, const float colf[3], char label, const float3x3 &yuv_matrix)
void draw_roundbox_4fv(const rctf *rect, bool filled, float rad, const float col[4])
void draw_gradient(const rcti *rect, const float hsv[3], eButGradientType type, float alpha, const ColorManagedDisplay *display)
void draw_but_CURVE(ARegion *region, Button *but, const uiWidgetColors *wcol, const rcti *rect)
static int roundboxtype
MINLINE float min_ff(float a, float b)
UserDef U
Definition blender.cc:58
void GPU_vertbuf_tag_dirty(gpu::VertBuf *verts)
void GPU_scissor_test(bool enable)
Definition gpu_state.cc:173
@ GPU_CULL_NONE
Definition GPU_state.hh:157
@ GPU_CULL_BACK
Definition GPU_state.hh:159
MINLINE void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
void immAttr4f(uint attr_id, float x, float y, float z, float w)
gpu::Batch * GPU_batch_create_ex(GPUPrimType primitive_type, gpu::VertBuf *vertex_buf, gpu::IndexBuf *index_buf, GPUBatchFlag owns_flag)
Definition gpu_batch.cc:53
void linearrgb_to_srgb_v3_v3(float srgb[3], const float linear[3])
void BLF_position(int fontid, float x, float y, float z)
Definition blf.cc:390
void immEnd()
void GPU_matrix_scale_1f(float factor)
void immUniformColor3f(float r, float g, float b)
void BLF_batch_draw_flush()
Definition blf.cc:542
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
void GPU_polygon_smooth(bool enable)
Definition gpu_state.cc:85
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void GPU_uniformbuf_free(gpu::UniformBuf *ubo)
void immUniformColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
bool BLI_rcti_isect(const struct rcti *src1, const struct rcti *src2, struct rcti *dest)
MINLINE void mul_v2_fl(float r[2], float f)
void immUniform2f(const char *name, float x, float y)
void immBeginAtMost(GPUPrimType, uint max_vertex_len)
GPUVertFormat * immVertexFormat()
void BLI_polyfill_calc(const float(*coords)[2], unsigned int coords_num, int coords_sign, unsigned int(*r_tris)[3])
void GPU_point_size(float size)
Definition gpu_state.cc:157
void GPU_matrix_ortho_set_z(float near, float far)
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
void immBegin(GPUPrimType, uint vertex_len)
void GPU_line_smooth(bool enable)
Definition gpu_state.cc:80
@ SCOPES_WAVEFRM_LUMA
@ SCOPES_WAVEFRM_YCC_601
@ SCOPES_WAVEFRM_YCC_709
@ SCOPES_WAVEFRM_RGB_PARADE
@ SCOPES_WAVEFRM_YCC_JPEG
@ GPU_PRIM_TRI_STRIP
@ GPU_PRIM_LINE_STRIP
@ GPU_PRIM_LINE_LOOP
void GPU_batch_discard(gpu::Batch *batch)
void GPU_vertbuf_use(gpu::VertBuf *)
@ TH_MARKER_OUTLINE
bool BKE_colorband_evaluate(const ColorBand *coba, float in, float out[4])
Definition colorband.cc:399
MINLINE void copy_v4_fl4(float v[4], float x, float y, float z, float w)
ATTR_WARN_UNUSED_RESULT const BMVert * v
void immUniformColor4fv(const float rgba[4])
void immUnbindProgram()
void BLF_color4f(int fontid, float r, float g, float b, float a)
Definition blf.cc:516
void immUniformColor3ubv(const unsigned char rgb[3])
bool immIsShaderBound()
void GPU_line_width(float width)
Definition gpu_state.cc:151
void GPU_matrix_scale_2f(float x, float y)
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
@ GPU_BLEND_ADDITIVE
Definition GPU_state.hh:92
@ GPU_BLEND_ALPHA_PREMULT
Definition GPU_state.hh:91
VecBase< float, 4 > float4
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
void imm_draw_circle_wire_2d(uint shdr_pos, float x, float y, float radius, int nsegments)
void BLF_size(int fontid, float size)
Definition blf.cc:445
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
void IMB_freeImBuf(ImBuf *ibuf)
VecBase< float, 2 > float2
void immUniform1f(const char *name, float x)
void immVertex2f(uint attr_id, float x, float y)
unsigned char uchar
Definition BKE_text.h:58
ocio::ScopeInfo IMB_colormanagement_get_scope_info(const ColorManagedDisplaySettings *display_settings, const ColorManagedViewSettings *view_settings)
void GPU_viewport_size_get_f(float coords[4])
Definition gpu_state.cc:258
void immAttr4fv(uint attr_id, const float data[4])
BMesh const char void * data
int BLF_default()
@ GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA
@ GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR
@ GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA
@ GPU_SHADER_2D_WIDGET_SHADOW
@ GPU_SHADER_3D_POINT_FLAT_COLOR
void GPU_scissor_get(int coords[4])
Definition gpu_state.cc:253
void immUniform4fv(const char *name, const float data[4])
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.hh:215
void BKE_curvemapping_changed(CurveMapping *cumap, bool rem_doubles)
void immUniformColor4f(float r, float g, float b, float a)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
void GPU_batch_draw(gpu::Batch *batch)
void immUniformColor3ub(unsigned char r, unsigned char g, unsigned char b)
@ GPU_BATCH_OWNS_VBO
Definition GPU_batch.hh:44
void GPU_program_point_size(bool enable)
Definition gpu_state.cc:165
void GPU_matrix_translate_2f(float x, float y)
MatBase< float, 3, 3 > float3x3
void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:587
gpu::UniformBuf * GPU_uniformbuf_create_ex(size_t size, const void *data, const char *name)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
void GPU_batch_program_set_builtin(gpu::Batch *batch, GPUBuiltinShader shader_id)
void immAttr4ub(uint attr_id, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
int BKE_curveprofile_table_size(const struct CurveProfile *profile)
MINLINE float smoothminf(float a, float b, float c)
void BLF_draw_default(float x, float y, float z, const char *str, size_t str_len) ATTR_NONNULL()
BLI_INLINE float IMB_colormanagement_get_luminance(const float rgb[3])
void GPU_scissor(int x, int y, int width, int height)
Definition gpu_state.cc:178
void IMB_colormanagement_scene_linear_to_display_v3(float pixel[3], const ColorManagedDisplay *display, ColorManagedDisplaySpace display_space=DISPLAY_SPACE_DRAW)
void immUniform4f(const char *name, float x, float y, float z, float w)
void unit_m3(float m[3][3])
ATTR_WARN_UNUSED_RESULT const BMVert * v2
void IMB_byte_from_float(ImBuf *ibuf)
void GPU_matrix_pop_projection()
void imm_draw_box_wire_2d(uint pos, float x1, float y1, float x2, float y2)
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.hh:211
void GPU_vertbuf_attr_fill(gpu::VertBuf *, uint a_idx, const void *data)
GPUBlend GPU_blend_get()
Definition gpu_state.cc:211
MINLINE float max_ff(float a, float b)
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
void GPU_face_culling(GPUFaceCullTest culling)
Definition gpu_state.cc:49
Scene * CTX_data_scene(const bContext *C)
gpu::Batch * GPU_batch_preset_sphere(int lod) ATTR_WARN_UNUSED_RESULT
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
void immUniform1i(const char *name, int x)
VecBase< float, 3 > float3
ImBuf * BKE_tracking_sample_pattern(int frame_width, int frame_height, const ImBuf *search_ib, const MovieTrackingTrack *track, const MovieTrackingMarker *marker, bool from_anchor, bool use_mask, int num_samples_x, int num_samples_y, float pos[2])
Definition tracking.cc:2530
void BLF_width_and_height(int fontid, const char *str, size_t str_len, float *r_width, float *r_height) ATTR_NONNULL()
Definition blf.cc:822
void immUniformColor4ubv(const unsigned char rgba[4])
void immVertex2fv(uint attr_id, const float data[2])
void immUniformColor3ubvAlpha(const unsigned char rgb[3], unsigned char a)
void GPU_matrix_pop()
void immUniformColor3fvAlpha(const float rgb[3], float a)
void GPU_matrix_push_projection()
void BKE_curveprofile_update(struct CurveProfile *profile, int update_flags)
void immRectf(uint pos, float x1, float y1, float x2, float y2)
void GPU_matrix_push()
ocio::Display ColorManagedDisplay
@ CUMA_EXTEND_EXTRAPOLATE
#define floorf
#define sqrtf
#define atanf
#define sinf
#define cosf
#define ceilf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
CurveMapPoint * curve
CurveMapPoint * table
eCurveMappingFlags flag
CurveProfilePoint * segments
eHistogram_Mode mode
eHistogram_Flag flag
const uint8_t * byte_data() const
const float * float_data() const
struct MovieTrackingTrack * track
struct MovieTrackingMarker undist_marker
ColorManagedViewSettings view_settings
ColorManagedDisplaySettings display_settings
eScopes_WaveformMode wavefrm_mode
eScopes_VecscopeMode vecscope_mode
blender::float3x3 yuv_matrix
Definition OCIO_scope.hh:45
blender::float3x3 scope_gamut_to_rec709
Definition OCIO_scope.hh:41
Vector< ScopeGraticule > graticules
Definition OCIO_scope.hh:27
unsigned char inner_sel[4]
unsigned char inner[4]
unsigned char outline[4]
unsigned char outline_sel[4]
unsigned char text[4]
unsigned char item[4]
unsigned char text_sel[4]