Blender V4.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
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/* -------------------------------------------------------------------- */
25static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
26{
27 View3D *v3d = CTX_wm_view3d(C);
29 ARegion *region = CTX_wm_region(C);
30
31 if (rv3d) {
33 float new_ofs[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, nullptr);
42
43 if (ED_view3d_autodist(region, v3d, event->mval, new_ofs, nullptr)) {
44 /* pass */
45 }
46 else {
47 /* fallback to simple pan */
48 negate_v3_v3(new_ofs, rv3d->ofs);
49 ED_view3d_win_to_3d_int(v3d, region, new_ofs, event->mval, new_ofs);
50 }
51 negate_v3(new_ofs);
52
53 V3D_SmoothParams sview = {nullptr};
54 sview.ofs = new_ofs;
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
Depsgraph * CTX_data_ensure_evaluated_depsgraph(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])
MINLINE void negate_v3(float r[3])
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])
bool ED_view3d_autodist(ARegion *region, View3D *v3d, const int mval[2], float mouse_worldloc[3], const float fallback_depth_pt[3])
void ED_view3d_depth_override(Depsgraph *depsgraph, ARegion *region, View3D *v3d, Object *obact, eV3DDepthOverrideMode mode, ViewDepths **r_depths)
void view3d_operator_needs_opengl(const bContext *C)
@ V3D_DEPTH_NO_GPENCIL
Definition ED_view3d.hh:188
Read Guarded memory(de)allocation.
const Depsgraph * depsgraph
const char * undo_str
int mval[2]
Definition WM_types.hh:728
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(* invoke)(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1022
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_pick(wmOperatorType *ot)
static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
wmOperatorType * ot
Definition wm_files.cc:4125
int WM_operator_smooth_viewtx_get(const wmOperator *op)