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