Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_spreadsheet/spreadsheet_layout.cc
| Show All 11 Lines | |||||
| * You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
| * along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
| */ | */ | ||||
| #include <iomanip> | #include <iomanip> | ||||
| #include <sstream> | #include <sstream> | ||||
| #include "BLI_float2.hh" | |||||
| #include "BLI_float3.hh" | |||||
| #include "BKE_geometry_set.hh" | |||||
| #include "spreadsheet_column_values.hh" | |||||
| #include "spreadsheet_layout.hh" | #include "spreadsheet_layout.hh" | ||||
| #include "DNA_userdef_types.h" | #include "DNA_userdef_types.h" | ||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| #include "BLF_api.h" | #include "BLF_api.h" | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | void draw_left_column_cell(int row_index, const CellDrawParams ¶ms) const final | ||||
| UI_but_drawflag_enable(but, UI_BUT_TEXT_RIGHT); | UI_but_drawflag_enable(but, UI_BUT_TEXT_RIGHT); | ||||
| UI_but_drawflag_disable(but, UI_BUT_TEXT_LEFT); | UI_but_drawflag_disable(but, UI_BUT_TEXT_LEFT); | ||||
| } | } | ||||
| void draw_content_cell(int row_index, int column_index, const CellDrawParams ¶ms) const final | void draw_content_cell(int row_index, int column_index, const CellDrawParams ¶ms) const final | ||||
| { | { | ||||
| const int real_index = spreadsheet_layout_.row_indices[row_index]; | const int real_index = spreadsheet_layout_.row_indices[row_index]; | ||||
| const ColumnValues &column = *spreadsheet_layout_.columns[column_index].values; | const ColumnValues &column = *spreadsheet_layout_.columns[column_index].values; | ||||
| CellValue cell_value; | if (real_index > column.size()) { | ||||
| if (real_index < column.size()) { | return; | ||||
| column.get_value(real_index, cell_value); | |||||
| } | } | ||||
| if (cell_value.value_int.has_value()) { | const fn::GVArray &data = column.data(); | ||||
| const int value = *cell_value.value_int; | |||||
| if (data.type().is<int>()) { | |||||
| const int value = data.get<int>(real_index); | |||||
| const std::string value_str = std::to_string(value); | const std::string value_str = std::to_string(value); | ||||
| uiBut *but = uiDefIconTextBut(params.block, | uiBut *but = uiDefIconTextBut(params.block, | ||||
| UI_BTYPE_LABEL, | UI_BTYPE_LABEL, | ||||
| 0, | 0, | ||||
| ICON_NONE, | ICON_NONE, | ||||
| value_str.c_str(), | value_str.c_str(), | ||||
| params.xmin, | params.xmin, | ||||
| params.ymin, | params.ymin, | ||||
| params.width, | params.width, | ||||
| params.height, | params.height, | ||||
| nullptr, | nullptr, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| nullptr); | nullptr); | ||||
| /* Right-align Integers. */ | /* Right-align Integers. */ | ||||
| UI_but_drawflag_disable(but, UI_BUT_TEXT_LEFT); | UI_but_drawflag_disable(but, UI_BUT_TEXT_LEFT); | ||||
| UI_but_drawflag_enable(but, UI_BUT_TEXT_RIGHT); | UI_but_drawflag_enable(but, UI_BUT_TEXT_RIGHT); | ||||
| } | } | ||||
| else if (cell_value.value_float.has_value()) { | else if (data.type().is<float>()) { | ||||
| const float value = *cell_value.value_float; | const float value = data.get<float>(real_index); | ||||
| std::stringstream ss; | std::stringstream ss; | ||||
| ss << std::fixed << std::setprecision(3) << value; | ss << std::fixed << std::setprecision(3) << value; | ||||
| const std::string value_str = ss.str(); | const std::string value_str = ss.str(); | ||||
| uiBut *but = uiDefIconTextBut(params.block, | uiBut *but = uiDefIconTextBut(params.block, | ||||
| UI_BTYPE_LABEL, | UI_BTYPE_LABEL, | ||||
| 0, | 0, | ||||
| ICON_NONE, | ICON_NONE, | ||||
| value_str.c_str(), | value_str.c_str(), | ||||
| params.xmin, | params.xmin, | ||||
| params.ymin, | params.ymin, | ||||
| params.width, | params.width, | ||||
| params.height, | params.height, | ||||
| nullptr, | nullptr, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| nullptr); | nullptr); | ||||
| /* Right-align Floats. */ | /* Right-align Floats. */ | ||||
| UI_but_drawflag_disable(but, UI_BUT_TEXT_LEFT); | UI_but_drawflag_disable(but, UI_BUT_TEXT_LEFT); | ||||
| UI_but_drawflag_enable(but, UI_BUT_TEXT_RIGHT); | UI_but_drawflag_enable(but, UI_BUT_TEXT_RIGHT); | ||||
| } | } | ||||
| else if (cell_value.value_bool.has_value()) { | else if (data.type().is<bool>()) { | ||||
| const bool value = *cell_value.value_bool; | const bool value = data.get<bool>(real_index); | ||||
| const int icon = value ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT; | const int icon = value ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT; | ||||
| uiBut *but = uiDefIconTextBut(params.block, | uiBut *but = uiDefIconTextBut(params.block, | ||||
| UI_BTYPE_LABEL, | UI_BTYPE_LABEL, | ||||
| 0, | 0, | ||||
| icon, | icon, | ||||
| "", | "", | ||||
| params.xmin, | params.xmin, | ||||
| params.ymin, | params.ymin, | ||||
| params.width, | params.width, | ||||
| params.height, | params.height, | ||||
| nullptr, | nullptr, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| nullptr); | nullptr); | ||||
| UI_but_drawflag_disable(but, UI_BUT_ICON_LEFT); | UI_but_drawflag_disable(but, UI_BUT_ICON_LEFT); | ||||
| } | } | ||||
| else if (cell_value.value_float2.has_value()) { | else if (data.type().is<float2>()) { | ||||
| const float2 value = *cell_value.value_float2; | const float2 value = data.get<float2>(real_index); | ||||
| this->draw_float_vector(params, Span(&value.x, 2)); | this->draw_float_vector(params, Span(&value.x, 2)); | ||||
| } | } | ||||
| else if (cell_value.value_float3.has_value()) { | else if (data.type().is<float3>()) { | ||||
| const float3 value = *cell_value.value_float3; | const float3 value = data.get<float3>(real_index); | ||||
| this->draw_float_vector(params, Span(&value.x, 3)); | this->draw_float_vector(params, Span(&value.x, 3)); | ||||
| } | } | ||||
| else if (cell_value.value_color.has_value()) { | else if (data.type().is<ColorGeometry4f>()) { | ||||
| const ColorGeometry4f value = *cell_value.value_color; | const ColorGeometry4f value = data.get<ColorGeometry4f>(real_index); | ||||
| this->draw_float_vector(params, Span(&value.r, 4)); | this->draw_float_vector(params, Span(&value.r, 4)); | ||||
| } | } | ||||
| else if (cell_value.value_object.has_value()) { | else if (data.type().is<InstanceReference>()) { | ||||
| const ObjectCellValue value = *cell_value.value_object; | const InstanceReference &value = data.get<InstanceReference>(real_index); | ||||
JacquesLucke: Using a const reference here is not wrong, but it could be misleading, because `get` does not… | |||||
| switch (value.type()) { | |||||
| case InstanceReference::Type::Object: { | |||||
| const Object &object = value.object(); | |||||
| uiDefIconTextBut(params.block, | uiDefIconTextBut(params.block, | ||||
| UI_BTYPE_LABEL, | UI_BTYPE_LABEL, | ||||
| 0, | 0, | ||||
| ICON_OBJECT_DATA, | ICON_OBJECT_DATA, | ||||
| reinterpret_cast<const ID *const>(value.object)->name + 2, | reinterpret_cast<const ID &>(object).name + 2, | ||||
| params.xmin, | params.xmin, | ||||
| params.ymin, | params.ymin, | ||||
| params.width, | params.width, | ||||
| params.height, | params.height, | ||||
| nullptr, | nullptr, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| nullptr); | nullptr); | ||||
| break; | |||||
| } | } | ||||
| else if (cell_value.value_collection.has_value()) { | case InstanceReference::Type::Collection: { | ||||
| const CollectionCellValue value = *cell_value.value_collection; | Collection &collection = value.collection(); | ||||
| uiDefIconTextBut(params.block, | uiDefIconTextBut(params.block, | ||||
| UI_BTYPE_LABEL, | UI_BTYPE_LABEL, | ||||
| 0, | 0, | ||||
| ICON_OUTLINER_COLLECTION, | ICON_OUTLINER_COLLECTION, | ||||
| reinterpret_cast<const ID *const>(value.collection)->name + 2, | reinterpret_cast<const ID &>(collection).name + 2, | ||||
| params.xmin, | params.xmin, | ||||
| params.ymin, | params.ymin, | ||||
| params.width, | params.width, | ||||
| params.height, | params.height, | ||||
| nullptr, | nullptr, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| nullptr); | nullptr); | ||||
| break; | |||||
| } | } | ||||
| else if (cell_value.value_geometry_set.has_value()) { | case InstanceReference::Type::GeometrySet: { | ||||
| uiDefIconTextBut(params.block, | uiDefIconTextBut(params.block, | ||||
| UI_BTYPE_LABEL, | UI_BTYPE_LABEL, | ||||
| 0, | 0, | ||||
| ICON_MESH_DATA, | ICON_MESH_DATA, | ||||
| "Geometry", | "Geometry", | ||||
| params.xmin, | params.xmin, | ||||
| params.ymin, | params.ymin, | ||||
| params.width, | params.width, | ||||
| params.height, | params.height, | ||||
| nullptr, | nullptr, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| nullptr); | nullptr); | ||||
| break; | |||||
| } | |||||
| case InstanceReference::Type::None: { | |||||
| break; | |||||
| } | |||||
| } | } | ||||
| else if (cell_value.value_string.has_value()) { | |||||
| uiDefIconTextBut(params.block, | |||||
| UI_BTYPE_LABEL, | |||||
| 0, | |||||
| ICON_NONE, | |||||
| cell_value.value_string->c_str(), | |||||
| params.xmin, | |||||
| params.ymin, | |||||
| params.width, | |||||
| params.height, | |||||
| nullptr, | |||||
| 0, | |||||
| 0, | |||||
| 0, | |||||
| 0, | |||||
| nullptr); | |||||
| } | } | ||||
| } | } | ||||
| void draw_float_vector(const CellDrawParams ¶ms, const Span<float> values) const | void draw_float_vector(const CellDrawParams ¶ms, const Span<float> values) const | ||||
| { | { | ||||
| BLI_assert(!values.is_empty()); | BLI_assert(!values.is_empty()); | ||||
| const float segment_width = (float)params.width / values.size(); | const float segment_width = (float)params.width / values.size(); | ||||
| for (const int i : values.index_range()) { | for (const int i : values.index_range()) { | ||||
| Show All 38 Lines | |||||
Using a const reference here is not wrong, but it could be misleading, because get does not (and can not return a reference.