Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_node/space_node.cc
| /* SPDX-License-Identifier: GPL-2.0-or-later | /* SPDX-License-Identifier: GPL-2.0-or-later | ||||
| * Copyright 2008 Blender Foundation. All rights reserved. */ | * Copyright 2008 Blender Foundation. All rights reserved. */ | ||||
| /** \file | /** \file | ||||
| * \ingroup spnode | * \ingroup spnode | ||||
| */ | */ | ||||
| #include "DNA_gpencil_types.h" | #include "DNA_gpencil_types.h" | ||||
| #include "DNA_light_types.h" | #include "DNA_light_types.h" | ||||
| #include "DNA_material_types.h" | #include "DNA_material_types.h" | ||||
| #include "DNA_node_types.h" | #include "DNA_node_types.h" | ||||
| #include "DNA_world_types.h" | #include "DNA_world_types.h" | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_gpencil.h" | |||||
| #include "BKE_lib_id.h" | #include "BKE_lib_id.h" | ||||
| #include "BKE_lib_remap.h" | #include "BKE_lib_remap.h" | ||||
| #include "BKE_node.h" | #include "BKE_node.h" | ||||
| #include "BKE_screen.h" | #include "BKE_screen.h" | ||||
| #include "ED_node.h" | #include "ED_node.h" | ||||
| #include "ED_render.h" | #include "ED_render.h" | ||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| #include "ED_space_api.h" | #include "ED_space_api.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| #include "UI_view2d.h" | #include "UI_view2d.h" | ||||
| #include "BLO_read_write.h" | |||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "RNA_define.h" | #include "RNA_define.h" | ||||
| #include "RNA_enum_types.h" | #include "RNA_enum_types.h" | ||||
| #include "RNA_prototypes.h" | #include "RNA_prototypes.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| ▲ Show 20 Lines • Show All 777 Lines • ▼ Show 20 Lines | switch (wmn->category) { | ||||
| case NC_GPENCIL: | case NC_GPENCIL: | ||||
| if (wmn->action == NA_EDITED) { | if (wmn->action == NA_EDITED) { | ||||
| ED_region_tag_redraw(region); | ED_region_tag_redraw(region); | ||||
| } | } | ||||
| else if (wmn->data & ND_GPENCIL_EDITMODE) { | else if (wmn->data & ND_GPENCIL_EDITMODE) { | ||||
| ED_region_tag_redraw(region); | ED_region_tag_redraw(region); | ||||
| } | } | ||||
| break; | break; | ||||
| case NC_VIEWER_PATH: | |||||
| ED_region_tag_redraw(region); | |||||
| break; | |||||
| } | } | ||||
| } | } | ||||
| } // namespace blender::ed::space_node | } // namespace blender::ed::space_node | ||||
| /* Outside of blender namespace to avoid Python documentation build error with `ctypes`. */ | /* Outside of blender namespace to avoid Python documentation build error with `ctypes`. */ | ||||
| extern "C" { | extern "C" { | ||||
| const char *node_context_dir[] = { | const char *node_context_dir[] = { | ||||
| ▲ Show 20 Lines • Show All 175 Lines • ▼ Show 20 Lines | static void node_space_subtype_item_extend(bContext *C, EnumPropertyItem **item, int *totitem) | ||||
| bool free; | bool free; | ||||
| const EnumPropertyItem *item_src = RNA_enum_node_tree_types_itemf_impl(C, &free); | const EnumPropertyItem *item_src = RNA_enum_node_tree_types_itemf_impl(C, &free); | ||||
| RNA_enum_items_add(item, totitem, item_src); | RNA_enum_items_add(item, totitem, item_src); | ||||
| if (free) { | if (free) { | ||||
| MEM_freeN((void *)item_src); | MEM_freeN((void *)item_src); | ||||
| } | } | ||||
| } | } | ||||
| static void node_blend_read_data(BlendDataReader *reader, SpaceLink *sl) | |||||
| { | |||||
| SpaceNode *snode = (SpaceNode *)sl; | |||||
| if (snode->gpd) { | |||||
| BLO_read_data_address(reader, &snode->gpd); | |||||
| BKE_gpencil_blend_read_data(reader, snode->gpd); | |||||
| } | |||||
| BLO_read_list(reader, &snode->treepath); | |||||
| snode->edittree = nullptr; | |||||
| snode->runtime = nullptr; | |||||
| } | |||||
| static void node_blend_read_lib(BlendLibReader *reader, ID *parent_id, SpaceLink *sl) | |||||
| { | |||||
| SpaceNode *snode = (SpaceNode *)sl; | |||||
| /* node tree can be stored locally in id too, link this first */ | |||||
| BLO_read_id_address(reader, parent_id->lib, &snode->id); | |||||
| BLO_read_id_address(reader, parent_id->lib, &snode->from); | |||||
| bNodeTree *ntree = snode->id ? ntreeFromID(snode->id) : nullptr; | |||||
| if (ntree) { | |||||
| snode->nodetree = ntree; | |||||
| } | |||||
| else { | |||||
| BLO_read_id_address(reader, parent_id->lib, &snode->nodetree); | |||||
| } | |||||
| bNodeTreePath *path; | |||||
| for (path = static_cast<bNodeTreePath *>(snode->treepath.first); path; path = path->next) { | |||||
| if (path == snode->treepath.first) { | |||||
| /* first nodetree in path is same as snode->nodetree */ | |||||
| path->nodetree = snode->nodetree; | |||||
| } | |||||
| else { | |||||
| BLO_read_id_address(reader, parent_id->lib, &path->nodetree); | |||||
| } | |||||
| if (!path->nodetree) { | |||||
| break; | |||||
| } | |||||
| } | |||||
| /* remaining path entries are invalid, remove */ | |||||
| bNodeTreePath *path_next; | |||||
| for (; path; path = path_next) { | |||||
| path_next = path->next; | |||||
| BLI_remlink(&snode->treepath, path); | |||||
| MEM_freeN(path); | |||||
| } | |||||
| /* edittree is just the last in the path, | |||||
| * set this directly since the path may have been shortened above */ | |||||
| if (snode->treepath.last) { | |||||
| path = static_cast<bNodeTreePath *>(snode->treepath.last); | |||||
| snode->edittree = path->nodetree; | |||||
| } | |||||
| else { | |||||
| snode->edittree = nullptr; | |||||
| } | |||||
| } | |||||
| static void node_blend_write(BlendWriter *writer, SpaceLink *sl) | |||||
| { | |||||
| SpaceNode *snode = (SpaceNode *)sl; | |||||
| BLO_write_struct(writer, SpaceNode, snode); | |||||
| LISTBASE_FOREACH (bNodeTreePath *, path, &snode->treepath) { | |||||
| BLO_write_struct(writer, bNodeTreePath, path); | |||||
| } | |||||
| } | |||||
| } // namespace blender::ed::space_node | } // namespace blender::ed::space_node | ||||
| void ED_spacetype_node() | void ED_spacetype_node() | ||||
| { | { | ||||
| using namespace blender::ed::space_node; | using namespace blender::ed::space_node; | ||||
| SpaceType *st = MEM_cnew<SpaceType>("spacetype node"); | SpaceType *st = MEM_cnew<SpaceType>("spacetype node"); | ||||
| ARegionType *art; | ARegionType *art; | ||||
| Show All 11 Lines | void ED_spacetype_node() | ||||
| st->refresh = node_area_refresh; | st->refresh = node_area_refresh; | ||||
| st->context = node_context; | st->context = node_context; | ||||
| st->dropboxes = node_dropboxes; | st->dropboxes = node_dropboxes; | ||||
| st->gizmos = node_widgets; | st->gizmos = node_widgets; | ||||
| st->id_remap = node_id_remap; | st->id_remap = node_id_remap; | ||||
| st->space_subtype_item_extend = node_space_subtype_item_extend; | st->space_subtype_item_extend = node_space_subtype_item_extend; | ||||
| st->space_subtype_get = node_space_subtype_get; | st->space_subtype_get = node_space_subtype_get; | ||||
| st->space_subtype_set = node_space_subtype_set; | st->space_subtype_set = node_space_subtype_set; | ||||
| st->blend_read_data = node_blend_read_data; | |||||
| st->blend_read_lib = node_blend_read_lib; | |||||
| st->blend_write = node_blend_write; | |||||
| /* regions: main window */ | /* regions: main window */ | ||||
| art = MEM_cnew<ARegionType>("spacetype node region"); | art = MEM_cnew<ARegionType>("spacetype node region"); | ||||
| art->regionid = RGN_TYPE_WINDOW; | art->regionid = RGN_TYPE_WINDOW; | ||||
| art->init = node_main_region_init; | art->init = node_main_region_init; | ||||
| art->draw = node_main_region_draw; | art->draw = node_main_region_draw; | ||||
| art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_GIZMO | ED_KEYMAP_TOOL | ED_KEYMAP_VIEW2D | | art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_GIZMO | ED_KEYMAP_TOOL | ED_KEYMAP_VIEW2D | | ||||
| ED_KEYMAP_FRAMES | ED_KEYMAP_GPENCIL; | ED_KEYMAP_FRAMES | ED_KEYMAP_GPENCIL; | ||||
| ▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines | |||||