diff options
author | Martin Poirier <theeth@yahoo.com> | 2009-07-09 06:45:48 +0400 |
---|---|---|
committer | Martin Poirier <theeth@yahoo.com> | 2009-07-09 06:45:48 +0400 |
commit | d7a333f83fcaa33a73304c8bbff7c0809ada9aa0 (patch) | |
tree | db2295e409d08f18b9f01f14bacb3108e6d433bc /source | |
parent | b0038be275b24253989dbfd19c2543c770849653 (diff) |
Hooking transform operators with manipulator.
It's just a straight application of the normal operator for now, none of the normal manipulator goodies yet (no draw code and you have to click to confirm).
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/include/ED_transform.h | 6 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawarmature.c | 4 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 232 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_manipulator.c | 500 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_ops.c | 105 |
5 files changed, 436 insertions, 411 deletions
diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h index 9327301336f..adcf2cfc024 100644 --- a/source/blender/editors/include/ED_transform.h +++ b/source/blender/editors/include/ED_transform.h @@ -87,7 +87,7 @@ enum { /* Standalone call to get the transformation center corresponding to the current situation * returns 1 if successful, 0 otherwise (usually means there's no selection) - * (if 0 is returns, *vec is unmodified) + * (if 0 is returns, *vec is unmodified) * */ int calculateTransformCenter(struct bContext *C, struct wmEvent *event, int centerMode, float *vec); @@ -128,7 +128,7 @@ void BIF_selectOrientation(void); void initManipulator(int mode); void ManipulatorTransform(); -int BIF_do_manipulator(struct bContext *C, short mval[2]); +int BIF_do_manipulator(struct bContext *C, struct wmEvent *event, struct wmOperator *op); void BIF_draw_manipulator(const struct bContext *C); /* Snapping */ @@ -137,7 +137,7 @@ void BIF_draw_manipulator(const struct bContext *C); typedef struct DepthPeel { struct DepthPeel *next, *prev; - + float depth; float p[3]; float no[3]; diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c index 68a9bf3f555..e0ec878ea4a 100644 --- a/source/blender/editors/space_view3d/drawarmature.c +++ b/source/blender/editors/space_view3d/drawarmature.c @@ -1812,7 +1812,7 @@ static void draw_pose_channels(Scene *scene, View3D *v3d, RegionView3D *rv3d, Ba if ( (arm->flag & ARM_DRAWAXES) && (arm->flag & ARM_POSEMODE) ) { glPushMatrix(); glMultMatrixf(pchan->pose_mat); - glTranslatef(0.0f, pchan->bone->length, 0.0f); + //glTranslatef(0.0f, pchan->bone->length, 0.0f); drawaxes(0.25f*pchan->bone->length, 0, OB_ARROWS); glPopMatrix(); } @@ -1996,7 +1996,7 @@ static void draw_ebones(View3D *v3d, RegionView3D *rv3d, Object *ob, int dt) if (arm->flag & ARM_DRAWAXES) { glPushMatrix(); set_matrix_editbone(eBone); - glTranslatef(0.0f, eBone->length, 0.0f); + //glTranslatef(0.0f, eBone->length, 0.0f); drawaxes(eBone->length*0.25f, 0, OB_ARROWS); glPopMatrix(); } diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 1206bf72b72..7880e588767 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -95,50 +95,50 @@ static void view3d_boxview_clip(ScrArea *sa) float clip[6][4]; float x1= 0.0f, y1= 0.0f, z1= 0.0f, ofs[3]; int val; - + /* create bounding box */ for(ar= sa->regionbase.first; ar; ar= ar->next) { if(ar->regiontype==RGN_TYPE_WINDOW) { RegionView3D *rv3d= ar->regiondata; - + if(rv3d->viewlock & RV3D_BOXCLIP) { if(ELEM(rv3d->view, V3D_VIEW_TOP, V3D_VIEW_BOTTOM)) { if(ar->winx>ar->winy) x1= rv3d->dist; else x1= ar->winx*rv3d->dist/ar->winy; - + if(ar->winx>ar->winy) y1= ar->winy*rv3d->dist/ar->winx; else y1= rv3d->dist; - + ofs[0]= rv3d->ofs[0]; ofs[1]= rv3d->ofs[1]; } else if(ELEM(rv3d->view, V3D_VIEW_FRONT, V3D_VIEW_BACK)) { ofs[2]= rv3d->ofs[2]; - + if(ar->winx>ar->winy) z1= ar->winy*rv3d->dist/ar->winx; else z1= rv3d->dist; } } } } - + for(val=0; val<8; val++) { if(ELEM4(val, 0, 3, 4, 7)) bb->vec[val][0]= -x1 - ofs[0]; else bb->vec[val][0]= x1 - ofs[0]; - + if(ELEM4(val, 0, 1, 4, 5)) bb->vec[val][1]= -y1 - ofs[1]; else bb->vec[val][1]= y1 - ofs[1]; - + if(val > 3) bb->vec[val][2]= -z1 - ofs[2]; else bb->vec[val][2]= z1 - ofs[2]; - } - + } + /* normals for plane equations */ CalcNormFloat(bb->vec[0], bb->vec[1], bb->vec[4], clip[0]); CalcNormFloat(bb->vec[1], bb->vec[2], bb->vec[5], clip[1]); @@ -146,18 +146,18 @@ static void view3d_boxview_clip(ScrArea *sa) CalcNormFloat(bb->vec[3], bb->vec[0], bb->vec[7], clip[3]); CalcNormFloat(bb->vec[4], bb->vec[5], bb->vec[6], clip[4]); CalcNormFloat(bb->vec[0], bb->vec[2], bb->vec[1], clip[5]); - + /* then plane equations */ for(val=0; val<5; val++) { clip[val][3]= - clip[val][0]*bb->vec[val][0] - clip[val][1]*bb->vec[val][1] - clip[val][2]*bb->vec[val][2]; } clip[5][3]= - clip[5][0]*bb->vec[0][0] - clip[5][1]*bb->vec[0][1] - clip[5][2]*bb->vec[0][2]; - + /* create bounding box */ for(ar= sa->regionbase.first; ar; ar= ar->next) { if(ar->regiontype==RGN_TYPE_WINDOW) { RegionView3D *rv3d= ar->regiondata; - + if(rv3d->viewlock & RV3D_BOXCLIP) { rv3d->rflag |= RV3D_CLIPPING; memcpy(rv3d->clip, clip, sizeof(clip)); @@ -172,11 +172,11 @@ static void view3d_boxview_sync(ScrArea *sa, ARegion *ar) { ARegion *artest; RegionView3D *rv3d= ar->regiondata; - + for(artest= sa->regionbase.first; artest; artest= artest->next) { if(artest!=ar && artest->regiontype==RGN_TYPE_WINDOW) { RegionView3D *rv3dtest= artest->regiondata; - + if(rv3dtest->viewlock) { rv3dtest->dist= rv3d->dist; @@ -198,7 +198,7 @@ static void view3d_boxview_sync(ScrArea *sa, ARegion *ar) if( ELEM(rv3dtest->view, V3D_VIEW_FRONT, V3D_VIEW_BACK)) rv3dtest->ofs[2]= rv3d->ofs[2]; } - + ED_region_tag_redraw(artest); } } @@ -211,11 +211,11 @@ void view3d_boxview_copy(ScrArea *sa, ARegion *ar) { ARegion *artest; RegionView3D *rv3d= ar->regiondata; - + for(artest= sa->regionbase.first; artest; artest= artest->next) { if(artest!=ar && artest->regiontype==RGN_TYPE_WINDOW) { RegionView3D *rv3dtest= artest->regiondata; - + if(rv3dtest->viewlock) { rv3dtest->dist= rv3d->dist; VECCOPY(rv3dtest->ofs, rv3d->ofs); @@ -238,7 +238,7 @@ typedef struct ViewOpsData { float ofs[3], obofs[3]; float reverse, dist0; float grid, far; - + int origx, origy, oldx, oldy; int origkey; @@ -289,11 +289,11 @@ static void viewops_data(bContext *C, wmOperator *op, wmEvent *event) vod->origx= vod->oldx= event->x; vod->origy= vod->oldy= event->y; vod->origkey= event->type; - + /* lookup, we dont pass on v3d to prevent confusement */ vod->grid= v3d->grid; vod->far= v3d->far; - + calctrackballvec(&vod->ar->winrct, event->x, event->y, vod->trackvec); initgrabz(rv3d, -rv3d->ofs[0], -rv3d->ofs[1], -rv3d->ofs[2]); @@ -523,7 +523,7 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, wmEvent *event) if(rv3d->viewlock) return OPERATOR_CANCELLED; - + /* makes op->customdata */ viewops_data(C, op, event); vod= op->customdata; @@ -557,7 +557,7 @@ void VIEW3D_OT_viewrotate(wmOperatorType *ot) ot->invoke= viewrotate_invoke; ot->modal= viewrotate_modal; ot->poll= ED_operator_view3d_active; - + /* flags */ ot->flag= OPTYPE_REGISTER; } @@ -580,7 +580,7 @@ static void viewmove_apply(ViewOpsData *vod, int x, int y) window_to_3d_delta(vod->ar, dvec, x-vod->oldx, y-vod->oldy); VecAddf(vod->rv3d->ofs, vod->rv3d->ofs, dvec); - + if(vod->rv3d->viewlock & RV3D_BOXVIEW) view3d_boxview_sync(vod->sa, vod->ar); } @@ -640,7 +640,7 @@ void VIEW3D_OT_viewmove(wmOperatorType *ot) ot->invoke= viewmove_invoke; ot->modal= viewmove_modal; ot->poll= ED_operator_view3d_active; - + /* flags */ ot->flag= OPTYPE_REGISTER; } @@ -650,7 +650,7 @@ void VIEW3D_OT_viewmove(wmOperatorType *ot) static void view_zoom_mouseloc(ARegion *ar, float dfac, int mx, int my) { RegionView3D *rv3d= ar->regiondata; - + if(U.uiflag & USER_ZOOM_TO_MOUSEPOS) { float dvec[3]; float tvec[3]; @@ -800,7 +800,7 @@ static int viewzoom_exec(bContext *C, wmOperator *op) if(rv3d->viewlock & RV3D_BOXVIEW) view3d_boxview_sync(CTX_wm_area(C), CTX_wm_region(C)); - + request_depth_update(CTX_wm_region_view3d(C)); ED_region_tag_redraw(CTX_wm_region(C)); @@ -839,10 +839,10 @@ void VIEW3D_OT_zoom(wmOperatorType *ot) ot->exec= viewzoom_exec; ot->modal= viewzoom_modal; ot->poll= ED_operator_view3d_active; - + /* flags */ ot->flag= OPTYPE_REGISTER; - + RNA_def_int(ot->srna, "delta", 0, INT_MIN, INT_MAX, "Delta", "", INT_MIN, INT_MAX); } @@ -899,11 +899,11 @@ static int viewhome_exec(bContext *C, wmOperator *op) /* was view3d_home() in 2. if (rv3d->persp==V3D_CAMOB) { rv3d->persp= V3D_PERSP; - smooth_view(C, NULL, v3d->camera, new_ofs, NULL, &new_dist, NULL); + smooth_view(C, NULL, v3d->camera, new_ofs, NULL, &new_dist, NULL); } } // XXX BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT); - + if(rv3d->viewlock & RV3D_BOXVIEW) view3d_boxview_copy(CTX_wm_area(C), ar); @@ -920,10 +920,10 @@ void VIEW3D_OT_viewhome(wmOperatorType *ot) /* api callbacks */ ot->exec= viewhome_exec; ot->poll= ED_operator_view3d_active; - + /* flags */ ot->flag= OPTYPE_REGISTER; - + RNA_def_boolean(ot->srna, "center", 0, "Center", ""); } @@ -1013,7 +1013,7 @@ static int viewcenter_exec(bContext *C, wmOperator *op) /* like a localview with /* perspective should be a bit farther away to look nice */ if(rv3d->persp==V3D_ORTHO) size*= 0.7; - + if(size <= v3d->near*1.5f) size= v3d->near*1.5f; new_ofs[0]= -(min[0]+max[0])/2.0f; @@ -1036,7 +1036,7 @@ static int viewcenter_exec(bContext *C, wmOperator *op) /* like a localview with if (rv3d->persp==V3D_CAMOB) { rv3d->persp= V3D_PERSP; smooth_view(C, v3d->camera, NULL, new_ofs, NULL, &new_dist, NULL); - } + } else { smooth_view(C, NULL, NULL, new_ofs, NULL, &new_dist, NULL); } @@ -1059,7 +1059,7 @@ void VIEW3D_OT_viewcenter(wmOperatorType *ot) /* api callbacks */ ot->exec= viewcenter_exec; ot->poll= ED_operator_view3d_active; - + /* flags */ ot->flag= OPTYPE_REGISTER; } @@ -1071,16 +1071,16 @@ static int render_border_exec(bContext *C, wmOperator *op) View3D *v3d = CTX_wm_view3d(C); ARegion *ar= CTX_wm_region(C); Scene *scene= CTX_data_scene(C); - + rcti rect; rctf vb; - + /* get border select values using rna */ rect.xmin= RNA_int_get(op->ptr, "xmin"); rect.ymin= RNA_int_get(op->ptr, "ymin"); rect.xmax= RNA_int_get(op->ptr, "xmax"); rect.ymax= RNA_int_get(op->ptr, "ymax"); - + /* calculate range */ calc_viewborder(scene, ar, v3d, &vb); @@ -1088,13 +1088,13 @@ static int render_border_exec(bContext *C, wmOperator *op) scene->r.border.ymin= ((float)rect.ymin-vb.ymin)/(vb.ymax-vb.ymin); scene->r.border.xmax= ((float)rect.xmax-vb.xmin)/(vb.xmax-vb.xmin); scene->r.border.ymax= ((float)rect.ymax-vb.ymin)/(vb.ymax-vb.ymin); - - /* actually set border */ + + /* actually set border */ CLAMP(scene->r.border.xmin, 0.0, 1.0); CLAMP(scene->r.border.ymin, 0.0, 1.0); CLAMP(scene->r.border.xmax, 0.0, 1.0); CLAMP(scene->r.border.ymax, 0.0, 1.0); - + /* drawing a border surrounding the entire camera view switches off border rendering * or the border covers no pixels */ if ((scene->r.border.xmin <= 0.0 && scene->r.border.xmax >= 1.0 && @@ -1106,7 +1106,7 @@ static int render_border_exec(bContext *C, wmOperator *op) } else { scene->r.mode |= R_BORDER; } - + return OPERATOR_FINISHED; } @@ -1114,9 +1114,9 @@ static int render_border_exec(bContext *C, wmOperator *op) static int view3d_render_border_invoke(bContext *C, wmOperator *op, wmEvent *event) { RegionView3D *rv3d= CTX_wm_region_view3d(C); - + /* if not in camera view do not exec the operator*/ - if (rv3d->persp == V3D_CAMOB) return WM_border_select_invoke(C, op, event); + if (rv3d->persp == V3D_CAMOB) return WM_border_select_invoke(C, op, event); else return OPERATOR_PASS_THROUGH; } @@ -1131,12 +1131,12 @@ void VIEW3D_OT_render_border(wmOperatorType *ot) ot->invoke= view3d_render_border_invoke; ot->exec= render_border_exec; ot->modal= WM_border_select_modal; - + ot->poll= ED_operator_view3d_active; - + /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; - + /* rna */ RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX); RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX); @@ -1152,7 +1152,7 @@ static int view3d_border_zoom_exec(bContext *C, wmOperator *op) View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d= CTX_wm_region_view3d(C); Scene *scene= CTX_data_scene(C); - + /* Zooms in on a border drawn by the user */ rcti rect; float dvec[3], vb[2], xscale, yscale, scale; @@ -1167,16 +1167,16 @@ static int view3d_border_zoom_exec(bContext *C, wmOperator *op) int had_depth = 0; double cent[2], p[3]; int xs, ys; - + /* note; otherwise opengl won't work */ view3d_operator_needs_opengl(C); - + /* get border select values using rna */ rect.xmin= RNA_int_get(op->ptr, "xmin"); rect.ymin= RNA_int_get(op->ptr, "ymin"); rect.xmax= RNA_int_get(op->ptr, "xmax"); rect.ymax= RNA_int_get(op->ptr, "ymax"); - + /* Get Z Depths, needed for perspective, nice for ortho */ bgl_get_mats(&mats); draw_depth(scene, ar, v3d, NULL); @@ -1275,27 +1275,27 @@ static int view3d_border_zoom_exec(bContext *C, wmOperator *op) } smooth_view(C, NULL, NULL, new_ofs, NULL, &new_dist, NULL); - + if(rv3d->viewlock & RV3D_BOXVIEW) view3d_boxview_sync(CTX_wm_area(C), ar); - + return OPERATOR_FINISHED; } static int view3d_border_zoom_invoke(bContext *C, wmOperator *op, wmEvent *event) { RegionView3D *rv3d= CTX_wm_region_view3d(C); - + /* if in camera view do not exec the operator so we do not conflict with set render border*/ - if (rv3d->persp != V3D_CAMOB) - return WM_border_select_invoke(C, op, event); - else + if (rv3d->persp != V3D_CAMOB) + return WM_border_select_invoke(C, op, event); + else return OPERATOR_PASS_THROUGH; } void VIEW3D_OT_zoom_border(wmOperatorType *ot) { - + /* identifiers */ ot->name= "Border Zoom"; ot->description = "Zoom in the view to the nearest object contained in the border."; @@ -1305,12 +1305,12 @@ void VIEW3D_OT_zoom_border(wmOperatorType *ot) ot->invoke= view3d_border_zoom_invoke; ot->exec= view3d_border_zoom_exec; ot->modal= WM_border_select_modal; - + ot->poll= ED_operator_view3d_active; - + /* flags */ ot->flag= OPTYPE_REGISTER; - + /* rna */ RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX); RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX); @@ -1335,7 +1335,7 @@ static void axis_set_view(bContext *C, float q1, float q2, float q3, float q4, s View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d= CTX_wm_region_view3d(C); float new_quat[4]; - + if(rv3d->viewlock) { /* only pass on if */ if(rv3d->view==V3D_VIEW_FRONT && view==V3D_VIEW_BACK); @@ -1346,10 +1346,10 @@ static void axis_set_view(bContext *C, float q1, float q2, float q3, float q4, s else if(rv3d->view==V3D_VIEW_TOP && view==V3D_VIEW_BOTTOM); else return; } - + new_quat[0]= q1; new_quat[1]= q2; new_quat[2]= q3; new_quat[3]= q4; - + rv3d->view= view; if(rv3d->viewlock) { @@ -1362,8 +1362,8 @@ static void axis_set_view(bContext *C, float q1, float q2, float q3, float q4, s if (U.uiflag & USER_AUTOPERSP) rv3d->persp= V3D_ORTHO; else if(rv3d->persp==V3D_CAMOB) rv3d->persp= perspo; - smooth_view(C, v3d->camera, NULL, rv3d->ofs, new_quat, NULL, NULL); - } + smooth_view(C, v3d->camera, NULL, rv3d->ofs, new_quat, NULL, NULL); + } else { if (U.uiflag & USER_AUTOPERSP) rv3d->persp= V3D_ORTHO; @@ -1420,7 +1420,7 @@ static int viewnumpad_exec(bContext *C, wmOperator *op) QUATCOPY(rv3d->lviewquat, rv3d->viewquat); rv3d->lview= rv3d->view; rv3d->lpersp= rv3d->persp; - + #if 0 if(G.qual==LR_ALTKEY) { if(oldcamera && is_an_active_object(oldcamera)) { @@ -1429,7 +1429,7 @@ static int viewnumpad_exec(bContext *C, wmOperator *op) handle_view3d_lock(); } #endif - + if(BASACT) { /* check both G.vd as G.scene cameras */ if((v3d->camera==NULL || scene->camera==NULL) && OBACT->type==OB_CAMERA) { @@ -1437,14 +1437,14 @@ static int viewnumpad_exec(bContext *C, wmOperator *op) /*handle_view3d_lock();*/ } } - + if(v3d->camera==NULL) { v3d->camera= scene_find_camera(scene); /*handle_view3d_lock();*/ } rv3d->persp= V3D_CAMOB; smooth_view(C, NULL, v3d->camera, rv3d->ofs, rv3d->viewquat, &rv3d->dist, &v3d->lens); - + } else{ /* return to settings of last view */ @@ -1472,10 +1472,10 @@ void VIEW3D_OT_viewnumpad(wmOperatorType *ot) /* api callbacks */ ot->exec= viewnumpad_exec; ot->poll= ED_operator_view3d_active; - + /* flags */ ot->flag= OPTYPE_REGISTER; - + RNA_def_enum(ot->srna, "type", prop_view_items, 0, "View", "The Type of view"); } @@ -1490,11 +1490,11 @@ static int vieworbit_exec(bContext *C, wmOperator *op) { ARegion *ar= CTX_wm_region(C); RegionView3D *rv3d= CTX_wm_region_view3d(C); - float phi, si, q1[4]; + float phi, si, q1[4]; int orbitdir; orbitdir = RNA_enum_get(op->ptr, "type"); - + if(rv3d->viewlock==0) { if(rv3d->persp != V3D_CAMOB) { @@ -1528,7 +1528,7 @@ static int vieworbit_exec(bContext *C, wmOperator *op) } } - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void VIEW3D_OT_view_orbit(wmOperatorType *ot) @@ -1541,7 +1541,7 @@ void VIEW3D_OT_view_orbit(wmOperatorType *ot) /* api callbacks */ ot->exec= vieworbit_exec; ot->poll= ED_operator_view3d_active; - + /* flags */ ot->flag= OPTYPE_REGISTER; RNA_def_enum(ot->srna, "type", prop_view_orbit_items, 0, "Orbit", "Direction of View Orbit"); @@ -1557,12 +1557,12 @@ static EnumPropertyItem prop_view_pan_items[] = { static int viewpan_exec(bContext *C, wmOperator *op) { ARegion *ar= CTX_wm_region(C); - RegionView3D *rv3d= CTX_wm_region_view3d(C); - float vec[3]; + RegionView3D *rv3d= CTX_wm_region_view3d(C); + float vec[3]; int pandir; pandir = RNA_enum_get(op->ptr, "type"); - + initgrabz(rv3d, 0.0, 0.0, 0.0); if(pandir == V3D_VIEW_PANRIGHT) window_to_3d_delta(ar, vec, -32, 0); @@ -1578,7 +1578,7 @@ static int viewpan_exec(bContext *C, wmOperator *op) ED_region_tag_redraw(ar); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void VIEW3D_OT_view_pan(wmOperatorType *ot) @@ -1591,7 +1591,7 @@ void VIEW3D_OT_view_pan(wmOperatorType *ot) /* api callbacks */ ot->exec= viewpan_exec; ot->poll= ED_operator_view3d_active; - + /* flags */ ot->flag= OPTYPE_REGISTER; RNA_def_enum(ot->srna, "type", prop_view_pan_items, 0, "Pan", "Direction of View Pan"); @@ -1600,17 +1600,17 @@ void VIEW3D_OT_view_pan(wmOperatorType *ot) static int viewpersportho_exec(bContext *C, wmOperator *op) { ARegion *ar= CTX_wm_region(C); - RegionView3D *rv3d= CTX_wm_region_view3d(C); - + RegionView3D *rv3d= CTX_wm_region_view3d(C); + if(rv3d->viewlock==0) { - if(rv3d->persp!=V3D_ORTHO) + if(rv3d->persp!=V3D_ORTHO) rv3d->persp=V3D_ORTHO; else rv3d->persp=V3D_PERSP; ED_region_tag_redraw(ar); } return OPERATOR_FINISHED; - + } void VIEW3D_OT_view_persportho(wmOperatorType *ot) @@ -1623,7 +1623,7 @@ void VIEW3D_OT_view_persportho(wmOperatorType *ot) /* api callbacks */ ot->exec= viewpersportho_exec; ot->poll= ED_operator_view3d_active; - + /* flags */ ot->flag= OPTYPE_REGISTER; } @@ -1725,10 +1725,10 @@ void VIEW3D_OT_clipping(wmOperatorType *ot) ot->modal= WM_border_select_modal; ot->poll= ED_operator_view3d_active; - + /* flags */ ot->flag= OPTYPE_REGISTER; - + /* rna */ RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX); RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX); @@ -1745,7 +1745,7 @@ static int view3d_drawtype_exec(bContext *C, wmOperator *op) dt = RNA_int_get(op->ptr, "draw_type"); dt_alt = RNA_int_get(op->ptr, "draw_type_alternate"); - + if (dt_alt != -1) { if (v3d->drawtype == dt) v3d->drawtype = dt_alt; @@ -1756,7 +1756,7 @@ static int view3d_drawtype_exec(bContext *C, wmOperator *op) v3d->drawtype = dt; ED_area_tag_redraw(CTX_wm_area(C)); - + return OPERATOR_FINISHED; } @@ -1778,10 +1778,10 @@ void VIEW3D_OT_drawtype(wmOperatorType *ot) ot->exec= view3d_drawtype_exec; ot->poll= ED_operator_view3d_active; - + /* flags */ ot->flag= OPTYPE_REGISTER; - + /* rna XXX should become enum */ RNA_def_int(ot->srna, "draw_type", 0, INT_MIN, INT_MAX, "Draw Type", "", INT_MIN, INT_MAX); RNA_def_int(ot->srna, "draw_type_alternate", -1, INT_MIN, INT_MAX, "Draw Type Alternate", "", INT_MIN, INT_MAX); @@ -1799,36 +1799,36 @@ static int set_3dcursor_invoke(bContext *C, wmOperator *op, wmEvent *event) float dx, dy, fz, *fp = NULL, dvec[3], oldcurs[3]; short mx, my, mval[2]; // short ctrl= 0; // XXX - + fp= give_cursor(scene, v3d); - + // if(obedit && ctrl) lr_click= 1; VECCOPY(oldcurs, fp); - + mx= event->x - ar->winrct.xmin; my= event->y - ar->winrct.ymin; project_short_noclip(ar, fp, mval); - + initgrabz(rv3d, fp[0], fp[1], fp[2]); - + if(mval[0]!=IS_CLIPPED) { - + window_to_3d_delta(ar, dvec, mval[0]-mx, mval[1]-my); VecSubf(fp, fp, dvec); } else { - + dx= ((float)(mx-(ar->winx/2)))*rv3d->zfac/(ar->winx/2); dy= ((float)(my-(ar->winy/2)))*rv3d->zfac/(ar->winy/2); - + fz= rv3d->persmat[0][3]*fp[0]+ rv3d->persmat[1][3]*fp[1]+ rv3d->persmat[2][3]*fp[2]+ rv3d->persmat[3][3]; fz= fz/rv3d->zfac; - + fp[0]= (rv3d->persinv[0][0]*dx + rv3d->persinv[1][0]*dy+ rv3d->persinv[2][0]*fz)-rv3d->ofs[0]; fp[1]= (rv3d->persinv[0][1]*dx + rv3d->persinv[1][1]*dy+ rv3d->persinv[2][1]*fz)-rv3d->ofs[1]; fp[2]= (rv3d->persinv[0][2]*dx + rv3d->persinv[1][2]*dy+ rv3d->persinv[2][2]*fz)-rv3d->ofs[2]; } - + // if(lr_click) { // XXX if(obedit->type==OB_MESH) add_click_mesh(); // else if ELEM(obedit->type, OB_CURVE, OB_SURF) addvert_Nurb(0); @@ -1837,24 +1837,24 @@ static int set_3dcursor_invoke(bContext *C, wmOperator *op, wmEvent *event) // } // XXX notifier for scene */ ED_area_tag_redraw(CTX_wm_area(C)); - + /* prevent other mouse ops to fail */ return OPERATOR_PASS_THROUGH; } void VIEW3D_OT_cursor3d(wmOperatorType *ot) { - + /* identifiers */ ot->name= "Set 3D Cursor"; ot->description = "Set the location of the 3D cursor."; ot->idname= "VIEW3D_OT_cursor3d"; - + /* api callbacks */ ot->invoke= set_3dcursor_invoke; - + ot->poll= ED_operator_view3d_active; - + /* rna later */ } @@ -1871,28 +1871,28 @@ static int manipulator_invoke(bContext *C, wmOperator *op, wmEvent *event) /* note; otherwise opengl won't work */ view3d_operator_needs_opengl(C); - - if(0==BIF_do_manipulator(C, event->mval)) + + if(0==BIF_do_manipulator(C, event, op)) return OPERATOR_PASS_THROUGH; - + return OPERATOR_FINISHED; } void VIEW3D_OT_manipulator(wmOperatorType *ot) { - + /* identifiers */ ot->name= "3D Manipulator"; ot->description = ""; ot->idname= "VIEW3D_OT_manipulator"; - + /* api callbacks */ ot->invoke= manipulator_invoke; - + ot->poll= ED_operator_view3d_active; - + /* rna later */ - + RNA_def_boolean_vector(ot->srna, "constraint_axis", 3, NULL, "Constraint Axis", ""); } diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c index 3868ac9204b..c4cca6eba07 100644 --- a/source/blender/editors/transform/transform_manipulator.c +++ b/source/blender/editors/transform/transform_manipulator.c @@ -53,6 +53,8 @@ #include "DNA_userdef_types.h" #include "DNA_view3d_types.h" +#include "RNA_access.h" + #include "BKE_armature.h" #include "BKE_context.h" #include "BKE_global.h" @@ -111,11 +113,11 @@ static int is_mat4_flipped(float mat[][4]) { float vec[3]; - + Crossf(vec, mat[0], mat[1]); if( Inpf(vec, mat[2]) < 0.0 ) return 1; return 0; -} +} /* transform widget center calc helper for below */ static void calc_tw_center(Scene *scene, float *co) @@ -123,7 +125,7 @@ static void calc_tw_center(Scene *scene, float *co) float *twcent= scene->twcent; float *min= scene->twmin; float *max= scene->twmax; - + DO_MINMAX(co, min, max); VecAddf(twcent, twcent, co); } @@ -136,7 +138,7 @@ static void protectflag_to_drawflags(short protectflag, short *drawflags) *drawflags &= ~MAN_TRANS_Y; if(protectflag & OB_LOCK_LOCZ) *drawflags &= ~MAN_TRANS_Z; - + if(protectflag & OB_LOCK_ROTX) *drawflags &= ~MAN_ROT_X; if(protectflag & OB_LOCK_ROTY) @@ -156,7 +158,7 @@ static void protectflag_to_drawflags(short protectflag, short *drawflags) static void stats_pose(Scene *scene, View3D *v3d, bPoseChannel *pchan) { Bone *bone= pchan->bone; - + if(bone) { if (bone->flag & BONE_TRANSFORM) { calc_tw_center(scene, pchan->pose_head); @@ -174,11 +176,11 @@ static void stats_editbone(View3D *v3d, EditBone *ebo) /* only counts the parent selection, and tags transform flag */ /* bad call... should re-use method from transform_conversion once */ -static void count_bone_select(TransInfo *t, bArmature *arm, ListBase *lb, int do_it) +static void count_bone_select(TransInfo *t, bArmature *arm, ListBase *lb, int do_it) { Bone *bone; int do_next; - + for(bone= lb->first; bone; bone= bone->next) { bone->flag &= ~BONE_TRANSFORM; do_next= do_it; @@ -214,16 +216,16 @@ int calc_manipulator_stats(const bContext *C) float normal[3]={0.0, 0.0, 0.0}; float plane[3]={0.0, 0.0, 0.0}; int a, totsel= 0; - + /* transform widget matrix */ Mat4One(rv3d->twmat); - + v3d->twdrawflag= 0xFFFF; - + /* transform widget centroid/center */ scene->twcent[0]= scene->twcent[1]= scene->twcent[2]= 0.0f; INIT_MINMAX(scene->twmin, scene->twmax); - + if(obedit) { ob= obedit; if((ob->lay & v3d->lay)==0) return 0; @@ -233,7 +235,7 @@ int calc_manipulator_stats(const bContext *C) EditVert *eve; EditSelection ese; float vec[3]= {0,0,0}; - + /* USE LAST SELECTE WITH ACTIVE */ if (v3d->around==V3D_ACTIVE && EM_get_actSelection(em, &ese)) { EM_editselection_center(vec, &ese); @@ -273,7 +275,7 @@ int calc_manipulator_stats(const bContext *C) Nurb *nu; BezTriple *bezt; BPoint *bp; - + nu= cu->editnurb->first; while(nu) { if((nu->type & 7)==CU_BEZIER) { @@ -329,7 +331,7 @@ int calc_manipulator_stats(const bContext *C) /* editmball.c */ ListBase editelems= {NULL, NULL}; /* XXX */ MetaElem *ml, *ml_sel=NULL; - + ml= editelems.first; while(ml) { if(ml->flag & SELECT) { @@ -343,9 +345,9 @@ int calc_manipulator_stats(const bContext *C) else if(obedit->type==OB_LATTICE) { BPoint *bp; Lattice *lt= obedit->data; - + bp= lt->editlatt->def; - + a= lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw; while(a--) { if(bp->f1 & SELECT) { @@ -355,7 +357,7 @@ int calc_manipulator_stats(const bContext *C) bp++; } } - + /* selection center */ if(totsel) { VecMulf(scene->twcent, 1.0f/(float)totsel); // centroid! @@ -368,12 +370,12 @@ int calc_manipulator_stats(const bContext *C) bArmature *arm = ob->data; bPoseChannel *pchan; int mode; - + if((ob->lay & v3d->lay)==0) return 0; - + mode = t->mode; t->mode = TFM_ROTATION; // mislead counting bones... bah - + /* count total, we use same method as transform will do */ t->total= 0; count_bone_select(t, arm, &arm->bonebase, 1); @@ -383,7 +385,7 @@ int calc_manipulator_stats(const bContext *C) for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { stats_pose(scene, v3d, pchan); } - + VecMulf(scene->twcent, 1.0f/(float)totsel); // centroid! Mat4MulVecfl(ob->obmat, scene->twcent); Mat4MulVecfl(ob->obmat, scene->twmin); @@ -419,44 +421,44 @@ int calc_manipulator_stats(const bContext *C) } } else { - + /* we need the one selected object, if its not active */ ob= OBACT; if(ob && !(ob->flag & SELECT)) ob= NULL; - + for(base= scene->base.first; base; base= base->next) { if TESTBASELIB(scene, base) { - if(ob==NULL) + if(ob==NULL) ob= base->object; calc_tw_center(scene, base->object->obmat[3]); protectflag_to_drawflags(base->object->protectflag, &v3d->twdrawflag); totsel++; } } - + /* selection center */ if(totsel) { VecMulf(scene->twcent, 1.0f/(float)totsel); // centroid! } } - + /* global, local or normal orientation? */ if(ob && totsel) { - + switch(v3d->twmode) { case V3D_MANIP_GLOBAL: strcpy(t->spacename, "global"); break; - + case V3D_MANIP_NORMAL: if(obedit || ob->flag & OB_POSEMODE) { float mat[3][3]; int type; - + strcpy(t->spacename, "normal"); - + type = getTransformOrientation(C, normal, plane, (v3d->around == V3D_ACTIVE)); - + switch (type) { case ORIENTATION_NORMAL: @@ -484,7 +486,7 @@ int calc_manipulator_stats(const bContext *C) } break; } - + if (type == ORIENTATION_NONE) { Mat4One(rv3d->twmat); @@ -501,7 +503,7 @@ int calc_manipulator_stats(const bContext *C) Mat4CpyMat4(rv3d->twmat, ob->obmat); Mat4Ortho(rv3d->twmat); break; - + case V3D_MANIP_VIEW: { float mat[3][3]; @@ -515,9 +517,9 @@ int calc_manipulator_stats(const bContext *C) applyTransformOrientation(C, t); break; } - + } - + return totsel; } @@ -526,15 +528,15 @@ int calc_manipulator_stats(const bContext *C) static float screen_aligned(RegionView3D *rv3d, float mat[][4]) { float vec[3], size; - + VECCOPY(vec, mat[0]); size= Normalize(vec); - + glTranslatef(mat[3][0], mat[3][1], mat[3][2]); - + /* sets view screen aligned */ glRotatef( -360.0f*saacos(rv3d->viewquat[0])/(float)M_PI, rv3d->viewquat[1], rv3d->viewquat[2], rv3d->viewquat[3]); - + return size; } @@ -553,32 +555,32 @@ static void partial_donut(float radring, float radhole, int start, int end, int float cos_theta1, sin_theta1; float ring_delta, side_delta; int i, j, docaps= 1; - + if(start==0 && end==nrings) docaps= 0; - + ring_delta= 2.0f*(float)M_PI/(float)nrings; side_delta= 2.0f*(float)M_PI/(float)nsides; - + theta= (float)M_PI+0.5f*ring_delta; cos_theta= (float)cos(theta); sin_theta= (float)sin(theta); - + for(i= nrings - 1; i >= 0; i--) { theta1= theta + ring_delta; cos_theta1= (float)cos(theta1); sin_theta1= (float)sin(theta1); - + if(docaps && i==start) { // cap glBegin(GL_POLYGON); phi= 0.0; for(j= nsides; j >= 0; j--) { float cos_phi, sin_phi, dist; - + phi += side_delta; cos_phi= (float)cos(phi); sin_phi= (float)sin(phi); dist= radhole + radring * cos_phi; - + glVertex3f(cos_theta1 * dist, -sin_theta1 * dist, radring * sin_phi); } glEnd(); @@ -588,35 +590,35 @@ static void partial_donut(float radring, float radhole, int start, int end, int phi= 0.0; for(j= nsides; j >= 0; j--) { float cos_phi, sin_phi, dist; - + phi += side_delta; cos_phi= (float)cos(phi); sin_phi= (float)sin(phi); dist= radhole + radring * cos_phi; - + glVertex3f(cos_theta1 * dist, -sin_theta1 * dist, radring * sin_phi); glVertex3f(cos_theta * dist, -sin_theta * dist, radring * sin_phi); } glEnd(); } - + if(docaps && i==end) { // cap glBegin(GL_POLYGON); phi= 0.0; for(j= nsides; j >= 0; j--) { float cos_phi, sin_phi, dist; - + phi -= side_delta; cos_phi= (float)cos(phi); sin_phi= (float)sin(phi); dist= radhole + radring * cos_phi; - + glVertex3f(cos_theta * dist, -sin_theta * dist, radring * sin_phi); } glEnd(); } - - + + theta= theta1; cos_theta= cos_theta1; sin_theta= sin_theta1; @@ -632,9 +634,9 @@ static void manipulator_setcolor(View3D *v3d, char axis, int colcode) { float vec[4]; char col[4]; - + vec[3]= 0.7f; // alpha set on 0.5, can be glEnabled or not - + if(colcode==MAN_GHOST) { glColor4ub(0, 0, 0, 70); } @@ -674,7 +676,7 @@ static void manipulator_setcolor(View3D *v3d, char axis, int colcode) /* viewmatrix should have been set OK, also no shademode! */ static void draw_manipulator_axes(View3D *v3d, int colcode, int flagx, int flagy, int flagz) { - + /* axes */ if(flagx) { manipulator_setcolor(v3d, 'x', colcode); @@ -684,7 +686,7 @@ static void draw_manipulator_axes(View3D *v3d, int colcode, int flagx, int flagy glVertex3f(0.2f, 0.0f, 0.0f); glVertex3f(1.0f, 0.0f, 0.0f); glEnd(); - } + } if(flagy) { if(flagy & MAN_SCALE_Y) glLoadName(MAN_SCALE_Y); else if(flagy & MAN_TRANS_Y) glLoadName(MAN_TRANS_Y); @@ -693,7 +695,7 @@ static void draw_manipulator_axes(View3D *v3d, int colcode, int flagx, int flagy glVertex3f(0.0f, 0.2f, 0.0f); glVertex3f(0.0f, 1.0f, 0.0f); glEnd(); - } + } if(flagz) { if(flagz & MAN_SCALE_Z) glLoadName(MAN_SCALE_Z); else if(flagz & MAN_TRANS_Z) glLoadName(MAN_TRANS_Z); @@ -712,63 +714,63 @@ static void draw_manipulator_rotate_ghost(View3D *v3d, RegionView3D *rv3d, int d GLUquadricObj *qobj; float size, phi, startphi, vec[3], svec[3], matt[4][4], cross[3], tmat[3][3]; int arcs= (G.rt!=2); - + glDisable(GL_DEPTH_TEST); - qobj= gluNewQuadric(); - gluQuadricDrawStyle(qobj, GLU_FILL); - + qobj= gluNewQuadric(); + gluQuadricDrawStyle(qobj, GLU_FILL); + glColor4ub(0,0,0,64); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); - + /* we need both [4][4] transforms, t->mat seems to be premul, not post for mat[][4] */ Mat4CpyMat4(matt, rv3d->twmat); // to copy the parts outside of [3][3] Mat4MulMat34(matt, t->mat, rv3d->twmat); /* Screen aligned view rot circle */ if(drawflags & MAN_ROT_V) { - + /* prepare for screen aligned draw */ glPushMatrix(); size= screen_aligned(rv3d, rv3d->twmat); - + vec[0]= (float)(t->con.imval[0] - t->center2d[0]); vec[1]= (float)(t->con.imval[1] - t->center2d[1]); vec[2]= 0.0f; Normalize(vec); - + startphi= saacos( vec[1] ); if(vec[0]<0.0) startphi= -startphi; - + phi= (float)fmod(180.0*t->val/M_PI, 360.0); if(phi > 180.0) phi-= 360.0; else if(phi<-180.0) phi+= 360.0; - + gluPartialDisk(qobj, 0.0, size, 32, 1, 180.0*startphi/M_PI, phi); - + glPopMatrix(); } else if(arcs) { float imat[3][3], ivmat[3][3]; /* try to get the start rotation */ - + svec[0]= (float)(t->con.imval[0] - t->center2d[0]); svec[1]= (float)(t->con.imval[1] - t->center2d[1]); svec[2]= 0.0f; - + /* screen aligned vec transform back to manipulator space */ Mat3CpyMat4(ivmat, rv3d->viewinv); Mat3CpyMat4(tmat, rv3d->twmat); Mat3Inv(imat, tmat); Mat3MulMat3(tmat, imat, ivmat); - + Mat3MulVecfl(tmat, svec); // tmat is used further on Normalize(svec); - } - + } + wmMultMatrix(rv3d->twmat); // aligns with original widget - + /* Z disk */ if(drawflags & MAN_ROT_Z) { if(arcs) { @@ -776,11 +778,11 @@ static void draw_manipulator_rotate_ghost(View3D *v3d, RegionView3D *rv3d, int d svec[0]+= tmat[2][0]; svec[1]+= tmat[2][1]; Normalize(svec); - + startphi= (float)atan2(svec[0], svec[1]); } else startphi= 0.5f*(float)M_PI; - + VECCOPY(vec, rv3d->twmat[0]); // use x axis to detect rotation Normalize(vec); Normalize(matt[0]); @@ -798,11 +800,11 @@ static void draw_manipulator_rotate_ghost(View3D *v3d, RegionView3D *rv3d, int d svec[1]+= tmat[2][1]; svec[2]+= tmat[2][2]; Normalize(svec); - + startphi= (float)(M_PI + atan2(svec[2], -svec[1])); } else startphi= 0.0f; - + VECCOPY(vec, rv3d->twmat[1]); // use y axis to detect rotation Normalize(vec); Normalize(matt[1]); @@ -814,7 +816,7 @@ static void draw_manipulator_rotate_ghost(View3D *v3d, RegionView3D *rv3d, int d gluPartialDisk(qobj, 0.0, 1.0, 32, 1, 180.0*startphi/M_PI, 180.0*phi/M_PI); glRotatef(-90.0, 0.0, 1.0, 0.0); } - } + } /* Y circle */ if(drawflags & MAN_ROT_Y) { if(arcs) { @@ -822,11 +824,11 @@ static void draw_manipulator_rotate_ghost(View3D *v3d, RegionView3D *rv3d, int d svec[0]+= tmat[2][0]; svec[2]+= tmat[2][2]; Normalize(svec); - + startphi= (float)(M_PI + atan2(-svec[0], svec[2])); } else startphi= (float)M_PI; - + VECCOPY(vec, rv3d->twmat[2]); // use z axis to detect rotation Normalize(vec); Normalize(matt[2]); @@ -839,7 +841,7 @@ static void draw_manipulator_rotate_ghost(View3D *v3d, RegionView3D *rv3d, int d glRotatef(90.0, 1.0, 0.0, 0.0); } } - + glDisable(GL_BLEND); wmLoadMatrix(rv3d->viewmat); } @@ -847,33 +849,33 @@ static void draw_manipulator_rotate_ghost(View3D *v3d, RegionView3D *rv3d, int d static void draw_manipulator_rotate(View3D *v3d, RegionView3D *rv3d, int moving, int drawflags, int combo) { TransInfo *t= BIF_GetTransInfo(); // XXX - GLUquadricObj *qobj; + GLUquadricObj *qobj; double plane[4]; float size, vec[3], unitmat[4][4]; - float cywid= 0.33f*0.01f*(float)U.tw_handlesize; + float cywid= 0.33f*0.01f*(float)U.tw_handlesize; float cusize= cywid*0.65f; int arcs= (G.rt!=2); int colcode; - + if(moving) colcode= MAN_MOVECOL; else colcode= MAN_RGB; - + /* when called while moving in mixed mode, do not draw when... */ if((drawflags & MAN_ROT_C)==0) return; - + /* Init stuff */ glDisable(GL_DEPTH_TEST); Mat4One(unitmat); qobj= gluNewQuadric(); - gluQuadricDrawStyle(qobj, GLU_FILL); - + gluQuadricDrawStyle(qobj, GLU_FILL); + /* prepare for screen aligned draw */ VECCOPY(vec, rv3d->twmat[0]); size= Normalize(vec); glPushMatrix(); glTranslatef(rv3d->twmat[3][0], rv3d->twmat[3][1], rv3d->twmat[3][2]); - + if(arcs) { /* clipplane makes nice handles, calc here because of multmatrix but with translate! */ VECCOPY(plane, rv3d->viewinv[2]); @@ -882,7 +884,7 @@ static void draw_manipulator_rotate(View3D *v3d, RegionView3D *rv3d, int moving, } /* sets view screen aligned */ glRotatef( -360.0f*saacos(rv3d->viewquat[0])/(float)M_PI, rv3d->viewquat[1], rv3d->viewquat[2], rv3d->viewquat[3]); - + /* Screen aligned help circle */ if(arcs) { if((G.f & G_PICKSEL)==0) { @@ -895,8 +897,8 @@ static void draw_manipulator_rotate(View3D *v3d, RegionView3D *rv3d, int moving, if(G.f & G_PICKSEL) glLoadName(MAN_ROT_V); UI_ThemeColor(TH_TRANSFORM); drawcircball(GL_LINE_LOOP, unitmat[3], 1.2f*size, unitmat); - - if(moving) { + + if(moving) { float vec[3]; vec[0]= (float)(t->imval[0] - t->center2d[0]); vec[1]= (float)(t->imval[1] - t->center2d[1]); @@ -910,7 +912,7 @@ static void draw_manipulator_rotate(View3D *v3d, RegionView3D *rv3d, int moving, } } glPopMatrix(); - + /* apply the transform delta */ if(moving) { float matt[4][4]; @@ -923,7 +925,7 @@ static void draw_manipulator_rotate(View3D *v3d, RegionView3D *rv3d, int moving, glFrontFace( is_mat4_flipped(rv3d->twmat)?GL_CW:GL_CCW); wmMultMatrix(rv3d->twmat); } - + /* axes */ if(arcs==0) { if(!(G.f & G_PICKSEL)) { @@ -934,12 +936,12 @@ static void draw_manipulator_rotate(View3D *v3d, RegionView3D *rv3d, int moving, manipulator_setcolor(v3d, 'x', colcode); glVertex3f(0.2f, 0.0f, 0.0f); glVertex3f(1.0f, 0.0f, 0.0f); - } + } if( (drawflags & MAN_ROT_Y) || (moving && (drawflags & MAN_ROT_X)) ) { manipulator_setcolor(v3d, 'y', colcode); glVertex3f(0.0f, 0.2f, 0.0f); glVertex3f(0.0f, 1.0f, 0.0f); - } + } if( (drawflags & MAN_ROT_Z) || (moving && (drawflags & MAN_ROT_Y)) ) { manipulator_setcolor(v3d, 'z', colcode); glVertex3f(0.0f, 0.0f, 0.2f); @@ -949,9 +951,9 @@ static void draw_manipulator_rotate(View3D *v3d, RegionView3D *rv3d, int moving, } } } - + if(arcs==0 && moving) { - + /* Z circle */ if(drawflags & MAN_ROT_Z) { if(G.f & G_PICKSEL) glLoadName(MAN_ROT_Z); @@ -965,7 +967,7 @@ static void draw_manipulator_rotate(View3D *v3d, RegionView3D *rv3d, int moving, manipulator_setcolor(v3d, 'x', colcode); drawcircball(GL_LINE_LOOP, unitmat[3], 1.0, unitmat); glRotatef(-90.0, 0.0, 1.0, 0.0); - } + } /* Y circle */ if(drawflags & MAN_ROT_Y) { if(G.f & G_PICKSEL) glLoadName(MAN_ROT_Y); @@ -974,13 +976,13 @@ static void draw_manipulator_rotate(View3D *v3d, RegionView3D *rv3d, int moving, drawcircball(GL_LINE_LOOP, unitmat[3], 1.0, unitmat); glRotatef(90.0, 1.0, 0.0, 0.0); } - + if(arcs) glDisable(GL_CLIP_PLANE0); } // donut arcs if(arcs) { glEnable(GL_CLIP_PLANE0); - + /* Z circle */ if(drawflags & MAN_ROT_Z) { if(G.f & G_PICKSEL) glLoadName(MAN_ROT_Z); @@ -994,7 +996,7 @@ static void draw_manipulator_rotate(View3D *v3d, RegionView3D *rv3d, int moving, manipulator_setcolor(v3d, 'x', colcode); partial_donut(cusize/4.0f, 1.0f, 0, 48, 8, 48); glRotatef(-90.0, 0.0, 1.0, 0.0); - } + } /* Y circle */ if(drawflags & MAN_ROT_Y) { if(G.f & G_PICKSEL) glLoadName(MAN_ROT_Y); @@ -1003,12 +1005,12 @@ static void draw_manipulator_rotate(View3D *v3d, RegionView3D *rv3d, int moving, partial_donut(cusize/4.0f, 1.0f, 0, 48, 8, 48); glRotatef(90.0, 1.0, 0.0, 0.0); } - + glDisable(GL_CLIP_PLANE0); } - + if(arcs==0) { - + /* Z handle on X axis */ if(drawflags & MAN_ROT_Z) { glPushMatrix(); @@ -1018,41 +1020,41 @@ static void draw_manipulator_rotate(View3D *v3d, RegionView3D *rv3d, int moving, partial_donut(0.7f*cusize, 1.0f, 31, 33, 8, 64); glPopMatrix(); - } + } /* Y handle on X axis */ if(drawflags & MAN_ROT_Y) { glPushMatrix(); if(G.f & G_PICKSEL) glLoadName(MAN_ROT_Y); manipulator_setcolor(v3d, 'y', colcode); - + glRotatef(90.0, 1.0, 0.0, 0.0); glRotatef(90.0, 0.0, 0.0, 1.0); partial_donut(0.7f*cusize, 1.0f, 31, 33, 8, 64); - + glPopMatrix(); } - + /* X handle on Z axis */ if(drawflags & MAN_ROT_X) { glPushMatrix(); if(G.f & G_PICKSEL) glLoadName(MAN_ROT_X); manipulator_setcolor(v3d, 'x', colcode); - + glRotatef(-90.0, 0.0, 1.0, 0.0); glRotatef(90.0, 0.0, 0.0, 1.0); partial_donut(0.7f*cusize, 1.0f, 31, 33, 8, 64); glPopMatrix(); } - + } - + /* restore */ wmLoadMatrix(rv3d->viewmat); gluDeleteQuadric(qobj); if(v3d->zbuf) glEnable(GL_DEPTH_TEST); - + } static void drawsolidcube(float size) @@ -1067,52 +1069,52 @@ static void drawsolidcube(float size) { 1.0, 1.0, 1.0}, { 1.0, 1.0, -1.0}, }; float n[3]; - + glPushMatrix(); glScalef(size, size, size); - + n[0]=0; n[1]=0; n[2]=0; glBegin(GL_QUADS); n[0]= -1.0; - glNormal3fv(n); + glNormal3fv(n); glVertex3fv(cube[0]); glVertex3fv(cube[1]); glVertex3fv(cube[2]); glVertex3fv(cube[3]); n[0]=0; glEnd(); - + glBegin(GL_QUADS); n[1]= -1.0; - glNormal3fv(n); + glNormal3fv(n); glVertex3fv(cube[0]); glVertex3fv(cube[4]); glVertex3fv(cube[5]); glVertex3fv(cube[1]); n[1]=0; glEnd(); - + glBegin(GL_QUADS); n[0]= 1.0; - glNormal3fv(n); + glNormal3fv(n); glVertex3fv(cube[4]); glVertex3fv(cube[7]); glVertex3fv(cube[6]); glVertex3fv(cube[5]); n[0]=0; glEnd(); - + glBegin(GL_QUADS); n[1]= 1.0; - glNormal3fv(n); + glNormal3fv(n); glVertex3fv(cube[7]); glVertex3fv(cube[3]); glVertex3fv(cube[2]); glVertex3fv(cube[6]); n[1]=0; glEnd(); - + glBegin(GL_QUADS); n[2]= 1.0; - glNormal3fv(n); + glNormal3fv(n); glVertex3fv(cube[1]); glVertex3fv(cube[5]); glVertex3fv(cube[6]); glVertex3fv(cube[2]); n[2]=0; glEnd(); - + glBegin(GL_QUADS); n[2]= -1.0; - glNormal3fv(n); + glNormal3fv(n); glVertex3fv(cube[7]); glVertex3fv(cube[4]); glVertex3fv(cube[0]); glVertex3fv(cube[3]); glEnd(); - + glPopMatrix(); } @@ -1120,36 +1122,36 @@ static void drawsolidcube(float size) static void draw_manipulator_scale(View3D *v3d, RegionView3D *rv3d, int moving, int drawflags, int combo, int colcode) { TransInfo *t= BIF_GetTransInfo(); // XXX - float cywid= 0.25f*0.01f*(float)U.tw_handlesize; + float cywid= 0.25f*0.01f*(float)U.tw_handlesize; float cusize= cywid*0.75f, dz; - + /* when called while moving in mixed mode, do not draw when... */ if((drawflags & MAN_SCALE_C)==0) return; - + glDisable(GL_DEPTH_TEST); - + /* not in combo mode */ if( (combo & (V3D_MANIP_TRANSLATE|V3D_MANIP_ROTATE))==0) { float size, unitmat[4][4]; int shift= 0; // XXX - + /* center circle, do not add to selection when shift is pressed (planar constraint) */ if( (G.f & G_PICKSEL) && shift==0) glLoadName(MAN_SCALE_C); - + manipulator_setcolor(v3d, 'c', colcode); glPushMatrix(); size= screen_aligned(rv3d, rv3d->twmat); Mat4One(unitmat); drawcircball(GL_LINE_LOOP, unitmat[3], 0.2f*size, unitmat); glPopMatrix(); - + dz= 1.0; } else dz= 1.0f-4.0f*cusize; - + if(moving) { float matt[4][4]; - + Mat4CpyMat4(matt, rv3d->twmat); // to copy the parts outside of [3][3] Mat4MulMat34(matt, t->mat, rv3d->twmat); wmMultMatrix(matt); @@ -1159,26 +1161,26 @@ static void draw_manipulator_scale(View3D *v3d, RegionView3D *rv3d, int moving, wmMultMatrix(rv3d->twmat); glFrontFace( is_mat4_flipped(rv3d->twmat)?GL_CW:GL_CCW); } - + /* axis */ - + /* in combo mode, this is always drawn as first type */ draw_manipulator_axes(v3d, colcode, drawflags & MAN_SCALE_X, drawflags & MAN_SCALE_Y, drawflags & MAN_SCALE_Z); - + /* Z cube */ glTranslatef(0.0, 0.0, dz); if(drawflags & MAN_SCALE_Z) { if(G.f & G_PICKSEL) glLoadName(MAN_SCALE_Z); manipulator_setcolor(v3d, 'z', colcode); drawsolidcube(cusize); - } + } /* X cube */ glTranslatef(dz, 0.0, -dz); if(drawflags & MAN_SCALE_X) { if(G.f & G_PICKSEL) glLoadName(MAN_SCALE_X); manipulator_setcolor(v3d, 'x', colcode); drawsolidcube(cusize); - } + } /* Y cube */ glTranslatef(-dz, dz, 0.0); if(drawflags & MAN_SCALE_Y) { @@ -1186,11 +1188,11 @@ static void draw_manipulator_scale(View3D *v3d, RegionView3D *rv3d, int moving, manipulator_setcolor(v3d, 'y', colcode); drawsolidcube(cusize); } - + /* if shiftkey, center point as last, for selectbuffer order */ if(G.f & G_PICKSEL) { int shift= 0; // XXX - + if(shift) { glTranslatef(0.0, -dz, 0.0); glLoadName(MAN_SCALE_C); @@ -1199,11 +1201,11 @@ static void draw_manipulator_scale(View3D *v3d, RegionView3D *rv3d, int moving, glEnd(); } } - + /* restore */ wmLoadMatrix(rv3d->viewmat); - - if(v3d->zbuf) glEnable(GL_DEPTH_TEST); + + if(v3d->zbuf) glEnable(GL_DEPTH_TEST); glFrontFace(GL_CCW); } @@ -1213,23 +1215,23 @@ static void draw_cone(GLUquadricObj *qobj, float len, float width) glTranslatef(0.0, 0.0, -0.5f*len); gluCylinder(qobj, width, 0.0, len, 8, 1); gluQuadricOrientation(qobj, GLU_INSIDE); - gluDisk(qobj, 0.0, width, 8, 1); + gluDisk(qobj, 0.0, width, 8, 1); gluQuadricOrientation(qobj, GLU_OUTSIDE); glTranslatef(0.0, 0.0, 0.5f*len); } static void draw_cylinder(GLUquadricObj *qobj, float len, float width) { - + width*= 0.8f; // just for beauty - + glTranslatef(0.0, 0.0, -0.5f*len); gluCylinder(qobj, width, width, len, 8, 1); gluQuadricOrientation(qobj, GLU_INSIDE); - gluDisk(qobj, 0.0, width, 8, 1); + gluDisk(qobj, 0.0, width, 8, 1); gluQuadricOrientation(qobj, GLU_OUTSIDE); glTranslatef(0.0, 0.0, len); - gluDisk(qobj, 0.0, width, 8, 1); + gluDisk(qobj, 0.0, width, 8, 1); glTranslatef(0.0, 0.0, -0.5f*len); } @@ -1237,54 +1239,54 @@ static void draw_cylinder(GLUquadricObj *qobj, float len, float width) static void draw_manipulator_translate(View3D *v3d, RegionView3D *rv3d, int moving, int drawflags, int combo, int colcode) { TransInfo *t= BIF_GetTransInfo(); // XXX - GLUquadricObj *qobj; + GLUquadricObj *qobj; float cylen= 0.01f*(float)U.tw_handlesize; float cywid= 0.25f*cylen, dz, size; float unitmat[4][4]; int shift= 0; // XXX - + /* when called while moving in mixed mode, do not draw when... */ if((drawflags & MAN_TRANS_C)==0) return; - + if(moving) glTranslatef(t->vec[0], t->vec[1], t->vec[2]); glDisable(GL_DEPTH_TEST); qobj= gluNewQuadric(); - gluQuadricDrawStyle(qobj, GLU_FILL); - + gluQuadricDrawStyle(qobj, GLU_FILL); + /* center circle, do not add to selection when shift is pressed (planar constraint) */ if( (G.f & G_PICKSEL) && shift==0) glLoadName(MAN_TRANS_C); - + manipulator_setcolor(v3d, 'c', colcode); glPushMatrix(); size= screen_aligned(rv3d, rv3d->twmat); Mat4One(unitmat); drawcircball(GL_LINE_LOOP, unitmat[3], 0.2f*size, unitmat); glPopMatrix(); - + /* and now apply matrix, we move to local matrix drawing */ wmMultMatrix(rv3d->twmat); - + /* axis */ glLoadName(-1); - + // translate drawn as last, only axis when no combo with scale, or for ghosting if((combo & V3D_MANIP_SCALE)==0 || colcode==MAN_GHOST) draw_manipulator_axes(v3d, colcode, drawflags & MAN_TRANS_X, drawflags & MAN_TRANS_Y, drawflags & MAN_TRANS_Z); - + /* offset in combo mode, for rotate a bit more */ if(combo & (V3D_MANIP_ROTATE)) dz= 1.0f+2.0f*cylen; else if(combo & (V3D_MANIP_SCALE)) dz= 1.0f+0.5f*cylen; else dz= 1.0f; - + /* Z Cone */ glTranslatef(0.0, 0.0, dz); if(drawflags & MAN_TRANS_Z) { if(G.f & G_PICKSEL) glLoadName(MAN_TRANS_Z); manipulator_setcolor(v3d, 'z', colcode); draw_cone(qobj, cylen, cywid); - } + } /* X Cone */ glTranslatef(dz, 0.0, -dz); if(drawflags & MAN_TRANS_X) { @@ -1293,7 +1295,7 @@ static void draw_manipulator_translate(View3D *v3d, RegionView3D *rv3d, int movi manipulator_setcolor(v3d, 'x', colcode); draw_cone(qobj, cylen, cywid); glRotatef(-90.0, 0.0, 1.0, 0.0); - } + } /* Y Cone */ glTranslatef(-dz, dz, 0.0); if(drawflags & MAN_TRANS_Y) { @@ -1305,9 +1307,9 @@ static void draw_manipulator_translate(View3D *v3d, RegionView3D *rv3d, int movi gluDeleteQuadric(qobj); wmLoadMatrix(rv3d->viewmat); - + if(v3d->zbuf) glEnable(GL_DEPTH_TEST); - + } static void draw_manipulator_rotate_cyl(View3D *v3d, RegionView3D *rv3d, int moving, int drawflags, int combo, int colcode) @@ -1317,27 +1319,27 @@ static void draw_manipulator_rotate_cyl(View3D *v3d, RegionView3D *rv3d, int mov float size; float cylen= 0.01f*(float)U.tw_handlesize; float cywid= 0.25f*cylen; - + /* when called while moving in mixed mode, do not draw when... */ if((drawflags & MAN_ROT_C)==0) return; /* prepare for screen aligned draw */ glPushMatrix(); size= screen_aligned(rv3d, rv3d->twmat); - + glDisable(GL_DEPTH_TEST); - qobj= gluNewQuadric(); - + qobj= gluNewQuadric(); + /* Screen aligned view rot circle */ if(drawflags & MAN_ROT_V) { float unitmat[4][4]; Mat4One(unitmat); - + if(G.f & G_PICKSEL) glLoadName(MAN_ROT_V); UI_ThemeColor(TH_TRANSFORM); drawcircball(GL_LINE_LOOP, unitmat[3], 1.2f*size, unitmat); - + if(moving) { float vec[3]; vec[0]= (float)(t->imval[0] - t->center2d[0]); @@ -1352,7 +1354,7 @@ static void draw_manipulator_rotate_cyl(View3D *v3d, RegionView3D *rv3d, int mov } } glPopMatrix(); - + /* apply the transform delta */ if(moving) { float matt[4][4]; @@ -1365,27 +1367,27 @@ static void draw_manipulator_rotate_cyl(View3D *v3d, RegionView3D *rv3d, int mov else { wmMultMatrix(rv3d->twmat); } - + glFrontFace( is_mat4_flipped(rv3d->twmat)?GL_CW:GL_CCW); - + /* axis */ if( (G.f & G_PICKSEL)==0 ) { - + // only draw axis when combo didn't draw scale axes if((combo & V3D_MANIP_SCALE)==0) draw_manipulator_axes(v3d, colcode, drawflags & MAN_ROT_X, drawflags & MAN_ROT_Y, drawflags & MAN_ROT_Z); - + /* only has to be set when not in picking */ - gluQuadricDrawStyle(qobj, GLU_FILL); + gluQuadricDrawStyle(qobj, GLU_FILL); } - + /* Z cyl */ glTranslatef(0.0, 0.0, 1.0); if(drawflags & MAN_ROT_Z) { if(G.f & G_PICKSEL) glLoadName(MAN_ROT_Z); manipulator_setcolor(v3d, 'z', colcode); draw_cylinder(qobj, cylen, cywid); - } + } /* X cyl */ glTranslatef(1.0, 0.0, -1.0); if(drawflags & MAN_ROT_X) { @@ -1394,7 +1396,7 @@ static void draw_manipulator_rotate_cyl(View3D *v3d, RegionView3D *rv3d, int mov manipulator_setcolor(v3d, 'x', colcode); draw_cylinder(qobj, cylen, cywid); glRotatef(-90.0, 0.0, 1.0, 0.0); - } + } /* Y cylinder */ glTranslatef(-1.0, 1.0, 0.0); if(drawflags & MAN_ROT_Y) { @@ -1403,14 +1405,14 @@ static void draw_manipulator_rotate_cyl(View3D *v3d, RegionView3D *rv3d, int mov manipulator_setcolor(v3d, 'y', colcode); draw_cylinder(qobj, cylen, cywid); } - + /* restore */ - + gluDeleteQuadric(qobj); wmLoadMatrix(rv3d->viewmat); - + if(v3d->zbuf) glEnable(GL_DEPTH_TEST); - + } @@ -1420,7 +1422,7 @@ static float get_manipulator_drawsize(ARegion *ar) { RegionView3D *rv3d= ar->regiondata; float size = get_drawsize(ar, rv3d->twmat[3]); - + size*= (float)U.tw_size; return size; @@ -1439,13 +1441,13 @@ void BIF_draw_manipulator(const bContext *C) View3D *v3d= sa->spacedata.first; RegionView3D *rv3d= ar->regiondata; int totsel; - + if(!(v3d->twflag & V3D_USE_MANIPULATOR)) return; if(G.moving && (G.moving & G_TRANSFORM_MANIP)==0) return; - + if(G.moving==0) { v3d->twflag &= ~V3D_DRAW_MANIPULATOR; - + totsel= calc_manipulator_stats(C); if(totsel==0) return; drawflags= v3d->twdrawflag; /* set in calc_manipulator_stats */ @@ -1461,7 +1463,7 @@ void BIF_draw_manipulator(const bContext *C) rv3d->twmat[3][2]= (scene->twmin[2] + scene->twmax[2])/2.0f; if(v3d->around==V3D_ACTIVE && scene->obedit==NULL) { Object *ob= OBACT; - if(ob && !(ob->flag & OB_POSEMODE)) + if(ob && !(ob->flag & OB_POSEMODE)) VECCOPY(rv3d->twmat[3], ob->obmat[3]); } break; @@ -1473,26 +1475,26 @@ void BIF_draw_manipulator(const bContext *C) VECCOPY(rv3d->twmat[3], give_cursor(scene, v3d)); break; } - + Mat4MulFloat3((float *)rv3d->twmat, get_manipulator_drawsize(ar)); } - + if(v3d->twflag & V3D_DRAW_MANIPULATOR) { - + if(v3d->twtype & V3D_MANIP_ROTATE) { - + /* rotate has special ghosting draw, for pie chart */ if(G.moving) draw_manipulator_rotate_ghost(v3d, rv3d, drawflags); - + if(G.moving) glEnable(GL_BLEND); - + if(G.rt==3) { if(G.moving) draw_manipulator_rotate_cyl(v3d, rv3d, 1, drawflags, v3d->twtype, MAN_MOVECOL); else draw_manipulator_rotate_cyl(v3d, rv3d, 0, drawflags, v3d->twtype, MAN_RGB); } else draw_manipulator_rotate(v3d, rv3d, G.moving, drawflags, v3d->twtype); - + glDisable(GL_BLEND); } if(v3d->twtype & V3D_MANIP_SCALE) { @@ -1524,22 +1526,22 @@ static int manipulator_selectbuf(ScrArea *sa, ARegion *ar, short *mval, float ho GLuint buffer[64]; // max 4 items per select, so large enuf short hits; extern void setwinmatrixview3d(ARegion *ar, View3D *v3d, rctf *rect); // XXX check a bit later on this... (ton) - + G.f |= G_PICKSEL; - + rect.xmin= mval[0]-hotspot; rect.xmax= mval[0]+hotspot; rect.ymin= mval[1]-hotspot; rect.ymax= mval[1]+hotspot; - + setwinmatrixview3d(ar, v3d, &rect); Mat4MulMat4(rv3d->persmat, rv3d->viewmat, rv3d->winmat); - + glSelectBuffer( 64, buffer); glRenderMode(GL_SELECT); glInitNames(); /* these two calls whatfor? It doesnt work otherwise */ glPushName(-2); - + /* do the drawing */ if(v3d->twtype & V3D_MANIP_ROTATE) { if(G.rt==3) draw_manipulator_rotate_cyl(v3d, rv3d, 0, MAN_ROT_C & v3d->twdrawflag, v3d->twtype, MAN_RGB); @@ -1549,26 +1551,26 @@ static int manipulator_selectbuf(ScrArea *sa, ARegion *ar, short *mval, float ho draw_manipulator_scale(v3d, rv3d, 0, MAN_SCALE_C & v3d->twdrawflag, v3d->twtype, MAN_RGB); if(v3d->twtype & V3D_MANIP_TRANSLATE) draw_manipulator_translate(v3d, rv3d, 0, MAN_TRANS_C & v3d->twdrawflag, v3d->twtype, MAN_RGB); - + glPopName(); hits= glRenderMode(GL_RENDER); - + G.f &= ~G_PICKSEL; setwinmatrixview3d(ar, v3d, NULL); Mat4MulMat4(rv3d->persmat, rv3d->viewmat, rv3d->winmat); - + if(hits==1) return buffer[3]; else if(hits>1) { GLuint val, dep, mindep=0, mindeprot=0, minval=0, minvalrot=0; int a; - + /* we compare the hits in buffer, but value centers highest */ /* we also store the rotation hits separate (because of arcs) and return hits on other widgets if there are */ for(a=0; a<hits; a++) { dep= buffer[4*a + 1]; val= buffer[4*a + 3]; - + if(val==MAN_TRANS_C) return MAN_TRANS_C; else if(val==MAN_SCALE_C) return MAN_SCALE_C; else { @@ -1586,7 +1588,7 @@ static int manipulator_selectbuf(ScrArea *sa, ARegion *ar, short *mval, float ho } } } - + if(minval) return minval; else @@ -1596,113 +1598,111 @@ static int manipulator_selectbuf(ScrArea *sa, ARegion *ar, short *mval, float ho } /* return 0; nothing happened */ -int BIF_do_manipulator(bContext *C, short mval[2]) +int BIF_do_manipulator(bContext *C, struct wmEvent *event, wmOperator *op) { ScrArea *sa= CTX_wm_area(C); View3D *v3d= sa->spacedata.first; ARegion *ar= CTX_wm_region(C); RegionView3D *rv3d= ar->regiondata; + int constraint_axis[3] = {0, 0, 0}; int val; - int shift= 0; // XXX - + int shift = event->shift; + if(!(v3d->twflag & V3D_USE_MANIPULATOR)) return 0; if(!(v3d->twflag & V3D_DRAW_MANIPULATOR)) return 0; - + // find the hotspots first test narrow hotspot - val= manipulator_selectbuf(sa, ar, mval, 0.5f*(float)U.tw_hotspot); + val= manipulator_selectbuf(sa, ar, event->mval, 0.5f*(float)U.tw_hotspot); if(val) { - - // XXX checkFirstTime(); // TEMPORARY, check this before doing any transform call. - + // drawflags still global, for drawing call above - drawflags= manipulator_selectbuf(sa, ar, mval, 0.2f*(float)U.tw_hotspot); + drawflags= manipulator_selectbuf(sa, ar, event->mval, 0.2f*(float)U.tw_hotspot); if(drawflags==0) drawflags= val; if (drawflags & MAN_TRANS_C) { - initManipulator(TFM_TRANSLATION); switch(drawflags) { case MAN_TRANS_C: break; case MAN_TRANS_X: if(shift) { - drawflags= MAN_TRANS_Y|MAN_TRANS_Z; - BIF_setDualAxisConstraint(rv3d->twmat[1], rv3d->twmat[2], " Y+Z"); + constraint_axis[1] = 1; + constraint_axis[2] = 1; } else - BIF_setSingleAxisConstraint(rv3d->twmat[0], " X"); + constraint_axis[0] = 1; break; case MAN_TRANS_Y: if(shift) { - drawflags= MAN_TRANS_X|MAN_TRANS_Z; - BIF_setDualAxisConstraint(rv3d->twmat[0], rv3d->twmat[2], " X+Z"); + constraint_axis[0] = 1; + constraint_axis[2] = 1; } else - BIF_setSingleAxisConstraint(rv3d->twmat[1], " Y"); + constraint_axis[1] = 1; break; case MAN_TRANS_Z: if(shift) { - drawflags= MAN_TRANS_X|MAN_TRANS_Y; - BIF_setDualAxisConstraint(rv3d->twmat[0], rv3d->twmat[1], " X+Y"); + constraint_axis[0] = 1; + constraint_axis[1] = 1; } else - BIF_setSingleAxisConstraint(rv3d->twmat[2], " Z"); + constraint_axis[2] = 1; break; } - ManipulatorTransform(); + RNA_boolean_set_array(op->ptr, "constraint_axis", constraint_axis); + WM_operator_name_call(C, "TFM_OT_translation", WM_OP_INVOKE_REGION_WIN, op->ptr); } else if (drawflags & MAN_SCALE_C) { - initManipulator(TFM_RESIZE); switch(drawflags) { case MAN_SCALE_X: if(shift) { - drawflags= MAN_SCALE_Y|MAN_SCALE_Z; - BIF_setDualAxisConstraint(rv3d->twmat[1], rv3d->twmat[2], " Y+Z"); + constraint_axis[1] = 1; + constraint_axis[2] = 1; } else - BIF_setSingleAxisConstraint(rv3d->twmat[0], " X"); + constraint_axis[0] = 1; break; case MAN_SCALE_Y: if(shift) { - drawflags= MAN_SCALE_X|MAN_SCALE_Z; - BIF_setDualAxisConstraint(rv3d->twmat[0], rv3d->twmat[2], " X+Z"); + constraint_axis[0] = 1; + constraint_axis[2] = 1; } else - BIF_setSingleAxisConstraint(rv3d->twmat[1], " Y"); + constraint_axis[1] = 1; break; case MAN_SCALE_Z: if(shift) { - drawflags= MAN_SCALE_X|MAN_SCALE_Y; - BIF_setDualAxisConstraint(rv3d->twmat[0], rv3d->twmat[1], " X+Y"); + constraint_axis[0] = 1; + constraint_axis[1] = 1; } else - BIF_setSingleAxisConstraint(rv3d->twmat[2], " Z"); + constraint_axis[2] = 1; break; } - ManipulatorTransform(); + RNA_boolean_set_array(op->ptr, "constraint_axis", constraint_axis); + WM_operator_name_call(C, "TFM_OT_resize", WM_OP_INVOKE_REGION_WIN, op->ptr); } - else if (drawflags == MAN_ROT_T) { /* trackbal need special case, init is different */ - initManipulator(TFM_TRACKBALL); - ManipulatorTransform(); + else if (drawflags == MAN_ROT_T) { /* trackball need special case, init is different */ + WM_operator_name_call(C, "TFM_OT_trackball", WM_OP_INVOKE_REGION_WIN, op->ptr); } else if (drawflags & MAN_ROT_C) { - initManipulator(TFM_ROTATION); switch(drawflags) { case MAN_ROT_X: - BIF_setSingleAxisConstraint(rv3d->twmat[0], " X"); + constraint_axis[0] = 1; break; case MAN_ROT_Y: - BIF_setSingleAxisConstraint(rv3d->twmat[1], " Y"); + constraint_axis[1] = 1; break; case MAN_ROT_Z: - BIF_setSingleAxisConstraint(rv3d->twmat[2], " Z"); + constraint_axis[2] = 1; break; } - ManipulatorTransform(); + RNA_boolean_set_array(op->ptr, "constraint_axis", constraint_axis); + WM_operator_name_call(C, "TFM_OT_rotation", WM_OP_INVOKE_REGION_WIN, op->ptr); } } /* after transform, restore drawflags */ drawflags= 0xFFFF; - + return val; } diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index 9e4115f38f0..97fb3531718 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -89,6 +89,7 @@ char OP_SHEAR[] = "TFM_OT_shear"; char OP_WARP[] = "TFM_OT_warp"; char OP_SHRINK_FATTEN[] = "TFM_OT_shrink_fatten"; char OP_TILT[] = "TFM_OT_tilt"; +char OP_TRACKBALL[] = "TFM_OT_trackball"; TransformModeItem transform_modes[] = @@ -101,6 +102,7 @@ TransformModeItem transform_modes[] = {OP_WARP, TFM_WARP}, {OP_SHRINK_FATTEN, TFM_SHRINKFATTEN}, {OP_TILT, TFM_TILT}, + {OP_TRACKBALL, TFM_TRACKBALL}, {NULL, 0} }; @@ -111,7 +113,7 @@ static int select_orientation_exec(bContext *C, wmOperator *op) if(orientation == V3D_MANIP_CUSTOM) orientation += custom_index; - + BIF_selectTransformOrientationValue(C, orientation); return OPERATOR_FINISHED; @@ -121,15 +123,15 @@ static int select_orientation_invoke(bContext *C, wmOperator *op, wmEvent *event { uiPopupMenu *pup; uiLayout *layout; - + pup= uiPupMenuBegin(C, "Orientation", 0); layout= uiPupMenuLayout(pup); BIF_menuTransformOrientation(C, layout, NULL); uiPupMenuEnd(C, pup); - + return OPERATOR_CANCELLED; } - + void TFM_OT_select_orientation(struct wmOperatorType *ot) { static EnumPropertyItem orientation_items[]= { @@ -183,27 +185,27 @@ static int transformops_data(bContext *C, wmOperator *op, wmEvent *event) } retval = initTransform(C, t, op, event, mode); - + /* store data */ op->customdata = t; } - + return retval; /* return 0 on error */ } static int transform_modal(bContext *C, wmOperator *op, wmEvent *event) { int exit_code; - + TransInfo *t = op->customdata; - + transformEvent(t, event); - + transformApply(C, t); - - + + exit_code = transformEnd(C, t); - + if (exit_code != OPERATOR_RUNNING_MODAL) { transformops_exit(C, op); @@ -215,11 +217,11 @@ static int transform_modal(bContext *C, wmOperator *op, wmEvent *event) static int transform_cancel(bContext *C, wmOperator *op) { TransInfo *t = op->customdata; - + t->state = TRANS_CANCEL; transformEnd(C, t); transformops_exit(C, op); - + return OPERATOR_CANCELLED; } @@ -237,11 +239,11 @@ static int transform_exec(bContext *C, wmOperator *op) t->options |= CTX_AUTOCONFIRM; transformApply(C, t); - + transformEnd(C, t); transformops_exit(C, op); - + return OPERATOR_FINISHED; } @@ -279,7 +281,7 @@ void Properties_Snapping(struct wmOperatorType *ot, short align) RNA_def_boolean(ot->srna, "snap", 0, "Snap to Point", ""); RNA_def_enum(ot->srna, "snap_mode", snap_mode_types, 0, "Mode", ""); RNA_def_float_vector(ot->srna, "snap_point", 3, NULL, -FLT_MAX, FLT_MAX, "Point", "", -FLT_MAX, FLT_MAX); - + if (align) { RNA_def_boolean(ot->srna, "snap_align", 0, "Align with Point Normal", ""); @@ -314,7 +316,7 @@ void TFM_OT_translation(struct wmOperatorType *ot) RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", ""); Properties_Constraints(ot); - + Properties_Snapping(ot, 1); } @@ -339,10 +341,32 @@ void TFM_OT_resize(struct wmOperatorType *ot) RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", ""); Properties_Constraints(ot); - + Properties_Snapping(ot, 0); } + +void TFM_OT_trackball(struct wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Trackball"; + ot->idname = OP_TRACKBALL; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + + /* api callbacks */ + ot->invoke = transform_invoke; + ot->exec = transform_exec; + ot->modal = transform_modal; + ot->cancel = transform_cancel; + ot->poll = ED_operator_areaactive; + + RNA_def_float_vector(ot->srna, "value", 2, VecOne, -FLT_MAX, FLT_MAX, "angle", "", -FLT_MAX, FLT_MAX); + + Properties_Proportional(ot); + + RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", ""); +} + void TFM_OT_rotation(struct wmOperatorType *ot) { /* identifiers */ @@ -364,7 +388,7 @@ void TFM_OT_rotation(struct wmOperatorType *ot) RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", ""); Properties_Constraints(ot); - + Properties_Snapping(ot, 0); } @@ -547,10 +571,11 @@ void transform_operatortypes(void) WM_operatortype_append(TFM_OT_warp); WM_operatortype_append(TFM_OT_shrink_fatten); WM_operatortype_append(TFM_OT_tilt); + WM_operatortype_append(TFM_OT_trackball); WM_operatortype_append(TFM_OT_select_orientation); } - + void transform_keymap_for_space(struct wmWindowManager *wm, struct ListBase *keymap, int spaceid) { wmKeymapItem *km; @@ -558,9 +583,9 @@ void transform_keymap_for_space(struct wmWindowManager *wm, struct ListBase *key { case SPACE_VIEW3D: km = WM_keymap_add_item(keymap, "TFM_OT_translation", GKEY, KM_PRESS, 0, 0); - + km= WM_keymap_add_item(keymap, "TFM_OT_translation", EVT_TWEAK_S, KM_ANY, 0, 0); - + km = WM_keymap_add_item(keymap, "TFM_OT_rotation", RKEY, KM_PRESS, 0, 0); km = WM_keymap_add_item(keymap, "TFM_OT_resize", SKEY, KM_PRESS, 0, 0); @@ -568,9 +593,9 @@ void transform_keymap_for_space(struct wmWindowManager *wm, struct ListBase *key km = WM_keymap_add_item(keymap, "TFM_OT_warp", WKEY, KM_PRESS, KM_SHIFT, 0); km = WM_keymap_add_item(keymap, "TFM_OT_tosphere", SKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0); - + km = WM_keymap_add_item(keymap, "TFM_OT_shear", SKEY, KM_PRESS, KM_ALT|KM_CTRL|KM_SHIFT, 0); - + km = WM_keymap_add_item(keymap, "TFM_OT_shrink_fatten", SKEY, KM_PRESS, KM_ALT, 0); km = WM_keymap_add_item(keymap, "TFM_OT_tilt", TKEY, KM_PRESS, 0, 0); @@ -581,55 +606,55 @@ void transform_keymap_for_space(struct wmWindowManager *wm, struct ListBase *key case SPACE_ACTION: km= WM_keymap_add_item(keymap, "TFM_OT_transform", GKEY, KM_PRESS, 0, 0); RNA_int_set(km->ptr, "mode", TFM_TIME_TRANSLATE); - + km= WM_keymap_add_item(keymap, "TFM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0); RNA_int_set(km->ptr, "mode", TFM_TIME_TRANSLATE); - + km= WM_keymap_add_item(keymap, "TFM_OT_transform", EKEY, KM_PRESS, 0, 0); RNA_int_set(km->ptr, "mode", TFM_TIME_EXTEND); - + km= WM_keymap_add_item(keymap, "TFM_OT_transform", SKEY, KM_PRESS, 0, 0); RNA_int_set(km->ptr, "mode", TFM_TIME_SCALE); - + km= WM_keymap_add_item(keymap, "TFM_OT_transform", TKEY, KM_PRESS, 0, 0); RNA_int_set(km->ptr, "mode", TFM_TIME_SLIDE); break; case SPACE_IPO: km= WM_keymap_add_item(keymap, "TFM_OT_translation", GKEY, KM_PRESS, 0, 0); - + km= WM_keymap_add_item(keymap, "TFM_OT_translation", EVT_TWEAK_S, KM_ANY, 0, 0); - + // XXX the 'mode' identifier here is not quite right km= WM_keymap_add_item(keymap, "TFM_OT_transform", EKEY, KM_PRESS, 0, 0); RNA_int_set(km->ptr, "mode", TFM_TIME_EXTEND); - + km = WM_keymap_add_item(keymap, "TFM_OT_rotation", RKEY, KM_PRESS, 0, 0); - + km = WM_keymap_add_item(keymap, "TFM_OT_resize", SKEY, KM_PRESS, 0, 0); break; case SPACE_NODE: km= WM_keymap_add_item(keymap, "TFM_OT_translation", GKEY, KM_PRESS, 0, 0); - + km= WM_keymap_add_item(keymap, "TFM_OT_translation", EVT_TWEAK_A, KM_ANY, 0, 0); km= WM_keymap_add_item(keymap, "TFM_OT_translation", EVT_TWEAK_S, KM_ANY, 0, 0); - + km = WM_keymap_add_item(keymap, "TFM_OT_rotation", RKEY, KM_PRESS, 0, 0); - + km = WM_keymap_add_item(keymap, "TFM_OT_resize", SKEY, KM_PRESS, 0, 0); break; case SPACE_SEQ: km= WM_keymap_add_item(keymap, "TFM_OT_translation", GKEY, KM_PRESS, 0, 0); - + km= WM_keymap_add_item(keymap, "TFM_OT_translation", EVT_TWEAK_S, KM_ANY, 0, 0); - + km= WM_keymap_add_item(keymap, "TFM_OT_transform", EKEY, KM_PRESS, 0, 0); RNA_int_set(km->ptr, "mode", TFM_TIME_EXTEND); break; case SPACE_IMAGE: km = WM_keymap_add_item(keymap, "TFM_OT_translation", GKEY, KM_PRESS, 0, 0); - + km= WM_keymap_add_item(keymap, "TFM_OT_translation", EVT_TWEAK_S, KM_ANY, 0, 0); - + km = WM_keymap_add_item(keymap, "TFM_OT_rotation", RKEY, KM_PRESS, 0, 0); km = WM_keymap_add_item(keymap, "TFM_OT_resize", SKEY, KM_PRESS, 0, 0); |