/** * \warning \a vec must be set beforehand otherwise we risk uninitialized vars. */ void applyNumInput(NumInput *n, float *vec) { short i, j; if (hasNumInput(n)) { for (j = 0; j <= n->idx_max; j++) { /* if AFFECTALL and no number typed and cursor not on number, use first number */ if (n->flag & NUM_AFFECT_ALL && n->idx != j && n->ctrl[j] == 0) i = 0; else i = j; if (n->ctrl[i] == 0 && n->flag & NUM_NULL_ONE) { vec[j] = 1.0f; } else if (n->val[i] == 0.0f && n->flag & NUM_NO_ZERO) { vec[j] = 0.0001f; } else { if (n->inv[i]) { vec[j] = 1.0f / n->val[i]; } else { vec[j] = n->val[i]; } } } } }
static void applyAxisConstraintRot(TransInfo *t, TransData *td, float vec[3], float *angle) { if (!td && t->con.mode & CON_APPLY) { int mode = t->con.mode & (CON_AXIS0 | CON_AXIS1 | CON_AXIS2); switch (mode) { case CON_AXIS0: case (CON_AXIS1 | CON_AXIS2): copy_v3_v3(vec, t->con.mtx[0]); break; case CON_AXIS1: case (CON_AXIS0 | CON_AXIS2): copy_v3_v3(vec, t->con.mtx[1]); break; case CON_AXIS2: case (CON_AXIS0 | CON_AXIS1): copy_v3_v3(vec, t->con.mtx[2]); break; } /* don't flip axis if asked to or if num input */ if (angle && (mode & CON_NOFLIP) == 0 && hasNumInput(&t->num) == 0) { if (dot_v3v3(vec, t->viewinv[2]) > 0.0f) { *angle = -(*angle); } } } }
static void edbm_bevel_update_header(bContext *C, wmOperator *op) { const char *str = IFACE_("Confirm: (Enter/LMB), Cancel: (Esc/RMB), Mode: %s (M), Clamp Overlap: %s (C), " "Vertex Only: %s (V), Profile Control: %s (P), Offset: %s, Segments: %d, Profile: %.3f"); char msg[UI_MAX_DRAW_STR]; ScrArea *sa = CTX_wm_area(C); Scene *sce = CTX_data_scene(C); if (sa) { BevelData *opdata = op->customdata; char offset_str[NUM_STR_REP_LEN]; const char *type_str; PropertyRNA *prop = RNA_struct_find_property(op->ptr, "offset_type"); if (hasNumInput(&opdata->num_input[OFFSET_VALUE])) { outputNumInput(&opdata->num_input[OFFSET_VALUE], offset_str, &sce->unit); } else { BLI_snprintf(offset_str, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "offset")); } RNA_property_enum_name_gettexted(C, op->ptr, prop, RNA_property_enum_get(op->ptr, prop), &type_str); BLI_snprintf(msg, sizeof(msg), str, type_str, WM_bool_as_string(RNA_boolean_get(op->ptr, "clamp_overlap")), WM_bool_as_string(RNA_boolean_get(op->ptr, "vertex_only")), WM_bool_as_string(opdata->value_mode == PROFILE_VALUE), offset_str, RNA_int_get(op->ptr, "segments"), RNA_float_get(op->ptr, "profile")); ED_area_headerprint(sa, msg); } }
/** * \warning \a vec must be set beforehand otherwise we risk uninitialized vars. */ void applyNumInput(NumInput *n, float *vec) { short i, j; float val; if (hasNumInput(n)) { for (j = 0; j <= n->idx_max; j++) { /* if AFFECTALL and no number typed and cursor not on number, use first number */ i = (n->flag & NUM_AFFECT_ALL && n->idx != j && !(n->val_flag[j] & NUM_EDITED)) ? 0 : j; val = (!(n->val_flag[i] & NUM_EDITED) && n->val_flag[i] & NUM_NULL_ONE) ? 1.0f : n->val[i]; if (n->val_flag[i] & NUM_NO_NEGATIVE && val < 0.0f) { val = 0.0f; } if (n->val_flag[i] & NUM_NO_ZERO && val == 0.0f) { val = 0.0001f; } if (n->val_flag[i] & NUM_NO_FRACTION && val != floorf(val)) { val = floorf(val + 0.5f); if (n->val_flag[i] & NUM_NO_ZERO && val == 0.0f) { val = 1.0f; } } vec[j] = val; } } }
static void edbm_inset_update_header(wmOperator *op, bContext *C) { InsetData *opdata = op->customdata; const char *str = IFACE_("Confirm: Enter/LClick, Cancel: (Esc/RClick), Thickness: %s, " "Depth (Ctrl to tweak): %s (%s), Outset (O): (%s), Boundary (B): (%s), Individual (I): (%s)"); char msg[HEADER_LENGTH]; ScrArea *sa = CTX_wm_area(C); Scene *sce = CTX_data_scene(C); if (sa) { char flts_str[NUM_STR_REP_LEN * 2]; if (hasNumInput(&opdata->num_input)) outputNumInput(&opdata->num_input, flts_str, &sce->unit); else { BLI_snprintf(flts_str, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "thickness")); BLI_snprintf(flts_str + NUM_STR_REP_LEN, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "depth")); } BLI_snprintf(msg, HEADER_LENGTH, str, flts_str, flts_str + NUM_STR_REP_LEN, WM_bool_as_string(opdata->modify_depth), WM_bool_as_string(RNA_boolean_get(op->ptr, "use_outset")), WM_bool_as_string(RNA_boolean_get(op->ptr, "use_boundary")), WM_bool_as_string(RNA_boolean_get(op->ptr, "use_individual")) ); ED_area_headerprint(sa, msg); } }
static void applyObjectConstraintRot(TransInfo *t, TransData *td, float vec[3], float *angle) { if (t->con.mode & CON_APPLY) { int mode = t->con.mode & (CON_AXIS0|CON_AXIS1|CON_AXIS2); /* on setup call, use first object */ if (td == NULL) { td= t->data; } switch(mode) { case CON_AXIS0: case (CON_AXIS1|CON_AXIS2): VECCOPY(vec, td->axismtx[0]); break; case CON_AXIS1: case (CON_AXIS0|CON_AXIS2): VECCOPY(vec, td->axismtx[1]); break; case CON_AXIS2: case (CON_AXIS0|CON_AXIS1): VECCOPY(vec, td->axismtx[2]); break; } if (angle && (mode & CON_NOFLIP) == 0 && hasNumInput(&t->num) == 0) { if (dot_v3v3(vec, t->viewinv[2]) > 0.0f) { *angle = -(*angle); } } } }
static void applyObjectConstraintRot( TransInfo *t, TransDataContainer *tc, TransData *td, float vec[3], float *angle) { if (t->con.mode & CON_APPLY) { int mode = t->con.mode & (CON_AXIS0 | CON_AXIS1 | CON_AXIS2); float tmp_axismtx[3][3]; float(*axismtx)[3]; /* on setup call, use first object */ if (td == NULL) { BLI_assert(tc == NULL); tc = TRANS_DATA_CONTAINER_FIRST_OK(t); td = tc->data; } if (t->flag & T_EDIT) { mul_m3_m3m3(tmp_axismtx, tc->mat3_unit, td->axismtx); axismtx = tmp_axismtx; } else { axismtx = td->axismtx; } switch (mode) { case CON_AXIS0: case (CON_AXIS1 | CON_AXIS2): copy_v3_v3(vec, axismtx[0]); break; case CON_AXIS1: case (CON_AXIS0 | CON_AXIS2): copy_v3_v3(vec, axismtx[1]); break; case CON_AXIS2: case (CON_AXIS0 | CON_AXIS1): copy_v3_v3(vec, axismtx[2]); break; } if (angle && (mode & CON_NOFLIP) == 0 && hasNumInput(&t->num) == 0) { if (dot_v3v3(vec, t->viewinv[2]) > 0.0f) { *angle = -(*angle); } } } }
static void postConstraintChecks(TransInfo *t, float vec[3], float pvec[3]) { int i = 0; mul_m3_v3(t->con.imtx, vec); snapGrid(t, vec); if (t->num.flag & T_NULL_ONE) { if (!(t->con.mode & CON_AXIS0)) vec[0] = 1.0f; if (!(t->con.mode & CON_AXIS1)) vec[1] = 1.0f; if (!(t->con.mode & CON_AXIS2)) vec[2] = 1.0f; } if (hasNumInput(&t->num)) { applyNumInput(&t->num, vec); removeAspectRatio(t, vec); constraintNumInput(t, vec); } /* autovalues is operator param, use that directly but not if snapping is forced */ if (t->flag & T_AUTOVALUES && (t->tsnap.status & SNAP_FORCED) == 0) { mul_v3_m3v3(vec, t->con.imtx, t->auto_values); constraintAutoValues(t, vec); /* inverse transformation at the end */ } if (t->con.mode & CON_AXIS0) { pvec[i++] = vec[0]; } if (t->con.mode & CON_AXIS1) { pvec[i++] = vec[1]; } if (t->con.mode & CON_AXIS2) { pvec[i++] = vec[2]; } mul_m3_v3(t->con.mtx, vec); }
static void ed_marker_move_update_header(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); MarkerMove *mm = op->customdata; TimeMarker *marker, *selmarker = NULL; const int offs = RNA_int_get(op->ptr, "frames"); char str[256]; char str_offs[NUM_STR_REP_LEN]; int totmark; const bool use_time = ed_marker_move_use_time(mm); for (totmark = 0, marker = mm->markers->first; marker; marker = marker->next) { if (marker->flag & SELECT) { selmarker = marker; totmark++; } } if (hasNumInput(&mm->num)) { outputNumInput(&mm->num, str_offs, &scene->unit); } else if (use_time) { BLI_snprintf(str_offs, sizeof(str_offs), "%.2f", FRA2TIME(offs)); } else { BLI_snprintf(str_offs, sizeof(str_offs), "%d", offs); } if (totmark == 1 && selmarker) { /* we print current marker value */ if (use_time) { BLI_snprintf(str, sizeof(str), "Marker %.2f offset %s", FRA2TIME(selmarker->frame), str_offs); } else { BLI_snprintf(str, sizeof(str), "Marker %d offset %s", selmarker->frame, str_offs); } } else { BLI_snprintf(str, sizeof(str), "Marker offset %s", str_offs); } ED_area_headerprint(CTX_wm_area(C), str); }
/** * \warning \a vec must be set beforehand otherwise we risk uninitialized vars. */ bool applyNumInput(NumInput *n, float *vec) { short i, j; float val; if (hasNumInput(n)) { for (j = 0; j <= n->idx_max; j++) { if (n->flag & NUM_FAKE_EDITED) { val = n->val[j]; } else { /* if AFFECTALL and no number typed and cursor not on number, use first number */ i = (n->flag & NUM_AFFECT_ALL && n->idx != j && !(n->val_flag[j] & NUM_EDITED)) ? 0 : j; val = (!(n->val_flag[i] & NUM_EDITED) && n->val_flag[i] & NUM_NULL_ONE) ? 1.0f : n->val[i]; if (n->val_flag[i] & NUM_NO_NEGATIVE && val < 0.0f) { val = 0.0f; } if (n->val_flag[i] & NUM_NO_FRACTION && val != floorf(val)) { val = floorf(val + 0.5f); if (n->val_flag[i] & NUM_NO_ZERO && val == 0.0f) { val = 1.0f; } } else if (n->val_flag[i] & NUM_NO_ZERO && val == 0.0f) { val = 0.0001f; } } vec[j] = val; } n->flag &= ~NUM_FAKE_EDITED; return true; } else { /* Else, we set the 'org' values for numinput! */ for (j = 0; j <= n->idx_max; j++) { n->val[j] = n->val_org[j] = vec[j]; } return false; } }
static void edbm_bevel_update_header(wmOperator *op, bContext *C) { const char *str = IFACE_("Confirm: (Enter/LMB), Cancel: (Esc/RMB), Offset: %s, Segments: %d"); char msg[HEADER_LENGTH]; ScrArea *sa = CTX_wm_area(C); if (sa) { BevelData *opdata = op->customdata; char offset_str[NUM_STR_REP_LEN]; if (hasNumInput(&opdata->num_input)) { outputNumInput(&opdata->num_input, offset_str); } else { BLI_snprintf(offset_str, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "offset")); } BLI_snprintf(msg, HEADER_LENGTH, str, offset_str, RNA_int_get(op->ptr, "segments")); ED_area_headerprint(sa, msg); } }
/* draw percentage indicator in header */ static void pose_slide_draw_status(tPoseSlideOp *pso) { char status_str[UI_MAX_DRAW_STR]; char mode_str[32]; switch (pso->mode) { case POSESLIDE_PUSH: strcpy(mode_str, "Push Pose"); break; case POSESLIDE_RELAX: strcpy(mode_str, "Relax Pose"); break; case POSESLIDE_BREAKDOWN: strcpy(mode_str, "Breakdown"); break; default: /* unknown */ strcpy(mode_str, "Sliding-Tool"); break; } if (hasNumInput(&pso->num)) { Scene *scene = pso->scene; char str_offs[NUM_STR_REP_LEN]; outputNumInput(&pso->num, str_offs, &scene->unit); BLI_snprintf(status_str, sizeof(status_str), "%s: %s", mode_str, str_offs); } else { BLI_snprintf(status_str, sizeof(status_str), "%s: %d %%", mode_str, (int)(pso->percentage * 100.0f)); } ED_area_headerprint(pso->sa, status_str); }
/* 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; const bool has_numinput = hasNumInput(&opdata->num_input[opdata->value_mode]); /* Modal numinput active, try to handle numeric inputs first... */ if (event->val == KM_PRESS && has_numinput && handleNumInput(C, &opdata->num_input[opdata->value_mode], event)) { edbm_bevel_numinput_set_value(op); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); 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 (!has_numinput) { edbm_bevel_mouse_set_value(op, event); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; } break; case LEFTMOUSE: case PADENTER: case RETKEY: if (event->val == KM_PRESS) { edbm_bevel_calc(op); edbm_bevel_exit(C, op); return OPERATOR_FINISHED; } break; case MOUSEPAN: { float delta = 0.02f * (event->y - event->prevy); if (opdata->segments >= 1 && opdata->segments + delta < 1) opdata->segments = 1; else opdata->segments += delta; RNA_int_set(op->ptr, "segments", (int)opdata->segments); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; break; } /* 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; opdata->segments = opdata->segments + 1; RNA_int_set(op->ptr, "segments", (int)opdata->segments); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; break; case WHEELDOWNMOUSE: /* change number of segments */ case PADMINUS: if (event->val == KM_RELEASE) break; opdata->segments = max_ff(opdata->segments - 1, 1); RNA_int_set(op->ptr, "segments", (int)opdata->segments); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; break; case MKEY: if (event->val == KM_RELEASE) break; { PropertyRNA *prop = RNA_struct_find_property(op->ptr, "offset_type"); int type = RNA_property_enum_get(op->ptr, prop); type++; if (type > BEVEL_AMT_PERCENT) { type = BEVEL_AMT_OFFSET; } if (opdata->value_mode == OFFSET_VALUE && type == BEVEL_AMT_PERCENT) opdata->value_mode = OFFSET_VALUE_PERCENT; else if (opdata->value_mode == OFFSET_VALUE_PERCENT && type != BEVEL_AMT_PERCENT) opdata->value_mode = OFFSET_VALUE; RNA_property_enum_set(op->ptr, prop, type); if (opdata->initial_length[opdata->value_mode] == -1.0f) edbm_bevel_calc_initial_length(op, event, true); } /* Update offset accordingly to new offset_type. */ if (!has_numinput && (opdata->value_mode == OFFSET_VALUE || opdata->value_mode == OFFSET_VALUE_PERCENT)) { edbm_bevel_mouse_set_value(op, event); } edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; break; case CKEY: if (event->val == KM_RELEASE) break; { PropertyRNA *prop = RNA_struct_find_property(op->ptr, "clamp_overlap"); RNA_property_boolean_set(op->ptr, prop, !RNA_property_boolean_get(op->ptr, prop)); } edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; break; case PKEY: if (event->val == KM_RELEASE) break; if (opdata->value_mode == PROFILE_VALUE) { opdata->value_mode = OFFSET_VALUE; } else { opdata->value_mode = PROFILE_VALUE; } edbm_bevel_calc_initial_length(op, event, true); break; case SKEY: if (event->val == KM_RELEASE) break; if (opdata->value_mode == SEGMENTS_VALUE) { opdata->value_mode = OFFSET_VALUE; } else { opdata->value_mode = SEGMENTS_VALUE; } edbm_bevel_calc_initial_length(op, event, true); break; case VKEY: if (event->val == KM_RELEASE) break; { PropertyRNA *prop = RNA_struct_find_property(op->ptr, "vertex_only"); RNA_property_boolean_set(op->ptr, prop, !RNA_property_boolean_get(op->ptr, prop)); } edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; break; } /* Modal numinput inactive, try to handle numeric inputs last... */ if (!handled && event->val == KM_PRESS && handleNumInput(C, &opdata->num_input[opdata->value_mode], event)) { edbm_bevel_numinput_set_value(op); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); return OPERATOR_RUNNING_MODAL; } } 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 edbm_bevel_modal(bContext *C, wmOperator *op, const wmEvent *event) { BevelData *opdata = op->customdata; int segments = RNA_int_get(op->ptr, "segments"); 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 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(C, op); 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 (!has_numinput) { const float factor = edbm_bevel_mval_factor(op, event); RNA_float_set(op->ptr, "offset", factor); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; } break; case LEFTMOUSE: case PADENTER: case RETKEY: if (event->val == KM_PRESS) { edbm_bevel_calc(op); edbm_bevel_exit(C, op); return OPERATOR_FINISHED; } break; /* 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(C, op); 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(C, op); handled = true; break; case MKEY: if (event->val == KM_RELEASE) break; { PropertyRNA *prop = RNA_struct_find_property(op->ptr, "offset_type"); int type = RNA_property_enum_get(op->ptr, prop); type++; if (type > BEVEL_AMT_PERCENT) { type = BEVEL_AMT_OFFSET; } RNA_property_enum_set(op->ptr, prop, type); } /* Update factor accordingly to new offset_type. */ if (!has_numinput) { RNA_float_set(op->ptr, "offset", edbm_bevel_mval_factor(op, event)); } edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; break; case CKEY: if (event->val == KM_RELEASE) break; { PropertyRNA *prop = RNA_struct_find_property(op->ptr, "clamp_overlap"); RNA_property_boolean_set(op->ptr, prop, !RNA_property_boolean_get(op->ptr, prop)); } edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; break; case VKEY: if (event->val == KM_RELEASE) break; { PropertyRNA *prop = RNA_struct_find_property(op->ptr, "vertex_only"); RNA_property_boolean_set(op->ptr, prop, !RNA_property_boolean_get(op->ptr, prop)); } edbm_bevel_calc(op); edbm_bevel_update_header(C, op); 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 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(C, op); return OPERATOR_RUNNING_MODAL; } } return OPERATOR_RUNNING_MODAL; }
static int edbm_bevel_modal(bContext *C, wmOperator *op, const wmEvent *event) { BevelData *opdata = op->customdata; const bool has_numinput = hasNumInput(&opdata->num_input[opdata->value_mode]); bool handled = false; short etype = event->type; short eval = event->val; /* When activated from toolbar, need to convert leftmouse release to confirm */ if (etype == LEFTMOUSE && eval == KM_RELEASE && RNA_boolean_get(op->ptr, "release_confirm")) { etype = EVT_MODAL_MAP; eval = BEV_MODAL_CONFIRM; } /* Modal numinput active, try to handle numeric inputs first... */ if (etype != EVT_MODAL_MAP && eval == KM_PRESS && has_numinput && handleNumInput(C, &opdata->num_input[opdata->value_mode], event)) { edbm_bevel_numinput_set_value(op); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); return OPERATOR_RUNNING_MODAL; } else if (etype == MOUSEMOVE) { if (!has_numinput) { edbm_bevel_mouse_set_value(op, event); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; } } else if (etype == MOUSEPAN) { float delta = 0.02f * (event->y - event->prevy); if (opdata->segments >= 1 && opdata->segments + delta < 1) { opdata->segments = 1; } else { opdata->segments += delta; } RNA_int_set(op->ptr, "segments", (int)opdata->segments); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; } else if (etype == EVT_MODAL_MAP) { switch (eval) { case BEV_MODAL_CANCEL: edbm_bevel_cancel(C, op); ED_workspace_status_text(C, NULL); return OPERATOR_CANCELLED; case BEV_MODAL_CONFIRM: edbm_bevel_calc(op); edbm_bevel_exit(C, op); ED_workspace_status_text(C, NULL); return OPERATOR_FINISHED; case BEV_MODAL_SEGMENTS_UP: opdata->segments = opdata->segments + 1; RNA_int_set(op->ptr, "segments", (int)opdata->segments); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; break; case BEV_MODAL_SEGMENTS_DOWN: opdata->segments = max_ff(opdata->segments - 1, 1); RNA_int_set(op->ptr, "segments", (int)opdata->segments); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; break; case BEV_MODAL_OFFSET_MODE_CHANGE: { int type = RNA_enum_get(op->ptr, "offset_type"); type++; if (type > BEVEL_AMT_PERCENT) { type = BEVEL_AMT_OFFSET; } if (opdata->value_mode == OFFSET_VALUE && type == BEVEL_AMT_PERCENT) { opdata->value_mode = OFFSET_VALUE_PERCENT; } else if (opdata->value_mode == OFFSET_VALUE_PERCENT && type != BEVEL_AMT_PERCENT) { opdata->value_mode = OFFSET_VALUE; } RNA_enum_set(op->ptr, "offset_type", type); if (opdata->initial_length[opdata->value_mode] == -1.0f) { edbm_bevel_calc_initial_length(op, event, true); } } /* Update offset accordingly to new offset_type. */ if (!has_numinput && (opdata->value_mode == OFFSET_VALUE || opdata->value_mode == OFFSET_VALUE_PERCENT)) { edbm_bevel_mouse_set_value(op, event); } edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; break; case BEV_MODAL_CLAMP_OVERLAP_TOGGLE: { bool clamp_overlap = RNA_boolean_get(op->ptr, "clamp_overlap"); RNA_boolean_set(op->ptr, "clamp_overlap", !clamp_overlap); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; break; } case BEV_MODAL_VALUE_OFFSET: opdata->value_mode = OFFSET_VALUE; edbm_bevel_calc_initial_length(op, event, true); break; case BEV_MODAL_VALUE_PROFILE: opdata->value_mode = PROFILE_VALUE; edbm_bevel_calc_initial_length(op, event, true); break; case BEV_MODAL_VALUE_SEGMENTS: opdata->value_mode = SEGMENTS_VALUE; edbm_bevel_calc_initial_length(op, event, true); break; case BEV_MODAL_VERTEX_ONLY_TOGGLE: { bool vertex_only = RNA_boolean_get(op->ptr, "vertex_only"); RNA_boolean_set(op->ptr, "vertex_only", !vertex_only); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; break; } case BEV_MODAL_MARK_SEAM_TOGGLE: { bool mark_seam = RNA_boolean_get(op->ptr, "mark_seam"); RNA_boolean_set(op->ptr, "mark_seam", !mark_seam); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; break; } case BEV_MODAL_MARK_SHARP_TOGGLE: { bool mark_sharp = RNA_boolean_get(op->ptr, "mark_sharp"); RNA_boolean_set(op->ptr, "mark_sharp", !mark_sharp); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; break; } case BEV_MODAL_INNER_MITER_CHANGE: { int miter_inner = RNA_enum_get(op->ptr, "miter_inner"); miter_inner++; if (miter_inner == BEVEL_MITER_PATCH) { miter_inner++; /* no patch option for inner miter */ } if (miter_inner > BEVEL_MITER_ARC) { miter_inner = BEVEL_MITER_SHARP; } RNA_enum_set(op->ptr, "miter_inner", miter_inner); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; break; } case BEV_MODAL_OUTER_MITER_CHANGE: { int miter_outer = RNA_enum_get(op->ptr, "miter_outer"); miter_outer++; if (miter_outer > BEVEL_MITER_ARC) { miter_outer = BEVEL_MITER_SHARP; } RNA_enum_set(op->ptr, "miter_outer", miter_outer); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; break; } case BEV_MODAL_HARDEN_NORMALS_TOGGLE: { bool harden_normals = RNA_boolean_get(op->ptr, "harden_normals"); RNA_boolean_set(op->ptr, "harden_normals", !harden_normals); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); handled = true; break; } } } /* Modal numinput inactive, try to handle numeric inputs last... */ if (!handled && eval == KM_PRESS && handleNumInput(C, &opdata->num_input[opdata->value_mode], event)) { edbm_bevel_numinput_set_value(op); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); return OPERATOR_RUNNING_MODAL; } return OPERATOR_RUNNING_MODAL; }
static int ed_marker_move_modal(bContext *C, wmOperator *op, const wmEvent *event) { Scene *scene = CTX_data_scene(C); MarkerMove *mm = op->customdata; View2D *v2d = UI_view2d_fromcontext(C); const bool has_numinput = hasNumInput(&mm->num); const bool use_time = ed_marker_move_use_time(mm); /* Modal numinput active, try to handle numeric inputs first... */ if (event->val == KM_PRESS && has_numinput && handleNumInput(C, &mm->num, event)) { float value = (float)RNA_int_get(op->ptr, "frames"); applyNumInput(&mm->num, &value); if (use_time) { value = TIME2FRA(value); } RNA_int_set(op->ptr, "frames", (int)value); ed_marker_move_apply(C, op); ed_marker_move_update_header(C, op); } else { bool handled = false; switch (event->type) { case ESCKEY: ed_marker_move_cancel(C, op); return OPERATOR_CANCELLED; case RIGHTMOUSE: /* press = user manually demands transform to be canceled */ if (event->val == KM_PRESS) { ed_marker_move_cancel(C, op); return OPERATOR_CANCELLED; } /* else continue; <--- see if release event should be caught for tweak-end */ case RETKEY: case PADENTER: case LEFTMOUSE: case MIDDLEMOUSE: if (WM_modal_tweak_exit(event, 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 (!has_numinput) { float dx; dx = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask); if (event->x != mm->evtx) { /* XXX maybe init for first time */ float fac; mm->evtx = event->x; fac = ((float)(event->x - mm->firstx) * dx); if (mm->slink->spacetype == SPACE_TIME) apply_keyb_grid(event->shift, event->ctrl, &fac, 0.0, FPS, 0.1 * FPS, 0); else apply_keyb_grid(event->shift, event->ctrl, &fac, 0.0, 1.0, 0.1, 0 /*was: U.flag & USER_AUTOGRABGRID*/); RNA_int_set(op->ptr, "frames", (int)fac); ed_marker_move_apply(C, op); ed_marker_move_update_header(C, op); } } break; } if (!handled && event->val == KM_PRESS && handleNumInput(C, &mm->num, event)) { float value = (float)RNA_int_get(op->ptr, "frames"); applyNumInput(&mm->num, &value); if (use_time) { value = TIME2FRA(value); } RNA_int_set(op->ptr, "frames", (int)value); ed_marker_move_apply(C, op); ed_marker_move_update_header(C, op); } } return OPERATOR_RUNNING_MODAL; }
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 ed_marker_move_modal(bContext *C, wmOperator *op, const wmEvent *event) { 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 (event->type) { case ESCKEY: ed_marker_move_cancel(C, op); return OPERATOR_CANCELLED; case RIGHTMOUSE: /* press = user manually demands transform to be canceled */ if (event->val == KM_PRESS) { ed_marker_move_cancel(C, op); return OPERATOR_CANCELLED; } /* else continue; <--- see if release event should be caught for tweak-end */ case RETKEY: case PADENTER: case LEFTMOUSE: case MIDDLEMOUSE: if (WM_modal_tweak_exit(event, 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 = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask); if (event->x != mm->evtx) { /* XXX maybe init for first time */ int a, offs, totmark = 0; mm->evtx = event->x; fac = ((float)(event->x - mm->firstx) * dx); if (mm->slink->spacetype == SPACE_TIME) apply_keyb_grid(event->shift, event->ctrl, &fac, 0.0, FPS, 0.1 * FPS, 0); else apply_keyb_grid(event->shift, event->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(C, 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 (mm->slink->spacetype == SPACE_TIME) { 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 (mm->slink->spacetype == SPACE_TIME) { 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)); } } ED_area_headerprint(CTX_wm_area(C), str); } } if (event->val == KM_PRESS) { if (handleNumInput(&mm->num, event)) { char str_tx[NUM_STR_REP_LEN]; float value = RNA_int_get(op->ptr, "frames"); applyNumInput(&mm->num, &value); if (hasNumInput(&mm->num)) { outputNumInput(&mm->num, str_tx); } else { BLI_snprintf(str_tx, sizeof(str_tx), "%d", (int)value); } RNA_int_set(op->ptr, "frames", value); ed_marker_move_apply(C, op); // ed_marker_header_update(C, op, str, (int)value); // strcat(str, str_tx); BLI_snprintf(str, sizeof(str), "Marker offset %s", str_tx); ED_area_headerprint(CTX_wm_area(C), str); } } 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; }