Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / gpencil / gpencil_ops.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2009, Blender Foundation, Joshua Leung
19  * This is a new part of Blender
20  *
21  * Contributor(s): Joshua Leung, Antonio Vazquez
22  *
23  * ***** END GPL LICENSE BLOCK *****
24  */
25
26 /** \file blender/editors/gpencil/gpencil_ops.c
27  *  \ingroup edgpencil
28  */
29
30
31 #include <stdlib.h>
32 #include <stddef.h>
33 #include <stdio.h>
34
35 #include "BLI_sys_types.h"
36
37 #include "BKE_context.h"
38 #include "BKE_brush.h"
39 #include "BKE_gpencil.h"
40
41 #include "DNA_brush_types.h"
42 #include "DNA_gpencil_types.h"
43 #include "DNA_object_types.h"
44 #include "DNA_screen_types.h"
45 #include "DNA_space_types.h"
46
47 #include "WM_api.h"
48 #include "WM_types.h"
49
50 #include "RNA_access.h"
51
52 #include "ED_gpencil.h"
53 #include "ED_select_utils.h"
54 #include "ED_object.h"
55 #include "ED_transform.h"
56
57 #include "gpencil_intern.h"
58
59 /* ****************************************** */
60 /* Grease Pencil Keymaps */
61
62 /* Generic Drawing Keymap - Annotations */
63 static void ed_keymap_gpencil_general(wmKeyConfig *keyconf)
64 {
65         wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil", 0, 0);
66         wmKeyMapItem *kmi;
67
68         /* Draw  --------------------------------------- */
69         /* draw */
70         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_annotate", LEFTMOUSE, KM_PRESS, 0, DKEY);
71         RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW);
72         RNA_boolean_set(kmi->ptr, "wait_for_input", false);
73
74         /* draw - straight lines */
75         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_annotate", LEFTMOUSE, KM_PRESS, KM_ALT, DKEY);
76         RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW_STRAIGHT);
77         RNA_boolean_set(kmi->ptr, "wait_for_input", false);
78
79         /* draw - poly lines */
80         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_annotate", LEFTMOUSE, KM_PRESS, KM_SHIFT | KM_ALT, DKEY);
81         RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW_POLY);
82         RNA_boolean_set(kmi->ptr, "wait_for_input", false);
83
84         /* erase */
85         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_annotate", RIGHTMOUSE, KM_PRESS, 0, DKEY);
86         RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_ERASER);
87         RNA_boolean_set(kmi->ptr, "wait_for_input", false);
88
89         /* Viewport Tools ------------------------------- */
90
91         /* Enter EditMode */
92         WM_keymap_add_item(keymap, "GPENCIL_OT_editmode_toggle", TABKEY, KM_PRESS, 0, DKEY);
93
94         /* Pie Menu - For standard tools */
95         WM_keymap_add_menu_pie(keymap, "GPENCIL_MT_pie_tool_palette", QKEY, KM_PRESS, 0, DKEY);
96         WM_keymap_add_menu_pie(keymap, "GPENCIL_MT_pie_settings_palette", WKEY, KM_PRESS, 0, DKEY);
97
98         /* Add Blank Frame */
99         /* XXX: BKEY or NKEY? BKEY is easier to reach from DKEY, so we'll use that for now */
100         WM_keymap_add_item(keymap, "GPENCIL_OT_blank_frame_add", BKEY, KM_PRESS, 0, DKEY);
101
102         /* Delete Active Frame - For easier video tutorials/review sessions */
103         /* NOTE: This works even when not in EditMode */
104         WM_keymap_add_item(keymap, "GPENCIL_OT_active_frames_delete_all", XKEY, KM_PRESS, 0, DKEY);
105         WM_keymap_add_item(keymap, "GPENCIL_OT_active_frames_delete_all", DELKEY, KM_PRESS, 0, DKEY);
106 }
107
108 /* ==================== */
109
110 /* Poll callback for stroke editing mode */
111 static bool gp_stroke_editmode_poll(bContext *C)
112 {
113         bGPdata *gpd = CTX_data_gpencil_data(C);
114         return (gpd && (gpd->flag & GP_DATA_STROKE_EDITMODE));
115 }
116
117 /* Poll callback for stroke painting mode */
118 static bool gp_stroke_paintmode_poll(bContext *C)
119 {
120         /* TODO: limit this to mode, but review 2D editors */
121         bGPdata *gpd = CTX_data_gpencil_data(C);
122         return (gpd && (gpd->flag & GP_DATA_STROKE_PAINTMODE));
123 }
124
125 /* Poll callback for stroke painting (draw brush) */
126 static bool gp_stroke_paintmode_draw_poll(bContext *C)
127 {
128         /* TODO: limit this to mode, but review 2D editors */
129         bGPdata *gpd = CTX_data_gpencil_data(C);
130         ToolSettings *ts = CTX_data_tool_settings(C);
131         Brush *brush = BKE_brush_getactive_gpencil(ts);
132         return ((gpd) && (gpd->flag & GP_DATA_STROKE_PAINTMODE) &&
133                 (brush && brush->gpencil_settings) &&
134                 (brush->gpencil_settings->brush_type == GP_BRUSH_TYPE_DRAW));
135 }
136
137 /* Poll callback for stroke painting (erase brush) */
138 static bool gp_stroke_paintmode_erase_poll(bContext *C)
139 {
140         /* TODO: limit this to mode, but review 2D editors */
141         bGPdata *gpd = CTX_data_gpencil_data(C);
142         ToolSettings *ts = CTX_data_tool_settings(C);
143         Brush *brush = BKE_brush_getactive_gpencil(ts);
144         return ((gpd) && (gpd->flag & GP_DATA_STROKE_PAINTMODE) &&
145                 (brush && brush->gpencil_settings) &&
146                 (brush->gpencil_settings->brush_type == GP_BRUSH_TYPE_ERASE));
147 }
148
149 /* Poll callback for stroke painting (fill) */
150 static bool gp_stroke_paintmode_fill_poll(bContext *C)
151 {
152         /* TODO: limit this to mode, but review 2D editors */
153         bGPdata *gpd = CTX_data_gpencil_data(C);
154         ToolSettings *ts = CTX_data_tool_settings(C);
155         Brush *brush = BKE_brush_getactive_gpencil(ts);
156         return ((gpd) && (gpd->flag & GP_DATA_STROKE_PAINTMODE) &&
157                 (brush && brush->gpencil_settings) &&
158                 (brush->gpencil_settings->brush_type == GP_BRUSH_TYPE_FILL));
159 }
160
161 /* Poll callback for stroke sculpting mode */
162 static bool gp_stroke_sculptmode_poll(bContext *C)
163 {
164         bGPdata *gpd = CTX_data_gpencil_data(C);
165         Object *ob = CTX_data_active_object(C);
166         ScrArea *sa = CTX_wm_area(C);
167
168         /* if not gpencil object and not view3d, need sculpt keys if edit mode */
169         if (sa->spacetype != SPACE_VIEW3D) {
170                 return ((gpd) && (gpd->flag & GP_DATA_STROKE_EDITMODE));
171         }
172         else {
173                 /* weight paint is a submode of sculpt */
174                 if ((ob) && (ob->type == OB_GPENCIL)) {
175                         return GPENCIL_SCULPT_OR_WEIGHT_MODE(gpd);
176                 }
177         }
178
179         return 0;
180 }
181
182 /* Poll callback for stroke weight paint mode */
183 static bool gp_stroke_weightmode_poll(bContext *C)
184 {
185         bGPdata *gpd = CTX_data_gpencil_data(C);
186         Object *ob = CTX_data_active_object(C);
187
188         if ((ob) && (ob->type == OB_GPENCIL)) {
189                 return (gpd && (gpd->flag & GP_DATA_STROKE_WEIGHTMODE));
190         }
191
192         return 0;
193 }
194
195 static void ed_keymap_gpencil_selection(wmKeyMap *keymap)
196 {
197         wmKeyMapItem *kmi;
198
199         /* select all */
200         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select_all", AKEY, KM_PRESS, 0, 0);
201         RNA_enum_set(kmi->ptr, "action", SEL_SELECT);
202         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select_all", AKEY, KM_PRESS, KM_ALT, 0);
203         RNA_enum_set(kmi->ptr, "action", SEL_DESELECT);
204
205         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
206         RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
207
208         /* circle select */
209         WM_keymap_add_item(keymap, "GPENCIL_OT_select_circle", CKEY, KM_PRESS, 0, 0);
210
211         /* border select */
212         WM_keymap_add_item(keymap, "GPENCIL_OT_select_border", BKEY, KM_PRESS, 0, 0);
213
214         /* lasso select */
215         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0);
216         RNA_boolean_set(kmi->ptr, "deselect", false);
217         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_SHIFT | KM_CTRL, 0);
218         RNA_boolean_set(kmi->ptr, "deselect", true);
219
220         /* In the Node Editor, lasso select needs ALT modifier too (as somehow CTRL+LMB drag gets taken for "cut" quite early)
221         * There probably isn't too much harm adding this for other editors too as part of standard GP editing keymap. This hotkey
222         * combo doesn't seem to see much use under standard scenarios?
223         */
224         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL | KM_ALT, 0);
225         RNA_boolean_set(kmi->ptr, "deselect", false);
226         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_SHIFT | KM_CTRL | KM_ALT, 0);
227         RNA_boolean_set(kmi->ptr, "deselect", true);
228
229         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
230         RNA_boolean_set(kmi->ptr, "extend", true);
231         RNA_boolean_set(kmi->ptr, "toggle", true);
232
233         /* whole stroke select */
234         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
235         RNA_boolean_set(kmi->ptr, "entire_strokes", true);
236
237         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select", SELECTMOUSE, KM_PRESS, KM_ALT | KM_SHIFT, 0);
238         RNA_boolean_set(kmi->ptr, "entire_strokes", true);
239         RNA_boolean_set(kmi->ptr, "extend", true);
240
241         /* select linked */
242         /* NOTE: While LKEY is redundant, not having it breaks the mode illusion too much */
243         WM_keymap_add_item(keymap, "GPENCIL_OT_select_linked", LKEY, KM_PRESS, 0, 0);
244         WM_keymap_add_item(keymap, "GPENCIL_OT_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
245
246         /* select alternate */
247         WM_keymap_add_item(keymap, "GPENCIL_OT_select_alternate", LKEY, KM_PRESS, KM_SHIFT, 0);
248
249         /* select grouped */
250         WM_keymap_add_item(keymap, "GPENCIL_OT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0);
251
252         /* select more/less */
253         WM_keymap_add_item(keymap, "GPENCIL_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
254         WM_keymap_add_item(keymap, "GPENCIL_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
255 }
256
257 static void ed_keymap_gpencil_display(wmKeyMap *keymap)
258 {
259         wmKeyMapItem *kmi;
260
261         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", QKEY, KM_PRESS, KM_SHIFT, 0);
262         RNA_string_set(kmi->ptr, "data_path", "space_data.overlay.use_gpencil_edit_lines");
263
264         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", QKEY, KM_PRESS, KM_SHIFT | KM_ALT, 0);
265         RNA_string_set(kmi->ptr, "data_path", "space_data.overlay.use_gpencil_multiedit_line_only");
266 }
267
268 static void ed_keymap_gpencil_sculpt(wmKeyMap *keymap)
269 {
270         wmKeyMapItem *kmi;
271
272         /* Pie Menu - For settings/tools easy access */
273         WM_keymap_add_menu_pie(keymap, "GPENCIL_PIE_sculpt", EKEY, KM_PRESS, 0, DKEY);
274
275         /* Sculpting ------------------------------------- */
276
277         /* Brush-Based Editing:
278         *   EKEY + LMB                          = Single stroke, draw immediately
279         *        + Other Modifiers (Ctrl/Shift) = Invert, Smooth, etc.
280         *
281         * For the modal version, use D+E -> Sculpt
282         */
283         /* GPXX: disabled to make toolsystem works */
284         //kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_brush_paint", LEFTMOUSE, KM_PRESS, 0, 0);
285         //RNA_boolean_set(kmi->ptr, "wait_for_input", false);
286
287         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_brush_paint", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
288         RNA_boolean_set(kmi->ptr, "wait_for_input", false);
289         RNA_boolean_set(kmi->ptr, "keep_brush", true);
290         /*RNA_boolean_set(kmi->ptr, "use_invert", true);*/
291
292         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_brush_paint", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
293         RNA_boolean_set(kmi->ptr, "wait_for_input", false);
294         RNA_boolean_set(kmi->ptr, "keep_brush", true);
295         /*RNA_boolean_set(kmi->ptr, "use_smooth", true);*/
296
297         /* Shift-FKEY = Sculpt Strength */
298         kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0);
299         RNA_string_set(kmi->ptr, "data_path_primary", "tool_settings.gpencil_sculpt.brush.strength");
300
301         /* FKEY = Sculpt Brush Size */
302         kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, 0, 0);
303         RNA_string_set(kmi->ptr, "data_path_primary", "tool_settings.gpencil_sculpt.brush.size");
304
305         /* menu sculpt specials */
306         WM_keymap_add_menu(keymap, "VIEW3D_MT_gpencil_sculpt_specials", WKEY, KM_PRESS, 0, 0);
307 }
308
309 static void ed_keymap_gpencil_weight(wmKeyMap *keymap)
310 {
311         wmKeyMapItem *kmi;
312
313
314         /* Brush-Based Editing:
315         *   EKEY + LMB                          = Single stroke, draw immediately
316         *        + Other Modifiers (Ctrl/Shift) = Invert, Smooth, etc.
317         *
318         * For the modal version, use D+E -> Sculpt
319         */
320         /* GPXX: disabled to make toolsystem works */
321         //kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_brush_paint", LEFTMOUSE, KM_PRESS, 0, 0);
322         //RNA_boolean_set(kmi->ptr, "wait_for_input", false);
323
324         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_brush_paint", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
325         RNA_boolean_set(kmi->ptr, "wait_for_input", false);
326         RNA_boolean_set(kmi->ptr, "keep_brush", true);
327         /*RNA_boolean_set(kmi->ptr, "use_invert", true);*/
328
329         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_brush_paint", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
330         RNA_boolean_set(kmi->ptr, "wait_for_input", false);
331         RNA_boolean_set(kmi->ptr, "keep_brush", true);
332         /*RNA_boolean_set(kmi->ptr, "use_smooth", true);*/
333 }
334
335 /* Stroke Editing Keymap - Only when editmode is enabled */
336 static void ed_keymap_gpencil_editing(wmKeyConfig *keyconf)
337 {
338         wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Edit Mode", 0, 0);
339         wmKeyMapItem *kmi;
340
341         /* set poll callback - so that this keymap only gets enabled when stroke editmode is enabled */
342         keymap->poll = gp_stroke_editmode_poll;
343
344         /* ----------------------------------------------- */
345
346         /* Brush Settings */
347         /* NOTE: We cannot expose these in the standard keymap, as they will interfere with regular hotkeys
348          *       in other modes. However, when we are dealing with Stroke Edit Mode, we know for certain
349          *       that the only data being edited is that of the Grease Pencil strokes
350          */
351
352         /* Interpolation */
353         WM_keymap_add_item(keymap, "GPENCIL_OT_interpolate", EKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
354         WM_keymap_add_item(keymap, "GPENCIL_OT_interpolate_sequence", EKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
355
356         /* normal select */
357         WM_keymap_add_item(keymap, "GPENCIL_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
358
359         /* Selection */
360         ed_keymap_gpencil_selection(keymap);
361
362         /* Editing ----------------------------------------- */
363
364         /* duplicate and move selected points */
365         WM_keymap_add_item(keymap, "GPENCIL_OT_duplicate_move", DKEY, KM_PRESS, KM_SHIFT, 0);
366
367         /* delete */
368         WM_keymap_add_menu(keymap, "VIEW3D_MT_edit_gpencil_delete", XKEY, KM_PRESS, 0, 0);
369         WM_keymap_add_menu(keymap, "VIEW3D_MT_edit_gpencil_delete", DELKEY, KM_PRESS, 0, 0);
370
371         WM_keymap_add_item(keymap, "GPENCIL_OT_dissolve", XKEY, KM_PRESS, KM_CTRL, 0);
372         WM_keymap_add_item(keymap, "GPENCIL_OT_dissolve", DELKEY, KM_PRESS, KM_CTRL, 0);
373
374         WM_keymap_add_item(keymap, "GPENCIL_OT_active_frames_delete_all", XKEY, KM_PRESS, KM_SHIFT, 0);
375         WM_keymap_add_item(keymap, "GPENCIL_OT_active_frames_delete_all", DELKEY, KM_PRESS, KM_SHIFT, 0);
376
377         /* menu edit specials */
378         WM_keymap_add_menu(keymap, "VIEW3D_MT_gpencil_edit_specials", WKEY, KM_PRESS, 0, 0);
379
380         /* menu separate */
381         WM_keymap_add_menu(keymap, "GPENCIL_MT_separate", PKEY, KM_PRESS, 0, 0);
382
383         /* split strokes */
384         WM_keymap_add_item(keymap, "GPENCIL_OT_stroke_split", VKEY, KM_PRESS, 0, 0);
385
386         /* join strokes */
387         WM_keymap_add_item(keymap, "GPENCIL_OT_stroke_join", JKEY, KM_PRESS, KM_CTRL, 0);
388
389         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_stroke_join", JKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
390         RNA_enum_set(kmi->ptr, "type", GP_STROKE_JOINCOPY);
391
392         /* copy + paste */
393         WM_keymap_add_item(keymap, "GPENCIL_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
394         WM_keymap_add_item(keymap, "GPENCIL_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
395
396 #ifdef __APPLE__
397         WM_keymap_add_item(keymap, "GPENCIL_OT_copy", CKEY, KM_PRESS, KM_OSKEY, 0);
398         WM_keymap_add_item(keymap, "GPENCIL_OT_paste", VKEY, KM_PRESS, KM_OSKEY, 0);
399 #endif
400
401         /* snap */
402         WM_keymap_add_menu(keymap, "GPENCIL_MT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
403
404         /* convert to geometry */
405         WM_keymap_add_item(keymap, "GPENCIL_OT_convert", CKEY, KM_PRESS, KM_ALT, 0);
406
407
408         /* Show/Hide */
409         /* NOTE: These are available only in EditMode now, since they clash with general-purpose hotkeys */
410         WM_keymap_add_item(keymap, "GPENCIL_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0);
411
412         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_hide", HKEY, KM_PRESS, 0, 0);
413         RNA_boolean_set(kmi->ptr, "unselected", false);
414
415         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
416         RNA_boolean_set(kmi->ptr, "unselected", true);
417
418         WM_keymap_add_item(keymap, "GPENCIL_OT_selection_opacity_toggle", HKEY, KM_PRESS, KM_CTRL, 0);
419
420         /* Display. */
421         ed_keymap_gpencil_display(keymap);
422
423         /* Isolate Layer */
424         WM_keymap_add_item(keymap, "GPENCIL_OT_layer_isolate", PADASTERKEY, KM_PRESS, 0, 0);
425
426         /* Move to Layer */
427         WM_keymap_add_item(keymap, "GPENCIL_OT_move_to_layer", MKEY, KM_PRESS, 0, 0);
428
429         /* Transform Tools */
430         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", GKEY, KM_PRESS, 0, 0);
431
432         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", EVT_TWEAK_S, KM_ANY, 0, 0);
433
434         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_rotate", RKEY, KM_PRESS, 0, 0);
435
436         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_resize", SKEY, KM_PRESS, 0, 0);
437
438         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_mirror", MKEY, KM_PRESS, KM_CTRL, 0);
439
440         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_bend", WKEY, KM_PRESS, KM_SHIFT, 0);
441
442         WM_keymap_add_item(keymap, "TRANSFORM_OT_tosphere", SKEY, KM_PRESS, KM_ALT | KM_SHIFT, 0);
443
444         WM_keymap_add_item(keymap, "TRANSFORM_OT_shear", SKEY, KM_PRESS, KM_ALT | KM_CTRL | KM_SHIFT, 0);
445
446         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, KM_ALT, 0);
447         RNA_enum_set(kmi->ptr, "mode", TFM_GPENCIL_SHRINKFATTEN);
448
449         /* Proportional Editing */
450         ED_keymap_proportional_cycle(keyconf, keymap);
451         ED_keymap_proportional_editmode(keyconf, keymap, true);
452
453         /* menu - add GP object (3d view only) */
454         WM_keymap_add_item(keymap, "OBJECT_OT_gpencil_add", AKEY, KM_PRESS, KM_SHIFT, 0);
455
456         /* menu vertex group */
457         WM_keymap_add_menu(keymap, "GPENCIL_MT_gpencil_vertex_group", GKEY, KM_PRESS, KM_CTRL, 0);
458
459         /* toggle edit mode */
460         WM_keymap_add_item(keymap, "GPENCIL_OT_editmode_toggle", TABKEY, KM_PRESS, 0, 0);
461 }
462
463 /* keys for draw with a drawing brush (no fill) */
464 static void ed_keymap_gpencil_painting_draw(wmKeyConfig *keyconf)
465 {
466         wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Paint (Draw brush)", 0, 0);
467         wmKeyMapItem *kmi;
468
469         /* set poll callback */
470         keymap->poll = gp_stroke_paintmode_draw_poll;
471
472         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, 0, 0);
473         RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW);
474         RNA_boolean_set(kmi->ptr, "wait_for_input", false);
475
476         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
477         RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW);
478         RNA_boolean_set(kmi->ptr, "wait_for_input", false);
479
480         /* draw - straight lines */
481         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, KM_ALT, 0);
482         RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW_STRAIGHT);
483         RNA_boolean_set(kmi->ptr, "wait_for_input", false);
484
485         /* draw - poly lines */
486         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, KM_SHIFT | KM_ALT, 0);
487         RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW_POLY);
488         RNA_boolean_set(kmi->ptr, "wait_for_input", false);
489
490         /* erase */
491         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
492         RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_ERASER);
493         RNA_boolean_set(kmi->ptr, "wait_for_input", false);
494
495         /* Tablet Mappings for Drawing ------------------ */
496         /* For now, only support direct drawing using the eraser, as most users using a tablet
497         * may still want to use that as their primary pointing device!
498         */
499 #if 0
500         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", TABLET_STYLUS, KM_PRESS, 0, 0);
501         RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW);
502         RNA_boolean_set(kmi->ptr, "wait_for_input", false);
503 #endif
504
505         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", TABLET_ERASER, KM_PRESS, 0, 0);
506         RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_ERASER);
507         RNA_boolean_set(kmi->ptr, "wait_for_input", false);
508
509         /* Selection (used by eraser) */
510         /* border select */
511         WM_keymap_add_item(keymap, "GPENCIL_OT_select_border", BKEY, KM_PRESS, 0, 0);
512
513         /* lasso select */
514         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL | KM_ALT, 0);
515         RNA_boolean_set(kmi->ptr, "deselect", false);
516 }
517
518 /* keys for draw with a eraser brush (erase) */
519 static void ed_keymap_gpencil_painting_erase(wmKeyConfig *keyconf)
520 {
521         wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Paint (Erase)", 0, 0);
522         wmKeyMapItem *kmi;
523
524         /* set poll callback */
525         keymap->poll = gp_stroke_paintmode_erase_poll;
526
527         /* erase */
528         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, 0, 0);
529         RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_ERASER);
530         RNA_boolean_set(kmi->ptr, "wait_for_input", false);
531
532         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", TABLET_ERASER, KM_PRESS, 0, 0);
533         RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_ERASER);
534         RNA_boolean_set(kmi->ptr, "wait_for_input", false);
535
536         /* Selection (used by eraser) */
537         /* border select */
538         WM_keymap_add_item(keymap, "GPENCIL_OT_select_border", BKEY, KM_PRESS, 0, 0);
539
540         /* lasso select */
541         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL | KM_ALT, 0);
542         RNA_boolean_set(kmi->ptr, "deselect", false);
543 }
544
545 /* keys for draw with a fill brush */
546 static void ed_keymap_gpencil_painting_fill(wmKeyConfig *keyconf)
547 {
548         wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Paint (Fill)", 0, 0);
549         wmKeyMapItem *kmi;
550
551         /* set poll callback */
552         keymap->poll = gp_stroke_paintmode_fill_poll;
553
554         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_fill", LEFTMOUSE, KM_PRESS, 0, 0);
555         RNA_boolean_set(kmi->ptr, "on_back", false);
556
557         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_fill", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
558         RNA_boolean_set(kmi->ptr, "on_back", true);
559
560         /* if press alternative key, the brush now it's for drawing areas */
561         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
562         RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW);
563         RNA_boolean_set(kmi->ptr, "wait_for_input", false);
564         /* disable straight lines */
565         RNA_boolean_set(kmi->ptr, "disable_straight", true);
566
567         /* if press alternative key, the brush now it's for drawing lines */
568         kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, KM_ALT, 0);
569         RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW);
570         RNA_boolean_set(kmi->ptr, "wait_for_input", false);
571         /* disable straight lines */
572         RNA_boolean_set(kmi->ptr, "disable_straight", true);
573         /* enable special stroke with no fill flag */
574         RNA_boolean_set(kmi->ptr, "disable_fill", true);
575 }
576
577 /* Stroke Painting Keymap - Only when paintmode is enabled */
578 static void ed_keymap_gpencil_painting(wmKeyConfig *keyconf)
579 {
580         wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Paint Mode", 0, 0);
581         wmKeyMapItem *kmi;
582
583         /* set poll callback - so that this keymap only gets enabled when stroke paintmode is enabled */
584         keymap->poll = gp_stroke_paintmode_poll;
585
586         /* FKEY = Brush Size */
587         kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, 0, 0);
588         RNA_string_set(kmi->ptr, "data_path_primary", "tool_settings.gpencil_paint.brush.size");
589
590         /* CTRL + FKEY = Eraser Radius */
591         kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_CTRL, 0);
592         RNA_string_set(kmi->ptr, "data_path_primary", "user_preferences.edit.grease_pencil_eraser_radius");
593
594         /* menu draw specials */
595         WM_keymap_add_menu(keymap, "GPENCIL_MT_gpencil_draw_specials", WKEY, KM_PRESS, 0, 0);
596
597         /* menu draw delete */
598         WM_keymap_add_menu(keymap, "GPENCIL_MT_gpencil_draw_delete", XKEY, KM_PRESS, 0, 0);
599
600 }
601
602 /* Stroke Sculpting Keymap - Only when sculptmode is enabled */
603 static void ed_keymap_gpencil_sculpting(wmKeyConfig *keyconf)
604 {
605         wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Sculpt Mode", 0, 0);
606
607         /* set poll callback - so that this keymap only gets enabled when stroke sculptmode is enabled */
608         keymap->poll = gp_stroke_sculptmode_poll;
609
610         /* Selection */
611         ed_keymap_gpencil_selection(keymap);
612
613         /* sculpt */
614         ed_keymap_gpencil_sculpt(keymap);
615
616         /* Display. */
617         ed_keymap_gpencil_display(keymap);
618 }
619
620 /* Stroke Weight Paint Keymap - Only when weight is enabled */
621 static void ed_keymap_gpencil_weightpainting(wmKeyConfig *keyconf)
622 {
623         wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Weight Mode", 0, 0);
624         wmKeyMapItem *kmi;
625
626         /* set poll callback - so that this keymap only gets enabled when stroke sculptmode is enabled */
627         keymap->poll = gp_stroke_weightmode_poll;
628
629         /* Selection */
630         ed_keymap_gpencil_selection(keymap);
631
632         /* sculpt */
633         ed_keymap_gpencil_weight(keymap);
634
635         /* Shift-FKEY = Sculpt Strength */
636         kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0);
637         RNA_string_set(kmi->ptr, "data_path_primary", "tool_settings.gpencil_sculpt.weight_brush.strength");
638
639         /* FKEY = Sculpt Brush Size */
640         kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, 0, 0);
641         RNA_string_set(kmi->ptr, "data_path_primary", "tool_settings.gpencil_sculpt.weight_brush.size");
642
643         /* Display. */
644         ed_keymap_gpencil_display(keymap);
645 }
646 /* ==================== */
647
648 void ED_keymap_gpencil(wmKeyConfig *keyconf)
649 {
650         ed_keymap_gpencil_general(keyconf);
651         ed_keymap_gpencil_editing(keyconf);
652         ed_keymap_gpencil_painting(keyconf);
653         ed_keymap_gpencil_painting_draw(keyconf);
654         ed_keymap_gpencil_painting_erase(keyconf);
655         ed_keymap_gpencil_painting_fill(keyconf);
656         ed_keymap_gpencil_sculpting(keyconf);
657         ed_keymap_gpencil_weightpainting(keyconf);
658 }
659
660 /* ****************************************** */
661
662 void ED_operatortypes_gpencil(void)
663 {
664         /* Annotations -------------------- */
665
666         WM_operatortype_append(GPENCIL_OT_annotate);
667
668         /* Drawing ----------------------- */
669
670         WM_operatortype_append(GPENCIL_OT_draw);
671         WM_operatortype_append(GPENCIL_OT_fill);
672
673         /* Editing (Strokes) ------------ */
674
675         WM_operatortype_append(GPENCIL_OT_editmode_toggle);
676         WM_operatortype_append(GPENCIL_OT_paintmode_toggle);
677         WM_operatortype_append(GPENCIL_OT_sculptmode_toggle);
678         WM_operatortype_append(GPENCIL_OT_weightmode_toggle);
679         WM_operatortype_append(GPENCIL_OT_selection_opacity_toggle);
680
681         WM_operatortype_append(GPENCIL_OT_select);
682         WM_operatortype_append(GPENCIL_OT_select_all);
683         WM_operatortype_append(GPENCIL_OT_select_circle);
684         WM_operatortype_append(GPENCIL_OT_select_border);
685         WM_operatortype_append(GPENCIL_OT_select_lasso);
686
687         WM_operatortype_append(GPENCIL_OT_select_linked);
688         WM_operatortype_append(GPENCIL_OT_select_grouped);
689         WM_operatortype_append(GPENCIL_OT_select_more);
690         WM_operatortype_append(GPENCIL_OT_select_less);
691         WM_operatortype_append(GPENCIL_OT_select_first);
692         WM_operatortype_append(GPENCIL_OT_select_last);
693         WM_operatortype_append(GPENCIL_OT_select_alternate);
694
695         WM_operatortype_append(GPENCIL_OT_duplicate);
696         WM_operatortype_append(GPENCIL_OT_delete);
697         WM_operatortype_append(GPENCIL_OT_dissolve);
698         WM_operatortype_append(GPENCIL_OT_copy);
699         WM_operatortype_append(GPENCIL_OT_paste);
700
701         WM_operatortype_append(GPENCIL_OT_move_to_layer);
702         WM_operatortype_append(GPENCIL_OT_layer_change);
703
704         WM_operatortype_append(GPENCIL_OT_snap_to_grid);
705         WM_operatortype_append(GPENCIL_OT_snap_to_cursor);
706         WM_operatortype_append(GPENCIL_OT_snap_cursor_to_selected);
707
708         WM_operatortype_append(GPENCIL_OT_reproject);
709
710         WM_operatortype_append(GPENCIL_OT_brush_paint);
711
712         /* Editing (Buttons) ------------ */
713
714         WM_operatortype_append(GPENCIL_OT_data_add);
715         WM_operatortype_append(GPENCIL_OT_data_unlink);
716
717         WM_operatortype_append(GPENCIL_OT_layer_add);
718         WM_operatortype_append(GPENCIL_OT_layer_remove);
719         WM_operatortype_append(GPENCIL_OT_layer_move);
720         WM_operatortype_append(GPENCIL_OT_layer_duplicate);
721         WM_operatortype_append(GPENCIL_OT_layer_duplicate_object);
722
723         WM_operatortype_append(GPENCIL_OT_hide);
724         WM_operatortype_append(GPENCIL_OT_reveal);
725         WM_operatortype_append(GPENCIL_OT_lock_all);
726         WM_operatortype_append(GPENCIL_OT_unlock_all);
727         WM_operatortype_append(GPENCIL_OT_layer_isolate);
728         WM_operatortype_append(GPENCIL_OT_layer_merge);
729
730         WM_operatortype_append(GPENCIL_OT_blank_frame_add);
731
732         WM_operatortype_append(GPENCIL_OT_active_frame_delete);
733         WM_operatortype_append(GPENCIL_OT_active_frames_delete_all);
734         WM_operatortype_append(GPENCIL_OT_frame_duplicate);
735         WM_operatortype_append(GPENCIL_OT_frame_clean_fill);
736         WM_operatortype_append(GPENCIL_OT_frame_clean_loose);
737
738         WM_operatortype_append(GPENCIL_OT_convert);
739
740         WM_operatortype_append(GPENCIL_OT_stroke_arrange);
741         WM_operatortype_append(GPENCIL_OT_stroke_change_color);
742         WM_operatortype_append(GPENCIL_OT_stroke_lock_color);
743         WM_operatortype_append(GPENCIL_OT_stroke_apply_thickness);
744         WM_operatortype_append(GPENCIL_OT_stroke_cyclical_set);
745         WM_operatortype_append(GPENCIL_OT_stroke_join);
746         WM_operatortype_append(GPENCIL_OT_stroke_flip);
747         WM_operatortype_append(GPENCIL_OT_stroke_subdivide);
748         WM_operatortype_append(GPENCIL_OT_stroke_simplify);
749         WM_operatortype_append(GPENCIL_OT_stroke_simplify_fixed);
750         WM_operatortype_append(GPENCIL_OT_stroke_separate);
751         WM_operatortype_append(GPENCIL_OT_stroke_split);
752
753         WM_operatortype_append(GPENCIL_OT_brush_presets_create);
754         WM_operatortype_append(GPENCIL_OT_brush_select);
755
756         WM_operatortype_append(GPENCIL_OT_sculpt_select);
757
758         /* vertex groups */
759         WM_operatortype_append(GPENCIL_OT_vertex_group_assign);
760         WM_operatortype_append(GPENCIL_OT_vertex_group_remove_from);
761         WM_operatortype_append(GPENCIL_OT_vertex_group_select);
762         WM_operatortype_append(GPENCIL_OT_vertex_group_deselect);
763         WM_operatortype_append(GPENCIL_OT_vertex_group_invert);
764         WM_operatortype_append(GPENCIL_OT_vertex_group_smooth);
765
766         /* color handle */
767         WM_operatortype_append(GPENCIL_OT_lock_layer);
768         WM_operatortype_append(GPENCIL_OT_color_isolate);
769         WM_operatortype_append(GPENCIL_OT_color_hide);
770         WM_operatortype_append(GPENCIL_OT_color_reveal);
771         WM_operatortype_append(GPENCIL_OT_color_lock_all);
772         WM_operatortype_append(GPENCIL_OT_color_unlock_all);
773         WM_operatortype_append(GPENCIL_OT_color_select);
774
775         /* Editing (Time) --------------- */
776
777         /* Interpolation */
778         WM_operatortype_append(GPENCIL_OT_interpolate);
779         WM_operatortype_append(GPENCIL_OT_interpolate_sequence);
780         WM_operatortype_append(GPENCIL_OT_interpolate_reverse);
781
782         /* Primitives */
783         WM_operatortype_append(GPENCIL_OT_primitive);
784
785         /* convert old 2.7 files to 2.8 */
786         WM_operatortype_append(GPENCIL_OT_convert_old_files);
787
788         /* armatures */
789         WM_operatortype_append(GPENCIL_OT_generate_weights);
790 }
791
792 void ED_operatormacros_gpencil(void)
793 {
794         wmOperatorType *ot;
795         wmOperatorTypeMacro *otmacro;
796
797         /* Duplicate + Move = Interactively place newly duplicated strokes */
798         ot = WM_operatortype_append_macro("GPENCIL_OT_duplicate_move", "Duplicate Strokes",
799                                           "Make copies of the selected Grease Pencil strokes and move them",
800                                           OPTYPE_UNDO | OPTYPE_REGISTER);
801         WM_operatortype_macro_define(ot, "GPENCIL_OT_duplicate");
802         otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
803         RNA_boolean_set(otmacro->ptr, "gpencil_strokes", true);
804
805 }
806
807 /* ****************************************** */