GP: Allow canvas grid with different scales in X/Y
authorAntonioya <blendergit@gmail.com>
Wed, 3 Oct 2018 20:42:45 +0000 (22:42 +0200)
committerAntonioya <blendergit@gmail.com>
Wed, 3 Oct 2018 20:42:45 +0000 (22:42 +0200)
Now it's possible create rectangular shapes and disable the subdivisions to get only a rectangle

release/scripts/startup/bl_ui/space_view3d.py
source/blender/blenloader/intern/versioning_280.c
source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
source/blender/editors/space_view3d/space_view3d.c
source/blender/makesdna/DNA_view3d_types.h
source/blender/makesrna/intern/rna_space.c

index 05a009b9b190c93add5cc5c97a9fdf5f91e952dd..71cc129d222365301172ea2c6b9037f3b153f5ee 100644 (file)
@@ -4924,7 +4924,9 @@ class VIEW3D_PT_overlay_gpencil_options(Panel):
 
         if overlay.use_gpencil_grid:
             row = layout.row(align=True)
-            row.prop(overlay, "gpencil_grid_scale")
+            col = row.column()
+            col.prop(overlay, "gpencil_grid_scale")
+            row = layout.row(align=True)
             col = row.column()
             col.prop(overlay, "gpencil_grid_lines", text="Subdivisions")
             col.prop(overlay, "gpencil_grid_axis", text="Plane")
index 7d059d6f996be6feb97562932eb04095461fa98f..1e2ae48ccb16b2e23ca1ec29a4f60f78c3f9f66d 100644 (file)
@@ -1102,7 +1102,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
                                        for (SpaceLink *sl = area->spacedata.first; sl; sl = sl->next) {
                                                if (sl->spacetype == SPACE_VIEW3D) {
                                                        View3D *v3d = (View3D *)sl;
-                                                       v3d->overlay.gpencil_grid_scale = 1.0f; // Scale
+                                                       ARRAY_SET_ITEMS(v3d->overlay.gpencil_grid_scale, 1.0f, 1.0f); // Scale
                                                        v3d->overlay.gpencil_grid_lines = GP_DEFAULT_GRID_LINES; // NUmber of lines
                                                        v3d->overlay.gpencil_paper_opacity = 0.5f;
                                                        v3d->overlay.gpencil_grid_axis = V3D_GP_GRID_AXIS_Y;
@@ -1882,7 +1882,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
                                        for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
                                                if (sl->spacetype == SPACE_VIEW3D) {
                                                        View3D *v3d = (View3D *)sl;
-                                                       v3d->overlay.gpencil_grid_scale = 1.0f;
+                                                       ARRAY_SET_ITEMS(v3d->overlay.gpencil_grid_scale, 1.0f, 1.0f);
                                                }
                                        }
                                }
index 63e05e186dd672f70a911f0eccdad029c8305118..3edeb78fbdc865749942ec4223ada7ced7a064b1 100644 (file)
@@ -654,8 +654,11 @@ GPUBatch *DRW_gpencil_get_grid(void)
        float col_grid[4];
 
        /* verify we have something to draw and valid values */
-       if (v3d->overlay.gpencil_grid_scale == 0.0f) {
-               v3d->overlay.gpencil_grid_scale = 1.0f;
+       if (v3d->overlay.gpencil_grid_scale[0] == 0.0f) {
+               v3d->overlay.gpencil_grid_scale[0] = 1.0f;
+       }
+       if (v3d->overlay.gpencil_grid_scale[1] == 0.0f) {
+               v3d->overlay.gpencil_grid_scale[1] = 1.0f;
        }
 
        if (v3d->overlay.gpencil_grid_opacity < 0.1f) {
@@ -694,9 +697,10 @@ GPUBatch *DRW_gpencil_get_grid(void)
 
        const char *grid_unit = NULL;
        const int gridlines = (v3d->overlay.gpencil_grid_lines <= 0) ? 1 : v3d->overlay.gpencil_grid_lines;
-       const float grid_scale = v3d->overlay.gpencil_grid_scale * ED_scene_grid_scale(scene, &grid_unit);
-       const float grid = grid_scale;
-       const float space = (grid_scale / gridlines);
+       const float grid_w = v3d->overlay.gpencil_grid_scale[0] * ED_scene_grid_scale(scene, &grid_unit);
+       const float grid_h = v3d->overlay.gpencil_grid_scale[1] * ED_scene_grid_scale(scene, &grid_unit);
+       const float space_w = (grid_w / gridlines);
+       const float space_h = (grid_h / gridlines);
 
        const uint vertex_len = 2 * (gridlines * 4 + 2);
 
@@ -713,36 +717,37 @@ GPUBatch *DRW_gpencil_get_grid(void)
        int idx = 0;
 
        for (int a = 1; a <= gridlines; a++) {
-               const float line = a * space;
+               const float line_w = a * space_w;
+               const float line_h = a * space_h;
 
-               set_grid_point(vbo, idx, col_grid, pos_id, color_id, -grid, -line, axis);
+               set_grid_point(vbo, idx, col_grid, pos_id, color_id, -grid_w, -line_h, axis);
                idx++;
-               set_grid_point(vbo, idx, col_grid, pos_id, color_id, +grid, -line, axis);
+               set_grid_point(vbo, idx, col_grid, pos_id, color_id, +grid_w, -line_h, axis);
                idx++;
-               set_grid_point(vbo, idx, col_grid, pos_id, color_id, -grid, +line, axis);
+               set_grid_point(vbo, idx, col_grid, pos_id, color_id, -grid_w, +line_h, axis);
                idx++;
-               set_grid_point(vbo, idx, col_grid, pos_id, color_id, +grid, +line, axis);
+               set_grid_point(vbo, idx, col_grid, pos_id, color_id, +grid_w, +line_h, axis);
                idx++;
 
-               set_grid_point(vbo, idx, col_grid, pos_id, color_id, -line, -grid, axis);
+               set_grid_point(vbo, idx, col_grid, pos_id, color_id, -line_w, -grid_h, axis);
                idx++;
-               set_grid_point(vbo, idx, col_grid, pos_id, color_id, -line, +grid, axis);
+               set_grid_point(vbo, idx, col_grid, pos_id, color_id, -line_w, +grid_h, axis);
                idx++;
-               set_grid_point(vbo, idx, col_grid, pos_id, color_id, +line, -grid, axis);
+               set_grid_point(vbo, idx, col_grid, pos_id, color_id, +line_w, -grid_h, axis);
                idx++;
-               set_grid_point(vbo, idx, col_grid, pos_id, color_id, +line, +grid, axis);
+               set_grid_point(vbo, idx, col_grid, pos_id, color_id, +line_w, +grid_h, axis);
                idx++;
        }
        /* center lines */
        if (do_center) {
-               set_grid_point(vbo, idx, col_grid, pos_id, color_id, -grid, 0.0f, axis);
+               set_grid_point(vbo, idx, col_grid, pos_id, color_id, -grid_w, 0.0f, axis);
                idx++;
-               set_grid_point(vbo, idx, col_grid, pos_id, color_id, +grid, 0.0f, axis);
+               set_grid_point(vbo, idx, col_grid, pos_id, color_id, +grid_w, 0.0f, axis);
                idx++;
 
-               set_grid_point(vbo, idx, col_grid, pos_id, color_id, 0.0f, -grid, axis);
+               set_grid_point(vbo, idx, col_grid, pos_id, color_id, 0.0f, -grid_h, axis);
                idx++;
-               set_grid_point(vbo, idx, col_grid, pos_id, color_id, 0.0f, +grid, axis);
+               set_grid_point(vbo, idx, col_grid, pos_id, color_id, 0.0f, +grid_h, axis);
                idx++;
        }
        return GPU_batch_create_ex(GPU_PRIM_LINES, vbo, NULL, GPU_BATCH_OWNS_VBO);
index 1cfb60f808c53d96a6dbedfe8604af4eb1a72441..6f6b94e000c4f0d03cb12adabd6646606a0a333d 100644 (file)
@@ -350,7 +350,7 @@ static SpaceLink *view3d_new(const ScrArea *UNUSED(sa), const Scene *scene)
        v3d->near = 0.01f;
        v3d->far = 1000.0f;
 
-       v3d->overlay.gpencil_grid_scale = 1.0; // Scales
+       ARRAY_SET_ITEMS(v3d->overlay.gpencil_grid_scale, 1.0f, 1.0f); // Scales
        v3d->overlay.gpencil_grid_lines = GP_DEFAULT_GRID_LINES; // NUmber of Lines
        v3d->overlay.gpencil_paper_opacity = 0.5f;
        v3d->overlay.gpencil_grid_axis = V3D_GP_GRID_AXIS_Y;
index c73def54cc664e2ed6283b3ef74030eb51aae5b6..7876153cbce4ffadf59575c99f319a14e23612d5 100644 (file)
@@ -188,10 +188,9 @@ typedef struct View3DOverlay {
 
        /* Other settings */
        float wireframe_threshold;
-       char _pad0[4];
 
        /* grease pencil settings */
-       float gpencil_grid_scale;
+       float gpencil_grid_scale[2];
        float gpencil_paper_opacity;
        int   gpencil_grid_lines;
        int   gpencil_grid_axis;
index d067088ec4b23236440c90ed69e893aaee8ec201..fdf16ce37de39c5bfe4fb843302f299286cbcb95 100644 (file)
@@ -2961,7 +2961,7 @@ static void rna_def_space_view3d_overlay(BlenderRNA *brna)
                "Display a grid over grease pencil paper");
        RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
 
-       prop = RNA_def_property(srna, "gpencil_grid_scale", PROP_FLOAT, PROP_NONE);
+       prop = RNA_def_property(srna, "gpencil_grid_scale", PROP_FLOAT, PROP_XYZ);
        RNA_def_property_float_sdna(prop, NULL, "overlay.gpencil_grid_scale");
        RNA_def_property_range(prop, 0.01f, FLT_MAX);
        RNA_def_property_float_default(prop, 1.0f);