From 093a4d63f3bac26427028e7a7eecae8e2ab2960a Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Mon, 10 Jul 2023 21:48:38 +0200 Subject: [PATCH] Cleanup: Move some space_view3d files to C++ See: #103343 Pull Request: https://projects.blender.org/blender/blender/pulls/109936 --- .../editors/space_view3d/CMakeLists.txt | 26 +- .../editors/space_view3d/space_view3d.cc | 4 +- .../editors/space_view3d/view3d_navigate.cc | 4 +- .../{view3d_navigate.h => view3d_navigate.hh} | 176 +++++----- ...igate_dolly.c => view3d_navigate_dolly.cc} | 33 +- ..._navigate_fly.c => view3d_navigate_fly.cc} | 44 +-- ...avigate_move.c => view3d_navigate_move.cc} | 4 +- ...avigate_ndof.c => view3d_navigate_ndof.cc} | 14 +- ...avigate_roll.c => view3d_navigate_roll.cc} | 67 ++-- ...ate_rotate.c => view3d_navigate_rotate.cc} | 12 +- ...thview.c => view3d_navigate_smoothview.cc} | 89 +++--- ...avigate_walk.c => view3d_navigate_walk.cc} | 96 +++--- ...avigate_zoom.c => view3d_navigate_zoom.cc} | 50 +-- ...order.c => view3d_navigate_zoom_border.cc} | 30 +- .../{view3d_ops.c => view3d_ops.cc} | 7 +- .../{view3d_view.c => view3d_view.cc} | 300 +++++++++--------- 16 files changed, 464 insertions(+), 492 deletions(-) rename source/blender/editors/space_view3d/{view3d_navigate.h => view3d_navigate.hh} (70%) rename source/blender/editors/space_view3d/{view3d_navigate_dolly.c => view3d_navigate_dolly.cc} (90%) rename source/blender/editors/space_view3d/{view3d_navigate_fly.c => view3d_navigate_fly.cc} (96%) rename source/blender/editors/space_view3d/{view3d_navigate_move.c => view3d_navigate_move.cc} (97%) rename source/blender/editors/space_view3d/{view3d_navigate_ndof.c => view3d_navigate_ndof.cc} (97%) rename source/blender/editors/space_view3d/{view3d_navigate_roll.c => view3d_navigate_roll.cc} (81%) rename source/blender/editors/space_view3d/{view3d_navigate_rotate.c => view3d_navigate_rotate.cc} (96%) rename source/blender/editors/space_view3d/{view3d_navigate_smoothview.c => view3d_navigate_smoothview.cc} (85%) rename source/blender/editors/space_view3d/{view3d_navigate_walk.c => view3d_navigate_walk.cc} (94%) rename source/blender/editors/space_view3d/{view3d_navigate_zoom.c => view3d_navigate_zoom.cc} (92%) rename source/blender/editors/space_view3d/{view3d_navigate_zoom_border.c => view3d_navigate_zoom_border.cc} (84%) rename source/blender/editors/space_view3d/{view3d_ops.c => view3d_ops.cc} (98%) rename source/blender/editors/space_view3d/{view3d_view.c => view3d_view.cc} (84%) diff --git a/source/blender/editors/space_view3d/CMakeLists.txt b/source/blender/editors/space_view3d/CMakeLists.txt index 3393ed50fcf..9b3d7b8e479 100644 --- a/source/blender/editors/space_view3d/CMakeLists.txt +++ b/source/blender/editors/space_view3d/CMakeLists.txt @@ -49,26 +49,26 @@ set(SRC view3d_header.c view3d_iterators.cc view3d_navigate.cc - view3d_navigate_dolly.c - view3d_navigate_fly.c - view3d_navigate_move.c - view3d_navigate_ndof.c - view3d_navigate_roll.c - view3d_navigate_rotate.c - view3d_navigate_smoothview.c - view3d_navigate_walk.c - view3d_navigate_zoom.c - view3d_navigate_zoom_border.c - view3d_ops.c + view3d_navigate_dolly.cc + view3d_navigate_fly.cc + view3d_navigate_move.cc + view3d_navigate_ndof.cc + view3d_navigate_roll.cc + view3d_navigate_rotate.cc + view3d_navigate_smoothview.cc + view3d_navigate_walk.cc + view3d_navigate_zoom.cc + view3d_navigate_zoom_border.cc + view3d_ops.cc view3d_placement.c view3d_project.c view3d_select.cc view3d_snap.c view3d_utils.c - view3d_view.c + view3d_view.cc view3d_intern.h - view3d_navigate.h + view3d_navigate.hh ) set(LIB diff --git a/source/blender/editors/space_view3d/space_view3d.cc b/source/blender/editors/space_view3d/space_view3d.cc index d4b464ed522..59d800364ac 100644 --- a/source/blender/editors/space_view3d/space_view3d.cc +++ b/source/blender/editors/space_view3d/space_view3d.cc @@ -88,7 +88,7 @@ #include "DEG_depsgraph_build.h" #include "view3d_intern.h" /* own include */ -#include "view3d_navigate.h" +#include "view3d_navigate.hh" /* ******************** manage regions ********************* */ @@ -1179,7 +1179,7 @@ static void view3d_main_region_listener(const wmRegionListenerParams *params) break; case ND_OB_ACTIVE: case ND_OB_SELECT: - ATTR_FALLTHROUGH; + [[fallthrough]]; case ND_FRAME: case ND_TRANSFORM: case ND_OB_VISIBLE: diff --git a/source/blender/editors/space_view3d/view3d_navigate.cc b/source/blender/editors/space_view3d/view3d_navigate.cc index 349454ba4e3..41eb3fc3ef8 100644 --- a/source/blender/editors/space_view3d/view3d_navigate.cc +++ b/source/blender/editors/space_view3d/view3d_navigate.cc @@ -43,7 +43,7 @@ #include "view3d_intern.h" -#include "view3d_navigate.h" /* own include */ +#include "view3d_navigate.hh" /* own include */ /* Prototypes. */ static void viewops_data_init_context(bContext *C, ViewOpsData *vod); @@ -278,7 +278,7 @@ int view3d_navigate_modal_fn(bContext *C, wmOperator *op, const wmEvent *event) void view3d_navigate_cancel_fn(bContext *C, wmOperator *op) { - viewops_data_free(C, (ViewOpsData *)op->customdata); + viewops_data_free(C, static_cast(op->customdata)); op->customdata = nullptr; } diff --git a/source/blender/editors/space_view3d/view3d_navigate.h b/source/blender/editors/space_view3d/view3d_navigate.hh similarity index 70% rename from source/blender/editors/space_view3d/view3d_navigate.h rename to source/blender/editors/space_view3d/view3d_navigate.hh index 52f1223285d..d42655b6694 100644 --- a/source/blender/editors/space_view3d/view3d_navigate.h +++ b/source/blender/editors/space_view3d/view3d_navigate.hh @@ -10,10 +10,6 @@ #include "BLI_utildefines.h" -#ifdef __cplusplus -extern "C" { -#endif - /** * Size of the sphere being dragged for trackball rotation within the view bounds. * also affects speed (smaller is faster). @@ -31,9 +27,13 @@ struct View3D; struct bContext; struct rcti; struct wmEvent; +struct wmKeyConfig; +struct wmKeyMap; struct wmOperator; +struct wmOperatorType; +struct wmWindowManager; -typedef enum eV3D_OpMode { +enum eV3D_OpMode { V3D_OP_MODE_NONE = -1, V3D_OP_MODE_ZOOM = 0, V3D_OP_MODE_ROTATE, @@ -47,7 +47,7 @@ typedef enum eV3D_OpMode { V3D_OP_MODE_NDOF_PAN, V3D_OP_MODE_NDOF_ALL, #endif -} eV3D_OpMode; +}; #ifndef WITH_INPUT_NDOF # define V3D_OP_MODE_LEN V3D_OP_MODE_DOLLY + 1 #else @@ -60,14 +60,15 @@ enum eV3D_OpPropFlag { V3D_OP_PROP_USE_ALL_REGIONS = (1 << 2), V3D_OP_PROP_USE_MOUSE_INIT = (1 << 3), }; +ENUM_OPERATORS(eV3D_OpPropFlag, V3D_OP_PROP_USE_MOUSE_INIT); -typedef enum eV3D_OpEvent { +enum eV3D_OpEvent { VIEW_PASS = 0, VIEW_APPLY, VIEW_CONFIRM, /** Only supported by some viewport operators. */ VIEW_CANCEL, -} eV3D_OpEvent; +}; /* NOTE: these defines are saved in keymap files, do not change values but just add new ones */ enum { @@ -80,7 +81,7 @@ enum { VIEWROT_MODAL_SWITCH_ROTATE = 6, }; -typedef enum eViewOpsFlag { +enum eViewOpsFlag { VIEWOPS_FLAG_NONE = 0, /** When enabled, rotate around the selection. */ VIEWOPS_FLAG_ORBIT_SELECT = (1 << 0), @@ -96,22 +97,22 @@ typedef enum eViewOpsFlag { VIEWOPS_FLAG_USE_MOUSE_INIT = (1 << 3), VIEWOPS_FLAG_ZOOM_TO_MOUSE = (1 << 4), -} eViewOpsFlag; +}; ENUM_OPERATORS(eViewOpsFlag, VIEWOPS_FLAG_ZOOM_TO_MOUSE); /** Generic View Operator Custom-Data */ -typedef struct ViewOpsData { +struct ViewOpsData { /** Context pointers (assigned by #viewops_data_create). */ - struct Main *bmain; - struct Scene *scene; - struct ScrArea *area; - struct ARegion *region; - struct View3D *v3d; - struct RegionView3D *rv3d; - struct Depsgraph *depsgraph; + Main *bmain; + Scene *scene; + ScrArea *area; + ARegion *region; + View3D *v3d; + RegionView3D *rv3d; + Depsgraph *depsgraph; /** Needed for continuous zoom. */ - struct wmTimer *timer; + wmTimer *timer; /** Viewport state on initialization, don't change afterwards. */ struct { @@ -193,7 +194,7 @@ typedef struct ViewOpsData { /** Used for navigation on non view3d operators. */ wmKeyMap *keymap; bool is_modal_event; -} ViewOpsData; +}; /* view3d_navigate.cc */ @@ -202,18 +203,18 @@ typedef struct ViewOpsData { */ const char *viewops_operator_idname_get(eV3D_OpMode nav_type); -bool view3d_location_poll(struct bContext *C); -bool view3d_rotation_poll(struct bContext *C); -bool view3d_zoom_or_dolly_poll(struct bContext *C); +bool view3d_location_poll(bContext *C); +bool view3d_rotation_poll(bContext *C); +bool view3d_zoom_or_dolly_poll(bContext *C); int view3d_navigate_invoke_impl(bContext *C, wmOperator *op, const wmEvent *event, const eV3D_OpMode nav_type); int view3d_navigate_modal_fn(bContext *C, wmOperator *op, const wmEvent *event); -void view3d_navigate_cancel_fn(struct bContext *C, struct wmOperator *op); +void view3d_navigate_cancel_fn(bContext *C, wmOperator *op); -void calctrackballvec(const struct rcti *rect, const int event_xy[2], float r_dir[3]); +void calctrackballvec(const rcti *rect, const int event_xy[2], float r_dir[3]); void viewmove_apply(ViewOpsData *vod, int x, int y); void view3d_orbit_apply_dyn_ofs(float r_ofs[3], const float ofs_old[3], @@ -221,14 +222,14 @@ void view3d_orbit_apply_dyn_ofs(float r_ofs[3], const float viewquat_new[4], const float dyn_ofs[3]); void viewrotate_apply_dyn_ofs(ViewOpsData *vod, const float viewquat_new[4]); -bool view3d_orbit_calc_center(struct bContext *C, float r_dyn_ofs[3]); +bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3]); -void view3d_operator_properties_common(struct wmOperatorType *ot, const enum eV3D_OpPropFlag flag); +void view3d_operator_properties_common(wmOperatorType *ot, const eV3D_OpPropFlag flag); /** * Allocate and fill in context pointers for #ViewOpsData */ -void viewops_data_free(struct bContext *C, ViewOpsData *vod); +void viewops_data_free(bContext *C, ViewOpsData *vod); /** * Allocate, fill in context pointers and calculate the values for #ViewOpsData @@ -239,37 +240,37 @@ ViewOpsData *viewops_data_create(bContext *C, const bool use_cursor_init); void viewops_data_state_restore(ViewOpsData *vod); -void VIEW3D_OT_view_all(struct wmOperatorType *ot); -void VIEW3D_OT_view_selected(struct wmOperatorType *ot); -void VIEW3D_OT_view_center_cursor(struct wmOperatorType *ot); -void VIEW3D_OT_view_center_pick(struct wmOperatorType *ot); -void VIEW3D_OT_view_axis(struct wmOperatorType *ot); -void VIEW3D_OT_view_camera(struct wmOperatorType *ot); -void VIEW3D_OT_view_orbit(struct wmOperatorType *ot); -void VIEW3D_OT_view_pan(struct wmOperatorType *ot); +void VIEW3D_OT_view_all(wmOperatorType *ot); +void VIEW3D_OT_view_selected(wmOperatorType *ot); +void VIEW3D_OT_view_center_cursor(wmOperatorType *ot); +void VIEW3D_OT_view_center_pick(wmOperatorType *ot); +void VIEW3D_OT_view_axis(wmOperatorType *ot); +void VIEW3D_OT_view_camera(wmOperatorType *ot); +void VIEW3D_OT_view_orbit(wmOperatorType *ot); +void VIEW3D_OT_view_pan(wmOperatorType *ot); -/* view3d_navigate_dolly.c */ +/* view3d_navigate_dolly.cc */ -void viewdolly_modal_keymap(struct wmKeyConfig *keyconf); -void VIEW3D_OT_dolly(struct wmOperatorType *ot); +void viewdolly_modal_keymap(wmKeyConfig *keyconf); +void VIEW3D_OT_dolly(wmOperatorType *ot); -/* view3d_navigate_fly.c */ +/* view3d_navigate_fly.cc */ -void fly_modal_keymap(struct wmKeyConfig *keyconf); -void view3d_keymap(struct wmKeyConfig *keyconf); -void VIEW3D_OT_fly(struct wmOperatorType *ot); +void fly_modal_keymap(wmKeyConfig *keyconf); +void view3d_keymap(wmKeyConfig *keyconf); +void VIEW3D_OT_fly(wmOperatorType *ot); -/* view3d_navigate_move.c */ +/* view3d_navigate_move.cc */ int viewmove_modal_impl(bContext *C, ViewOpsData *vod, const eV3D_OpEvent event_code, const int xy[2]); int viewmove_invoke_impl(ViewOpsData *vod, const wmEvent *event); -void viewmove_modal_keymap(struct wmKeyConfig *keyconf); -void VIEW3D_OT_move(struct wmOperatorType *ot); +void viewmove_modal_keymap(wmKeyConfig *keyconf); +void VIEW3D_OT_move(wmOperatorType *ot); -/* view3d_navigate_ndof.c */ +/* view3d_navigate_ndof.cc */ #ifdef WITH_INPUT_NDOF struct wmNDOFMotionData; @@ -282,41 +283,41 @@ int ndof_all_invoke_impl(bContext *C, ViewOpsData *vod, const wmEvent *event); /** * Called from both fly mode and walk mode, */ -void view3d_ndof_fly(const struct wmNDOFMotionData *ndof, - struct View3D *v3d, - struct RegionView3D *rv3d, +void view3d_ndof_fly(const wmNDOFMotionData *ndof, + View3D *v3d, + RegionView3D *rv3d, bool use_precision, short protectflag, bool *r_has_translate, bool *r_has_rotate); -void VIEW3D_OT_ndof_orbit(struct wmOperatorType *ot); -void VIEW3D_OT_ndof_orbit_zoom(struct wmOperatorType *ot); -void VIEW3D_OT_ndof_pan(struct wmOperatorType *ot); -void VIEW3D_OT_ndof_all(struct wmOperatorType *ot); +void VIEW3D_OT_ndof_orbit(wmOperatorType *ot); +void VIEW3D_OT_ndof_orbit_zoom(wmOperatorType *ot); +void VIEW3D_OT_ndof_pan(wmOperatorType *ot); +void VIEW3D_OT_ndof_all(wmOperatorType *ot); #endif /* WITH_INPUT_NDOF */ -/* view3d_navigate_roll.c */ +/* view3d_navigate_roll.cc */ -void VIEW3D_OT_view_roll(struct wmOperatorType *ot); +void VIEW3D_OT_view_roll(wmOperatorType *ot); -/* view3d_navigate_rotate.c */ +/* view3d_navigate_rotate.cc */ int viewrotate_modal_impl(bContext *C, ViewOpsData *vod, const eV3D_OpEvent event_code, const int xy[2]); int viewrotate_invoke_impl(ViewOpsData *vod, const wmEvent *event); -void viewrotate_modal_keymap(struct wmKeyConfig *keyconf); -void VIEW3D_OT_rotate(struct wmOperatorType *ot); +void viewrotate_modal_keymap(wmKeyConfig *keyconf); +void VIEW3D_OT_rotate(wmOperatorType *ot); -/* view3d_navigate_smoothview.c */ +/* view3d_navigate_smoothview.cc */ /** * Parameters for setting the new 3D Viewport state. * * Each of the struct members may be NULL to signify they aren't to be adjusted. */ -typedef struct V3D_SmoothParams { +struct V3D_SmoothParams { struct Object *camera_old, *camera; const float *ofs, *quat, *dist, *lens; @@ -330,25 +331,22 @@ typedef struct V3D_SmoothParams { * which are likely to be activated by holding a key or from the mouse-wheel. */ bool undo_grouped; -} V3D_SmoothParams; +}; /** * The arguments are the desired situation. */ -void ED_view3d_smooth_view_ex(const struct Depsgraph *depsgraph, - struct wmWindowManager *wm, - struct wmWindow *win, - struct ScrArea *area, - struct View3D *v3d, - struct ARegion *region, +void ED_view3d_smooth_view_ex(const Depsgraph *depsgraph, + wmWindowManager *wm, + wmWindow *win, + ScrArea *area, + View3D *v3d, + ARegion *region, int smooth_viewtx, const V3D_SmoothParams *sview); -void ED_view3d_smooth_view(struct bContext *C, - struct View3D *v3d, - struct ARegion *region, - int smooth_viewtx, - const V3D_SmoothParams *sview); +void ED_view3d_smooth_view( + bContext *C, View3D *v3d, ARegion *region, int smooth_viewtx, const V3D_SmoothParams *sview); /** * Call before multiple smooth-view operations begin to properly handle undo. @@ -357,12 +355,12 @@ void ED_view3d_smooth_view(struct bContext *C, * or when calling #ED_view3d_smooth_view_ex. * Otherwise pass in #V3D_SmoothParams.undo_str so an undo step is pushed as needed. */ -void ED_view3d_smooth_view_undo_begin(struct bContext *C, const struct ScrArea *area); +void ED_view3d_smooth_view_undo_begin(bContext *C, const ScrArea *area); /** * Run after multiple smooth-view operations have run to push undo as needed. */ -void ED_view3d_smooth_view_undo_end(struct bContext *C, - const struct ScrArea *area, +void ED_view3d_smooth_view_undo_end(bContext *C, + const ScrArea *area, const char *undo_str, bool undo_grouped); @@ -370,31 +368,25 @@ void ED_view3d_smooth_view_undo_end(struct bContext *C, * Apply the smooth-view immediately, use when we need to start a new view operation. * (so we don't end up half-applying a view operation when pressing keys quickly). */ -void ED_view3d_smooth_view_force_finish(struct bContext *C, - struct View3D *v3d, - struct ARegion *region); +void ED_view3d_smooth_view_force_finish(bContext *C, View3D *v3d, ARegion *region); -void VIEW3D_OT_smoothview(struct wmOperatorType *ot); +void VIEW3D_OT_smoothview(wmOperatorType *ot); -/* view3d_navigate_walk.c */ +/* view3d_navigate_walk.cc */ -void walk_modal_keymap(struct wmKeyConfig *keyconf); -void VIEW3D_OT_walk(struct wmOperatorType *ot); +void walk_modal_keymap(wmKeyConfig *keyconf); +void VIEW3D_OT_walk(wmOperatorType *ot); -/* view3d_navigate_zoom.c */ +/* view3d_navigate_zoom.cc */ int viewzoom_modal_impl(bContext *C, ViewOpsData *vod, const eV3D_OpEvent event_code, const int xy[2]); int viewzoom_invoke_impl(bContext *C, ViewOpsData *vod, const wmEvent *event, PointerRNA *ptr); -void viewzoom_modal_keymap(struct wmKeyConfig *keyconf); -void VIEW3D_OT_zoom(struct wmOperatorType *ot); +void viewzoom_modal_keymap(wmKeyConfig *keyconf); +void VIEW3D_OT_zoom(wmOperatorType *ot); -/* view3d_navigate_zoom_border.c */ +/* view3d_navigate_zoom_border.cc */ -void VIEW3D_OT_zoom_border(struct wmOperatorType *ot); - -#ifdef __cplusplus -} -#endif +void VIEW3D_OT_zoom_border(wmOperatorType *ot); diff --git a/source/blender/editors/space_view3d/view3d_navigate_dolly.c b/source/blender/editors/space_view3d/view3d_navigate_dolly.cc similarity index 90% rename from source/blender/editors/space_view3d/view3d_navigate_dolly.c rename to source/blender/editors/space_view3d/view3d_navigate_dolly.cc index 28853d408fc..e9c7ce012dc 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_dolly.c +++ b/source/blender/editors/space_view3d/view3d_navigate_dolly.cc @@ -20,7 +20,7 @@ #include "ED_screen.h" #include "view3d_intern.h" -#include "view3d_navigate.h" /* own include */ +#include "view3d_navigate.hh" /* own include */ /* -------------------------------------------------------------------- */ /** \name View Dolly Operator @@ -39,7 +39,7 @@ void viewdolly_modal_keymap(wmKeyConfig *keyconf) {VIEWROT_MODAL_SWITCH_ROTATE, "SWITCH_TO_ROTATE", 0, "Switch to Rotate"}, {VIEWROT_MODAL_SWITCH_MOVE, "SWITCH_TO_MOVE", 0, "Switch to Move"}, - {0, NULL, 0, NULL, NULL}, + {0, nullptr, 0, nullptr, nullptr}, }; wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Dolly Modal"); @@ -71,7 +71,7 @@ static void view_dolly_to_vector_3d(ARegion *region, const float dvec[3], float dfac) { - RegionView3D *rv3d = region->regiondata; + RegionView3D *rv3d = static_cast(region->regiondata); madd_v3_v3v3fl(rv3d->ofs, orig_ofs, dvec, -(1.0f - dfac)); } @@ -112,7 +112,7 @@ static void viewdolly_apply(ViewOpsData *vod, const int xy[2], const bool zoom_i static int viewdolly_modal(bContext *C, wmOperator *op, const wmEvent *event) { - ViewOpsData *vod = op->customdata; + ViewOpsData *vod = static_cast(op->customdata); short event_code = VIEW_PASS; bool use_autokey = false; int ret = OPERATOR_RUNNING_MODAL; @@ -124,11 +124,11 @@ static int viewdolly_modal(bContext *C, wmOperator *op, const wmEvent *event) event_code = VIEW_CONFIRM; break; case VIEWROT_MODAL_SWITCH_MOVE: - WM_operator_name_call(C, "VIEW3D_OT_move", WM_OP_INVOKE_DEFAULT, NULL, event); + WM_operator_name_call(C, "VIEW3D_OT_move", WM_OP_INVOKE_DEFAULT, nullptr, event); event_code = VIEW_CONFIRM; break; case VIEWROT_MODAL_SWITCH_ROTATE: - WM_operator_name_call(C, "VIEW3D_OT_rotate", WM_OP_INVOKE_DEFAULT, NULL, event); + WM_operator_name_call(C, "VIEW3D_OT_rotate", WM_OP_INVOKE_DEFAULT, nullptr, event); event_code = VIEW_CONFIRM; break; } @@ -178,7 +178,7 @@ static int viewdolly_modal(bContext *C, wmOperator *op, const wmEvent *event) ED_view3d_camera_lock_undo_push(op->type->name, vod->v3d, vod->rv3d, C); } viewops_data_free(C, vod); - op->customdata = NULL; + op->customdata = nullptr; } return ret; @@ -195,7 +195,7 @@ static int viewdolly_exec(bContext *C, wmOperator *op) const int delta = RNA_int_get(op->ptr, "delta"); if (op->customdata) { - ViewOpsData *vod = op->customdata; + ViewOpsData *vod = static_cast(op->customdata); area = vod->area; region = vod->region; @@ -204,12 +204,12 @@ static int viewdolly_exec(bContext *C, wmOperator *op) else { area = CTX_wm_area(C); region = CTX_wm_region(C); - negate_v3_v3(mousevec, ((RegionView3D *)region->regiondata)->viewinv[2]); + negate_v3_v3(mousevec, static_cast(region->regiondata)->viewinv[2]); normalize_v3(mousevec); } - v3d = area->spacedata.first; - rv3d = region->regiondata; + v3d = static_cast(area->spacedata.first); + rv3d = static_cast(region->regiondata); const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); @@ -229,8 +229,8 @@ static int viewdolly_exec(bContext *C, wmOperator *op) ED_region_tag_redraw(region); - viewops_data_free(C, op->customdata); - op->customdata = NULL; + viewops_data_free(C, static_cast(op->customdata)); + op->customdata = nullptr; return OPERATOR_FINISHED; } @@ -246,7 +246,8 @@ static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event) const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); - vod = op->customdata = viewops_data_create(C, event, V3D_OP_MODE_DOLLY, use_cursor_init); + vod = viewops_data_create(C, event, V3D_OP_MODE_DOLLY, use_cursor_init); + op->customdata = vod; ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); @@ -293,8 +294,8 @@ static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event) } viewdolly_apply(vod, event->prev_xy, (U.uiflag & USER_ZOOM_INVERT) == 0); - viewops_data_free(C, op->customdata); - op->customdata = NULL; + viewops_data_free(C, static_cast(op->customdata)); + op->customdata = nullptr; return OPERATOR_FINISHED; } diff --git a/source/blender/editors/space_view3d/view3d_navigate_fly.c b/source/blender/editors/space_view3d/view3d_navigate_fly.cc similarity index 96% rename from source/blender/editors/space_view3d/view3d_navigate_fly.c rename to source/blender/editors/space_view3d/view3d_navigate_fly.cc index 1e8c5a22bd7..3e85c459509 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_fly.c +++ b/source/blender/editors/space_view3d/view3d_navigate_fly.cc @@ -7,7 +7,7 @@ * * Interactive fly navigation modal operator (flying around in space). * - * \note Similar logic to `view3d_navigate_walk.c` changes here may apply there too. + * \note Similar logic to `view3d_navigate_walk.cc` changes here may apply there too. */ /* defines VIEW3D_OT_fly modal operator */ @@ -47,7 +47,7 @@ #include "DEG_depsgraph.h" #include "view3d_intern.h" /* own include */ -#include "view3d_navigate.h" +#include "view3d_navigate.hh" /* -------------------------------------------------------------------- */ /** \name Modal Key-map @@ -119,7 +119,7 @@ void fly_modal_keymap(wmKeyConfig *keyconf) {FLY_MODAL_FREELOOK_ENABLE, "FREELOOK_ENABLE", 0, "Rotation", ""}, {FLY_MODAL_FREELOOK_DISABLE, "FREELOOK_DISABLE", 0, "Rotation (Off)", ""}, - {0, NULL, 0, NULL, NULL}, + {0, nullptr, 0, nullptr, nullptr}, }; wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Fly Modal"); @@ -141,7 +141,7 @@ void fly_modal_keymap(wmKeyConfig *keyconf) /** \name Internal Fly Structs * \{ */ -typedef struct FlyInfo { +struct FlyInfo { /* context stuff */ RegionView3D *rv3d; View3D *v3d; @@ -204,9 +204,8 @@ typedef struct FlyInfo { /** Keep the previous value to smooth transitions (use lag). */ float dvec_prev[3]; - struct View3DCameraControl *v3d_camera_control; - -} FlyInfo; + View3DCameraControl *v3d_camera_control; +}; /** \} */ @@ -220,9 +219,9 @@ static void flyApply_ndof(bContext *C, FlyInfo *fly, bool is_confirm); #endif /* WITH_INPUT_NDOF */ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm); -static void drawFlyPixel(const bContext *UNUSED(C), ARegion *UNUSED(region), void *arg) +static void drawFlyPixel(const bContext * /*C*/, ARegion * /*region*/, void *arg) { - FlyInfo *fly = arg; + FlyInfo *fly = static_cast(arg); rctf viewborder; int xoff, yoff; float x1, x2, y1, y2; @@ -320,7 +319,7 @@ static bool initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent #endif /* sanity check: for rare but possible case (if lib-linking the camera fails) */ - if ((fly->rv3d->persp == RV3D_CAMOB) && (fly->v3d->camera == NULL)) { + if ((fly->rv3d->persp == RV3D_CAMOB) && (fly->v3d->camera == nullptr)) { fly->rv3d->persp = RV3D_PERSP; } @@ -366,7 +365,7 @@ static bool initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent copy_v2_v2_int(fly->mval, event->mval); #ifdef WITH_INPUT_NDOF - fly->ndof = NULL; + fly->ndof = nullptr; #endif fly->time_lastdraw = fly->time_lastwheel = PIL_check_seconds_timer(); @@ -479,7 +478,8 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event) // puts("ndof motion detected in fly mode!"); // static const char *tag_name = "3D mouse position"; - const wmNDOFMotionData *incoming_ndof = event->customdata; + const wmNDOFMotionData *incoming_ndof = static_cast( + event->customdata); switch (incoming_ndof->progress) { case P_STARTING: /* start keeping track of 3D mouse position */ @@ -493,9 +493,9 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event) putchar('.'); fflush(stdout); # endif - if (fly->ndof == NULL) { + if (fly->ndof == nullptr) { // fly->ndof = MEM_mallocN(sizeof(wmNDOFMotionData), tag_name); - fly->ndof = MEM_dupallocN(incoming_ndof); + fly->ndof = static_cast(MEM_dupallocN(incoming_ndof)); // fly->ndof = malloc(sizeof(wmNDOFMotionData)); } else { @@ -510,7 +510,7 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event) if (fly->ndof) { MEM_freeN(fly->ndof); // free(fly->ndof); - fly->ndof = NULL; + fly->ndof = nullptr; } /* update the time else the view will jump when 2D mouse/timer resume */ fly->time_lastdraw = PIL_check_seconds_timer(); @@ -558,7 +558,7 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event) } time_currwheel = PIL_check_seconds_timer(); - time_wheel = (float)(time_currwheel - fly->time_lastwheel); + time_wheel = float(time_currwheel - fly->time_lastwheel); fly->time_lastwheel = time_currwheel; /* Mouse wheel delays range from (0.5 == slow) to (0.01 == fast) */ /* 0-0.5 -> 0-5.0 */ @@ -583,7 +583,7 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event) } time_currwheel = PIL_check_seconds_timer(); - time_wheel = (float)(time_currwheel - fly->time_lastwheel); + time_wheel = float(time_currwheel - fly->time_lastwheel); fly->time_lastwheel = time_currwheel; /* 0-0.5 -> 0-5.0 */ time_wheel = 1.0f + (10.0f - (20.0f * min_ff(time_wheel, 0.5f))); @@ -832,7 +832,7 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm) fly->redraw = 1; #endif time_current = PIL_check_seconds_timer(); - time_redraw = (float)(time_current - fly->time_lastdraw); + time_redraw = float(time_current - fly->time_lastdraw); /* clamp redraw time to avoid jitter in roll correction */ time_redraw_clamped = min_ff(0.05f, time_redraw); @@ -1052,7 +1052,7 @@ static int fly_invoke(bContext *C, wmOperator *op, const wmEvent *event) return OPERATOR_CANCELLED; } - fly = MEM_callocN(sizeof(FlyInfo), "FlyOperation"); + fly = MEM_cnew("FlyOperation"); op->customdata = fly; @@ -1070,18 +1070,18 @@ static int fly_invoke(bContext *C, wmOperator *op, const wmEvent *event) static void fly_cancel(bContext *C, wmOperator *op) { - FlyInfo *fly = op->customdata; + FlyInfo *fly = static_cast(op->customdata); fly->state = FLY_CANCEL; flyEnd(C, fly); - op->customdata = NULL; + op->customdata = nullptr; } static int fly_modal(bContext *C, wmOperator *op, const wmEvent *event) { int exit_code; bool do_draw = false; - FlyInfo *fly = op->customdata; + FlyInfo *fly = static_cast(op->customdata); View3D *v3d = fly->v3d; RegionView3D *rv3d = fly->rv3d; Object *fly_object = ED_view3d_cameracontrol_object_get(fly->v3d_camera_control); diff --git a/source/blender/editors/space_view3d/view3d_navigate_move.c b/source/blender/editors/space_view3d/view3d_navigate_move.cc similarity index 97% rename from source/blender/editors/space_view3d/view3d_navigate_move.c rename to source/blender/editors/space_view3d/view3d_navigate_move.cc index a4728700339..8beeb53017a 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_move.c +++ b/source/blender/editors/space_view3d/view3d_navigate_move.cc @@ -18,7 +18,7 @@ #include "ED_screen.h" #include "view3d_intern.h" -#include "view3d_navigate.h" /* own include */ +#include "view3d_navigate.hh" /* own include */ /* -------------------------------------------------------------------- */ /** \name View Move (Pan) Operator @@ -35,7 +35,7 @@ void viewmove_modal_keymap(wmKeyConfig *keyconf) {VIEWROT_MODAL_SWITCH_ZOOM, "SWITCH_TO_ZOOM", 0, "Switch to Zoom"}, {VIEWROT_MODAL_SWITCH_ROTATE, "SWITCH_TO_ROTATE", 0, "Switch to Rotate"}, - {0, NULL, 0, NULL, NULL}, + {0, nullptr, 0, nullptr, nullptr}, }; wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Move Modal"); diff --git a/source/blender/editors/space_view3d/view3d_navigate_ndof.c b/source/blender/editors/space_view3d/view3d_navigate_ndof.cc similarity index 97% rename from source/blender/editors/space_view3d/view3d_navigate_ndof.c rename to source/blender/editors/space_view3d/view3d_navigate_ndof.cc index e3a7e8ef8fc..b49e0e61062 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_ndof.c +++ b/source/blender/editors/space_view3d/view3d_navigate_ndof.cc @@ -17,7 +17,7 @@ #include "ED_screen.h" #include "view3d_intern.h" -#include "view3d_navigate.h" /* own include */ +#include "view3d_navigate.hh" /* own include */ /* -------------------------------------------------------------------- */ /** \name NDOF Utility Functions @@ -95,7 +95,7 @@ static void view3d_ndof_pan_zoom(const wmNDOFMotionData *ndof, const bool has_translate, const bool has_zoom) { - RegionView3D *rv3d = region->regiondata; + RegionView3D *rv3d = static_cast(region->regiondata); float view_inv[4]; float pan_vec[3]; @@ -159,8 +159,8 @@ static void view3d_ndof_orbit(const wmNDOFMotionData *ndof, ViewOpsData *vod, const bool apply_dyn_ofs) { - View3D *v3d = area->spacedata.first; - RegionView3D *rv3d = region->regiondata; + View3D *v3d = static_cast(area->spacedata.first); + RegionView3D *rv3d = static_cast(region->regiondata); float view_inv[4]; @@ -431,7 +431,7 @@ int ndof_orbit_invoke_impl(bContext *C, ViewOpsData *vod, const wmEvent *event) RegionView3D *rv3d = vod->rv3d; char xform_flag = 0; - const wmNDOFMotionData *ndof = event->customdata; + const wmNDOFMotionData *ndof = static_cast(event->customdata); /* off by default, until changed later this function */ rv3d->rot_angle = 0.0f; @@ -501,7 +501,7 @@ int ndof_orbit_zoom_invoke_impl(bContext *C, ViewOpsData *vod, const wmEvent *ev return OPERATOR_CANCELLED; } - const wmNDOFMotionData *ndof = event->customdata; + const wmNDOFMotionData *ndof = static_cast(event->customdata); if (U.ndof_flag & NDOF_CAMERA_PAN_ZOOM) { const int camera_retval = view3d_ndof_cameraview_pan_zoom(vod, ndof); @@ -616,7 +616,7 @@ int ndof_pan_invoke_impl(bContext *C, ViewOpsData *vod, const wmEvent *event) return OPERATOR_CANCELLED; } - const wmNDOFMotionData *ndof = event->customdata; + const wmNDOFMotionData *ndof = static_cast(event->customdata); if (U.ndof_flag & NDOF_CAMERA_PAN_ZOOM) { const int camera_retval = view3d_ndof_cameraview_pan_zoom(vod, ndof); diff --git a/source/blender/editors/space_view3d/view3d_navigate_roll.c b/source/blender/editors/space_view3d/view3d_navigate_roll.cc similarity index 81% rename from source/blender/editors/space_view3d/view3d_navigate_roll.c rename to source/blender/editors/space_view3d/view3d_navigate_roll.cc index c5baabe36ac..ae60300efac 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_roll.c +++ b/source/blender/editors/space_view3d/view3d_navigate_roll.cc @@ -22,7 +22,7 @@ #include "ED_screen.h" #include "view3d_intern.h" -#include "view3d_navigate.h" /* own include */ +#include "view3d_navigate.hh" /* own include */ /* -------------------------------------------------------------------- */ /** \name View Roll Operator @@ -40,7 +40,7 @@ static void view_roll_angle(ARegion *region, float angle, bool use_axis_view) { - RegionView3D *rv3d = region->regiondata; + RegionView3D *rv3d = static_cast(region->regiondata); float quat_mul[4]; /* camera axis */ @@ -51,7 +51,7 @@ static void view_roll_angle(ARegion *region, /* avoid precision loss over time */ normalize_qt(quat); - if (use_axis_view && RV3D_VIEW_IS_AXIS(rv3d->view) && (fabsf(angle) == (float)M_PI_2)) { + if (use_axis_view && RV3D_VIEW_IS_AXIS(rv3d->view) && (fabsf(angle) == float(M_PI_2))) { ED_view3d_quat_to_axis_view_and_reset_quat(quat, 0.01f, &rv3d->view, &rv3d->view_axis_roll); } else { @@ -61,7 +61,8 @@ static void view_roll_angle(ARegion *region, static void viewroll_apply(ViewOpsData *vod, int x, int y) { - float angle = BLI_dial_angle(vod->init.dial, (const float[2]){x, y}); + const float current_position[2] = {float(x), float(y)}; + float angle = BLI_dial_angle(vod->init.dial, current_position); if (angle != 0.0f) { view_roll_angle( @@ -84,7 +85,7 @@ static void viewroll_apply(ViewOpsData *vod, int x, int y) static int viewroll_modal(bContext *C, wmOperator *op, const wmEvent *event) { - ViewOpsData *vod = op->customdata; + ViewOpsData *vod = static_cast(op->customdata); short event_code = VIEW_PASS; bool use_autokey = false; int ret = OPERATOR_RUNNING_MODAL; @@ -99,11 +100,11 @@ static int viewroll_modal(bContext *C, wmOperator *op, const wmEvent *event) event_code = VIEW_CANCEL; break; case VIEWROT_MODAL_SWITCH_MOVE: - WM_operator_name_call(C, "VIEW3D_OT_move", WM_OP_INVOKE_DEFAULT, NULL, event); + WM_operator_name_call(C, "VIEW3D_OT_move", WM_OP_INVOKE_DEFAULT, nullptr, event); event_code = VIEW_CONFIRM; break; case VIEWROT_MODAL_SWITCH_ROTATE: - WM_operator_name_call(C, "VIEW3D_OT_rotate", WM_OP_INVOKE_DEFAULT, NULL, event); + WM_operator_name_call(C, "VIEW3D_OT_rotate", WM_OP_INVOKE_DEFAULT, nullptr, event); event_code = VIEW_CONFIRM; break; } @@ -151,8 +152,8 @@ static int viewroll_modal(bContext *C, wmOperator *op, const wmEvent *event) } if ((ret & OPERATOR_RUNNING_MODAL) == 0) { - viewops_data_free(C, op->customdata); - op->customdata = NULL; + viewops_data_free(C, static_cast(op->customdata)); + op->customdata = nullptr; } return ret; @@ -167,7 +168,7 @@ static const EnumPropertyItem prop_view_roll_items[] = { {0, "ANGLE", 0, "Roll Angle", "Roll the view using an angle value"}, {V3D_VIEW_STEPLEFT, "LEFT", 0, "Roll Left", "Roll the view around to the left"}, {V3D_VIEW_STEPRIGHT, "RIGHT", 0, "Roll Right", "Roll the view around to the right"}, - {0, NULL, 0, NULL, NULL}, + {0, nullptr, 0, nullptr, nullptr}, }; static int viewroll_exec(bContext *C, wmOperator *op) @@ -177,7 +178,7 @@ static int viewroll_exec(bContext *C, wmOperator *op) ARegion *region; if (op->customdata) { - ViewOpsData *vod = op->customdata; + ViewOpsData *vod = static_cast(op->customdata); region = vod->region; v3d = vod->v3d; } @@ -185,7 +186,7 @@ static int viewroll_exec(bContext *C, wmOperator *op) ED_view3d_context_user_region(C, &v3d, ®ion); } - rv3d = region->regiondata; + rv3d = static_cast(region->regiondata); const bool is_camera_lock = ED_view3d_camera_lock_check(v3d, rv3d); if ((rv3d->persp != RV3D_CAMOB) || is_camera_lock) { @@ -211,7 +212,7 @@ static int viewroll_exec(bContext *C, wmOperator *op) negate_v3(mousevec); view_roll_angle(region, quat_new, rv3d->viewquat, mousevec, angle, true); - const float *dyn_ofs_pt = NULL; + const float *dyn_ofs_pt = nullptr; float dyn_ofs[3]; if (U.uiflag & USER_ORBIT_SELECTION) { if (view3d_orbit_calc_center(C, dyn_ofs)) { @@ -220,25 +221,22 @@ static int viewroll_exec(bContext *C, wmOperator *op) } } - ED_view3d_smooth_view(C, - v3d, - region, - smooth_viewtx, - &(const V3D_SmoothParams){ - .quat = quat_new, - .dyn_ofs = dyn_ofs_pt, - /* Group as successive roll may run by holding a key. */ - .undo_str = op->type->name, - .undo_grouped = true, - }); + V3D_SmoothParams sview_params = {}; + sview_params.quat = quat_new; + sview_params.dyn_ofs = dyn_ofs_pt; + /* Group as successive roll may run by holding a key. */ + sview_params.undo_str = op->type->name; + sview_params.undo_grouped = true; - viewops_data_free(C, op->customdata); - op->customdata = NULL; + ED_view3d_smooth_view(C, v3d, region, smooth_viewtx, &sview_params); + + viewops_data_free(C, static_cast(op->customdata)); + op->customdata = nullptr; return OPERATOR_FINISHED; } - viewops_data_free(C, op->customdata); - op->customdata = NULL; + viewops_data_free(C, static_cast(op->customdata)); + op->customdata = nullptr; return OPERATOR_CANCELLED; } @@ -253,10 +251,11 @@ static int viewroll_invoke(bContext *C, wmOperator *op, const wmEvent *event) } else { /* makes op->customdata */ - vod = op->customdata = viewops_data_create(C, event, V3D_OP_MODE_VIEW_ROLL, false); - vod->init.dial = BLI_dial_init((const float[2]){BLI_rcti_cent_x(&vod->region->winrct), - BLI_rcti_cent_y(&vod->region->winrct)}, - FLT_EPSILON); + vod = viewops_data_create(C, event, V3D_OP_MODE_VIEW_ROLL, false); + const float start_position[2] = {float(BLI_rcti_cent_x(&vod->region->winrct)), + float(BLI_rcti_cent_y(&vod->region->winrct))}; + vod->init.dial = BLI_dial_init(start_position, FLT_EPSILON); + op->customdata = vod; ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); @@ -268,8 +267,8 @@ static int viewroll_invoke(bContext *C, wmOperator *op, const wmEvent *event) vod->init.event_xy[0] = vod->prev.event_xy[0] = event->xy[0]; viewroll_apply(vod, event->prev_xy[0], event->prev_xy[1]); - viewops_data_free(C, op->customdata); - op->customdata = NULL; + viewops_data_free(C, static_cast(op->customdata)); + op->customdata = nullptr; return OPERATOR_FINISHED; } diff --git a/source/blender/editors/space_view3d/view3d_navigate_rotate.c b/source/blender/editors/space_view3d/view3d_navigate_rotate.cc similarity index 96% rename from source/blender/editors/space_view3d/view3d_navigate_rotate.c rename to source/blender/editors/space_view3d/view3d_navigate_rotate.cc index b7293610961..3558cd70e3f 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_rotate.c +++ b/source/blender/editors/space_view3d/view3d_navigate_rotate.cc @@ -17,7 +17,7 @@ #include "ED_screen.h" #include "view3d_intern.h" -#include "view3d_navigate.h" /* own include */ +#include "view3d_navigate.hh" /* own include */ /* -------------------------------------------------------------------- */ /** \name View Rotate Operator @@ -35,7 +35,7 @@ void viewrotate_modal_keymap(wmKeyConfig *keyconf) {VIEWROT_MODAL_SWITCH_ZOOM, "SWITCH_TO_ZOOM", 0, "Switch to Zoom"}, {VIEWROT_MODAL_SWITCH_MOVE, "SWITCH_TO_MOVE", 0, "Switch to Move"}, - {0, NULL, 0, NULL, NULL}, + {0, nullptr, 0, nullptr, nullptr}, }; wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Rotate Modal"); @@ -72,7 +72,7 @@ static void viewrotate_apply_snap(ViewOpsData *vod) for (y = -1; y < 2; y++) { for (z = -1; z < 2; z++) { if (x || y || z) { - float zaxis_test[3] = {x, y, z}; + float zaxis_test[3] = {float(x), float(y), float(z)}; normalize_v3(zaxis_test); @@ -116,7 +116,7 @@ static void viewrotate_apply_snap(ViewOpsData *vod) float xaxis2[3] = {1, 0, 0}; float quat_final_inv[4]; - axis_angle_to_quat(quat_roll, zaxis_best, (float)j * DEG2RADF(45.0f)); + axis_angle_to_quat(quat_roll, zaxis_best, float(j * DEG2RADF(45.0f))); normalize_qt(quat_roll); mul_qt_qtqt(quat_final, quat_snap, quat_roll); @@ -181,7 +181,7 @@ static void viewrotate_apply(ViewOpsData *vod, const int event_xy[2]) sub_v3_v3v3(dvec, newvec, vod->init.trackvec); - angle = (len_v3(dvec) / (2.0f * V3D_OP_TRACKBALLSIZE)) * (float)M_PI; + angle = (len_v3(dvec) / (2.0f * V3D_OP_TRACKBALLSIZE)) * float(M_PI); /* Before applying the sensitivity this is rotating 1:1, * where the cursor would match the surface of a sphere in the view. */ @@ -248,7 +248,7 @@ static void viewrotate_apply(ViewOpsData *vod, const int event_xy[2]) if (dot_v3v3(xaxis, m_inv[0]) < 0) { negate_v3(xaxis); } - fac = angle_normalized_v3v3(zvec_global, m_inv[2]) / (float)M_PI; + fac = angle_normalized_v3v3(zvec_global, m_inv[2]) / float(M_PI); fac = fabsf(fac - 0.5f) * 2; fac = fac * fac; interp_v3_v3v3(xaxis, xaxis, m_inv[0], fac); diff --git a/source/blender/editors/space_view3d/view3d_navigate_smoothview.c b/source/blender/editors/space_view3d/view3d_navigate_smoothview.cc similarity index 85% rename from source/blender/editors/space_view3d/view3d_navigate_smoothview.c rename to source/blender/editors/space_view3d/view3d_navigate_smoothview.cc index 7f02d38243b..31e9277fe62 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_smoothview.c +++ b/source/blender/editors/space_view3d/view3d_navigate_smoothview.cc @@ -22,7 +22,7 @@ #include "ED_screen.h" #include "view3d_intern.h" -#include "view3d_navigate.h" /* own include */ +#include "view3d_navigate.hh" /* own include */ static void view3d_smoothview_apply_with_interp( bContext *C, View3D *v3d, RegionView3D *rv3d, const bool use_autokey, const float factor); @@ -44,7 +44,7 @@ static void view3d_smoothview_apply_with_interp( void ED_view3d_smooth_view_undo_begin(bContext *C, const ScrArea *area) { - const View3D *v3d = area->spacedata.first; + const View3D *v3d = static_cast(area->spacedata.first); Object *camera = v3d->camera; if (!camera) { return; @@ -59,7 +59,7 @@ void ED_view3d_smooth_view_undo_begin(bContext *C, const ScrArea *area) if (region->regiontype != RGN_TYPE_WINDOW) { continue; } - const RegionView3D *rv3d = region->regiondata; + const RegionView3D *rv3d = static_cast(region->regiondata); if (ED_view3d_camera_lock_undo_test(v3d, rv3d, C)) { camera->id.tag |= LIB_TAG_DOIT; break; @@ -72,7 +72,7 @@ void ED_view3d_smooth_view_undo_end(bContext *C, const char *undo_str, const bool undo_grouped) { - View3D *v3d = area->spacedata.first; + View3D *v3d = static_cast(area->spacedata.first); Object *camera = v3d->camera; if (!camera) { return; @@ -91,7 +91,7 @@ void ED_view3d_smooth_view_undo_end(bContext *C, * so even in the case there is a quad-view with multiple camera views set, these will all * reference the same camera. In this case it doesn't matter which region is used. * If in the future multiple cameras are supported, this logic can be extended. */ - const ARegion *region_camera = NULL; + const ARegion *region_camera = nullptr; /* An undo push should be performed. */ bool is_interactive = false; @@ -99,7 +99,7 @@ void ED_view3d_smooth_view_undo_end(bContext *C, if (region->regiontype != RGN_TYPE_WINDOW) { continue; } - const RegionView3D *rv3d = region->regiondata; + const RegionView3D *rv3d = static_cast(region->regiondata); if (ED_view3d_camera_lock_undo_test(v3d, rv3d, C)) { region_camera = region; if (rv3d->sms) { @@ -108,11 +108,11 @@ void ED_view3d_smooth_view_undo_end(bContext *C, } } - if (region_camera == NULL) { + if (region_camera == nullptr) { return; } - RegionView3D *rv3d = region_camera->regiondata; + RegionView3D *rv3d = static_cast(region_camera->regiondata); /* Fast forward, undo push, then rewind. */ if (is_interactive) { @@ -150,9 +150,9 @@ struct SmoothView3DState { struct SmoothView3DStore { /* Source. */ - struct SmoothView3DState src; /* source */ - struct SmoothView3DState dst; /* destination */ - struct SmoothView3DState org; /* original */ + SmoothView3DState src; /* source */ + SmoothView3DState dst; /* destination */ + SmoothView3DState org; /* original */ bool to_camera; @@ -166,7 +166,7 @@ struct SmoothView3DStore { double time_allowed; }; -static void view3d_smooth_view_state_backup(struct SmoothView3DState *sms_state, +static void view3d_smooth_view_state_backup(SmoothView3DState *sms_state, const View3D *v3d, const RegionView3D *rv3d) { @@ -176,7 +176,7 @@ static void view3d_smooth_view_state_backup(struct SmoothView3DState *sms_state, sms_state->lens = v3d->lens; } -static void view3d_smooth_view_state_restore(const struct SmoothView3DState *sms_state, +static void view3d_smooth_view_state_restore(const SmoothView3DState *sms_state, View3D *v3d, RegionView3D *rv3d) { @@ -200,17 +200,17 @@ void ED_view3d_smooth_view_ex( { /* In this case use #ED_view3d_smooth_view_undo_begin & end functions * instead of passing in undo. */ - BLI_assert_msg(sview->undo_str == NULL, + BLI_assert_msg(sview->undo_str == nullptr, "Only the 'ED_view3d_smooth_view' version of this function handles undo!"); - RegionView3D *rv3d = region->regiondata; - struct SmoothView3DStore sms = {{0}}; + RegionView3D *rv3d = static_cast(region->regiondata); + SmoothView3DStore sms = {{0}}; /* initialize sms */ view3d_smooth_view_state_backup(&sms.dst, v3d, rv3d); view3d_smooth_view_state_backup(&sms.src, v3d, rv3d); /* If smooth-view runs multiple times. */ - if (rv3d->sms == NULL) { + if (rv3d->sms == nullptr) { view3d_smooth_view_state_backup(&sms.org, v3d, rv3d); } else { @@ -228,7 +228,7 @@ void ED_view3d_smooth_view_ex( * camera to be moved or changed, so only when the camera is not being set should * we allow camera option locking to initialize the view settings from the camera. */ - if (sview->camera == NULL && sview->camera_old == NULL) { + if (sview->camera == nullptr && sview->camera_old == nullptr) { ED_view3d_camera_lock_init(depsgraph, v3d, rv3d); } @@ -247,8 +247,8 @@ void ED_view3d_smooth_view_ex( } if (sview->dyn_ofs) { - BLI_assert(sview->ofs == NULL); - BLI_assert(sview->quat != NULL); + BLI_assert(sview->ofs == nullptr); + BLI_assert(sview->quat != nullptr); copy_v3_v3(sms.dyn_ofs, sview->dyn_ofs); sms.use_dyn_ofs = true; @@ -259,7 +259,7 @@ void ED_view3d_smooth_view_ex( if (sview->camera) { Object *ob_camera_eval = DEG_get_evaluated_object(depsgraph, sview->camera); - if (sview->ofs != NULL) { + if (sview->ofs != nullptr) { sms.dst.dist = ED_view3d_offset_distance( ob_camera_eval->object_to_world, sview->ofs, VIEW3D_DIST_FALLBACK); } @@ -284,7 +284,7 @@ void ED_view3d_smooth_view_ex( /* original values */ if (sview->camera_old) { Object *ob_camera_old_eval = DEG_get_evaluated_object(depsgraph, sview->camera_old); - if (sview->ofs != NULL) { + if (sview->ofs != nullptr) { sms.src.dist = ED_view3d_offset_distance( ob_camera_old_eval->object_to_world, sview->ofs, 0.0f); } @@ -298,14 +298,14 @@ void ED_view3d_smooth_view_ex( rv3d->view = RV3D_VIEW_USER; } - sms.time_allowed = (double)smooth_viewtx / 1000.0; + sms.time_allowed = double(smooth_viewtx / 1000.0); /* If this is view rotation only we can decrease the time allowed by the angle between quats * this means small rotations won't lag. */ if (sview->quat && !sview->ofs && !sview->dist) { /* scale the time allowed by the rotation */ /* 180deg == 1.0 */ - sms.time_allowed *= (double)fabsf(angle_signed_normalized_qtqt(sms.dst.quat, sms.src.quat)) / + sms.time_allowed *= double(fabsf(angle_signed_normalized_qtqt(sms.dst.quat, sms.src.quat))) / M_PI; } @@ -313,10 +313,10 @@ void ED_view3d_smooth_view_ex( if (sms.to_camera) { /* use ortho if we move from an ortho view to an ortho camera */ Object *ob_camera_eval = DEG_get_evaluated_object(depsgraph, sview->camera); - rv3d->persp = (((rv3d->is_persp == false) && (ob_camera_eval->type == OB_CAMERA) && - (((Camera *)ob_camera_eval->data)->type == CAM_ORTHO)) ? - RV3D_ORTHO : - RV3D_PERSP); + rv3d->persp = ((rv3d->is_persp == false) && (ob_camera_eval->type == OB_CAMERA) && + (static_cast(ob_camera_eval->data)->type == CAM_ORTHO)) ? + RV3D_ORTHO : + RV3D_PERSP; } rv3d->rflag |= RV3D_NAVIGATING; @@ -326,8 +326,9 @@ void ED_view3d_smooth_view_ex( view3d_smooth_view_state_restore(&sms.src, v3d, rv3d); /* keep track of running timer! */ - if (rv3d->sms == NULL) { - rv3d->sms = MEM_mallocN(sizeof(struct SmoothView3DStore), "smoothview v3d"); + if (rv3d->sms == nullptr) { + rv3d->sms = static_cast( + MEM_mallocN(sizeof(SmoothView3DStore), "smoothview v3d")); } *rv3d->sms = sms; if (rv3d->smooth_timer) { @@ -377,10 +378,10 @@ void ED_view3d_smooth_view(bContext *C, /* #ED_view3d_smooth_view_ex asserts this is not set as it doesn't support undo. */ V3D_SmoothParams sview_no_undo = *sview; - sview_no_undo.undo_str = NULL; + sview_no_undo.undo_str = nullptr; sview_no_undo.undo_grouped = false; - const bool do_undo = (sview->undo_str != NULL); + const bool do_undo = (sview->undo_str != nullptr); if (do_undo) { ED_view3d_smooth_view_undo_begin(C, area); } @@ -398,7 +399,7 @@ void ED_view3d_smooth_view(bContext *C, static void view3d_smoothview_apply_with_interp( bContext *C, View3D *v3d, RegionView3D *rv3d, const bool use_autokey, const float factor) { - struct SmoothView3DStore *sms = rv3d->sms; + SmoothView3DStore *sms = rv3d->sms; interp_qt_qtqt(rv3d->viewquat, sms->src.quat, sms->dst.quat, factor); @@ -427,7 +428,7 @@ static void view3d_smoothview_apply_with_interp( static void view3d_smoothview_apply_and_finish(bContext *C, View3D *v3d, RegionView3D *rv3d) { wmWindowManager *wm = CTX_wm_manager(C); - struct SmoothView3DStore *sms = rv3d->sms; + SmoothView3DStore *sms = rv3d->sms; wmWindow *win = CTX_wm_window(C); @@ -451,10 +452,10 @@ static void view3d_smoothview_apply_and_finish(bContext *C, View3D *v3d, RegionV } MEM_freeN(rv3d->sms); - rv3d->sms = NULL; + rv3d->sms = nullptr; WM_event_remove_timer(wm, win, rv3d->smooth_timer); - rv3d->smooth_timer = NULL; + rv3d->smooth_timer = nullptr; rv3d->rflag &= ~RV3D_NAVIGATING; /* Event handling won't know if a UI item has been moved under the pointer. */ @@ -473,12 +474,12 @@ static void view3d_smoothview_apply_and_finish(bContext *C, View3D *v3d, RegionV static void view3d_smoothview_apply_from_timer(bContext *C, View3D *v3d, ARegion *region) { wmWindowManager *wm = CTX_wm_manager(C); - RegionView3D *rv3d = region->regiondata; - struct SmoothView3DStore *sms = rv3d->sms; + RegionView3D *rv3d = static_cast(region->regiondata); + SmoothView3DStore *sms = rv3d->sms; float factor; if (sms->time_allowed != 0.0) { - factor = (float)((rv3d->smooth_timer->duration) / sms->time_allowed); + factor = float(rv3d->smooth_timer->duration / sms->time_allowed); } else { factor = 1.0f; @@ -500,14 +501,14 @@ static void view3d_smoothview_apply_from_timer(bContext *C, View3D *v3d, ARegion ED_region_tag_redraw(region); } -static int view3d_smoothview_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) +static int view3d_smoothview_invoke(bContext *C, wmOperator * /*op*/, const wmEvent *event) { View3D *v3d = CTX_wm_view3d(C); ARegion *region = CTX_wm_region(C); - RegionView3D *rv3d = region->regiondata; + RegionView3D *rv3d = static_cast(region->regiondata); /* escape if not our timer */ - if (rv3d->smooth_timer == NULL || rv3d->smooth_timer != event->customdata) { + if (rv3d->smooth_timer == nullptr || rv3d->smooth_timer != event->customdata) { return OPERATOR_PASS_THROUGH; } @@ -518,7 +519,7 @@ static int view3d_smoothview_invoke(bContext *C, wmOperator *UNUSED(op), const w void ED_view3d_smooth_view_force_finish(bContext *C, View3D *v3d, ARegion *region) { - RegionView3D *rv3d = region->regiondata; + RegionView3D *rv3d = static_cast(region->regiondata); if (rv3d && rv3d->sms) { view3d_smoothview_apply_and_finish(C, v3d, rv3d); @@ -526,7 +527,7 @@ void ED_view3d_smooth_view_force_finish(bContext *C, View3D *v3d, ARegion *regio * can use them without redrawing first */ Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); - ED_view3d_update_viewmat(depsgraph, scene, v3d, region, NULL, NULL, NULL, false); + ED_view3d_update_viewmat(depsgraph, scene, v3d, region, nullptr, nullptr, nullptr, false); } } diff --git a/source/blender/editors/space_view3d/view3d_navigate_walk.c b/source/blender/editors/space_view3d/view3d_navigate_walk.cc similarity index 94% rename from source/blender/editors/space_view3d/view3d_navigate_walk.c rename to source/blender/editors/space_view3d/view3d_navigate_walk.cc index b7f9814a40c..4671be749c2 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_walk.c +++ b/source/blender/editors/space_view3d/view3d_navigate_walk.cc @@ -8,7 +8,7 @@ * Interactive walk navigation modal operator * (similar to walking around in a first person game). * - * \note Similar logic to `view3d_navigate_fly.c` changes here may apply there too. + * \note Similar logic to `view3d_navigate_fly.cc` changes here may apply there too. */ /* defines VIEW3D_OT_navigate - walk modal operator */ @@ -47,7 +47,7 @@ #include "DEG_depsgraph.h" #include "view3d_intern.h" /* own include */ -#include "view3d_navigate.h" +#include "view3d_navigate.hh" #ifdef WITH_INPUT_NDOF //# define NDOF_WALK_DEBUG @@ -167,7 +167,7 @@ void walk_modal_keymap(wmKeyConfig *keyconf) {WALK_MODAL_AXIS_LOCK_Z, "AXIS_LOCK_Z", 0, "Z Axis Correction", "Z axis correction"}, - {0, NULL, 0, NULL, NULL}, + {0, nullptr, 0, nullptr, nullptr}, }; wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Walk Modal"); @@ -189,17 +189,16 @@ void walk_modal_keymap(wmKeyConfig *keyconf) /** \name Internal Walk Structs * \{ */ -typedef struct WalkTeleport { +struct WalkTeleport { eWalkTeleportState state; float duration; /* from user preferences */ float origin[3]; float direction[3]; double initial_time; eWalkMethod navigation_mode; /* teleport always set FREE mode on */ +}; -} WalkTeleport; - -typedef struct WalkInfo { +struct WalkInfo { /* context stuff */ RegionView3D *rv3d; View3D *v3d; @@ -296,9 +295,8 @@ typedef struct WalkInfo { SnapObjectContext *snap_context; - struct View3DCameraControl *v3d_camera_control; - -} WalkInfo; + View3DCameraControl *v3d_camera_control; +}; /** \} */ @@ -313,10 +311,10 @@ static void walkApply_ndof(bContext *C, WalkInfo *walk, bool is_confirm); static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm); static float getVelocityZeroTime(const float gravity, const float velocity); -static void drawWalkPixel(const bContext *UNUSED(C), ARegion *region, void *arg) +static void drawWalkPixel(const bContext * /*C*/, ARegion *region, void *arg) { /* draws an aim/cross in the center */ - WalkInfo *walk = arg; + WalkInfo *walk = static_cast(arg); const int outter_length = 24; const int inner_length = 14; @@ -403,20 +401,20 @@ static bool walk_floor_distance_get(RegionView3D *rv3d, mul_v3_v3fl(dvec_tmp, dvec, walk->grid); add_v3_v3(ray_start, dvec_tmp); - ret = ED_transform_snap_object_project_ray( - walk->snap_context, - walk->depsgraph, - walk->v3d, - &(const struct SnapObjectParams){ - .snap_target_select = SCE_SNAP_TARGET_ALL, - /* Avoid having to convert the edit-mesh to a regular mesh. */ - .edit_mode_type = SNAP_GEOM_EDIT, - }, - ray_start, - ray_normal, - r_distance, - r_location, - r_normal_dummy); + SnapObjectParams snap_params = {}; + snap_params.snap_target_select = SCE_SNAP_TARGET_ALL; + /* Avoid having to convert the edit-mesh to a regular mesh. */ + snap_params.edit_mode_type = SNAP_GEOM_EDIT; + + ret = ED_transform_snap_object_project_ray(walk->snap_context, + walk->depsgraph, + walk->v3d, + &snap_params, + ray_start, + ray_normal, + r_distance, + r_location, + r_normal_dummy); /* artificially scale the distance to the scene size */ *r_distance /= walk->grid; @@ -446,15 +444,16 @@ static bool walk_ray_cast(RegionView3D *rv3d, normalize_v3(ray_normal); + SnapObjectParams snap_params = {}; + snap_params.snap_target_select = SCE_SNAP_TARGET_ALL; + ret = ED_transform_snap_object_project_ray(walk->snap_context, walk->depsgraph, walk->v3d, - &(const struct SnapObjectParams){ - .snap_target_select = SCE_SNAP_TARGET_ALL, - }, + &snap_params, ray_start, ray_normal, - NULL, + nullptr, r_location, r_normal); @@ -496,7 +495,7 @@ static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op, const int #endif /* sanity check: for rare but possible case (if lib-linking the camera fails) */ - if ((walk->rv3d->persp == RV3D_CAMOB) && (walk->v3d->camera == NULL)) { + if ((walk->rv3d->persp == RV3D_CAMOB) && (walk->v3d->camera == nullptr)) { walk->rv3d->persp = RV3D_PERSP; } @@ -575,7 +574,7 @@ static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op, const int walk->timer = WM_event_add_timer(CTX_wm_manager(C), win, TIMER, 0.01f); #ifdef WITH_INPUT_NDOF - walk->ndof = NULL; + walk->ndof = nullptr; #endif walk->anim_playing = ED_screen_animation_playing(wm); @@ -597,7 +596,7 @@ static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op, const int copy_v2_v2_int(walk->init_mval, mval); copy_v2_v2_int(walk->prev_mval, mval); - WM_cursor_grab_enable(win, 0, NULL, true); + WM_cursor_grab_enable(win, WM_CURSOR_WRAP_NONE, nullptr, true); return 1; } @@ -646,7 +645,7 @@ static int walkEnd(bContext *C, WalkInfo *walk) } #endif - WM_cursor_grab_disable(win, NULL); + WM_cursor_grab_disable(win, nullptr); if (walk->state == WALK_CONFIRM) { MEM_freeN(walk); @@ -685,7 +684,8 @@ static void walkEvent(WalkInfo *walk, const wmEvent *event) // puts("ndof motion detected in walk mode!"); // static const char *tag_name = "3D mouse position"; - const wmNDOFMotionData *incoming_ndof = event->customdata; + const wmNDOFMotionData *incoming_ndof = static_cast( + event->customdata); switch (incoming_ndof->progress) { case P_STARTING: /* start keeping track of 3D mouse position */ @@ -699,9 +699,9 @@ static void walkEvent(WalkInfo *walk, const wmEvent *event) putchar('.'); fflush(stdout); # endif - if (walk->ndof == NULL) { + if (walk->ndof == nullptr) { // walk->ndof = MEM_mallocN(sizeof(wmNDOFMotionData), tag_name); - walk->ndof = MEM_dupallocN(incoming_ndof); + walk->ndof = static_cast(MEM_dupallocN(incoming_ndof)); // walk->ndof = malloc(sizeof(wmNDOFMotionData)); } else { @@ -716,7 +716,7 @@ static void walkEvent(WalkInfo *walk, const wmEvent *event) if (walk->ndof) { MEM_freeN(walk->ndof); // free(walk->ndof); - walk->ndof = NULL; + walk->ndof = nullptr; } /* update the time else the view will jump when 2D mouse/timer resume */ @@ -806,7 +806,7 @@ static void walkEvent(WalkInfo *walk, const wmEvent *event) float t; /* delta time */ - t = (float)(PIL_check_seconds_timer() - walk->teleport.initial_time); + t = float(PIL_check_seconds_timer() - walk->teleport.initial_time); /* Reduce the velocity, if JUMP wasn't hold for long enough. */ t = min_ff(t, JUMP_TIME_MAX); @@ -985,7 +985,7 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) walk->redraw = 1; #endif time_current = PIL_check_seconds_timer(); - time_redraw = (float)(time_current - walk->time_lastdraw); + time_redraw = float(time_current - walk->time_lastdraw); /* Clamp redraw time to avoid jitter in roll correction. */ time_redraw_clamped = min_ff(0.05f, time_redraw); @@ -1012,7 +1012,7 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) float y; /* relative offset */ - y = (float)moffset[1]; + y = float(moffset[1]); /* Speed factor. */ #ifdef USE_TABLET_SUPPORT @@ -1061,7 +1061,7 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) } /* relative offset */ - x = (float)moffset[0]; + x = float(moffset[0]); /* Speed factor. */ #ifdef USE_TABLET_SUPPORT @@ -1232,7 +1232,7 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) float ray_distance, difference = -100.0f; /* delta time */ - t = (float)(PIL_check_seconds_timer() - walk->teleport.initial_time); + t = float(PIL_check_seconds_timer() - walk->teleport.initial_time); /* keep moving if we were moving */ copy_v2_v2(dvec, walk->teleport.direction); @@ -1277,7 +1277,7 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) float cur_loc[3]; /* linear interpolation */ - t = (float)(PIL_check_seconds_timer() - walk->teleport.initial_time); + t = float(PIL_check_seconds_timer() - walk->teleport.initial_time); t /= walk->teleport.duration; /* clamp so we don't go past our limit */ @@ -1364,7 +1364,7 @@ static int walk_invoke(bContext *C, wmOperator *op, const wmEvent *event) return OPERATOR_CANCELLED; } - walk = MEM_callocN(sizeof(WalkInfo), "NavigationWalkOperation"); + walk = MEM_cnew("NavigationWalkOperation"); op->customdata = walk; @@ -1382,18 +1382,18 @@ static int walk_invoke(bContext *C, wmOperator *op, const wmEvent *event) static void walk_cancel(bContext *C, wmOperator *op) { - WalkInfo *walk = op->customdata; + WalkInfo *walk = static_cast(op->customdata); walk->state = WALK_CANCEL; walkEnd(C, walk); - op->customdata = NULL; + op->customdata = nullptr; } static int walk_modal(bContext *C, wmOperator *op, const wmEvent *event) { int exit_code; bool do_draw = false; - WalkInfo *walk = op->customdata; + WalkInfo *walk = static_cast(op->customdata); View3D *v3d = walk->v3d; RegionView3D *rv3d = walk->rv3d; Object *walk_object = ED_view3d_cameracontrol_object_get(walk->v3d_camera_control); diff --git a/source/blender/editors/space_view3d/view3d_navigate_zoom.c b/source/blender/editors/space_view3d/view3d_navigate_zoom.cc similarity index 92% rename from source/blender/editors/space_view3d/view3d_navigate_zoom.c rename to source/blender/editors/space_view3d/view3d_navigate_zoom.cc index 4b942c25930..c3fbf5dd125 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_zoom.c +++ b/source/blender/editors/space_view3d/view3d_navigate_zoom.cc @@ -23,7 +23,7 @@ #include "PIL_time.h" #include "view3d_intern.h" -#include "view3d_navigate.h" /* own include */ +#include "view3d_navigate.hh" /* own include */ /* -------------------------------------------------------------------- */ /** \name View Zoom Operator @@ -39,7 +39,7 @@ void viewzoom_modal_keymap(wmKeyConfig *keyconf) {VIEWROT_MODAL_SWITCH_ROTATE, "SWITCH_TO_ROTATE", 0, "Switch to Rotate"}, {VIEWROT_MODAL_SWITCH_MOVE, "SWITCH_TO_MOVE", 0, "Switch to Move"}, - {0, NULL, 0, NULL, NULL}, + {0, nullptr, 0, nullptr, nullptr}, }; wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Zoom Modal"); @@ -57,7 +57,7 @@ void viewzoom_modal_keymap(wmKeyConfig *keyconf) /** * \param zoom_xy: Optionally zoom to window location - * (coords compatible w/ #wmEvent.xy). Use when not NULL. + * (coords compatible w/ #wmEvent.xy). Use when not nullptr. */ static void view_zoom_to_window_xy_camera(Scene *scene, Depsgraph *depsgraph, @@ -66,18 +66,18 @@ static void view_zoom_to_window_xy_camera(Scene *scene, float dfac, const int zoom_xy[2]) { - RegionView3D *rv3d = region->regiondata; + RegionView3D *rv3d = static_cast(region->regiondata); const float zoomfac = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom); const float zoomfac_new = clamp_f( zoomfac * (1.0f / dfac), RV3D_CAMZOOM_MIN_FACTOR, RV3D_CAMZOOM_MAX_FACTOR); const float camzoom_new = BKE_screen_view3d_zoom_from_fac(zoomfac_new); - if (zoom_xy != NULL) { + if (zoom_xy != nullptr) { float zoomfac_px; rctf camera_frame_old; rctf camera_frame_new; - const float pt_src[2] = {zoom_xy[0], zoom_xy[1]}; + const float pt_src[2] = {float(zoom_xy[0]), float(zoom_xy[1])}; float pt_dst[2]; float delta_px[2]; @@ -110,14 +110,14 @@ static void view_zoom_to_window_xy_camera(Scene *scene, /** * \param zoom_xy: Optionally zoom to window location - * (coords compatible w/ #wmEvent.xy). Use when not NULL. + * (coords compatible w/ #wmEvent.xy). Use when not nullptr. */ static void view_zoom_to_window_xy_3d(ARegion *region, float dfac, const int zoom_xy[2]) { - RegionView3D *rv3d = region->regiondata; + RegionView3D *rv3d = static_cast(region->regiondata); const float dist_new = rv3d->dist * dfac; - if (zoom_xy != NULL) { + if (zoom_xy != nullptr) { float dvec[3]; float tvec[3]; float tpos[3]; @@ -127,8 +127,8 @@ static void view_zoom_to_window_xy_3d(ARegion *region, float dfac, const int zoo negate_v3_v3(tpos, rv3d->ofs); - xy_delta[0] = (float)(((zoom_xy[0] - region->winrct.xmin) * 2) - region->winx) / 2.0f; - xy_delta[1] = (float)(((zoom_xy[1] - region->winrct.ymin) * 2) - region->winy) / 2.0f; + xy_delta[0] = float(((zoom_xy[0] - region->winrct.xmin) * 2) - region->winx) / 2.0f; + xy_delta[1] = float(((zoom_xy[1] - region->winrct.ymin) * 2) - region->winy) / 2.0f; /* Project cursor position into 3D space */ zfac = ED_view3d_calc_zfac(rv3d, tpos); @@ -164,14 +164,14 @@ static float viewzoom_scale_value(const rcti *winrct, if (viewzoom == USER_ZOOM_CONTINUE) { double time = PIL_check_seconds_timer(); - float time_step = (float)(time - *r_timer_lastdraw); + float time_step = float(time - *r_timer_lastdraw); float fac; if (U.uiflag & USER_ZOOM_HORIZ) { - fac = (float)(xy_init[0] - xy_curr[0]); + fac = float(xy_init[0] - xy_curr[0]); } else { - fac = (float)(xy_init[1] - xy_curr[1]); + fac = float(xy_init[1] - xy_curr[1]); } fac /= UI_SCALE_FAC; @@ -190,8 +190,8 @@ static float viewzoom_scale_value(const rcti *winrct, BLI_rcti_cent_x(winrct), BLI_rcti_cent_y(winrct), }; - float len_new = (5 * UI_SCALE_FAC) + ((float)len_v2v2_int(ctr, xy_curr) / UI_SCALE_FAC); - float len_old = (5 * UI_SCALE_FAC) + ((float)len_v2v2_int(ctr, xy_init) / UI_SCALE_FAC); + float len_new = (5 * UI_SCALE_FAC) + (float(len_v2v2_int(ctr, xy_curr)) / UI_SCALE_FAC); + float len_old = (5 * UI_SCALE_FAC) + (float(len_v2v2_int(ctr, xy_init)) / UI_SCALE_FAC); /* intentionally ignore 'zoom_invert' for scale */ if (zoom_invert_force) { @@ -282,7 +282,7 @@ static void viewzoom_apply_camera(ViewOpsData *vod, vod->v3d, vod->region, zfac, - zoom_to_pos ? vod->prev.event_xy : NULL); + zoom_to_pos ? vod->prev.event_xy : nullptr); } ED_region_tag_redraw(vod->region); @@ -315,7 +315,7 @@ static void viewzoom_apply_3d(ViewOpsData *vod, const float zfac_max = dist_range[1] / vod->rv3d->dist; CLAMP(zfac, zfac_min, zfac_max); - view_zoom_to_window_xy_3d(vod->region, zfac, zoom_to_pos ? vod->prev.event_xy : NULL); + view_zoom_to_window_xy_3d(vod->region, zfac, zoom_to_pos ? vod->prev.event_xy : nullptr); } /* these limits were in old code too */ @@ -392,8 +392,8 @@ static void view_zoom_apply_step(bContext *C, const int delta, const int zoom_xy[2]) { - View3D *v3d = area->spacedata.first; - RegionView3D *rv3d = region->regiondata; + View3D *v3d = static_cast(area->spacedata.first); + RegionView3D *rv3d = static_cast(region->regiondata); bool use_cam_zoom; float dist_range[2]; @@ -437,20 +437,20 @@ static void view_zoom_apply_step(bContext *C, static int viewzoom_exec(bContext *C, wmOperator *op) { - BLI_assert(op->customdata == NULL); + BLI_assert(op->customdata == nullptr); Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); ScrArea *area = CTX_wm_area(C); ARegion *region = CTX_wm_region(C); - View3D *v3d = area->spacedata.first; - RegionView3D *rv3d = region->regiondata; + View3D *v3d = static_cast(area->spacedata.first); + RegionView3D *rv3d = static_cast(region->regiondata); const int delta = RNA_int_get(op->ptr, "delta"); const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); int zoom_xy_buf[2]; - const int *zoom_xy = NULL; + const int *zoom_xy = nullptr; const bool do_zoom_to_mouse_pos = (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)); if (do_zoom_to_mouse_pos) { zoom_xy_buf[0] = RNA_struct_property_is_set(op->ptr, "mx") ? RNA_int_get(op->ptr, "mx") : @@ -488,7 +488,7 @@ int viewzoom_invoke_impl(bContext *C, ViewOpsData *vod, const wmEvent *event, Po vod->area, vod->region, delta, - do_zoom_to_mouse_pos ? xy : NULL); + do_zoom_to_mouse_pos ? xy : nullptr); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/space_view3d/view3d_navigate_zoom_border.c b/source/blender/editors/space_view3d/view3d_navigate_zoom_border.cc similarity index 84% rename from source/blender/editors/space_view3d/view3d_navigate_zoom_border.c rename to source/blender/editors/space_view3d/view3d_navigate_zoom_border.cc index 3c926569c9b..0497b0b6222 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_zoom_border.c +++ b/source/blender/editors/space_view3d/view3d_navigate_zoom_border.cc @@ -23,7 +23,7 @@ #include "RNA_access.h" #include "view3d_intern.h" -#include "view3d_navigate.h" /* own include */ +#include "view3d_navigate.hh" /* own include */ /* -------------------------------------------------------------------- */ /** \name Border Zoom Operator @@ -61,7 +61,7 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) ED_view3d_dist_range_get(v3d, dist_range); ED_view3d_depth_override( - CTX_data_ensure_evaluated_depsgraph(C), region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, NULL); + CTX_data_ensure_evaluated_depsgraph(C), region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, nullptr); { /* avoid allocating the whole depth buffer */ ViewDepths depth_temp = {0}; @@ -77,17 +77,17 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) /* Resize border to the same ratio as the window. */ { - const float region_aspect = (float)region->winx / (float)region->winy; - if (((float)BLI_rcti_size_x(&rect) / (float)BLI_rcti_size_y(&rect)) < region_aspect) { - BLI_rcti_resize_x(&rect, (int)(BLI_rcti_size_y(&rect) * region_aspect)); + const float region_aspect = float(region->winx) / float(region->winy); + if ((float(BLI_rcti_size_x(&rect)) / float(BLI_rcti_size_y(&rect))) < region_aspect) { + BLI_rcti_resize_x(&rect, int(BLI_rcti_size_y(&rect) * region_aspect)); } else { - BLI_rcti_resize_y(&rect, (int)(BLI_rcti_size_x(&rect) / region_aspect)); + BLI_rcti_resize_y(&rect, int(BLI_rcti_size_x(&rect) / region_aspect)); } } - cent[0] = (((float)rect.xmin) + ((float)rect.xmax)) / 2; - cent[1] = (((float)rect.ymin) + ((float)rect.ymax)) / 2; + cent[0] = (float(rect.xmin) + float(rect.xmax)) / 2; + cent[1] = (float(rect.ymin) + float(rect.ymax)) / 2; if (rv3d->is_persp) { float p_corner[3]; @@ -172,16 +172,12 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) ED_view3d_persp_switch_from_camera(depsgraph, v3d, rv3d, RV3D_PERSP); } } + V3D_SmoothParams sview_params = {}; + sview_params.ofs = new_ofs; + sview_params.dist = &new_dist; + sview_params.undo_str = op->type->name; - ED_view3d_smooth_view(C, - v3d, - region, - smooth_viewtx, - &(const V3D_SmoothParams){ - .ofs = new_ofs, - .dist = &new_dist, - .undo_str = op->type->name, - }); + ED_view3d_smooth_view(C, v3d, region, smooth_viewtx, &sview_params); if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) { view3d_boxview_sync(CTX_wm_area(C), region); diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.cc similarity index 98% rename from source/blender/editors/space_view3d/view3d_ops.c rename to source/blender/editors/space_view3d/view3d_ops.cc index 6de7de43961..5bef4f22212 100644 --- a/source/blender/editors/space_view3d/view3d_ops.c +++ b/source/blender/editors/space_view3d/view3d_ops.cc @@ -6,8 +6,7 @@ * \ingroup spview3d */ -#include -#include +#include #include "DNA_object_types.h" #include "DNA_scene_types.h" @@ -35,7 +34,7 @@ #include "ED_transform.h" #include "view3d_intern.h" -#include "view3d_navigate.h" +#include "view3d_navigate.hh" #ifdef WIN32 # include "BLI_math_base.h" /* M_PI */ @@ -119,7 +118,7 @@ static int view3d_pastebuffer_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - WM_event_add_notifier(C, NC_WINDOW, NULL); + WM_event_add_notifier(C, NC_WINDOW, nullptr); ED_outliner_select_sync_from_object_tag(C); BKE_reportf(op->reports, RPT_INFO, "%d object(s) pasted", num_pasted); diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.cc similarity index 84% rename from source/blender/editors/space_view3d/view3d_view.c rename to source/blender/editors/space_view3d/view3d_view.cc index d3c25ecaa3c..dee69cdf7ac 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.cc @@ -45,13 +45,13 @@ #include "RNA_define.h" #include "view3d_intern.h" /* own include */ -#include "view3d_navigate.h" +#include "view3d_navigate.hh" /* -------------------------------------------------------------------- */ /** \name Camera to View Operator * \{ */ -static int view3d_camera_to_view_exec(bContext *C, wmOperator *UNUSED(op)) +static int view3d_camera_to_view_exec(bContext *C, wmOperator * /*op*/) { const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); View3D *v3d; @@ -61,7 +61,7 @@ static int view3d_camera_to_view_exec(bContext *C, wmOperator *UNUSED(op)) ObjectTfmProtectedChannels obtfm; ED_view3d_context_user_region(C, &v3d, ®ion); - rv3d = region->regiondata; + rv3d = static_cast(region->regiondata); ED_view3d_lastview_store(rv3d); @@ -85,7 +85,7 @@ static bool view3d_camera_to_view_poll(bContext *C) ARegion *region; if (ED_view3d_context_user_region(C, &v3d, ®ion)) { - RegionView3D *rv3d = region->regiondata; + RegionView3D *rv3d = static_cast(region->regiondata); if (v3d && v3d->camera && BKE_id_is_editable(CTX_data_main(C), &v3d->camera->id)) { if (rv3d && (RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ANY_TRANSFORM) == 0) { if (rv3d->persp != RV3D_CAMOB) { @@ -126,10 +126,10 @@ static int view3d_camera_to_view_selected_exec(bContext *C, wmOperator *op) Main *bmain = CTX_data_main(C); Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); - View3D *v3d = CTX_wm_view3d(C); /* can be NULL */ + View3D *v3d = CTX_wm_view3d(C); /* can be nullptr */ Object *camera_ob = v3d ? v3d->camera : scene->camera; - if (camera_ob == NULL) { + if (camera_ob == nullptr) { BKE_report(op->reports, RPT_ERROR, "No active camera"); return OPERATOR_CANCELLED; } @@ -168,13 +168,11 @@ static void sync_viewport_camera_smoothview(bContext *C, const int smooth_viewtx) { Main *bmain = CTX_data_main(C); - for (bScreen *screen = bmain->screens.first; screen != NULL; screen = screen->id.next) { - for (ScrArea *area = screen->areabase.first; area != NULL; area = area->next) { - for (SpaceLink *space_link = area->spacedata.first; space_link != NULL; - space_link = space_link->next) - { + LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, space_link, &area->spacedata) { if (space_link->spacetype == SPACE_VIEW3D) { - View3D *other_v3d = (View3D *)space_link; + View3D *other_v3d = reinterpret_cast(space_link); if (other_v3d == v3d) { continue; } @@ -185,29 +183,27 @@ static void sync_viewport_camera_smoothview(bContext *C, if (v3d->scenelock && other_v3d->scenelock) { ListBase *lb = (space_link == area->spacedata.first) ? &area->regionbase : &space_link->regionbase; - for (ARegion *other_region = lb->first; other_region != NULL; - other_region = other_region->next) { + LISTBASE_FOREACH (ARegion *, other_region, lb) { if (other_region->regiontype == RGN_TYPE_WINDOW) { if (other_region->regiondata) { - RegionView3D *other_rv3d = other_region->regiondata; + RegionView3D *other_rv3d = static_cast(other_region->regiondata); if (other_rv3d->persp == RV3D_CAMOB) { Object *other_camera_old = other_v3d->camera; other_v3d->camera = ob; + + V3D_SmoothParams sview_params = {}; + sview_params.camera_old = other_camera_old; + sview_params.camera = other_v3d->camera; + sview_params.ofs = other_rv3d->ofs; + sview_params.quat = other_rv3d->viewquat; + sview_params.dist = &other_rv3d->dist; + sview_params.lens = &other_v3d->lens; + /* No undo because this switches cameras. */ + sview_params.undo_str = nullptr; + ED_view3d_lastview_store(other_rv3d); - ED_view3d_smooth_view(C, - other_v3d, - other_region, - smooth_viewtx, - &(const V3D_SmoothParams){ - .camera_old = other_camera_old, - .camera = other_v3d->camera, - .ofs = other_rv3d->ofs, - .quat = other_rv3d->viewquat, - .dist = &other_rv3d->dist, - .lens = &other_v3d->lens, - /* No undo because this switches cameras. */ - .undo_str = NULL, - }); + ED_view3d_smooth_view( + C, other_v3d, other_region, smooth_viewtx, &sview_params); } else { other_v3d->camera = ob; @@ -233,12 +229,12 @@ static int view3d_setobjectascamera_exec(bContext *C, wmOperator *op) const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); - /* no NULL check is needed, poll checks */ + /* no nullptr check is needed, poll checks */ ED_view3d_context_user_region(C, &v3d, ®ion); - rv3d = region->regiondata; + rv3d = static_cast(region->regiondata); if (ob) { - Object *camera_old = (rv3d->persp == RV3D_CAMOB) ? V3D_CAMERA_SCENE(scene, v3d) : NULL; + Object *camera_old = (rv3d->persp == RV3D_CAMOB) ? V3D_CAMERA_SCENE(scene, v3d) : nullptr; rv3d->persp = RV3D_CAMOB; v3d->camera = ob; if (v3d->scenelock && scene->camera != ob) { @@ -248,22 +244,18 @@ static int view3d_setobjectascamera_exec(bContext *C, wmOperator *op) /* unlikely but looks like a glitch when set to the same */ if (camera_old != ob) { - ED_view3d_lastview_store(rv3d); + V3D_SmoothParams sview_params = {}; + sview_params.camera_old = camera_old; + sview_params.camera = v3d->camera; + sview_params.ofs = rv3d->ofs; + sview_params.quat = rv3d->viewquat; + sview_params.dist = &rv3d->dist; + sview_params.lens = &v3d->lens; + /* No undo because this switches cameras. */ + sview_params.undo_str = nullptr; - ED_view3d_smooth_view(C, - v3d, - region, - smooth_viewtx, - &(const V3D_SmoothParams){ - .camera_old = camera_old, - .camera = v3d->camera, - .ofs = rv3d->ofs, - .quat = rv3d->viewquat, - .dist = &rv3d->dist, - .lens = &v3d->lens, - /* No undo because this switches cameras. */ - .undo_str = NULL, - }); + ED_view3d_lastview_store(rv3d); + ED_view3d_smooth_view(C, v3d, region, smooth_viewtx, &sview_params); } if (v3d->scenelock) { @@ -310,13 +302,20 @@ void view3d_winmatrix_set(Depsgraph *depsgraph, const View3D *v3d, const rcti *rect) { - RegionView3D *rv3d = region->regiondata; + RegionView3D *rv3d = static_cast(region->regiondata); rctf full_viewplane; float clipsta, clipend; bool is_ortho; - is_ortho = ED_view3d_viewplane_get( - depsgraph, v3d, rv3d, region->winx, region->winy, &full_viewplane, &clipsta, &clipend, NULL); + is_ortho = ED_view3d_viewplane_get(depsgraph, + v3d, + rv3d, + region->winx, + region->winy, + &full_viewplane, + &clipsta, + &clipend, + nullptr); rv3d->is_persp = !is_ortho; #if 0 @@ -337,13 +336,13 @@ void view3d_winmatrix_set(Depsgraph *depsgraph, if (rect) { /* Smaller viewplane subset for selection picking. */ viewplane.xmin = full_viewplane.xmin + - (BLI_rctf_size_x(&full_viewplane) * (rect->xmin / (float)region->winx)); + (BLI_rctf_size_x(&full_viewplane) * (rect->xmin / float(region->winx))); viewplane.ymin = full_viewplane.ymin + - (BLI_rctf_size_y(&full_viewplane) * (rect->ymin / (float)region->winy)); + (BLI_rctf_size_y(&full_viewplane) * (rect->ymin / float(region->winy))); viewplane.xmax = full_viewplane.xmin + - (BLI_rctf_size_x(&full_viewplane) * (rect->xmax / (float)region->winx)); + (BLI_rctf_size_x(&full_viewplane) * (rect->xmax / float(region->winx))); viewplane.ymax = full_viewplane.ymin + - (BLI_rctf_size_y(&full_viewplane) * (rect->ymax / (float)region->winy)); + (BLI_rctf_size_y(&full_viewplane) * (rect->ymax / float(region->winy))); } else { viewplane = full_viewplane; @@ -486,7 +485,7 @@ struct DrawSelectLoopUserData { static bool drw_select_loop_pass(eDRWSelectStage stage, void *user_data) { bool continue_pass = false; - struct DrawSelectLoopUserData *data = user_data; + DrawSelectLoopUserData *data = static_cast(user_data); if (stage == DRW_SELECT_PASS_PRE) { GPU_select_begin_next( data->buffer, data->buffer_len, data->rect, data->gpu_select_mode, data->hits); @@ -527,8 +526,8 @@ eV3DSelectObjectFilter ED_view3d_select_filter_from_mode(const Scene *scene, con /** Implement #VIEW3D_SELECT_FILTER_OBJECT_MODE_LOCK. */ static bool drw_select_filter_object_mode_lock(Object *ob, void *user_data) { - const Object *obact = user_data; - return BKE_object_is_mode_compat(ob, obact->mode); + const Object *obact = static_cast(user_data); + return BKE_object_is_mode_compat(ob, eObjectMode(obact->mode)); } /** @@ -537,7 +536,7 @@ static bool drw_select_filter_object_mode_lock(Object *ob, void *user_data) */ static bool drw_select_filter_object_mode_lock_for_weight_paint(Object *ob, void *user_data) { - LinkNode *ob_pose_list = user_data; + LinkNode *ob_pose_list = static_cast(user_data); return ob_pose_list && (BLI_linklist_index(ob_pose_list, DEG_get_original_object(ob)) != -1); } @@ -549,7 +548,7 @@ int view3d_opengl_select_ex(ViewContext *vc, eV3DSelectObjectFilter select_filter, const bool do_material_slot_selection) { - struct bThemeState theme_state; + bThemeState theme_state; const wmWindowManager *wm = CTX_wm_manager(vc->C); Depsgraph *depsgraph = vc->depsgraph; Scene *scene = vc->scene; @@ -558,8 +557,8 @@ int view3d_opengl_select_ex(ViewContext *vc, rcti rect; int hits = 0; BKE_view_layer_synced_ensure(scene, vc->view_layer); - const bool use_obedit_skip = (BKE_view_layer_edit_object_get(vc->view_layer) != NULL) && - (vc->obedit == NULL); + const bool use_obedit_skip = (BKE_view_layer_edit_object_get(vc->view_layer) != nullptr) && + (vc->obedit == nullptr); const bool is_pick_select = (U.gpu_flag & USER_GPU_FLAG_NO_DEPT_PICK) == 0; const bool do_passes = ((is_pick_select == false) && (select_mode == VIEW3D_SELECT_PICK_NEAREST)); @@ -570,8 +569,9 @@ int view3d_opengl_select_ex(ViewContext *vc, /* case not a box select */ if (input->xmin == input->xmax) { + const int xy[2] = {input->xmin, input->ymin}; /* seems to be default value for bones only now */ - BLI_rcti_init_pt_radius(&rect, (const int[2]){input->xmin, input->ymin}, 12); + BLI_rcti_init_pt_radius(&rect, xy, 12); } else { rect = *input; @@ -597,6 +597,13 @@ int view3d_opengl_select_ex(ViewContext *vc, } } + /* Important to use 'vc->obact', not 'BKE_view_layer_active_object_get(vc->view_layer)' below, + * so it will be nullptr when hidden. */ + struct { + DRW_ObjectFilterFn fn; + void *user_data; + } object_filter = {nullptr, nullptr}; + /* Re-use cache (rect must be smaller than the cached) * other context is assumed to be unchanged */ if (GPU_select_is_cached()) { @@ -606,12 +613,6 @@ int view3d_opengl_select_ex(ViewContext *vc, goto finally; } - /* Important to use 'vc->obact', not 'BKE_view_layer_active_object_get(vc->view_layer)' below, - * so it will be NULL when hidden. */ - struct { - DRW_ObjectFilterFn fn; - void *user_data; - } object_filter = {NULL, NULL}; switch (select_filter) { case VIEW3D_SELECT_FILTER_OBJECT_MODE_LOCK: { Object *obact = vc->obact; @@ -626,7 +627,7 @@ int view3d_opengl_select_ex(ViewContext *vc, BLI_assert(obact && (obact->mode & OB_MODE_ALL_WEIGHT_PAINT)); /* While this uses 'alloca' in a loop (which we typically avoid), * the number of items is nearly always 1, maybe 2..3 in rare cases. */ - LinkNode *ob_pose_list = NULL; + LinkNode *ob_pose_list = nullptr; if (obact->type == OB_GPENCIL_LEGACY) { GpencilVirtualModifierData virtualModifierData; const GpencilModifierData *md = BKE_gpencil_modifiers_get_virtual_modifierlist( @@ -673,7 +674,7 @@ int view3d_opengl_select_ex(ViewContext *vc, /* Important we use the 'viewmat' and don't re-calculate since * the object & bone view locking takes 'rect' into account, see: #51629. */ ED_view3d_draw_setup_view( - wm, vc->win, depsgraph, scene, region, v3d, vc->rv3d->viewmat, NULL, &rect); + wm, vc->win, depsgraph, scene, region, v3d, vc->rv3d->viewmat, nullptr, &rect); if (!XRAY_ACTIVE(v3d)) { GPU_depth_test(GPU_DEPTH_LESS_EQUAL); @@ -683,14 +684,14 @@ int view3d_opengl_select_ex(ViewContext *vc, if (XRAY_ACTIVE(v3d) && use_nearest) { /* We need to call "GPU_select_*" API's inside DRW_draw_select_loop * because the OpenGL context created & destroyed inside this function. */ - struct DrawSelectLoopUserData drw_select_loop_user_data = { - .pass = 0, - .hits = 0, - .buffer = buffer, - .buffer_len = buffer_len, - .rect = &rect, - .gpu_select_mode = gpu_select_mode, - }; + DrawSelectLoopUserData drw_select_loop_user_data = {}; + drw_select_loop_user_data.pass = 0; + drw_select_loop_user_data.hits = 0; + drw_select_loop_user_data.buffer = buffer; + drw_select_loop_user_data.buffer_len = buffer_len; + drw_select_loop_user_data.rect = ▭ + drw_select_loop_user_data.gpu_select_mode = gpu_select_mode; + draw_surface = false; DRW_draw_select_loop(depsgraph, region, @@ -713,14 +714,14 @@ int view3d_opengl_select_ex(ViewContext *vc, if (hits == 0) { /* We need to call "GPU_select_*" API's inside DRW_draw_select_loop * because the OpenGL context created & destroyed inside this function. */ - struct DrawSelectLoopUserData drw_select_loop_user_data = { - .pass = 0, - .hits = 0, - .buffer = buffer, - .buffer_len = buffer_len, - .rect = &rect, - .gpu_select_mode = gpu_select_mode, - }; + DrawSelectLoopUserData drw_select_loop_user_data = {}; + drw_select_loop_user_data.pass = 0; + drw_select_loop_user_data.hits = 0; + drw_select_loop_user_data.buffer = buffer; + drw_select_loop_user_data.buffer_len = buffer_len; + drw_select_loop_user_data.rect = ▭ + drw_select_loop_user_data.gpu_select_mode = gpu_select_mode; + /* If are not in wireframe mode, we need to use the mesh surfaces to check for hits */ draw_surface = (v3d->shading.type > OB_WIRE) || !XRAY_ENABLED(v3d); DRW_draw_select_loop(depsgraph, @@ -740,7 +741,7 @@ int view3d_opengl_select_ex(ViewContext *vc, G.f &= ~G_FLAG_PICKSEL; ED_view3d_draw_setup_view( - wm, vc->win, depsgraph, scene, region, v3d, vc->rv3d->viewmat, NULL, NULL); + wm, vc->win, depsgraph, scene, region, v3d, vc->rv3d->viewmat, nullptr, nullptr); if (!XRAY_ACTIVE(v3d)) { GPU_depth_test(GPU_DEPTH_NONE); @@ -795,19 +796,16 @@ int view3d_opengl_select_with_id_filter(ViewContext *vc, static uint free_localview_bit(Main *bmain) { - ScrArea *area; - bScreen *screen; - ushort local_view_bits = 0; /* Sometimes we lose a local-view: when an area is closed. * Check all areas: which local-views are in use? */ - for (screen = bmain->screens.first; screen; screen = screen->id.next) { - for (area = screen->areabase.first; area; area = area->next) { - SpaceLink *sl = area->spacedata.first; + LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + SpaceLink *sl = static_cast(area->spacedata.first); for (; sl; sl = sl->next) { if (sl->spacetype == SPACE_VIEW3D) { - View3D *v3d = (View3D *)sl; + View3D *v3d = reinterpret_cast(sl); if (v3d->localvd) { local_view_bits |= v3d->local_view_uuid; } @@ -836,7 +834,7 @@ static bool view3d_localview_init(const Depsgraph *depsgraph, const int smooth_viewtx, ReportList *reports) { - View3D *v3d = area->spacedata.first; + View3D *v3d = static_cast(area->spacedata.first); float min[3], max[3], box[3]; float size = 0.0f; uint local_view_bit; @@ -893,23 +891,22 @@ static bool view3d_localview_init(const Depsgraph *depsgraph, return false; } - ARegion *region; - - v3d->localvd = MEM_mallocN(sizeof(View3D), "localview"); + v3d->localvd = static_cast(MEM_mallocN(sizeof(View3D), "localview")); memcpy(v3d->localvd, v3d, sizeof(View3D)); v3d->local_view_uuid = local_view_bit; - for (region = area->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { if (region->regiontype == RGN_TYPE_WINDOW) { - RegionView3D *rv3d = region->regiondata; + RegionView3D *rv3d = static_cast(region->regiondata); bool ok_dist = true; /* New view values. */ - Object *camera_old = NULL; + Object *camera_old = nullptr; float dist_new, ofs_new[3]; - rv3d->localvd = MEM_mallocN(sizeof(RegionView3D), "localview region"); + rv3d->localvd = static_cast( + MEM_mallocN(sizeof(RegionView3D), "localview region")); memcpy(rv3d->localvd, rv3d, sizeof(RegionView3D)); if (frame_selected) { @@ -938,22 +935,17 @@ static bool view3d_localview_init(const Depsgraph *depsgraph, } } - ED_view3d_smooth_view_ex(depsgraph, - wm, - win, - area, - v3d, - region, - smooth_viewtx, - &(const V3D_SmoothParams){ - .camera_old = camera_old, - .ofs = ofs_new, - .quat = rv3d->viewquat, - .dist = ok_dist ? &dist_new : NULL, - .lens = &v3d->lens, - /* No undo because this doesn't move the camera. */ - .undo_str = NULL, - }); + V3D_SmoothParams sview_params = {}; + sview_params.camera_old = camera_old; + sview_params.ofs = ofs_new; + sview_params.quat = rv3d->viewquat; + sview_params.dist = ok_dist ? &dist_new : nullptr; + sview_params.lens = &v3d->lens; + /* No undo because this doesn't move the camera. */ + sview_params.undo_str = nullptr; + + ED_view3d_smooth_view_ex( + depsgraph, wm, win, area, v3d, region, smooth_viewtx, &sview_params); } } } @@ -970,9 +962,9 @@ static void view3d_localview_exit(const Depsgraph *depsgraph, const bool frame_selected, const int smooth_viewtx) { - View3D *v3d = area->spacedata.first; + View3D *v3d = static_cast(area->spacedata.first); - if (v3d->localvd == NULL) { + if (v3d->localvd == nullptr) { return; } BKE_view_layer_synced_ensure(scene, view_layer); @@ -989,47 +981,42 @@ static void view3d_localview_exit(const Depsgraph *depsgraph, v3d->camera = v3d->localvd->camera; MEM_freeN(v3d->localvd); - v3d->localvd = NULL; + v3d->localvd = nullptr; MEM_SAFE_FREE(v3d->runtime.local_stats); LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { if (region->regiontype == RGN_TYPE_WINDOW) { - RegionView3D *rv3d = region->regiondata; + RegionView3D *rv3d = static_cast(region->regiondata); - if (rv3d->localvd == NULL) { + if (rv3d->localvd == nullptr) { continue; } if (frame_selected) { Object *camera_old_rv3d, *camera_new_rv3d; - camera_old_rv3d = (rv3d->persp == RV3D_CAMOB) ? camera_old : NULL; - camera_new_rv3d = (rv3d->localvd->persp == RV3D_CAMOB) ? camera_new : NULL; + camera_old_rv3d = (rv3d->persp == RV3D_CAMOB) ? camera_old : nullptr; + camera_new_rv3d = (rv3d->localvd->persp == RV3D_CAMOB) ? camera_new : nullptr; rv3d->view = rv3d->localvd->view; rv3d->persp = rv3d->localvd->persp; rv3d->camzoom = rv3d->localvd->camzoom; - ED_view3d_smooth_view_ex(depsgraph, - wm, - win, - area, - v3d, - region, - smooth_viewtx, - &(const V3D_SmoothParams){ - .camera_old = camera_old_rv3d, - .camera = camera_new_rv3d, - .ofs = rv3d->localvd->ofs, - .quat = rv3d->localvd->viewquat, - .dist = &rv3d->localvd->dist, - /* No undo because this doesn't move the camera. */ - .undo_str = NULL, - }); + V3D_SmoothParams sview_params = {}; + sview_params.camera_old = camera_old_rv3d; + sview_params.camera = camera_new_rv3d; + sview_params.ofs = rv3d->localvd->ofs; + sview_params.quat = rv3d->localvd->viewquat; + sview_params.dist = &rv3d->localvd->dist; + /* No undo because this doesn't move the camera. */ + sview_params.undo_str = nullptr; + + ED_view3d_smooth_view_ex( + depsgraph, wm, win, area, v3d, region, smooth_viewtx, &sview_params); } MEM_freeN(rv3d->localvd); - rv3d->localvd = NULL; + rv3d->localvd = nullptr; } } } @@ -1071,7 +1058,7 @@ static int localview_exec(bContext *C, wmOperator *op) ED_area_tag_redraw(area); /* Unselected objects become selected when exiting. */ - if (v3d->localvd == NULL) { + if (v3d->localvd == nullptr) { DEG_id_tag_update(&scene->id, ID_RECALC_SELECT); WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); } @@ -1118,7 +1105,7 @@ static int localview_remove_from_exec(bContext *C, wmOperator *op) ED_object_base_select(base, BA_DESELECT); if (base == view_layer->basact) { - view_layer->basact = NULL; + view_layer->basact = nullptr; } changed = true; } @@ -1138,7 +1125,7 @@ static int localview_remove_from_exec(bContext *C, wmOperator *op) static bool localview_remove_from_poll(bContext *C) { - if (CTX_data_edit_object(C) != NULL) { + if (CTX_data_edit_object(C) != nullptr) { return false; } @@ -1167,18 +1154,14 @@ void VIEW3D_OT_localview_remove_from(wmOperatorType *ot) static uint free_localcollection_bit(Main *bmain, ushort local_collections_uuid, bool *r_reset) { - ScrArea *area; - bScreen *screen; - ushort local_view_bits = 0; /* Check all areas: which local-views are in use? */ - for (screen = bmain->screens.first; screen; screen = screen->id.next) { - for (area = screen->areabase.first; area; area = area->next) { - SpaceLink *sl = area->spacedata.first; - for (; sl; sl = sl->next) { + LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { if (sl->spacetype == SPACE_VIEW3D) { - View3D *v3d = (View3D *)sl; + View3D *v3d = reinterpret_cast(sl); if (v3d->flag & V3D_LOCAL_COLLECTIONS) { local_view_bits |= v3d->local_collections_uuid; } @@ -1264,7 +1247,7 @@ void ED_view3d_local_collections_reset(bContext *C, const bool reset_all) LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { if (sl->spacetype == SPACE_VIEW3D) { - View3D *v3d = (View3D *)sl; + View3D *v3d = reinterpret_cast(sl); if (v3d->local_collections_uuid) { if (v3d->flag & V3D_LOCAL_COLLECTIONS) { local_view_bit &= ~v3d->local_collections_uuid; @@ -1283,7 +1266,8 @@ void ED_view3d_local_collections_reset(bContext *C, const bool reset_all) } else if (reset_all && (do_reset || (local_view_bit != ~(0)))) { view3d_local_collections_reset(bmain, ~(0)); - View3D v3d = {.local_collections_uuid = ~(0)}; + View3D v3d = {}; + v3d.local_collections_uuid = ~(0); BKE_layer_collection_local_sync(CTX_data_scene(C), CTX_data_view_layer(C), &v3d); DEG_id_tag_update(&CTX_data_scene(C)->id, ID_RECALC_BASE_FLAGS); } @@ -1320,10 +1304,10 @@ void ED_view3d_xr_mirror_update(const ScrArea *area, const View3D *v3d, const bo if (ED_view3d_area_user_region(area, v3d, ®ion_rv3d)) { if (enable) { - view3d_xr_mirror_begin(region_rv3d->regiondata); + view3d_xr_mirror_begin(static_cast(region_rv3d->regiondata)); } else { - view3d_xr_mirror_end(region_rv3d->regiondata); + view3d_xr_mirror_end(static_cast(region_rv3d->regiondata)); } } } @@ -1352,7 +1336,7 @@ void ED_view3d_xr_shading_update(wmWindowManager *wm, const View3D *v3d, const S if (xr_shading->prop) { IDP_FreeProperty(xr_shading->prop); - xr_shading->prop = NULL; + xr_shading->prop = nullptr; } /* Copy shading from View3D to VR view. */