Sculpt Branch:
[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 "ED_screen.h"
32 #include "UI_resources.h"
33
34 #include "WM_api.h"
35 #include "WM_types.h"
36
37 #include "RNA_access.h"
38 #include "RNA_define.h"
39 #include "RNA_enum_types.h"
40
41 #include "paint_intern.h"
42 #include "sculpt_intern.h"
43
44 #include <string.h>
45
46 /* Brush operators */
47 static int brush_add_exec(bContext *C, wmOperator *op)
48 {
49         /*int type = RNA_enum_get(op->ptr, "type");*/
50         Brush *br = NULL;
51
52         br = add_brush("Brush");
53
54         if(br)
55                 paint_brush_set(paint_get_active(CTX_data_scene(C)), br);
56
57         return OPERATOR_FINISHED;
58 }
59
60 static EnumPropertyItem brush_type_items[] = {
61         {OB_MODE_SCULPT, "SCULPT", ICON_SCULPTMODE_HLT, "Sculpt", ""},
62         {OB_MODE_VERTEX_PAINT, "VERTEX_PAINT", ICON_VPAINT_HLT, "Vertex Paint", ""},
63         {OB_MODE_WEIGHT_PAINT, "WEIGHT_PAINT", ICON_WPAINT_HLT, "Weight Paint", ""},
64         {OB_MODE_TEXTURE_PAINT, "TEXTURE_PAINT", ICON_TPAINT_HLT, "Texture Paint", ""},
65         {0, NULL, 0, NULL, NULL}};
66
67 void BRUSH_OT_add(wmOperatorType *ot)
68 {
69         /* identifiers */
70         ot->name= "Add Brush";
71     ot->description= "Add brush by mode type.";
72         ot->idname= "BRUSH_OT_add";
73         
74         /* api callbacks */
75         ot->exec= brush_add_exec;
76         
77         /* flags */
78         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
79
80         RNA_def_enum(ot->srna, "type", brush_type_items, OB_MODE_VERTEX_PAINT, "Type", "Which paint mode to create the brush for.");
81 }
82
83 static int vertex_color_set_exec(bContext *C, wmOperator *op)
84 {
85         Scene *scene = CTX_data_scene(C);
86         Object *obact = CTX_data_active_object(C);
87         unsigned int paintcol = vpaint_get_current_col(scene->toolsettings->vpaint);
88         vpaint_fill(obact, paintcol);
89         
90         ED_region_tag_redraw(CTX_wm_region(C)); // XXX - should redraw all 3D views
91         return OPERATOR_FINISHED;
92 }
93
94 void PAINT_OT_vertex_color_set(wmOperatorType *ot)
95 {
96         /* identifiers */
97         ot->name= "Set Vertex Colors";
98         ot->idname= "PAINT_OT_vertex_color_set";
99         
100         /* api callbacks */
101         ot->exec= vertex_color_set_exec;
102         ot->poll= vertex_paint_mode_poll;
103         
104         /* flags */
105         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
106 }
107
108 /**************************** registration **********************************/
109
110 void ED_operatortypes_paint(void)
111 {
112         /* brush */
113         WM_operatortype_append(BRUSH_OT_add);
114         WM_operatortype_append(BRUSH_OT_curve_preset);
115
116         /* image */
117         WM_operatortype_append(PAINT_OT_texture_paint_toggle);
118         WM_operatortype_append(PAINT_OT_texture_paint_radial_control);
119         WM_operatortype_append(PAINT_OT_image_paint);
120         WM_operatortype_append(PAINT_OT_image_paint_radial_control);
121         WM_operatortype_append(PAINT_OT_sample_color);
122         WM_operatortype_append(PAINT_OT_grab_clone);
123         WM_operatortype_append(PAINT_OT_clone_cursor_set);
124
125         /* weight */
126         WM_operatortype_append(PAINT_OT_weight_paint_toggle);
127         WM_operatortype_append(PAINT_OT_weight_paint_radial_control);
128         WM_operatortype_append(PAINT_OT_weight_paint);
129         WM_operatortype_append(PAINT_OT_weight_set);
130
131         /* vertex */
132         WM_operatortype_append(PAINT_OT_vertex_paint_radial_control);
133         WM_operatortype_append(PAINT_OT_vertex_paint_toggle);
134         WM_operatortype_append(PAINT_OT_vertex_paint);
135         WM_operatortype_append(PAINT_OT_vertex_color_set);
136
137         /* face-select */
138         WM_operatortype_append(PAINT_OT_face_select_linked);
139         WM_operatortype_append(PAINT_OT_face_select_linked_pick);
140         WM_operatortype_append(PAINT_OT_face_select_all);
141 }
142
143 static void ed_keymap_paint_brush_switch(wmKeyMap *keymap, const char *path)
144 {
145         wmKeyMapItem *kmi;
146
147         kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", ONEKEY, KM_PRESS, 0, 0);
148         RNA_string_set(kmi->ptr, "path", path);
149         RNA_int_set(kmi->ptr, "value", 0);
150         kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", TWOKEY, KM_PRESS, 0, 0);
151         RNA_string_set(kmi->ptr, "path", path);
152         RNA_int_set(kmi->ptr, "value", 1);
153         kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", THREEKEY, KM_PRESS, 0, 0);
154         RNA_string_set(kmi->ptr, "path", path);
155         RNA_int_set(kmi->ptr, "value", 2);
156         kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", FOURKEY, KM_PRESS, 0, 0);
157         RNA_string_set(kmi->ptr, "path", path);
158         RNA_int_set(kmi->ptr, "value", 3);
159         kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", FIVEKEY, KM_PRESS, 0, 0);
160         RNA_string_set(kmi->ptr, "path", path);
161         RNA_int_set(kmi->ptr, "value", 4);
162         kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", SIXKEY, KM_PRESS, 0, 0);
163         RNA_string_set(kmi->ptr, "path", path);
164         RNA_int_set(kmi->ptr, "value", 5);
165         kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", SEVENKEY, KM_PRESS, 0, 0);
166         RNA_string_set(kmi->ptr, "path", path);
167         RNA_int_set(kmi->ptr, "value", 6);
168         kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", EIGHTKEY, KM_PRESS, 0, 0);
169         RNA_string_set(kmi->ptr, "path", path);
170         RNA_int_set(kmi->ptr, "value", 7);
171         kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", NINEKEY, KM_PRESS, 0, 0);
172         RNA_string_set(kmi->ptr, "path", path);
173         RNA_int_set(kmi->ptr, "value", 8);
174         kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", ZEROKEY, KM_PRESS, 0, 0);
175         RNA_string_set(kmi->ptr, "path", path);
176         RNA_int_set(kmi->ptr, "value", 10);
177 }
178
179 void ED_keymap_paint(wmKeyConfig *keyconf)
180 {
181         wmKeyMap *keymap;
182         int i;
183         
184         /* Sculpt mode */
185         keymap= WM_keymap_find(keyconf, "Sculpt", 0, 0);
186         keymap->poll= sculpt_poll;
187
188         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_radial_control", FKEY, KM_PRESS, 0, 0)->ptr, "mode", WM_RADIALCONTROL_SIZE);
189         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", WM_RADIALCONTROL_STRENGTH);
190         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_radial_control", FKEY, KM_PRESS, KM_CTRL, 0)->ptr, "mode", WM_RADIALCONTROL_ANGLE);
191
192         WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, 0, 0);
193         WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
194
195         ed_keymap_paint_brush_switch(keymap, "tool_settings.sculpt.active_brush_index");
196
197         for(i=1; i<=5; i++)
198                 RNA_int_set(WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", ZEROKEY+i, KM_PRESS, KM_CTRL, 0)->ptr, "level", i);
199
200         /* Vertex Paint mode */
201         keymap= WM_keymap_find(keyconf, "Vertex Paint", 0, 0);
202         keymap->poll= vertex_paint_poll;
203
204         RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_vertex_paint_radial_control", FKEY, KM_PRESS, 0, 0)->ptr, "mode", WM_RADIALCONTROL_SIZE);
205         RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_vertex_paint_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", WM_RADIALCONTROL_STRENGTH);
206         WM_keymap_verify_item(keymap, "PAINT_OT_vertex_paint", LEFTMOUSE, KM_PRESS, 0, 0);
207         WM_keymap_add_item(keymap, "PAINT_OT_sample_color", RIGHTMOUSE, KM_PRESS, 0, 0);
208
209         WM_keymap_add_item(keymap,
210                         "PAINT_OT_vertex_color_set",KKEY, KM_PRESS, KM_SHIFT, 0);
211
212         ed_keymap_paint_brush_switch(keymap, "tool_settings.vertex_paint.active_brush_index");
213
214         /* Weight Paint mode */
215         keymap= WM_keymap_find(keyconf, "Weight Paint", 0, 0);
216         keymap->poll= weight_paint_poll;
217
218         RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_weight_paint_radial_control", FKEY, KM_PRESS, 0, 0)->ptr, "mode", WM_RADIALCONTROL_SIZE);
219         RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_weight_paint_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", WM_RADIALCONTROL_STRENGTH);
220
221         WM_keymap_verify_item(keymap, "PAINT_OT_weight_paint", LEFTMOUSE, KM_PRESS, 0, 0);
222
223         WM_keymap_add_item(keymap,
224                         "PAINT_OT_weight_set", KKEY, KM_PRESS, KM_SHIFT, 0);
225
226         ed_keymap_paint_brush_switch(keymap, "tool_settings.weight_paint.active_brush_index");
227
228         /* Image/Texture Paint mode */
229         keymap= WM_keymap_find(keyconf, "Image Paint", 0, 0);
230         keymap->poll= image_texture_paint_poll;
231
232         RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_texture_paint_radial_control", FKEY, KM_PRESS, 0, 0)->ptr, "mode", WM_RADIALCONTROL_SIZE);
233         RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_texture_paint_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", WM_RADIALCONTROL_STRENGTH);
234
235         WM_keymap_add_item(keymap, "PAINT_OT_image_paint", LEFTMOUSE, KM_PRESS, 0, 0);
236         WM_keymap_add_item(keymap, "PAINT_OT_sample_color", RIGHTMOUSE, KM_PRESS, 0, 0);
237         WM_keymap_add_item(keymap, "PAINT_OT_clone_cursor_set", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
238
239         ed_keymap_paint_brush_switch(keymap, "tool_settings.image_paint.active_brush_index");
240
241         /* face-mask mode */
242         keymap= WM_keymap_find(keyconf, "Face Mask", 0, 0);
243         keymap->poll= facemask_paint_poll;
244
245         WM_keymap_add_item(keymap, "PAINT_OT_face_select_all", AKEY, KM_PRESS, 0, 0);
246         WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
247         WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked_pick", LKEY, KM_PRESS, 0, 0);
248
249 }