Blender V4.3
view3d_navigate_view_center_cursor.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "MEM_guardedalloc.h"
10
11#include "BLI_math_vector.h"
12
13#include "BKE_context.hh"
14
15#include "WM_api.hh"
16
17#include "view3d_intern.hh"
18
19#include "view3d_navigate.hh" /* own include */
20
21/* -------------------------------------------------------------------- */
26{
27 View3D *v3d = CTX_wm_view3d(C);
29 Scene *scene = CTX_data_scene(C);
30
31 if (rv3d) {
32 ARegion *region = CTX_wm_region(C);
33 const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
34
36
37 /* non camera center */
38 float new_ofs[3];
39 negate_v3_v3(new_ofs, scene->cursor.location);
40
41 V3D_SmoothParams sview = {nullptr};
42 sview.ofs = new_ofs;
43 sview.undo_str = op->type->name;
44 ED_view3d_smooth_view(C, v3d, region, smooth_viewtx, &sview);
45
46 /* Smooth view does view-lock #RV3D_BOXVIEW copy. */
47 }
48
49 return OPERATOR_FINISHED;
50}
51
53{
54 /* identifiers */
55 ot->name = "Center View to Cursor";
56 ot->description = "Center the view so that the cursor is in the middle of the view";
57 ot->idname = "VIEW3D_OT_view_center_cursor";
58
59 /* api callbacks */
62
63 /* flags */
64 ot->flag = 0;
65}
66
Scene * CTX_data_scene(const bContext *C)
RegionView3D * CTX_wm_region_view3d(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
View3D * CTX_wm_view3d(const bContext *C)
MINLINE void negate_v3_v3(float r[3], const float a[3])
Read Guarded memory(de)allocation.
const char * undo_str
const char * name
Definition WM_types.hh:990
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1042
const char * idname
Definition WM_types.hh:992
int(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1006
const char * description
Definition WM_types.hh:996
struct wmOperatorType * type
bool view3d_location_poll(bContext *C)
void ED_view3d_smooth_view(bContext *C, View3D *v3d, ARegion *region, int smooth_viewtx, const V3D_SmoothParams *sview)
void ED_view3d_smooth_view_force_finish(bContext *C, View3D *v3d, ARegion *region)
void VIEW3D_OT_view_center_cursor(wmOperatorType *ot)
static int viewcenter_cursor_exec(bContext *C, wmOperator *op)
wmOperatorType * ot
Definition wm_files.cc:4125
int WM_operator_smooth_viewtx_get(const wmOperator *op)