rename user interface operator properties from 'op' to 'props'
[blender.git] / release / scripts / startup / bl_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 from bpy.types import Header, Menu, Panel
22
23
24 class BrushButtonsPanel():
25     bl_space_type = 'IMAGE_EDITOR'
26     bl_region_type = 'UI'
27
28     @classmethod
29     def poll(cls, context):
30         sima = context.space_data
31         toolsettings = context.tool_settings.image_paint
32         return sima.show_paint and toolsettings.brush
33
34
35 class IMAGE_MT_view(Menu):
36     bl_label = "View"
37
38     def draw(self, context):
39         layout = self.layout
40
41         sima = context.space_data
42         uv = sima.uv_editor
43         toolsettings = context.tool_settings
44
45         show_uvedit = sima.show_uvedit
46
47         layout.operator("image.properties", icon='MENU_PANEL')
48         layout.operator("image.scopes", icon='MENU_PANEL')
49
50         layout.separator()
51
52         layout.prop(sima, "use_realtime_update")
53         if show_uvedit:
54             layout.prop(toolsettings, "show_uv_local_view")
55             layout.prop(uv, "show_other_objects")
56
57         layout.separator()
58
59         layout.operator("image.view_zoom_in")
60         layout.operator("image.view_zoom_out")
61
62         layout.separator()
63
64         ratios = [[1, 8], [1, 4], [1, 2], [1, 1], [2, 1], [4, 1], [8, 1]]
65
66         for a, b in ratios:
67             layout.operator("image.view_zoom_ratio", text="Zoom" + " %d:%d" % (a, b)).ratio = a / b
68
69         layout.separator()
70
71         if show_uvedit:
72             layout.operator("image.view_selected")
73
74         layout.operator("image.view_all")
75
76         layout.separator()
77
78         layout.operator("screen.area_dupli")
79         layout.operator("screen.screen_full_area")
80
81
82 class IMAGE_MT_select(Menu):
83     bl_label = "Select"
84
85     def draw(self, context):
86         layout = self.layout
87
88         layout.operator("uv.select_border")
89         layout.operator("uv.select_border").pinned = True
90
91         layout.separator()
92
93         layout.operator("uv.select_all")
94         layout.operator("uv.select_all", text="Inverse").action = 'INVERT'
95         layout.operator("uv.unlink_selected")
96
97         layout.separator()
98
99         layout.operator("uv.select_pinned")
100         layout.operator("uv.select_linked")
101
102
103 class IMAGE_MT_image(Menu):
104     bl_label = "Image"
105
106     def draw(self, context):
107         layout = self.layout
108
109         sima = context.space_data
110         ima = sima.image
111
112         layout.operator("image.new")
113         layout.operator("image.open")
114
115         show_render = sima.show_render
116
117         if ima:
118             if not show_render:
119                 layout.operator("image.replace")
120                 layout.operator("image.reload")
121
122             layout.operator("image.save")
123             layout.operator("image.save_as")
124             layout.operator("image.save_as", text="Save a Copy").copy = True
125
126             if ima.source == 'SEQUENCE':
127                 layout.operator("image.save_sequence")
128
129             layout.operator("image.external_edit", "Edit Externally")
130
131             layout.separator()
132
133             layout.menu("IMAGE_MT_image_invert")
134
135             if not show_render:
136                 layout.separator()
137
138                 if ima.packed_file:
139                     layout.operator("image.unpack")
140                 else:
141                     layout.operator("image.pack")
142
143                 # only for dirty && specific image types, perhaps
144                 # this could be done in operator poll too
145                 if ima.is_dirty:
146                     if ima.source in {'FILE', 'GENERATED'} and ima.type != 'MULTILAYER':
147                         layout.operator("image.pack", text="Pack As PNG").as_png = True
148
149             layout.separator()
150
151             layout.prop(sima, "use_image_paint")
152
153
154 class IMAGE_MT_image_invert(Menu):
155     bl_label = "Invert"
156
157     def draw(self, context):
158         layout = self.layout
159
160         props = layout.operator("image.invert", text="Invert Image Colors")
161         props.invert_r = True
162         props.invert_g = True
163         props.invert_b = True
164
165         layout.separator()
166
167         props = layout.operator("image.invert", text="Invert Red Channel")
168         props.invert_r = True
169
170         props = layout.operator("image.invert", text="Invert Green Channel")
171         props.invert_g = True
172
173         props = layout.operator("image.invert", text="Invert Blue Channel")
174         props.invert_b = True
175
176         props = layout.operator("image.invert", text="Invert Alpha Channel")
177         props.invert_a = True
178
179
180 class IMAGE_MT_uvs_showhide(Menu):
181     bl_label = "Show/Hide Faces"
182
183     def draw(self, context):
184         layout = self.layout
185
186         layout.operator("uv.reveal")
187         layout.operator("uv.hide", text="Hide Selected")
188         layout.operator("uv.hide", text="Hide Unselected").unselected = True
189
190
191 class IMAGE_MT_uvs_transform(Menu):
192     bl_label = "Transform"
193
194     def draw(self, context):
195         layout = self.layout
196
197         layout.operator("transform.translate")
198         layout.operator("transform.rotate")
199         layout.operator("transform.resize")
200
201         layout.separator()
202
203         layout.operator("transform.shear")
204
205
206 class IMAGE_MT_uvs_snap(Menu):
207     bl_label = "Snap"
208
209     def draw(self, context):
210         layout = self.layout
211         layout.operator_context = 'EXEC_REGION_WIN'
212
213         layout.operator("uv.snap_selected", text="Selected to Pixels").target = 'PIXELS'
214         layout.operator("uv.snap_selected", text="Selected to Cursor").target = 'CURSOR'
215         layout.operator("uv.snap_selected", text="Selected to Adjacent Unselected").target = 'ADJACENT_UNSELECTED'
216
217         layout.separator()
218
219         layout.operator("uv.snap_cursor", text="Cursor to Pixels").target = 'PIXELS'
220         layout.operator("uv.snap_cursor", text="Cursor to Selected").target = 'SELECTED'
221
222
223 class IMAGE_MT_uvs_mirror(Menu):
224     bl_label = "Mirror"
225
226     def draw(self, context):
227         layout = self.layout
228         layout.operator_context = 'EXEC_REGION_WIN'
229
230         layout.operator("transform.mirror", text="X Axis").constraint_axis[0] = True
231         layout.operator("transform.mirror", text="Y Axis").constraint_axis[1] = True
232
233
234 class IMAGE_MT_uvs_weldalign(Menu):
235     bl_label = "Weld/Align"
236
237     def draw(self, context):
238         layout = self.layout
239
240         layout.operator("uv.weld")  # W, 1
241         layout.operator_enum("uv.align", "axis")  # W, 2/3/4
242
243
244 class IMAGE_MT_uvs(Menu):
245     bl_label = "UVs"
246
247     def draw(self, context):
248         layout = self.layout
249
250         sima = context.space_data
251         uv = sima.uv_editor
252         toolsettings = context.tool_settings
253
254         layout.prop(uv, "use_snap_to_pixels")
255         layout.prop(uv, "lock_bounds")
256
257         layout.separator()
258
259         layout.prop(uv, "use_live_unwrap")
260         layout.operator("uv.unwrap")
261         layout.operator("uv.pin", text="Unpin").clear = True
262         layout.operator("uv.pin")
263
264         layout.separator()
265
266         layout.operator("uv.pack_islands")
267         layout.operator("uv.average_islands_scale")
268         layout.operator("uv.minimize_stretch")
269         layout.operator("uv.stitch")
270         layout.operator("mesh.faces_mirror_uv")
271
272         layout.separator()
273
274         layout.menu("IMAGE_MT_uvs_transform")
275         layout.menu("IMAGE_MT_uvs_mirror")
276         layout.menu("IMAGE_MT_uvs_snap")
277         layout.menu("IMAGE_MT_uvs_weldalign")
278
279         layout.separator()
280
281         layout.prop_menu_enum(toolsettings, "proportional_edit")
282         layout.prop_menu_enum(toolsettings, "proportional_edit_falloff")
283
284         layout.separator()
285
286         layout.menu("IMAGE_MT_uvs_showhide")
287
288
289 class IMAGE_MT_uvs_select_mode(Menu):
290     bl_label = "UV Select Mode"
291
292     def draw(self, context):
293         layout = self.layout
294
295         layout.operator_context = 'INVOKE_REGION_WIN'
296         toolsettings = context.tool_settings
297
298         # do smart things depending on whether uv_select_sync is on
299
300         if toolsettings.use_uv_select_sync:
301             prop = layout.operator("wm.context_set_value", text="Vertex", icon='VERTEXSEL')
302             prop.value = "(True, False, False)"
303             prop.data_path = "tool_settings.mesh_select_mode"
304
305             prop = layout.operator("wm.context_set_value", text="Edge", icon='EDGESEL')
306             prop.value = "(False, True, False)"
307             prop.data_path = "tool_settings.mesh_select_mode"
308
309             prop = layout.operator("wm.context_set_value", text="Face", icon='FACESEL')
310             prop.value = "(False, False, True)"
311             prop.data_path = "tool_settings.mesh_select_mode"
312
313         else:
314             prop = layout.operator("wm.context_set_string", text="Vertex", icon='UV_VERTEXSEL')
315             prop.value = "VERTEX"
316             prop.data_path = "tool_settings.uv_select_mode"
317
318             prop = layout.operator("wm.context_set_string", text="Edge", icon='UV_EDGESEL')
319             prop.value = "EDGE"
320             prop.data_path = "tool_settings.uv_select_mode"
321
322             prop = layout.operator("wm.context_set_string", text="Face", icon='UV_FACESEL')
323             prop.value = "FACE"
324             prop.data_path = "tool_settings.uv_select_mode"
325
326             prop = layout.operator("wm.context_set_string", text="Island", icon='UV_ISLANDSEL')
327             prop.value = "ISLAND"
328             prop.data_path = "tool_settings.uv_select_mode"
329
330
331 class IMAGE_HT_header(Header):
332     bl_space_type = 'IMAGE_EDITOR'
333
334     def draw(self, context):
335         layout = self.layout
336
337         sima = context.space_data
338         ima = sima.image
339         iuser = sima.image_user
340         toolsettings = context.tool_settings
341
342         show_render = sima.show_render
343         # show_paint = sima.show_paint
344         show_uvedit = sima.show_uvedit
345
346         row = layout.row(align=True)
347         row.template_header()
348
349         # menus
350         if context.area.show_menus:
351             sub = row.row(align=True)
352             sub.menu("IMAGE_MT_view")
353
354             if show_uvedit:
355                 sub.menu("IMAGE_MT_select")
356
357             if ima and ima.is_dirty:
358                 sub.menu("IMAGE_MT_image", text="Image*")
359             else:
360                 sub.menu("IMAGE_MT_image", text="Image")
361
362             if show_uvedit:
363                 sub.menu("IMAGE_MT_uvs")
364
365         layout.template_ID(sima, "image", new="image.new")
366         if not show_render:
367             layout.prop(sima, "use_image_pin", text="")
368
369         # uv editing
370         if show_uvedit:
371             uvedit = sima.uv_editor
372
373             layout.prop(uvedit, "pivot_point", text="", icon_only=True)
374             layout.prop(toolsettings, "use_uv_select_sync", text="")
375
376             if toolsettings.use_uv_select_sync:
377                 layout.template_edit_mode_selection()
378             else:
379                 layout.prop(toolsettings, "uv_select_mode", text="", expand=True)
380                 layout.prop(uvedit, "sticky_select_mode", text="", icon_only=True)
381
382             row = layout.row(align=True)
383             row.prop(toolsettings, "proportional_edit", text="", icon_only=True)
384             if toolsettings.proportional_edit != 'DISABLED':
385                 row.prop(toolsettings, "proportional_edit_falloff", text="", icon_only=True)
386
387             row = layout.row(align=True)
388             row.prop(toolsettings, "use_snap", text="")
389             row.prop(toolsettings, "snap_target", text="")
390
391             mesh = context.edit_object.data
392             layout.prop_search(mesh.uv_textures, "active", mesh, "uv_textures", text="")
393
394         if ima:
395             # layers
396             layout.template_image_layers(ima, iuser)
397
398             # painting
399             layout.prop(sima, "use_image_paint", text="")
400
401             # draw options
402             row = layout.row(align=True)
403             row.prop(sima, "draw_channels", text="", expand=True)
404
405             row = layout.row(align=True)
406             if ima.type == 'COMPOSITE':
407                 row.operator("image.record_composite", icon='REC')
408             if ima.type == 'COMPOSITE' and ima.source in {'MOVIE', 'SEQUENCE'}:
409                 row.operator("image.play_composite", icon='PLAY')
410
411         if show_uvedit or sima.use_image_paint:
412             layout.prop(sima, "use_realtime_update", text="", icon_only=True, icon='LOCKED')
413
414
415 class IMAGE_PT_image_properties(Panel):
416     bl_space_type = 'IMAGE_EDITOR'
417     bl_region_type = 'UI'
418     bl_label = "Image"
419
420     @classmethod
421     def poll(cls, context):
422         sima = context.space_data
423         return (sima.image)
424
425     def draw(self, context):
426         layout = self.layout
427
428         sima = context.space_data
429         iuser = sima.image_user
430
431         layout.template_image(sima, "image", iuser)
432
433
434 class IMAGE_PT_game_properties(Panel):
435     bl_space_type = 'IMAGE_EDITOR'
436     bl_region_type = 'UI'
437     bl_label = "Game Properties"
438
439     @classmethod
440     def poll(cls, context):
441         sima = context.space_data
442         # display even when not in game mode because these settings effect the 3d view
443         return (sima and sima.image)  # and (rd.engine == 'BLENDER_GAME')
444
445     def draw(self, context):
446         layout = self.layout
447
448         sima = context.space_data
449         ima = sima.image
450
451         split = layout.split()
452
453         col = split.column()
454
455         col.prop(ima, "use_animation")
456         sub = col.column(align=True)
457         sub.active = ima.use_animation
458         sub.prop(ima, "frame_start", text="Start")
459         sub.prop(ima, "frame_end", text="End")
460         sub.prop(ima, "fps", text="Speed")
461
462         col.prop(ima, "use_tiles")
463         sub = col.column(align=True)
464         sub.active = ima.use_tiles or ima.use_animation
465         sub.prop(ima, "tiles_x", text="X")
466         sub.prop(ima, "tiles_y", text="Y")
467
468         col = split.column()
469         col.label(text="Clamp:")
470         col.prop(ima, "use_clamp_x", text="X")
471         col.prop(ima, "use_clamp_y", text="Y")
472         col.separator()
473         col.prop(ima, "mapping", expand=True)
474
475
476 class IMAGE_PT_view_histogram(Panel):
477     bl_space_type = 'IMAGE_EDITOR'
478     bl_region_type = 'PREVIEW'
479     bl_label = "Histogram"
480
481     @classmethod
482     def poll(cls, context):
483         sima = context.space_data
484         return (sima and sima.image)
485
486     def draw(self, context):
487         layout = self.layout
488
489         sima = context.space_data
490
491         layout.template_histogram(sima.scopes, "histogram")
492         layout.prop(sima.scopes.histogram, "mode", icon_only=True)
493
494
495 class IMAGE_PT_view_waveform(Panel):
496     bl_space_type = 'IMAGE_EDITOR'
497     bl_region_type = 'PREVIEW'
498     bl_label = "Waveform"
499
500     @classmethod
501     def poll(cls, context):
502         sima = context.space_data
503         return (sima and sima.image)
504
505     def draw(self, context):
506         layout = self.layout
507
508         sima = context.space_data
509
510         layout.template_waveform(sima, "scopes")
511         row = layout.split(percentage=0.75)
512         row.prop(sima.scopes, "waveform_alpha")
513         row.prop(sima.scopes, "waveform_mode", text="", icon_only=True)
514
515
516 class IMAGE_PT_view_vectorscope(Panel):
517     bl_space_type = 'IMAGE_EDITOR'
518     bl_region_type = 'PREVIEW'
519     bl_label = "Vectorscope"
520
521     @classmethod
522     def poll(cls, context):
523         sima = context.space_data
524         return (sima and sima.image)
525
526     def draw(self, context):
527         layout = self.layout
528
529         sima = context.space_data
530         layout.template_vectorscope(sima, "scopes")
531         layout.prop(sima.scopes, "vectorscope_alpha")
532
533
534 class IMAGE_PT_sample_line(Panel):
535     bl_space_type = 'IMAGE_EDITOR'
536     bl_region_type = 'PREVIEW'
537     bl_label = "Sample Line"
538
539     @classmethod
540     def poll(cls, context):
541         sima = context.space_data
542         return (sima and sima.image)
543
544     def draw(self, context):
545         layout = self.layout
546
547         sima = context.space_data
548
549         layout.operator("image.sample_line")
550         layout.template_histogram(sima, "sample_histogram")
551         layout.prop(sima.sample_histogram, "mode")
552
553
554 class IMAGE_PT_scope_sample(Panel):
555     bl_space_type = 'IMAGE_EDITOR'
556     bl_region_type = 'PREVIEW'
557     bl_label = "Scope Samples"
558
559     @classmethod
560     def poll(cls, context):
561         sima = context.space_data
562         return sima
563
564     def draw(self, context):
565         layout = self.layout
566
567         sima = context.space_data
568
569         row = layout.row()
570         row.prop(sima.scopes, "use_full_resolution")
571         sub = row.row()
572         sub.active = not sima.scopes.use_full_resolution
573         sub.prop(sima.scopes, "accuracy")
574
575
576 class IMAGE_PT_view_properties(Panel):
577     bl_space_type = 'IMAGE_EDITOR'
578     bl_region_type = 'UI'
579     bl_label = "Display"
580
581     @classmethod
582     def poll(cls, context):
583         sima = context.space_data
584         return (sima and (sima.image or sima.show_uvedit))
585
586     def draw(self, context):
587         layout = self.layout
588
589         sima = context.space_data
590         ima = sima.image
591         show_uvedit = sima.show_uvedit
592         uvedit = sima.uv_editor
593
594         split = layout.split()
595
596         col = split.column()
597         if ima:
598             col.prop(ima, "display_aspect", text="Aspect Ratio")
599
600             col = split.column()
601             col.label(text="Coordinates:")
602             col.prop(sima, "show_repeat", text="Repeat")
603             if show_uvedit:
604                 col.prop(uvedit, "show_normalized_coords", text="Normalized")
605
606         elif show_uvedit:
607             col.label(text="Coordinates:")
608             col.prop(uvedit, "show_normalized_coords", text="Normalized")
609
610         if show_uvedit:
611
612             col = layout.column()
613             col.label("Cursor Location:")
614             col.row().prop(uvedit, "cursor_location", text="")
615
616             col.separator()
617
618             col.label(text="UVs:")
619             col.row().prop(uvedit, "edge_draw_type", expand=True)
620
621             split = layout.split()
622
623             col = split.column()
624             col.prop(uvedit, "show_faces")
625             col.prop(uvedit, "show_smooth_edges", text="Smooth")
626             col.prop(uvedit, "show_modified_edges", text="Modified")
627
628             col = split.column()
629             col.prop(uvedit, "show_stretch", text="Stretch")
630             sub = col.column()
631             sub.active = uvedit.show_stretch
632             sub.row().prop(uvedit, "draw_stretch_type", expand=True)
633
634
635 class IMAGE_PT_paint(Panel):
636     bl_space_type = 'IMAGE_EDITOR'
637     bl_region_type = 'UI'
638     bl_label = "Paint"
639
640     @classmethod
641     def poll(cls, context):
642         sima = context.space_data
643         return sima.show_paint
644
645     def draw(self, context):
646         layout = self.layout
647
648         toolsettings = context.tool_settings.image_paint
649         brush = toolsettings.brush
650
651         col = layout.column()
652         col.template_ID_preview(toolsettings, "brush", new="brush.add", rows=2, cols=6)
653
654         if brush:
655             col = layout.column()
656             col.template_color_wheel(brush, "color", value_slider=True)
657             col.prop(brush, "color", text="")
658
659             row = col.row(align=True)
660             row.prop(brush, "size", slider=True)
661             row.prop(brush, "use_pressure_size", toggle=True, text="")
662
663             row = col.row(align=True)
664             row.prop(brush, "strength", slider=True)
665             row.prop(brush, "use_pressure_strength", toggle=True, text="")
666
667             row = col.row(align=True)
668             row.prop(brush, "jitter", slider=True)
669             row.prop(brush, "use_pressure_jitter", toggle=True, text="")
670
671             col.prop(brush, "blend", text="Blend")
672
673             if brush.image_tool == 'CLONE':
674                 col.separator()
675                 col.prop(brush, "clone_image", text="Image")
676                 col.prop(brush, "clone_alpha", text="Alpha")
677
678
679 class IMAGE_PT_tools_brush_texture(BrushButtonsPanel, Panel):
680     bl_label = "Texture"
681     bl_options = {'DEFAULT_CLOSED'}
682
683     def draw(self, context):
684         layout = self.layout
685
686         toolsettings = context.tool_settings.image_paint
687         brush = toolsettings.brush
688
689         col = layout.column()
690         col.template_ID_preview(brush, "texture", new="texture.new", rows=3, cols=8)
691         col.prop(brush, "use_fixed_texture")
692
693
694 class IMAGE_PT_tools_brush_tool(BrushButtonsPanel, Panel):
695     bl_label = "Tool"
696     bl_options = {'DEFAULT_CLOSED'}
697
698     def draw(self, context):
699         layout = self.layout
700         settings = context.tool_settings.image_paint
701         brush = settings.brush
702
703         layout.prop(brush, "image_tool", text="")
704
705         row = layout.row(align=True)
706         row.prop(brush, "use_paint_sculpt", text="", icon='SCULPTMODE_HLT')
707         row.prop(brush, "use_paint_vertex", text="", icon='VPAINT_HLT')
708         row.prop(brush, "use_paint_weight", text="", icon='WPAINT_HLT')
709         row.prop(brush, "use_paint_image", text="", icon='TPAINT_HLT')
710
711
712 class IMAGE_PT_paint_stroke(BrushButtonsPanel, Panel):
713     bl_label = "Paint Stroke"
714     bl_options = {'DEFAULT_CLOSED'}
715
716     def draw(self, context):
717         layout = self.layout
718
719         toolsettings = context.tool_settings.image_paint
720         brush = toolsettings.brush
721
722         layout.prop(brush, "use_airbrush")
723         row = layout.row()
724         row.active = brush.use_airbrush
725         row.prop(brush, "rate", slider=True)
726
727         layout.prop(brush, "use_space")
728         row = layout.row(align=True)
729         row.active = brush.use_space
730         row.prop(brush, "spacing", text="Distance", slider=True)
731         row.prop(brush, "use_pressure_spacing", toggle=True, text="")
732
733         layout.prop(brush, "use_wrap")
734
735
736 class IMAGE_PT_paint_curve(BrushButtonsPanel, Panel):
737     bl_label = "Paint Curve"
738     bl_options = {'DEFAULT_CLOSED'}
739
740     def draw(self, context):
741         layout = self.layout
742
743         toolsettings = context.tool_settings.image_paint
744         brush = toolsettings.brush
745
746         layout.template_curve_mapping(brush, "curve")
747
748         row = layout.row(align=True)
749         row.operator("brush.curve_preset", icon="SMOOTHCURVE", text="").shape = 'SMOOTH'
750         row.operator("brush.curve_preset", icon="SPHERECURVE", text="").shape = 'ROUND'
751         row.operator("brush.curve_preset", icon="ROOTCURVE", text="").shape = 'ROOT'
752         row.operator("brush.curve_preset", icon="SHARPCURVE", text="").shape = 'SHARP'
753         row.operator("brush.curve_preset", icon="LINCURVE", text="").shape = 'LINE'
754         row.operator("brush.curve_preset", icon="NOCURVE", text="").shape = 'MAX'
755
756 if __name__ == "__main__":  # only for live edit.
757     bpy.utils.register_module(__name__)