~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/editors/space_node/node_state.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * ***** BEGIN GPL LICENSE BLOCK *****
3
 
 *
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. 
8
 
 *
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.
13
 
 *
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.
17
 
 *
18
 
 * The Original Code is Copyright (C) 2008 Blender Foundation.
19
 
 * All rights reserved.
20
 
 *
21
 
 * 
22
 
 * Contributor(s): Blender Foundation, Nathan Letwory
23
 
 *
24
 
 * ***** END GPL LICENSE BLOCK *****
25
 
 */
26
 
 
27
 
/** \file blender/editors/space_node/node_state.c
28
 
 *  \ingroup spnode
29
 
 */
30
 
 
31
 
 
32
 
#include <stdio.h>
33
 
 
34
 
#include "DNA_node_types.h"
35
 
#include "DNA_scene_types.h"
36
 
 
37
 
#include "BLI_rect.h"
38
 
#include "BLI_utildefines.h"
39
 
 
40
 
#include "BKE_context.h"
41
 
#include "BKE_node.h"
42
 
 
43
 
#include "ED_screen.h"
44
 
 
45
 
#include "RNA_access.h"
46
 
#include "RNA_define.h"
47
 
 
48
 
#include "WM_api.h"
49
 
#include "WM_types.h"
50
 
 
51
 
#include "UI_view2d.h"
52
 
 
53
 
#include "node_intern.h"
54
 
 
55
 
 
56
 
/* **************** View All Operator ************** */
57
 
 
58
 
static void snode_home(ScrArea *UNUSED(sa), ARegion *ar, SpaceNode* snode)
59
 
{
60
 
        bNode *node;
61
 
        rctf *cur;
62
 
        float oldwidth, oldheight, width, height;
63
 
        int first= 1;
64
 
        
65
 
        cur= &ar->v2d.cur;
66
 
        
67
 
        oldwidth= cur->xmax - cur->xmin;
68
 
        oldheight= cur->ymax - cur->ymin;
69
 
        
70
 
        cur->xmin = cur->ymin = 0.0f;
71
 
        cur->xmax=ar->winx;
72
 
        cur->ymax=ar->winy;
73
 
        
74
 
        if (snode->edittree) {
75
 
                for (node= snode->edittree->nodes.first; node; node= node->next) {
76
 
                        if (first) {
77
 
                                first= 0;
78
 
                                ar->v2d.cur= node->totr;
79
 
                        }
80
 
                        else {
81
 
                                BLI_union_rctf(cur, &node->totr);
82
 
                        }
83
 
                }
84
 
        }
85
 
        
86
 
        snode->xof= 0;
87
 
        snode->yof= 0;
88
 
        width= cur->xmax - cur->xmin;
89
 
        height= cur->ymax- cur->ymin;
90
 
 
91
 
        if (width > height) {
92
 
                float newheight;
93
 
                newheight= oldheight * width/oldwidth;
94
 
                cur->ymin = cur->ymin - newheight/4;
95
 
                cur->ymax = cur->ymax + newheight/4;
96
 
        }
97
 
        else {
98
 
                float newwidth;
99
 
                newwidth= oldwidth * height/oldheight;
100
 
                cur->xmin = cur->xmin - newwidth/4;
101
 
                cur->xmax = cur->xmax + newwidth/4;
102
 
        }
103
 
 
104
 
        ar->v2d.tot= ar->v2d.cur;
105
 
        UI_view2d_curRect_validate(&ar->v2d);
106
 
}
107
 
 
108
 
static int node_view_all_exec(bContext *C, wmOperator *UNUSED(op))
109
 
{
110
 
        ScrArea *sa= CTX_wm_area(C);
111
 
        ARegion *ar= CTX_wm_region(C);
112
 
        SpaceNode *snode= CTX_wm_space_node(C);
113
 
        
114
 
        snode_home(sa, ar, snode);
115
 
        ED_region_tag_redraw(ar);
116
 
        
117
 
        return OPERATOR_FINISHED;
118
 
}
119
 
 
120
 
void NODE_OT_view_all(wmOperatorType *ot)
121
 
{
122
 
        /* identifiers */
123
 
        ot->name = "View All";
124
 
        ot->idname = "NODE_OT_view_all";
125
 
        ot->description = "Resize view so you can see all nodes";
126
 
        
127
 
        /* api callbacks */
128
 
        ot->exec = node_view_all_exec;
129
 
        ot->poll = ED_operator_node_active;
130
 
        
131
 
        /* flags */
132
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
133
 
}