Image/Clip Space: Add view center to cursor operators
D5932 by @a.monti with edits
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
* \{ */
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
* \{ */
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user