Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/space_view3d.c
| Show First 20 Lines • Show All 463 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static bool view3d_drop_in_main_region_poll(bContext *C, const wmEvent *event) | static bool view3d_drop_in_main_region_poll(bContext *C, const wmEvent *event) | ||||
| { | { | ||||
| ScrArea *area = CTX_wm_area(C); | ScrArea *area = CTX_wm_area(C); | ||||
| return ED_region_overlap_isect_any_xy(area, &event->x) == false; | return ED_region_overlap_isect_any_xy(area, &event->x) == false; | ||||
| } | } | ||||
| static ID *view3d_drop_id_in_main_region_poll_id(bContext *C, | static ID_Type view3d_drop_id_in_main_region_poll_get_id_type(bContext *C, | ||||
| wmDrag *drag, | wmDrag *drag, | ||||
| const wmEvent *event, | const wmEvent *event) | ||||
| ID_Type id_type) | |||||
| { | { | ||||
| ScrArea *area = CTX_wm_area(C); | const ScrArea *area = CTX_wm_area(C); | ||||
| if (ED_region_overlap_isect_any_xy(area, &event->x)) { | if (ED_region_overlap_isect_any_xy(area, &event->x)) { | ||||
| return NULL; | return 0; | ||||
| } | |||||
| if (!view3d_drop_in_main_region_poll(C, event)) { | |||||
| return 0; | |||||
| } | |||||
| ID *local_id = WM_drag_get_local_ID(drag, 0); | |||||
| if (local_id) { | |||||
| return GS(local_id->name); | |||||
| } | |||||
| wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, 0); | |||||
| if (asset_drag) { | |||||
| return asset_drag->id_type; | |||||
| } | } | ||||
| return view3d_drop_in_main_region_poll(C, event) ? WM_drag_get_local_ID(drag, id_type) : NULL; | |||||
| return 0; | |||||
| } | } | ||||
| static bool view3d_drop_id_in_main_region_poll(bContext *C, | static bool view3d_drop_id_in_main_region_poll(bContext *C, | ||||
| wmDrag *drag, | wmDrag *drag, | ||||
| const wmEvent *event, | const wmEvent *event, | ||||
| ID_Type id_type) | ID_Type id_type) | ||||
| { | { | ||||
| if (!view3d_drop_in_main_region_poll(C, event)) { | if (!view3d_drop_in_main_region_poll(C, event)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| return WM_drag_get_local_ID(drag, id_type) || WM_drag_get_asset_data(drag, id_type); | return WM_drag_is_ID_type(drag, id_type); | ||||
| } | } | ||||
| static bool view3d_ob_drop_poll(bContext *C, | static bool view3d_ob_drop_poll(bContext *C, | ||||
| wmDrag *drag, | wmDrag *drag, | ||||
| const wmEvent *event, | const wmEvent *event, | ||||
| const char **UNUSED(r_tooltip)) | const char **UNUSED(r_tooltip)) | ||||
| { | { | ||||
| return view3d_drop_id_in_main_region_poll(C, drag, event, ID_OB); | return view3d_drop_id_in_main_region_poll(C, drag, event, ID_OB); | ||||
| Show All 15 Lines | static bool view3d_mat_drop_poll(bContext *C, | ||||
| return view3d_drop_id_in_main_region_poll(C, drag, event, ID_MA); | return view3d_drop_id_in_main_region_poll(C, drag, event, ID_MA); | ||||
| } | } | ||||
| static bool view3d_object_data_drop_poll(bContext *C, | static bool view3d_object_data_drop_poll(bContext *C, | ||||
| wmDrag *drag, | wmDrag *drag, | ||||
| const wmEvent *event, | const wmEvent *event, | ||||
| const char **r_tooltip) | const char **r_tooltip) | ||||
| { | { | ||||
| ID *id = view3d_drop_id_in_main_region_poll_id(C, drag, event, 0); | ID_Type id_type = view3d_drop_id_in_main_region_poll_get_id_type(C, drag, event); | ||||
| if (id != NULL) { | if (id_type) { | ||||
| if (BKE_object_obdata_to_type(id) != -1) { | if (OB_DATA_SUPPORT_ID(id_type)) { | ||||
| *r_tooltip = TIP_("Create object instance from object-data"); | *r_tooltip = TIP_("Create object instance from object-data"); | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| static bool view3d_ima_drop_poll(bContext *C, | static bool view3d_ima_drop_poll(bContext *C, | ||||
| wmDrag *drag, | wmDrag *drag, | ||||
| const wmEvent *event, | const wmEvent *event, | ||||
| const char **UNUSED(r_tooltip)) | const char **UNUSED(r_tooltip)) | ||||
| { | { | ||||
| if (ED_region_overlap_isect_any_xy(CTX_wm_area(C), &event->x)) { | if (ED_region_overlap_isect_any_xy(CTX_wm_area(C), &event->x)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (drag->type == WM_DRAG_PATH) { | if (drag->type == WM_DRAG_PATH) { | ||||
| /* rule might not work? */ | /* rule might not work? */ | ||||
| return (ELEM(drag->icon, 0, ICON_FILE_IMAGE, ICON_FILE_MOVIE)); | return (ELEM(drag->icon, 0, ICON_FILE_IMAGE, ICON_FILE_MOVIE)); | ||||
| } | } | ||||
| return WM_drag_get_local_ID(drag, ID_IM) || WM_drag_get_asset_data(drag, ID_IM); | return WM_drag_is_ID_type(drag, ID_IM); | ||||
| } | } | ||||
| static bool view3d_ima_bg_is_camera_view(bContext *C) | static bool view3d_ima_bg_is_camera_view(bContext *C) | ||||
| { | { | ||||
| RegionView3D *rv3d = CTX_wm_region_view3d(C); | RegionView3D *rv3d = CTX_wm_region_view3d(C); | ||||
| if ((rv3d && (rv3d->persp == RV3D_CAMOB))) { | if ((rv3d && (rv3d->persp == RV3D_CAMOB))) { | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| if (v3d && v3d->camera && v3d->camera->type == OB_CAMERA) { | if (v3d && v3d->camera && v3d->camera->type == OB_CAMERA) { | ||||
| ▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, 0); | ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, 0); | ||||
| RNA_string_set(drop->ptr, "name", id->name + 2); | RNA_string_set(drop->ptr, "name", id->name + 2); | ||||
| } | } | ||||
| static void view3d_id_drop_copy_with_type(wmDrag *drag, wmDropBox *drop) | static void view3d_id_drop_copy_with_type(wmDrag *drag, wmDropBox *drop) | ||||
| { | { | ||||
| ID *id = WM_drag_get_local_ID(drag, 0); | ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, 0); | ||||
| RNA_string_set(drop->ptr, "name", id->name + 2); | RNA_string_set(drop->ptr, "name", id->name + 2); | ||||
| RNA_enum_set(drop->ptr, "type", GS(id->name)); | RNA_enum_set(drop->ptr, "type", GS(id->name)); | ||||
| } | } | ||||
| static void view3d_id_path_drop_copy(wmDrag *drag, wmDropBox *drop) | static void view3d_id_path_drop_copy(wmDrag *drag, wmDropBox *drop) | ||||
| { | { | ||||
| ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, 0); | ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, 0); | ||||
| ▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | if (poin) { | ||||
| new->sms = NULL; | new->sms = NULL; | ||||
| new->smooth_timer = NULL; | new->smooth_timer = NULL; | ||||
| return new; | return new; | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| static void view3d_main_region_listener( | static void view3d_main_region_listener(const wmRegionListenerParams *params) | ||||
| wmWindow *win, ScrArea *area, ARegion *region, wmNotifier *wmn, const Scene *scene) | |||||
| { | { | ||||
| wmWindow *window = params->window; | |||||
| ScrArea *area = params->area; | |||||
| ARegion *region = params->region; | |||||
| wmNotifier *wmn = params->notifier; | |||||
| const Scene *scene = params->scene; | |||||
| View3D *v3d = area->spacedata.first; | View3D *v3d = area->spacedata.first; | ||||
| RegionView3D *rv3d = region->regiondata; | RegionView3D *rv3d = region->regiondata; | ||||
| wmGizmoMap *gzmap = region->gizmo_map; | wmGizmoMap *gzmap = region->gizmo_map; | ||||
| /* context changes */ | /* context changes */ | ||||
| switch (wmn->category) { | switch (wmn->category) { | ||||
| case NC_WM: | case NC_WM: | ||||
| if (ELEM(wmn->data, ND_UNDO)) { | if (ELEM(wmn->data, ND_UNDO)) { | ||||
| ▲ Show 20 Lines • Show All 204 Lines • ▼ Show 20 Lines | case NC_SPACE: | ||||
| if (wmn->subtype == NS_VIEW3D_GPU) { | if (wmn->subtype == NS_VIEW3D_GPU) { | ||||
| rv3d->rflag |= RV3D_GPULIGHT_UPDATE; | rv3d->rflag |= RV3D_GPULIGHT_UPDATE; | ||||
| } | } | ||||
| else if (wmn->subtype == NS_VIEW3D_SHADING) { | else if (wmn->subtype == NS_VIEW3D_SHADING) { | ||||
| #ifdef WITH_XR_OPENXR | #ifdef WITH_XR_OPENXR | ||||
| ED_view3d_xr_shading_update(G_MAIN->wm.first, v3d, scene); | ED_view3d_xr_shading_update(G_MAIN->wm.first, v3d, scene); | ||||
| #endif | #endif | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(window); | ||||
| Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer); | Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer); | ||||
| if (depsgraph) { | if (depsgraph) { | ||||
| ED_render_view3d_update(depsgraph, win, area, true); | ED_render_view3d_update(depsgraph, window, area, true); | ||||
| } | } | ||||
| } | } | ||||
| ED_region_tag_redraw(region); | ED_region_tag_redraw(region); | ||||
| WM_gizmomap_tag_refresh(gzmap); | WM_gizmomap_tag_refresh(gzmap); | ||||
| } | } | ||||
| break; | break; | ||||
| case NC_ID: | case NC_ID: | ||||
| if (wmn->action == NA_RENAME) { | if (wmn->action == NA_RENAME) { | ||||
| Show All 21 Lines | #endif | ||||
| case NC_GPENCIL: | case NC_GPENCIL: | ||||
| if (wmn->data == ND_DATA || ELEM(wmn->action, NA_EDITED, NA_SELECTED)) { | if (wmn->data == ND_DATA || ELEM(wmn->action, NA_EDITED, NA_SELECTED)) { | ||||
| ED_region_tag_redraw(region); | ED_region_tag_redraw(region); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| static void view3d_main_region_message_subscribe(const struct bContext *C, | static void view3d_main_region_message_subscribe(const wmRegionMessageSubscribeParams *params) | ||||
| struct WorkSpace *UNUSED(workspace), | |||||
| struct Scene *UNUSED(scene), | |||||
| struct bScreen *UNUSED(screen), | |||||
| struct ScrArea *area, | |||||
| struct ARegion *region, | |||||
| struct wmMsgBus *mbus) | |||||
| { | { | ||||
| struct wmMsgBus *mbus = params->message_bus; | |||||
| const bContext *C = params->context; | |||||
| ScrArea *area = params->area; | |||||
| ARegion *region = params->region; | |||||
| /* Developer note: there are many properties that impact 3D view drawing, | /* Developer note: there are many properties that impact 3D view drawing, | ||||
| * so instead of subscribing to individual properties, just subscribe to types | * so instead of subscribing to individual properties, just subscribe to types | ||||
| * accepting some redundant redraws. | * accepting some redundant redraws. | ||||
| * | * | ||||
| * For other space types we might try avoid this, keep the 3D view as an exceptional case! */ | * For other space types we might try avoid this, keep the 3D view as an exceptional case! */ | ||||
| wmMsgParams_RNA msg_key_params = {{0}}; | wmMsgParams_RNA msg_key_params = {{0}}; | ||||
| /* Only subscribe to types. */ | /* Only subscribe to types. */ | ||||
| ▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | static void view3d_header_region_init(wmWindowManager *wm, ARegion *region) | ||||
| ED_region_header_init(region); | ED_region_header_init(region); | ||||
| } | } | ||||
| static void view3d_header_region_draw(const bContext *C, ARegion *region) | static void view3d_header_region_draw(const bContext *C, ARegion *region) | ||||
| { | { | ||||
| ED_region_header(C, region); | ED_region_header(C, region); | ||||
| } | } | ||||
| static void view3d_header_region_listener(wmWindow *UNUSED(win), | static void view3d_header_region_listener(const wmRegionListenerParams *params) | ||||
| ScrArea *UNUSED(area), | |||||
| ARegion *region, | |||||
| wmNotifier *wmn, | |||||
| const Scene *UNUSED(scene)) | |||||
| { | { | ||||
| ARegion *region = params->region; | |||||
| wmNotifier *wmn = params->notifier; | |||||
| /* context changes */ | /* context changes */ | ||||
| switch (wmn->category) { | switch (wmn->category) { | ||||
| case NC_SCENE: | case NC_SCENE: | ||||
| switch (wmn->data) { | switch (wmn->data) { | ||||
| case ND_FRAME: | case ND_FRAME: | ||||
| case ND_OB_ACTIVE: | case ND_OB_ACTIVE: | ||||
| case ND_OB_SELECT: | case ND_OB_SELECT: | ||||
| case ND_OB_VISIBLE: | case ND_OB_VISIBLE: | ||||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | case NC_GPENCIL: | ||||
| if (wmn->data == ND_DATA) { | if (wmn->data == ND_DATA) { | ||||
| ED_region_tag_redraw(region); | ED_region_tag_redraw(region); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| #endif | #endif | ||||
| } | } | ||||
| static void view3d_header_region_message_subscribe(const struct bContext *UNUSED(C), | static void view3d_header_region_message_subscribe(const wmRegionMessageSubscribeParams *params) | ||||
| struct WorkSpace *UNUSED(workspace), | |||||
| struct Scene *UNUSED(scene), | |||||
| struct bScreen *UNUSED(screen), | |||||
| struct ScrArea *UNUSED(area), | |||||
| struct ARegion *region, | |||||
| struct wmMsgBus *mbus) | |||||
| { | { | ||||
| struct wmMsgBus *mbus = params->message_bus; | |||||
| ARegion *region = params->region; | |||||
| wmMsgParams_RNA msg_key_params = {{0}}; | wmMsgParams_RNA msg_key_params = {{0}}; | ||||
| /* Only subscribe to types. */ | /* Only subscribe to types. */ | ||||
| StructRNA *type_array[] = { | StructRNA *type_array[] = { | ||||
| &RNA_View3DShading, | &RNA_View3DShading, | ||||
| }; | }; | ||||
| wmMsgSubscribeValue msg_sub_value_region_tag_redraw = { | wmMsgSubscribeValue msg_sub_value_region_tag_redraw = { | ||||
| ▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | void ED_view3d_buttons_region_layout_ex(const bContext *C, | ||||
| ED_region_panels_layout_ex(C, region, paneltypes, contexts_base, category_override); | ED_region_panels_layout_ex(C, region, paneltypes, contexts_base, category_override); | ||||
| } | } | ||||
| static void view3d_buttons_region_layout(const bContext *C, ARegion *region) | static void view3d_buttons_region_layout(const bContext *C, ARegion *region) | ||||
| { | { | ||||
| ED_view3d_buttons_region_layout_ex(C, region, NULL); | ED_view3d_buttons_region_layout_ex(C, region, NULL); | ||||
| } | } | ||||
| static void view3d_buttons_region_listener(wmWindow *UNUSED(win), | static void view3d_buttons_region_listener(const wmRegionListenerParams *params) | ||||
| ScrArea *UNUSED(area), | |||||
| ARegion *region, | |||||
| wmNotifier *wmn, | |||||
| const Scene *UNUSED(scene)) | |||||
| { | { | ||||
| ARegion *region = params->region; | |||||
| wmNotifier *wmn = params->notifier; | |||||
| /* context changes */ | /* context changes */ | ||||
| switch (wmn->category) { | switch (wmn->category) { | ||||
| case NC_ANIMATION: | case NC_ANIMATION: | ||||
| switch (wmn->data) { | switch (wmn->data) { | ||||
| case ND_KEYFRAME_PROP: | case ND_KEYFRAME_PROP: | ||||
| case ND_NLA_ACTCHANGE: | case ND_NLA_ACTCHANGE: | ||||
| ED_region_tag_redraw(region); | ED_region_tag_redraw(region); | ||||
| break; | break; | ||||
| ▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static void view3d_tools_region_draw(const bContext *C, ARegion *region) | static void view3d_tools_region_draw(const bContext *C, ARegion *region) | ||||
| { | { | ||||
| ED_region_panels_ex(C, region, (const char *[]){CTX_data_mode_string(C), NULL}); | ED_region_panels_ex(C, region, (const char *[]){CTX_data_mode_string(C), NULL}); | ||||
| } | } | ||||
| /* area (not region) level listener */ | /* area (not region) level listener */ | ||||
| static void space_view3d_listener(wmWindow *UNUSED(win), | static void space_view3d_listener(const wmSpaceTypeListenerParams *params) | ||||
| ScrArea *area, | |||||
| struct wmNotifier *wmn, | |||||
| Scene *UNUSED(scene)) | |||||
| { | { | ||||
| ScrArea *area = params->area; | |||||
| wmNotifier *wmn = params->notifier; | |||||
| View3D *v3d = area->spacedata.first; | View3D *v3d = area->spacedata.first; | ||||
| /* context changes */ | /* context changes */ | ||||
| switch (wmn->category) { | switch (wmn->category) { | ||||
| case NC_SCENE: | case NC_SCENE: | ||||
| switch (wmn->data) { | switch (wmn->data) { | ||||
| case ND_WORLD: | case ND_WORLD: | ||||
| if (v3d->flag2 & V3D_HIDE_OVERLAYS) { | if (v3d->flag2 & V3D_HIDE_OVERLAYS) { | ||||
| ▲ Show 20 Lines • Show All 224 Lines • Show Last 20 Lines | |||||