static void depthdropper_cancel(bContext *C, wmOperator *op) { DepthDropper *ddr = op->customdata; if (ddr->is_set) { depthdropper_depth_set(C, ddr, ddr->init_depth); } depthdropper_exit(C, op); }
/* Repeat operator */ static int depthdropper_exec(bContext *C, wmOperator *op) { /* init */ if (depthdropper_init(C, op)) { /* cleanup */ depthdropper_exit(C, op); return OPERATOR_FINISHED; } else { return OPERATOR_CANCELLED; } }
/* Modal Operator init */ static int depthdropper_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { /* init */ if (depthdropper_init(C, op)) { WM_cursor_modal_set(CTX_wm_window(C), BC_EYEDROPPER_CURSOR); /* add temp handler */ WM_event_add_modal_handler(C, op); return OPERATOR_RUNNING_MODAL; } else { depthdropper_exit(C, op); return OPERATOR_CANCELLED; } }
/* main modal status check */ static int depthdropper_modal(bContext *C, wmOperator *op, const wmEvent *event) { DepthDropper *ddr = (DepthDropper *)op->customdata; switch (event->type) { case ESCKEY: case RIGHTMOUSE: depthdropper_cancel(C, op); return OPERATOR_CANCELLED; case LEFTMOUSE: if (event->val == KM_RELEASE) { if (ddr->accum_tot == 0) { depthdropper_depth_sample(C, ddr, event->x, event->y); } else { depthdropper_depth_set_accum(C, ddr); } depthdropper_exit(C, op); return OPERATOR_FINISHED; } else if (event->val == KM_PRESS) { /* enable accum and make first sample */ ddr->accum_start = true; depthdropper_depth_sample_accum(C, ddr, event->x, event->y); } break; case MOUSEMOVE: if (ddr->accum_start) { /* button is pressed so keep sampling */ depthdropper_depth_sample_accum(C, ddr, event->x, event->y); depthdropper_depth_set_accum(C, ddr); } break; case SPACEKEY: if (event->val == KM_RELEASE) { ddr->accum_tot = 0; ddr->accum_depth = 0.0f; depthdropper_depth_sample_accum(C, ddr, event->x, event->y); depthdropper_depth_set_accum(C, ddr); } break; } return OPERATOR_RUNNING_MODAL; }
/* main modal status check */ static int depthdropper_modal(bContext *C, wmOperator *op, const wmEvent *event) { DepthDropper *ddr = (DepthDropper *)op->customdata; /* handle modal keymap */ if (event->type == EVT_MODAL_MAP) { switch (event->val) { case EYE_MODAL_CANCEL: depthdropper_cancel(C, op); return OPERATOR_CANCELLED; case EYE_MODAL_SAMPLE_CONFIRM: { const bool is_undo = ddr->is_undo; if (ddr->accum_tot == 0) { depthdropper_depth_sample(C, ddr, event->x, event->y); } else { depthdropper_depth_set_accum(C, ddr); } depthdropper_exit(C, op); /* Could support finished & undo-skip. */ return is_undo ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } case EYE_MODAL_SAMPLE_BEGIN: /* enable accum and make first sample */ ddr->accum_start = true; depthdropper_depth_sample_accum(C, ddr, event->x, event->y); break; case EYE_MODAL_SAMPLE_RESET: ddr->accum_tot = 0; ddr->accum_depth = 0.0f; depthdropper_depth_sample_accum(C, ddr, event->x, event->y); depthdropper_depth_set_accum(C, ddr); break; } } else if (event->type == MOUSEMOVE) { if (ddr->accum_start) { /* button is pressed so keep sampling */ depthdropper_depth_sample_accum(C, ddr, event->x, event->y); depthdropper_depth_set_accum(C, ddr); } } return OPERATOR_RUNNING_MODAL; }
static void depthdropper_cancel(bContext *C, wmOperator *op) { depthdropper_exit(C, op); }