2.5 Sculpt:
[blender-staging.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_scene_types.h"
23
24 #include "BKE_brush.h"
25 #include "BKE_context.h"
26 #include "BKE_paint.h"
27
28 #include "ED_sculpt.h"
29
30 #include "WM_api.h"
31 #include "WM_types.h"
32
33 #include "RNA_access.h"
34 #include "RNA_define.h"
35 #include "RNA_enum_types.h"
36
37 #include "paint_intern.h"
38
39 #include <string.h>
40
41 /* Brush operators */
42 static int new_brush_exec(bContext *C, wmOperator *op)
43 {
44         int sculpt_tool = RNA_enum_get(op->ptr, "sculpt_tool");
45         const char *name = NULL;
46         Brush *br = NULL;
47
48         RNA_enum_name(brush_sculpt_tool_items, sculpt_tool, &name);
49         br = add_brush(name);
50
51         if(br) {
52                 br->sculpt_tool = sculpt_tool;
53                 paint_brush_set(paint_get_active(CTX_data_scene(C)), br);
54         }
55         
56         return OPERATOR_FINISHED;
57 }
58
59 void BRUSH_OT_new(wmOperatorType *ot)
60 {
61         /* identifiers */
62         ot->name= "Add Brush";
63         ot->idname= "BRUSH_OT_new";
64         
65         /* api callbacks */
66         ot->exec= new_brush_exec;
67         
68         /* flags */
69         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
70
71         /* TODO: add enum props for other paint modes */
72         RNA_def_enum(ot->srna, "sculpt_tool", brush_sculpt_tool_items, 0, "Sculpt Tool", "");
73 }
74
75 /* Paint operators */
76 static int paint_poll(bContext *C)
77 {
78         return !!paint_get_active(CTX_data_scene(C));
79 }
80
81 static int brush_slot_add_exec(bContext *C, wmOperator *op)
82 {
83         Paint *p = paint_get_active(CTX_data_scene(C));
84
85         paint_brush_slot_add(p);
86
87         return OPERATOR_FINISHED;
88 }
89
90 void PAINT_OT_brush_slot_add(wmOperatorType *ot)
91 {
92         /* identifiers */
93         ot->name= "Add Brush Slot";
94         ot->idname= "PAINT_OT_brush_slot_add";
95        
96         /* api callbacks */
97         ot->poll= paint_poll;
98         ot->exec= brush_slot_add_exec;
99
100         /* flags */
101         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
102 }
103
104 static int brush_slot_remove_exec(bContext *C, wmOperator *op)
105 {
106         Paint *p = paint_get_active(CTX_data_scene(C));
107
108         paint_brush_slot_remove(p);
109
110         return OPERATOR_FINISHED;
111 }
112
113 void PAINT_OT_brush_slot_remove(wmOperatorType *ot)
114 {
115         /* identifiers */
116         ot->name= "Remove Brush Slot";
117         ot->idname= "PAINT_OT_brush_slot_remove";
118        
119         /* api callbacks */
120         ot->poll= paint_poll;
121         ot->exec= brush_slot_remove_exec;
122
123         /* flags */
124         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
125 }
126
127 /**************************** registration **********************************/
128
129 void ED_operatortypes_paint(void)
130 {
131         /* paint */
132         WM_operatortype_append(PAINT_OT_brush_slot_add);
133         WM_operatortype_append(PAINT_OT_brush_slot_remove);
134
135         /* brush */
136         WM_operatortype_append(BRUSH_OT_new);
137         WM_operatortype_append(BRUSH_OT_curve_preset);
138
139         /* image */
140         WM_operatortype_append(PAINT_OT_texture_paint_toggle);
141         WM_operatortype_append(PAINT_OT_texture_paint_radial_control);
142         WM_operatortype_append(PAINT_OT_image_paint);
143         WM_operatortype_append(PAINT_OT_image_paint_radial_control);
144         WM_operatortype_append(PAINT_OT_sample_color);
145         WM_operatortype_append(PAINT_OT_grab_clone);
146         WM_operatortype_append(PAINT_OT_clone_cursor_set);
147
148         /* weight */
149         WM_operatortype_append(PAINT_OT_weight_paint_toggle);
150         WM_operatortype_append(PAINT_OT_weight_paint_radial_control);
151         WM_operatortype_append(PAINT_OT_weight_paint);
152
153         /* vertex */
154         WM_operatortype_append(PAINT_OT_vertex_paint_radial_control);
155         WM_operatortype_append(PAINT_OT_vertex_paint_toggle);
156         WM_operatortype_append(PAINT_OT_vertex_paint);
157 }
158