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