diff options
Diffstat (limited to 'source/blender/editors/transform/transform.c')
-rw-r--r-- | source/blender/editors/transform/transform.c | 1319 |
1 files changed, 654 insertions, 665 deletions
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 674de81a9f5..c62ea07e398 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -45,6 +45,7 @@ #include "MEM_guardedalloc.h" +#include "DNA_anim_types.h" #include "DNA_armature_types.h" #include "DNA_action_types.h" /* for some special action-editor settings */ #include "DNA_constraint_types.h" @@ -76,9 +77,9 @@ //#include "BIF_editmesh.h" //#include "BIF_editsima.h" //#include "BIF_editparticle.h" -//#include "BIF_editaction.h" -#include "BKE_action.h" /* get_action_frame */ +#include "BKE_action.h" +#include "BKE_nla.h" //#include "BKE_bad_level_calls.h"/* popmenu and error */ #include "BKE_bmesh.h" #include "BKE_context.h" @@ -89,7 +90,6 @@ #include "BKE_utildefines.h" #include "BKE_context.h" -//#include "BSE_editaction_types.h" //#include "BSE_view.h" #include "ED_image.h" @@ -123,7 +123,7 @@ void setTransformViewMatrices(TransInfo *t) { if(t->spacetype==SPACE_VIEW3D && t->ar->regiontype == RGN_TYPE_WINDOW) { RegionView3D *rv3d = t->ar->regiondata; - + Mat4CpyMat4(t->viewmat, rv3d->viewmat); Mat4CpyMat4(t->viewinv, rv3d->viewinv); Mat4CpyMat4(t->persmat, rv3d->persmat); @@ -137,7 +137,7 @@ void setTransformViewMatrices(TransInfo *t) Mat4One(t->persinv); t->persp = V3D_ORTHO; } - + calculateCenter2D(t); } @@ -152,23 +152,23 @@ void convertViewVec(TransInfo *t, float *vec, short dx, short dy) else if(t->spacetype==SPACE_IMAGE) { View2D *v2d = t->view; float divx, divy, aspx, aspy; - + ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy); - + divx= v2d->mask.xmax-v2d->mask.xmin; divy= v2d->mask.ymax-v2d->mask.ymin; - + vec[0]= aspx*(v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx; vec[1]= aspy*(v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy; vec[2]= 0.0f; } - else if(t->spacetype==SPACE_IPO) { + else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) { View2D *v2d = t->view; float divx, divy; - + divx= v2d->mask.xmax-v2d->mask.xmin; divy= v2d->mask.ymax-v2d->mask.ymin; - + vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx) / (divx); vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy) / (divy); vec[2]= 0.0f; @@ -176,10 +176,10 @@ void convertViewVec(TransInfo *t, float *vec, short dx, short dy) else if(t->spacetype==SPACE_NODE) { View2D *v2d = &t->ar->v2d; float divx, divy; - + divx= v2d->mask.xmax-v2d->mask.xmin; divy= v2d->mask.ymax-v2d->mask.ymin; - + vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx; vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy; vec[2]= 0.0f; @@ -205,23 +205,23 @@ void projectIntView(TransInfo *t, float *vec, int *adr) } else if(t->spacetype==SPACE_IMAGE) { float aspx, aspy, v[2]; - + ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy); v[0]= vec[0]/aspx; v[1]= vec[1]/aspy; - + UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr+1); } - else if(t->spacetype==SPACE_IPO) { + else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) { int out[2] = {0, 0}; - - UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], out, out+1); + + UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], out, out+1); adr[0]= out[0]; adr[1]= out[1]; } else if(t->spacetype==SPACE_SEQ) { /* XXX not tested yet, but should work */ int out[2] = {0, 0}; - + UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], out, out+1); adr[0]= out[0]; adr[1]= out[1]; @@ -236,14 +236,14 @@ void projectFloatView(TransInfo *t, float *vec, float *adr) } else if(t->spacetype==SPACE_IMAGE) { int a[2]; - + projectIntView(t, vec, a); adr[0]= a[0]; adr[1]= a[1]; } - else if(t->spacetype==SPACE_IPO) { + else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) { int a[2]; - + projectIntView(t, vec, a); adr[0]= a[0]; adr[1]= a[1]; @@ -296,28 +296,19 @@ static void viewRedrawForce(bContext *C, TransInfo *t) { if (t->spacetype == SPACE_VIEW3D) { - /* Do we need more refined tags? */ + /* Do we need more refined tags? */ WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL); } else if (t->spacetype == SPACE_ACTION) { - SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first; - - // TRANSFORM_FIX_ME - if (saction->lock) { - // whole window... - } - else - ED_area_tag_redraw(t->sa); + //SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first; + WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_EDIT, NULL); } else if (t->spacetype == SPACE_IPO) { - SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first; - - // TRANSFORM_FIX_ME - if (sipo->lock) { - // whole window... - } - else - ED_area_tag_redraw(t->sa); + //SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first; + WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_EDIT, NULL); + } + else if (t->spacetype == SPACE_NLA) { + WM_event_add_notifier(C, NC_ANIMATION|ND_NLA_EDIT, NULL); } else if(t->spacetype == SPACE_NODE) { @@ -343,7 +334,7 @@ static void viewRedrawForce(bContext *C, TransInfo *t) static void viewRedrawPost(TransInfo *t) { ED_area_headerprint(t->sa, NULL); - + #if 0 // TRANSFORM_FIX_ME if(t->spacetype==SPACE_VIEW3D) { allqueue(REDRAWBUTSOBJECT, 0); @@ -374,7 +365,7 @@ void BIF_selectOrientation() { char *str_menu = BIF_menustringTransformOrientation("Orientation"); val= pupmenu(str_menu); MEM_freeN(str_menu); - + if(val >= 0) { G.vd->twmode = val; } @@ -390,18 +381,18 @@ static void view_editmove(unsigned short event) /* Ctrl: Scroll right */ /* Alt-Shift: Rotate up */ /* Alt-Ctrl: Rotate right */ - + /* only work in 3D window for now * In the end, will have to send to event to a 2D window handler instead */ if (Trans.flag & T_2D_EDIT) return; - + switch(event) { case WHEELUPMOUSE: - + if( G.qual & LR_SHIFTKEY ) { - if( G.qual & LR_ALTKEY ) { + if( G.qual & LR_ALTKEY ) { G.qual &= ~LR_SHIFTKEY; persptoetsen(PAD2); G.qual |= LR_SHIFTKEY; @@ -409,23 +400,23 @@ static void view_editmove(unsigned short event) persptoetsen(PAD2); } } else if( G.qual & LR_CTRLKEY ) { - if( G.qual & LR_ALTKEY ) { + if( G.qual & LR_ALTKEY ) { G.qual &= ~LR_CTRLKEY; persptoetsen(PAD4); G.qual |= LR_CTRLKEY; } else { persptoetsen(PAD4); } - } else if(U.uiflag & USER_WHEELZOOMDIR) + } else if(U.uiflag & USER_WHEELZOOMDIR) persptoetsen(PADMINUS); else persptoetsen(PADPLUSKEY); - + refresh = 1; break; case WHEELDOWNMOUSE: if( G.qual & LR_SHIFTKEY ) { - if( G.qual & LR_ALTKEY ) { + if( G.qual & LR_ALTKEY ) { G.qual &= ~LR_SHIFTKEY; persptoetsen(PAD8); G.qual |= LR_SHIFTKEY; @@ -433,18 +424,18 @@ static void view_editmove(unsigned short event) persptoetsen(PAD8); } } else if( G.qual & LR_CTRLKEY ) { - if( G.qual & LR_ALTKEY ) { + if( G.qual & LR_ALTKEY ) { G.qual &= ~LR_CTRLKEY; persptoetsen(PAD6); G.qual |= LR_CTRLKEY; } else { persptoetsen(PAD6); } - } else if(U.uiflag & USER_WHEELZOOMDIR) + } else if(U.uiflag & USER_WHEELZOOMDIR) persptoetsen(PADPLUSKEY); else persptoetsen(PADMINUS); - + refresh = 1; break; } @@ -454,6 +445,7 @@ static void view_editmove(unsigned short event) #endif } +#if 0 static char *transform_to_undostr(TransInfo *t) { switch (t->mode) { @@ -500,6 +492,7 @@ static char *transform_to_undostr(TransInfo *t) } return "Transform"; } +#endif /* ************************************************* */ @@ -507,19 +500,19 @@ void transformEvent(TransInfo *t, wmEvent *event) { float mati[3][3] = {{1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}}; char cmode = constraintModeToChar(t); - + t->redraw |= handleMouseInput(t, &t->mouse, event); if (event->type == MOUSEMOVE) { t->mval[0] = event->x - t->ar->winrct.xmin; t->mval[1] = event->y - t->ar->winrct.ymin; - + t->redraw = 1; - + applyMouseInput(t, &t->mouse, t->mval, t->values); } - + if (event->val) { switch (event->type){ /* enforce redraw of transform when modifiers are used */ @@ -528,7 +521,7 @@ void transformEvent(TransInfo *t, wmEvent *event) t->modifiers |= MOD_SNAP_GEARS; t->redraw = 1; break; - + case LEFTSHIFTKEY: case RIGHTSHIFTKEY: t->modifiers |= MOD_CONSTRAINT_PLANE; @@ -539,7 +532,7 @@ void transformEvent(TransInfo *t, wmEvent *event) if ((t->spacetype==SPACE_VIEW3D) && event->alt) { #if 0 // TRANSFORM_FIX_ME short mval[2]; - + getmouseco_sc(mval); BIF_selectOrientation(); calc_manipulator_stats(curarea); @@ -551,7 +544,7 @@ void transformEvent(TransInfo *t, wmEvent *event) t->state = TRANS_CONFIRM; } break; - + case MIDDLEMOUSE: if ((t->flag & T_NO_CONSTRAINT)==0) { /* exception for switching to dolly, or trackball, in camera view */ @@ -584,19 +577,16 @@ void transformEvent(TransInfo *t, wmEvent *event) } break; case ESCKEY: - case RIGHTMOUSE: - printf("cancelled\n"); t->state = TRANS_CANCEL; break; - case LEFTMOUSE: case PADENTER: case RETKEY: t->state = TRANS_CONFIRM; break; case GKEY: /* only switch when... */ - if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) { - resetTransRestrictions(t); + if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) { + resetTransRestrictions(t); restoreTransObjects(t); initTranslation(t); initSnapping(t, NULL); // need to reinit after mode change @@ -605,8 +595,8 @@ void transformEvent(TransInfo *t, wmEvent *event) break; case SKEY: /* only switch when... */ - if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) { - resetTransRestrictions(t); + if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) { + resetTransRestrictions(t); restoreTransObjects(t); initResize(t); initSnapping(t, NULL); // need to reinit after mode change @@ -616,9 +606,9 @@ void transformEvent(TransInfo *t, wmEvent *event) case RKEY: /* only switch when... */ if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) { - - resetTransRestrictions(t); - + + resetTransRestrictions(t); + if (t->mode == TFM_ROTATION) { restoreTransObjects(t); initTrackball(t); @@ -778,10 +768,10 @@ void transformEvent(TransInfo *t, wmEvent *event) // viewmoveNDOF(1); // break; } - + // Numerical input events t->redraw |= handleNumInput(&(t->num), event); - + // NDof input events switch(handleNDofInput(&(t->ndof), event)) { @@ -796,7 +786,7 @@ void transformEvent(TransInfo *t, wmEvent *event) if (t->options & CTX_NDOF) { /* Cancel on pure NDOF transform */ - t->state = TRANS_CANCEL; + t->state = TRANS_CANCEL; } else { @@ -814,16 +804,22 @@ void transformEvent(TransInfo *t, wmEvent *event) case NDOF_REFRESH: t->redraw = 1; break; - + } - + // Snapping events t->redraw |= handleSnapping(t, event); - + //arrows_move_cursor(event->type); } else { switch (event->type){ + case RIGHTMOUSE: + t->state = TRANS_CANCEL; + break; + case LEFTMOUSE: + t->state = TRANS_CONFIRM; + break; case LEFTSHIFTKEY: case RIGHTSHIFTKEY: t->modifiers &= ~MOD_CONSTRAINT_PLANE; @@ -833,7 +829,7 @@ void transformEvent(TransInfo *t, wmEvent *event) case LEFTCTRLKEY: case RIGHTCTRLKEY: t->modifiers &= ~MOD_SNAP_GEARS; - /* no redraw on release modifier keys! this makes sure you can assign the 'grid' still + /* no redraw on release modifier keys! this makes sure you can assign the 'grid' still after releasing modifer key */ //t->redraw = 1; break; @@ -844,15 +840,15 @@ void transformEvent(TransInfo *t, wmEvent *event) t->redraw = 1; } break; - case LEFTMOUSE: - case RIGHTMOUSE: - if(WM_modal_tweak_exit(event, t->event_type)) -// if (t->options & CTX_TWEAK) - t->state = TRANS_CONFIRM; - break; +// case LEFTMOUSE: +// case RIGHTMOUSE: +// if(WM_modal_tweak_exit(event, t->event_type)) +//// if (t->options & CTX_TWEAK) +// t->state = TRANS_CONFIRM; +// break; } } - + // Per transform event, if present if (t->handleEvent) t->redraw |= t->handleEvent(t, event); @@ -866,7 +862,7 @@ int calculateTransformCenter(bContext *C, wmEvent *event, int centerMode, float t->state = TRANS_RUNNING; t->options = CTX_NONE; - + t->mode = TFM_DUMMY; initTransInfo(C, t, NULL, event); // internal data, mouse, vectors @@ -880,10 +876,10 @@ int calculateTransformCenter(bContext *C, wmEvent *event, int centerMode, float } else { success = 1; - + calculateCenter(t); - - // Copy center from constraint center. Transform center can be local + + // Copy center from constraint center. Transform center can be local VECCOPY(vec, t->con.center); } @@ -891,9 +887,9 @@ int calculateTransformCenter(bContext *C, wmEvent *event, int centerMode, float /* aftertrans does insert ipos and action channels, and clears base flags, doesnt read transdata */ special_aftertrans_update(t); - + MEM_freeN(t); - + return success; } @@ -912,28 +908,28 @@ static void drawArrow(ArrowDirection d, short offset, short length, short size) length = -length; size = -size; case RIGHT: - glBegin(GL_LINES); - glVertex2s( offset, 0); - glVertex2s( offset + length, 0); - glVertex2s( offset + length, 0); - glVertex2s( offset + length - size, -size); - glVertex2s( offset + length, 0); + glBegin(GL_LINES); + glVertex2s( offset, 0); + glVertex2s( offset + length, 0); + glVertex2s( offset + length, 0); + glVertex2s( offset + length - size, -size); + glVertex2s( offset + length, 0); glVertex2s( offset + length - size, size); - glEnd(); + glEnd(); break; case DOWN: offset = -offset; length = -length; size = -size; case UP: - glBegin(GL_LINES); - glVertex2s( 0, offset); - glVertex2s( 0, offset + length); - glVertex2s( 0, offset + length); - glVertex2s(-size, offset + length - size); - glVertex2s( 0, offset + length); + glBegin(GL_LINES); + glVertex2s( 0, offset); + glVertex2s( 0, offset + length); + glVertex2s( 0, offset + length); + glVertex2s(-size, offset + length - size); + glVertex2s( 0, offset + length); glVertex2s( size, offset + length - size); - glEnd(); + glEnd(); break; } } @@ -945,22 +941,22 @@ static void drawArrowHead(ArrowDirection d, short size) case LEFT: size = -size; case RIGHT: - glBegin(GL_LINES); - glVertex2s( 0, 0); - glVertex2s( -size, -size); - glVertex2s( 0, 0); + glBegin(GL_LINES); + glVertex2s( 0, 0); + glVertex2s( -size, -size); + glVertex2s( 0, 0); glVertex2s( -size, size); - glEnd(); + glEnd(); break; case DOWN: size = -size; case UP: - glBegin(GL_LINES); - glVertex2s( 0, 0); - glVertex2s(-size, -size); - glVertex2s( 0, 0); + glBegin(GL_LINES); + glVertex2s( 0, 0); + glVertex2s(-size, -size); + glVertex2s( 0, 0); glVertex2s( size, -size); - glEnd(); + glEnd(); break; } } @@ -969,15 +965,15 @@ static void drawArc(float size, float angle_start, float angle_end, int segments { float delta = (angle_end - angle_start) / segments; float angle; - + glBegin(GL_LINE_STRIP); - + for( angle = angle_start; angle < angle_end; angle += delta) { glVertex2f( cosf(angle) * size, sinf(angle) * size); } glVertex2f( cosf(angle_end) * size, sinf(angle_end) * size); - + glEnd(); } @@ -986,7 +982,7 @@ void drawHelpline(const struct bContext *C, TransInfo *t) if (t->helpline != HLP_NONE && !(t->flag & T_USES_MANIPULATOR)) { float vecrot[3], cent[2]; - + VECCOPY(vecrot, t->center); if(t->flag & T_EDIT) { Object *ob= t->obedit; @@ -996,9 +992,9 @@ void drawHelpline(const struct bContext *C, TransInfo *t) Object *ob=t->poseobj; if(ob) Mat4MulVecfl(ob->obmat, vecrot); } - + projectFloatView(t, vecrot, cent); // no overflow in extreme cases - + glDisable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); @@ -1007,16 +1003,16 @@ void drawHelpline(const struct bContext *C, TransInfo *t) glPushMatrix(); ED_region_pixelspace(t->ar); - + switch(t->helpline) { case HLP_SPRING: UI_ThemeColor(TH_WIRE); - + setlinestyle(3); - glBegin(GL_LINE_STRIP); - glVertex2sv(t->mval); - glVertex2fv(cent); + glBegin(GL_LINE_STRIP); + glVertex2sv(t->mval); + glVertex2fv(cent); glEnd(); glTranslatef(t->mval[0], t->mval[1], 0); @@ -1044,7 +1040,7 @@ void drawHelpline(const struct bContext *C, TransInfo *t) glTranslatef(t->mval[0], t->mval[1], 0); glLineWidth(3.0); - glBegin(GL_LINES); + glBegin(GL_LINES); drawArrow(UP, 5, 10, 5); drawArrow(DOWN, 5, 10, 5); glLineWidth(1.0); @@ -1057,27 +1053,27 @@ void drawHelpline(const struct bContext *C, TransInfo *t) float delta_angle = MIN2(15 / dist, M_PI/4); float spacing_angle = MIN2(5 / dist, M_PI/12); UI_ThemeColor(TH_WIRE); - + setlinestyle(3); - glBegin(GL_LINE_STRIP); - glVertex2sv(t->mval); - glVertex2fv(cent); + glBegin(GL_LINE_STRIP); + glVertex2sv(t->mval); + glVertex2fv(cent); glEnd(); - + glTranslatef(cent[0], cent[1], 0); - + setlinestyle(0); glLineWidth(3.0); drawArc(dist, angle - delta_angle, angle - spacing_angle, 10); drawArc(dist, angle + spacing_angle, angle + delta_angle, 10); - + glPushMatrix(); glTranslatef(cosf(angle - delta_angle) * dist, sinf(angle - delta_angle) * dist, 0); glRotatef(180 / M_PI * (angle - delta_angle), 0, 0, 1); - + drawArrowHead(DOWN, 5); - + glPopMatrix(); glTranslatef(cosf(angle + delta_angle) * dist, sinf(angle + delta_angle) * dist, 0); @@ -1092,32 +1088,32 @@ void drawHelpline(const struct bContext *C, TransInfo *t) { char col[3], col2[3]; UI_GetThemeColor3ubv(TH_GRID, col); - + glTranslatef(t->mval[0], t->mval[1], 0); - + glLineWidth(3.0); - + UI_make_axis_color(col, col2, 'x'); glColor3ubv((GLubyte *)col2); - + drawArrow(RIGHT, 5, 10, 5); drawArrow(LEFT, 5, 10, 5); - + UI_make_axis_color(col, col2, 'y'); glColor3ubv((GLubyte *)col2); - + drawArrow(UP, 5, 10, 5); drawArrow(DOWN, 5, 10, 5); glLineWidth(1.0); break; } } - + glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); - + glEnable(GL_DEPTH_TEST); } } @@ -1125,7 +1121,7 @@ void drawHelpline(const struct bContext *C, TransInfo *t) void drawTransform(const struct bContext *C, struct ARegion *ar, void *arg) { TransInfo *t = arg; - + drawConstraint(C, t); drawPropCircle(C, t); drawSnapping(C, t); @@ -1134,7 +1130,7 @@ void drawTransform(const struct bContext *C, struct ARegion *ar, void *arg) void saveTransform(bContext *C, TransInfo *t, wmOperator *op) { - Scene *sce = CTX_data_scene(C); + ToolSettings *ts = CTX_data_tool_settings(C); int constraint_axis[3] = {0, 0, 0}; int proportional = 0; @@ -1171,10 +1167,10 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op) { RNA_boolean_set(op->ptr, "mirror", t->flag & T_MIRROR); } - + if (RNA_struct_find_property(op->ptr, "constraint_axis")) { - RNA_int_set(op->ptr, "constraint_orientation", t->current_orientation); + RNA_enum_set(op->ptr, "constraint_orientation", t->current_orientation); if (t->con.mode & CON_APPLY) { @@ -1195,13 +1191,13 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op) // XXX If modal, save settings back in scene if (t->flag & T_MODAL) { - sce->prop_mode = t->prop_mode; - sce->proportional = proportional; + ts->prop_mode = t->prop_mode; + ts->proportional = proportional; if(t->spacetype == SPACE_VIEW3D) { View3D *v3d = t->view; - + v3d->twmode = t->current_orientation; } } @@ -1216,7 +1212,7 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int t->state = TRANS_RUNNING; t->options = options; - + t->mode = mode; if (!initTransInfo(C, t, op, event)) // internal data, mouse, vectors @@ -1228,7 +1224,7 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int { //calc_manipulator_stats(curarea); initTransformOrientation(C, t); - + t->draw_handle = ED_region_draw_cb_activate(t->ar->type, drawTransform, t, REGION_DRAW_POST); } else if(t->spacetype == SPACE_IMAGE) { @@ -1251,10 +1247,10 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int /* EVIL2: we gave as argument also texture space context bit... was cleared */ /* EVIL3: extend mode for animation editors also switches modes... but is best way to avoid duplicate code */ mode = t->mode; - + calculatePropRatio(t); calculateCenter(t); - + initMouseInput(t, &t->mouse, t->center2d, t->imval); switch (mode) { @@ -1318,13 +1314,13 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int case TFM_TIME_SCALE: initTimeScale(t); break; - case TFM_TIME_EXTEND: + case TFM_TIME_EXTEND: /* now that transdata has been made, do like for TFM_TIME_TRANSLATE (for most Animation * Editors because they have only 1D transforms for time values) or TFM_TRANSLATION - * (for Graph Editor only since it uses 'standard' transforms to get 2D movement) - * depending on which editor this was called from + * (for Graph/NLA Editors only since they uses 'standard' transforms to get 2D movement) + * depending on which editor this was called from */ - if (t->spacetype == SPACE_IPO) + if ELEM(t->spacetype, SPACE_IPO, SPACE_NLA) initTranslation(t); else initTimeTranslate(t); @@ -1376,11 +1372,11 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int if (constraint_axis[2]) { t->con.mode |= CON_AXIS2; } - - setUserConstraint(t, t->con.mode, "%s"); + + setUserConstraint(t, t->con.mode, "%s"); } } - + return 1; } @@ -1399,7 +1395,7 @@ void transformApply(bContext *C, TransInfo *t) t->redraw = 0; } - /* If auto confirm is on, break after one pass */ + /* If auto confirm is on, break after one pass */ if (t->options & CTX_AUTOCONFIRM) { t->state = TRANS_CONFIRM; @@ -1416,7 +1412,7 @@ void transformApply(bContext *C, TransInfo *t) int transformEnd(bContext *C, TransInfo *t) { int exit_code = OPERATOR_RUNNING_MODAL; - + if (t->state != TRANS_RUNNING) { /* handle restoring objects */ @@ -1429,16 +1425,16 @@ int transformEnd(bContext *C, TransInfo *t) { exit_code = OPERATOR_FINISHED; } - + /* free data */ postTrans(t); - + /* aftertrans does insert keyframes, and clears base flags, doesnt read transdata */ special_aftertrans_update(t); - + /* send events out for redraws */ viewRedrawPost(t); - + /* Undo as last, certainly after special_trans_update! */ if(t->state == TRANS_CANCEL) { @@ -1452,7 +1448,7 @@ int transformEnd(bContext *C, TransInfo *t) viewRedrawForce(C, t); } - + return exit_code; } @@ -1460,13 +1456,15 @@ int transformEnd(bContext *C, TransInfo *t) void initManipulator(int mode) { + printf("init manipulator mode %d\n", mode); + #if 0 // TRANSFORM_FIX_ME Trans.state = TRANS_RUNNING; Trans.options = CTX_NONE; - + Trans.mode = mode; - + /* automatic switch to scaling bone envelopes */ if(mode==TFM_RESIZE && t->obedit && t->obedit->type==OB_ARMATURE) { bArmature *arm= t->obedit->data; @@ -1487,7 +1485,7 @@ void initManipulator(int mode) /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */ /* EVIL2: we gave as argument also texture space context bit... was cleared */ mode = Trans.mode; - + calculatePropRatio(&Trans); calculateCenter(&Trans); @@ -1510,7 +1508,7 @@ void initManipulator(int mode) #endif } -void ManipulatorTransform() +void ManipulatorTransform() { #if 0 // TRANSFORM_FIX_ME int mouse_moved = 0; @@ -1523,9 +1521,9 @@ void ManipulatorTransform() Trans.redraw = 1; /* initial draw */ while (Trans.state == TRANS_RUNNING) { - + getmouseco_areawin(mval); - + if (mval[0] != pmval[0] || mval[1] != pmval[1]) { Trans.redraw = 1; } @@ -1539,7 +1537,7 @@ void ManipulatorTransform() } Trans.redraw = 0; } - + /* essential for idling subloop */ if( qtest()==0) PIL_sleep_ms(2); @@ -1564,9 +1562,9 @@ void ManipulatorTransform() Trans.flag |= T_SHIFT_MOD; Trans.redraw = 1; } - else Trans.flag &= ~T_SHIFT_MOD; + else Trans.flag &= ~T_SHIFT_MOD; break; - + case ESCKEY: case RIGHTMOUSE: Trans.state = TRANS_CANCEL; @@ -1624,23 +1622,23 @@ void ManipulatorTransform() Trans.redraw= 1; break; } - + // Numerical input events Trans.redraw |= handleNumInput(&(Trans.num), event); } } } - + if(Trans.state == TRANS_CANCEL) { restoreTransObjects(&Trans); } - + /* free data, reset vars */ postTrans(&Trans); - + /* aftertrans does insert ipos and action channels, and clears base flags */ special_aftertrans_update(&Trans); - + /* send events out for redraws */ viewRedrawPost(&Trans); @@ -1686,21 +1684,21 @@ static void protectedQuaternionBits(short protectflag, float *quat, float *oldqu { /* quaternions get limited with euler... */ /* this function only does the delta rotation */ - + if(protectflag) { float eul[3], oldeul[3], quat1[4]; - + QUATCOPY(quat1, quat); QuatToEul(quat, eul); QuatToEul(oldquat, oldeul); - + if(protectflag & OB_LOCK_ROTX) eul[0]= oldeul[0]; if(protectflag & OB_LOCK_ROTY) eul[1]= oldeul[1]; if(protectflag & OB_LOCK_ROTZ) eul[2]= oldeul[2]; - + EulToQuat(eul, quat); /* quaternions flip w sign to accumulate rotations correctly */ if( (quat1[0]<0.0f && quat[0]>0.0f) || (quat1[0]>0.0f && quat[0]<0.0f) ) { @@ -1717,8 +1715,8 @@ static void constraintTransLim(TransInfo *t, TransData *td) bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT); bConstraintOb cob; bConstraint *con; - - /* Make a temporary bConstraintOb for using these limit constraints + + /* Make a temporary bConstraintOb for using these limit constraints * - they only care that cob->matrix is correctly set ;-) * - current space should be local */ @@ -1733,22 +1731,22 @@ static void constraintTransLim(TransInfo *t, TransData *td) else { VECCOPY(cob.matrix[3], td->loc); } - + /* Evaluate valid constraints */ for (con= td->con; con; con= con->next) { float tmat[4][4]; - + /* only consider constraint if enabled */ if (con->flag & CONSTRAINT_DISABLE) continue; if (con->enforce == 0.0f) continue; - + /* only use it if it's tagged for this purpose (and the right type) */ if (con->type == CONSTRAINT_TYPE_LOCLIMIT) { bLocLimitConstraint *data= con->data; - - if ((data->flag2 & LIMIT_TRANSFORM)==0) + + if ((data->flag2 & LIMIT_TRANSFORM)==0) continue; - + /* do space conversions */ if (con->ownspace == CONSTRAINT_SPACE_WORLD) { /* just multiply by td->mtx (this should be ok) */ @@ -1759,10 +1757,10 @@ static void constraintTransLim(TransInfo *t, TransData *td) /* skip... incompatable spacetype */ continue; } - + /* do constraint */ cti->evaluate_constraint(con, &cob, NULL); - + /* convert spaces again */ if (con->ownspace == CONSTRAINT_SPACE_WORLD) { /* just multiply by td->mtx (this should be ok) */ @@ -1771,7 +1769,7 @@ static void constraintTransLim(TransInfo *t, TransData *td) } } } - + /* copy results from cob->matrix */ if (td->tdi) { TransDataIpokey *tdi= td->tdi; @@ -1791,8 +1789,8 @@ static void constraintRotLim(TransInfo *t, TransData *td) bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_ROTLIMIT); bConstraintOb cob; bConstraint *con; - - /* Make a temporary bConstraintOb for using these limit constraints + + /* Make a temporary bConstraintOb for using these limit constraints * - they only care that cob->matrix is correctly set ;-) * - current space should be local */ @@ -1808,11 +1806,11 @@ static void constraintRotLim(TransInfo *t, TransData *td) /* ipo-keys eulers */ TransDataIpokey *tdi= td->tdi; float eul[3]; - + eul[0]= tdi->rotx[0]; eul[1]= tdi->roty[0]; eul[2]= tdi->rotz[0]; - + EulToMat4(eul, cob.matrix); } else { @@ -1822,22 +1820,22 @@ static void constraintRotLim(TransInfo *t, TransData *td) else return; } - + /* Evaluate valid constraints */ for (con= td->con; con; con= con->next) { /* only consider constraint if enabled */ if (con->flag & CONSTRAINT_DISABLE) continue; if (con->enforce == 0.0f) continue; - + /* we're only interested in Limit-Rotation constraints */ if (con->type == CONSTRAINT_TYPE_ROTLIMIT) { bRotLimitConstraint *data= con->data; float tmat[4][4]; - + /* only use it if it's tagged for this purpose */ - if ((data->flag2 & LIMIT_TRANSFORM)==0) + if ((data->flag2 & LIMIT_TRANSFORM)==0) continue; - + /* do space conversions */ if (con->ownspace == CONSTRAINT_SPACE_WORLD) { /* just multiply by td->mtx (this should be ok) */ @@ -1848,10 +1846,10 @@ static void constraintRotLim(TransInfo *t, TransData *td) /* skip... incompatable spacetype */ continue; } - + /* do constraint */ cti->evaluate_constraint(con, &cob, NULL); - + /* convert spaces again */ if (con->ownspace == CONSTRAINT_SPACE_WORLD) { /* just multiply by td->mtx (this should be ok) */ @@ -1860,7 +1858,7 @@ static void constraintRotLim(TransInfo *t, TransData *td) } } } - + /* copy results from cob->matrix */ if (td->flag & TD_USEQUAT) { /* quats */ @@ -1870,9 +1868,9 @@ static void constraintRotLim(TransInfo *t, TransData *td) /* ipo-keys eulers */ TransDataIpokey *tdi= td->tdi; float eul[3]; - + Mat4ToEul(cob.matrix, eul); - + tdi->rotx[0]= eul[0]; tdi->roty[0]= eul[1]; tdi->rotz[0]= eul[2]; @@ -1890,8 +1888,8 @@ static void constraintSizeLim(TransInfo *t, TransData *td) bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_SIZELIMIT); bConstraintOb cob; bConstraint *con; - - /* Make a temporary bConstraintOb for using these limit constraints + + /* Make a temporary bConstraintOb for using these limit constraints * - they only care that cob->matrix is correctly set ;-) * - current space should be local */ @@ -1899,12 +1897,12 @@ static void constraintSizeLim(TransInfo *t, TransData *td) if (td->tdi) { TransDataIpokey *tdi= td->tdi; float size[3]; - + size[0]= tdi->sizex[0]; size[1]= tdi->sizey[0]; size[2]= tdi->sizez[0]; SizeToMat4(size, cob.matrix); - } + } else if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) { /* scale val and reset size */ return; // TODO: fix this case @@ -1913,25 +1911,25 @@ static void constraintSizeLim(TransInfo *t, TransData *td) /* Reset val if SINGLESIZE but using a constraint */ if (td->flag & TD_SINGLESIZE) return; - + SizeToMat4(td->ext->size, cob.matrix); } - + /* Evaluate valid constraints */ for (con= td->con; con; con= con->next) { /* only consider constraint if enabled */ if (con->flag & CONSTRAINT_DISABLE) continue; if (con->enforce == 0.0f) continue; - + /* we're only interested in Limit-Scale constraints */ if (con->type == CONSTRAINT_TYPE_SIZELIMIT) { bSizeLimitConstraint *data= con->data; float tmat[4][4]; - + /* only use it if it's tagged for this purpose */ - if ((data->flag2 & LIMIT_TRANSFORM)==0) + if ((data->flag2 & LIMIT_TRANSFORM)==0) continue; - + /* do space conversions */ if (con->ownspace == CONSTRAINT_SPACE_WORLD) { /* just multiply by td->mtx (this should be ok) */ @@ -1942,10 +1940,10 @@ static void constraintSizeLim(TransInfo *t, TransData *td) /* skip... incompatable spacetype */ continue; } - + /* do constraint */ cti->evaluate_constraint(con, &cob, NULL); - + /* convert spaces again */ if (con->ownspace == CONSTRAINT_SPACE_WORLD) { /* just multiply by td->mtx (this should be ok) */ @@ -1954,18 +1952,18 @@ static void constraintSizeLim(TransInfo *t, TransData *td) } } } - + /* copy results from cob->matrix */ if (td->tdi) { TransDataIpokey *tdi= td->tdi; float size[3]; - + Mat4ToSize(cob.matrix, size); - + tdi->sizex[0]= size[0]; tdi->sizey[0]= size[1]; tdi->sizez[0]= size[2]; - } + } else if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) { /* scale val and reset size */ return; // TODO: fix this case @@ -1974,7 +1972,7 @@ static void constraintSizeLim(TransInfo *t, TransData *td) /* Reset val if SINGLESIZE but using a constraint */ if (td->flag & TD_SINGLESIZE) return; - + Mat4ToSize(cob.matrix, td->ext->size); } } @@ -1982,15 +1980,15 @@ static void constraintSizeLim(TransInfo *t, TransData *td) /* ************************** WARP *************************** */ -void initWarp(TransInfo *t) +void initWarp(TransInfo *t) { float max[3], min[3]; int i; - + t->mode = TFM_WARP; t->transform = Warp; t->handleEvent = handleEventWarp; - + initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO); t->idx_max = 0; @@ -1998,9 +1996,9 @@ void initWarp(TransInfo *t) t->snap[0] = 0.0f; t->snap[1] = 5.0f; t->snap[2] = 1.0f; - + t->flag |= T_NO_CONSTRAINT; - + /* we need min/max in view space */ for(i = 0; i < t->total; i++) { float center[3]; @@ -2015,11 +2013,11 @@ void initWarp(TransInfo *t) VECCOPY(min, center); } } - + t->center[0]= (min[0]+max[0])/2.0f; t->center[1]= (min[1]+max[1])/2.0f; t->center[2]= (min[2]+max[2])/2.0f; - + if (max[0] == min[0]) max[0] += 0.1; /* not optimal, but flipping is better than invalid garbage (i.e. division by zero!) */ t->val= (max[0]-min[0])/2.0f; /* t->val is X dimension projected boundbox */ } @@ -2027,7 +2025,7 @@ void initWarp(TransInfo *t) int handleEventWarp(TransInfo *t, wmEvent *event) { int status = 0; - + if (event->type == MIDDLEMOUSE && event->val) { // Use customData pointer to signal warp direction @@ -2035,10 +2033,10 @@ int handleEventWarp(TransInfo *t, wmEvent *event) t->customData = (void*)1; else t->customData = 0; - + status = 1; } - + return status; } @@ -2048,7 +2046,7 @@ int Warp(TransInfo *t, short mval[2]) float vec[3], circumfac, dist, phi0, co, si, *curs, cursor[3], gcursor[3]; int i; char str[50]; - + curs= give_cursor(t->scene, t->view); /* * gcursor is the one used for helpline. @@ -2061,7 +2059,7 @@ int Warp(TransInfo *t, short mval[2]) * into account if in Edit mode. */ VECCOPY(cursor, curs); - VECCOPY(gcursor, cursor); + VECCOPY(gcursor, cursor); if (t->flag & T_EDIT) { VecSubf(cursor, cursor, t->obedit->obmat[3]); VecSubf(gcursor, gcursor, t->obedit->obmat[3]); @@ -2072,7 +2070,7 @@ int Warp(TransInfo *t, short mval[2]) /* amount of degrees for warp */ circumfac = 360.0f * t->values[0]; - + if (t->customData) /* non-null value indicates reversed input */ { circumfac *= -1; @@ -2080,22 +2078,22 @@ int Warp(TransInfo *t, short mval[2]) snapGrid(t, &circumfac); applyNumInput(&t->num, &circumfac); - + /* header print for NumInput */ if (hasNumInput(&t->num)) { char c[20]; - + outputNumInput(&(t->num), c); - + sprintf(str, "Warp: %s", c); } else { /* default header print */ sprintf(str, "Warp: %.3f", circumfac); } - + circumfac*= (float)(-M_PI/360.0); - + for(i = 0; i < t->total; i++, td++) { float loc[3]; if (td->flag & TD_NOACTION) @@ -2103,65 +2101,65 @@ int Warp(TransInfo *t, short mval[2]) if (td->flag & TD_SKIP) continue; - + /* translate point to center, rotate in such a way that outline==distance */ VECCOPY(vec, td->iloc); Mat3MulVecfl(td->mtx, vec); Mat4MulVecfl(t->viewmat, vec); VecSubf(vec, vec, t->viewmat[3]); - + dist= vec[0]-cursor[0]; - + /* t->val is X dimension projected boundbox */ - phi0= (circumfac*dist/t->val); - + phi0= (circumfac*dist/t->val); + vec[1]= (vec[1]-cursor[1]); - + co= (float)cos(phi0); si= (float)sin(phi0); loc[0]= -si*vec[1]+cursor[0]; loc[1]= co*vec[1]+cursor[1]; loc[2]= vec[2]; - + Mat4MulVecfl(t->viewinv, loc); VecSubf(loc, loc, t->viewinv[3]); Mat3MulVecfl(td->smtx, loc); - + VecSubf(loc, loc, td->iloc); VecMulf(loc, td->factor); VecAddf(td->loc, td->iloc, loc); } recalcData(t); - + ED_area_headerprint(t->sa, str); - + return 1; } /* ************************** SHEAR *************************** */ -void initShear(TransInfo *t) +void initShear(TransInfo *t) { t->mode = TFM_SHEAR; t->transform = Shear; t->handleEvent = handleEventShear; - + initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE); - + t->idx_max = 0; t->num.idx_max = 0; t->snap[0] = 0.0f; t->snap[1] = 0.1f; t->snap[2] = t->snap[1] * 0.1f; - + t->flag |= T_NO_CONSTRAINT; } int handleEventShear(TransInfo *t, wmEvent *event) { int status = 0; - + if (event->type == MIDDLEMOUSE && event->val) { // Use customData pointer to signal Shear direction @@ -2175,15 +2173,15 @@ int handleEventShear(TransInfo *t, wmEvent *event) initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE); t->customData = 0; } - + status = 1; } - + return status; } -int Shear(TransInfo *t, short mval[2]) +int Shear(TransInfo *t, short mval[2]) { TransData *td = t->data; float vec[3]; @@ -2213,18 +2211,18 @@ int Shear(TransInfo *t, short mval[2]) /* default header print */ sprintf(str, "Shear: %.3f %s", value, t->proptext); } - + Mat3One(smat); - + // Custom data signals shear direction if (t->customData == 0) smat[1][0] = value; else smat[0][1] = value; - + Mat3MulMat3(tmat, smat, persmat); Mat3MulMat3(totmat, persinv, tmat); - + for(i = 0 ; i < t->total; i++, td++) { if (td->flag & TD_NOACTION) break; @@ -2261,13 +2259,13 @@ int Shear(TransInfo *t, short mval[2]) /* ************************** RESIZE *************************** */ -void initResize(TransInfo *t) +void initResize(TransInfo *t) { t->mode = TFM_RESIZE; t->transform = Resize; - + initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP); - + t->flag |= T_NULL_ONE; t->num.flag |= NUM_NULL_ONE; t->num.flag |= NUM_AFFECT_ALL; @@ -2275,7 +2273,7 @@ void initResize(TransInfo *t) t->flag |= T_NO_ZERO; t->num.flag |= NUM_NO_ZERO; } - + t->idx_max = 2; t->num.idx_max = 2; t->snap[0] = 0.0f; @@ -2321,18 +2319,18 @@ static void headerResize(TransInfo *t, float vec[3], char *str) { static void TransMat3ToSize( float mat[][3], float smat[][3], float *size) { float vec[3]; - + VecCopyf(vec, mat[0]); size[0]= Normalize(vec); VecCopyf(vec, mat[1]); size[1]= Normalize(vec); VecCopyf(vec, mat[2]); size[2]= Normalize(vec); - + /* first tried with dotproduct... but the sign flip is crucial */ - if( VECSIGNFLIP(mat[0], smat[0]) ) size[0]= -size[0]; - if( VECSIGNFLIP(mat[1], smat[1]) ) size[1]= -size[1]; - if( VECSIGNFLIP(mat[2], smat[2]) ) size[2]= -size[2]; + if( VECSIGNFLIP(mat[0], smat[0]) ) size[0]= -size[0]; + if( VECSIGNFLIP(mat[1], smat[1]) ) size[1]= -size[1]; + if( VECSIGNFLIP(mat[2], smat[2]) ) size[2]= -size[2]; } @@ -2358,8 +2356,8 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) { VECCOPY(center, td->center); } else if (t->flag & T_EDIT) { - - if(t->around==V3D_LOCAL && (t->scene->selectmode & SCE_SELECT_FACE)) { + + if(t->around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) { VECCOPY(center, td->center); } else { @@ -2376,7 +2374,7 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) { if (td->ext) { float fsize[3]; - + if (t->flag & (T_OBJECT|T_TEXTURE|T_POSE)) { float obsizemat[3][3]; // Reorient the size mat to fit the oriented object. @@ -2388,28 +2386,28 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) { else { Mat3ToSize(tmat, fsize); } - + protectedSizeBits(td->protectflag, fsize); - + if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't resize objects itself /* handle ipokeys? */ if(td->tdi) { TransDataIpokey *tdi= td->tdi; /* calculate delta size (equal for size and dsize) */ - + vec[0]= (tdi->oldsize[0])*(fsize[0] -1.0f) * td->factor; vec[1]= (tdi->oldsize[1])*(fsize[1] -1.0f) * td->factor; vec[2]= (tdi->oldsize[2])*(fsize[2] -1.0f) * td->factor; - + add_tdi_poin(tdi->sizex, tdi->oldsize, vec[0]); add_tdi_poin(tdi->sizey, tdi->oldsize+1, vec[1]); add_tdi_poin(tdi->sizez, tdi->oldsize+2, vec[2]); - - } + + } else if((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)){ /* scale val and reset size */ *td->val = td->ival * fsize[0] * td->factor; - + td->ext->size[0] = td->ext->isize[0]; td->ext->size[1] = td->ext->isize[1]; td->ext->size[2] = td->ext->isize[2]; @@ -2418,16 +2416,16 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) { /* Reset val if SINGLESIZE but using a constraint */ if (td->flag & TD_SINGLESIZE) *td->val = td->ival; - + td->ext->size[0] = td->ext->isize[0] * (fsize[0]) * td->factor; td->ext->size[1] = td->ext->isize[1] * (fsize[1]) * td->factor; td->ext->size[2] = td->ext->isize[2] * (fsize[2]) * td->factor; } } - + constraintSizeLim(t, td); } - + /* For individual element center, Editmode need to use iloc */ if (t->flag & T_POINTS) VecSubf(vec, td->iloc, center); @@ -2457,11 +2455,11 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) { add_tdi_poin(tdi->locz, tdi->oldloc+2, vec[2]); } else VecAddf(td->loc, td->iloc, vec); - + constraintTransLim(t, td); } -int Resize(TransInfo *t, short mval[2]) +int Resize(TransInfo *t, short mval[2]) { TransData *td; float size[3], mat[3][3]; @@ -2478,7 +2476,7 @@ int Resize(TransInfo *t, short mval[2]) { ratio = t->values[0]; } - + size[0] = size[1] = size[2] = ratio; snapGrid(t, size); @@ -2504,7 +2502,7 @@ int Resize(TransInfo *t, short mval[2]) } Mat3CpyMat3(t->mat, mat); // used in manipulator - + headerResize(t, size, str); for(i = 0, td=t->data; i < t->total; i++, td++) { @@ -2513,7 +2511,7 @@ int Resize(TransInfo *t, short mval[2]) if (td->flag & TD_SKIP) continue; - + ElementResize(t, td, mat); } @@ -2537,14 +2535,14 @@ int Resize(TransInfo *t, short mval[2]) /* ************************** TOSPHERE *************************** */ -void initToSphere(TransInfo *t) +void initToSphere(TransInfo *t) { TransData *td = t->data; int i; t->mode = TFM_TOSPHERE; t->transform = ToSphere; - + initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO); t->idx_max = 0; @@ -2552,10 +2550,10 @@ void initToSphere(TransInfo *t) t->snap[0] = 0.0f; t->snap[1] = 0.1f; t->snap[2] = t->snap[1] * 0.1f; - + t->num.flag |= NUM_NULL_ONE | NUM_NO_NEGATIVE; t->flag |= T_NO_CONSTRAINT; - + // Calculate average radius for(i = 0 ; i < t->total; i++, td++) { t->val += VecLenf(t->center, td->iloc); @@ -2564,7 +2562,7 @@ void initToSphere(TransInfo *t) t->val /= (float)t->total; } -int ToSphere(TransInfo *t, short mval[2]) +int ToSphere(TransInfo *t, short mval[2]) { float vec[3]; float ratio, radius; @@ -2595,8 +2593,8 @@ int ToSphere(TransInfo *t, short mval[2]) /* default header print */ sprintf(str, "To Sphere: %.4f %s", ratio, t->proptext); } - - + + for(i = 0 ; i < t->total; i++, td++) { float tratio; if (td->flag & TD_NOACTION) @@ -2615,7 +2613,7 @@ int ToSphere(TransInfo *t, short mval[2]) VecAddf(td->loc, t->center, vec); } - + recalcData(t); @@ -2627,23 +2625,23 @@ int ToSphere(TransInfo *t, short mval[2]) /* ************************** ROTATION *************************** */ -void initRotation(TransInfo *t) +void initRotation(TransInfo *t) { t->mode = TFM_ROTATION; t->transform = Rotation; - + initMouseInputMode(t, &t->mouse, INPUT_ANGLE); - + t->ndof.axis = 16; /* Scale down and flip input for rotation */ t->ndof.factor[0] = -0.2f; - + t->idx_max = 0; t->num.idx_max = 0; t->snap[0] = 0.0f; t->snap[1] = (float)((5.0/180)*M_PI); t->snap[2] = t->snap[1] * 0.2f; - + if (t->flag & T_2D_EDIT) t->flag |= T_NO_CONSTRAINT; } @@ -2652,7 +2650,7 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short float vec[3], totmat[3][3], smat[3][3]; float eul[3], fmat[3][3], quat[4]; float *center = t->center; - + /* local constraint shouldn't alter center */ if (around == V3D_LOCAL) { if (t->flag & (T_OBJECT|T_POSE)) { @@ -2660,19 +2658,19 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short } else { /* !TODO! Make this if not rely on G */ - if(around==V3D_LOCAL && (t->scene->selectmode & SCE_SELECT_FACE)) { + if(around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) { center = td->center; } } } - + if (t->flag & T_POINTS) { Mat3MulMat3(totmat, mat, td->mtx); Mat3MulMat3(smat, td->smtx, totmat); - + VecSubf(vec, td->iloc, center); Mat3MulVecfl(smat, vec); - + VecAddf(td->loc, vec, center); VecSubf(vec,td->loc,td->iloc); @@ -2682,10 +2680,10 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short if(td->flag & TD_USEQUAT) { Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0); Mat3ToQuat(fmat, quat); // Actual transform - + if(td->ext->quat){ QuatMul(td->ext->quat, quat, td->ext->iquat); - + /* is there a reason not to have this here? -jahka */ protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat); } @@ -2693,11 +2691,11 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short } /** * HACK WARNING - * + * * This is some VERY ugly special case to deal with pose mode. - * + * * The problem is that mtx and smtx include each bone orientation. - * + * * That is needed to rotate each bone properly, HOWEVER, to calculate * the translation component, we only need the actual armature object's * matrix (and inverse). That is not all though. Once the proper translation @@ -2706,65 +2704,65 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short else if (t->flag & T_POSE) { float pmtx[3][3], imtx[3][3]; - // Extract and invert armature object matrix + // Extract and invert armature object matrix Mat3CpyMat4(pmtx, t->poseobj->obmat); Mat3Inv(imtx, pmtx); - + if ((td->flag & TD_NO_LOC) == 0) { VecSubf(vec, td->center, center); - + Mat3MulVecfl(pmtx, vec); // To Global space Mat3MulVecfl(mat, vec); // Applying rotation Mat3MulVecfl(imtx, vec); // To Local space - + VecAddf(vec, vec, center); /* vec now is the location where the object has to be */ - + VecSubf(vec, vec, td->center); // Translation needed from the initial location - + Mat3MulVecfl(pmtx, vec); // To Global space Mat3MulVecfl(td->smtx, vec);// To Pose space - + protectedTransBits(td->protectflag, vec); - + VecAddf(td->loc, td->iloc, vec); - + constraintTransLim(t, td); } - + /* rotation */ if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself /* euler or quaternion? */ if (td->flag & TD_USEQUAT) { Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0); - + Mat3ToQuat(fmat, quat); // Actual transform - + QuatMul(td->ext->quat, quat, td->ext->iquat); /* this function works on end result */ protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat); } else { float eulmat[3][3]; - + Mat3MulMat3(totmat, mat, td->mtx); Mat3MulMat3(smat, td->smtx, totmat); - + /* calculate the total rotatation in eulers */ VECCOPY(eul, td->ext->irot); EulToMat3(eul, eulmat); - + /* mat = transform, obmat = bone rotation */ Mat3MulMat3(fmat, smat, eulmat); - + Mat3ToCompatibleEul(fmat, eul, td->ext->rot); - + /* and apply (to end result only) */ protectedRotateBits(td->protectflag, eul, td->ext->irot); VECCOPY(td->ext->rot, eul); } - + constraintRotLim(t, td); } } @@ -2778,9 +2776,9 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short /* vec now is the location where the object has to be */ VecSubf(vec, vec, td->center); Mat3MulVecfl(td->smtx, vec); - + protectedTransBits(td->protectflag, vec); - + if(td->tdi) { TransDataIpokey *tdi= td->tdi; add_tdi_poin(tdi->locx, tdi->oldloc, vec[0]); @@ -2789,8 +2787,8 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short } else VecAddf(td->loc, td->iloc, vec); } - - + + constraintTransLim(t, td); /* rotation */ @@ -2799,34 +2797,34 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short if (td->flag & TD_USEQUAT) { Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0); Mat3ToQuat(fmat, quat); // Actual transform - + QuatMul(td->ext->quat, quat, td->ext->iquat); /* this function works on end result */ protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat); } else { float obmat[3][3]; - + /* are there ipo keys? */ if(td->tdi) { TransDataIpokey *tdi= td->tdi; float current_rot[3]; float rot[3]; - + /* current IPO value for compatible euler */ current_rot[0] = (tdi->rotx) ? tdi->rotx[0] : 0.0f; current_rot[1] = (tdi->roty) ? tdi->roty[0] : 0.0f; current_rot[2] = (tdi->rotz) ? tdi->rotz[0] : 0.0f; VecMulf(current_rot, (float)(M_PI_2 / 9.0)); - + /* calculate the total rotatation in eulers */ VecAddf(eul, td->ext->irot, td->ext->drot); EulToMat3(eul, obmat); /* mat = transform, obmat = object rotation */ Mat3MulMat3(fmat, mat, obmat); - + Mat3ToCompatibleEul(fmat, eul, current_rot); - + /* correct back for delta rot */ if(tdi->flag & TOB_IPODROT) { VecSubf(rot, eul, td->ext->irot); @@ -2834,12 +2832,12 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short else { VecSubf(rot, eul, td->ext->drot); } - + VecMulf(rot, (float)(9.0/M_PI_2)); VecSubf(rot, rot, tdi->oldrot); - + protectedRotateBits(td->protectflag, rot, tdi->oldrot); - + add_tdi_poin(tdi->rotx, tdi->oldrot, rot[0]); add_tdi_poin(tdi->roty, tdi->oldrot+1, rot[1]); add_tdi_poin(tdi->rotz, tdi->oldrot+2, rot[2]); @@ -2847,37 +2845,37 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short else { Mat3MulMat3(totmat, mat, td->mtx); Mat3MulMat3(smat, td->smtx, totmat); - + /* calculate the total rotatation in eulers */ VecAddf(eul, td->ext->irot, td->ext->drot); /* we have to correct for delta rot */ EulToMat3(eul, obmat); /* mat = transform, obmat = object rotation */ Mat3MulMat3(fmat, smat, obmat); - + Mat3ToCompatibleEul(fmat, eul, td->ext->rot); - + /* correct back for delta rot */ VecSubf(eul, eul, td->ext->drot); - + /* and apply */ protectedRotateBits(td->protectflag, eul, td->ext->irot); VECCOPY(td->ext->rot, eul); } } - + constraintRotLim(t, td); } } } -static void applyRotation(TransInfo *t, float angle, float axis[3]) +static void applyRotation(TransInfo *t, float angle, float axis[3]) { TransData *td = t->data; float mat[3][3]; int i; VecRotToMat3(axis, angle, mat); - + for(i = 0 ; i < t->total; i++, td++) { if (td->flag & TD_NOACTION) @@ -2885,7 +2883,7 @@ static void applyRotation(TransInfo *t, float angle, float axis[3]) if (td->flag & TD_SKIP) continue; - + if (t->con.applyRot) { t->con.applyRot(t, td, axis, NULL); VecRotToMat3(axis, angle * td->factor, mat); @@ -2898,7 +2896,7 @@ static void applyRotation(TransInfo *t, float angle, float axis[3]) } } -int Rotation(TransInfo *t, short mval[2]) +int Rotation(TransInfo *t, short mval[2]) { char str[64]; @@ -2914,13 +2912,13 @@ int Rotation(TransInfo *t, short mval[2]) final = t->values[0]; applyNDofInput(&t->ndof, &final); - + snapGrid(t, &final); if (t->con.applyRot) { t->con.applyRot(t, NULL, axis, &final); } - + applySnapping(t, &final); if (hasNumInput(&t->num)) { @@ -2935,7 +2933,7 @@ int Rotation(TransInfo *t, short mval[2]) /* Clamp between -180 and 180 */ while (final >= 180.0) final -= 360.0; - + while (final <= -180.0) final += 360.0; @@ -2950,9 +2948,9 @@ int Rotation(TransInfo *t, short mval[2]) // TRANSFORM_FIX_ME // t->values[0] = final; // used in manipulator // Mat3CpyMat3(t->mat, mat); // used in manipulator - + applyRotation(t, final, axis); - + recalcData(t); ED_area_headerprint(t->sa, str); @@ -2963,13 +2961,13 @@ int Rotation(TransInfo *t, short mval[2]) /* ************************** TRACKBALL *************************** */ -void initTrackball(TransInfo *t) +void initTrackball(TransInfo *t) { t->mode = TFM_TRACKBALL; t->transform = Trackball; - + initMouseInputMode(t, &t->mouse, INPUT_TRACKBALL); - + t->ndof.axis = 40; /* Scale down input for rotation */ t->ndof.factor[0] = 0.2f; @@ -2980,7 +2978,7 @@ void initTrackball(TransInfo *t) t->snap[0] = 0.0f; t->snap[1] = (float)((5.0/180)*M_PI); t->snap[2] = t->snap[1] * 0.2f; - + t->flag |= T_NO_CONSTRAINT; } @@ -2992,7 +2990,7 @@ static void applyTrackball(TransInfo *t, float axis1[3], float axis2[3], float a VecRotToMat3(axis1, angles[0], smat); VecRotToMat3(axis2, angles[1], totmat); - + Mat3MulMat3(mat, smat, totmat); for(i = 0 ; i < t->total; i++, td++) { @@ -3001,46 +2999,46 @@ static void applyTrackball(TransInfo *t, float axis1[3], float axis2[3], float a if (td->flag & TD_SKIP) continue; - + if (t->flag & T_PROP_EDIT) { VecRotToMat3(axis1, td->factor * angles[0], smat); VecRotToMat3(axis2, td->factor * angles[1], totmat); - + Mat3MulMat3(mat, smat, totmat); } - + ElementRotation(t, td, mat, t->around); } } -int Trackball(TransInfo *t, short mval[2]) +int Trackball(TransInfo *t, short mval[2]) { char str[128]; float axis1[3], axis2[3]; float mat[3][3], totmat[3][3], smat[3][3]; float phi[2]; - + VECCOPY(axis1, t->persinv[0]); VECCOPY(axis2, t->persinv[1]); Normalize(axis1); Normalize(axis2); - + phi[0] = t->values[0]; phi[1] = t->values[1]; - + applyNDofInput(&t->ndof, phi); - + snapGrid(t, phi); - + if (hasNumInput(&t->num)) { char c[40]; - + applyNumInput(&t->num, phi); - + outputNumInput(&(t->num), c); - + sprintf(str, "Trackball: %s %s %s", &c[0], &c[20], t->proptext); - + phi[0] *= (float)(M_PI / 180.0); phi[1] *= (float)(M_PI / 180.0); } @@ -3050,34 +3048,34 @@ int Trackball(TransInfo *t, short mval[2]) VecRotToMat3(axis1, phi[0], smat); VecRotToMat3(axis2, phi[1], totmat); - + Mat3MulMat3(mat, smat, totmat); - + // TRANSFORM_FIX_ME //Mat3CpyMat3(t->mat, mat); // used in manipulator - + applyTrackball(t, axis1, axis2, phi); - + recalcData(t); - + ED_area_headerprint(t->sa, str); - + return 1; } /* ************************** TRANSLATION *************************** */ - -void initTranslation(TransInfo *t) + +void initTranslation(TransInfo *t) { t->mode = TFM_TRANSLATION; t->transform = Translation; - + initMouseInputMode(t, &t->mouse, INPUT_VECTOR); t->idx_max = (t->flag & T_2D_EDIT)? 1: 2; t->num.flag = 0; t->num.idx_max = t->idx_max; - + t->ndof.axis = (t->flag & T_2D_EDIT)? 1|2: 1|2|4; if(t->spacetype == SPACE_VIEW3D) { @@ -3103,7 +3101,7 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str) { char distvec[20]; char autoik[20]; float dist; - + if (hasNumInput(&t->num)) { outputNumInput(&(t->num), tvec); dist = VecLength(t->num.val); @@ -3124,10 +3122,10 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str) { sprintf(distvec, "%.4e", dist); else sprintf(distvec, "%.4f", dist); - + if(t->flag & T_AUTOIK) { - short chainlen= t->scene->toolsettings->autoik_chainlen; - + short chainlen= t->settings->autoik_chainlen; + if(chainlen) sprintf(autoik, "AutoIK-Len: %d", chainlen); else @@ -3164,10 +3162,10 @@ static void applyTranslation(TransInfo *t, float vec[3]) { for(i = 0 ; i < t->total; i++, td++) { if (td->flag & TD_NOACTION) break; - + if (td->flag & TD_SKIP) continue; - + /* handle snapping rotation before doing the translation */ if (usingSnappingNormal(t)) { @@ -3178,22 +3176,22 @@ static void applyTranslation(TransInfo *t, float vec[3]) { float quat[4]; float mat[3][3]; float angle; - + Crossf(axis, original_normal, t->tsnap.snapNormal); angle = saacos(Inpf(original_normal, t->tsnap.snapNormal)); - + AxisAngleToQuat(quat, axis, angle); - + QuatToMat3(quat, mat); - + ElementRotation(t, td, mat, V3D_LOCAL); } else { float mat[3][3]; - + Mat3One(mat); - + ElementRotation(t, td, mat, V3D_LOCAL); } } @@ -3205,12 +3203,12 @@ static void applyTranslation(TransInfo *t, float vec[3]) { else { VECCOPY(tvec, vec); } - + Mat3MulVecfl(td->smtx, tvec); VecMulf(tvec, td->factor); - + protectedTransBits(td->protectflag, tvec); - + /* transdata ipokey */ if(td->tdi) { TransDataIpokey *tdi= td->tdi; @@ -3219,17 +3217,17 @@ static void applyTranslation(TransInfo *t, float vec[3]) { add_tdi_poin(tdi->locz, tdi->oldloc+2, tvec[2]); } else VecAddf(td->loc, td->iloc, tvec); - + constraintTransLim(t, td); } } /* uses t->vec to store actual translation in */ -int Translation(TransInfo *t, short mval[2]) +int Translation(TransInfo *t, short mval[2]) { float tvec[3]; char str[250]; - + if (t->con.mode & CON_APPLY) { float pvec[3] = {0.0f, 0.0f, 0.0f}; applySnapping(t, t->values); @@ -3245,11 +3243,11 @@ int Translation(TransInfo *t, short mval[2]) { removeAspectRatio(t, t->values); } - + applySnapping(t, t->values); headerTranslation(t, t->values, str); } - + applyTranslation(t, t->values); /* evil hack - redo translation if clipping needed */ @@ -3265,7 +3263,7 @@ int Translation(TransInfo *t, short mval[2]) /* ************************** SHRINK/FATTEN *************************** */ -void initShrinkFatten(TransInfo *t) +void initShrinkFatten(TransInfo *t) { // If not in mesh edit mode, fallback to Resize if (t->obedit==NULL || t->obedit->type != OB_MESH) { @@ -3274,22 +3272,22 @@ void initShrinkFatten(TransInfo *t) else { t->mode = TFM_SHRINKFATTEN; t->transform = ShrinkFatten; - + initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE); - + t->idx_max = 0; t->num.idx_max = 0; t->snap[0] = 0.0f; t->snap[1] = 1.0f; t->snap[2] = t->snap[1] * 0.1f; - + t->flag |= T_NO_CONSTRAINT; } } -int ShrinkFatten(TransInfo *t, short mval[2]) +int ShrinkFatten(TransInfo *t, short mval[2]) { float vec[3]; float distance; @@ -3315,8 +3313,8 @@ int ShrinkFatten(TransInfo *t, short mval[2]) /* default header print */ sprintf(str, "Shrink/Fatten: %.4f %s", distance, t->proptext); } - - + + for(i = 0 ; i < t->total; i++, td++) { if (td->flag & TD_NOACTION) break; @@ -3340,11 +3338,11 @@ int ShrinkFatten(TransInfo *t, short mval[2]) /* ************************** TILT *************************** */ -void initTilt(TransInfo *t) +void initTilt(TransInfo *t) { t->mode = TFM_TILT; t->transform = Tilt; - + initMouseInputMode(t, &t->mouse, INPUT_ANGLE); t->ndof.axis = 16; @@ -3356,13 +3354,13 @@ void initTilt(TransInfo *t) t->snap[0] = 0.0f; t->snap[1] = (float)((5.0/180)*M_PI); t->snap[2] = t->snap[1] * 0.2f; - + t->flag |= T_NO_CONSTRAINT; } -int Tilt(TransInfo *t, short mval[2]) +int Tilt(TransInfo *t, short mval[2]) { TransData *td = t->data; int i; @@ -3371,7 +3369,7 @@ int Tilt(TransInfo *t, short mval[2]) float final; final = t->values[0]; - + applyNDofInput(&t->ndof, &final); snapGrid(t, &final); @@ -3417,72 +3415,72 @@ void initCurveShrinkFatten(TransInfo *t) { t->mode = TFM_CURVE_SHRINKFATTEN; t->transform = CurveShrinkFatten; - + initMouseInputMode(t, &t->mouse, INPUT_SPRING); - + t->idx_max = 0; t->num.idx_max = 0; t->snap[0] = 0.0f; t->snap[1] = 0.1f; t->snap[2] = t->snap[1] * 0.1f; - + t->flag |= T_NO_CONSTRAINT; } -int CurveShrinkFatten(TransInfo *t, short mval[2]) +int CurveShrinkFatten(TransInfo *t, short mval[2]) { TransData *td = t->data; float ratio; int i; char str[50]; - + ratio = t->values[0]; - + snapGrid(t, &ratio); - + applyNumInput(&t->num, &ratio); - + /* header print for NumInput */ if (hasNumInput(&t->num)) { char c[20]; - + outputNumInput(&(t->num), c); sprintf(str, "Shrink/Fatten: %s", c); } else { sprintf(str, "Shrink/Fatten: %3f", ratio); } - + for(i = 0 ; i < t->total; i++, td++) { if (td->flag & TD_NOACTION) break; if (td->flag & TD_SKIP) continue; - + if(td->val) { //*td->val= ratio; *td->val= td->ival*ratio; if (*td->val <= 0.0f) *td->val = 0.0001f; } } - + recalcData(t); - + ED_area_headerprint(t->sa, str); - + return 1; } /* ************************** PUSH/PULL *************************** */ -void initPushPull(TransInfo *t) +void initPushPull(TransInfo *t) { t->mode = TFM_PUSHPULL; t->transform = PushPull; - + initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE); - + t->ndof.axis = 4; /* Flip direction */ t->ndof.factor[0] = -1.0f; @@ -3495,7 +3493,7 @@ void initPushPull(TransInfo *t) } -int PushPull(TransInfo *t, short mval[2]) +int PushPull(TransInfo *t, short mval[2]) { float vec[3], axis[3]; float distance; @@ -3504,7 +3502,7 @@ int PushPull(TransInfo *t, short mval[2]) TransData *td = t->data; distance = t->values[0]; - + applyNDofInput(&t->ndof, &distance); snapGrid(t, &distance); @@ -3523,11 +3521,11 @@ int PushPull(TransInfo *t, short mval[2]) /* default header print */ sprintf(str, "Push/Pull: %.4f%s %s", distance, t->con.text, t->proptext); } - + if (t->con.applyRot && t->con.mode & CON_APPLY) { t->con.applyRot(t, NULL, axis, NULL); } - + for(i = 0 ; i < t->total; i++, td++) { if (td->flag & TD_NOACTION) break; @@ -3563,11 +3561,11 @@ int PushPull(TransInfo *t, short mval[2]) /* ************************** BEVEL **************************** */ -void initBevel(TransInfo *t) +void initBevel(TransInfo *t) { t->transform = Bevel; t->handleEvent = handleEventBevel; - + initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE); t->mode = TFM_BEVEL; @@ -3636,7 +3634,7 @@ int Bevel(TransInfo *t, short mval[2]) mode = (G.editBMesh->options & BME_BEVEL_VERT) ? "verts only" : "normal"; distance = t->values[0] / 4; /* 4 just seemed a nice value to me, nothing special */ - + distance = fabs(distance); snapGrid(t, &distance); @@ -3655,7 +3653,7 @@ int Bevel(TransInfo *t, short mval[2]) /* default header print */ sprintf(str, "Bevel - Dist: %.4f, Mode: %s (MMB to toggle))", distance, mode); } - + if (distance < 0) distance = -distance; for(i = 0 ; i < t->total; i++, td++) { if (td->axismtx[1][0] > 0 && distance > td->axismtx[1][0]) { @@ -3676,23 +3674,23 @@ int Bevel(TransInfo *t, short mval[2]) /* ************************** BEVEL WEIGHT *************************** */ -void initBevelWeight(TransInfo *t) +void initBevelWeight(TransInfo *t) { t->mode = TFM_BWEIGHT; t->transform = BevelWeight; - + initMouseInputMode(t, &t->mouse, INPUT_SPRING); - + t->idx_max = 0; t->num.idx_max = 0; t->snap[0] = 0.0f; t->snap[1] = 0.1f; t->snap[2] = t->snap[1] * 0.1f; - + t->flag |= T_NO_CONSTRAINT; } -int BevelWeight(TransInfo *t, short mval[2]) +int BevelWeight(TransInfo *t, short mval[2]) { TransData *td = t->data; float weight; @@ -3726,7 +3724,7 @@ int BevelWeight(TransInfo *t, short mval[2]) else sprintf(str, "Bevel Weight: %.3f %s", weight, t->proptext); } - + for(i = 0 ; i < t->total; i++, td++) { if (td->flag & TD_NOACTION) break; @@ -3747,23 +3745,23 @@ int BevelWeight(TransInfo *t, short mval[2]) /* ************************** CREASE *************************** */ -void initCrease(TransInfo *t) +void initCrease(TransInfo *t) { t->mode = TFM_CREASE; t->transform = Crease; - + initMouseInputMode(t, &t->mouse, INPUT_SPRING); - + t->idx_max = 0; t->num.idx_max = 0; t->snap[0] = 0.0f; t->snap[1] = 0.1f; t->snap[2] = t->snap[1] * 0.1f; - + t->flag |= T_NO_CONSTRAINT; } -int Crease(TransInfo *t, short mval[2]) +int Crease(TransInfo *t, short mval[2]) { TransData *td = t->data; float crease; @@ -3797,7 +3795,7 @@ int Crease(TransInfo *t, short mval[2]) else sprintf(str, "Crease: %.3f %s", crease, t->proptext); } - + for(i = 0 ; i < t->total; i++, td++) { if (td->flag & TD_NOACTION) break; @@ -3825,9 +3823,9 @@ void initBoneSize(TransInfo *t) { t->mode = TFM_BONESIZE; t->transform = BoneSize; - + initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP); - + t->idx_max = 2; t->num.idx_max = 2; t->num.flag |= NUM_NULL_ONE; @@ -3851,7 +3849,7 @@ static void headerBoneSize(TransInfo *t, float vec[3], char *str) { if (t->con.mode & CON_APPLY) { if (t->num.idx_max == 0) sprintf(str, "ScaleB: %s%s %s", &tvec[0], t->con.text, t->proptext); - else + else sprintf(str, "ScaleB: %s : %s : %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext); } else { @@ -3859,18 +3857,18 @@ static void headerBoneSize(TransInfo *t, float vec[3], char *str) { } } -static void ElementBoneSize(TransInfo *t, TransData *td, float mat[3][3]) +static void ElementBoneSize(TransInfo *t, TransData *td, float mat[3][3]) { float tmat[3][3], smat[3][3], oldy; float sizemat[3][3]; - + Mat3MulMat3(smat, mat, td->mtx); Mat3MulMat3(tmat, td->smtx, smat); - + if (t->con.applySize) { t->con.applySize(t, td, tmat); } - + /* we've tucked the scale in loc */ oldy= td->iloc[1]; SizeToMat3(td->iloc, sizemat); @@ -3879,14 +3877,14 @@ static void ElementBoneSize(TransInfo *t, TransData *td, float mat[3][3]) td->loc[1]= oldy; } -int BoneSize(TransInfo *t, short mval[2]) +int BoneSize(TransInfo *t, short mval[2]) { TransData *td = t->data; float size[3], mat[3][3]; float ratio; int i; char str[60]; - + // TRANSFORM_FIX_ME MOVE TO MOUSE INPUT /* for manipulator, center handle, the scaling can't be done relative to center */ if( (t->flag & T_USES_MANIPULATOR) && t->con.mode==0) @@ -3897,40 +3895,40 @@ int BoneSize(TransInfo *t, short mval[2]) { ratio = t->values[0]; } - + size[0] = size[1] = size[2] = ratio; - + snapGrid(t, size); - + if (hasNumInput(&t->num)) { applyNumInput(&t->num, size); constraintNumInput(t, size); } - + SizeToMat3(size, mat); - + if (t->con.applySize) { t->con.applySize(t, NULL, mat); } - + Mat3CpyMat3(t->mat, mat); // used in manipulator - + headerBoneSize(t, size, str); - + for(i = 0 ; i < t->total; i++, td++) { if (td->flag & TD_NOACTION) break; if (td->flag & TD_SKIP) continue; - + ElementBoneSize(t, td, mat); } - + recalcData(t); - + ED_area_headerprint(t->sa, str); - + return 1; } @@ -3941,9 +3939,9 @@ void initBoneEnvelope(TransInfo *t) { t->mode = TFM_BONE_ENVELOPE; t->transform = BoneEnvelope; - + initMouseInputMode(t, &t->mouse, INPUT_SPRING); - + t->idx_max = 0; t->num.idx_max = 0; t->snap[0] = 0.0f; @@ -3953,37 +3951,37 @@ void initBoneEnvelope(TransInfo *t) t->flag |= T_NO_CONSTRAINT; } -int BoneEnvelope(TransInfo *t, short mval[2]) +int BoneEnvelope(TransInfo *t, short mval[2]) { TransData *td = t->data; float ratio; int i; char str[50]; - + ratio = t->values[0]; - + snapGrid(t, &ratio); - + applyNumInput(&t->num, &ratio); - + /* header print for NumInput */ if (hasNumInput(&t->num)) { char c[20]; - + outputNumInput(&(t->num), c); sprintf(str, "Envelope: %s", c); } else { sprintf(str, "Envelope: %3f", ratio); } - + for(i = 0 ; i < t->total; i++, td++) { if (td->flag & TD_NOACTION) break; if (td->flag & TD_SKIP) continue; - + if (td->val) { /* if the old/original value was 0.0f, then just use ratio */ if (td->ival) @@ -3992,11 +3990,11 @@ int BoneEnvelope(TransInfo *t, short mval[2]) *td->val= ratio; } } - + recalcData(t); - + ED_area_headerprint(t->sa, str); - + return 1; } @@ -4007,7 +4005,7 @@ void initBoneRoll(TransInfo *t) { t->mode = TFM_BONE_ROLL; t->transform = BoneRoll; - + initMouseInputMode(t, &t->mouse, INPUT_ANGLE); t->idx_max = 0; @@ -4015,11 +4013,11 @@ void initBoneRoll(TransInfo *t) t->snap[0] = 0.0f; t->snap[1] = (float)((5.0/180)*M_PI); t->snap[2] = t->snap[1] * 0.2f; - + t->flag |= T_NO_CONSTRAINT; } -int BoneRoll(TransInfo *t, short mval[2]) +int BoneRoll(TransInfo *t, short mval[2]) { TransData *td = t->data; int i; @@ -4045,18 +4043,18 @@ int BoneRoll(TransInfo *t, short mval[2]) else { sprintf(str, "Roll: %.2f", 180.0*final/M_PI); } - + /* set roll values */ - for (i = 0; i < t->total; i++, td++) { + for (i = 0; i < t->total; i++, td++) { if (td->flag & TD_NOACTION) break; if (td->flag & TD_SKIP) continue; - + *(td->val) = td->ival - final; } - + recalcData(t); ED_area_headerprint(t->sa, str); @@ -4066,11 +4064,11 @@ int BoneRoll(TransInfo *t, short mval[2]) /* ************************** BAKE TIME ******************* */ -void initBakeTime(TransInfo *t) +void initBakeTime(TransInfo *t) { t->transform = BakeTime; initMouseInputMode(t, &t->mouse, INPUT_NONE); - + t->idx_max = 0; t->num.idx_max = 0; t->snap[0] = 0.0f; @@ -4078,15 +4076,15 @@ void initBakeTime(TransInfo *t) t->snap[2] = t->snap[1] * 0.1f; } -int BakeTime(TransInfo *t, short mval[2]) +int BakeTime(TransInfo *t, short mval[2]) { TransData *td = t->data; float time; int i; char str[50]; - + float fac = 0.1f; - + if(t->mouse.precision) { /* calculate ratio for shiftkey pos, and for total, and blend these for precision */ time= (float)(t->center2d[0] - t->mouse.precision_mval[0]) * fac; @@ -4118,7 +4116,7 @@ int BakeTime(TransInfo *t, short mval[2]) else sprintf(str, "Time: %.3f %s", time, t->proptext); } - + for(i = 0 ; i < t->total; i++, td++) { if (td->flag & TD_NOACTION) break; @@ -4142,7 +4140,7 @@ int BakeTime(TransInfo *t, short mval[2]) /* ************************** MIRROR *************************** */ -void initMirror(TransInfo *t) +void initMirror(TransInfo *t) { t->transform = Mirror; initMouseInputMode(t, &t->mouse, INPUT_NONE); @@ -4153,7 +4151,7 @@ void initMirror(TransInfo *t) } } -int Mirror(TransInfo *t, short mval[2]) +int Mirror(TransInfo *t, short mval[2]) { TransData *td; float size[3], mat[3][3]; @@ -4169,47 +4167,47 @@ int Mirror(TransInfo *t, short mval[2]) /* if an axis has been selected */ if (t->con.mode & CON_APPLY) { size[0] = size[1] = size[2] = -1; - + SizeToMat3(size, mat); - + if (t->con.applySize) { t->con.applySize(t, NULL, mat); } - + sprintf(str, "Mirror%s", t->con.text); - + for(i = 0, td=t->data; i < t->total; i++, td++) { if (td->flag & TD_NOACTION) break; - + if (td->flag & TD_SKIP) continue; - + ElementResize(t, td, mat); } - + recalcData(t); - + ED_area_headerprint(t->sa, str); } else { size[0] = size[1] = size[2] = 1; - + SizeToMat3(size, mat); - + for(i = 0, td=t->data; i < t->total; i++, td++) { if (td->flag & TD_NOACTION) break; - + if (td->flag & TD_SKIP) continue; - + ElementResize(t, td, mat); } - + recalcData(t); - + ED_area_headerprint(t->sa, "Select a mirror axis (X, Y, Z)"); } @@ -4218,12 +4216,12 @@ int Mirror(TransInfo *t, short mval[2]) /* ************************** ALIGN *************************** */ -void initAlign(TransInfo *t) +void initAlign(TransInfo *t) { t->flag |= T_NO_CONSTRAINT; - + t->transform = Align; - + initMouseInputMode(t, &t->mouse, INPUT_NONE); } @@ -4239,37 +4237,37 @@ int Align(TransInfo *t, short mval[2]) for(i = 0 ; i < t->total; i++, td++) { float mat[3][3], invmat[3][3]; - + if (td->flag & TD_NOACTION) break; if (td->flag & TD_SKIP) continue; - + /* around local centers */ if (t->flag & (T_OBJECT|T_POSE)) { VECCOPY(t->center, td->center); } else { - if(t->scene->selectmode & SCE_SELECT_FACE) { + if(t->settings->selectmode & SCE_SELECT_FACE) { VECCOPY(t->center, td->center); } } Mat3Inv(invmat, td->axismtx); - - Mat3MulMat3(mat, t->spacemtx, invmat); + + Mat3MulMat3(mat, t->spacemtx, invmat); ElementRotation(t, td, mat, t->around); } /* restoring original center */ VECCOPY(t->center, center); - + recalcData(t); ED_area_headerprint(t->sa, "Align"); - + return 1; } @@ -4278,37 +4276,37 @@ int Align(TransInfo *t, short mval[2]) /* ---------------- Special Helpers for Various Settings ------------- */ -/* This function returns the snapping 'mode' for Animation Editors only +/* This function returns the snapping 'mode' for Animation Editors only * We cannot use the standard snapping due to NLA-strip scaling complexities. */ // XXX these modifier checks should be keymappable static short getAnimEdit_SnapMode(TransInfo *t) { short autosnap= SACTSNAP_OFF; - + /* currently, some of these are only for the action editor */ if (t->spacetype == SPACE_ACTION) { SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first; - + if (saction) autosnap= saction->autosnap; } else if (t->spacetype == SPACE_IPO) { SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first; - + if (sipo) autosnap= sipo->autosnap; } else if (t->spacetype == SPACE_NLA) { SpaceNla *snla= (SpaceNla *)t->sa->spacedata.first; - + if (snla) autosnap= snla->autosnap; } else { // TRANSFORM_FIX_ME This needs to use proper defines for t->modifiers // // FIXME: this still toggles the modes... -// if (ctrl) +// if (ctrl) // autosnap= SACTSNAP_STEP; // else if (shift) // autosnap= SACTSNAP_FRAME; @@ -4317,41 +4315,41 @@ static short getAnimEdit_SnapMode(TransInfo *t) // else autosnap= SACTSNAP_OFF; } - + return autosnap; } /* This function is used for testing if an Animation Editor is displaying * its data in frames or seconds (and the data needing to be edited as such). - * Returns 1 if in seconds, 0 if in frames + * Returns 1 if in seconds, 0 if in frames */ static short getAnimEdit_DrawTime(TransInfo *t) { short drawtime; - + /* currently, some of these are only for the action editor */ if (t->spacetype == SPACE_ACTION) { SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first; - + drawtime = (saction->flag & SACTION_DRAWTIME)? 1 : 0; } else if (t->spacetype == SPACE_NLA) { SpaceNla *snla= (SpaceNla *)t->sa->spacedata.first; - + drawtime = (snla->flag & SNLA_DRAWTIME)? 1 : 0; } else { drawtime = 0; } - + return drawtime; -} +} -/* This function is used by Animation Editor specific transform functions to do +/* This function is used by Animation Editor specific transform functions to do * the Snap Keyframe to Nearest Frame/Marker */ -static void doAnimEdit_SnapFrame(TransInfo *t, TransData *td, Object *ob, short autosnap) +static void doAnimEdit_SnapFrame(TransInfo *t, TransData *td, AnimData *adt, short autosnap) { /* snap key to nearest frame? */ if (autosnap == SACTSNAP_FRAME) { @@ -4359,42 +4357,42 @@ static void doAnimEdit_SnapFrame(TransInfo *t, TransData *td, Object *ob, short const short doTime= getAnimEdit_DrawTime(t); const double secf= FPS; double val; - + /* convert frame to nla-action time (if needed) */ - if (ob) - val= get_action_frame_inv(ob, *(td->val)); + if (adt) + val= BKE_nla_tweakedit_remap(adt, *(td->val), NLATIME_CONVERT_MAP); else val= *(td->val); - + /* do the snapping to nearest frame/second */ if (doTime) val= (float)( floor((val/secf) + 0.5f) * secf ); else val= (float)( floor(val+0.5f) ); - + /* convert frame out of nla-action time */ - if (ob) - *(td->val)= get_action_frame(ob, val); + if (adt) + *(td->val)= BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_UNMAP); else *(td->val)= val; } /* snap key to nearest marker? */ else if (autosnap == SACTSNAP_MARKER) { float val; - + /* convert frame to nla-action time (if needed) */ - if (ob) - val= get_action_frame_inv(ob, *(td->val)); + if (adt) + val= BKE_nla_tweakedit_remap(adt, *(td->val), NLATIME_CONVERT_MAP); else val= *(td->val); - + /* snap to nearest marker */ // TODO: need some more careful checks for where data comes from val= (float)ED_markers_find_nearest_marker_time(&t->scene->markers, val); - + /* convert frame out of nla-action time */ - if (ob) - *(td->val)= get_action_frame(ob, val); + if (adt) + *(td->val)= BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_UNMAP); else *(td->val)= val; } @@ -4402,27 +4400,27 @@ static void doAnimEdit_SnapFrame(TransInfo *t, TransData *td, Object *ob, short /* ----------------- Translation ----------------------- */ -void initTimeTranslate(TransInfo *t) +void initTimeTranslate(TransInfo *t) { t->mode = TFM_TIME_TRANSLATE; t->transform = TimeTranslate; - + initMouseInputMode(t, &t->mouse, INPUT_NONE); /* num-input has max of (n-1) */ t->idx_max = 0; t->num.flag = 0; t->num.idx_max = t->idx_max; - + /* initialise snap like for everything else */ - t->snap[0] = 0.0f; + t->snap[0] = 0.0f; t->snap[1] = t->snap[2] = 1.0f; } -static void headerTimeTranslate(TransInfo *t, char *str) +static void headerTimeTranslate(TransInfo *t, char *str) { char tvec[60]; - + /* if numeric input is active, use results from that, otherwise apply snapping to result */ if (hasNumInput(&t->num)) { outputNumInput(&(t->num), tvec); @@ -4433,7 +4431,7 @@ static void headerTimeTranslate(TransInfo *t, char *str) const short doTime = getAnimEdit_DrawTime(t); const double secf= FPS; float val = t->values[0]; - + /* apply snapping + frame->seconds conversions */ if (autosnap == SACTSNAP_STEP) { if (doTime) @@ -4445,85 +4443,86 @@ static void headerTimeTranslate(TransInfo *t, char *str) if (doTime) val= val / secf; } - + sprintf(&tvec[0], "%.4f", val); } - + sprintf(str, "DeltaX: %s", &tvec[0]); } -static void applyTimeTranslate(TransInfo *t, float sval) +static void applyTimeTranslate(TransInfo *t, float sval) { TransData *td = t->data; Scene *scene = t->scene; int i; - + const short doTime= getAnimEdit_DrawTime(t); const double secf= FPS; - + const short autosnap= getAnimEdit_SnapMode(t); - + float deltax, val; - + /* it doesn't matter whether we apply to t->data or t->data2d, but t->data2d is more convenient */ for (i = 0 ; i < t->total; i++, td++) { - /* it is assumed that td->ob is a pointer to the object, - * whose active action is where this keyframe comes from + /* it is assumed that td->extra is a pointer to the AnimData, + * whose active action is where this keyframe comes from + * (this is only valid when not in NLA) */ - Object *ob= td->ob; - - /* check if any need to apply nla-scaling */ - if (ob) { + AnimData *adt= (t->spacetype != SPACE_NLA) ? td->extra : NULL; + + /* check if any need to apply nla-mapping */ + if (adt) { deltax = t->values[0]; - + if (autosnap == SACTSNAP_STEP) { - if (doTime) + if (doTime) deltax= (float)( floor((deltax/secf) + 0.5f) * secf ); else deltax= (float)( floor(deltax + 0.5f) ); } - - val = get_action_frame_inv(ob, td->ival); + + val = BKE_nla_tweakedit_remap(adt, td->ival, NLATIME_CONVERT_MAP); val += deltax; - *(td->val) = get_action_frame(ob, val); + *(td->val) = BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_UNMAP); } else { deltax = val = t->values[0]; - + if (autosnap == SACTSNAP_STEP) { if (doTime) val= (float)( floor((deltax/secf) + 0.5f) * secf ); else val= (float)( floor(val + 0.5f) ); } - + *(td->val) = td->ival + val; } - + /* apply nearest snapping */ - doAnimEdit_SnapFrame(t, td, ob, autosnap); + doAnimEdit_SnapFrame(t, td, adt, autosnap); } } -int TimeTranslate(TransInfo *t, short mval[2]) +int TimeTranslate(TransInfo *t, short mval[2]) { View2D *v2d = (View2D *)t->view; float cval[2], sval[2]; char str[200]; - + /* calculate translation amount from mouse movement - in 'time-grid space' */ UI_view2d_region_to_view(v2d, mval[0], mval[0], &cval[0], &cval[1]); UI_view2d_region_to_view(v2d, t->imval[0], t->imval[0], &sval[0], &sval[1]); - + /* we only need to calculate effect for time (applyTimeTranslate only needs that) */ t->values[0] = cval[0] - sval[0]; - + /* handle numeric-input stuff */ t->vec[0] = t->values[0]; applyNumInput(&t->num, &t->vec[0]); t->values[0] = t->vec[0]; headerTimeTranslate(t, str); - + applyTimeTranslate(t, sval[0]); recalcData(t); @@ -4535,36 +4534,36 @@ int TimeTranslate(TransInfo *t, short mval[2]) /* ----------------- Time Slide ----------------------- */ -void initTimeSlide(TransInfo *t) +void initTimeSlide(TransInfo *t) { /* this tool is only really available in the Action Editor... */ if (t->spacetype == SPACE_ACTION) { SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first; - + /* set flag for drawing stuff */ saction->flag |= SACTION_MOVING; } - + t->mode = TFM_TIME_SLIDE; t->transform = TimeSlide; t->flag |= T_FREE_CUSTOMDATA; - + initMouseInputMode(t, &t->mouse, INPUT_NONE); /* num-input has max of (n-1) */ t->idx_max = 0; t->num.flag = 0; t->num.idx_max = t->idx_max; - + /* initialise snap like for everything else */ - t->snap[0] = 0.0f; + t->snap[0] = 0.0f; t->snap[1] = t->snap[2] = 1.0f; } -static void headerTimeSlide(TransInfo *t, float sval, char *str) +static void headerTimeSlide(TransInfo *t, float sval, char *str) { char tvec[60]; - + if (hasNumInput(&t->num)) { outputNumInput(&(t->num), tvec); } @@ -4573,49 +4572,50 @@ static void headerTimeSlide(TransInfo *t, float sval, char *str) float maxx= *((float *)(t->customData) + 1); float cval= t->values[0]; float val; - + val= 2.0f*(cval-sval) / (maxx-minx); CLAMP(val, -1.0f, 1.0f); - + sprintf(&tvec[0], "%.4f", val); } - + sprintf(str, "TimeSlide: %s", &tvec[0]); } -static void applyTimeSlide(TransInfo *t, float sval) +static void applyTimeSlide(TransInfo *t, float sval) { TransData *td = t->data; int i; - + float minx= *((float *)(t->customData)); float maxx= *((float *)(t->customData) + 1); - + /* set value for drawing black line */ if (t->spacetype == SPACE_ACTION) { SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first; float cvalf = t->values[0]; - + saction->timeslide= cvalf; } - + /* it doesn't matter whether we apply to t->data or t->data2d, but t->data2d is more convenient */ for (i = 0 ; i < t->total; i++, td++) { - /* it is assumed that td->ob is a pointer to the object, - * whose active action is where this keyframe comes from + /* it is assumed that td->extra is a pointer to the AnimData, + * whose active action is where this keyframe comes from + * (this is only valid when not in NLA) */ - Object *ob= td->ob; + AnimData *adt= (t->spacetype != SPACE_NLA) ? td->extra : NULL; float cval = t->values[0]; - - /* apply scaling to necessary values */ - if (ob) - cval= get_action_frame(ob, cval); - + + /* apply NLA-mapping to necessary values */ + if (adt) + cval= BKE_nla_tweakedit_remap(adt, cval, NLATIME_CONVERT_UNMAP); + /* only apply to data if in range */ if ((sval > minx) && (sval < maxx)) { float cvalc= CLAMPIS(cval, minx, maxx); float timefac; - + /* left half? */ if (td->ival < sval) { timefac= (sval - td->ival) / (sval - minx); @@ -4629,26 +4629,26 @@ static void applyTimeSlide(TransInfo *t, float sval) } } -int TimeSlide(TransInfo *t, short mval[2]) +int TimeSlide(TransInfo *t, short mval[2]) { View2D *v2d = (View2D *)t->view; float cval[2], sval[2]; float minx= *((float *)(t->customData)); float maxx= *((float *)(t->customData) + 1); char str[200]; - + /* calculate mouse co-ordinates */ UI_view2d_region_to_view(v2d, mval[0], mval[0], &cval[0], &cval[1]); UI_view2d_region_to_view(v2d, t->imval[0], t->imval[0], &sval[0], &sval[1]); - + /* t->values[0] stores cval[0], which is the current mouse-pointer location (in frames) */ t->values[0] = cval[0]; - + /* handle numeric-input stuff */ t->vec[0] = 2.0f*(cval[0]-sval[0]) / (maxx-minx); applyNumInput(&t->num, &t->vec[0]); t->values[0] = (maxx-minx) * t->vec[0] / 2.0 + sval[0]; - + headerTimeSlide(t, sval[0], str); applyTimeSlide(t, sval[0]); @@ -4661,35 +4661,35 @@ int TimeSlide(TransInfo *t, short mval[2]) /* ----------------- Scaling ----------------------- */ -void initTimeScale(TransInfo *t) +void initTimeScale(TransInfo *t) { t->mode = TFM_TIME_SCALE; t->transform = TimeScale; - + initMouseInputMode(t, &t->mouse, INPUT_NONE); t->helpline = HLP_SPRING; /* set manually because we don't use a predefined input */ t->flag |= T_NULL_ONE; t->num.flag |= NUM_NULL_ONE; - + /* num-input has max of (n-1) */ t->idx_max = 0; t->num.flag = 0; t->num.idx_max = t->idx_max; - + /* initialise snap like for everything else */ - t->snap[0] = 0.0f; + t->snap[0] = 0.0f; t->snap[1] = t->snap[2] = 1.0f; } static void headerTimeScale(TransInfo *t, char *str) { char tvec[60]; - + if (hasNumInput(&t->num)) outputNumInput(&(t->num), tvec); else sprintf(&tvec[0], "%.4f", t->values[0]); - + sprintf(str, "ScaleX: %s", &tvec[0]); } @@ -4697,74 +4697,63 @@ static void applyTimeScale(TransInfo *t) { Scene *scene = t->scene; TransData *td = t->data; int i; - + const short autosnap= getAnimEdit_SnapMode(t); const short doTime= getAnimEdit_DrawTime(t); const double secf= FPS; - - + + for (i = 0 ; i < t->total; i++, td++) { - /* it is assumed that td->ob is a pointer to the object, - * whose active action is where this keyframe comes from + /* it is assumed that td->extra is a pointer to the AnimData, + * whose active action is where this keyframe comes from + * (this is only valid when not in NLA) */ - Object *ob= td->ob; + AnimData *adt= (t->spacetype != SPACE_NLA) ? td->extra : NULL; float startx= CFRA; float fac= t->values[0]; - + if (autosnap == SACTSNAP_STEP) { if (doTime) fac= (float)( floor(fac/secf + 0.5f) * secf ); else fac= (float)( floor(fac + 0.5f) ); } - - /* check if any need to apply nla-scaling */ - if (ob) - startx= get_action_frame(ob, startx); - + + /* check if any need to apply nla-mapping */ + if (adt) + startx= BKE_nla_tweakedit_remap(adt, startx, NLATIME_CONVERT_UNMAP); + /* now, calculate the new value */ *(td->val) = td->ival - startx; *(td->val) *= fac; *(td->val) += startx; - + /* apply nearest snapping */ - doAnimEdit_SnapFrame(t, td, ob, autosnap); + doAnimEdit_SnapFrame(t, td, adt, autosnap); } } -int TimeScale(TransInfo *t, short mval[2]) +int TimeScale(TransInfo *t, short mval[2]) { float cval, sval; float deltax, startx; float width= 0.0f; char str[200]; - + sval= t->imval[0]; cval= mval[0]; - - // XXX ewww... we need a better factor! -#if 0 // TRANSFORM_FIX_ME - switch (t->spacetype) { - case SPACE_ACTION: - width= ACTWIDTH; - break; - case SPACE_NLA: - width= NLAWIDTH; - break; - } -#endif - + /* calculate scaling factor */ startx= sval-(width/2+(t->ar->winx)/2); deltax= cval-(width/2+(t->ar->winx)/2); t->values[0] = deltax / startx; - + /* handle numeric-input stuff */ t->vec[0] = t->values[0]; applyNumInput(&t->num, &t->vec[0]); t->values[0] = t->vec[0]; headerTimeScale(t, str); - + applyTimeScale(t); recalcData(t); @@ -4803,7 +4792,7 @@ void NDofTransform() maxval = val; } } - + switch(axis) { case -1: @@ -4824,7 +4813,7 @@ void NDofTransform() default: printf("ndof: what we are doing here ?"); } - + if (mode != 0) { initTransform(mode, CTX_NDOF); |