Audaspace Py API documentation fixes.
[blender.git] / release / scripts / ui / space_image.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 narrowui = bpy.context.user_preferences.view.properties_width_check
23
24
25 class IMAGE_MT_view(bpy.types.Menu):
26     bl_label = "View"
27
28     def draw(self, context):
29         layout = self.layout
30
31         sima = context.space_data
32         uv = sima.uv_editor
33         toolsettings = context.tool_settings
34
35         show_uvedit = sima.show_uvedit
36
37         layout.operator("image.properties", icon='MENU_PANEL')
38         layout.operator("image.scopes", icon='MENU_PANEL')
39
40         layout.separator()
41
42         layout.prop(sima, "update_automatically")
43         if show_uvedit:
44             layout.prop(toolsettings, "uv_local_view") # Numpad /
45             layout.prop(uv, "draw_other_objects")
46
47         layout.separator()
48
49         layout.operator("image.view_zoom_in")
50         layout.operator("image.view_zoom_out")
51
52         layout.separator()
53
54         ratios = [[1, 8], [1, 4], [1, 2], [1, 1], [2, 1], [4, 1], [8, 1]]
55
56         for a, b in ratios:
57             text = "Zoom %d:%d" % (a, b)
58             layout.operator("image.view_zoom_ratio", text=text).ratio = a / b
59
60         layout.separator()
61
62         if show_uvedit:
63             layout.operator("image.view_selected")
64
65         layout.operator("image.view_all")
66
67         layout.separator()
68
69         layout.operator("screen.area_dupli")
70         layout.operator("screen.screen_full_area")
71
72
73 class IMAGE_MT_select(bpy.types.Menu):
74     bl_label = "Select"
75
76     def draw(self, context):
77         layout = self.layout
78
79         layout.operator("uv.select_border")
80         layout.operator("uv.select_border").pinned = True
81
82         layout.separator()
83
84         layout.operator("uv.select_all")
85         layout.operator("uv.select_inverse")
86         layout.operator("uv.unlink_selection")
87
88         layout.separator()
89
90         layout.operator("uv.select_pinned")
91         layout.operator("uv.select_linked")
92
93
94 class IMAGE_MT_image(bpy.types.Menu):
95     bl_label = "Image"
96
97     def draw(self, context):
98         layout = self.layout
99
100         sima = context.space_data
101         ima = sima.image
102
103         layout.operator("image.new")
104         layout.operator("image.open")
105
106         show_render = sima.show_render
107
108         if ima:
109             if not show_render:
110                 layout.operator("image.replace")
111                 layout.operator("image.reload")
112
113             layout.operator("image.save")
114             layout.operator("image.save_as")
115             layout.operator("image.save_as", text="Save a Copy").copy = True
116
117             if ima.source == 'SEQUENCE':
118                 layout.operator("image.save_sequence")
119
120             layout.operator("image.external_edit", "Edit Externally")
121
122             if not show_render:
123                 layout.separator()
124
125                 if ima.packed_file:
126                     layout.operator("image.unpack")
127                 else:
128                     layout.operator("image.pack")
129
130                 # only for dirty && specific image types, perhaps
131                 # this could be done in operator poll too
132                 if ima.dirty:
133                     if ima.source in ('FILE', 'GENERATED') and ima.type != 'MULTILAYER':
134                         layout.operator("image.pack", text="Pack As PNG").as_png = True
135
136             layout.separator()
137
138             layout.prop(sima, "image_painting")
139
140
141 class IMAGE_MT_uvs_showhide(bpy.types.Menu):
142     bl_label = "Show/Hide Faces"
143
144     def draw(self, context):
145         layout = self.layout
146
147         layout.operator("uv.reveal")
148         layout.operator("uv.hide", text="Hide Selected")
149         layout.operator("uv.hide", text="Hide Unselected").unselected = True
150
151
152 class IMAGE_MT_uvs_transform(bpy.types.Menu):
153     bl_label = "Transform"
154
155     def draw(self, context):
156         layout = self.layout
157
158         layout.operator("transform.translate")
159         layout.operator("transform.rotate")
160         layout.operator("transform.resize")
161
162
163 class IMAGE_MT_uvs_snap(bpy.types.Menu):
164     bl_label = "Snap"
165
166     def draw(self, context):
167         layout = self.layout
168         layout.operator_context = 'EXEC_REGION_WIN'
169
170         layout.operator("uv.snap_selection", text="Selected to Pixels").target = 'PIXELS'
171         layout.operator("uv.snap_selection", text="Selected to Cursor").target = 'CURSOR'
172         layout.operator("uv.snap_selection", text="Selected to Adjacent Unselected").target = 'ADJACENT_UNSELECTED'
173
174         layout.separator()
175
176         layout.operator("uv.snap_cursor", text="Cursor to Pixels").target = 'PIXELS'
177         layout.operator("uv.snap_cursor", text="Cursor to Selection").target = 'SELECTION'
178
179
180 class IMAGE_MT_uvs_mirror(bpy.types.Menu):
181     bl_label = "Mirror"
182
183     def draw(self, context):
184         layout = self.layout
185         layout.operator_context = 'EXEC_REGION_WIN'
186
187         layout.operator("transform.mirror", text="X Axis").constraint_axis[0] = True
188         layout.operator("transform.mirror", text="Y Axis").constraint_axis[1] = True
189
190
191 class IMAGE_MT_uvs_weldalign(bpy.types.Menu):
192     bl_label = "Weld/Align"
193
194     def draw(self, context):
195         layout = self.layout
196
197         layout.operator("uv.weld") # W, 1
198         layout.operator_enums("uv.align", "axis") # W, 2/3/4
199
200
201 class IMAGE_MT_uvs(bpy.types.Menu):
202     bl_label = "UVs"
203
204     def draw(self, context):
205         layout = self.layout
206
207         sima = context.space_data
208         uv = sima.uv_editor
209         toolsettings = context.tool_settings
210
211         layout.prop(uv, "snap_to_pixels")
212         layout.prop(uv, "constrain_to_image_bounds")
213
214         layout.separator()
215
216         layout.prop(uv, "live_unwrap")
217         layout.operator("uv.unwrap")
218         layout.operator("uv.pin", text="Unpin").clear = True
219         layout.operator("uv.pin")
220
221         layout.separator()
222
223         layout.operator("uv.pack_islands")
224         layout.operator("uv.average_islands_scale")
225         layout.operator("uv.minimize_stretch")
226         layout.operator("uv.stitch")
227         layout.operator("mesh.faces_miror_uv")
228
229         layout.separator()
230
231         layout.menu("IMAGE_MT_uvs_transform")
232         layout.menu("IMAGE_MT_uvs_mirror")
233         layout.menu("IMAGE_MT_uvs_snap")
234         layout.menu("IMAGE_MT_uvs_weldalign")
235
236         layout.separator()
237
238         layout.prop_menu_enum(toolsettings, "proportional_editing")
239         layout.prop_menu_enum(toolsettings, "proportional_editing_falloff")
240
241         layout.separator()
242
243         layout.menu("IMAGE_MT_uvs_showhide")
244
245
246 class IMAGE_HT_header(bpy.types.Header):
247     bl_space_type = 'IMAGE_EDITOR'
248
249     def draw(self, context):
250         layout = self.layout
251
252         sima = context.space_data
253         ima = sima.image
254         iuser = sima.image_user
255         toolsettings = context.tool_settings
256
257         show_render = sima.show_render
258         # show_paint = sima.show_paint
259         show_uvedit = sima.show_uvedit
260
261         row = layout.row(align=True)
262         row.template_header()
263
264         # menus
265         if context.area.show_menus:
266             sub = row.row(align=True)
267             sub.menu("IMAGE_MT_view")
268
269             if show_uvedit:
270                 sub.menu("IMAGE_MT_select")
271
272             if ima and ima.dirty:
273                 sub.menu("IMAGE_MT_image", text="Image*")
274             else:
275                 sub.menu("IMAGE_MT_image", text="Image")
276
277             if show_uvedit:
278                 sub.menu("IMAGE_MT_uvs")
279
280         layout.template_ID(sima, "image", new="image.new")
281         if not show_render:
282             layout.prop(sima, "image_pin", text="")
283
284         # uv editing
285         if show_uvedit:
286             uvedit = sima.uv_editor
287
288             layout.prop(uvedit, "pivot", text="", icon_only=True)
289             layout.prop(toolsettings, "uv_sync_selection", text="")
290
291             if toolsettings.uv_sync_selection:
292                 row = layout.row(align=True)
293                 row.prop(toolsettings, "mesh_selection_mode", text="", index=0, icon='VERTEXSEL')
294                 row.prop(toolsettings, "mesh_selection_mode", text="", index=1, icon='EDGESEL')
295                 row.prop(toolsettings, "mesh_selection_mode", text="", index=2, icon='FACESEL')
296             else:
297                 layout.prop(toolsettings, "uv_selection_mode", text="", expand=True)
298                 layout.prop(uvedit, "sticky_selection_mode", text="", icon_only=True)
299
300             row = layout.row(align=True)
301             row.prop(toolsettings, "proportional_editing", text="", icon_only=True)
302             if toolsettings.proportional_editing != 'DISABLED':
303                 row.prop(toolsettings, "proportional_editing_falloff", text="", icon_only=True)
304
305             row = layout.row(align=True)
306             row.prop(toolsettings, "snap", text="")
307             row.prop(toolsettings, "snap_element", text="", icon_only=True)
308
309             # mesh = context.edit_object.data
310             # row.prop_object(mesh, "active_uv_layer", mesh, "uv_textures")
311
312         if ima:
313             # layers
314             layout.template_image_layers(ima, iuser)
315
316             # painting
317             layout.prop(sima, "image_painting", text="")
318
319             # draw options
320             row = layout.row(align=True)
321             row.prop(sima, "draw_channels", text="", expand=True)
322
323             row = layout.row(align=True)
324             if ima.type == 'COMPOSITE':
325                 row.operator("image.record_composite", icon='REC')
326             if ima.type == 'COMPOSITE' and ima.source in ('MOVIE', 'SEQUENCE'):
327                 row.operator("image.play_composite", icon='PLAY')
328
329         if show_uvedit or sima.image_painting:
330             layout.prop(sima, "update_automatically", text="", icon_only=True, icon='LOCKED')
331
332
333 class IMAGE_PT_image_properties(bpy.types.Panel):
334     bl_space_type = 'IMAGE_EDITOR'
335     bl_region_type = 'UI'
336     bl_label = "Image"
337
338     def poll(self, context):
339         sima = context.space_data
340         return (sima.image)
341
342     def draw(self, context):
343         layout = self.layout
344
345         sima = context.space_data
346         # ima = sima.image
347         iuser = sima.image_user
348
349         layout.template_image(sima, "image", iuser)
350
351
352 class IMAGE_PT_game_properties(bpy.types.Panel):
353     bl_space_type = 'IMAGE_EDITOR'
354     bl_region_type = 'UI'
355     bl_label = "Game Properties"
356
357     def poll(self, context):
358         rd = context.scene.render
359         sima = context.space_data
360         return (sima and sima.image) and (rd.engine == 'BLENDER_GAME')
361
362     def draw(self, context):
363         layout = self.layout
364
365         sima = context.space_data
366         ima = sima.image
367         wide_ui = context.region.width > narrowui
368
369         split = layout.split()
370
371         col = split.column()
372
373         sub = col.column(align=True)
374         sub.prop(ima, "animated")
375
376         subsub = sub.column()
377         subsub.active = ima.animated
378         subsub.prop(ima, "animation_start", text="Start")
379         subsub.prop(ima, "animation_end", text="End")
380         subsub.prop(ima, "animation_speed", text="Speed")
381
382         col.prop(ima, "tiles")
383         sub = col.column(align=True)
384         sub.active = ima.tiles or ima.animated
385         sub.prop(ima, "tiles_x", text="X")
386         sub.prop(ima, "tiles_y", text="Y")
387
388         if wide_ui:
389             col = split.column()
390         col.label(text="Clamp:")
391         col.prop(ima, "clamp_x", text="X")
392         col.prop(ima, "clamp_y", text="Y")
393         col.separator()
394         col.prop(ima, "mapping", expand=True)
395
396
397 class IMAGE_PT_view_histogram(bpy.types.Panel):
398     bl_space_type = 'IMAGE_EDITOR'
399     bl_region_type = 'PREVIEW'
400     bl_label = "Histogram"
401
402     def poll(self, context):
403         sima = context.space_data
404         return (sima and sima.image)
405
406     def draw(self, context):
407         layout = self.layout
408
409         sima = context.space_data
410
411         layout.template_histogram(sima.scopes, "histogram")
412         layout.prop(sima.scopes.histogram, "mode", icon_only=True)
413
414
415 class IMAGE_PT_view_waveform(bpy.types.Panel):
416     bl_space_type = 'IMAGE_EDITOR'
417     bl_region_type = 'PREVIEW'
418     bl_label = "Waveform"
419
420     def poll(self, context):
421         sima = context.space_data
422         return (sima and sima.image)
423
424     def draw(self, context):
425         layout = self.layout
426
427         sima = context.space_data
428         layout.template_waveform(sima, "scopes")
429         sub = layout.row().split(percentage=0.75)
430         sub.prop(sima.scopes, "waveform_alpha")
431         sub.prop(sima.scopes, "waveform_mode", text="", icon_only=True)
432
433
434 class IMAGE_PT_view_vectorscope(bpy.types.Panel):
435     bl_space_type = 'IMAGE_EDITOR'
436     bl_region_type = 'PREVIEW'
437     bl_label = "Vectorscope"
438
439     def poll(self, context):
440         sima = context.space_data
441         return (sima and sima.image)
442
443     def draw(self, context):
444         layout = self.layout
445
446         sima = context.space_data
447         layout.template_vectorscope(sima, "scopes")
448         layout.prop(sima.scopes, "vectorscope_alpha")
449
450
451 class IMAGE_PT_sample_line(bpy.types.Panel):
452     bl_space_type = 'IMAGE_EDITOR'
453     bl_region_type = 'PREVIEW'
454     bl_label = "Sample Line"
455
456     def poll(self, context):
457         sima = context.space_data
458         return (sima and sima.image)
459
460     def draw(self, context):
461         layout = self.layout
462         layout.operator("image.sample_line")
463         sima = context.space_data
464         layout.template_histogram(sima, "sample_histogram")
465         layout.prop(sima.sample_histogram, "mode")
466
467
468 class IMAGE_PT_scope_sample(bpy.types.Panel):
469     bl_space_type = 'IMAGE_EDITOR'
470     bl_region_type = 'PREVIEW'
471     bl_label = "Scope Samples"
472
473     def poll(self, context):
474         sima = context.space_data
475         return sima
476
477     def draw(self, context):
478         layout = self.layout
479         sima = context.space_data
480         split = layout.split()
481         row = split.row()
482         row.prop(sima.scopes, "use_full_resolution")
483         row = split.row()
484         row.active = not sima.scopes.use_full_resolution
485         row.prop(sima.scopes, "accuracy")
486
487
488 class IMAGE_PT_view_properties(bpy.types.Panel):
489     bl_space_type = 'IMAGE_EDITOR'
490     bl_region_type = 'UI'
491     bl_label = "Display"
492
493     def poll(self, context):
494         sima = context.space_data
495         return (sima and (sima.image or sima.show_uvedit))
496
497     def draw(self, context):
498         layout = self.layout
499
500         sima = context.space_data
501         ima = sima.image
502         show_uvedit = sima.show_uvedit
503         uvedit = sima.uv_editor
504         wide_ui = context.region.width > narrowui
505
506         split = layout.split()
507
508         col = split.column()
509         if ima:
510             col.prop(ima, "display_aspect", text="Aspect Ratio")
511
512             if wide_ui:
513                 col = split.column()
514             col.label(text="Coordinates:")
515             col.prop(sima, "draw_repeated", text="Repeat")
516             if show_uvedit:
517                 col.prop(uvedit, "normalized_coordinates", text="Normalized")
518
519         elif show_uvedit:
520             col.label(text="Coordinates:")
521             col.prop(uvedit, "normalized_coordinates", text="Normalized")
522
523         if show_uvedit:
524
525             col = layout.column()
526             col.prop(uvedit, "cursor_location")
527
528             col = layout.column()
529             col.label(text="UVs:")
530             row = col.row()
531             if wide_ui:
532                 row.prop(uvedit, "edge_draw_type", expand=True)
533             else:
534                 row.prop(uvedit, "edge_draw_type", text="")
535
536             split = layout.split()
537             col = split.column()
538             col.prop(uvedit, "draw_smooth_edges", text="Smooth")
539             col.prop(uvedit, "draw_modified_edges", text="Modified")
540             #col.prop(uvedit, "draw_edges")
541             #col.prop(uvedit, "draw_faces")
542
543             if wide_ui:
544                 col = split.column()
545             col.prop(uvedit, "draw_stretch", text="Stretch")
546             sub = col.column()
547             sub.active = uvedit.draw_stretch
548             sub.row().prop(uvedit, "draw_stretch_type", expand=True)
549
550
551 class IMAGE_PT_paint(bpy.types.Panel):
552     bl_space_type = 'IMAGE_EDITOR'
553     bl_region_type = 'UI'
554     bl_label = "Paint"
555
556     def poll(self, context):
557         sima = context.space_data
558         return sima.show_paint
559
560     def draw(self, context):
561         layout = self.layout
562
563         toolsettings = context.tool_settings.image_paint
564         brush = toolsettings.brush
565         wide_ui = context.region.width > narrowui
566
567         col = layout.split().column()
568         row = col.row()
569         row.template_list(toolsettings, "brushes", toolsettings, "active_brush_index", rows=2)
570
571         col.template_ID(toolsettings, "brush", new="brush.add")
572
573         if wide_ui:
574             sub = layout.row(align=True)
575         else:
576             sub = layout.column(align=True)
577         sub.prop_enum(brush, "imagepaint_tool", 'DRAW')
578         sub.prop_enum(brush, "imagepaint_tool", 'SOFTEN')
579         sub.prop_enum(brush, "imagepaint_tool", 'CLONE')
580         sub.prop_enum(brush, "imagepaint_tool", 'SMEAR')
581
582         if brush:
583             col = layout.column()
584             col.template_color_wheel(brush, "color", value_slider=True)
585             col.prop(brush, "color", text="")
586
587             row = col.row(align=True)
588             row.prop(brush, "size", slider=True)
589             row.prop(brush, "use_size_pressure", toggle=True, text="")
590
591             row = col.row(align=True)
592             row.prop(brush, "strength", slider=True)
593             row.prop(brush, "use_strength_pressure", toggle=True, text="")
594
595             row = col.row(align=True)
596             row.prop(brush, "jitter", slider=True)
597             row.prop(brush, "use_jitter_pressure", toggle=True, text="")
598
599             col.prop(brush, "blend", text="Blend")
600
601             if brush.imagepaint_tool == 'CLONE':
602                 col.separator()
603                 col.prop(brush, "clone_image", text="Image")
604                 col.prop(brush, "clone_alpha", text="Alpha")
605
606
607 class IMAGE_PT_paint_stroke(bpy.types.Panel):
608     bl_space_type = 'IMAGE_EDITOR'
609     bl_region_type = 'UI'
610     bl_label = "Paint Stroke"
611     bl_default_closed = True
612
613     def poll(self, context):
614         sima = context.space_data
615         toolsettings = context.tool_settings.image_paint
616         return sima.show_paint and toolsettings.brush
617
618     def draw(self, context):
619         layout = self.layout
620
621         toolsettings = context.tool_settings.image_paint
622         brush = toolsettings.brush
623
624         layout.prop(brush, "use_airbrush")
625         col = layout.column()
626         col.active = brush.use_airbrush
627         col.prop(brush, "rate", slider=True)
628
629         layout.prop(brush, "use_space")
630         row = layout.row(align=True)
631         row.active = brush.use_space
632         row.prop(brush, "spacing", text="Distance", slider=True)
633         row.prop(brush, "use_spacing_pressure", toggle=True, text="")
634
635         layout.prop(brush, "use_wrap")
636
637
638 class IMAGE_PT_paint_curve(bpy.types.Panel):
639     bl_space_type = 'IMAGE_EDITOR'
640     bl_region_type = 'UI'
641     bl_label = "Paint Curve"
642     bl_default_closed = True
643
644     def poll(self, context):
645         sima = context.space_data
646         toolsettings = context.tool_settings.image_paint
647         return sima.show_paint and toolsettings.brush
648
649     def draw(self, context):
650         layout = self.layout
651
652         toolsettings = context.tool_settings.image_paint
653         brush = toolsettings.brush
654
655         layout.template_curve_mapping(brush, "curve")
656         layout.operator_menu_enum("brush.curve_preset", "shape")
657
658
659 classes = [
660     IMAGE_MT_view,
661     IMAGE_MT_select,
662     IMAGE_MT_image,
663     IMAGE_MT_uvs_showhide,
664     IMAGE_MT_uvs_transform,
665     IMAGE_MT_uvs_snap,
666     IMAGE_MT_uvs_mirror,
667     IMAGE_MT_uvs_weldalign,
668     IMAGE_MT_uvs,
669     IMAGE_HT_header,
670     IMAGE_PT_image_properties,
671     IMAGE_PT_paint,
672     IMAGE_PT_paint_stroke,
673     IMAGE_PT_paint_curve,
674     IMAGE_PT_game_properties,
675     IMAGE_PT_view_properties,
676     IMAGE_PT_view_histogram,
677     IMAGE_PT_view_waveform,
678     IMAGE_PT_view_vectorscope,
679     IMAGE_PT_sample_line,
680     IMAGE_PT_scope_sample]
681
682
683 def register():
684     register = bpy.types.register
685     for cls in classes:
686         register(cls)
687
688
689 def unregister():
690     unregister = bpy.types.unregister
691     for cls in classes:
692         unregister(cls)
693
694 if __name__ == "__main__":
695     register()