doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / blender / editors / space_logic / logic_buttons.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2009 by Blender Foundation
21  * All rights reserved.
22  *
23  * ***** END GPL LICENSE BLOCK *****
24  */
25
26 #include <string.h>
27 #include <stdio.h>
28
29 #include "BLI_blenlib.h"
30 #include "BLI_math.h"
31 #include "BLI_utildefines.h"
32
33 #include "BKE_context.h"
34 #include "BKE_screen.h"
35
36 #include "ED_screen.h"
37
38 #include "RNA_access.h"
39 #include "RNA_define.h"
40
41 #include "WM_api.h"
42 #include "WM_types.h"
43
44 #include "UI_interface.h"
45 #include "UI_view2d.h"
46
47 #include "interface_intern.h"
48 #include "logic_intern.h"
49
50 #if 0
51 static void do_logic_panel_events(bContext *C, void *arg, int event)
52 {
53         
54         switch(event) {
55                 
56         }
57 }
58
59
60 /* *** */
61
62 static void logic_panel_properties(const bContext *C, Panel *pa)
63 {
64 //      SpaceLogic *slogic= CTX_wm_space_logic(C);
65         uiBlock *block;
66         
67         block= uiLayoutAbsoluteBlock(pa->layout);
68         uiBlockSetHandleFunc(block, do_logic_panel_events, NULL);
69
70 }       
71
72 static void logic_panel_view_properties(const bContext *C, Panel *pa)
73 {
74         //      SpaceLogic *slogic= CTX_wm_space_logic(C);
75         uiBlock *block;
76         
77         block= uiLayoutAbsoluteBlock(pa->layout);
78         uiBlockSetHandleFunc(block, do_logic_panel_events, NULL);
79         
80 }       
81 #endif
82
83 void logic_buttons_register(ARegionType *UNUSED(art))
84 {
85 #if 0
86         PanelType *pt;
87
88         pt= MEM_callocN(sizeof(PanelType), "spacetype logic panel properties");
89         strcpy(pt->idname, "LOGIC_PT_properties");
90         strcpy(pt->label, "Logic Properties");
91         pt->draw= logic_panel_properties;
92         BLI_addtail(&art->paneltypes, pt);
93
94         pt= MEM_callocN(sizeof(PanelType), "spacetype logic view properties");
95         strcpy(pt->idname, "LOGIC_PT_view_properties");
96         strcpy(pt->label, "View Properties");
97         pt->draw= logic_panel_view_properties;
98         BLI_addtail(&art->paneltypes, pt);
99 #endif
100
101 }
102
103 static int logic_properties(bContext *C, wmOperator *UNUSED(op))
104 {
105         ScrArea *sa= CTX_wm_area(C);
106         ARegion *ar= logic_has_buttons_region(sa);
107         
108         if(ar)
109                 ED_region_toggle_hidden(C, ar);
110
111         return OPERATOR_FINISHED;
112 }
113
114 void LOGIC_OT_properties(wmOperatorType *ot)
115 {
116         ot->name= "Properties";
117         ot->description= "Toggle display properties panel";
118         ot->idname= "LOGIC_OT_properties";
119         
120         ot->exec= logic_properties;
121         ot->poll= ED_operator_logic_active;
122         
123         /* flags */
124         ot->flag= 0;
125 }
126
127 /* Remove Logic Bricks Connections */
128 /* ********************** Cut Link operator ***************** */
129
130 #define LINK_RESOL 12
131 static int cut_links_intersect(uiLinkLine *line, float mcoords[][2], int tot)
132 {
133         float coord_array[LINK_RESOL+1][2];
134         int i, b;
135         rcti rectlink;
136
137         rectlink.xmin= (int) (line->from->x1 + line->from->x2) / 2;
138         rectlink.ymin= (int) (line->from->y1 + line->from->y2) / 2;
139         rectlink.xmax= (int) (line->to->x1 + line->to->x2) / 2;
140         rectlink.ymax= (int) (line->to->y1 + line->to->y2) / 2;
141
142         if(ui_link_bezier_points(&rectlink, coord_array, LINK_RESOL)){
143                 for(i=0; i<tot-1; i++)
144                         for(b=0; b<LINK_RESOL-1; b++)
145                                 if(isect_line_line_v2(mcoords[i], mcoords[i+1], coord_array[b], coord_array[b+1]) > 0)
146                                         return 1;
147         }
148         return 0;
149 }
150
151 static int cut_links_exec(bContext *C, wmOperator *op)
152 {
153         ARegion *ar= CTX_wm_region(C);
154         float mcoords[256][2];
155         int i= 0;
156         
157         RNA_BEGIN(op->ptr, itemptr, "path") {
158                 float loc[2];
159                 
160                 RNA_float_get_array(&itemptr, "loc", loc);
161                 UI_view2d_region_to_view(&ar->v2d, (short)loc[0], (short)loc[1], 
162                                                                  &mcoords[i][0], &mcoords[i][1]);
163                 i++;
164                 if(i>= 256) break;
165         }
166         RNA_END;
167
168         if (i>1) {
169                 uiBlock *block;
170                 uiLinkLine *line, *nline;
171                 uiBut *but;
172                 for(block= ar->uiblocks.first; block; block= block->next)
173                 {
174                         but= block->buttons.first;
175                         while(but) {
176                                 if(but->type==LINK && but->link) {
177                                         for(line= but->link->lines.first; line; line= nline) {
178                                                 nline= line->next;
179
180                                                 if(cut_links_intersect(line, mcoords, i)) {
181                                                         ui_delete_linkline(line, but);
182                                                 }
183                                         }
184                                 }
185                                 but= but->next;
186                         }
187                 }
188                 return OPERATOR_FINISHED;
189         }       
190         return OPERATOR_CANCELLED|OPERATOR_PASS_THROUGH;
191 }
192
193 void LOGIC_OT_links_cut(wmOperatorType *ot)
194 {
195         PropertyRNA *prop;
196         
197         ot->name= "Cut links";
198         ot->idname= "LOGIC_OT_links_cut";
199         ot->description= "Remove logic brick connections";
200         
201         ot->invoke= WM_gesture_lines_invoke;
202         ot->modal= WM_gesture_lines_modal;
203         ot->exec= cut_links_exec;
204         
205         ot->poll= ED_operator_logic_active;
206         
207         /* flags */
208         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
209         
210         prop= RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE);
211         RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath);
212         /* internal */
213         RNA_def_int(ot->srna, "cursor", BC_KNIFECURSOR, 0, INT_MAX, "Cursor", "", 0, INT_MAX);
214 }
215