Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_edit.c')
-rw-r--r--source/blender/editors/gpencil/gpencil_edit.c277
1 files changed, 221 insertions, 56 deletions
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 77e45642939..2d53679b61a 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -90,8 +90,9 @@
#include "gpencil_intern.h"
-/* ************************************************ */
-/* Stroke Edit Mode Management */
+/* -------------------------------------------------------------------- */
+/** \name Stroke Edit Mode Management
+ * \{ */
/* poll callback for all stroke editing operators */
static bool gp_stroke_edit_poll(bContext *C)
@@ -138,6 +139,12 @@ static bool gpencil_editmode_toggle_poll(bContext *C)
return ED_gpencil_data_get_active(C) != NULL;
}
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Toggle Edit Mode Operator
+ * \{ */
+
static int gpencil_editmode_toggle_exec(bContext *C, wmOperator *op)
{
const int back = RNA_boolean_get(op->ptr, "back");
@@ -223,6 +230,12 @@ void GPENCIL_OT_editmode_toggle(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
}
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Toggle Select Mode Operator
+ * \{ */
+
/* set select mode */
static bool gpencil_selectmode_toggle_poll(bContext *C)
{
@@ -298,7 +311,11 @@ void GPENCIL_OT_selectmode_toggle(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
}
-/* Stroke Paint Mode Management */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Toggle Stroke Paint Mode Operator
+ * \{ */
static bool gpencil_paintmode_toggle_poll(bContext *C)
{
@@ -402,7 +419,11 @@ void GPENCIL_OT_paintmode_toggle(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
}
-/* Stroke Sculpt Mode Management */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Toggle Stroke Sculpt Mode Operator
+ * \{ */
static bool gpencil_sculptmode_toggle_poll(bContext *C)
{
@@ -479,6 +500,12 @@ static int gpencil_sculptmode_toggle_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Toggle Weight Paint Mode Operator
+ * \{ */
+
void GPENCIL_OT_sculptmode_toggle(wmOperatorType *ot)
{
PropertyRNA *prop;
@@ -600,7 +627,11 @@ void GPENCIL_OT_weightmode_toggle(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
}
-/* Vertex Paint Mode Management */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Toggle Vertex Paint Mode Operator
+ * \{ */
static bool gpencil_vertexmode_toggle_poll(bContext *C)
{
@@ -698,10 +729,11 @@ void GPENCIL_OT_vertexmode_toggle(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
}
-/* ************************************************ */
-/* Stroke Editing Operators */
+/** \} */
-/* ************ Stroke Hide selection Toggle ************** */
+/* -------------------------------------------------------------------- */
+/** \name Stroke Hide Selection Toggle Operator
+ * \{ */
static int gpencil_hideselect_toggle_exec(bContext *C, wmOperator *UNUSED(op))
{
@@ -740,7 +772,11 @@ void GPENCIL_OT_selection_opacity_toggle(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO | OPTYPE_REGISTER;
}
-/* ************** Duplicate Selected Strokes **************** */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Duplicate Selected Strokes Operator
+ * \{ */
/* Make copies of selected point segments in a selected stroke */
static void gp_duplicate_points(const bGPDstroke *gps,
@@ -917,7 +953,11 @@ void GPENCIL_OT_duplicate(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
-/* ************** Extrude Selected Strokes **************** */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Extrude Selected Strokes Operator
+ * \{ */
/* helper to copy a point to temp area */
static void copy_move_point(bGPDstroke *gps,
@@ -1138,14 +1178,18 @@ void GPENCIL_OT_extrude(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
-/* ******************* Copy/Paste Strokes ************************* */
-/* Grease Pencil stroke data copy/paste buffer:
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Copy/Paste Strokes Utilities
+ *
+ * Grease Pencil stroke data copy/paste buffer:
* - The copy operation collects all segments of selected strokes,
* dumping "ready to be copied" copies of the strokes into the buffer.
* - The paste operation makes a copy of those elements, and adds them
* to the active layer. This effectively flattens down the strokes
* from several different layers into a single layer.
- */
+ * \{ */
/* list of bGPDstroke instances */
/* NOTE: is exposed within the editors/gpencil module so that other tools can use it too */
@@ -1257,8 +1301,11 @@ GHash *gp_copybuf_validate_colormap(bContext *C)
return new_colors;
}
-/* --------------------- */
-/* Copy selected strokes */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Copy Selected Strokes Operator
+ * \{ */
static int gp_strokes_copy_exec(bContext *C, wmOperator *op)
{
@@ -1375,8 +1422,11 @@ void GPENCIL_OT_copy(wmOperatorType *ot)
// ot->flag = OPTYPE_REGISTER;
}
-/* --------------------- */
-/* Paste selected strokes */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Paste Selected Strokes Operator
+ * \{ */
static bool gp_strokes_paste_poll(bContext *C)
{
@@ -1547,7 +1597,11 @@ void GPENCIL_OT_paste(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
-/* ******************* Move To Layer ****************************** */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Move To Layer Operator
+ * \{ */
static int gp_move_to_layer_exec(bContext *C, wmOperator *op)
{
@@ -1667,7 +1721,11 @@ void GPENCIL_OT_move_to_layer(wmOperatorType *ot)
RNA_def_property_flag(ot->prop, PROP_HIDDEN | PROP_SKIP_SAVE);
}
-/* ********************* Add Blank Frame *************************** */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Add Blank Frame Operator
+ * \{ */
static int gp_blank_frame_add_exec(bContext *C, wmOperator *op)
{
@@ -1741,7 +1799,11 @@ void GPENCIL_OT_blank_frame_add(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
-/* ******************* Delete Active Frame ************************ */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Delete Active Frame Operator
+ * \{ */
static bool gp_actframe_delete_poll(bContext *C)
{
@@ -1822,7 +1884,12 @@ void GPENCIL_OT_annotation_active_frame_delete(wmOperatorType *ot)
ot->exec = gp_actframe_delete_exec;
ot->poll = gp_annotation_actframe_delete_poll;
}
-/* **************** Delete All Active Frames ****************** */
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Delete All Active Frames
+ * \{ */
static bool gp_actframe_delete_all_poll(bContext *C)
{
@@ -1883,7 +1950,11 @@ void GPENCIL_OT_active_frames_delete_all(wmOperatorType *ot)
ot->poll = gp_actframe_delete_all_poll;
}
-/* ******************* Delete Operator ************************ */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Delete/Dissolve Utilities
+ * \{ */
typedef enum eGP_DeleteMode {
/* delete selected stroke points */
@@ -1903,8 +1974,6 @@ typedef enum eGP_DissolveMode {
GP_DISSOLVE_UNSELECT = 2,
} eGP_DissolveMode;
-/* ----------------------------------- */
-
/* Delete selected strokes */
static int gp_delete_selected_strokes(bContext *C)
{
@@ -2498,7 +2567,11 @@ int gp_delete_selected_point_wrap(bContext *C)
return gp_delete_selected_points(C);
}
-/* ----------------------------------- */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Delete Operator
+ * \{ */
static int gp_delete_exec(bContext *C, wmOperator *op)
{
@@ -2557,6 +2630,12 @@ void GPENCIL_OT_delete(wmOperatorType *ot)
"Method used for deleting Grease Pencil data");
}
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Dissolve Operator
+ * \{ */
+
static int gp_dissolve_exec(bContext *C, wmOperator *op)
{
eGP_DissolveMode mode = RNA_enum_get(op->ptr, "type");
@@ -2599,7 +2678,11 @@ void GPENCIL_OT_dissolve(wmOperatorType *ot)
"Method used for dissolving Stroke points");
}
-/* ****************** Snapping - Strokes <-> Cursor ************************ */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Snapping Selection to Grid Operator
+ * \{ */
/* Poll callback for snap operators */
/* NOTE: For now, we only allow these in the 3D view, as other editors do not
@@ -2614,8 +2697,6 @@ static bool gp_snap_poll(bContext *C)
((area != NULL) && (area->spacetype == SPACE_VIEW3D));
}
-/* --------------------------------- */
-
static int gp_snap_to_grid(bContext *C, wmOperator *UNUSED(op))
{
bGPdata *gpd = ED_gpencil_data_get_active(C);
@@ -2690,7 +2771,11 @@ void GPENCIL_OT_snap_to_grid(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
-/* ------------------------------- */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Snapping Selection to Cursor Operator
+ * \{ */
static int gp_snap_to_cursor(bContext *C, wmOperator *op)
{
@@ -2782,7 +2867,11 @@ void GPENCIL_OT_snap_to_cursor(wmOperatorType *ot)
"Offset the entire stroke instead of selected points only");
}
-/* ------------------------------- */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Snapping Cursor to Selection Operator
+ * \{ */
static int gp_snap_cursor_to_sel(bContext *C, wmOperator *UNUSED(op))
{
@@ -2873,7 +2962,11 @@ void GPENCIL_OT_snap_cursor_to_selected(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
-/* ******************* Apply layer thickness change to strokes ************************** */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Apply Layer Thickness Change to Strokes Operator
+ * \{ */
static int gp_stroke_apply_thickness_exec(bContext *C, wmOperator *UNUSED(op))
{
@@ -2920,7 +3013,11 @@ void GPENCIL_OT_stroke_apply_thickness(wmOperatorType *ot)
ot->poll = gp_active_layer_poll;
}
-/* ******************* Close Strokes ************************** */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Stroke Toggle Cyclic Operator
+ * \{ */
enum {
GP_STROKE_CYCLIC_CLOSE = 1,
@@ -3040,7 +3137,11 @@ void GPENCIL_OT_stroke_cyclical_set(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
-/* ******************* Flat Stroke Caps ************************** */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Stroke Toggle Flat Caps Operator
+ * \{ */
enum {
GP_STROKE_CAPS_TOGGLE_BOTH = 0,
@@ -3136,7 +3237,11 @@ void GPENCIL_OT_stroke_caps_set(wmOperatorType *ot)
ot->prop = RNA_def_enum(ot->srna, "type", toggle_type, GP_STROKE_CAPS_TOGGLE_BOTH, "Type", "");
}
-/* ******************* Stroke join ************************** */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Stroke Join Operator
+ * \{ */
/* Helper: flip stroke */
static void gpencil_flip_stroke(bGPDstroke *gps)
@@ -3186,8 +3291,8 @@ static void gpencil_flip_stroke(bGPDstroke *gps)
/* Helper: copy point between strokes */
static void gpencil_stroke_copy_point(bGPDstroke *gps,
+ MDeformVert *dvert,
bGPDspoint *point,
- int idx,
const float delta[3],
float pressure,
float strength,
@@ -3199,6 +3304,13 @@ static void gpencil_stroke_copy_point(bGPDstroke *gps,
if (gps->dvert != NULL) {
gps->dvert = MEM_reallocN(gps->dvert, sizeof(MDeformVert) * (gps->totpoints + 1));
}
+ else {
+ /* If destination has weight add weight to origin. */
+ if (dvert != NULL) {
+ gps->dvert = MEM_callocN(sizeof(MDeformVert) * (gps->totpoints + 1), __func__);
+ }
+ }
+
gps->totpoints++;
newpoint = &gps->points[gps->totpoints - 1];
@@ -3212,11 +3324,16 @@ static void gpencil_stroke_copy_point(bGPDstroke *gps,
copy_v4_v4(newpoint->vert_color, point->vert_color);
if (gps->dvert != NULL) {
- MDeformVert *dvert = &gps->dvert[idx];
MDeformVert *newdvert = &gps->dvert[gps->totpoints - 1];
- newdvert->totweight = dvert->totweight;
- newdvert->dw = MEM_dupallocN(dvert->dw);
+ if (dvert != NULL) {
+ newdvert->totweight = dvert->totweight;
+ newdvert->dw = MEM_dupallocN(dvert->dw);
+ }
+ else {
+ newdvert->totweight = 0;
+ newdvert->dw = NULL;
+ }
}
}
@@ -3267,16 +3384,18 @@ static void gpencil_stroke_join_strokes(bGPDstroke *gps_a,
/* 1st: add one tail point to start invisible area */
point = gps_a->points[gps_a->totpoints - 1];
deltatime = point.time;
- gpencil_stroke_copy_point(gps_a, &point, gps_a->totpoints - 1, delta, 0.0f, 0.0f, 0.0f);
+
+ gpencil_stroke_copy_point(gps_a, NULL, &point, delta, 0.0f, 0.0f, 0.0f);
/* 2nd: add one head point to finish invisible area */
point = gps_b->points[0];
- gpencil_stroke_copy_point(gps_a, &point, 0, delta, 0.0f, 0.0f, deltatime);
+ gpencil_stroke_copy_point(gps_a, NULL, &point, delta, 0.0f, 0.0f, deltatime);
}
/* 3rd: add all points */
for (i = 0, pt = gps_b->points; i < gps_b->totpoints && pt; i++, pt++) {
- gpencil_stroke_copy_point(gps_a, pt, i, delta, pt->pressure, pt->strength, deltatime);
+ MDeformVert *dvert = (gps_b->dvert) ? &gps_b->dvert[i] : NULL;
+ gpencil_stroke_copy_point(gps_a, dvert, pt, delta, pt->pressure, pt->strength, deltatime);
}
}
@@ -3422,7 +3541,11 @@ void GPENCIL_OT_stroke_join(wmOperatorType *ot)
"Leave gaps between joined strokes instead of linking them");
}
-/* ******************* Stroke flip ************************** */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Stroke Flip Operator
+ * \{ */
static int gp_stroke_flip_exec(bContext *C, wmOperator *UNUSED(op))
{
@@ -3481,7 +3604,11 @@ void GPENCIL_OT_stroke_flip(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
-/* ***************** Reproject Strokes ********************** */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Stroke Re-project Operator
+ * \{ */
typedef enum eGP_ReprojectModes {
/* Axis */
@@ -3719,7 +3846,6 @@ static int gp_recalc_geometry_exec(bContext *C, wmOperator *UNUSED(op))
void GPENCIL_OT_recalc_geometry(wmOperatorType *ot)
{
-
/* identifiers */
ot->name = "Recalculate internal geometry";
ot->idname = "GPENCIL_OT_recalc_geometry";
@@ -3733,7 +3859,12 @@ void GPENCIL_OT_recalc_geometry(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
-/* ******************* Stroke subdivide ************************** */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Stroke Subdivide Operator
+ * \{ */
+
/* helper to smooth */
static void gp_smooth_stroke(bContext *C, wmOperator *op)
{
@@ -4114,7 +4245,12 @@ void GPENCIL_OT_stroke_sample(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
-/* ******************* Stroke trim ************************** */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Stroke Trim Operator
+ * \{ */
+
static int gp_stroke_trim_exec(bContext *C, wmOperator *UNUSED(op))
{
bGPdata *gpd = ED_gpencil_data_get_active(C);
@@ -4179,7 +4315,12 @@ void GPENCIL_OT_stroke_trim(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
-/* ***************** Separate Strokes ********************** */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Stroke Separate Operator
+ * \{ */
+
typedef enum eGP_SeparateModes {
/* Points */
GP_SEPARATE_POINT = 0,
@@ -4397,7 +4538,12 @@ void GPENCIL_OT_stroke_separate(wmOperatorType *ot)
ot->prop = RNA_def_enum(ot->srna, "mode", separate_type, GP_SEPARATE_POINT, "Mode", "");
}
-/* ***************** Split Strokes ********************** */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Stroke Split Operator
+ * \{ */
+
static int gp_stroke_split_exec(bContext *C, wmOperator *UNUSED(op))
{
Object *ob = CTX_data_active_object(C);
@@ -4494,6 +4640,12 @@ void GPENCIL_OT_stroke_split(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Stroke Smooth Operator
+ * \{ */
+
static int gp_stroke_smooth_exec(bContext *C, wmOperator *op)
{
bGPdata *gpd = ED_gpencil_data_get_active(C);
@@ -4544,11 +4696,17 @@ void GPENCIL_OT_stroke_smooth(wmOperatorType *ot)
RNA_def_boolean(ot->srna, "smooth_uv", false, "UV", "");
}
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Stroke Cutter Operator
+ * \{ */
+
/* smart stroke cutter for trimming stroke ends */
struct GP_SelectLassoUserData {
rcti rect;
- const int (*mcords)[2];
- int mcords_len;
+ const int (*mcoords)[2];
+ int mcoords_len;
};
static bool gpencil_test_lasso(bGPDstroke *gps,
@@ -4564,7 +4722,7 @@ static bool gpencil_test_lasso(bGPDstroke *gps,
gp_point_to_xy(gsc, gps, &pt2, &x0, &y0);
/* test if in lasso */
return ((!ELEM(V2D_IS_CLIPPED, x0, y0)) && BLI_rcti_isect_pt(&data->rect, x0, y0) &&
- BLI_lasso_is_point_inside(data->mcords, data->mcords_len, x0, y0, INT_MAX));
+ BLI_lasso_is_point_inside(data->mcoords, data->mcoords_len, x0, y0, INT_MAX));
}
typedef bool (*GPencilTestFn)(bGPDstroke *gps,
@@ -4742,19 +4900,19 @@ static int gpencil_cutter_exec(bContext *C, wmOperator *op)
}
struct GP_SelectLassoUserData data = {0};
- data.mcords = WM_gesture_lasso_path_to_array(C, op, &data.mcords_len);
+ data.mcoords = WM_gesture_lasso_path_to_array(C, op, &data.mcoords_len);
/* Sanity check. */
- if (data.mcords == NULL) {
+ if (data.mcoords == NULL) {
return OPERATOR_PASS_THROUGH;
}
/* Compute boundbox of lasso (for faster testing later). */
- BLI_lasso_boundbox(&data.rect, data.mcords, data.mcords_len);
+ BLI_lasso_boundbox(&data.rect, data.mcoords, data.mcoords_len);
gpencil_cutter_lasso_select(C, op, gpencil_test_lasso, &data);
- MEM_freeN((void *)data.mcords);
+ MEM_freeN((void *)data.mcoords);
return OPERATOR_FINISHED;
}
@@ -4800,7 +4958,12 @@ bool ED_object_gpencil_exit(struct Main *bmain, Object *ob)
return ok;
}
-/* ** merge by distance *** */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Merge By Distance Operator
+ * \{ */
+
static bool gp_merge_by_distance_poll(bContext *C)
{
Object *ob = CTX_data_active_object(C);
@@ -4869,3 +5032,5 @@ void GPENCIL_OT_stroke_merge_by_distance(wmOperatorType *ot)
ot->srna, "use_unselected", 0, "Unselected", "Use whole stroke, not only selected points");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
+
+/** \} */