diff options
Diffstat (limited to 'source/blender')
6 files changed, 38 insertions, 36 deletions
diff --git a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc index dd3aac1eae9..8dbb4a2ee0c 100644 --- a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc +++ b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc @@ -298,7 +298,6 @@ static float get_default_column_width(const ColumnValues &values) return values.default_width; } static const float float_width = 3; - static const float int_width = 2; switch (values.type()) { case SPREADSHEET_VALUE_TYPE_BOOL: return 2.0f; @@ -312,13 +311,12 @@ static float get_default_column_width(const ColumnValues &values) case SPREADSHEET_VALUE_TYPE_FLOAT3: return 3.0f * float_width; case SPREADSHEET_VALUE_TYPE_COLOR: + case SPREADSHEET_VALUE_TYPE_BYTE_COLOR: return 4.0f * float_width; case SPREADSHEET_VALUE_TYPE_INSTANCES: return 8.0f; case SPREADSHEET_VALUE_TYPE_STRING: return 5.0f; - case SPREADSHEET_VALUE_TYPE_BYTE_COLOR: - return 4.0f * int_width; case SPREADSHEET_VALUE_TYPE_UNKNOWN: return 2.0f; } 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 ¶ms, const Span<int> 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<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); } } diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc index d71a355850f..6806e185cfe 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc @@ -230,7 +230,7 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter, } } else if (column_data.type().is<ColorGeometry4b>()) { - const ColorGeometry4b value = row_filter.value_byte_color; + const ColorGeometry4f value = row_filter.value_color; switch (row_filter.operation) { case SPREADSHEET_ROW_FILTER_EQUAL: { const float4 value_floats = { @@ -238,7 +238,8 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter, const float threshold_sq = pow2f(row_filter.threshold); apply_filter_operation( column_data.typed<ColorGeometry4b>(), - [&](const ColorGeometry4b cell) { + [&](const ColorGeometry4b cell_bytes) { + const ColorGeometry4f cell = cell_bytes.decode(); const float4 cell_floats = { (float)cell.r, (float)cell.g, (float)cell.b, (float)cell.a}; return len_squared_v4v4(value_floats, cell_floats) <= threshold_sq; @@ -250,7 +251,8 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter, case SPREADSHEET_ROW_FILTER_GREATER: { apply_filter_operation( column_data.typed<ColorGeometry4b>(), - [&](const ColorGeometry4b cell) { + [&](const ColorGeometry4b cell_bytes) { + const ColorGeometry4f cell = cell_bytes.decode(); return cell.r > value.r && cell.g > value.g && cell.b > value.b && cell.a > value.a; }, prev_mask, @@ -260,7 +262,8 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter, case SPREADSHEET_ROW_FILTER_LESS: { apply_filter_operation( column_data.typed<ColorGeometry4b>(), - [&](const ColorGeometry4b cell) { + [&](const ColorGeometry4b cell_bytes) { + const ColorGeometry4f cell = cell_bytes.decode(); return cell.r < value.r && cell.g < value.g && cell.b < value.b && cell.a < value.a; }, prev_mask, diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter_ui.cc b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter_ui.cc index 6d8febc0e45..548e6cf29e4 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter_ui.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter_ui.cc @@ -90,7 +90,8 @@ static std::string value_string(const SpreadsheetRowFilter &row_filter, return row_filter.value_string; } return ""; - case SPREADSHEET_VALUE_TYPE_COLOR: { + case SPREADSHEET_VALUE_TYPE_COLOR: + case SPREADSHEET_VALUE_TYPE_BYTE_COLOR: { std::ostringstream result; result.precision(3); result << std::fixed << "(" << row_filter.value_color[0] << ", " << row_filter.value_color[1] @@ -99,14 +100,6 @@ static std::string value_string(const SpreadsheetRowFilter &row_filter, } case SPREADSHEET_VALUE_TYPE_STRING: return row_filter.value_string; - case SPREADSHEET_VALUE_TYPE_BYTE_COLOR: { - std::ostringstream result; - result.precision(3); - result << std::fixed << "(" << (int)row_filter.value_byte_color[0] << ", " - << (int)row_filter.value_byte_color[1] << ", " << (int)row_filter.value_byte_color[2] - << ", " << (int)row_filter.value_byte_color[3] << ")"; - return result.str(); - } case SPREADSHEET_VALUE_TYPE_UNKNOWN: return ""; } @@ -233,6 +226,7 @@ static void spreadsheet_filter_panel_draw(const bContext *C, Panel *panel) uiItemR(layout, filter_ptr, "value_string", 0, IFACE_("Value"), ICON_NONE); break; case SPREADSHEET_VALUE_TYPE_COLOR: + case SPREADSHEET_VALUE_TYPE_BYTE_COLOR: uiItemR(layout, filter_ptr, "operation", 0, nullptr, ICON_NONE); uiItemR(layout, filter_ptr, "value_color", 0, IFACE_("Value"), ICON_NONE); if (operation == SPREADSHEET_ROW_FILTER_EQUAL) { @@ -242,13 +236,6 @@ static void spreadsheet_filter_panel_draw(const bContext *C, Panel *panel) case SPREADSHEET_VALUE_TYPE_STRING: uiItemR(layout, filter_ptr, "value_string", 0, IFACE_("Value"), ICON_NONE); break; - case SPREADSHEET_VALUE_TYPE_BYTE_COLOR: - uiItemR(layout, filter_ptr, "operation", 0, nullptr, ICON_NONE); - uiItemR(layout, filter_ptr, "value_byte_color", 0, IFACE_("Value"), ICON_NONE); - if (operation == SPREADSHEET_ROW_FILTER_EQUAL) { - uiItemR(layout, filter_ptr, "threshold", 0, nullptr, ICON_NONE); - } - break; case SPREADSHEET_VALUE_TYPE_UNKNOWN: uiItemL(layout, IFACE_("Unknown column type"), ICON_ERROR); break; diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h index 2905ef06833..2a5ca4c9541 100644 --- a/source/blender/makesdna/DNA_space_types.h +++ b/source/blender/makesdna/DNA_space_types.h @@ -1977,7 +1977,7 @@ typedef struct SpreadsheetRowFilter { float value_float2[2]; float value_float3[3]; float value_color[4]; - uint8_t value_byte_color[4]; + char _pad1[4]; } SpreadsheetRowFilter; typedef enum eSpaceSpreadsheet_RowFilterFlag { diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 70f111359a5..745c7137cb2 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -7805,12 +7805,6 @@ static void rna_def_spreadsheet_row_filter(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Color Value", ""); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_SPREADSHEET, NULL); - prop = RNA_def_property(srna, "value_byte_color", PROP_INT, PROP_NONE); - RNA_def_property_array(prop, 4); - RNA_def_property_range(prop, 0, 255); - RNA_def_property_ui_text(prop, "Byte Color Value", ""); - RNA_def_property_update(prop, NC_SPACE | ND_SPACE_SPREADSHEET, NULL); - prop = RNA_def_property(srna, "value_string", PROP_STRING, PROP_NONE); RNA_def_property_ui_text(prop, "Text Value", ""); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_SPREADSHEET, NULL); |