From 6b508eb012b929b34e893f71a785580562cc9a6a Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 29 Jun 2022 13:01:38 +0200 Subject: Spreadsheet: display byte colors as scene linear floats The compression as sRGB is mostly an implementation detail and showing the integers does not make it clear what the actual values are that will be used for computations in geometry nodes. This follows the general convention that colors in Blender are displayed and edited in scene linear floats. The raw sRGB bytes can still be viewed as a tooltip. Ref T99205 Differential Revision: https://developer.blender.org/D15322 --- .../space_spreadsheet/spreadsheet_layout.cc | 32 ++++++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'source/blender/editors/space_spreadsheet/spreadsheet_layout.cc') diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc b/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc index e19a343335a..ad4ca80f36f 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc @@ -19,6 +19,8 @@ #include "BLF_api.h" +#include "BLT_translation.h" + namespace blender::ed::spreadsheet { class SpreadsheetLayoutDrawer : public SpreadsheetDrawer { @@ -193,7 +195,7 @@ class SpreadsheetLayoutDrawer : public SpreadsheetDrawer { } else if (data.type().is()) { const ColorGeometry4b value = data.get(real_index); - this->draw_int_vector(params, {value.r, value.g, value.b, value.a}); + this->draw_byte_color(params, value); } else if (data.type().is()) { const InstanceReference value = data.get(real_index); @@ -308,13 +310,16 @@ class SpreadsheetLayoutDrawer : public SpreadsheetDrawer { } } - void draw_int_vector(const CellDrawParams ¶ms, const Span values) const + void draw_byte_color(const CellDrawParams ¶ms, const ColorGeometry4b color) const { - BLI_assert(!values.is_empty()); + const ColorGeometry4f float_color = color.decode(); + Span values(&float_color.r, 4); const float segment_width = (float)params.width / values.size(); for (const int i : values.index_range()) { - const int value = values[i]; - const std::string value_str = std::to_string(value); + std::stringstream ss; + const float value = values[i]; + ss << std::fixed << std::setprecision(3) << value; + const std::string value_str = ss.str(); uiBut *but = uiDefIconTextBut(params.block, UI_BTYPE_LABEL, 0, @@ -330,9 +335,24 @@ class SpreadsheetLayoutDrawer : public SpreadsheetDrawer { 0, 0, nullptr); - /* Right-align Ints. */ + /* Right-align Floats. */ UI_but_drawflag_disable(but, UI_BUT_TEXT_LEFT); UI_but_drawflag_enable(but, UI_BUT_TEXT_RIGHT); + + /* Tooltip showing raw byte values. Encode values in pointer to avoid memory allocation. */ + UI_but_func_tooltip_set( + but, + [](bContext *C, void *argN, const char *UNUSED(tip)) { + const uint32_t uint_color = POINTER_AS_UINT(argN); + ColorGeometry4b color = *(ColorGeometry4b *)&uint_color; + return BLI_sprintfN(TIP_("Byte Color (sRGB encoded):\n%3d %3d %3d %3d"), + color.r, + color.g, + color.b, + color.a); + }, + POINTER_FROM_UINT(*(uint32_t *)&color), + nullptr); } } -- cgit v1.2.3