Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_node/node_add.c
| Show First 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | static bool add_reroute_intersect_check(bNodeLink *link, | ||||
| int tot, | int tot, | ||||
| float result[2]) | float result[2]) | ||||
| { | { | ||||
| float coord_array[NODE_LINK_RESOL + 1][2]; | float coord_array[NODE_LINK_RESOL + 1][2]; | ||||
| if (node_link_bezier_points(NULL, NULL, link, coord_array, NODE_LINK_RESOL)) { | if (node_link_bezier_points(NULL, NULL, link, coord_array, NODE_LINK_RESOL)) { | ||||
| for (int i = 0; i < tot - 1; i++) { | for (int i = 0; i < tot - 1; i++) { | ||||
| for (int b = 0; b < NODE_LINK_RESOL; b++) { | for (int b = 0; b < NODE_LINK_RESOL; b++) { | ||||
| if (isect_seg_seg_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0) { | if (isect_seg_seg_v2_point( | ||||
| result[0] = (mcoords[i][0] + mcoords[i + 1][0]) / 2.0f; | mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1], result) > 0) { | ||||
| result[1] = (mcoords[i][1] + mcoords[i + 1][1]) / 2.0f; | |||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 189 Lines • ▼ Show 20 Lines | void NODE_OT_add_reroute(wmOperatorType *ot) | ||||
| prop = RNA_def_collection_runtime(ot->srna, "path", &RNA_OperatorMousePath, "Path", ""); | prop = RNA_def_collection_runtime(ot->srna, "path", &RNA_OperatorMousePath, "Path", ""); | ||||
| RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); | RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); | ||||
| /* internal */ | /* internal */ | ||||
| RNA_def_int(ot->srna, "cursor", WM_CURSOR_CROSS, 0, INT_MAX, "Cursor", "", 0, INT_MAX); | RNA_def_int(ot->srna, "cursor", WM_CURSOR_CROSS, 0, INT_MAX, "Cursor", "", 0, INT_MAX); | ||||
| } | } | ||||
| /* ****************** Add File Node Operator ******************* */ | /* ****************** Add File Node Operator ******************* */ | ||||
| static bool node_add_file_poll(bContext *C) | |||||
| { | |||||
| const SpaceNode *snode = CTX_wm_space_node(C); | |||||
| return ED_operator_node_editable(C) && | |||||
| ELEM(snode->nodetree->type, NTREE_SHADER, NTREE_TEXTURE, NTREE_COMPOSIT); | |||||
| } | |||||
| static int node_add_file_exec(bContext *C, wmOperator *op) | static int node_add_file_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| SpaceNode *snode = CTX_wm_space_node(C); | SpaceNode *snode = CTX_wm_space_node(C); | ||||
| bNode *node; | bNode *node; | ||||
| Image *ima; | Image *ima; | ||||
| int type = 0; | int type = 0; | ||||
| Show All 13 Lines | case NTREE_COMPOSIT: | ||||
| type = CMP_NODE_IMAGE; | type = CMP_NODE_IMAGE; | ||||
| break; | break; | ||||
| default: | default: | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); | ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); | ||||
| node = node_add_node(C, NULL, type, snode->cursor[0], snode->cursor[1]); | node = node_add_node(C, NULL, type, snode->runtime->cursor[0], snode->runtime->cursor[1]); | ||||
| if (!node) { | if (!node) { | ||||
| BKE_report(op->reports, RPT_WARNING, "Could not add an image node"); | BKE_report(op->reports, RPT_WARNING, "Could not add an image node"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| node->id = (ID *)ima; | node->id = (ID *)ima; | ||||
| Show All 12 Lines | |||||
| } | } | ||||
| static int node_add_file_invoke(bContext *C, wmOperator *op, const wmEvent *event) | static int node_add_file_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| { | { | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| SpaceNode *snode = CTX_wm_space_node(C); | SpaceNode *snode = CTX_wm_space_node(C); | ||||
| /* convert mouse coordinates to v2d space */ | /* convert mouse coordinates to v2d space */ | ||||
| UI_view2d_region_to_view( | UI_view2d_region_to_view(®ion->v2d, | ||||
| ®ion->v2d, event->mval[0], event->mval[1], &snode->cursor[0], &snode->cursor[1]); | event->mval[0], | ||||
| event->mval[1], | |||||
| &snode->runtime->cursor[0], | |||||
| &snode->runtime->cursor[1]); | |||||
| 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; | ||||
| if (RNA_struct_property_is_set(op->ptr, "filepath") || | if (RNA_struct_property_is_set(op->ptr, "filepath") || | ||||
| RNA_struct_property_is_set(op->ptr, "name")) { | RNA_struct_property_is_set(op->ptr, "name")) { | ||||
| return node_add_file_exec(C, op); | return node_add_file_exec(C, op); | ||||
| } | } | ||||
| return WM_operator_filesel(C, op, event); | return WM_operator_filesel(C, op, event); | ||||
| } | } | ||||
| void NODE_OT_add_file(wmOperatorType *ot) | void NODE_OT_add_file(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Add File Node"; | ot->name = "Add File Node"; | ||||
| ot->description = "Add a file node to the current node editor"; | ot->description = "Add a file node to the current node editor"; | ||||
| ot->idname = "NODE_OT_add_file"; | ot->idname = "NODE_OT_add_file"; | ||||
| /* callbacks */ | /* callbacks */ | ||||
| ot->exec = node_add_file_exec; | ot->exec = node_add_file_exec; | ||||
| ot->invoke = node_add_file_invoke; | ot->invoke = node_add_file_invoke; | ||||
| ot->poll = ED_operator_node_editable; | ot->poll = node_add_file_poll; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| WM_operator_properties_filesel(ot, | WM_operator_properties_filesel(ot, | ||||
| FILE_TYPE_FOLDER | FILE_TYPE_IMAGE | FILE_TYPE_MOVIE, | FILE_TYPE_FOLDER | FILE_TYPE_IMAGE | FILE_TYPE_MOVIE, | ||||
| FILE_SPECIAL, | FILE_SPECIAL, | ||||
| FILE_OPENFILE, | FILE_OPENFILE, | ||||
| Show All 25 Lines | static int node_add_mask_exec(bContext *C, wmOperator *op) | ||||
| mask = BKE_libblock_find_name(bmain, ID_MSK, name); | mask = BKE_libblock_find_name(bmain, ID_MSK, name); | ||||
| if (!mask) { | if (!mask) { | ||||
| BKE_reportf(op->reports, RPT_ERROR, "Mask '%s' not found", name); | BKE_reportf(op->reports, RPT_ERROR, "Mask '%s' not found", name); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); | ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); | ||||
| node = node_add_node(C, NULL, CMP_NODE_MASK, snode->cursor[0], snode->cursor[1]); | node = node_add_node( | ||||
| C, NULL, CMP_NODE_MASK, snode->runtime->cursor[0], snode->runtime->cursor[1]); | |||||
| if (!node) { | if (!node) { | ||||
| BKE_report(op->reports, RPT_WARNING, "Could not add a mask node"); | BKE_report(op->reports, RPT_WARNING, "Could not add a mask node"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| node->id = mask; | node->id = mask; | ||||
| id_us_plus(mask); | id_us_plus(mask); | ||||
| ▲ Show 20 Lines • Show All 112 Lines • Show Last 20 Lines | |||||