5d6589b7d8cef415f38d5fd17154cd4d45f96742
[blender.git] / source / blender / editors / sculpt_paint / paint_ops.c
1 /**
2  *
3  * ***** BEGIN GPL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place - Suite 330, Boston, MA        02111-1307, USA.
18  *
19  * ***** END GPL LICENSE BLOCK *****
20  */
21
22 #include "DNA_brush_types.h"
23 #include "DNA_object_types.h"
24 #include "DNA_scene_types.h"
25
26 #include "BKE_brush.h"
27 #include "BKE_context.h"
28 #include "BKE_paint.h"
29
30 #include "ED_sculpt.h"
31 #include "UI_resources.h"
32
33 #include "WM_api.h"
34 #include "WM_types.h"
35
36 #include "RNA_access.h"
37 #include "RNA_define.h"
38 #include "RNA_enum_types.h"
39
40 #include "paint_intern.h"
41
42 #include <string.h>
43
44 /* Brush operators */
45 static int brush_add_exec(bContext *C, wmOperator *op)
46 {
47         int type = RNA_enum_get(op->ptr, "type");
48         int sculpt_tool = SCULPT_TOOL_DRAW;
49         const char *name = "Brush";
50         Brush *br = NULL;
51
52         if(type == OB_MODE_SCULPT) {
53                 sculpt_tool = RNA_enum_get(op->ptr, "sculpt_tool");
54                 RNA_enum_name(brush_sculpt_tool_items, sculpt_tool, &name);
55         }
56
57         br = add_brush(name);
58
59         if(br) {
60                 br->sculpt_tool = sculpt_tool;
61                 paint_brush_set(paint_get_active(CTX_data_scene(C)), br);
62         }
63         
64         return OPERATOR_FINISHED;
65 }
66
67 static EnumPropertyItem brush_type_items[] = {
68         {OB_MODE_SCULPT, "SCULPT", ICON_SCULPTMODE_HLT, "Sculpt", ""},
69         {OB_MODE_VERTEX_PAINT, "VERTEX_PAINT", ICON_VPAINT_HLT, "Vertex Paint", ""},
70         {OB_MODE_WEIGHT_PAINT, "WEIGHT_PAINT", ICON_WPAINT_HLT, "Weight Paint", ""},
71         {OB_MODE_TEXTURE_PAINT, "TEXTURE_PAINT", ICON_TPAINT_HLT, "Texture Paint", ""},
72         {0, NULL, 0, NULL, NULL}};
73
74 void SCULPT_OT_brush_add(wmOperatorType *ot)
75 {
76         /* identifiers */
77         ot->name= "Add Brush";
78         ot->idname= "SCULPT_OT_brush_add";
79         
80         /* api callbacks */
81         ot->exec= brush_add_exec;
82         
83         /* flags */
84         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
85
86         RNA_def_enum(ot->srna, "sculpt_tool", brush_sculpt_tool_items, SCULPT_TOOL_DRAW, "Sculpt Tool", "");
87
88         RNA_def_enum(ot->srna, "type", brush_type_items, OB_MODE_SCULPT, "Type", "Which paint mode to create the brush for.");
89 }
90
91 void BRUSH_OT_add(wmOperatorType *ot)
92 {
93         /* identifiers */
94         ot->name= "Add Brush";
95         ot->idname= "BRUSH_OT_add";
96         
97         /* api callbacks */
98         ot->exec= brush_add_exec;
99         
100         /* flags */
101         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
102
103         RNA_def_enum(ot->srna, "type", brush_type_items, OB_MODE_VERTEX_PAINT, "Type", "Which paint mode to create the brush for.");
104 }
105
106 /* Paint operators */
107 static int paint_poll(bContext *C)
108 {
109         return !!paint_get_active(CTX_data_scene(C));
110 }
111
112 static int brush_slot_add_exec(bContext *C, wmOperator *op)
113 {
114         Paint *p = paint_get_active(CTX_data_scene(C));
115
116         paint_brush_slot_add(p);
117
118         return OPERATOR_FINISHED;
119 }
120
121 void PAINT_OT_brush_slot_add(wmOperatorType *ot)
122 {
123         /* identifiers */
124         ot->name= "Add Brush Slot";
125         ot->idname= "PAINT_OT_brush_slot_add";
126        
127         /* api callbacks */
128         ot->poll= paint_poll;
129         ot->exec= brush_slot_add_exec;
130
131         /* flags */
132         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
133 }
134
135 static int brush_slot_remove_exec(bContext *C, wmOperator *op)
136 {
137         Paint *p = paint_get_active(CTX_data_scene(C));
138
139         paint_brush_slot_remove(p);
140
141         return OPERATOR_FINISHED;
142 }
143
144 void PAINT_OT_brush_slot_remove(wmOperatorType *ot)
145 {
146         /* identifiers */
147         ot->name= "Remove Brush Slot";
148         ot->idname= "PAINT_OT_brush_slot_remove";
149        
150         /* api callbacks */
151         ot->poll= paint_poll;
152         ot->exec= brush_slot_remove_exec;
153
154         /* flags */
155         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
156 }
157
158 /**************************** registration **********************************/
159
160 void ED_operatortypes_paint(void)
161 {
162         /* paint */
163         WM_operatortype_append(PAINT_OT_brush_slot_add);
164         WM_operatortype_append(PAINT_OT_brush_slot_remove);
165
166         /* brush */
167         WM_operatortype_append(BRUSH_OT_add);
168         WM_operatortype_append(BRUSH_OT_curve_preset);
169
170         /* sculpt */
171         WM_operatortype_append(SCULPT_OT_brush_add);
172
173         /* image */
174         WM_operatortype_append(PAINT_OT_texture_paint_toggle);
175         WM_operatortype_append(PAINT_OT_texture_paint_radial_control);
176         WM_operatortype_append(PAINT_OT_image_paint);
177         WM_operatortype_append(PAINT_OT_image_paint_radial_control);
178         WM_operatortype_append(PAINT_OT_sample_color);
179         WM_operatortype_append(PAINT_OT_grab_clone);
180         WM_operatortype_append(PAINT_OT_clone_cursor_set);
181
182         /* weight */
183         WM_operatortype_append(PAINT_OT_weight_paint_toggle);
184         WM_operatortype_append(PAINT_OT_weight_paint_radial_control);
185         WM_operatortype_append(PAINT_OT_weight_paint);
186
187         /* vertex */
188         WM_operatortype_append(PAINT_OT_vertex_paint_radial_control);
189         WM_operatortype_append(PAINT_OT_vertex_paint_toggle);
190         WM_operatortype_append(PAINT_OT_vertex_paint);
191 }
192