Blender V4.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
9#include "BKE_brush.hh"
10#include "BKE_context.hh"
11#include "BKE_global.hh"
12#include "BKE_gpencil_legacy.h"
13#include "BKE_paint.hh"
14
15#include "RNA_access.hh"
16#include "RNA_define.hh"
17
18#include "ED_grease_pencil.hh"
19#include "ED_image.hh"
20#include "ED_object.hh"
21
23
24#include "WM_api.hh"
25#include "WM_message.hh"
26#include "WM_toolsystem.hh"
27
29
30/* -------------------------------------------------------------------- */
35{
37 return true;
38 }
39 return false;
40}
41
43{
45 if ((ob) && ob->type == OB_GREASE_PENCIL) {
46 return ob->data != nullptr;
47 }
48 return false;
49}
50
52{
53 const bool back = RNA_boolean_get(op->ptr, "back");
54
56 Main *bmain = CTX_data_main(C);
58
59 short mode;
61 BLI_assert(ob != nullptr);
62
63 const bool is_mode_set = (ob->mode & OB_MODE_PAINT_GREASE_PENCIL) != 0;
64 if (!is_mode_set) {
65 Scene *scene = CTX_data_scene(C);
70 }
71 else {
72 mode = OB_MODE_OBJECT;
73 }
74
75 if ((ob->restore_mode) && ((ob->mode & OB_MODE_PAINT_GREASE_PENCIL) == 0) && (back == 1)) {
76 mode = ob->restore_mode;
77 }
78 ob->restore_mode = ob->mode;
79 ob->mode = mode;
80
81 if (mode == OB_MODE_PAINT_GREASE_PENCIL) {
82 /* Be sure we have brushes and Paint settings.
83 * Need Draw and Vertex (used for Tint). */
84 BKE_paint_ensure(ts, (Paint **)&ts->gp_paint);
88
89 /* Ensure Palette by default. */
91
92 Paint *paint = &ts->gp_paint->paint;
93 Brush *brush = BKE_paint_brush(paint);
94 if (brush && !brush->gpencil_settings) {
96 }
98 }
99
100 GreasePencil *grease_pencil = static_cast<GreasePencil *>(ob->data);
102
105
106 WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
107
108 if (G.background == false) {
110 }
111
112 return OPERATOR_FINISHED;
113}
114
116{
117 PropertyRNA *prop;
118
119 ot->name = "Strokes Paint Mode Toggle";
120 ot->idname = "GREASE_PENCIL_OT_paintmode_toggle";
121 ot->description = "Enter/Exit paint mode for Grease Pencil strokes";
122
125
127
128 prop = RNA_def_boolean(
129 ot->srna, "back", false, "Return to Previous Mode", "Return to previous mode");
131}
132
135/* -------------------------------------------------------------------- */
140{
142 if (ob == nullptr) {
143 return false;
144 }
145 if (ob->type == OB_GREASE_PENCIL) {
146 return ob->data != nullptr;
147 }
148 return false;
149}
150
152{
153 const Object *ob = CTX_data_active_object(C);
154 if (ob == nullptr || (ob->mode & OB_MODE_SCULPT_GREASE_PENCIL) == 0) {
155 return false;
156 }
157 if (CTX_wm_region_view3d(C) == nullptr) {
158 return false;
159 }
160 return true;
161}
162
164{
165 Main *bmain = CTX_data_main(C);
167
168 const bool back = RNA_boolean_get(op->ptr, "back");
169
170 wmMsgBus *mbus = CTX_wm_message_bus(C);
171 short mode;
173 BLI_assert(ob != nullptr);
174 const bool is_mode_set = (ob->mode & OB_MODE_SCULPT_GREASE_PENCIL) != 0;
175 if (is_mode_set) {
176 mode = OB_MODE_OBJECT;
177 }
178 else {
179 Scene *scene = CTX_data_scene(C);
184 }
185
186 if ((ob->restore_mode) && ((ob->mode & OB_MODE_SCULPT_GREASE_PENCIL) == 0) && (back == 1)) {
187 mode = ob->restore_mode;
188 }
189 ob->restore_mode = ob->mode;
190 ob->mode = mode;
191
192 if (mode == OB_MODE_SCULPT_GREASE_PENCIL) {
196 }
197
198 GreasePencil *grease_pencil = static_cast<GreasePencil *>(ob->data);
200
203
204 WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
205
206 if (G.background == false) {
208 }
209
210 return OPERATOR_FINISHED;
211}
212
215/* -------------------------------------------------------------------- */
220{
221 PropertyRNA *prop;
222
223 ot->name = "Strokes Sculpt Mode Toggle";
224 ot->idname = "GREASE_PENCIL_OT_sculptmode_toggle";
225 ot->description = "Enter/Exit sculpt mode for Grease Pencil strokes";
226
229
231
232 prop = RNA_def_boolean(
233 ot->srna, "back", false, "Return to Previous Mode", "Return to previous mode");
235}
236
243
245{
247 if ((ob) && ob->type == OB_GREASE_PENCIL) {
248 return ob->data != nullptr;
249 }
250 return false;
251}
252
254{
255 Main *bmain = CTX_data_main(C);
256 Scene *scene = CTX_data_scene(C);
258
259 const bool back = RNA_boolean_get(op->ptr, "back");
260
261 wmMsgBus *mbus = CTX_wm_message_bus(C);
262 short mode;
264 BLI_assert(ob != nullptr);
265 const bool is_mode_set = (ob->mode & OB_MODE_WEIGHT_GREASE_PENCIL) != 0;
266 if (!is_mode_set) {
268 }
269 else {
270 mode = OB_MODE_OBJECT;
271 }
272
273 if ((ob->restore_mode) && ((ob->mode & OB_MODE_WEIGHT_GREASE_PENCIL) == 0) && (back == 1)) {
274 mode = ob->restore_mode;
275 }
276 ob->restore_mode = ob->mode;
277 ob->mode = mode;
278
279 /* Prepare armature posemode. */
281
282 if (mode == OB_MODE_WEIGHT_GREASE_PENCIL) {
283 /* Be sure we have brushes. */
286
288
290 BKE_paint_brushes_validate(bmain, weight_paint);
291 }
292
293 GreasePencil *grease_pencil = static_cast<GreasePencil *>(ob->data);
295
298
299 WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
300
301 if (G.background == false) {
303 }
304
305 return OPERATOR_FINISHED;
306}
307
309{
310 PropertyRNA *prop;
311
312 ot->name = "Strokes Weight Mode Toggle";
313 ot->idname = "GREASE_PENCIL_OT_weightmode_toggle";
314 ot->description = "Enter/Exit weight paint mode for Grease Pencil strokes";
315
318
320
321 prop = RNA_def_boolean(
322 ot->srna, "back", false, "Return to Previous Mode", "Return to previous mode");
324}
325
328/* -------------------------------------------------------------------- */
338
340{
342 if ((ob) && ob->type == OB_GREASE_PENCIL) {
343 return ob->data != nullptr;
344 }
345 return false;
346}
347
349{
350 const bool back = RNA_boolean_get(op->ptr, "back");
351
352 wmMsgBus *mbus = CTX_wm_message_bus(C);
353 Main *bmain = CTX_data_main(C);
354 Scene *scene = CTX_data_scene(C);
356
357 short mode;
359 BLI_assert(ob != nullptr);
360 const bool is_mode_set = (ob->mode & OB_MODE_VERTEX_GREASE_PENCIL) != 0;
361 if (!is_mode_set) {
363 }
364 else {
365 mode = OB_MODE_OBJECT;
366 }
367
368 if ((ob->restore_mode) && ((ob->mode & OB_MODE_VERTEX_GREASE_PENCIL) == 0) && (back == 1)) {
369 mode = ob->restore_mode;
370 }
371 ob->restore_mode = ob->mode;
372 ob->mode = mode;
373
374 if (mode == OB_MODE_VERTEX_GREASE_PENCIL) {
375 /* Be sure we have brushes.
376 * Need Draw as well (used for Palettes). */
377 BKE_paint_ensure(ts, (Paint **)&ts->gp_paint);
381
382 BKE_paint_brushes_ensure(bmain, gp_paint);
383 BKE_paint_brushes_ensure(bmain, vertex_paint);
384 BKE_paint_brushes_validate(bmain, vertex_paint);
385
387
388 /* Ensure Palette by default. */
389 BKE_gpencil_palette_ensure(bmain, scene);
390 }
391
392 GreasePencil *grease_pencil = static_cast<GreasePencil *>(ob->data);
394
397
398 WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
399
400 if (G.background == false) {
402 }
403
404 return OPERATOR_FINISHED;
405}
406
408{
409 PropertyRNA *prop;
410
411 ot->name = "Strokes Vertex Mode Toggle";
412 ot->idname = "GREASE_PENCIL_OT_vertexmode_toggle";
413 ot->description = "Enter/Exit vertex paint mode for Grease Pencil strokes";
414
417
419
420 prop = RNA_def_boolean(
421 ot->srna, "back", false, "Return to Previous Mode", "Return to previous mode");
423}
424
427} // namespace blender::ed::greasepencil
428
430{
431 using namespace blender::ed::greasepencil;
432 WM_operatortype_append(GREASE_PENCIL_OT_paintmode_toggle);
433 WM_operatortype_append(GREASE_PENCIL_OT_sculptmode_toggle);
434 WM_operatortype_append(GREASE_PENCIL_OT_weightmode_toggle);
435 WM_operatortype_append(GREASE_PENCIL_OT_vertexmode_toggle);
436}
void BKE_brush_init_gpencil_settings(Brush *brush)
Definition brush.cc:563
Object * CTX_data_active_object(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
Main * CTX_data_main(const bContext *C)
ToolSettings * CTX_data_tool_settings(const bContext *C)
RegionView3D * CTX_wm_region_view3d(const bContext *C)
wmMsgBus * CTX_wm_message_bus(const bContext *C)
void BKE_gpencil_palette_ensure(struct Main *bmain, struct Scene *scene)
const uchar PAINT_CURSOR_SCULPT_GREASE_PENCIL[3]
Definition paint.cc:249
@ SculptGreasePencil
void BKE_paint_brushes_ensure(Main *bmain, Paint *paint)
Definition paint.cc:1762
const uchar PAINT_CURSOR_PAINT_GREASE_PENCIL[3]
Definition paint.cc:248
Paint * BKE_paint_get_active_from_paintmode(Scene *sce, PaintMode mode)
Definition paint.cc:371
void BKE_paint_init(Main *bmain, Scene *sce, PaintMode mode, const uchar col[3], bool ensure_brushes=true)
Definition paint.cc:1779
bool BKE_paint_ensure(ToolSettings *ts, Paint **r_paint)
Definition paint.cc:1685
Brush * BKE_paint_brush(Paint *paint)
Definition paint.cc:649
void BKE_paint_brushes_validate(Main *bmain, Paint *paint)
Definition paint.cc:1108
#define BLI_assert(a)
Definition BLI_assert.h:50
void DEG_id_tag_update(ID *id, unsigned int flags)
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1021
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1041
@ OB_MODE_VERTEX_GREASE_PENCIL
@ OB_MODE_PAINT_GREASE_PENCIL
@ OB_MODE_SCULPT_GREASE_PENCIL
@ OB_MODE_OBJECT
@ OB_MODE_WEIGHT_GREASE_PENCIL
@ OB_GREASE_PENCIL
void ED_paint_cursor_start(Paint *paint, bool(*poll)(bContext *C))
@ PROP_SKIP_SAVE
Definition RNA_types.hh:245
@ PROP_HIDDEN
Definition RNA_types.hh:239
@ OPTYPE_UNDO
Definition WM_types.hh:162
@ OPTYPE_REGISTER
Definition WM_types.hh:160
#define ND_DATA
Definition WM_types.hh:475
#define ND_GPENCIL_EDITMODE
Definition WM_types.hh:470
#define ND_MODE
Definition WM_types.hh:412
#define NC_SCENE
Definition WM_types.hh:345
#define NC_GPENCIL
Definition WM_types.hh:366
void ED_operatortypes_grease_pencil_modes()
#define G(x, y, z)
static void GREASE_PENCIL_OT_sculptmode_toggle(wmOperatorType *ot)
static int weightmode_toggle_exec(bContext *C, wmOperator *op)
static void GREASE_PENCIL_OT_weightmode_toggle(wmOperatorType *ot)
static bool sculptmode_toggle_poll(bContext *C)
static bool grease_pencil_poll_vertex_cursor(bContext *C)
static bool paintmode_toggle_poll(bContext *C)
static bool brush_cursor_poll(bContext *C)
static int vertexmode_toggle_exec(bContext *C, wmOperator *op)
static bool weightmode_toggle_poll(bContext *C)
static bool sculpt_poll_view3d(bContext *C)
static int sculptmode_toggle_exec(bContext *C, wmOperator *op)
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 int paintmode_toggle_exec(bContext *C, wmOperator *op)
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)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
struct BrushGpencilSettings * gpencil_settings
GpWeightPaint * gp_weightpaint
GpSculptPaint * gp_sculptpaint
GpVertexPaint * gp_vertexpaint
const char * name
Definition WM_types.hh:990
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1042
const char * idname
Definition WM_types.hh:992
int(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1006
const char * description
Definition WM_types.hh:996
StructRNA * srna
Definition WM_types.hh:1080
struct PointerRNA * ptr
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition wm_files.cc:4125
#define WM_msg_publish_rna_prop(mbus, id_, data_, type_, prop_)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
bool WM_toolsystem_active_tool_is_brush(const bContext *C)
bool WM_toolsystem_active_tool_has_custom_cursor(const bContext *C)
void WM_toolsystem_update_from_context_view3d(bContext *C)