[Bf-blender-cvs] [3e0ca1c8e76] temp-gpencil-bezier-stroke-type: GPencil: WIP curve pen tool for drawing curves

Falk David noreply at git.blender.org
Sat Mar 20 12:32:15 CET 2021


Commit: 3e0ca1c8e76d65c93016b225eca55eac3bd09b13
Author: Falk David
Date:   Mon Jan 18 10:19:25 2021 +0100
Branches: temp-gpencil-bezier-stroke-type
https://developer.blender.org/rB3e0ca1c8e76d65c93016b225eca55eac3bd09b13

GPencil: WIP curve pen tool for drawing curves

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

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M	source/blender/editors/gpencil/CMakeLists.txt
A	source/blender/editors/gpencil/gpencil_curve_draw.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_ops.c

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

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index ad309c541f4..6fcde39a34c 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -6796,6 +6796,15 @@ def km_3d_view_tool_paint_gpencil_eyedropper(params):
         ]},
     )
 
+def km_3d_view_tool_paint_gpencil_curve_pen(params):
+    return (
+        "3D View Tool: Paint Gpencil, Curve Pen",
+        {"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
+        {"items": [
+            ("gpencil.draw_curve", {"type": params.tool_mouse, "value": 'PRESS'}, {"properties":[("wait_for_input", False)]}),
+        ]},
+    )
+
 def km_3d_view_tool_paint_gpencil_interpolate(params):
     return (
         "3D View Tool: Paint Gpencil, Interpolate",
@@ -6806,6 +6815,7 @@ def km_3d_view_tool_paint_gpencil_interpolate(params):
         ]},
     )
 
+
 def km_3d_view_tool_edit_gpencil_select(params):
     return (
         "3D View Tool: Edit Gpencil, Tweak",
@@ -7233,9 +7243,9 @@ def generate_keymaps(params=None):
         km_3d_view_tool_paint_gpencil_curve(params),
         km_3d_view_tool_paint_gpencil_cutter(params),
         km_3d_view_tool_paint_gpencil_eyedropper(params),
+        km_3d_view_tool_paint_gpencil_curve_pen(params),
         km_3d_view_tool_paint_gpencil_interpolate(params),
         km_3d_view_tool_edit_gpencil_select(params),
-        km_3d_view_tool_edit_gpencil_select_box(params),
         km_3d_view_tool_edit_gpencil_select_circle(params),
         km_3d_view_tool_edit_gpencil_select_lasso(params),
         km_3d_view_tool_edit_gpencil_extrude(params),
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 1e52142c85c..ce1ef733c69 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -2034,6 +2034,21 @@ class _defs_gpencil_paint:
             keymap=(),
             draw_settings=draw_settings,
         )
+    
+    @ToolDef.from_fn
+    def curve_pen():
+        def draw_settings(context, layout, tool):
+            pass
+
+        return dict(
+            idname="builtin.curve_pen",
+            label="Curve Pen",
+            icon="",
+            cursor='DOT',
+            widget=None,
+            keymap=(),
+            draw_settings=draw_settings,
+        )
 
     @ToolDef.from_fn
     def interpolate():
@@ -2049,9 +2064,6 @@ class _defs_gpencil_paint:
             label="Interpolate",
             icon="ops.pose.breakdowner",
             cursor='DEFAULT',
-            widget=None,
-            keymap=(),
-            draw_settings=draw_settings,
         )
 
 
@@ -2906,6 +2918,8 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
             None,
             _defs_gpencil_paint.eyedropper,
             None,
+            _defs_gpencil_paint.curve_pen,
+            None,
             _defs_gpencil_paint.line,
             _defs_gpencil_paint.polyline,
             _defs_gpencil_paint.arc,
diff --git a/source/blender/editors/gpencil/CMakeLists.txt b/source/blender/editors/gpencil/CMakeLists.txt
index 47ae90acb74..a2c24c5710a 100644
--- a/source/blender/editors/gpencil/CMakeLists.txt
+++ b/source/blender/editors/gpencil/CMakeLists.txt
@@ -41,6 +41,7 @@ set(SRC
   gpencil_add_stroke.c
   gpencil_armature.c
   gpencil_convert.c
+  gpencil_curve_draw.c
   gpencil_data.c
   gpencil_edit.c
   gpencil_edit_curve.c
diff --git a/source/blender/editors/gpencil/gpencil_curve_draw.c b/source/blender/editors/gpencil/gpencil_curve_draw.c
new file mode 100644
index 00000000000..7b4956a867e
--- /dev/null
+++ b/source/blender/editors/gpencil/gpencil_curve_draw.c
@@ -0,0 +1,246 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2017, Blender Foundation
+ * This is a new part of Blender
+ * Operators for creating new Grease Pencil primitives (boxes, circles, ...)
+ */
+
+/** \file
+ * \ingroup edgpencil
+ */
+#include <stdio.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+
+#include "DNA_gpencil_types.h"
+#include "DNA_space_types.h"
+#include "DNA_windowmanager_types.h"
+
+#include "BKE_context.h"
+#include "BKE_gpencil.h"
+#include "BKE_gpencil_geom.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+#include "RNA_types.h"
+
+#include "ED_gpencil.h"
+#include "ED_screen.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
+#include "gpencil_intern.h"
+
+/* ------------------------------------------------------------------------- */
+
+typedef struct tGPDcurve_draw {
+  bGPdata *gpd;
+  bGPDframe *gpf;
+  bGPDstroke *gps;
+  bGPDcurve *gpc;
+  int imval[2];
+  short flag;
+} tGPDcurve_draw;
+
+typedef enum eGPDcurve_draw_state {
+  MOUSE_DOWN = (1 << 0),
+} eGPDcurve_draw_state;
+
+void gpencil_curve_draw_init(bContext *C, wmOperator *op, const wmEvent *event)
+{
+  bGPdata *gpd = CTX_data_gpencil_data(C);
+
+  tGPDcurve_draw *tcd = MEM_callocN(sizeof(tGPDcurve_draw), __func__);
+  tcd->gpd = gpd;
+  copy_v2_v2_int(tcd->imval, event->mval);
+
+  /* Initialize mouse state */
+  tcd->flag |= event->val == KM_PRESS ? MOUSE_DOWN : 0;
+
+  op->customdata = tcd;
+}
+
+void gpencil_curve_draw_update(bContext *C, tGPDcurve_draw *tcd)
+{
+  printf("Update curve draw\n");
+  bGPdata *gpd = tgpi->gpd;
+
+  DEG_id_tag_update(&gpd->id, ID_RECALC_COPY_ON_WRITE);
+  DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
+  WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, NULL);
+}
+
+void gpencil_curve_draw_confirm(bContext *C, wmOperator *op, tGPDcurve_draw *tcd)
+{
+  printf("Confirm curve draw\n");
+}
+
+void gpencil_curve_draw_exit(bContext *C, wmOperator *op)
+{
+  printf("Exit curve draw\n");
+  tGPDcurve_draw *tcd = op->customdata;
+  bGPdata *gpd = tcd->gpd;
+
+  MEM_SAFE_FREE(tcd);
+
+  DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
+  WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, NULL);
+
+  op->customdata = NULL;
+}
+
+/* ------------------------------------------------------------------------- */
+/* Operator callbacks */
+
+static int gpencil_curve_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+  printf("Invoke curve draw\n");
+  wmWindow *win = CTX_wm_window(C);
+
+  /* Set cursor to dot. */
+  WM_cursor_modal_set(win, WM_CURSOR_DOT);
+
+  gpencil_curve_draw_init(C, op, event);
+  tGPDcurve_draw *tcd = op->customdata;
+
+  // if (RNA_boolean_get(op->ptr, "wait_for_input") == false) {
+  //   printf("%s\tMouse x: %d y: %d\n",
+  //          (tcd->flag & MOUSE_DOWN) ? "DOWN" : "UP",
+  //          tcd->imval[0],
+  //          tcd->imval[1]);
+  // }
+
+  /* Add modal handler. */
+  WM_event_add_modal_handler(C, op);
+  return OPERATOR_RUNNING_MODAL;
+}
+
+static int gpencil_curve_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
+{
+  tGPDcurve_draw *tcd = op->customdata;
+  wmWindow *win = CTX_wm_window(C);
+
+  copy_v2_v2_int(tcd->imval, event->mval);
+
+  switch (event->type) {
+    case LEFTMOUSE: {
+      if (event->val == KM_PRESS) {
+        printf("Mouse press\n");
+        tcd->flag |= MOUSE_DOWN;
+      }
+      else if (event->val == KM_RELEASE) {
+        printf("Mouse release\n");
+        tcd->flag &= ~MOUSE_DOWN;
+      }
+      break;
+    }
+    case RIGHTMOUSE: {
+      ATTR_FALLTHROUGH;
+    }
+    case EVT_ESCKEY: {
+      ED_workspace_status_text(C, NULL);
+      WM_cursor_modal_restore(win);
+
+      gpencil_curve_draw_exit(C, op);
+
+      return OPERATOR_CANCELLED;
+    }
+    case EVT_SPACEKEY:
+    case MIDDLEMOUSE:
+    case EVT_PADENTER:
+    case EVT_RETKEY: {
+      ED_workspace_status_text(C, NULL);
+      WM_cursor_modal_restore(win);
+
+      /* Create curve */
+      gpencil_curve_draw_confirm(C, op, tcd);
+
+      gpencil_curve_draw_exit(C, op);
+
+      return OPERATOR_FINISHED;
+    }
+    case MOUSEMOVE: {
+      printf("%s\tMouse x: %d y: %d\n",
+             (tcd->flag & MOUSE_DOWN) ? "DOWN" : "UP",
+             tcd->imval[0],
+             tcd->imval[1]);
+      gpencil_curve_draw_update(C, op)
+      break;
+    }
+    default:
+      return OPERATOR_RUNNING_MODAL | OPERATOR_PASS_THROUGH;
+  }
+  return OPERATOR_RUNNING_MODAL;
+}
+
+static void gpencil_curve_draw_cancel(bContext *C, wmOperator *op)
+{
+  printf("Cancel curve draw\n");
+  gpencil_curve_draw_exit(C, op);
+}
+
+static bool gpencil_curve_draw_poll(bContext *C)
+{
+  printf("Poll curve draw\n");
+  ScrArea *area = CTX_wm_area(C);
+  if (area && area->spacetype != SPACE_VIEW3D) {
+    return false;
+  }
+
+  bGPdata *gpd = CTX_data_gpencil_data(C);
+  if (gpd == NULL) {
+    return false;
+  }
+
+  if ((gpd->flag & GP_DATA_STROKE_PAINTMODE) == 0) {
+    return false;
+  }
+
+  bGPDlayer *gpl = BKE_gpencil_layer_active_get(gpd);
+  if ((gpl) && (gpl->flag & (GP_LAYER_LOCKED | GP_LAYER_HIDE))) {
+    return false;
+  }
+
+  return true;
+}
+
+void GPENCIL_OT_draw_curve(wmOperatorType *ot)
+{
+  PropertyRNA *prop;
+
+  /* identifiers */
+  ot->name = "Grease Pencil Draw Curve";
+  ot->idname = "GPENCIL_OT_draw_curve";
+  ot->description = "Draw a bezier curve in the active grease pencil object";
+
+  /* api callbacks */
+  ot->invoke = gpencil_curve_draw_invoke;
+  ot->modal = gpencil_curve_draw_modal;
+  ot->cancel = gpencil_c

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list