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