Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/gpencil_edit.c
| Show First 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | static bool gpencil_editmode_toggle_poll(bContext *C) | ||||
| return ED_gpencil_data_get_active(C) != NULL; | return ED_gpencil_data_get_active(C) != NULL; | ||||
| } | } | ||||
| static int gpencil_editmode_toggle_exec(bContext *C, wmOperator *op) | static int gpencil_editmode_toggle_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| const int back = RNA_boolean_get(op->ptr, "back"); | const int back = RNA_boolean_get(op->ptr, "back"); | ||||
| struct wmMsgBus *mbus = CTX_wm_message_bus(C); | struct wmMsgBus *mbus = CTX_wm_message_bus(C); | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph(C); | |||||
| bGPdata *gpd = ED_gpencil_data_get_active(C); | bGPdata *gpd = ED_gpencil_data_get_active(C); | ||||
| bool is_object = false; | bool is_object = false; | ||||
| short mode; | short mode; | ||||
| /* if using a gpencil object, use this datablock */ | /* if using a gpencil object, use this datablock */ | ||||
| Object *ob = CTX_data_active_object(C); | Object *ob = CTX_data_active_object(C); | ||||
| if ((ob) && (ob->type == OB_GPENCIL)) { | if ((ob) && (ob->type == OB_GPENCIL)) { | ||||
| gpd = ob->data; | gpd = ob->data; | ||||
| is_object = true; | is_object = true; | ||||
| } | } | ||||
| if (gpd == NULL) { | if (gpd == NULL) { | ||||
| BKE_report(op->reports, RPT_ERROR, "No active GP data"); | BKE_report(op->reports, RPT_ERROR, "No active GP data"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| /* Just toggle editmode flag... */ | /* Just toggle editmode flag... */ | ||||
| gpd->flag ^= GP_DATA_STROKE_EDITMODE; | gpd->flag ^= GP_DATA_STROKE_EDITMODE; | ||||
| /* recalculate parent matrix */ | /* recalculate parent matrix */ | ||||
| if (gpd->flag & GP_DATA_STROKE_EDITMODE) { | if (gpd->flag & GP_DATA_STROKE_EDITMODE) { | ||||
| Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | |||||
| ED_gpencil_reset_layers_parent(depsgraph, ob, gpd); | ED_gpencil_reset_layers_parent(depsgraph, ob, gpd); | ||||
| } | } | ||||
| /* set mode */ | /* set mode */ | ||||
| if (gpd->flag & GP_DATA_STROKE_EDITMODE) { | if (gpd->flag & GP_DATA_STROKE_EDITMODE) { | ||||
| mode = OB_MODE_EDIT_GPENCIL; | mode = OB_MODE_EDIT_GPENCIL; | ||||
| } | } | ||||
| else { | else { | ||||
| mode = OB_MODE_OBJECT; | mode = OB_MODE_OBJECT; | ||||
| ▲ Show 20 Lines • Show All 1,207 Lines • ▼ Show 20 Lines | void GPENCIL_OT_paste(wmOperatorType *ot) | ||||
| ot->idname = "GPENCIL_OT_paste"; | ot->idname = "GPENCIL_OT_paste"; | ||||
| ot->description = "Paste previously copied strokes or copy and merge in active layer"; | ot->description = "Paste previously copied strokes or copy and merge in active layer"; | ||||
| /* callbacks */ | /* callbacks */ | ||||
| ot->exec = gp_strokes_paste_exec; | ot->exec = gp_strokes_paste_exec; | ||||
| ot->poll = gp_strokes_paste_poll; | ot->poll = gp_strokes_paste_poll; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| /* properties */ | /* properties */ | ||||
| ot->prop = RNA_def_enum(ot->srna, "type", copy_type, 0, "Type", ""); | ot->prop = RNA_def_enum(ot->srna, "type", copy_type, 0, "Type", ""); | ||||
| } | } | ||||
| /* ******************* Move To Layer ****************************** */ | /* ******************* Move To Layer ****************************** */ | ||||
| static int gp_move_to_layer_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(evt)) | static int gp_move_to_layer_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(evt)) | ||||
| ▲ Show 20 Lines • Show All 1,094 Lines • ▼ Show 20 Lines | |||||
| /* --------------------------------- */ | /* --------------------------------- */ | ||||
| static int gp_snap_to_grid(bContext *C, wmOperator *UNUSED(op)) | static int gp_snap_to_grid(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| bGPdata *gpd = ED_gpencil_data_get_active(C); | bGPdata *gpd = ED_gpencil_data_get_active(C); | ||||
| RegionView3D *rv3d = CTX_wm_region_data(C); | RegionView3D *rv3d = CTX_wm_region_data(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph(C); | Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | ||||
| Object *obact = CTX_data_active_object(C); | Object *obact = CTX_data_active_object(C); | ||||
| const float gridf = ED_view3d_grid_view_scale(scene, v3d, rv3d, NULL); | const float gridf = ED_view3d_grid_view_scale(scene, v3d, rv3d, NULL); | ||||
| for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { | for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { | ||||
| /* only editable and visible layers are considered */ | /* only editable and visible layers are considered */ | ||||
| if (gpencil_layer_is_editable(gpl) && (gpl->actframe != NULL)) { | if (gpencil_layer_is_editable(gpl) && (gpl->actframe != NULL)) { | ||||
| bGPDframe *gpf = gpl->actframe; | bGPDframe *gpf = gpl->actframe; | ||||
| float diff_mat[4][4]; | float diff_mat[4][4]; | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | |||||
| /* ------------------------------- */ | /* ------------------------------- */ | ||||
| static int gp_snap_to_cursor(bContext *C, wmOperator *op) | static int gp_snap_to_cursor(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| bGPdata *gpd = ED_gpencil_data_get_active(C); | bGPdata *gpd = ED_gpencil_data_get_active(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph(C); | Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | ||||
| Object *obact = CTX_data_active_object(C); | Object *obact = CTX_data_active_object(C); | ||||
| const bool use_offset = RNA_boolean_get(op->ptr, "use_offset"); | const bool use_offset = RNA_boolean_get(op->ptr, "use_offset"); | ||||
| const float *cursor_global = scene->cursor.location; | const float *cursor_global = scene->cursor.location; | ||||
| for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { | for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { | ||||
| /* only editable and visible layers are considered */ | /* only editable and visible layers are considered */ | ||||
| if (gpencil_layer_is_editable(gpl) && (gpl->actframe != NULL)) { | if (gpencil_layer_is_editable(gpl) && (gpl->actframe != NULL)) { | ||||
| ▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | |||||
| /* ------------------------------- */ | /* ------------------------------- */ | ||||
| static int gp_snap_cursor_to_sel(bContext *C, wmOperator *UNUSED(op)) | static int gp_snap_cursor_to_sel(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| bGPdata *gpd = ED_gpencil_data_get_active(C); | bGPdata *gpd = ED_gpencil_data_get_active(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph(C); | Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | ||||
| Object *obact = CTX_data_active_object(C); | Object *obact = CTX_data_active_object(C); | ||||
| float *cursor = scene->cursor.location; | float *cursor = scene->cursor.location; | ||||
| float centroid[3] = {0.0f}; | float centroid[3] = {0.0f}; | ||||
| float min[3], max[3]; | float min[3], max[3]; | ||||
| size_t count = 0; | size_t count = 0; | ||||
| INIT_MINMAX(min, max); | INIT_MINMAX(min, max); | ||||
| ▲ Show 20 Lines • Show All 697 Lines • ▼ Show 20 Lines | typedef enum eGP_ReprojectModes { | ||||
| GP_REPROJECT_CURSOR, | GP_REPROJECT_CURSOR, | ||||
| } eGP_ReprojectModes; | } eGP_ReprojectModes; | ||||
| static int gp_strokes_reproject_exec(bContext *C, wmOperator *op) | static int gp_strokes_reproject_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| bGPdata *gpd = ED_gpencil_data_get_active(C); | bGPdata *gpd = ED_gpencil_data_get_active(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| ToolSettings *ts = CTX_data_tool_settings(C); | ToolSettings *ts = CTX_data_tool_settings(C); | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph(C); | Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | ||||
| Object *ob = CTX_data_active_object(C); | Object *ob = CTX_data_active_object(C); | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| RegionView3D *rv3d = ar->regiondata; | RegionView3D *rv3d = ar->regiondata; | ||||
| GP_SpaceConversion gsc = {NULL}; | GP_SpaceConversion gsc = {NULL}; | ||||
| eGP_ReprojectModes mode = RNA_enum_get(op->ptr, "type"); | eGP_ReprojectModes mode = RNA_enum_get(op->ptr, "type"); | ||||
| float origin[3]; | float origin[3]; | ||||
| ▲ Show 20 Lines • Show All 152 Lines • ▼ Show 20 Lines | ot->description = | ||||
| "or for matching deforming geometry)"; | "or for matching deforming geometry)"; | ||||
| /* callbacks */ | /* callbacks */ | ||||
| ot->invoke = WM_menu_invoke; | ot->invoke = WM_menu_invoke; | ||||
| ot->exec = gp_strokes_reproject_exec; | ot->exec = gp_strokes_reproject_exec; | ||||
| ot->poll = gp_strokes_edit3d_poll; | ot->poll = gp_strokes_edit3d_poll; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| /* properties */ | /* properties */ | ||||
| ot->prop = RNA_def_enum( | ot->prop = RNA_def_enum( | ||||
| ot->srna, "type", reproject_type, GP_REPROJECT_VIEW, "Projection Type", ""); | ot->srna, "type", reproject_type, GP_REPROJECT_VIEW, "Projection Type", ""); | ||||
| } | } | ||||
| /* ******************* Stroke subdivide ************************** */ | /* ******************* Stroke subdivide ************************** */ | ||||
| /* helper to smooth */ | /* helper to smooth */ | ||||
| ▲ Show 20 Lines • Show All 973 Lines • ▼ Show 20 Lines | void GPENCIL_OT_stroke_cutter(wmOperatorType *ot) | ||||
| /* callbacks */ | /* callbacks */ | ||||
| ot->invoke = WM_gesture_lasso_invoke; | ot->invoke = WM_gesture_lasso_invoke; | ||||
| ot->modal = WM_gesture_lasso_modal; | ot->modal = WM_gesture_lasso_modal; | ||||
| ot->exec = gpencil_cutter_exec; | ot->exec = gpencil_cutter_exec; | ||||
| ot->poll = gpencil_cutter_poll; | ot->poll = gpencil_cutter_poll; | ||||
| ot->cancel = WM_gesture_lasso_cancel; | ot->cancel = WM_gesture_lasso_cancel; | ||||
| /* flag */ | /* flag */ | ||||
| ot->flag = OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; | ot->flag = OPTYPE_UNDO; | ||||
| /* properties */ | /* properties */ | ||||
| WM_operator_properties_gesture_lasso(ot); | WM_operator_properties_gesture_lasso(ot); | ||||
| } | } | ||||
| bool ED_object_gpencil_exit(struct Main *bmain, Object *ob) | bool ED_object_gpencil_exit(struct Main *bmain, Object *ob) | ||||
| { | { | ||||
| bool ok = false; | bool ok = false; | ||||
| Show All 16 Lines | |||||