Fix build error on Windows 32 bit.
[blender-staging.git] / source / blender / editors / space_logic / logic_buttons.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2009 by Blender Foundation
19  * All rights reserved.
20  *
21  * ***** END GPL LICENSE BLOCK *****
22  */
23
24 /** \file blender/editors/space_logic/logic_buttons.c
25  *  \ingroup splogic
26  */
27
28
29 #include <string.h>
30 #include <stdio.h>
31
32 #include "BLI_blenlib.h"
33 #include "BLI_math.h"
34 #include "BLI_utildefines.h"
35
36 #include "BKE_context.h"
37
38 #include "ED_screen.h"
39
40 #include "RNA_access.h"
41 #include "RNA_define.h"
42
43 #include "WM_api.h"
44 #include "WM_types.h"
45
46 #include "UI_interface.h"
47 #include "UI_view2d.h"
48
49 #include "interface_intern.h"
50 #include "logic_intern.h"
51
52 static int logic_properties_toggle_exec(bContext *C, wmOperator *UNUSED(op))
53 {
54         ScrArea *sa = CTX_wm_area(C);
55         ARegion *ar = logic_has_buttons_region(sa);
56         
57         if (ar)
58                 ED_region_toggle_hidden(C, ar);
59
60         return OPERATOR_FINISHED;
61 }
62
63 void LOGIC_OT_properties(wmOperatorType *ot)
64 {
65         ot->name = "Properties";
66         ot->description = "Toggle the properties region visibility";
67         ot->idname = "LOGIC_OT_properties";
68         
69         ot->exec = logic_properties_toggle_exec;
70         ot->poll = ED_operator_logic_active;
71         
72         /* flags */
73         ot->flag = 0;
74 }
75
76 /* Remove Logic Bricks Connections */
77 /* ********************** Cut Link operator ***************** */
78
79 #define LINK_RESOL 12
80 static int cut_links_intersect(uiLinkLine *line, float mcoords[][2], int tot)
81 {
82         float coord_array[LINK_RESOL+1][2];
83         int i, b;
84         rcti rectlink;
85
86         rectlink.xmin = (int)BLI_rctf_cent_x(&line->from->rect);
87         rectlink.ymin = (int)BLI_rctf_cent_y(&line->from->rect);
88         rectlink.xmax = (int)BLI_rctf_cent_x(&line->to->rect);
89         rectlink.ymax = (int)BLI_rctf_cent_y(&line->to->rect);
90
91         if (ui_link_bezier_points(&rectlink, coord_array, LINK_RESOL)) {
92                 for (i=0; i<tot-1; i++)
93                         for (b=0; b<LINK_RESOL-1; b++)
94                                 if (isect_seg_seg_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0)
95                                         return 1;
96         }
97         return 0;
98 }
99
100 static int cut_links_exec(bContext *C, wmOperator *op)
101 {
102         ARegion *ar = CTX_wm_region(C);
103         float mcoords[256][2];
104         int i = 0;
105         
106         RNA_BEGIN (op->ptr, itemptr, "path")
107         {
108                 float loc[2];
109                 
110                 RNA_float_get_array(&itemptr, "loc", loc);
111                 UI_view2d_region_to_view(&ar->v2d,
112                                          (int)loc[0], (int)loc[1],
113                                          &mcoords[i][0], &mcoords[i][1]);
114                 i++;
115                 if (i >= 256) break;
116         }
117         RNA_END;
118
119         if (i>1) {
120                 uiBlock *block;
121                 uiLinkLine *line, *nline;
122                 uiBut *but;
123                 for (block = ar->uiblocks.first; block; block = block->next) {
124                         but = block->buttons.first;
125                         while (but) {
126                                 if (but->type==UI_BTYPE_LINK && but->link) {
127                                         for (line = but->link->lines.first; line; line = nline) {
128                                                 nline = line->next;
129
130                                                 if (cut_links_intersect(line, mcoords, i)) {
131                                                         ui_linkline_remove(line, but);
132                                                 }
133                                         }
134                                 }
135                                 but = but->next;
136                         }
137                 }
138                 return OPERATOR_FINISHED;
139         }
140         return OPERATOR_CANCELLED|OPERATOR_PASS_THROUGH;
141 }
142
143 void LOGIC_OT_links_cut(wmOperatorType *ot)
144 {
145         ot->name = "Cut Links";
146         ot->idname = "LOGIC_OT_links_cut";
147         ot->description = "Remove logic brick connections";
148         
149         ot->invoke = WM_gesture_lines_invoke;
150         ot->modal = WM_gesture_lines_modal;
151         ot->exec = cut_links_exec;
152         ot->cancel = WM_gesture_lines_cancel;
153         
154         ot->poll = ED_operator_logic_active;
155         
156         /* flags */
157         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
158         
159         /* properties */
160         PropertyRNA *prop;
161         prop = RNA_def_collection_runtime(ot->srna, "path", &RNA_OperatorMousePath, "Path", "");
162         RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
163         /* internal */
164         RNA_def_int(ot->srna, "cursor", BC_KNIFECURSOR, 0, INT_MAX, "Cursor", "", 0, INT_MAX);
165 }
166