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