2
* ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
18
* The Original Code is Copyright (C) 2008 Blender Foundation.
19
* All rights reserved.
22
* Contributor(s): Blender Foundation, Nathan Letwory
24
* ***** END GPL LICENSE BLOCK *****
27
/** \file blender/editors/space_node/node_state.c
34
#include "DNA_node_types.h"
35
#include "DNA_scene_types.h"
38
#include "BLI_utildefines.h"
40
#include "BKE_context.h"
43
#include "ED_screen.h"
45
#include "RNA_access.h"
46
#include "RNA_define.h"
51
#include "UI_view2d.h"
53
#include "node_intern.h"
56
/* **************** View All Operator ************** */
58
static void snode_home(ScrArea *UNUSED(sa), ARegion *ar, SpaceNode* snode)
62
float oldwidth, oldheight, width, height;
67
oldwidth= cur->xmax - cur->xmin;
68
oldheight= cur->ymax - cur->ymin;
70
cur->xmin = cur->ymin = 0.0f;
74
if (snode->edittree) {
75
for (node= snode->edittree->nodes.first; node; node= node->next) {
78
ar->v2d.cur= node->totr;
81
BLI_union_rctf(cur, &node->totr);
88
width= cur->xmax - cur->xmin;
89
height= cur->ymax- cur->ymin;
93
newheight= oldheight * width/oldwidth;
94
cur->ymin = cur->ymin - newheight/4;
95
cur->ymax = cur->ymax + newheight/4;
99
newwidth= oldwidth * height/oldheight;
100
cur->xmin = cur->xmin - newwidth/4;
101
cur->xmax = cur->xmax + newwidth/4;
104
ar->v2d.tot= ar->v2d.cur;
105
UI_view2d_curRect_validate(&ar->v2d);
108
static int node_view_all_exec(bContext *C, wmOperator *UNUSED(op))
110
ScrArea *sa= CTX_wm_area(C);
111
ARegion *ar= CTX_wm_region(C);
112
SpaceNode *snode= CTX_wm_space_node(C);
114
snode_home(sa, ar, snode);
115
ED_region_tag_redraw(ar);
117
return OPERATOR_FINISHED;
120
void NODE_OT_view_all(wmOperatorType *ot)
123
ot->name = "View All";
124
ot->idname = "NODE_OT_view_all";
125
ot->description = "Resize view so you can see all nodes";
128
ot->exec = node_view_all_exec;
129
ot->poll = ED_operator_node_active;
132
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;