fix for keying set rna path attribute and object select menu incorrect args to UI...
[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 class IMAGE_PT_sample_line(bpy.types.Panel):
410     bl_space_type = 'IMAGE_EDITOR'
411     bl_region_type = 'PREVIEW'
412     bl_label = "Sample Line"
413
414     def poll(self, context):
415         sima = context.space_data
416         return (sima and sima.image)
417
418     def draw(self, context):
419         layout = self.layout
420         layout.operator("image.sample_line")
421         sima = context.space_data
422         layout.template_histogram(sima, "sample_histogram")
423
424 class IMAGE_PT_view_properties(bpy.types.Panel):
425     bl_space_type = 'IMAGE_EDITOR'
426     bl_region_type = 'UI'
427     bl_label = "Display"
428
429     def poll(self, context):
430         sima = context.space_data
431         return (sima and (sima.image or sima.show_uvedit))
432
433     def draw(self, context):
434         layout = self.layout
435
436         sima = context.space_data
437         ima = sima.image
438         show_uvedit = sima.show_uvedit
439         uvedit = sima.uv_editor
440         wide_ui = context.region.width > narrowui
441
442         split = layout.split()
443
444         col = split.column()
445         if ima:
446             col.prop(ima, "display_aspect", text="Aspect Ratio")
447
448             if wide_ui:
449                 col = split.column()
450             col.label(text="Coordinates:")
451             col.prop(sima, "draw_repeated", text="Repeat")
452             if show_uvedit:
453                 col.prop(uvedit, "normalized_coordinates", text="Normalized")
454
455         elif show_uvedit:
456             col.label(text="Coordinates:")
457             col.prop(uvedit, "normalized_coordinates", text="Normalized")
458
459         if show_uvedit:
460
461             col = layout.column()
462             col.label(text="UVs:")
463             row = col.row()
464             if wide_ui:
465                 row.prop(uvedit, "edge_draw_type", expand=True)
466             else:
467                 row.prop(uvedit, "edge_draw_type", text="")
468
469             split = layout.split()
470             col = split.column()
471             col.prop(uvedit, "draw_smooth_edges", text="Smooth")
472             col.prop(uvedit, "draw_modified_edges", text="Modified")
473             #col.prop(uvedit, "draw_edges")
474             #col.prop(uvedit, "draw_faces")
475
476             if wide_ui:
477                 col = split.column()
478             col.prop(uvedit, "draw_stretch", text="Stretch")
479             sub = col.column()
480             sub.active = uvedit.draw_stretch
481             sub.row().prop(uvedit, "draw_stretch_type", expand=True)
482
483
484 class IMAGE_PT_paint(bpy.types.Panel):
485     bl_space_type = 'IMAGE_EDITOR'
486     bl_region_type = 'UI'
487     bl_label = "Paint"
488
489     def poll(self, context):
490         sima = context.space_data
491         return sima.show_paint
492
493     def draw(self, context):
494         layout = self.layout
495
496         toolsettings = context.tool_settings.image_paint
497         brush = toolsettings.brush
498         wide_ui = context.region.width > narrowui
499
500         col = layout.split().column()
501         row = col.row()
502         row.template_list(toolsettings, "brushes", toolsettings, "active_brush_index", rows=2)
503
504         col.template_ID(toolsettings, "brush", new="brush.add")
505
506         if wide_ui:
507             sub = layout.row(align=True)
508         else:
509             sub = layout.column(align=True)
510         sub.prop_enum(brush, "imagepaint_tool", 'DRAW')
511         sub.prop_enum(brush, "imagepaint_tool", 'SOFTEN')
512         sub.prop_enum(brush, "imagepaint_tool", 'CLONE')
513         sub.prop_enum(brush, "imagepaint_tool", 'SMEAR')
514
515         if brush:
516             col = layout.column()
517             col.template_color_wheel(brush, "color", value_slider=True)
518             col.prop(brush, "color", text="")
519
520             row = col.row(align=True)
521             row.prop(brush, "size", slider=True)
522             row.prop(brush, "use_size_pressure", toggle=True, text="")
523
524             row = col.row(align=True)
525             row.prop(brush, "strength", slider=True)
526             row.prop(brush, "use_strength_pressure", toggle=True, text="")
527
528             row = col.row(align=True)
529             row.prop(brush, "jitter", slider=True)
530             row.prop(brush, "use_jitter_pressure", toggle=True, text="")
531
532             col.prop(brush, "blend", text="Blend")
533
534             if brush.imagepaint_tool == 'CLONE':
535                 col.separator()
536                 col.prop(brush, "clone_image", text="Image")
537                 col.prop(brush, "clone_alpha", text="Alpha")
538
539
540 class IMAGE_PT_paint_stroke(bpy.types.Panel):
541     bl_space_type = 'IMAGE_EDITOR'
542     bl_region_type = 'UI'
543     bl_label = "Paint Stroke"
544     bl_default_closed = True
545
546     def poll(self, context):
547         sima = context.space_data
548         toolsettings = context.tool_settings.image_paint
549         return sima.show_paint and toolsettings.brush
550
551     def draw(self, context):
552         layout = self.layout
553
554         toolsettings = context.tool_settings.image_paint
555         brush = toolsettings.brush
556
557         layout.prop(brush, "use_airbrush")
558         col = layout.column()
559         col.active = brush.use_airbrush
560         col.prop(brush, "rate", slider=True)
561
562         layout.prop(brush, "use_space")
563         row = layout.row(align=True)
564         row.active = brush.use_space
565         row.prop(brush, "spacing", text="Distance", slider=True)
566         row.prop(brush, "use_spacing_pressure", toggle=True, text="")
567
568         layout.prop(brush, "use_wrap")
569
570
571 class IMAGE_PT_paint_curve(bpy.types.Panel):
572     bl_space_type = 'IMAGE_EDITOR'
573     bl_region_type = 'UI'
574     bl_label = "Paint Curve"
575     bl_default_closed = True
576
577     def poll(self, context):
578         sima = context.space_data
579         toolsettings = context.tool_settings.image_paint
580         return sima.show_paint and toolsettings.brush
581
582     def draw(self, context):
583         layout = self.layout
584
585         toolsettings = context.tool_settings.image_paint
586         brush = toolsettings.brush
587
588         layout.template_curve_mapping(brush, "curve")
589         layout.operator_menu_enum("brush.curve_preset", "shape")
590
591
592 classes = [
593     IMAGE_MT_view,
594     IMAGE_MT_select,
595     IMAGE_MT_image,
596     IMAGE_MT_uvs_showhide,
597     IMAGE_MT_uvs_transform,
598     IMAGE_MT_uvs_snap,
599     IMAGE_MT_uvs_mirror,
600     IMAGE_MT_uvs_weldalign,
601     IMAGE_MT_uvs,
602     IMAGE_HT_header,
603     IMAGE_PT_image_properties,
604     IMAGE_PT_paint,
605     IMAGE_PT_paint_stroke,
606     IMAGE_PT_paint_curve,
607     IMAGE_PT_game_properties,
608     IMAGE_PT_view_properties,
609     IMAGE_PT_view_histogram,
610     IMAGE_PT_sample_line]
611
612
613 def register():
614     register = bpy.types.register
615     for cls in classes:
616         register(cls)
617
618
619 def unregister():
620     unregister = bpy.types.unregister
621     for cls in classes:
622         unregister(cls)
623
624 if __name__ == "__main__":
625     register()