Blender V4.5
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_grease_pencil.hh"
20#include "ED_screen.hh"
21
22#include "WM_api.hh"
23#include "WM_toolsystem.hh"
24#include "WM_types.hh"
25
26#include "RNA_access.hh"
27
29
31{
33 if (!grease_pencil || ID_IS_LINKED(grease_pencil)) {
34 return false;
35 }
36 return true;
37}
38
40{
42 if (object == nullptr || object->type != OB_GREASE_PENCIL) {
43 return false;
44 }
45 return true;
46}
47
49{
51 if (object == nullptr || object->type != OB_GREASE_PENCIL) {
52 return false;
53 }
54 short *totcolp = BKE_object_material_len_p(object);
55 return *totcolp > 0;
56}
57
59{
61 if (object == nullptr || object->type != OB_GREASE_PENCIL) {
62 return false;
63 }
65 return false;
66 }
67
68 const GreasePencil *grease_pencil = static_cast<GreasePencil *>(object->data);
69 if (ID_IS_LINKED(grease_pencil)) {
70 return false;
71 }
72
73 return true;
74}
75
80
82{
84 return false;
85 }
87 return grease_pencil && grease_pencil->has_active_layer();
88}
89
91{
93 return false;
94 }
96 return grease_pencil && grease_pencil->has_active_group();
97}
98
100{
102 return false;
103 }
104
105 /* Allowed: point and segment selection mode, not allowed: stroke selection mode. */
108}
109
111{
113 return false;
114 }
116 /* Selection operators are available in multiple modes, e.g. for masking in sculpt and vertex
117 * paint mode. */
118 if (!ELEM(
120 {
121 return false;
122 }
123 return true;
124}
125
127{
129 return false;
130 }
132 if ((object->mode & OB_MODE_PAINT_GREASE_PENCIL) == 0) {
133 return false;
134 }
136 if (!ts || !ts->gp_paint) {
137 return false;
138 }
139 return true;
140}
141
143{
145 return false;
146 }
148 if ((object->mode & OB_MODE_EDIT) == 0) {
149 return false;
150 }
151 return true;
152}
153
155{
157 return false;
158 }
160 if ((object->mode & OB_MODE_SCULPT_GREASE_PENCIL) == 0) {
161 return false;
162 }
164 if (!ts || !ts->gp_sculptpaint) {
165 return false;
166 }
167 return true;
168}
169
171{
173 return false;
174 }
176 if ((object->mode & OB_MODE_WEIGHT_GREASE_PENCIL) == 0) {
177 return false;
178 }
180 if (!ts || !ts->gp_weightpaint) {
181 return false;
182 }
183 return true;
184}
185
187{
189 return false;
190 }
192 if ((object->mode & OB_MODE_VERTEX_GREASE_PENCIL) == 0) {
193 return false;
194 }
196 if (!ts || !ts->gp_vertexpaint) {
197 return false;
198 }
199 return true;
200}
201
203{
204 wmKeyMap *keymap = WM_keymap_ensure(
205 keyconf, "Grease Pencil Selection", SPACE_EMPTY, RGN_TYPE_WINDOW);
207}
208
210{
211 wmKeyMap *keymap = WM_keymap_ensure(
212 keyconf, "Grease Pencil Edit Mode", SPACE_EMPTY, RGN_TYPE_WINDOW);
214}
215
217{
218 wmKeyMap *keymap = WM_keymap_ensure(
219 keyconf, "Grease Pencil Paint Mode", SPACE_EMPTY, RGN_TYPE_WINDOW);
221}
222
224{
225 wmKeyMap *keymap = WM_keymap_ensure(
226 keyconf, "Grease Pencil Sculpt Mode", SPACE_EMPTY, RGN_TYPE_WINDOW);
228}
229
231{
232 wmKeyMap *keymap = WM_keymap_ensure(
233 keyconf, "Grease Pencil Weight Paint", SPACE_EMPTY, RGN_TYPE_WINDOW);
235}
236
238{
239 wmKeyMap *keymap = WM_keymap_ensure(
240 keyconf, "Grease Pencil Vertex Paint", SPACE_EMPTY, RGN_TYPE_WINDOW);
242}
243
244/* Enabled for all tools except the fill tool and primitive tools. */
246{
248 return false;
249 }
251 return false;
252 }
253
254 /* Don't use the normal brush stroke keymap while the primitive tools are active. Otherwise
255 * simple mouse presses start freehand drawing instead of invoking the primitive operators. Could
256 * be a flag on the tool itself, for now making it a hardcoded exception. */
257 if (const bToolRef *tref = WM_toolsystem_ref_from_context(C)) {
258 const Set<StringRef> primitive_tools = {
259 "builtin.line",
260 "builtin.polyline",
261 "builtin.arc",
262 "builtin.curve",
263 "builtin.box",
264 "builtin.circle",
265 };
266 if (primitive_tools.contains(tref->idname)) {
267 return false;
268 }
269 }
270
272 Brush *brush = BKE_paint_brush(&ts->gp_paint->paint);
273 return brush && brush->gpencil_settings && brush->gpencil_brush_type != GPAINT_BRUSH_TYPE_FILL;
274}
275
277{
278 wmKeyMap *keymap = WM_keymap_ensure(
279 keyconf, "Grease Pencil Brush Stroke", SPACE_EMPTY, RGN_TYPE_WINDOW);
281}
282
283/* Enabled only for the fill tool. */
285{
287 return false;
288 }
290 return false;
291 }
293 Brush *brush = BKE_paint_brush(&ts->gp_paint->paint);
294 return brush && brush->gpencil_settings && brush->gpencil_brush_type == GPAINT_BRUSH_TYPE_FILL;
295}
296
298{
299 wmKeyMap *keymap = WM_keymap_ensure(
300 keyconf, "Grease Pencil Fill Tool", SPACE_EMPTY, RGN_TYPE_WINDOW);
302}
303
304} // namespace blender::ed::greasepencil
305
324
326{
328 wmOperatorTypeMacro *otmacro;
329
330 /* Duplicate + Move = Interactively place newly duplicated strokes */
332 "GREASE_PENCIL_OT_duplicate_move",
333 "Duplicate Strokes",
334 "Make copies of the selected Grease Pencil strokes and move them",
336 WM_operatortype_macro_define(ot, "GREASE_PENCIL_OT_duplicate");
337 otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
338 RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false);
339 RNA_boolean_set(otmacro->ptr, "mirror", false);
340
341 /* Subdivide and Smooth. */
342 ot = WM_operatortype_append_macro("GREASE_PENCIL_OT_stroke_subdivide_smooth",
343 "Subdivide and Smooth",
344 "Subdivide strokes and smooth them",
346 WM_operatortype_macro_define(ot, "GREASE_PENCIL_OT_stroke_subdivide");
347 WM_operatortype_macro_define(ot, "GREASE_PENCIL_OT_stroke_smooth");
348
349 /* Extrude + Move = Interactively add new points */
350 ot = WM_operatortype_append_macro("GREASE_PENCIL_OT_extrude_move",
351 "Extrude Stroke Points",
352 "Extrude selected points and move them",
354 WM_operatortype_macro_define(ot, "GREASE_PENCIL_OT_extrude");
355 otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
356 RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false);
357 RNA_boolean_set(otmacro->ptr, "mirror", false);
358}
359
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:636
#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_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
#define ID_IS_LINKED(_id)
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)
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:4226
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:893
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)