diff options
author | Mike Erwin <significant.bit@gmail.com> | 2011-06-25 22:51:29 +0400 |
---|---|---|
committer | Mike Erwin <significant.bit@gmail.com> | 2011-06-25 22:51:29 +0400 |
commit | e61063f04296d4af023718485ba0ac52b7a42a5a (patch) | |
tree | 9ada035f5829d02b78458853fc4be955ca70aa78 /source/blender/editors/space_image | |
parent | 651df035f790b6e82dec074972aad52d616b2d47 (diff) |
NDOF pan/zoom/fit working in image/uv editor
Diffstat (limited to 'source/blender/editors/space_image')
-rw-r--r-- | source/blender/editors/space_image/image_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_ops.c | 54 | ||||
-rw-r--r-- | source/blender/editors/space_image/space_image.c | 4 |
3 files changed, 59 insertions, 0 deletions
diff --git a/source/blender/editors/space_image/image_intern.h b/source/blender/editors/space_image/image_intern.h index e9e77ddf430..399157da85c 100644 --- a/source/blender/editors/space_image/image_intern.h +++ b/source/blender/editors/space_image/image_intern.h @@ -73,6 +73,7 @@ void IMAGE_OT_view_zoom(struct wmOperatorType *ot); void IMAGE_OT_view_zoom_in(struct wmOperatorType *ot); void IMAGE_OT_view_zoom_out(struct wmOperatorType *ot); void IMAGE_OT_view_zoom_ratio(struct wmOperatorType *ot); +void IMAGE_OT_view_ndof(struct wmOperatorType *ot); void IMAGE_OT_new(struct wmOperatorType *ot); void IMAGE_OT_open(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 10b8cb238aa..fc7b84e21ae 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -437,6 +437,60 @@ void IMAGE_OT_view_zoom(wmOperatorType *ot) "Factor", "Zoom factor, values higher than 1.0 zoom in, lower values zoom out.", -FLT_MAX, FLT_MAX); } +/********************** NDOF operator *********************/ + +/* Combined pan/zoom from a 3D mouse device. + * Y zooms, XZ pans + * "view" (not "paper") control -- user moves the viewpoint, not the image being viewed + * that explains the negative signs in the code below + */ + +static int view_ndof_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + SpaceImage *sima= CTX_wm_space_image(C); + ARegion *ar= CTX_wm_region(C); + + wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; + + float dt = ndof->dt > 0.25f ? 0.0125f : ndof->dt; + /* this is probably the first event for this motion, so set dt to something reasonable + * TODO: replace such guesswork with a flag or field from the NDOF manager + */ + + /* tune these until it feels right */ + const float zoom_sensitivity = 0.5f; + const float pan_sensitivity = 300.f; + + float pan_x = pan_sensitivity * dt * -ndof->tx / sima->zoom; + float pan_y = pan_sensitivity * dt * -ndof->tz / sima->zoom; + + /* "mouse zoom" factor = 1 + (dx + dy) / 300 + * what about "ndof zoom" factor? should behave like this: + * at rest -> factor = 1 + * move forward -> factor > 1 + * move backward -> factor < 1 + */ + float zoom_factor = 1.f + zoom_sensitivity * dt * -ndof->ty; + + sima_zoom_set_factor(sima, ar, zoom_factor); + sima->xof += pan_x; + sima->yof += pan_y; + + ED_region_tag_redraw(ar); + + return OPERATOR_FINISHED; +} + +void IMAGE_OT_view_ndof(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "NDOF Pan/Zoom"; + ot->idname= "IMAGE_OT_view_ndof"; + + /* api callbacks */ + ot->invoke= view_ndof_invoke; +} + /********************** view all operator *********************/ /* Updates the fields of the View2D member of the SpaceImage struct. diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index 2e9544f5d20..afab4ede229 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -469,6 +469,7 @@ static void image_operatortypes(void) WM_operatortype_append(IMAGE_OT_view_zoom_in); WM_operatortype_append(IMAGE_OT_view_zoom_out); WM_operatortype_append(IMAGE_OT_view_zoom_ratio); + WM_operatortype_append(IMAGE_OT_view_ndof); WM_operatortype_append(IMAGE_OT_new); WM_operatortype_append(IMAGE_OT_open); @@ -518,6 +519,9 @@ static void image_keymap(struct wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "IMAGE_OT_view_pan", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0); WM_keymap_add_item(keymap, "IMAGE_OT_view_pan", MOUSEPAN, 0, 0, 0); + WM_keymap_add_item(keymap, "IMAGE_OT_view_all", NDOF_BUTTON_FIT, KM_PRESS, 0, 0); // or view selected? + WM_keymap_add_item(keymap, "IMAGE_OT_view_ndof", NDOF_MOTION, 0, 0, 0); + WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_in", WHEELINMOUSE, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_out", WHEELOUTMOUSE, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0); |