Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/space_logic/logic_buttons.c')
-rw-r--r--source/blender/editors/space_logic/logic_buttons.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/source/blender/editors/space_logic/logic_buttons.c b/source/blender/editors/space_logic/logic_buttons.c
index e159af65c74..9ee170b90d8 100644
--- a/source/blender/editors/space_logic/logic_buttons.c
+++ b/source/blender/editors/space_logic/logic_buttons.c
@@ -56,6 +56,7 @@
#include "BIF_glutil.h"
#include "RNA_access.h"
+#include "RNA_define.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -64,6 +65,7 @@
#include "UI_resources.h"
#include "UI_view2d.h"
+#include "interface_intern.h"
#include "logic_intern.h"
#if 0
@@ -143,5 +145,90 @@ void LOGIC_OT_properties(wmOperatorType *ot)
ot->flag= 0;
}
+/* Remove Logic Bricks Connections */
+/* ********************** Cut Link operator ***************** */
+#define LINK_RESOL 12
+static int cut_links_intersect(uiLinkLine *line, float mcoords[][2], int tot)
+{
+ float coord_array[LINK_RESOL+1][2];
+ int i, b;
+ rcti rectlink;
+
+ rectlink.xmin= (int) (line->from->x1 + line->from->x2) / 2;
+ rectlink.ymin= (int) (line->from->y1 + line->from->y2) / 2;
+ rectlink.xmax= (int) (line->to->x1 + line->to->x2) / 2;
+ rectlink.ymax= (int) (line->to->y1 + line->to->y2) / 2;
+
+ if(ui_link_bezier_points(&rectlink, coord_array, LINK_RESOL)){
+ for(i=0; i<tot-1; i++)
+ for(b=0; b<LINK_RESOL-1; b++)
+ if(isect_line_line_v2(mcoords[i], mcoords[i+1], coord_array[b], coord_array[b+1]) > 0)
+ return 1;
+ }
+ return 0;
+}
+
+static int cut_links_exec(bContext *C, wmOperator *op)
+{
+ ARegion *ar= CTX_wm_region(C);
+ float mcoords[256][2];
+ int i= 0;
+
+ RNA_BEGIN(op->ptr, itemptr, "path") {
+ float loc[2];
+
+ RNA_float_get_array(&itemptr, "loc", loc);
+ UI_view2d_region_to_view(&ar->v2d, (short)loc[0], (short)loc[1],
+ &mcoords[i][0], &mcoords[i][1]);
+ i++;
+ if(i>= 256) break;
+ }
+ RNA_END;
+
+ if (i>1) {
+ uiBlock *block;
+ uiLinkLine *line, *nline;
+ uiBut *but;
+ for(block= ar->uiblocks.first; block; block= block->next)
+ {
+ but= block->buttons.first;
+ while(but) {
+ if(but->type==LINK && but->link) {
+ for(line= but->link->lines.first; line; line= nline) {
+ nline= line->next;
+
+ if(cut_links_intersect(line, mcoords, i)) {
+ ui_delete_linkline(line, but);
+ }
+ }
+ }
+ but= but->next;
+ }
+ }
+ return OPERATOR_FINISHED;
+ }
+ return OPERATOR_CANCELLED|OPERATOR_PASS_THROUGH;
+}
+void LOGIC_OT_links_cut(wmOperatorType *ot)
+{
+ PropertyRNA *prop;
+
+ ot->name= "Cut links";
+ ot->idname= "LOGIC_OT_links_cut";
+
+ ot->invoke= WM_gesture_lines_invoke;
+ ot->modal= WM_gesture_lines_modal;
+ ot->exec= cut_links_exec;
+
+ ot->poll= ED_operator_logic_active;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ prop= RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath);
+ /* internal */
+ RNA_def_int(ot->srna, "cursor", BC_KNIFECURSOR, 0, INT_MAX, "Cursor", "", 0, INT_MAX);
+} \ No newline at end of file