Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brecht@blender.org>2022-06-29 14:01:38 +0300
committerBrecht Van Lommel <brecht@blender.org>2022-06-29 18:08:50 +0300
commit6b508eb012b929b34e893f71a785580562cc9a6a (patch)
tree37cd279a588e7b6f187163208af29466f2f3124d /source/blender/editors/space_spreadsheet/spreadsheet_layout.cc
parent6dd8ceef2a21f64cbb61a96560c50c162f9dae39 (diff)
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
Diffstat (limited to 'source/blender/editors/space_spreadsheet/spreadsheet_layout.cc')
-rw-r--r--source/blender/editors/space_spreadsheet/spreadsheet_layout.cc32
1 files changed, 26 insertions, 6 deletions
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<ColorGeometry4b>()) {
const ColorGeometry4b value = data.get<ColorGeometry4b>(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<InstanceReference>()) {
const InstanceReference value = data.get<InstanceReference>(real_index);
@@ -308,13 +310,16 @@ class SpreadsheetLayoutDrawer : public SpreadsheetDrawer {
}
}
- void draw_int_vector(const CellDrawParams &params, const Span<int> values) const
+ void draw_byte_color(const CellDrawParams &params, const ColorGeometry4b color) const
{
- BLI_assert(!values.is_empty());
+ const ColorGeometry4f float_color = color.decode();
+ Span<float> 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);
}
}