Blender V5.3
interface_widgets.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10#include <climits>
11#include <cstdlib>
12#include <cstring>
13#include <list>
14#include <optional>
15
16#include "DNA_brush_types.h"
17#include "DNA_node_types.h"
18#include "DNA_screen_types.h"
19#include "DNA_space_types.h"
20#include "DNA_userdef_types.h"
21
22#include "BLI_color_types.hh"
23#include "BLI_listbase.hh"
24#include "BLI_math_color_c.hh"
25#include "BLI_math_vector_c.hh"
26#include "BLI_rect.hh"
27#include "BLI_string.hh"
28#include "BLI_string_utf8.hh"
29#include "BLI_utildefines.hh"
30
31#include "BKE_context.hh"
32#include "BKE_path_templates.hh"
33
34#include "RNA_access.hh"
35
36#include "BLF_api.hh"
37
38#include "ED_node.hh"
39
40#include "UI_interface_icons.hh"
41#include "UI_view2d.hh"
42
46#include "interface_intern.hh"
47
48#include "GPU_batch.hh"
49#include "GPU_batch_presets.hh"
50#include "GPU_immediate.hh"
51#include "GPU_immediate_util.hh"
52#include "GPU_matrix.hh"
53#include "GPU_state.hh"
54
55#include "UI_abstract_view.hh"
56
58
59#ifdef WITH_INPUT_IME
60# include "WM_types.hh"
61#endif
62
63namespace blender::ui {
64
65/* -------------------------------------------------------------------- */
68
69/* icons are 80% of height of button (16 pixels inside 20 height) */
70#define ICON_SIZE_FROM_BUTRECT(rect) (0.8f * BLI_rcti_size_y(rect))
71/* Used e.g. by placeholders and unit hint completion. */
72#define UI_INPUT_HINT_ALPHA 0.33f
73
74/* visual types for drawing */
75/* for time being separated from functional types */
76enum class WidgetStyle {
77 /* default */
79
80 /* standard set */
82 Toggle,
91
92 /* strings */
97
98 /* menus */
103
106 /* Same as #WidgetStyle::MenuItem, but doesn't add padding to sides for text & icon inside the
107 * widget. To be used when multiple menu items should be displayed close to each other
108 * horizontally. */
112
113 /* specials */
126};
127
147
149
151
152/* -------------------------------------------------------------------- */
155
156static void color_blend_v3_v3(uchar cp[3], const uchar cpstate[3], const float fac)
157{
158 if (fac != 0.0f) {
159 cp[0] = int((1.0f - fac) * cp[0] + fac * cpstate[0]);
160 cp[1] = int((1.0f - fac) * cp[1] + fac * cpstate[1]);
161 cp[2] = int((1.0f - fac) * cp[2] + fac * cpstate[2]);
162 }
163}
164
165static void color_blend_v4_v4v4(uchar r_col[4],
166 const uchar col1[4],
167 const uchar col2[4],
168 const float fac)
169{
170 const int faci = unit_float_to_uchar_clamp(fac);
171 const int facm = 255 - faci;
172
173 r_col[0] = (faci * col1[0] + facm * col2[0]) / 256;
174 r_col[1] = (faci * col1[1] + facm * col2[1]) / 256;
175 r_col[2] = (faci * col1[2] + facm * col2[2]) / 256;
176 r_col[3] = (faci * col1[3] + facm * col2[3]) / 256;
177}
178
179static void color_ensure_contrast_v3(uchar cp[3], const uchar cp_other[3], int contrast)
180{
181 BLI_assert(contrast > 0);
182 const int item_value = srgb_to_grayscale_byte(cp);
183 const int inner_value = srgb_to_grayscale_byte(cp_other);
184 const int delta = item_value - inner_value;
185 if (delta >= 0) {
186 if (contrast > delta) {
187 add_v3_uchar_clamped(cp, contrast - delta);
188 }
189 }
190 else {
191 if (contrast > -delta) {
192 add_v3_uchar_clamped(cp, -contrast - delta);
193 }
194 }
195}
196
197static void color_mul_hsl_v3(uchar ch[3], float h_factor, float s_factor, float l_factor)
198{
199 float rgb[3], hsl[3];
200 rgb_uchar_to_float(rgb, ch);
201 rgb_to_hsl_v(rgb, hsl);
202 hsl[0] *= h_factor;
203 hsl[1] *= s_factor;
204 hsl[2] *= l_factor;
205 hsl_to_rgb_v(hsl, rgb);
206 rgb_float_to_uchar(ch, rgb);
207}
208
210
211/* -------------------------------------------------------------------- */
214
227
228/* fill this struct with polygon info to draw AA'ed */
229/* it has outline, back, and two optional tria meshes */
230
233 int type;
234 float size, center[2];
235
236 float vec[16][2];
237 const uint (*index)[3];
238};
239
240/* max as used by round_box__edges */
241/* Make sure to change widget_base_vert.glsl accordingly. */
242#define WIDGET_CURVE_RESOLU 9
243#define WIDGET_SIZE_MAX (WIDGET_CURVE_RESOLU * 4)
244
246 /* TODO: remove these completely. */
251
253
256
257 /* Widget shader parameters, must match the shader layout. */
259};
260
266
267 /* pointer to theme color definition */
270
271 /* converted colors for state */
273
276 rcti *,
277 const WidgetStateInfo *,
278 int roundboxalign,
279 const float zoom) ATTR_NONNULL();
280 void (*custom)(Button *,
282 rcti *,
283 const WidgetStateInfo *,
284 int roundboxalign,
285 const float zoom) ATTR_NONNULL();
286 void (*draw_block)(
287 uiWidgetColors *, const rcti *, int block_flag, int roundboxalign, const float zoom);
288 void (*text)(const uiFontStyle *, const uiWidgetColors *, Button *, rcti *);
289};
290
292
293/* -------------------------------------------------------------------- */
296
297static const float cornervec[WIDGET_CURVE_RESOLU][2] = {
298 {0.0, 0.0},
299 {0.195, 0.02},
300 {0.383, 0.067},
301 {0.55, 0.169},
302 {0.707, 0.293},
303 {0.831, 0.45},
304 {0.924, 0.617},
305 {0.98, 0.805},
306 {1.0, 1.0},
307};
308
310 {0.468813, -0.481430},
311 {-0.155755, -0.352820},
312 {0.219306, -0.238501},
313 {-0.393286, -0.110949},
314 {-0.024699, 0.013908},
315 {0.343805, 0.147431},
316 {-0.272855, 0.269918},
317 {0.095909, 0.388710},
318};
319#define WIDGET_AA_JITTER UI_PIXEL_AA_JITTER
320#define jit ui_pixel_jitter
321
322static const float g_shape_preset_number_arrow_vert[3][2] = {
323 {-0.352077, 0.532607},
324 {-0.352077, -0.549313},
325 {0.330000, -0.008353},
326};
328 {0, 1, 2},
329};
330
331static const float g_shape_preset_scroll_circle_vert[16][2] = {
332 {0.382684, 0.923879},
333 {0.000001, 1.000000},
334 {-0.382683, 0.923880},
335 {-0.707107, 0.707107},
336 {-0.923879, 0.382684},
337 {-1.000000, 0.000000},
338 {-0.923880, -0.382684},
339 {-0.707107, -0.707107},
340 {-0.382683, -0.923880},
341 {0.000000, -1.000000},
342 {0.382684, -0.923880},
343 {0.707107, -0.707107},
344 {0.923880, -0.382684},
345 {1.000000, -0.000000},
346 {0.923880, 0.382683},
347 {0.707107, 0.707107},
348};
350 {0, 1, 2},
351 {2, 0, 3},
352 {3, 0, 15},
353 {3, 15, 4},
354 {4, 15, 14},
355 {4, 14, 5},
356 {5, 14, 13},
357 {5, 13, 6},
358 {6, 13, 12},
359 {6, 12, 7},
360 {7, 12, 11},
361 {7, 11, 8},
362 {8, 11, 10},
363 {8, 10, 9},
364};
365
366static const float g_shape_preset_menu_arrow_vert[6][2] = {
367 {-0.33, 0.16},
368 {0.33, 0.16},
369 {0, 0.82},
370 {0, -0.82},
371 {-0.33, -0.16},
372 {0.33, -0.16},
373};
374static const uint g_shape_preset_menu_arrow_face[2][3] = {{2, 0, 1}, {3, 5, 4}};
375
376static const float g_shape_preset_checkmark_vert[6][2] = {
377 {-0.578579, 0.253369},
378 {-0.392773, 0.412794},
379 {-0.004241, -0.328551},
380 {-0.003001, 0.034320},
381 {1.055313, 0.864744},
382 {0.866408, 1.026895},
383};
384
386 {3, 2, 4},
387 {3, 4, 5},
388 {1, 0, 3},
389 {0, 2, 3},
390};
391
392#define OY (-0.2 / 2)
393#define SC (0.35 * 2)
394static const float g_shape_preset_hold_action_vert[6][2] = {
395 {-0.5 + SC, 1.0 + OY},
396 {0.5, 1.0 + OY},
397 {0.5, 0.0 + OY + SC},
398};
399static const uint g_shape_preset_hold_action_face[2][3] = {{2, 0, 1}, {3, 5, 4}};
400#undef OY
401#undef SC
402
404
405/* -------------------------------------------------------------------- */
413
414static struct {
415 gpu::Batch *roundbox_widget;
416 gpu::Batch *roundbox_shadow;
417
418 /* TODO: remove. */
421} g_ui_batch_cache = {nullptr};
422
424{
425 if (g_ui_batch_cache.format.attr_len == 0) {
426 GPUVertFormat *format = &g_ui_batch_cache.format;
428 format, "vflag", gpu::VertAttrType::UINT_32);
429 }
430 return g_ui_batch_cache.format;
431}
432
433#define INNER 0
434#define OUTLINE 1
435#define EMBOSS 2
436#define NO_AA 0
437
439{
440 uint32_t *data = static_cast<uint32_t *>(GPU_vertbuf_raw_step(vflag_step));
441 *data = d;
442}
443
445 int corner_id,
446 int corner_v,
447 int jit_v,
448 bool inner,
449 bool emboss,
450 int color)
451{
452 uint32_t *data = static_cast<uint32_t *>(GPU_vertbuf_raw_step(vflag_step));
453 *data = corner_id;
454 *data |= corner_v << 2;
455 *data |= jit_v << 6;
456 *data |= color << 12;
457 *data |= (inner) ? (1 << 10) : 0; /* is inner vert */
458 *data |= (emboss) ? (1 << 11) : 0; /* is emboss vert */
459 return *data;
460}
461
463{
464 if (g_ui_batch_cache.roundbox_widget == nullptr) {
465 gpu::VertBuf *vbo = GPU_vertbuf_create_with_format(vflag_format());
466
467 GPU_vertbuf_data_alloc(*vbo, 12);
468
470 GPU_indexbuf_init(&ibuf, GPU_PRIM_TRIS, 6, 12);
471 /* Widget */
472 GPU_indexbuf_add_tri_verts(&ibuf, 0, 1, 2);
473 GPU_indexbuf_add_tri_verts(&ibuf, 2, 1, 3);
474 /* Trias */
475 GPU_indexbuf_add_tri_verts(&ibuf, 4, 5, 6);
476 GPU_indexbuf_add_tri_verts(&ibuf, 6, 5, 7);
477
478 GPU_indexbuf_add_tri_verts(&ibuf, 8, 9, 10);
479 GPU_indexbuf_add_tri_verts(&ibuf, 10, 9, 11);
480
481 g_ui_batch_cache.roundbox_widget = GPU_batch_create_ex(
484 }
485 return g_ui_batch_cache.roundbox_widget;
486}
487
489{
490 if (g_ui_batch_cache.roundbox_shadow == nullptr) {
491 uint32_t last_data;
492 GPUVertBufRaw vflag_step;
493 gpu::VertBuf *vbo = GPU_vertbuf_create_with_format(vflag_format());
494 const int vcount = (WIDGET_SIZE_MAX + 1) * 2 + 2 + WIDGET_SIZE_MAX;
495 GPU_vertbuf_data_alloc(*vbo, vcount);
496 GPU_vertbuf_attr_get_raw_data(vbo, g_ui_batch_cache.vflag_id, &vflag_step);
497
498 for (int c = 0; c < 4; c++) {
499 for (int a = 0; a < WIDGET_CURVE_RESOLU; a++) {
500 set_roundbox_vertex(&vflag_step, c, a, NO_AA, true, false, INNER);
501 set_roundbox_vertex(&vflag_step, c, a, NO_AA, false, false, INNER);
502 }
503 }
504 /* close loop */
505 last_data = set_roundbox_vertex(&vflag_step, 0, 0, NO_AA, true, false, INNER);
506 last_data = set_roundbox_vertex(&vflag_step, 0, 0, NO_AA, false, false, INNER);
507 /* restart */
508 set_roundbox_vertex_data(&vflag_step, last_data);
509 set_roundbox_vertex(&vflag_step, 0, 0, NO_AA, true, false, INNER);
510 /* filled */
511 for (int c1 = 0, c2 = 3; c1 < 2; c1++, c2--) {
512 for (int a1 = 0, a2 = WIDGET_CURVE_RESOLU - 1; a2 >= 0; a1++, a2--) {
513 set_roundbox_vertex(&vflag_step, c1, a1, NO_AA, true, false, INNER);
514 set_roundbox_vertex(&vflag_step, c2, a2, NO_AA, true, false, INNER);
515 }
516 }
517 g_ui_batch_cache.roundbox_shadow = GPU_batch_create_ex(
520 }
521 return g_ui_batch_cache.roundbox_shadow;
522}
523
524#undef INNER
525#undef OUTLINE
526#undef EMBOSS
527#undef NO_AA
528
530
531/* -------------------------------------------------------------------- */
534
535static void draw_anti_tria(
536 float x1, float y1, float x2, float y2, float x3, float y3, const float color[4])
537{
538 const float tri_arr[3][2] = {{x1, y1}, {x2, y2}, {x3, y3}};
539
540 float draw_color[4];
541 copy_v4_v4(draw_color, color);
542 /* NOTE: This won't give back the original color. */
543 draw_color[3] *= 1.0f / WIDGET_AA_JITTER;
544
546
547 const uint pos = GPU_vertformat_attr_add(
548 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
550
551 immUniformColor4fv(draw_color);
553
554 /* for each AA step */
555 for (int j = 0; j < WIDGET_AA_JITTER; j++) {
556 immVertex2f(pos, tri_arr[0][0] + jit[j][0], tri_arr[0][1] + jit[j][1]);
557 immVertex2f(pos, tri_arr[1][0] + jit[j][0], tri_arr[1][1] + jit[j][1]);
558 immVertex2f(pos, tri_arr[2][0] + jit[j][0], tri_arr[2][1] + jit[j][1]);
559 }
560
561 immEnd();
562
564
566}
567
568void draw_icon_tri(float x, float y, char dir, const float color[4], float aspect)
569{
570 const float f3 = 0.05 * U.widget_unit / aspect;
571 const float f5 = 0.15 * U.widget_unit / aspect;
572 const float f7 = 0.25 * U.widget_unit / aspect;
573
574 if (dir == 'h') {
575 draw_anti_tria(x - f3, y - f5, x - f3, y + f5, x + f7, y, color);
576 }
577 else if (dir == 't') {
578 draw_anti_tria(x - f5, y - f7, x + f5, y - f7, x, y + f3, color);
579 }
580 else { /* 'v' = vertical, down. */
581 draw_anti_tria(x - f5, y + f3, x + f5, y + f3, x, y - f7, color);
582 }
583}
584
585/* triangle 'icon' inside rect */
586static void draw_anti_tria_rect(const rctf *rect, char dir, const float color[4])
587{
588 if (dir == 'h') {
589 const float half = 0.5f * BLI_rctf_size_y(rect);
591 rect->xmin, rect->ymin, rect->xmin, rect->ymax, rect->xmax, rect->ymin + half, color);
592 }
593 else {
594 const float half = 0.5f * BLI_rctf_size_x(rect);
596 rect->xmin, rect->ymax, rect->xmax, rect->ymax, rect->xmin + half, rect->ymin, color);
597 }
598}
599
600static void widget_init(WidgetBase *wtb)
601{
602 wtb->totvert = wtb->halfwayvert = 0;
603 wtb->tria1.tot = 0;
604 wtb->tria2.tot = 0;
606 wtb->tria1.size = 0;
607 wtb->tria2.size = 0;
608
609 wtb->draw_inner = true;
610 wtb->draw_outline = true;
611 wtb->draw_emboss = true;
612
613 wtb->uniform_params.shade_dir = 1.0f;
614 wtb->uniform_params.alpha_discard = 1.0f;
615}
616
618
619/* -------------------------------------------------------------------- */
622
623/* this call has 1 extra arg to allow mask outline */
625 WidgetBase *wt, int roundboxalign, const rcti *rect, float rad, float radi)
626{
627 float vec[WIDGET_CURVE_RESOLU][2], veci[WIDGET_CURVE_RESOLU][2];
628 const float minx = rect->xmin, miny = rect->ymin, maxx = rect->xmax, maxy = rect->ymax;
629 const float minxi = minx + U.pixelsize; /* Bounding-box inner. */
630 const float maxxi = maxx - U.pixelsize;
631 const float minyi = miny + U.pixelsize;
632 const float maxyi = maxy - U.pixelsize;
633 /* for uv, can divide by zero */
634 const float facxi = (maxxi != minxi) ? 1.0f / (maxxi - minxi) : 0.0f;
635 const float facyi = (maxyi != minyi) ? 1.0f / (maxyi - minyi) : 0.0f;
636 int tot = 0;
637 const int hnum = ((roundboxalign & (CNR_TOP_LEFT | CNR_TOP_RIGHT)) ==
639 (roundboxalign & (CNR_BOTTOM_RIGHT | CNR_BOTTOM_LEFT)) ==
641 1 :
642 2;
643 const int vnum = ((roundboxalign & (CNR_TOP_LEFT | CNR_BOTTOM_LEFT)) ==
645 (roundboxalign & (CNR_TOP_RIGHT | CNR_BOTTOM_RIGHT)) ==
647 1 :
648 2;
649
650 const int minsize = min_ii(BLI_rcti_size_x(rect) * hnum, BLI_rcti_size_y(rect) * vnum);
651
652 if (2.0f * rad > minsize) {
653 rad = 0.5f * minsize;
654 }
655
656 if (2.0f * (radi + 1.0f) > minsize) {
657 radi = 0.5f * minsize - U.pixelsize;
658 }
659
660 wt->uniform_params.rad = rad;
661 wt->uniform_params.radi = radi;
662 wt->uniform_params.facxi = facxi;
663 wt->uniform_params.facyi = facyi;
664 wt->uniform_params.round_corners[0] = (roundboxalign & CNR_BOTTOM_LEFT) ? 1.0f : 0.0f;
665 wt->uniform_params.round_corners[1] = (roundboxalign & CNR_BOTTOM_RIGHT) ? 1.0f : 0.0f;
666 wt->uniform_params.round_corners[2] = (roundboxalign & CNR_TOP_RIGHT) ? 1.0f : 0.0f;
667 wt->uniform_params.round_corners[3] = (roundboxalign & CNR_TOP_LEFT) ? 1.0f : 0.0f;
669 BLI_rctf_init(&wt->uniform_params.recti, minxi, maxxi, minyi, maxyi);
670
671 /* Multiply by radius. */
672 for (int a = 0; a < WIDGET_CURVE_RESOLU; a++) {
673 veci[a][0] = radi * cornervec[a][0];
674 veci[a][1] = radi * cornervec[a][1];
675 vec[a][0] = rad * cornervec[a][0];
676 vec[a][1] = rad * cornervec[a][1];
677 }
678
679 /* corner left-bottom */
680 if (roundboxalign & CNR_BOTTOM_LEFT) {
681 for (int a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
682 wt->inner_v[tot][0] = minxi + veci[a][1];
683 wt->inner_v[tot][1] = minyi + radi - veci[a][0];
684
685 wt->outer_v[tot][0] = minx + vec[a][1];
686 wt->outer_v[tot][1] = miny + rad - vec[a][0];
687
688 wt->inner_uv[tot][0] = facxi * (wt->inner_v[tot][0] - minxi);
689 wt->inner_uv[tot][1] = facyi * (wt->inner_v[tot][1] - minyi);
690 }
691 }
692 else {
693 wt->inner_v[tot][0] = minxi;
694 wt->inner_v[tot][1] = minyi;
695
696 wt->outer_v[tot][0] = minx;
697 wt->outer_v[tot][1] = miny;
698
699 wt->inner_uv[tot][0] = 0.0f;
700 wt->inner_uv[tot][1] = 0.0f;
701
702 tot++;
703 }
704
705 /* corner right-bottom */
706 if (roundboxalign & CNR_BOTTOM_RIGHT) {
707 for (int a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
708 wt->inner_v[tot][0] = maxxi - radi + veci[a][0];
709 wt->inner_v[tot][1] = minyi + veci[a][1];
710
711 wt->outer_v[tot][0] = maxx - rad + vec[a][0];
712 wt->outer_v[tot][1] = miny + vec[a][1];
713
714 wt->inner_uv[tot][0] = facxi * (wt->inner_v[tot][0] - minxi);
715 wt->inner_uv[tot][1] = facyi * (wt->inner_v[tot][1] - minyi);
716 }
717 }
718 else {
719 wt->inner_v[tot][0] = maxxi;
720 wt->inner_v[tot][1] = minyi;
721
722 wt->outer_v[tot][0] = maxx;
723 wt->outer_v[tot][1] = miny;
724
725 wt->inner_uv[tot][0] = 1.0f;
726 wt->inner_uv[tot][1] = 0.0f;
727
728 tot++;
729 }
730
731 wt->halfwayvert = tot;
732
733 /* corner right-top */
734 if (roundboxalign & CNR_TOP_RIGHT) {
735 for (int a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
736 wt->inner_v[tot][0] = maxxi - veci[a][1];
737 wt->inner_v[tot][1] = maxyi - radi + veci[a][0];
738
739 wt->outer_v[tot][0] = maxx - vec[a][1];
740 wt->outer_v[tot][1] = maxy - rad + vec[a][0];
741
742 wt->inner_uv[tot][0] = facxi * (wt->inner_v[tot][0] - minxi);
743 wt->inner_uv[tot][1] = facyi * (wt->inner_v[tot][1] - minyi);
744 }
745 }
746 else {
747 wt->inner_v[tot][0] = maxxi;
748 wt->inner_v[tot][1] = maxyi;
749
750 wt->outer_v[tot][0] = maxx;
751 wt->outer_v[tot][1] = maxy;
752
753 wt->inner_uv[tot][0] = 1.0f;
754 wt->inner_uv[tot][1] = 1.0f;
755
756 tot++;
757 }
758
759 /* corner left-top */
760 if (roundboxalign & CNR_TOP_LEFT) {
761 for (int a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
762 wt->inner_v[tot][0] = minxi + radi - veci[a][0];
763 wt->inner_v[tot][1] = maxyi - veci[a][1];
764
765 wt->outer_v[tot][0] = minx + rad - vec[a][0];
766 wt->outer_v[tot][1] = maxy - vec[a][1];
767
768 wt->inner_uv[tot][0] = facxi * (wt->inner_v[tot][0] - minxi);
769 wt->inner_uv[tot][1] = facyi * (wt->inner_v[tot][1] - minyi);
770 }
771 }
772 else {
773 wt->inner_v[tot][0] = minxi;
774 wt->inner_v[tot][1] = maxyi;
775
776 wt->outer_v[tot][0] = minx;
777 wt->outer_v[tot][1] = maxy;
778
779 wt->inner_uv[tot][0] = 0.0f;
780 wt->inner_uv[tot][1] = 1.0f;
781
782 tot++;
783 }
784
786
787 wt->totvert = tot;
788}
789
790static void round_box_edges(WidgetBase *wt, int roundboxalign, const rcti *rect, float rad)
791{
792 round_box__edges(wt, roundboxalign, rect, rad, rad - U.pixelsize);
793}
794
796
797/* -------------------------------------------------------------------- */
800
801/* based on button rect, return scaled array of triangles */
803 const rcti *rect,
804 float triasize,
805 char where,
806 /* input data */
807 const float verts[][2],
808 const int verts_tot,
809 const uint tris[][3],
810 const int tris_tot)
811{
812 float sizex, sizey;
813 int i1 = 0, i2 = 1;
814
815 const float minsize = ELEM(where, 'r', 'l') ? BLI_rcti_size_y(rect) : BLI_rcti_size_x(rect);
816
817 /* center position and size */
818 float centx = float(rect->xmin) + 0.4f * minsize;
819 float centy = float(rect->ymin) + 0.5f * minsize;
820 tria->size = sizex = sizey = -0.5f * triasize * minsize;
821
822 if (where == 'r') {
823 centx = float(rect->xmax) - 0.4f * minsize;
824 sizex = -sizex;
825 }
826 else if (where == 't') {
827 centx = float(rect->xmin) + 0.5f * minsize;
828 centy = float(rect->ymax) - 0.5f * minsize;
829 sizey = -sizey;
830 i2 = 0;
831 i1 = 1;
832 }
833 else if (where == 'b') {
834 centx = float(rect->xmin) + 0.5f * minsize;
835 sizex = -sizex;
836 i2 = 0;
837 i1 = 1;
838 }
839
840 for (int a = 0; a < verts_tot; a++) {
841 tria->vec[a][0] = sizex * verts[a][i1] + centx;
842 tria->vec[a][1] = sizey * verts[a][i2] + centy;
843 }
844
845 tria->center[0] = centx;
846 tria->center[1] = centy;
847
848 tria->tot = tris_tot;
849 tria->index = tris;
850}
851
853 const rcti *rect,
854 float triasize,
855 char where)
856{
859 rect,
860 triasize,
861 where,
866}
867
869 const rcti *rect,
870 float triasize,
871 char where)
872{
874 /* With the current changes to use batches for widget drawing, the code
875 * below is doing almost nothing effectively. 'where' doesn't work either,
876 * shader is currently hardcoded to work for the button triangle pointing
877 * at the lower right. The same limitation applies to other trias as well.
878 * XXX Should be addressed. */
880 rect,
881 triasize,
882 where,
887}
888
890 const rcti *rect,
891 float triasize,
892 char where)
893{
896 rect,
897 triasize,
898 where,
903}
904
906 uint col,
907 GPUPrimType mode,
908 const float quads_pos[WIDGET_SIZE_MAX][2],
909 const uchar quads_col[WIDGET_SIZE_MAX][4],
910 uint totvert)
911{
912 immBegin(mode, totvert);
913 for (int i = 0; i < totvert; i++) {
914 if (quads_col) {
915 immAttr4ubv(col, quads_col[i]);
916 }
917 immVertex2fv(pos, quads_pos[i]);
918 }
919 immEnd();
920}
921
923{
924 const float width = BLI_rcti_size_x(rect);
925 const float height = BLI_rcti_size_y(rect);
926 if ((width / height) < 0.5f) {
927 /* Too narrow to fit. */
928 return;
929 }
930 float centx, centy, size;
931
932 tria->type = ROUNDBOX_TRIA_MENU;
933
934 /* Center position and size. */
935 tria->center[0] = centx = rect->xmin + 0.52f * BLI_rcti_size_y(rect);
936 tria->center[1] = centy = rect->ymin + 0.52f * BLI_rcti_size_y(rect);
937 tria->size = size = 0.4f * height;
938
939 if (width > height * 1.1f) {
940 /* For wider buttons align tighter to the right. */
941 tria->center[0] = centx = rect->xmax - 0.32f * height;
942 }
943
944 for (int a = 0; a < 6; a++) {
945 tria->vec[a][0] = size * g_shape_preset_menu_arrow_vert[a][0] + centx;
946 tria->vec[a][1] = size * g_shape_preset_menu_arrow_vert[a][1] + centy;
947 }
948
949 tria->tot = 2;
951}
952
954{
955 float centx, centy, size;
956
958
959 /* Center position and size. */
960 tria->center[0] = centx = rect->xmin + 0.5f * BLI_rcti_size_y(rect);
961 tria->center[1] = centy = rect->ymin + 0.5f * BLI_rcti_size_y(rect);
962 tria->size = size = 0.5f * BLI_rcti_size_y(rect);
963
964 for (int a = 0; a < 6; a++) {
965 tria->vec[a][0] = size * g_shape_preset_checkmark_vert[a][0] + centx;
966 tria->vec[a][1] = size * g_shape_preset_checkmark_vert[a][1] + centy;
967 }
968
969 tria->tot = 4;
971}
972
974{
975 tria->type = ROUNDBOX_TRIA_DASH;
976
977 /* Center position and size. */
978 tria->center[0] = rect->xmin + 0.5f * BLI_rcti_size_y(rect);
979 tria->center[1] = rect->ymin + 0.5f * BLI_rcti_size_y(rect);
980 tria->size = 0.5f * BLI_rcti_size_y(rect);
981}
982
984
985/* -------------------------------------------------------------------- */
988
989/* prepares shade colors */
990static void shadecolors4(
991 const uchar *color, short shadetop, short shadedown, uchar r_coltop[4], uchar r_coldown[4])
992{
993 r_coltop[0] = std::clamp(color[0] + shadetop, 0, 255);
994 r_coltop[1] = std::clamp(color[1] + shadetop, 0, 255);
995 r_coltop[2] = std::clamp(color[2] + shadetop, 0, 255);
996 r_coltop[3] = color[3];
997
998 r_coldown[0] = std::clamp(color[0] + shadedown, 0, 255);
999 r_coldown[1] = std::clamp(color[1] + shadedown, 0, 255);
1000 r_coldown[2] = std::clamp(color[2] + shadedown, 0, 255);
1001 r_coldown[3] = color[3];
1002}
1003
1005 const int totvert,
1006 float triangle_strip[WIDGET_SIZE_MAX * 2 + 2][2])
1007{
1008 int a;
1009 for (a = 0; a < totvert; a++) {
1010 copy_v2_v2(triangle_strip[a * 2], wtb->outer_v[a]);
1011 copy_v2_v2(triangle_strip[a * 2 + 1], wtb->inner_v[a]);
1012 }
1013 copy_v2_v2(triangle_strip[a * 2], wtb->outer_v[0]);
1014 copy_v2_v2(triangle_strip[a * 2 + 1], wtb->inner_v[0]);
1015}
1016
1017static void widgetbase_outline(WidgetBase *wtb, uint pos)
1018{
1019 float triangle_strip[WIDGET_SIZE_MAX * 2 + 2][2]; /* + 2 because the last pair is wrapped */
1020 widget_verts_to_triangle_strip(wtb, wtb->totvert, triangle_strip);
1021
1023 pos, 0, GPU_PRIM_TRI_STRIP, triangle_strip, nullptr, wtb->totvert * 2 + 2);
1024}
1025
1027 const bool alpha_check,
1028 const float discard_factor)
1029{
1030 if (alpha_check) {
1031 wtb->uniform_params.alpha_discard = -discard_factor;
1032 }
1033 else {
1034 wtb->uniform_params.alpha_discard = discard_factor;
1035 }
1036}
1037
1038static void widgetbase_set_uniform_alpha_check(WidgetBase *wtb, const bool alpha_check)
1039{
1040 const float discard_factor = fabs(wtb->uniform_params.alpha_discard);
1041 widgetbase_set_uniform_alpha_discard(wtb, alpha_check, discard_factor);
1042}
1043
1044static void widgetbase_set_uniform_discard_factor(WidgetBase *wtb, const float discard_factor)
1045{
1046 const bool alpha_check = wtb->uniform_params.alpha_discard < 0.0f;
1047 widgetbase_set_uniform_alpha_discard(wtb, alpha_check, discard_factor);
1048}
1049
1051 const uchar *col1,
1052 const uchar *col2,
1053 const uchar *outline,
1054 const uchar *emboss,
1055 const uchar *tria)
1056{
1057 rgba_float_args_set_ch(wtb->uniform_params.color_inner1, col1[0], col1[1], col1[2], col1[3]);
1058 rgba_float_args_set_ch(wtb->uniform_params.color_inner2, col2[0], col2[1], col2[2], col2[3]);
1060 wtb->uniform_params.color_outline, outline[0], outline[1], outline[2], outline[3]);
1062 wtb->uniform_params.color_emboss, emboss[0], emboss[1], emboss[2], emboss[3]);
1063 rgba_float_args_set_ch(wtb->uniform_params.color_tria, tria[0], tria[1], tria[2], tria[3]);
1064}
1065
1067
1068/* -------------------------------------------------------------------- */
1071
1072/* keep in sync with shader */
1073#define MAX_WIDGET_BASE_BATCH 6
1074#define MAX_WIDGET_PARAMETERS 12
1075
1076static struct {
1078 int count;
1079 bool enabled;
1081
1083{
1084 const float checker_params[3] = {
1085 UI_ALPHA_CHECKER_DARK / 255.0f, UI_ALPHA_CHECKER_LIGHT / 255.0f, 8.0f};
1086
1087 if (g_widget_base_batch.count == 0) {
1088 return;
1089 }
1090
1091 gpu::Batch *batch = batch_roundbox_widget_get();
1092 if (g_widget_base_batch.count == 1) {
1093 /* draw single */
1096 "parameters",
1098 (const float (*)[4])g_widget_base_batch.params);
1099 GPU_batch_uniform_3fv(batch, "checkerColorAndSize", checker_params);
1100 GPU_batch_draw(batch);
1101 }
1102 else {
1105 "parameters_inst",
1107 (float (*)[4])g_widget_base_batch.params);
1108 GPU_batch_uniform_3fv(batch, "checkerColorAndSize", checker_params);
1110 }
1111 g_widget_base_batch.count = 0;
1112}
1113
1115{
1116 BLI_assert(g_widget_base_batch.enabled == false);
1117 g_widget_base_batch.enabled = true;
1118}
1119
1121{
1122 BLI_assert(g_widget_base_batch.enabled == true);
1123 g_widget_base_batch.enabled = false;
1124
1126
1128
1130}
1131
1133{
1134 wtb->uniform_params.tria_type = wtb->tria1.type;
1135 wtb->uniform_params.tria1_size = wtb->tria1.size;
1136 wtb->uniform_params.tria2_size = wtb->tria2.size;
1139
1140 if (g_widget_base_batch.enabled) {
1142 g_widget_base_batch.count++;
1143
1146 }
1147 }
1148 else {
1149 const float checker_params[3] = {
1150 UI_ALPHA_CHECKER_DARK / 255.0f, UI_ALPHA_CHECKER_LIGHT / 255.0f, 8.0f};
1151 /* draw single */
1152 gpu::Batch *batch = batch_roundbox_widget_get();
1155 batch, "parameters", MAX_WIDGET_PARAMETERS, (float (*)[4]) & wtb->uniform_params);
1156 GPU_batch_uniform_3fv(batch, "checkerColorAndSize", checker_params);
1157 GPU_batch_draw(batch);
1158 }
1159}
1160
1161static void widgetbase_draw(WidgetBase *wtb, const uiWidgetColors *wcol)
1162{
1163 uchar inner_col1[4] = {0};
1164 uchar inner_col2[4] = {0};
1165 uchar emboss_col[4] = {0};
1166 uchar outline_col[4] = {0};
1167 uchar tria_col[4] = {0};
1168
1169 /* backdrop non AA */
1170 if (wtb->draw_inner) {
1171 if (wcol->shaded == 0) {
1172 /* simple fill */
1173 inner_col1[0] = inner_col2[0] = wcol->inner[0];
1174 inner_col1[1] = inner_col2[1] = wcol->inner[1];
1175 inner_col1[2] = inner_col2[2] = wcol->inner[2];
1176 inner_col1[3] = inner_col2[3] = wcol->inner[3];
1177 }
1178 else {
1179 /* gradient fill */
1180 shadecolors4(wcol->inner, wcol->shadetop, wcol->shadedown, inner_col1, inner_col2);
1181 }
1182 }
1183
1184 if (wtb->draw_outline) {
1185 outline_col[0] = wcol->outline[0];
1186 outline_col[1] = wcol->outline[1];
1187 outline_col[2] = wcol->outline[2];
1188 outline_col[3] = wcol->outline[3];
1189 }
1190
1191 /* Draw emboss only if the outline is not fully transparent, it looks like a gap otherwise. */
1192 if (wtb->draw_emboss && wcol->outline[3] != 0.0f) {
1194 }
1195
1196 if (wtb->tria1.type != ROUNDBOX_TRIA_NONE) {
1197 tria_col[0] = wcol->item[0];
1198 tria_col[1] = wcol->item[1];
1199 tria_col[2] = wcol->item[2];
1200 tria_col[3] = wcol->item[3];
1201 }
1202
1203 /* Draw everything in one draw-call. */
1204 if (inner_col1[3] || inner_col2[3] || outline_col[3] || emboss_col[3] || tria_col[3]) {
1206 wtb, inner_col1, inner_col2, outline_col, emboss_col, tria_col);
1207
1211 }
1212}
1213
1214/* widgetbase_draw variation for drawing colors, with full float color for wide gamut. */
1216 const uiWidgetColors *wcol,
1217 float color[4],
1218 bool show_alpha_checkers)
1219{
1220 const uchar unused_col[4] = {0};
1221 uchar emboss_col[4] = {0};
1222 uchar outline_col[4] = {0};
1223
1224 if (wtb->draw_outline) {
1225 outline_col[0] = wcol->outline[0];
1226 outline_col[1] = wcol->outline[1];
1227 outline_col[2] = wcol->outline[2];
1228 outline_col[3] = wcol->outline[3];
1229
1230 /* Emboss shadow if enabled, and inner and outline colors are not fully transparent. */
1231 if ((wtb->draw_emboss) && (wcol->inner[3] != 0.0f || wcol->outline[3] != 0.0f)) {
1233 }
1234 }
1235
1236 /* Draw everything in one draw-call. */
1237 widgetbase_set_uniform_alpha_check(wtb, show_alpha_checkers);
1239 wtb, unused_col, unused_col, outline_col, emboss_col, unused_col);
1242
1246}
1247
1249
1250/* -------------------------------------------------------------------- */
1253
1254#define UI_TEXT_CLIP_MARGIN (0.25f * U.widget_unit / but->block->aspect)
1255
1256#define PREVIEW_PAD (0.15f * UI_UNIT_X)
1257
1259{
1260 if (state->but_flag & (BUT_INACTIVE | BUT_DISABLED)) {
1261 if (state->but_flag & UI_SEARCH_FILTER_NO_MATCH) {
1262 return 0.25f;
1263 }
1264 return 0.5f;
1265 }
1266
1267 if (state->but_flag & UI_SEARCH_FILTER_NO_MATCH) {
1268 return 0.5f;
1269 }
1270
1271 return 1.0f;
1272}
1273
1275 const float aspect,
1276 const float alpha,
1277 const rcti *rect,
1278 const uchar mono_color[4])
1279{
1280 if (icon == ICON_NONE) {
1281 return;
1282 }
1283
1284 const float size = ICON_DEFAULT_HEIGHT / (aspect * UI_INV_SCALE_FAC);
1285
1286 if (size > 0) {
1287 const int x = BLI_rcti_cent_x(rect) - size / 2;
1288 const int y = BLI_rcti_cent_y(rect) - size / 2;
1289
1290 const bTheme *btheme = theme::theme_get();
1291 const float desaturate = 1.0 - btheme->tui.icon_saturation;
1292 uchar color[4] = {mono_color[0], mono_color[1], mono_color[2], mono_color[3]};
1293 const bool has_theme = icon_get_theme_color(int(icon), color);
1294 const bool outline = btheme->tui.icon_border_intensity > 0.0f && has_theme;
1295
1297 x, y, icon, aspect * UI_INV_SCALE_FAC, alpha, desaturate, color, outline, nullptr);
1298 }
1299}
1300
1307 float alpha,
1308 float aspect,
1309 const bool add_padding,
1310 const rcti *rect,
1311 const uchar mono_color[4])
1312{
1313 if (icon == ICON_NONE) {
1314 return;
1315 }
1316
1317 if (icon < BIFICONID_LAST_STATIC) {
1318 widget_draw_icon_centered(icon, aspect, alpha, rect, mono_color);
1319 return;
1320 }
1321
1322 const int w = BLI_rcti_size_x(rect);
1323 const int h = BLI_rcti_size_y(rect);
1324 const int size = std::min(w, h) - (add_padding ? (PREVIEW_PAD * 2) : 0);
1325
1326 if (size > 0) {
1327 const int x = rect->xmin + w / 2 - size / 2;
1328 const int y = rect->ymin + h / 2 - size / 2;
1329
1330 icon_draw_preview(x, y, icon, 1.0f, alpha, size);
1331 }
1332}
1333
1334static int but_draw_menu_icon(const Button *but)
1335{
1336 return (but->flag & BUT_ICON_SUBMENU) && (but->emboss == EmbossType::Pulldown);
1337}
1338
1339/* icons have been standardized... and this call draws in untransformed coordinates */
1340
1342 const Button *but, BIFIconID icon, float alpha, const rcti *rect, const uchar mono_color[4])
1343{
1344 if (but->flag & BUT_ICON_PREVIEW) {
1347 alpha,
1348 but->block->aspect,
1350 rect,
1351 mono_color);
1353 return;
1354 }
1355
1356 /* this icon doesn't need draw... */
1357 if (icon == ICON_BLANK1 && (but->flag & BUT_ICON_SUBMENU) == 0) {
1358 return;
1359 }
1360
1361 const float aspect = (1.0f / but->icon_scale) * but->block->aspect * UI_INV_SCALE_FAC;
1362 const float height = ICON_DEFAULT_HEIGHT / aspect;
1363 bool force_outline = false;
1364
1365 /* calculate blend color */
1366 if (ELEM(but->type,
1371 {
1372 if (but->flag & UI_SELECT) {
1373 /* pass */
1374 }
1375 else if (but->flag & UI_HOVER) {
1376 /* pass */
1377 }
1378 else {
1379 alpha = 0.75f;
1380 }
1381 }
1382 else if (but->type == ButtonType::Label) {
1383 /* extra feature allows more alpha blending */
1384 const auto *but_label = reinterpret_cast<const ButtonLabel *>(but);
1385 alpha *= but_label->alpha_factor;
1386 if (but_label->draw_icon_border) {
1387 force_outline = true;
1388 }
1389 }
1391 WidgetStateInfo state = {0};
1392 state.but_flag = but->flag;
1393 state.but_drawflag = but->drawflag;
1394 alpha *= widget_alpha_factor(&state);
1395 }
1396
1397 /* Dim the icon as its space is reduced to zero. */
1398 if (height > (rect->xmax - rect->xmin)) {
1399 alpha *= std::max(float(rect->xmax - rect->xmin) / height, 0.0f);
1400 }
1401
1403
1404 if (icon && icon != ICON_BLANK1) {
1405 const float ofs = 1.0f / aspect;
1406 float xs, ys;
1407
1408 if (but->drawflag & BUT_ICON_LEFT) {
1409 /* special case - icon_only pie buttons */
1410 if (block_is_pie_menu(but->block) &&
1411 !ELEM(but->type, ButtonType::Menu, ButtonType::Popover) && but->str.empty())
1412 {
1413 xs = rect->xmin + 2.0f * ofs;
1414 }
1415 else if (but->emboss == EmbossType::None || but->type == ButtonType::Label) {
1416 xs = rect->xmin + 2.0f * ofs;
1417 }
1418 else {
1419 xs = rect->xmin + 4.0f * ofs;
1420 }
1421 }
1422 else {
1423 xs = (rect->xmin + rect->xmax - height) / 2.0f;
1424 }
1425
1426 /* Align icon to the top. */
1427 if (button_label_is_multiline(but)) {
1428 ys = rect->ymax - height - 2.0f * ofs;
1429 }
1430 else {
1431 ys = (rect->ymin + rect->ymax - height) / 2.0f;
1432 }
1433
1434 /* force positions to integers, for zoom levels near 1. draws icons crisp. */
1435 if (aspect > 0.95f && aspect < 1.05f) {
1436 xs = roundf(xs);
1437 ys = roundf(ys);
1438 }
1439
1440 /* Get theme color. */
1441 uchar color[4] = {mono_color[0], mono_color[1], mono_color[2], mono_color[3]};
1442 const bTheme *btheme = theme::theme_get();
1443 /* Only use theme colors if the button doesn't override the color. */
1444 const bool has_theme = !but->col[3] && icon_get_theme_color(int(icon), color);
1445 const bool outline = force_outline || (btheme->tui.icon_border_intensity > 0.0f && has_theme);
1446
1447 /* to indicate draggable */
1448 if (button_drag_is_draggable(but) && (but->flag & UI_HOVER)) {
1449 icon_draw_ex(xs, ys, icon, aspect, 1.25f, 0.0f, color, outline, &but->icon_overlay_text);
1450 }
1451 else if (but->flag & (UI_HOVER | UI_SELECT | UI_SELECT_DRAW)) {
1452 icon_draw_ex(xs, ys, icon, aspect, alpha, 0.0f, color, outline, &but->icon_overlay_text);
1453 }
1454 else if (!((but->icon != ICON_NONE) && but_is_tool(but))) {
1455 if (has_theme) {
1456 alpha *= 0.8f;
1457 }
1458 icon_draw_ex(xs,
1459 ys,
1460 icon,
1461 aspect,
1462 alpha,
1463 0.0f,
1464 color,
1465 outline,
1466 &but->icon_overlay_text,
1467 but->drawflag & BUT_ICON_INVERT);
1468 }
1469 else {
1470 const float desaturate = 1.0 - btheme->tui.icon_saturation;
1472 xs, ys, icon, aspect, alpha, desaturate, color, outline, &but->icon_overlay_text);
1473 }
1474 }
1475
1477}
1478
1479static void widget_draw_submenu_tria(const Button *but,
1480 const rcti *rect,
1481 const uiWidgetColors *wcol)
1482{
1483 const float aspect = but->block->aspect * UI_INV_SCALE_FAC;
1484 const int tria_height = int(ICON_DEFAULT_HEIGHT / aspect);
1485 const int tria_width = int(ICON_DEFAULT_WIDTH / aspect) - 2 * U.pixelsize;
1486 const int xs = rect->xmax - tria_width;
1487 const int ys = (rect->ymin + rect->ymax - tria_height) / 2.0f;
1488
1489 float col[4];
1490 rgba_uchar_to_float(col, wcol->text);
1491 col[3] *= 0.8f;
1492
1493 rctf tria_rect;
1494 BLI_rctf_init(&tria_rect, xs, xs + tria_width, ys, ys + tria_height);
1495 BLI_rctf_scale(&tria_rect, 0.4f);
1496
1500 draw_anti_tria_rect(&tria_rect, 'h', col);
1501}
1502
1503static void text_clip_give_prev_off(Button *but, const char *str)
1504{
1505 const char *prev_utf8 = BLI_str_find_prev_char_utf8(str + but->ofs, str);
1506 const int bytes = str + but->ofs - prev_utf8;
1507
1508 but->ofs -= bytes;
1509}
1510
1511static void text_clip_give_next_off(Button *but, const char *str, const char *str_end)
1512{
1513 const char *next_utf8 = BLI_str_find_next_char_utf8(str + but->ofs, str_end);
1514 const int bytes = next_utf8 - (str + but->ofs);
1515
1516 but->ofs += bytes;
1517}
1518
1533static size_t text_shorten_next_template_var(char *str, size_t byte_position)
1534{
1535 const std::optional<bke::path_templates::ExpressionInfo> info =
1537 if (!info.has_value()) {
1538 return -1;
1539 }
1540
1541 const StringRef short_expression{BKE_TEMPLATE_EXPRESSION_ABBREVIATION};
1542
1543 /* Since we don't have control over the length of `str`, for now we just don't
1544 * substitute if it would grow the length of the string. This is a bit hacky,
1545 * and it means that 1 and 2-byte template expressions won't get substituted.
1546 *
1547 * In the future we can get a bit more involved and grow the string as needed,
1548 * and perhaps also verify that the substitution actually reduces the display
1549 * length of the string. */
1550 if (short_expression.size() > info->byte_range.size()) {
1551 return info->byte_range.one_after_last();
1552 }
1553
1554 std::memcpy(str + info->byte_range.first(), short_expression.data(), short_expression.size());
1555 std::memmove(str + info->byte_range.first() + short_expression.size(),
1556 str + info->byte_range.one_after_last(),
1557 strlen(str) + 1 - info->byte_range.one_after_last());
1558
1559 return info->byte_range.first() + short_expression.size();
1560}
1561
1576 const size_t split_offset,
1577 const bool shift_left)
1578{
1579 /* String patterns to avoid splitting when clipping text: they are either left
1580 * as-is or removed completely, never partially removed. */
1581 const StringRef no_split_strings[] = {
1583 };
1584
1585 for (const StringRef unit : no_split_strings) {
1586 /* Algorithm summary:
1587 * - We scan backwards to find the first character of the unsplittable pattern.
1588 * - If found, we scan forward to verify if there's a full match.
1589 * - If there's a full match, we move the split offset to be on one side or the other of the
1590 * unsplittable pattern.
1591 *
1592 * Note that we limit the scan range so that if a match is found, we know that it straddles the
1593 * split offset.
1594 */
1595 const int range_min = std::max(0, int(split_offset - unit.size() + 1));
1596 const int range_max = std::max(0, int(split_offset - 1));
1597 int match = -1;
1598 for (int i = range_max; i >= range_min; i--) {
1599 if (str.drop_prefix(i).startswith(unit)) {
1600 match = i;
1601 }
1602 }
1603
1604 if (match == -1) {
1605 continue;
1606 }
1607
1608 size_t new_offset = match;
1609 if (!shift_left) {
1610 new_offset += unit.size();
1611 }
1612
1613 return new_offset;
1614 }
1615
1616 return split_offset;
1617}
1618
1624static void text_clip_right_ex(const uiFontStyle *fstyle,
1625 char *str,
1626 const size_t str_maxncpy,
1627 const float okwidth,
1628 const char *sep,
1629 const int sep_len,
1630 const float sep_strwidth,
1631 size_t *r_final_len)
1632{
1633 BLI_assert(str[0]);
1634
1635 /* How many BYTES (not characters) of this UTF8 string can fit, along with appended ellipsis. */
1636 int l_end = BLF_width_to_strlen(
1637 fstyle->uifont_id, str, str_maxncpy, okwidth - sep_strwidth, nullptr);
1638 l_end = avoid_non_split_patterns(str, l_end, true);
1639
1640 if (l_end > 0) {
1641 StringRef trimmed_str = StringRef(str, l_end).trim_right();
1642 /* At least one character, so clip and add the ellipsis. */
1643 memcpy(str + trimmed_str.size(), sep, sep_len + 1); /* +1 for trailing '\0'. */
1644 if (r_final_len) {
1645 *r_final_len = trimmed_str.size() + sep_len;
1646 }
1647 }
1648 else {
1649 /* Otherwise fit as much as we can without adding an ellipsis. */
1650 l_end = BLF_width_to_strlen(fstyle->uifont_id, str, str_maxncpy, okwidth, nullptr);
1651 str[l_end] = '\0';
1652 if (r_final_len) {
1653 *r_final_len = size_t(l_end);
1654 }
1655 }
1656}
1657
1659 char *str,
1660 float okwidth,
1661 const float minwidth,
1662 const size_t str_maxncpy,
1663 const char rpart_sep,
1664 const bool clip_right_if_tight,
1665 const bool shorten_template_variables)
1666{
1667 BLI_assert(str[0]);
1668
1669 /* need to set this first */
1670 fontstyle_set(fstyle);
1671
1672 float strwidth = BLF_width(fstyle->uifont_id, str, str_maxncpy);
1673
1674 /* Shorten template variables. */
1675 if (shorten_template_variables) {
1676 size_t byte_position = 0;
1677 while ((okwidth > 0.0f) && (strwidth > okwidth)) {
1678 byte_position = text_shorten_next_template_var(str, byte_position);
1679 strwidth = BLF_width(fstyle->uifont_id, str, str_maxncpy);
1680 if (byte_position == -1) {
1681 break;
1682 }
1683 }
1684 }
1685
1686 if ((okwidth > 0.0f) && (strwidth > okwidth)) {
1687 const char sep[] = BLI_STR_UTF8_HORIZONTAL_ELLIPSIS;
1688 const int sep_len = sizeof(sep) - 1;
1689 const float sep_strwidth = BLF_width(fstyle->uifont_id, sep, sep_len + 1);
1690
1691 char *rpart = nullptr, rpart_buf[UI_MAX_DRAW_STR];
1692 float rpart_width = 0.0f;
1693 size_t rpart_len = 0;
1694 size_t final_lpart_len;
1695
1696 if (rpart_sep) {
1697 rpart = strrchr(str, rpart_sep);
1698
1699 if (rpart) {
1700 rpart = str + avoid_non_split_patterns(str, size_t(rpart - str), false);
1701 rpart_len = strlen(rpart);
1702 rpart_width = BLF_width(fstyle->uifont_id, rpart, rpart_len);
1703 okwidth -= rpart_width;
1704 strwidth -= rpart_width;
1705
1706 if (okwidth < 0.0f) {
1707 /* Not enough place for actual label, just display protected right part.
1708 * Here just for safety, should never happen in real life! */
1709 memmove(str, rpart, rpart_len + 1);
1710 rpart = nullptr;
1711 okwidth += rpart_width;
1712 strwidth = rpart_width;
1713 }
1714 }
1715 }
1716
1717 const float parts_strwidth = (okwidth - sep_strwidth) / 2.0f;
1718
1719 if (rpart) {
1720 STRNCPY(rpart_buf, rpart);
1721 *rpart = '\0';
1722 rpart = rpart_buf;
1723 }
1724
1725 size_t l_end = BLF_width_to_strlen(
1726 fstyle->uifont_id, str, str_maxncpy, parts_strwidth, nullptr);
1727 l_end = avoid_non_split_patterns(str, l_end, true);
1728 if (clip_right_if_tight &&
1729 (l_end < 10 || min_ff(parts_strwidth, strwidth - okwidth) < minwidth))
1730 {
1731 /* If we really have no place, or we would clip a very small piece of string in the middle,
1732 * only show start of string.
1733 */
1735 fstyle, str, str_maxncpy, okwidth, sep, sep_len, sep_strwidth, &final_lpart_len);
1736 }
1737 else {
1738 l_end = StringRef(str, l_end).trim_right().size();
1739 size_t r_offset, r_len;
1740 r_offset = BLF_width_to_rstrlen(
1741 fstyle->uifont_id, str, str_maxncpy, parts_strwidth, nullptr);
1742 r_offset = avoid_non_split_patterns(str, r_offset, false);
1743 const StringRef r_trimmed = StringRef(str + r_offset).trim_left();
1744 r_len = r_trimmed.size();
1745
1746 if (l_end + sep_len + r_len + 1 + rpart_len > str_maxncpy) {
1747 /* Corner case, the str already takes all available mem,
1748 * and the ellipsis chars would actually add more chars.
1749 * Better to just trim one or two letters to the right in this case...
1750 * NOTE: with a single-char ellipsis, this should never happen! But better be safe
1751 * here...
1752 */
1754 fstyle, str, str_maxncpy, okwidth, sep, sep_len, sep_strwidth, &final_lpart_len);
1755 }
1756 else {
1757 memmove(str + l_end + sep_len, r_trimmed.begin(), r_len);
1758 memcpy(str + l_end, sep, sep_len);
1759 final_lpart_len = size_t(l_end + sep_len + r_len);
1760 /* Set string null terminator. */
1761 str[final_lpart_len] = '\0';
1762
1763/* Seems like this was only needed because of an error in #BLF_width_to_rstrlen(), not because of
1764 * integer imprecision. See PR #135239. */
1765#if 0
1766 while (BLF_width(fstyle->uifont_id, str, str_maxncpy) > okwidth) {
1767 /* This will happen because a lot of string width processing is done in integer pixels,
1768 * which can introduce a rather high error in the end (about 2 pixels or so).
1769 * Only one char removal shall ever be needed in real-life situation... */
1770 r_len--;
1771 final_lpart_len--;
1772 char *c = str + l_end + sep_len;
1773 memmove(c, c + 1, r_len);
1774 }
1775#endif
1776 }
1777 }
1778
1779 if (rpart) {
1780 /* Add back preserved right part to our shorten str. */
1781 memcpy(str + final_lpart_len, rpart, rpart_len + 1); /* +1 for trailing '\0'. */
1782 okwidth += rpart_width;
1783 }
1784
1785 strwidth = BLF_width(fstyle->uifont_id, str, str_maxncpy);
1786 }
1787
1788 /* The following assert is meant to catch code changes that break this function's result, but
1789 * some wriggle room is fine and needed. Just a couple pixels for large sizes and with some
1790 * settings like "Full" hinting which can move features both left and right a pixel. We could
1791 * probably reduce this to one pixel if we consolidate text output with length measuring. But
1792 * our text string lengths include the last character's right-side bearing anyway, so a string
1793 * can be longer by that amount and still fit visibly in the required space. */
1794 BLI_assert((strwidth <= (okwidth + 2)) || (okwidth <= 0.0f) ||
1795 /* TODO: proper handling of non UTF8 strings. */
1796 (BLI_str_utf8_invalid_byte(str, strlen(str)) != -1));
1797 UNUSED_VARS_NDEBUG(okwidth);
1798
1799 return strwidth;
1800}
1801
1802bool button_draw_as_link(const Button *button)
1803{
1804 return button->type == ButtonType::But && static_cast<const ButtonPush *>(button)->draw_as_link;
1805}
1806
1810static void text_clip_middle(const uiFontStyle *fstyle, Button *but, const rcti *rect)
1811{
1812 /* No margin for labels! */
1813 const int border = (ELEM(but->type, ButtonType::Label, ButtonType::Menu, ButtonType::Popover) ||
1814 (button_draw_as_link(but) && !(but->flag & UI_HAS_ICON))) ?
1815 0 :
1816 int(UI_TEXT_CLIP_MARGIN + 0.5f);
1817 const float okwidth = float(max_ii(BLI_rcti_size_x(rect) - border, 0));
1818 const float minwidth = UI_ICON_SIZE / but->block->aspect * 2.0f;
1819
1820 const bool clip_right_if_tight = true;
1821 const bool shorten_template_variables = but->rnaprop && (RNA_property_flag(but->rnaprop) &
1823
1824 but->ofs = 0;
1825 char new_drawstr[UI_MAX_DRAW_STR];
1826 STRNCPY(new_drawstr, but->drawstr.c_str());
1827 const size_t new_drawstr_maxncpy = sizeof(new_drawstr);
1828 but->strwidth = text_clip_middle_ex(fstyle,
1829 new_drawstr,
1830 okwidth,
1831 minwidth,
1832 new_drawstr_maxncpy,
1833 '\0',
1834 clip_right_if_tight,
1835 shorten_template_variables);
1836 but->drawstr = new_drawstr;
1837}
1838
1846 Button *but,
1847 const rcti *rect,
1848 const char rsep)
1849{
1850 /* No margin for labels! */
1851 const int border = (ELEM(but->type, ButtonType::Label, ButtonType::Menu, ButtonType::Popover) ||
1852 (button_draw_as_link(but) && !(but->flag & UI_HAS_ICON))) ?
1853 0 :
1854 int(UI_TEXT_CLIP_MARGIN + 0.5f);
1855 const float okwidth = float(max_ii(BLI_rcti_size_x(rect) - border, 0));
1856 const float minwidth = UI_ICON_SIZE / but->block->aspect * 2.0f;
1857
1858 but->ofs = 0;
1859 char new_drawstr[UI_MAX_DRAW_STR];
1860 STRNCPY(new_drawstr, but->drawstr.c_str());
1861 const size_t new_drawstr_maxncpy = sizeof(new_drawstr);
1863 fstyle, new_drawstr, okwidth, minwidth, new_drawstr_maxncpy, rsep);
1864 but->drawstr = new_drawstr;
1865}
1866
1868 const char *str,
1869 char *clipped_str_buf,
1870 const size_t clipped_str_buf_maxncpy,
1871 const float max_line_width,
1872 const int max_lines)
1873{
1874 BLI_assert(max_lines > 0);
1875
1876 const Vector<StringRef> lines = BLF_string_wrap(
1878
1879 if (lines.size() <= max_lines) {
1880 return lines;
1881 }
1882
1883 Vector<StringRef> clipped_lines;
1884 clipped_lines.reserve(max_lines);
1885
1886 if (max_lines == 1) {
1887 BLI_strncpy(clipped_str_buf, str, clipped_str_buf_maxncpy);
1888
1890 fstyle, clipped_str_buf, max_line_width, UI_ICON_SIZE, clipped_str_buf_maxncpy, '\0');
1891 clipped_lines.append(clipped_str_buf);
1892 return clipped_lines;
1893 }
1894 if (max_lines == 2) {
1895 clipped_lines.append(lines[0]);
1896 BLI_strncpy(clipped_str_buf, str + lines[0].size(), clipped_str_buf_maxncpy);
1897 text_clip_middle_ex(fstyle,
1898 clipped_str_buf,
1899 max_line_width,
1901 clipped_str_buf_maxncpy,
1902 '\0',
1903 false);
1904 clipped_lines.append(clipped_str_buf);
1905 return clipped_lines;
1906 }
1907
1908 /* The line in the middle that will get the "..." (rounded upwards, so will use the first line of
1909 * the second half if the number of lines is even) */
1910 const int middle_index = max_lines / 2;
1911
1912 /* Take the lines until the middle line with the "..." as is. */
1913 for (int i = 0; i < middle_index; i++) {
1914 clipped_lines.append(lines[i]);
1915 }
1916
1917 /* Clip the middle of the middle line. */
1918 {
1919 BLI_strncpy(clipped_str_buf, lines[middle_index].data(), clipped_str_buf_maxncpy);
1920 text_clip_middle_ex(fstyle,
1921 clipped_str_buf,
1922 max_line_width,
1924 clipped_str_buf_maxncpy,
1925 '\0',
1926 false);
1927 clipped_lines.append(clipped_str_buf);
1928 }
1929
1930 /* All remaining lines should be completely filled, including the last one. So fill lines
1931 * backwards, and append them to #clipped_lines in the correct order afterwards. */
1932 if ((middle_index + 1) < max_lines) {
1933 const char *remaining = lines[middle_index + 1].data();
1934 size_t remaining_len = strlen(remaining);
1935 std::list<StringRef> last_lines;
1936 for (int i = 0; i < max_lines - (middle_index + 1) && remaining_len; i++) {
1937 size_t offset = BLF_width_to_rstrlen(
1938 fstyle->uifont_id, remaining, remaining_len, max_line_width, nullptr);
1939 size_t line_len = remaining_len - offset;
1940 last_lines.emplace_front(remaining + offset, int64_t(line_len));
1941 remaining_len = offset;
1942 }
1943
1944 for (StringRef line : last_lines) {
1945 clipped_lines.append(line);
1946 }
1947 }
1948
1949 return clipped_lines;
1950}
1951
1955static void text_clip_cursor(const uiFontStyle *fstyle, Button *but, const rcti *rect)
1956{
1957 /* Rect already includes text padding, no need for extra margin. */
1958 const int okwidth = BLI_rcti_size_x(rect);
1959
1960 BLI_assert(but->editstr && but->pos >= 0);
1961
1962 /* need to set this first */
1963 fontstyle_set(fstyle);
1964
1965 /* Shift text left until caret is visible. */
1966 but->ofs = std::min(but->ofs, but->pos);
1967
1968 /* String is small enough to not require clipping. */
1969 if (BLF_width(fstyle->uifont_id, but->editstr, INT_MAX) <= okwidth) {
1970 but->ofs = 0;
1971 return;
1972 }
1973
1974 /* Pixel width of visible string fragment. */
1975 but->strwidth = BLF_width(fstyle->uifont_id, but->editstr + but->ofs, INT_MAX);
1976
1977 const int editstr_len = strlen(but->editstr);
1978 int len = editstr_len;
1979
1980 /* Shift text right to fill available space. */
1981 while (but->strwidth < okwidth && but->ofs > 0) {
1983 but->strwidth = BLF_width(fstyle->uifont_id, but->editstr + but->ofs, len - but->ofs);
1984 }
1985
1986 /* Shift text left until caret is visible. */
1987 if (but->strwidth > okwidth) {
1988 while (but->strwidth > okwidth) {
1989 float caret_x;
1990
1991 /* Cursor position relative to text start. */
1992 caret_x = BLF_width(fstyle->uifont_id, but->editstr + but->ofs, (but->pos - but->ofs));
1993
1994 /* Caret is too far right, shift text left. */
1995 if (caret_x > okwidth - 20) {
1996 text_clip_give_next_off(but, but->editstr, but->editstr + editstr_len);
1997 }
1998 else {
1999 /* Caret is too far left, shift text right. */
2000 if (caret_x < 20 && but->ofs > 0) {
2002 }
2003 /* String fragment is too wide, trim end. */
2006 }
2007
2008 but->strwidth = BLF_width(fstyle->uifont_id, but->editstr + but->ofs, len - but->ofs);
2009
2010 if (but->strwidth < 10) {
2011 break;
2012 }
2013 }
2014 }
2015}
2016
2022static void text_clip_right_label(const uiFontStyle *fstyle, Button *but, const rcti *rect)
2023{
2024 const int border = UI_TEXT_CLIP_MARGIN + 1;
2025 const int okwidth = max_ii(BLI_rcti_size_x(rect) - border, 0);
2026
2027 int drawstr_len = but->drawstr.size();
2028 char new_drawstr[UI_MAX_DRAW_STR];
2029 STRNCPY(new_drawstr, but->drawstr.c_str());
2030
2031 const char *cpend = new_drawstr + drawstr_len;
2032
2033 /* need to set this first */
2034 fontstyle_set(fstyle);
2035
2036 /* Clear stale edit scroll offset so numeric text is not scrolled. See #157999. */
2037 but->ofs = 0;
2038 but->strwidth = BLF_width(fstyle->uifont_id, new_drawstr, drawstr_len);
2039
2040 /* The string already fits, so do nothing. */
2041 if (but->strwidth <= okwidth) {
2042 return;
2043 }
2044
2045 const char sep[] = BLI_STR_UTF8_HORIZONTAL_ELLIPSIS;
2046 const int sep_len = sizeof(sep) - 1;
2047 const float sep_strwidth = BLF_width(fstyle->uifont_id, sep, sep_len + 1);
2048
2049 /* Assume the string will have an ellipsis for initial tests. */
2050 but->strwidth += sep_strwidth;
2051
2052 /* First shorten number-buttons eg,
2053 * Translucency: 0.000
2054 * becomes
2055 * Trans: 0.000
2056 */
2057
2058 /* find the space after ':' separator */
2059 char *cpoin = strrchr(new_drawstr, ':');
2060
2061 if (cpoin && (cpoin < cpend - 2)) {
2062 char *cp2 = cpoin;
2063
2064 /* chop off the leading text, starting from the right */
2065 while (but->strwidth > okwidth && cp2 > new_drawstr) {
2066 const char *prev_utf8 = BLI_str_find_prev_char_utf8(cp2, new_drawstr);
2067 const int bytes = cp2 - prev_utf8;
2068
2069 /* shift the text after and including cp2 back by 1 char,
2070 * +1 to include null terminator */
2071 memmove(cp2 - bytes, cp2, drawstr_len + 1);
2072 cp2 -= bytes;
2073
2074 drawstr_len -= bytes;
2075
2076 but->strwidth = BLF_width(fstyle->uifont_id,
2077 new_drawstr + but->ofs,
2078 sizeof(new_drawstr) - but->ofs) +
2079 sep_strwidth;
2080 if (but->strwidth < sep_strwidth) {
2081 break;
2082 }
2083 }
2084
2085 /* after the leading text is gone, chop off the : and following space, with ofs */
2086 while ((but->strwidth > okwidth) && (but->ofs < 2)) {
2087 text_clip_give_next_off(but, new_drawstr, new_drawstr + drawstr_len);
2088 but->strwidth = BLF_width(
2089 fstyle->uifont_id, new_drawstr + but->ofs, sizeof(new_drawstr) - but->ofs);
2090 if (but->strwidth < 10) {
2091 break;
2092 }
2093 }
2094 }
2095
2096 /* Now just remove trailing chars */
2097 /* once the label's gone, chop off the least significant digits */
2098 if (but->strwidth > okwidth) {
2099 float strwidth;
2100 drawstr_len = BLF_width_to_strlen(fstyle->uifont_id,
2101 new_drawstr + but->ofs,
2102 drawstr_len - but->ofs,
2103 okwidth,
2104 &strwidth) +
2105 but->ofs;
2106 but->strwidth = strwidth;
2107 new_drawstr[drawstr_len] = 0;
2108 }
2109
2110 cpoin = strrchr(new_drawstr, ':');
2111 if (cpoin && (cpoin - new_drawstr > 0) && (drawstr_len < (sizeof(new_drawstr) - sep_len))) {
2112 /* We shortened the string and still have a colon, so insert ellipsis. */
2113 memmove(cpoin + sep_len, cpoin, cpend - cpoin);
2114 memcpy(cpoin, sep, sep_len);
2115 but->strwidth = BLF_width(
2116 fstyle->uifont_id, new_drawstr + but->ofs, sizeof(new_drawstr) - but->ofs);
2117 }
2118
2119 but->drawstr = new_drawstr;
2120}
2121
2122#ifdef WITH_INPUT_IME
2123static void widget_draw_text_ime_underline(const uiFontStyle *fstyle,
2124 const uiWidgetColors *wcol,
2125 const Button *but,
2126 const rcti *rect,
2127 const wmIMEData *ime_data,
2128 const char *drawstr,
2129 const int align_x_ofs)
2130{
2131 int ofs_x, width;
2132 int rect_x = BLI_rcti_size_x(rect);
2133 int sel_start = ime_data->sel_start, sel_end = ime_data->sel_end;
2134 float fcol[4];
2135
2136 if (drawstr[0] != 0) {
2137 if (but->pos >= but->ofs) {
2138 ofs_x = BLF_width(fstyle->uifont_id, drawstr + but->ofs, but->pos - but->ofs);
2139 }
2140 else {
2141 ofs_x = 0;
2142 }
2143
2144 width = BLF_width(
2145 fstyle->uifont_id, drawstr + but->ofs, ime_data->composite.size() + but->pos - but->ofs);
2146
2147 rgba_uchar_to_float(fcol, wcol->text);
2148 draw_text_underline(rect->xmin + ofs_x + align_x_ofs,
2149 rect->ymin + 6 * U.pixelsize,
2150 min_ii(width, rect_x - 2) - ofs_x,
2151 1,
2152 fcol);
2153
2154 /* draw the thick line */
2155 if (sel_start != -1 && sel_end != -1) {
2156 sel_end -= sel_start;
2157 sel_start += but->pos;
2158
2159 if (sel_start >= but->ofs) {
2160 ofs_x = BLF_width(fstyle->uifont_id, drawstr + but->ofs, sel_start - but->ofs);
2161 }
2162 else {
2163 ofs_x = 0;
2164 }
2165
2166 width = BLF_width(fstyle->uifont_id, drawstr + but->ofs, sel_end + sel_start - but->ofs);
2167
2168 draw_text_underline(rect->xmin + ofs_x + align_x_ofs,
2169 rect->ymin + 6 * U.pixelsize,
2170 min_ii(width, rect_x - 2) - ofs_x,
2171 2,
2172 fcol);
2173 }
2174 }
2175}
2176#endif /* WITH_INPUT_IME */
2177
2178static void widget_draw_textbox(const uiFontStyle *fstyle,
2179 const uiWidgetColors *wcol,
2180 Button *but,
2181 const rcti *button_rect)
2182{
2183
2184#ifdef WITH_INPUT_IME
2185 const wmIMEData *ime_data = button_ime_data_get(but);
2186#endif
2187 rcti rect = *button_rect;
2188 const int text_padding = button_text_padding(but);
2189 const int scrollbar_pad = round_fl_to_int(2.0f / but->block->aspect);
2190 const int caret_width = std::max(round_fl_to_int(2.0f * U.pixelsize), 1);
2191
2192 rect.xmax = std::max<int>(rect.xmin, rect.xmax - text_padding - scrollbar_pad);
2193
2194 rect.ymax -= textbox_vertical_padding() / but->block->aspect;
2195 rect.ymin += textbox_vertical_padding() / but->block->aspect;
2196
2198
2199 ButtonTextBox *textbox = static_cast<ButtonTextBox *>(but);
2200 const Vector<StringRef> lines = textbox_wrap_lines(textbox);
2201 const int visible_lines = textbox->visible_lines();
2202 fontstyle_set(fstyle);
2203
2204 const float line_height = BLI_rcti_size_y(&rect) / float(visible_lines);
2205
2206 const int scroll = textbox->line_scroll();
2207 const char *str = lines[0].begin();
2208
2209 int line_cursor = 0;
2210 int line_select_start = 0;
2211 int line_select_end = 0;
2212
2213 int but_pos = but->pos;
2214 int selsta = but->selsta, selend = but->selend;
2215#ifdef WITH_INPUT_IME
2216 /* If is IME compositing, move the cursor. */
2217 if (ime_data && !ime_data->composite.empty() && ime_data->cursor_pos != -1) {
2218 but_pos += ime_data->cursor_pos;
2219 /* Translate selection if the IME composite string is inserted before the selection. */
2220 if (selsta != selend) {
2221 if (but->pos == selsta) {
2222 selsta += ime_data->composite.size();
2223 selend += ime_data->composite.size();
2224 }
2225 }
2226 }
2227 int ime_line_start = 0;
2228 int ime_line_end = 0;
2229#endif
2230
2231 for (int i : lines.index_range()) {
2232 const char *line_bounds[] = {
2233 lines[i].begin(), i != lines.size() - 1 ? lines[i + 1].begin() : lines.last().end()};
2234 if (line_bounds[0] <= (str + but_pos) && (str + but_pos) <= line_bounds[1]) {
2235 line_cursor = i;
2236 }
2237 auto selection_line_bounds_get =
2238 [line_bounds, str, i](int start, int end, int &r_line_begin, int &r_line_end) {
2239 if (line_bounds[0] <= (str + start) && (str + start) <= line_bounds[1]) {
2240 r_line_begin = i;
2241 }
2242 if (line_bounds[0] <= (str + end) && (str + end) <= line_bounds[1]) {
2243 r_line_end = i;
2244 }
2245 };
2246 selection_line_bounds_get(selsta, selend, line_select_start, line_select_end);
2247#ifdef WITH_INPUT_IME
2248 if (ime_data) {
2249 selection_line_bounds_get(
2250 but->pos, but->pos + ime_data->composite.size(), ime_line_start, ime_line_end);
2251 }
2252#endif
2253 }
2254
2255 FontStyleAlign align;
2256 if (but->editstr || (but->drawflag & BUT_TEXT_LEFT)) {
2257 align = UI_STYLE_TEXT_LEFT;
2258 }
2259 else if (but->drawflag & BUT_TEXT_RIGHT) {
2260 align = UI_STYLE_TEXT_RIGHT;
2261 }
2262 else {
2263 align = UI_STYLE_TEXT_CENTER;
2264 }
2269
2270 int scissor[4];
2271 GPU_scissor_get(scissor);
2272 {
2273 rcti scissor_rect = {scissor[0], scissor[0] + scissor[2], scissor[1], scissor[1] + scissor[3]};
2274 rcti scissor_textbox;
2275 scissor_textbox.xmin = rect.xmin - caret_width;
2276 scissor_textbox.xmax = scissor_textbox.xmin + BLI_rcti_size_x(&rect) + caret_width,
2277 scissor_textbox.ymin = rect.ymin;
2278 scissor_textbox.ymax = scissor_textbox.ymin + BLI_rcti_size_y(&rect);
2279 BLI_rcti_isect(&scissor_rect, &scissor_textbox, &scissor_textbox);
2280 /* Text-box text isn't clipped, apply scissors to avoid text overflowing the scrollbar. */
2281 GPU_scissor(scissor_textbox.xmin,
2282 scissor_textbox.ymin,
2283 BLI_rcti_size_x(&scissor_textbox),
2284 BLI_rcti_size_y(&scissor_textbox));
2285 }
2286
2287 /* Text button selection, cursor, composite underline. */
2288 if (but->editstr) {
2289
2290#ifdef WITH_INPUT_IME
2291 bool ime_reposition_window = false;
2292 int ime_win_x, ime_win_y;
2293#endif
2294 struct LineSelection {
2295 int line;
2296 const char *start;
2297 const char *end;
2298 };
2299 auto lines_selection_get =
2300 [str, &lines](int start, int end, int line_start, int line_end) -> Vector<LineSelection> {
2301 if (start == end) {
2302 return {};
2303 }
2304 Vector<LineSelection> selection = {};
2305
2306 const char *itr = str + start;
2307 for (int i = line_start; i <= line_end; i++) {
2308 /* Include line feed in selection draw. */
2309 const char *itr_end = std::min(
2310 str + end, i != lines.size() - 1 ? lines[i + 1].begin() : lines.last().end());
2311 selection.append({i, itr, itr_end});
2312 itr = itr_end;
2313 }
2314 return selection;
2315 };
2316 const Vector<LineSelection> lines_selection = lines_selection_get(
2317 selsta, selend, line_select_start, line_select_end);
2318 /* Text button selection. */
2319 for (const LineSelection &selection : lines_selection) {
2320 if (!(scroll <= selection.line && selection.line < visible_lines + scroll)) {
2321 continue;
2322 }
2323 /* We are drawing on top of widget bases. Flush cache. */
2326 const uint pos = GPU_vertformat_attr_add(
2327 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
2330 const StringRef line = lines[selection.line];
2332 fstyle->uifont_id,
2333 line.begin(),
2334 line.size(),
2335 std::max<int>(0, selection.start - line.begin()),
2336 selection.end - selection.start);
2337 for (const Bounds<int> &bounds : boxes) {
2338 const float y = rect.ymax - (line_height * float(selection.line - scroll));
2339 immRectf(pos,
2340 rect.xmin + bounds.min,
2341 y - line_height,
2342 std::min(rect.xmin + bounds.max, rect.xmax - 2),
2343 y);
2344 }
2347 }
2348#ifdef WITH_INPUT_IME
2349 /* IME candidate window uses selection position. */
2350 if (!ime_reposition_window && lines_selection.size() > 0) {
2351 ime_reposition_window = true;
2352 ime_win_x = rect.xmin;
2353 ime_win_y = rect.ymax -
2354 (line_height * (std::clamp(line_select_end, scroll, scroll + visible_lines - 1) -
2355 scroll + 1)) +
2356 3;
2357 }
2358#endif
2359
2360#ifdef WITH_INPUT_IME
2361 /* Composite underline. */
2362 const Vector<LineSelection> ime_underlying_selection = lines_selection_get(
2363 but->pos,
2364 but->pos + (ime_data ? ime_data->composite.size() : 0),
2365 ime_line_start,
2366 ime_line_end);
2367 float fcol[4];
2371 rgba_uchar_to_float(fcol, wcol->text);
2372 for (const LineSelection &underlying : ime_underlying_selection) {
2373 if (!(scroll <= underlying.line && underlying.line < visible_lines + scroll)) {
2374 continue;
2375 }
2376 const StringRef line = lines[underlying.line];
2378 fstyle->uifont_id,
2379 line.begin(),
2380 line.size(),
2381 std::max<int>(0, underlying.start - line.begin()),
2382 underlying.end - underlying.start);
2383 for (const Bounds<int> &bounds : boxes) {
2384 const int y = rect.ymax - (line_height * float(underlying.line - scroll + 1)) +
2385 6.0f * U.pixelsize;
2386 draw_text_underline(rect.xmin + bounds.min,
2387 y,
2388 std::min(bounds.max - bounds.min, rect.xmax - 2 - rect.xmin),
2389 1,
2390 fcol);
2391 }
2392 }
2393#endif
2394
2395 /* Draw text cursor (caret). */
2396 if (scroll <= line_cursor && line_cursor < scroll + visible_lines) {
2397 const int t = BLF_str_offset_to_cursor(fstyle->uifont_id,
2398 lines[line_cursor].begin(),
2399 lines[line_cursor].size(),
2400 but_pos - (lines[line_cursor].begin() - str),
2401 caret_width);
2402
2403 /* We are drawing on top of widget bases. Flush cache. */
2407
2408 const uint pos = GPU_vertformat_attr_add(
2409 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
2411
2413 const int y = rect.ymax - (line_height * (line_cursor - scroll));
2414 /* draw cursor */
2415 immRectf(pos, rect.xmin + t, y - line_height, rect.xmin + t + caret_width, y);
2416
2418#ifdef WITH_INPUT_IME
2419 /* IME candidate window uses cursor position. */
2420 if (!ime_reposition_window) {
2421 ime_reposition_window = true;
2422 ime_win_x = rect.xmin + t + 5;
2423 ime_win_y = rect.ymax -
2424 (line_height *
2425 (std::clamp(line_cursor, scroll, scroll + visible_lines - 1) - scroll + 1)) +
2426 3;
2427 }
2428#endif
2429 }
2430
2431#ifdef WITH_INPUT_IME
2432 /* IME cursor following. */
2433 if (ime_reposition_window) {
2434 button_ime_reposition(but, ime_win_x, ime_win_y);
2435 }
2436#endif
2437 }
2438 /* Draw text. */
2439 FontStyleDrawParams params{};
2440 params.align = align;
2441 params.word_clip = false;
2442 float ymax = rect.ymax;
2443
2444 uchar col[4];
2445 copy_v4_v4_uchar(col, wcol->text);
2446 uiFontStyle style = *fstyle;
2447 Vector<blender::StringRef> draw_lines = lines;
2448 if (textbox->wrap_cache->text.empty() && textbox->placeholder) {
2449 draw_lines = textbox_wrap_placeholder(textbox);
2450 style.shadow = 0;
2451 col[3] *= UI_INPUT_HINT_ALPHA;
2452 }
2453 for (const StringRef line : draw_lines.as_span().slice_safe(scroll, visible_lines)) {
2454 if (rect.xmin > button_rect->xmax - scrollbar_pad - text_padding) {
2455 break;
2456 }
2457 rect.ymax = ymax;
2458 ymax -= line_height;
2459 rect.ymin = ymax;
2461 &style, &rect, line.begin(), line.size(), col, &params, nullptr, nullptr, nullptr);
2462 }
2463
2468
2469 GPU_scissor(scissor[0], scissor[1], scissor[2], scissor[3]);
2470 rcti grip_rect = *button_rect;
2471 grip_rect.ymax = grip_rect.ymin + std::floor(textbox_grip_height() / but->block->aspect);
2472 grip_rect.xmin = grip_rect.xmax - text_padding - scrollbar_pad;
2473 /* Draw grip button if there is space enough. */
2474 if (BLI_rcti_isect(&grip_rect, button_rect, nullptr)) {
2476 ICON_GRIP_CORNER_BOTTOM_RIGHT, textbox->block->aspect, 1.0f, &grip_rect, wcol->text);
2477 }
2478
2479 if (textbox->last_total_lines <= visible_lines) {
2480 return;
2481 }
2482 /* Draw scrollbar. */
2483 rcti scroll_rect = *button_rect;
2484 BLI_rcti_pad(&scroll_rect, -scrollbar_pad, -scrollbar_pad);
2485 scroll_rect.xmin = scroll_rect.xmax - text_padding;
2486 scroll_rect.ymin += textbox_grip_height() / but->block->aspect;
2487
2488 rcti slider_rect = scroll_rect;
2489
2490 const float factor = float(scroll_rect.ymax - scroll_rect.ymin) / float(lines.size());
2491
2492 slider_rect.ymax -= std::ceil(factor * textbox->line_scroll());
2493 slider_rect.ymin = slider_rect.ymax - std::ceil(factor * visible_lines);
2494 if (BLI_rcti_size_y(&slider_rect) < (10.0f / but->block->aspect)) {
2495 float center = BLI_rcti_cent_y_fl(&slider_rect);
2496 slider_rect.ymin = center - (5.0f / but->block->aspect);
2497 slider_rect.ymax = center + (5.0f / but->block->aspect);
2498 }
2499 const int pad = slider_rect.ymax > scroll_rect.ymax ? -(slider_rect.ymax - scroll_rect.ymax) :
2500 slider_rect.ymin < scroll_rect.ymin ? (scroll_rect.ymin - slider_rect.ymin) :
2501 0;
2502 BLI_rcti_translate(&slider_rect, 0, pad);
2503 slider_rect.ymin = std::max(slider_rect.ymin, scroll_rect.ymin);
2504 slider_rect.ymax = std::min(slider_rect.ymax, scroll_rect.ymax);
2506 if (BLI_rcti_isect(&scroll_rect, button_rect, nullptr)) {
2507 draw_widget_scroll(&wscroll, &scroll_rect, &slider_rect, 0);
2508 }
2509}
2510
2511static void widget_draw_vertical_text(const uiFontStyle *fstyle,
2512 const uiWidgetColors *wcol,
2513 const Button *but,
2514 const rcti *rect)
2515{
2516 fontstyle_set(fstyle);
2518 const bool down = but->text_direction == TextDirection::Down;
2519 BLF_rotation(fstyle->uifont_id, !down ? M_PI_2 : -M_PI_2);
2520 BLF_color4ubv(fstyle->uifont_id, wcol->text);
2521 const float width = BLF_width(fstyle->uifont_id, but->drawstr.c_str(), but->drawstr.size());
2522 const float height = BLF_ascender(fstyle->uifont_id) + BLF_descender(fstyle->uifont_id);
2523 const int xofs = ceil(0.5f * (BLI_rcti_size_x(rect) - height)) * (down ? 1 : -1);
2524 const int yofs = (BLI_rcti_size_y(rect) - width) / 2 * (down ? 1 : -1);
2525 BLF_position(fstyle->uifont_id,
2526 (down ? rect->xmin : rect->xmax) + xofs,
2527 (down ? rect->ymax : rect->ymin) - yofs,
2528 0.0f);
2529 BLF_draw(fstyle->uifont_id, but->drawstr.c_str(), but->drawstr.size());
2530
2532}
2533
2534static void widget_draw_text(const uiFontStyle *fstyle,
2535 const uiWidgetColors *wcol,
2536 Button *but,
2537 rcti *rect)
2538{
2539 int drawstr_left_len = UI_MAX_DRAW_STR;
2540 const char *drawstr = but->drawstr.c_str();
2541 const char *drawstr_right = nullptr;
2542 bool use_right_only = false;
2543 const char *indeterminate_str = UI_VALUE_INDETERMINATE_CHAR;
2544 std::optional<StringRef> unit_hint = button_edit_unit_hint_get(*but);
2545
2546#ifdef WITH_INPUT_IME
2547 const wmIMEData *ime_data;
2548 std::string ime_drawstr;
2549#endif
2550
2551 fontstyle_set(fstyle);
2552
2553 FontStyleAlign align;
2554 if (but->drawflag & BUT_TEXT_RIGHT) {
2555 align = UI_STYLE_TEXT_RIGHT;
2556 }
2557 else if (but->editstr || (but->drawflag & BUT_TEXT_LEFT)) {
2558 align = UI_STYLE_TEXT_LEFT;
2559 }
2560 else {
2561 align = UI_STYLE_TEXT_CENTER;
2562 }
2563
2564 /* Special case: when we're entering text for multiple buttons,
2565 * don't draw the text for any of the multi-editing buttons */
2566 if (but->flag & BUT_DRAG_MULTI) [[unlikely]] {
2567 Button *but_edit = button_drag_multi_edit_get(but);
2568 if (but_edit) {
2569 drawstr = but_edit->editstr;
2570 unit_hint = button_edit_unit_hint_get(*but_edit);
2571 align = UI_STYLE_TEXT_LEFT;
2572 }
2573 }
2574 else {
2575 if (but->editstr) {
2576 /* The maximum length isn't used in this case,
2577 * we rely on string being null terminated. */
2578 drawstr_left_len = INT_MAX;
2579
2580#ifdef WITH_INPUT_IME
2581 ime_data = button_ime_data_get(but);
2582
2583 if (ime_data && !ime_data->composite.empty()) {
2584 /* insert composite string into cursor pos */
2585 char tmp_drawstr[UI_MAX_DRAW_STR];
2586 STRNCPY(tmp_drawstr, drawstr);
2587 BLI_snprintf(tmp_drawstr,
2588 sizeof(tmp_drawstr),
2589 "%.*s%s%s",
2590 but->pos,
2591 but->editstr,
2592 ime_data->composite.c_str(),
2593 but->editstr + but->pos);
2594 ime_drawstr = tmp_drawstr;
2595 drawstr = ime_drawstr.c_str();
2596 }
2597 else
2598#endif
2599 {
2600 drawstr = but->editstr;
2601 }
2602 }
2603 }
2604
2605 /* If not editing and indeterminate, show dash. */
2606 if (but->drawflag & BUT_INDETERMINATE && !but->editstr &&
2607 ELEM(but->type,
2613 {
2614 drawstr = indeterminate_str;
2615 drawstr_left_len = strlen(drawstr);
2616 align = UI_STYLE_TEXT_CENTER;
2617 }
2618
2619 /* text button selection, cursor, composite underline */
2620 if (but->editstr && but->pos != -1) {
2621 int align_x_ofs = 0;
2622 if (align == UI_STYLE_TEXT_RIGHT) {
2623 int width = BLF_width(fstyle->uifont_id, drawstr + but->ofs, drawstr_left_len - but->ofs);
2624 const int rect_width = BLI_rcti_size_x(rect);
2625 align_x_ofs = max_ii(0, rect_width - width);
2626 }
2627 int but_pos_ofs;
2628
2629#ifdef WITH_INPUT_IME
2630 bool ime_reposition_window = false;
2631 int ime_win_x, ime_win_y;
2632#endif
2633
2634 /* text button selection */
2635 if ((but->selend - but->selsta) != 0 && drawstr[0] != 0) {
2636 /* We are drawing on top of widget bases. Flush cache. */
2640 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
2643 const auto boxes = BLF_str_selection_boxes(
2644 fstyle->uifont_id,
2645 drawstr + but->ofs,
2646 strlen(drawstr + but->ofs),
2647 (but->selsta >= but->ofs) ? but->selsta - but->ofs : 0,
2648 but->selend - std::max(but->ofs, but->selsta));
2649 for (auto bounds : boxes) {
2650 immRectf(pos,
2651 rect->xmin + bounds.min + align_x_ofs,
2652 rect->ymin + U.pixelsize,
2653 std::min(rect->xmin + bounds.max + align_x_ofs, rect->xmax - 2),
2654 rect->ymax - U.pixelsize);
2655 }
2658
2659#ifdef WITH_INPUT_IME
2660 /* IME candidate window uses selection position. */
2661 if (!ime_reposition_window && boxes.size() > 0) {
2662 ime_reposition_window = true;
2663 ime_win_x = rect->xmin + boxes[0].min;
2664 ime_win_y = rect->ymin + U.pixelsize;
2665 }
2666#endif
2667 }
2668
2669 /* Text cursor position. */
2670 but_pos_ofs = but->pos;
2671
2672#ifdef WITH_INPUT_IME
2673 /* If is IME compositing, move the cursor. */
2674 if (ime_data && !ime_data->composite.empty() && ime_data->cursor_pos != -1) {
2675 but_pos_ofs += ime_data->cursor_pos;
2676 }
2677#endif
2678
2679 /* Draw text cursor (caret). */
2680 if (but->pos >= but->ofs) {
2681
2682 int t = BLF_str_offset_to_cursor(fstyle->uifont_id,
2683 drawstr + but->ofs,
2685 but_pos_ofs - but->ofs,
2686 max_ii(1, int(U.pixelsize * 2)));
2687
2688 /* We are drawing on top of widget bases. Flush cache. */
2692
2694 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
2696
2698
2699 /* draw cursor */
2700 immRectf(pos,
2701 rect->xmin + t + align_x_ofs,
2702 rect->ymin + U.pixelsize,
2703 rect->xmin + t + align_x_ofs + int(2.0f * U.pixelsize),
2704 rect->ymax - U.pixelsize);
2705
2707
2708#ifdef WITH_INPUT_IME
2709 /* IME candidate window uses cursor position. */
2710 if (!ime_reposition_window) {
2711 ime_reposition_window = true;
2712 ime_win_x = rect->xmin + t + 5;
2713 ime_win_y = rect->ymin + 3;
2714 }
2715#endif
2716 }
2717
2718#ifdef WITH_INPUT_IME
2719 /* IME cursor following. */
2720 if (ime_reposition_window) {
2721 button_ime_reposition(but, ime_win_x, ime_win_y);
2722 }
2723 if (ime_data && !ime_data->composite.empty()) {
2724 /* Composite underline. */
2725 widget_draw_text_ime_underline(fstyle, wcol, but, rect, ime_data, drawstr, align_x_ofs);
2726 }
2727#endif
2728 }
2729
2730#if 0
2731 rasterpos_safe(x, y, but->aspect);
2732 transopts = translate_buttons();
2733#endif
2734
2735 bool use_drawstr_right_as_hint = false;
2736
2737 /* cut string in 2 parts - only for menu entries */
2738 if (but->flag & BUT_HAS_SEP_CHAR && (but->editstr == nullptr)) {
2739 drawstr_right = strrchr(drawstr, UI_SEP_CHAR);
2740 if (drawstr_right) {
2741 use_drawstr_right_as_hint = true;
2742 drawstr_left_len = (drawstr_right - drawstr);
2743 drawstr_right++;
2744 }
2745 }
2746
2747#ifdef USE_NUMBUTS_LR_ALIGN
2748 if (!drawstr_right && (but->drawflag & BUT_TEXT_LEFT) &&
2750 /* if we're editing or multi-drag (fake editing), then use left alignment */
2751 (but->editstr == nullptr) && (drawstr == but->drawstr))
2752 {
2753 drawstr_right = strrchr(drawstr + but->ofs, ':');
2754 if (drawstr_right) {
2755 drawstr_right++;
2756 drawstr_left_len = (drawstr_right - drawstr - 1);
2757
2758 while (*drawstr_right == ' ') {
2759 drawstr_right++;
2760 }
2761 }
2762 else {
2763 /* no prefix, even so use only cpoin */
2764 drawstr_right = drawstr + but->ofs;
2765 use_right_only = true;
2766 }
2767 }
2768#endif
2769 /* Draw text underline when the link button is active. */
2770 if (button_draw_as_link(but) && but->active) {
2771 float4 color;
2773 int width = BLF_width(fstyle->uifont_id, drawstr, drawstr_left_len);
2774 int xmin = rect->xmin;
2775 if (align == UI_STYLE_TEXT_RIGHT) {
2776 xmin = rect->xmax - width;
2777 }
2778 else if (align == UI_STYLE_TEXT_CENTER) {
2779 const int rect_width = BLI_rcti_size_x(rect);
2780 xmin = rect->xmin + std::round(float(rect_width - width + 1) / 2.0f);
2781 }
2782 draw_text_underline(xmin, rect->ymin + 6 * U.pixelsize, width, 1, color);
2783 }
2784 if (!use_right_only) {
2785 /* for underline drawing */
2786 int font_xofs, font_yofs;
2787
2788 int drawlen = (drawstr_left_len == INT_MAX) ? strlen(drawstr + but->ofs) :
2789 (drawstr_left_len - but->ofs);
2790
2791 if (drawlen > 0) {
2792 FontStyleDrawParams params{};
2793 params.align = align;
2794 fontstyle_draw_ex(fstyle,
2795 rect,
2796 drawstr + but->ofs,
2797 drawlen,
2798 wcol->text,
2799 &params,
2800 &font_xofs,
2801 &font_yofs,
2802 nullptr);
2803
2804 if (but->menu_key != '\0') {
2805 const char *drawstr_ofs = drawstr + but->ofs;
2806 int ul_index = -1;
2807
2808 {
2809 /* Find upper case, fall back to lower case. */
2810 const char *drawstr_end = drawstr_ofs + drawlen;
2811 const char keys[] = {char(but->menu_key - 32), but->menu_key};
2812 for (int i = 0; i < ARRAY_SIZE(keys); i++) {
2813 const char *drawstr_menu = strchr(drawstr_ofs, keys[i]);
2814 if (drawstr_menu != nullptr && drawstr_menu < drawstr_end) {
2815 ul_index = int(drawstr_menu - drawstr_ofs);
2816 break;
2817 }
2818 }
2819 }
2820
2821 if (ul_index != -1) {
2822 rcti bounds;
2823 if (BLF_str_offset_to_glyph_bounds(fstyle->uifont_id, drawstr_ofs, ul_index, &bounds) &&
2825 {
2826 int ul_width = round_fl_to_int(BLF_width(fstyle->uifont_id, "_", 2));
2827 int pos_x = rect->xmin + font_xofs + bounds.xmin +
2828 (bounds.xmax - bounds.xmin - ul_width) / 2;
2829 int pos_y = rect->ymin + font_yofs + bounds.ymin - U.pixelsize;
2830 /* Use text output because direct drawing doesn't always work. See #89246. */
2831 BLF_position(fstyle->uifont_id, float(pos_x), pos_y, 0.0f);
2832 BLF_color4ubv(fstyle->uifont_id, wcol->text);
2833 BLF_draw(fstyle->uifont_id, "_", 2);
2834 }
2835 }
2836 }
2837
2838 if (unit_hint && drawstr[0] != '\0') {
2839 rcti text_bounds;
2840 BLF_boundbox(fstyle->uifont_id, drawstr + but->ofs, drawlen, &text_bounds);
2841
2842 /* Draw unit hint with 33% opacity. */
2843 uiFontStyle style = *fstyle;
2844 style.shadow = 0;
2845 uchar col[4];
2846 copy_v4_v4_uchar(col, wcol->text);
2847 col[3] *= UI_INPUT_HINT_ALPHA;
2848
2849 rcti unit_hint_rect;
2850 unit_hint_rect.xmin = rect->xmin + text_bounds.xmax;
2851 unit_hint_rect.ymin = rect->ymin;
2852 unit_hint_rect.xmax = rect->xmax;
2853 unit_hint_rect.ymax = rect->ymax;
2854 fontstyle_draw_ex(&style,
2855 &unit_hint_rect,
2856 unit_hint->data(),
2857 unit_hint->size(),
2858 col,
2859 &params,
2860 nullptr,
2861 nullptr,
2862 nullptr);
2863 }
2864 }
2865 }
2866
2867 /* Show placeholder text if the input is empty. */
2868 if (!drawstr[0] && ELEM(but->type, ButtonType::Text, ButtonType::SearchMenu)) {
2869 const char *placeholder = button_placeholder_get(but);
2870 if (placeholder && placeholder[0]) {
2871 FontStyleDrawParams params{};
2872 params.align = align;
2873 uiFontStyle style = *fstyle;
2874 style.shadow = 0;
2875 uchar col[4];
2876 copy_v4_v4_uchar(col, wcol->text);
2877 col[3] *= UI_INPUT_HINT_ALPHA;
2879 &style, rect, placeholder, strlen(placeholder), col, &params, nullptr, nullptr, nullptr);
2880 }
2881 }
2882
2883 /* part text right aligned */
2884 if (drawstr_right) {
2885 uchar col[4];
2886 copy_v4_v4_uchar(col, wcol->text);
2887 if (use_drawstr_right_as_hint) {
2888 col[3] *= 0.5f;
2889 }
2890
2891 rect->xmax -= UI_TEXT_CLIP_MARGIN;
2892 FontStyleDrawParams params{};
2893 params.align = UI_STYLE_TEXT_RIGHT;
2894 fontstyle_draw(fstyle, rect, drawstr_right, UI_MAX_DRAW_STR, col, &params);
2895 }
2896}
2897
2898static void widget_draw_multiline_text(const uiFontStyle *fstyle,
2899 const uiWidgetColors *wcol,
2900 Button *but,
2901 rcti *rect)
2902{
2903 /* Draw multiline text. */
2904 ButtonLabel *multiline_label = static_cast<ButtonLabel *>(but);
2905 const int total_lines = multiline_label->wrap_cache->wrapped_lines.size();
2906 const int lines = multiline_label->max_lines > 0 ?
2907 std::min(multiline_label->max_lines, total_lines) :
2908 total_lines;
2909
2910 const float line_height = ui::fontstyle_height_max(UI_FSTYLE_WIDGET) / but->block->aspect;
2911 const float padding = (std::max(UI_UNIT_Y / but->block->aspect - line_height, 0.0f) / 2.0f);
2912
2913 FontStyleDrawParams params{};
2914 params.align = multiline_label->text_align;
2915 params.word_clip = false;
2916
2917 float ymax = rect->ymax - padding;
2918 rcti line_rect = *rect;
2919 int scissors[4];
2920 GPU_scissor_get(scissors);
2921 int scissors_ymin = scissors[1];
2922 int scissors_ymax = scissors_ymin + scissors[3];
2923
2924 for (const int i : multiline_label->wrap_cache->wrapped_lines.index_range().take_front(lines)) {
2925 StringRef line = multiline_label->wrap_cache->wrapped_lines[i];
2926 line_rect.ymax = ymax;
2927 ymax -= line_height;
2928 line_rect.ymin = ymax;
2929 /* Break when there is not more space to draw. */
2930 if (line_rect.ymax < scissors_ymin) {
2931 break;
2932 }
2933 /* Skip the line if the line is not in visible bounds. */
2934 if (line_rect.ymin > scissors_ymax) {
2935 continue;
2936 }
2937 if (i < (lines - 1) || total_lines == lines) {
2938 fontstyle_draw_ex(fstyle,
2939 &line_rect,
2940 line.begin(),
2941 line.size(),
2942 wcol->text,
2943 &params,
2944 nullptr,
2945 nullptr,
2946 nullptr);
2947 continue;
2948 }
2949 /* Add ellipsis when not all lines are drawn. */
2950 float strwidth = BLF_width(fstyle->uifont_id, line.begin(), line.size(), nullptr);
2951
2952 const int border = UI_TEXT_CLIP_MARGIN + 1;
2953 const int okwidth = max_ii(BLI_rcti_size_x(&line_rect) - border, 0);
2954 std::string str = line;
2955 if (strwidth > okwidth) {
2956 int drawstr_len = BLF_width_to_strlen(
2957 fstyle->uifont_id, line.begin(), line.size(), okwidth, &strwidth);
2958 str = str.substr(0, drawstr_len);
2959 }
2960 /* Trim trailing white-space. */
2961 str = StringRef(str).trim_right();
2962
2964 str += ellipsis;
2965 fontstyle_draw_ex(fstyle,
2966 &line_rect,
2967 str.data(),
2968 str.size(),
2969 wcol->text,
2970 &params,
2971 nullptr,
2972 nullptr,
2973 nullptr);
2974 break;
2975 }
2976}
2977
2979 Button *but,
2980 rcti *rect,
2981 float alpha)
2982{
2983 const float icon_size = ICON_SIZE_FROM_BUTRECT(rect);
2984
2985 /* Offset of icons from the right edge. Keep in sync
2986 * with 'but_extra_operator_icon_mouse_over_get'. */
2987 if (!but->extra_op_icons.is_empty()) {
2988 /* Eyeballed. */
2989 rect->xmax -= 0.2 * icon_size;
2990 }
2991
2992 /* Inverse order, from right to left. */
2993 for (ButtonExtraOpIcon &op_icon : but->extra_op_icons.items_reversed()) {
2994 rcti temp = *rect;
2995 float alpha_this = alpha;
2996
2997 temp.xmin = temp.xmax - icon_size;
2998
2999 if (op_icon.disabled) {
3000 alpha_this *= 0.4f;
3001 }
3002 else if (!op_icon.highlighted) {
3003 alpha_this *= 0.75f;
3004 }
3005
3006 /* Draw the icon at the center, and restore the flags after. */
3007 const int old_drawflags = but->drawflag;
3009 widget_draw_icon(but, op_icon.icon, alpha_this, &temp, wcol->text);
3010 but->drawflag = old_drawflags;
3011
3012 rect->xmax -= icon_size;
3013 }
3014}
3015
3017 const rcti *rect,
3018 Button *but,
3019 float alpha)
3020{
3021 /* Node socket pointer can be passed as custom_data, see button_node_link_set(). */
3022 if (but->custom_data) {
3023 const float scale = 0.9f / but->block->aspect;
3024
3025 float col[4];
3026 rgba_uchar_to_float(col, but->col);
3027 col[3] *= alpha;
3028
3032
3034 static_cast<bNodeSocket *>(but->custom_data), rect, col, scale);
3035 }
3036 else {
3037 widget_draw_icon(but, ICON_LAYER_USED, alpha, rect, wcol->text);
3038 }
3039}
3040
3041/* draws text and icons for buttons */
3042static void widget_draw_text_icon(const uiFontStyle *fstyle,
3043 const uiWidgetColors *wcol,
3044 Button *but,
3045 rcti *rect)
3046{
3047 const bool show_menu_icon = but_draw_menu_icon(but);
3048 const float alpha = float(wcol->text[3]) / 255.0f;
3049 std::string password_str;
3050 bool no_left_padding = but->drawflag & BUT_NO_TEXT_PADDING;
3051 bool no_right_padding = no_left_padding;
3052
3053 button_text_password_hide(password_str, but, false);
3054
3055 /* check for button text label */
3057 rcti temp = *rect;
3058 const int size = BLI_rcti_size_y(rect) + 1; /* Not the icon size! */
3059
3060 if (but->drawflag & BUT_ICON_LEFT) {
3061 temp.xmax = rect->xmin + size;
3062 rect->xmin = temp.xmax;
3063 /* Further padding looks off. */
3064 no_left_padding = true;
3065 }
3066 else {
3067 temp.xmin = rect->xmax - size;
3068 rect->xmax = temp.xmin;
3069 no_right_padding = true;
3070 }
3071
3072 widget_draw_node_link_socket(wcol, &temp, but, alpha);
3073 }
3074
3075 const uchar *icon_color = (but->col[3] != 0) ? but->col : wcol->text;
3076
3077 /* If there's an icon too (made with uiDefIconTextBut) then draw the icon
3078 * and offset the text label to accommodate it */
3079
3080 /* Big previews with optional text label below */
3081 if (but->flag & BUT_ICON_PREVIEW && block_is_menu(but->block)) {
3082 const BIFIconID icon = button_icon(but);
3083 int icon_size = BLI_rcti_size_y(rect);
3084 int text_size = 0;
3085
3086 /* This is a bit brittle, but avoids adding an 'BUT_HAS_LABEL' flag to but... */
3087 if (icon_size > BLI_rcti_size_x(rect)) {
3088 /* button is not square, it has extra height for label */
3089 text_size = UI_UNIT_Y;
3090 icon_size -= text_size;
3091 }
3092
3093 /* draw icon in rect above the space reserved for the label */
3094 rect->ymin += text_size;
3097 alpha,
3098 but->block->aspect,
3100 rect,
3101 icon_color);
3103
3104 /* offset rect to draw label in */
3105 rect->ymin -= text_size;
3106 rect->ymax -= icon_size;
3107
3108 /* vertically centering text */
3109 rect->ymin += UI_UNIT_Y / 2;
3110 }
3111 /* Icons on the left with optional text label on the right */
3112 else if (but->flag & UI_HAS_ICON || show_menu_icon) {
3113 const bool is_tool = ((but->icon != ICON_NONE) & but_is_tool(but));
3114
3115 /* XXX add way to draw icons at a different size!
3116 * Use small icons for popup. */
3117#ifdef USE_UI_TOOLBAR_HACK
3118 const float aspect_orig = but->block->aspect;
3119 if (is_tool && (but->block->flag & BLOCK_POPOVER)) {
3120 but->block->aspect *= 2.0f;
3121 }
3122#endif
3123
3124 const BIFIconID icon = button_icon(but);
3125 const int icon_size_init = is_tool ? ICON_DEFAULT_HEIGHT_TOOLBAR : ICON_DEFAULT_HEIGHT;
3126 const float icon_size = icon_size_init / (but->block->aspect * UI_INV_SCALE_FAC);
3127 const float icon_padding = 2 * UI_SCALE_FAC;
3128
3129#ifdef USE_UI_TOOLBAR_HACK
3130 if (is_tool) {
3131 /* pass (even if its a menu toolbar) */
3132 but->drawflag |= BUT_TEXT_LEFT;
3133 but->drawflag |= BUT_ICON_LEFT;
3134 }
3135#endif
3136
3137 /* menu item - add some more padding so menus don't feel cramped. it must
3138 * be part of the button so that this area is still clickable */
3139 if (is_tool) {
3140 /* pass (even if its a menu toolbar) */
3141 }
3142 else if (block_is_pie_menu(but->block)) {
3143 if (but->emboss == EmbossType::PieMenu) {
3144 rect->xmin += 0.3f * U.widget_unit;
3145 }
3146 }
3147 /* Menu items, but only if they are not icon-only (rare). */
3148 else if (block_is_menu(but->block) && but->drawstr[0]) {
3149 rect->xmin += 0.2f * U.widget_unit;
3150 }
3151
3152 /* By default icon is the color of text, but can optionally override with but->col. */
3153 widget_draw_icon(but, icon, alpha, rect, icon_color);
3154
3155 if (show_menu_icon) {
3157 widget_draw_submenu_tria(but, rect, wcol);
3158 }
3159
3160#ifdef USE_UI_TOOLBAR_HACK
3161 but->block->aspect = aspect_orig;
3162#endif
3163
3164 rect->xmin += round_fl_to_int(icon_size + icon_padding);
3165 }
3166
3167 /* Menu contains sub-menu items with triangle icon on their right. Shortcut
3168 * strings should be drawn with some padding to the right then. */
3171 }
3172
3173 /* extra icons, e.g. 'x' icon to clear text or icon for eyedropper */
3174 widget_draw_extra_icons(wcol, but, rect, alpha);
3175
3176 /* Text padding, after icon padding. Ideally we would have the same padding
3177 * in both sides always (except for icons), but many button types rely on the
3178 * current asymmetric padding. */
3179 if (but->drawflag & BUT_TEXT_RIGHT) {
3180 if (!no_right_padding) {
3181 rect->xmax -= button_text_padding(but);
3182 }
3183 else {
3184 rect->xmax -= U.pixelsize;
3185 }
3186 rect->xmin += U.pixelsize;
3187 }
3188 else {
3189 if (!no_left_padding) {
3190 const int text_padding = button_text_padding(but);
3191 if (but->editstr || but->drawflag & BUT_TEXT_LEFT) {
3192 rect->xmin += text_padding;
3193 }
3194 else if (but->flag & BUT_DRAG_MULTI) {
3195 const bool text_is_edited = button_drag_multi_edit_get(but) != nullptr;
3196 if (text_is_edited || (but->drawflag & BUT_TEXT_LEFT)) {
3197 rect->xmin += text_padding;
3198 }
3199 }
3200 }
3201 else {
3202 /* In case a separate text label and some other button are placed under each other,
3203 * and the outline of the button does not contrast with the background.
3204 * Add an offset (thickness of the outline) so that the text does not stick out visually. */
3205 if (but->drawflag & BUT_TEXT_LEFT) {
3206 rect->xmin += U.pixelsize;
3207 }
3208 }
3209 }
3210
3211 /* Text-box wraps content in lines, skip clipping text. */
3212 if (but->type == ButtonType::TextBox) {
3213 }
3215 /* Multi-line and markdown labels manage their own wrapping. */
3216 }
3217 else if (but->text_direction != TextDirection::Default) {
3218 /* Do not clip vertical text. */
3219 }
3220 else if (but->editstr && but->pos >= 0) {
3221 /* clip but->drawstr to fit in available space */
3222 text_clip_cursor(fstyle, but, rect);
3223 }
3224 else if (but->drawstr[0] == '\0') {
3225 /* bypass text clipping on icon buttons */
3226 but->ofs = 0;
3227 but->strwidth = 0;
3228 }
3230 text_clip_right_label(fstyle, but, rect);
3231 }
3232 else if (but->flag & BUT_HAS_SEP_CHAR) {
3233 /* Clip middle, but protect in all case right part containing the shortcut, if any. */
3234 text_clip_middle_protect_right(fstyle, but, rect, UI_SEP_CHAR);
3235 }
3236 else {
3237 text_clip_middle(fstyle, but, rect);
3238 }
3239
3240 /* Always draw text for text-button cursor. */
3242 widget_draw_vertical_text(fstyle, wcol, but, rect);
3243 }
3244 else if (button_label_is_multiline(but)) {
3245 widget_draw_multiline_text(fstyle, wcol, but, rect);
3246 }
3247 else if (button_label_is_markdown(but)) {
3248 label_markdown_draw(static_cast<const ButtonLabel *>(but), wcol->text, rect);
3249 }
3250 else if (but->type == ButtonType::TextBox) {
3251 widget_draw_textbox(fstyle, wcol, but, rect);
3252 }
3253 else {
3254 widget_draw_text(fstyle, wcol, but, rect);
3255 }
3256
3257 button_text_password_hide(password_str, but, true);
3258
3259 /* if a widget uses font shadow it has to be deactivated now */
3261}
3262
3263#undef UI_TEXT_CLIP_MARGIN
3264
3266
3267/* -------------------------------------------------------------------- */
3272
3273/* Put all widget colors on reduced alpha. */
3275{
3276 const float factor = widget_alpha_factor(state);
3277 wcol.outline[3] *= factor;
3278 wcol.outline_sel[3] *= factor;
3279 wcol.inner[3] *= factor;
3280 wcol.inner_sel[3] *= factor;
3281 wcol.item[3] *= factor;
3282 wcol.text[3] *= factor;
3283 wcol.text_sel[3] *= factor;
3284}
3285
3286/* Put all widget colors on reduced alpha, to avoid overriding theme colors use local storage. */
3288{
3289 static uiWidgetColors wcol_theme_s;
3290
3291 wcol_theme_s = *wt->wcol_theme;
3292 widget_color_disabled(wcol_theme_s, state);
3293
3294 wt->wcol_theme = &wcol_theme_s;
3295}
3296
3298{
3299 const bool dark = (srgb_to_grayscale_byte(wcol->text) > srgb_to_grayscale_byte(wcol->inner));
3300 color_mul_hsl_v3(wcol->inner, 1.0f, 1.15f, dark ? 1.2f : 1.1f);
3301 color_blend_v4_v4v4(wcol->outline, wcol->outline, wcol->outline_sel, 0.5f);
3302 color_mul_hsl_v3(wcol->outline_sel, 1.0f, 1.15f, 1.15f);
3303 color_mul_hsl_v3(wcol->text, 1.0f, 1.15f, dark ? 1.25f : 0.8f);
3304}
3305
3307 const WidgetStateInfo *state,
3308 const EmbossType emboss)
3309{
3310 /* Explicitly require #EmbossType::NoneOrStatus for color blending with no emboss.
3311 */
3312 if (emboss == EmbossType::None) {
3313 return nullptr;
3314 }
3315
3316 if (state->but_drawflag & BUT_ANIMATED_CHANGED) {
3317 return wcol_state->inner_changed_sel;
3318 }
3319 if (state->but_flag & BUT_ANIMATED_KEY) {
3320 return wcol_state->inner_key_sel;
3321 }
3322 if (state->but_flag & BUT_ANIMATED) {
3323 return wcol_state->inner_anim_sel;
3324 }
3325 if (state->but_flag & BUT_DRIVEN) {
3326 return wcol_state->inner_driven_sel;
3327 }
3328 if (state->but_flag & BUT_OVERRIDDEN) {
3329 return wcol_state->inner_overridden_sel;
3330 }
3331 return nullptr;
3332}
3333
3334/* copy colors from theme, and set changes in it based on state */
3336{
3337 const uiWidgetStateColors *wcol_state = wt->wcol_state;
3338
3339 if (state->but_flag & BUT_LIST_ITEM) {
3340 /* Override default widget's colors. */
3341 const bTheme *btheme = theme::theme_get();
3342 wt->wcol_theme = &btheme->tui.wcol_list_item;
3343
3346 }
3347 }
3348
3349 wt->wcol = *(wt->wcol_theme);
3350 if (state->draw_as_link) {
3355 }
3356 }
3357 const uchar *color_blend = widget_color_blend_from_flags(wcol_state, state, emboss);
3358
3359 if (state->but_flag & UI_SELECT) {
3362 if (color_blend != nullptr) {
3363 color_blend_v3_v3(wt->wcol.inner, color_blend, wcol_state->blend);
3364 }
3365
3367
3368 std::swap(wt->wcol.shadetop, wt->wcol.shadedown);
3369 }
3370 else {
3371 if (state->but_flag & BUT_ACTIVE_DEFAULT) {
3375 }
3376 if (color_blend != nullptr) {
3377 color_blend_v3_v3(wt->wcol.inner, color_blend, wcol_state->blend);
3378 }
3379
3380 /* Add "hover" highlight. Ideally this could apply in all cases,
3381 * even if UI_SELECT. But currently this causes some flickering
3382 * as buttons can be created and updated without respect to mouse
3383 * position and so can draw without UI_HOVER set. See D6503. */
3384 if (state->but_flag & UI_HOVER) {
3386 }
3387 }
3388
3389 if (state->but_flag & BUT_REDALERT) {
3390 uchar red[4];
3392 /* Alpha is used to blend between the original color (text, background) and alert theme. */
3393 const float red_alpha = float(red[3]) / 255.0f;
3394
3395 /* In regular widgets, tint the background and outline. */
3396 if (wt->draw && emboss != EmbossType::None) {
3397 color_blend_v3_v3(wt->wcol.outline, red, red_alpha);
3398 color_blend_v3_v3(wt->wcol.inner, red, red_alpha);
3399 }
3400 /* Text such as labels or widgets without emboss. Tint the text only. */
3401 else {
3402 color_blend_v3_v3(wt->wcol.text, red, red_alpha);
3403 }
3404 }
3405
3406 if (state->but_flag & BUT_DRAG_MULTI) {
3407 /* the button isn't SELECT but we're editing this so draw with sel color */
3410 std::swap(wt->wcol.shadetop, wt->wcol.shadedown);
3411 color_blend_v3_v3(wt->wcol.text, wt->wcol.text_sel, 0.85f);
3412 }
3413
3414 if (state->but_flag & BUT_NODE_ACTIVE) {
3415 const uchar blue[4] = {86, 128, 194};
3416 color_blend_v3_v3(wt->wcol.inner, blue, 0.3f);
3417 }
3418}
3419
3421
3422/* -------------------------------------------------------------------- */
3430
3431static float widget_radius_from_zoom(const float zoom, const uiWidgetColors *wcol)
3432{
3433 return wcol->roundness * U.widget_unit * zoom;
3434}
3435
3436static float widget_radius_from_rcti(const rcti *rect, const uiWidgetColors *wcol)
3437{
3438 return wcol->roundness * BLI_rcti_size_y(rect);
3439}
3440
3442
3443/* -------------------------------------------------------------------- */
3449
3450static bool draw_emboss(const Button *but)
3451{
3452 if (but->drawflag & BUT_ALIGN_DOWN) {
3453 return false;
3454 }
3455 Button *but_next = but->block->next_but(but);
3456 if (but->type == ButtonType::Tab &&
3457 (BLI_rctf_size_y(&but->block->rect) > BLI_rctf_size_x(&but->block->rect)) &&
3458 !(but_next == nullptr || but_next->type == ButtonType::Sepr))
3459 {
3460 /* Vertical tabs, emboss at end and before separators. */
3461 return false;
3462 }
3463
3464 return true;
3465}
3466
3468
3469/* -------------------------------------------------------------------- */
3472
3473/* sliders use special hack which sets 'item' as inner when drawing filling */
3475{
3476 const uiWidgetStateColors *wcol_state = wt->wcol_state;
3477
3478 /* call this for option button */
3479 widget_state(wt, state, emboss);
3480
3481 const uchar *color_blend = widget_color_blend_from_flags(wcol_state, state, emboss);
3482 if (color_blend != nullptr) {
3483 /* Set the slider 'item' so that it reflects state settings too.
3484 * De-saturate so the color of the slider doesn't conflict with the blend color,
3485 * which can make the color hard to see when the slider is set to full (see #66102). */
3486 wt->wcol.item[0] = wt->wcol.item[1] = wt->wcol.item[2] = srgb_to_grayscale_byte(wt->wcol.item);
3487 color_blend_v3_v3(wt->wcol.item, color_blend, wcol_state->blend);
3489 }
3490
3491 if (state->but_flag & UI_SELECT) {
3492 std::swap(wt->wcol.shadetop, wt->wcol.shadedown);
3493 }
3494}
3495
3496/* labels use theme colors for text */
3498 const WidgetStateInfo *state,
3499 EmbossType emboss)
3500{
3501 const bTheme *btheme = theme::theme_get();
3502
3503 const uiWidgetColors *old_wcol = wt->wcol_theme;
3504 uiWidgetColors wcol_menu_option = *wt->wcol_theme;
3505
3506 /* Override the checkbox theme colors to use the menu-back text colors. */
3507 copy_v3_v3_uchar(wcol_menu_option.text, btheme->tui.wcol_menu_back.text);
3508 copy_v3_v3_uchar(wcol_menu_option.text_sel, btheme->tui.wcol_menu_back.text_sel);
3509 wt->wcol_theme = &wcol_menu_option;
3510
3511 widget_state(wt, state, emboss);
3512
3513 wt->wcol_theme = old_wcol;
3514}
3515
3517 const WidgetStateInfo * /*state*/,
3518 EmbossType /*emboss*/)
3519{
3520 wt->wcol = *(wt->wcol_theme);
3521}
3522
3523/* special case, button that calls pulldown */
3525 const WidgetStateInfo * /*state*/,
3526 EmbossType /*emboss*/)
3527{
3528 wt->wcol = *(wt->wcol_theme);
3529}
3530
3531/* special case, pie menu items */
3533 const WidgetStateInfo *state,
3534 EmbossType /*emboss*/)
3535{
3536 wt->wcol = *(wt->wcol_theme);
3537
3538 if ((state->but_flag & BUT_DISABLED) && (state->but_flag & UI_HOVER)) {
3539 color_blend_v3_v3(wt->wcol.text, wt->wcol.text_sel, 0.5f);
3541 /* draw the backdrop at low alpha, helps navigating with keys
3542 * when disabled items are active */
3544 wt->wcol.inner[3] = 64;
3545 }
3546 else {
3547 /* regular active */
3548 if (state->but_flag & (UI_SELECT | UI_HOVER)) {
3551 }
3552 else if (state->but_flag & (BUT_DISABLED | BUT_INACTIVE)) {
3553 /* regular disabled */
3554 color_blend_v3_v3(wt->wcol.text, wt->wcol.inner, 0.5f);
3555 }
3556
3557 if (state->but_flag & UI_SELECT) {
3560 }
3561 else if (state->but_flag & UI_HOVER) {
3564 }
3565 }
3566}
3567
3568/* special case, menu items */
3570 const WidgetStateInfo *state,
3571 EmbossType /*emboss*/)
3572{
3573 wt->wcol = *(wt->wcol_theme);
3574
3575 if ((state->but_flag & BUT_DISABLED) && (state->but_flag & UI_HOVER)) {
3576 /* Hovering over disabled item. */
3577 wt->wcol.text[3] = 128;
3578 color_blend_v3_v3(wt->wcol.inner, wt->wcol.text, 0.5f);
3579 wt->wcol.inner[3] = 64;
3580 }
3581 else if (state->but_flag & BUT_DISABLED) {
3582 /* Regular disabled. */
3583 wt->wcol.text[3] = 128;
3584 }
3585 else if (state->but_flag & BUT_INACTIVE) {
3586 /* Inactive. */
3587 if (state->but_flag & UI_HOVER) {
3588 color_blend_v3_v3(wt->wcol.inner, wt->wcol.text, 0.2f);
3590 wt->wcol.inner[3] = 255;
3591 }
3592 color_blend_v3_v3(wt->wcol.text, wt->wcol.inner, 0.5f);
3593 }
3594 else if (state->but_flag & (BUT_ACTIVE_DEFAULT | UI_SELECT_DRAW)) {
3595 /* Currently-selected item. */
3599 }
3600 else if ((state->but_flag & (UI_SELECT | BUT_ICON_PREVIEW)) == (UI_SELECT | BUT_ICON_PREVIEW)) {
3601 /* Currently-selected list or menu item that is large icon preview. */
3605 }
3606 else if (state->but_flag & UI_HOVER) {
3607 /* Regular hover. */
3608 color_blend_v3_v3(wt->wcol.inner, wt->wcol.text, 0.2f);
3611 wt->wcol.inner[3] = 255;
3612 wt->wcol.text[3] = 255;
3613 }
3614 /* Subtle background for larger preview buttons, so text and icons feel connected (esp. for while
3615 * previews are loading still and a loading icon is displayed). */
3616 else if (state->but_flag & BUT_ICON_PREVIEW) {
3618 wt->wcol.inner[3] = 11;
3619 }
3620}
3621
3623
3624/* -------------------------------------------------------------------- */
3627
3628/* outside of rect, rad to left/bottom/right */
3629static void widget_softshadow(const rcti *rect, int roundboxalign, const float radin)
3630{
3631 const float outline = U.pixelsize;
3632
3633 rctf shadow_rect;
3634 BLI_rctf_rcti_copy(&shadow_rect, rect);
3635 BLI_rctf_pad(&shadow_rect, -outline, -outline);
3636
3637 draw_roundbox_corner_set(roundboxalign);
3638
3639 const float shadow_alpha = theme::theme_get()->tui.menu_shadow_fac;
3640 const float shadow_width = theme::get_menu_shadow_width();
3641
3642 draw_dropshadow(&shadow_rect, radin, shadow_width, 1.0f, shadow_alpha);
3643}
3644
3646 const rcti *rect,
3647 const int block_flag,
3648 const int direction,
3649 const float zoom)
3650{
3651 WidgetBase wtb;
3652 int roundboxalign = CNR_ALL;
3653
3654 widget_init(&wtb);
3655
3656 /* menu is 2nd level or deeper */
3657 if (block_flag & BLOCK_POPUP) {
3658 // rect->ymin -= 4.0;
3659 // rect->ymax += 4.0;
3660 }
3661 else if (direction & (UI_DIR_DOWN | UI_DIR_UP)) {
3662 if (direction & UI_DIR_DOWN) {
3663 roundboxalign = (CNR_BOTTOM_RIGHT | CNR_BOTTOM_LEFT);
3664 }
3665 else {
3666 roundboxalign = (CNR_TOP_LEFT | CNR_TOP_RIGHT);
3667 }
3668 /* Corner rounding based on secondary direction. */
3669 if (direction & UI_DIR_LEFT) {
3670 roundboxalign |= (CNR_TOP_RIGHT | CNR_BOTTOM_RIGHT);
3671 }
3672 if (direction & UI_DIR_RIGHT) {
3673 roundboxalign |= (CNR_TOP_LEFT | CNR_BOTTOM_LEFT);
3674 }
3675 }
3676
3678 const float radius = widget_radius_from_zoom(zoom, wcol);
3679 widget_softshadow(rect, roundboxalign, radius);
3680
3681 round_box_edges(&wtb, roundboxalign, rect, radius);
3682 wtb.draw_emboss = false;
3683 widgetbase_draw(&wtb, wcol);
3684
3686}
3687
3688static void hsv_cursor(const float x,
3689 const float y,
3690 const float zoom,
3691 const float rgb[3],
3692 const float hsv[3],
3693 const bool is_active)
3694{
3695 /* Draw the circle larger while the mouse button is pressed down. */
3696 const float radius = zoom * (((is_active ? 20.0f : 12.0f) * UI_SCALE_FAC) + U.pixelsize);
3697
3699 const uint pos = GPU_vertformat_attr_add(
3700 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
3703 immUniformColor3fv(rgb);
3704 immUniform1f("outlineWidth", U.pixelsize);
3705
3706 /* Alpha of outline colors just strong enough to give good contrast. */
3707 const float fg = std::min(1.0f - hsv[2] + 0.2f, 0.8f);
3708 const float bg = hsv[2] / 2.0f;
3709
3710 immUniform4f("outlineColor", 0.0f, 0.0f, 0.0f, bg);
3711 immUniform1f("size", radius);
3713 immVertex2f(pos, x, y);
3714 immEnd();
3715
3716 immUniform4f("outlineColor", 1.0f, 1.0f, 1.0f, fg);
3717 immUniform1f("size", radius - 1.0f);
3719 immVertex2f(pos, x, y);
3720 immEnd();
3721
3725}
3726
3728 const rcti *rect, const float mx, const float my, float *r_val_rad, float *r_val_dist)
3729{
3730 /* duplication of code... well, simple is better now */
3731 const float centx = BLI_rcti_cent_x_fl(rect);
3732 const float centy = BLI_rcti_cent_y_fl(rect);
3733 const float radius = float(min_ii(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect))) / 2.0f;
3734 const float m_delta[2] = {mx - centx, my - centy};
3735 const float dist_sq = len_squared_v2(m_delta);
3736
3737 *r_val_dist = (dist_sq < (radius * radius)) ? sqrtf(dist_sq) / radius : 1.0f;
3738 *r_val_rad = atan2f(m_delta[0], m_delta[1]) / (2.0f * float(M_PI)) + 0.5f;
3739}
3740
3742 const ColorPicker *cpicker, const rcti *rect, const float *hsv, float *r_xpos, float *r_ypos)
3743{
3744 /* duplication of code... well, simple is better now */
3745 const float centx = BLI_rcti_cent_x_fl(rect);
3746 const float centy = BLI_rcti_cent_y_fl(rect);
3747 const float radius = float(min_ii(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect))) / 2.0f;
3748
3749 const float ang = 2.0f * float(M_PI) * hsv[0] + float(M_PI_2);
3750
3751 float radius_t;
3752 if (cpicker->use_color_cubic && (U.color_picker_type == USER_CP_CIRCLE_HSV)) {
3753 radius_t = (1.0f - pow3f(1.0f - hsv[1]));
3754 }
3755 else {
3756 radius_t = hsv[1];
3757 }
3758
3759 const float rad = clamp_f(radius_t, 0.0f, 1.0f) * radius;
3760 *r_xpos = centx + cosf(-ang) * rad;
3761 *r_ypos = centy + sinf(-ang) * rad;
3762}
3763
3764static void draw_but_HSVCIRCLE(Button *but, const uiWidgetColors *wcol, const rcti *rect)
3765{
3766 /* TODO(merwin): reimplement as shader for pixel-perfect colors */
3767
3768 const int tot = 64;
3769 const float radstep = 2.0f * float(M_PI) / float(tot);
3770 const float centx = BLI_rcti_cent_x_fl(rect);
3771 const float centy = BLI_rcti_cent_y_fl(rect);
3772 const float radius = float(min_ii(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect))) / 2.0f;
3773
3774 ColorPicker *cpicker = static_cast<ColorPicker *>(but->custom_data);
3775 float rgb[3], hsv[3], rgb_center[3], rgb_perceptual[3];
3776 const bool is_color_gamma = button_is_color_gamma(but);
3777
3778 /* Initialize for compatibility. */
3779 copy_v3_v3(hsv, cpicker->hsv_perceptual);
3780
3781 /* Compute current hue. */
3782 button_v3_get(but, rgb);
3783 copy_v3_v3(rgb_perceptual, rgb);
3784 scene_linear_to_perceptual_space(but, rgb_perceptual);
3785 color_picker_rgb_to_hsv_compat(rgb_perceptual, hsv);
3786
3787 if (!is_color_gamma) {
3789 }
3790
3791 CLAMP(hsv[2], 0.0f, 1.0f); /* for display only */
3792
3793 /* exception: if 'lock' is set
3794 * lock the value of the color wheel to 1.
3795 * Useful for color correction tools where you're only interested in hue. */
3796 if (cpicker->use_color_lock) {
3797 if (U.color_picker_type == USER_CP_CIRCLE_HSV) {
3798 hsv[2] = 1.0f;
3799 }
3800 else {
3801 hsv[2] = 0.5f;
3802 }
3803 }
3804
3805 const float hsv_center[3] = {0.0f, 0.0f, hsv[2]};
3806 color_picker_hsv_to_rgb(hsv_center, rgb_center);
3807 perceptual_to_scene_linear_space(but, rgb_center);
3808
3809 if (!is_color_gamma) {
3810 block_cm_to_display_space_v3(but->block, rgb_center);
3811 }
3812
3813 GPUVertFormat *format = immVertexFormat();
3814 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
3815 const uint color = GPU_vertformat_attr_add(format, "color", gpu::VertAttrType::SFLOAT_32_32_32);
3816
3818
3819 immBegin(GPU_PRIM_TRI_FAN, tot + 2);
3820 immAttr3fv(color, rgb_center);
3821 immVertex2f(pos, centx, centy);
3822
3823 float ang = 0.0f;
3824 for (int a = 0; a <= tot; a++, ang += radstep) {
3825 const float si = sinf(ang);
3826 const float co = cosf(ang);
3827 float hsv_ang[3];
3828 float rgb_ang[3];
3829
3830 hsvcircle_vals_from_pos(rect, centx + co * radius, centy + si * radius, hsv_ang, hsv_ang + 1);
3831 hsv_ang[2] = hsv[2];
3832
3833 color_picker_hsv_to_rgb(hsv_ang, rgb_ang);
3835
3836 if (!is_color_gamma) {
3837 block_cm_to_display_space_v3(but->block, rgb_ang);
3838 }
3839
3840 immAttr3fv(color, rgb_ang);
3841 immVertex2f(pos, centx + co * radius, centy + si * radius);
3842 }
3843 immEnd();
3845
3846 /* fully rounded outline */
3847 format = immVertexFormat();
3848 pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
3849
3851
3853 GPU_line_smooth(true);
3854
3856 imm_draw_circle_wire_2d(pos, centx, centy, radius, tot);
3857
3859
3861 GPU_line_smooth(false);
3862
3863 /* cursor */
3864 copy_v3_v3(hsv, cpicker->hsv_perceptual);
3865 color_picker_rgb_to_hsv_compat(rgb_perceptual, hsv);
3866
3867 float xpos, ypos;
3868 hsvcircle_pos_from_vals(cpicker, rect, hsv, &xpos, &ypos);
3869 const float zoom = 1.0f / but->block->aspect;
3870 hsv_cursor(xpos, ypos, zoom, rgb, hsv, but->flag & UI_SELECT);
3871}
3872
3874
3875/* -------------------------------------------------------------------- */
3878
3880 const ColorManagedDisplay *display, float h, float s, float v, float rgb[3])
3881{
3882 hsv_to_rgb(h, s, v, rgb, rgb + 1, rgb + 2);
3883
3884 if (display) {
3887 }
3888}
3889
3890void draw_gradient(const rcti *rect,
3891 const float hsv[3],
3892 const eButGradientType type,
3893 const float alpha,
3894 const ColorManagedDisplay *display)
3895{
3896 /* allows for 4 steps (red->yellow) */
3897 const int steps = 48;
3898 const float color_step = 1.0f / steps;
3899 int a;
3900 const float h = hsv[0], s = hsv[1], v = hsv[2];
3901 float dx, dy, sx1, sx2, sy;
3902 float col0[4][3]; /* left half, rect bottom to top */
3903 float col1[4][3]; /* right half, rect bottom to top */
3904
3905 /* draw series of gouraud rects */
3906
3907 switch (type) {
3908 case GRAD_SV:
3909 draw_gradient_hsv_to_rgb(display, h, 0.0, 0.0, col1[0]);
3910 draw_gradient_hsv_to_rgb(display, h, 0.0, 0.333, col1[1]);
3911 draw_gradient_hsv_to_rgb(display, h, 0.0, 0.666, col1[2]);
3912 draw_gradient_hsv_to_rgb(display, h, 0.0, 1.0, col1[3]);
3913 break;
3914 case GRAD_HV:
3915 draw_gradient_hsv_to_rgb(display, 0.0, s, 0.0, col1[0]);
3916 draw_gradient_hsv_to_rgb(display, 0.0, s, 0.333, col1[1]);
3917 draw_gradient_hsv_to_rgb(display, 0.0, s, 0.666, col1[2]);
3918 draw_gradient_hsv_to_rgb(display, 0.0, s, 1.0, col1[3]);
3919 break;
3920 case GRAD_HS:
3921 draw_gradient_hsv_to_rgb(display, 0.0, 0.0, v, col1[0]);
3922 draw_gradient_hsv_to_rgb(display, 0.0, 0.333, v, col1[1]);
3923 draw_gradient_hsv_to_rgb(display, 0.0, 0.666, v, col1[2]);
3924 draw_gradient_hsv_to_rgb(display, 0.0, 1.0, v, col1[3]);
3925 break;
3926 case GRAD_H:
3927 draw_gradient_hsv_to_rgb(display, 0.0, 1.0, 1.0, col1[0]);
3928 copy_v3_v3(col1[1], col1[0]);
3929 copy_v3_v3(col1[2], col1[0]);
3930 copy_v3_v3(col1[3], col1[0]);
3931 break;
3932 case GRAD_S:
3933 draw_gradient_hsv_to_rgb(display, 1.0, 0.0, 1.0, col1[1]);
3934 copy_v3_v3(col1[0], col1[1]);
3935 copy_v3_v3(col1[2], col1[1]);
3936 copy_v3_v3(col1[3], col1[1]);
3937 break;
3938 case GRAD_V:
3939 draw_gradient_hsv_to_rgb(display, 1.0, 1.0, 0.0, col1[2]);
3940 copy_v3_v3(col1[0], col1[2]);
3941 copy_v3_v3(col1[1], col1[2]);
3942 copy_v3_v3(col1[3], col1[2]);
3943 break;
3944 default:
3945 BLI_assert_msg(0, "invalid 'type' argument");
3946 draw_gradient_hsv_to_rgb(display, 1.0, 1.0, 1.0, col1[2]);
3947 copy_v3_v3(col1[0], col1[2]);
3948 copy_v3_v3(col1[1], col1[2]);
3949 copy_v3_v3(col1[3], col1[2]);
3950 break;
3951 }
3952
3953 /* old below */
3954 GPUVertFormat *format = immVertexFormat();
3955 const uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
3956 const uint col = GPU_vertformat_attr_add(format, "color", gpu::VertAttrType::SFLOAT_32_32_32_32);
3958
3959 immBegin(GPU_PRIM_TRIS, steps * 3 * 6);
3960
3961 /* 0.999 = prevent float inaccuracy for steps */
3962 for (dx = 0.0f; dx < 0.999f; dx += color_step) {
3963 const float dx_next = dx + color_step;
3964
3965 /* previous color */
3966 copy_v3_v3(col0[0], col1[0]);
3967 copy_v3_v3(col0[1], col1[1]);
3968 copy_v3_v3(col0[2], col1[2]);
3969 copy_v3_v3(col0[3], col1[3]);
3970
3971 /* new color */
3972 switch (type) {
3973 case GRAD_SV:
3974 draw_gradient_hsv_to_rgb(display, h, dx, 0.0, col1[0]);
3975 draw_gradient_hsv_to_rgb(display, h, dx, 0.333, col1[1]);
3976 draw_gradient_hsv_to_rgb(display, h, dx, 0.666, col1[2]);
3977 draw_gradient_hsv_to_rgb(display, h, dx, 1.0, col1[3]);
3978 break;
3979 case GRAD_HV:
3980 draw_gradient_hsv_to_rgb(display, dx_next, s, 0.0, col1[0]);
3981 draw_gradient_hsv_to_rgb(display, dx_next, s, 0.333, col1[1]);
3982 draw_gradient_hsv_to_rgb(display, dx_next, s, 0.666, col1[2]);
3983 draw_gradient_hsv_to_rgb(display, dx_next, s, 1.0, col1[3]);
3984 break;
3985 case GRAD_HS:
3986 draw_gradient_hsv_to_rgb(display, dx_next, 0.0, v, col1[0]);
3987 draw_gradient_hsv_to_rgb(display, dx_next, 0.333, v, col1[1]);
3988 draw_gradient_hsv_to_rgb(display, dx_next, 0.666, v, col1[2]);
3989 draw_gradient_hsv_to_rgb(display, dx_next, 1.0, v, col1[3]);
3990 break;
3991 case GRAD_H:
3992 /* annoying but without this the color shifts - could be solved some other way
3993 * - campbell */
3994 draw_gradient_hsv_to_rgb(display, dx_next, 1.0, 1.0, col1[0]);
3995 copy_v3_v3(col1[1], col1[0]);
3996 copy_v3_v3(col1[2], col1[0]);
3997 copy_v3_v3(col1[3], col1[0]);
3998 break;
3999 case GRAD_S:
4000 draw_gradient_hsv_to_rgb(display, h, dx, 1.0, col1[1]);
4001 copy_v3_v3(col1[0], col1[1]);
4002 copy_v3_v3(col1[2], col1[1]);
4003 copy_v3_v3(col1[3], col1[1]);
4004 break;
4005 case GRAD_V:
4006 draw_gradient_hsv_to_rgb(display, h, 1.0, dx, col1[2]);
4007 copy_v3_v3(col1[0], col1[2]);
4008 copy_v3_v3(col1[1], col1[2]);
4009 copy_v3_v3(col1[3], col1[2]);
4010 break;
4011 default:
4012 break;
4013 }
4014
4015 /* rect */
4016 sx1 = rect->xmin + dx * BLI_rcti_size_x(rect);
4017 sx2 = rect->xmin + dx_next * BLI_rcti_size_x(rect);
4018 sy = rect->ymin;
4019 dy = float(BLI_rcti_size_y(rect)) / 3.0f;
4020
4021 for (a = 0; a < 3; a++, sy += dy) {
4022 immAttr4f(col, col0[a][0], col0[a][1], col0[a][2], alpha);
4023 immVertex2f(pos, sx1, sy);
4024
4025 immAttr4f(col, col1[a][0], col1[a][1], col1[a][2], alpha);
4026 immVertex2f(pos, sx2, sy);
4027
4028 immAttr4f(col, col1[a + 1][0], col1[a + 1][1], col1[a + 1][2], alpha);
4029 immVertex2f(pos, sx2, sy + dy);
4030
4031 immAttr4f(col, col0[a][0], col0[a][1], col0[a][2], alpha);
4032 immVertex2f(pos, sx1, sy);
4033
4034 immAttr4f(col, col1[a + 1][0], col1[a + 1][1], col1[a + 1][2], alpha);
4035 immVertex2f(pos, sx2, sy + dy);
4036
4037 immAttr4f(col, col0[a + 1][0], col0[a + 1][1], col0[a + 1][2], alpha);
4038 immVertex2f(pos, sx1, sy + dy);
4039 }
4040 }
4041 immEnd();
4042
4044}
4045
4047 const ButtonHSVCube *hsv_but, const rcti *rect, const float *hsv, float *r_xp, float *r_yp)
4048{
4049 float x = 0.0f, y = 0.0f;
4050
4051 switch (hsv_but->gradient_type) {
4052 case GRAD_SV:
4053 x = hsv[1];
4054 y = hsv[2];
4055 break;
4056 case GRAD_HV:
4057 x = hsv[0];
4058 y = hsv[2];
4059 break;
4060 case GRAD_HS:
4061 x = hsv[0];
4062 y = hsv[1];
4063 break;
4064 case GRAD_H:
4065 x = hsv[0];
4066 y = 0.5;
4067 break;
4068 case GRAD_S:
4069 x = hsv[1];
4070 y = 0.5;
4071 break;
4072 case GRAD_V:
4073 x = hsv[2];
4074 y = 0.5;
4075 break;
4076 case GRAD_L_ALT:
4077 x = 0.5f;
4078 /* exception only for value strip - use the range set in but->min/max */
4079 y = hsv[2];
4080 break;
4081 case GRAD_V_ALT:
4082 x = 0.5f;
4083 /* exception only for value strip - use the range set in but->min/max */
4084 y = (hsv[2] - hsv_but->softmin) / (hsv_but->softmax - hsv_but->softmin);
4085 break;
4086 case GRAD_NONE:
4088 }
4089
4090 /* cursor */
4091 *r_xp = rect->xmin + x * BLI_rcti_size_x(rect);
4092 *r_yp = rect->ymin + y * BLI_rcti_size_y(rect);
4093}
4094
4095static void draw_but_HSVCUBE(Button *but, const rcti *rect)
4096{
4097 const ButtonHSVCube *hsv_but = static_cast<ButtonHSVCube *>(but);
4098 float rgb[3], rgb_perceptual[3];
4099 float x = 0.0f, y = 0.0f;
4100 const ColorManagedDisplay *display = block_cm_display_get(but->block);
4101 ColorPicker *cpicker = static_cast<ColorPicker *>(but->custom_data);
4102 float *hsv = cpicker->hsv_perceptual;
4103 float hsv_n[3];
4104
4105 /* Is this the larger color canvas or narrow color slider? */
4106 bool is_canvas = ELEM(hsv_but->gradient_type, GRAD_SV, GRAD_HV, GRAD_HS);
4107
4108 /* Initialize for compatibility. */
4109 copy_v3_v3(hsv_n, hsv);
4110
4111 button_v3_get(but, rgb);
4112 copy_v3_v3(rgb_perceptual, rgb);
4113 scene_linear_to_perceptual_space(but, rgb_perceptual);
4114 rgb_to_hsv_compat_v(rgb_perceptual, hsv_n);
4115
4116 if (!button_is_color_gamma(but)) {
4118 }
4119
4120 draw_gradient(rect, hsv_n, hsv_but->gradient_type, 1.0f, display);
4121
4122 hsvcube_pos_from_vals(hsv_but, rect, hsv_n, &x, &y);
4123
4124 const float zoom = 1.0f / but->block->aspect;
4125
4126 /* outline */
4127 const uint pos = GPU_vertformat_attr_add(
4128 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
4130 immUniformColor3ub(0, 0, 0);
4131 imm_draw_box_wire_2d(pos, (rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax));
4133
4134 if (is_canvas) {
4135 /* Round cursor in the large square area. */
4136 float margin = (4.0f * UI_SCALE_FAC);
4137 CLAMP(x, rect->xmin + margin, rect->xmax - margin);
4138 CLAMP(y, rect->ymin + margin, rect->ymax - margin);
4139 hsv_cursor(x, y, zoom, rgb, hsv, but->flag & UI_SELECT);
4140 }
4141 else {
4142 /* Square indicator in the narrow area. */
4143 rctf rectf;
4144 BLI_rctf_rcti_copy(&rectf, rect);
4145 const float margin = (2.0f * UI_SCALE_FAC);
4146 CLAMP(x, rect->xmin + margin, rect->xmax - margin);
4147 CLAMP(y, rect->ymin + margin, rect->ymax - margin);
4148 rectf.ymax += 1;
4149 const float cursor_width = std::max(BLI_rctf_size_y(&rectf) * 0.35f, 1.0f);
4150 rectf.xmin = x - cursor_width;
4151 rectf.xmax = x + cursor_width;
4152
4153 if (but->flag & UI_SELECT) {
4154 /* Make the indicator larger while the mouse button is pressed. */
4155 rectf.xmin -= U.pixelsize;
4156 rectf.xmax += U.pixelsize;
4157 rectf.ymin -= U.pixelsize;
4158 rectf.ymax += U.pixelsize;
4159 }
4160
4161 const float col[4] = {0.0f, 0.0f, 0.0f, 1.0f};
4162 draw_roundbox_4fv(&rectf, false, 0, col);
4163
4164 rectf.xmin += 1.0f;
4165 rectf.xmax -= 1.0f;
4166 const float inner[4] = {1.0f, 1.0f, 1.0f, 1.0f};
4167 const float col2[4] = {0.0f, 0.0f, 0.0f, 0.0f};
4168 draw_roundbox_4fv_ex(&rectf, col2, nullptr, 0.0f, inner, U.pixelsize, 0.0f);
4169 }
4170}
4171
4172/* vertical 'value' slider, using new widget code */
4173static void draw_but_HSV_v(Button *but, const rcti *rect)
4174{
4175 const ButtonHSVCube *hsv_but = static_cast<ButtonHSVCube *>(but);
4176 float rgb[3], hsv[3], v;
4177
4178 button_v3_get(but, rgb);
4180
4181 if (hsv_but->gradient_type == GRAD_L_ALT) {
4182 rgb_to_hsl_v(rgb, hsv);
4183 }
4184 else {
4185 rgb_to_hsv_v(rgb, hsv);
4186 }
4187 v = hsv[2];
4188
4189 /* map v from property range to [0,1] */
4190 if (hsv_but->gradient_type == GRAD_V_ALT) {
4191 const float min = but->softmin, max = but->softmax;
4192 v = (v - min) / (max - min);
4193 }
4194
4195 rctf rectf;
4196 BLI_rctf_rcti_copy(&rectf, rect);
4197
4198 const float inner1[4] = {1.0f, 1.0f, 1.0f, 1.0f};
4199 const float inner2[4] = {0.0f, 0.0f, 0.0f, 1.0f};
4200 const float outline[4] = {0.0f, 0.0f, 0.0f, 1.0f};
4201
4202 const float outline_width = (BLI_rctf_size_x(&rectf) < 4.0f) ? 0.0f : 1.0f;
4203 draw_roundbox_4fv_ex(&rectf, inner1, inner2, U.pixelsize, outline, outline_width, 0.0f);
4204
4205 /* cursor */
4206 float y = rect->ymin + v * BLI_rcti_size_y(rect);
4207 CLAMP(y, float(rect->ymin) + (2.0f * UI_SCALE_FAC), float(rect->ymax) - (2.0f * UI_SCALE_FAC));
4208 const float cursor_height = std::max(BLI_rctf_size_x(&rectf) * 0.35f, 1.0f);
4209 rectf.ymin = y - cursor_height;
4210 rectf.ymax = y + cursor_height;
4211 float col[4] = {0.0f, 0.0f, 0.0f, 1.0f};
4212
4213 if (but->flag & UI_SELECT) {
4214 /* Enlarge the indicator while the mouse button is pressed down. */
4215 rectf.xmin -= U.pixelsize;
4216 rectf.xmax += U.pixelsize;
4217 rectf.ymin -= U.pixelsize;
4218 rectf.ymax += U.pixelsize;
4219 }
4220
4221 draw_roundbox_4fv(&rectf, false, 0.0f, col);
4222
4223 rectf.ymin += 1.0f;
4224 rectf.ymax -= 1.0f;
4225 const float col2[4] = {v, v, v, 1.0f};
4226 draw_roundbox_4fv_ex(&rectf, col2, nullptr, 0.0f, inner1, U.pixelsize, 0.0f);
4227}
4228
4230static void draw_separator(const uiWidgetColors *wcol, Button *but, const rcti *rect)
4231{
4232 const ButtonSeparatorLine *but_line = static_cast<ButtonSeparatorLine *>(but);
4233 const bool vertical = but_line->is_vertical;
4234 const int mid = vertical ? BLI_rcti_cent_x(rect) : BLI_rcti_cent_y(rect);
4235 const uchar col[4] = {
4236 wcol->text[0],
4237 wcol->text[1],
4238 wcol->text[2],
4239 30,
4240 };
4241
4242 const uint pos = GPU_vertformat_attr_add(
4243 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
4245
4248 GPU_line_width(1.0f);
4249
4251
4252 if (vertical) {
4253 immVertex2f(pos, mid, rect->ymin);
4254 immVertex2f(pos, mid, rect->ymax);
4255 }
4256 else {
4257 immVertex2f(pos, rect->xmin, mid);
4258 immVertex2f(pos, rect->xmax, mid);
4259 }
4260
4261 immEnd();
4262
4264
4266}
4267
4269
4270/* -------------------------------------------------------------------- */
4273
4274#define NUM_BUT_PADDING_FACTOR 0.425f
4275
4276static void widget_numbut_draw(const Button *but,
4277 uiWidgetColors *wcol,
4278 rcti *rect,
4279 const float zoom,
4280 const WidgetStateInfo *state,
4281 int roundboxalign,
4282 bool emboss)
4283{
4284 const float rad = widget_radius_from_zoom(zoom, wcol);
4285 const int handle_width = min_ii(BLI_rcti_size_x(rect) / 3, BLI_rcti_size_y(rect) * 0.7f);
4286
4287 if (state->but_flag & UI_SELECT) {
4288 std::swap(wcol->shadetop, wcol->shadedown);
4289 }
4290
4291 WidgetBase wtb;
4292 widget_init(&wtb);
4293
4294 if (!emboss) {
4295 round_box_edges(&wtb, roundboxalign, rect, rad);
4296 }
4297 else {
4298 wtb.draw_inner = false;
4299 wtb.draw_outline = false;
4300 }
4301
4302 /* decoration */
4303 if (((state->but_flag & UI_HOVER) || (U.uiflag2 & USER_ALWAYS_SHOW_NUMBER_ARROWS)) &&
4304 !state->is_text_input)
4305 {
4306 uiWidgetColors wcol_zone;
4307 WidgetBase wtb_zone;
4308 rcti rect_zone;
4309 int roundboxalign_zone;
4310
4311 /* left arrow zone */
4312 widget_init(&wtb_zone);
4313 wtb_zone.draw_outline = false;
4314 wtb_zone.draw_emboss = false;
4315
4316 wcol_zone = *wcol;
4317 copy_v3_v3_uchar(wcol_zone.item, wcol->text);
4318 if (!(state->but_flag & UI_HOVER)) {
4319 wcol_zone.item[3] = 180;
4320 }
4321 if (state->but_drawflag & BUT_HOVER_LEFT) {
4322 widget_active_color(&wcol_zone);
4323 }
4324
4325 rect_zone = *rect;
4326 rect_zone.xmax = rect->xmin + handle_width + U.pixelsize;
4327 roundboxalign_zone = roundboxalign & ~(CNR_TOP_RIGHT | CNR_BOTTOM_RIGHT);
4328 round_box_edges(&wtb_zone, roundboxalign_zone, &rect_zone, rad);
4329
4330 shape_preset_init_number_arrows(&wtb_zone.tria1, &rect_zone, 0.6f, 'l');
4331 widgetbase_draw(&wtb_zone, &wcol_zone);
4332
4333 /* right arrow zone */
4334 widget_init(&wtb_zone);
4335 wtb_zone.draw_outline = false;
4336 wtb_zone.draw_emboss = false;
4337 wtb_zone.tria1.type = ROUNDBOX_TRIA_ARROWS;
4338
4339 wcol_zone = *wcol;
4340 copy_v3_v3_uchar(wcol_zone.item, wcol->text);
4341 if (!(state->but_flag & UI_HOVER)) {
4342 wcol_zone.item[3] = 180;
4343 }
4344 if (state->but_drawflag & BUT_HOVER_RIGHT) {
4345 widget_active_color(&wcol_zone);
4346 }
4347
4348 rect_zone = *rect;
4349 rect_zone.xmin = rect->xmax - handle_width - U.pixelsize;
4350 roundboxalign_zone = roundboxalign & ~(CNR_TOP_LEFT | CNR_BOTTOM_LEFT);
4351 round_box_edges(&wtb_zone, roundboxalign_zone, &rect_zone, rad);
4352
4353 shape_preset_init_number_arrows(&wtb_zone.tria2, &rect_zone, 0.6f, 'r');
4354 widgetbase_draw(&wtb_zone, &wcol_zone);
4355
4356 /* middle highlight zone */
4357 widget_init(&wtb_zone);
4358 wtb_zone.draw_outline = false;
4359 wtb_zone.draw_emboss = false;
4360
4361 wcol_zone = *wcol;
4362 copy_v3_v3_uchar(wcol_zone.item, wcol->text);
4363 if ((state->but_flag & UI_HOVER) &&
4364 !(state->but_drawflag & (BUT_HOVER_LEFT | BUT_HOVER_RIGHT)))
4365 {
4366 widget_active_color(&wcol_zone);
4367 }
4368
4369 rect_zone = *rect;
4370 rect_zone.xmin = rect->xmin + handle_width - U.pixelsize;
4371 rect_zone.xmax = rect->xmax - handle_width + U.pixelsize;
4372 round_box_edges(&wtb_zone, 0, &rect_zone, 0);
4373 widgetbase_draw(&wtb_zone, &wcol_zone);
4374
4375 /* outline */
4376 wtb.draw_inner = false;
4377 wtb.draw_emboss = draw_emboss(but);
4378 widgetbase_draw(&wtb, wcol);
4379 }
4380 else {
4381 /* inner and outline */
4382 wtb.draw_emboss = draw_emboss(but);
4383 widgetbase_draw(&wtb, wcol);
4384 }
4385
4386 if (!state->is_text_input) {
4387 const float text_padding = NUM_BUT_PADDING_FACTOR * BLI_rcti_size_y(rect);
4388
4389 rect->xmin += text_padding;
4390 rect->xmax -= text_padding;
4391 }
4392}
4393
4394static void widget_numbut(Button *but,
4395 uiWidgetColors *wcol,
4396 rcti *rect,
4397 const WidgetStateInfo *state,
4398 int roundboxalign,
4399 const float zoom)
4400{
4401 widget_numbut_draw(but, wcol, rect, zoom, state, roundboxalign, false);
4402}
4403
4405 rcti *rect,
4406 const WidgetStateInfo *state,
4407 int roundboxalign,
4408 const float zoom)
4409{
4410 WidgetBase wtb;
4411 widget_init(&wtb);
4412
4413 const float rad = widget_radius_from_zoom(zoom, wcol);
4414 round_box_edges(&wtb, roundboxalign, rect, rad);
4415
4416 /* decoration */
4418 /* copy size and center to 2nd tria */
4419 wtb.tria2 = wtb.tria1;
4420
4422 wtb.draw_inner = false;
4423 wtb.draw_outline = false;
4424 wtb.draw_emboss = false;
4425 }
4426
4427 widgetbase_draw(&wtb, wcol);
4428
4429 /* text space, arrows are about 0.6 height of button */
4430 rect->xmax -= (6 * BLI_rcti_size_y(rect)) / 10;
4431}
4432
4436static void widget_menubut_embossn(const Button * /*but*/,
4437 uiWidgetColors *wcol,
4438 rcti *rect,
4439 const WidgetStateInfo * /*state*/,
4440 int /*roundboxalign*/)
4441{
4442 WidgetBase wtb;
4443 widget_init(&wtb);
4444 wtb.draw_inner = false;
4445 wtb.draw_outline = false;
4446
4447 /* decoration */
4449 /* copy size and center to 2nd tria */
4450 wtb.tria2 = wtb.tria1;
4451
4452 widgetbase_draw(&wtb, wcol);
4453}
4454
4458static void widget_numbut_embossn(const Button *but,
4459 uiWidgetColors *wcol,
4460 rcti *rect,
4461 const WidgetStateInfo *state,
4462 int roundboxalign,
4463 const float zoom)
4464{
4465 widget_numbut_draw(but, wcol, rect, zoom, state, roundboxalign, true);
4466}
4467
4468void draw_widget_scroll(uiWidgetColors *wcol, const rcti *rect, const rcti *slider, int state)
4469{
4470 WidgetBase wtb;
4471
4472 widget_init(&wtb);
4473
4474 /* determine horizontal/vertical */
4475 const bool horizontal = (BLI_rcti_size_x(rect) > BLI_rcti_size_y(rect));
4476
4477 const float rad = (horizontal) ? wcol->roundness * BLI_rcti_size_y(rect) :
4478 wcol->roundness * BLI_rcti_size_x(rect);
4479
4480 wtb.uniform_params.shade_dir = (horizontal) ? 1.0f : 0.0;
4481
4482 /* draw back part, colors swapped and shading inverted */
4483 if (horizontal) {
4484 std::swap(wcol->shadetop, wcol->shadedown);
4485 }
4486
4487 round_box_edges(&wtb, CNR_ALL, rect, rad);
4488 widgetbase_draw(&wtb, wcol);
4489
4490 /* slider */
4491 if ((BLI_rcti_size_x(slider) < 2) || (BLI_rcti_size_y(slider) < 2)) {
4492 /* pass */
4493 }
4494 else {
4495 std::swap(wcol->shadetop, wcol->shadedown);
4496
4497 copy_v4_v4_uchar(wcol->inner, wcol->item);
4498
4499 if (wcol->shadetop > wcol->shadedown) {
4500 wcol->shadetop += 20; /* XXX violates themes... */
4501 }
4502 else {
4503 wcol->shadedown += 20;
4504 }
4505
4506 if (state & SCROLL_PRESSED) {
4507 wcol->inner[0] = wcol->inner[0] >= 250 ? 255 : wcol->inner[0] + 5;
4508 wcol->inner[1] = wcol->inner[1] >= 250 ? 255 : wcol->inner[1] + 5;
4509 wcol->inner[2] = wcol->inner[2] >= 250 ? 255 : wcol->inner[2] + 5;
4510 }
4511
4512 /* draw */
4513 wtb.draw_emboss = false; /* only emboss once */
4514
4515 round_box_edges(&wtb, CNR_ALL, slider, rad);
4516
4517 if (state & SCROLL_ARROWS) {
4518 const uchar lightness = srgb_to_grayscale_byte(wcol->item);
4519 if (lightness > 70) {
4520 wcol->item[0] = 0;
4521 wcol->item[1] = 0;
4522 wcol->item[2] = 0;
4523 wcol->item[3] = 128;
4524 }
4525 else {
4526 wcol->item[0] = 255;
4527 wcol->item[1] = 255;
4528 wcol->item[2] = 255;
4529 wcol->item[3] = 128;
4530 }
4531
4532 if (horizontal) {
4533 rcti slider_inset = *slider;
4534 slider_inset.xmin += 0.05 * U.widget_unit;
4535 slider_inset.xmax -= 0.05 * U.widget_unit;
4536 shape_preset_init_scroll_circle(&wtb.tria1, &slider_inset, 0.6f, 'l');
4537 shape_preset_init_scroll_circle(&wtb.tria2, &slider_inset, 0.6f, 'r');
4538 }
4539 else {
4540 shape_preset_init_scroll_circle(&wtb.tria1, slider, 0.6f, 'b');
4541 shape_preset_init_scroll_circle(&wtb.tria2, slider, 0.6f, 't');
4542 }
4543 }
4544 widgetbase_draw(&wtb, wcol);
4545 }
4546}
4547
4548static void widget_scroll(Button *but,
4549 uiWidgetColors *wcol,
4550 rcti *rect,
4551 const WidgetStateInfo *state,
4552 int /*roundboxalign*/,
4553 const float /*zoom*/)
4554{
4555 const ButtonScrollBar *but_scroll = reinterpret_cast<const ButtonScrollBar *>(but);
4556 const float height = but_scroll->visual_height;
4557
4558 /* calculate slider part */
4559 const float value = float(button_value_get(but));
4560
4561 const float size = max_ff((but->softmax + height - but->softmin), 2.0f);
4562
4563 /* position */
4564 rcti rect1 = *rect;
4565
4566 /* determine horizontal/vertical */
4567 const bool horizontal = (BLI_rcti_size_x(rect) > BLI_rcti_size_y(rect));
4568
4569 if (horizontal) {
4570 const float fac = BLI_rcti_size_x(rect) / size;
4571 rect1.xmin = rect1.xmin + ceilf(fac * (value - but->softmin));
4572 rect1.xmax = rect1.xmin + ceilf(fac * (height - but->softmin));
4573
4574 /* Ensure minimum size. */
4575 const float min = BLI_rcti_size_y(rect);
4576
4577 if (BLI_rcti_size_x(&rect1) < min) {
4578 rect1.xmax = rect1.xmin + min;
4579
4580 if (rect1.xmax > rect->xmax) {
4581 rect1.xmax = rect->xmax;
4582 rect1.xmin = max_ii(rect1.xmax - min, rect->xmin);
4583 }
4584 }
4585 }
4586 else {
4587 const float fac = BLI_rcti_size_y(rect) / size;
4588 rect1.ymax = rect1.ymax - ceilf(fac * (value - but->softmin));
4589 rect1.ymin = rect1.ymax - ceilf(fac * (height - but->softmin));
4590
4591 /* Ensure minimum size. */
4592 const float min = BLI_rcti_size_x(rect);
4593
4594 if (BLI_rcti_size_y(&rect1) < min) {
4595 rect1.ymax = rect1.ymin + min;
4596
4597 if (rect1.ymax > rect->ymax) {
4598 rect1.ymax = rect->ymax;
4599 rect1.ymin = max_ii(rect1.ymax - min, rect->ymin);
4600 }
4601 }
4602 }
4603
4604 draw_widget_scroll(wcol, rect, &rect1, (state->but_flag & UI_SELECT) ? SCROLL_PRESSED : 0);
4605}
4606
4608 uiWidgetColors *wcol,
4609 rcti *rect,
4610 int roundboxalign,
4611 const float zoom)
4612{
4613 rcti rect_prog = *rect, rect_bar = *rect;
4614
4615 WidgetBase wtb, wtb_bar;
4616 widget_init(&wtb);
4617 widget_init(&wtb_bar);
4618
4619 /* round corners */
4620 const float factor = but_progress->progress_factor;
4621 const float ofs = widget_radius_from_zoom(zoom, wcol);
4622 float w = factor * BLI_rcti_size_x(&rect_prog);
4623
4624 /* Ensure minimum size. */
4625 w = std::max(w, ofs);
4626
4627 rect_bar.xmax = rect_bar.xmin + w;
4628
4629 round_box_edges(&wtb, roundboxalign, &rect_prog, ofs);
4630 round_box_edges(&wtb_bar, roundboxalign, &rect_bar, ofs);
4631
4632 wtb.draw_outline = true;
4633 widgetbase_draw(&wtb, wcol);
4634
4635 /* "slider" bar color */
4636 copy_v3_v3_uchar(wcol->inner, wcol->item);
4637 widgetbase_draw(&wtb_bar, wcol);
4638}
4639
4644 uiWidgetColors *wcol,
4645 rcti *rect)
4646{
4647 const float ring_width = 0.6; /* 0.0 would be a pie. */
4648 const float outer_rad = (rect->ymax - rect->ymin) / 2.0f;
4649 const float inner_rad = outer_rad * ring_width;
4650 const float x = rect->xmin + outer_rad;
4651 const float y = rect->ymin + outer_rad;
4652 const float start = 0.0f;
4653 const float end = but_progress->progress_factor * 360.0f;
4654 GPUVertFormat *format = immVertexFormat();
4655 const uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
4659
4660 for (int i = 0; i < UI_PIXEL_AA_JITTER; i++) {
4662 x + ui_pixel_jitter[i][0],
4663 y + ui_pixel_jitter[i][1],
4664 inner_rad,
4665 outer_rad,
4666 48,
4667 start,
4668 end);
4669 }
4671
4672 if (but_progress->drawstr[0]) {
4673 rect->xmin += UI_UNIT_X;
4674 }
4675}
4676
4678 uiWidgetColors *wcol,
4679 rcti *rect,
4680 const WidgetStateInfo * /*state*/,
4681 int roundboxalign,
4682 const float zoom)
4683{
4684 ButtonProgress *but_progress = static_cast<ButtonProgress *>(but);
4685 switch (but_progress->progress_type) {
4686 case ButProgressType::Bar: {
4687 widget_progress_type_bar(but_progress, wcol, rect, roundboxalign, zoom);
4688 break;
4689 }
4690 case ButProgressType::Ring: {
4691 widget_progress_type_ring(but_progress, wcol, rect);
4692 break;
4693 }
4694 }
4695}
4696
4697static void widget_nodesocket(Button *but,
4698 uiWidgetColors * /*wcol*/,
4699 rcti *rect,
4700 const WidgetStateInfo * /*state*/,
4701 int /*roundboxalign*/,
4702 const float zoom)
4703{
4704 ColorTheme4f socket_color;
4705 rgba_uchar_to_float(socket_color, but->col);
4706
4707 ColorTheme4f outline_color;
4709 outline_color.a = 1.0f;
4710
4711 const int cent_x = BLI_rcti_cent_x(rect);
4712 const int cent_y = BLI_rcti_cent_y(rect);
4713 const int socket_radius = 0.25f * BLI_rcti_size_y(rect);
4714
4715 rctf socket_rect;
4716 socket_rect.xmin = cent_x - socket_radius;
4717 socket_rect.xmax = cent_x + socket_radius;
4718 socket_rect.ymin = cent_y - socket_radius;
4719 socket_rect.ymax = cent_y + socket_radius;
4720
4724
4726 socket_color,
4727 outline_color,
4728 U.pixelsize,
4730 1.0f / zoom);
4731}
4732
4733static void widget_numslider(Button *but,
4734 uiWidgetColors *wcol,
4735 rcti *rect,
4736 const WidgetStateInfo *state,
4737 int roundboxalign,
4738 const float zoom)
4739{
4740 WidgetBase wtb, wtb1;
4741 widget_init(&wtb);
4742 widget_init(&wtb1);
4743
4744 /* Backdrop first. */
4745 const float rad = widget_radius_from_zoom(zoom, wcol);
4746 round_box_edges(&wtb, roundboxalign, rect, rad);
4747
4748 wtb.draw_outline = false;
4749 widgetbase_draw(&wtb, wcol);
4750
4751 /* Draw slider part only when not in text editing. */
4752 if (!state->is_text_input && !(but->drawflag & BUT_INDETERMINATE)) {
4753 int roundboxalign_slider = roundboxalign;
4754
4755 uchar outline[3];
4756 copy_v3_v3_uchar(outline, wcol->outline);
4757 copy_v3_v3_uchar(wcol->outline, wcol->item);
4758 copy_v3_v3_uchar(wcol->inner, wcol->item);
4759
4760 if (!(state->but_flag & UI_SELECT)) {
4761 std::swap(wcol->shadetop, wcol->shadedown);
4762 }
4763
4764 rcti rect1 = *rect;
4765 float factor, factor_ui;
4766 float factor_discard = 1.0f; /* No discard. */
4767 const float value = float(button_value_get(but));
4768 const float softmin = but->softmin;
4769 const float softmax = but->softmax;
4770 const float softrange = softmax - softmin;
4771 const PropertyScaleType scale_type = button_scale_type(but);
4772
4773 switch (scale_type) {
4774 case PROP_SCALE_LINEAR: {
4775 factor = (value - softmin) / softrange;
4776 break;
4777 }
4778 case PROP_SCALE_LOG: {
4779 const float logmin = fmaxf(softmin, 0.5e-8f);
4780 const float base = softmax / logmin;
4781 factor = logf(value / logmin) / logf(base);
4782 break;
4783 }
4784 case PROP_SCALE_CUBIC: {
4785 const float cubicmin = cube_f(softmin);
4786 const float cubicmax = cube_f(softmax);
4787 const float cubicrange = cubicmax - cubicmin;
4788 const float f = (value - softmin) * cubicrange / softrange + cubicmin;
4789 factor = (cbrtf(f) - softmin) / softrange;
4790 break;
4791 }
4792 }
4793
4794 const float width = float(BLI_rcti_size_x(rect));
4795 factor_ui = factor * width;
4796 /* The rectangle width needs to be at least twice the corner radius for the round corners
4797 * to be drawn properly. */
4798 const float min_width = 2.0f * rad;
4799
4800 if (factor_ui > width - rad) {
4801 /* Left part + middle part + right part. */
4802 factor_discard = factor;
4803 }
4804 else if (factor_ui > min_width) {
4805 /* Left part + middle part. */
4806 roundboxalign_slider &= ~(CNR_TOP_RIGHT | CNR_BOTTOM_RIGHT);
4807 rect1.xmax = rect1.xmin + factor_ui;
4808 }
4809 else {
4810 /* Left part */
4811 roundboxalign_slider &= ~(CNR_TOP_RIGHT | CNR_BOTTOM_RIGHT);
4812 rect1.xmax = rect1.xmin + min_width;
4813 factor_discard = factor_ui / min_width;
4814 }
4815
4816 round_box_edges(&wtb1, roundboxalign_slider, &rect1, rad);
4817 wtb1.draw_outline = false;
4818 wtb1.draw_emboss = false;
4819 widgetbase_set_uniform_discard_factor(&wtb1, factor_discard);
4820 widgetbase_draw(&wtb1, wcol);
4821
4822 copy_v3_v3_uchar(wcol->outline, outline);
4823
4824 if (!(state->but_flag & UI_SELECT)) {
4825 std::swap(wcol->shadetop, wcol->shadedown);
4826 }
4827 }
4828
4829 /* Outline. */
4830 wtb.draw_outline = true;
4831 wtb.draw_inner = false;
4832 wtb.draw_emboss = false;
4833 widgetbase_draw(&wtb, wcol);
4834
4835 /* Add space at either side of the button so text aligns with number-buttons
4836 * (which have arrow icons). */
4837 if (!state->is_text_input) {
4838 const float text_padding = NUM_BUT_PADDING_FACTOR * BLI_rcti_size_y(rect);
4839 rect->xmax -= text_padding;
4840 rect->xmin += text_padding;
4841 }
4842}
4843
4844/* I think 3 is sufficient border to indicate keyed status */
4845#define SWATCH_KEYED_BORDER 3
4846
4847static void widget_swatch(Button *but,
4848 uiWidgetColors *wcol,
4849 rcti *rect,
4850 const WidgetStateInfo *state,
4851 int roundboxalign,
4852 const float zoom)
4853{
4855 ButtonColor *color_but = static_cast<ButtonColor *>(but);
4856 float col[4];
4857
4858 col[3] = 1.0f;
4859
4860 if (but->rnaprop) {
4861 BLI_assert(but->rnaindex == -1);
4862
4863 if (RNA_property_array_length(&but->rnapoin, but->rnaprop) >= 4) {
4864 col[3] = RNA_property_float_get_index(&but->rnapoin, but->rnaprop, 3);
4865 }
4866 }
4867
4868 WidgetBase wtb;
4869 widget_init(&wtb);
4870
4871 const float rad = widget_radius_from_zoom(zoom, wcol);
4872 round_box_edges(&wtb, roundboxalign, rect, rad);
4873
4874 button_v3_get(but, col);
4875
4876 if (but->drawflag & BUT_INDETERMINATE) {
4877 col[0] = col[1] = col[2] = col[3] = 0.5f;
4878 }
4879
4880 if ((state->but_flag &
4882 (state->but_drawflag & BUT_ANIMATED_CHANGED))
4883 {
4884 /* draw based on state - color for keyed etc */
4885 widgetbase_draw(&wtb, wcol);
4886
4887 /* inset to draw swatch color */
4888 rect->xmin += SWATCH_KEYED_BORDER;
4889 rect->xmax -= SWATCH_KEYED_BORDER;
4890 rect->ymin += SWATCH_KEYED_BORDER;
4891 rect->ymax -= SWATCH_KEYED_BORDER;
4892
4893 round_box_edges(&wtb, roundboxalign, rect, rad);
4894 }
4895
4896 if (!button_is_color_gamma(but)) {
4898 }
4899
4900 const bool show_alpha_checkers = col[3] < 1.0f;
4901
4902 /* Now we reduce alpha of the inner color (i.e. the color shown)
4903 * so that this setting can look grayed out, while retaining
4904 * the checkerboard (for transparent values). This is needed
4905 * here as the effects of widget_type_color_disabled() are overwritten. */
4906 col[3] *= widget_alpha_factor(state);
4907
4908 widgetbase_draw_color(&wtb, wcol, col, show_alpha_checkers);
4909 if (color_but->is_palette_color &&
4910 (id_cast<Palette *>(but->rnapoin.owner_id))->active_color == color_but->palette_color_index)
4911 {
4912 const float width = rect->xmax - rect->xmin;
4913 const float height = rect->ymax - rect->ymin;
4914 /* find color luminance and change it slightly */
4915 float bw = srgb_to_grayscale(col);
4916
4917 bw += (bw < 0.5f) ? 0.5f : -0.5f;
4918
4919 /* We are drawing on top of widget bases. Flush cache. */
4923
4924 const uint pos = GPU_vertformat_attr_add(
4925 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
4927
4928 immUniformColor3f(bw, bw, bw);
4930 immVertex2f(pos, rect->xmin + 0.1f * width, rect->ymin + 0.9f * height);
4931 immVertex2f(pos, rect->xmin + 0.1f * width, rect->ymin + 0.5f * height);
4932 immVertex2f(pos, rect->xmin + 0.5f * width, rect->ymin + 0.9f * height);
4933 immEnd();
4934
4936 }
4937}
4938
4939static void widget_unitvec(Button *but,
4940 uiWidgetColors *wcol,
4941 rcti *rect,
4942 const WidgetStateInfo * /*state*/,
4943 int /*roundboxalign*/,
4944 const float zoom)
4945{
4946 const float rad = widget_radius_from_zoom(zoom, wcol);
4947 draw_but_UNITVEC(but, wcol, rect, rad);
4948}
4949
4951 uiWidgetColors *wcol,
4952 rcti *rect,
4953 const WidgetStateInfo *state,
4954 int roundboxalign,
4955 const float zoom)
4956{
4957 if (state->but_flag &
4959 but->emboss != EmbossType::None)
4960 {
4961 WidgetBase wtb;
4962 widget_init(&wtb);
4963 wtb.draw_outline = false;
4964
4965 const float rad = widget_radius_from_zoom(zoom, wcol);
4966 round_box_edges(&wtb, CNR_ALL, rect, rad);
4967 widgetbase_draw(&wtb, wcol);
4968 }
4969 else if (but->type == ButtonType::Num) {
4970 /* Draw number buttons still with left/right
4971 * triangles when field is not embossed */
4972 widget_numbut_embossn(but, wcol, rect, state, roundboxalign, zoom);
4973 }
4974 else if (but->type == ButtonType::Menu) {
4975 /* Draw menu buttons still with down arrow. */
4976 widget_menubut_embossn(but, wcol, rect, state, roundboxalign);
4977 }
4978 else if (but->type == ButtonType::Text && static_cast<ButtonText *>(but)->use_label_style) {
4979 if (state->but_flag & UI_HOVER && !(state->but_flag & UI_SELECT)) {
4981 }
4982 }
4983}
4984
4986 rcti *rect,
4987 const WidgetStateInfo *state,
4988 int roundboxalign,
4989 const float zoom)
4990{
4991 if (state->but_flag & UI_SELECT) {
4992 std::swap(wcol->shadetop, wcol->shadedown);
4993 }
4994
4995 WidgetBase wtb;
4996 widget_init(&wtb);
4997
4998 const float rad = widget_radius_from_zoom(zoom, wcol);
4999 round_box_edges(&wtb, roundboxalign, rect, rad);
5000
5001 widgetbase_draw(&wtb, wcol);
5002}
5003
5005 rcti *rect,
5006 const WidgetStateInfo * /*state*/,
5007 int roundboxalign,
5008 const float zoom)
5009{
5010 WidgetBase wtb;
5011 widget_init(&wtb);
5012
5013 const float rad = widget_radius_from_zoom(zoom, wcol);
5014 round_box_edges(&wtb, roundboxalign, rect, rad);
5015
5016 /* decoration */
5017 widgetbase_draw(&wtb, wcol);
5018}
5019
5021 rcti *rect,
5022 const WidgetStateInfo *state,
5023 int roundboxalign,
5024 const float zoom)
5025{
5026 float back[4];
5028
5029 if ((state->but_flag & UI_HOVER) || (back[3] < 1.0f)) {
5030 WidgetBase wtb;
5031 const float rad = widget_radius_from_zoom(zoom, wcol);
5032
5033 if (state->but_flag & UI_HOVER) {
5034 copy_v4_v4_uchar(wcol->inner, wcol->inner_sel);
5035 copy_v3_v3_uchar(wcol->text, wcol->text_sel);
5036 }
5037 else {
5038 wcol->inner[3] *= 1.0f - back[3];
5039 wcol->outline[3] = 0.0f;
5040 }
5041
5042 widget_init(&wtb);
5043
5044 /* half rounded */
5045 round_box_edges(&wtb, roundboxalign, rect, rad);
5046
5047 widgetbase_draw(&wtb, wcol);
5048 }
5049}
5050
5052 rcti *rect,
5053 const WidgetStateInfo * /*state*/,
5054 int /*roundboxalign*/,
5055 const float zoom)
5056{
5057 WidgetBase wtb;
5058 widget_init(&wtb);
5059
5060 /* Padding on the sides. */
5061 const float padding = zoom * 0.125f * U.widget_unit;
5062 rect->xmin += padding;
5063 rect->xmax -= padding;
5064
5065 const float rad = widget_radius_from_zoom(zoom, wcol);
5066
5067 round_box_edges(&wtb, CNR_ALL, rect, rad);
5068
5069 widgetbase_draw(&wtb, wcol);
5070}
5071
5073 rcti *rect,
5074 const WidgetStateInfo * /*state*/,
5075 int /*roundboxalign*/,
5076 const float zoom)
5077{
5078 /* This function is used for menu items placed close to each other horizontally, e.g. the matcap
5079 * preview popup or the row of collection color icons in the Outliner context menu. Don't use
5080 * padding on the sides like the normal menu item. */
5081
5082 WidgetBase wtb;
5083 widget_init(&wtb);
5084
5085 /* No outline. */
5086 wtb.draw_outline = false;
5087 const float rad = widget_radius_from_zoom(zoom, wcol);
5088 round_box_edges(&wtb, CNR_ALL, rect, rad);
5089
5090 widgetbase_draw(&wtb, wcol);
5091}
5092
5094 uiWidgetColors *wcol,
5095 rcti *rect,
5096 const WidgetStateInfo * /*state*/,
5097 int /*roundboxalign*/,
5098 const float zoom)
5099{
5100 const float fac = but->block->pie_data ? but->block->pie_data->alphafac : 1.0f;
5101
5102 WidgetBase wtb;
5103 widget_init(&wtb);
5104
5105 wtb.draw_emboss = false;
5106
5107 const float rad = widget_radius_from_zoom(zoom, wcol);
5108 round_box_edges(&wtb, CNR_ALL, rect, rad);
5109
5110 wcol->inner[3] *= fac;
5111 wcol->inner_sel[3] *= fac;
5112 wcol->item[3] *= fac;
5113 wcol->text[3] *= fac;
5114 wcol->text_sel[3] *= fac;
5115 wcol->outline[3] *= fac;
5116
5117 widgetbase_draw(&wtb, wcol);
5118}
5119
5121 uiWidgetColors *wcol,
5122 rcti *rect,
5123 const WidgetStateInfo *state,
5124 int /*roundboxalign*/,
5125 const float zoom)
5126{
5127 rcti draw_rect = *rect;
5128 bool is_selected = state->but_flag & UI_SELECT;
5129
5130 if (but->type == ButtonType::ViewItem) {
5131 ButtonViewItem *item_but = static_cast<ButtonViewItem *>(but);
5132 AbstractViewItem &view_item = *item_but->view_item;
5133
5134 if (!view_item.is_active() && view_item.is_selected()) {
5135 copy_v4_v4_uchar(wcol->inner, wcol->inner_sel);
5136 color_blend_v3_v3(wcol->inner, wcol->outline, 0.5);
5137 is_selected = true;
5138 }
5139 if (item_but->draw_width > 0) {
5140 BLI_rcti_resize_x(&draw_rect, zoom * item_but->draw_width);
5141 }
5142 if (item_but->draw_height > 0) {
5143 BLI_rcti_resize_y(&draw_rect, zoom * item_but->draw_height);
5144 }
5145 }
5146
5147 WidgetBase wtb;
5148 widget_init(&wtb);
5149
5150 const float rad = widget_radius_from_zoom(zoom, wcol);
5151 round_box_edges(&wtb, CNR_ALL, &draw_rect, rad);
5152
5153 if (state->but_flag & UI_HOVER) {
5154 color_blend_v3_v3(wcol->inner, wcol->text, 0.2);
5155 wcol->inner[3] = is_selected ? 255 : 20;
5156 }
5157
5158 widgetbase_draw(&wtb, wcol);
5159}
5160
5162 uiWidgetColors *wcol,
5163 rcti *rect,
5164 const WidgetStateInfo *state,
5165 int roundboxalign,
5166 const float zoom)
5167{
5169 widget_list_itembut(but, wcol, rect, state, roundboxalign, zoom);
5170 }
5171
5172 const BIFIconID icon = button_icon(but);
5174 rect,
5175 but->drawstr,
5176 icon,
5177 wcol->text,
5180}
5181
5183 rcti *rect,
5184 const WidgetStateInfo *state,
5185 int /*roundboxalign*/,
5186 const float /*zoom*/)
5187{
5188 /* For a right aligned layout (signified by #BUT_TEXT_RIGHT), draw the text on the left of the
5189 * checkbox. */
5190 const bool text_before_widget = (state->but_drawflag & BUT_TEXT_RIGHT);
5191 rcti recttemp = *rect;
5192
5193 WidgetBase wtb;
5194 widget_init(&wtb);
5195
5196 /* square */
5197 if (text_before_widget) {
5198 recttemp.xmin = recttemp.xmax - BLI_rcti_size_y(&recttemp);
5199 }
5200 else {
5201 recttemp.xmax = recttemp.xmin + BLI_rcti_size_y(&recttemp);
5202 }
5203
5204 /* smaller */
5205 const int delta = (BLI_rcti_size_y(&recttemp) - 2 * U.pixelsize) / 6;
5207 &recttemp, BLI_rcti_size_x(&recttemp) - delta * 2, BLI_rcti_size_y(&recttemp) - delta * 2);
5208 /* Keep one edge in place. */
5209 BLI_rcti_translate(&recttemp, text_before_widget ? delta : -delta, 0);
5210
5211 if (state->but_drawflag & BUT_INDETERMINATE) {
5212 /* The same muted background color regardless of state. */
5213 color_blend_v4_v4v4(wcol->inner, wcol->inner, wcol->inner_sel, 0.75f);
5214 }
5215
5216 const float rad = widget_radius_from_rcti(&recttemp, wcol);
5217 round_box_edges(&wtb, CNR_ALL, &recttemp, rad);
5218
5219 /* decoration */
5220 if (state->but_drawflag & BUT_INDETERMINATE) {
5222 }
5223 else if (state->but_flag & UI_SELECT) {
5225 }
5226
5227 widgetbase_draw(&wtb, wcol);
5228
5229 /* Text space - factor is really just eyeballed. */
5230 const float offset = delta * 0.9;
5231 if (text_before_widget) {
5232 rect->xmax = recttemp.xmin - offset;
5233 }
5234 else {
5235 rect->xmin = recttemp.xmax + offset;
5236 }
5237}
5238
5239/* labels use Editor theme colors for text */
5241{
5242 if (state->but_flag & BUT_LIST_ITEM) {
5243 /* Override default label theme's colors. */
5244 const bTheme *btheme = theme::theme_get();
5245 wt->wcol_theme = &btheme->tui.wcol_list_item;
5246 /* call this for option button */
5247 widget_state(wt, state, emboss);
5248 }
5249 else {
5250 /* call this for option button */
5251 widget_state(wt, state, emboss);
5252 if (state->but_flag & UI_SELECT) {
5254 }
5255 else {
5257 }
5258 }
5259
5260 if (state->but_flag & BUT_REDALERT) {
5261 uchar red[4];
5263
5264 /* Alert color's alpha is used to blend between the text and alert tint.
5265 * This ensures the text be always readable, lighter or darker depending on the theme. */
5266 float red_alpha = float(red[3]) / 255.0f;
5267 color_blend_v3_v3(wt->wcol.text, red, red_alpha);
5268 }
5269}
5270
5272 rcti *rect,
5273 const WidgetStateInfo * /*state*/,
5274 int roundboxalign,
5275 const float zoom)
5276{
5277 WidgetBase wtb;
5278 widget_init(&wtb);
5279
5280 const float rad = widget_radius_from_zoom(zoom, wcol);
5281 round_box_edges(&wtb, roundboxalign, rect, rad);
5282
5283 widgetbase_draw(&wtb, wcol);
5284}
5285
5286static void widget_box(Button *but,
5287 uiWidgetColors *wcol,
5288 rcti *rect,
5289 const WidgetStateInfo * /*state*/,
5290 int roundboxalign,
5291 const float zoom)
5292{
5293 WidgetBase wtb;
5294 widget_init(&wtb);
5295
5296 uchar old_col[3];
5297 copy_v3_v3_uchar(old_col, wcol->inner);
5298
5299 /* abuse but->hsv - if it's non-zero, use this color as the box's background */
5300 if (but != nullptr && but->col[3]) {
5301 wcol->inner[0] = but->col[0];
5302 wcol->inner[1] = but->col[1];
5303 wcol->inner[2] = but->col[2];
5304 wcol->inner[3] = but->col[3];
5305 }
5306
5307 const float rad = widget_radius_from_zoom(zoom, wcol);
5308 round_box_edges(&wtb, roundboxalign, rect, rad);
5309 wtb.draw_emboss = draw_emboss(but);
5310 widgetbase_draw(&wtb, wcol);
5311
5312 copy_v3_v3_uchar(wcol->inner, old_col);
5313
5314 /* Flush the cache so that we don't draw over contents. #125035 */
5318}
5319
5320static void widget_but(uiWidgetColors *wcol,
5321 rcti *rect,
5322 const WidgetStateInfo * /*state*/,
5323 int roundboxalign,
5324 const float zoom)
5325{
5326 WidgetBase wtb;
5327 widget_init(&wtb);
5328
5329 const float rad = widget_radius_from_zoom(zoom, wcol);
5330 round_box_edges(&wtb, roundboxalign, rect, rad);
5331
5332 widgetbase_draw(&wtb, wcol);
5333}
5334
5335#if 0
5336static void widget_roundbut(uiWidgetColors *wcol, rcti *rect, int /*state*/ int roundboxalign)
5337{
5338 uiWidgetBase wtb;
5339 const float rad = wcol->roundness * U.widget_unit;
5340
5341 widget_init(&wtb);
5342
5343 /* half rounded */
5344 round_box_edges(&wtb, roundboxalign, rect, rad);
5345
5346 widgetbase_draw(&wtb, wcol);
5347}
5348#endif
5349
5351 uiWidgetColors *wcol,
5352 rcti *rect,
5353 const WidgetStateInfo *state,
5354 int roundboxalign,
5355 const float zoom)
5356{
5357 WidgetBase wtb;
5358 widget_init(&wtb);
5359
5360 if (state->has_hold_action) {
5361 /* Show that keeping pressed performs another action (typically a menu). */
5362 shape_preset_init_hold_action(&wtb.tria1, rect, 0.75f, 'r');
5363 }
5364
5365 float rad = widget_radius_from_zoom(zoom, wcol);
5366
5367 wtb.draw_emboss = draw_emboss(but);
5368
5369 if (const ButtonPush *push_but = dynamic_cast<ButtonPush *>(but)) {
5370 if (push_but->draw_as_overlay) {
5371 /* Enforce a full circle. */
5372 rad = BLI_rcti_size_y(rect) * 0.5f;
5373 roundboxalign = CNR_ALL;
5374 wtb.draw_inner = true;
5375 wtb.draw_outline = false;
5376 wtb.draw_emboss = true;
5377 /* Use a black transparent background and a white icon color, to ensure good contrast. */
5378 const uchar background_col[4] = {0, 0, 0, (but->flag & UI_HOVER) ? uchar(120) : uchar(100)};
5379 copy_v4_v4_uchar(wcol->inner, background_col);
5380 copy_v4_v4_uchar(wcol->inner_sel, background_col);
5381 const uchar foreground_col[4] = {
5382 255, 255, 255, (but->flag & UI_HOVER) ? uchar(255) : uchar(230)};
5383 copy_v4_v4_uchar(wcol->text, foreground_col);
5384 copy_v4_v4_uchar(wcol->text_sel, foreground_col);
5385 }
5386 }
5387
5388 /* half rounded */
5389 round_box_edges(&wtb, roundboxalign, rect, rad);
5390 widgetbase_draw(&wtb, wcol);
5391}
5392
5393static void widget_tab(Button *but,
5394 uiWidgetColors *wcol,
5395 rcti *rect,
5396 const WidgetStateInfo *state,
5397 int roundboxalign,
5398 const float zoom)
5399{
5400 const float rad = widget_radius_from_zoom(zoom, wcol);
5401 const bool is_active = (state->but_flag & UI_SELECT);
5402
5403 /* Draw shaded outline - Disabled for now,
5404 * seems incorrect and also looks nicer without it IMHO ;). */
5405 // #define USE_TAB_SHADED_HIGHLIGHT
5406
5407 uchar theme_col_tab_highlight[3];
5408
5409#ifdef USE_TAB_SHADED_HIGHLIGHT
5410 /* create outline highlight colors */
5411 if (is_active) {
5412 interp_v3_v3v3_uchar(theme_col_tab_highlight, wcol->inner_sel, wcol->outline, 0.2f);
5413 }
5414 else {
5415 interp_v3_v3v3_uchar(theme_col_tab_highlight, wcol->inner, wcol->outline, 0.12f);
5416 }
5417#endif
5418
5419 WidgetBase wtb;
5420 widget_init(&wtb);
5421
5422 /* half rounded */
5423 round_box_edges(&wtb, roundboxalign, rect, rad);
5424
5425 /* draw inner */
5426#ifdef USE_TAB_SHADED_HIGHLIGHT
5427 wtb.draw_outline = 0;
5428#endif
5429 wtb.draw_emboss = draw_emboss(but);
5430 widgetbase_draw(&wtb, wcol);
5431
5432 /* We are drawing on top of widget bases. Flush cache. */
5436
5437#ifdef USE_TAB_SHADED_HIGHLIGHT
5438 /* draw outline (3d look) */
5439 draw_but_TAB_outline(rect, rad, theme_col_tab_highlight, wcol->inner);
5440#endif
5441
5442#ifndef USE_TAB_SHADED_HIGHLIGHT
5443 UNUSED_VARS(is_active, theme_col_tab_highlight);
5444#endif
5445}
5446
5447static void widget_draw_extra_mask(const bContext *C, Button *but, WidgetType *wt, rcti *rect)
5448{
5449 const bTheme *btheme = theme::theme_get();
5450 const uiWidgetColors *wcol = &btheme->tui.wcol_radio;
5451 const float rad = wcol->roundness * U.widget_unit;
5452
5453 /* state copy! */
5454 wt->wcol = *(wt->wcol_theme);
5455
5456 WidgetBase wtb;
5457 widget_init(&wtb);
5458
5459 if (but->block->drawextra) {
5460 /* NOTE: drawextra can change rect +1 or -1, to match round errors of existing previews. */
5461 but->block->drawextra(C, rect);
5462
5463 const uint pos = GPU_vertformat_attr_add(
5464 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
5466
5467 /* make mask to draw over image */
5468 uchar col[4];
5471
5472 round_box__edges(&wtb, CNR_ALL, rect, 0.0f, rad);
5473 widgetbase_outline(&wtb, pos);
5474
5476 }
5477
5478 /* outline */
5479 round_box_edges(&wtb, CNR_ALL, rect, rad);
5480 wtb.draw_outline = true;
5481 wtb.draw_inner = false;
5482 widgetbase_draw(&wtb, &wt->wcol);
5483}
5484
5486{
5487 const bTheme *btheme = theme::theme_get();
5488
5489 /* defaults */
5490 static WidgetType wt;
5491 wt.wcol_theme = &btheme->tui.wcol_regular;
5492 wt.wcol_state = &btheme->tui.wcol_state;
5493 wt.state = widget_state;
5494 wt.draw = widget_but;
5495 wt.custom = nullptr;
5497
5498 switch (type) {
5500 break;
5501
5502 case WidgetStyle::Label:
5503 wt.draw = nullptr;
5505 break;
5506
5508 wt.wcol_theme = &btheme->tui.wcol_toggle;
5509 break;
5510
5512 wt.wcol_theme = &btheme->tui.wcol_option;
5514 break;
5515
5516 case WidgetStyle::Radio:
5517 wt.wcol_theme = &btheme->tui.wcol_radio;
5518 wt.draw = widget_radiobut;
5519 break;
5520
5522 wt.wcol_theme = &btheme->tui.wcol_num;
5523 wt.custom = widget_numbut;
5524 break;
5525
5527 wt.wcol_theme = &btheme->tui.wcol_numslider;
5530 break;
5531
5532 case WidgetStyle::Exec:
5533 wt.wcol_theme = &btheme->tui.wcol_tool;
5535 break;
5536
5538 wt.wcol_theme = &btheme->tui.wcol_toolbar_item;
5540 break;
5541
5542 case WidgetStyle::Tab:
5543 wt.wcol_theme = &btheme->tui.wcol_tab;
5544 wt.custom = widget_tab;
5545 break;
5546
5548 wt.wcol_theme = &btheme->tui.wcol_tooltip;
5550 break;
5551
5552 /* strings */
5553 case WidgetStyle::Name:
5554 wt.wcol_theme = &btheme->tui.wcol_text;
5555 wt.draw = widget_textbut;
5556 break;
5557
5559 break;
5560
5562 break;
5563
5565 break;
5566
5567 /* start menus */
5569 wt.wcol_theme = &btheme->tui.wcol_menu;
5570 wt.draw = widget_menubut;
5571 break;
5572
5575 wt.wcol_theme = &btheme->tui.wcol_menu;
5577 break;
5578
5580 wt.wcol_theme = &btheme->tui.wcol_menu;
5581 wt.draw = widget_menubut;
5582 break;
5583
5585 wt.wcol_theme = &btheme->tui.wcol_pulldown;
5588 break;
5589
5590 /* in menus */
5592 wt.wcol_theme = &btheme->tui.wcol_menu_item;
5595 break;
5596
5598 wt.wcol_theme = &btheme->tui.wcol_menu_item;
5601 break;
5602
5604 wt.wcol_theme = &btheme->tui.wcol_menu_back;
5606 break;
5607
5608 /* specials */
5609 case WidgetStyle::Icon:
5611 break;
5612
5614 /* behave like regular labels (this is simply a label with an icon) */
5617 break;
5618
5620 wt.draw = nullptr;
5621 /* Drawn via the `custom` callback. */
5622 wt.text = nullptr;
5623 /* Drawing indicates state well enough. No need to change colors further. */
5626 wt.wcol_theme = &btheme->tui.wcol_list_item;
5627 break;
5628
5630 wt.custom = widget_swatch;
5631 break;
5632
5633 case WidgetStyle::Box:
5634 wt.custom = widget_box;
5635 wt.wcol_theme = &btheme->tui.wcol_box;
5636 break;
5637
5639 break;
5640
5643 break;
5644
5646 wt.wcol_theme = &btheme->tui.wcol_scroll;
5648 wt.custom = widget_scroll;
5649 break;
5650
5653 wt.wcol_theme = &btheme->tui.wcol_list_item;
5655 break;
5656
5658 wt.wcol_theme = &btheme->tui.wcol_progress;
5660 break;
5661
5664 break;
5665
5667 wt.wcol_theme = &btheme->tui.wcol_pie_menu;
5670 break;
5671 }
5672
5673 return &wt;
5674}
5675
5676static int widget_roundbox_set(Button *but, rcti *rect)
5677{
5678 int roundbox = CNR_ALL;
5679
5680 /* alignment */
5681 if ((but->drawflag & BUT_ALIGN) && but->type != ButtonType::Pulldown) {
5682
5683 /* popup_block_position and #widget_roundbox_set has this correction too, keep in sync */
5685 rect->ymax += U.pixelsize;
5686 }
5688 rect->xmin -= U.pixelsize;
5689 }
5690
5691 switch (but->drawflag & BUT_ALIGN) {
5692 case BUT_ALIGN_TOP:
5693 roundbox = CNR_BOTTOM_LEFT | CNR_BOTTOM_RIGHT;
5694 break;
5695 case BUT_ALIGN_DOWN:
5696 roundbox = CNR_TOP_LEFT | CNR_TOP_RIGHT;
5697 break;
5698 case BUT_ALIGN_LEFT:
5699 roundbox = CNR_TOP_RIGHT | CNR_BOTTOM_RIGHT;
5700 break;
5701 case BUT_ALIGN_RIGHT:
5702 roundbox = CNR_TOP_LEFT | CNR_BOTTOM_LEFT;
5703 break;
5705 roundbox = CNR_TOP_LEFT;
5706 break;
5708 roundbox = CNR_TOP_RIGHT;
5709 break;
5711 roundbox = CNR_BOTTOM_LEFT;
5712 break;
5714 roundbox = CNR_BOTTOM_RIGHT;
5715 break;
5716 default:
5717 roundbox = 0;
5718 break;
5719 }
5720 }
5721
5722 /* align with open menu */
5723 if (but->active && (but->type != ButtonType::Popover) && !button_menu_draw_as_popover(but)) {
5724 const int direction = button_menu_direction(but);
5725
5726 /* Pull-down menus that open above or below a button can have more than one direction. */
5727 if (direction & UI_DIR_UP) {
5728 roundbox &= ~(CNR_TOP_RIGHT | CNR_TOP_LEFT);
5729 }
5730 else if (direction & UI_DIR_DOWN) {
5731 roundbox &= ~(CNR_BOTTOM_RIGHT | CNR_BOTTOM_LEFT);
5732 }
5733 else if (direction == UI_DIR_LEFT) {
5734 roundbox &= ~(CNR_TOP_LEFT | CNR_BOTTOM_LEFT);
5735 }
5736 else if (direction == UI_DIR_RIGHT) {
5737 roundbox &= ~(CNR_TOP_RIGHT | CNR_BOTTOM_RIGHT);
5738 }
5739 }
5740
5741 return roundbox;
5742}
5743
5745{
5746 /* We could use a flag for this, but for now just check size,
5747 * add up/down arrows if there is room. */
5748 if ((but->str.empty() && but->icon && (BLI_rcti_size_x(rect) < BLI_rcti_size_y(rect) + 2)) ||
5749 /* disable for brushes also */
5750 (but->flag & BUT_ICON_PREVIEW))
5751 {
5752 /* No arrows. */
5754 }
5755
5756 /* With menu arrows. */
5758}
5759
5761
5762/* -------------------------------------------------------------------- */
5765
5766void draw_button(const bContext *C, ARegion *region, uiStyle *style, Button *but, rcti *rect)
5767{
5768 const bTheme *btheme = theme::theme_get();
5769 const ThemeUI *tui = &btheme->tui;
5770 const uiFontStyle *fstyle = &style->widget;
5771 WidgetType *wt = nullptr;
5772
5773 /* handle menus separately */
5774 if (but->emboss == EmbossType::Pulldown) {
5775 switch (but->type) {
5776 case ButtonType::Color:
5778 break;
5779 case ButtonType::Label:
5780 widget_draw_text_icon(&style->widget, &tui->wcol_menu_back, but, rect);
5781 break;
5782 case ButtonType::Sepr:
5783 break;
5785 /* Add horizontal padding between the line and menu sides. */
5786 BLI_rcti_pad(rect, int(-7.0f * UI_SCALE_FAC), 0);
5787 draw_separator(&tui->wcol_menu_item, but, rect);
5788 break;
5789 default: {
5790 const bool use_unpadded = (but->flag & BUT_ICON_PREVIEW) ||
5791 ((but->flag & UI_HAS_ICON) && !but->drawstr[0]);
5793 break;
5794 }
5795 }
5796 }
5798 /* Use the same widget types for both no emboss types. Later on,
5799 * #EmbossType::NoneOrStatus will blend state colors if they apply. */
5800 switch (but->type) {
5801 case ButtonType::Label:
5802 case ButtonType::Text:
5804 if (!(but->flag & UI_HAS_ICON)) {
5806 }
5807 break;
5810 break;
5812 if (but->icon == 0) {
5813 wt = popover_widget_type(but, rect);
5814 }
5815 else { /* Currently used for presets. */
5817 }
5818 break;
5821 break;
5822 default:
5824 break;
5825 }
5826 }
5827 else if (but->emboss == EmbossType::PieMenu) {
5829 }
5830 else {
5832
5833 switch (but->type) {
5834 case ButtonType::Label:
5836 if (but->drawflag & BUT_BOX_ITEM) {
5837 wt->wcol_theme = &tui->wcol_box;
5838 wt->state = widget_state;
5839 }
5840 else if (but->block->theme_style == BLOCK_THEME_STYLE_POPUP) {
5841 wt->wcol_theme = &tui->wcol_menu_back;
5842 wt->state = widget_state;
5843 }
5844 if (!(but->flag & UI_HAS_ICON)) {
5846 }
5847 break;
5848
5849 case ButtonType::Sepr:
5851 break;
5853 draw_separator(&tui->wcol_menu_item, but, rect);
5854 break;
5855
5856 case ButtonType::But:
5858#ifdef USE_UI_TOOLBAR_HACK
5859 if ((but->icon != ICON_NONE) && but_is_tool(but)) {
5861 }
5862 else {
5864 }
5865#else
5867#endif
5868 if (button_draw_as_link(but)) {
5869 wt->draw = nullptr;
5870 wt->custom = nullptr;
5871 if (!(but->flag & UI_HAS_ICON)) {
5873 }
5874 }
5875 break;
5876
5877 case ButtonType::Num:
5879 break;
5880
5883 break;
5884
5885 case ButtonType::Row:
5887 break;
5888
5891 break;
5892
5894 case ButtonType::Text:
5896 break;
5897
5900 break;
5901
5902 case ButtonType::Tab:
5904 break;
5905
5907 case ButtonType::Toggle:
5910 break;
5911
5914 if (!(but->flag & UI_HAS_ICON)) {
5916
5917 if ((but->drawflag & (BUT_TEXT_LEFT | BUT_TEXT_RIGHT)) == 0) {
5918 but->drawflag |= BUT_TEXT_LEFT;
5919 }
5920 /* #widget_optionbut() carefully sets the text rectangle for fine tuned paddings. If the
5921 * text drawing were to add its own padding, DPI and zoom factor would be applied twice
5922 * in the final padding, so it's difficult to control it. */
5924 }
5925 else {
5927 }
5928
5929 /* option buttons have strings outside, on menus use different colors */
5932 }
5933 break;
5934
5935 case ButtonType::Menu:
5936 case ButtonType::Block:
5938 if (but->flag & BUT_NODE_LINK) {
5939 /* new node-link button, not active yet XXX */
5941 }
5942 else {
5943 /* Popover button. */
5944 wt = popover_widget_type(but, rect);
5945 }
5946 break;
5947
5950 break;
5951
5954 break;
5955
5956 case ButtonType::Color:
5958 break;
5959
5963 break;
5964
5967 break;
5968
5969 case ButtonType::Extra:
5971 break;
5972
5973 case ButtonType::HsvCube: {
5974 const ButtonHSVCube *hsv_but = static_cast<ButtonHSVCube *>(but);
5975
5976 if (ELEM(hsv_but->gradient_type, GRAD_V_ALT, GRAD_L_ALT)) {
5977 /* vertical V slider, uses new widget draw now */
5978 draw_but_HSV_v(but, rect);
5979 }
5980 else { /* other HSV pickers... */
5981 draw_but_HSVCUBE(but, rect);
5982 }
5983 break;
5984 }
5985
5987 draw_but_HSVCIRCLE(but, &tui->wcol_regular, rect);
5988 break;
5989
5990 case ButtonType::ColorBand: {
5991 /* Horizontal padding to make room for handles at edges. */
5992 const int padding = BLI_rcti_size_y(rect) / 6;
5993 rect->xmin += padding;
5994 rect->xmax -= padding;
5995 draw_but_COLORBAND(but, &tui->wcol_regular, rect);
5996 break;
5997 }
5998
6001 break;
6002
6003 case ButtonType::Image:
6004 draw_but_IMAGE(region, but, &tui->wcol_regular, rect);
6005 break;
6006
6008 draw_but_HISTOGRAM(region, but, &tui->wcol_regular, rect);
6009 break;
6010
6012 draw_but_WAVEFORM(C, region, but, &tui->wcol_regular, rect);
6013 break;
6014
6016 draw_but_VECTORSCOPE(C, region, but, &tui->wcol_regular, rect);
6017 break;
6018
6019 case ButtonType::Curve:
6020 draw_but_CURVE(region, but, &tui->wcol_curve, rect);
6021 break;
6022
6024 draw_but_CURVEPROFILE(region, but, &tui->wcol_curve, rect);
6025 break;
6026
6029 break;
6030
6033 break;
6034
6035 case ButtonType::Scroll:
6037 break;
6038
6039 case ButtonType::Grip:
6041 break;
6042
6044 draw_but_TRACKPREVIEW(region, but, &tui->wcol_regular, rect);
6045 break;
6046
6049 break;
6050
6051 default:
6053 break;
6054 }
6055 }
6056
6057 if (wt == nullptr) {
6058 return;
6059 }
6060
6061 // rcti disablerect = *rect; /* rect gets clipped smaller for text */
6062
6063 const int roundboxalign = widget_roundbox_set(but, rect);
6064
6065 WidgetStateInfo state = {0};
6066 state.but_flag = but->flag;
6067 state.but_drawflag = but->drawflag;
6068 state.emboss = but->emboss;
6069 state.draw_as_link = button_draw_as_link(but);
6070
6071 /* Override selected flag for drawing. */
6072 if (but->flag & UI_SELECT_DRAW) {
6073 state.but_flag |= UI_SELECT;
6074 }
6075
6076 if ((but->editstr) || (UNLIKELY(but->flag & BUT_DRAG_MULTI) && button_drag_multi_edit_get(but)))
6077 {
6078 state.is_text_input = true;
6079 }
6080
6081 if (but->hold_func) {
6082 state.has_hold_action = true;
6083 }
6084
6085 bool use_alpha_blend = false;
6086 if (but->emboss != EmbossType::Pulldown) {
6088 use_alpha_blend = true;
6090 }
6091 }
6092
6093#ifdef USE_UI_POPOVER_ONCE
6094 if (but->block->flag & BLOCK_POPOVER_ONCE) {
6095 if ((but->flag & UI_HOVER) && button_is_popover_once_compat(but)) {
6096 state.but_flag |= BUT_ACTIVE_DEFAULT;
6097 }
6098 }
6099#endif
6101 state.but_flag &= ~BUT_OVERRIDDEN;
6102 }
6103
6104 if (state.but_drawflag & BUT_INDETERMINATE) {
6105 state.but_flag &= ~UI_SELECT;
6106 }
6107
6108 const float zoom = 1.0f / but->block->aspect;
6109 wt->state(wt, &state, but->emboss);
6110 if (wt->custom) {
6111 wt->custom(but, &wt->wcol, rect, &state, roundboxalign, zoom);
6112 }
6113 else if (wt->draw) {
6114 wt->draw(&wt->wcol, rect, &state, roundboxalign, zoom);
6115 }
6116
6117 if (wt->text) {
6118 if (use_alpha_blend) {
6120 }
6121
6122 if (but->type == ButtonType::Label && !(but->flag & UI_HAS_ICON) && but->col[3] != 0) {
6123 /* Optionally use button color for text color if label without icon.
6124 * For example, ensuring that the Splash version text is always white. */
6125 copy_v4_v4_uchar(wt->wcol.text, but->col);
6126 }
6127
6128 wt->text(fstyle, &wt->wcol, but, rect);
6129 if (use_alpha_blend) {
6131 }
6132 }
6133}
6134
6135static void draw_clip_tri(Block *block, const rcti *rect, WidgetType *wt)
6136{
6137 if (block) {
6138 float draw_color[4];
6139 const uchar *color = wt->wcol.text;
6140
6141 draw_color[0] = float(color[0]) / 255.0f;
6142 draw_color[1] = float(color[1]) / 255.0f;
6143 draw_color[2] = float(color[2]) / 255.0f;
6144 draw_color[3] = 1.0f;
6145
6146 if (block->flag & BLOCK_CLIPTOP) {
6148 rect->ymax - (6 * UI_SCALE_FAC) / block->aspect,
6149 't',
6150 draw_color,
6151 block->aspect);
6152 }
6153 if (block->flag & BLOCK_CLIPBOTTOM) {
6155 rect->ymin + (10 * UI_SCALE_FAC) / block->aspect,
6156 'v',
6157 draw_color,
6158 block->aspect);
6159 }
6160 }
6161}
6162
6163static void draw_dialog_alert(Block *block, const rcti *rect)
6164{
6165 if (block->alert_level != BlockAlertLevel::Error) {
6166 return;
6167 }
6168
6169 float color[4];
6170 switch (block->alert_level) {
6173 break;
6176 break;
6179 break;
6180 default:
6182 }
6183
6184 const bTheme *btheme = theme::theme_get();
6185 const float bg_radius = btheme->tui.wcol_menu_back.roundness * U.widget_unit;
6186 const float line_width = 3.0f * UI_SCALE_FAC;
6187 const float radius = (bg_radius > (line_width * 2.0f)) ? 0.0f : bg_radius;
6188 const float padding = (bg_radius > (line_width * 2.0f)) ? bg_radius : 0.0f;
6189 rctf line_rect;
6190 BLI_rctf_rcti_copy(&line_rect, rect);
6191 line_rect.ymin = line_rect.ymax - line_width;
6192 BLI_rctf_pad(&line_rect, -padding, 0.0f);
6194 draw_roundbox_4fv(&line_rect, true, radius, color);
6195}
6196
6197void draw_menu_back(uiStyle * /*style*/, Block *block, const rcti *rect)
6198{
6200
6202 if (block) {
6203 const float zoom = 1.0f / block->aspect;
6204 wt->draw_block(&wt->wcol,
6205 rect,
6206 block->flag,
6207 block->alert_level == BlockAlertLevel::None ? block->direction :
6208 char(UI_DIR_DOWN),
6209 zoom);
6210 if (block->alert_level != BlockAlertLevel::None) {
6211 draw_dialog_alert(block, rect);
6212 }
6213 }
6214 else {
6215 wt->draw_block(&wt->wcol, rect, 0, 0, 1.0f);
6216 }
6217
6218 draw_clip_tri(block, rect, wt);
6219}
6220
6226 const rcti *rect,
6227 int direction,
6228 const float unit_size,
6229 const float mval_origin[2])
6230{
6231 /* Alas, this isn't nice. */
6232 const float unit_half = unit_size / 2;
6233 const float cent_x = mval_origin ? std::clamp(mval_origin[0],
6234 rect->xmin + unit_size,
6235 rect->xmax - unit_size) :
6236 BLI_rcti_cent_x(rect);
6237
6239
6240 /* Extracted from 'widget_menu_back', keep separate to avoid menu changes breaking popovers */
6241 {
6242 WidgetBase wtb;
6243 widget_init(&wtb);
6244
6245 const int roundboxalign = CNR_ALL;
6246 widget_softshadow(rect, roundboxalign, wcol->roundness * U.widget_unit);
6247
6248 round_box_edges(&wtb, roundboxalign, rect, wcol->roundness * U.widget_unit);
6249 wtb.draw_emboss = false;
6250 widgetbase_draw(&wtb, wcol);
6251 }
6252
6253 /* Draw popover arrow (top/bottom) */
6254 if (ELEM(direction, UI_DIR_UP, UI_DIR_DOWN)) {
6255 const uint pos = GPU_vertformat_attr_add(
6256 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
6258
6259 const bool is_down = (direction == UI_DIR_DOWN);
6260 const int sign = is_down ? 1 : -1;
6261 float y = is_down ? rect->ymax : rect->ymin;
6262
6266 immVertex2f(pos, cent_x - unit_half, y);
6267 immVertex2f(pos, cent_x + unit_half, y);
6268 immVertex2f(pos, cent_x, y + sign * unit_half);
6269 immEnd();
6270
6271 y = y - sign * round(U.pixelsize * 1.41);
6272
6275 immUniformColor4ub(0, 0, 0, 0);
6276 immVertex2f(pos, cent_x - unit_half, y);
6277 immVertex2f(pos, cent_x + unit_half, y);
6278 immVertex2f(pos, cent_x, y + sign * unit_half);
6279 immEnd();
6280
6284 immVertex2f(pos, cent_x - unit_half, y);
6285 immVertex2f(pos, cent_x + unit_half, y);
6286 immVertex2f(pos, cent_x, y + sign * unit_half);
6287 immEnd();
6288
6290 }
6291
6293}
6294
6295void draw_popover_back(ARegion *region, uiStyle * /*style*/, Block *block, const rcti *rect)
6296{
6298
6299 float mval_origin[2] = {float(block->bounds_offset[0]), float(block->bounds_offset[1])};
6300 window_to_block_fl(region, block, &mval_origin[0], &mval_origin[1]);
6302 wt->wcol_theme, rect, block->direction, U.widget_unit / block->aspect, mval_origin);
6303
6304 draw_clip_tri(block, rect, wt);
6305}
6306
6307static void draw_disk_shaded(float start,
6308 float angle,
6309 float radius_int,
6310 float radius_ext,
6311 int subd,
6312 const uchar col1[4],
6313 const uchar col2[4],
6314 bool shaded)
6315{
6316 const float radius_ext_scale = (0.5f / radius_ext); /* 1 / (2 * radius_ext) */
6317
6318 uint col;
6319 GPUVertFormat *format = immVertexFormat();
6320 const uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
6321 if (shaded) {
6322 col = GPU_vertformat_attr_add(format, "color", gpu::VertAttrType::SFLOAT_32_32_32_32);
6324 }
6325 else {
6327 immUniformColor4ubv(col1);
6328 }
6329
6330 immBegin(GPU_PRIM_TRI_STRIP, subd * 2);
6331 for (int i = 0; i < subd; i++) {
6332 const float a = start + ((i) / float(subd - 1)) * angle;
6333 const float s = sinf(a);
6334 const float c = cosf(a);
6335 const float y1 = s * radius_int;
6336 const float y2 = s * radius_ext;
6337
6338 if (shaded) {
6339 uchar r_col[4];
6340 const float fac = (y1 + radius_ext) * radius_ext_scale;
6341 color_blend_v4_v4v4(r_col, col1, col2, fac);
6342 float f_col[4];
6343 rgba_uchar_to_float(f_col, r_col);
6344 immAttr4fv(col, f_col);
6345 }
6346 immVertex2f(pos, c * radius_int, s * radius_int);
6347
6348 if (shaded) {
6349 uchar r_col[4];
6350 const float fac = (y2 + radius_ext) * radius_ext_scale;
6351 color_blend_v4_v4v4(r_col, col1, col2, fac);
6352 float f_col[4];
6353 rgba_uchar_to_float(f_col, r_col);
6354 immAttr4fv(col, f_col);
6355 }
6356 immVertex2f(pos, c * radius_ext, s * radius_ext);
6357 }
6358 immEnd();
6359
6361}
6362
6364{
6365 const bTheme *btheme = theme::theme_get();
6366 const float cx = block->pie_data->pie_center_spawned[0];
6367 const float cy = block->pie_data->pie_center_spawned[1];
6368
6369 const float *pie_dir = block->pie_data->pie_dir;
6370
6371 const float pie_radius_internal = UI_SCALE_FAC * U.pie_menu_threshold;
6372 const float pie_radius_external = UI_SCALE_FAC * (U.pie_menu_threshold + 7.0f);
6373
6374 const int subd = 40;
6375
6376 const float angle = atan2f(pie_dir[1], pie_dir[0]);
6377 /* Use a smaller range if there are both axis aligned & diagonal buttons. */
6378 const bool has_aligned = (block->pie_data->pie_dir_mask & UI_RADIAL_MASK_ALL_AXIS_ALIGNED) != 0;
6379 const bool has_diagonal = (block->pie_data->pie_dir_mask & UI_RADIAL_MASK_ALL_DIAGONAL) != 0;
6380 const float range = (has_aligned && has_diagonal) ? M_PI_4 : M_PI_2;
6381
6384
6386 if (btheme->tui.wcol_pie_menu.shaded) {
6387 uchar col1[4], col2[4];
6389 btheme->tui.wcol_pie_menu.shadetop,
6390 btheme->tui.wcol_pie_menu.shadedown,
6391 col1,
6392 col2);
6394 0.0f, float(M_PI * 2.0), pie_radius_internal, pie_radius_external, subd, col1, col2, true);
6395 }
6396 else {
6397 draw_disk_shaded(0.0f,
6398 float(M_PI * 2.0),
6399 pie_radius_internal,
6400 pie_radius_external,
6401 subd,
6402 btheme->tui.wcol_pie_menu.inner,
6403 nullptr,
6404 false);
6405 }
6406
6407 if (!(block->pie_data->flags & PIE_INVALID_DIR)) {
6408 if (btheme->tui.wcol_pie_menu.shaded) {
6409 uchar col1[4], col2[4];
6411 btheme->tui.wcol_pie_menu.shadetop,
6412 btheme->tui.wcol_pie_menu.shadedown,
6413 col1,
6414 col2);
6415 draw_disk_shaded(angle - range / 2.0f,
6416 range,
6417 pie_radius_internal,
6418 pie_radius_external,
6419 subd,
6420 col1,
6421 col2,
6422 true);
6423 }
6424 else {
6425 draw_disk_shaded(angle - range / 2.0f,
6426 range,
6427 pie_radius_internal,
6428 pie_radius_external,
6429 subd,
6430 btheme->tui.wcol_pie_menu.inner_sel,
6431 nullptr,
6432 false);
6433 }
6434 }
6435
6436 GPUVertFormat *format = immVertexFormat();
6437 const uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
6440
6441 imm_draw_circle_wire_2d(pos, 0.0f, 0.0f, pie_radius_internal, subd);
6442 imm_draw_circle_wire_2d(pos, 0.0f, 0.0f, pie_radius_external, subd);
6443
6445
6446 if (U.pie_menu_confirm > 0 && !(block->pie_data->flags & (PIE_INVALID_DIR | PIE_CLICK_STYLE))) {
6447 const float pie_confirm_radius = UI_SCALE_FAC * (pie_radius_internal + U.pie_menu_confirm);
6448 const float pie_confirm_external = UI_SCALE_FAC *
6449 (pie_radius_internal + U.pie_menu_confirm + 7.0f);
6450
6451 const uchar col[4] = {UNPACK3(btheme->tui.wcol_pie_menu.text_sel), 64};
6452 draw_disk_shaded(angle - range / 2.0f,
6453 range,
6454 pie_confirm_radius,
6455 pie_confirm_external,
6456 subd,
6457 col,
6458 nullptr,
6459 false);
6460 }
6461
6464}
6465
6471
6476 bool use_shadow,
6477 const rcti *rect,
6478 const float color[4])
6479{
6480 WidgetType *wt = widget_type(type);
6481
6482 if (use_shadow) {
6483 widget_softshadow(rect, CNR_ALL, 0.25f * U.widget_unit);
6484 }
6485
6487 if (color) {
6489 }
6490
6491 if (wt->draw_block) {
6492 wt->draw_block(&wt->wcol, rect, 0, CNR_ALL, 1.0f);
6493 }
6494 else if (wt->draw) {
6495 rcti rect_copy = *rect;
6496 wt->draw(&wt->wcol, &rect_copy, &STATE_INFO_NULL, CNR_ALL, 1.0f);
6497 }
6498 else {
6500 }
6501}
6502void draw_widget_menu_back_color(const rcti *rect, bool use_shadow, const float color[4])
6503{
6505}
6506
6507void draw_widget_menu_back(const rcti *rect, bool use_shadow)
6508{
6509 draw_widget_back_color(WidgetStyle::MenuBack, use_shadow, rect, nullptr);
6510}
6511
6512void draw_tooltip_background(const uiStyle * /*style*/, Block * /*block*/, const rcti *rect)
6513{
6516 /* wt->draw_block ends up using same function to draw the tooltip as menu_back */
6517 wt->draw_block(&wt->wcol, rect, 0, 0, 1.0f);
6518}
6519
6520void draw_menu_item(const uiFontStyle *fstyle,
6521 rcti *rect,
6522 rcti *back_rect,
6523 const float zoom,
6524 const bool use_unpadded,
6525 const char *name,
6526 int iconid,
6527 int64_t but_flag,
6528 MenuItemSeparatorType separator_type,
6529 int *r_xmax)
6530{
6533 const rcti _rect = *rect;
6534 const int row_height = BLI_rcti_size_y(rect);
6535 int max_hint_width = INT_MAX;
6536 int padding = 0.25f * row_height;
6537 char *cpoin = nullptr;
6538
6539 WidgetStateInfo state = {0};
6540 state.but_flag = but_flag;
6541
6543
6544 if (back_rect) {
6545 wt->draw(&wt->wcol, back_rect, &STATE_INFO_NULL, 0, zoom);
6546 }
6547
6548 fontstyle_set(fstyle);
6549
6550 /* text location offset */
6551 rect->xmin += padding;
6552 if (iconid) {
6553 rect->xmin += row_height; /* Use square area for icon. */
6554 }
6555
6556 /* cut string in 2 parts? */
6557 if (separator_type != UI_MENU_ITEM_SEPARATOR_NONE) {
6558 cpoin = const_cast<char *>(strrchr(name, UI_SEP_CHAR));
6559 if (cpoin) {
6560 *cpoin = 0;
6561
6562 /* need to set this first */
6563 fontstyle_set(fstyle);
6564
6565 if (separator_type == UI_MENU_ITEM_SEPARATOR_SHORTCUT) {
6566 /* Shrink rect to exclude the shortcut string. */
6567 rect->xmax -= BLF_width(fstyle->uifont_id, cpoin + 1, INT_MAX) + UI_ICON_SIZE;
6568 }
6569 else if (separator_type == UI_MENU_ITEM_SEPARATOR_HINT) {
6570 /* Determine max-width for the hint string to leave the name string un-clipped (if there's
6571 * enough space to display it). */
6572
6573 const int available_width = BLI_rcti_size_x(rect) - padding;
6574 const int name_width = BLF_width(fstyle->uifont_id, name, INT_MAX);
6575 const int hint_width = BLF_width(fstyle->uifont_id, cpoin + 1, INT_MAX) + padding;
6576
6577 if ((name_width + hint_width) > available_width) {
6578 /* Clipping width for hint string. */
6579 max_hint_width = available_width * 0.40f;
6580 /* Clipping xmax for clipping of item name. */
6581 rect->xmax = (hint_width < max_hint_width) ?
6582 (rect->xmax - hint_width) :
6583 (rect->xmin + (available_width - max_hint_width));
6584 }
6585 }
6586 else {
6587 BLI_assert_msg(0, "Unknown menu item separator type");
6588 }
6589 }
6590 }
6591
6592 {
6593 char drawstr[UI_MAX_DRAW_STR];
6594 const float okwidth = float(BLI_rcti_size_x(rect));
6595 const size_t drawstr_maxncpy = sizeof(drawstr);
6596 const float minwidth = UI_ICON_SIZE;
6597
6598 STRNCPY_UTF8(drawstr, name);
6599 if (drawstr[0]) {
6600 text_clip_middle_ex(fstyle, drawstr, okwidth, minwidth, drawstr_maxncpy, '\0');
6601 }
6602
6603 int xofs = 0, yofs = 0;
6604 ResultBLF info;
6605 FontStyleDrawParams params{};
6606 params.align = UI_STYLE_TEXT_LEFT;
6608 fstyle, rect, drawstr, sizeof(drawstr), wt->wcol.text, &params, &xofs, &yofs, &info);
6609 if (r_xmax != nullptr) {
6610 *r_xmax = xofs + info.width;
6611 }
6612 }
6613
6614 /* restore rect, was messed with */
6615 *rect = _rect;
6616
6617 if (iconid) {
6618 const int xs = rect->xmin + 0.2f * UI_UNIT_X * zoom;
6619 const int ys = rect->ymin + 0.5f * (BLI_rcti_size_y(rect) - UI_ICON_SIZE * zoom);
6620
6621 const float aspect = U.inv_scale_factor / zoom;
6622
6625 xs, ys, iconid, aspect, 1.0f, 0.0f, wt->wcol.text, false, UI_NO_ICON_OVERLAY_TEXT);
6627 }
6628
6629 /* part text right aligned */
6630 if (separator_type != UI_MENU_ITEM_SEPARATOR_NONE) {
6631 if (cpoin) {
6632 /* State info for the hint drawing. */
6633 WidgetStateInfo hint_state = state;
6634 /* Set inactive state for grayed out text. */
6635 hint_state.but_flag |= BUT_INACTIVE;
6636
6637 wt->state(wt, &hint_state, EmbossType::Undefined);
6638
6639 char hint_drawstr[UI_MAX_DRAW_STR];
6640 {
6641 const size_t hint_drawstr_maxncpy = sizeof(hint_drawstr);
6642 const float minwidth = UI_ICON_SIZE;
6643
6644 STRNCPY_UTF8(hint_drawstr, cpoin + 1);
6645 if (hint_drawstr[0] && (max_hint_width < INT_MAX)) {
6647 fstyle, hint_drawstr, max_hint_width, minwidth, hint_drawstr_maxncpy, '\0');
6648 }
6649 }
6650
6651 rect->xmax = _rect.xmax - padding;
6652 FontStyleDrawParams params{};
6653 params.align = UI_STYLE_TEXT_RIGHT;
6654 fontstyle_draw(fstyle, rect, hint_drawstr, sizeof(hint_drawstr), wt->wcol.text, &params);
6655 *cpoin = UI_SEP_CHAR;
6656 }
6657 }
6658}
6659
6661 rcti *rect,
6662 const StringRef name,
6663 int iconid,
6664 const uchar text_col[4],
6665 FontStyleAlign text_align,
6666 const bool add_padding)
6667{
6668 rcti trect = *rect;
6669 const float text_size = UI_UNIT_Y;
6670 const bool has_text = !name.is_empty();
6671
6672 float alpha = 1.0f;
6673
6674 if (has_text) {
6675 /* draw icon in rect above the space reserved for the label */
6676 rect->ymin += text_size;
6677 }
6679 widget_draw_preview_icon(iconid, alpha, 1.0f, add_padding, rect, text_col);
6681
6682 if (!has_text) {
6683 return;
6684 }
6685
6686 /* text rect */
6687 trect.ymax = trect.ymin + text_size;
6688 if (add_padding) {
6689 trect.ymin += PREVIEW_PAD;
6690 trect.xmin += PREVIEW_PAD;
6691 trect.xmax -= PREVIEW_PAD;
6692 }
6693
6694 {
6695 char drawstr[UI_MAX_DRAW_STR];
6696 const float okwidth = float(BLI_rcti_size_x(&trect));
6697 const size_t drawstr_maxncpy = sizeof(drawstr);
6698 const float minwidth = UI_ICON_SIZE;
6699
6700 memcpy(drawstr, name.data(), name.size());
6701 drawstr[name.size()] = '\0';
6702 text_clip_middle_ex(fstyle, drawstr, okwidth, minwidth, drawstr_maxncpy, '\0');
6703
6704 FontStyleDrawParams params{};
6705 params.align = text_align;
6706 fontstyle_draw(fstyle, &trect, drawstr, sizeof(drawstr), text_col, &params);
6707 }
6708}
6709
6711 rcti *rect,
6712 const float zoom,
6713 const char *name,
6714 int iconid,
6715 int64_t but_flag,
6716 FontStyleAlign text_align)
6717{
6719
6720 WidgetStateInfo state = {0};
6721 state.but_flag = but_flag;
6722
6723 /* drawing button background */
6725 wt->draw(&wt->wcol, rect, &STATE_INFO_NULL, 0, zoom);
6726
6727 draw_preview_item_stateless(fstyle, rect, name, iconid, wt->wcol.text, text_align, true);
6728}
6729
6731
6732} // namespace blender::ui
Functions and classes for evaluating template expressions in filepaths.
#define BKE_TEMPLATE_EXPRESSION_ABBREVIATION
#define rgba_float_args_set_ch(col, r, g, b, a)
#define M_PI_2
#define M_PI
#define M_PI_4
#define STRNCPY_UTF8(dst, src)
#define BLI_STR_UTF8_HORIZONTAL_ELLIPSIS
#define UI_SCALE_FAC
#define UI_INV_SCALE_FAC
#define UI_ICON_SIZE
#define GPU_batch_uniform_4fv_array(batch, name, len, val)
Definition GPU_batch.hh:278
#define GPU_batch_uniform_3fv(batch, name, val)
Definition GPU_batch.hh:274
#define C
Definition RandGen.cpp:29
#define UI_ALPHA_CHECKER_LIGHT
#define UI_UNIT_Y
#define UI_SEP_CHAR
#define UI_ALPHA_CHECKER_DARK
#define UI_VALUE_INDETERMINATE_CHAR
#define UI_FSTYLE_WIDGET
#define UI_UNIT_X
#define ICON_DEFAULT_HEIGHT
#define ICON_DEFAULT_HEIGHT_TOOLBAR
#define UI_NO_ICON_OVERLAY_TEXT
#define ICON_DEFAULT_WIDTH
#define UI_MAX_DRAW_STR
int pad[32 - sizeof(int)]
#define CLAMP(a, b, c)
#define BLI_assert_unreachable()
#define UNUSED_VARS(...)
#define UNUSED_VARS_NDEBUG(...)
#define UNPACK3(a)
#define UNLIKELY(x)
#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
btVector3 m_delta
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
ChannelStorageType a
constexpr StringRef()
constexpr const char * begin() const
constexpr bool is_empty() const
constexpr int64_t size() const
constexpr StringRef trim_right() const
constexpr StringRef trim_left() const
constexpr const char * data() const
void append(const T &value)
void reserve(const int64_t min_capacity)
Definition half.h:29
#define logf(x)
#define roundf(x)
#define str(s)
#define INT_MAX
#define round
constexpr T sign(T) RET
#define ceil
float3x3 scale(float3x3 mat, float2 scale)
#define UI_MENU_SUBMENU_PADDING
#define UI_RADIAL_MASK_ALL_DIAGONAL
#define UI_RADIAL_MASK_ALL_AXIS_ALIGNED
#define UI_PIXEL_AA_JITTER
#define INNER
#define UI_TEXT_CLIP_MARGIN
#define PREVIEW_PAD
#define NUM_BUT_PADDING_FACTOR
#define MAX_WIDGET_BASE_BATCH
#define SC
#define OY
#define jit
#define WIDGET_SIZE_MAX
#define ICON_SIZE_FROM_BUTRECT(rect)
#define UI_INPUT_HINT_ALPHA
#define WIDGET_CURVE_RESOLU
#define MAX_WIDGET_PARAMETERS
#define NO_AA
#define WIDGET_AA_JITTER
#define SWATCH_KEYED_BORDER
const int state
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
std::optional< ExpressionInfo > next_template_variable_expression(StringRef text, size_t starting_offset)
void node_socket_draw(bNodeSocket *sock, const rcti *rect, const float color[4], float scale)
void node_draw_nodesocket(const rctf *rect, const float color_inner[4], const float color_outline[4], float outline_thickness, int shape, float aspect)
Definition drawnode.cc:1988
void get_color_4ubv(int colorid, unsigned char col[4])
void get_color_4fv(int colorid, float col[4])
const bTheme * theme_get()
void get_color_3ubv(int colorid, unsigned char col[3])
void get_color_type_4fv(int colorid, int spacetype, float col[4])
static void widget_state_nothing(WidgetType *wt, const WidgetStateInfo *, EmbossType)
static void widget_numbut_draw(const Button *but, uiWidgetColors *wcol, rcti *rect, const float zoom, const WidgetStateInfo *state, int roundboxalign, bool emboss)
static void text_clip_cursor(const uiFontStyle *fstyle, Button *but, const rcti *rect)
static const uint g_shape_preset_scroll_circle_face[14][3]
static void widget_box(Button *but, uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *, int roundboxalign, const float zoom)
void draw_preview_item(const uiFontStyle *fstyle, rcti *rect, float zoom, const char *name, int iconid, int64_t but_flag, FontStyleAlign text_align)
static void widget_but(uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *, int roundboxalign, const float zoom)
static void text_clip_give_next_off(Button *but, const char *str, const char *str_end)
static void draw_popover_back_impl(const uiWidgetColors *wcol, const rcti *rect, int direction, const float unit_size, const float mval_origin[2])
static void widgetbase_outline(WidgetBase *wtb, uint pos)
void hsvcircle_vals_from_pos(const rcti *rect, float mx, float my, float *r_val_rad, float *r_val_dist)
void perceptual_to_scene_linear_space(Button *but, float rgb[3])
int button_icon(const Button *but)
static void widget_menu_back(uiWidgetColors *wcol, const rcti *rect, const int block_flag, const int direction, const float zoom)
static void widget_scroll(Button *but, uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *state, int, const float)
static void widgetbase_set_uniform_discard_factor(WidgetBase *wtb, const float discard_factor)
static void draw_dialog_alert(Block *block, const rcti *rect)
void draw_tooltip_background(const uiStyle *style, Block *block, const rcti *rect)
gpu::Batch * batch_roundbox_widget_get()
void draw_but_VECTORSCOPE(const bContext *C, ARegion *region, Button *but, const uiWidgetColors *, const rcti *recti)
static float widget_alpha_factor(const WidgetStateInfo *state)
static void widgetbase_set_uniform_colors_ubv(WidgetBase *wtb, const uchar *col1, const uchar *col2, const uchar *outline, const uchar *emboss, const uchar *tria)
static void widget_swatch(Button *but, uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *state, int roundboxalign, const float zoom)
bool button_menu_draw_as_popover(const Button *but)
static void set_roundbox_vertex_data(GPUVertBufRaw *vflag_step, uint32_t d)
static float widget_radius_from_zoom(const float zoom, const uiWidgetColors *wcol)
void widgetbase_draw_cache_begin()
static void widget_textbut(uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *state, int roundboxalign, const float zoom)
static void widget_icon_has_anim(Button *but, uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *state, int roundboxalign, const float zoom)
Vector< StringRef > textbox_wrap_lines(ButtonTextBox *textbox)
static void widget_state_pulldown(WidgetType *wt, const WidgetStateInfo *, EmbossType)
static size_t text_shorten_next_template_var(char *str, size_t byte_position)
const ColorManagedDisplay * block_cm_display_get(Block *block)
bool button_label_is_markdown(const Button *button)
void draw_widget_menu_back(const rcti *rect, bool use_shadow)
static void hsv_cursor(const float x, const float y, const float zoom, const float rgb[3], const float hsv[3], const bool is_active)
const char * button_placeholder_get(Button *but)
static void widget_menu_itembut_unpadded(uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *, int, const float zoom)
const uiStyle * style_get()
void button_text_password_hide(std::string &password_str, Button *but, const bool restore)
void draw_but_WAVEFORM(const bContext *C, ARegion *region, Button *but, const uiWidgetColors *, const rcti *recti)
static void widget_init(WidgetBase *wtb)
static void text_clip_middle_protect_right(const uiFontStyle *fstyle, Button *but, const rcti *rect, const char rsep)
static struct blender::ui::@103037352170362214212313350304074272316175255355 g_ui_batch_cache
static void round_box_edges(WidgetBase *wt, int roundboxalign, const rcti *rect, float rad)
static const uint g_shape_preset_checkmark_face[4][3]
static const GPUVertFormat & vflag_format()
static void widget_numbut(Button *but, uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *state, int roundboxalign, const float zoom)
static const WidgetStateInfo STATE_INFO_NULL
void fontstyle_draw_ex(const uiFontStyle *fs, const rcti *rect, const char *str, size_t str_len, const uchar col[4], const FontStyleDrawParams *fs_params, int *r_xofs, int *r_yofs, ResultBLF *r_info)
bool icon_get_theme_color(int icon_id, unsigned char color[4])
static int widget_roundbox_set(Button *but, rcti *rect)
static void widget_draw_preview_icon(BIFIconID icon, float alpha, float aspect, const bool add_padding, const rcti *rect, const uchar mono_color[4])
void block_cm_to_display_space_v3(Block *block, float pixel[3])
static void draw_but_HSVCIRCLE(Button *but, const uiWidgetColors *wcol, const rcti *rect)
static const float g_shape_preset_menu_arrow_vert[6][2]
static void draw_anti_tria_rect(const rctf *rect, char dir, const float color[4])
Vector< StringRef > textbox_wrap_placeholder(ButtonTextBox *textbox)
static void widget_tab(Button *but, uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *state, int roundboxalign, const float zoom)
static const uint g_shape_preset_menu_arrow_face[2][3]
static void round_box__edges(WidgetBase *wt, int roundboxalign, const rcti *rect, float rad, float radi)
static void widget_menubut_embossn(const Button *, uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *, int)
static void widget_radiobut(uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *, int roundboxalign, const float zoom)
static void text_clip_give_prev_off(Button *but, const char *str)
static void widget_preview_tile(Button *but, uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *state, int roundboxalign, const float zoom)
void icon_draw_ex(float x, float y, int icon_id, float aspect, float alpha, float desaturate, const uchar mono_color[4], bool mono_border, const IconTextOverlay *text_overlay, const bool inverted=false, float scale=1.0f)
void draw_widget_menu_back_color(const rcti *rect, bool use_shadow, const float color[4])
void draw_but_CURVEPROFILE(ARegion *region, Button *but, const uiWidgetColors *wcol, const rcti *rect)
void fontstyle_set(const uiFontStyle *fs)
static void widget_state_option_menu(WidgetType *wt, const WidgetStateInfo *state, EmbossType emboss)
static void widget_draw_node_link_socket(const uiWidgetColors *wcol, const rcti *rect, Button *but, float alpha)
static WidgetType * popover_widget_type(Button *but, rcti *rect)
void draw_popover_back(ARegion *region, uiStyle *style, Block *block, const rcti *rect)
void draw_dropshadow(const rctf *rct, float radius, float width, float aspect, float alpha)
static void widget_draw_text_icon(const uiFontStyle *fstyle, const uiWidgetColors *wcol, Button *but, rcti *rect)
PropertyScaleType button_scale_type(const Button *but)
static void draw_but_HSVCUBE(Button *but, const rcti *rect)
static void widget_draw_extra_mask(const bContext *C, Button *but, WidgetType *wt, rcti *rect)
void draw_but_TAB_outline(const rcti *rect, float rad, uchar highlight[3], uchar highlight_fade[3])
static void widget_draw_icon(const Button *but, BIFIconID icon, float alpha, const rcti *rect, const uchar mono_color[4])
static void widget_draw_vertical_text(const uiFontStyle *fstyle, const uiWidgetColors *wcol, const Button *but, const rcti *rect)
float text_clip_middle_ex(const uiFontStyle *fstyle, char *str, float okwidth, float minwidth, size_t str_maxncpy, char rpart_sep, bool clip_right_if_tight=true, bool shorten_template_variables=false)
static void widget_state_menu_item(WidgetType *wt, const WidgetStateInfo *state, EmbossType)
static void widget_progress_type_bar(ButtonProgress *but_progress, uiWidgetColors *wcol, rcti *rect, int roundboxalign, const float zoom)
static void draw_but_HSV_v(Button *but, const rcti *rect)
void hsvcube_pos_from_vals(const ButtonHSVCube *hsv_but, const rcti *rect, const float *hsv, float *r_xp, float *r_yp)
static void widget_numslider(Button *but, uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *state, int roundboxalign, const float zoom)
bool block_is_menu(const Block *block) ATTR_WARN_UNUSED_RESULT
static size_t avoid_non_split_patterns(StringRef str, const size_t split_offset, const bool shift_left)
static void color_ensure_contrast_v3(uchar cp[3], const uchar cp_other[3], int contrast)
void widgetbase_draw_cache_end()
Button * button_drag_multi_edit_get(Button *but)
static void widget_state_label(WidgetType *wt, const WidgetStateInfo *state, EmbossType emboss)
static void color_mul_hsl_v3(uchar ch[3], float h_factor, float s_factor, float l_factor)
void draw_but_IMAGE(ARegion *, Button *but, const uiWidgetColors *, const rcti *rect)
static void draw_clip_tri(Block *block, const rcti *rect, WidgetType *wt)
@ BLOCK_NO_DRAW_OVERRIDDEN_STATE
void draw_menu_back(uiStyle *style, Block *block, const rcti *rect)
void fontstyle_draw(const uiFontStyle *fs, const rcti *rect, const char *str, size_t str_len, const uchar col[4], const FontStyleDrawParams *fs_params)
static void widget_draw_textbox(const uiFontStyle *fstyle, const uiWidgetColors *wcol, Button *but, const rcti *button_rect)
static void shape_preset_trias_from_rect_checkmark(WidgetTrias *tria, const rcti *rect)
void draw_icon_tri(float x, float y, char dir, const float[4], float aspect=1.0f)
static void widget_state_pie_menu_item(WidgetType *wt, const WidgetStateInfo *state, EmbossType)
static void color_blend_v4_v4v4(uchar r_col[4], const uchar col1[4], const uchar col2[4], const float fac)
static const float g_shape_preset_scroll_circle_vert[16][2]
void scene_linear_to_perceptual_space(Button *but, float rgb[3])
void draw_widget_scroll(uiWidgetColors *wcol, const rcti *rect, const rcti *slider, int state)
static void widget_progress_indicator(Button *but, uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *, int roundboxalign, const float zoom)
void draw_but_COLORBAND(Button *but, const uiWidgetColors *wcol, const rcti *rect)
static void widget_draw_text(const uiFontStyle *fstyle, const uiWidgetColors *wcol, Button *but, rcti *rect)
void widgetbase_draw_cache_flush()
static int but_draw_menu_icon(const Button *but)
std::optional< StringRef > button_edit_unit_hint_get(const Button &but)
static const float g_shape_preset_checkmark_vert[6][2]
static void widget_nodesocket(Button *but, uiWidgetColors *, rcti *rect, const WidgetStateInfo *, int, const float zoom)
static void widget_menu_itembut(uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *, int, const float zoom)
static void text_clip_right_ex(const uiFontStyle *fstyle, char *str, const size_t str_maxncpy, const float okwidth, const char *sep, const int sep_len, const float sep_strwidth, size_t *r_final_len)
void button_v3_get(Button *but, float vec[3])
static void widget_numbut_embossn(const Button *but, uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *state, int roundboxalign, const float zoom)
void draw_roundbox_corner_set(int type)
void draw_but_UNITVEC(Button *but, const uiWidgetColors *wcol, const rcti *rect, const float radius)
void icon_draw_preview(float x, float y, int icon_id, float aspect, float alpha, int size)
static void widget_draw_icon_centered(const BIFIconID icon, const float aspect, const float alpha, const rcti *rect, const uchar mono_color[4])
static void widget_verts_to_triangle_strip(WidgetBase *wtb, const int totvert, float triangle_strip[WIDGET_SIZE_MAX *2+2][2])
static void widget_softshadow(const rcti *rect, int roundboxalign, const float radin)
static void widgetbase_set_uniform_alpha_discard(WidgetBase *wtb, const bool alpha_check, const float discard_factor)
void draw_but_TRACKPREVIEW(ARegion *region, Button *but, const uiWidgetColors *, const rcti *recti)
static float widget_radius_from_rcti(const rcti *rect, const uiWidgetColors *wcol)
static void widget_menu_pie_itembut(Button *but, uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *, int, const float zoom)
static void shape_preset_init_trias_ex(WidgetTrias *tria, const rcti *rect, float triasize, char where, const float verts[][2], const int verts_tot, const uint tris[][3], const int tris_tot)
static void shape_preset_init_hold_action(WidgetTrias *tria, const rcti *rect, float triasize, char where)
static void color_blend_v3_v3(uchar cp[3], const uchar cpstate[3], const float fac)
static void widget_menuiconbut(uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *, int roundboxalign, const float zoom)
static void widget_menubut(uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *state, int roundboxalign, const float zoom)
const uiWidgetColors * tooltip_get_theme()
static void widgetbase_set_uniform_alpha_check(WidgetBase *wtb, const bool alpha_check)
double button_value_get(Button *but)
static const float cornervec[WIDGET_CURVE_RESOLU][2]
void label_markdown_draw(const ButtonLabel *button, const uchar color[4], const rcti *rect)
static void widget_type_color_disabled(WidgetType *wt, const WidgetStateInfo *state)
static const uint g_shape_preset_number_arrow_face[1][3]
void draw_pie_center(Block *block)
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)
int button_menu_direction(Button *but)
bool block_is_pie_menu(const Block *block) ATTR_WARN_UNUSED_RESULT
static void widget_active_color(uiWidgetColors *wcol)
static void widgetbase_draw_color(WidgetBase *wtb, const uiWidgetColors *wcol, float color[4], bool show_alpha_checkers)
static void widget_state(WidgetType *wt, const WidgetStateInfo *state, EmbossType emboss)
static uint32_t set_roundbox_vertex(GPUVertBufRaw *vflag_step, int corner_id, int corner_v, int jit_v, bool inner, bool emboss, int color)
bool button_label_is_multiline(const Button *button)
static void widget_progress_type_ring(ButtonProgress *but_progress, uiWidgetColors *wcol, rcti *rect)
static void widget_draw_multiline_text(const uiFontStyle *fstyle, const uiWidgetColors *wcol, Button *but, rcti *rect)
int fontstyle_height_max(const uiFontStyle *fs)
bool button_drag_is_draggable(const Button *but)
static void draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3, const float color[4])
void hsvcircle_pos_from_vals(const ColorPicker *cpicker, const rcti *rect, const float *hsv, float *r_xpos, float *r_ypos)
void color_picker_hsv_to_rgb(const float r_cp[3], float rgb[3])
void button_drawflag_disable(Button *but, int flag)
static void shape_preset_trias_from_rect_menu(WidgetTrias *tria, const rcti *rect)
static void draw_separator(const uiWidgetColors *wcol, Button *but, const rcti *rect)
bool button_is_color_gamma(Button &but)
static const uint g_shape_preset_hold_action_face[2][3]
static void widget_draw_vertex_buffer(uint pos, uint col, GPUPrimType mode, const float quads_pos[WIDGET_SIZE_MAX][2], const uchar quads_col[WIDGET_SIZE_MAX][4], uint totvert)
static void text_clip_middle(const uiFontStyle *fstyle, Button *but, const rcti *rect)
static void widgetbase_draw(WidgetBase *wtb, const uiWidgetColors *wcol)
bool button_is_popover_once_compat(const Button *but) ATTR_WARN_UNUSED_RESULT
static void widget_pulldownbut(uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *state, int roundboxalign, const float zoom)
static void widget_optionbut(uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *state, int, const float)
int button_text_padding(const Button *button)
static void widget_draw_extra_icons(const uiWidgetColors *wcol, Button *but, rcti *rect, float alpha)
void window_to_block_fl(const ARegion *region, const Block *block, float *x, float *y)
Definition interface.cc:193
static void shadecolors4(const uchar *color, short shadetop, short shadedown, uchar r_coltop[4], uchar r_coldown[4])
float textbox_grip_height()
void draw_text_underline(int pos_x, int pos_y, int len, int height, const float color[4])
static void widget_unitvec(Button *but, uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *, int, const float zoom)
static void shape_preset_trias_from_rect_dash(WidgetTrias *tria, const rcti *rect)
static const uchar * widget_color_blend_from_flags(const uiWidgetStateColors *wcol_state, const WidgetStateInfo *state, const EmbossType emboss)
static void widget_list_itembut(Button *but, uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *state, int, const float zoom)
static void draw_widget_back_color(WidgetStyle type, bool use_shadow, const rcti *rect, const float color[4])
static void draw_disk_shaded(float start, float angle, float radius_int, float radius_ext, int subd, const uchar col1[4], const uchar col2[4], bool shaded)
const float ui_pixel_jitter[UI_PIXEL_AA_JITTER][2]
gpu::Batch * batch_roundbox_shadow_get()
void draw_but_HISTOGRAM(ARegion *region, Button *but, const uiWidgetColors *, const rcti *recti)
static struct blender::ui::@267216362346346046265002004211257064216053106206 g_widget_base_batch
bool button_draw_as_link(const Button *button)
float textbox_vertical_padding()
static void shape_preset_init_number_arrows(WidgetTrias *tria, const rcti *rect, float triasize, char where)
void draw_preview_item_stateless(const uiFontStyle *fstyle, rcti *rect, StringRef name, int iconid, const uchar text_col[4], FontStyleAlign text_align, const bool add_padding)
static const float g_shape_preset_number_arrow_vert[3][2]
static void widget_draw_submenu_tria(const Button *but, const rcti *rect, const uiWidgetColors *wcol)
static WidgetType * widget_type(WidgetStyle type)
void color_picker_rgb_to_hsv_compat(const float rgb[3], float r_cp[3])
static void draw_gradient_hsv_to_rgb(const ColorManagedDisplay *display, float h, float s, float v, float rgb[3])
static void widget_state_numslider(WidgetType *wt, const WidgetStateInfo *state, EmbossType emboss)
void draw_roundbox_4fv(const rctf *rect, bool filled, float rad, const float col[4])
Vector< StringRef > text_clip_multiline_middle(const uiFontStyle *fstyle, const char *str, char *clipped_str_buf, const size_t clipped_str_buf_maxncpy, const float max_line_width, const int max_lines)
static void shape_preset_init_scroll_circle(WidgetTrias *tria, const rcti *rect, float triasize, char where)
static void draw_widgetbase_batch(WidgetBase *wtb)
static bool draw_emboss(const Button *but)
void draw_menu_item(const uiFontStyle *fstyle, rcti *rect, rcti *back_rect, float zoom, bool use_unpadded, const char *name, int iconid, int64_t but_flag, MenuItemSeparatorType separator_type, int *r_xmax)
bool but_is_tool(const Button *but)
void draw_gradient(const rcti *rect, const float hsv[3], eButGradientType type, float alpha, const ColorManagedDisplay *display)
static const float g_shape_preset_hold_action_vert[6][2]
static void text_clip_right_label(const uiFontStyle *fstyle, Button *but, const rcti *rect)
void draw_but_CURVE(ARegion *region, Button *but, const uiWidgetColors *wcol, const rcti *rect)
static void widget_roundbut_exec(Button *but, uiWidgetColors *wcol, rcti *rect, const WidgetStateInfo *state, int roundboxalign, const float zoom)
static void widget_color_disabled(uiWidgetColors &wcol, const WidgetStateInfo *state)
void draw_button(const bContext *C, ARegion *region, uiStyle *style, Button *but, rcti *rect)
MINLINE float min_ff(float a, float b)
UserDef U
Definition blender.cc:58
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BLF_boundbox(int fontid, const char *str, size_t str_len, rcti *r_box, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:805
__int64 int64_t
Definition BKE_text.h:90
size_t BLI_snprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
MINLINE void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
char * STRNCPY(char(&dst)[N], const char *src)
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
uint padding(uint offset, uint alignment)
MINLINE unsigned char unit_float_to_uchar_clamp(float val)
void GPU_indexbuf_init(GPUIndexBufBuilder *, GPUPrimType, uint prim_len, uint vertex_len)
void BLF_position(int fontid, float x, float y, float z)
Definition blf.cc:390
void immEnd()
void BLI_rcti_resize_y(struct rcti *rect, int y)
Definition rct.cc:629
ptrdiff_t BLI_str_utf8_invalid_byte(const char *str, size_t str_len) ATTR_NONNULL(1)
float BLF_width(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition blf.cc:835
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 hsv_to_rgb(float h, float s, float v, float *r_r, float *r_g, float *r_b)
Definition math_color.cc:25
void immAttr4ubv(uint attr_id, const unsigned char data[4])
MINLINE int round_fl_to_int(float a)
@ USER_ALWAYS_SHOW_NUMBER_ARROWS
MINLINE unsigned char srgb_to_grayscale_byte(const unsigned char rgb[3])
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)
@ SOCK_DISPLAY_SHAPE_CIRCLE
MINLINE void copy_v2_v2(float r[2], const float a[2])
size_t BLF_width_to_strlen(int fontid, const char *str, size_t str_len, float width, float *r_width) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition blf.cc:761
GPUVertFormat * immVertexFormat()
void rgb_to_hsl_v(const float rgb[3], float r_hsl[3])
float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
void immBegin(GPUPrimType, uint vertex_len)
void rgb_to_hsv_compat_v(const float rgb[3], float r_hsv[3])
void GPU_line_smooth(bool enable)
Definition gpu_state.cc:80
void BLI_rcti_resize_x(struct rcti *rect, int x)
Definition rct.cc:623
@ GPU_PRIM_TRI_STRIP
MINLINE int max_ii(int a, int b)
@ TH_WIDGET_TEXT_CURSOR
ATTR_WARN_UNUSED_RESULT const BMVert * v
void immUniformColor4fv(const float rgba[4])
void BLI_rctf_scale(rctf *rect, float scale)
Definition rct.cc:691
MINLINE void rgb_float_to_uchar(unsigned char r_col[3], const float col_f[3])
MINLINE float cube_f(float a)
MINLINE float srgb_to_grayscale(const float rgb[3])
void BLF_disable(int fontid, FontFlags flag)
Definition blf.cc:331
GPU_INLINE void * GPU_vertbuf_raw_step(GPUVertBufRaw *a)
MINLINE float pow3f(float x)
void immUnbindProgram()
void BLI_rctf_rcti_copy(struct rctf *dst, const struct rcti *src)
void immUniformColor3ubv(const unsigned char rgb[3])
void GPU_line_width(float width)
Definition gpu_state.cc:151
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
VecBase< float, 4 > float4
void immAttr3fv(uint attr_id, const float data[3])
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
void imm_draw_circle_wire_2d(uint shdr_pos, float x, float y, float radius, int nsegments)
unsigned int uint32_t
Definition BKE_text.h:81
void immUniformThemeColor(int color_id)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
gpu::IndexBuf * GPU_indexbuf_build(GPUIndexBufBuilder *)
PropertyScaleType
Definition RNA_types.hh:251
@ PROP_SCALE_LOG
Definition RNA_types.hh:258
@ PROP_SCALE_CUBIC
Definition RNA_types.hh:263
@ PROP_SCALE_LINEAR
Definition RNA_types.hh:253
void immUniform1f(const char *name, float x)
bool BLF_str_offset_to_glyph_bounds(int fontid, const char *str, size_t str_offset, rcti *r_glyph_bounds) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2
Definition blf.cc:725
void immVertex2f(uint attr_id, float x, float y)
unsigned char uchar
Definition BKE_text.h:58
BLI_INLINE int BLI_rcti_cent_y(const struct rcti *rct)
Definition BLI_rect.hh:190
void immAttr4fv(uint attr_id, const float data[4])
BMesh const char void * data
@ GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA
@ GPU_SHADER_2D_WIDGET_BASE_INST
void GPU_scissor_get(int coords[4])
Definition gpu_state.cc:253
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.hh:215
void GPU_batch_draw_instance_range(gpu::Batch *batch, int instance_first, int instance_count)
void BLI_rcti_translate(struct rcti *rect, int x, int y)
Definition rct.cc:580
int RNA_property_flag(PropertyRNA *prop)
const char const char * BLI_str_find_next_char_utf8(const char *p, const char *str_end) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
size_t BLF_width_to_rstrlen(int fontid, const char *str, size_t str_len, float width, float *r_width) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition blf.cc:783
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
@ GPU_BATCH_OWNS_INDEX
Definition GPU_batch.hh:48
void GPU_program_point_size(bool enable)
Definition gpu_state.cc:165
void gpu_batch_presets_register(gpu::Batch *preset_batch)
int BLI_str_utf8_size_safe(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Vector< StringRef > BLF_string_wrap(int fontid, StringRef str, const int max_pixel_width, BLFWrapMode mode=BLFWrapMode::Minimal)
Definition blf.cc:1103
MINLINE void add_v3_uchar_clamped(uchar r[3], int i)
bool BLI_rcti_is_empty(const struct rcti *rect)
void GPU_indexbuf_add_tri_verts(GPUIndexBufBuilder *, uint v1, uint v2, uint v3)
MINLINE void copy_v4_v4_uchar(unsigned char r[4], const unsigned char a[4])
void GPU_matrix_translate_2f(float x, float y)
void GPU_vertbuf_attr_get_raw_data(gpu::VertBuf *, uint a_idx, GPUVertBufRaw *access)
void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:587
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
int BLF_ascender(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:916
void GPU_batch_program_set_builtin(gpu::Batch *batch, GPUBuiltinShader shader_id)
void BLF_color4ubv(int fontid, const unsigned char rgba[4])
Definition blf.cc:454
int BIFIconID
Definition ED_asset.hh:30
void hsl_to_rgb_v(const float hsl[3], float r_rgb[3])
Definition math_color.cc:66
BLI_INLINE float BLI_rcti_cent_x_fl(const struct rcti *rct)
Definition BLI_rect.hh:178
MINLINE float len_squared_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
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)
const char * BLI_str_find_prev_char_utf8(const char *p, const char *str_start) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1
void immUniform4f(const char *name, float x, float y, float z, float w)
void IMB_colormanagement_color_picking_to_scene_linear_v3(float scene_linear[3], const float color_picking[3])
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 interp_v3_v3v3_uchar(unsigned char target[3], const unsigned char a[3], const unsigned char b[3], float t)
MINLINE float max_ff(float a, float b)
MINLINE void copy_v3_v3_uchar(unsigned char r[3], const unsigned char a[3])
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
int BLF_descender(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:905
bool int BLF_str_offset_to_cursor(int fontid, const char *str, size_t str_len, size_t str_offset, int cursor_width)
Definition blf.cc:738
@ PROP_PATH_SUPPORTS_TEMPLATES
Definition RNA_types.hh:540
MINLINE void rgb_uchar_to_float(float r_col[3], const unsigned char col_ub[3])
MINLINE void copy_v4_v4(float r[4], const float a[4])
ColorTheme4< float > ColorTheme4f
void immUniformColor3fv(const float rgb[3])
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
void BLI_rcti_pad(struct rcti *rect, int pad_x, int pad_y)
Definition rct.cc:643
void BLI_rcti_resize(struct rcti *rect, int x, int y)
Definition rct.cc:635
void ATTR_NONNULL(1, 2)
BLI_INLINE int BLI_rcti_cent_x(const struct rcti *rct)
Definition BLI_rect.hh:186
void imm_draw_disk_partial_fill_2d(uint pos, float x, float y, float rad_inner, float rad_outer, int nsegments, float start, float sweep)
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 BLF_rotation(int fontid, float angle)
Definition blf.cc:936
MINLINE int min_ii(int a, int b)
void immRectf(uint pos, float x1, float y1, float x2, float y2)
BLI_INLINE float BLI_rcti_cent_y_fl(const struct rcti *rct)
Definition BLI_rect.hh:182
void BLI_rctf_pad(struct rctf *rect, float pad_x, float pad_y)
Definition rct.cc:651
void BLF_enable(int fontid, FontFlags flag)
Definition blf.cc:322
@ BLF_SHADOW
Definition BLF_enums.hh:38
@ BLF_ROTATION
Definition BLF_enums.hh:36
void GPU_matrix_push()
@ BIFICONID_LAST_STATIC
MINLINE void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
Vector< Bounds< int > > BLF_str_selection_boxes(int fontid, const char *str, size_t str_len, size_t sel_start, size_t sel_length)
Definition blf.cc:751
ocio::Display ColorManagedDisplay
void BLI_rctf_init(struct rctf *rect, float xmin, float xmax, float ymin, float ymax)
Definition rct.cc:418
MINLINE float clamp_f(float value, float min, float max)
@ Number
Definition types.hh:44
#define sqrtf
#define fmaxf
#define sinf
#define cosf
#define ceilf
#define atan2f
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
float menu_shadow_fac
uiWidgetColors wcol_pulldown
uiWidgetColors wcol_numslider
uiWidgetColors wcol_list_item
uiWidgetColors wcol_menu
uiWidgetColors wcol_progress
uiWidgetColors wcol_menu_back
uiWidgetColors wcol_num
float icon_border_intensity
uiWidgetColors wcol_curve
uiWidgetColors wcol_menu_item
uiWidgetColors wcol_toggle
uiWidgetColors wcol_regular
uiWidgetColors wcol_tooltip
uiWidgetColors wcol_option
uiWidgetColors wcol_text
uiWidgetColors wcol_tab
uiWidgetStateColors wcol_state
uiWidgetColors wcol_radio
uiWidgetColors wcol_scroll
uiWidgetColors wcol_pie_menu
uiWidgetColors wcol_toolbar_item
uiWidgetColors wcol_tool
float icon_saturation
uiWidgetColors wcol_box
ThemeUI tui
std::function< void(const bContext *, rcti *)> drawextra
BlockAlertLevel alert_level
Button * next_but(const Button *but) const
Definition interface.cc:288
std::unique_ptr< PieMenuData > pie_data
std::shared_ptr< TextWrapCache > wrap_cache
std::unique_ptr< TextWrapCache > wrap_cache
ButtonHandleHoldFunc hold_func
TextDirection text_direction
IconTextOverlay icon_overlay_text
HandleButtonData * active
ListBaseT< ButtonExtraOpIcon > extra_op_icons
float outer_v[WIDGET_SIZE_MAX][2]
float inner_v[WIDGET_SIZE_MAX][2]
WidgetBaseParameters uniform_params
float inner_uv[WIDGET_SIZE_MAX][2]
const uiWidgetColors * wcol_theme
void(*) state(WidgetType *, const WidgetStateInfo *state, EmbossType emboss) ATTR_NONNULL()
const uiWidgetStateColors * wcol_state
void(*) draw(uiWidgetColors *, rcti *, const WidgetStateInfo *, int roundboxalign, const float zoom) ATTR_NONNULL()
void(*) custom(Button *, uiWidgetColors *, rcti *, const WidgetStateInfo *, int roundboxalign, const float zoom) ATTR_NONNULL()
void(*) draw_block(uiWidgetColors *, const rcti *, int block_flag, int roundboxalign, const float zoom)
void(*) text(const uiFontStyle *, const uiWidgetColors *, Button *, rcti *)
WidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
uiFontStyle widget
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]
unsigned char shaded
unsigned char inner_key_sel[4]
unsigned char inner_changed_sel[4]
unsigned char inner_anim_sel[4]
unsigned char inner_driven_sel[4]
unsigned char inner_overridden_sel[4]