Blender V2.61 - r43446

logic_buttons.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2009 by Blender Foundation
00019  * All rights reserved.
00020  *
00021  * ***** END GPL LICENSE BLOCK *****
00022  */
00023 
00029 #include <string.h>
00030 #include <stdio.h>
00031 
00032 #include "BLI_blenlib.h"
00033 #include "BLI_math.h"
00034 #include "BLI_utildefines.h"
00035 
00036 #include "BKE_context.h"
00037 #include "BKE_screen.h"
00038 
00039 #include "ED_screen.h"
00040 
00041 #include "RNA_access.h"
00042 #include "RNA_define.h"
00043 
00044 #include "WM_api.h"
00045 #include "WM_types.h"
00046 
00047 #include "UI_interface.h"
00048 #include "UI_view2d.h"
00049 
00050 #include "interface_intern.h"
00051 #include "logic_intern.h"
00052 
00053 #if 0
00054 static void do_logic_panel_events(bContext *C, void *arg, int event)
00055 {
00056     
00057     switch(event) {
00058         
00059     }
00060 }
00061 
00062 
00063 /* *** */
00064 
00065 static void logic_panel_properties(const bContext *C, Panel *pa)
00066 {
00067 //  SpaceLogic *slogic= CTX_wm_space_logic(C);
00068     uiBlock *block;
00069     
00070     block= uiLayoutAbsoluteBlock(pa->layout);
00071     uiBlockSetHandleFunc(block, do_logic_panel_events, NULL);
00072 
00073 }   
00074 
00075 static void logic_panel_view_properties(const bContext *C, Panel *pa)
00076 {
00077     //  SpaceLogic *slogic= CTX_wm_space_logic(C);
00078     uiBlock *block;
00079     
00080     block= uiLayoutAbsoluteBlock(pa->layout);
00081     uiBlockSetHandleFunc(block, do_logic_panel_events, NULL);
00082     
00083 }   
00084 #endif
00085 
00086 void logic_buttons_register(ARegionType *UNUSED(art))
00087 {
00088 #if 0
00089     PanelType *pt;
00090 
00091     pt= MEM_callocN(sizeof(PanelType), "spacetype logic panel properties");
00092     strcpy(pt->idname, "LOGIC_PT_properties");
00093     strcpy(pt->label, "Logic Properties");
00094     pt->draw= logic_panel_properties;
00095     BLI_addtail(&art->paneltypes, pt);
00096 
00097     pt= MEM_callocN(sizeof(PanelType), "spacetype logic view properties");
00098     strcpy(pt->idname, "LOGIC_PT_view_properties");
00099     strcpy(pt->label, "View Properties");
00100     pt->draw= logic_panel_view_properties;
00101     BLI_addtail(&art->paneltypes, pt);
00102 #endif
00103 
00104 }
00105 
00106 static int logic_properties(bContext *C, wmOperator *UNUSED(op))
00107 {
00108     ScrArea *sa= CTX_wm_area(C);
00109     ARegion *ar= logic_has_buttons_region(sa);
00110     
00111     if(ar)
00112         ED_region_toggle_hidden(C, ar);
00113 
00114     return OPERATOR_FINISHED;
00115 }
00116 
00117 void LOGIC_OT_properties(wmOperatorType *ot)
00118 {
00119     ot->name= "Properties";
00120     ot->description= "Toggle display properties panel";
00121     ot->idname= "LOGIC_OT_properties";
00122     
00123     ot->exec= logic_properties;
00124     ot->poll= ED_operator_logic_active;
00125     
00126     /* flags */
00127     ot->flag= 0;
00128 }
00129 
00130 /* Remove Logic Bricks Connections */
00131 /* ********************** Cut Link operator ***************** */
00132 
00133 #define LINK_RESOL 12
00134 static int cut_links_intersect(uiLinkLine *line, float mcoords[][2], int tot)
00135 {
00136     float coord_array[LINK_RESOL+1][2];
00137     int i, b;
00138     rcti rectlink;
00139 
00140     rectlink.xmin= (int) (line->from->x1 + line->from->x2) / 2;
00141     rectlink.ymin= (int) (line->from->y1 + line->from->y2) / 2;
00142     rectlink.xmax= (int) (line->to->x1 + line->to->x2) / 2;
00143     rectlink.ymax= (int) (line->to->y1 + line->to->y2) / 2;
00144 
00145     if(ui_link_bezier_points(&rectlink, coord_array, LINK_RESOL)){
00146         for(i=0; i<tot-1; i++)
00147             for(b=0; b<LINK_RESOL-1; b++)
00148                 if(isect_line_line_v2(mcoords[i], mcoords[i+1], coord_array[b], coord_array[b+1]) > 0)
00149                     return 1;
00150     }
00151     return 0;
00152 }
00153 
00154 static int cut_links_exec(bContext *C, wmOperator *op)
00155 {
00156     ARegion *ar= CTX_wm_region(C);
00157     float mcoords[256][2];
00158     int i= 0;
00159     
00160     RNA_BEGIN(op->ptr, itemptr, "path") {
00161         float loc[2];
00162         
00163         RNA_float_get_array(&itemptr, "loc", loc);
00164         UI_view2d_region_to_view(&ar->v2d, (short)loc[0], (short)loc[1], 
00165                                  &mcoords[i][0], &mcoords[i][1]);
00166         i++;
00167         if(i>= 256) break;
00168     }
00169     RNA_END;
00170 
00171     if (i>1) {
00172         uiBlock *block;
00173         uiLinkLine *line, *nline;
00174         uiBut *but;
00175         for(block= ar->uiblocks.first; block; block= block->next)
00176         {
00177             but= block->buttons.first;
00178             while(but) {
00179                 if(but->type==LINK && but->link) {
00180                     for(line= but->link->lines.first; line; line= nline) {
00181                         nline= line->next;
00182 
00183                         if(cut_links_intersect(line, mcoords, i)) {
00184                             ui_delete_linkline(line, but);
00185                         }
00186                     }
00187                 }
00188                 but= but->next;
00189             }
00190         }
00191         return OPERATOR_FINISHED;
00192     }   
00193     return OPERATOR_CANCELLED|OPERATOR_PASS_THROUGH;
00194 }
00195 
00196 void LOGIC_OT_links_cut(wmOperatorType *ot)
00197 {
00198     PropertyRNA *prop;
00199     
00200     ot->name= "Cut links";
00201     ot->idname= "LOGIC_OT_links_cut";
00202     ot->description= "Remove logic brick connections";
00203     
00204     ot->invoke= WM_gesture_lines_invoke;
00205     ot->modal= WM_gesture_lines_modal;
00206     ot->exec= cut_links_exec;
00207     ot->cancel= WM_gesture_lines_cancel;
00208     
00209     ot->poll= ED_operator_logic_active;
00210     
00211     /* flags */
00212     ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
00213     
00214     prop= RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE);
00215     RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath);
00216     /* internal */
00217     RNA_def_int(ot->srna, "cursor", BC_KNIFECURSOR, 0, INT_MAX, "Cursor", "", 0, INT_MAX);
00218 }
00219