Blender V5.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
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
29namespace blender {
30
31namespace ed::greasepencil {
32
41
43{
45 if (object == nullptr || object->type != OB_GREASE_PENCIL) {
46 return false;
47 }
48 return true;
49}
50
52{
54 if (object == nullptr || object->type != OB_GREASE_PENCIL) {
55 return false;
56 }
57 short *totcolp = BKE_object_material_len_p(object);
58 return *totcolp > 0;
59}
60
62{
64 if (object == nullptr || object->type != OB_GREASE_PENCIL) {
65 return false;
66 }
68 return false;
69 }
70
71 const GreasePencil *grease_pencil = id_cast<GreasePencil *>(object->data);
73 return false;
74 }
75
76 return true;
77}
78
83
85{
87 return false;
88 }
90 return grease_pencil && grease_pencil->has_active_layer();
91}
92
94{
96 return false;
97 }
99 return grease_pencil && grease_pencil->has_active_group();
100}
101
103{
105 return false;
106 }
107
108 /* Allowed: point and segment selection mode, not allowed: stroke selection mode. */
111}
112
114{
116 return false;
117 }
119 /* Selection operators are available in multiple modes, e.g. for masking in sculpt and vertex
120 * paint mode. */
121 if (!ELEM(
123 {
124 return false;
125 }
126 return true;
127}
128
130{
132 return false;
133 }
135 if ((object->mode & OB_MODE_PAINT_GREASE_PENCIL) == 0) {
136 return false;
137 }
139 if (!ts || !ts->gp_paint) {
140 return false;
141 }
142 return true;
143}
144
146{
148 return false;
149 }
151 if ((object->mode & OB_MODE_EDIT) == 0) {
152 return false;
153 }
154 return true;
155}
156
158{
160 return false;
161 }
163 if ((object->mode & OB_MODE_SCULPT_GREASE_PENCIL) == 0) {
164 return false;
165 }
167 if (!ts || !ts->gp_sculptpaint) {
168 return false;
169 }
170 return true;
171}
172
174{
176 return false;
177 }
179 if ((object->mode & OB_MODE_WEIGHT_GREASE_PENCIL) == 0) {
180 return false;
181 }
183 if (!ts || !ts->gp_weightpaint) {
184 return false;
185 }
186 return true;
187}
188
190{
192 return false;
193 }
195 if ((object->mode & OB_MODE_VERTEX_GREASE_PENCIL) == 0) {
196 return false;
197 }
199 if (!ts || !ts->gp_vertexpaint) {
200 return false;
201 }
202 return true;
203}
204
206{
207 if (!brush) {
208 return false;
209 }
210 if (brush->gpencil_settings && (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED)) {
211 Material *ma = (brush->gpencil_settings) ? brush->gpencil_settings->material : nullptr;
212 if (ma && BKE_object_material_index_get(ob, ma) < 0) {
213 /* The material needed for this brush doesn't exist on the object yet. */
214 return true;
215 }
216 }
217 return false;
218}
219
221{
222 wmKeyMap *keymap = WM_keymap_ensure(
223 keyconf, "Grease Pencil Selection", SPACE_EMPTY, RGN_TYPE_WINDOW);
225}
226
228{
229 wmKeyMap *keymap = WM_keymap_ensure(
230 keyconf, "Grease Pencil Edit Mode", SPACE_EMPTY, RGN_TYPE_WINDOW);
232}
233
235{
236 wmKeyMap *keymap = WM_keymap_ensure(
237 keyconf, "Grease Pencil Draw Mode", SPACE_EMPTY, RGN_TYPE_WINDOW);
239}
240
242{
243 wmKeyMap *keymap = WM_keymap_ensure(
244 keyconf, "Grease Pencil Sculpt Mode", SPACE_EMPTY, RGN_TYPE_WINDOW);
246}
247
249{
250 wmKeyMap *keymap = WM_keymap_ensure(
251 keyconf, "Grease Pencil Weight Paint", SPACE_EMPTY, RGN_TYPE_WINDOW);
253}
254
256{
257 wmKeyMap *keymap = WM_keymap_ensure(
258 keyconf, "Grease Pencil Vertex Paint", SPACE_EMPTY, RGN_TYPE_WINDOW);
260}
261
262/* Enabled for all tools except the fill tool and primitive tools. */
264{
266 return false;
267 }
269 return false;
270 }
271
272 /* Don't use the normal brush stroke keymap while the primitive tools are active. Otherwise
273 * simple mouse presses start freehand drawing instead of invoking the primitive operators. Could
274 * be a flag on the tool itself, for now making it a hardcoded exception. */
275 if (const bToolRef *tref = WM_toolsystem_ref_from_context(C)) {
276 const Set<StringRef> primitive_tools = {
277 "builtin.line",
278 "builtin.polyline",
279 "builtin.arc",
280 "builtin.curve",
281 "builtin.box",
282 "builtin.circle",
283 };
284 if (primitive_tools.contains(tref->idname)) {
285 return false;
286 }
287 }
288
291 return brush && brush->gpencil_settings && brush->gpencil_brush_type != GPAINT_BRUSH_TYPE_FILL;
292}
293
295{
296 wmKeyMap *keymap = WM_keymap_ensure(
297 keyconf, "Grease Pencil Brush Stroke", SPACE_EMPTY, RGN_TYPE_WINDOW);
299}
300
301/* Enabled only for the fill tool. */
303{
305 return false;
306 }
308 return false;
309 }
312 return brush && brush->gpencil_settings && brush->gpencil_brush_type == GPAINT_BRUSH_TYPE_FILL;
313}
314
316{
317 wmKeyMap *keymap = WM_keymap_ensure(
318 keyconf, "Grease Pencil Fill Tool", SPACE_EMPTY, RGN_TYPE_WINDOW);
320}
321
322} // namespace ed::greasepencil
323
343
345{
346 wmOperatorType *ot;
347 wmOperatorTypeMacro *otmacro;
348
349 /* Duplicate + Move = Interactively place newly duplicated strokes */
351 "GREASE_PENCIL_OT_duplicate_move",
352 "Duplicate Strokes",
353 "Make copies of the selected Grease Pencil strokes and move them",
355 WM_operatortype_macro_define(ot, "GREASE_PENCIL_OT_duplicate");
356 otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
357 RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false);
358 RNA_boolean_set(otmacro->ptr, "mirror", false);
359
360 /* Subdivide and Smooth. */
361 ot = WM_operatortype_append_macro("GREASE_PENCIL_OT_stroke_subdivide_smooth",
362 "Subdivide and Smooth",
363 "Subdivide strokes and smooth them",
365 WM_operatortype_macro_define(ot, "GREASE_PENCIL_OT_stroke_subdivide");
366 WM_operatortype_macro_define(ot, "GREASE_PENCIL_OT_stroke_smooth");
367
368 /* Extrude + Move = Interactively add new points */
369 ot = WM_operatortype_append_macro("GREASE_PENCIL_OT_extrude_move",
370 "Extrude Stroke Points",
371 "Extrude selected points and move them",
373 WM_operatortype_macro_define(ot, "GREASE_PENCIL_OT_extrude");
374 otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
375 RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false);
376 RNA_boolean_set(otmacro->ptr, "mirror", false);
377}
378
396
397} // namespace blender
General operations, lookup, etc. for materials.
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define C
Definition RandGen.cpp:29
#define ELEM(...)
bool contains(const Key &key) const
Definition BLI_set.hh:310
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 check_brush_needs_new_material(Object *ob, const Brush *brush)
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)
BMesh Iterators.
void ED_operatormacros_grease_pencil()
short * BKE_object_material_len_p(Object *ob)
void ED_keymap_grease_pencil(wmKeyConfig *keyconf)
void ED_grease_pencil_pentool_modal_keymap(wmKeyConfig *keyconf)
wmOperatorTypeMacro * WM_operatortype_macro_define(wmOperatorType *ot, const char *idname)
void ED_operatortypes_grease_pencil_bake_animation()
void ED_operatortypes_grease_pencil_select()
void ED_operatortypes_grease_pencil_frames()
void ED_operatortypes_grease_pencil_edit()
void ED_operatortypes_grease_pencil_interpolate()
void ED_interpolatetool_modal_keymap(wmKeyConfig *keyconf)
void ED_operatortypes_grease_pencil_draw()
Definition draw_ops.cc:2432
@ GPAINT_BRUSH_TYPE_FILL
void ED_primitivetool_modal_keymap(wmKeyConfig *keyconf)
@ OB_MODE_VERTEX_GREASE_PENCIL
@ OB_MODE_SCULPT_GREASE_PENCIL
@ OB_MODE_WEIGHT_GREASE_PENCIL
@ OB_MODE_PAINT_GREASE_PENCIL
void ED_operatortypes_grease_pencil_layers()
void ED_operatortypes_grease_pencil_weight_paint()
void ED_operatortypes_grease_pencil_modes()
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:935
ToolSettings * CTX_data_tool_settings(const bContext *C)
int BKE_object_material_index_get(Object *ob, const Material *ma)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
void ED_operatortypes_grease_pencil_pen()
void ED_operatortypes_grease_pencil()
wmOperatorType * WM_operatortype_append_macro(const char *idname, const char *name, const char *description, int flag)
void ED_operatortypes_grease_pencil_join()
bToolRef * WM_toolsystem_ref_from_context(const bContext *C)
bool WM_toolsystem_active_tool_is_brush(const bContext *C)
void ED_operatortypes_grease_pencil_material()
void ED_operatortypes_grease_pencil_lineart()
bool ED_operator_region_view3d_active(bContext *C)
void ED_operatortypes_grease_pencil_vertex_paint()
void ED_operatortypes_grease_pencil_primitives()
Brush * BKE_paint_brush(Paint *paint)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ GP_BRUSH_MATERIAL_PINNED
void ED_filltool_modal_keymap(wmKeyConfig *keyconf)
Definition draw_ops.cc:2444
Object * CTX_data_active_object(const bContext *C)
bool ED_operator_object_active_editable_ex(bContext *C, const Object *ob)
void ED_operatortypes_grease_pencil_trace()
Definition trace.cc:551
GpSculptPaint * gp_sculptpaint
eGPencil_Selectmode_types gpencil_selectmode_edit
GpVertexPaint * gp_vertexpaint
GpWeightPaint * gp_weightpaint
bool(*) poll(struct bContext *)