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