Image/Clip Space: Add view center to cursor operators
authorCampbell Barton <ideasman42@gmail.com>
Tue, 1 Oct 2019 10:19:44 +0000 (20:19 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 1 Oct 2019 10:20:53 +0000 (20:20 +1000)
D5932 by @a.monti with edits

12 files changed:
release/scripts/presets/keyconfig/keymap_data/blender_default.py
release/scripts/startup/bl_ui/space_clip.py
release/scripts/startup/bl_ui/space_image.py
source/blender/editors/include/ED_image.h
source/blender/editors/space_clip/clip_intern.h
source/blender/editors/space_clip/clip_ops.c
source/blender/editors/space_clip/space_clip.c
source/blender/editors/space_image/image_edit.c
source/blender/editors/space_image/image_intern.h
source/blender/editors/space_image/image_ops.c
source/blender/editors/space_image/space_image.c
source/blender/editors/uvedit/uvedit_ops.c

index 1839dd5f322b0153314f23263cbb0179268aa33e..fafe950dfd8c0f74f81ea294e2c6072ab034fe22 100644 (file)
@@ -1587,6 +1587,11 @@ def km_image(params):
         ("image.clear_render_border", {"type": 'B', "value": 'PRESS', "ctrl": True, "alt": True}, None),
     ])
 
+    if params.legacy:
+        items.extend([
+            ("image.view_center_cursor", {"type": 'HOME', "value": 'PRESS', "alt": True}, None),
+        ])
+
     return keymap
 
 
@@ -2686,6 +2691,11 @@ def km_clip_editor(params):
         ("clip.paste_tracks", {"type": 'V', "value": 'PRESS', "ctrl": True}, None),
     ])
 
+    if params.legacy:
+        items.extend([
+            ("clip.view_center_cursor", {"type": 'HOME', "value": 'PRESS', "alt": True}, None),
+        ])
+
     return keymap
 
 
@@ -6201,7 +6211,7 @@ def generate_keymaps(params=None):
         km_3d_view_tool_edit_gpencil_select_box(params),
         km_3d_view_tool_edit_gpencil_select_circle(params),
         km_3d_view_tool_edit_gpencil_select_lasso(params),
-        km_3d_view_tool_edit_gpencil_extrude(params), 
+        km_3d_view_tool_edit_gpencil_extrude(params),
         km_3d_view_tool_edit_gpencil_radius(params),
         km_3d_view_tool_edit_gpencil_bend(params),
         km_3d_view_tool_edit_gpencil_shear(params),
index e58d5117bc3e9da55c7d909cef807b751b15f786..b5154e72de6c3c9446b5217d5dafb69e075fd133 100644 (file)
@@ -1255,6 +1255,7 @@ class CLIP_MT_view(Menu):
             layout.operator("clip.view_selected")
             layout.operator("clip.view_all")
             layout.operator("clip.view_all", text="View Fit").fit_view = True
+            layout.operator("clip.view_center_cursor")
 
             layout.separator()
 
index 5e05c49b56701c69470ecd1e258c08f21894e9d4..0044475d67d969d56b28ffaedbcdc3d3f328927d 100644 (file)
@@ -113,6 +113,8 @@ class IMAGE_MT_view(Menu):
         layout.operator("image.view_all", text="Frame All")
         layout.operator("image.view_all", text="Frame All Fit").fit_view = True
 
+        layout.operator("image.view_center_cursor", text="Center View to Cursor")
+
         layout.separator()
 
         if show_render:
index 7d69f86dbf8217d0a3688368b24855b3202c2a96..69742af9f50b80f2923b596281d1afaccb28feca 100644 (file)
@@ -77,6 +77,7 @@ void ED_image_mouse_pos(struct SpaceImage *sima,
                         struct ARegion *ar,
                         const int mval[2],
                         float co[2]);
+void ED_image_view_center_to_point(struct SpaceImage *sima, float x, float y);
 void ED_image_point_pos(
     struct SpaceImage *sima, struct ARegion *ar, float x, float y, float *xr, float *yr);
 void ED_image_point_pos__reverse(struct SpaceImage *sima,
@@ -94,6 +95,7 @@ bool ED_space_image_paint_curve(const struct bContext *C);
 bool ED_space_image_check_show_maskedit(struct SpaceImage *sima, struct ViewLayer *view_layer);
 bool ED_space_image_maskedit_poll(struct bContext *C);
 bool ED_space_image_maskedit_mask_poll(struct bContext *C);
+bool ED_space_image_cursor_poll(struct bContext *C);
 
 void ED_image_draw_info(struct Scene *scene,
                         struct ARegion *ar,
index 1fae4c91a48b0b331470c22835baa2e87e2e23f7..bd54d4f0016ded5dfee8268dd13bb4ff554ab0e1 100644 (file)
@@ -94,6 +94,7 @@ void CLIP_OT_view_zoom_out(struct wmOperatorType *ot);
 void CLIP_OT_view_zoom_ratio(struct wmOperatorType *ot);
 void CLIP_OT_view_all(struct wmOperatorType *ot);
 void CLIP_OT_view_selected(struct wmOperatorType *ot);
+void CLIP_OT_view_center_cursor(struct wmOperatorType *ot);
 void CLIP_OT_change_frame(wmOperatorType *ot);
 void CLIP_OT_rebuild_proxy(struct wmOperatorType *ot);
 void CLIP_OT_mode_set(struct wmOperatorType *ot);
index 446e3408d8c7bbacb213865bd844403ab856cb5d..192449a219d87248fa18ec7d7e7e58ffd9eaddd3 100644 (file)
@@ -992,6 +992,36 @@ void CLIP_OT_view_all(wmOperatorType *ot)
 }
 /** \} */
 
+/* -------------------------------------------------------------------- */
+/** \name Center View To Cursor Operator
+ * \{ */
+
+static int view_center_cursor_exec(bContext *C, wmOperator *UNUSED(op))
+{
+  SpaceClip *sc = CTX_wm_space_clip(C);
+  ARegion *ar = CTX_wm_region(C);
+
+  clip_view_center_to_point(sc, sc->cursor[0], sc->cursor[1]);
+
+  ED_region_tag_redraw(ar);
+
+  return OPERATOR_FINISHED;
+}
+
+void CLIP_OT_view_center_cursor(wmOperatorType *ot)
+{
+  /* identifiers */
+  ot->name = "Center View to Cursor";
+  ot->description = "Center the view so that the cursor is in the middle of the view";
+  ot->idname = "CLIP_OT_view_center_cursor";
+
+  /* api callbacks */
+  ot->exec = view_center_cursor_exec;
+  ot->poll = ED_space_clip_maskedit_poll;
+}
+
+/** \} */
+
 /* -------------------------------------------------------------------- */
 /** \name View Selected Operator
  * \{ */
index 2964a95648ab5c0bcffea65f352525e2978c9711..16305a9b17bfbf1be3f92c23052ba3d432324efc 100644 (file)
@@ -443,6 +443,7 @@ static void clip_operatortypes(void)
   WM_operatortype_append(CLIP_OT_view_zoom_ratio);
   WM_operatortype_append(CLIP_OT_view_all);
   WM_operatortype_append(CLIP_OT_view_selected);
+  WM_operatortype_append(CLIP_OT_view_center_cursor);
   WM_operatortype_append(CLIP_OT_change_frame);
   WM_operatortype_append(CLIP_OT_rebuild_proxy);
   WM_operatortype_append(CLIP_OT_mode_set);
index ccd0a2bfd792cbbcf423ba006209cf3ee78cd957..ec2b1cc7fbe58590bce517e9827767726932b785 100644 (file)
@@ -301,6 +301,18 @@ void ED_image_mouse_pos(SpaceImage *sima, ARegion *ar, const int mval[2], float
   co[1] = ((mval[1] - sy) / zoomy) / height;
 }
 
+void ED_image_view_center_to_point(SpaceImage *sima, float x, float y)
+{
+  int width, height;
+  float aspx, aspy;
+
+  ED_space_image_get_size(sima, &width, &height);
+  ED_space_image_get_aspect(sima, &aspx, &aspy);
+
+  sima->xof = (x - 0.5f) * width * aspx;
+  sima->yof = (y - 0.5f) * height * aspy;
+}
+
 void ED_image_point_pos(SpaceImage *sima, ARegion *ar, float x, float y, float *xr, float *yr)
 {
   int sx, sy, width, height;
@@ -476,3 +488,9 @@ bool ED_space_image_maskedit_mask_poll(bContext *C)
 
   return false;
 }
+
+bool ED_space_image_cursor_poll(bContext *C)
+{
+  return ED_operator_uvedit_space_image(C) || ED_space_image_maskedit_poll(C) ||
+         ED_space_image_paint_curve(C);
+}
index 1abb6715fdb693dd28670486188f2f3beb0ef362..6f1ce01ceacba8ba636d4a899e2c35d35c45b281 100644 (file)
@@ -44,10 +44,12 @@ void draw_image_sample_line(struct SpaceImage *sima);
 
 /* image_ops.c */
 bool space_image_main_region_poll(struct bContext *C);
+bool space_image_view_center_cursor_poll(struct bContext *C);
 
 void IMAGE_OT_view_all(struct wmOperatorType *ot);
 void IMAGE_OT_view_pan(struct wmOperatorType *ot);
 void IMAGE_OT_view_selected(struct wmOperatorType *ot);
+void IMAGE_OT_view_center_cursor(struct wmOperatorType *ot);
 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);
index 23336e369924d887089814740b1adcedaa41eb6d..bed178e5a68c2f75eeb073b147f7922069d375cb 100644 (file)
@@ -823,6 +823,36 @@ void IMAGE_OT_view_all(wmOperatorType *ot)
 
 /** \} */
 
+/* -------------------------------------------------------------------- */
+/** \name Center View To Cursor Operator
+ * \{ */
+
+static int view_center_cursor_exec(bContext *C, wmOperator *UNUSED(op))
+{
+  SpaceImage *sima = CTX_wm_space_image(C);
+  ARegion *ar = CTX_wm_region(C);
+
+  ED_image_view_center_to_point(sima, sima->cursor[0], sima->cursor[1]);
+
+  ED_region_tag_redraw(ar);
+
+  return OPERATOR_FINISHED;
+}
+
+void IMAGE_OT_view_center_cursor(wmOperatorType *ot)
+{
+  /* identifiers */
+  ot->name = "Center View to Cursor";
+  ot->description = "Center the view so that the cursor is in the middle of the view";
+  ot->idname = "IMAGE_OT_view_center_cursor";
+
+  /* api callbacks */
+  ot->exec = view_center_cursor_exec;
+  ot->poll = ED_space_image_cursor_poll;
+}
+
+/** \} */
+
 /* -------------------------------------------------------------------- */
 /** \name View Selected Operator
  * \{ */
index 5fa4fe3e077578160eaa1879ee31770272d89b03..749266149c1b3b3a4b627b08ad33d6824b1ed299 100644 (file)
@@ -207,6 +207,7 @@ static void image_operatortypes(void)
   WM_operatortype_append(IMAGE_OT_view_all);
   WM_operatortype_append(IMAGE_OT_view_pan);
   WM_operatortype_append(IMAGE_OT_view_selected);
+  WM_operatortype_append(IMAGE_OT_view_center_cursor);
   WM_operatortype_append(IMAGE_OT_view_zoom);
   WM_operatortype_append(IMAGE_OT_view_zoom_in);
   WM_operatortype_append(IMAGE_OT_view_zoom_out);
index 57e2a84d248d73c22cee475f68035db36a724a88..0d258ba542bc52aa33b7805bd2611f3d2699af86 100644 (file)
@@ -4872,12 +4872,6 @@ static void UV_OT_reveal(wmOperatorType *ot)
 /** \name Set 2D Cursor Operator
  * \{ */
 
-static bool uv_set_2d_cursor_poll(bContext *C)
-{
-  return ED_operator_uvedit_space_image(C) || ED_space_image_maskedit_poll(C) ||
-         ED_space_image_paint_curve(C);
-}
-
 static int uv_set_2d_cursor_exec(bContext *C, wmOperator *op)
 {
   SpaceImage *sima = CTX_wm_space_image(C);
@@ -4923,7 +4917,7 @@ static void UV_OT_cursor_set(wmOperatorType *ot)
   /* api callbacks */
   ot->exec = uv_set_2d_cursor_exec;
   ot->invoke = uv_set_2d_cursor_invoke;
-  ot->poll = uv_set_2d_cursor_poll;
+  ot->poll = ED_space_image_cursor_poll;
 
   /* properties */
   RNA_def_float_vector(ot->srna,