diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-03-31 04:53:39 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-03-31 05:04:12 +0300 |
commit | 5678e6c2bcccd7ce80958f5a0bd7c92837a41e74 (patch) | |
tree | 177039f0a1491fe4469ef679b8814b6184d4fd71 /source | |
parent | 87aa514611b99f75baf1d54948f773ad9ee7a6c4 (diff) |
Cleanup: improve navigation gizmo flag use
Flag check for V3D_LOCK_CAMERA used boolean style assignment to a char,
which worked with this flag but could fail if other flags are added
that use this convention in the future.
- Add static type checks for values so any change to DNA types
will need to be made in the navigation gizmo too.
- Move camera lock check from `rv3d` to `v3d`,
as this isn't stored in the region data.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_gizmo_navigate.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_navigate.c b/source/blender/editors/space_view3d/view3d_gizmo_navigate.c index c0fe57a4cf4..f11b8566690 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_navigate.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_navigate.c @@ -143,10 +143,12 @@ struct NavigateWidgetGroup { struct { rcti rect_visible; struct { + int flag2; + } v3d; + struct { char is_persp; - char is_camera; + bool is_camera; char viewlock; - char cameralock; } rv3d; } state; int region_size[2]; @@ -227,11 +229,13 @@ static void WIDGETGROUP_navigate_setup(const bContext *C, wmGizmoGroup *gzgroup) /* Click only buttons (not modal). */ { - int gz_ids[] = {GZ_INDEX_PERSP, - GZ_INDEX_ORTHO, - GZ_INDEX_CAMERA, - GZ_INDEX_CAMERA_LOCK, - GZ_INDEX_CAMERA_UNLOCK}; + int gz_ids[] = { + GZ_INDEX_PERSP, + GZ_INDEX_ORTHO, + GZ_INDEX_CAMERA, + GZ_INDEX_CAMERA_LOCK, + GZ_INDEX_CAMERA_UNLOCK, + }; for (int i = 0; i < ARRAY_SIZE(gz_ids); i++) { wmGizmo *gz = navgroup->gz_array[gz_ids[i]]; RNA_boolean_set(gz->ptr, "show_drag", false); @@ -280,6 +284,7 @@ static void WIDGETGROUP_navigate_draw_prepare(const bContext *C, wmGizmoGroup *g ARegion *region = CTX_wm_region(C); const RegionView3D *rv3d = region->regiondata; View3D *v3d = CTX_wm_view3d(C); + const int v3d_flag2_test = V3D_LOCK_CAMERA; for (int i = 0; i < 3; i++) { copy_v3_v3(navgroup->gz_array[GZ_INDEX_ROTATE]->matrix_offset[i], rv3d->viewmat[i]); @@ -287,20 +292,24 @@ static void WIDGETGROUP_navigate_draw_prepare(const bContext *C, wmGizmoGroup *g const rcti *rect_visible = ED_region_visible_rect(region); + /* Ensure types match so bits are never lost on assignment. */ + CHECK_TYPE_PAIR(navgroup->state.v3d.flag2, v3d->flag2); + CHECK_TYPE_PAIR(navgroup->state.rv3d.viewlock, rv3d->viewlock); + if ((navgroup->state.rect_visible.xmax == rect_visible->xmax) && (navgroup->state.rect_visible.ymax == rect_visible->ymax) && + (navgroup->state.v3d.flag2 == (v3d->flag2 & v3d_flag2_test)) && (navgroup->state.rv3d.is_persp == rv3d->is_persp) && - (navgroup->state.rv3d.cameralock == (v3d->flag2 & V3D_LOCK_CAMERA)) && (navgroup->state.rv3d.is_camera == (rv3d->persp == RV3D_CAMOB)) && (navgroup->state.rv3d.viewlock == RV3D_LOCK_FLAGS(rv3d))) { return; } navgroup->state.rect_visible = *rect_visible; + navgroup->state.v3d.flag2 = v3d->flag2 & v3d_flag2_test; navgroup->state.rv3d.is_persp = rv3d->is_persp; navgroup->state.rv3d.is_camera = (rv3d->persp == RV3D_CAMOB); navgroup->state.rv3d.viewlock = RV3D_LOCK_FLAGS(rv3d); - navgroup->state.rv3d.cameralock = v3d->flag2 & V3D_LOCK_CAMERA; const bool show_navigate = (U.uiflag & USER_SHOW_GIZMO_NAVIGATE) != 0; const bool show_rotate_gizmo = (U.mini_axis_type == USER_MINI_AXIS_TYPE_GIZMO); |