Blender V5.3
grease_pencil_modes.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "DNA_brush_types.h"
10
11#include "BKE_brush.hh"
12#include "BKE_context.hh"
13#include "BKE_global.hh"
14#include "BKE_library.hh"
15#include "BKE_paint.hh"
16#include "BKE_paint_types.hh"
17
18#include "RNA_access.hh"
19#include "RNA_define.hh"
20
21#include "ED_grease_pencil.hh"
22#include "ED_object.hh"
23#include "ED_paint.hh"
24
25#include "DEG_depsgraph.hh"
26
27#include "WM_api.hh"
28#include "WM_message.hh"
29#include "WM_toolsystem.hh"
30
31namespace blender {
32
33namespace ed::greasepencil {
34
35/* -------------------------------------------------------------------- */
38
40{
42 return true;
43 }
44 return false;
45}
46
48{
50 if (ob == nullptr || ob->type != OB_GREASE_PENCIL) {
51 return false;
52 }
53 if (!ob->data || !ID_IS_EDITABLE(ob->data)) {
54 return false;
55 }
56 return true;
57}
58
60{
61 const bool back = RNA_boolean_get(op->ptr, "back");
62
64 Main *bmain = CTX_data_main(C);
66
67 eObjectMode mode;
69 BLI_assert(ob != nullptr);
70
71 const bool is_mode_set = (ob->mode & OB_MODE_PAINT_GREASE_PENCIL) != 0;
72 if (!is_mode_set) {
73 Scene *scene = CTX_data_scene(C);
78 }
79 else {
80 mode = OB_MODE_OBJECT;
81 }
82
83 if ((ob->restore_mode) && ((ob->mode & OB_MODE_PAINT_GREASE_PENCIL) == 0) && (back == 1)) {
84 mode = ob->restore_mode;
85 }
86 ob->restore_mode = ob->mode;
87 ob->mode = mode;
88
89 if (mode == OB_MODE_PAINT_GREASE_PENCIL) {
90 /* Be sure we have brushes and Paint settings.
91 * Need Draw and Vertex (used for Tint). */
92 BKE_paint_ensure(ts, reinterpret_cast<Paint **>(&ts->gp_paint));
94 BKE_paint_ensure(ts, reinterpret_cast<Paint **>(&ts->gp_vertexpaint));
96
97 /* Ensure Palette by default. */
99
100 Paint *paint = &ts->gp_paint->paint;
102 if (brush && !brush->gpencil_settings) {
104 }
106
108 }
109
110 GreasePencil *grease_pencil = id_cast<GreasePencil *>(ob->data);
112
115
116 WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
117
119
120 return OPERATOR_FINISHED;
121}
122
124{
125 PropertyRNA *prop;
126
127 ot->name = "Strokes Paint Mode Toggle";
128 ot->idname = "GREASE_PENCIL_OT_paintmode_toggle";
129 ot->description = "Enter/Exit paint mode for Grease Pencil strokes";
130
133
135
136 prop = RNA_def_boolean(
137 ot->srna, "back", false, "Return to Previous Mode", "Return to previous mode");
139}
140
142
143/* -------------------------------------------------------------------- */
146
148{
150 if (ob == nullptr || ob->type != OB_GREASE_PENCIL) {
151 return false;
152 }
153 if (!ob->data || !ID_IS_EDITABLE(ob->data)) {
154 return false;
155 }
156 return true;
157}
158
160{
161 const Object *ob = CTX_data_active_object(C);
162 if (ob == nullptr || (ob->mode & OB_MODE_SCULPT_GREASE_PENCIL) == 0) {
163 return false;
164 }
165 if (CTX_wm_region_view3d(C) == nullptr) {
166 return false;
167 }
168 return true;
169}
170
172{
173 Main *bmain = CTX_data_main(C);
175
176 const bool back = RNA_boolean_get(op->ptr, "back");
177
179 eObjectMode mode;
181 BLI_assert(ob != nullptr);
182 const bool is_mode_set = (ob->mode & OB_MODE_SCULPT_GREASE_PENCIL) != 0;
183 if (is_mode_set) {
184 mode = OB_MODE_OBJECT;
185 }
186 else {
187 Scene *scene = CTX_data_scene(C);
192 }
193
194 if ((ob->restore_mode) && ((ob->mode & OB_MODE_SCULPT_GREASE_PENCIL) == 0) && (back == 1)) {
195 mode = ob->restore_mode;
196 }
197 ob->restore_mode = ob->mode;
198 ob->mode = mode;
199
200 if (mode == OB_MODE_SCULPT_GREASE_PENCIL) {
201 BKE_paint_ensure(ts, reinterpret_cast<Paint **>(&ts->gp_sculptpaint));
204
206 }
207
208 GreasePencil *grease_pencil = id_cast<GreasePencil *>(ob->data);
210
213
214 WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
215
217
218 return OPERATOR_FINISHED;
219}
220
222
223/* -------------------------------------------------------------------- */
226
228{
229 PropertyRNA *prop;
230
231 ot->name = "Strokes Sculpt Mode Toggle";
232 ot->idname = "GREASE_PENCIL_OT_sculptmode_toggle";
233 ot->description = "Enter/Exit sculpt mode for Grease Pencil strokes";
234
237
239
240 prop = RNA_def_boolean(
241 ot->srna, "back", false, "Return to Previous Mode", "Return to previous mode");
243}
244
251
253{
255 if (ob == nullptr || ob->type != OB_GREASE_PENCIL) {
256 return false;
257 }
258 if (!ob->data || !ID_IS_EDITABLE(ob->data)) {
259 return false;
260 }
261 return true;
262}
263
265{
266 Main *bmain = CTX_data_main(C);
267 Scene *scene = CTX_data_scene(C);
269
270 const bool back = RNA_boolean_get(op->ptr, "back");
271
273 eObjectMode mode;
275 BLI_assert(ob != nullptr);
276 const bool is_mode_set = (ob->mode & OB_MODE_WEIGHT_GREASE_PENCIL) != 0;
277 if (!is_mode_set) {
279 }
280 else {
281 mode = OB_MODE_OBJECT;
282 }
283
284 if ((ob->restore_mode) && ((ob->mode & OB_MODE_WEIGHT_GREASE_PENCIL) == 0) && (back == 1)) {
285 mode = ob->restore_mode;
286 }
287 ob->restore_mode = ob->mode;
288 ob->mode = mode;
289
290 /* Prepare armature posemode. */
291 ed::object::posemode_set_for_weight_paint(C, bmain, ob, is_mode_set);
292
293 if (mode == OB_MODE_WEIGHT_GREASE_PENCIL) {
294 /* Be sure we have brushes. */
295 BKE_paint_ensure(ts, reinterpret_cast<Paint **>(&ts->gp_weightpaint));
297
299
301 BKE_paint_brushes_validate(bmain, weight_paint);
302
304 }
305
306 GreasePencil *grease_pencil = id_cast<GreasePencil *>(ob->data);
308
311
312 WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
313
315
316 return OPERATOR_FINISHED;
317}
318
320{
321 PropertyRNA *prop;
322
323 ot->name = "Strokes Weight Mode Toggle";
324 ot->idname = "GREASE_PENCIL_OT_weightmode_toggle";
325 ot->description = "Enter/Exit weight paint mode for Grease Pencil strokes";
326
329
331
332 prop = RNA_def_boolean(
333 ot->srna, "back", false, "Return to Previous Mode", "Return to previous mode");
335}
336
338
339/* -------------------------------------------------------------------- */
342
349
351{
353 if (ob == nullptr || ob->type != OB_GREASE_PENCIL) {
354 return false;
355 }
356 if (!ob->data || !ID_IS_EDITABLE(ob->data)) {
357 return false;
358 }
359 return true;
360}
361
363{
364 const bool back = RNA_boolean_get(op->ptr, "back");
365
367 Main *bmain = CTX_data_main(C);
368 Scene *scene = CTX_data_scene(C);
370
371 eObjectMode mode;
373 BLI_assert(ob != nullptr);
374 const bool is_mode_set = (ob->mode & OB_MODE_VERTEX_GREASE_PENCIL) != 0;
375 if (!is_mode_set) {
377 }
378 else {
379 mode = OB_MODE_OBJECT;
380 }
381
382 if ((ob->restore_mode) && ((ob->mode & OB_MODE_VERTEX_GREASE_PENCIL) == 0) && (back == 1)) {
383 mode = ob->restore_mode;
384 }
385 ob->restore_mode = ob->mode;
386 ob->mode = mode;
387
388 if (mode == OB_MODE_VERTEX_GREASE_PENCIL) {
389 /* Be sure we have brushes.
390 * Need Draw as well (used for Palettes). */
391 BKE_paint_ensure(ts, reinterpret_cast<Paint **>(&ts->gp_paint));
392 BKE_paint_ensure(ts, reinterpret_cast<Paint **>(&ts->gp_vertexpaint));
395
396 BKE_paint_brushes_ensure(bmain, gp_paint);
397 BKE_paint_brushes_ensure(bmain, vertex_paint);
398 BKE_paint_brushes_validate(bmain, vertex_paint);
399
401
402 /* Ensure Palette by default. */
404
406 }
407
408 GreasePencil *grease_pencil = id_cast<GreasePencil *>(ob->data);
410
413
414 WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
415
417
418 return OPERATOR_FINISHED;
419}
420
422{
423 PropertyRNA *prop;
424
425 ot->name = "Strokes Vertex Mode Toggle";
426 ot->idname = "GREASE_PENCIL_OT_vertexmode_toggle";
427 ot->description = "Enter/Exit vertex paint mode for Grease Pencil strokes";
428
431
433
434 prop = RNA_def_boolean(
435 ot->srna, "back", false, "Return to Previous Mode", "Return to previous mode");
437}
438
440
441} // namespace ed::greasepencil
442
451
452} // namespace blender
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
#define C
Definition RandGen.cpp:29
#define ND_DATA
Definition WM_types.hh:552
#define ND_GPENCIL_EDITMODE
Definition WM_types.hh:547
#define ND_MODE
Definition WM_types.hh:464
#define NC_SCENE
Definition WM_types.hh:391
#define NC_GPENCIL
Definition WM_types.hh:412
static void GREASE_PENCIL_OT_sculptmode_toggle(wmOperatorType *ot)
static void GREASE_PENCIL_OT_weightmode_toggle(wmOperatorType *ot)
bool ensure_selection_domain(ToolSettings *ts, Object *object)
static bool sculptmode_toggle_poll(bContext *C)
static bool grease_pencil_poll_vertex_cursor(bContext *C)
static wmOperatorStatus vertexmode_toggle_exec(bContext *C, wmOperator *op)
static wmOperatorStatus weightmode_toggle_exec(bContext *C, wmOperator *op)
static bool paintmode_toggle_poll(bContext *C)
static wmOperatorStatus paintmode_toggle_exec(bContext *C, wmOperator *op)
static bool brush_cursor_poll(bContext *C)
static bool weightmode_toggle_poll(bContext *C)
static wmOperatorStatus sculptmode_toggle_exec(bContext *C, wmOperator *op)
static bool sculpt_poll_view3d(bContext *C)
static void GREASE_PENCIL_OT_paintmode_toggle(wmOperatorType *ot)
static bool vertexmode_toggle_poll(bContext *C)
static void GREASE_PENCIL_OT_vertexmode_toggle(wmOperatorType *ot)
static bool grease_pencil_poll_weight_cursor(bContext *C)
void posemode_set_for_weight_paint(bContext *C, Main *bmain, Object *ob, bool is_mode_set)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
void BKE_brush_init_gpencil_settings(Brush *brush)
Definition brush.cc:719
void ED_paint_cursor_start(Paint *paint, bool(*poll)(bContext *C))
void DEG_id_tag_update(ID *id, unsigned int flags)
@ OB_MODE_VERTEX_GREASE_PENCIL
@ OB_MODE_SCULPT_GREASE_PENCIL
@ OB_MODE_WEIGHT_GREASE_PENCIL
@ OB_MODE_PAINT_GREASE_PENCIL
void BKE_paint_brushes_ensure(Main *bmain, Paint *paint)
void BKE_paint_init(Main *bmain, Scene *sce, PaintMode mode, bool ensure_brushes=true)
void ED_operatortypes_grease_pencil_modes()
void WM_toolsystem_update_from_context_view3d(bContext *C)
RegionView3D * CTX_wm_region_view3d(const bContext *C)
ToolSettings * CTX_data_tool_settings(const bContext *C)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmMsgBus * CTX_wm_message_bus(const bContext *C)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
bool WM_toolsystem_active_tool_has_custom_cursor(const bContext *C)
Main * CTX_data_main(const bContext *C)
bool WM_toolsystem_active_tool_is_brush(const bContext *C)
Paint * BKE_paint_get_active_from_paintmode(Scene *sce, PaintMode mode)
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
Brush * BKE_paint_brush(Paint *paint)
Scene * CTX_data_scene(const bContext *C)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
bool BKE_paint_ensure(ToolSettings *ts, Paint **r_paint)
void BKE_paint_brushes_validate(Main *bmain, Paint *paint)
Object * CTX_data_active_object(const bContext *C)
void BKE_grease_pencil_palette_ensure(Main *bmain, Scene *scene)
eObjectMode restore_mode
GpSculptPaint * gp_sculptpaint
GpVertexPaint * gp_vertexpaint
GpWeightPaint * gp_weightpaint
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
#define WM_msg_publish_rna_prop(mbus, id_, data_, type_, prop_)