static int edbm_inset_modal(bContext *C, wmOperator *op, const wmEvent *event) { InsetData *opdata = op->customdata; const bool has_numinput = hasNumInput(&opdata->num_input); /* Modal numinput active, try to handle numeric inputs first... */ if (event->val == KM_PRESS && has_numinput && handleNumInput(C, &opdata->num_input, event)) { float amounts[2] = {RNA_float_get(op->ptr, "thickness"), RNA_float_get(op->ptr, "depth")}; applyNumInput(&opdata->num_input, amounts); amounts[0] = max_ff(amounts[0], 0.0f); RNA_float_set(op->ptr, "thickness", amounts[0]); RNA_float_set(op->ptr, "depth", amounts[1]); if (edbm_inset_calc(op)) { edbm_inset_update_header(op, C); return OPERATOR_RUNNING_MODAL; } else { edbm_inset_cancel(C, op); return OPERATOR_CANCELLED; } } else { bool handled = false; switch (event->type) { case ESCKEY: case RIGHTMOUSE: edbm_inset_cancel(C, op); return OPERATOR_CANCELLED; case MOUSEMOVE: if (!has_numinput) { float mdiff[2]; float amount; mdiff[0] = opdata->mcenter[0] - event->mval[0]; mdiff[1] = opdata->mcenter[1] - event->mval[1]; if (opdata->modify_depth) amount = opdata->old_depth + ((len_v2(mdiff) - opdata->initial_length) * opdata->pixel_size); else amount = opdata->old_thickness - ((len_v2(mdiff) - opdata->initial_length) * opdata->pixel_size); /* Fake shift-transform... */ if (opdata->shift) amount = (amount - opdata->shift_amount) * 0.1f + opdata->shift_amount; if (opdata->modify_depth) RNA_float_set(op->ptr, "depth", amount); else { amount = max_ff(amount, 0.0f); RNA_float_set(op->ptr, "thickness", amount); } if (edbm_inset_calc(op)) edbm_inset_update_header(op, C); else { edbm_inset_cancel(C, op); return OPERATOR_CANCELLED; } handled = true; } break; case LEFTMOUSE: case PADENTER: case RETKEY: edbm_inset_calc(op); edbm_inset_exit(C, op); return OPERATOR_FINISHED; case LEFTSHIFTKEY: case RIGHTSHIFTKEY: if (event->val == KM_PRESS) { if (opdata->modify_depth) opdata->shift_amount = RNA_float_get(op->ptr, "depth"); else opdata->shift_amount = RNA_float_get(op->ptr, "thickness"); opdata->shift = true; handled = true; } else { opdata->shift_amount = 0.0f; opdata->shift = false; handled = true; } break; case LEFTCTRLKEY: case RIGHTCTRLKEY: { float mlen[2]; mlen[0] = opdata->mcenter[0] - event->mval[0]; mlen[1] = opdata->mcenter[1] - event->mval[1]; if (event->val == KM_PRESS) { opdata->old_thickness = RNA_float_get(op->ptr, "thickness"); if (opdata->shift) opdata->shift_amount = opdata->old_thickness; opdata->modify_depth = true; } else { opdata->old_depth = RNA_float_get(op->ptr, "depth"); if (opdata->shift) opdata->shift_amount = opdata->old_depth; opdata->modify_depth = false; } opdata->initial_length = len_v2(mlen); edbm_inset_update_header(op, C); handled = true; break; } case OKEY: if (event->val == KM_PRESS) { const bool use_outset = RNA_boolean_get(op->ptr, "use_outset"); RNA_boolean_set(op->ptr, "use_outset", !use_outset); if (edbm_inset_calc(op)) { edbm_inset_update_header(op, C); } else { edbm_inset_cancel(C, op); return OPERATOR_CANCELLED; } handled = true; } break; case BKEY: if (event->val == KM_PRESS) { const bool use_boundary = RNA_boolean_get(op->ptr, "use_boundary"); RNA_boolean_set(op->ptr, "use_boundary", !use_boundary); if (edbm_inset_calc(op)) { edbm_inset_update_header(op, C); } else { edbm_inset_cancel(C, op); return OPERATOR_CANCELLED; } handled = true; } break; case IKEY: if (event->val == KM_PRESS) { const bool use_individual = RNA_boolean_get(op->ptr, "use_individual"); RNA_boolean_set(op->ptr, "use_individual", !use_individual); if (edbm_inset_calc(op)) { edbm_inset_update_header(op, C); } else { edbm_inset_cancel(C, op); return OPERATOR_CANCELLED; } handled = true; } break; } /* Modal numinput inactive, try to handle numeric inputs last... */ if (!handled && event->val == KM_PRESS && handleNumInput(C, &opdata->num_input, event)) { float amounts[2] = {RNA_float_get(op->ptr, "thickness"), RNA_float_get(op->ptr, "depth")}; applyNumInput(&opdata->num_input, amounts); amounts[0] = max_ff(amounts[0], 0.0f); RNA_float_set(op->ptr, "thickness", amounts[0]); RNA_float_set(op->ptr, "depth", amounts[1]); if (edbm_inset_calc(op)) { edbm_inset_update_header(op, C); return OPERATOR_RUNNING_MODAL; } else { edbm_inset_cancel(C, op); return OPERATOR_CANCELLED; } } } return OPERATOR_RUNNING_MODAL; }
static int edbm_bevel_modal(bContext *C, wmOperator *op, const wmEvent *event) { BevelData *opdata = op->customdata; int segments = RNA_int_get(op->ptr, "segments"); if (event->val == KM_PRESS) { /* Try to handle numeric inputs... */ if (handleNumInput(&opdata->num_input, event)) { float value = RNA_float_get(op->ptr, "offset"); applyNumInput(&opdata->num_input, &value); RNA_float_set(op->ptr, "offset", value); edbm_bevel_calc(op); edbm_bevel_update_header(op, C); return OPERATOR_RUNNING_MODAL; } } switch (event->type) { case ESCKEY: case RIGHTMOUSE: edbm_bevel_cancel(C, op); return OPERATOR_CANCELLED; case MOUSEMOVE: if (!hasNumInput(&opdata->num_input)) { const float factor = edbm_bevel_mval_factor(op, event); RNA_float_set(op->ptr, "offset", factor); edbm_bevel_calc(op); edbm_bevel_update_header(op, C); } break; case LEFTMOUSE: case PADENTER: case RETKEY: edbm_bevel_calc(op); edbm_bevel_exit(C, op); return OPERATOR_FINISHED; case WHEELUPMOUSE: /* change number of segments */ case PADPLUSKEY: if (event->val == KM_RELEASE) break; segments++; RNA_int_set(op->ptr, "segments", segments); edbm_bevel_calc(op); edbm_bevel_update_header(op, C); break; case WHEELDOWNMOUSE: /* change number of segments */ case PADMINUS: if (event->val == KM_RELEASE) break; segments = max_ii(segments - 1, 1); RNA_int_set(op->ptr, "segments", segments); edbm_bevel_calc(op); edbm_bevel_update_header(op, C); break; } return OPERATOR_RUNNING_MODAL; }
static int ed_marker_move_modal(bContext *C, wmOperator *op, wmEvent *evt) { Scene *scene= CTX_data_scene(C); MarkerMove *mm= op->customdata; View2D *v2d= UI_view2d_fromcontext(C); TimeMarker *marker, *selmarker=NULL; float dx, fac; char str[256]; switch(evt->type) { case ESCKEY: ed_marker_move_cancel(C, op); return OPERATOR_CANCELLED; case RETKEY: case PADENTER: case LEFTMOUSE: case MIDDLEMOUSE: case RIGHTMOUSE: if (WM_modal_tweak_exit(evt, mm->event_type)) { ed_marker_move_exit(C, op); WM_event_add_notifier(C, NC_SCENE|ND_MARKERS, NULL); WM_event_add_notifier(C, NC_ANIMATION|ND_MARKERS, NULL); return OPERATOR_FINISHED; } break; case MOUSEMOVE: if (hasNumInput(&mm->num)) break; dx= v2d->mask.xmax-v2d->mask.xmin; dx= (v2d->cur.xmax-v2d->cur.xmin)/dx; if (evt->x != mm->evtx) { /* XXX maybe init for firsttime */ int a, offs, totmark=0; mm->evtx= evt->x; fac= ((float)(evt->x - mm->firstx)*dx); if (ELEM(mm->slink->spacetype, SPACE_TIME, SPACE_SOUND)) apply_keyb_grid(evt->shift, evt->ctrl, &fac, 0.0, FPS, 0.1*FPS, 0); else apply_keyb_grid(evt->shift, evt->ctrl, &fac, 0.0, 1.0, 0.1, 0 /*was: U.flag & USER_AUTOGRABGRID*/); offs= (int)fac; RNA_int_set(op->ptr, "frames", offs); ed_marker_move_apply(op); /* cruft below is for header print */ for (a=0, marker= mm->markers->first; marker; marker= marker->next) { if (marker->flag & SELECT) { selmarker= marker; a++; totmark++; } } if (totmark==1) { /* we print current marker value */ if (ELEM(mm->slink->spacetype, SPACE_TIME, SPACE_SOUND)) { SpaceTime *stime= (SpaceTime *)mm->slink; if (stime->flag & TIME_DRAWFRAMES) BLI_snprintf(str, sizeof(str), "Marker %d offset %d", selmarker->frame, offs); else BLI_snprintf(str, sizeof(str), "Marker %.2f offset %.2f", FRA2TIME(selmarker->frame), FRA2TIME(offs)); } else if (mm->slink->spacetype == SPACE_ACTION) { SpaceAction *saction= (SpaceAction *)mm->slink; if (saction->flag & SACTION_DRAWTIME) BLI_snprintf(str, sizeof(str), "Marker %.2f offset %.2f", FRA2TIME(selmarker->frame), FRA2TIME(offs)); else BLI_snprintf(str, sizeof(str), "Marker %.2f offset %.2f", (double)(selmarker->frame), (double)(offs)); } else { BLI_snprintf(str, sizeof(str), "Marker %.2f offset %.2f", (double)(selmarker->frame), (double)(offs)); } } else { /* we only print the offset */ if (ELEM(mm->slink->spacetype, SPACE_TIME, SPACE_SOUND)) { SpaceTime *stime= (SpaceTime *)mm->slink; if (stime->flag & TIME_DRAWFRAMES) BLI_snprintf(str, sizeof(str), "Marker offset %d ", offs); else BLI_snprintf(str, sizeof(str), "Marker offset %.2f ", FRA2TIME(offs)); } else if (mm->slink->spacetype == SPACE_ACTION) { SpaceAction *saction= (SpaceAction *)mm->slink; if (saction->flag & SACTION_DRAWTIME) BLI_snprintf(str, sizeof(str), "Marker offset %.2f ", FRA2TIME(offs)); else BLI_snprintf(str, sizeof(str), "Marker offset %.2f ", (double)(offs)); } else { BLI_snprintf(str, sizeof(str), "Marker offset %.2f ", (double)(offs)); } } WM_event_add_notifier(C, NC_SCENE|ND_MARKERS, NULL); WM_event_add_notifier(C, NC_ANIMATION|ND_MARKERS, NULL); ED_area_headerprint(CTX_wm_area(C), str); } } if (evt->val==KM_PRESS) { float vec[3]; char str_tx[256]; if (handleNumInput(&mm->num, evt)) { applyNumInput(&mm->num, vec); outputNumInput(&mm->num, str_tx); RNA_int_set(op->ptr, "frames", vec[0]); ed_marker_move_apply(op); // ed_marker_header_update(C, op, str, (int)vec[0]); // strcat(str, str_tx); BLI_snprintf(str, sizeof(str), "Marker offset %s", str_tx); ED_area_headerprint(CTX_wm_area(C), str); WM_event_add_notifier(C, NC_SCENE|ND_MARKERS, NULL); WM_event_add_notifier(C, NC_ANIMATION|ND_MARKERS, NULL); } } return OPERATOR_RUNNING_MODAL; }
/* common code for modal() */ static int pose_slide_modal(bContext *C, wmOperator *op, const wmEvent *event) { tPoseSlideOp *pso = op->customdata; wmWindow *win = CTX_wm_window(C); const bool has_numinput = hasNumInput(&pso->num); switch (event->type) { case LEFTMOUSE: /* confirm */ case RETKEY: case PADENTER: { /* return to normal cursor and header status */ ED_area_headerprint(pso->sa, NULL); WM_cursor_modal_restore(win); /* insert keyframes as required... */ pose_slide_autoKeyframe(C, pso); pose_slide_exit(op); /* done! */ return OPERATOR_FINISHED; } case ESCKEY: /* cancel */ case RIGHTMOUSE: { /* return to normal cursor and header status */ ED_area_headerprint(pso->sa, NULL); WM_cursor_modal_restore(win); /* reset transforms back to original state */ pose_slide_reset(pso); /* depsgraph updates + redraws */ pose_slide_refresh(C, pso); /* clean up temp data */ pose_slide_exit(op); /* canceled! */ return OPERATOR_CANCELLED; } case MOUSEMOVE: /* calculate new position */ { /* only handle mousemove if not doing numinput */ if (has_numinput == false) { /* update percentage based on position of mouse */ pose_slide_mouse_update_percentage(pso, op, event); /* update percentage indicator in header */ pose_slide_draw_status(pso); /* reset transforms (to avoid accumulation errors) */ pose_slide_reset(pso); /* apply... */ pose_slide_apply(C, pso); } break; } default: if ((event->val == KM_PRESS) && handleNumInput(C, &pso->num, event)) { float value; /* Grab percentage from numeric input, and store this new value for redo * NOTE: users see ints, while internally we use a 0-1 float */ value = pso->percentage * 100.0f; applyNumInput(&pso->num, &value); pso->percentage = value / 100.0f; CLAMP(pso->percentage, 0.0f, 1.0f); RNA_float_set(op->ptr, "percentage", pso->percentage); /* update percentage indicator in header */ pose_slide_draw_status(pso); /* reset transforms (to avoid accumulation errors) */ pose_slide_reset(pso); /* apply... */ pose_slide_apply(C, pso); break; } else { /* unhandled event - maybe it was some view manip? */ /* allow to pass through */ return OPERATOR_RUNNING_MODAL | OPERATOR_PASS_THROUGH; } } /* still running... */ return OPERATOR_RUNNING_MODAL; }
static int edbm_bevel_modal(bContext *C, wmOperator *op, const wmEvent *event) { BevelData *opdata = op->customdata; int segments = RNA_int_get(op->ptr, "segments"); if (event->val == KM_PRESS && hasNumInput(&opdata->num_input)) { /* Modal numinput active, try to handle numeric inputs first... */ if (handleNumInput(C, &opdata->num_input, event)) { float value = RNA_float_get(op->ptr, "offset"); applyNumInput(&opdata->num_input, &value); RNA_float_set(op->ptr, "offset", value); edbm_bevel_calc(op); edbm_bevel_update_header(op, C); return OPERATOR_RUNNING_MODAL; } } else { bool handled = false; switch (event->type) { case ESCKEY: case RIGHTMOUSE: edbm_bevel_cancel(C, op); return OPERATOR_CANCELLED; case MOUSEMOVE: if (!hasNumInput(&opdata->num_input)) { const float factor = edbm_bevel_mval_factor(op, event); RNA_float_set(op->ptr, "offset", factor); edbm_bevel_calc(op); edbm_bevel_update_header(op, C); handled = true; } break; case LEFTMOUSE: case PADENTER: case RETKEY: edbm_bevel_calc(op); edbm_bevel_exit(C, op); return OPERATOR_FINISHED; /* Note this will prevent padplus and padminus to ever activate modal numinput. * This is not really an issue though, as we only expect positive values here... * Else we could force them to only modify segments number when shift is pressed, or so. */ case WHEELUPMOUSE: /* change number of segments */ case PADPLUSKEY: if (event->val == KM_RELEASE) break; segments++; RNA_int_set(op->ptr, "segments", segments); edbm_bevel_calc(op); edbm_bevel_update_header(op, C); handled = true; break; case WHEELDOWNMOUSE: /* change number of segments */ case PADMINUS: if (event->val == KM_RELEASE) break; segments = max_ii(segments - 1, 1); RNA_int_set(op->ptr, "segments", segments); edbm_bevel_calc(op); edbm_bevel_update_header(op, C); handled = true; break; } if (!handled && event->val == KM_PRESS) { /* Modal numinput inactive, try to handle numeric inputs last... */ if (handleNumInput(C, &opdata->num_input, event)) { float value = RNA_float_get(op->ptr, "offset"); applyNumInput(&opdata->num_input, &value); RNA_float_set(op->ptr, "offset", value); edbm_bevel_calc(op); edbm_bevel_update_header(op, C); return OPERATOR_RUNNING_MODAL; } } } return OPERATOR_RUNNING_MODAL; }