Key Configuration
[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 #include "sculpt_intern.h"
42
43 #include <string.h>
44
45 /* Brush operators */
46 static int brush_add_exec(bContext *C, wmOperator *op)
47 {
48         /*int type = RNA_enum_get(op->ptr, "type");*/
49         Brush *br = NULL;
50
51         br = add_brush("Brush");
52
53         if(br)
54                 paint_brush_set(paint_get_active(CTX_data_scene(C)), br);
55         
56         return OPERATOR_FINISHED;
57 }
58
59 static EnumPropertyItem brush_type_items[] = {
60         {OB_MODE_SCULPT, "SCULPT", ICON_SCULPTMODE_HLT, "Sculpt", ""},
61         {OB_MODE_VERTEX_PAINT, "VERTEX_PAINT", ICON_VPAINT_HLT, "Vertex Paint", ""},
62         {OB_MODE_WEIGHT_PAINT, "WEIGHT_PAINT", ICON_WPAINT_HLT, "Weight Paint", ""},
63         {OB_MODE_TEXTURE_PAINT, "TEXTURE_PAINT", ICON_TPAINT_HLT, "Texture Paint", ""},
64         {0, NULL, 0, NULL, NULL}};
65
66 void BRUSH_OT_add(wmOperatorType *ot)
67 {
68         /* identifiers */
69         ot->name= "Add Brush";
70     ot->description= "Add brush by mode type.";
71         ot->idname= "BRUSH_OT_add";
72         
73         /* api callbacks */
74         ot->exec= brush_add_exec;
75         
76         /* flags */
77         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
78
79         RNA_def_enum(ot->srna, "type", brush_type_items, OB_MODE_VERTEX_PAINT, "Type", "Which paint mode to create the brush for.");
80 }
81
82 static int vertex_color_set_exec(bContext *C, wmOperator *op)
83 {
84         int selected = RNA_boolean_get(op->ptr, "selected");
85         Scene *scene = CTX_data_scene(C);
86
87         clear_vpaint(scene, selected);
88         
89         return OPERATOR_FINISHED;
90 }
91
92 void PAINT_OT_vertex_color_set(wmOperatorType *ot)
93 {
94         /* identifiers */
95         ot->name= "Set Vertex Colors";
96         ot->idname= "PAINT_OT_vertex_color_set";
97         
98         /* api callbacks */
99         ot->exec= vertex_color_set_exec;
100         ot->poll= vertex_paint_mode_poll;
101         
102         /* flags */
103         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
104
105         RNA_def_boolean(ot->srna, "selected", 0, "Type", "Only color selected faces.");
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
130         /* vertex */
131         WM_operatortype_append(PAINT_OT_vertex_paint_radial_control);
132         WM_operatortype_append(PAINT_OT_vertex_paint_toggle);
133         WM_operatortype_append(PAINT_OT_vertex_paint);
134         WM_operatortype_append(PAINT_OT_vertex_color_set);
135 }
136
137 void ED_keymap_paint(wmKeyConfig *keyconf)
138 {
139         wmKeyMap *keymap;
140         
141         /* Sculpt mode */
142         keymap= WM_keymap_find(keyconf, "Sculpt", 0, 0);
143         keymap->poll= sculpt_poll;
144
145         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_radial_control", FKEY, KM_PRESS, 0, 0)->ptr, "mode", WM_RADIALCONTROL_SIZE);
146         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", WM_RADIALCONTROL_STRENGTH);
147         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_radial_control", FKEY, KM_PRESS, KM_CTRL, 0)->ptr, "mode", WM_RADIALCONTROL_ANGLE);
148
149         WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, 0, 0);
150         WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
151
152         /* Vertex Paint mode */
153         keymap= WM_keymap_find(keyconf, "Vertex Paint", 0, 0);
154         keymap->poll= vertex_paint_poll;
155
156         RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_vertex_paint_radial_control", FKEY, KM_PRESS, 0, 0)->ptr, "mode", WM_RADIALCONTROL_SIZE);
157         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);
158         WM_keymap_verify_item(keymap, "PAINT_OT_vertex_paint", LEFTMOUSE, KM_PRESS, 0, 0);
159         WM_keymap_add_item(keymap, "PAINT_OT_sample_color", RIGHTMOUSE, KM_PRESS, 0, 0);
160
161         /* Weight Paint mode */
162         keymap= WM_keymap_find(keyconf, "Weight Paint", 0, 0);
163         keymap->poll= weight_paint_poll;
164
165         RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_weight_paint_radial_control", FKEY, KM_PRESS, 0, 0)->ptr, "mode", WM_RADIALCONTROL_SIZE);
166         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);
167
168         WM_keymap_verify_item(keymap, "PAINT_OT_weight_paint", LEFTMOUSE, KM_PRESS, 0, 0);
169
170         /* Image/Texture Paint mode */
171         keymap= WM_keymap_find(keyconf, "Image Paint", 0, 0);
172         keymap->poll= image_texture_paint_poll;
173
174         RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_texture_paint_radial_control", FKEY, KM_PRESS, 0, 0)->ptr, "mode", WM_RADIALCONTROL_SIZE);
175         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);
176
177         WM_keymap_add_item(keymap, "PAINT_OT_image_paint", LEFTMOUSE, KM_PRESS, 0, 0);
178         WM_keymap_add_item(keymap, "PAINT_OT_sample_color", RIGHTMOUSE, KM_PRESS, 0, 0);
179         WM_keymap_add_item(keymap, "PAINT_OT_clone_cursor_set", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
180 }
181