Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_node/space_node.c
| Show First 20 Lines • Show All 315 Lines • ▼ Show 20 Lines | |||||
| static void node_free(SpaceLink *sl) | static void node_free(SpaceLink *sl) | ||||
| { | { | ||||
| SpaceNode *snode = (SpaceNode *)sl; | SpaceNode *snode = (SpaceNode *)sl; | ||||
| LISTBASE_FOREACH_MUTABLE (bNodeTreePath *, path, &snode->treepath) { | LISTBASE_FOREACH_MUTABLE (bNodeTreePath *, path, &snode->treepath) { | ||||
| MEM_freeN(path); | MEM_freeN(path); | ||||
| } | } | ||||
| MEM_SAFE_FREE(snode->runtime); | |||||
| } | } | ||||
| /* spacetype; init callback */ | /* spacetype; init callback */ | ||||
| static void node_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(area)) | static void node_init(struct wmWindowManager *UNUSED(wm), ScrArea *area) | ||||
| { | { | ||||
| SpaceNode *snode = (SpaceNode *)area->spacedata.first; | |||||
| if (snode->runtime == NULL) { | |||||
| snode->runtime = MEM_callocN(sizeof(SpaceNode_Runtime), __func__); | |||||
| } | |||||
| } | } | ||||
| static void node_area_listener(wmWindow *UNUSED(win), | static void node_area_listener(const wmSpaceTypeListenerParams *params) | ||||
| ScrArea *area, | |||||
| wmNotifier *wmn, | |||||
| Scene *UNUSED(scene)) | |||||
| { | { | ||||
| ScrArea *area = params->area; | |||||
| wmNotifier *wmn = params->notifier; | |||||
| /* note, ED_area_tag_refresh will re-execute compositor */ | /* note, ED_area_tag_refresh will re-execute compositor */ | ||||
| SpaceNode *snode = area->spacedata.first; | SpaceNode *snode = area->spacedata.first; | ||||
| /* shaderfrom is only used for new shading nodes, otherwise all shaders are from objects */ | /* shaderfrom is only used for new shading nodes, otherwise all shaders are from objects */ | ||||
| short shader_type = snode->shaderfrom; | short shader_type = snode->shaderfrom; | ||||
| /* preview renders */ | /* preview renders */ | ||||
| switch (wmn->category) { | switch (wmn->category) { | ||||
| case NC_SCENE: | case NC_SCENE: | ||||
| Show All 13 Lines | case NC_SCENE: | ||||
| ED_area_tag_refresh(area); | ED_area_tag_refresh(area); | ||||
| break; | break; | ||||
| case ND_COMPO_RESULT: | case ND_COMPO_RESULT: | ||||
| ED_area_tag_redraw(area); | ED_area_tag_redraw(area); | ||||
| break; | break; | ||||
| case ND_TRANSFORM_DONE: | case ND_TRANSFORM_DONE: | ||||
| if (ED_node_is_compositor(snode)) { | if (ED_node_is_compositor(snode)) { | ||||
| if (snode->flag & SNODE_AUTO_RENDER) { | if (snode->flag & SNODE_AUTO_RENDER) { | ||||
| snode->recalc = 1; | snode->runtime->recalc = true; | ||||
| ED_area_tag_refresh(area); | ED_area_tag_refresh(area); | ||||
| } | } | ||||
| } | } | ||||
| break; | break; | ||||
| case ND_LAYER_CONTENT: | case ND_LAYER_CONTENT: | ||||
| ED_area_tag_refresh(area); | ED_area_tag_refresh(area); | ||||
| break; | break; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | if (snode->nodetree->type == NTREE_SHADER) { | ||||
| ED_preview_shader_job(C, area, snode->id, NULL, NULL, 100, 100, PR_NODE_RENDER); | ED_preview_shader_job(C, area, snode->id, NULL, NULL, 100, 100, PR_NODE_RENDER); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else if (snode->nodetree->type == NTREE_COMPOSIT) { | else if (snode->nodetree->type == NTREE_COMPOSIT) { | ||||
| Scene *scene = (Scene *)snode->id; | Scene *scene = (Scene *)snode->id; | ||||
| if (scene->use_nodes) { | if (scene->use_nodes) { | ||||
| /* recalc is set on 3d view changes for auto compo */ | /* recalc is set on 3d view changes for auto compo */ | ||||
| if (snode->recalc) { | if (snode->runtime->recalc) { | ||||
| snode->recalc = 0; | snode->runtime->recalc = false; | ||||
| node_render_changed_exec((struct bContext *)C, NULL); | node_render_changed_exec((struct bContext *)C, NULL); | ||||
| } | } | ||||
| else { | else { | ||||
| ED_node_composite_job(C, snode->nodetree, scene); | ED_node_composite_job(C, snode->nodetree, scene); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else if (snode->nodetree->type == NTREE_TEXTURE) { | else if (snode->nodetree->type == NTREE_TEXTURE) { | ||||
| Tex *tex = (Tex *)snode->id; | Tex *tex = (Tex *)snode->id; | ||||
| if (tex->use_nodes) { | if (tex->use_nodes) { | ||||
| ED_preview_shader_job(C, area, snode->id, NULL, NULL, 100, 100, PR_NODE_RENDER); | ED_preview_shader_job(C, area, snode->id, NULL, NULL, 100, 100, PR_NODE_RENDER); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static SpaceLink *node_duplicate(SpaceLink *sl) | static SpaceLink *node_duplicate(SpaceLink *sl) | ||||
| { | { | ||||
| SpaceNode *snode = (SpaceNode *)sl; | SpaceNode *snode = (SpaceNode *)sl; | ||||
| SpaceNode *snoden = MEM_dupallocN(snode); | SpaceNode *snoden = MEM_dupallocN(snode); | ||||
| BLI_duplicatelist(&snoden->treepath, &snode->treepath); | BLI_duplicatelist(&snoden->treepath, &snode->treepath); | ||||
| /* clear or remove stuff from old */ | if (snode->runtime != NULL) { | ||||
| BLI_listbase_clear(&snoden->linkdrag); | snoden->runtime = MEM_dupallocN(snode->runtime); | ||||
| BLI_listbase_clear(&snoden->runtime->linkdrag); | |||||
| } | |||||
| /* Note: no need to set node tree user counts, | /* Note: no need to set node tree user counts, | ||||
| * the editor only keeps at least 1 (id_us_ensure_real), | * the editor only keeps at least 1 (id_us_ensure_real), | ||||
| * which is already done by the original SpaceNode. | * which is already done by the original SpaceNode. | ||||
| */ | */ | ||||
| return (SpaceLink *)snoden; | return (SpaceLink *)snoden; | ||||
| } | } | ||||
| Show All 25 Lines | static void node_toolbar_region_init(wmWindowManager *wm, ARegion *region) | ||||
| WM_event_add_keymap_handler(®ion->handlers, keymap); | WM_event_add_keymap_handler(®ion->handlers, keymap); | ||||
| } | } | ||||
| static void node_toolbar_region_draw(const bContext *C, ARegion *region) | static void node_toolbar_region_draw(const bContext *C, ARegion *region) | ||||
| { | { | ||||
| ED_region_panels(C, region); | ED_region_panels(C, region); | ||||
| } | } | ||||
| void ED_node_cursor_location_get(const SpaceNode *snode, float value[2]) | |||||
| { | |||||
| copy_v2_v2(value, snode->runtime->cursor); | |||||
| } | |||||
| void ED_node_cursor_location_set(SpaceNode *snode, const float value[2]) | |||||
| { | |||||
| copy_v2_v2(snode->runtime->cursor, value); | |||||
| } | |||||
| static void node_cursor(wmWindow *win, ScrArea *area, ARegion *region) | static void node_cursor(wmWindow *win, ScrArea *area, ARegion *region) | ||||
| { | { | ||||
| SpaceNode *snode = area->spacedata.first; | SpaceNode *snode = area->spacedata.first; | ||||
| /* convert mouse coordinates to v2d space */ | /* convert mouse coordinates to v2d space */ | ||||
| UI_view2d_region_to_view(®ion->v2d, | UI_view2d_region_to_view(®ion->v2d, | ||||
| win->eventstate->x - region->winrct.xmin, | win->eventstate->x - region->winrct.xmin, | ||||
| win->eventstate->y - region->winrct.ymin, | win->eventstate->y - region->winrct.ymin, | ||||
| &snode->cursor[0], | &snode->runtime->cursor[0], | ||||
| &snode->cursor[1]); | &snode->runtime->cursor[1]); | ||||
| /* here snode->cursor is used to detect the node edge for sizing */ | /* here snode->runtime->cursor is used to detect the node edge for sizing */ | ||||
| node_set_cursor(win, snode, snode->cursor); | node_set_cursor(win, snode, snode->runtime->cursor); | ||||
| /* XXX snode->cursor is in placing new nodes space */ | /* XXX snode->runtime->cursor is in placing new nodes space */ | ||||
| snode->cursor[0] /= UI_DPI_FAC; | snode->runtime->cursor[0] /= UI_DPI_FAC; | ||||
| snode->cursor[1] /= UI_DPI_FAC; | snode->runtime->cursor[1] /= UI_DPI_FAC; | ||||
| } | } | ||||
| /* Initialize main region, setting handlers. */ | /* Initialize main region, setting handlers. */ | ||||
| static void node_main_region_init(wmWindowManager *wm, ARegion *region) | static void node_main_region_init(wmWindowManager *wm, ARegion *region) | ||||
| { | { | ||||
| wmKeyMap *keymap; | wmKeyMap *keymap; | ||||
| ListBase *lb; | ListBase *lb; | ||||
| Show All 23 Lines | static bool node_ima_drop_poll(bContext *UNUSED(C), | ||||
| wmDrag *drag, | wmDrag *drag, | ||||
| const wmEvent *UNUSED(event), | const wmEvent *UNUSED(event), | ||||
| const char **UNUSED(r_tooltip)) | const char **UNUSED(r_tooltip)) | ||||
| { | { | ||||
| 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) != NULL; | return WM_drag_is_ID_type(drag, ID_IM); | ||||
| } | } | ||||
| static bool node_mask_drop_poll(bContext *UNUSED(C), | static bool node_mask_drop_poll(bContext *UNUSED(C), | ||||
| wmDrag *drag, | wmDrag *drag, | ||||
| const wmEvent *UNUSED(event), | const wmEvent *UNUSED(event), | ||||
| const char **UNUSED(r_tooltip)) | const char **UNUSED(r_tooltip)) | ||||
| { | { | ||||
| return WM_drag_get_local_ID(drag, ID_MSK) != NULL; | return WM_drag_is_ID_type(drag, ID_MSK); | ||||
| } | } | ||||
| static void node_id_drop_copy(wmDrag *drag, wmDropBox *drop) | static void node_id_drop_copy(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); | ||||
| } | } | ||||
| static void node_id_path_drop_copy(wmDrag *drag, wmDropBox *drop) | static void node_id_path_drop_copy(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); | ||||
| if (id) { | if (id) { | ||||
| RNA_string_set(drop->ptr, "name", id->name + 2); | RNA_string_set(drop->ptr, "name", id->name + 2); | ||||
| RNA_struct_property_unset(drop->ptr, "filepath"); | RNA_struct_property_unset(drop->ptr, "filepath"); | ||||
| } | } | ||||
| else if (drag->path[0]) { | else if (drag->path[0]) { | ||||
| RNA_string_set(drop->ptr, "filepath", drag->path); | RNA_string_set(drop->ptr, "filepath", drag->path); | ||||
| RNA_struct_property_unset(drop->ptr, "name"); | RNA_struct_property_unset(drop->ptr, "name"); | ||||
| Show All 21 Lines | |||||
| { | { | ||||
| /* find and set the context */ | /* find and set the context */ | ||||
| snode_set_context(C); | snode_set_context(C); | ||||
| ED_region_header(C, region); | ED_region_header(C, region); | ||||
| } | } | ||||
| /* used for header + main region */ | /* used for header + main region */ | ||||
| static void node_region_listener(wmWindow *UNUSED(win), | static void node_region_listener(const wmRegionListenerParams *params) | ||||
| ScrArea *UNUSED(area), | |||||
| ARegion *region, | |||||
| wmNotifier *wmn, | |||||
| const Scene *UNUSED(scene)) | |||||
| { | { | ||||
| ARegion *region = params->region; | |||||
| wmNotifier *wmn = params->notifier; | |||||
| wmGizmoMap *gzmap = region->gizmo_map; | wmGizmoMap *gzmap = region->gizmo_map; | ||||
| /* context changes */ | /* context changes */ | ||||
| switch (wmn->category) { | switch (wmn->category) { | ||||
| case NC_SPACE: | case NC_SPACE: | ||||
| switch (wmn->data) { | switch (wmn->data) { | ||||
| case ND_SPACE_NODE: | case ND_SPACE_NODE: | ||||
| ED_region_tag_redraw(region); | ED_region_tag_redraw(region); | ||||
| ▲ Show 20 Lines • Show All 307 Lines • Show Last 20 Lines | |||||