rename operators TFM_OT_* --> TRANSFORM_OT_*
[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
223         layout.separator()
224
225         layout.menu("IMAGE_MT_uvs_transform")
226         layout.menu("IMAGE_MT_uvs_mirror")
227         layout.menu("IMAGE_MT_uvs_snap")
228         layout.menu("IMAGE_MT_uvs_weldalign")
229
230         layout.separator()
231
232         layout.prop_menu_enum(settings, "proportional_editing")
233         layout.prop_menu_enum(settings, "proportional_editing_falloff")
234
235         layout.separator()
236
237         layout.menu("IMAGE_MT_uvs_showhide")
238
239
240 class IMAGE_HT_header(bpy.types.Header):
241     bl_space_type = 'IMAGE_EDITOR'
242
243     def draw(self, context):
244         layout = self.layout
245
246         sima = context.space_data
247         ima = sima.image
248         iuser = sima.image_user
249         settings = context.tool_settings
250
251         # show_render = sima.show_render
252         # show_paint = sima.show_paint
253         show_uvedit = sima.show_uvedit
254
255         row = layout.row(align=True)
256         row.template_header()
257
258         # menus
259         if context.area.show_menus:
260             sub = row.row(align=True)
261             sub.menu("IMAGE_MT_view")
262
263             if show_uvedit:
264                 sub.menu("IMAGE_MT_select")
265
266             if ima and ima.dirty:
267                 sub.menu("IMAGE_MT_image", text="Image*")
268             else:
269                 sub.menu("IMAGE_MT_image", text="Image")
270
271             if show_uvedit:
272                 sub.menu("IMAGE_MT_uvs")
273
274         layout.template_ID(sima, "image", new="image.new")
275
276         # uv editing
277         if show_uvedit:
278             uvedit = sima.uv_editor
279
280             layout.prop(uvedit, "pivot", text="", icon_only=True)
281             layout.prop(settings, "uv_sync_selection", text="")
282
283             if settings.uv_sync_selection:
284                 layout.prop(settings, "mesh_selection_mode", text="", expand=True)
285             else:
286                 layout.prop(settings, "uv_selection_mode", text="", expand=True)
287                 layout.prop(uvedit, "sticky_selection_mode", text="", icon_only=True)
288
289             row = layout.row(align=True)
290             row.prop(settings, "snap", text="")
291             row.prop(settings, "snap_element", text="", icon_only=True)
292
293             # mesh = context.edit_object.data
294             # row.prop_object(mesh, "active_uv_layer", mesh, "uv_textures")
295
296         if ima:
297             # layers
298             layout.template_image_layers(ima, iuser)
299
300             # painting
301             layout.prop(sima, "image_painting", text="")
302
303             # draw options
304             row = layout.row(align=True)
305             row.prop(sima, "draw_channels", text="", expand=True)
306
307             row = layout.row(align=True)
308             if ima.type == 'COMPOSITE':
309                 row.operator("image.record_composite", icon='REC')
310             if ima.type == 'COMPOSITE' and ima.source in ('MOVIE', 'SEQUENCE'):
311                 row.operator("image.play_composite", icon='PLAY')
312
313         if show_uvedit or sima.image_painting:
314             layout.prop(sima, "update_automatically", text="")
315
316
317 class IMAGE_PT_image_properties(bpy.types.Panel):
318     bl_space_type = 'IMAGE_EDITOR'
319     bl_region_type = 'UI'
320     bl_label = "Image"
321
322     def poll(self, context):
323         sima = context.space_data
324         return (sima.image)
325
326     def draw(self, context):
327         layout = self.layout
328
329         sima = context.space_data
330         # ima = sima.image
331         iuser = sima.image_user
332
333         layout.template_image(sima, "image", iuser, compact=True)
334
335
336 class IMAGE_PT_game_properties(bpy.types.Panel):
337     bl_space_type = 'IMAGE_EDITOR'
338     bl_region_type = 'UI'
339     bl_label = "Game Properties"
340
341     def poll(self, context):
342         rd = context.scene.render_data
343         sima = context.space_data
344         return (sima and sima.image) and (rd.engine == 'BLENDER_GAME')
345
346     def draw(self, context):
347         layout = self.layout
348
349         sima = context.space_data
350         ima = sima.image
351         wide_ui = context.region.width > narrowui
352
353         split = layout.split()
354
355         col = split.column()
356
357         sub = col.column(align=True)
358         sub.prop(ima, "animated")
359
360         subsub = sub.column()
361         subsub.active = ima.animated
362         subsub.prop(ima, "animation_start", text="Start")
363         subsub.prop(ima, "animation_end", text="End")
364         subsub.prop(ima, "animation_speed", text="Speed")
365
366         col.prop(ima, "tiles")
367         sub = col.column(align=True)
368         sub.active = ima.tiles or ima.animated
369         sub.prop(ima, "tiles_x", text="X")
370         sub.prop(ima, "tiles_y", text="Y")
371
372         if wide_ui:
373             col = split.column()
374         col.label(text="Clamp:")
375         col.prop(ima, "clamp_x", text="X")
376         col.prop(ima, "clamp_y", text="Y")
377         col.separator()
378         col.prop(ima, "mapping", expand=True)
379
380
381 class IMAGE_PT_view_properties(bpy.types.Panel):
382     bl_space_type = 'IMAGE_EDITOR'
383     bl_region_type = 'UI'
384     bl_label = "Display"
385
386     def poll(self, context):
387         sima = context.space_data
388         return (sima and (sima.image or sima.show_uvedit))
389
390     def draw(self, context):
391         layout = self.layout
392
393         sima = context.space_data
394         ima = sima.image
395         show_uvedit = sima.show_uvedit
396         uvedit = sima.uv_editor
397         wide_ui = context.region.width > narrowui
398
399         split = layout.split()
400
401         col = split.column()
402         if ima:
403             col.prop(ima, "display_aspect", text="Aspect Ratio")
404
405             if wide_ui:
406                 col = split.column()
407             col.label(text="Coordinates:")
408             col.prop(sima, "draw_repeated", text="Repeat")
409             if show_uvedit:
410                 col.prop(uvedit, "normalized_coordinates", text="Normalized")
411         elif show_uvedit:
412             col.label(text="Coordinates:")
413             col.prop(uvedit, "normalized_coordinates", text="Normalized")
414
415         if show_uvedit:
416
417             col = layout.column()
418             col.label(text="UVs:")
419             row = col.row()
420             if wide_ui:
421                 row.prop(uvedit, "edge_draw_type", expand=True)
422             else:
423                 row.prop(uvedit, "edge_draw_type", text="")
424
425             split = layout.split()
426             col = split.column()
427             col.prop(uvedit, "draw_smooth_edges", text="Smooth")
428             col.prop(uvedit, "draw_modified_edges", text="Modified")
429             #col.prop(uvedit, "draw_edges")
430             #col.prop(uvedit, "draw_faces")
431
432             if wide_ui:
433                 col = split.column()
434             col.prop(uvedit, "draw_stretch", text="Stretch")
435             sub = col.column()
436             sub.active = uvedit.draw_stretch
437             sub.row().prop(uvedit, "draw_stretch_type", expand=True)
438
439
440 class IMAGE_PT_paint(bpy.types.Panel):
441     bl_space_type = 'IMAGE_EDITOR'
442     bl_region_type = 'UI'
443     bl_label = "Paint"
444
445     def poll(self, context):
446         sima = context.space_data
447         return sima.show_paint
448
449     def draw(self, context):
450         layout = self.layout
451
452         settings = context.tool_settings.image_paint
453         brush = settings.brush
454         wide_ui = context.region.width > narrowui
455
456         col = layout.split().column()
457         row = col.row()
458         row.template_list(settings, "brushes", settings, "active_brush_index", rows=2)
459
460         col.template_ID(settings, "brush", new="brush.add")
461
462         if wide_ui:
463             sub = layout.row(align=True)
464         else:
465             sub = layout.column(align=True)
466         sub.prop_enum(settings, "tool", 'DRAW')
467         sub.prop_enum(settings, "tool", 'SOFTEN')
468         sub.prop_enum(settings, "tool", 'CLONE')
469         sub.prop_enum(settings, "tool", 'SMEAR')
470
471         if brush:
472             col = layout.column()
473             col.prop(brush, "color", text="")
474
475             row = col.row(align=True)
476             row.prop(brush, "size", slider=True)
477             row.prop(brush, "use_size_pressure", toggle=True, text="")
478
479             row = col.row(align=True)
480             row.prop(brush, "strength", slider=True)
481             row.prop(brush, "use_strength_pressure", toggle=True, text="")
482
483             row = col.row(align=True)
484             row.prop(brush, "jitter", slider=True)
485             row.prop(brush, "use_jitter_pressure", toggle=True, text="")
486
487             col.prop(brush, "blend", text="Blend")
488
489
490 class IMAGE_PT_paint_stroke(bpy.types.Panel):
491     bl_space_type = 'IMAGE_EDITOR'
492     bl_region_type = 'UI'
493     bl_label = "Paint Stroke"
494     bl_default_closed = True
495
496     def poll(self, context):
497         sima = context.space_data
498         settings = context.tool_settings.image_paint
499         return sima.show_paint and settings.brush
500
501     def draw(self, context):
502         layout = self.layout
503
504         settings = context.tool_settings.image_paint
505         brush = settings.brush
506
507         layout.prop(brush, "use_airbrush")
508         col = layout.column()
509         col.active = brush.use_airbrush
510         col.prop(brush, "rate", slider=True)
511
512         layout.prop(brush, "use_space")
513         row = layout.row(align=True)
514         row.active = brush.use_space
515         row.prop(brush, "spacing", text="Distance", slider=True)
516         row.prop(brush, "use_spacing_pressure", toggle=True, text="")
517
518
519 class IMAGE_PT_paint_curve(bpy.types.Panel):
520     bl_space_type = 'IMAGE_EDITOR'
521     bl_region_type = 'UI'
522     bl_label = "Paint Curve"
523     bl_default_closed = True
524
525     def poll(self, context):
526         sima = context.space_data
527         settings = context.tool_settings.image_paint
528         return sima.show_paint and settings.brush
529
530     def draw(self, context):
531         layout = self.layout
532
533         settings = context.tool_settings.image_paint
534         brush = settings.brush
535
536         layout.template_curve_mapping(brush, "curve")
537         layout.operator_menu_enum("brush.curve_preset", property="shape")
538
539 bpy.types.register(IMAGE_MT_view)
540 bpy.types.register(IMAGE_MT_select)
541 bpy.types.register(IMAGE_MT_image)
542 bpy.types.register(IMAGE_MT_uvs_showhide)
543 bpy.types.register(IMAGE_MT_uvs_transform)
544 bpy.types.register(IMAGE_MT_uvs_snap)
545 bpy.types.register(IMAGE_MT_uvs_mirror)
546 bpy.types.register(IMAGE_MT_uvs_weldalign)
547 bpy.types.register(IMAGE_MT_uvs)
548 bpy.types.register(IMAGE_HT_header)
549 bpy.types.register(IMAGE_PT_image_properties)
550 bpy.types.register(IMAGE_PT_paint)
551 bpy.types.register(IMAGE_PT_paint_stroke)
552 bpy.types.register(IMAGE_PT_paint_curve)
553 bpy.types.register(IMAGE_PT_game_properties)
554 bpy.types.register(IMAGE_PT_view_properties)