Fix io_anim_camera error exporting cameras with quotes in their name
[blender-addons.git] / space_view3d_brush_menus / brushes.py
blobdc9d59126981d06c8373bf2470539c54b2a0ea29
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 import bpy
4 from bpy.types import Menu
5 from . import utils_core
6 from bl_ui.properties_paint_common import UnifiedPaintPanel
8 # Particle Tools
10 particle_tools = (
11 ("Comb", 'COMB'),
12 ("Smooth", 'SMOOTH'),
13 ("Add", 'ADD'),
14 ("Length", 'LENGTH'),
15 ("Puff", 'PUFF'),
16 ("Cut", 'CUT'),
17 ("Weight", 'WEIGHT')
20 # Brush Datapaths
22 brush_datapath = {
23 'SCULPT': "tool_settings.sculpt.brush",
24 'VERTEX_PAINT': "tool_settings.vertex_paint.brush",
25 'WEIGHT_PAINT': "tool_settings.weight_paint.brush",
26 'TEXTURE_PAINT': "tool_settings.image_paint.brush",
27 'PARTICLE_EDIT': "tool_settings.particle_edit.tool"
30 # Brush Icons
32 brush_icon = {
33 'SCULPT': {
34 "BLOB": 'BRUSH_BLOB',
35 "CLAY": 'BRUSH_CLAY',
36 "CLAY_STRIPS": 'BRUSH_CLAY_STRIPS',
37 "CREASE": 'BRUSH_CREASE',
38 "DRAW": 'BRUSH_SCULPT_DRAW',
39 "DRAW_SHARP": 'BRUSH_SCULPT_DRAW',
40 "ELASTIC_DEFORM": 'BRUSH_GRAB',
41 "FILL": 'BRUSH_FILL',
42 "FLATTEN": 'BRUSH_FLATTEN',
43 "GRAB": 'BRUSH_GRAB',
44 "INFLATE": 'BRUSH_INFLATE',
45 "LAYER": 'BRUSH_LAYER',
46 "MASK": 'BRUSH_MASK',
47 "NUDGE": 'BRUSH_NUDGE',
48 "PINCH": 'BRUSH_PINCH',
49 "POSE": 'BRUSH_GRAB',
50 "ROTATE": 'BRUSH_ROTATE',
51 "SCRAPE": 'BRUSH_SCRAPE',
52 "SIMPLIFY": 'BRUSH_DATA',
53 "SMOOTH": 'BRUSH_SMOOTH',
54 "SNAKE_HOOK": 'BRUSH_SNAKE_HOOK',
55 "THUMB": 'BRUSH_THUMB'
58 'VERTEX_PAINT': {
59 "AVERAGE": 'BRUSH_BLUR',
60 "BLUR": 'BRUSH_BLUR',
61 "DRAW": 'BRUSH_MIX',
62 "SMEAR": 'BRUSH_BLUR'
65 'WEIGHT_PAINT': {
66 "AVERAGE": 'BRUSH_BLUR',
67 "BLUR": 'BRUSH_BLUR',
68 "DRAW": 'BRUSH_MIX',
69 "SMEAR": 'BRUSH_BLUR'
72 'TEXTURE_PAINT': {
73 "CLONE": 'BRUSH_CLONE',
74 "DRAW": 'BRUSH_TEXDRAW',
75 "FILL": 'BRUSH_TEXFILL',
76 "MASK": 'BRUSH_TEXMASK',
77 "SMEAR": 'BRUSH_SMEAR',
78 "SOFTEN": 'BRUSH_SOFTEN'
83 class BrushesMenu(Menu):
84 bl_label = "Brush"
85 bl_idname = "VIEW3D_MT_sv3_brushes_menu"
87 def draw(self, context):
88 mode = utils_core.get_mode()
89 layout = self.layout
90 settings = UnifiedPaintPanel.paint_settings(context)
91 colum_n = utils_core.addon_settings()
93 layout.row().label(text="Brush")
94 layout.row().separator()
96 has_brush = utils_core.get_brush_link(context, types="brush")
97 current_brush = eval("bpy.context.{}".format(brush_datapath[mode])) if has_brush else None
99 # get the current brush's name
100 if current_brush and utils_core.get_mode() != 'PARTICLE_EDIT':
101 current_brush = current_brush.name
103 if mode == 'PARTICLE_EDIT':
104 # if you are in particle edit mode add the menu items for particle mode
105 for tool in particle_tools:
106 utils_core.menuprop(
107 layout.row(), tool[0], tool[1], brush_datapath[mode],
108 icon='RADIOBUT_OFF', disable=True,
109 disable_icon='RADIOBUT_ON'
111 else:
112 column_flow = layout.column_flow(columns=colum_n)
114 # iterate over all the brushes
115 for item in bpy.data.brushes:
116 if mode == 'SCULPT':
117 if item.use_paint_sculpt:
118 # if you are in sculpt mode and the brush
119 # is a sculpt brush add the brush to the menu
120 utils_core.menuprop(
121 column_flow.row(), item.name,
122 'bpy.data.brushes["%s"]' % item.name,
123 brush_datapath[mode], icon=brush_icon[mode][item.sculpt_tool],
124 disable=True, custom_disable_exp=(item.name, current_brush),
125 path=True
127 if mode == 'VERTEX_PAINT':
128 if item.use_paint_vertex:
129 # if you are in vertex paint mode and the brush
130 # is a vertex paint brush add the brush to the menu
131 utils_core.menuprop(
132 column_flow.row(), item.name,
133 'bpy.data.brushes["%s"]' % item.name,
134 brush_datapath[mode], icon=brush_icon[mode][item.vertex_tool],
135 disable=True, custom_disable_exp=(item.name, current_brush),
136 path=True
138 if mode == 'WEIGHT_PAINT':
139 if item.use_paint_weight:
140 # if you are in weight paint mode and the brush
141 # is a weight paint brush add the brush to the menu
142 utils_core.menuprop(
143 column_flow.row(), item.name,
144 'bpy.data.brushes["%s"]' % item.name,
145 brush_datapath[mode], icon=brush_icon[mode][item.vertex_tool],
146 disable=True, custom_disable_exp=(item.name, current_brush),
147 path=True
149 if utils_core.get_mode() == 'TEXTURE_PAINT':
150 if item.use_paint_image:
151 # if you are in texture paint mode and the brush
152 # is a texture paint brush add the brush to the menu
153 utils_core.menuprop(
154 column_flow.row(), item.name,
155 'bpy.data.brushes["%s"]' % item.name,
156 brush_datapath[mode], icon=brush_icon[mode][item.image_tool],
157 disable=True, custom_disable_exp=(item.name, current_brush),
158 path=True
162 def register():
163 bpy.utils.register_class(BrushesMenu)
165 def unregister():
166 bpy.utils.unregister_class(BrushesMenu)