Blender V5.0
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
8
9#include "DNA_brush_types.h"
10
11#include "BKE_context.hh"
12#include "BKE_material.hh"
13#include "BKE_paint.hh"
14
15#include "DNA_brush_enums.h"
16#include "DNA_object_enums.h"
17#include "DNA_scene_types.h"
18
19#include "ED_curves.hh"
20#include "ED_grease_pencil.hh"
21#include "ED_screen.hh"
22
23#include "WM_api.hh"
24#include "WM_toolsystem.hh"
25#include "WM_types.hh"
26
27#include "RNA_access.hh"
28
30
32{
34 if (!grease_pencil || ID_IS_LINKED(grease_pencil)) {
35 return false;
36 }
37 return true;
38}
39
41{
43 if (object == nullptr || object->type != OB_GREASE_PENCIL) {
44 return false;
45 }
46 return true;
47}
48
50{
52 if (object == nullptr || object->type != OB_GREASE_PENCIL) {
53 return false;
54 }
55 short *totcolp = BKE_object_material_len_p(object);
56 return *totcolp > 0;
57}
58
60{
62 if (object == nullptr || object->type != OB_GREASE_PENCIL) {
63 return false;
64 }
66 return false;
67 }
68
69 const GreasePencil *grease_pencil = static_cast<GreasePencil *>(object->data);
70 if (ID_IS_LINKED(grease_pencil)) {
71 return false;
72 }
73
74 return true;
75}
76
81
83{
85 return false;
86 }
88 return grease_pencil && grease_pencil->has_active_layer();
89}
90
92{
94 return false;
95 }
97 return grease_pencil && grease_pencil->has_active_group();
98}
99
101{
103 return false;
104 }
105
106 /* Allowed: point and segment selection mode, not allowed: stroke selection mode. */
109}
110
112{
114 return false;
115 }
117 /* Selection operators are available in multiple modes, e.g. for masking in sculpt and vertex
118 * paint mode. */
119 if (!ELEM(
121 {
122 return false;
123 }
124 return true;
125}
126
128{
130 return false;
131 }
133 if ((object->mode & OB_MODE_PAINT_GREASE_PENCIL) == 0) {
134 return false;
135 }
137 if (!ts || !ts->gp_paint) {
138 return false;
139 }
140 return true;
141}
142
144{
146 return false;
147 }
149 if ((object->mode & OB_MODE_EDIT) == 0) {
150 return false;
151 }
152 return true;
153}
154
156{
158 return false;
159 }
161 if ((object->mode & OB_MODE_SCULPT_GREASE_PENCIL) == 0) {
162 return false;
163 }
165 if (!ts || !ts->gp_sculptpaint) {
166 return false;
167 }
168 return true;
169}
170
172{
174 return false;
175 }
177 if ((object->mode & OB_MODE_WEIGHT_GREASE_PENCIL) == 0) {
178 return false;
179 }
181 if (!ts || !ts->gp_weightpaint) {
182 return false;
183 }
184 return true;
185}
186
188{
190 return false;
191 }
193 if ((object->mode & OB_MODE_VERTEX_GREASE_PENCIL) == 0) {
194 return false;
195 }
197 if (!ts || !ts->gp_vertexpaint) {
198 return false;
199 }
200 return true;
201}
202
204{
205 wmKeyMap *keymap = WM_keymap_ensure(
206 keyconf, "Grease Pencil Selection", SPACE_EMPTY, RGN_TYPE_WINDOW);
208}
209
211{
212 wmKeyMap *keymap = WM_keymap_ensure(
213 keyconf, "Grease Pencil Edit Mode", SPACE_EMPTY, RGN_TYPE_WINDOW);
215}
216
218{
219 wmKeyMap *keymap = WM_keymap_ensure(
220 keyconf, "Grease Pencil Paint Mode", SPACE_EMPTY, RGN_TYPE_WINDOW);
222}
223
225{
226 wmKeyMap *keymap = WM_keymap_ensure(
227 keyconf, "Grease Pencil Sculpt Mode", SPACE_EMPTY, RGN_TYPE_WINDOW);
229}
230
232{
233 wmKeyMap *keymap = WM_keymap_ensure(
234 keyconf, "Grease Pencil Weight Paint", SPACE_EMPTY, RGN_TYPE_WINDOW);
236}
237
239{
240 wmKeyMap *keymap = WM_keymap_ensure(
241 keyconf, "Grease Pencil Vertex Paint", SPACE_EMPTY, RGN_TYPE_WINDOW);
243}
244
245/* Enabled for all tools except the fill tool and primitive tools. */
247{
249 return false;
250 }
252 return false;
253 }
254
255 /* Don't use the normal brush stroke keymap while the primitive tools are active. Otherwise
256 * simple mouse presses start freehand drawing instead of invoking the primitive operators. Could
257 * be a flag on the tool itself, for now making it a hardcoded exception. */
258 if (const bToolRef *tref = WM_toolsystem_ref_from_context(C)) {
259 const Set<StringRef> primitive_tools = {
260 "builtin.line",
261 "builtin.polyline",
262 "builtin.arc",
263 "builtin.curve",
264 "builtin.box",
265 "builtin.circle",
266 };
267 if (primitive_tools.contains(tref->idname)) {
268 return false;
269 }
270 }
271
273 Brush *brush = BKE_paint_brush(&ts->gp_paint->paint);
274 return brush && brush->gpencil_settings && brush->gpencil_brush_type != GPAINT_BRUSH_TYPE_FILL;
275}
276
278{
279 wmKeyMap *keymap = WM_keymap_ensure(
280 keyconf, "Grease Pencil Brush Stroke", SPACE_EMPTY, RGN_TYPE_WINDOW);
282}
283
284/* Enabled only for the fill tool. */
286{
288 return false;
289 }
291 return false;
292 }
294 Brush *brush = BKE_paint_brush(&ts->gp_paint->paint);
295 return brush && brush->gpencil_settings && brush->gpencil_brush_type == GPAINT_BRUSH_TYPE_FILL;
296}
297
299{
300 wmKeyMap *keymap = WM_keymap_ensure(
301 keyconf, "Grease Pencil Fill Tool", SPACE_EMPTY, RGN_TYPE_WINDOW);
303}
304
305} // namespace blender::ed::greasepencil
306
326
328{
330 wmOperatorTypeMacro *otmacro;
331
332 /* Duplicate + Move = Interactively place newly duplicated strokes */
334 "GREASE_PENCIL_OT_duplicate_move",
335 "Duplicate Strokes",
336 "Make copies of the selected Grease Pencil strokes and move them",
338 WM_operatortype_macro_define(ot, "GREASE_PENCIL_OT_duplicate");
339 otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
340 RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false);
341 RNA_boolean_set(otmacro->ptr, "mirror", false);
342
343 /* Subdivide and Smooth. */
344 ot = WM_operatortype_append_macro("GREASE_PENCIL_OT_stroke_subdivide_smooth",
345 "Subdivide and Smooth",
346 "Subdivide strokes and smooth them",
348 WM_operatortype_macro_define(ot, "GREASE_PENCIL_OT_stroke_subdivide");
349 WM_operatortype_macro_define(ot, "GREASE_PENCIL_OT_stroke_smooth");
350
351 /* Extrude + Move = Interactively add new points */
352 ot = WM_operatortype_append_macro("GREASE_PENCIL_OT_extrude_move",
353 "Extrude Stroke Points",
354 "Extrude selected points and move them",
356 WM_operatortype_macro_define(ot, "GREASE_PENCIL_OT_extrude");
357 otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
358 RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false);
359 RNA_boolean_set(otmacro->ptr, "mirror", false);
360}
361
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(Object *ob)
Brush * BKE_paint_brush(Paint *paint)
Definition paint.cc:645
#define ELEM(...)
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:694
@ 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_region_view3d_active(bContext *C)
bool ED_operator_object_active_editable_ex(bContext *C, const Object *ob)
#define C
Definition RandGen.cpp:29
@ OPTYPE_UNDO
Definition WM_types.hh:182
@ OPTYPE_REGISTER
Definition WM_types.hh:180
bool contains(const Key &key) const
Definition BLI_set.hh:310
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_operatortypes_grease_pencil_pen()
void ED_grease_pencil_pentool_modal_keymap(wmKeyConfig *keyconf)
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)
bool editable_grease_pencil_with_region_view3d_poll(bContext *C)
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 active_grease_pencil_layer_group_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:4237
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:895
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)