b3335f322315380f374034f196fdfd7bbb8979a3
[blender.git] / release / scripts / startup / bl_ui / properties_paint_common.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
21
22 class UnifiedPaintPanel():
23     # subclass must set
24     # bl_space_type = 'IMAGE_EDITOR'
25     # bl_region_type = 'UI'
26
27     @staticmethod
28     def paint_settings(context):
29         toolsettings = context.tool_settings
30
31         if context.sculpt_object:
32             return toolsettings.sculpt
33         elif context.vertex_paint_object:
34             return toolsettings.vertex_paint
35         elif context.weight_paint_object:
36             return toolsettings.weight_paint
37         elif context.image_paint_object:
38             return toolsettings.image_paint
39         elif context.particle_edit_object:
40             return toolsettings.particle_edit
41
42         return None
43
44     @staticmethod
45     def unified_paint_settings(parent, context):
46         ups = context.tool_settings.unified_paint_settings
47         parent.label(text="Unified Settings:")
48         parent.prop(ups, "use_unified_size", text="Size")
49         parent.prop(ups, "use_unified_strength", text="Strength")
50         if context.weight_paint_object:
51             parent.prop(ups, "use_unified_weight", text="Weight")
52
53     @staticmethod
54     def prop_unified_size(parent, context, brush, prop_name, icon='NONE', text="", slider=False):
55         ups = context.tool_settings.unified_paint_settings
56         ptr = ups if ups.use_unified_size else brush
57         parent.prop(ptr, prop_name, icon=icon, text=text, slider=slider)
58
59     @staticmethod
60     def prop_unified_strength(parent, context, brush, prop_name, icon='NONE', text="", slider=False):
61         ups = context.tool_settings.unified_paint_settings
62         ptr = ups if ups.use_unified_strength else brush
63         parent.prop(ptr, prop_name, icon=icon, text=text, slider=slider)
64
65     @staticmethod
66     def prop_unified_weight(parent, context, brush, prop_name, icon='NONE', text="", slider=False):
67         ups = context.tool_settings.unified_paint_settings
68         ptr = ups if ups.use_unified_weight else brush
69         parent.prop(ptr, prop_name, icon=icon, text=text, slider=slider)
70
71
72 # Used in both the View3D toolbar and texture properties
73 def brush_texture_settings(layout, brush, sculpt):
74     tex_slot = brush.texture_slot
75
76     layout.label(text="Brush Mapping:")
77
78     # map_mode
79     if sculpt:
80         layout.row().prop(tex_slot, "map_mode", text="")
81         layout.separator()
82     else:
83         layout.row().prop(tex_slot, "tex_paint_map_mode", text="")
84         layout.separator()
85
86     if tex_slot.map_mode == 'STENCIL':
87         if brush.texture and brush.texture.type == 'IMAGE':
88             layout.operator("brush.stencil_fit_image_aspect")
89         layout.operator("brush.stencil_reset_transform")
90
91     # angle and texture_angle_source
92     col = layout.column()
93     col.active = brush.brush_capabilities.has_texture_angle_source
94     col.label(text="Angle:")
95     if brush.brush_capabilities.has_random_texture_angle:
96         if sculpt:
97             if brush.sculpt_capabilities.has_random_texture_angle:
98                 col.prop(brush, "texture_angle_source_random", text="")
99             else:
100                 col.prop(brush, "texture_angle_source_no_random", text="")
101
102         else:
103             col.prop(brush, "texture_angle_source_random", text="")
104     else:
105         col.prop(brush, "texture_angle_source_no_random", text="")
106     col = layout.column()
107     col.active = brush.brush_capabilities.has_texture_angle
108     col.prop(tex_slot, "angle", text="")
109
110     # scale and offset
111     split = layout.split()
112     split.prop(tex_slot, "offset")
113     split.prop(tex_slot, "scale")
114
115     if sculpt:
116         # texture_sample_bias
117         col = layout.column(align=True)
118         col.label(text="Sample Bias:")
119         col.prop(brush, "texture_sample_bias", slider=True, text="")
120
121
122 def brush_mask_texture_settings(layout, brush):
123     mask_tex_slot = brush.mask_texture_slot
124
125     layout.label(text="Mask Mapping:")
126
127     # map_mode
128     layout.row().prop(mask_tex_slot, "mask_map_mode", text="")
129     layout.separator()
130
131     if mask_tex_slot.map_mode == 'STENCIL':
132         if brush.mask_texture and brush.mask_texture.type == 'IMAGE':
133             layout.operator("brush.stencil_fit_image_aspect").mask = True
134         layout.operator("brush.stencil_reset_transform").mask = True
135
136     if brush.mask_texture:
137         col = layout.column()
138         col.label(text="Angle:")
139         col.active = brush.brush_capabilities.has_texture_angle
140         col.prop(mask_tex_slot, "angle", text="")
141
142         # scale and offset
143         split = layout.split()
144         split.prop(mask_tex_slot, "offset")
145         split.prop(mask_tex_slot, "scale")