[Bf-blender-cvs] [2dbfc4aab14] temp-gpencil-bezier-stroke-type: GPencil: Custom drawing/status for curve pen

Falk David noreply at git.blender.org
Fri Apr 2 11:10:56 CEST 2021


Commit: 2dbfc4aab14de4c2c8a9b7e9c8ebd1870b9320b2
Author: Falk David
Date:   Fri Apr 2 11:10:18 2021 +0200
Branches: temp-gpencil-bezier-stroke-type
https://developer.blender.org/rB2dbfc4aab14de4c2c8a9b7e9c8ebd1870b9320b2

GPencil: Custom drawing/status for curve pen

This commits adds custom drawing for the curve pen.
Initially this will draw the handle while draging.
This commits also adds a modal keymap to the operator making the
status text possible. Now the user can see what key does what in
each of the states.

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

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	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 96131977334..36177511621 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -5675,6 +5675,33 @@ def km_generic_gizmo_tweak_modal_map(_params):
     return keymap
 
 
+def km_gpencil_curve_draw_modal_map(_params):
+    items = []
+    keymap = (
+        "Curve Draw Tool Modal Map",
+        {"space_type": 'EMPTY', "region_type": 'WINDOW', "modal": True},
+        {"items": items},
+    )
+
+    items.extend([
+        ("CANCEL", {"type": 'ESC', "value": 'PRESS', "any": True}, None),
+        ("CANCEL", {"type": 'RIGHTMOUSE', "value": 'PRESS', "any": True}, None),
+        ("CONFIRM", {"type": 'SPACE', "value": 'PRESS', "any": True}, None),
+        ("CONFIRM", {"type": 'RET', "value": 'PRESS', "any": True}, None),
+        ("CONFIRM", {"type": 'NUMPAD_ENTER', "value": 'PRESS', "any": True}, None),
+        ("CONFIRM", {"type": 'MIDDLEMOUSE', "value": 'PRESS', "any": True}, None),
+        ("FREE_HANDLE_ON", {"type": 'RIGHT_ALT', "value": 'PRESS', "any": True}, None),
+        ("FREE_HANDLE_OFF", {"type": 'RIGHT_ALT', "value": 'RELEASE', "any": True}, None),
+        ("FREE_HANDLE_ON", {"type": 'LEFT_ALT', "value": 'PRESS', "any": True}, None),
+        ("FREE_HANDLE_OFF", {"type": 'LEFT_ALT', "value": 'RELEASE', "any": True}, None),
+        ("CYCLIC_TOGGLE", {"type": 'C', "value": 'PRESS', "any": True}, None),
+        ("DELETE_LAST", {"type": 'X', "value": 'PRESS', "any": True}, None),
+        ("SET_THICKNESS", {"type": 'F', "value": 'PRESS', "any": True}, None),
+    ])
+
+    return keymap
+    
+
 # ------------------------------------------------------------------------------
 # Popup Keymaps
 
@@ -7120,6 +7147,7 @@ def generate_keymaps(params=None):
         km_view3d_dolly_modal(params),
         km_paint_stroke_modal(params),
         km_sculpt_expand_modal(params),
+        km_gpencil_curve_draw_modal_map(params),
 
         # Gizmos.
         km_generic_gizmo(params),
diff --git a/source/blender/editors/gpencil/gpencil_curve_draw.c b/source/blender/editors/gpencil/gpencil_curve_draw.c
index 9114402c196..214ddd50886 100644
--- a/source/blender/editors/gpencil/gpencil_curve_draw.c
+++ b/source/blender/editors/gpencil/gpencil_curve_draw.c
@@ -27,6 +27,7 @@
 
 #include "BLI_listbase.h"
 #include "BLI_math.h"
+#include "BLI_string.h"
 
 #include "BLT_translation.h"
 
@@ -34,6 +35,7 @@
 #include "DNA_gpencil_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_space_types.h"
+#include "DNA_userdef_types.h"
 #include "DNA_windowmanager_types.h"
 
 #include "BKE_brush.h"
@@ -63,6 +65,7 @@
 #include "GPU_state.h"
 
 #include "UI_interface.h"
+#include "UI_resources.h"
 
 #include "DEG_depsgraph.h"
 #include "DEG_depsgraph_query.h"
@@ -114,6 +117,16 @@ typedef struct tGPDcurve_draw {
   eGPDcurve_draw_state state;
 } tGPDcurve_draw;
 
+enum {
+  CD_MODAL_CANCEL = 1,
+  CD_MODAL_CONFIRM,
+  CD_MODAL_FREE_HANDLE_ON,
+  CD_MODAL_FREE_HANDLE_OFF,
+  CD_MODAL_CYCLIC_TOGGLE,
+  CD_MODAL_DELETE_LAST,
+  CD_MODAL_SET_THICKNESS,
+};
+
 /* Forward declaration */
 static void gpencil_curve_draw_init(bContext *C, wmOperator *op, const wmEvent *event);
 static void gpencil_curve_draw_update(bContext *C, tGPDcurve_draw *tcd);
@@ -248,9 +261,56 @@ static void gpencil_curve_draw_ui_callback(const struct bContext *UNUSED(C),
   GPU_matrix_push();
   GPU_matrix_mul(tcd->ob->obmat);
 
+  GPUVertFormat *format = immVertexFormat();
+  uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+
   immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
 
   /* Draw overlays. */
+  if (ELEM(tcd->state, IN_DRAG_ALIGNED_HANDLE, IN_DRAG_FREE_HANDLE)) {
+    bGPDcurve *gpc = tcd->gpc;
+    bGPDcurve_point *cpt_last = &gpc->curve_points[gpc->tot_curve_points - 1];
+    BezTriple *bezt = &cpt_last->bezt;
+
+    float viewport[4];
+    GPU_viewport_size_get_f(viewport);
+    immUniform2fv("viewportSize", &viewport[2]);
+
+    float color[4] = {0, 0, 0, 1.0f};
+    UI_GetThemeColorType3fv(TH_GP_VERTEX_SELECT, SPACE_VIEW3D, color);
+
+    /* TODO: Use the GPU_SHADER_3D_POLYLINE_* shader instead. GPU_line_smooth will be deprecated.
+     */
+    GPU_line_smooth(true);
+    GPU_blend(GPU_BLEND_ALPHA);
+
+    // immUniform1f("lineWidth", U.pixelsize * 2.0f);
+    // immUniform1i("lineSmooth", 1);
+
+    immUniformColor4fv(color);
+
+    /* Handle lines. */
+    immBegin(GPU_PRIM_LINES, 4);
+    immVertex3fv(pos, bezt->vec[0]);
+    immVertex3fv(pos, bezt->vec[1]);
+    immVertex3fv(pos, bezt->vec[1]);
+    immVertex3fv(pos, bezt->vec[2]);
+    immEnd();
+
+    // immUniform1f("size", U.pixelsize * UI_GetThemeValuef(TH_GP_VERTEX_SIZE) * 2.0f);
+
+    // immUniformColor4fv(color);
+
+    /* Handle points. */
+    immBegin(GPU_PRIM_POINTS, 3);
+    immVertex3fv(pos, bezt->vec[0]);
+    immVertex3fv(pos, bezt->vec[1]);
+    immVertex3fv(pos, bezt->vec[2]);
+    immEnd();
+
+    GPU_line_smooth(false);
+    GPU_blend(GPU_BLEND_NONE);
+  }
 
   immUnbindProgram();
 
@@ -263,8 +323,10 @@ static void gpencil_curve_draw_ui_callback(const struct bContext *UNUSED(C),
 
 /* ------------------------------------------------------------------------- */
 /* Main drawing functions */
-/*
-static void knife_update_header(bContext *C, wmOperator *op, const tGPDcurve_draw *tcd)
+
+static void gpencil_curve_draw_update_header(bContext *C,
+                                             wmOperator *op,
+                                             const tGPDcurve_draw *tcd)
 {
   char header[UI_MAX_DRAW_STR];
   char buf[UI_MAX_DRAW_STR];
@@ -276,33 +338,57 @@ static void knife_update_header(bContext *C, wmOperator *op, const tGPDcurve_dra
   WM_modalkeymap_operator_items_to_string_buf( \
       op->type, (_id), true, UI_MAX_SHORTCUT_STR, &available_len, &p)
 
-  BLI_snprintf(header,
-               sizeof(header),
-               TIP_("%s: confirm, %s: cancel, "
-                    "%s: start/define cut, %s: close cut, %s: new cut, "
-                    "%s: midpoint snap (%s), %s: ignore snap (%s), "
-                    "%s: angle constraint (%s), %s: cut through (%s), "
-                    "%s: panning"),
-               WM_MODALKEY(KNF_MODAL_CONFIRM),
-               WM_MODALKEY(KNF_MODAL_CANCEL),
-               WM_MODALKEY(KNF_MODAL_ADD_CUT),
-               WM_MODALKEY(KNF_MODAL_ADD_CUT_CLOSED),
-               WM_MODALKEY(KNF_MODAL_NEW_CUT),
-               WM_MODALKEY(KNF_MODAL_MIDPOINT_ON),
-               WM_bool_as_string(kcd->snap_midpoints),
-               WM_MODALKEY(KNF_MODAL_IGNORE_SNAP_ON),
-               WM_bool_as_string(kcd->ignore_edge_snapping),
-               WM_MODALKEY(KNF_MODAL_ANGLE_SNAP_TOGGLE),
-               WM_bool_as_string(kcd->angle_snapping),
-               WM_MODALKEY(KNF_MODAL_CUT_THROUGH_TOGGLE),
-               WM_bool_as_string(kcd->cut_through),
-               WM_MODALKEY(KNF_MODAL_PANNING));
-
-#undef WM_MODALKEY
+  switch (tcd->state) {
+    case IN_MOVE:
+    case IN_SET_VECTOR:
+      BLI_snprintf(header,
+                   sizeof(header),
+                   TIP_("%s: confirm, %s: cancel, "
+                        "%s: toggle cyclic (%s), "
+                        "%s: delete last, %s: set thickness"),
+                   WM_MODALKEY(CD_MODAL_CONFIRM),
+                   WM_MODALKEY(CD_MODAL_CANCEL),
+                   WM_MODALKEY(CD_MODAL_CYCLIC_TOGGLE),
+                   WM_bool_as_string(tcd->is_cyclic),
+                   WM_MODALKEY(CD_MODAL_DELETE_LAST),
+                   WM_MODALKEY(CD_MODAL_SET_THICKNESS));
+      break;
+    case IN_DRAG_FREE_HANDLE:
+    case IN_DRAG_ALIGNED_HANDLE:
+      BLI_snprintf(header,
+                   sizeof(header),
+                   TIP_("%s: confirm, %s: cancel, "
+                        "%s: toggle cyclic (%s), "
+                        "%s: free handle (%s), "
+                        "%s: delete last, %s: set thickness"),
+                   WM_MODALKEY(CD_MODAL_CONFIRM),
+                   WM_MODALKEY(CD_MODAL_CANCEL),
+                   WM_MODALKEY(CD_MODAL_CYCLIC_TOGGLE),
+                   WM_bool_as_string(tcd->is_cyclic),
+                   WM_MODALKEY(CD_MODAL_FREE_HANDLE_ON),
+                   WM_bool_as_string(tcd->state == IN_DRAG_FREE_HANDLE),
+                   WM_MODALKEY(CD_MODAL_DELETE_LAST),
+                   WM_MODALKEY(CD_MODAL_SET_THICKNESS));
+      break;
+    case IN_SET_THICKNESS:
+      BLI_snprintf(header,
+                   sizeof(header),
+                   TIP_("%s: confirm, %s: cancel, "
+                        "%s: toggle cyclic (%s), "
+                        "%s: delete last"),
+                   WM_MODALKEY(CD_MODAL_CONFIRM),
+                   WM_MODALKEY(CD_MODAL_CANCEL),
+                   WM_MODALKEY(CD_MODAL_CYCLIC_TOGGLE),
+                   WM_bool_as_string(tcd->is_cyclic),
+                   WM_MODALKEY(CD_MODAL_DELETE_LAST));
+      break;
+  }
 
   ED_workspace_status_text(C, header);
+
+#undef WM_MODALKEY
 }
-*/
+
 /* ------------------------------------------------------------------------- */
 /* Main drawing functions */
 
@@ -541,79 +627,43 @@ static int gpencil_curve_draw_modal(bContext *C, wmOperator *op, const wmEvent *
 
   copy_v2_v2_int(tcd->imval, event->mval);
 
-  switch (event->type) {
-    case LEFTMOUSE: {
-      if (event->val == KM_PRESS) {
-        copy_v2_v2_int(tcd->imval_start, tcd->imval);
-        tcd->is_mouse_down = true;
-        /* Set state to vector. */
+  /* Modal keymap event. */
+  if (event->type == EVT_MODAL_MAP) {
+    switch (event->val) {
+      case CD_MODAL_CONFIRM: {
+        /* Delete the 'preview' point. */
         if (tcd->state == IN_MOVE) {
-          tcd->state = IN_SET_VECTOR;
-        }
-      }
-      else if (event->val == KM_RELEASE) {
-        copy_v2_v2_int(tcd->imval_end, tcd->imval);
-        tcd->is_mouse_down = false;
-        /* Reset state to move. */
-        if (ELEM(tcd->state, IN_SET_VECTOR, IN_DRAG_ALIGNED_HANDLE, IN_DRAG_FREE_HANDLE)) {
-          tcd->state = IN_MOVE;
-          gpencil_p

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list