示例#1
0
static int ed_marker_move_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
	Scene *scene = CTX_data_scene(C);
	MarkerMove *mm = op->customdata;
	View2D *v2d = UI_view2d_fromcontext(C);
	const bool has_numinput = hasNumInput(&mm->num);
	const bool use_time = ed_marker_move_use_time(mm);

	/* Modal numinput active, try to handle numeric inputs first... */
	if (event->val == KM_PRESS && has_numinput && handleNumInput(C, &mm->num, event)) {
		float value = (float)RNA_int_get(op->ptr, "frames");

		applyNumInput(&mm->num, &value);
		if (use_time) {
			value = TIME2FRA(value);
		}

		RNA_int_set(op->ptr, "frames", (int)value);
		ed_marker_move_apply(C, op);
		ed_marker_move_update_header(C, op);
	}
	else {
		bool handled = false;
		switch (event->type) {
			case ESCKEY:
				ed_marker_move_cancel(C, op);
				return OPERATOR_CANCELLED;
			case RIGHTMOUSE:
				/* press = user manually demands transform to be canceled */
				if (event->val == KM_PRESS) {
					ed_marker_move_cancel(C, op);
					return OPERATOR_CANCELLED;
				}
			/* else continue; <--- see if release event should be caught for tweak-end */

			case RETKEY:
			case PADENTER:
			case LEFTMOUSE:
			case MIDDLEMOUSE:
				if (WM_modal_tweak_exit(event, mm->event_type)) {
					ed_marker_move_exit(C, op);
					WM_event_add_notifier(C, NC_SCENE | ND_MARKERS, NULL);
					WM_event_add_notifier(C, NC_ANIMATION | ND_MARKERS, NULL);
					return OPERATOR_FINISHED;
				}
				break;
			case MOUSEMOVE:
				if (!has_numinput) {
					float dx;

					dx = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask);

					if (event->x != mm->evtx) {   /* XXX maybe init for first time */
						float fac;

						mm->evtx = event->x;
						fac = ((float)(event->x - mm->firstx) * dx);

						if (mm->slink->spacetype == SPACE_TIME)
							apply_keyb_grid(event->shift, event->ctrl, &fac, 0.0, FPS, 0.1 * FPS, 0);
						else
							apply_keyb_grid(event->shift, event->ctrl, &fac, 0.0, 1.0, 0.1, 0 /*was: U.flag & USER_AUTOGRABGRID*/);

						RNA_int_set(op->ptr, "frames", (int)fac);
						ed_marker_move_apply(C, op);
						ed_marker_move_update_header(C, op);
					}
				}
				break;
		}

		if (!handled && event->val == KM_PRESS && handleNumInput(C, &mm->num, event)) {
			float value = (float)RNA_int_get(op->ptr, "frames");

			applyNumInput(&mm->num, &value);
			if (use_time) {
				value = TIME2FRA(value);
			}

			RNA_int_set(op->ptr, "frames", (int)value);
			ed_marker_move_apply(C, op);
			ed_marker_move_update_header(C, op);
		}
	}

	return OPERATOR_RUNNING_MODAL;
}
static int ed_marker_move_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
	Scene *scene = CTX_data_scene(C);
	MarkerMove *mm = op->customdata;
	View2D *v2d = UI_view2d_fromcontext(C);
	TimeMarker *marker, *selmarker = NULL;
	float dx, fac;
	char str[256];
		
	switch (event->type) {
		case ESCKEY:
			ed_marker_move_cancel(C, op);
			return OPERATOR_CANCELLED;
		
		case RIGHTMOUSE:
			/* press = user manually demands transform to be canceled */
			if (event->val == KM_PRESS) {
				ed_marker_move_cancel(C, op);
				return OPERATOR_CANCELLED;
			}
		/* else continue; <--- see if release event should be caught for tweak-end */
		
		case RETKEY:
		case PADENTER:
		case LEFTMOUSE:
		case MIDDLEMOUSE:
			if (WM_modal_tweak_exit(event, mm->event_type)) {
				ed_marker_move_exit(C, op);
				WM_event_add_notifier(C, NC_SCENE | ND_MARKERS, NULL);
				WM_event_add_notifier(C, NC_ANIMATION | ND_MARKERS, NULL);
				return OPERATOR_FINISHED;
			}
			break;
		case MOUSEMOVE:
			if (hasNumInput(&mm->num))
				break;
			
			dx = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask);
			
			if (event->x != mm->evtx) {   /* XXX maybe init for first time */
				int a, offs, totmark = 0;
				
				mm->evtx = event->x;
				
				fac = ((float)(event->x - mm->firstx) * dx);
				
				if (mm->slink->spacetype == SPACE_TIME) 
					apply_keyb_grid(event->shift, event->ctrl, &fac, 0.0, FPS, 0.1 * FPS, 0);
				else
					apply_keyb_grid(event->shift, event->ctrl, &fac, 0.0, 1.0, 0.1, 0 /*was: U.flag & USER_AUTOGRABGRID*/);
				
				offs = (int)fac;
				RNA_int_set(op->ptr, "frames", offs);
				ed_marker_move_apply(C, op);
				
				/* cruft below is for header print */
				for (a = 0, marker = mm->markers->first; marker; marker = marker->next) {
					if (marker->flag & SELECT) {
						selmarker = marker;
						a++; totmark++;
					}
				}
				
				if (totmark == 1) {
					/* we print current marker value */
					if (mm->slink->spacetype == SPACE_TIME) {
						SpaceTime *stime = (SpaceTime *)mm->slink;
						if (stime->flag & TIME_DRAWFRAMES) 
							BLI_snprintf(str, sizeof(str), "Marker %d offset %d", selmarker->frame, offs);
						else 
							BLI_snprintf(str, sizeof(str), "Marker %.2f offset %.2f", FRA2TIME(selmarker->frame), FRA2TIME(offs));
					}
					else if (mm->slink->spacetype == SPACE_ACTION) {
						SpaceAction *saction = (SpaceAction *)mm->slink;
						if (saction->flag & SACTION_DRAWTIME)
							BLI_snprintf(str, sizeof(str), "Marker %.2f offset %.2f", FRA2TIME(selmarker->frame), FRA2TIME(offs));
						else
							BLI_snprintf(str, sizeof(str), "Marker %.2f offset %.2f", (double)(selmarker->frame), (double)(offs));
					}
					else {
						BLI_snprintf(str, sizeof(str), "Marker %.2f offset %.2f", (double)(selmarker->frame), (double)(offs));
					}
				}
				else {
					/* we only print the offset */
					if (mm->slink->spacetype == SPACE_TIME) {
						SpaceTime *stime = (SpaceTime *)mm->slink;
						if (stime->flag & TIME_DRAWFRAMES) 
							BLI_snprintf(str, sizeof(str), "Marker offset %d ", offs);
						else 
							BLI_snprintf(str, sizeof(str), "Marker offset %.2f ", FRA2TIME(offs));
					}
					else if (mm->slink->spacetype == SPACE_ACTION) {
						SpaceAction *saction = (SpaceAction *)mm->slink;
						if (saction->flag & SACTION_DRAWTIME)
							BLI_snprintf(str, sizeof(str), "Marker offset %.2f ", FRA2TIME(offs));
						else
							BLI_snprintf(str, sizeof(str), "Marker offset %.2f ", (double)(offs));
					}
					else {
						BLI_snprintf(str, sizeof(str), "Marker offset %.2f ", (double)(offs));
					}
				}
				
				ED_area_headerprint(CTX_wm_area(C), str);
			}
	}

	if (event->val == KM_PRESS) {
		if (handleNumInput(&mm->num, event)) {
			char str_tx[NUM_STR_REP_LEN];
			float value = RNA_int_get(op->ptr, "frames");
			applyNumInput(&mm->num, &value);

			if (hasNumInput(&mm->num)) {
				outputNumInput(&mm->num, str_tx);
			}
			else {
				BLI_snprintf(str_tx, sizeof(str_tx), "%d", (int)value);
			}

			RNA_int_set(op->ptr, "frames", value);
			ed_marker_move_apply(C, op);
			// ed_marker_header_update(C, op, str, (int)value);
			// strcat(str, str_tx);
			BLI_snprintf(str, sizeof(str), "Marker offset %s", str_tx);
			ED_area_headerprint(CTX_wm_area(C), str);
		}
	}

	return OPERATOR_RUNNING_MODAL;
}
示例#3
0
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;
}
示例#4
0
static int edbm_bevel_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
	BevelData *opdata = op->customdata;
	const bool has_numinput = hasNumInput(&opdata->num_input[opdata->value_mode]);

	/* Modal numinput active, try to handle numeric inputs first... */
	if (event->val == KM_PRESS && has_numinput && handleNumInput(C, &opdata->num_input[opdata->value_mode], event)) {
		edbm_bevel_numinput_set_value(op);
		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) {
					edbm_bevel_mouse_set_value(op, event);
					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;

			case MOUSEPAN: {
				float delta = 0.02f * (event->y - event->prevy);
				if (opdata->segments >= 1 && opdata->segments + delta < 1)
					opdata->segments = 1;
				else
					opdata->segments += delta;
				RNA_int_set(op->ptr, "segments", (int)opdata->segments);
				edbm_bevel_calc(op);
				edbm_bevel_update_header(C, op);
				handled = true;
				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;

				opdata->segments = opdata->segments + 1;
				RNA_int_set(op->ptr, "segments", (int)opdata->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;

				opdata->segments = max_ff(opdata->segments - 1, 1);
				RNA_int_set(op->ptr, "segments", (int)opdata->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;
					}
					if (opdata->value_mode == OFFSET_VALUE && type == BEVEL_AMT_PERCENT)
						opdata->value_mode = OFFSET_VALUE_PERCENT;
					else if (opdata->value_mode == OFFSET_VALUE_PERCENT && type != BEVEL_AMT_PERCENT)
						opdata->value_mode = OFFSET_VALUE;
					RNA_property_enum_set(op->ptr, prop, type);
					if (opdata->initial_length[opdata->value_mode] == -1.0f)
						edbm_bevel_calc_initial_length(op, event, true);
				}
				/* Update offset accordingly to new offset_type. */
				if (!has_numinput &&
				    (opdata->value_mode == OFFSET_VALUE || opdata->value_mode == OFFSET_VALUE_PERCENT))
				{
					edbm_bevel_mouse_set_value(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 PKEY:
				if (event->val == KM_RELEASE)
					break;
				if (opdata->value_mode == PROFILE_VALUE) {
					opdata->value_mode = OFFSET_VALUE;
				}
				else {
					opdata->value_mode = PROFILE_VALUE;
				}
				edbm_bevel_calc_initial_length(op, event, true);
				break;
			case SKEY:
				if (event->val == KM_RELEASE)
					break;
				if (opdata->value_mode == SEGMENTS_VALUE) {
					opdata->value_mode = OFFSET_VALUE;
				}
				else {
					opdata->value_mode = SEGMENTS_VALUE;
				}
				edbm_bevel_calc_initial_length(op, event, 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[opdata->value_mode], event)) {
			edbm_bevel_numinput_set_value(op);
			edbm_bevel_calc(op);
			edbm_bevel_update_header(C, op);
			return OPERATOR_RUNNING_MODAL;
		}
	}

	return OPERATOR_RUNNING_MODAL;
}
示例#5
0
static int edbm_bevel_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
  BevelData *opdata = op->customdata;
  const bool has_numinput = hasNumInput(&opdata->num_input[opdata->value_mode]);
  bool handled = false;
  short etype = event->type;
  short eval = event->val;

  /* When activated from toolbar, need to convert leftmouse release to confirm */
  if (etype == LEFTMOUSE && eval == KM_RELEASE && RNA_boolean_get(op->ptr, "release_confirm")) {
    etype = EVT_MODAL_MAP;
    eval = BEV_MODAL_CONFIRM;
  }
  /* Modal numinput active, try to handle numeric inputs first... */
  if (etype != EVT_MODAL_MAP && eval == KM_PRESS && has_numinput &&
      handleNumInput(C, &opdata->num_input[opdata->value_mode], event)) {
    edbm_bevel_numinput_set_value(op);
    edbm_bevel_calc(op);
    edbm_bevel_update_header(C, op);
    return OPERATOR_RUNNING_MODAL;
  }
  else if (etype == MOUSEMOVE) {
    if (!has_numinput) {
      edbm_bevel_mouse_set_value(op, event);
      edbm_bevel_calc(op);
      edbm_bevel_update_header(C, op);
      handled = true;
    }
  }
  else if (etype == MOUSEPAN) {
    float delta = 0.02f * (event->y - event->prevy);
    if (opdata->segments >= 1 && opdata->segments + delta < 1) {
      opdata->segments = 1;
    }
    else {
      opdata->segments += delta;
    }
    RNA_int_set(op->ptr, "segments", (int)opdata->segments);
    edbm_bevel_calc(op);
    edbm_bevel_update_header(C, op);
    handled = true;
  }
  else if (etype == EVT_MODAL_MAP) {
    switch (eval) {
      case BEV_MODAL_CANCEL:
        edbm_bevel_cancel(C, op);
        ED_workspace_status_text(C, NULL);
        return OPERATOR_CANCELLED;

      case BEV_MODAL_CONFIRM:
        edbm_bevel_calc(op);
        edbm_bevel_exit(C, op);
        ED_workspace_status_text(C, NULL);
        return OPERATOR_FINISHED;

      case BEV_MODAL_SEGMENTS_UP:
        opdata->segments = opdata->segments + 1;
        RNA_int_set(op->ptr, "segments", (int)opdata->segments);
        edbm_bevel_calc(op);
        edbm_bevel_update_header(C, op);
        handled = true;
        break;

      case BEV_MODAL_SEGMENTS_DOWN:
        opdata->segments = max_ff(opdata->segments - 1, 1);
        RNA_int_set(op->ptr, "segments", (int)opdata->segments);
        edbm_bevel_calc(op);
        edbm_bevel_update_header(C, op);
        handled = true;
        break;

      case BEV_MODAL_OFFSET_MODE_CHANGE: {
        int type = RNA_enum_get(op->ptr, "offset_type");
        type++;
        if (type > BEVEL_AMT_PERCENT) {
          type = BEVEL_AMT_OFFSET;
        }
        if (opdata->value_mode == OFFSET_VALUE && type == BEVEL_AMT_PERCENT) {
          opdata->value_mode = OFFSET_VALUE_PERCENT;
        }
        else if (opdata->value_mode == OFFSET_VALUE_PERCENT && type != BEVEL_AMT_PERCENT) {
          opdata->value_mode = OFFSET_VALUE;
        }
        RNA_enum_set(op->ptr, "offset_type", type);
        if (opdata->initial_length[opdata->value_mode] == -1.0f) {
          edbm_bevel_calc_initial_length(op, event, true);
        }
      }
        /* Update offset accordingly to new offset_type. */
        if (!has_numinput &&
            (opdata->value_mode == OFFSET_VALUE || opdata->value_mode == OFFSET_VALUE_PERCENT)) {
          edbm_bevel_mouse_set_value(op, event);
        }
        edbm_bevel_calc(op);
        edbm_bevel_update_header(C, op);
        handled = true;
        break;

      case BEV_MODAL_CLAMP_OVERLAP_TOGGLE: {
        bool clamp_overlap = RNA_boolean_get(op->ptr, "clamp_overlap");
        RNA_boolean_set(op->ptr, "clamp_overlap", !clamp_overlap);
        edbm_bevel_calc(op);
        edbm_bevel_update_header(C, op);
        handled = true;
        break;
      }

      case BEV_MODAL_VALUE_OFFSET:
        opdata->value_mode = OFFSET_VALUE;
        edbm_bevel_calc_initial_length(op, event, true);
        break;

      case BEV_MODAL_VALUE_PROFILE:
        opdata->value_mode = PROFILE_VALUE;
        edbm_bevel_calc_initial_length(op, event, true);
        break;

      case BEV_MODAL_VALUE_SEGMENTS:
        opdata->value_mode = SEGMENTS_VALUE;
        edbm_bevel_calc_initial_length(op, event, true);
        break;

      case BEV_MODAL_VERTEX_ONLY_TOGGLE: {
        bool vertex_only = RNA_boolean_get(op->ptr, "vertex_only");
        RNA_boolean_set(op->ptr, "vertex_only", !vertex_only);
        edbm_bevel_calc(op);
        edbm_bevel_update_header(C, op);
        handled = true;
        break;
      }

      case BEV_MODAL_MARK_SEAM_TOGGLE: {
        bool mark_seam = RNA_boolean_get(op->ptr, "mark_seam");
        RNA_boolean_set(op->ptr, "mark_seam", !mark_seam);
        edbm_bevel_calc(op);
        edbm_bevel_update_header(C, op);
        handled = true;
        break;
      }

      case BEV_MODAL_MARK_SHARP_TOGGLE: {
        bool mark_sharp = RNA_boolean_get(op->ptr, "mark_sharp");
        RNA_boolean_set(op->ptr, "mark_sharp", !mark_sharp);
        edbm_bevel_calc(op);
        edbm_bevel_update_header(C, op);
        handled = true;
        break;
      }

      case BEV_MODAL_INNER_MITER_CHANGE: {
        int miter_inner = RNA_enum_get(op->ptr, "miter_inner");
        miter_inner++;
        if (miter_inner == BEVEL_MITER_PATCH) {
          miter_inner++; /* no patch option for inner miter */
        }
        if (miter_inner > BEVEL_MITER_ARC) {
          miter_inner = BEVEL_MITER_SHARP;
        }
        RNA_enum_set(op->ptr, "miter_inner", miter_inner);
        edbm_bevel_calc(op);
        edbm_bevel_update_header(C, op);
        handled = true;
        break;
      }

      case BEV_MODAL_OUTER_MITER_CHANGE: {
        int miter_outer = RNA_enum_get(op->ptr, "miter_outer");
        miter_outer++;
        if (miter_outer > BEVEL_MITER_ARC) {
          miter_outer = BEVEL_MITER_SHARP;
        }
        RNA_enum_set(op->ptr, "miter_outer", miter_outer);
        edbm_bevel_calc(op);
        edbm_bevel_update_header(C, op);
        handled = true;
        break;
      }

      case BEV_MODAL_HARDEN_NORMALS_TOGGLE: {
        bool harden_normals = RNA_boolean_get(op->ptr, "harden_normals");
        RNA_boolean_set(op->ptr, "harden_normals", !harden_normals);
        edbm_bevel_calc(op);
        edbm_bevel_update_header(C, op);
        handled = true;
        break;
      }
    }
  }

  /* Modal numinput inactive, try to handle numeric inputs last... */
  if (!handled && eval == KM_PRESS &&
      handleNumInput(C, &opdata->num_input[opdata->value_mode], event)) {
    edbm_bevel_numinput_set_value(op);
    edbm_bevel_calc(op);
    edbm_bevel_update_header(C, op);
    return OPERATOR_RUNNING_MODAL;
  }

  return OPERATOR_RUNNING_MODAL;
}
示例#6
0
static int edbm_inset_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
	InsetData *opdata = op->customdata;
	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 amounts[2] = {RNA_float_get(op->ptr, "thickness"),
		                    RNA_float_get(op->ptr, "depth")};
		applyNumInput(&opdata->num_input, amounts);
		amounts[0] = max_ff(amounts[0], 0.0f);
		RNA_float_set(op->ptr, "thickness", amounts[0]);
		RNA_float_set(op->ptr, "depth", amounts[1]);

		if (edbm_inset_calc(op)) {
			edbm_inset_update_header(op, C);
			return OPERATOR_RUNNING_MODAL;
		}
		else {
			edbm_inset_cancel(C, op);
			return OPERATOR_CANCELLED;
		}
	}
	else {
		bool handled = false;
		switch (event->type) {
			case ESCKEY:
			case RIGHTMOUSE:
				edbm_inset_cancel(C, op);
				return OPERATOR_CANCELLED;

			case MOUSEMOVE:
				if (!has_numinput) {
					float mdiff[2];
					float amount;

					mdiff[0] = opdata->mcenter[0] - event->mval[0];
					mdiff[1] = opdata->mcenter[1] - event->mval[1];

					if (opdata->modify_depth)
						amount = opdata->old_depth     + ((len_v2(mdiff) - opdata->initial_length) * opdata->pixel_size);
					else
						amount = opdata->old_thickness - ((len_v2(mdiff) - opdata->initial_length) * opdata->pixel_size);

					/* Fake shift-transform... */
					if (opdata->shift)
						amount = (amount - opdata->shift_amount) * 0.1f + opdata->shift_amount;

					if (opdata->modify_depth)
						RNA_float_set(op->ptr, "depth", amount);
					else {
						amount = max_ff(amount, 0.0f);
						RNA_float_set(op->ptr, "thickness", amount);
					}

					if (edbm_inset_calc(op))
						edbm_inset_update_header(op, C);
					else {
						edbm_inset_cancel(C, op);
						return OPERATOR_CANCELLED;
					}
					handled = true;
				}
				break;

			case LEFTMOUSE:
			case PADENTER:
			case RETKEY:
				edbm_inset_calc(op);
				edbm_inset_exit(C, op);
				return OPERATOR_FINISHED;

			case LEFTSHIFTKEY:
			case RIGHTSHIFTKEY:
				if (event->val == KM_PRESS) {
					if (opdata->modify_depth)
						opdata->shift_amount = RNA_float_get(op->ptr, "depth");
					else
						opdata->shift_amount = RNA_float_get(op->ptr, "thickness");
					opdata->shift = true;
					handled = true;
				}
				else {
					opdata->shift_amount = 0.0f;
					opdata->shift = false;
					handled = true;
				}
				break;

			case LEFTCTRLKEY:
			case RIGHTCTRLKEY:
			{
				float mlen[2];

				mlen[0] = opdata->mcenter[0] - event->mval[0];
				mlen[1] = opdata->mcenter[1] - event->mval[1];

				if (event->val == KM_PRESS) {
					opdata->old_thickness = RNA_float_get(op->ptr, "thickness");
					if (opdata->shift)
						opdata->shift_amount = opdata->old_thickness;
					opdata->modify_depth = true;
				}
				else {
					opdata->old_depth = RNA_float_get(op->ptr, "depth");
					if (opdata->shift)
						opdata->shift_amount = opdata->old_depth;
					opdata->modify_depth = false;
				}
				opdata->initial_length = len_v2(mlen);

				edbm_inset_update_header(op, C);
				handled = true;
				break;
			}

			case OKEY:
				if (event->val == KM_PRESS) {
					const bool use_outset = RNA_boolean_get(op->ptr, "use_outset");
					RNA_boolean_set(op->ptr, "use_outset", !use_outset);
					if (edbm_inset_calc(op)) {
						edbm_inset_update_header(op, C);
					}
					else {
						edbm_inset_cancel(C, op);
						return OPERATOR_CANCELLED;
					}
					handled = true;
				}
				break;
			case BKEY:
				if (event->val == KM_PRESS) {
					const bool use_boundary = RNA_boolean_get(op->ptr, "use_boundary");
					RNA_boolean_set(op->ptr, "use_boundary", !use_boundary);
					if (edbm_inset_calc(op)) {
						edbm_inset_update_header(op, C);
					}
					else {
						edbm_inset_cancel(C, op);
						return OPERATOR_CANCELLED;
					}
					handled = true;
				}
				break;
			case IKEY:
				if (event->val == KM_PRESS) {
					const bool use_individual = RNA_boolean_get(op->ptr, "use_individual");
					RNA_boolean_set(op->ptr, "use_individual", !use_individual);
					if (edbm_inset_calc(op)) {
						edbm_inset_update_header(op, C);
					}
					else {
						edbm_inset_cancel(C, op);
						return OPERATOR_CANCELLED;
					}
					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 amounts[2] = {RNA_float_get(op->ptr, "thickness"),
			                    RNA_float_get(op->ptr, "depth")};
			applyNumInput(&opdata->num_input, amounts);
			amounts[0] = max_ff(amounts[0], 0.0f);
			RNA_float_set(op->ptr, "thickness", amounts[0]);
			RNA_float_set(op->ptr, "depth", amounts[1]);

			if (edbm_inset_calc(op)) {
				edbm_inset_update_header(op, C);
				return OPERATOR_RUNNING_MODAL;
			}
			else {
				edbm_inset_cancel(C, op);
				return OPERATOR_CANCELLED;
			}
		}
	}

	return OPERATOR_RUNNING_MODAL;
}
示例#7
0
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;
}
示例#8
0
/* common code for modal() */
static int pose_slide_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
	tPoseSlideOp *pso = op->customdata;
	wmWindow *win = CTX_wm_window(C);
	const bool has_numinput = hasNumInput(&pso->num);
	
	switch (event->type) {
		case LEFTMOUSE: /* confirm */
		case RETKEY:
		case PADENTER:
		{
			/* return to normal cursor and header status */
			ED_area_headerprint(pso->sa, NULL);
			WM_cursor_modal_restore(win);
			
			/* insert keyframes as required... */
			pose_slide_autoKeyframe(C, pso);
			pose_slide_exit(op);
			
			/* done! */
			return OPERATOR_FINISHED;
		}
		
		case ESCKEY:    /* cancel */
		case RIGHTMOUSE: 
		{
			/* return to normal cursor and header status */
			ED_area_headerprint(pso->sa, NULL);
			WM_cursor_modal_restore(win);
			
			/* reset transforms back to original state */
			pose_slide_reset(pso);
			
			/* depsgraph updates + redraws */
			pose_slide_refresh(C, pso);
			
			/* clean up temp data */
			pose_slide_exit(op);
			
			/* canceled! */
			return OPERATOR_CANCELLED;
		}
			
		case MOUSEMOVE: /* calculate new position */
		{
			/* only handle mousemove if not doing numinput */
			if (has_numinput == false) {
				/* update percentage based on position of mouse */
				pose_slide_mouse_update_percentage(pso, op, event);
				
				/* update percentage indicator in header */
				pose_slide_draw_status(pso);
				
				/* reset transforms (to avoid accumulation errors) */
				pose_slide_reset(pso);
				
				/* apply... */
				pose_slide_apply(C, pso);
			}
			break;
		}
		default:
			if ((event->val == KM_PRESS) && handleNumInput(C, &pso->num, event)) {
				float value;
				
				/* Grab percentage from numeric input, and store this new value for redo  
				 * NOTE: users see ints, while internally we use a 0-1 float
				 */
				value = pso->percentage * 100.0f;
				applyNumInput(&pso->num, &value);
				
				pso->percentage = value / 100.0f;
				CLAMP(pso->percentage, 0.0f, 1.0f);
				RNA_float_set(op->ptr, "percentage", pso->percentage);
				
				/* update percentage indicator in header */
				pose_slide_draw_status(pso);
				
				/* reset transforms (to avoid accumulation errors) */
				pose_slide_reset(pso);
				
				/* apply... */
				pose_slide_apply(C, pso);
				break;
			}
			else {
				/* unhandled event - maybe it was some view manip? */
				/* allow to pass through */
				return OPERATOR_RUNNING_MODAL | OPERATOR_PASS_THROUGH;
			}
	}
	
	/* still running... */
	return OPERATOR_RUNNING_MODAL;
}
示例#9
0
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;
}