[Bf-blender-cvs] [667af6cf411] master: Refactor grid and scale indicator text drawing

Jacques Lucke noreply at git.blender.org
Thu May 2 12:04:54 CEST 2019


Commit: 667af6cf411918ba181afc1a7d6bcb474f9fadb8
Author: Jacques Lucke
Date:   Thu May 2 12:00:12 2019 +0200
Branches: master
https://developer.blender.org/rB667af6cf411918ba181afc1a7d6bcb474f9fadb8

Refactor grid and scale indicator text drawing

This affects the timeline, dopesheet, graph editor, sequencer,
clip editor and nla editor.

Removed structs and enums: `V2D_ARG_DUMMY`, `eView2D_Units`,
`eView2D_Clamp`, `eView2D_Gridlines`, `View2DGrid`.

A main goal of this refactor is to get rid of the very generic
`View2DGrid` struct. The drawing code became very complex
because there were many different combinations of settings.

This refactor implements a different approach.
Instead of one very generic API, there are many slighly
different functions that do exactly, what we need in the
different editors. Only very little code is duplicated,
because the API functions compose some shared low level code.

This structure makes the code much easier to debug and change,
because every function has much fewer responsibilities.

Additionally, this refactor fixes some long standing bugs.
E.g. when `Show Seconds` is enabled, you zoom in and pan the view.
Or that the step size between displayed frame numbers was
always `>= 2`, no matter how close you zoom in.

Reviewers: brecht

Differential Revision: https://developer.blender.org/D4776

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

M	source/blender/editors/include/UI_view2d.h
M	source/blender/editors/interface/CMakeLists.txt
M	source/blender/editors/interface/view2d.c
A	source/blender/editors/interface/view2d_draw.c
M	source/blender/editors/space_action/space_action.c
M	source/blender/editors/space_clip/clip_graph_draw.c
M	source/blender/editors/space_clip/space_clip.c
M	source/blender/editors/space_graph/graph_draw.c
M	source/blender/editors/space_graph/graph_intern.h
M	source/blender/editors/space_graph/space_graph.c
M	source/blender/editors/space_nla/space_nla.c
M	source/blender/editors/space_sequencer/sequencer_draw.c
M	source/blender/editors/transform/transform_snap.c

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

diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h
index fee1efcf25b..07dbb49ac07 100644
--- a/source/blender/editors/include/UI_view2d.h
+++ b/source/blender/editors/include/UI_view2d.h
@@ -56,40 +56,7 @@ enum eView2D_CommonViewTypes {
   V2D_COMMONVIEW_PANELS_UI,
 };
 
-/* ---- Defines for Scroller/Grid Arguments ----- */
-
-/* 'dummy' argument to pass when argument is irrelevant */
-#define V2D_ARG_DUMMY -1
-
-/* Grid units */
-enum eView2D_Units {
-  /* for drawing time */
-  V2D_UNIT_SECONDS = 0,
-  V2D_UNIT_FRAMES,
-  V2D_UNIT_FRAMESCALE,
-
-  /* for drawing values */
-  V2D_UNIT_VALUES,
-};
-
-/* clamping of grid values to whole numbers */
-enum eView2D_Clamp {
-  V2D_GRID_NOCLAMP = 0,
-  V2D_GRID_CLAMP,
-};
-
-/* flags for grid-lines to draw */
-enum eView2D_Gridlines {
-  V2D_HORIZONTAL_LINES = (1 << 0),
-  V2D_VERTICAL_LINES = (1 << 1),
-  V2D_HORIZONTAL_AXIS = (1 << 2),
-  V2D_VERTICAL_AXIS = (1 << 3),
-  V2D_HORIZONTAL_FINELINES = (1 << 4),
-
-  V2D_GRIDLINES_MAJOR = (V2D_VERTICAL_LINES | V2D_VERTICAL_AXIS | V2D_HORIZONTAL_LINES |
-                         V2D_HORIZONTAL_AXIS),
-  V2D_GRIDLINES_ALL = (V2D_GRIDLINES_MAJOR | V2D_HORIZONTAL_FINELINES),
-};
+/* ---- Defines for Scroller Arguments ----- */
 
 /* ------ Defines for Scrollers ----- */
 
@@ -124,7 +91,6 @@ enum eView2D_Gridlines {
 /* Type definitions:                          */
 
 struct View2D;
-struct View2DGrid;
 struct View2DScrollers;
 
 struct ARegion;
@@ -135,7 +101,6 @@ struct bScreen;
 struct rctf;
 struct wmKeyConfig;
 
-typedef struct View2DGrid View2DGrid;
 typedef struct View2DScrollers View2DScrollers;
 
 /* ----------------------------------------- */
@@ -159,37 +124,58 @@ bool UI_view2d_tab_set(struct View2D *v2d, int tab);
 void UI_view2d_zoom_cache_reset(void);
 
 /* view matrix operations */
-void UI_view2d_view_ortho(struct View2D *v2d);
+void UI_view2d_view_ortho(const struct View2D *v2d);
 void UI_view2d_view_orthoSpecial(struct ARegion *ar, struct View2D *v2d, const bool xaxis);
 void UI_view2d_view_restore(const struct bContext *C);
 
 /* grid drawing */
-View2DGrid *UI_view2d_grid_calc(struct Scene *scene,
-                                struct View2D *v2d,
-                                short xunits,
-                                short xclamp,
-                                short yunits,
-                                short yclamp,
-                                int winx,
-                                int winy);
-void UI_view2d_grid_draw(struct View2D *v2d, View2DGrid *grid, int flag);
 void UI_view2d_constant_grid_draw(struct View2D *v2d, float step);
 void UI_view2d_multi_grid_draw(
     struct View2D *v2d, int colorid, float step, int level_size, int totlevels);
-void UI_view2d_grid_size(View2DGrid *grid, float *r_dx, float *r_dy);
-void UI_view2d_grid_draw_numbers_horizontal(const struct Scene *scene,
-                                            const struct View2D *v2d,
-                                            const View2DGrid *grid,
-                                            const struct rcti *rect,
-                                            int unit,
-                                            bool whole_numbers_only);
-void UI_view2d_grid_draw_numbers_vertical(const struct Scene *scene,
-                                          const struct View2D *v2d,
-                                          const View2DGrid *grid,
-                                          const struct rcti *rect,
-                                          int unit,
-                                          float text_offset);
-void UI_view2d_grid_free(View2DGrid *grid);
+
+void UI_view2d_draw_lines_y__values(const struct View2D *v2d);
+void UI_view2d_draw_lines_x__values(const struct View2D *v2d);
+void UI_view2d_draw_lines_x__discrete_values(const struct View2D *v2d);
+void UI_view2d_draw_lines_x__discrete_time(const struct View2D *v2d, const struct Scene *scene);
+void UI_view2d_draw_lines_x__discrete_frames_or_seconds(const struct View2D *v2d,
+                                                        const struct Scene *scene,
+                                                        bool display_seconds);
+void UI_view2d_draw_lines_x__frames_or_seconds(const struct View2D *v2d,
+                                               const struct Scene *scene,
+                                               bool display_seconds);
+
+float UI_view2d_grid_resolution_x__frames_or_seconds(const struct View2D *v2d,
+                                                     const struct Scene *scene,
+                                                     bool display_seconds);
+float UI_view2d_grid_resolution_y__values(const struct View2D *v2d);
+
+/* scale indicator text drawing */
+void UI_view2d_draw_scale_y__values(const struct ARegion *ar,
+                                    const struct View2D *v2d,
+                                    const struct rcti *rect);
+void UI_view2d_draw_scale_y__block(const struct ARegion *ar,
+                                   const struct View2D *v2d,
+                                   const struct rcti *rect);
+void UI_view2d_draw_scale_x__values(const struct ARegion *ar,
+                                    const struct View2D *v2d,
+                                    const struct rcti *rect);
+void UI_view2d_draw_scale_x__discrete_values(const struct ARegion *ar,
+                                             const struct View2D *v2d,
+                                             const struct rcti *rect);
+void UI_view2d_draw_scale_x__discrete_time(const struct ARegion *ar,
+                                           const struct View2D *v2d,
+                                           const struct rcti *rect,
+                                           const struct Scene *scene);
+void UI_view2d_draw_scale_x__discrete_frames_or_seconds(const struct ARegion *ar,
+                                                        const struct View2D *v2d,
+                                                        const struct rcti *rect,
+                                                        const struct Scene *scene,
+                                                        bool display_seconds);
+void UI_view2d_draw_scale_x__frames_or_seconds(const struct ARegion *ar,
+                                               const struct View2D *v2d,
+                                               const struct rcti *rect,
+                                               const struct Scene *scene,
+                                               bool display_seconds);
 
 /* scrollbar drawing */
 View2DScrollers *UI_view2d_scrollers_calc(struct View2D *v2d, const struct rcti *mask_custom);
diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt
index 55a44b4d314..6ab1761e7f8 100644
--- a/source/blender/editors/interface/CMakeLists.txt
+++ b/source/blender/editors/interface/CMakeLists.txt
@@ -72,6 +72,7 @@ set(SRC
   interface_widgets.c
   resources.c
   view2d.c
+  view2d_draw.c
   view2d_ops.c
 
   interface_eyedropper_intern.h
diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c
index 072497dbb74..58d26c4a840 100644
--- a/source/blender/editors/interface/view2d.c
+++ b/source/blender/editors/interface/view2d.c
@@ -31,12 +31,14 @@
 #include "DNA_scene_types.h"
 #include "DNA_userdef_types.h"
 
+#include "BLI_array.h"
 #include "BLI_utildefines.h"
 #include "BLI_link_utils.h"
 #include "BLI_rect.h"
 #include "BLI_math.h"
 #include "BLI_memarena.h"
 #include "BLI_timecode.h"
+#include "BLI_string.h"
 
 #include "BKE_context.h"
 #include "BKE_screen.h"
@@ -1117,7 +1119,7 @@ void UI_view2d_zoom_cache_reset(void)
 /* View Matrix Setup */
 
 /* mapping function to ensure 'cur' draws extended over the area where sliders are */
-static void view2d_map_cur_using_mask(View2D *v2d, rctf *r_curmasked)
+static void view2d_map_cur_using_mask(const View2D *v2d, rctf *r_curmasked)
 {
   *r_curmasked = v2d->cur;
 
@@ -1149,7 +1151,7 @@ static void view2d_map_cur_using_mask(View2D *v2d, rctf *r_curmasked)
 }
 
 /* Set view matrices to use 'cur' rect as viewing frame for View2D drawing */
-void UI_view2d_view_ortho(View2D *v2d)
+void UI_view2d_view_ortho(const View2D *v2d)
 {
   rctf curmasked;
   const int sizex = BLI_rcti_size_x(&v2d->mask);
@@ -1238,337 +1240,6 @@ void UI_view2d_view_restore(const bContext *C)
 /* *********************************************************************** */
 /* Gridlines */
 
-/* View2DGrid is typedef'd in UI_view2d.h */
-struct View2DGrid {
-  float dx, dy;         /* stepsize (in pixels) between gridlines */
-  float startx, starty; /* initial coordinates to start drawing grid from */
-  int powerx, powery;   /* step as power of 10 */
-};
-
-/* --------------- */
-
-/* try to write step as a power of 10 */
-static void step_to_grid(float *step, const int unit, int *r_power)
-{
-  const float loga = (float)log10(*step);
-  float rem;
-
-  int power = (int)(loga);
-
-  rem = loga - power;
-  rem = (float)pow(10.0, rem);
-
-  if (loga < 0.0f) {
-    if (rem < 0.2f) {
-      rem = 0.2f;
-    }
-    else if (rem < 0.5f) {
-      rem = 0.5f;
-    }
-    else {
-      rem = 1.0f;
-    }
-
-    *step = rem * (float)pow(10.0, power);
-
-    /* for frames, we want 1.0 frame intervals only */
-    if (unit == V2D_UNIT_FRAMES) {
-      rem = 1.0f;
-      /* use 2 since there are grid lines drawn in between,
-       * this way to get 1 line per frame */
-      *step = 2.0f;
-    }
-
-    /* prevents printing 1.0 2.0 3.0 etc */
-    if (rem == 1.0f) {
-      power++;
-    }
-  }
-  else {
-    if (rem < 2.0f) {
-      rem = 2.0f;
-    }
-    else if (rem < 5.0f) {
-      rem = 5.0f;
-    }
-    else {
-      rem = 10.0f;
-    }
-
-    *step = rem * (float)pow(10.0, power);
-
-    power++;
-    /* prevents printing 1.0, 2.0, 3.0, etc. */
-    if (rem == 10.0f) {
-      power++;
-    }
-  }
-
-  *r_power = power;
-}
-
-/**
- * Initialize settings necessary for drawing gridlines in a 2d-view
- *
- * - Currently, will return pointer to View2DGrid struct that needs to
- *   be freed with UI_vie

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list