[Bf-blender-cvs] [9d6789115aa] master: Cleanup: Move panel category drawing to proper section

Hans Goudey noreply at git.blender.org
Thu Aug 27 19:35:36 CEST 2020


Commit: 9d6789115aaf5b3cc8b6c4658b923cc281fb07c0
Author: Hans Goudey
Date:   Thu Aug 27 12:33:27 2020 -0500
Branches: master
https://developer.blender.org/rB9d6789115aaf5b3cc8b6c4658b923cc281fb07c0

Cleanup: Move panel category drawing to proper section

Somehow the panel category drawing functions ended up in the middle
of the region event handling code. This commit moves them to their
own section next to the rest of the drawing code.

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

M	source/blender/editors/interface/interface_panel.c

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

diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index 0b4bf0493f4..fcbda4864f3 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -1101,1205 +1101,1207 @@ void ui_draw_aligned_panel(const uiStyle *style,
   }
 }
 
-/************************** panel alignment *************************/
+/********************** category drawing ***************************/
 
-static int get_panel_size_y(const Panel *panel)
+static void imm_buf_append(
+    float vbuf[][2], uchar cbuf[][3], float x, float y, const uchar col[3], int *index)
 {
-  if (panel->type && (panel->type->flag & PNL_NO_HEADER)) {
-    return panel->sizey;
-  }
-
-  return PNL_HEADER + panel->sizey;
+  ARRAY_SET_ITEMS(vbuf[*index], x, y);
+  ARRAY_SET_ITEMS(cbuf[*index], UNPACK3(col));
+  (*index)++;
 }
 
-static int get_panel_real_size_y(const Panel *panel)
+/* based on UI_draw_roundbox, check on making a version which allows us to skip some sides */
+static void ui_panel_category_draw_tab(bool filled,
+                                       float minx,
+                                       float miny,
+                                       float maxx,
+                                       float maxy,
+                                       float rad,
+                                       const int roundboxtype,
+                                       const bool use_highlight,
+                                       const bool use_shadow,
+                                       const bool use_flip_x,
+                                       const uchar highlight_fade[3],
+                                       const uchar col[3])
 {
-  const int sizey = (panel->flag & PNL_CLOSED) ? 0 : panel->sizey;
+  float vec[4][2] = {{0.195, 0.02}, {0.55, 0.169}, {0.831, 0.45}, {0.98, 0.805}};
 
-  if (panel->type && (panel->type->flag & PNL_NO_HEADER)) {
-    return sizey;
+  /* mult */
+  for (int a = 0; a < 4; a++) {
+    mul_v2_fl(vec[a], rad);
   }
 
-  return PNL_HEADER + sizey;
-}
-
-int UI_panel_size_y(const Panel *panel)
-{
-  return get_panel_real_size_y(panel);
-}
-
-/* this function is needed because uiBlock and Panel itself don't
- * change sizey or location when closed */
-static int get_panel_real_ofsy(Panel *panel)
-{
-  if (panel->flag & PNL_CLOSED) {
-    return panel->ofsy + panel->sizey;
+  uint vert_len = 0;
+  if (use_highlight) {
+    vert_len += (roundboxtype & UI_CNR_TOP_RIGHT) ? 6 : 1;
+    vert_len += (roundboxtype & UI_CNR_TOP_LEFT) ? 6 : 1;
   }
-  return panel->ofsy;
-}
-
-bool UI_panel_is_dragging(const struct Panel *panel)
-{
-  uiHandlePanelData *data = panel->activedata;
-  if (!data) {
-    return false;
+  if (use_highlight && !use_shadow) {
+    vert_len++;
   }
+  else {
+    vert_len += (roundboxtype & UI_CNR_BOTTOM_RIGHT) ? 6 : 1;
+    vert_len += (roundboxtype & UI_CNR_BOTTOM_LEFT) ? 6 : 1;
+  }
+  /* Maximum size. */
+  float vbuf[24][2];
+  uchar cbuf[24][3];
+  int buf_index = 0;
 
-  return data->is_drag_drop;
-}
-
-/**
- * \note about sorting;
- * the sortorder has a lower value for new panels being added.
- * however, that only works to insert a single panel, when more new panels get
- * added the coordinates of existing panels and the previously stored to-be-inserted
- * panels do not match for sorting
- */
-
-static int find_highest_panel(const void *a1, const void *a2)
-{
-  const PanelSort *ps1 = a1, *ps2 = a2;
+  /* start with corner right-top */
+  if (use_highlight) {
+    if (roundboxtype & UI_CNR_TOP_RIGHT) {
+      imm_buf_append(vbuf, cbuf, maxx, maxy - rad, col, &buf_index);
+      for (int a = 0; a < 4; a++) {
+        imm_buf_append(vbuf, cbuf, maxx - vec[a][1], maxy - rad + vec[a][0], col, &buf_index);
+      }
+      imm_buf_append(vbuf, cbuf, maxx - rad, maxy, col, &buf_index);
+    }
+    else {
+      imm_buf_append(vbuf, cbuf, maxx, maxy, col, &buf_index);
+    }
 
-  /* stick uppermost header-less panels to the top of the region -
-   * prevent them from being sorted (multiple header-less panels have to be sorted though) */
-  if (ps1->panel->type->flag & PNL_NO_HEADER && ps2->panel->type->flag & PNL_NO_HEADER) {
-    /* skip and check for ofs and sortorder below */
-  }
-  if (ps1->panel->type->flag & PNL_NO_HEADER) {
-    return -1;
-  }
-  if (ps2->panel->type->flag & PNL_NO_HEADER) {
-    return 1;
+    /* corner left-top */
+    if (roundboxtype & UI_CNR_TOP_LEFT) {
+      imm_buf_append(vbuf, cbuf, minx + rad, maxy, col, &buf_index);
+      for (int a = 0; a < 4; a++) {
+        imm_buf_append(vbuf, cbuf, minx + rad - vec[a][0], maxy - vec[a][1], col, &buf_index);
+      }
+      imm_buf_append(vbuf, cbuf, minx, maxy - rad, col, &buf_index);
+    }
+    else {
+      imm_buf_append(vbuf, cbuf, minx, maxy, col, &buf_index);
+    }
   }
 
-  if (ps1->panel->ofsy + ps1->panel->sizey < ps2->panel->ofsy + ps2->panel->sizey) {
-    return 1;
-  }
-  if (ps1->panel->ofsy + ps1->panel->sizey > ps2->panel->ofsy + ps2->panel->sizey) {
-    return -1;
-  }
-  if (ps1->panel->sortorder > ps2->panel->sortorder) {
-    return 1;
+  if (use_highlight && !use_shadow) {
+    imm_buf_append(
+        vbuf, cbuf, minx, miny + rad, highlight_fade ? col : highlight_fade, &buf_index);
   }
-  if (ps1->panel->sortorder < ps2->panel->sortorder) {
-    return -1;
+  else {
+    /* corner left-bottom */
+    if (roundboxtype & UI_CNR_BOTTOM_LEFT) {
+      imm_buf_append(vbuf, cbuf, minx, miny + rad, col, &buf_index);
+      for (int a = 0; a < 4; a++) {
+        imm_buf_append(vbuf, cbuf, minx + vec[a][1], miny + rad - vec[a][0], col, &buf_index);
+      }
+      imm_buf_append(vbuf, cbuf, minx + rad, miny, col, &buf_index);
+    }
+    else {
+      imm_buf_append(vbuf, cbuf, minx, miny, col, &buf_index);
+    }
+
+    /* corner right-bottom */
+    if (roundboxtype & UI_CNR_BOTTOM_RIGHT) {
+      imm_buf_append(vbuf, cbuf, maxx - rad, miny, col, &buf_index);
+      for (int a = 0; a < 4; a++) {
+        imm_buf_append(vbuf, cbuf, maxx - rad + vec[a][0], miny + vec[a][1], col, &buf_index);
+      }
+      imm_buf_append(vbuf, cbuf, maxx, miny + rad, col, &buf_index);
+    }
+    else {
+      imm_buf_append(vbuf, cbuf, maxx, miny, col, &buf_index);
+    }
   }
 
-  return 0;
-}
+  if (use_flip_x) {
+    const float midx = (minx + maxx) / 2.0f;
+    for (int i = 0; i < buf_index; i++) {
+      vbuf[i][0] = midx - (vbuf[i][0] - midx);
+    }
+  }
 
-static int compare_panel(const void *a1, const void *a2)
-{
-  const PanelSort *ps1 = a1, *ps2 = a2;
+  GPUVertFormat *format = immVertexFormat();
+  const uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+  uint color = GPU_vertformat_attr_add(
+      format, "color", GPU_COMP_U8, 3, GPU_FETCH_INT_TO_FLOAT_UNIT);
 
-  if (ps1->panel->sortorder > ps2->panel->sortorder) {
-    return 1;
-  }
-  if (ps1->panel->sortorder < ps2->panel->sortorder) {
-    return -1;
+  immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
+  immBegin(filled ? GPU_PRIM_TRI_FAN : GPU_PRIM_LINE_STRIP, vert_len);
+  for (int i = 0; i < buf_index; i++) {
+    immAttr3ubv(color, cbuf[i]);
+    immVertex2fv(pos, vbuf[i]);
   }
-
-  return 0;
+  immEnd();
+  immUnbindProgram();
 }
 
-static void align_sub_panels(Panel *panel)
+/**
+ * Draw vertical tabs on the left side of the region,
+ * one tab per category.
+ */
+void UI_panel_category_draw_all(ARegion *region, const char *category_id_active)
 {
-  /* Position sub panels. */
-  int ofsy = panel->ofsy + panel->sizey - panel->blocksizey;
+  /* no tab outlines for */
+  // #define USE_FLAT_INACTIVE
+  const bool is_left = RGN_ALIGN_ENUM_FROM_MASK(region->alignment != RGN_ALIGN_RIGHT);
+  View2D *v2d = &region->v2d;
+  const uiStyle *style = UI_style_get();
+  const uiFontStyle *fstyle = &style->widget;
+  const int fontid = fstyle->uifont_id;
+  short fstyle_points = fstyle->points;
+  const float aspect = ((uiBlock *)region->uiblocks.first)->aspect;
+  const float zoom = 1.0f / aspect;
+  const int px = max_ii(1, round_fl_to_int(U.pixelsize));
+  const int px_x_sign = is_left ? px : -px;
+  const int category_tabs_width = round_fl_to_int(UI_PANEL_CATEGORY_MARGIN_WIDTH * zoom);
+  const float dpi_fac = UI_DPI_FAC;
+  /* padding of tabs around text */
+  const int tab_v_pad_text = round_fl_to_int((2 + ((px * 3) * dpi_fac)) * zoom);
+  /* padding between tabs */
+  const int tab_v_pad = round_fl_to_int((4 + (2 * px * dpi_fac)) * zoom);
+  const float tab_curve_radius = ((px * 3) * dpi_fac) * zoom;
+  /* We flip the tab drawing, so always use these flags. */
+  const int roundboxtype = UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT;
+  bool is_alpha;
+  bool do_scaletabs = false;
+#ifdef USE_FLAT_INACTIVE
+  bool is_active_prev = false;
+#endif
+  float scaletabs = 1.0f;
+  /* same for all tabs */
+  /* intentionally dont scale by 'px' */
+  const int rct_xmin = is_left ? v2d->mask.xmin + 3 : (v2d->mask.xmax - category_tabs_width);
+  const int rct_xmax = is_left ? v2d->mask.xmin + category_tabs_width : (v2d->mask.xmax - 3);
+  const int text_v_ofs = (rct_xmax - rct_xmin) * 0.3f;
 
-  LISTBASE_FOREACH (Panel *, pachild, &panel->children) {
-    if (pachild->runtime_flag & PNL_ACTIVE) {
-      pachild->ofsx = panel->ofsx;
-      pachild->ofsy = ofsy - get_panel_size_y(pachild);
-      ofsy -= get_panel_real_size_y(pachild);
+  int y_ofs = tab_v_pad;
 
-      if (pachild->children.first) {
-        align_sub_panels(pachild);
-      }
-    }
-  }
-}
+  /* Primary theme colors */
+  uchar theme_col_back[4];
+  uchar theme_col_text[3];
+  uchar theme_col_text_hi[3];
 
-/* this doesn't draw */
-/* returns 1 when it did something */
-static bool uiAlignPanelStep(ARegion *region, const float fac, const bool drag)
-{
-  int i;
+  /* Tab colors */
+  uchar theme_col_tab_bg[4];
+  uchar theme_col_tab_active[3];
+  uchar theme_col_tab_inactive[3];
 
-  /* count active, not tabbed panels */
-  int tot = 0;
-  LISTBASE_FOREACH (Panel *, panel, &region->panels) {
-    if (panel->runtime_flag & PNL_ACTIVE) {
-      tot++;
-    }
-  }
+  /* Secondary theme colors */
+  uchar theme_col_tab_outline[3];
+  uchar theme_col_tab_divider[3]; /* line t

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list