static void template_texture_select(bContext *C, void *user_p, void *UNUSED(arg)) { /* callback when selecting a texture user in the menu */ SpaceButs *sbuts = CTX_wm_space_buts(C); ButsContextTexture *ct= (sbuts)? sbuts->texuser: NULL; ButsTextureUser *user = (ButsTextureUser*)user_p; PointerRNA texptr; Tex *tex; if(!ct) return; /* set user as active */ if(user->node) { ED_node_set_active(CTX_data_main(C), user->ntree, user->node); ct->texture = NULL; } else { texptr = RNA_property_pointer_get(&user->ptr, user->prop); tex = (RNA_struct_is_a(texptr.type, &RNA_Texture))? texptr.data: NULL; ct->texture = tex; } ct->user = user; ct->index = user->index; }
static void template_texture_select(bContext *C, void *user_p, void *UNUSED(arg)) { /* callback when selecting a texture user in the menu */ SpaceProperties *sbuts = CTX_wm_space_properties(C); ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL; ButsTextureUser *user = (ButsTextureUser *)user_p; PointerRNA texptr; Tex *tex; if (!ct) { return; } /* set user as active */ if (user->node) { ED_node_set_active(CTX_data_main(C), user->ntree, user->node); ct->texture = NULL; } else { texptr = RNA_property_pointer_get(&user->ptr, user->prop); tex = (RNA_struct_is_a(texptr.type, &RNA_Texture)) ? texptr.data : NULL; ct->texture = tex; if (user->ptr.type == &RNA_ParticleSettingsTextureSlot) { /* stupid exception for particle systems which still uses influence * from the old texture system, set the active texture slots as well */ ParticleSettings *part = user->ptr.id.data; int a; for (a = 0; a < MAX_MTEX; a++) { if (user->ptr.data == part->mtex[a]) { part->texact = a; } } } if (sbuts && tex) { sbuts->preview = 1; } } ct->user = user; ct->index = user->index; }
void node_select_single(bContext *C, bNode *node) { Main *bmain = CTX_data_main(C); SpaceNode *snode = CTX_wm_space_node(C); bNode *tnode; for (tnode = snode->edittree->nodes.first; tnode; tnode = tnode->next) if (tnode != node) nodeSetSelected(tnode, false); nodeSetSelected(node, true); ED_node_set_active(bmain, snode->edittree, node); ED_node_set_active_viewer_key(snode); ED_node_sort(snode->edittree); WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); }
static int node_mouse_select(Main *bmain, SpaceNode *snode, ARegion *ar, const int mval[2], short extend) { bNode *node, *tnode; bNodeSocket *sock, *tsock; float cursor[2]; int selected = 0; /* get mouse coordinates in view2d space */ UI_view2d_region_to_view(&ar->v2d, mval[0], mval[1], &cursor[0], &cursor[1]); if (extend) { /* first do socket selection, these generally overlap with nodes. * socket selection only in extend mode. */ if (node_find_indicated_socket(snode, &node, &sock, cursor, SOCK_IN)) { node_socket_toggle(node, sock, 1); selected = 1; } else if (node_find_indicated_socket(snode, &node, &sock, cursor, SOCK_OUT)) { if (sock->flag & SELECT) { node_socket_deselect(node, sock, 1); } else { /* only allow one selected output per node, for sensible linking. * allows selecting outputs from different nodes though. */ if (node) { for (tsock = node->outputs.first; tsock; tsock = tsock->next) node_socket_deselect(node, tsock, 1); } node_socket_select(node, sock); } selected = 1; } else { /* find the closest visible node */ node = node_under_mouse_select(snode->edittree, cursor[0], cursor[1]); if (node) { if ((node->flag & SELECT) && (node->flag & NODE_ACTIVE) == 0) { /* if node is selected but not active make it active * before it'll be desleected */ ED_node_set_active(bmain, snode->edittree, node); } else { node_toggle(node); ED_node_set_active(bmain, snode->edittree, node); } selected = 1; } } } else { /* extend == 0 */ /* find the closest visible node */ node = node_under_mouse_select(snode->edittree, cursor[0], cursor[1]); if (node) { for (tnode = snode->edittree->nodes.first; tnode; tnode = tnode->next) { nodeSetSelected(tnode, false); } nodeSetSelected(node, true); ED_node_set_active(bmain, snode->edittree, node); selected = 1; } } /* update node order */ if (selected) { ED_node_set_active_viewer_key(snode); ED_node_sort(snode->edittree); } return selected; }