Merge with -r 22620:23107.
[blender.git] / release / ui / space_image.py
1
2 import bpy
3
4 class IMAGE_MT_view(bpy.types.Menu):
5         __space_type__ = 'IMAGE_EDITOR'
6         __label__ = "View"
7
8         def draw(self, context):
9                 layout = self.layout
10                 
11                 sima = context.space_data
12                 uv = sima.uv_editor
13                 settings = context.tool_settings
14
15                 show_uvedit = sima.show_uvedit
16
17                 layout.itemO("image.properties", icon='ICON_MENU_PANEL')
18
19                 layout.itemS()
20
21                 layout.itemR(sima, "update_automatically")
22                 if show_uvedit:
23                         layout.itemR(settings, "uv_local_view") # Numpad /
24
25                 layout.itemS()
26
27                 layout.itemO("image.view_zoom_in")
28                 layout.itemO("image.view_zoom_out")
29
30                 layout.itemS()
31
32                 ratios = [[1, 8], [1, 4], [1, 2], [1, 1], [2, 1], [4, 1], [8, 1]];
33
34                 for a, b in ratios:
35                         text = "Zoom %d:%d" % (a, b)
36                         layout.item_floatO("image.view_zoom_ratio", "ratio", a/float(b), text=text)
37
38                 layout.itemS()
39
40                 if show_uvedit:
41                         layout.itemO("image.view_selected")
42
43                 layout.itemO("image.view_all")
44                 layout.itemO("screen.screen_full_area")
45
46 class IMAGE_MT_select(bpy.types.Menu):
47         __space_type__ = 'IMAGE_EDITOR'
48         __label__ = "Select"
49
50         def draw(self, context):
51                 layout = self.layout
52
53                 layout.itemO("uv.select_border")
54                 layout.item_booleanO("uv.select_border", "pinned", True)
55
56                 layout.itemS()
57                 
58                 layout.itemO("uv.select_all_toggle")
59                 layout.itemO("uv.select_inverse")
60                 layout.itemO("uv.unlink_selection")
61                 
62                 layout.itemS()
63
64                 layout.itemO("uv.select_pinned")
65                 layout.itemO("uv.select_linked")
66
67 class IMAGE_MT_image(bpy.types.Menu):
68         __space_type__ = 'IMAGE_EDITOR'
69         __label__ = "Image"
70
71         def draw(self, context):
72                 layout = self.layout
73
74                 sima = context.space_data
75                 ima = sima.image
76
77                 layout.itemO("image.new")
78                 layout.itemO("image.open")
79
80                 show_render = sima.show_render
81
82                 if ima:
83                         if not show_render:
84                                 layout.itemO("image.replace")
85                                 layout.itemO("image.reload")
86
87                         layout.itemO("image.save")
88                         layout.itemO("image.save_as")
89
90                         if ima.source == 'SEQUENCE':
91                                 layout.itemO("image.save_sequence")
92
93                         if not show_render:
94                                 layout.itemS()
95
96                                 if ima.packed_file:
97                                         layout.itemO("image.unpack")
98                                 else:
99                                         layout.itemO("image.pack")
100
101                                 # only for dirty && specific image types, perhaps
102                                 # this could be done in operator poll too
103                                 if ima.dirty:
104                                         if ima.source in ('FILE', 'GENERATED') and ima.type != 'MULTILAYER':
105                                                 layout.item_booleanO("image.pack", "as_png", True, text="Pack As PNG")
106
107                         layout.itemS()
108
109                         layout.itemR(sima, "image_painting")
110
111 class IMAGE_MT_uvs_showhide(bpy.types.Menu):
112         __space_type__ = 'IMAGE_EDITOR'
113         __label__ = "Show/Hide Faces"
114
115         def draw(self, context):
116                 layout = self.layout
117
118                 layout.itemO("uv.reveal")
119                 layout.itemO("uv.hide")
120                 layout.item_booleanO("uv.hide", "unselected", True)
121
122 class IMAGE_MT_uvs_transform(bpy.types.Menu):
123         __space_type__ = 'IMAGE_EDITOR'
124         __label__ = "Transform"
125
126         def draw(self, context):
127                 layout = self.layout
128
129                 layout.item_enumO("tfm.transform", "mode", 'TRANSLATION')
130                 layout.item_enumO("tfm.transform", "mode", 'ROTATION')
131                 layout.item_enumO("tfm.transform", "mode", 'RESIZE')
132
133 class IMAGE_MT_uvs_mirror(bpy.types.Menu):
134         __space_type__ = 'IMAGE_EDITOR'
135         __label__ = "Mirror"
136
137         def draw(self, context):
138                 layout = self.layout
139
140                 layout.item_enumO("uv.mirror", "axis", 'MIRROR_X') # "X Axis", M, 
141                 layout.item_enumO("uv.mirror", "axis", 'MIRROR_Y') # "Y Axis", M, 
142
143 class IMAGE_MT_uvs_weldalign(bpy.types.Menu):
144         __space_type__ = 'IMAGE_EDITOR'
145         __label__ = "Weld/Align"
146
147         def draw(self, context):
148                 layout = self.layout
149
150                 layout.itemO("uv.weld") # W, 1
151                 layout.items_enumO("uv.align", "axis") # W, 2/3/4
152
153 class IMAGE_MT_uvs(bpy.types.Menu):
154         __space_type__ = 'IMAGE_EDITOR'
155         __label__ = "UVs"
156
157         def draw(self, context):
158                 layout = self.layout
159                 
160                 sima = context.space_data
161                 uv = sima.uv_editor
162                 settings = context.tool_settings
163
164                 layout.itemR(uv, "snap_to_pixels")
165                 layout.itemR(uv, "constrain_to_image_bounds")
166
167                 layout.itemS()
168
169                 layout.itemR(uv, "live_unwrap")
170                 layout.itemO("uv.unwrap")
171                 layout.item_booleanO("uv.pin", "clear", True, text="Unpin")
172                 layout.itemO("uv.pin")
173
174                 layout.itemS()
175
176                 layout.itemO("uv.pack_islands")
177                 layout.itemO("uv.average_islands_scale")
178                 layout.itemO("uv.minimize_stretch")
179                 layout.itemO("uv.stitch")
180
181                 layout.itemS()
182
183                 layout.itemM("IMAGE_MT_uvs_transform")
184                 layout.itemM("IMAGE_MT_uvs_mirror")
185                 layout.itemM("IMAGE_MT_uvs_weldalign")
186
187                 layout.itemS()
188
189                 layout.itemR(settings, "proportional_editing")
190                 layout.item_menu_enumR(settings, "proportional_editing_falloff")
191
192                 layout.itemS()
193
194                 layout.itemM("IMAGE_MT_uvs_showhide")
195
196 class IMAGE_HT_header(bpy.types.Header):
197         __space_type__ = 'IMAGE_EDITOR'
198
199         def draw(self, context):
200                 layout = self.layout
201                 
202                 sima = context.space_data
203                 ima = sima.image
204                 iuser = sima.image_user
205                 settings = context.tool_settings
206
207                 show_render = sima.show_render
208                 show_paint = sima.show_paint
209                 show_uvedit = sima.show_uvedit
210
211                 row = layout.row(align=True)
212                 row.template_header()
213
214                 # menus
215                 if context.area.show_menus:
216                         sub = row.row(align=True)
217                         sub.itemM("IMAGE_MT_view")
218
219                         if show_uvedit:
220                                 sub.itemM("IMAGE_MT_select")
221
222                         if ima and ima.dirty:
223                                 sub.itemM("IMAGE_MT_image", text="Image*")
224                         else:
225                                 sub.itemM("IMAGE_MT_image", text="Image")
226
227                         if show_uvedit:
228                                 sub.itemM("IMAGE_MT_uvs")
229
230                 layout.template_ID(sima, "image", new="image.new")
231
232                 # uv editing
233                 if show_uvedit:
234                         uvedit = sima.uv_editor
235
236                         layout.itemR(uvedit, "pivot", text="")
237                         layout.itemR(settings, "uv_sync_selection", text="")
238
239                         if settings.uv_sync_selection:
240                                 layout.itemR(settings, "mesh_selection_mode", text="", expand=True)
241                         else:
242                                 layout.itemR(settings, "uv_selection_mode", text="", expand=True)
243                                 layout.itemR(uvedit, "sticky_selection_mode", text="")
244                         pass
245
246                         row = layout.row(align=True)
247                         row.itemR(settings, "snap", text="")
248                         if settings.snap:
249                                 row.itemR(settings, "snap_mode", text="")
250
251                         """
252                         mesh = context.edit_object.data
253                         row.item_pointerR(mesh, "active_uv_layer", mesh, "uv_textures")
254                         """
255
256                 if ima:
257                         # layers
258                         layout.template_image_layers(ima, iuser)
259
260                         # painting
261                         layout.itemR(sima, "image_painting", text="")
262
263                         # draw options
264                         row = layout.row(align=True)
265                         row.itemR(sima, "draw_channels", text="", expand=True)
266
267                         row = layout.row(align=True)
268                         if ima.type == 'COMPOSITE':
269                                 row.itemO("image.record_composite", icon='ICON_REC')
270                         if ima.type == 'COMPOSITE' and ima.source in ('MOVIE', 'SEQUENCE'):
271                                 row.itemO("image.play_composite", icon='ICON_PLAY')
272                 
273                 if show_uvedit or sima.image_painting:
274                         layout.itemR(sima, "update_automatically", text="")
275
276 class IMAGE_PT_game_properties(bpy.types.Panel):
277         __space_type__ = 'IMAGE_EDITOR'
278         __region_type__ = 'UI'
279         __label__ = "Game Properties"
280
281         def poll(self, context):
282                 rd = context.scene.render_data
283                 sima = context.space_data
284                 return (sima and sima.image) and (rd.engine == 'BLENDER_GAME')
285
286         def draw(self, context):
287                 layout = self.layout
288                 
289                 sima = context.space_data
290                 ima = sima.image
291
292                 split = layout.split()
293
294                 col = split.column()
295                 col.itemR(ima, "clamp_x")
296                 col.itemR(ima, "clamp_y")
297                 col.itemR(ima, "mapping", expand=True)
298                 col.itemR(ima, "tiles")
299
300                 col = split.column()
301
302                 sub = col.column(align=True)
303                 sub.itemR(ima, "animated")
304
305                 subsub = sub.column()
306                 subsub.active = ima.animated
307                 subsub.itemR(ima, "animation_start", text="Start")
308                 subsub.itemR(ima, "animation_end", text="End")
309                 subsub.itemR(ima, "animation_speed", text="Speed")
310
311                 sub = col.row(align=True)
312                 sub.active = ima.tiles or ima.animated
313                 sub.itemR(ima, "tiles_x", text="X")
314                 sub.itemR(ima, "tiles_y", text="Y")
315
316 class IMAGE_PT_view_properties(bpy.types.Panel):
317         __space_type__ = 'IMAGE_EDITOR'
318         __region_type__ = 'UI'
319         __label__ = "Display"
320
321         def poll(self, context):
322                 sima = context.space_data
323                 return (sima and (sima.image or sima.show_uvedit))
324
325         def draw(self, context):
326                 layout = self.layout
327                 
328                 sima = context.space_data
329                 ima = sima.image
330                 show_uvedit = sima.show_uvedit
331                 uvedit = sima.uv_editor
332
333                 split = layout.split()
334
335                 col = split.column()
336                 if ima:
337                         col.itemR(ima, "display_aspect", text="Aspect Ratio")
338
339                         col = split.column()
340                         col.itemL(text="Coordinates:")
341                         col.itemR(sima, "draw_repeated", text="Repeat")
342                         if show_uvedit:
343                                 col.itemR(uvedit, "normalized_coordinates", text="Normalized")
344                 elif show_uvedit:
345                         col.itemL(text="Coordinates:")
346                         col.itemR(uvedit, "normalized_coordinates", text="Normalized")
347
348                 if show_uvedit:
349                         col = layout.column()
350                         row = col.row()
351                         row.itemR(uvedit, "edge_draw_type", expand=True)
352                         
353                         split = layout.split()
354
355                         col = split.column()
356                         col.itemR(uvedit, "draw_stretch", text="Stretch")
357                         sub = col.column()
358                         sub.active = uvedit.draw_stretch
359                         sub.row().itemR(uvedit, "draw_stretch_type", expand=True)
360                         
361                         col = split.column()
362                         col.itemR(uvedit, "draw_smooth_edges", text="Smooth")
363                         col.itemR(uvedit, "draw_modified_edges", text="Modified")
364                         #col.itemR(uvedit, "draw_edges")
365                         #col.itemR(uvedit, "draw_faces")
366
367 bpy.types.register(IMAGE_MT_view)
368 bpy.types.register(IMAGE_MT_select)
369 bpy.types.register(IMAGE_MT_image)
370 bpy.types.register(IMAGE_MT_uvs_showhide)
371 bpy.types.register(IMAGE_MT_uvs_transform)
372 bpy.types.register(IMAGE_MT_uvs_mirror)
373 bpy.types.register(IMAGE_MT_uvs_weldalign)
374 bpy.types.register(IMAGE_MT_uvs)
375 bpy.types.register(IMAGE_HT_header)
376 bpy.types.register(IMAGE_PT_game_properties)
377 bpy.types.register(IMAGE_PT_view_properties)