Exemplo n.º 1
0
/* 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;
}
Exemplo n.º 2
0
/* 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;
}