diff options
Diffstat (limited to 'source/blender/editors/space_node/space_node.cc')
-rw-r--r-- | source/blender/editors/space_node/space_node.cc | 71 |
1 files changed, 19 insertions, 52 deletions
diff --git a/source/blender/editors/space_node/space_node.cc b/source/blender/editors/space_node/space_node.cc index 784cf7d4dd8..4cc0bed1928 100644 --- a/source/blender/editors/space_node/space_node.cc +++ b/source/blender/editors/space_node/space_node.cc @@ -29,9 +29,6 @@ #include "MEM_guardedalloc.h" -#include "BLI_blenlib.h" -#include "BLI_math.h" - #include "BKE_context.h" #include "BKE_lib_id.h" #include "BKE_node.h" @@ -54,6 +51,8 @@ #include "node_intern.hh" /* own include */ +using blender::float2; + /* ******************** tree path ********************* */ void ED_node_tree_start(SpaceNode *snode, bNodeTree *ntree, ID *id, ID *from) @@ -207,19 +206,14 @@ void ED_node_set_active_viewer_key(SpaceNode *snode) } } -void space_node_group_offset(SpaceNode *snode, float *x, float *y) +float2 space_node_group_offset(const SpaceNode &snode) { - bNodeTreePath *path = (bNodeTreePath *)snode->treepath.last; + const bNodeTreePath *path = (bNodeTreePath *)snode.treepath.last; if (path && path->prev) { - float dcenter[2]; - sub_v2_v2v2(dcenter, path->view_center, path->prev->view_center); - *x = dcenter[0]; - *y = dcenter[1]; - } - else { - *x = *y = 0.0f; + return float2(path->view_center) - float2(path->prev->view_center); } + return float2(0); } /* ******************** default callbacks for node space ***************** */ @@ -230,8 +224,8 @@ static SpaceLink *node_create(const ScrArea *UNUSED(area), const Scene *UNUSED(s snode->spacetype = SPACE_NODE; snode->flag = SNODE_SHOW_GPENCIL | SNODE_USE_ALPHA; - snode->overlay.flag |= SN_OVERLAY_SHOW_OVERLAYS; - snode->overlay.flag |= SN_OVERLAY_SHOW_WIRE_COLORS; + snode->overlay.flag = (SN_OVERLAY_SHOW_OVERLAYS | SN_OVERLAY_SHOW_WIRE_COLORS | + SN_OVERLAY_SHOW_PATH); /* backdrop */ snode->zoom = 1.0f; @@ -303,7 +297,10 @@ static void node_free(SpaceLink *sl) MEM_freeN(path); } - MEM_SAFE_FREE(snode->runtime); + if (snode->runtime) { + snode->runtime->linkdrag.reset(); + MEM_freeN(snode->runtime); + } } /* spacetype; init callback */ @@ -482,30 +479,10 @@ static void node_area_refresh(const struct bContext *C, ScrArea *area) /* default now: refresh node is starting preview */ SpaceNode *snode = (SpaceNode *)area->spacedata.first; - snode_set_context(C); + snode_set_context(*C); if (snode->nodetree) { - if (snode->nodetree->type == NTREE_SHADER) { - if (GS(snode->id->name) == ID_MA) { - Material *ma = (Material *)snode->id; - if (ma->use_nodes) { - ED_preview_shader_job(C, area, snode->id, nullptr, nullptr, 100, 100, PR_NODE_RENDER); - } - } - else if (GS(snode->id->name) == ID_LA) { - Light *la = (Light *)snode->id; - if (la->use_nodes) { - ED_preview_shader_job(C, area, snode->id, nullptr, nullptr, 100, 100, PR_NODE_RENDER); - } - } - else if (GS(snode->id->name) == ID_WO) { - World *wo = (World *)snode->id; - if (wo->use_nodes) { - ED_preview_shader_job(C, area, snode->id, nullptr, nullptr, 100, 100, PR_NODE_RENDER); - } - } - } - else if (snode->nodetree->type == NTREE_COMPOSIT) { + if (snode->nodetree->type == NTREE_COMPOSIT) { Scene *scene = (Scene *)snode->id; if (scene->use_nodes) { /* recalc is set on 3d view changes for auto compo */ @@ -518,12 +495,6 @@ static void node_area_refresh(const struct bContext *C, ScrArea *area) } } } - else if (snode->nodetree->type == NTREE_TEXTURE) { - Tex *tex = (Tex *)snode->id; - if (tex->use_nodes) { - ED_preview_shader_job(C, area, snode->id, nullptr, nullptr, 100, 100, PR_NODE_RENDER); - } - } } } @@ -534,10 +505,7 @@ static SpaceLink *node_duplicate(SpaceLink *sl) BLI_duplicatelist(&snoden->treepath, &snode->treepath); - if (snode->runtime != nullptr) { - snoden->runtime = (SpaceNode_Runtime *)MEM_dupallocN(snode->runtime); - BLI_listbase_clear(&snoden->runtime->linkdrag); - } + snoden->runtime = nullptr; /* NOTE: no need to set node tree user counts, * the editor only keeps at least 1 (id_us_ensure_real), @@ -601,7 +569,7 @@ static void node_cursor(wmWindow *win, ScrArea *area, ARegion *region) &snode->runtime->cursor[1]); /* here snode->runtime->cursor is used to detect the node edge for sizing */ - node_set_cursor(win, snode, snode->runtime->cursor); + node_set_cursor(*win, *snode, snode->runtime->cursor); /* XXX snode->runtime->cursor is in placing new nodes space */ snode->runtime->cursor[0] /= UI_DPI_FAC; @@ -635,7 +603,7 @@ static void node_main_region_init(wmWindowManager *wm, ARegion *region) static void node_main_region_draw(const bContext *C, ARegion *region) { - node_draw_space(C, region); + node_draw_space(*C, *region); } /* ************* dropboxes ************* */ @@ -758,7 +726,7 @@ static void node_header_region_init(wmWindowManager *UNUSED(wm), ARegion *region static void node_header_region_draw(const bContext *C, ARegion *region) { /* find and set the context */ - snode_set_context(C); + snode_set_context(*C); ED_region_header(C, region); } @@ -1001,8 +969,7 @@ static void node_space_subtype_item_extend(bContext *C, EnumPropertyItem **item, } } -/* only called once, from space/spacetypes.c */ -void ED_spacetype_node(void) +void ED_spacetype_node() { SpaceType *st = (SpaceType *)MEM_callocN(sizeof(SpaceType), "spacetype node"); ARegionType *art; |