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