Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/gpencil_paint.c
| Show First 20 Lines • Show All 1,905 Lines • ▼ Show 20 Lines | if (curarea == NULL) { | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| /* pass on current scene and window */ | /* pass on current scene and window */ | ||||
| p->C = C; | p->C = C; | ||||
| p->bmain = CTX_data_main(C); | p->bmain = CTX_data_main(C); | ||||
| p->scene = CTX_data_scene(C); | p->scene = CTX_data_scene(C); | ||||
| p->depsgraph = CTX_data_depsgraph(C); | p->depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | ||||
| p->win = CTX_wm_window(C); | p->win = CTX_wm_window(C); | ||||
| p->disable_fill = RNA_boolean_get(op->ptr, "disable_fill"); | p->disable_fill = RNA_boolean_get(op->ptr, "disable_fill"); | ||||
| unit_m4(p->imat); | unit_m4(p->imat); | ||||
| unit_m4(p->mat); | unit_m4(p->mat); | ||||
| switch (curarea->spacetype) { | switch (curarea->spacetype) { | ||||
| /* supported views first */ | /* supported views first */ | ||||
| ▲ Show 20 Lines • Show All 520 Lines • ▼ Show 20 Lines | static int gpencil_draw_init(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| p = op->customdata = gp_session_initpaint(C, op); | p = op->customdata = gp_session_initpaint(C, op); | ||||
| if ((p == NULL) || (p->status == GP_STATUS_ERROR)) { | if ((p == NULL) || (p->status == GP_STATUS_ERROR)) { | ||||
| /* something wasn't set correctly in context */ | /* something wasn't set correctly in context */ | ||||
| gpencil_draw_exit(C, op); | gpencil_draw_exit(C, op); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| /* init painting data */ | /* init painting data */ | ||||
| gp_paint_initstroke(p, paintmode, CTX_data_depsgraph(C)); | gp_paint_initstroke(p, paintmode, CTX_data_ensure_evaluated_depsgraph(C)); | ||||
| if (p->status == GP_STATUS_ERROR) { | if (p->status == GP_STATUS_ERROR) { | ||||
| gpencil_draw_exit(C, op); | gpencil_draw_exit(C, op); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| if (event != NULL) { | if (event != NULL) { | ||||
| p->keymodifier = event->keymodifier; | p->keymodifier = event->keymodifier; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 377 Lines • ▼ Show 20 Lines | if (p->flags & GP_PAINTFLAG_REQ_VECTOR) { | ||||
| p->flags &= ~GP_PAINTFLAG_REQ_VECTOR; | p->flags &= ~GP_PAINTFLAG_REQ_VECTOR; | ||||
| /* create fake events */ | /* create fake events */ | ||||
| float tmp[2]; | float tmp[2]; | ||||
| float pt[2]; | float pt[2]; | ||||
| copy_v2_v2(tmp, p->mval); | copy_v2_v2(tmp, p->mval); | ||||
| sub_v2_v2v2(pt, p->mval, p->mvali); | sub_v2_v2v2(pt, p->mval, p->mvali); | ||||
| gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph(C), pt[0], pt[1]); | gpencil_draw_apply_event(C, op, event, depsgraph, pt[0], pt[1]); | ||||
| if (len_v2v2(p->mval, p->mvalo)) { | if (len_v2v2(p->mval, p->mvalo)) { | ||||
| sub_v2_v2v2(pt, p->mval, p->mvalo); | sub_v2_v2v2(pt, p->mval, p->mvalo); | ||||
| gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph(C), pt[0], pt[1]); | gpencil_draw_apply_event(C, op, event, depsgraph, pt[0], pt[1]); | ||||
| } | } | ||||
| copy_v2_v2(p->mval, tmp); | copy_v2_v2(p->mval, tmp); | ||||
| } | } | ||||
| /* check if stroke is straight or guided */ | /* check if stroke is straight or guided */ | ||||
| if ((p->paintmode != GP_PAINTMODE_ERASER) && ((p->straight) || (is_speed_guide))) { | if ((p->paintmode != GP_PAINTMODE_ERASER) && ((p->straight) || (is_speed_guide))) { | ||||
| /* guided stroke */ | /* guided stroke */ | ||||
| if (is_speed_guide) { | if (is_speed_guide) { | ||||
| ▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /* ------------------------------- */ | /* ------------------------------- */ | ||||
| /* operator 'redo' (i.e. after changing some properties, but also for repeat last) */ | /* operator 'redo' (i.e. after changing some properties, but also for repeat last) */ | ||||
| static int gpencil_draw_exec(bContext *C, wmOperator *op) | static int gpencil_draw_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| tGPsdata *p = NULL; | tGPsdata *p = NULL; | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph(C); | Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | ||||
| /* printf("GPencil - Starting Re-Drawing\n"); */ | /* printf("GPencil - Starting Re-Drawing\n"); */ | ||||
| /* try to initialize context data needed while drawing */ | /* try to initialize context data needed while drawing */ | ||||
| if (!gpencil_draw_init(C, op, NULL)) { | if (!gpencil_draw_init(C, op, NULL)) { | ||||
| MEM_SAFE_FREE(op->customdata); | MEM_SAFE_FREE(op->customdata); | ||||
| /* printf("\tGP - no valid data\n"); */ | /* printf("\tGP - no valid data\n"); */ | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| ▲ Show 20 Lines • Show All 231 Lines • ▼ Show 20 Lines | static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| /* only start drawing immediately if we're allowed to do so... */ | /* only start drawing immediately if we're allowed to do so... */ | ||||
| if (RNA_boolean_get(op->ptr, "wait_for_input") == false) { | if (RNA_boolean_get(op->ptr, "wait_for_input") == false) { | ||||
| /* hotkey invoked - start drawing */ | /* hotkey invoked - start drawing */ | ||||
| /* printf("\tGP - set first spot\n"); */ | /* printf("\tGP - set first spot\n"); */ | ||||
| p->status = GP_STATUS_PAINTING; | p->status = GP_STATUS_PAINTING; | ||||
| /* handle the initial drawing - i.e. for just doing a simple dot */ | /* handle the initial drawing - i.e. for just doing a simple dot */ | ||||
| gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph(C), 0.0f, 0.0f); | gpencil_draw_apply_event(C, op, event, CTX_data_ensure_evaluated_depsgraph(C), 0.0f, 0.0f); | ||||
| op->flag |= OP_IS_MODAL_CURSOR_REGION; | op->flag |= OP_IS_MODAL_CURSOR_REGION; | ||||
| } | } | ||||
| else { | else { | ||||
| /* toolbar invoked - don't start drawing yet... */ | /* toolbar invoked - don't start drawing yet... */ | ||||
| /* printf("\tGP - hotkey invoked... waiting for click-drag\n"); */ | /* printf("\tGP - hotkey invoked... waiting for click-drag\n"); */ | ||||
| op->flag |= OP_IS_MODAL_CURSOR_REGION; | op->flag |= OP_IS_MODAL_CURSOR_REGION; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | static tGPsdata *gpencil_stroke_begin(bContext *C, wmOperator *op) | ||||
| /* printf("\t\tGP - start stroke\n"); */ | /* printf("\t\tGP - start stroke\n"); */ | ||||
| /* we may need to set up paint env again if we're resuming */ | /* we may need to set up paint env again if we're resuming */ | ||||
| /* XXX: watch it with the paintmode! in future, | /* XXX: watch it with the paintmode! in future, | ||||
| * it'd be nice to allow changing paint-mode when in sketching-sessions */ | * it'd be nice to allow changing paint-mode when in sketching-sessions */ | ||||
| if (gp_session_initdata(C, op, p)) { | if (gp_session_initdata(C, op, p)) { | ||||
| gp_paint_initstroke(p, p->paintmode, CTX_data_depsgraph(C)); | gp_paint_initstroke(p, p->paintmode, CTX_data_depsgraph_pointer(C)); | ||||
| } | } | ||||
| if (p->status != GP_STATUS_ERROR) { | if (p->status != GP_STATUS_ERROR) { | ||||
| p->status = GP_STATUS_PAINTING; | p->status = GP_STATUS_PAINTING; | ||||
| op->flag &= ~OP_IS_MODAL_CURSOR_REGION; | op->flag &= ~OP_IS_MODAL_CURSOR_REGION; | ||||
| } | } | ||||
| return op->customdata; | return op->customdata; | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
| /* add events for missing mouse movements when the artist draw very fast */ | /* add events for missing mouse movements when the artist draw very fast */ | ||||
| static void gpencil_add_missing_events(bContext *C, | static void gpencil_add_missing_events(bContext *C, | ||||
| wmOperator *op, | wmOperator *op, | ||||
| const wmEvent *event, | const wmEvent *event, | ||||
| tGPsdata *p) | tGPsdata *p) | ||||
| { | { | ||||
| Brush *brush = p->brush; | Brush *brush = p->brush; | ||||
| GP_Sculpt_Guide *guide = &p->scene->toolsettings->gp_sculpt.guide; | GP_Sculpt_Guide *guide = &p->scene->toolsettings->gp_sculpt.guide; | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); | |||||
| int input_samples = brush->gpencil_settings->input_samples; | int input_samples = brush->gpencil_settings->input_samples; | ||||
| /* ensure sampling when using circular guide */ | /* ensure sampling when using circular guide */ | ||||
| if (guide->use_guide && (guide->type == GP_GUIDE_CIRCULAR)) { | if (guide->use_guide && (guide->type == GP_GUIDE_CIRCULAR)) { | ||||
| input_samples = GP_MAX_INPUT_SAMPLES; | input_samples = GP_MAX_INPUT_SAMPLES; | ||||
| } | } | ||||
| if (input_samples == 0) { | if (input_samples == 0) { | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | static void gpencil_add_missing_events(bContext *C, | ||||
| /* get distance in pixels */ | /* get distance in pixels */ | ||||
| float dist = len_v2v2(a, b); | float dist = len_v2v2(a, b); | ||||
| /* for very small distances, add a half way point */ | /* for very small distances, add a half way point */ | ||||
| if (dist <= 2.0f) { | if (dist <= 2.0f) { | ||||
| interp_v2_v2v2(pt, a, b, 0.5f); | interp_v2_v2v2(pt, a, b, 0.5f); | ||||
| sub_v2_v2v2(pt, b, pt); | sub_v2_v2v2(pt, b, pt); | ||||
| /* create fake event */ | /* create fake event */ | ||||
| gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph(C), pt[0], pt[1]); | gpencil_draw_apply_event(C, op, event, depsgraph, pt[0], pt[1]); | ||||
| } | } | ||||
| else if (dist >= factor) { | else if (dist >= factor) { | ||||
| int slices = 2 + (int)((dist - 1.0) / factor); | int slices = 2 + (int)((dist - 1.0) / factor); | ||||
| float n = 1.0f / slices; | float n = 1.0f / slices; | ||||
| for (int i = 1; i < slices; i++) { | for (int i = 1; i < slices; i++) { | ||||
| interp_v2_v2v2(pt, a, b, n * i); | interp_v2_v2v2(pt, a, b, n * i); | ||||
| sub_v2_v2v2(pt, b, pt); | sub_v2_v2v2(pt, b, pt); | ||||
| /* create fake event */ | /* create fake event */ | ||||
| gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph(C), pt[0], pt[1]); | gpencil_draw_apply_event(C, op, event, depsgraph, pt[0], pt[1]); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* events handling during interactive drawing part of operator */ | /* events handling during interactive drawing part of operator */ | ||||
| static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event) | static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| { | { | ||||
| tGPsdata *p = op->customdata; | tGPsdata *p = op->customdata; | ||||
| ▲ Show 20 Lines • Show All 290 Lines • ▼ Show 20 Lines | if (p->status == GP_STATUS_PAINTING) { | ||||
| if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE) || (p->flags & GP_PAINTFLAG_FIRSTRUN)) { | if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE) || (p->flags & GP_PAINTFLAG_FIRSTRUN)) { | ||||
| /* handle drawing event */ | /* handle drawing event */ | ||||
| /* printf("\t\tGP - add point\n"); */ | /* printf("\t\tGP - add point\n"); */ | ||||
| if (((p->flags & GP_PAINTFLAG_FIRSTRUN) == 0) && (p->paintmode != GP_PAINTMODE_ERASER)) { | if (((p->flags & GP_PAINTFLAG_FIRSTRUN) == 0) && (p->paintmode != GP_PAINTMODE_ERASER)) { | ||||
| gpencil_add_missing_events(C, op, event, p); | gpencil_add_missing_events(C, op, event, p); | ||||
| } | } | ||||
| gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph(C), 0.0f, 0.0f); | gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph_pointer(C), 0.0f, 0.0f); | ||||
| /* finish painting operation if anything went wrong just now */ | /* finish painting operation if anything went wrong just now */ | ||||
| if (p->status == GP_STATUS_ERROR) { | if (p->status == GP_STATUS_ERROR) { | ||||
| printf("\t\t\t\tGP - add error done!\n"); | printf("\t\t\t\tGP - add error done!\n"); | ||||
| estate = OPERATOR_CANCELLED; | estate = OPERATOR_CANCELLED; | ||||
| } | } | ||||
| else { | else { | ||||
| /* event handled, so just tag as running modal */ | /* event handled, so just tag as running modal */ | ||||
| ▲ Show 20 Lines • Show All 204 Lines • Show Last 20 Lines | |||||