use floats for knife tool internal mouse coord.

This commit is contained in:
Campbell Barton 2013-03-14 14:46:59 +00:00
parent 93d7e3b442
commit d92e32e4e7

@ -137,7 +137,8 @@ typedef struct KnifePosData {
typedef struct KnifeTool_OpData { typedef struct KnifeTool_OpData {
ARegion *ar; /* region that knifetool was activated in */ ARegion *ar; /* region that knifetool was activated in */
void *draw_handle; /* for drawing preview loop */ void *draw_handle; /* for drawing preview loop */
ViewContext vc; ViewContext vc; /* note: _don't_ use 'mval', instead use the one we define below */
float mval[2]; /* mouse value with snapping applied */
//bContext *C; //bContext *C;
Object *ob; Object *ob;
@ -245,8 +246,7 @@ static void knife_pos_data_clear(KnifePosData *kpd)
kpd->vert = NULL; kpd->vert = NULL;
kpd->edge = NULL; kpd->edge = NULL;
kpd->bmface = NULL; kpd->bmface = NULL;
kpd->mval[0] = 0.0f; zero_v2(kpd->mval);
kpd->mval[1] = 0.0f;
} }
static ListBase *knife_empty_list(KnifeTool_OpData *kcd) static ListBase *knife_empty_list(KnifeTool_OpData *kcd)
@ -1747,7 +1747,7 @@ static KnifeVert *knife_find_closest_vert(KnifeTool_OpData *kcd, float p[3], flo
return NULL; return NULL;
} }
/* update both kcd->curr.mval and kcd->vc.mval to snap to required angle */ /* update both kcd->curr.mval and kcd->mval to snap to required angle */
static void knife_snap_angle(KnifeTool_OpData *kcd) static void knife_snap_angle(KnifeTool_OpData *kcd)
{ {
float dx, dy; float dx, dy;
@ -1784,16 +1784,14 @@ static void knife_snap_angle(KnifeTool_OpData *kcd)
kcd->curr.mval[0] = kcd->prev.mval[0]; kcd->curr.mval[0] = kcd->prev.mval[0];
} }
kcd->vc.mval[0] = round_ftoi(kcd->curr.mval[0]); copy_v2_v2(kcd->mval, kcd->curr.mval);
kcd->vc.mval[1] = round_ftoi(kcd->curr.mval[1]);
} }
/* update active knife edge/vert pointers */ /* update active knife edge/vert pointers */
static int knife_update_active(KnifeTool_OpData *kcd) static int knife_update_active(KnifeTool_OpData *kcd)
{ {
knife_pos_data_clear(&kcd->curr); knife_pos_data_clear(&kcd->curr);
kcd->curr.mval[0] = (float)kcd->vc.mval[0]; copy_v2_v2(kcd->curr.mval, kcd->mval);
kcd->curr.mval[1] = (float)kcd->vc.mval[1];
if (kcd->angle_snapping != ANGLE_FREE && kcd->mode == MODE_DRAGGING) if (kcd->angle_snapping != ANGLE_FREE && kcd->mode == MODE_DRAGGING)
knife_snap_angle(kcd); knife_snap_angle(kcd);
@ -2936,17 +2934,22 @@ static void cage_mapped_verts_callback(void *userData, int index, const float co
} }
} }
static void knifetool_update_mval(KnifeTool_OpData *kcd, const int mval_i[2]) static void knifetool_update_mval(KnifeTool_OpData *kcd, const float mval[2])
{ {
knife_recalc_projmat(kcd); knife_recalc_projmat(kcd);
kcd->vc.mval[0] = mval_i[0]; copy_v2_v2(kcd->mval, mval);
kcd->vc.mval[1] = mval_i[1];
if (knife_update_active(kcd)) { if (knife_update_active(kcd)) {
ED_region_tag_redraw(kcd->ar); ED_region_tag_redraw(kcd->ar);
} }
} }
static void knifetool_update_mval_i(KnifeTool_OpData *kcd, const int mval_i[2])
{
float mval[2] = {UNPACK2(mval_i)};
knifetool_update_mval(kcd, mval);
}
/* called when modal loop selection gets set up... */ /* called when modal loop selection gets set up... */
static void knifetool_init(bContext *C, KnifeTool_OpData *kcd, static void knifetool_init(bContext *C, KnifeTool_OpData *kcd,
const bool only_select, const bool cut_through) const bool only_select, const bool cut_through)
@ -3038,8 +3041,7 @@ static int knifetool_invoke(bContext *C, wmOperator *op, const wmEvent *event)
WM_cursor_modal(CTX_wm_window(C), BC_KNIFECURSOR); WM_cursor_modal(CTX_wm_window(C), BC_KNIFECURSOR);
WM_event_add_modal_handler(C, op); WM_event_add_modal_handler(C, op);
kcd = op->customdata; knifetool_update_mval_i(kcd, event->mval);
knifetool_update_mval(kcd, event->mval);
knife_update_header(C, kcd); knife_update_header(C, kcd);
@ -3232,7 +3234,7 @@ static int knifetool_modal(bContext *C, wmOperator *op, const wmEvent *event)
case MOUSEMOVE: /* mouse moved somewhere to select another loop */ case MOUSEMOVE: /* mouse moved somewhere to select another loop */
if (kcd->mode != MODE_PANNING) { if (kcd->mode != MODE_PANNING) {
knifetool_update_mval(kcd, event->mval); knifetool_update_mval_i(kcd, event->mval);
} }
break; break;
@ -3242,7 +3244,7 @@ static int knifetool_modal(bContext *C, wmOperator *op, const wmEvent *event)
if (do_refresh) { if (do_refresh) {
/* we don't really need to update mval, /* we don't really need to update mval,
* but this happens to be the best way to refresh at the moment */ * but this happens to be the best way to refresh at the moment */
knifetool_update_mval(kcd, event->mval); knifetool_update_mval_i(kcd, event->mval);
} }
/* keep going until the user confirms */ /* keep going until the user confirms */