Cycles:
[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 from blf import gettext as _
23
24
25 class NODE_HT_header(Header):
26     bl_space_type = 'NODE_EDITOR'
27
28     def draw(self, context):
29         layout = self.layout
30
31         snode = context.space_data
32         snode_id = snode.id
33         id_from = snode.id_from
34
35         row = layout.row(align=True)
36         row.template_header()
37
38         if context.area.show_menus:
39             row.menu("NODE_MT_view")
40             row.menu("NODE_MT_select")
41             row.menu("NODE_MT_add")
42             row.menu("NODE_MT_node")
43
44         layout.prop(snode, "tree_type", text="", expand=True)
45
46         if snode.tree_type == 'SHADER':
47             row.prop(snode, "shader_type", text="", expand=True)
48
49             if snode.shader_type == 'OBJECT':
50                 if id_from:
51                     layout.template_ID(id_from, "active_material", new="material.new")
52                 if snode_id:
53                     layout.prop(snode_id, "use_nodes")
54
55         elif snode.tree_type == 'TEXTURE':
56             layout.prop(snode, "texture_type", text="", expand=True)
57
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             layout.prop(snode_id, "use_nodes")
68             layout.prop(snode_id.render, "use_free_unused_nodes", text=_("Free Unused"))
69             layout.prop(snode, "show_backdrop")
70             if snode.show_backdrop:
71                 row = layout.row(align=True)
72                 row.prop(snode, "backdrop_channels", text="", expand=True)
73             layout.prop(snode, "use_auto_render")
74
75         layout.separator()
76
77         layout.template_running_jobs()
78
79
80 class NODE_MT_view(Menu):
81     bl_label = "View"
82
83     def draw(self, context):
84         layout = self.layout
85
86         layout.operator("node.properties", icon='MENU_PANEL')
87         layout.separator()
88
89         layout.operator("view2d.zoom_in")
90         layout.operator("view2d.zoom_out")
91
92         layout.separator()
93
94         layout.operator("node.view_all")
95
96         if context.space_data.show_backdrop:
97             layout.separator()
98
99             layout.operator("node.backimage_move", text=_("Backdrop move"))
100             layout.operator("node.backimage_zoom", text=_("Backdrop zoom in")).factor = 1.2
101             layout.operator("node.backimage_zoom", text=_("Backdrop zoom out")).factor = 0.833
102
103         layout.separator()
104
105         layout.operator("screen.area_dupli")
106         layout.operator("screen.screen_full_area")
107
108
109 class NODE_MT_select(Menu):
110     bl_label = "Select"
111
112     def draw(self, context):
113         layout = self.layout
114
115         layout.operator("node.select_border")
116
117         layout.separator()
118         layout.operator("node.select_all")
119         layout.operator("node.select_linked_from")
120         layout.operator("node.select_linked_to")
121         layout.operator("node.select_same_type")
122         layout.operator("node.select_same_type_next")
123         layout.operator("node.select_same_type_prev")
124
125
126 class NODE_MT_node(Menu):
127     bl_label = "Node"
128
129     def draw(self, context):
130         layout = self.layout
131
132         layout.operator("transform.translate")
133         layout.operator("transform.rotate")
134         layout.operator("transform.resize")
135
136         layout.separator()
137
138         layout.operator("node.duplicate_move")
139         layout.operator("node.delete")
140         layout.operator("node.delete_reconnect")
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(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__)