tabs to spaces, remove trailing white space. (apart of pep8)
[blender-staging.git] / release / scripts / ui / space_image.py
1
2 import bpy
3
4 class IMAGE_MT_view(bpy.types.Menu):
5     bl_label = "View"
6
7     def draw(self, context):
8         layout = self.layout
9
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/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     bl_label = "Select"
47
48     def draw(self, context):
49         layout = self.layout
50
51         layout.itemO("uv.select_border")
52         layout.item_booleanO("uv.select_border", "pinned", True)
53
54         layout.itemS()
55
56         layout.itemO("uv.select_all_toggle")
57         layout.itemO("uv.select_inverse")
58         layout.itemO("uv.unlink_selection")
59
60         layout.itemS()
61
62         layout.itemO("uv.select_pinned")
63         layout.itemO("uv.select_linked")
64
65 class IMAGE_MT_image(bpy.types.Menu):
66     bl_label = "Image"
67
68     def draw(self, context):
69         layout = self.layout
70
71         sima = context.space_data
72         ima = sima.image
73
74         layout.itemO("image.new")
75         layout.itemO("image.open")
76
77         show_render = sima.show_render
78
79         if ima:
80             if not show_render:
81                 layout.itemO("image.replace")
82                 layout.itemO("image.reload")
83
84             layout.itemO("image.save")
85             layout.itemO("image.save_as")
86
87             if ima.source == 'SEQUENCE':
88                 layout.itemO("image.save_sequence")
89
90             if not show_render:
91                 layout.itemS()
92
93                 if ima.packed_file:
94                     layout.itemO("image.unpack")
95                 else:
96                     layout.itemO("image.pack")
97
98                 # only for dirty && specific image types, perhaps
99                 # this could be done in operator poll too
100                 if ima.dirty:
101                     if ima.source in ('FILE', 'GENERATED') and ima.type != 'MULTILAYER':
102                         layout.item_booleanO("image.pack", "as_png", True, text="Pack As PNG")
103
104             layout.itemS()
105
106             layout.itemR(sima, "image_painting")
107
108 class IMAGE_MT_uvs_showhide(bpy.types.Menu):
109     bl_label = "Show/Hide Faces"
110
111     def draw(self, context):
112         layout = self.layout
113
114         layout.itemO("uv.reveal")
115         layout.itemO("uv.hide")
116         layout.item_booleanO("uv.hide", "unselected", True)
117
118 class IMAGE_MT_uvs_transform(bpy.types.Menu):
119     bl_label = "Transform"
120
121     def draw(self, context):
122         layout = self.layout
123
124         layout.itemO("tfm.translate")
125         layout.itemO("tfm.rotate")
126         layout.itemO("tfm.resize")
127
128 class IMAGE_MT_uvs_mirror(bpy.types.Menu):
129     bl_label = "Mirror"
130
131     def draw(self, context):
132         layout = self.layout
133         layout.operator_context = "EXEC_REGION_WIN"
134
135         props= layout.itemO("tfm.mirror", text="X Axis", properties=True)
136         props.constraint_axis[0]= True
137
138         props= layout.itemO("tfm.mirror", text="Y Axis", properties=True)
139         props.constraint_axis[1]= True
140
141 class IMAGE_MT_uvs_weldalign(bpy.types.Menu):
142     bl_label = "Weld/Align"
143
144     def draw(self, context):
145         layout = self.layout
146
147         layout.itemO("uv.weld") # W, 1
148         layout.items_enumO("uv.align", "axis") # W, 2/3/4
149
150 class IMAGE_MT_uvs(bpy.types.Menu):
151     bl_label = "UVs"
152
153     def draw(self, context):
154         layout = self.layout
155
156         sima = context.space_data
157         uv = sima.uv_editor
158         settings = context.tool_settings
159
160         layout.itemR(uv, "snap_to_pixels")
161         layout.itemR(uv, "constrain_to_image_bounds")
162
163         layout.itemS()
164
165         layout.itemR(uv, "live_unwrap")
166         layout.itemO("uv.unwrap")
167         layout.item_booleanO("uv.pin", "clear", True, text="Unpin")
168         layout.itemO("uv.pin")
169
170         layout.itemS()
171
172         layout.itemO("uv.pack_islands")
173         layout.itemO("uv.average_islands_scale")
174         layout.itemO("uv.minimize_stretch")
175         layout.itemO("uv.stitch")
176
177         layout.itemS()
178
179         layout.itemM("IMAGE_MT_uvs_transform")
180         layout.itemM("IMAGE_MT_uvs_mirror")
181         layout.itemM("IMAGE_MT_uvs_weldalign")
182
183         layout.itemS()
184
185         layout.itemR(settings, "proportional_editing")
186         layout.item_menu_enumR(settings, "proportional_editing_falloff")
187
188         layout.itemS()
189
190         layout.itemM("IMAGE_MT_uvs_showhide")
191
192 class IMAGE_HT_header(bpy.types.Header):
193     bl_space_type = 'IMAGE_EDITOR'
194
195     def draw(self, context):
196         layout = self.layout
197
198         sima = context.space_data
199         ima = sima.image
200         iuser = sima.image_user
201         settings = context.tool_settings
202
203         show_render = sima.show_render
204         show_paint = sima.show_paint
205         show_uvedit = sima.show_uvedit
206
207         row = layout.row(align=True)
208         row.template_header()
209
210         # menus
211         if context.area.show_menus:
212             sub = row.row(align=True)
213             sub.itemM("IMAGE_MT_view")
214
215             if show_uvedit:
216                 sub.itemM("IMAGE_MT_select")
217
218             if ima and ima.dirty:
219                 sub.itemM("IMAGE_MT_image", text="Image*")
220             else:
221                 sub.itemM("IMAGE_MT_image", text="Image")
222
223             if show_uvedit:
224                 sub.itemM("IMAGE_MT_uvs")
225
226         layout.template_ID(sima, "image", new="image.new")
227
228         # uv editing
229         if show_uvedit:
230             uvedit = sima.uv_editor
231
232             layout.itemR(uvedit, "pivot", text="", icon_only=True)
233             layout.itemR(settings, "uv_sync_selection", text="")
234
235             if settings.uv_sync_selection:
236                 layout.itemR(settings, "mesh_selection_mode", text="", expand=True)
237             else:
238                 layout.itemR(settings, "uv_selection_mode", text="", expand=True)
239                 layout.itemR(uvedit, "sticky_selection_mode", text="", icon_only=True)
240             pass
241
242             row = layout.row(align=True)
243             row.itemR(settings, "snap", text="")
244             if settings.snap:
245                 row.itemR(settings, "snap_mode", text="")
246
247             """
248             mesh = context.edit_object.data
249             row.item_pointerR(mesh, "active_uv_layer", mesh, "uv_textures")
250             """
251
252         if ima:
253             # layers
254             layout.template_image_layers(ima, iuser)
255
256             # painting
257             layout.itemR(sima, "image_painting", text="")
258
259             # draw options
260             row = layout.row(align=True)
261             row.itemR(sima, "draw_channels", text="", expand=True)
262
263             row = layout.row(align=True)
264             if ima.type == 'COMPOSITE':
265                 row.itemO("image.record_composite", icon='ICON_REC')
266             if ima.type == 'COMPOSITE' and ima.source in ('MOVIE', 'SEQUENCE'):
267                 row.itemO("image.play_composite", icon='ICON_PLAY')
268
269         if show_uvedit or sima.image_painting:
270             layout.itemR(sima, "update_automatically", text="")
271
272 class IMAGE_PT_image_properties(bpy.types.Panel):
273     bl_space_type = 'IMAGE_EDITOR'
274     bl_region_type = 'UI'
275     bl_label = "Image"
276
277     def poll(self, context):
278         sima = context.space_data
279         return (sima.image)
280
281     def draw(self, context):
282         layout = self.layout
283
284         sima = context.space_data
285         ima = sima.image
286         iuser = sima.image_user
287
288         layout.template_image(sima, "image", iuser, compact=True)
289
290 class IMAGE_PT_game_properties(bpy.types.Panel):
291     bl_space_type = 'IMAGE_EDITOR'
292     bl_region_type = 'UI'
293     bl_label = "Game Properties"
294
295     def poll(self, context):
296         rd = context.scene.render_data
297         sima = context.space_data
298         return (sima and sima.image) and (rd.engine == 'BLENDER_GAME')
299
300     def draw(self, context):
301         layout = self.layout
302
303         sima = context.space_data
304         ima = sima.image
305
306         split = layout.split()
307
308         col = split.column()
309
310         sub = col.column(align=True)
311         sub.itemR(ima, "animated")
312
313         subsub = sub.column()
314         subsub.active = ima.animated
315         subsub.itemR(ima, "animation_start", text="Start")
316         subsub.itemR(ima, "animation_end", text="End")
317         subsub.itemR(ima, "animation_speed", text="Speed")
318
319         col.itemR(ima, "tiles")
320         sub = col.column(align=True)
321         sub.active = ima.tiles or ima.animated
322         sub.itemR(ima, "tiles_x", text="X")
323         sub.itemR(ima, "tiles_y", text="Y")
324
325         col = split.column()
326         col.itemL(text="Clamp:")
327         col.itemR(ima, "clamp_x", text="X")
328         col.itemR(ima, "clamp_y", text="Y")
329         col.itemS()
330         col.itemR(ima, "mapping", expand=True)
331
332
333
334 class IMAGE_PT_view_properties(bpy.types.Panel):
335     bl_space_type = 'IMAGE_EDITOR'
336     bl_region_type = 'UI'
337     bl_label = "Display"
338
339     def poll(self, context):
340         sima = context.space_data
341         return (sima and (sima.image or sima.show_uvedit))
342
343     def draw(self, context):
344         layout = self.layout
345
346         sima = context.space_data
347         ima = sima.image
348         show_uvedit = sima.show_uvedit
349         uvedit = sima.uv_editor
350
351         split = layout.split()
352
353         col = split.column()
354         if ima:
355             col.itemR(ima, "display_aspect", text="Aspect Ratio")
356
357             col = split.column()
358             col.itemL(text="Coordinates:")
359             col.itemR(sima, "draw_repeated", text="Repeat")
360             if show_uvedit:
361                 col.itemR(uvedit, "normalized_coordinates", text="Normalized")
362         elif show_uvedit:
363             col.itemL(text="Coordinates:")
364             col.itemR(uvedit, "normalized_coordinates", text="Normalized")
365
366         if show_uvedit:
367
368             col = layout.column()
369             col.itemL(text="UVs:")
370             row = col.row()
371             row.itemR(uvedit, "edge_draw_type", expand=True)
372
373             split = layout.split()
374
375             col = split.column()
376             col.itemR(uvedit, "draw_stretch", text="Stretch")
377             sub = col.column()
378             sub.active = uvedit.draw_stretch
379             sub.row().itemR(uvedit, "draw_stretch_type", expand=True)
380
381             col = split.column()
382             col.itemR(uvedit, "draw_smooth_edges", text="Smooth")
383             col.itemR(uvedit, "draw_modified_edges", text="Modified")
384             #col.itemR(uvedit, "draw_edges")
385             #col.itemR(uvedit, "draw_faces")
386
387 class IMAGE_PT_paint(bpy.types.Panel):
388     bl_space_type = 'IMAGE_EDITOR'
389     bl_region_type = 'UI'
390     bl_label = "Paint"
391
392     def poll(self, context):
393         sima = context.space_data
394         return sima.show_paint
395
396     def draw(self, context):
397         layout = self.layout
398
399         settings = context.tool_settings.image_paint
400         brush = settings.brush
401
402         col = layout.split().column()
403         row = col.row()
404         row.template_list(settings, "brushes", settings, "active_brush_index", rows=2)
405
406         col.template_ID(settings, "brush", new="brush.add")
407
408         row = layout.row(align=True)
409         row.item_enumR(settings, "tool", 'DRAW')
410         row.item_enumR(settings, "tool", 'SOFTEN')
411         row.item_enumR(settings, "tool", 'CLONE')
412         row.item_enumR(settings, "tool", 'SMEAR')
413
414         if brush:
415             col = layout.column()
416             col.itemR(brush, "color", text="")
417
418             row = col.row(align=True)
419             row.itemR(brush, "size", slider=True)
420             row.itemR(brush, "use_size_pressure", toggle=True, text="")
421
422             row = col.row(align=True)
423             row.itemR(brush, "strength", slider=True)
424             row.itemR(brush, "use_strength_pressure", toggle=True, text="")
425
426             row = col.row(align=True)
427             row.itemR(brush, "jitter", slider=True)
428             row.itemR(brush, "use_jitter_pressure", toggle=True, text="")
429
430             col.itemR(brush, "blend", text="Blend")
431
432 class IMAGE_PT_paint_stroke(bpy.types.Panel):
433     bl_space_type = 'IMAGE_EDITOR'
434     bl_region_type = 'UI'
435     bl_label = "Paint Stroke"
436     bl_default_closed = True
437
438     def poll(self, context):
439         sima = context.space_data
440         settings = context.tool_settings.image_paint
441         return sima.show_paint and settings.brush
442
443     def draw(self, context):
444         layout = self.layout
445
446         settings = context.tool_settings.image_paint
447         brush = settings.brush
448
449         layout.itemR(brush, "use_airbrush")
450         col = layout.column()
451         col.active = brush.use_airbrush
452         col.itemR(brush, "rate", slider=True)
453
454         layout.itemR(brush, "use_space")
455         row = layout.row(align=True)
456         row.active = brush.use_space
457         row.itemR(brush, "spacing", text="Distance", slider=True)
458         row.itemR(brush, "use_spacing_pressure", toggle=True, text="")
459
460 class IMAGE_PT_paint_curve(bpy.types.Panel):
461     bl_space_type = 'IMAGE_EDITOR'
462     bl_region_type = 'UI'
463     bl_label = "Paint Curve"
464     bl_default_closed = True
465
466     def poll(self, context):
467         sima = context.space_data
468         settings = context.tool_settings.image_paint
469         return sima.show_paint and settings.brush
470
471     def draw(self, context):
472         layout = self.layout
473
474         settings = context.tool_settings.image_paint
475         brush = settings.brush
476
477         layout.template_curve_mapping(brush, "curve")
478         layout.item_menu_enumO("brush.curve_preset", property="shape")
479
480 bpy.types.register(IMAGE_MT_view)
481 bpy.types.register(IMAGE_MT_select)
482 bpy.types.register(IMAGE_MT_image)
483 bpy.types.register(IMAGE_MT_uvs_showhide)
484 bpy.types.register(IMAGE_MT_uvs_transform)
485 bpy.types.register(IMAGE_MT_uvs_mirror)
486 bpy.types.register(IMAGE_MT_uvs_weldalign)
487 bpy.types.register(IMAGE_MT_uvs)
488 bpy.types.register(IMAGE_HT_header)
489 bpy.types.register(IMAGE_PT_image_properties)
490 bpy.types.register(IMAGE_PT_paint)
491 bpy.types.register(IMAGE_PT_paint_stroke)
492 bpy.types.register(IMAGE_PT_paint_curve)
493 bpy.types.register(IMAGE_PT_game_properties)
494 bpy.types.register(IMAGE_PT_view_properties)
495