Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/gpencil_edit.c
| Show All 33 Lines | |||||
| #include "BLI_ghash.h" | #include "BLI_ghash.h" | ||||
| #include "BLI_lasso_2d.h" | #include "BLI_lasso_2d.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLT_translation.h" | #include "BLT_translation.h" | ||||
| #include "DNA_gpencil_modifier_types.h" | |||||
| #include "DNA_gpencil_types.h" | #include "DNA_gpencil_types.h" | ||||
| #include "DNA_meshdata_types.h" | #include "DNA_meshdata_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_screen_types.h" | #include "DNA_screen_types.h" | ||||
| #include "DNA_space_types.h" | #include "DNA_space_types.h" | ||||
| #include "DNA_view3d_types.h" | #include "DNA_view3d_types.h" | ||||
| #include "BKE_brush.h" | #include "BKE_brush.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_gpencil.h" | #include "BKE_gpencil.h" | ||||
| #include "BKE_gpencil_geom.h" | #include "BKE_gpencil_geom.h" | ||||
| #include "BKE_layer.h" | |||||
| #include "BKE_lib_id.h" | #include "BKE_lib_id.h" | ||||
| #include "BKE_library.h" | |||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_material.h" | #include "BKE_material.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_paint.h" | #include "BKE_paint.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "BKE_workspace.h" | #include "BKE_workspace.h" | ||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_message.h" | #include "WM_message.h" | ||||
| #include "WM_toolsystem.h" | #include "WM_toolsystem.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "RNA_define.h" | #include "RNA_define.h" | ||||
| #include "RNA_enum_types.h" | #include "RNA_enum_types.h" | ||||
| #include "UI_view2d.h" | #include "UI_view2d.h" | ||||
| #include "ED_armature.h" | |||||
| #include "ED_gpencil.h" | #include "ED_gpencil.h" | ||||
| #include "ED_object.h" | #include "ED_object.h" | ||||
| #include "ED_outliner.h" | #include "ED_outliner.h" | ||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| #include "ED_select_utils.h" | #include "ED_select_utils.h" | ||||
| #include "ED_space_api.h" | #include "ED_space_api.h" | ||||
| #include "ED_transform_snap_object_context.h" | #include "ED_transform_snap_object_context.h" | ||||
| #include "ED_view3d.h" | #include "ED_view3d.h" | ||||
| ▲ Show 20 Lines • Show All 480 Lines • ▼ Show 20 Lines | static int gpencil_weightmode_toggle_exec(bContext *C, wmOperator *op) | ||||
| 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; | ||||
| } | } | ||||
| const int mode_flag = OB_MODE_WEIGHT_GPENCIL; | |||||
| const bool is_mode_set = (ob->mode & mode_flag) != 0; | |||||
| if (gpd == NULL) { | if (gpd == NULL) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| /* Just toggle weightmode flag... */ | /* Just toggle weightmode flag... */ | ||||
| gpd->flag ^= GP_DATA_STROKE_WEIGHTMODE; | gpd->flag ^= GP_DATA_STROKE_WEIGHTMODE; | ||||
| /* set mode */ | /* set mode */ | ||||
| if (gpd->flag & GP_DATA_STROKE_WEIGHTMODE) { | if (gpd->flag & GP_DATA_STROKE_WEIGHTMODE) { | ||||
| mode = OB_MODE_WEIGHT_GPENCIL; | mode = OB_MODE_WEIGHT_GPENCIL; | ||||
| } | } | ||||
| else { | else { | ||||
| mode = OB_MODE_OBJECT; | mode = OB_MODE_OBJECT; | ||||
| } | } | ||||
| if (is_object) { | if (is_object) { | ||||
| /* try to back previous mode */ | /* try to back previous mode */ | ||||
| if ((ob->restore_mode) && ((gpd->flag & GP_DATA_STROKE_WEIGHTMODE) == 0) && (back == 1)) { | if ((ob->restore_mode) && ((gpd->flag & GP_DATA_STROKE_WEIGHTMODE) == 0) && (back == 1)) { | ||||
| mode = ob->restore_mode; | mode = ob->restore_mode; | ||||
| } | } | ||||
| ob->restore_mode = ob->mode; | ob->restore_mode = ob->mode; | ||||
| ob->mode = mode; | ob->mode = mode; | ||||
| /* Prepare armature posemode. */ | |||||
| ED_object_mode_weight_armature_posemode_toggle(C, bmain, ob, is_mode_set); | |||||
| } | } | ||||
campbellbarton: This is copying a fairly large block of code from `paint_vertex.c`, this should be moved into a… | |||||
| if (mode == OB_MODE_WEIGHT_GPENCIL) { | if (mode == OB_MODE_WEIGHT_GPENCIL) { | ||||
| /* Be sure we have brushes. */ | /* Be sure we have brushes. */ | ||||
| BKE_paint_ensure(ts, (Paint **)&ts->gp_weightpaint); | BKE_paint_ensure(ts, (Paint **)&ts->gp_weightpaint); | ||||
| const bool reset_mode = (ts->gp_weightpaint->paint.brush == NULL); | const bool reset_mode = (ts->gp_weightpaint->paint.brush == NULL); | ||||
| BKE_brush_gpencil_weight_presets(bmain, ts, reset_mode); | BKE_brush_gpencil_weight_presets(bmain, ts, reset_mode); | ||||
| ▲ Show 20 Lines • Show All 4,358 Lines • Show Last 20 Lines | |||||
This is copying a fairly large block of code from paint_vertex.c, this should be moved into a shared function. Or, if this is not an options because of the modifier type, two functions next to each other, although I think it's worth attempting to generalize them, even if the modifier type check happens inside the modifier loop.