Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_gizmo_navigate.c
| Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | enum { | ||||
| GZ_INDEX_ZOOM = 2, | GZ_INDEX_ZOOM = 2, | ||||
| /* just buttons */ | /* just buttons */ | ||||
| /* overlaps GZ_INDEX_ORTHO (switch between) */ | /* overlaps GZ_INDEX_ORTHO (switch between) */ | ||||
| GZ_INDEX_PERSP = 3, | GZ_INDEX_PERSP = 3, | ||||
| GZ_INDEX_ORTHO = 4, | GZ_INDEX_ORTHO = 4, | ||||
| GZ_INDEX_CAMERA = 5, | GZ_INDEX_CAMERA = 5, | ||||
| /* overlaps GZ_INDEX_ORTHO (switch between) */ | GZ_INDEX_TOTAL = 6, | ||||
| GZ_INDEX_CAMERA_LOCK = 6, | |||||
| GZ_INDEX_CAMERA_UNLOCK = 7, | |||||
| GZ_INDEX_TOTAL = 8, | |||||
| }; | }; | ||||
| struct NavigateGizmoInfo { | struct NavigateGizmoInfo { | ||||
| const char *opname; | const char *opname; | ||||
| const char *gizmo; | const char *gizmo; | ||||
| uint icon; | 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] = { | static struct NavigateGizmoInfo g_navigate_params[GZ_INDEX_TOTAL] = { | ||||
| { | { | ||||
| .opname = "VIEW3D_OT_move", | .opname = "VIEW3D_OT_move", | ||||
| .gizmo = "GIZMO_GT_button_2d", | .gizmo = "GIZMO_GT_button_2d", | ||||
| .icon = ICON_VIEW_PAN, | .icon = ICON_VIEW_PAN, | ||||
| .op_prop_fn = NULL, | |||||
| }, | }, | ||||
| { | { | ||||
| .opname = "VIEW3D_OT_rotate", | .opname = "VIEW3D_OT_rotate", | ||||
| .gizmo = "VIEW3D_GT_navigate_rotate", | .gizmo = "VIEW3D_GT_navigate_rotate", | ||||
| .icon = ICON_NONE, | .icon = ICON_NONE, | ||||
| .op_prop_fn = NULL, | |||||
| }, | }, | ||||
| { | { | ||||
| .opname = "VIEW3D_OT_zoom", | .opname = "VIEW3D_OT_zoom", | ||||
| .gizmo = "GIZMO_GT_button_2d", | .gizmo = "GIZMO_GT_button_2d", | ||||
| .icon = ICON_VIEW_ZOOM, | .icon = ICON_VIEW_ZOOM, | ||||
| .op_prop_fn = NULL, | |||||
| }, | }, | ||||
| { | { | ||||
| .opname = "VIEW3D_OT_view_persportho", | .opname = "VIEW3D_OT_view_persportho", | ||||
| .gizmo = "GIZMO_GT_button_2d", | .gizmo = "GIZMO_GT_button_2d", | ||||
| .icon = ICON_VIEW_PERSPECTIVE, | .icon = ICON_VIEW_PERSPECTIVE, | ||||
| .op_prop_fn = NULL, | |||||
| }, | }, | ||||
| { | { | ||||
| .opname = "VIEW3D_OT_view_persportho", | .opname = "VIEW3D_OT_view_persportho", | ||||
| .gizmo = "GIZMO_GT_button_2d", | .gizmo = "GIZMO_GT_button_2d", | ||||
| .icon = ICON_VIEW_ORTHO, | .icon = ICON_VIEW_ORTHO, | ||||
| .op_prop_fn = NULL, | |||||
| }, | }, | ||||
| { | { | ||||
| .opname = "VIEW3D_OT_view_camera", | .opname = "VIEW3D_OT_view_camera", | ||||
| .gizmo = "GIZMO_GT_button_2d", | .gizmo = "GIZMO_GT_button_2d", | ||||
| .icon = 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, | |||||
| }, | }, | ||||
| }; | }; | ||||
| struct NavigateWidgetGroup { | struct NavigateWidgetGroup { | ||||
| wmGizmo *gz_array[GZ_INDEX_TOTAL]; | wmGizmo *gz_array[GZ_INDEX_TOTAL]; | ||||
| /* Store the view state to check for changes. */ | /* Store the view state to check for changes. */ | ||||
| struct { | struct { | ||||
| rcti rect_visible; | rcti rect_visible; | ||||
| struct { | struct { | ||||
| int flag2; | |||||
| } v3d; | |||||
| struct { | |||||
| char is_persp; | char is_persp; | ||||
| bool is_camera; | bool is_camera; | ||||
| char viewlock; | char viewlock; | ||||
| } rv3d; | } rv3d; | ||||
| } state; | } state; | ||||
| int region_size[2]; | int region_size[2]; | ||||
| }; | }; | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | for (int i = 0; i < GZ_INDEX_TOTAL; i++) { | ||||
| if (info->icon != ICON_NONE) { | if (info->icon != ICON_NONE) { | ||||
| PropertyRNA *prop = RNA_struct_find_property(gz->ptr, "icon"); | PropertyRNA *prop = RNA_struct_find_property(gz->ptr, "icon"); | ||||
| RNA_property_enum_set(gz->ptr, prop, info->icon); | RNA_property_enum_set(gz->ptr, prop, info->icon); | ||||
| RNA_enum_set( | RNA_enum_set( | ||||
| gz->ptr, "draw_options", ED_GIZMO_BUTTON_SHOW_OUTLINE | ED_GIZMO_BUTTON_SHOW_BACKDROP); | gz->ptr, "draw_options", ED_GIZMO_BUTTON_SHOW_OUTLINE | ED_GIZMO_BUTTON_SHOW_BACKDROP); | ||||
| } | } | ||||
| wmOperatorType *ot = WM_operatortype_find(info->opname, true); | wmOperatorType *ot = WM_operatortype_find(info->opname, true); | ||||
| PointerRNA *ptr = WM_gizmo_operator_set(gz, 0, ot, NULL); | WM_gizmo_operator_set(gz, 0, ot, NULL); | ||||
| if (info->op_prop_fn != NULL) { | |||||
| info->op_prop_fn(ptr); | |||||
| } | |||||
| } | } | ||||
| { | { | ||||
| wmGizmo *gz = navgroup->gz_array[GZ_INDEX_CAMERA]; | wmGizmo *gz = navgroup->gz_array[GZ_INDEX_CAMERA]; | ||||
| WM_gizmo_operator_set(gz, 0, ot_view_camera, NULL); | WM_gizmo_operator_set(gz, 0, ot_view_camera, NULL); | ||||
| } | } | ||||
| /* Click only buttons (not modal). */ | /* Click only buttons (not modal). */ | ||||
| { | { | ||||
| int gz_ids[] = { | int gz_ids[] = {GZ_INDEX_PERSP, GZ_INDEX_ORTHO, GZ_INDEX_CAMERA}; | ||||
| 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++) { | for (int i = 0; i < ARRAY_SIZE(gz_ids); i++) { | ||||
| wmGizmo *gz = navgroup->gz_array[gz_ids[i]]; | wmGizmo *gz = navgroup->gz_array[gz_ids[i]]; | ||||
| RNA_boolean_set(gz->ptr, "show_drag", false); | RNA_boolean_set(gz->ptr, "show_drag", false); | ||||
| } | } | ||||
| } | } | ||||
| /* Modal operators, don't use initial mouse location since we're clicking on a button. */ | /* Modal operators, don't use initial mouse location since we're clicking on a button. */ | ||||
| { | { | ||||
| Show All 31 Lines | static void WIDGETGROUP_navigate_setup(const bContext *C, wmGizmoGroup *gzgroup) | ||||
| gzgroup->customdata = navgroup; | gzgroup->customdata = navgroup; | ||||
| } | } | ||||
| static void WIDGETGROUP_navigate_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup) | static void WIDGETGROUP_navigate_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup) | ||||
| { | { | ||||
| struct NavigateWidgetGroup *navgroup = gzgroup->customdata; | struct NavigateWidgetGroup *navgroup = gzgroup->customdata; | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| const RegionView3D *rv3d = region->regiondata; | 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++) { | for (int i = 0; i < 3; i++) { | ||||
| copy_v3_v3(navgroup->gz_array[GZ_INDEX_ROTATE]->matrix_offset[i], rv3d->viewmat[i]); | copy_v3_v3(navgroup->gz_array[GZ_INDEX_ROTATE]->matrix_offset[i], rv3d->viewmat[i]); | ||||
| } | } | ||||
| const rcti *rect_visible = ED_region_visible_rect(region); | const rcti *rect_visible = ED_region_visible_rect(region); | ||||
| /* Ensure types match so bits are never lost on assignment. */ | /* 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); | CHECK_TYPE_PAIR(navgroup->state.rv3d.viewlock, rv3d->viewlock); | ||||
| if ((navgroup->state.rect_visible.xmax == rect_visible->xmax) && | if ((navgroup->state.rect_visible.xmax == rect_visible->xmax) && | ||||
| (navgroup->state.rect_visible.ymax == rect_visible->ymax) && | (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.is_persp == rv3d->is_persp) && | ||||
| (navgroup->state.rv3d.is_camera == (rv3d->persp == RV3D_CAMOB)) && | (navgroup->state.rv3d.is_camera == (rv3d->persp == RV3D_CAMOB)) && | ||||
| (navgroup->state.rv3d.viewlock == RV3D_LOCK_FLAGS(rv3d))) { | (navgroup->state.rv3d.viewlock == RV3D_LOCK_FLAGS(rv3d))) { | ||||
| return; | return; | ||||
| } | } | ||||
| navgroup->state.rect_visible = *rect_visible; | 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_persp = rv3d->is_persp; | ||||
| navgroup->state.rv3d.is_camera = (rv3d->persp == RV3D_CAMOB); | navgroup->state.rv3d.is_camera = (rv3d->persp == RV3D_CAMOB); | ||||
| navgroup->state.rv3d.viewlock = RV3D_LOCK_FLAGS(rv3d); | navgroup->state.rv3d.viewlock = RV3D_LOCK_FLAGS(rv3d); | ||||
| const bool show_navigate = (U.uiflag & USER_SHOW_GIZMO_NAVIGATE) != 0; | 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); | const bool show_rotate_gizmo = (U.mini_axis_type == USER_MINI_AXIS_TYPE_GIZMO); | ||||
| const float icon_offset = ((GIZMO_SIZE / 2.0f) + GIZMO_OFFSET) * UI_DPI_FAC; | const float icon_offset = ((GIZMO_SIZE / 2.0f) + GIZMO_OFFSET) * UI_DPI_FAC; | ||||
| const float icon_offset_mini = (GIZMO_MINI_SIZE + GIZMO_MINI_OFFSET) * UI_DPI_FAC; | const float icon_offset_mini = (GIZMO_MINI_SIZE + GIZMO_MINI_OFFSET) * UI_DPI_FAC; | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0) { | ||||
| if (navgroup->state.rv3d.is_camera == false) { | if (navgroup->state.rv3d.is_camera == false) { | ||||
| gz = navgroup->gz_array[rv3d->is_persp ? GZ_INDEX_PERSP : GZ_INDEX_ORTHO]; | gz = navgroup->gz_array[rv3d->is_persp ? GZ_INDEX_PERSP : GZ_INDEX_ORTHO]; | ||||
| gz->matrix_basis[3][0] = roundf(co[0]); | gz->matrix_basis[3][0] = roundf(co[0]); | ||||
| gz->matrix_basis[3][1] = roundf(co[1] - (icon_offset_mini * icon_mini_slot++)); | gz->matrix_basis[3][1] = roundf(co[1] - (icon_offset_mini * icon_mini_slot++)); | ||||
| WM_gizmo_set_flag(gz, WM_GIZMO_HIDDEN, false); | 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); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| void VIEW3D_GGT_navigate(wmGizmoGroupType *gzgt) | void VIEW3D_GGT_navigate(wmGizmoGroupType *gzgt) | ||||
| { | { | ||||
| gzgt->name = "View3D Navigate"; | gzgt->name = "View3D Navigate"; | ||||
| gzgt->idname = "VIEW3D_GGT_navigate"; | gzgt->idname = "VIEW3D_GGT_navigate"; | ||||
| Show All 9 Lines | |||||