Stencil dimension control:
[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         layout.operator("brush.stencil_fit_image_aspect")
88
89     # angle and texture_angle_source
90     col = layout.column()
91     col.active = brush.brush_capabilities.has_texture_angle_source
92     col.label(text="Angle:")
93     if brush.brush_capabilities.has_random_texture_angle:
94         if sculpt:
95             if brush.sculpt_capabilities.has_random_texture_angle:
96                 col.prop(brush, "texture_angle_source_random", text="")
97             else:
98                 col.prop(brush, "texture_angle_source_no_random", text="")
99
100         else:
101             col.prop(brush, "texture_angle_source_random", text="")
102     else:
103         col.prop(brush, "texture_angle_source_no_random", text="")
104     col = layout.column()
105     col.active = brush.brush_capabilities.has_texture_angle
106     col.prop(tex_slot, "angle", text="")
107
108     # scale and offset
109     split = layout.split()
110     split.prop(tex_slot, "offset")
111     split.prop(tex_slot, "scale")
112
113     if sculpt:
114         # texture_sample_bias
115         col = layout.column(align=True)
116         col.label(text="Sample Bias:")
117         col.prop(brush, "texture_sample_bias", slider=True, text="")
118
119
120 def brush_mask_texture_settings(layout, brush):
121     mask_tex_slot = brush.mask_texture_slot
122
123     if brush.mask_texture:
124         layout.label(text="Mask Mapping:")
125         col = layout.column()
126         col.active = brush.brush_capabilities.has_texture_angle
127         col.prop(mask_tex_slot, "angle", text="")
128
129         # scale and offset
130         split = layout.split()
131         split.prop(mask_tex_slot, "offset")
132         split.prop(mask_tex_slot, "scale")