Esempio n. 1
0
/* main modal status check */
static int datadropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
	DataDropper *ddr = (DataDropper *)op->customdata;

	switch (event->type) {
		case ESCKEY:
		case RIGHTMOUSE:
			datadropper_cancel(C, op);
			return OPERATOR_CANCELLED;
		case LEFTMOUSE:
			if (event->val == KM_RELEASE) {
				bool success;

				success = datadropper_id_sample(C, ddr, event->x, event->y);
				datadropper_exit(C, op);

				if (success) {
					return OPERATOR_FINISHED;
				}
				else {
					BKE_report(op->reports, RPT_WARNING, "Failed to set value");
					return OPERATOR_CANCELLED;
				}
			}
			break;
		case MOUSEMOVE:
		{
			ID *id = NULL;
			datadropper_id_sample_pt(C, ddr, event->x, event->y, &id);
			break;
		}
	}

	return OPERATOR_RUNNING_MODAL;
}
/* main modal status check */
static int datadropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
  DataDropper *ddr = (DataDropper *)op->customdata;

  /* handle modal keymap */
  if (event->type == EVT_MODAL_MAP) {
    switch (event->val) {
      case EYE_MODAL_CANCEL:
        datadropper_cancel(C, op);
        return OPERATOR_CANCELLED;
      case EYE_MODAL_SAMPLE_CONFIRM: {
        const bool is_undo = ddr->is_undo;
        const bool success = datadropper_id_sample(C, ddr, event->x, event->y);
        datadropper_exit(C, op);
        if (success) {
          /* Could support finished & undo-skip. */
          return is_undo ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
        }
        else {
          BKE_report(op->reports, RPT_WARNING, "Failed to set value");
          return OPERATOR_CANCELLED;
        }
      }
    }
  }
  else if (event->type == MOUSEMOVE) {
    ID *id = NULL;
    datadropper_id_sample_pt(C, ddr, event->x, event->y, &id);
  }

  return OPERATOR_RUNNING_MODAL;
}
Esempio n. 3
0
/* Repeat operator */
static int datadropper_exec(bContext *C, wmOperator *op)
{
	/* init */
	if (datadropper_init(C, op)) {
		/* cleanup */
		datadropper_exit(C, op);

		return OPERATOR_FINISHED;
	}
	else {
		return OPERATOR_CANCELLED;
	}
}
Esempio n. 4
0
/* Modal Operator init */
static int datadropper_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
	/* init */
	if (datadropper_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 {
		datadropper_exit(C, op);
		return OPERATOR_CANCELLED;
	}
}
Esempio n. 5
0
static void datadropper_cancel(bContext *C, wmOperator *op)
{
	datadropper_exit(C, op);
}
static void datadropper_cancel(bContext *C, wmOperator *op)
{
  DataDropper *ddr = op->customdata;
  datadropper_id_set(C, ddr, ddr->init_id);
  datadropper_exit(C, op);
}