Blender V5.0
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
8
9#include "BLI_math_vector.h"
10
11#include "BKE_context.hh"
12
13#include "WM_api.hh"
14
15#include "view3d_intern.hh"
16
17#include "view3d_navigate.hh" /* own include */
18
19/* -------------------------------------------------------------------- */
22
24{
25 View3D *v3d = CTX_wm_view3d(C);
27 Scene *scene = CTX_data_scene(C);
28
29 if (rv3d) {
30 ARegion *region = CTX_wm_region(C);
31 const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
32
34
35 /* non camera center */
36 float ofs_new[3];
37 negate_v3_v3(ofs_new, scene->cursor.location);
38
39 V3D_SmoothParams sview = {nullptr};
40 sview.ofs = ofs_new;
41 sview.undo_str = op->type->name;
42 ED_view3d_smooth_view(C, v3d, region, smooth_viewtx, &sview);
43
44 /* Smooth view does view-lock #RV3D_BOXVIEW copy. */
45 }
46
47 return OPERATOR_FINISHED;
48}
49
51{
52 /* identifiers */
53 ot->name = "Center View to Cursor";
54 ot->description = "Center the view so that the cursor is in the middle of the view";
55 ot->idname = "VIEW3D_OT_view_center_cursor";
56
57 /* API callbacks. */
60
61 /* flags */
62 ot->flag = 0;
63}
64
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])
@ OPERATOR_FINISHED
#define C
Definition RandGen.cpp:29
View3DCursor cursor
const char * undo_str
const char * name
Definition WM_types.hh:1033
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)
static wmOperatorStatus viewcenter_cursor_exec(bContext *C, wmOperator *op)
void VIEW3D_OT_view_center_cursor(wmOperatorType *ot)
wmOperatorType * ot
Definition wm_files.cc:4237
int WM_operator_smooth_viewtx_get(const wmOperator *op)