UI: Color Tooltips #117815
@ -1043,6 +1043,89 @@ static uiTooltipData *ui_tooltip_data_from_button_or_extra_icon(bContext *C,
|
||||
}
|
||||
}
|
||||
|
||||
if (but->type == UI_BTYPE_COLOR) {
|
||||
|
||||
float color[4];
|
||||
ui_but_v3_get(but, color);
|
||||
color[3] = 1.0f;
|
||||
|
||||
Harley marked this conversation as resolved
|
||||
if (but->rnaprop) {
|
||||
BLI_assert(but->rnaindex == -1);
|
||||
if (RNA_property_array_length(&but->rnapoin, but->rnaprop) == 4) {
|
||||
color[3] = RNA_property_float_get_index(&but->rnapoin, but->rnaprop, 3);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ui_but_is_color_gamma(but)) {
|
||||
ui_block_cm_to_display_space_v3(but->block, color);
|
||||
}
|
||||
|
||||
const std::string hex_st = fmt::format("Hex: {:X}{:X}{:X}{:X}",
|
||||
int(color[0] * 255.0f),
|
||||
int(color[1] * 255.0f),
|
||||
int(color[2] * 255.0f),
|
||||
int(color[3] * 255.0f));
|
||||
|
||||
const std::string rgba_st = fmt::format("{}: {:.3f} {:.3f} {:.3f} {:.3f}",
|
||||
TIP_("RGBA"),
|
||||
color[0],
|
||||
color[1],
|
||||
color[2],
|
||||
color[3]);
|
||||
float hsva[4];
|
||||
rgb_to_hsv_v(color, hsva);
|
||||
hsva[3] = color[3];
|
||||
const std::string hsva_st = fmt::format(
|
||||
"{}: {:.3f} {:.3f} {:.3f} {:.3f}", TIP_("HSVA"), hsva[0], hsva[1], hsva[2], hsva[3]);
|
||||
|
||||
const float aspect = min_ff(1.0f, but->block->aspect);
|
||||
const uiFontStyle *fs = UI_FSTYLE_WIDGET;
|
||||
BLF_size(blf_mono_font, fs->points * UI_SCALE_FAC / aspect);
|
||||
float w = BLF_width(blf_mono_font, hsva_st.c_str(), hsva_st.size());
|
||||
|
||||
uiTooltipImage image_data;
|
||||
image_data.width = int(w);
|
||||
image_data.height = int(w / 4.0f);
|
||||
image_data.ibuf = IMB_allocImBuf(image_data.width, image_data.height, 32, IB_rect);
|
||||
image_data.border = true;
|
||||
image_data.premultiplied = false;
|
||||
Harley marked this conversation as resolved
Iliya Katushenock
commented
How this memory should be freed? How this memory should be freed?
|
||||
|
||||
ColorManagedDisplay *display = ui_block_cm_display_get(but->block);
|
||||
if (color[3] == 1.0f) {
|
||||
/* No transparency so draw the entire area solid without checkerboard. */
|
||||
image_data.background = uiTooltipImageBackground::None;
|
||||
IMB_rectfill_area(
|
||||
Harley marked this conversation as resolved
Outdated
Hans Goudey
commented
Would be nice to have a comment here about the sequence of drawing two rectangles, and maybe a more explicit Would be nice to have a comment here about the sequence of drawing two rectangles, and maybe a more explicit `== 0.0f` check here.
|
||||
image_data.ibuf, color, 1, 1, image_data.width, image_data.height, display);
|
||||
}
|
||||
else {
|
||||
image_data.background = uiTooltipImageBackground::Checkerboard_Fixed;
|
||||
/* Draw one half with transparency. */
|
||||
IMB_rectfill_area(image_data.ibuf,
|
||||
color,
|
||||
image_data.width / 2,
|
||||
1,
|
||||
image_data.width,
|
||||
image_data.height,
|
||||
display);
|
||||
/* Draw the other half with a solid color. */
|
||||
color[3] = 1.0f;
|
||||
IMB_rectfill_area(
|
||||
image_data.ibuf, color, 1, 1, image_data.width / 2, image_data.height, display);
|
||||
}
|
||||
|
||||
UI_tooltip_text_field_add(data, {}, {}, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL, false);
|
||||
UI_tooltip_text_field_add(data, {}, {}, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL, false);
|
||||
UI_tooltip_image_field_add(data, image_data);
|
||||
UI_tooltip_text_field_add(data, {}, {}, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL, false);
|
||||
UI_tooltip_text_field_add(data, hex_st, {}, UI_TIP_STYLE_MONO, UI_TIP_LC_NORMAL, false);
|
||||
UI_tooltip_text_field_add(data, {}, {}, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL, false);
|
||||
UI_tooltip_text_field_add(data, rgba_st, {}, UI_TIP_STYLE_MONO, UI_TIP_LC_NORMAL, false);
|
||||
UI_tooltip_text_field_add(data, hsva_st, {}, UI_TIP_STYLE_MONO, UI_TIP_LC_NORMAL, false);
|
||||
|
||||
/* Tooltip now owns a copy of the ImBuf, so we can delete ours.*/
|
||||
IMB_freeImBuf(image_data.ibuf);
|
||||
}
|
||||
|
||||
if (data->fields.is_empty()) {
|
||||
MEM_delete(data);
|
||||
return nullptr;
|
||||
|
Loading…
Reference in New Issue
Block a user
has_alpha
is unused hereIt's used, just a few lines below
yikes, you are right, removing that.