[Bf-blender-cvs] [3a97c4056f8] file-browser-grid-view: Proof of Concept: File Browser thumbnail mode using grid view

Julian Eisel noreply at git.blender.org
Thu Jul 21 17:16:40 CEST 2022


Commit: 3a97c4056f8b9f663150a988b9aa9647517c33ed
Author: Julian Eisel
Date:   Thu Jul 21 14:55:18 2022 +0200
Branches: file-browser-grid-view
https://developer.blender.org/rB3a97c4056f8b9f663150a988b9aa9647517c33ed

Proof of Concept: File Browser thumbnail mode using grid view

This was meant as an experiment to see how tangible it is to rewrite the
File Browser UI code to be based on views, starting with the grid view
for thumbnail mode. See T99890.
My initial conclusion is that porting to views is quite doable, but
we'll need some further UI code features to make certain things
possible. Like big "composed" icons, where a file type icon is displayed
on top of a big, generic file icon.

There is a fair bit of stuff here that I'm not happy with. Plus things
like selection, double clicking to open and renaming don't work yet.
It's a start, a proof of concept even :)

===================================================================

M	source/blender/blenkernel/BKE_icons.h
M	source/blender/editors/include/UI_grid_view.hh
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/include/UI_interface_icons.h
M	source/blender/editors/interface/interface.cc
M	source/blender/editors/interface/interface_icons.c
M	source/blender/editors/interface/interface_intern.h
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/interface/views/grid_view.cc
M	source/blender/editors/space_file/CMakeLists.txt
M	source/blender/editors/space_file/file_draw.c
M	source/blender/editors/space_file/file_intern.h
A	source/blender/editors/space_file/file_view_grid.cc
M	source/blender/editors/space_file/filelist.c
M	source/blender/editors/space_file/filelist.h
M	source/blender/editors/space_file/space_file.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_icons.h b/source/blender/blenkernel/BKE_icons.h
index 8d9351806c4..4ab3a2ac904 100644
--- a/source/blender/blenkernel/BKE_icons.h
+++ b/source/blender/blenkernel/BKE_icons.h
@@ -77,7 +77,9 @@ struct PreviewImage;
 struct StudioLight;
 struct bGPDlayer;
 
+#ifndef __cplusplus
 enum eIconSizes;
+#endif
 
 void BKE_icons_init(int first_dyn_id);
 
diff --git a/source/blender/editors/include/UI_grid_view.hh b/source/blender/editors/include/UI_grid_view.hh
index 402c0c8512f..2d5b5f941ed 100644
--- a/source/blender/editors/include/UI_grid_view.hh
+++ b/source/blender/editors/include/UI_grid_view.hh
@@ -194,7 +194,11 @@ class PreviewGridItem : public AbstractGridViewItem {
   std::string label{};
   int preview_icon_id = ICON_NONE;
 
-  PreviewGridItem(StringRef identifier, StringRef label, int preview_icon_id);
+  PreviewGridItem(StringRef identifier, StringRef label, int preview_icon_id = ICON_NONE);
+
+  uiBut *add_preview_button(uiLayout &layout,
+                            int preview_icon_id,
+                            const uchar mono_color[4] = nullptr) const;
 
   void build_grid_tile(uiLayout &layout) const override;
 
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index a8d25b75036..20f2a553a52 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1228,6 +1228,15 @@ uiBut *uiDefIconButO_ptr(uiBlock *block,
                          short width,
                          short height,
                          const char *tip);
+uiBut *uiDefButPadding(uiBlock *block, int x, int y, short width, short height);
+uiBut *uiDefButPreviewTile(uiBlock *block,
+                           int preview_icon_id,
+                           const char *label,
+                           int x,
+                           int y,
+                           short width,
+                           short height,
+                           const uchar mono_color[4]);
 uiBut *uiDefButImage(
     uiBlock *block, void *imbuf, int x, int y, short width, short height, const uchar color[4]);
 uiBut *uiDefButAlert(uiBlock *block, int icon, int x, int y, short width, short height);
@@ -1746,6 +1755,7 @@ struct PointerRNA *UI_but_extra_operator_icon_opptr_get(struct uiButExtraOpIcon
 int UI_preview_tile_size_x(void);
 int UI_preview_tile_size_y(void);
 int UI_preview_tile_size_y_no_label(void);
+rcti UI_preview_tile_but_preview_rect_get(const uiBut *but);
 
 /* Autocomplete
  *
diff --git a/source/blender/editors/include/UI_interface_icons.h b/source/blender/editors/include/UI_interface_icons.h
index a1a98a4b08c..1cfec698680 100644
--- a/source/blender/editors/include/UI_interface_icons.h
+++ b/source/blender/editors/include/UI_interface_icons.h
@@ -96,7 +96,8 @@ int UI_icon_preview_to_render_size(enum eIconSizes size);
  */
 void UI_icon_draw(float x, float y, int icon_id);
 void UI_icon_draw_alpha(float x, float y, int icon_id, float alpha);
-void UI_icon_draw_preview(float x, float y, int icon_id, float aspect, float alpha, int size);
+void UI_icon_draw_preview(
+    float x, float y, int icon_id, float aspect, float alpha, int size, const uchar mono_color[4]);
 
 void UI_icon_draw_ex(float x,
                      float y,
diff --git a/source/blender/editors/interface/interface.cc b/source/blender/editors/interface/interface.cc
index 2f9e69137ed..b6d212b891e 100644
--- a/source/blender/editors/interface/interface.cc
+++ b/source/blender/editors/interface/interface.cc
@@ -4826,6 +4826,37 @@ uiBut *uiDefBut(uiBlock *block,
   return but;
 }
 
+uiBut *uiDefButPadding(uiBlock *block, int x, int y, short width, short height)
+{
+  uiBut *but = ui_def_but(
+      block, UI_BTYPE_LABEL, 0, "", x, y, width, height, nullptr, 0, 0, 0, 0, "");
+  ui_but_update(but);
+  return but;
+}
+
+uiBut *uiDefButPreviewTile(uiBlock *block,
+                           int preview_icon_id,
+                           const char *label,
+                           int x,
+                           int y,
+                           short width,
+                           short height,
+                           const uchar mono_color[4])
+{
+  uiBut *but = ui_def_but(
+      block, UI_BTYPE_PREVIEW_TILE, 0, label, x, y, width, height, nullptr, 0, 0, 0, 0, "");
+  ui_def_but_icon(but,
+                  preview_icon_id,
+                  /* NOLINTNEXTLINE: bugprone-suspicious-enum-usage */
+                  UI_HAS_ICON | UI_BUT_ICON_PREVIEW);
+  if (mono_color) {
+    copy_v4_v4_uchar(but->col, mono_color);
+  }
+
+  ui_but_update(but);
+  return but;
+}
+
 uiBut *uiDefButImage(
     uiBlock *block, void *imbuf, int x, int y, short width, short height, const uchar color[4])
 {
@@ -4993,6 +5024,30 @@ int UI_preview_tile_size_y_no_label(void)
   return round_fl_to_int((96.0f / 20.0f) * UI_UNIT_Y + 2.0f * pad);
 }
 
+#define PREVIEW_PAD 4
+
+rcti UI_preview_tile_but_preview_rect_get(const uiBut *but)
+{
+  rcti rect;
+
+  BLI_rcti_rctf_copy_round(&rect, &but->rect);
+
+  if (but->drawstr[0]) {
+    const uiStyle *style = UI_style_get();
+    const uiFontStyle *fstyle = &style->widget;
+    float font_dims[2] = {0.0f, 0.0f};
+
+    UI_fontstyle_set(fstyle);
+    BLF_width_and_height(
+        fstyle->uifont_id, but->drawstr, BLF_DRAW_STR_DUMMY_MAX, &font_dims[0], &font_dims[1]);
+    /* draw icon in rect above the space reserved for the label */
+    rect.ymin += round_fl_to_int(font_dims[1] + 2 * PREVIEW_PAD);
+  }
+
+  return ui_preview_draw_rect_get(&rect);
+}
+
+#undef PREVIEW_PAD
 #undef PREVIEW_TILE_PAD
 
 static void ui_but_update_and_icon_set(uiBut *but, int icon)
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index c19e842aad8..71bd61764c0 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -1503,6 +1503,7 @@ static void icon_draw_rect(float x,
                            int rh,
                            uint *rect,
                            float alpha,
+                           const uchar mono_rgba[4],
                            const float desaturate)
 {
   int draw_w = w;
@@ -1518,7 +1519,12 @@ static void icon_draw_rect(float x,
     return;
   }
   /* modulate color */
-  const float col[4] = {alpha, alpha, alpha, alpha};
+  float col[4] = {alpha, alpha, alpha, alpha};
+  if (mono_rgba) {
+    /* Optionally use a mono color to recolor the image. */
+    rgba_uchar_to_float(col, mono_rgba);
+    mul_v4_fl(col, alpha);
+  }
 
   float scale_x = 1.0f;
   float scale_y = 1.0f;
@@ -1813,9 +1819,10 @@ static void icon_draw_size(float x,
   if (di->type == ICON_TYPE_IMBUF) {
     ImBuf *ibuf = icon->obj;
 
-    GPU_blend(GPU_BLEND_ALPHA_PREMULT);
-    icon_draw_rect(x, y, w, h, aspect, ibuf->x, ibuf->y, ibuf->rect, alpha, desaturate);
-    GPU_blend(GPU_BLEND_ALPHA);
+    /* TODO preview images are premultiplied apparently (see ICON_TYPE_PREVIEW). */
+    //    GPU_blend(GPU_BLEND_ALPHA_PREMULT);
+    icon_draw_rect(x, y, w, h, aspect, ibuf->x, ibuf->y, ibuf->rect, alpha, mono_rgba, desaturate);
+    //    GPU_blend(GPU_BLEND_ALPHA);
   }
   else if (di->type == ICON_TYPE_VECTOR) {
     /* vector icons use the uiBlock transformation, they are not drawn
@@ -1854,7 +1861,7 @@ static void icon_draw_size(float x,
     }
 
     GPU_blend(GPU_BLEND_ALPHA_PREMULT);
-    icon_draw_rect(x, y, w, h, aspect, w, h, ibuf->rect, alpha, desaturate);
+    icon_draw_rect(x, y, w, h, aspect, w, h, ibuf->rect, alpha, NULL, desaturate);
     GPU_blend(GPU_BLEND_ALPHA);
   }
   else if (di->type == ICON_TYPE_EVENT) {
@@ -1922,7 +1929,7 @@ static void icon_draw_size(float x,
       return;
     }
 
-    icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, desaturate);
+    icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, NULL, desaturate);
   }
   else if (di->type == ICON_TYPE_PREVIEW) {
     PreviewImage *pi = (icon->id_type != 0) ? BKE_previewimg_id_ensure((ID *)icon->obj) :
@@ -1938,7 +1945,7 @@ static void icon_draw_size(float x,
       /* Preview images use premultiplied alpha. */
       GPU_blend(GPU_BLEND_ALPHA_PREMULT);
       icon_draw_rect(
-          x, y, w, h, aspect, pi->w[size], pi->h[size], pi->rect[size], alpha, desaturate);
+          x, y, w, h, aspect, pi->w[size], pi->h[size], pi->rect[size], alpha, NULL, desaturate);
       GPU_blend(GPU_BLEND_ALPHA);
     }
   }
@@ -2433,9 +2440,10 @@ void UI_icon_draw_alpha(float x, float y, int icon_id, float alpha)
   UI_icon_draw_ex(x, y, icon_id, U.inv_dpi_fac, alpha, 0.0f, NULL, false);
 }
 
-void UI_icon_draw_preview(float x, float y, int icon_id, float aspect, float alpha, int size)
+void UI_icon_draw_preview(
+    float x, float y, int icon_id, float aspect, float alpha, int size, const uchar mono_color[4])
 {
-  icon_draw_size(x, y, icon_id, aspect, alpha, ICON_SIZE_PREVIEW, size, false, NULL, false);
+  icon_draw_size(x, y, icon_id, aspect, alpha, ICON_SIZE_PREVIEW, size, 0.0f, mono_color, false);
 }
 
 void UI_icon_draw_ex(float x,
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 03b9d03a6e3..ade238a86ef 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -1236,6 +1236,8 @@ void ui_draw_preview_item(const struct uiFontStyle *fstyle,
                           int iconid,
                           int but_flag,
                           eFontStyle_Align text_align);
+rcti ui_preview_draw_rect_get(const rcti *bounds_rect);
+
 /**
  * Version of #ui_draw_preview_item() that does not draw the menu background and item text based on
  * state. It just draws the preview and text directly.
@@ -1245,6 +1247,7 @@ void ui_draw_preview_item_stateless(const struct uiFontStyle *fstyle,
                                     const char *name,
                                     int iconid,
                                     const uchar text_col[4],
+                                    const uchar mono_col[4],
                                    

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list