Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/annotate_paint.c
| Show First 20 Lines • Show All 212 Lines • ▼ Show 20 Lines | |||||
| static void gp_session_validatebuffer(tGPsdata *p); | static void gp_session_validatebuffer(tGPsdata *p); | ||||
| /* ******************************************* */ | /* ******************************************* */ | ||||
| /* Context Wrangling... */ | /* Context Wrangling... */ | ||||
| /* check if context is suitable for drawing */ | /* check if context is suitable for drawing */ | ||||
| static bool gpencil_draw_poll(bContext *C) | static bool gpencil_draw_poll(bContext *C) | ||||
| { | { | ||||
| /* if is inside grease pencil draw mode cannot use annotations */ | |||||
| Object *obact = CTX_data_active_object(C); | |||||
| ScrArea *sa = CTX_wm_area(C); | |||||
| if ((sa) && (sa->spacetype == SPACE_VIEW3D)) { | |||||
| if ((obact) && (obact->type == OB_GPENCIL) && (obact->mode == OB_MODE_PAINT_GPENCIL)) { | |||||
| CTX_wm_operator_poll_msg_set(C, "Annotation cannot be used in grease pencil draw mode"); | |||||
| return false; | |||||
| } | |||||
| } | |||||
| if (ED_operator_regionactive(C)) { | if (ED_operator_regionactive(C)) { | ||||
| /* check if current context can support GPencil data */ | /* check if current context can support GPencil data */ | ||||
| if (ED_gpencil_data_get_pointers(C, NULL) != NULL) { | if (ED_annotation_data_get_pointers(C, NULL) != NULL) { | ||||
| /* check if Grease Pencil isn't already running */ | /* check if Grease Pencil isn't already running */ | ||||
| if (ED_gpencil_session_active() == 0) { | if (ED_gpencil_session_active() == 0) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| else { | else { | ||||
| CTX_wm_operator_poll_msg_set(C, "Annotation operator is already active"); | CTX_wm_operator_poll_msg_set(C, "Annotation operator is already active"); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| CTX_wm_operator_poll_msg_set(C, "Failed to find Grease Pencil data to draw into"); | CTX_wm_operator_poll_msg_set(C, "Failed to find Annotation data to draw into"); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| CTX_wm_operator_poll_msg_set(C, "Active region not set"); | CTX_wm_operator_poll_msg_set(C, "Active region not set"); | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 858 Lines • ▼ Show 20 Lines | default: { | ||||
| if (G.debug & G_DEBUG) { | if (G.debug & G_DEBUG) { | ||||
| printf("Error: Annotations are not supported in this editor\n"); | printf("Error: Annotations are not supported in this editor\n"); | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| } | } | ||||
| /* get gp-data */ | /* get gp-data */ | ||||
| gpd_ptr = ED_gpencil_data_get_pointers(C, &p->ownerPtr); | gpd_ptr = ED_annotation_data_get_pointers(C, &p->ownerPtr); | ||||
| if ((gpd_ptr == NULL) || !ED_gpencil_data_owner_is_annotation(&p->ownerPtr)) { | if ((gpd_ptr == NULL) || !ED_gpencil_data_owner_is_annotation(&p->ownerPtr)) { | ||||
| p->status = GP_STATUS_ERROR; | p->status = GP_STATUS_ERROR; | ||||
| if (G.debug & G_DEBUG) { | if (G.debug & G_DEBUG) { | ||||
| printf("Error: Current context doesn't allow for any Annotation data\n"); | printf("Error: Current context doesn't allow for any Annotation data\n"); | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| else { | else { | ||||
| ▲ Show 20 Lines • Show All 754 Lines • ▼ Show 20 Lines | static int gpencil_draw_exec(bContext *C, wmOperator *op) | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| /* ------------------------------- */ | /* ------------------------------- */ | ||||
| /* start of interactive drawing part of operator */ | /* start of interactive drawing part of operator */ | ||||
| static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event) | static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| { | { | ||||
| Object *ob = CTX_data_active_object(C); | |||||
| ScrArea *sa = CTX_wm_area(C); | |||||
| Scene *scene = CTX_data_scene(C); | |||||
| tGPsdata *p = NULL; | tGPsdata *p = NULL; | ||||
| /* support for tablets eraser pen */ | /* support for tablets eraser pen */ | ||||
| if (gpencil_is_tablet_eraser_active(event)) { | if (gpencil_is_tablet_eraser_active(event)) { | ||||
| RNA_enum_set(op->ptr, "mode", GP_PAINTMODE_ERASER); | RNA_enum_set(op->ptr, "mode", GP_PAINTMODE_ERASER); | ||||
| } | } | ||||
| /* if try to do annotations with a gp object selected, first | |||||
| * unselect the object to avoid conflicts. | |||||
| * The solution is not perfect but we can keep running the annotations while | |||||
| * found a better solution. | |||||
| */ | |||||
| if (sa && sa->spacetype == SPACE_VIEW3D) { | |||||
| if ((ob != NULL) && (ob->type == OB_GPENCIL)) { | |||||
| ob->mode = OB_MODE_OBJECT; | |||||
| bGPdata *gpd = (bGPdata *)ob->data; | |||||
| ED_gpencil_setup_modes(C, gpd, 0); | |||||
| DEG_id_tag_update(&gpd->id, ID_RECALC_COPY_ON_WRITE); | |||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | |||||
| BKE_view_layer_base_deselect_all(view_layer); | |||||
| view_layer->basact = NULL; | |||||
| DEG_id_tag_update(&scene->id, ID_RECALC_SELECT); | |||||
| WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); | |||||
| } | |||||
| } | |||||
| if (G.debug & G_DEBUG) { | if (G.debug & G_DEBUG) { | ||||
| printf("GPencil - Starting Drawing\n"); | printf("GPencil - Starting Drawing\n"); | ||||
| } | } | ||||
| /* try to initialize context data needed while drawing */ | /* try to initialize context data needed while drawing */ | ||||
| if (!gpencil_draw_init(C, op, event)) { | if (!gpencil_draw_init(C, op, event)) { | ||||
| if (op->customdata) { | if (op->customdata) { | ||||
| MEM_freeN(op->customdata); | MEM_freeN(op->customdata); | ||||
| ▲ Show 20 Lines • Show All 513 Lines • Show Last 20 Lines | |||||