Merging trunk up to r39447.
[blender.git] / release / scripts / startup / bl_ui / space_node.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 from bpy.types import Header, Menu, Panel
22
23
24 class NODE_HT_header(Header):
25     bl_space_type = 'NODE_EDITOR'
26
27     def draw(self, context):
28         layout = self.layout
29
30         snode = context.space_data
31         snode_id = snode.id
32         id_from = snode.id_from
33
34         row = layout.row(align=True)
35         row.template_header()
36
37         if context.area.show_menus:
38             row.menu("NODE_MT_view")
39             row.menu("NODE_MT_select")
40             row.menu("NODE_MT_add")
41             row.menu("NODE_MT_node")
42
43         layout.prop(snode, "tree_type", text="", expand=True)
44
45         if snode.tree_type == 'MATERIAL':
46             if id_from:
47                 layout.template_ID(id_from, "active_material", new="material.new")
48             if snode_id:
49                 layout.prop(snode_id, "use_nodes")
50
51         elif snode.tree_type == 'TEXTURE':
52             layout.prop(snode, "texture_type", text="", expand=True)
53
54             if id_from:
55                 if snode.texture_type == 'BRUSH':
56                     layout.template_ID(id_from, "texture", new="texture.new")
57                 else:
58                     layout.template_ID(id_from, "active_texture", new="texture.new")
59             if snode_id:
60                 layout.prop(snode_id, "use_nodes")
61
62         elif snode.tree_type == 'COMPOSITING':
63             layout.prop(snode_id, "use_nodes")
64             layout.prop(snode_id.render, "use_free_unused_nodes", text="Free Unused")
65             layout.prop(snode, "show_backdrop")
66             if snode.show_backdrop:
67                 row = layout.row(align=True)
68                 row.prop(snode, "backdrop_channels", text="", expand=True)
69             layout.prop(snode, "use_auto_render")
70
71         layout.separator()
72
73         layout.template_running_jobs()
74
75
76 class NODE_MT_view(Menu):
77     bl_label = "View"
78
79     def draw(self, context):
80         layout = self.layout
81
82         layout.operator("node.properties", icon='MENU_PANEL')
83         layout.separator()
84
85         layout.operator("view2d.zoom_in")
86         layout.operator("view2d.zoom_out")
87
88         layout.separator()
89
90         layout.operator("node.view_all")
91
92         if context.space_data.show_backdrop:
93             layout.separator()
94
95             layout.operator("node.backimage_move", text="Backdrop move")
96             layout.operator("node.backimage_zoom", text="Backdrop zoom in").factor = 1.2
97             layout.operator("node.backimage_zoom", text="Backdrop zoom out").factor = 0.833
98
99         layout.separator()
100
101         layout.operator("screen.area_dupli")
102         layout.operator("screen.screen_full_area")
103
104
105 class NODE_MT_select(Menu):
106     bl_label = "Select"
107
108     def draw(self, context):
109         layout = self.layout
110
111         layout.operator("node.select_border")
112
113         layout.separator()
114         layout.operator("node.select_all")
115         layout.operator("node.select_linked_from")
116         layout.operator("node.select_linked_to")
117         layout.operator("node.select_same_type")
118         layout.operator("node.select_same_type_next")
119         layout.operator("node.select_same_type_prev")
120
121
122 class NODE_MT_node(Menu):
123     bl_label = "Node"
124
125     def draw(self, context):
126         layout = self.layout
127
128         layout.operator("transform.translate")
129         layout.operator("transform.rotate")
130         layout.operator("transform.resize")
131
132         layout.separator()
133
134         layout.operator("node.duplicate_move")
135         layout.operator("node.delete")
136         layout.operator("node.delete_reconnect")
137
138         layout.separator()
139         layout.operator("node.link_make")
140         layout.operator("node.link_make", text="Make and Replace Links").replace = True
141         layout.operator("node.links_cut")
142
143         layout.separator()
144         layout.operator("node.group_edit")
145         layout.operator("node.group_ungroup")
146         layout.operator("node.group_make")
147
148         layout.separator()
149
150         layout.operator("node.hide_toggle")
151         layout.operator("node.mute_toggle")
152         layout.operator("node.preview_toggle")
153         layout.operator("node.hide_socket_toggle")
154
155         layout.separator()
156
157         layout.operator("node.show_cyclic_dependencies")
158         layout.operator("node.read_renderlayers")
159         layout.operator("node.read_fullsamplelayers")
160
161
162 # Node Backdrop options
163 class NODE_PT_properties(Panel):
164     bl_space_type = 'NODE_EDITOR'
165     bl_region_type = 'UI'
166     bl_label = "Backdrop"
167
168     @classmethod
169     def poll(cls, context):
170         snode = context.space_data
171         return snode.tree_type == 'COMPOSITING'
172
173     def draw_header(self, context):
174         snode = context.space_data
175         self.layout.prop(snode, "show_backdrop", text="")
176
177     def draw(self, context):
178         layout = self.layout
179
180         snode = context.space_data
181         layout.active = snode.show_backdrop
182         layout.prop(snode, "backdrop_channels", text="")
183         layout.prop(snode, "backdrop_zoom", text="Zoom")
184
185         col = layout.column(align=True)
186         col.label(text="Offset:")
187         col.prop(snode, "backdrop_x", text="X")
188         col.prop(snode, "backdrop_y", text="Y")
189         col.operator("node.backimage_move", text="Move")
190
191 if __name__ == "__main__":  # only for live edit.
192     bpy.utils.register_module(__name__)