2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-12-28 21:41:33 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-12-28 21:41:33 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2008 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Contributor(s): Blender Foundation, Nathan Letwory
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-27 20:29:51 +00:00
|
|
|
/** \file blender/editors/space_node/node_state.c
|
|
|
|
* \ingroup spnode
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2008-12-28 21:41:33 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "DNA_node_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_rect.h"
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
2008-12-28 21:41:33 +00:00
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_node.h"
|
|
|
|
|
|
|
|
#include "ED_screen.h"
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
|
|
#include "UI_view2d.h"
|
|
|
|
|
|
|
|
#include "node_intern.h"
|
|
|
|
|
2009-01-01 16:27:02 +00:00
|
|
|
|
2009-11-20 21:04:41 +00:00
|
|
|
/* **************** View All Operator ************** */
|
|
|
|
|
2010-10-16 08:03:28 +00:00
|
|
|
static void snode_home(ScrArea *UNUSED(sa), ARegion *ar, SpaceNode* snode)
|
2009-11-20 21:04:41 +00:00
|
|
|
{
|
|
|
|
bNode *node;
|
2011-09-20 08:48:48 +00:00
|
|
|
rctf *cur;
|
2009-11-20 21:04:41 +00:00
|
|
|
float oldwidth, oldheight, width, height;
|
|
|
|
int first= 1;
|
|
|
|
|
|
|
|
cur= &ar->v2d.cur;
|
|
|
|
|
|
|
|
oldwidth= cur->xmax - cur->xmin;
|
|
|
|
oldheight= cur->ymax - cur->ymin;
|
|
|
|
|
|
|
|
cur->xmin= cur->ymin= 0.0f;
|
|
|
|
cur->xmax=ar->winx;
|
2010-07-19 22:47:15 +00:00
|
|
|
cur->ymax=ar->winy;
|
2009-11-20 21:04:41 +00:00
|
|
|
|
|
|
|
if(snode->edittree) {
|
|
|
|
for(node= snode->edittree->nodes.first; node; node= node->next) {
|
|
|
|
if(first) {
|
|
|
|
first= 0;
|
|
|
|
ar->v2d.cur= node->totr;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_union_rctf(cur, &node->totr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
snode->xof= 0;
|
|
|
|
snode->yof= 0;
|
|
|
|
width= cur->xmax - cur->xmin;
|
|
|
|
height= cur->ymax- cur->ymin;
|
2010-07-19 22:47:15 +00:00
|
|
|
|
2009-11-20 21:04:41 +00:00
|
|
|
if(width > height) {
|
|
|
|
float newheight;
|
|
|
|
newheight= oldheight * width/oldwidth;
|
|
|
|
cur->ymin= cur->ymin - newheight/4;
|
2010-07-19 22:47:15 +00:00
|
|
|
cur->ymax= cur->ymax + newheight/4;
|
2009-11-20 21:04:41 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
float newwidth;
|
|
|
|
newwidth= oldwidth * height/oldheight;
|
|
|
|
cur->xmin= cur->xmin - newwidth/4;
|
2010-07-19 22:47:15 +00:00
|
|
|
cur->xmax= cur->xmax + newwidth/4;
|
2009-11-20 21:04:41 +00:00
|
|
|
}
|
2010-07-19 22:47:15 +00:00
|
|
|
|
2009-11-20 21:04:41 +00:00
|
|
|
ar->v2d.tot= ar->v2d.cur;
|
|
|
|
UI_view2d_curRect_validate(&ar->v2d);
|
|
|
|
}
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int node_view_all_exec(bContext *C, wmOperator *UNUSED(op))
|
2009-01-01 16:27:02 +00:00
|
|
|
{
|
|
|
|
ScrArea *sa= CTX_wm_area(C);
|
|
|
|
ARegion *ar= CTX_wm_region(C);
|
2009-07-28 16:33:02 +00:00
|
|
|
SpaceNode *snode= CTX_wm_space_node(C);
|
2009-11-20 21:04:41 +00:00
|
|
|
|
2009-01-01 16:27:02 +00:00
|
|
|
snode_home(sa, ar, snode);
|
|
|
|
ED_region_tag_redraw(ar);
|
2009-11-20 21:04:41 +00:00
|
|
|
|
2009-01-01 16:27:02 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2009-03-29 02:15:13 +00:00
|
|
|
void NODE_OT_view_all(wmOperatorType *ot)
|
2009-01-01 16:27:02 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
2009-08-19 00:55:30 +00:00
|
|
|
ot->name= "View All";
|
2009-03-29 02:15:13 +00:00
|
|
|
ot->idname= "NODE_OT_view_all";
|
2010-12-09 16:50:32 +00:00
|
|
|
ot->description= "Resize view so you can see all nodes";
|
2009-01-01 16:27:02 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2009-08-19 00:55:30 +00:00
|
|
|
ot->exec= node_view_all_exec;
|
2009-01-01 16:27:02 +00:00
|
|
|
ot->poll= ED_operator_node_active;
|
2009-01-31 19:40:40 +00:00
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
2009-01-16 23:53:11 +00:00
|
|
|
}
|