More painting fixes:
[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.unlink_selected")
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 Adjacent Unselected").target = 'ADJACENT_UNSELECTED'
236
237         layout.separator()
238
239         layout.operator("uv.snap_cursor", text="Cursor to Pixels").target = 'PIXELS'
240         layout.operator("uv.snap_cursor", text="Cursor to Selected").target = 'SELECTED'
241
242
243 class IMAGE_MT_uvs_mirror(Menu):
244     bl_label = "Mirror"
245
246     def draw(self, context):
247         layout = self.layout
248
249         layout.operator_context = 'EXEC_REGION_WIN'
250
251         layout.operator("transform.mirror", text="X Axis").constraint_axis[0] = True
252         layout.operator("transform.mirror", text="Y Axis").constraint_axis[1] = True
253
254
255 class IMAGE_MT_uvs_weldalign(Menu):
256     bl_label = "Weld/Align"
257
258     def draw(self, context):
259         layout = self.layout
260
261         layout.operator("uv.weld")  # W, 1
262         layout.operator("uv.remove_doubles")
263         layout.operator_enum("uv.align", "axis")  # W, 2/3/4
264
265
266 class IMAGE_MT_uvs(Menu):
267     bl_label = "UVs"
268
269     def draw(self, context):
270         layout = self.layout
271
272         sima = context.space_data
273         uv = sima.uv_editor
274         toolsettings = context.tool_settings
275
276         layout.prop(uv, "use_snap_to_pixels")
277         layout.prop(uv, "lock_bounds")
278
279         layout.separator()
280
281         layout.prop(toolsettings, "use_uv_sculpt")
282
283         layout.separator()
284
285         layout.prop(uv, "use_live_unwrap")
286         layout.operator("uv.unwrap")
287         layout.operator("uv.pin", text="Unpin").clear = True
288         layout.operator("uv.pin")
289
290         layout.separator()
291
292         layout.operator("uv.pack_islands")
293         layout.operator("uv.average_islands_scale")
294         layout.operator("uv.minimize_stretch")
295         layout.operator("uv.stitch")
296         layout.operator("uv.mark_seam")
297         layout.operator("uv.seams_from_islands")
298         layout.operator("mesh.faces_mirror_uv")
299
300         layout.separator()
301
302         layout.menu("IMAGE_MT_uvs_transform")
303         layout.menu("IMAGE_MT_uvs_mirror")
304         layout.menu("IMAGE_MT_uvs_snap")
305         layout.menu("IMAGE_MT_uvs_weldalign")
306
307         layout.separator()
308
309         layout.prop_menu_enum(toolsettings, "proportional_edit")
310         layout.prop_menu_enum(toolsettings, "proportional_edit_falloff")
311
312         layout.separator()
313
314         layout.menu("IMAGE_MT_uvs_showhide")
315
316
317 class IMAGE_MT_uvs_select_mode(Menu):
318     bl_label = "UV Select Mode"
319
320     def draw(self, context):
321         layout = self.layout
322
323         layout.operator_context = 'INVOKE_REGION_WIN'
324         toolsettings = context.tool_settings
325
326         # do smart things depending on whether uv_select_sync is on
327
328         if toolsettings.use_uv_select_sync:
329             props = layout.operator("wm.context_set_value", text="Vertex", icon='VERTEXSEL')
330             props.value = "(True, False, False)"
331             props.data_path = "tool_settings.mesh_select_mode"
332
333             props = layout.operator("wm.context_set_value", text="Edge", icon='EDGESEL')
334             props.value = "(False, True, False)"
335             props.data_path = "tool_settings.mesh_select_mode"
336
337             props = layout.operator("wm.context_set_value", text="Face", icon='FACESEL')
338             props.value = "(False, False, True)"
339             props.data_path = "tool_settings.mesh_select_mode"
340
341         else:
342             props = layout.operator("wm.context_set_string", text="Vertex", icon='UV_VERTEXSEL')
343             props.value = 'VERTEX'
344             props.data_path = "tool_settings.uv_select_mode"
345
346             props = layout.operator("wm.context_set_string", text="Edge", icon='UV_EDGESEL')
347             props.value = 'EDGE'
348             props.data_path = "tool_settings.uv_select_mode"
349
350             props = layout.operator("wm.context_set_string", text="Face", icon='UV_FACESEL')
351             props.value = 'FACE'
352             props.data_path = "tool_settings.uv_select_mode"
353
354             props = layout.operator("wm.context_set_string", text="Island", icon='UV_ISLANDSEL')
355             props.value = 'ISLAND'
356             props.data_path = "tool_settings.uv_select_mode"
357
358
359 class IMAGE_HT_header(Header):
360     bl_space_type = 'IMAGE_EDITOR'
361
362     def draw(self, context):
363         layout = self.layout
364
365         sima = context.space_data
366         ima = sima.image
367         iuser = sima.image_user
368         toolsettings = context.tool_settings
369         mode = sima.mode
370
371         show_render = sima.show_render
372         # show_paint = sima.show_paint
373         show_uvedit = sima.show_uvedit
374         show_maskedit = sima.show_maskedit
375
376         row = layout.row(align=True)
377         row.template_header()
378
379         # menus
380         if context.area.show_menus:
381             sub = row.row(align=True)
382             sub.menu("IMAGE_MT_view")
383
384             if show_uvedit:
385                 sub.menu("IMAGE_MT_select")
386
387             if ima and ima.is_dirty:
388                 sub.menu("IMAGE_MT_image", text="Image*")
389             else:
390                 sub.menu("IMAGE_MT_image", text="Image")
391
392             if show_uvedit:
393                 sub.menu("IMAGE_MT_uvs")
394
395         layout.template_ID(sima, "image", new="image.new")
396         if not show_render:
397             layout.prop(sima, "use_image_pin", text="")
398
399         layout.prop(sima, "mode", text="")
400
401         if show_maskedit:
402             row = layout.row()
403             row.template_ID(sima, "mask", new="mask.new")
404
405         if show_uvedit or show_maskedit:
406             layout.prop(sima, "pivot_point", text="", icon_only=True)
407
408         # uv editing
409         if show_uvedit:
410             uvedit = sima.uv_editor
411
412             layout.prop(toolsettings, "use_uv_select_sync", text="")
413
414             if toolsettings.use_uv_select_sync:
415                 layout.template_edit_mode_selection()
416             else:
417                 layout.prop(toolsettings, "uv_select_mode", text="", expand=True)
418                 layout.prop(uvedit, "sticky_select_mode", text="", icon_only=True)
419
420             row = layout.row(align=True)
421             row.prop(toolsettings, "proportional_edit", text="", icon_only=True)
422             if toolsettings.proportional_edit != 'DISABLED':
423                 row.prop(toolsettings, "proportional_edit_falloff", text="", icon_only=True)
424
425             row = layout.row(align=True)
426             row.prop(toolsettings, "use_snap", text="")
427             row.prop(toolsettings, "snap_uv_element", text="", icon_only=True)
428             if toolsettings.snap_uv_element != 'INCREMENT':
429                 row.prop(toolsettings, "snap_target", text="")
430
431             mesh = context.edit_object.data
432             layout.prop_search(mesh.uv_textures, "active", mesh, "uv_textures", text="")
433
434         if ima:
435             # layers
436             layout.template_image_layers(ima, iuser)
437
438             # draw options
439             row = layout.row(align=True)
440             row.prop(sima, "draw_channels", text="", expand=True)
441
442             row = layout.row(align=True)
443             if ima.type == 'COMPOSITE':
444                 row.operator("image.record_composite", icon='REC')
445             if ima.type == 'COMPOSITE' and ima.source in {'MOVIE', 'SEQUENCE'}:
446                 row.operator("image.play_composite", icon='PLAY')
447
448         if show_uvedit or show_maskedit or mode == 'PAINT':
449             layout.prop(sima, "use_realtime_update", text="", icon_only=True, icon='LOCKED')
450
451
452 class IMAGE_PT_image_properties(Panel):
453     bl_space_type = 'IMAGE_EDITOR'
454     bl_region_type = 'UI'
455     bl_label = "Image"
456
457     @classmethod
458     def poll(cls, context):
459         sima = context.space_data
460         return (sima.image)
461
462     def draw(self, context):
463         layout = self.layout
464
465         sima = context.space_data
466         iuser = sima.image_user
467
468         layout.template_image(sima, "image", iuser)
469
470
471 class IMAGE_PT_game_properties(Panel):
472     bl_space_type = 'IMAGE_EDITOR'
473     bl_region_type = 'UI'
474     bl_label = "Game Properties"
475
476     @classmethod
477     def poll(cls, context):
478         sima = context.space_data
479         # display even when not in game mode because these settings effect the 3d view
480         return (sima and sima.image)  # and (rd.engine == 'BLENDER_GAME')
481
482     def draw(self, context):
483         layout = self.layout
484
485         sima = context.space_data
486         ima = sima.image
487
488         split = layout.split()
489
490         col = split.column()
491         col.prop(ima, "use_animation")
492         sub = col.column(align=True)
493         sub.active = ima.use_animation
494         sub.prop(ima, "frame_start", text="Start")
495         sub.prop(ima, "frame_end", text="End")
496         sub.prop(ima, "fps", text="Speed")
497
498         col.prop(ima, "use_tiles")
499         sub = col.column(align=True)
500         sub.active = ima.use_tiles or ima.use_animation
501         sub.prop(ima, "tiles_x", text="X")
502         sub.prop(ima, "tiles_y", text="Y")
503
504         col = split.column()
505         col.label(text="Clamp:")
506         col.prop(ima, "use_clamp_x", text="X")
507         col.prop(ima, "use_clamp_y", text="Y")
508         col.separator()
509         col.prop(ima, "mapping", expand=True)
510
511
512 class IMAGE_PT_view_histogram(Panel):
513     bl_space_type = 'IMAGE_EDITOR'
514     bl_region_type = 'PREVIEW'
515     bl_label = "Histogram"
516
517     @classmethod
518     def poll(cls, context):
519         sima = context.space_data
520         return (sima and sima.image)
521
522     def draw(self, context):
523         layout = self.layout
524
525         sima = context.space_data
526         hist = sima.scopes.histogram
527
528         layout.template_histogram(sima.scopes, "histogram")
529         row = layout.row(align=True)
530         row.prop(hist, "mode", icon_only=True, expand=True)
531         row.prop(hist, "show_line", text="")
532
533
534 class IMAGE_PT_view_waveform(Panel):
535     bl_space_type = 'IMAGE_EDITOR'
536     bl_region_type = 'PREVIEW'
537     bl_label = "Waveform"
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.template_waveform(sima, "scopes")
550         row = layout.split(percentage=0.75)
551         row.prop(sima.scopes, "waveform_alpha")
552         row.prop(sima.scopes, "waveform_mode", text="", icon_only=True)
553
554
555 class IMAGE_PT_view_vectorscope(Panel):
556     bl_space_type = 'IMAGE_EDITOR'
557     bl_region_type = 'PREVIEW'
558     bl_label = "Vectorscope"
559
560     @classmethod
561     def poll(cls, context):
562         sima = context.space_data
563         return (sima and sima.image)
564
565     def draw(self, context):
566         layout = self.layout
567
568         sima = context.space_data
569         layout.template_vectorscope(sima, "scopes")
570         layout.prop(sima.scopes, "vectorscope_alpha")
571
572
573 class IMAGE_PT_sample_line(Panel):
574     bl_space_type = 'IMAGE_EDITOR'
575     bl_region_type = 'PREVIEW'
576     bl_label = "Sample Line"
577
578     @classmethod
579     def poll(cls, context):
580         sima = context.space_data
581         return (sima and sima.image)
582
583     def draw(self, context):
584         layout = self.layout
585
586         sima = context.space_data
587         hist = sima.sample_histogram
588
589         layout.operator("image.sample_line")
590         layout.template_histogram(sima, "sample_histogram")
591         row = layout.row(align=True)
592         row.prop(hist, "mode", expand=True)
593         row.prop(hist, "show_line", text="")
594
595
596 class IMAGE_PT_scope_sample(Panel):
597     bl_space_type = 'IMAGE_EDITOR'
598     bl_region_type = 'PREVIEW'
599     bl_label = "Scope Samples"
600
601     @classmethod
602     def poll(cls, context):
603         sima = context.space_data
604         return sima
605
606     def draw(self, context):
607         layout = self.layout
608
609         sima = context.space_data
610
611         row = layout.row()
612         row.prop(sima.scopes, "use_full_resolution")
613         sub = row.row()
614         sub.active = not sima.scopes.use_full_resolution
615         sub.prop(sima.scopes, "accuracy")
616
617
618 class IMAGE_PT_view_properties(Panel):
619     bl_space_type = 'IMAGE_EDITOR'
620     bl_region_type = 'UI'
621     bl_label = "Display"
622
623     @classmethod
624     def poll(cls, context):
625         sima = context.space_data
626         return (sima and (sima.image or sima.show_uvedit))
627
628     def draw(self, context):
629         layout = self.layout
630
631         sima = context.space_data
632         ima = sima.image
633         show_uvedit = sima.show_uvedit
634         show_maskedit = sima.show_maskedit
635         uvedit = sima.uv_editor
636
637         split = layout.split()
638
639         col = split.column()
640         if ima:
641             col.prop(ima, "display_aspect", text="Aspect Ratio")
642
643             col = split.column()
644             col.label(text="Coordinates:")
645             col.prop(sima, "show_repeat", text="Repeat")
646             if show_uvedit:
647                 col.prop(uvedit, "show_normalized_coords", text="Normalized")
648
649         elif show_uvedit:
650             col.label(text="Coordinates:")
651             col.prop(uvedit, "show_normalized_coords", text="Normalized")
652
653         if show_uvedit or show_maskedit:
654             col = layout.column()
655             col.label("Cursor Location:")
656             col.row().prop(sima, "cursor_location", text="")
657
658         if show_uvedit:
659             col.separator()
660
661             col.label(text="UVs:")
662             col.row().prop(uvedit, "edge_draw_type", expand=True)
663
664             split = layout.split()
665
666             col = split.column()
667             col.prop(uvedit, "show_faces")
668             col.prop(uvedit, "show_smooth_edges", text="Smooth")
669             col.prop(uvedit, "show_modified_edges", text="Modified")
670
671             col = split.column()
672             col.prop(uvedit, "show_stretch", text="Stretch")
673             sub = col.column()
674             sub.active = uvedit.show_stretch
675             sub.row().prop(uvedit, "draw_stretch_type", expand=True)
676
677
678 class IMAGE_PT_paint(Panel, ImagePaintPanel):
679     bl_space_type = 'IMAGE_EDITOR'
680     bl_region_type = 'UI'
681     bl_label = "Paint"
682
683     @classmethod
684     def poll(cls, context):
685         sima = context.space_data
686         return sima.show_paint
687
688     def draw(self, context):
689         layout = self.layout
690
691         toolsettings = context.tool_settings.image_paint
692         brush = toolsettings.brush
693
694         col = layout.column()
695         col.template_ID_preview(toolsettings, "brush", new="brush.add", rows=2, cols=6)
696
697         if brush:
698             col = layout.column()
699
700             if brush.image_tool == 'DRAW' and brush.blend not in ('ERASE_ALPHA', 'ADD_ALPHA'):
701                 col.template_color_picker(brush, "color", value_slider=True)
702                 col.prop(brush, "color", text="")
703
704             row = col.row(align=True)
705             self.prop_unified_size(row, context, brush, "size", slider=True, text="Radius")
706             self.prop_unified_size(row, context, brush, "use_pressure_size")
707
708             row = col.row(align=True)
709             self.prop_unified_strength(row, context, brush, "strength", slider=True, text="Strength")
710             self.prop_unified_strength(row, context, brush, "use_pressure_strength")
711
712             row = col.row(align=True)
713
714             col.prop(brush, "blend", text="Blend")
715
716             if brush.image_tool == 'CLONE':
717                 col.separator()
718                 col.prop(brush, "clone_image", text="Image")
719                 col.prop(brush, "clone_alpha", text="Alpha")
720
721
722 class IMAGE_PT_tools_brush_texture(BrushButtonsPanel, Panel):
723     bl_label = "Texture"
724     bl_options = {'DEFAULT_CLOSED'}
725
726     def draw(self, context):
727         layout = self.layout
728
729         toolsettings = context.tool_settings.image_paint
730         brush = toolsettings.brush
731         tex_slot = brush.texture_slot
732
733         col = layout.column()
734         col.template_ID_preview(brush, "texture", new="texture.new", rows=3, cols=8)
735
736         brush_texture_settings(col, brush, 0)
737
738         # use_texture_overlay and texture_overlay_alpha
739         col = layout.column(align=True)
740         col.active = brush.brush_capabilities.has_overlay
741         col.label(text="Overlay:")
742
743         row = col.row()
744         if tex_slot.map_mode != 'STENCIL':
745             if brush.use_primary_overlay:
746                 row.prop(brush, "use_primary_overlay", toggle=True, text="", icon='RESTRICT_VIEW_OFF')
747             else:
748                 row.prop(brush, "use_primary_overlay", toggle=True, text="", icon='RESTRICT_VIEW_ON')
749
750         sub = row.row()
751         sub.prop(brush, "texture_overlay_alpha", text="Alpha")
752         sub.prop(brush, "use_primary_overlay_override", toggle=True, text="", icon='BRUSH_DATA')
753
754
755
756 class IMAGE_PT_tools_mask_texture(BrushButtonsPanel, Panel):
757     bl_label = "Texture Mask"
758     bl_options = {'DEFAULT_CLOSED'}
759
760     def draw(self, context):
761         layout = self.layout
762
763         brush = context.tool_settings.image_paint.brush
764         tex_slot_alpha = brush.mask_texture_slot
765
766         col = layout.column()
767
768         col.template_ID_preview(brush, "mask_texture", new="texture.new", rows=3, cols=8)
769
770         brush_mask_texture_settings(col, brush)
771
772         col = layout.column(align=True)
773         col.active = brush.brush_capabilities.has_overlay
774         col.label(text="Overlay:")
775
776         row = col.row()
777         if tex_slot_alpha.map_mode != 'STENCIL':
778             if brush.use_secondary_overlay:
779                 row.prop(brush, "use_secondary_overlay", toggle=True, text="", icon='RESTRICT_VIEW_OFF')
780             else:
781                 row.prop(brush, "use_secondary_overlay", toggle=True, text="", icon='RESTRICT_VIEW_ON')
782         
783         sub = row.row()
784         sub.prop(brush, "mask_overlay_alpha", text="Alpha")
785         sub.prop(brush, "use_secondary_overlay_override", toggle=True, text="", icon='BRUSH_DATA')
786
787
788 class IMAGE_PT_tools_brush_tool(BrushButtonsPanel, Panel):
789     bl_label = "Tool"
790     bl_options = {'DEFAULT_CLOSED'}
791
792     def draw(self, context):
793         layout = self.layout
794         toolsettings = context.tool_settings.image_paint
795         brush = toolsettings.brush
796
797         layout.prop(brush, "image_tool", text="")
798
799         row = layout.row(align=True)
800         row.prop(brush, "use_paint_sculpt", text="", icon='SCULPTMODE_HLT')
801         row.prop(brush, "use_paint_vertex", text="", icon='VPAINT_HLT')
802         row.prop(brush, "use_paint_weight", text="", icon='WPAINT_HLT')
803         row.prop(brush, "use_paint_image", text="", icon='TPAINT_HLT')
804
805
806 class IMAGE_PT_paint_stroke(BrushButtonsPanel, Panel):
807     bl_label = "Paint Stroke"
808     bl_options = {'DEFAULT_CLOSED'}
809
810     def draw(self, context):
811         layout = self.layout
812
813         toolsettings = context.tool_settings.image_paint
814         brush = toolsettings.brush
815
816         col = layout.column()
817         col.prop(toolsettings, "input_samples")
818
819         col = layout.column()
820
821         col.label(text="Stroke Method:")
822
823         col.prop(brush, "stroke_method", text="")
824
825         if brush.use_anchor:
826             col.separator()
827             col.prop(brush, "use_edge_to_edge", "Edge To Edge")
828
829         if brush.use_airbrush:
830             col.separator()
831             col.prop(brush, "rate", text="Rate", slider=True)
832
833         if brush.use_space:
834             col.separator()
835             row = col.row(align=True)
836             row.active = brush.use_space
837             row.prop(brush, "spacing", text="Spacing")
838             row.prop(brush, "use_pressure_spacing", toggle=True, text="")
839
840         col = layout.column()
841         col.separator()
842
843         col.prop(brush, "use_smooth_stroke")
844
845         sub = col.column()
846         sub.active = brush.use_smooth_stroke
847         sub.prop(brush, "smooth_stroke_radius", text="Radius", slider=True)
848         sub.prop(brush, "smooth_stroke_factor", text="Factor", slider=True)
849
850         col.separator()
851
852         row = col.row(align=True)
853         if brush.use_relative_jitter:
854             row.prop(brush, "use_relative_jitter", text="", icon='LOCKED')
855             row.prop(brush, "jitter", slider=True)
856         else:
857             row.prop(brush, "use_relative_jitter", text="", icon='UNLOCKED')
858             row.prop(brush, "jitter_absolute")
859         row.prop(brush, "use_pressure_jitter", toggle=True, text="")
860
861         col.prop(brush, "use_wrap")
862
863
864 class IMAGE_PT_paint_curve(BrushButtonsPanel, Panel):
865     bl_label = "Paint Curve"
866     bl_options = {'DEFAULT_CLOSED'}
867
868     def draw(self, context):
869         layout = self.layout
870
871         toolsettings = context.tool_settings.image_paint
872         brush = toolsettings.brush
873
874         layout.template_curve_mapping(brush, "curve")
875
876         row = layout.row(align=True)
877         row.operator("brush.curve_preset", icon='SMOOTHCURVE', text="").shape = 'SMOOTH'
878         row.operator("brush.curve_preset", icon='SPHERECURVE', text="").shape = 'ROUND'
879         row.operator("brush.curve_preset", icon='ROOTCURVE', text="").shape = 'ROOT'
880         row.operator("brush.curve_preset", icon='SHARPCURVE', text="").shape = 'SHARP'
881         row.operator("brush.curve_preset", icon='LINCURVE', text="").shape = 'LINE'
882         row.operator("brush.curve_preset", icon='NOCURVE', text="").shape = 'MAX'
883
884
885 class IMAGE_UV_sculpt_curve(Panel):
886     bl_space_type = 'IMAGE_EDITOR'
887     bl_region_type = 'UI'
888     bl_label = "UV Sculpt Curve"
889     bl_options = {'DEFAULT_CLOSED'}
890
891     @classmethod
892     def poll(cls, context):
893         sima = context.space_data
894         toolsettings = context.tool_settings.image_paint
895         return sima.show_uvedit and context.tool_settings.use_uv_sculpt and not (sima.show_paint and toolsettings.brush)
896
897     def draw(self, context):
898         layout = self.layout
899
900         toolsettings = context.tool_settings
901         uvsculpt = toolsettings.uv_sculpt
902         brush = uvsculpt.brush
903
904         layout.template_curve_mapping(brush, "curve")
905
906         row = layout.row(align=True)
907         row.operator("brush.curve_preset", icon='SMOOTHCURVE', text="").shape = 'SMOOTH'
908         row.operator("brush.curve_preset", icon='SPHERECURVE', text="").shape = 'ROUND'
909         row.operator("brush.curve_preset", icon='ROOTCURVE', text="").shape = 'ROOT'
910         row.operator("brush.curve_preset", icon='SHARPCURVE', text="").shape = 'SHARP'
911         row.operator("brush.curve_preset", icon='LINCURVE', text="").shape = 'LINE'
912         row.operator("brush.curve_preset", icon='NOCURVE', text="").shape = 'MAX'
913
914
915 class IMAGE_UV_sculpt(Panel, ImagePaintPanel):
916     bl_space_type = 'IMAGE_EDITOR'
917     bl_region_type = 'UI'
918     bl_label = "UV Sculpt"
919
920     @classmethod
921     def poll(cls, context):
922         sima = context.space_data
923         toolsettings = context.tool_settings.image_paint
924         return sima.show_uvedit and context.tool_settings.use_uv_sculpt and not (sima.show_paint and toolsettings.brush)
925
926     def draw(self, context):
927         layout = self.layout
928
929         toolsettings = context.tool_settings
930         uvsculpt = toolsettings.uv_sculpt
931         brush = uvsculpt.brush
932
933         if brush:
934             col = layout.column()
935
936             row = col.row(align=True)
937             self.prop_unified_size(row, context, brush, "size", slider=True, text="Radius")
938             self.prop_unified_size(row, context, brush, "use_pressure_size")
939
940             row = col.row(align=True)
941             self.prop_unified_strength(row, context, brush, "strength", slider=True, text="Strength")
942             self.prop_unified_strength(row, context, brush, "use_pressure_strength")
943
944         col = layout.column()
945         col.prop(toolsettings, "uv_sculpt_lock_borders")
946         col.prop(toolsettings, "uv_sculpt_all_islands")
947         col.prop(toolsettings, "uv_sculpt_tool")
948
949         if toolsettings.uv_sculpt_tool == 'RELAX':
950             col.prop(toolsettings, "uv_relax_method")
951
952
953 # -----------------------------------------------------------------------------
954 # Mask (similar code in space_clip.py, keep in sync)
955 # note! - panel placement does _not_ fit well with image panels... need to fix
956
957 from bl_ui.properties_mask_common import (MASK_PT_mask,
958                                           MASK_PT_layers,
959                                           MASK_PT_spline,
960                                           MASK_PT_point,
961                                           MASK_PT_display,
962                                           MASK_PT_tools)
963
964
965 class IMAGE_PT_mask(MASK_PT_mask, Panel):
966     bl_space_type = 'IMAGE_EDITOR'
967     bl_region_type = 'PREVIEW'
968
969
970 class IMAGE_PT_mask_layers(MASK_PT_layers, Panel):
971     bl_space_type = 'IMAGE_EDITOR'
972     bl_region_type = 'PREVIEW'
973
974
975 class IMAGE_PT_mask_display(MASK_PT_display, Panel):
976     bl_space_type = 'IMAGE_EDITOR'
977     bl_region_type = 'PREVIEW'
978
979
980 class IMAGE_PT_active_mask_spline(MASK_PT_spline, Panel):
981     bl_space_type = 'IMAGE_EDITOR'
982     bl_region_type = 'PREVIEW'
983
984
985 class IMAGE_PT_active_mask_point(MASK_PT_point, Panel):
986     bl_space_type = 'IMAGE_EDITOR'
987     bl_region_type = 'PREVIEW'
988
989
990 class IMAGE_PT_tools_mask(MASK_PT_tools, Panel):
991     bl_space_type = 'IMAGE_EDITOR'
992     bl_region_type = 'UI'  # is 'TOOLS' in the clip editor
993
994 # --- end mask ---
995
996 if __name__ == "__main__":  # only for live edit.
997     bpy.utils.register_module(__name__)