Blender V5.3
view3d_navigate_view_center_pick.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
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
19namespace blender {
20
21/* -------------------------------------------------------------------- */
24
26{
27 View3D *v3d = CTX_wm_view3d(C);
29 ARegion *region = CTX_wm_region(C);
30
31 if (rv3d) {
32 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
33 float ofs_new[3];
34 const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
35
37
39
40 /* Ensure the depth buffer is updated for #ED_view3d_autodist. */
41 ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, true, nullptr);
42
43 if (ED_view3d_autodist(region, v3d, event->mval, ofs_new, nullptr)) {
44 /* pass */
45 }
46 else {
47 /* fall back to simple pan */
48 negate_v3_v3(ofs_new, rv3d->ofs);
49 ED_view3d_win_to_3d_int(v3d, region, ofs_new, event->mval, ofs_new);
50 }
51 negate_v3(ofs_new);
52
53 V3D_SmoothParams sview = {nullptr};
54 sview.ofs = ofs_new;
55 sview.undo_str = op->type->name;
56
57 ED_view3d_smooth_view(C, v3d, region, smooth_viewtx, &sview);
58 }
59
60 return OPERATOR_FINISHED;
61}
62
64{
65 /* identifiers */
66 ot->name = "Center View to Mouse";
67 ot->description = "Center the view to the Z-depth position under the mouse cursor";
68 ot->idname = "VIEW3D_OT_view_center_pick";
69
70 /* API callbacks. */
73
74 /* flags */
75 ot->flag = 0;
76}
77
79
80} // namespace blender
#define C
Definition RandGen.cpp:29
BMesh Iterators.
MINLINE void negate_v3_v3(float r[3], const float a[3])
int WM_operator_smooth_viewtx_get(const wmOperator *op)
void view3d_operator_needs_gpu(const bContext *C)
bool ED_view3d_autodist(ARegion *region, View3D *v3d, const int mval[2], float mouse_worldloc[3], const float fallback_depth_pt[3])
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
bool view3d_location_poll(bContext *C)
MINLINE void negate_v3(float r[3])
RegionView3D * CTX_wm_region_view3d(const bContext *C)
void VIEW3D_OT_view_center_pick(wmOperatorType *ot)
static wmOperatorStatus viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void ED_view3d_depth_override(Depsgraph *depsgraph, ARegion *region, View3D *v3d, Object *obact, eV3DDepthOverrideMode mode, bool use_overlay, ViewDepths **r_depths)
void ED_view3d_smooth_view_force_finish(bContext *C, View3D *v3d, ARegion *region)
@ V3D_DEPTH_NO_GPENCIL
Definition ED_view3d.hh:209
void ED_view3d_win_to_3d_int(const View3D *v3d, const ARegion *region, const float depth_pt[3], const int mval[2], float r_out[3])
ARegion * CTX_wm_region(const bContext *C)
void ED_view3d_smooth_view(bContext *C, View3D *v3d, ARegion *region, int smooth_viewtx, const V3D_SmoothParams *sview)
View3D * CTX_wm_view3d(const bContext *C)
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
struct wmOperatorType * type