UI: Gizmo Button to Lock Camera to View

2D gizmo navigation button that toggles 'Lock Camera to View' while in Camera View.

Differential Revision: https://developer.blender.org/D10835

Reviewed by Campbell Barton
This commit is contained in:
Harley Acheson 2021-03-30 14:09:26 -07:00
parent 1425411249
commit 87aa514611
Notes: blender-bot 2023-02-13 18:59:22 +01:00
Referenced by commit 4baf3964ae, Revert 87aa514611b9: Removal of Lock Camera Gizmo Button
Referenced by issue #87460, Decide on Camera Lock Gizmo Design
Referenced by issue #87386, Crash on "Lock Camera to View" gizmo after Reload Scripts
1 changed files with 57 additions and 10 deletions

View File

@ -67,45 +67,73 @@ enum {
GZ_INDEX_ORTHO = 4,
GZ_INDEX_CAMERA = 5,
GZ_INDEX_TOTAL = 6,
/* overlaps GZ_INDEX_ORTHO (switch between) */
GZ_INDEX_CAMERA_LOCK = 6,
GZ_INDEX_CAMERA_UNLOCK = 7,
GZ_INDEX_TOTAL = 8,
};
struct NavigateGizmoInfo {
const char *opname;
const char *gizmo;
uint icon;
void (*op_prop_fn)(PointerRNA *ptr);
};
static void navigate_context_toggle_camera_lock_init(PointerRNA *ptr)
{
RNA_string_set(ptr, "data_path", "space_data.lock_camera");
}
static struct NavigateGizmoInfo g_navigate_params[GZ_INDEX_TOTAL] = {
{
.opname = "VIEW3D_OT_move",
.gizmo = "GIZMO_GT_button_2d",
ICON_VIEW_PAN,
.icon = ICON_VIEW_PAN,
.op_prop_fn = NULL,
},
{
.opname = "VIEW3D_OT_rotate",
.gizmo = "VIEW3D_GT_navigate_rotate",
0,
.icon = ICON_NONE,
.op_prop_fn = NULL,
},
{
.opname = "VIEW3D_OT_zoom",
.gizmo = "GIZMO_GT_button_2d",
ICON_VIEW_ZOOM,
.icon = ICON_VIEW_ZOOM,
.op_prop_fn = NULL,
},
{
.opname = "VIEW3D_OT_view_persportho",
.gizmo = "GIZMO_GT_button_2d",
ICON_VIEW_PERSPECTIVE,
.icon = ICON_VIEW_PERSPECTIVE,
.op_prop_fn = NULL,
},
{
.opname = "VIEW3D_OT_view_persportho",
.gizmo = "GIZMO_GT_button_2d",
ICON_VIEW_ORTHO,
.icon = ICON_VIEW_ORTHO,
.op_prop_fn = NULL,
},
{
.opname = "VIEW3D_OT_view_camera",
.gizmo = "GIZMO_GT_button_2d",
ICON_VIEW_CAMERA,
.icon = ICON_VIEW_CAMERA,
.op_prop_fn = NULL,
},
{
.opname = "WM_OT_context_toggle", /* GZ_INDEX_CAMERA_LOCK. Lock Camera to View. */
.gizmo = "GIZMO_GT_button_2d",
.icon = ICON_UNLOCKED,
.op_prop_fn = navigate_context_toggle_camera_lock_init,
},
{
.opname = "WM_OT_context_toggle", /* GZ_INDEX_CAMERA_UNLOCK. Unlock Camera to View. */
.gizmo = "GIZMO_GT_button_2d",
.icon = ICON_LOCKED,
.op_prop_fn = navigate_context_toggle_camera_lock_init,
},
};
@ -118,6 +146,7 @@ struct NavigateWidgetGroup {
char is_persp;
char is_camera;
char viewlock;
char cameralock;
} rv3d;
} state;
int region_size[2];
@ -177,7 +206,7 @@ static void WIDGETGROUP_navigate_setup(const bContext *C, wmGizmoGroup *gzgroup)
/* may be overwritten later */
gz->scale_basis = GIZMO_MINI_SIZE / 2.0f;
if (info->icon != 0) {
if (info->icon != ICON_NONE) {
PropertyRNA *prop = RNA_struct_find_property(gz->ptr, "icon");
RNA_property_enum_set(gz->ptr, prop, info->icon);
RNA_enum_set(
@ -185,7 +214,10 @@ static void WIDGETGROUP_navigate_setup(const bContext *C, wmGizmoGroup *gzgroup)
}
wmOperatorType *ot = WM_operatortype_find(info->opname, true);
WM_gizmo_operator_set(gz, 0, ot, NULL);
PointerRNA *ptr = WM_gizmo_operator_set(gz, 0, ot, NULL);
if (info->op_prop_fn != NULL) {
info->op_prop_fn(ptr);
}
}
{
@ -195,7 +227,11 @@ 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};
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);
@ -243,6 +279,7 @@ static void WIDGETGROUP_navigate_draw_prepare(const bContext *C, wmGizmoGroup *g
struct NavigateWidgetGroup *navgroup = gzgroup->customdata;
ARegion *region = CTX_wm_region(C);
const RegionView3D *rv3d = region->regiondata;
View3D *v3d = CTX_wm_view3d(C);
for (int i = 0; i < 3; i++) {
copy_v3_v3(navgroup->gz_array[GZ_INDEX_ROTATE]->matrix_offset[i], rv3d->viewmat[i]);
@ -253,6 +290,7 @@ static void WIDGETGROUP_navigate_draw_prepare(const bContext *C, wmGizmoGroup *g
if ((navgroup->state.rect_visible.xmax == rect_visible->xmax) &&
(navgroup->state.rect_visible.ymax == rect_visible->ymax) &&
(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;
@ -262,6 +300,7 @@ static void WIDGETGROUP_navigate_draw_prepare(const bContext *C, wmGizmoGroup *g
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);
@ -333,6 +372,14 @@ static void WIDGETGROUP_navigate_draw_prepare(const bContext *C, wmGizmoGroup *g
WM_gizmo_set_flag(gz, WM_GIZMO_HIDDEN, false);
}
}
if (navgroup->state.rv3d.is_camera == true) {
gz = navgroup->gz_array[(v3d->flag2 & V3D_LOCK_CAMERA) ? GZ_INDEX_CAMERA_UNLOCK :
GZ_INDEX_CAMERA_LOCK];
gz->matrix_basis[3][0] = roundf(co[0]);
gz->matrix_basis[3][1] = roundf(co[1] - (icon_offset_mini * icon_mini_slot++));
WM_gizmo_set_flag(gz, WM_GIZMO_HIDDEN, false);
}
}
}