merge with trunk r39216
[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 blf import gettext as _
22
23
24 class NODE_HT_header(bpy.types.Header):
25     bl_space_type = 'NODE_EDITOR'
26
27     def draw(self, context):
28         layout = self.layout
29
30         snode = context.space_data
31
32         row = layout.row(align=True)
33         row.template_header()
34
35         if context.area.show_menus:
36             sub = row.row(align=True)
37             sub.menu("NODE_MT_view")
38             sub.menu("NODE_MT_select")
39             sub.menu("NODE_MT_add")
40             sub.menu("NODE_MT_node")
41
42         row = layout.row()
43         row.prop(snode, "tree_type", text="", expand=True)
44
45         if snode.tree_type == 'MATERIAL':
46             ob = snode.id_from
47             snode_id = snode.id
48             if ob:
49                 layout.template_ID(ob, "active_material", new="material.new")
50             if snode_id:
51                 layout.prop(snode_id, "use_nodes")
52
53         elif snode.tree_type == 'TEXTURE':
54             row.prop(snode, "texture_type", text="", expand=True)
55
56             snode_id = snode.id
57             id_from = snode.id_from
58             if id_from:
59                 if snode.texture_type == 'BRUSH':
60                     layout.template_ID(id_from, "texture", new="texture.new")
61                 else:
62                     layout.template_ID(id_from, "active_texture", new="texture.new")
63             if snode_id:
64                 layout.prop(snode_id, "use_nodes")
65
66         elif snode.tree_type == 'COMPOSITING':
67             scene = snode.id
68
69             layout.prop(scene, "use_nodes")
70             layout.prop(scene.render, "use_free_unused_nodes", text=_("Free Unused"))
71             layout.prop(snode, "show_backdrop")
72             if snode.show_backdrop:
73                 row = layout.row(align=True)
74                 row.prop(snode, "backdrop_channels", text="", expand=True)
75             layout.prop(snode, "use_auto_render")
76
77         layout.separator()
78
79         layout.template_running_jobs()
80
81
82 class NODE_MT_view(bpy.types.Menu):
83     bl_label = _("View")
84
85     def draw(self, context):
86         layout = self.layout
87
88         layout.operator("node.properties", icon='MENU_PANEL')
89         layout.separator()
90
91         layout.operator("view2d.zoom_in")
92         layout.operator("view2d.zoom_out")
93
94         layout.separator()
95
96         layout.operator("node.view_all")
97
98         if context.space_data.show_backdrop:
99             layout.separator()
100
101             layout.operator("node.backimage_move", text=_("Backdrop move"))
102             layout.operator("node.backimage_zoom", text=_("Backdrop zoom in")).factor = 1.2
103             layout.operator("node.backimage_zoom", text=_("Backdrop zoom out")).factor = 0.833
104
105         layout.separator()
106
107         layout.operator("screen.area_dupli")
108         layout.operator("screen.screen_full_area")
109
110
111 class NODE_MT_select(bpy.types.Menu):
112     bl_label = _("Select")
113
114     def draw(self, context):
115         layout = self.layout
116
117         layout.operator("node.select_border")
118
119         layout.separator()
120         layout.operator("node.select_all")
121         layout.operator("node.select_linked_from")
122         layout.operator("node.select_linked_to")
123         layout.operator("node.select_same_type")
124         layout.operator("node.select_same_type_next")
125         layout.operator("node.select_same_type_prev")
126
127
128 class NODE_MT_node(bpy.types.Menu):
129     bl_label = _("Node")
130
131     def draw(self, context):
132         layout = self.layout
133
134         layout.operator("transform.translate")
135         layout.operator("transform.rotate")
136         layout.operator("transform.resize")
137
138         layout.separator()
139
140         layout.operator("node.duplicate_move")
141         layout.operator("node.delete")
142         layout.operator("node.delete_reconnect")
143
144         layout.separator()
145         layout.operator("node.link_make")
146         layout.operator("node.link_make", text=_("Make and Replace Links")).replace = True
147         layout.operator("node.links_cut")
148
149         layout.separator()
150         layout.operator("node.group_edit")
151         layout.operator("node.group_ungroup")
152         layout.operator("node.group_make")
153
154         layout.separator()
155
156         layout.operator("node.hide_toggle")
157         layout.operator("node.mute_toggle")
158         layout.operator("node.preview_toggle")
159         layout.operator("node.hide_socket_toggle")
160
161         layout.separator()
162
163         layout.operator("node.show_cyclic_dependencies")
164         layout.operator("node.read_renderlayers")
165         layout.operator("node.read_fullsamplelayers")
166
167
168 # Node Backdrop options
169 class NODE_PT_properties(bpy.types.Panel):
170     bl_space_type = 'NODE_EDITOR'
171     bl_region_type = 'UI'
172     bl_label = _("Backdrop")
173
174     @classmethod
175     def poll(cls, context):
176         snode = context.space_data
177         return snode.tree_type == 'COMPOSITING'
178
179     def draw_header(self, context):
180         snode = context.space_data
181         self.layout.prop(snode, "show_backdrop", text="")
182
183     def draw(self, context):
184         layout = self.layout
185
186         snode = context.space_data
187         layout.active = snode.show_backdrop
188         layout.prop(snode, "backdrop_channels", text="")
189         layout.prop(snode, "backdrop_zoom", text=_("Zoom"))
190
191         col = layout.column(align=True)
192         col.label(text=_("Offset:"))
193         col.prop(snode, "backdrop_x", text="X")
194         col.prop(snode, "backdrop_y", text="Y")
195         col.operator("node.backimage_move", text=_("Move"))
196
197 if __name__ == "__main__":  # only for live edit.
198     bpy.utils.register_module(__name__)