Blender V5.3
interface_region_tooltip.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11/* TODO(@ideasman42):
12 * We may want to have a higher level API that initializes a timer,
13 * checks for mouse motion and clears the tool-tip afterwards.
14 * We never want multiple tool-tips at once
15 * so this could be handled on the window / window-manager level.
16 *
17 * For now it's not a priority, so leave as-is.
18 */
19
20#include <algorithm>
21#include <cstdarg>
22#include <cstdlib>
23#include <cstring>
24#include <memory>
25
26#include <fmt/format.h>
27
29
30#include "MEM_guardedalloc.h"
31
32#include "DNA_userdef_types.h"
33
34#include "BLI_fileops.hh"
35#include "BLI_listbase.hh"
36#include "BLI_math_color_c.hh"
37#include "BLI_math_vector_c.hh"
38#include "BLI_path_utils.hh"
39#include "BLI_rect.hh"
40#include "BLI_string_utf8.hh"
41#include "BLI_utildefines.hh"
42
43#include "BKE_context.hh"
44#include "BKE_idtype.hh"
45#include "BKE_image.hh"
46#include "BKE_library.hh"
47#include "BKE_main.hh"
48#include "BKE_paint.hh"
49#include "BKE_path_templates.hh"
50#include "BKE_screen.hh"
51#include "BKE_vfont.hh"
52
53#include "BIF_glutil.hh"
54
55#include "DNA_vfont_types.h"
56
57#include "GPU_immediate.hh"
58#include "GPU_immediate_util.hh"
59#include "GPU_state.hh"
60
62#include "IMB_imbuf.hh"
63#include "IMB_imbuf_types.hh"
64#include "IMB_thumbs.hh"
65
66#include "MOV_read.hh"
67
68#include "WM_api.hh"
69#include "WM_types.hh"
70
71#include "RNA_access.hh"
72#include "RNA_enum_types.hh"
73#include "RNA_path.hh"
74#include "RNA_prototypes.hh"
75
76#include "BLF_api.hh"
77#include "BLT_translation.hh"
78
79#ifdef WITH_PYTHON
80# include "BPY_extern_run.hh"
81#endif
82
83#include "ED_screen.hh"
84
85#include "interface_intern.hh"
87
88namespace blender::ui {
89
90/* Portions of line height. */
91#define TIP_SPACER 0.3f
92#define TIP_PADDING_X 1.95f
93#define TIP_PADDING_Y 1.28f
94
95#define TIP_MAXWIDTH 600
96
101
103 std::string text;
104 std::string text_suffix;
105 struct {
107 uint x_pos;
109 uint lines;
112 std::optional<TooltipImage> image;
113};
114
122
123BLI_STATIC_ASSERT(int(TIP_LC_MAX) == int(TIP_LC_ALERT) + 1, "invalid lc-max");
124
126 std::string text,
127 std::string suffix,
128 const TooltipStyle style,
129 const TooltipColorID color_id,
130 const bool is_pad)
131{
132 if (is_pad) {
133 /* Add a spacer field before this one. */
135 }
136
137 TooltipField field{};
138 field.format.style = style;
139 field.format.color_id = color_id;
140 field.text = std::move(text);
141 field.text_suffix = std::move(suffix);
142 data.fields.append(std::move(field));
143}
144
146{
147 TooltipField field{};
149 field.image = image_data;
150 field.image->ibuf = IMB_dupImBuf(image_data.ibuf);
151 data.fields.append(std::move(field));
152}
153
154/* -------------------------------------------------------------------- */
157
158static void color_blend_f3_f3(float dest[3], const float source[3], const float fac)
159{
160 if (fac != 0.0f) {
161 dest[0] = (1.0f - fac) * dest[0] + (fac * source[0]);
162 dest[1] = (1.0f - fac) * dest[1] + (fac * source[1]);
163 dest[2] = (1.0f - fac) * dest[2] + (fac * source[2]);
164 }
165}
166
167static void tooltip_region_draw_cb(const bContext * /*C*/, ARegion *region)
168{
169 TooltipData *data = static_cast<TooltipData *>(region->regiondata);
170 const float pad_x = data->lineh * TIP_PADDING_X;
171 const float pad_y = data->lineh * TIP_PADDING_Y;
173 rcti bbox = data->bbox;
174 float tip_colors[TIP_LC_MAX][4];
175 uchar drawcol[4] = {0, 0, 0, 255}; /* to store color in while drawing (alpha is always 255) */
176
177 /* The color from the theme. */
178 float *main_color = tip_colors[TIP_LC_MAIN];
179 float *value_color = tip_colors[TIP_LC_VALUE];
180 float *active_color = tip_colors[TIP_LC_ACTIVE];
181 float *normal_color = tip_colors[TIP_LC_NORMAL];
182 float *dimmed_color = tip_colors[TIP_LC_DIMMED];
183 float *alert_color = tip_colors[TIP_LC_ALERT];
184
185 float background_color[3];
186
188
189 /* Draw background. */
190 draw_tooltip_background(style_get(), nullptr, &bbox);
191
192 /* set background_color */
193 rgb_uchar_to_float(background_color, theme->inner);
194
195 /* `normal_color` is just tooltip text color. */
196 rgb_uchar_to_float(main_color, theme->text);
197 copy_v3_v3(normal_color, main_color);
198
199 /* `value_color` mixes with some background for less strength. */
200 copy_v3_v3(value_color, main_color);
201 color_blend_f3_f3(value_color, background_color, 0.2f);
202
203 /* `python_color` mixes with more background to be even dimmer. */
204 copy_v3_v3(dimmed_color, main_color);
205 color_blend_f3_f3(dimmed_color, background_color, 0.5f);
206
207 /* Use the info color (light blue) to highlight things like the
208 * active enum value, use info's alpha as blend factor toward text color. */
209 theme::get_color_4fv(TH_INFO, active_color);
210 color_blend_f3_f3(active_color, main_color, 1.0f - active_color[3]);
211
212 /* `alert_color` is red, alpha as blend factor toward text color. */
213 theme::get_color_4fv(TH_REDALERT, alert_color);
214 color_blend_f3_f3(alert_color, main_color, 1.0f - alert_color[3]);
215
216 /* Draw text. */
217 BLF_size(data->fstyle.uifont_id, data->fstyle.points * UI_SCALE_FAC);
218
219 /* Wrap most text typographically with hard width limit. */
220 BLF_wordwrap(data->fstyle.uifont_id,
221 data->wrap_width,
223
224 /* Wrap paths with path-specific wrapping with hard width limit. */
226
227 bbox.xmin += 0.5f * pad_x; /* add padding to the text */
228 bbox.ymax -= 0.5f * pad_y;
229 bbox.ymax -= BLF_descender(data->fstyle.uifont_id);
230
231 for (int i = 0; i < data->fields.size(); i++) {
232 const TooltipField *field = &data->fields[i];
233
234 bbox.ymin = bbox.ymax - (data->lineh * field->geom.lines);
235 if (field->format.style == TIP_STYLE_HEADER) {
236 FontStyleDrawParams fs_params{};
237 fs_params.align = UI_STYLE_TEXT_LEFT;
238 fs_params.word_wrap = true;
239
240 /* Draw header and active data (is done here to be able to change color). */
241 rgb_float_to_uchar(drawcol, tip_colors[TIP_LC_MAIN]);
242 fontstyle_set(&data->fstyle);
244 &data->fstyle, &bbox, field->text.c_str(), field->text.size(), drawcol, &fs_params);
245
246 /* Offset to the end of the last line. */
247 if (!field->text_suffix.empty()) {
248 const float xofs = field->geom.x_pos;
249 const float yofs = data->lineh * (field->geom.lines - 1);
250 bbox.xmin += xofs;
251 bbox.ymax -= yofs;
252
253 rgb_float_to_uchar(drawcol, tip_colors[TIP_LC_ACTIVE]);
254 fontstyle_draw(&data->fstyle,
255 &bbox,
256 field->text_suffix.c_str(),
257 field->text_suffix.size(),
258 drawcol,
259 &fs_params);
260
261 /* Undo offset. */
262 bbox.xmin -= xofs;
263 bbox.ymax += yofs;
264 }
265 }
266 else if (field->format.style == TIP_STYLE_MONO) {
267 FontStyleDrawParams fs_params{};
268 fs_params.align = UI_STYLE_TEXT_LEFT;
269 fs_params.word_wrap = true;
270 uiFontStyle fstyle_mono = data->fstyle;
271 fstyle_mono.uifont_id = blf_mono_font;
272
273 fontstyle_set(&fstyle_mono);
274 /* XXX: needed because we don't have mono in 'U.uifonts'. */
275 BLF_size(fstyle_mono.uifont_id, fstyle_mono.points * UI_SCALE_FAC);
276 rgb_float_to_uchar(drawcol, tip_colors[int(field->format.color_id)]);
278 &fstyle_mono, &bbox, field->text.c_str(), field->text.size(), drawcol, &fs_params);
279 }
280 else if (field->format.style == TIP_STYLE_IMAGE && field->image.has_value()) {
281
282 bbox.ymax -= field->image->height;
283
284 if (field->image->background == TooltipImageBackground::Checkerboard_Themed) {
285 imm_draw_box_checker_2d(float(bbox.xmin),
286 float(bbox.ymax),
287 float(bbox.xmin + field->image->width),
288 float(bbox.ymax + field->image->height));
289 }
290 else if (field->image->background == TooltipImageBackground::Checkerboard_Fixed) {
291 const float checker_dark = UI_ALPHA_CHECKER_DARK / 255.0f;
292 const float checker_light = UI_ALPHA_CHECKER_LIGHT / 255.0f;
293 const float color1[4] = {checker_dark, checker_dark, checker_dark, 1.0f};
294 const float color2[4] = {checker_light, checker_light, checker_light, 1.0f};
295 imm_draw_box_checker_2d_ex(float(bbox.xmin + U.pixelsize),
296 float(bbox.ymax + U.pixelsize),
297 float(bbox.xmin + field->image->width),
298 float(bbox.ymax + field->image->height),
299 color1,
300 color2,
301 8);
302 }
303
304 GPU_blend((field->image->premultiplied) ? GPU_BLEND_ALPHA_PREMULT : GPU_BLEND_ALPHA);
305
307 drawer.draw(bbox.xmin,
308 bbox.ymax,
309 field->image->ibuf->x,
310 field->image->ibuf->y,
311 gpu::TextureFormat::UNORM_8_8_8_8,
312 true,
313 field->image->ibuf->byte_data(),
314 float(field->image->width) / float(field->image->ibuf->x),
315 float(field->image->height) / float(field->image->ibuf->y),
316 (field->image->text_color) ? main_color : nullptr);
317
318 if (field->image->border) {
320 GPUVertFormat *format = immVertexFormat();
321 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
323 float border_color[4] = {1.0f, 1.0f, 1.0f, 0.15f};
324 float bgcolor[4];
326 if (srgb_to_grayscale(bgcolor) > 0.5f) {
327 border_color[0] = 0.0f;
328 border_color[1] = 0.0f;
329 border_color[2] = 0.0f;
330 }
331 immUniformColor4fv(border_color);
333 float(bbox.xmin),
334 float(bbox.ymax),
335 float(bbox.xmin + field->image->width),
336 float(bbox.ymax + field->image->height));
339 }
340 }
341 else if (field->format.style == TIP_STYLE_SPACER) {
342 bbox.ymax -= data->lineh * TIP_SPACER;
343 }
344 else {
346 FontStyleDrawParams fs_params{};
347 fs_params.align = UI_STYLE_TEXT_LEFT;
348 fs_params.word_wrap = true;
349
350 /* Draw remaining data. */
351 rgb_float_to_uchar(drawcol, tip_colors[int(field->format.color_id)]);
352 fontstyle_set(&data->fstyle);
354 &data->fstyle, &bbox, field->text.c_str(), field->text.size(), drawcol, &fs_params);
355 }
356
357 bbox.ymax -= data->lineh * field->geom.lines;
358 }
359
360 BLF_disable(data->fstyle.uifont_id, BLF_WORD_WRAP);
362}
363
364static void tooltip_region_free_cb(ARegion *region)
365{
366 /* Put ownership back into a unique pointer. */
367 std::unique_ptr<TooltipData> data{static_cast<TooltipData *>(region->regiondata)};
368 for (TooltipField &field : data->fields) {
369 if (field.image && field.image->ibuf) {
370 IMB_freeImBuf(field.image->ibuf);
371 }
372 }
373 region->regiondata = nullptr;
374}
375
377
378/* -------------------------------------------------------------------- */
381
383{
384 std::string str = WM_operator_pystring_ex(C, nullptr, false, false, ot, opptr);
385
386 /* Avoid overly verbose tips (eg, arrays of 20 layers), exact limit is arbitrary. */
387 return WM_operator_pystring_abbreviate(std::move(str), 32);
388}
389
391
392/* -------------------------------------------------------------------- */
395
396#ifdef WITH_PYTHON
397
398static bool tooltip_data_append_from_keymap(bContext *C, TooltipData &data, wmKeyMap *keymap)
399{
400 const int fields_len_init = data.fields.size();
401
402 for (wmKeyMapItem &kmi : keymap->items) {
404 if (!ot) {
405 continue;
406 }
407 /* Tip. */
409 ot->description ? ot->description : ot->name,
410 {},
413 true);
414
415 /* Shortcut. */
416 const std::string kmi_str = WM_keymap_item_to_string(&kmi, false).value_or("None");
418 fmt::format(fmt::runtime(TIP_("Shortcut: {}")), kmi_str),
419 {},
422
423 /* Python. */
425 std::string str = tooltip_text_python_from_op(C, ot, kmi.ptr);
427 fmt::format(fmt::runtime(TIP_("Python: {}")), str),
428 {},
431 }
432 }
433
434 return (fields_len_init != data.fields.size());
435}
436
437#endif /* WITH_PYTHON */
438
439static std::string tooltip_with_period(StringRef tip)
440{
441 if (tip.is_empty()) {
442 return tip;
443 }
444
445 /* Already ends with punctuation. */
446 const uint charcode = BLI_str_utf8_as_unicode_safe(
447 BLI_str_find_prev_char_utf8(tip.data() + tip.size(), tip.data()));
449 return tip;
450 }
451
452 /* Contains a bullet Unicode character. */
453 if (tip.find("\xe2\x80\xa2") != StringRef::not_found) {
454 return tip;
455 }
456
457 return fmt::format("{}{}", tip, ".");
458}
459
463static std::unique_ptr<TooltipData> tooltip_data_from_tool(bContext *C,
464 Button *but,
465 bool is_quick_tip)
466{
467 if (but->optype == nullptr) {
468 return nullptr;
469 }
470 /* While this should always be set for buttons as they are shown in the UI,
471 * the operator search popup can create a button that has no properties, see: #112541. */
472 if (but->opptr == nullptr) {
473 return nullptr;
474 }
475
476 if (!STREQ(but->optype->idname, "WM_OT_tool_set_by_id")) {
477 return nullptr;
478 }
479
480 /* Needed to get the space-data's type (below). */
481 if (CTX_wm_space_data(C) == nullptr) {
482 return nullptr;
483 }
484
485 char tool_id[MAX_NAME];
486 RNA_string_get(but->opptr, "name", tool_id);
487 BLI_assert(tool_id[0] != '\0');
488
489 /* When false, we're in a different space type to the tool being set.
490 * Needed for setting the fallback tool from the properties space.
491 *
492 * If we drop the hard coded 3D-view in properties hack, we can remove this check. */
493 bool has_valid_context = true;
494 const char *has_valid_context_error = IFACE_("Unsupported context");
495 {
496 ScrArea *area = CTX_wm_area(C);
497 if (area == nullptr) {
498 has_valid_context = false;
499 }
500 else {
501 PropertyRNA *prop = RNA_struct_find_property(but->opptr, "space_type");
502 if (RNA_property_is_set(but->opptr, prop)) {
503 const int space_type_prop = RNA_property_enum_get(but->opptr, prop);
504 if (space_type_prop != area->spacetype) {
505 has_valid_context = false;
506 }
507 }
508 }
509 }
510
511 /* We have a tool, now extract the info. */
512 std::unique_ptr<TooltipData> data = std::make_unique<TooltipData>();
513
514#ifdef WITH_PYTHON
515 /* It turns out to be most simple to do this via Python since C
516 * doesn't have access to information about non-active tools. */
517
518 /* Title (when icon-only). */
519 if (but->drawstr.empty()) {
520 const char *expr_imports[] = {"bpy", "bl_ui", nullptr};
521 char expr[256];
522 SNPRINTF_UTF8(expr,
523 "bl_ui.space_toolsystem_common.item_from_id("
524 "bpy.context, "
525 "bpy.context.space_data.type, "
526 "'%s').label",
527 tool_id);
528 char *expr_result = nullptr;
529 bool is_error = false;
530
531 if (has_valid_context == false) {
532 expr_result = BLI_strdup(has_valid_context_error);
533 }
534 else if (BPY_run_string_as_string(C, expr_imports, expr, nullptr, &expr_result)) {
535 if (STREQ(expr_result, "")) {
536 MEM_delete(expr_result);
537 expr_result = nullptr;
538 }
539 }
540 else {
541 /* NOTE: this is an exceptional case, we could even remove it
542 * however there have been reports of tooltips failing, so keep it for now. */
543 expr_result = BLI_strdup(TIP_("Internal error!"));
544 is_error = true;
545 }
546
547 if (expr_result != nullptr) {
548 /* NOTE: This is a very weak hack to get a valid translation most of the time...
549 * Proper way to do would be to get i18n context from the item, somehow. */
550 const char *label_str = CTX_TIP_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, expr_result);
551 if (label_str == expr_result) {
552 label_str = TIP_(expr_result);
553 }
554
555 if (label_str != expr_result) {
556 MEM_delete(expr_result);
557 expr_result = BLI_strdup(label_str);
558 }
559
561 expr_result,
562 {},
564 (is_error) ? TIP_LC_ALERT : TIP_LC_MAIN,
565 false);
566 MEM_delete(expr_result);
567 }
568 }
569
570 /* Tip. */
571 if (is_quick_tip == false) {
572 const char *expr_imports[] = {"bpy", "bl_ui", nullptr};
573 char expr[256];
574 SNPRINTF_UTF8(expr,
575 "bl_ui.space_toolsystem_common.description_from_id("
576 "bpy.context, "
577 "bpy.context.space_data.type, "
578 "'%s')",
579 tool_id);
580
581 char *expr_result = nullptr;
582 bool is_error = false;
583
584 if (has_valid_context == false) {
585 expr_result = BLI_strdup(has_valid_context_error);
586 }
587 else if (BPY_run_string_as_string(C, expr_imports, expr, nullptr, &expr_result)) {
588 if (STREQ(expr_result, "")) {
589 MEM_delete(expr_result);
590 expr_result = nullptr;
591 }
592 }
593 else {
594 /* NOTE: this is an exceptional case, we could even remove it
595 * however there have been reports of tooltips failing, so keep it for now. */
596 expr_result = BLI_strdup(TIP_("Internal error!"));
597 is_error = true;
598 }
599
600 if (expr_result != nullptr) {
601 const std::string but_tip = tooltip_with_period(expr_result);
603 *data, but_tip, {}, TIP_STYLE_NORMAL, (is_error) ? TIP_LC_ALERT : TIP_LC_MAIN, false);
604 MEM_delete(expr_result);
605 }
606 }
607
608 /* Shortcut. */
609 const bool show_shortcut = is_quick_tip == false &&
610 ((but->block->flag & BLOCK_SHOW_SHORTCUT_ALWAYS) == 0);
611
612 if (show_shortcut) {
613 /* There are different kinds of shortcuts:
614 *
615 * - Direct access to the tool (as if the toolbar button is pressed).
616 * - The key is assigned to the operator itself
617 * (bypassing the tool, executing the operator).
618 *
619 * Either way case it's useful to show the shortcut.
620 */
621 std::string shortcut = button_string_get_operator_keymap(*C, *but);
622
623 if (shortcut.empty()) {
624 /* Check for direct access to the tool. */
625 std::optional<std::string> shortcut_toolbar = WM_key_event_operator_string(
626 C, "WM_OT_toolbar", wm::OpCallContext::InvokeRegionWin, nullptr, true);
627 if (shortcut_toolbar) {
628 /* Generate keymap in order to inspect it.
629 * NOTE: we could make a utility to avoid the keymap generation part of this. */
630 const char *expr_imports[] = {
631 "bpy", "bl_keymap_utils", "bl_keymap_utils.keymap_from_toolbar", nullptr};
632 const char *expr =
633 ("getattr("
634 "bl_keymap_utils.keymap_from_toolbar.generate("
635 "bpy.context, "
636 "bpy.context.space_data.type), "
637 "'as_pointer', lambda: 0)()");
638
639 intptr_t expr_result = 0;
640
641 if (has_valid_context == false) {
642 shortcut = has_valid_context_error;
643 }
644 else if (BPY_run_string_as_intptr(C, expr_imports, expr, nullptr, &expr_result)) {
645 if (expr_result != 0) {
646 wmKeyMap *keymap = reinterpret_cast<wmKeyMap *>(expr_result);
647 for (wmKeyMapItem &kmi : keymap->items) {
648 if (STREQ(kmi.idname, but->optype->idname)) {
649 char tool_id_test[MAX_NAME];
650 RNA_string_get(kmi.ptr, "name", tool_id_test);
651 if (STREQ(tool_id, tool_id_test)) {
652 std::string kmi_str = WM_keymap_item_to_string(&kmi, false).value_or("");
653 shortcut = fmt::format("{}, {}", *shortcut_toolbar, kmi_str);
654 break;
655 }
656 }
657 }
658 }
659 }
660 else {
661 BLI_assert(0);
662 }
663 }
664 }
665
666 if (!shortcut.empty()) {
668 fmt::format(fmt::runtime(TIP_("Shortcut: {}")), shortcut),
669 {},
672 true);
673 }
674 }
675
676 if (show_shortcut) {
677 /* Shortcut for Cycling
678 *
679 * As a second option, we may have a shortcut to cycle this tool group.
680 *
681 * Since some keymaps may use this for the primary means of binding keys,
682 * it's useful to show these too.
683 * Without this there is no way to know how to use a key to set the tool.
684 *
685 * This is a little involved since the shortcut may be bound to another tool in this group,
686 * instead of the current tool on display. */
687
688 char *expr_result = nullptr;
689 size_t expr_result_len;
690
691 {
692 const char *expr_imports[] = {"bpy", "bl_ui", nullptr};
693 char expr[256];
694 SNPRINTF_UTF8(expr,
695 "'\\x00'.join("
696 "item.idname for item in bl_ui.space_toolsystem_common.item_group_from_id("
697 "bpy.context, "
698 "bpy.context.space_data.type, '%s', coerce=True) "
699 "if item is not None)",
700 tool_id);
701
702 if (has_valid_context == false) {
703 /* pass */
704 }
706 C, expr_imports, expr, nullptr, &expr_result, &expr_result_len))
707 {
708 /* pass. */
709 }
710 }
711
712 if (expr_result != nullptr) {
714 RNA_boolean_set(&op_props, "cycle", true);
715
716 std::optional<std::string> shortcut;
717
718 const char *item_end = expr_result + expr_result_len;
719 const char *item_step = expr_result;
720
721 while (item_step < item_end) {
722 RNA_string_set(&op_props, "name", item_step);
724 but->optype->idname,
726 static_cast<IDProperty *>(op_props.data),
727 true);
728 if (shortcut) {
729 break;
730 }
731 item_step += strlen(item_step) + 1;
732 }
733
735 MEM_delete(expr_result);
736
737 if (shortcut) {
739 fmt::format(fmt::runtime(TIP_("Shortcut Cycle: {}")), *shortcut),
740 {},
743 true);
744 }
745 }
746 }
747
748 if (show_shortcut) {
749 /* Shortcut for Hold
750 *
751 * As a third option, we may have a shortcut that enables a tool when held, and
752 * returns to the previous tool when released.
753 */
754
755 std::optional<std::string> shortcut;
756 if (wmOperatorType *ot_hold = WM_operatortype_find("WM_OT_tool_set_by_id_hold", false)) {
758 RNA_string_set(&op_props, "name", tool_id);
760 ot_hold->idname,
762 static_cast<IDProperty *>(op_props.data),
763 true);
765 }
766
767 if (shortcut) {
769 fmt::format(fmt::runtime(TIP_("Shortcut Hold: {}")), *shortcut),
770 {},
773 true);
774 }
775 }
776
777 /* Python */
778 if ((is_quick_tip == false) && (U.flag & USER_TOOLTIPS_PYTHON)) {
779 std::string str = tooltip_text_python_from_op(C, but->optype, but->opptr);
781 fmt::format(fmt::runtime(TIP_("Python: {}")), str),
782 {},
785 true);
786 }
787
788 /* Keymap */
789
790 /* This is too handy not to expose somehow, let's be sneaky for now. */
791 if ((is_quick_tip == false) && CTX_wm_window(C)->runtime->eventstate->modifier & KM_SHIFT) {
792 const char *expr_imports[] = {"bpy", "bl_ui", nullptr};
793 char expr[256];
794 SNPRINTF_UTF8(expr,
795 "getattr("
796 "bl_ui.space_toolsystem_common.keymap_from_id("
797 "bpy.context, "
798 "bpy.context.space_data.type, "
799 "'%s'), "
800 "'as_pointer', lambda: 0)()",
801 tool_id);
802
803 intptr_t expr_result = 0;
804
805 if (has_valid_context == false) {
806 /* pass */
807 }
808 else if (BPY_run_string_as_intptr(C, expr_imports, expr, nullptr, &expr_result)) {
809 if (expr_result != 0) {
811 *data, TIP_("Tool Keymap:"), {}, TIP_STYLE_NORMAL, TIP_LC_VALUE, true);
812 wmKeyMap *keymap = reinterpret_cast<wmKeyMap *>(expr_result);
813 tooltip_data_append_from_keymap(C, *data, keymap);
814 }
815 }
816 else {
817 BLI_assert(0);
818 }
819 }
820#else
821 UNUSED_VARS(is_quick_tip, has_valid_context, has_valid_context_error);
822#endif /* WITH_PYTHON */
823
824 return data->fields.is_empty() ? nullptr : std::move(data);
825}
826
827static std::string tooltip_color_string(const float4 &color,
828 const StringRefNull title,
829 const int max_title_len,
830 const bool show_alpha,
831 const bool show_hex = false)
832{
833 const int align = max_title_len - title.size();
834
835 if (show_hex) {
836 uchar hex[4];
838 if (show_alpha) {
839 return fmt::format("{}:{: <{}} #{:02X}{:02X}{:02X}{:02X}",
840 title,
841 "",
842 align,
843 int(hex[0]),
844 int(hex[1]),
845 int(hex[2]),
846 int(hex[3]));
847 }
848 return fmt::format(
849 "{}:{: <{}} #{:02X}{:02X}{:02X}", title, "", align, int(hex[0]), int(hex[1]), int(hex[2]));
850 }
851
852 if (show_alpha) {
853 return fmt::format("{}:{: <{}} {:.3f}", title, "", align, color[3]);
854 }
855
856 return fmt::format(
857 "{}:{: <{}} {:.3f} {:.3f} {:.3f}", title, "", align, color[0], color[1], color[2]);
858};
859
861 const float4 &original_color,
862 const bool has_alpha,
863 const bool is_gamma,
864 const ColorManagedDisplay *display,
865 const TooltipColorID color_id)
866{
867 float4 scene_linear_color = original_color;
868 float4 display_color = original_color;
869 float4 srgb_color = original_color;
870
871 if (is_gamma) {
872 IMB_colormanagement_srgb_to_scene_linear_v3(scene_linear_color, scene_linear_color);
873 }
874 else {
876 display_color, display, DISPLAY_SPACE_COLOR_INSPECTION);
877 IMB_colormanagement_scene_linear_to_srgb_v3(srgb_color, srgb_color);
878 }
879
880 float hsv[4];
881 rgb_to_hsv_v(srgb_color, hsv);
882 hsv[3] = srgb_color[3];
883
884 const StringRefNull hex_title = TIP_("Hex");
885 const StringRefNull rgb_title = (is_gamma) ? TIP_("sRGB") : TIP_("Display RGB");
886 const StringRefNull hsv_title = TIP_("HSV");
887 const StringRefNull alpha_title = TIP_("Alpha");
888 const int max_title_len = std::max(
889 {hex_title.size(), rgb_title.size(), hsv_title.size(), alpha_title.size()});
890
891 const std::string hex_st = tooltip_color_string(
892 srgb_color, hex_title, max_title_len, has_alpha, true);
893 const std::string rgba_st = tooltip_color_string(display_color, rgb_title, max_title_len, false);
894 const std::string hsv_st = tooltip_color_string(hsv, hsv_title, max_title_len, false);
895 const std::string alpha_st = tooltip_color_string(
896 scene_linear_color, alpha_title, max_title_len, true);
897
898 const uiFontStyle *fs = &style_get()->tooltip;
900 float w = BLF_width(blf_mono_font, hsv_st.c_str(), hsv_st.size());
901
902 /* TODO: This clips wide gamut. Should make a float buffer and draw for display. */
903 TooltipImage image_data;
904 image_data.width = int(w);
905 image_data.height = int(w / (has_alpha ? 4.0f : 3.0f));
906 image_data.ibuf = IMB_allocImBuf(image_data.width, image_data.height, ImBufFlags::ByteData);
907 image_data.border = true;
908 image_data.premultiplied = false;
909
910 if (scene_linear_color[3] == 1.0f) {
911 /* No transparency so draw the entire area solid without checkerboard. */
914 image_data.ibuf, scene_linear_color, 1, 1, image_data.width, image_data.height);
915 }
916 else {
918 /* Draw one half with transparency. */
919 IMB_rectfill_area(image_data.ibuf,
920 scene_linear_color,
921 image_data.width / 2,
922 1,
923 image_data.width,
924 image_data.height);
925 /* Draw the other half with a solid color. */
926 scene_linear_color[3] = 1.0f;
928 image_data.ibuf, scene_linear_color, 1, 1, image_data.width / 2, image_data.height);
929 }
930
931 tooltip_text_field_add(data, {}, {}, TIP_STYLE_SPACER, color_id, false);
932 tooltip_text_field_add(data, {}, {}, TIP_STYLE_SPACER, color_id, false);
933 tooltip_image_field_add(data, image_data);
934 tooltip_text_field_add(data, {}, {}, TIP_STYLE_SPACER, color_id, false);
935 tooltip_text_field_add(data, rgba_st, {}, TIP_STYLE_MONO, color_id, false);
936 tooltip_text_field_add(data, hsv_st, {}, TIP_STYLE_MONO, color_id, false);
937 if (has_alpha) {
938 tooltip_text_field_add(data, alpha_st, {}, TIP_STYLE_MONO, color_id, false);
939 }
940 tooltip_text_field_add(data, hex_st, {}, TIP_STYLE_MONO, color_id, false);
941
942 /* Tooltip now owns a copy of the ImBuf, so we can delete ours. */
943 IMB_freeImBuf(image_data.ibuf);
944}
945
947 bContext &C,
948 Button &but,
949 ButtonExtraOpIcon *extra_icon)
950{
951 wmOperatorType *optype = extra_icon ? button_extra_operator_icon_optype_get(extra_icon) :
952 but.optype;
953 PropertyRNA *rnaprop = extra_icon ? nullptr : but.rnaprop;
954 std::string rna_struct = button_string_get_rna_struct_identifier(but);
955 std::string rna_prop = button_string_get_rna_property_identifier(but);
956
957 if (optype && !rnaprop) {
958 PointerRNA *opptr = extra_icon ? button_extra_operator_icon_opptr_get(extra_icon) :
959 /* Allocated when needed, the button owns it. */
961
962 /* So the context is passed to field functions (some Python field functions use it). */
964
965 std::string str = tooltip_text_python_from_op(&C, optype, opptr);
966
967 /* Operator info. */
969 fmt::format(fmt::runtime(TIP_("Python: {}")), str),
970 {},
973 true);
974 }
975
976 if (!optype && !rna_struct.empty()) {
977 {
979 data,
980 rna_prop.empty() ?
981 fmt::format(fmt::runtime(TIP_("Python: {}")), rna_struct) :
982 fmt::format(fmt::runtime(TIP_("Python: {}.{}")), rna_struct, rna_prop),
983 {},
986 (data.fields.size() > 0));
987 }
988
989 if (but.rnapoin.owner_id) {
990 std::optional<std::string> str = rnaprop ? RNA_path_full_property_py_ex(
991 &but.rnapoin, rnaprop, but.rnaindex, true) :
994 }
995 }
996}
997
998static const char *icon_id_to_name(BIFIconID icon_value)
999{
1000 const char *identifier = nullptr;
1001 RNA_enum_identifier(rna_enum_icon_items, icon_value, &identifier);
1002 return identifier;
1003}
1004
1006{
1007 if (ELEM(but.icon, ICON_NONE, ICON_BLANK1)) {
1008 return;
1009 }
1010
1011 if ((but.flag & BUT_ICON_PREVIEW) != 0) {
1012 return;
1013 }
1014
1015 const char *icon_name = icon_id_to_name(but.icon);
1016 if (!icon_name) {
1017 return;
1018 }
1019
1021 fmt::format("Icon: {}", icon_name),
1022 {},
1025 !data.fields.is_empty());
1026}
1027
1028static std::unique_ptr<TooltipData> tooltip_data_from_button_or_extra_icon(
1029 bContext *C, Button *but, ButtonExtraOpIcon *extra_icon, const bool is_quick_tip)
1030{
1031 char buf[512];
1032
1033 wmOperatorType *optype = extra_icon ? button_extra_operator_icon_optype_get(extra_icon) :
1034 but->optype;
1035 PropertyRNA *rnaprop = extra_icon ? nullptr : but->rnaprop;
1036
1037 std::unique_ptr<TooltipData> data = std::make_unique<TooltipData>();
1038
1039 /* Menus already show shortcuts, don't show them in the tool-tips. */
1040 const bool is_menu = block_is_menu(but->block) && !block_is_pie_menu(but->block);
1041
1042 std::string but_label;
1043 std::string but_tip;
1044 std::string but_tip_label;
1045 std::string op_keymap;
1046 std::string prop_keymap;
1047 std::string rna_struct;
1048 std::string rna_prop;
1049 std::string enum_label;
1050 std::string enum_tip;
1051
1052 if (extra_icon) {
1053 if (is_quick_tip) {
1054 but_label = button_extra_icon_string_get_label(*extra_icon);
1055 }
1056 else {
1057 but_label = button_extra_icon_string_get_label(*extra_icon);
1058 but_tip = button_extra_icon_string_get_tooltip(*C, *extra_icon);
1059 if (!is_menu) {
1060 op_keymap = button_extra_icon_string_get_operator_keymap(*C, *extra_icon);
1061 }
1062 }
1063 }
1064 else {
1065 const std::optional<EnumPropertyItem> enum_item = button_rna_enum_item_get(*C, *but);
1066 if (is_quick_tip) {
1067 but_tip_label = button_string_get_tooltip_label(*but);
1068 but_label = button_string_get_label(*but);
1069 enum_label = enum_item ? enum_item->name : "";
1070 }
1071 else {
1072 but_label = button_string_get_label(*but);
1073 but_tip_label = button_string_get_tooltip_label(*but);
1074 but_tip = button_string_get_tooltip(*C, *but);
1075 enum_label = enum_item ? enum_item->name : "";
1076 const char *description_c = enum_item ? enum_item->description : nullptr;
1077 enum_tip = description_c ? description_c : "";
1078 if (!is_menu) {
1079 op_keymap = button_string_get_operator_keymap(*C, *but);
1080 prop_keymap = button_string_get_property_keymap(*C, *but);
1081 }
1082 rna_struct = button_string_get_rna_struct_identifier(*but);
1084 }
1085 }
1086
1087 /* Label: If there is a custom tooltip label, use that to override the label to display.
1088 * Otherwise fallback to the regular label. */
1089 if (!but_tip_label.empty()) {
1091 if (!is_quick_tip) {
1093 }
1094 }
1095 /* Regular (non-custom) label. Only show when the button doesn't already show the label. Check
1096 * prefix instead of comparing because the button may include the shortcut. Buttons with dynamic
1097 * tool-tips also don't get their default label here since they can already provide more accurate
1098 * and specific tool-tip content. */
1099 else if (!but_label.empty() && !StringRef(but->drawstr).startswith(but_label) && !but->tip_func)
1100 {
1101 if (!enum_label.empty()) {
1103 *data, fmt::format("{}: ", but_label), enum_label, TIP_STYLE_HEADER, TIP_LC_NORMAL);
1104 }
1105 else {
1107 }
1109 }
1110
1111 /* Tip */
1112 if (!but_tip.empty()) {
1113 if (!enum_label.empty() && enum_label == but_label) {
1115 *data, fmt::format("{}: ", but_tip), enum_label, TIP_STYLE_HEADER, TIP_LC_NORMAL);
1117 }
1118 else {
1119 but_tip = tooltip_with_period(but_tip);
1121 if (but_label.empty()) {
1123 }
1124 }
1125
1126 /* special case enum rna buttons */
1127 if ((but->type == ButtonType::Row) && rnaprop && RNA_property_flag(rnaprop) & PROP_ENUM_FLAG) {
1129 TIP_("(Shift-Click/Drag to select multiple)"),
1130 {},
1133 }
1134 }
1135 /* When there is only an enum label (no button label or tip), draw that as header. */
1136 else if (!enum_label.empty() && but_label.empty()) {
1137 tooltip_text_field_add(*data, std::move(enum_label), {}, TIP_STYLE_HEADER, TIP_LC_MAIN);
1138 }
1139
1140 /* Don't include further details if this is just a quick label tooltip. */
1141 if (is_quick_tip) {
1142 return data->fields.is_empty() ? nullptr : std::move(data);
1143 }
1144
1145 /* Enum field label & tip. */
1146 if (!enum_tip.empty()) {
1147 enum_tip = tooltip_with_period(enum_tip);
1149 std::move(enum_tip),
1150 {},
1153 !enum_label.empty() && but_label.empty());
1154 }
1155
1156 /* Operator shortcut. */
1157 if (!op_keymap.empty()) {
1159 fmt::format(fmt::runtime(TIP_("Shortcut: {}")), op_keymap),
1160 {},
1163 !data->fields.is_empty());
1164 }
1165
1166 /* Property context-toggle shortcut. */
1167 if (!prop_keymap.empty()) {
1169 fmt::format(fmt::runtime(TIP_("Shortcut: {}")), prop_keymap),
1170 {},
1173 true);
1174 }
1175
1177 /* Better not show the value of a password. */
1178 if ((rnaprop && (RNA_property_subtype(rnaprop) == PROP_PASSWORD)) == 0) {
1179 /* Full string. */
1180 button_string_get(but, buf, sizeof(buf));
1181 if (buf[0]) {
1183 fmt::format(fmt::runtime(TIP_("Value: {}")), buf),
1184 {},
1187 true);
1188 }
1189 }
1190 }
1191
1192 /* Show template-evaluated path for filepaths with path templates. */
1193 if (but->type == ButtonType::Text && rnaprop &&
1195 {
1196 char filepath[FILE_MAX];
1197
1198 RNA_property_string_get(&but->rnapoin, rnaprop, filepath);
1199
1200 if (BKE_path_contains_template_syntax(filepath)) {
1201 const std::optional<blender::bke::path_templates::VariableMap> variables =
1203 BLI_assert(variables.has_value());
1204
1206 filepath, sizeof(filepath), *variables);
1207
1208 if (errors.is_empty()) {
1210 *data, std::string(filepath), {}, TIP_STYLE_NORMAL, TIP_LC_DIMMED, true);
1211 }
1212 }
1213 }
1214
1215 if (rnaprop) {
1216 const int unit_type = button_unit_type_get(but);
1217
1218 if (unit_type == PROP_UNIT_ROTATION) {
1219 if (RNA_property_type(rnaprop) == PROP_FLOAT) {
1220 float value = RNA_property_array_check(rnaprop) ?
1221 RNA_property_float_get_index(&but->rnapoin, rnaprop, but->rnaindex) :
1222 RNA_property_float_get(&but->rnapoin, rnaprop);
1224 fmt::format(fmt::runtime(TIP_("Radians: {}")), value),
1225 {},
1228 true);
1229 }
1230 }
1231
1232 if (but->flag & BUT_DRIVEN) {
1233 if (button_anim_expression_get(but, buf, sizeof(buf))) {
1235 fmt::format(fmt::runtime(TIP_("Expression: {}")), buf),
1236 {},
1239 true);
1240 }
1241 }
1242
1243 if (but->rnapoin.owner_id) {
1244 const ID *id = but->rnapoin.owner_id;
1245 if (ID_IS_LINKED(id)) {
1247 const bool is_builtin = BLI_path_contains(assets_path.c_str(), id->lib->filepath);
1248 const StringRef title = is_builtin ? TIP_("Built-in Asset") : TIP_("Library");
1249 const StringRef lib_path = id->lib->filepath;
1250 const StringRef path = is_builtin ? lib_path.substr(assets_path.size()) :
1251 id->lib->filepath;
1253 *data, fmt::format("{}: {}", title, path), {}, TIP_STYLE_NORMAL, TIP_LC_VALUE, true);
1254 }
1255 }
1256 }
1257
1258 /* Warn on path validity errors. */
1259 if (ELEM(but->type, ButtonType::Text) &&
1260 /* Check red-alert, if the flag is not set, then this was suppressed. */
1261 (but->flag & BUT_REDALERT))
1262 {
1263 if (rnaprop) {
1264 PropertySubType subtype = RNA_property_subtype(rnaprop);
1265
1266 /* If relative paths are used when unsupported (will already display red-alert). */
1267 if (ELEM(subtype, PROP_FILEPATH, PROP_DIRPATH)) {
1269 if (BLI_path_is_rel(but->drawstr.c_str())) {
1271 TIP_("Warning: the blend-file relative path prefix \"//\" "
1272 "is not supported for this property."),
1273 {},
1276 true);
1277 }
1278 }
1279 }
1280
1281 /* We include PROP_NONE here because some plain string properties are used
1282 * as parts of paths. For example, the sub-paths in the compositor's File
1283 * Output node. */
1285 /* Template parse errors, for paths that support it. */
1286 if ((RNA_property_flag(rnaprop) & PROP_PATH_SUPPORTS_TEMPLATES) != 0) {
1287 const std::string path = RNA_property_string_get(&but->rnapoin, rnaprop);
1289 const std::optional<bke::path_templates::VariableMap> variables =
1291 BLI_assert(variables.has_value());
1292
1294 path, *variables);
1295
1296 if (!errors.is_empty()) {
1297 std::string error_message("Path template error(s):");
1298 for (const bke::path_templates::Error &error : errors) {
1299 error_message += "\n - " + BKE_path_template_error_to_string(error, path);
1300 }
1302 *data, error_message, {}, TIP_STYLE_NORMAL, TIP_LC_ALERT, true);
1303 }
1304 }
1305 }
1306 }
1307 }
1308 }
1309
1310 /* Button is disabled, we may be able to tell user why. */
1311 if ((but->flag & BUT_DISABLED) || extra_icon) {
1312 const char *disabled_msg_orig = nullptr;
1313 const char *disabled_msg = nullptr;
1314 bool disabled_msg_free = false;
1315
1316 /* If operator poll check failed, it can give pretty precise info why. */
1317 if (optype) {
1318 const wm::OpCallContext opcontext = extra_icon ? extra_icon->optype_params->opcontext :
1319 but->opcontext;
1320 wmOperatorCallParams call_params{};
1321 call_params.optype = optype;
1322 call_params.opcontext = opcontext;
1324 button_context_poll_operator_ex(C, but, &call_params);
1325 disabled_msg_orig = CTX_wm_operator_poll_msg_get(C, &disabled_msg_free);
1326 disabled_msg = TIP_(disabled_msg_orig);
1327 }
1328 /* Alternatively, buttons can store some reasoning too. */
1329 else if (!extra_icon && but->disabled_info) {
1330 disabled_msg = TIP_(but->disabled_info);
1331 }
1332
1333 if (disabled_msg && disabled_msg[0]) {
1334 const std::string disabled_tip = tooltip_with_period(disabled_msg);
1335 tooltip_text_field_add(*data, disabled_tip, {}, TIP_STYLE_NORMAL, TIP_LC_ALERT, true);
1336 }
1337 if (disabled_msg_free) {
1338 MEM_delete(disabled_msg_orig);
1339 }
1340 }
1341
1342 if (but->type == ButtonType::Color) {
1343 const ColorManagedDisplay *display = button_cm_display_get(*but);
1344
1345 float color[4];
1346 button_v3_get(but, color);
1347 color[3] = 1.0f;
1348 bool has_alpha = false;
1349
1350 if (but->rnaprop) {
1351 BLI_assert(but->rnaindex == -1);
1352 has_alpha = RNA_property_array_length(&but->rnapoin, but->rnaprop) >= 4;
1353 if (has_alpha) {
1355 }
1356 }
1357
1359 *data, color, has_alpha, button_is_color_gamma(but), display, TIP_LC_VALUE);
1360 }
1361
1362 if (U.flag & USER_DEVELOPER_UI) {
1364 }
1365
1366 if (U.flag & USER_TOOLTIPS_PYTHON) {
1367 tooltip_uibut_python_add(*data, *C, *but, extra_icon);
1368 }
1369
1370 /* If the last field is a spacer, remove it. */
1371 while (!data->fields.is_empty() && data->fields.last().format.style == TIP_STYLE_SPACER) {
1372 data->fields.pop_last();
1373 }
1374
1375 return data->fields.is_empty() ? nullptr : std::move(data);
1376}
1377
1378static std::unique_ptr<TooltipData> tooltip_data_from_gizmo(bContext *C, wmGizmo *gz)
1379{
1380 std::unique_ptr<TooltipData> data = std::make_unique<TooltipData>();
1381
1382 /* TODO(@ideasman42): a way for gizmos to have their own descriptions (low priority). */
1383
1384 /* Operator Actions */
1385 {
1386 const bool use_drag = gz->drag_part != -1 && gz->highlight_part != gz->drag_part;
1387 struct GizmoOpActions {
1388 int part;
1389 const char *prefix;
1390 };
1391 GizmoOpActions gzop_actions[] = {
1392 {
1393 gz->highlight_part,
1394 use_drag ? CTX_TIP_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Click") : nullptr,
1395 },
1396 {
1397 use_drag ? gz->drag_part : -1,
1398 use_drag ? CTX_TIP_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Drag") : nullptr,
1399 },
1400 };
1401
1402 for (int i = 0; i < ARRAY_SIZE(gzop_actions); i++) {
1403 wmGizmoOpElem *gzop = (gzop_actions[i].part != -1) ?
1404 WM_gizmo_operator_get(gz, gzop_actions[i].part) :
1405 nullptr;
1406 if (gzop != nullptr) {
1407 /* Description */
1408 std::string info = WM_operatortype_description_or_name(C, gzop->type, &gzop->ptr);
1409
1410 if (!info.empty()) {
1412 *data,
1413 gzop_actions[i].prefix ? fmt::format("{}: {}", gzop_actions[i].prefix, info) : info,
1414 {},
1417 false);
1418 }
1419
1420 /* Shortcut */
1421 {
1422 IDProperty *prop = static_cast<IDProperty *>(gzop->ptr.data);
1423 std::optional<std::string> shortcut_str = WM_key_event_operator_string(
1424 C, gzop->type->idname, wm::OpCallContext::InvokeDefault, prop, true);
1425 if (shortcut_str) {
1427 fmt::format(fmt::runtime(TIP_("Shortcut: {}")), *shortcut_str),
1428 {},
1431 true);
1432 }
1433 }
1434 }
1435 }
1436 }
1437
1438 /* Property Actions */
1439 for (const wmGizmoProperty &gz_prop : gz->target_properties) {
1440 if (gz_prop.prop != nullptr) {
1441 const char *info = RNA_property_ui_description(gz_prop.prop);
1442 if (info && info[0]) {
1444 }
1445 }
1446 }
1447
1448 return data->fields.is_empty() ? nullptr : std::move(data);
1449}
1450
1451static std::unique_ptr<TooltipData> tooltip_data_from_custom_func(bContext *C, Button *but)
1452{
1453 /* Create tooltip data. */
1454 std::unique_ptr<TooltipData> data = std::make_unique<TooltipData>();
1455
1456 /* Create fields from custom callback. */
1457 but->tip_custom_func(*C, *data, but, but->tip_arg);
1458
1459 return data->fields.is_empty() ? nullptr : std::move(data);
1460}
1461
1463 std::unique_ptr<TooltipData> data_uptr,
1464 const float init_position[2],
1465 const rcti *init_rect_overlap)
1466{
1467 wmWindow *win = CTX_wm_window(C);
1468 const int2 win_size = WM_window_native_pixel_size(win);
1469 rcti rect_i;
1470 FontFlags font_flag = BLF_NONE;
1471
1472 /* Create area region. */
1474
1475 static ARegionType type;
1476 memset(&type, 0, sizeof(ARegionType));
1480 region->runtime->type = &type;
1481 /* Move ownership to region data. The region type free callback puts it back into a unique
1482 * pointer for save freeing. */
1483 region->regiondata = data_uptr.release();
1484
1485 TooltipData *data = static_cast<TooltipData *>(region->regiondata);
1486
1487 /* Set font, get bounding-box. */
1488 const uiStyle *style = style_get();
1489 data->fstyle = style->tooltip; /* copy struct */
1490 BLF_size(data->fstyle.uifont_id, data->fstyle.points * UI_SCALE_FAC);
1491 int h = BLF_height_max(data->fstyle.uifont_id);
1492 const float pad_x = h * TIP_PADDING_X;
1493 const float pad_y = h * TIP_PADDING_Y;
1494
1495 fontstyle_set(&data->fstyle);
1496
1497 data->wrap_width = min_ii(TIP_MAXWIDTH * UI_SCALE_FAC, win_size[0] - pad_x);
1498
1499 font_flag |= BLF_WORD_WRAP;
1500 BLF_enable(data->fstyle.uifont_id, font_flag);
1501 BLF_enable(blf_mono_font, font_flag);
1502 BLF_wordwrap(data->fstyle.uifont_id,
1503 data->wrap_width,
1506
1507 int i, fonth, fontw;
1508 for (i = 0, fontw = 0, fonth = 0; i < data->fields.size(); i++) {
1509 TooltipField *field = &data->fields[i];
1510 ResultBLF info = {0};
1511 int w = 0;
1512 int x_pos = 0;
1513 int font_id;
1514
1515 if (field->format.style == TIP_STYLE_MONO) {
1516 BLF_size(blf_mono_font, data->fstyle.points * UI_SCALE_FAC);
1517 font_id = blf_mono_font;
1518 }
1519 else {
1520 font_id = data->fstyle.uifont_id;
1521 }
1522
1523 if (!field->text.empty()) {
1524 w = BLF_width(font_id, field->text.c_str(), field->text.size(), &info);
1525 }
1526
1527 /* check for suffix (enum label) */
1528 if (!field->text_suffix.empty()) {
1529 x_pos = info.width;
1530 w = max_ii(w,
1531 x_pos + BLF_width(font_id, ": ", BLF_DRAW_STR_DUMMY_MAX) +
1532 BLF_width(font_id, field->text_suffix.c_str(), BLF_DRAW_STR_DUMMY_MAX));
1533 }
1534
1535 fonth += h * info.lines;
1536
1537 if (field->format.style == TIP_STYLE_SPACER) {
1538 fonth += h * TIP_SPACER;
1539 }
1540
1541 if (field->format.style == TIP_STYLE_IMAGE && field->image) {
1542 fonth += field->image->height;
1543 w = max_ii(w, field->image->width);
1544 }
1545
1546 fontw = max_ii(fontw, w);
1547
1548 field->geom.lines = info.lines;
1549 field->geom.x_pos = x_pos;
1550 }
1551
1552 BLF_disable(data->fstyle.uifont_id, font_flag);
1553 BLF_disable(blf_mono_font, font_flag);
1554
1555 data->toth = fonth;
1556 data->lineh = h;
1557
1558 /* Compute position. */
1559 {
1560 rctf rect_fl;
1561 rect_fl.xmin = init_position[0] - (h * 0.2f) - (pad_x * 0.5f);
1562 rect_fl.xmax = rect_fl.xmin + fontw;
1563 rect_fl.ymax = init_position[1] - (h * 0.2f) - (pad_y * 0.5f);
1564 rect_fl.ymin = rect_fl.ymax - fonth;
1565 BLI_rcti_rctf_copy(&rect_i, &rect_fl);
1566 }
1567
1568 // #define USE_ALIGN_Y_CENTER
1569
1570 /* Clamp to window bounds. */
1571 {
1572 /* Ensure at least 5 pixels above screen bounds.
1573 * #UI_UNIT_Y is just a guess to be above the menu item. */
1574 if (init_rect_overlap != nullptr) {
1575 const int pad = max_ff(1.0f, U.pixelsize) * 5;
1576 rcti init_rect;
1577 init_rect.xmin = init_rect_overlap->xmin - pad;
1578 init_rect.xmax = init_rect_overlap->xmax + pad;
1579 init_rect.ymin = init_rect_overlap->ymin - pad;
1580 init_rect.ymax = init_rect_overlap->ymax + pad;
1581 rcti rect_clamp;
1582 rect_clamp.xmin = pad_x + pad;
1583 rect_clamp.xmax = win_size[0] - pad_x - pad;
1584 rect_clamp.ymin = pad_y + pad;
1585 rect_clamp.ymax = win_size[1] - pad_y - pad;
1586 /* try right. */
1587 const int size_x = BLI_rcti_size_x(&rect_i);
1588 const int size_y = BLI_rcti_size_y(&rect_i);
1589 const int cent_overlap_x = BLI_rcti_cent_x(&init_rect);
1590#ifdef USE_ALIGN_Y_CENTER
1591 const int cent_overlap_y = BLI_rcti_cent_y(&init_rect);
1592#endif
1593 struct {
1594 rcti xpos;
1595 rcti xneg;
1596 rcti ypos;
1597 rcti yneg;
1598 } rect;
1599
1600 { /* xpos */
1601 rcti r = rect_i;
1602 r.xmin = init_rect.xmax;
1603 r.xmax = r.xmin + size_x;
1604#ifdef USE_ALIGN_Y_CENTER
1605 r.ymin = cent_overlap_y - (size_y / 2);
1606 r.ymax = r.ymin + size_y;
1607#else
1608 r.ymin = init_rect.ymax - BLI_rcti_size_y(&rect_i);
1609 r.ymax = init_rect.ymax;
1610 r.ymin -= UI_POPUP_MARGIN;
1611 r.ymax -= UI_POPUP_MARGIN;
1612#endif
1613 rect.xpos = r;
1614 }
1615 { /* xneg */
1616 rcti r = rect_i;
1617 r.xmin = init_rect.xmin - size_x;
1618 r.xmax = r.xmin + size_x;
1619#ifdef USE_ALIGN_Y_CENTER
1620 r.ymin = cent_overlap_y - (size_y / 2);
1621 r.ymax = r.ymin + size_y;
1622#else
1623 r.ymin = init_rect.ymax - BLI_rcti_size_y(&rect_i);
1624 r.ymax = init_rect.ymax;
1625 r.ymin -= UI_POPUP_MARGIN;
1626 r.ymax -= UI_POPUP_MARGIN;
1627#endif
1628 rect.xneg = r;
1629 }
1630 { /* ypos */
1631 rcti r = rect_i;
1632 r.xmin = cent_overlap_x - (size_x / 2);
1633 r.xmax = r.xmin + size_x;
1634 r.ymin = init_rect.ymax;
1635 r.ymax = r.ymin + size_y;
1636 rect.ypos = r;
1637 }
1638 { /* yneg */
1639 rcti r = rect_i;
1640 r.xmin = cent_overlap_x - (size_x / 2);
1641 r.xmax = r.xmin + size_x;
1642 r.ymin = init_rect.ymin - size_y;
1643 r.ymax = r.ymin + size_y;
1644 rect.yneg = r;
1645 }
1646
1647 bool found = false;
1648 for (int j = 0; j < 4; j++) {
1649 const rcti *r = (&rect.xpos) + j;
1650 if (BLI_rcti_inside_rcti(&rect_clamp, r)) {
1651 rect_i = *r;
1652 found = true;
1653 break;
1654 }
1655 }
1656 if (!found) {
1657 /* Fallback, we could pick the best fallback, for now just use xpos. */
1658 int offset_dummy[2];
1659 rect_i = rect.xpos;
1660 BLI_rcti_clamp(&rect_i, &rect_clamp, offset_dummy);
1661 }
1662 }
1663 else {
1664 const int clamp_pad_x = int((5.0f * UI_SCALE_FAC) + (pad_x * 0.5f));
1665 const int clamp_pad_y = int((7.0f * UI_SCALE_FAC) + (pad_y * 0.5f));
1666 rcti rect_clamp;
1667 rect_clamp.xmin = clamp_pad_x;
1668 rect_clamp.xmax = win_size[0] - clamp_pad_x;
1669 rect_clamp.ymin = clamp_pad_y;
1670 rect_clamp.ymax = win_size[1] - clamp_pad_y;
1671 int offset_dummy[2];
1672 BLI_rcti_clamp(&rect_i, &rect_clamp, offset_dummy);
1673 }
1674 }
1675
1676#undef USE_ALIGN_Y_CENTER
1677
1678 if (BLI_rcti_isect_pt(&rect_i, init_position[0], init_position[1]) &&
1679 rect_i.ymin < (win_size[1] / 4))
1680 {
1681 /* Near bottom and overlapping mouse and highlighted item. */
1682 BLI_rcti_translate(&rect_i, 0, h * 3);
1683 }
1684 else if (init_position[1] < UI_UNIT_Y) {
1685 /* At the very bottom. */
1686 BLI_rcti_translate(&rect_i, 0, UI_UNIT_Y - init_position[1]);
1687 }
1688
1689 /* add padding */
1690 BLI_rcti_pad(&rect_i, int(round(pad_x * 0.5f)), int(round(pad_y * 0.5f)));
1691
1692 /* widget rect, in region coords */
1693 {
1694 /* Compensate for margin offset, visually this corrects the position. */
1695 const int margin = UI_POPUP_MARGIN;
1696 if (init_rect_overlap != nullptr) {
1697 BLI_rcti_translate(&rect_i, margin, margin / 2);
1698 }
1699
1700 data->bbox.xmin = margin;
1701 data->bbox.xmax = BLI_rcti_size_x(&rect_i) + margin;
1702 data->bbox.ymin = margin;
1703 data->bbox.ymax = BLI_rcti_size_y(&rect_i) + margin;
1704
1705 /* region bigger for shadow */
1706 region->winrct.xmin = rect_i.xmin - margin;
1707 region->winrct.xmax = rect_i.xmax + margin;
1708 region->winrct.ymin = rect_i.ymin - margin;
1709 region->winrct.ymax = rect_i.ymax + margin;
1710 }
1711
1712 /* Adds sub-window. */
1714
1715 /* notify change and redraw */
1716 ED_region_tag_redraw(region);
1717
1718 return region;
1719}
1720
1722
1723/* -------------------------------------------------------------------- */
1726
1728 bContext *C, ARegion *butregion, Button *but, ButtonExtraOpIcon *extra_icon, bool is_quick_tip)
1729{
1730 wmWindow *win = CTX_wm_window(C);
1731 float init_position[2];
1732
1733 if (but->drawflag & BUT_NO_TOOLTIP) {
1734 return nullptr;
1735 }
1736 std::unique_ptr<TooltipData> data = nullptr;
1737
1738 if (!is_quick_tip && but->tip_custom_func) {
1740 }
1741
1742 if (data == nullptr) {
1743 data = tooltip_data_from_tool(C, but, is_quick_tip);
1744 }
1745
1746 if (data == nullptr) {
1747 data = tooltip_data_from_button_or_extra_icon(C, but, extra_icon, is_quick_tip);
1748 }
1749
1750 if (data == nullptr) {
1751 data = tooltip_data_from_button_or_extra_icon(C, but, nullptr, is_quick_tip);
1752 }
1753
1754 if (data == nullptr) {
1755 return nullptr;
1756 }
1757
1758 const bool is_no_overlap = but_has_quick_tooltip(but) || but_is_tool(but);
1759 rcti init_rect;
1760 if (is_no_overlap) {
1761 rctf overlap_rect_fl;
1762 init_position[0] = BLI_rctf_cent_x(&but->rect);
1763 init_position[1] = BLI_rctf_cent_y(&but->rect);
1764 if (butregion) {
1765 block_to_window_fl(butregion, but->block, &init_position[0], &init_position[1]);
1766 block_to_window_rctf(butregion, but->block, &overlap_rect_fl, &but->rect);
1767 }
1768 else {
1769 overlap_rect_fl = but->rect;
1770 }
1771 BLI_rcti_rctf_copy_round(&init_rect, &overlap_rect_fl);
1772 }
1773 else if (but->type == ButtonType::Label && BLI_rctf_size_y(&but->rect) > UI_UNIT_Y) {
1774 init_position[0] = win->runtime->eventstate->xy[0];
1775 init_position[1] = win->runtime->eventstate->xy[1] - (UI_POPUP_MARGIN / 2);
1776 }
1777 else {
1778 init_position[0] = BLI_rctf_cent_x(&but->rect);
1779 init_position[1] = but->rect.ymin;
1780 if (butregion) {
1781 block_to_window_fl(butregion, but->block, &init_position[0], &init_position[1]);
1782 init_position[0] = win->runtime->eventstate->xy[0];
1783 }
1784 init_position[1] -= (UI_POPUP_MARGIN / 2);
1785 }
1786
1788 C, std::move(data), init_position, is_no_overlap ? &init_rect : nullptr);
1789
1790 return region;
1791}
1792
1794 ARegion *butregion,
1795 Button *but,
1796 bool is_quick_tip)
1797{
1798 return tooltip_create_from_button_or_extra_icon(C, butregion, but, nullptr, is_quick_tip);
1799}
1800
1802{
1803 wmWindow *win = CTX_wm_window(C);
1804 float init_position[2] = {float(win->runtime->eventstate->xy[0]),
1805 float(win->runtime->eventstate->xy[1])};
1806
1807 std::unique_ptr<TooltipData> data = tooltip_data_from_gizmo(C, gz);
1808 if (data == nullptr) {
1809 return nullptr;
1810 }
1811
1812 /* TODO(@harley): Julian preferred that the gizmo callback return the 3D bounding box
1813 * which we then project to 2D here. Would make a nice improvement. */
1814 if (gz->type->screen_bounds_get) {
1815 rcti bounds;
1816 if (gz->type->screen_bounds_get(C, gz, &bounds)) {
1817 init_position[0] = bounds.xmin;
1818 init_position[1] = bounds.ymin;
1819 }
1820 }
1821
1822 return tooltip_create_with_data(C, std::move(data), init_position, nullptr);
1823}
1824
1826 const FunctionRef<void(TooltipData &data)> create_fn,
1827 const float init_position[2])
1828{
1829 std::unique_ptr<TooltipData> data = std::make_unique<TooltipData>();
1830 create_fn(*data);
1831 if (data->fields.is_empty()) {
1832 return nullptr;
1833 }
1834 return tooltip_create_with_data(C, std::move(data), init_position, nullptr);
1835}
1836
1838{
1839 if (ima.filepath[0]) {
1840 char root[FILE_MAX];
1841 BLI_path_split_dir_part(ima.filepath, root, FILE_MAX);
1843 }
1844
1845 std::string image_type;
1846 switch (ima.source) {
1847 case IMA_SRC_FILE:
1848 image_type = TIP_("Single Image");
1849 break;
1850 case IMA_SRC_SEQUENCE:
1851 image_type = TIP_("Image Sequence");
1852 break;
1853 case IMA_SRC_MOVIE:
1854 image_type = TIP_("Movie");
1855 break;
1856 case IMA_SRC_GENERATED:
1857 image_type = TIP_("Generated");
1858 break;
1859 case IMA_SRC_VIEWER:
1860 image_type = TIP_("Viewer");
1861 break;
1862 case IMA_SRC_TILED:
1863 image_type = TIP_("UDIM Tiles");
1864 break;
1865 }
1867
1868 short w;
1869 short h;
1870 ImBuf *ibuf = BKE_image_preview(&ima, 200.0f * UI_SCALE_FAC, &w, &h);
1871
1872 if (ibuf) {
1874 data, fmt::format("{} \u00D7 {}", w, h), {}, TIP_STYLE_NORMAL, TIP_LC_VALUE);
1875 }
1876
1877 if (BKE_image_has_anim(&ima)) {
1878 MovieReader *anim = ima.anims.first()->anim;
1879 if (anim) {
1880 int duration = MOV_get_duration_frames(anim);
1882 fmt::format(fmt::runtime(TIP_("Frames: {}")), duration),
1883 {},
1885 TIP_LC_VALUE);
1886 }
1887 }
1888
1889 tooltip_text_field_add(data, ima.colorspace_settings.name, {}, TIP_STYLE_NORMAL, TIP_LC_VALUE);
1890
1892 fmt::format(fmt::runtime(TIP_("Users: {}")), ima.id.us),
1893 {},
1895 TIP_LC_VALUE);
1896
1897 if (ibuf) {
1898 TooltipImage image_data;
1899 image_data.width = ibuf->x;
1900 image_data.height = ibuf->y;
1901 image_data.ibuf = ibuf;
1902 image_data.border = true;
1904 image_data.premultiplied = true;
1907 tooltip_image_field_add(data, image_data);
1908 IMB_freeImBuf(ibuf);
1909 }
1910}
1911
1913{
1914 if (clip.filepath[0]) {
1915 char root[FILE_MAX];
1918 }
1919
1920 std::string image_type;
1921 switch (clip.source) {
1922 case MCLIP_SRC_SEQUENCE:
1923 image_type = TIP_("Image Sequence");
1924 break;
1925 case MCLIP_SRC_MOVIE:
1926 image_type = TIP_("Movie");
1927 break;
1928 }
1930
1931 if (clip.anim) {
1932 MovieReader *anim = clip.anim;
1933
1935 data,
1936 fmt::format("{} \u00D7 {}", MOV_get_image_width(anim), MOV_get_image_height(anim)),
1937 {},
1939 TIP_LC_VALUE);
1940
1942 data,
1943 fmt::format(fmt::runtime(TIP_("Frames: {}")), MOV_get_duration_frames(anim)),
1944 {},
1946 TIP_LC_VALUE);
1947
1948 ImBuf *ibuf = MOV_decode_preview_frame(anim);
1949
1950 if (ibuf) {
1951 /* Resize. */
1952 float scale = (200.0f * UI_SCALE_FAC) / float(std::max(ibuf->x, ibuf->y));
1953 IMB_scale(ibuf, scale * ibuf->x, scale * ibuf->y, IMBScaleFilter::Box, false);
1954 IMB_byte_from_float(ibuf);
1955
1956 TooltipImage image_data;
1957 image_data.width = ibuf->x;
1958 image_data.height = ibuf->y;
1959 image_data.ibuf = ibuf;
1960 image_data.border = true;
1962 image_data.premultiplied = true;
1965 tooltip_image_field_add(data, image_data);
1966 IMB_freeImBuf(ibuf);
1967 }
1968 }
1969}
1970
1971static void tooltip_from_vfont(const VFont &font, TooltipData &data)
1972{
1973 if (BKE_vfont_is_builtin(&font)) {
1974 /* In memory font previews are currently not supported,
1975 * don't attempt to handle as a file. */
1976 return;
1977 }
1978 if (!font.filepath[0]) {
1979 /* These may be packed files, currently not supported. */
1980 return;
1981 }
1982
1983 char filepath_abs[FILE_MAX];
1984 STRNCPY(filepath_abs, font.filepath);
1985 BLI_path_abs(filepath_abs, ID_BLEND_PATH_FROM_GLOBAL(&font.id));
1986
1987 if (!BLI_exists(filepath_abs)) {
1989 return;
1990 }
1991
1992 float color[4];
1995 ImBuf *ibuf = IMB_font_preview(filepath_abs, 256 * UI_SCALE_FAC, color, "ABCDabefg&0123");
1996 if (ibuf) {
1997 TooltipImage image_data;
1998 image_data.width = ibuf->x;
1999 image_data.height = ibuf->y;
2000 image_data.ibuf = ibuf;
2001 image_data.border = false;
2003 image_data.premultiplied = false;
2004 image_data.text_color = true;
2005 tooltip_image_field_add(data, image_data);
2006 IMB_freeImBuf(ibuf);
2007 }
2008}
2009
2010static std::unique_ptr<TooltipData> tooltip_data_from_search_item_tooltip_data(ID *id)
2011{
2012 std::unique_ptr<TooltipData> data = std::make_unique<TooltipData>();
2013 const ID_Type type_id = GS(id->name);
2014
2016
2017 if (type_id == ID_IM) {
2018 tooltip_from_image(*reinterpret_cast<Image *>(id), *data);
2019 }
2020 else if (type_id == ID_MC) {
2021 tooltip_from_clip(*reinterpret_cast<MovieClip *>(id), *data);
2022 }
2023 else if (type_id == ID_VF) {
2024 tooltip_from_vfont(*reinterpret_cast<VFont *>(id), *data);
2025 }
2026 else {
2028 *data,
2029 fmt::format(fmt::runtime(TIP_("Choose {} data-block to be assigned to this user")),
2031 {},
2034 }
2035
2037 if (ID_IS_LINKED(id)) {
2039 fmt::format(fmt::runtime(TIP_("Source library: {}\n{}")),
2040 id->lib->id.name + 2,
2041 id->lib->filepath),
2042 {},
2044 TIP_LC_VALUE);
2045 }
2046
2047 return data->fields.is_empty() ? nullptr : std::move(data);
2048}
2049
2051 const ARegion *searchbox_region,
2052 const rcti *item_rect,
2053 ID *id)
2054{
2055 std::unique_ptr<TooltipData> data = tooltip_data_from_search_item_tooltip_data(id);
2056 if (data == nullptr) {
2057 return nullptr;
2058 }
2059
2060 const wmWindow *win = CTX_wm_window(C);
2061 float init_position[2];
2062 init_position[0] = win->runtime->eventstate->xy[0];
2063 init_position[1] = item_rect->ymin + searchbox_region->winrct.ymin - (UI_POPUP_MARGIN / 2);
2064
2065 return tooltip_create_with_data(C, std::move(data), init_position, nullptr);
2066}
2067
2068void tooltip_free(bContext *C, bScreen *screen, ARegion *region)
2069{
2070 region_temp_remove(C, screen, region);
2071}
2072
2074
2075} // namespace blender::ui
Functions and classes for evaluating template expressions in filepaths.
#define BLF_DRAW_STR_DUMMY_MAX
Definition BLF_api.hh:456
File and directory operations.
#define FILE_MAX
#define SNPRINTF_UTF8(dst, format,...)
#define TIP_(msgid)
#define BLT_I18NCONTEXT_OPERATOR_DEFAULT
#define IFACE_(msgid)
#define CTX_TIP_(context, msgid)
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define ID_BLEND_PATH_FROM_GLOBAL(_id)
Definition DNA_ID.h:691
#define MAX_NAME
Definition DNA_defs.h:63
#define UI_SCALE_FAC
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UI_ALPHA_CHECKER_LIGHT
#define UI_UNIT_Y
#define UI_ALPHA_CHECKER_DARK
int pad[32 - sizeof(int)]
#define UNUSED_VARS(...)
#define ELEM(...)
#define STREQ(a, b)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
void draw(float x, float y, int img_w, int img_h, gpu::TextureFormat gpu_format, bool use_filter, const void *rect, float scale_x, float scale_y, const float color[4])
Definition glutil.cc:45
constexpr const char * c_str() const
constexpr bool startswith(StringRef prefix) const
static constexpr int64_t not_found
constexpr bool is_empty() const
constexpr int64_t size() const
constexpr int64_t find(char c, int64_t pos=0) const
constexpr StringRef substr(int64_t start, int64_t size) const
constexpr const char * data() const
#define str(s)
#define round
float3x3 scale(float3x3 mat, float2 scale)
#define UI_POPUP_MARGIN
#define TIP_SPACER
#define TIP_PADDING_X
#define TIP_PADDING_Y
#define TIP_MAXWIDTH
StringRefNull essentials_directory_path()
void get_color_4fv(int colorid, float col[4])
static void tooltip_region_free_cb(ARegion *region)
bool button_context_poll_operator_ex(bContext *C, const Button *but, const wmOperatorCallParams *optype_params)
static std::string tooltip_text_python_from_op(bContext *C, wmOperatorType *ot, PointerRNA *opptr)
void tooltip_color_field_add(TooltipData &data, const float4 &color, bool has_alpha, bool is_gamma, const ColorManagedDisplay *display, TooltipColorID color_id)
std::string button_extra_icon_string_get_tooltip(bContext &C, const ButtonExtraOpIcon &extra_icon)
std::string button_string_get_tooltip(bContext &C, Button &but)
int button_unit_type_get(const Button *but)
static std::unique_ptr< TooltipData > tooltip_data_from_custom_func(bContext *C, Button *but)
ARegion * tooltip_create_from_button_or_extra_icon(bContext *C, ARegion *butregion, Button *but, ButtonExtraOpIcon *extra_icon, bool is_quick_tip)
BLI_STATIC_ASSERT(int(TIP_LC_MAX)==int(TIP_LC_ALERT)+1, "invalid lc-max")
void draw_tooltip_background(const uiStyle *style, Block *block, const rcti *rect)
wmOperatorType * button_extra_operator_icon_optype_get(const ButtonExtraOpIcon *extra_icon)
void button_string_get(Button *but, char *str, const size_t str_maxncpy)
static ARegion * tooltip_create_with_data(bContext *C, std::unique_ptr< TooltipData > data_uptr, const float init_position[2], const rcti *init_rect_overlap)
static void tooltip_region_draw_cb(const bContext *, ARegion *region)
const uiStyle * style_get()
static void tooltip_from_clip(MovieClip &clip, TooltipData &data)
static std::unique_ptr< TooltipData > tooltip_data_from_search_item_tooltip_data(ID *id)
bool but_has_quick_tooltip(const Button *but)
std::string button_string_get_rna_property_identifier(const Button &but)
PointerRNA * button_operator_ptr_ensure(Button *but)
void region_temp_remove(bContext *C, bScreen *screen, ARegion *region)
void tooltip_free(bContext *C, bScreen *screen, ARegion *region)
void block_to_window_fl(const ARegion *region, const Block *block, float *x, float *y)
Definition interface.cc:144
void fontstyle_set(const uiFontStyle *fs)
std::optional< EnumPropertyItem > button_rna_enum_item_get(bContext &C, Button &but)
std::string button_string_get_tooltip_label(const Button &but)
const ColorManagedDisplay * button_cm_display_get(Button &but)
bool block_is_menu(const Block *block) ATTR_WARN_UNUSED_RESULT
static void color_blend_f3_f3(float dest[3], const float source[3], const float fac)
void tooltip_uibut_python_add(TooltipData &data, bContext &C, Button &but, ButtonExtraOpIcon *extra_icon)
void fontstyle_draw(const uiFontStyle *fs, const rcti *rect, const char *str, size_t str_len, const uchar col[4], const FontStyleDrawParams *fs_params)
ARegion * region_temp_add(bScreen *screen)
bool button_anim_expression_get(Button *but, char *str, size_t str_maxncpy)
static void tooltip_uibut_icon_add(TooltipData &data, Button &but)
static std::unique_ptr< TooltipData > tooltip_data_from_gizmo(bContext *C, wmGizmo *gz)
std::string button_string_get_label(Button &but)
void tooltip_image_field_add(TooltipData &data, const TooltipImage &image_data)
ARegion * tooltip_create_from_func(bContext *C, FunctionRef< void(TooltipData &data)> create_fn, const float init_position[2])
static std::unique_ptr< TooltipData > tooltip_data_from_tool(bContext *C, Button *but, bool is_quick_tip)
void button_v3_get(Button *but, float vec[3])
void block_to_window_rctf(const ARegion *region, const Block *block, rctf *rct_dst, const rctf *rct_src)
Definition interface.cc:172
std::string button_string_get_rna_struct_identifier(const Button &but)
std::string button_string_get_operator_keymap(bContext &C, Button &but)
const uiWidgetColors * tooltip_get_theme()
void tooltip_text_field_add(TooltipData &data, std::string text, std::string suffix, const TooltipStyle style, const TooltipColorID color_id, const bool is_pad=false)
static std::string tooltip_color_string(const float4 &color, const StringRefNull title, const int max_title_len, const bool show_alpha, const bool show_hex=false)
PointerRNA * button_extra_operator_icon_opptr_get(const ButtonExtraOpIcon *extra_icon)
std::string button_extra_icon_string_get_label(const ButtonExtraOpIcon &extra_icon)
bool block_is_pie_menu(const Block *block) ATTR_WARN_UNUSED_RESULT
static std::string tooltip_with_period(StringRef tip)
static void tooltip_from_image(Image &ima, TooltipData &data)
static void tooltip_from_vfont(const VFont &font, TooltipData &data)
std::string button_extra_icon_string_get_operator_keymap(const bContext &C, const ButtonExtraOpIcon &extra_icon)
bool button_is_color_gamma(Button &but)
std::string button_string_get_property_keymap(bContext &C, Button &but)
static const char * icon_id_to_name(BIFIconID icon_value)
ARegion * tooltip_create_from_search_item_generic(bContext *C, const ARegion *searchbox_region, const rcti *item_rect, ID *id)
ARegion * tooltip_create_from_gizmo(bContext *C, wmGizmo *gz)
ARegion * tooltip_create_from_button(bContext *C, ARegion *butregion, Button *but, bool is_quick_tip)
static std::unique_ptr< TooltipData > tooltip_data_from_button_or_extra_icon(bContext *C, Button *but, ButtonExtraOpIcon *extra_icon, const bool is_quick_tip)
bool but_is_tool(const Button *but)
const char * BKE_idtype_idcode_to_name(short idcode)
Definition idtype.cc:261
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)
std::string WM_operator_pystring_abbreviate(std::string str, int str_len_max)
ScrArea * CTX_wm_area(const bContext *C)
void wmOrtho2_region_pixelspace(const ARegion *region)
MINLINE void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
char * STRNCPY(char(&dst)[N], const char *src)
ImBuf * IMB_font_preview(const char *filepath, unsigned int width, const float color[4], const char *sample_text=nullptr)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
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
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
void WM_operator_properties_sanitize(PointerRNA *ptr, const bool no_context)
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
bool BKE_vfont_is_builtin(const VFont *vfont)
Definition vfont.cc:278
int MOV_get_image_height(const MovieReader *anim)
unsigned int BLI_str_utf8_as_unicode_safe(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int MOV_get_image_width(const MovieReader *anim)
std::optional< std::string > RNA_path_full_struct_py(const PointerRNA *ptr)
Definition rna_path.cc:1325
void WM_operator_properties_free(PointerRNA *ptr)
bool BLI_str_utf32_char_is_terminal_punctuation(char32_t codepoint)
void BLF_wordwrap(int fontid, int wrap_width, BLFWrapMode mode=BLFWrapMode::Minimal)
Definition blf.cc:957
void imm_draw_box_checker_2d(float x1, float y1, float x2, float y2, bool clear_alpha=false)
bool bool bool BPY_run_string_as_string_and_len(bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, char **r_value, size_t *r_value_len) ATTR_NONNULL(1
bool BKE_path_contains_template_syntax(StringRef path)
GPUVertFormat * immVertexFormat()
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:404
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
void BLI_rcti_rctf_copy(struct rcti *dst, const struct rctf *src)
@ PROP_UNIT_ROTATION
Definition RNA_types.hh:226
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
PointerRNA WM_operator_properties_create_ptr(wmOperatorType *ot)
std::string RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop)
wmWindow * CTX_wm_window(const bContext *C)
void imm_draw_box_checker_2d_ex(float x1, float y1, float x2, float y2, const float color_primary[4], const float color_secondary[4], int checker_size)
MINLINE int max_ii(int a, int b)
std::optional< std::string > WM_key_event_operator_string(const bContext *C, const char *opname, wm::OpCallContext opcontext, IDProperty *properties, const bool is_strict)
void immUniformColor4fv(const float rgba[4])
void BLI_rcti_rctf_copy_round(struct rcti *dst, const struct rctf *src)
MINLINE void rgb_float_to_uchar(unsigned char r_col[3], const float col_f[3])
bool BLI_rcti_clamp(struct rcti *rect, const struct rcti *rect_bounds, int r_xy[2])
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
std::string WM_operatortype_description_or_name(bContext *C, wmOperatorType *ot, PointerRNA *properties)
void IMB_rectfill_area(ImBuf *ibuf, const float scene_linear_color[4], int x1, int y1, int x2, int y2)
Definition rectop.cc:1194
MINLINE float srgb_to_grayscale(const float rgb[3])
void BLF_disable(int fontid, FontFlags flag)
Definition blf.cc:331
void immUnbindProgram()
ImBuf * IMB_dupImBuf(const ImBuf *ibuf1)
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
@ GPU_BLEND_ALPHA_PREMULT
Definition GPU_state.hh:91
std::string BKE_path_template_error_to_string(const bke::path_templates::Error &error, StringRef path)
bool RNA_property_array_check(PropertyRNA *prop)
VecBase< float, 4 > float4
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
PropertyType RNA_property_type(PropertyRNA *prop)
Vector< bke::path_templates::Error > BKE_path_apply_template(char *path, int path_maxncpy, const bke::path_templates::VariableMap &template_variables)
std::string WM_operator_pystring_ex(bContext *C, wmOperator *op, const bool all_args, const bool macro_args, wmOperatorType *ot, PointerRNA *opptr)
void BLF_size(int fontid, float size)
Definition blf.cc:445
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
void void BLI_path_split_dir_part(const char *filepath, char *dir, size_t dir_maxncpy) ATTR_NONNULL(1
void IMB_freeImBuf(ImBuf *ibuf)
VecBase< int32_t, 2 > int2
unsigned char uchar
Definition BKE_text.h:58
BLI_INLINE int BLI_rcti_cent_y(const struct rcti *rct)
Definition BLI_rect.hh:190
BMesh const char void * data
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.hh:215
BLI_INLINE void IMB_colormanagement_srgb_to_scene_linear_v3(float scene_linear[3], const float srgb[3])
std::optional< bke::path_templates::VariableMap > BKE_build_template_variables_for_prop(const bContext *C, PointerRNA *ptr, PropertyRNA *prop)
void BLI_rcti_translate(struct rcti *rect, int x, int y)
Definition rct.cc:580
int RNA_property_flag(PropertyRNA *prop)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
const char * CTX_wm_operator_poll_msg_get(bContext *C, bool *r_free)
void ED_region_floating_init(ARegion *region)
Definition area.cc:2544
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
bool bool BPY_run_string_as_intptr(bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, intptr_t *r_value) ATTR_NONNULL(1
int BIFIconID
Definition ED_asset.hh:30
ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, ImBufFlags flags)
std::optional< std::string > WM_keymap_item_to_string(const wmKeyMapItem *kmi, const bool compact)
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
PropertySubType RNA_property_subtype(PropertyRNA *prop)
SpaceLink * CTX_wm_space_data(const bContext *C)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
int BLF_height_max(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:883
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
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
void IMB_byte_from_float(ImBuf *ibuf)
void imm_draw_box_wire_2d(uint pos, float x1, float y1, float x2, float y2)
int2 WM_window_native_pixel_size(const wmWindow *win)
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
const char * RNA_property_ui_description(const PropertyRNA *prop, const PointerRNA *ptr)
MINLINE float max_ff(float a, float b)
bool BLI_path_contains(const char *container_path, const char *containee_path) ATTR_NONNULL(1
std::optional< std::string > RNA_path_full_property_py_ex(const PointerRNA *ptr, PropertyRNA *prop, int index, bool use_fallback)
Definition rna_path.cc:1341
Vector< bke::path_templates::Error > BKE_path_validate_template(StringRef path, const bke::path_templates::VariableMap &template_variables)
int BLF_descender(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:905
BLI_INLINE float BLI_rctf_cent_y(const struct rctf *rct)
Definition BLI_rect.hh:198
ID_Type GS(const char *name)
Definition DNA_ID.h:410
@ PROP_ENUM_FLAG
Definition RNA_types.hh:474
@ PROP_PATH_SUPPORTS_TEMPLATES
Definition RNA_types.hh:540
@ PROP_PATH_SUPPORTS_BLEND_RELATIVE
Definition RNA_types.hh:526
MINLINE void rgb_uchar_to_float(float r_col[3], const unsigned char col_ub[3])
int blf_mono_font
Definition blf.cc:50
bScreen * CTX_wm_screen(const bContext *C)
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
bool BLI_rcti_isect_pt(const struct rcti *rect, int x, int y)
bool RNA_enum_identifier(const EnumPropertyItem *item, const int value, const char **r_identifier)
std::string RNA_string_get(PointerRNA *ptr, const char *name)
void BLI_rcti_pad(struct rcti *rect, int pad_x, int pad_y)
Definition rct.cc:643
@ DISPLAY_SPACE_COLOR_INSPECTION
ImBuf * MOV_decode_preview_frame(MovieReader *anim)
BLI_INLINE void IMB_colormanagement_scene_linear_to_srgb_v3(float srgb[3], const float scene_linear[3])
BLI_INLINE int BLI_rcti_cent_x(const struct rcti *rct)
Definition BLI_rect.hh:186
wmGizmoOpElem * WM_gizmo_operator_get(wmGizmo *gz, int part_index)
Definition wm_gizmo.cc:191
@ PROP_FILENAME
Definition RNA_types.hh:286
@ PROP_FILEPATH
Definition RNA_types.hh:284
@ PROP_DIRPATH
Definition RNA_types.hh:285
@ PROP_PASSWORD
Definition RNA_types.hh:298
bool IMB_scale(ImBuf *ibuf, int2 new_size, IMBScaleFilter filter, bool threaded=true)
Definition scaling.cc:467
const EnumPropertyItem rna_enum_icon_items[]
Definition rna_ui_api.cc:30
int MOV_get_duration_frames(const MovieReader *anim)
bool BLI_rcti_inside_rcti(const rcti *rct_a, const rcti *rct_b)
Definition rct.cc:200
MINLINE int min_ii(int a, int b)
void CTX_wm_operator_poll_msg_clear(bContext *C)
ImBuf * BKE_image_preview(Image *ima, short max_size, short *r_width, short *r_height)
BLI_INLINE float BLI_rctf_cent_x(const struct rctf *rct)
Definition BLI_rect.hh:194
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
void BLF_enable(int fontid, FontFlags flag)
Definition blf.cc:322
@ BLF_WORD_WRAP
Definition BLF_enums.hh:42
MINLINE void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
ocio::Display ColorManagedDisplay
bool bool bool bool BPY_run_string_as_string(bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, char **r_value) ATTR_NONNULL(1
_W64 int intptr_t
Definition BKE_text.h:119
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
void(*) free(ARegion *)
void(*) draw(const bContext *C, ARegion *region)
bke::ARegionRuntime * runtime
struct MovieReader * anim
eUserPref_Flag flag
char filepath[1024]
struct ARegionType * type
wmOperatorCallParams * optype_params
wm::OpCallContext opcontext
ButtonToolTipCustomFunc tip_custom_func
ButtonToolTipFunc tip_func
wmOperatorType * optype
std::optional< TooltipImage > image
struct blender::ui::TooltipField::@205015175056016006067054323350112016335315045057 geom
TooltipImageBackground background
wmGizmoFnScreenBoundsGet screen_bounds_get
const wmGizmoType * type
Vector< wmGizmoProperty, 0 > target_properties
ListBaseT< wmKeyMapItem > items
wm::OpCallContext opcontext
Definition WM_types.hh:1246
const char * description
Definition WM_types.hh:1115
bke::WindowRuntime * runtime
uiFontStyle tooltip