4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * Contributor(s): Blender Foundation (2008), Juho Vepsäläinen
22 * ***** END GPL LICENSE BLOCK *****
27 #include "RNA_define.h"
28 #include "RNA_types.h"
30 #include "rna_internal.h"
32 #include "DNA_brush_types.h"
33 #include "DNA_texture_types.h"
37 #include "MEM_guardedalloc.h"
39 #include "BKE_texture.h"
41 static void rna_Brush_mtex_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
43 Brush *brush= (Brush*)ptr->data;
44 rna_iterator_array_begin(iter, (void*)brush->mtex, sizeof(MTex*), MAX_MTEX, 0, NULL);
47 static PointerRNA rna_Brush_active_texture_get(PointerRNA *ptr)
49 Brush *brush= (Brush*)ptr->data;
50 return rna_pointer_inherit_refine(ptr, &RNA_TextureSlot, brush->mtex[(int)brush->texact]);
53 static void rna_Brush_active_texture_index_set(PointerRNA *ptr, int value)
55 Brush *brush= (Brush*)ptr->data;
56 int act= brush->texact;
58 if(value == act || value < 0 || value >= MAX_MTEX)
61 /* auto create/free mtex on activate/deactive, so we can edit
62 * the texture pointer in the buttons UI. */
63 if(brush->mtex[act] && !brush->mtex[act]->tex) {
64 MEM_freeN(brush->mtex[act]);
65 brush->mtex[act]= NULL;
70 if(!brush->mtex[value])
71 brush->mtex[value]= add_mtex();
74 static float rna_Brush_rotation_get(PointerRNA *ptr)
76 Brush *brush= (Brush*)ptr->data;
77 const float conv = 57.295779506;
78 return brush->rot * conv;
81 static void rna_Brush_rotation_set(PointerRNA *ptr, float v)
83 Brush *brush= (Brush*)ptr->data;
84 const float conv = 0.017453293;
85 brush->rot = v * conv;
90 void rna_def_brush(BlenderRNA *brna)
94 static EnumPropertyItem prop_blend_items[] = {
95 {BRUSH_BLEND_MIX, "MIX", 0, "Mix", "Use mix blending mode while painting."},
96 {BRUSH_BLEND_ADD, "ADD", 0, "Add", "Use add blending mode while painting."},
97 {BRUSH_BLEND_SUB, "SUB", 0, "Subtract", "Use subtract blending mode while painting."},
98 {BRUSH_BLEND_MUL, "MUL", 0, "Multiply", "Use multiply blending mode while painting."},
99 {BRUSH_BLEND_LIGHTEN, "LIGHTEN", 0, "Lighten", "Use lighten blending mode while painting."},
100 {BRUSH_BLEND_DARKEN, "DARKEN", 0, "Darken", "Use darken blending mode while painting."},
101 {BRUSH_BLEND_ERASE_ALPHA, "ERASE_ALPHA", 0, "Erase Alpha", "Erase alpha while painting."},
102 {BRUSH_BLEND_ADD_ALPHA, "ADD_ALPHA", 0, "Add Alpha", "Add alpha while painting."},
103 {0, NULL, 0, NULL, NULL}};
104 static EnumPropertyItem prop_texture_mode_items[] = {
105 {BRUSH_TEX_DRAG, "TEX_DRAG", 0, "Drag", ""},
106 {BRUSH_TEX_TILE, "TEX_TILE", 0, "Tile", ""},
107 {BRUSH_TEX_3D, "TEX_3D", 0, "3D", ""},
108 {0, NULL, 0, NULL, NULL}};
109 static EnumPropertyItem prop_sculpt_tool_items[] = {
110 {SCULPT_TOOL_DRAW, "DRAW", 0, "Draw", ""},
111 {SCULPT_TOOL_SMOOTH, "SMOOTH", 0, "Smooth", ""},
112 {SCULPT_TOOL_PINCH, "PINCH", 0, "Pinch", ""},
113 {SCULPT_TOOL_INFLATE, "INFLATE", 0, "Inflate", ""},
114 {SCULPT_TOOL_GRAB, "GRAB", 0, "Grab", ""},
115 {SCULPT_TOOL_LAYER, "LAYER", 0, "Layer", ""},
116 {SCULPT_TOOL_FLATTEN, "FLATTEN", 0, "Flatten", ""},
117 {0, NULL, 0, NULL, NULL}};
119 srna= RNA_def_struct(brna, "Brush", "ID");
120 RNA_def_struct_ui_text(srna, "Brush", "Brush datablock for storing brush settings for painting and sculpting.");
121 RNA_def_struct_ui_icon(srna, ICON_BRUSH_DATA);
124 prop= RNA_def_property(srna, "blend", PROP_ENUM, PROP_NONE);
125 RNA_def_property_enum_items(prop, prop_blend_items);
126 RNA_def_property_ui_text(prop, "Blending mode", "Brush blending mode.");
128 prop= RNA_def_property(srna, "texture_mode", PROP_ENUM, PROP_NONE);
129 RNA_def_property_enum_sdna(prop, NULL, "tex_mode");
130 RNA_def_property_enum_items(prop, prop_texture_mode_items);
131 RNA_def_property_ui_text(prop, "Texture Mode", "");
133 prop= RNA_def_property(srna, "sculpt_tool", PROP_ENUM, PROP_NONE);
134 RNA_def_property_enum_items(prop, prop_sculpt_tool_items);
135 RNA_def_property_ui_text(prop, "Sculpt Tool", "");
138 prop= RNA_def_property(srna, "size", PROP_INT, PROP_NONE);
139 RNA_def_property_range(prop, 1, 200);
140 RNA_def_property_ui_text(prop, "Size", "Diameter of the brush.");
142 prop= RNA_def_property(srna, "falloff", PROP_FLOAT, PROP_NONE);
143 RNA_def_property_float_sdna(prop, NULL, "innerradius");
144 RNA_def_property_range(prop, 0.0f, 1.0f);
145 RNA_def_property_ui_text(prop, "Falloff", "Falloff radius of the brush.");
147 prop= RNA_def_property(srna, "spacing", PROP_FLOAT, PROP_NONE);
148 RNA_def_property_float_sdna(prop, NULL, "spacing");
149 RNA_def_property_range(prop, 1.0f, 100.0f);
150 RNA_def_property_ui_text(prop, "Spacing", "Spacing between brush stamps.");
152 prop= RNA_def_property(srna, "rate", PROP_FLOAT, PROP_NONE);
153 RNA_def_property_float_sdna(prop, NULL, "rate");
154 RNA_def_property_range(prop, 0.010f, 1.0f);
155 RNA_def_property_ui_text(prop, "Rate", "Number of paints per second for Airbrush.");
157 prop= RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
158 RNA_def_property_float_sdna(prop, NULL, "rgb");
159 RNA_def_property_ui_text(prop, "Color", "");
161 prop= RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE);
162 RNA_def_property_float_sdna(prop, NULL, "alpha");
163 RNA_def_property_range(prop, 0.0f, 1.0f);
164 RNA_def_property_ui_text(prop, "Strength", "The amount of pressure on the brush.");
166 prop= RNA_def_property(srna, "rotation", PROP_FLOAT, PROP_NONE);
167 RNA_def_property_float_sdna(prop, NULL, "rot");
168 RNA_def_property_range(prop, 0, 360);
169 RNA_def_property_float_funcs(prop, "rna_Brush_rotation_get", "rna_Brush_rotation_set", NULL);
170 RNA_def_property_ui_text(prop, "Rotation", "Angle of the brush texture.");
173 prop= RNA_def_property(srna, "airbrush", PROP_BOOLEAN, PROP_NONE);
174 RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_AIRBRUSH);
175 RNA_def_property_ui_text(prop, "Airbrush", "Keep applying paint effect while holding mouse (spray).");
177 prop= RNA_def_property(srna, "wrap", PROP_BOOLEAN, PROP_NONE);
178 RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_TORUS);
179 RNA_def_property_ui_text(prop, "Wrap", "Enable torus wrapping while painting.");
181 prop= RNA_def_property(srna, "alpha_pressure", PROP_BOOLEAN, PROP_NONE);
182 RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_ALPHA_PRESSURE);
183 RNA_def_property_ui_text(prop, "Opacity Pressure", "Enable tablet pressure sensitivity for opacity.");
185 prop= RNA_def_property(srna, "size_pressure", PROP_BOOLEAN, PROP_NONE);
186 RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_SIZE_PRESSURE);
187 RNA_def_property_ui_text(prop, "Size Pressure", "Enable tablet pressure sensitivity for size.");
189 prop= RNA_def_property(srna, "falloff_pressure", PROP_BOOLEAN, PROP_NONE);
190 RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_RAD_PRESSURE);
191 RNA_def_property_ui_text(prop, "Falloff Pressure", "Enable tablet pressure sensitivity for falloff.");
193 prop= RNA_def_property(srna, "spacing_pressure", PROP_BOOLEAN, PROP_NONE);
194 RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_SPACING_PRESSURE);
195 RNA_def_property_ui_text(prop, "Spacing Pressure", "Enable tablet pressure sensitivity for spacing.");
197 prop= RNA_def_property(srna, "rake", PROP_BOOLEAN, PROP_NONE);
198 RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_RAKE);
199 RNA_def_property_ui_text(prop, "Rake", "Rotate the brush texture to match the stroke direction.");
201 prop= RNA_def_property(srna, "anchored", PROP_BOOLEAN, PROP_NONE);
202 RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_ANCHORED);
203 RNA_def_property_ui_text(prop, "Anchored", "Keep the brush anchored to the initial location.");
205 prop= RNA_def_property(srna, "flip_direction", PROP_BOOLEAN, PROP_NONE);
206 RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_DIR_IN);
207 RNA_def_property_ui_text(prop, "Flip Direction", "Move vertices in the opposite direction.");
209 prop= RNA_def_property(srna, "space", PROP_BOOLEAN, PROP_NONE);
210 RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_SPACE);
211 RNA_def_property_ui_text(prop, "Space", "Limit brush application to the distance specified by spacing.");
213 prop= RNA_def_property(srna, "smooth_stroke", PROP_BOOLEAN, PROP_NONE);
214 RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_SMOOTH_STROKE);
215 RNA_def_property_ui_text(prop, "Smooth Stroke", "Brush lags behind mouse and follows a smoother path.");
217 /* not exposed in the interface yet
218 prop= RNA_def_property(srna, "fixed_tex", PROP_BOOLEAN, PROP_NONE);
219 RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_FIXED_TEX);
220 RNA_def_property_ui_text(prop, "Fixed Texture", "Keep texture origin in fixed position.");*/
222 prop= RNA_def_property(srna, "curve", PROP_POINTER, PROP_NEVER_NULL);
223 RNA_def_property_ui_text(prop, "Curve", "Editable falloff curve.");
226 rna_def_mtex_common(srna, "rna_Brush_mtex_begin", "rna_Brush_active_texture_get", "rna_Brush_active_texture_index_set", "TextureSlot");
229 prop= RNA_def_property(srna, "clone_image", PROP_POINTER, PROP_NONE);
230 RNA_def_property_pointer_sdna(prop, NULL, "clone.image");
231 RNA_def_property_flag(prop, PROP_EDITABLE);
232 RNA_def_property_ui_text(prop, "Clone Image", "Image for clone tool.");
234 prop= RNA_def_property(srna, "clone_opacity", PROP_FLOAT, PROP_NONE);
235 RNA_def_property_float_sdna(prop, NULL, "clone.alpha");
236 RNA_def_property_range(prop, 0.0f, 1.0f);
237 RNA_def_property_ui_text(prop, "Clone Opacity", "Opacity of clone image display.");
239 prop= RNA_def_property(srna, "clone_offset", PROP_FLOAT, PROP_VECTOR);
240 RNA_def_property_float_sdna(prop, NULL, "clone.offset");
241 RNA_def_property_ui_text(prop, "Clone Offset", "");
242 RNA_def_property_ui_range(prop, -1.0f , 1.0f, 10.0f, 3);
246 /* A brush stroke is a list of changes to the brush that
247 * can occur during a stroke
249 * o 3D location of the brush
250 * o 2D mouse location
256 static void rna_def_operator_stroke_element(BlenderRNA *brna)
261 srna= RNA_def_struct(brna, "OperatorStrokeElement", "IDPropertyGroup");
262 RNA_def_struct_ui_text(srna, "Operator Stroke Element", "");
264 prop= RNA_def_property(srna, "location", PROP_FLOAT, PROP_VECTOR);
265 RNA_def_property_flag(prop, PROP_IDPROPERTY);
266 RNA_def_property_array(prop, 3);
267 RNA_def_property_ui_text(prop, "Location", "");
269 prop= RNA_def_property(srna, "mouse", PROP_INT, PROP_VECTOR);
270 RNA_def_property_flag(prop, PROP_IDPROPERTY);
271 RNA_def_property_array(prop, 2);
272 RNA_def_property_ui_text(prop, "Mouse", "");
274 prop= RNA_def_property(srna, "pressure", PROP_FLOAT, PROP_NONE);
275 RNA_def_property_flag(prop, PROP_IDPROPERTY);
276 RNA_def_property_range(prop, 0.0f, 1.0f);
277 RNA_def_property_ui_text(prop, "Pressure", "Tablet pressure.");
279 prop= RNA_def_property(srna, "time", PROP_FLOAT, PROP_UNSIGNED);
280 RNA_def_property_flag(prop, PROP_IDPROPERTY);
281 RNA_def_property_ui_text(prop, "Time", "");
283 prop= RNA_def_property(srna, "flip", PROP_BOOLEAN, PROP_NONE);
284 RNA_def_property_flag(prop, PROP_IDPROPERTY);
285 RNA_def_property_ui_text(prop, "Flip", "");
287 /* XXX: Tool (this will be for pressing a modifier key for a different brush,
288 e.g. switching to a Smooth brush in the middle of the stroke */
291 void RNA_def_brush(BlenderRNA *brna)
294 rna_def_operator_stroke_element(brna);