Blender V2.61 - r43446
|
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) 2008 Blender Foundation. 00019 * All rights reserved. 00020 * 00021 * 00022 * Contributor(s): Blender Foundation, Nathan Letwory 00023 * 00024 * ***** END GPL LICENSE BLOCK ***** 00025 */ 00026 00032 #include <stdio.h> 00033 00034 #include "DNA_node_types.h" 00035 #include "DNA_scene_types.h" 00036 00037 #include "BLI_rect.h" 00038 #include "BLI_utildefines.h" 00039 00040 #include "BKE_context.h" 00041 #include "BKE_node.h" 00042 00043 #include "ED_screen.h" 00044 00045 #include "RNA_access.h" 00046 #include "RNA_define.h" 00047 00048 #include "WM_api.h" 00049 #include "WM_types.h" 00050 00051 #include "UI_view2d.h" 00052 00053 #include "node_intern.h" 00054 00055 00056 /* **************** View All Operator ************** */ 00057 00058 static void snode_home(ScrArea *UNUSED(sa), ARegion *ar, SpaceNode* snode) 00059 { 00060 bNode *node; 00061 rctf *cur; 00062 float oldwidth, oldheight, width, height; 00063 int first= 1; 00064 00065 cur= &ar->v2d.cur; 00066 00067 oldwidth= cur->xmax - cur->xmin; 00068 oldheight= cur->ymax - cur->ymin; 00069 00070 cur->xmin= cur->ymin= 0.0f; 00071 cur->xmax=ar->winx; 00072 cur->ymax=ar->winy; 00073 00074 if(snode->edittree) { 00075 for(node= snode->edittree->nodes.first; node; node= node->next) { 00076 if(first) { 00077 first= 0; 00078 ar->v2d.cur= node->totr; 00079 } 00080 else { 00081 BLI_union_rctf(cur, &node->totr); 00082 } 00083 } 00084 } 00085 00086 snode->xof= 0; 00087 snode->yof= 0; 00088 width= cur->xmax - cur->xmin; 00089 height= cur->ymax- cur->ymin; 00090 00091 if(width > height) { 00092 float newheight; 00093 newheight= oldheight * width/oldwidth; 00094 cur->ymin= cur->ymin - newheight/4; 00095 cur->ymax= cur->ymax + newheight/4; 00096 } 00097 else { 00098 float newwidth; 00099 newwidth= oldwidth * height/oldheight; 00100 cur->xmin= cur->xmin - newwidth/4; 00101 cur->xmax= cur->xmax + newwidth/4; 00102 } 00103 00104 ar->v2d.tot= ar->v2d.cur; 00105 UI_view2d_curRect_validate(&ar->v2d); 00106 } 00107 00108 static int node_view_all_exec(bContext *C, wmOperator *UNUSED(op)) 00109 { 00110 ScrArea *sa= CTX_wm_area(C); 00111 ARegion *ar= CTX_wm_region(C); 00112 SpaceNode *snode= CTX_wm_space_node(C); 00113 00114 snode_home(sa, ar, snode); 00115 ED_region_tag_redraw(ar); 00116 00117 return OPERATOR_FINISHED; 00118 } 00119 00120 void NODE_OT_view_all(wmOperatorType *ot) 00121 { 00122 /* identifiers */ 00123 ot->name= "View All"; 00124 ot->idname= "NODE_OT_view_all"; 00125 ot->description= "Resize view so you can see all nodes"; 00126 00127 /* api callbacks */ 00128 ot->exec= node_view_all_exec; 00129 ot->poll= ED_operator_node_active; 00130 00131 /* flags */ 00132 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 00133 }