[Bf-blender-cvs] [b79cd1cb035] temp-spreadsheet-editor: refactor spreadsheet drawing
Jacques Lucke
noreply at git.blender.org
Wed Feb 24 18:07:21 CET 2021
Commit: b79cd1cb0357be004b756a844cf2b9b21580a40a
Author: Jacques Lucke
Date: Wed Feb 24 18:06:04 2021 +0100
Branches: temp-spreadsheet-editor
https://developer.blender.org/rBb79cd1cb0357be004b756a844cf2b9b21580a40a
refactor spreadsheet drawing
===================================================================
M source/blender/blenloader/intern/versioning_userdef.c
M source/blender/editors/interface/resources.c
M source/blender/editors/space_spreadsheet/space_spreadsheet.cc
M source/blender/makesdna/DNA_userdef_types.h
M source/blender/makesrna/intern/rna_userdef.c
===================================================================
diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c
index 3d39181cd32..12877452863 100644
--- a/source/blender/blenloader/intern/versioning_userdef.c
+++ b/source/blender/blenloader/intern/versioning_userdef.c
@@ -282,6 +282,8 @@ static void do_versions_theme(const UserDef *userdef, bTheme *btheme)
FROM_DEFAULT_V4_UCHAR(space_info.info_property);
FROM_DEFAULT_V4_UCHAR(space_info.info_error);
FROM_DEFAULT_V4_UCHAR(space_info.info_operator);
+
+ btheme->space_spreadsheet = btheme->space_file;
}
#undef FROM_DEFAULT_V4_UCHAR
diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c
index 80e54f4f92f..afac254f542 100644
--- a/source/blender/editors/interface/resources.c
+++ b/source/blender/editors/interface/resources.c
@@ -160,6 +160,9 @@ const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
case SPACE_STATUSBAR:
ts = &btheme->space_statusbar;
break;
+ case SPACE_SPREADSHEET:
+ ts = &btheme->space_spreadsheet;
+ break;
default:
ts = &btheme->space_view3d;
break;
diff --git a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
index a905b0581ee..922d114e567 100644
--- a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
+++ b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
@@ -45,6 +45,8 @@
#include "WM_types.h"
+#include "GPU_immediate.h"
+
#include "spreadsheet_intern.hh"
using blender::float3;
@@ -113,174 +115,377 @@ static void spreadsheet_main_region_init(wmWindowManager *UNUSED(wm), ARegion *r
UI_view2d_region_reinit(®ion->v2d, V2D_COMMONVIEW_LIST, region->winx, region->winy);
}
-static void draw_row_indices(uiBlock *block,
- const int amount,
- const int left_x,
- const int top_y,
- const int column_width,
- const int row_height)
-{
- for (const int i : IndexRange(amount)) {
- const int x = left_x;
- const int y = top_y - (i + 1) * row_height;
- const std::string number_string = std::to_string(i);
+class ColumnHeaderDrawer {
+ public:
+ virtual ~ColumnHeaderDrawer() = default;
+ virtual void draw_header(uiBlock *block, const rcti &rect) const = 0;
+};
+
+class CellDrawer {
+ public:
+ virtual ~CellDrawer() = default;
+ virtual void draw_cell(uiBlock *block, const rcti &rect, const int index) const = 0;
+};
+
+struct SpreadsheetColumnLayout {
+ int width;
+ const ColumnHeaderDrawer *header_drawer = nullptr;
+ const CellDrawer *cell_drawer = nullptr;
+};
+
+struct SpreadsheetLayout {
+ int index_column_width;
+ int title_row_height;
+ int row_height;
+ Vector<SpreadsheetColumnLayout> columns;
+};
+
+class TextColumnHeaderDrawer final : public ColumnHeaderDrawer {
+ private:
+ std::string text_;
+
+ public:
+ TextColumnHeaderDrawer(std::string text) : text_(std::move(text))
+ {
+ }
+
+ void draw_header(uiBlock *block, const rcti &rect) const final
+ {
uiBut *but = uiDefIconTextBut(block,
UI_BTYPE_LABEL,
0,
ICON_NONE,
- number_string.c_str(),
- x,
- y,
- column_width,
- row_height,
+ text_.c_str(),
+ rect.xmin,
+ rect.ymin,
+ BLI_rcti_size_x(&rect),
+ BLI_rcti_size_y(&rect),
nullptr,
0,
0,
0,
0,
nullptr);
- 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_RIGHT);
}
+};
+
+class ConstantTextCellDrawer final : public CellDrawer {
+ private:
+ std::string text_;
+
+ public:
+ ConstantTextCellDrawer(std::string text) : text_(std::move(text))
+ {
+ }
+
+ void draw_cell(uiBlock *block, const rcti &rect, const int UNUSED(index)) const final
+ {
+ uiDefIconTextBut(block,
+ UI_BTYPE_LABEL,
+ 0,
+ ICON_NONE,
+ text_.c_str(),
+ rect.xmin,
+ rect.ymin,
+ BLI_rcti_size_x(&rect),
+ BLI_rcti_size_y(&rect),
+ nullptr,
+ 0,
+ 0,
+ 0,
+ 0,
+ nullptr);
+ }
+};
+
+static void draw_index_column_background(const uint pos,
+ const ARegion *region,
+ const SpreadsheetLayout &spreadsheet_layout)
+{
+ immUniformThemeColorShade(TH_BACK, 11);
+ immRecti(pos,
+ 0,
+ region->winy - spreadsheet_layout.title_row_height,
+ spreadsheet_layout.index_column_width,
+ 0);
}
-static void draw_attribute_column(uiBlock *block,
- const StringRefNull attribute_name,
- const ReadAttribute &attribute,
- const int left_x,
- const int top_y,
- const int row_height,
- int *r_right_x)
+static void draw_alternating_row_overlay(const uint pos,
+ const int scroll_offset_y,
+ const ARegion *region,
+ const SpreadsheetLayout &spreadsheet_layout)
{
- const int width = 100;
- uiDefIconTextBut(block,
- UI_BTYPE_LABEL,
- 0,
- ICON_NONE,
- attribute_name.c_str(),
- left_x,
- top_y - row_height,
- width,
- row_height,
- nullptr,
- 0,
- 0,
- 0,
- 0,
- nullptr);
- const CustomDataType data_type = attribute.custom_data_type();
- const int domain_size = attribute.size();
- switch (data_type) {
- case CD_PROP_FLOAT: {
- const blender::bke::FloatReadAttribute float_attribute = attribute;
- for (const int i : IndexRange(domain_size)) {
- const float value = float_attribute[i];
- std::string value_str = std::to_string(value);
- const int x = left_x;
- const int y = top_y - (i + 2) * row_height;
- uiDefIconTextBut(block,
- UI_BTYPE_LABEL,
- 0,
- ICON_NONE,
- value_str.c_str(),
- x,
- y,
- width,
- row_height,
- nullptr,
- 0,
- 0,
- 0,
- 0,
- nullptr);
- }
- break;
- }
- case CD_PROP_FLOAT3: {
- break;
+ immUniformThemeColor(TH_ROW_ALTERNATE);
+ GPU_blend(GPU_BLEND_ALPHA);
+ const int row_pair_height = spreadsheet_layout.row_height * 2;
+ const int row_top_y = region->winy - spreadsheet_layout.title_row_height -
+ scroll_offset_y % row_pair_height;
+ for (const int i : IndexRange(region->winy / row_pair_height + 1)) {
+ int x_left = 0;
+ int x_right = region->winx;
+ int y_top = row_top_y - i * row_pair_height;
+ int y_bottom = y_top - spreadsheet_layout.row_height;
+ y_top = std::min(y_top, region->winy - spreadsheet_layout.title_row_height);
+ y_bottom = std::min(y_bottom, region->winy - spreadsheet_layout.title_row_height);
+ immRecti(pos, x_left, y_top, x_right, y_bottom);
+ }
+ GPU_blend(GPU_BLEND_NONE);
+}
+
+static void draw_title_row_background(const uint pos,
+ const ARegion *region,
+ const SpreadsheetLayout &spreadsheet_layout)
+{
+ immUniformThemeColorShade(TH_BACK, 11);
+ immRecti(pos, 0, region->winy, region->winx, region->winy - spreadsheet_layout.title_row_height);
+}
+
+static void draw_separator_lines(const uint pos,
+ const int scroll_offset_x,
+ const ARegion *region,
+ const SpreadsheetLayout &spreadsheet_layout)
+{
+ immUniformThemeColorShade(TH_BACK, -11);
+
+ immBeginAtMost(GPU_PRIM_LINES, spreadsheet_layout.columns.size() * 2 + 4);
+
+ /* Index column line. */
+ immVertex2i(pos, spreadsheet_layout.index_column_width, region->winy);
+ immVertex2i(pos, spreadsheet_layout.index_column_width, 0);
+
+ /* Title row line. */
+ immVertex2i(pos, 0, region->winy - spreadsheet_layout.title_row_height);
+ immVertex2i(pos, region->winx, region->winy - spreadsheet_layout.title_row_height);
+
+ /* Column separator lines. */
+ int line_x = spreadsheet_layout.index_column_width - scroll_offset_x;
+ for (const int i : spreadsheet_layout.columns.index_range()) {
+ const SpreadsheetColumnLayout &column = spreadsheet_layout.columns[i];
+ line_x += column.width;
+ if (line_x >= spreadsheet_layout.index_column_width) {
+ immVertex2i(pos, line_x, region->winy);
+ immVertex2i(pos, line_x, 0);
}
- default:
- break;
}
- *r_right_x = left_x + width;
+ immEnd();
}
-static void spreadsheet_draw_readonly_table(uiBlock *block,
- const GeometryComponent &component,
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list