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; 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; }