Merging r58475 through r58700 from trunk into soc-2013-depsgraph_mt
[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 from bl_ui.properties_paint_common import UnifiedPaintPanel, brush_texture_settings, brush_mask_texture_settings
23 from bpy.app.translations import pgettext_iface as iface_
24
25
26 class ImagePaintPanel(UnifiedPaintPanel):
27     bl_space_type = 'IMAGE_EDITOR'
28     bl_region_type = 'UI'
29
30
31 class BrushButtonsPanel:
32     bl_space_type = 'IMAGE_EDITOR'
33     bl_region_type = 'UI'
34
35     @classmethod
36     def poll(cls, context):
37         sima = context.space_data
38         toolsettings = context.tool_settings.image_paint
39         return sima.show_paint and toolsettings.brush
40
41
42 class IMAGE_MT_view(Menu):
43     bl_label = "View"
44
45     def draw(self, context):
46         layout = self.layout
47
48         sima = context.space_data
49         uv = sima.uv_editor
50         toolsettings = context.tool_settings
51
52         show_uvedit = sima.show_uvedit
53         show_render = sima.show_render
54
55         layout.operator("image.properties", icon='MENU_PANEL')
56         layout.operator("image.scopes", icon='MENU_PANEL')
57
58         layout.separator()
59
60         layout.prop(sima, "use_realtime_update")
61         if show_uvedit:
62             layout.prop(toolsettings, "show_uv_local_view")
63
64         layout.prop(uv, "show_other_objects")
65
66         layout.separator()
67
68         layout.operator("image.view_zoom_in")
69         layout.operator("image.view_zoom_out")
70
71         layout.separator()
72
73         ratios = ((1, 8), (1, 4), (1, 2), (1, 1), (2, 1), (4, 1), (8, 1))
74
75         for a, b in ratios:
76             layout.operator("image.view_zoom_ratio", text=iface_("Zoom %d:%d") % (a, b), translate=False).ratio = a / b
77
78         layout.separator()
79
80         if show_uvedit:
81             layout.operator("image.view_selected")
82
83         layout.operator("image.view_all")
84
85         layout.separator()
86
87         if show_render:
88             layout.operator("image.cycle_render_slot", text="Render Slot Cycle Next")
89             layout.operator("image.cycle_render_slot", text="Render Slot Cycle Previous").reverse = True
90             layout.separator()
91
92         layout.operator("screen.area_dupli")
93         layout.operator("screen.screen_full_area")
94
95
96 class IMAGE_MT_select(Menu):
97     bl_label = "Select"
98
99     def draw(self, context):
100         layout = self.layout
101
102         layout.operator("uv.select_border").pinned = False
103         layout.operator("uv.select_border", text="Border Select Pinned").pinned = True
104
105         layout.separator()
106
107         layout.operator("uv.select_all").action = 'TOGGLE'
108         layout.operator("uv.select_all", text="Inverse").action = 'INVERT'
109         layout.operator("uv.select_split")
110
111         layout.separator()
112
113         layout.operator("uv.select_pinned")
114         layout.operator("uv.select_linked")
115
116         layout.separator()
117
118         layout.operator("uv.select_less", text="Less")
119         layout.operator("uv.select_more", text="More")
120
121         layout.separator()
122
123         layout.operator("uv.select_split")
124
125
126 class IMAGE_MT_image(Menu):
127     bl_label = "Image"
128
129     def draw(self, context):
130         layout = self.layout
131
132         sima = context.space_data
133         ima = sima.image
134
135         layout.operator("image.new")
136         layout.operator("image.open")
137
138         show_render = sima.show_render
139
140         if ima:
141             if not show_render:
142                 layout.operator("image.replace")
143                 layout.operator("image.reload")
144
145             layout.operator("image.save")
146             layout.operator("image.save_as")
147             layout.operator("image.save_as", text="Save a Copy").copy = True
148
149             if ima.source == 'SEQUENCE':
150                 layout.operator("image.save_sequence")
151
152             layout.operator("image.external_edit", "Edit Externally")
153
154             layout.separator()
155
156             layout.menu("IMAGE_MT_image_invert")
157
158             if not show_render:
159                 layout.separator()
160
161                 if not ima.packed_file:
162                     layout.operator("image.pack")
163
164                 # only for dirty && specific image types, perhaps
165                 # this could be done in operator poll too
166                 if ima.is_dirty:
167                     if ima.source in {'FILE', 'GENERATED'} and ima.type != 'OPEN_EXR_MULTILAYER':
168                         layout.operator("image.pack", text="Pack As PNG").as_png = True
169
170             layout.separator()
171
172
173 class IMAGE_MT_image_invert(Menu):
174     bl_label = "Invert"
175
176     def draw(self, context):
177         layout = self.layout
178
179         props = layout.operator("image.invert", text="Invert Image Colors")
180         props.invert_r = True
181         props.invert_g = True
182         props.invert_b = True
183
184         layout.separator()
185
186         props = layout.operator("image.invert", text="Invert Red Channel")
187         props.invert_r = True
188
189         props = layout.operator("image.invert", text="Invert Green Channel")
190         props.invert_g = True
191
192         props = layout.operator("image.invert", text="Invert Blue Channel")
193         props.invert_b = True
194
195         props = layout.operator("image.invert", text="Invert Alpha Channel")
196         props.invert_a = True
197
198
199 class IMAGE_MT_uvs_showhide(Menu):
200     bl_label = "Show/Hide Faces"
201
202     def draw(self, context):
203         layout = self.layout
204
205         layout.operator("uv.reveal")
206         layout.operator("uv.hide", text="Hide Selected").unselected = False
207         layout.operator("uv.hide", text="Hide Unselected").unselected = True
208
209
210 class IMAGE_MT_uvs_transform(Menu):
211     bl_label = "Transform"
212
213     def draw(self, context):
214         layout = self.layout
215
216         layout.operator("transform.translate")
217         layout.operator("transform.rotate")
218         layout.operator("transform.resize")
219
220         layout.separator()
221
222         layout.operator("transform.shear")
223
224
225 class IMAGE_MT_uvs_snap(Menu):
226     bl_label = "Snap"
227
228     def draw(self, context):
229         layout = self.layout
230
231         layout.operator_context = 'EXEC_REGION_WIN'
232
233         layout.operator("uv.snap_selected", text="Selected to Pixels").target = 'PIXELS'
234         layout.operator("uv.snap_selected", text="Selected to Cursor").target = 'CURSOR'
235         layout.operator("uv.snap_selected", text="Selected to Cursor (Offset)").target = 'CURSOR_OFFSET'
236         layout.operator("uv.snap_selected", text="Selected to Adjacent Unselected").target = 'ADJACENT_UNSELECTED'
237
238         layout.separator()
239
240         layout.operator("uv.snap_cursor", text="Cursor to Pixels").target = 'PIXELS'
241         layout.operator("uv.snap_cursor", text="Cursor to Selected").target = 'SELECTED'
242
243
244 class IMAGE_MT_uvs_mirror(Menu):
245     bl_label = "Mirror"
246
247     def draw(self, context):
248         layout = self.layout
249
250         layout.operator_context = 'EXEC_REGION_WIN'
251
252         layout.operator("transform.mirror", text="X Axis").constraint_axis[0] = True
253         layout.operator("transform.mirror", text="Y Axis").constraint_axis[1] = True
254
255
256 class IMAGE_MT_uvs_weldalign(Menu):
257     bl_label = "Weld/Align"
258
259     def draw(self, context):
260         layout = self.layout
261
262         layout.operator("uv.weld")  # W, 1
263         layout.operator("uv.remove_doubles")
264         layout.operator_enum("uv.align", "axis")  # W, 2/3/4
265
266
267 class IMAGE_MT_uvs(Menu):
268     bl_label = "UVs"
269
270     def draw(self, context):
271         layout = self.layout
272
273         sima = context.space_data
274         uv = sima.uv_editor
275         toolsettings = context.tool_settings
276
277         layout.prop(uv, "use_snap_to_pixels")
278         layout.prop(uv, "lock_bounds")
279
280         layout.separator()
281
282         layout.prop(toolsettings, "use_uv_sculpt")
283
284         layout.separator()
285
286         layout.prop(uv, "use_live_unwrap")
287         layout.operator("uv.unwrap")
288         layout.operator("uv.pin", text="Unpin").clear = True
289         layout.operator("uv.pin")
290
291         layout.separator()
292
293         layout.operator("uv.pack_islands")
294         layout.operator("uv.average_islands_scale")
295         layout.operator("uv.minimize_stretch")
296         layout.operator("uv.stitch")
297         layout.operator("uv.mark_seam")
298         layout.operator("uv.seams_from_islands")
299         layout.operator("mesh.faces_mirror_uv")
300
301         layout.separator()
302
303         layout.menu("IMAGE_MT_uvs_transform")
304         layout.menu("IMAGE_MT_uvs_mirror")
305         layout.menu("IMAGE_MT_uvs_snap")
306         layout.menu("IMAGE_MT_uvs_weldalign")
307
308         layout.separator()
309
310         layout.prop_menu_enum(toolsettings, "proportional_edit")
311         layout.prop_menu_enum(toolsettings, "proportional_edit_falloff")
312
313         layout.separator()
314
315         layout.menu("IMAGE_MT_uvs_showhide")
316
317
318 class IMAGE_MT_uvs_select_mode(Menu):
319     bl_label = "UV Select Mode"
320
321     def draw(self, context):
322         layout = self.layout
323
324         layout.operator_context = 'INVOKE_REGION_WIN'
325         toolsettings = context.tool_settings
326
327         # do smart things depending on whether uv_select_sync is on
328
329         if toolsettings.use_uv_select_sync:
330             props = layout.operator("wm.context_set_value", text="Vertex", icon='VERTEXSEL')
331             props.value = "(True, False, False)"
332             props.data_path = "tool_settings.mesh_select_mode"
333
334             props = layout.operator("wm.context_set_value", text="Edge", icon='EDGESEL')
335             props.value = "(False, True, False)"
336             props.data_path = "tool_settings.mesh_select_mode"
337
338             props = layout.operator("wm.context_set_value", text="Face", icon='FACESEL')
339             props.value = "(False, False, True)"
340             props.data_path = "tool_settings.mesh_select_mode"
341
342         else:
343             props = layout.operator("wm.context_set_string", text="Vertex", icon='UV_VERTEXSEL')
344             props.value = 'VERTEX'
345             props.data_path = "tool_settings.uv_select_mode"
346
347             props = layout.operator("wm.context_set_string", text="Edge", icon='UV_EDGESEL')
348             props.value = 'EDGE'
349             props.data_path = "tool_settings.uv_select_mode"
350
351             props = layout.operator("wm.context_set_string", text="Face", icon='UV_FACESEL')
352             props.value = 'FACE'
353             props.data_path = "tool_settings.uv_select_mode"
354
355             props = layout.operator("wm.context_set_string", text="Island", icon='UV_ISLANDSEL')
356             props.value = 'ISLAND'
357             props.data_path = "tool_settings.uv_select_mode"
358
359
360 class IMAGE_HT_header(Header):
361     bl_space_type = 'IMAGE_EDITOR'
362
363     def draw(self, context):
364         layout = self.layout
365
366         sima = context.space_data
367         ima = sima.image
368         iuser = sima.image_user
369         toolsettings = context.tool_settings
370         mode = sima.mode
371
372         show_render = sima.show_render
373         # show_paint = sima.show_paint
374         show_uvedit = sima.show_uvedit
375         show_maskedit = sima.show_maskedit
376
377         row = layout.row(align=True)
378         row.template_header()
379
380         # menus
381         if context.area.show_menus:
382             sub = row.row(align=True)
383             sub.menu("IMAGE_MT_view")
384
385             if show_uvedit:
386                 sub.menu("IMAGE_MT_select")
387             if show_maskedit:
388                 sub.menu("MASK_MT_select")
389
390             if ima and ima.is_dirty:
391                 sub.menu("IMAGE_MT_image", text="Image*")
392             else:
393                 sub.menu("IMAGE_MT_image", text="Image")
394
395             if show_uvedit:
396                 sub.menu("IMAGE_MT_uvs")
397             if show_maskedit:
398                 sub.menu("MASK_MT_mask")
399
400         layout.template_ID(sima, "image", new="image.new")
401         if not show_render:
402             layout.prop(sima, "use_image_pin", text="")
403
404         layout.prop(sima, "mode", text="")
405
406         if show_maskedit:
407             row = layout.row()
408             row.template_ID(sima, "mask", new="mask.new")
409
410         if show_uvedit or show_maskedit:
411             layout.prop(sima, "pivot_point", text="", icon_only=True)
412
413         # uv editing
414         if show_uvedit:
415             uvedit = sima.uv_editor
416
417             layout.prop(toolsettings, "use_uv_select_sync", text="")
418
419             if toolsettings.use_uv_select_sync:
420                 layout.template_edit_mode_selection()
421             else:
422                 layout.prop(toolsettings, "uv_select_mode", text="", expand=True)
423                 layout.prop(uvedit, "sticky_select_mode", text="", icon_only=True)
424
425             row = layout.row(align=True)
426             row.prop(toolsettings, "proportional_edit", text="", icon_only=True)
427             if toolsettings.proportional_edit != 'DISABLED':
428                 row.prop(toolsettings, "proportional_edit_falloff", text="", icon_only=True)
429
430             row = layout.row(align=True)
431             row.prop(toolsettings, "use_snap", text="")
432             row.prop(toolsettings, "snap_uv_element", text="", icon_only=True)
433             if toolsettings.snap_uv_element != 'INCREMENT':
434                 row.prop(toolsettings, "snap_target", text="")
435
436             mesh = context.edit_object.data
437             layout.prop_search(mesh.uv_textures, "active", mesh, "uv_textures", text="")
438
439         if ima:
440             # layers
441             layout.template_image_layers(ima, iuser)
442
443             # draw options
444             row = layout.row(align=True)
445             row.prop(sima, "draw_channels", text="", expand=True)
446
447             row = layout.row(align=True)
448             if ima.type == 'COMPOSITE':
449                 row.operator("image.record_composite", icon='REC')
450             if ima.type == 'COMPOSITE' and ima.source in {'MOVIE', 'SEQUENCE'}:
451                 row.operator("image.play_composite", icon='PLAY')
452
453         if show_uvedit or show_maskedit or mode == 'PAINT':
454             layout.prop(sima, "use_realtime_update", text="", icon_only=True, icon='LOCKED')
455
456
457 class IMAGE_PT_image_properties(Panel):
458     bl_space_type = 'IMAGE_EDITOR'
459     bl_region_type = 'UI'
460     bl_label = "Image"
461
462     @classmethod
463     def poll(cls, context):
464         sima = context.space_data
465         return (sima.image)
466
467     def draw(self, context):
468         layout = self.layout
469
470         sima = context.space_data
471         iuser = sima.image_user
472
473         layout.template_image(sima, "image", iuser)
474
475
476 class IMAGE_PT_game_properties(Panel):
477     bl_space_type = 'IMAGE_EDITOR'
478     bl_region_type = 'UI'
479     bl_label = "Game Properties"
480
481     @classmethod
482     def poll(cls, context):
483         sima = context.space_data
484         # display even when not in game mode because these settings effect the 3d view
485         return (sima and sima.image)  # and (rd.engine == 'BLENDER_GAME')
486
487     def draw(self, context):
488         layout = self.layout
489
490         sima = context.space_data
491         ima = sima.image
492
493         split = layout.split()
494
495         col = split.column()
496         col.prop(ima, "use_animation")
497         sub = col.column(align=True)
498         sub.active = ima.use_animation
499         sub.prop(ima, "frame_start", text="Start")
500         sub.prop(ima, "frame_end", text="End")
501         sub.prop(ima, "fps", text="Speed")
502
503         col.prop(ima, "use_tiles")
504         sub = col.column(align=True)
505         sub.active = ima.use_tiles or ima.use_animation
506         sub.prop(ima, "tiles_x", text="X")
507         sub.prop(ima, "tiles_y", text="Y")
508
509         col = split.column()
510         col.label(text="Clamp:")
511         col.prop(ima, "use_clamp_x", text="X")
512         col.prop(ima, "use_clamp_y", text="Y")
513         col.separator()
514         col.prop(ima, "mapping", expand=True)
515
516
517 class IMAGE_PT_view_histogram(Panel):
518     bl_space_type = 'IMAGE_EDITOR'
519     bl_region_type = 'PREVIEW'
520     bl_label = "Histogram"
521
522     @classmethod
523     def poll(cls, context):
524         sima = context.space_data
525         return (sima and sima.image)
526
527     def draw(self, context):
528         layout = self.layout
529
530         sima = context.space_data
531         hist = sima.scopes.histogram
532
533         layout.template_histogram(sima.scopes, "histogram")
534         row = layout.row(align=True)
535         row.prop(hist, "mode", icon_only=True, expand=True)
536         row.prop(hist, "show_line", text="")
537
538
539 class IMAGE_PT_view_waveform(Panel):
540     bl_space_type = 'IMAGE_EDITOR'
541     bl_region_type = 'PREVIEW'
542     bl_label = "Waveform"
543
544     @classmethod
545     def poll(cls, context):
546         sima = context.space_data
547         return (sima and sima.image)
548
549     def draw(self, context):
550         layout = self.layout
551
552         sima = context.space_data
553
554         layout.template_waveform(sima, "scopes")
555         row = layout.split(percentage=0.75)
556         row.prop(sima.scopes, "waveform_alpha")
557         row.prop(sima.scopes, "waveform_mode", text="", icon_only=True)
558
559
560 class IMAGE_PT_view_vectorscope(Panel):
561     bl_space_type = 'IMAGE_EDITOR'
562     bl_region_type = 'PREVIEW'
563     bl_label = "Vectorscope"
564
565     @classmethod
566     def poll(cls, context):
567         sima = context.space_data
568         return (sima and sima.image)
569
570     def draw(self, context):
571         layout = self.layout
572
573         sima = context.space_data
574         layout.template_vectorscope(sima, "scopes")
575         layout.prop(sima.scopes, "vectorscope_alpha")
576
577
578 class IMAGE_PT_sample_line(Panel):
579     bl_space_type = 'IMAGE_EDITOR'
580     bl_region_type = 'PREVIEW'
581     bl_label = "Sample Line"
582
583     @classmethod
584     def poll(cls, context):
585         sima = context.space_data
586         return (sima and sima.image)
587
588     def draw(self, context):
589         layout = self.layout
590
591         sima = context.space_data
592         hist = sima.sample_histogram
593
594         layout.operator("image.sample_line")
595         layout.template_histogram(sima, "sample_histogram")
596         row = layout.row(align=True)
597         row.prop(hist, "mode", expand=True)
598         row.prop(hist, "show_line", text="")
599
600
601 class IMAGE_PT_scope_sample(Panel):
602     bl_space_type = 'IMAGE_EDITOR'
603     bl_region_type = 'PREVIEW'
604     bl_label = "Scope Samples"
605
606     @classmethod
607     def poll(cls, context):
608         sima = context.space_data
609         return sima
610
611     def draw(self, context):
612         layout = self.layout
613
614         sima = context.space_data
615
616         row = layout.row()
617         row.prop(sima.scopes, "use_full_resolution")
618         sub = row.row()
619         sub.active = not sima.scopes.use_full_resolution
620         sub.prop(sima.scopes, "accuracy")
621
622
623 class IMAGE_PT_view_properties(Panel):
624     bl_space_type = 'IMAGE_EDITOR'
625     bl_region_type = 'UI'
626     bl_label = "Display"
627
628     @classmethod
629     def poll(cls, context):
630         sima = context.space_data
631         return (sima and (sima.image or sima.show_uvedit))
632
633     def draw(self, context):
634         layout = self.layout
635
636         sima = context.space_data
637         ima = sima.image
638         show_uvedit = sima.show_uvedit
639         show_maskedit = sima.show_maskedit
640         uvedit = sima.uv_editor
641
642         split = layout.split()
643
644         col = split.column()
645         if ima:
646             col.prop(ima, "display_aspect", text="Aspect Ratio")
647
648             col = split.column()
649             col.label(text="Coordinates:")
650             col.prop(sima, "show_repeat", text="Repeat")
651             if show_uvedit:
652                 col.prop(uvedit, "show_normalized_coords", text="Normalized")
653
654         elif show_uvedit:
655             col.label(text="Coordinates:")
656             col.prop(uvedit, "show_normalized_coords", text="Normalized")
657
658         if show_uvedit or show_maskedit:
659             col = layout.column()
660             col.label("Cursor Location:")
661             col.row().prop(sima, "cursor_location", text="")
662
663         if show_uvedit:
664             col.separator()
665
666             col.label(text="UVs:")
667             col.row().prop(uvedit, "edge_draw_type", expand=True)
668
669             split = layout.split()
670
671             col = split.column()
672             col.prop(uvedit, "show_faces")
673             col.prop(uvedit, "show_smooth_edges", text="Smooth")
674             col.prop(uvedit, "show_modified_edges", text="Modified")
675
676             col = split.column()
677             col.prop(uvedit, "show_stretch", text="Stretch")
678             sub = col.column()
679             sub.active = uvedit.show_stretch
680             sub.row().prop(uvedit, "draw_stretch_type", expand=True)
681
682
683 class IMAGE_PT_paint(Panel, ImagePaintPanel):
684     bl_space_type = 'IMAGE_EDITOR'
685     bl_region_type = 'UI'
686     bl_label = "Paint"
687
688     @classmethod
689     def poll(cls, context):
690         sima = context.space_data
691         return sima.show_paint
692
693     def draw(self, context):
694         layout = self.layout
695
696         toolsettings = context.tool_settings.image_paint
697         brush = toolsettings.brush
698
699         col = layout.column()
700         col.template_ID_preview(toolsettings, "brush", new="brush.add", rows=2, cols=6)
701
702         if brush:
703             col = layout.column()
704
705             if brush.image_tool == 'DRAW' and brush.blend not in ('ERASE_ALPHA', 'ADD_ALPHA'):
706                 col.template_color_picker(brush, "color", value_slider=True)
707                 col.prop(brush, "color", text="")
708
709             row = col.row(align=True)
710             self.prop_unified_size(row, context, brush, "size", slider=True, text="Radius")
711             self.prop_unified_size(row, context, brush, "use_pressure_size")
712
713             row = col.row(align=True)
714             self.prop_unified_strength(row, context, brush, "strength", slider=True, text="Strength")
715             self.prop_unified_strength(row, context, brush, "use_pressure_strength")
716
717             row = col.row(align=True)
718
719             col.prop(brush, "blend", text="Blend")
720
721             if brush.image_tool == 'CLONE':
722                 col.separator()
723                 col.prop(brush, "clone_image", text="Image")
724                 col.prop(brush, "clone_alpha", text="Alpha")
725
726
727 class IMAGE_PT_tools_brush_texture(BrushButtonsPanel, Panel):
728     bl_label = "Texture"
729     bl_options = {'DEFAULT_CLOSED'}
730
731     def draw(self, context):
732         layout = self.layout
733
734         toolsettings = context.tool_settings.image_paint
735         brush = toolsettings.brush
736         tex_slot = brush.texture_slot
737
738         col = layout.column()
739         col.template_ID_preview(brush, "texture", new="texture.new", rows=3, cols=8)
740
741         brush_texture_settings(col, brush, 0)
742
743         # use_texture_overlay and texture_overlay_alpha
744         col = layout.column(align=True)
745         col.active = brush.brush_capabilities.has_overlay
746         col.label(text="Overlay:")
747
748         row = col.row()
749         if tex_slot.map_mode != 'STENCIL':
750             if brush.use_primary_overlay:
751                 row.prop(brush, "use_primary_overlay", toggle=True, text="", icon='RESTRICT_VIEW_OFF')
752             else:
753                 row.prop(brush, "use_primary_overlay", toggle=True, text="", icon='RESTRICT_VIEW_ON')
754
755         sub = row.row()
756         sub.prop(brush, "texture_overlay_alpha", text="Alpha")
757         sub.prop(brush, "use_primary_overlay_override", toggle=True, text="", icon='BRUSH_DATA')
758
759
760 class IMAGE_PT_tools_mask_texture(BrushButtonsPanel, Panel):
761     bl_label = "Texture Mask"
762     bl_options = {'DEFAULT_CLOSED'}
763
764     def draw(self, context):
765         layout = self.layout
766
767         brush = context.tool_settings.image_paint.brush
768         tex_slot_alpha = brush.mask_texture_slot
769
770         col = layout.column()
771
772         col.template_ID_preview(brush, "mask_texture", new="texture.new", rows=3, cols=8)
773
774         brush_mask_texture_settings(col, brush)
775
776         col = layout.column(align=True)
777         col.active = brush.brush_capabilities.has_overlay
778         col.label(text="Overlay:")
779
780         row = col.row()
781         if tex_slot_alpha.map_mode != 'STENCIL':
782             if brush.use_secondary_overlay:
783                 row.prop(brush, "use_secondary_overlay", toggle=True, text="", icon='RESTRICT_VIEW_OFF')
784             else:
785                 row.prop(brush, "use_secondary_overlay", toggle=True, text="", icon='RESTRICT_VIEW_ON')
786
787         sub = row.row()
788         sub.prop(brush, "mask_overlay_alpha", text="Alpha")
789         sub.prop(brush, "use_secondary_overlay_override", toggle=True, text="", icon='BRUSH_DATA')
790
791
792 class IMAGE_PT_tools_brush_tool(BrushButtonsPanel, Panel):
793     bl_label = "Tool"
794     bl_options = {'DEFAULT_CLOSED'}
795
796     def draw(self, context):
797         layout = self.layout
798         toolsettings = context.tool_settings.image_paint
799         brush = toolsettings.brush
800
801         layout.prop(brush, "image_tool", text="")
802
803         row = layout.row(align=True)
804         row.prop(brush, "use_paint_sculpt", text="", icon='SCULPTMODE_HLT')
805         row.prop(brush, "use_paint_vertex", text="", icon='VPAINT_HLT')
806         row.prop(brush, "use_paint_weight", text="", icon='WPAINT_HLT')
807         row.prop(brush, "use_paint_image", text="", icon='TPAINT_HLT')
808
809
810 class IMAGE_PT_paint_stroke(BrushButtonsPanel, Panel):
811     bl_label = "Paint Stroke"
812     bl_options = {'DEFAULT_CLOSED'}
813
814     def draw(self, context):
815         layout = self.layout
816
817         toolsettings = context.tool_settings.image_paint
818         brush = toolsettings.brush
819
820         col = layout.column()
821         col.prop(toolsettings, "input_samples")
822
823         col = layout.column()
824
825         col.label(text="Stroke Method:")
826
827         col.prop(brush, "stroke_method", text="")
828
829         if brush.use_anchor:
830             col.separator()
831             col.prop(brush, "use_edge_to_edge", "Edge To Edge")
832
833         if brush.use_airbrush:
834             col.separator()
835             col.prop(brush, "rate", text="Rate", slider=True)
836
837         if brush.use_space:
838             col.separator()
839             row = col.row(align=True)
840             row.active = brush.use_space
841             row.prop(brush, "spacing", text="Spacing")
842             row.prop(brush, "use_pressure_spacing", toggle=True, text="")
843
844         col = layout.column()
845         col.separator()
846
847         col.prop(brush, "use_smooth_stroke")
848
849         sub = col.column()
850         sub.active = brush.use_smooth_stroke
851         sub.prop(brush, "smooth_stroke_radius", text="Radius", slider=True)
852         sub.prop(brush, "smooth_stroke_factor", text="Factor", slider=True)
853
854         col.separator()
855
856         row = col.row(align=True)
857         if brush.use_relative_jitter:
858             row.prop(brush, "use_relative_jitter", text="", icon='LOCKED')
859             row.prop(brush, "jitter", slider=True)
860         else:
861             row.prop(brush, "use_relative_jitter", text="", icon='UNLOCKED')
862             row.prop(brush, "jitter_absolute")
863         row.prop(brush, "use_pressure_jitter", toggle=True, text="")
864
865         col.prop(brush, "use_wrap")
866
867
868 class IMAGE_PT_paint_curve(BrushButtonsPanel, Panel):
869     bl_label = "Paint Curve"
870     bl_options = {'DEFAULT_CLOSED'}
871
872     def draw(self, context):
873         layout = self.layout
874
875         toolsettings = context.tool_settings.image_paint
876         brush = toolsettings.brush
877
878         layout.template_curve_mapping(brush, "curve")
879
880         row = layout.row(align=True)
881         row.operator("brush.curve_preset", icon='SMOOTHCURVE', text="").shape = 'SMOOTH'
882         row.operator("brush.curve_preset", icon='SPHERECURVE', text="").shape = 'ROUND'
883         row.operator("brush.curve_preset", icon='ROOTCURVE', text="").shape = 'ROOT'
884         row.operator("brush.curve_preset", icon='SHARPCURVE', text="").shape = 'SHARP'
885         row.operator("brush.curve_preset", icon='LINCURVE', text="").shape = 'LINE'
886         row.operator("brush.curve_preset", icon='NOCURVE', text="").shape = 'MAX'
887
888
889 class IMAGE_PT_tools_brush_appearance(BrushButtonsPanel, Panel):
890     bl_label = "Appearance"
891     bl_options = {'DEFAULT_CLOSED'}
892
893     def draw(self, context):
894         layout = self.layout
895
896         toolsettings = context.tool_settings.image_paint
897         brush = toolsettings.brush
898
899         if brush is None:  # unlikely but can happen
900             layout.label(text="Brush Unset")
901             return
902
903         col = layout.column()
904         col.prop(toolsettings, "show_brush")
905
906         col = col.column()
907         col.prop(brush, "cursor_color_add", text="")
908         col.active = toolsettings.show_brush
909
910         layout.separator()
911
912         col = layout.column(align=True)
913         col.prop(brush, "use_custom_icon")
914         if brush.use_custom_icon:
915             col.prop(brush, "icon_filepath", text="")
916
917
918 class IMAGE_UV_sculpt_curve(Panel):
919     bl_space_type = 'IMAGE_EDITOR'
920     bl_region_type = 'UI'
921     bl_label = "UV Sculpt Curve"
922     bl_options = {'DEFAULT_CLOSED'}
923
924     @classmethod
925     def poll(cls, context):
926         sima = context.space_data
927         toolsettings = context.tool_settings.image_paint
928         return sima.show_uvedit and context.tool_settings.use_uv_sculpt and not (sima.show_paint and toolsettings.brush)
929
930     def draw(self, context):
931         layout = self.layout
932
933         toolsettings = context.tool_settings
934         uvsculpt = toolsettings.uv_sculpt
935         brush = uvsculpt.brush
936
937         layout.template_curve_mapping(brush, "curve")
938
939         row = layout.row(align=True)
940         row.operator("brush.curve_preset", icon='SMOOTHCURVE', text="").shape = 'SMOOTH'
941         row.operator("brush.curve_preset", icon='SPHERECURVE', text="").shape = 'ROUND'
942         row.operator("brush.curve_preset", icon='ROOTCURVE', text="").shape = 'ROOT'
943         row.operator("brush.curve_preset", icon='SHARPCURVE', text="").shape = 'SHARP'
944         row.operator("brush.curve_preset", icon='LINCURVE', text="").shape = 'LINE'
945         row.operator("brush.curve_preset", icon='NOCURVE', text="").shape = 'MAX'
946
947
948 class IMAGE_UV_sculpt(Panel, ImagePaintPanel):
949     bl_space_type = 'IMAGE_EDITOR'
950     bl_region_type = 'UI'
951     bl_label = "UV Sculpt"
952
953     @classmethod
954     def poll(cls, context):
955         sima = context.space_data
956         toolsettings = context.tool_settings.image_paint
957         return sima.show_uvedit and context.tool_settings.use_uv_sculpt and not (sima.show_paint and toolsettings.brush)
958
959     def draw(self, context):
960         layout = self.layout
961
962         toolsettings = context.tool_settings
963         uvsculpt = toolsettings.uv_sculpt
964         brush = uvsculpt.brush
965
966         if brush:
967             col = layout.column()
968
969             row = col.row(align=True)
970             self.prop_unified_size(row, context, brush, "size", slider=True, text="Radius")
971             self.prop_unified_size(row, context, brush, "use_pressure_size")
972
973             row = col.row(align=True)
974             self.prop_unified_strength(row, context, brush, "strength", slider=True, text="Strength")
975             self.prop_unified_strength(row, context, brush, "use_pressure_strength")
976
977         col = layout.column()
978         col.prop(toolsettings, "uv_sculpt_lock_borders")
979         col.prop(toolsettings, "uv_sculpt_all_islands")
980         col.prop(toolsettings, "uv_sculpt_tool")
981
982         if toolsettings.uv_sculpt_tool == 'RELAX':
983             col.prop(toolsettings, "uv_relax_method")
984
985
986 # -----------------------------------------------------------------------------
987 # Mask (similar code in space_clip.py, keep in sync)
988 # note! - panel placement does _not_ fit well with image panels... need to fix
989
990 from bl_ui.properties_mask_common import (MASK_PT_mask,
991                                           MASK_PT_layers,
992                                           MASK_PT_spline,
993                                           MASK_PT_point,
994                                           MASK_PT_display,
995                                           MASK_PT_tools)
996
997
998 class IMAGE_PT_mask(MASK_PT_mask, Panel):
999     bl_space_type = 'IMAGE_EDITOR'
1000     bl_region_type = 'PREVIEW'
1001
1002
1003 class IMAGE_PT_mask_layers(MASK_PT_layers, Panel):
1004     bl_space_type = 'IMAGE_EDITOR'
1005     bl_region_type = 'PREVIEW'
1006
1007
1008 class IMAGE_PT_mask_display(MASK_PT_display, Panel):
1009     bl_space_type = 'IMAGE_EDITOR'
1010     bl_region_type = 'PREVIEW'
1011
1012
1013 class IMAGE_PT_active_mask_spline(MASK_PT_spline, Panel):
1014     bl_space_type = 'IMAGE_EDITOR'
1015     bl_region_type = 'PREVIEW'
1016
1017
1018 class IMAGE_PT_active_mask_point(MASK_PT_point, Panel):
1019     bl_space_type = 'IMAGE_EDITOR'
1020     bl_region_type = 'PREVIEW'
1021
1022
1023 class IMAGE_PT_tools_mask(MASK_PT_tools, Panel):
1024     bl_space_type = 'IMAGE_EDITOR'
1025     bl_region_type = 'UI'  # is 'TOOLS' in the clip editor
1026
1027 # --- end mask ---
1028
1029 if __name__ == "__main__":  # only for live edit.
1030     bpy.utils.register_module(__name__)