Blender V4.3
grease_pencil_ops.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "BKE_context.hh"
10#include "BKE_material.h"
11#include "BKE_paint.hh"
12
13#include "DNA_brush_enums.h"
14#include "DNA_object_enums.h"
15#include "DNA_scene_types.h"
16
17#include "ED_grease_pencil.hh"
18#include "ED_screen.hh"
19
20#include "WM_api.hh"
21#include "WM_toolsystem.hh"
22#include "WM_types.hh"
23
24#include "RNA_access.hh"
25
27
29{
31 return grease_pencil != nullptr;
32}
33
35{
36 Object *object = CTX_data_active_object(C);
37 if (object == nullptr || object->type != OB_GREASE_PENCIL) {
38 return false;
39 }
40 return true;
41}
42
44{
45 Object *object = CTX_data_active_object(C);
46 if (object == nullptr || object->type != OB_GREASE_PENCIL) {
47 return false;
48 }
49 short *totcolp = BKE_object_material_len_p(object);
50 return *totcolp > 0;
51}
52
54{
55 Object *object = CTX_data_active_object(C);
56 if (object == nullptr || object->type != OB_GREASE_PENCIL) {
57 return false;
58 }
60 return false;
61 }
62 return true;
63}
64
66{
68 return grease_pencil && grease_pencil->has_active_layer();
69}
70
72{
74 return false;
75 }
76
77 /* Allowed: point and segment selection mode, not allowed: stroke selection mode. */
80}
81
83{
85 return false;
86 }
87 Object *object = CTX_data_active_object(C);
88 /* Selection operators are available in multiple modes, e.g. for masking in sculpt and vertex
89 * paint mode. */
90 if (!ELEM(
92 {
93 return false;
94 }
95 return true;
96}
97
99{
101 return false;
102 }
103 Object *object = CTX_data_active_object(C);
104 if ((object->mode & OB_MODE_PAINT_GREASE_PENCIL) == 0) {
105 return false;
106 }
108 if (!ts || !ts->gp_paint) {
109 return false;
110 }
111 return true;
112}
113
115{
117 return false;
118 }
119 Object *object = CTX_data_active_object(C);
120 if ((object->mode & OB_MODE_EDIT) == 0) {
121 return false;
122 }
123 return true;
124}
125
127{
129 return false;
130 }
131 Object *object = CTX_data_active_object(C);
132 if ((object->mode & OB_MODE_SCULPT_GREASE_PENCIL) == 0) {
133 return false;
134 }
136 if (!ts || !ts->gp_sculptpaint) {
137 return false;
138 }
139 return true;
140}
141
143{
145 return false;
146 }
147 Object *object = CTX_data_active_object(C);
148 if ((object->mode & OB_MODE_WEIGHT_GREASE_PENCIL) == 0) {
149 return false;
150 }
152 if (!ts || !ts->gp_weightpaint) {
153 return false;
154 }
155 return true;
156}
157
159{
161 return false;
162 }
163 Object *object = CTX_data_active_object(C);
164 if ((object->mode & OB_MODE_VERTEX_GREASE_PENCIL) == 0) {
165 return false;
166 }
168 if (!ts || !ts->gp_vertexpaint) {
169 return false;
170 }
171 return true;
172}
173
175{
176 wmKeyMap *keymap = WM_keymap_ensure(
177 keyconf, "Grease Pencil Selection", SPACE_EMPTY, RGN_TYPE_WINDOW);
179}
180
182{
183 wmKeyMap *keymap = WM_keymap_ensure(
184 keyconf, "Grease Pencil Edit Mode", SPACE_EMPTY, RGN_TYPE_WINDOW);
186}
187
189{
190 wmKeyMap *keymap = WM_keymap_ensure(
191 keyconf, "Grease Pencil Paint Mode", SPACE_EMPTY, RGN_TYPE_WINDOW);
193}
194
196{
197 wmKeyMap *keymap = WM_keymap_ensure(
198 keyconf, "Grease Pencil Sculpt Mode", SPACE_EMPTY, RGN_TYPE_WINDOW);
200}
201
203{
204 wmKeyMap *keymap = WM_keymap_ensure(
205 keyconf, "Grease Pencil Weight Paint", SPACE_EMPTY, RGN_TYPE_WINDOW);
207}
208
210{
211 wmKeyMap *keymap = WM_keymap_ensure(
212 keyconf, "Grease Pencil Vertex Paint", SPACE_EMPTY, RGN_TYPE_WINDOW);
214}
215
216/* Enabled for all tools except the fill tool and primitive tools. */
218{
220 return false;
221 }
223 return false;
224 }
225
226 /* Don't use the normal brush stroke keymap while the primitive tools are active. Otherwise
227 * simple mouse presses start freehand drawing instead of invoking the primitive operators. Could
228 * be a flag on the tool itself, for now making it a hardcoded exception. */
229 if (const bToolRef *tref = WM_toolsystem_ref_from_context(C)) {
230 const Set<StringRef> primitive_tools = {
231 "builtin.line",
232 "builtin.polyline",
233 "builtin.arc",
234 "builtin.curve",
235 "builtin.box",
236 "builtin.circle",
237 };
238 if (primitive_tools.contains(tref->idname)) {
239 return false;
240 }
241 }
242
244 Brush *brush = BKE_paint_brush(&ts->gp_paint->paint);
245 return brush && brush->gpencil_settings && brush->gpencil_brush_type != GPAINT_BRUSH_TYPE_FILL;
246}
247
249{
250 wmKeyMap *keymap = WM_keymap_ensure(
251 keyconf, "Grease Pencil Brush Stroke", SPACE_EMPTY, RGN_TYPE_WINDOW);
253}
254
255/* Enabled only for the fill tool. */
257{
259 return false;
260 }
262 return false;
263 }
265 Brush *brush = BKE_paint_brush(&ts->gp_paint->paint);
266 return brush && brush->gpencil_settings && brush->gpencil_brush_type == GPAINT_BRUSH_TYPE_FILL;
267}
268
270{
271 wmKeyMap *keymap = WM_keymap_ensure(
272 keyconf, "Grease Pencil Fill Tool", SPACE_EMPTY, RGN_TYPE_WINDOW);
274}
275
276} // namespace blender::ed::greasepencil
277
296
298{
300 wmOperatorTypeMacro *otmacro;
301
302 /* Duplicate + Move = Interactively place newly duplicated strokes */
304 "GREASE_PENCIL_OT_duplicate_move",
305 "Duplicate Strokes",
306 "Make copies of the selected Grease Pencil strokes and move them",
308 WM_operatortype_macro_define(ot, "GREASE_PENCIL_OT_duplicate");
309 otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
310 RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false);
311 RNA_boolean_set(otmacro->ptr, "mirror", false);
312
313 /* Subdivide and Smooth. */
314 ot = WM_operatortype_append_macro("GREASE_PENCIL_OT_stroke_subdivide_smooth",
315 "Subdivide and Smooth",
316 "Subdivide strokes and smooth them",
318 WM_operatortype_macro_define(ot, "GREASE_PENCIL_OT_stroke_subdivide");
319 WM_operatortype_macro_define(ot, "GREASE_PENCIL_OT_stroke_smooth");
320
321 /* Extrude + Move = Interactively add new points */
322 ot = WM_operatortype_append_macro("GREASE_PENCIL_OT_extrude_move",
323 "Extrude Stroke Points",
324 "Extrude selected points and move them",
326 WM_operatortype_macro_define(ot, "GREASE_PENCIL_OT_extrude");
327 otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
328 RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false);
329 RNA_boolean_set(otmacro->ptr, "mirror", false);
330}
331
333{
334 using namespace blender::ed::greasepencil;
335 keymap_grease_pencil_selection(keyconf);
336 keymap_grease_pencil_edit_mode(keyconf);
337 keymap_grease_pencil_paint_mode(keyconf);
338 keymap_grease_pencil_sculpt_mode(keyconf);
339 keymap_grease_pencil_weight_paint_mode(keyconf);
340 keymap_grease_pencil_vertex_paint_mode(keyconf);
341 keymap_grease_pencil_brush_stroke(keyconf);
342 keymap_grease_pencil_fill_tool(keyconf);
343
347}
Object * CTX_data_active_object(const bContext *C)
ToolSettings * CTX_data_tool_settings(const bContext *C)
General operations, lookup, etc. for materials.
short * BKE_object_material_len_p(struct Object *ob)
Brush * BKE_paint_brush(Paint *paint)
Definition paint.cc:649
#define ELEM(...)
@ GPAINT_BRUSH_TYPE_FILL
@ OB_MODE_VERTEX_GREASE_PENCIL
@ OB_MODE_EDIT
@ OB_MODE_PAINT_GREASE_PENCIL
@ OB_MODE_SCULPT_GREASE_PENCIL
@ OB_MODE_WEIGHT_GREASE_PENCIL
@ OB_GREASE_PENCIL
@ GP_SELECTMODE_STROKE
@ RGN_TYPE_WINDOW
@ SPACE_EMPTY
void ED_interpolatetool_modal_keymap(wmKeyConfig *keyconf)
void ED_operatortypes_grease_pencil_trace()
void ED_filltool_modal_keymap(wmKeyConfig *keyconf)
void ED_operatortypes_grease_pencil_draw()
void ED_operatortypes_grease_pencil_interpolate()
bool ED_operator_object_active_editable_ex(bContext *C, const Object *ob)
@ OPTYPE_UNDO
Definition WM_types.hh:162
@ OPTYPE_REGISTER
Definition WM_types.hh:160
bool contains(const Key &key) const
Definition BLI_set.hh:291
void ED_operatortypes_grease_pencil_bake_animation()
void ED_operatortypes_grease_pencil_edit()
void ED_operatortypes_grease_pencil_frames()
void ED_operatortypes_grease_pencil_join()
void ED_operatortypes_grease_pencil_layers()
void ED_operatortypes_grease_pencil_lineart()
void ED_operatortypes_grease_pencil_material()
void ED_operatortypes_grease_pencil_modes()
void ED_operatormacros_grease_pencil()
void ED_keymap_grease_pencil(wmKeyConfig *keyconf)
void ED_operatortypes_grease_pencil()
void ED_primitivetool_modal_keymap(wmKeyConfig *keyconf)
void ED_operatortypes_grease_pencil_primitives()
void ED_operatortypes_grease_pencil_select()
void ED_operatortypes_grease_pencil_weight_paint()
bool active_grease_pencil_poll(bContext *C)
static void keymap_grease_pencil_edit_mode(wmKeyConfig *keyconf)
static void keymap_grease_pencil_vertex_paint_mode(wmKeyConfig *keyconf)
static void keymap_grease_pencil_fill_tool(wmKeyConfig *keyconf)
GreasePencil * from_context(bContext &C)
bool grease_pencil_vertex_painting_poll(bContext *C)
static bool keymap_grease_pencil_fill_tool_poll(bContext *C)
bool editable_grease_pencil_point_selection_poll(bContext *C)
static void keymap_grease_pencil_paint_mode(wmKeyConfig *keyconf)
static void keymap_grease_pencil_weight_paint_mode(wmKeyConfig *keyconf)
bool editable_grease_pencil_poll(bContext *C)
bool grease_pencil_selection_poll(bContext *C)
static void keymap_grease_pencil_sculpt_mode(wmKeyConfig *keyconf)
bool grease_pencil_sculpting_poll(bContext *C)
static void keymap_grease_pencil_selection(wmKeyConfig *keyconf)
static bool keymap_grease_pencil_brush_stroke_poll(bContext *C)
static void keymap_grease_pencil_brush_stroke(wmKeyConfig *keyconf)
bool grease_pencil_weight_painting_poll(bContext *C)
bool active_grease_pencil_material_poll(bContext *C)
bool grease_pencil_context_poll(bContext *C)
bool grease_pencil_edit_poll(bContext *C)
bool grease_pencil_painting_poll(bContext *C)
bool active_grease_pencil_layer_poll(bContext *C)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
struct BrushGpencilSettings * gpencil_settings
char gpencil_brush_type
GpWeightPaint * gp_weightpaint
GpSculptPaint * gp_sculptpaint
GpVertexPaint * gp_vertexpaint
bool(* poll)(struct bContext *)
wmOperatorType * ot
Definition wm_files.cc:4125
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:897
wmOperatorTypeMacro * WM_operatortype_macro_define(wmOperatorType *ot, const char *idname)
wmOperatorType * WM_operatortype_append_macro(const char *idname, const char *name, const char *description, int flag)
bool WM_toolsystem_active_tool_is_brush(const bContext *C)
bToolRef * WM_toolsystem_ref_from_context(const bContext *C)