/* main modal status check */ static int eyedropper_modal(bContext *C, wmOperator *op, const wmEvent *event) { Eyedropper *eye = (Eyedropper *)op->customdata; switch (event->type) { case ESCKEY: case RIGHTMOUSE: eyedropper_cancel(C, op); return OPERATOR_CANCELLED; case LEFTMOUSE: if (event->val == KM_RELEASE) { if (eye->accum_tot == 0) { eyedropper_color_sample(C, eye, event->x, event->y); } else { eyedropper_color_set_accum(C, eye); } eyedropper_exit(C, op); return OPERATOR_FINISHED; } else if (event->val == KM_PRESS) { /* enable accum and make first sample */ eye->accum_start = true; eyedropper_color_sample_accum(C, eye, event->x, event->y); } break; case MOUSEMOVE: if (eye->accum_start) { /* button is pressed so keep sampling */ eyedropper_color_sample_accum(C, eye, event->x, event->y); eyedropper_color_set_accum(C, eye); } break; case SPACEKEY: if (event->val == KM_RELEASE) { eye->accum_tot = 0; zero_v3(eye->accum_col); eyedropper_color_sample_accum(C, eye, event->x, event->y); eyedropper_color_set_accum(C, eye); } break; } return OPERATOR_RUNNING_MODAL; }
/* main modal status check */ static int eyedropper_modal(bContext *C, wmOperator *op, wmEvent *event) { Eyedropper *eye = (Eyedropper *)op->customdata; switch(event->type) { case ESCKEY: case RIGHTMOUSE: return eyedropper_cancel(C, op); case LEFTMOUSE: if(event->val==KM_RELEASE) { eyedropper_sample(C, eye, event->x, event->y); eyedropper_exit(C, op); return OPERATOR_FINISHED; } break; } return OPERATOR_RUNNING_MODAL; }
/* main modal status check */ static int eyedropper_modal(bContext *C, wmOperator *op, const wmEvent *event) { Eyedropper *eye = (Eyedropper *)op->customdata; /* handle modal keymap */ if (event->type == EVT_MODAL_MAP) { switch (event->val) { case EYE_MODAL_CANCEL: eyedropper_cancel(C, op); return OPERATOR_CANCELLED; case EYE_MODAL_SAMPLE_CONFIRM: if (eye->accum_tot == 0) { eyedropper_color_sample(C, eye, event->x, event->y); } else { eyedropper_color_set_accum(C, eye); } eyedropper_exit(C, op); return OPERATOR_FINISHED; case EYE_MODAL_SAMPLE_BEGIN: /* enable accum and make first sample */ eye->accum_start = true; eyedropper_color_sample_accum(C, eye, event->x, event->y); break; case EYE_MODAL_SAMPLE_RESET: eye->accum_tot = 0; zero_v3(eye->accum_col); eyedropper_color_sample_accum(C, eye, event->x, event->y); eyedropper_color_set_accum(C, eye); break; } } else if (event->type == MOUSEMOVE) { if (eye->accum_start) { /* button is pressed so keep sampling */ eyedropper_color_sample_accum(C, eye, event->x, event->y); eyedropper_color_set_accum(C, eye); } } return OPERATOR_RUNNING_MODAL; }