Blender V4.5
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_gpencil_legacy.h"
15#include "BKE_paint.hh"
16
17#include "RNA_access.hh"
18#include "RNA_define.hh"
19
20#include "ED_grease_pencil.hh"
21#include "ED_image.hh"
22#include "ED_object.hh"
23
24#include "DEG_depsgraph.hh"
25
26#include "WM_api.hh"
27#include "WM_message.hh"
28#include "WM_toolsystem.hh"
29
31
32/* -------------------------------------------------------------------- */
35
37{
39 return true;
40 }
41 return false;
42}
43
45{
47 if ((ob) && ob->type == OB_GREASE_PENCIL) {
48 return ob->data != nullptr;
49 }
50 return false;
51}
52
54{
55 const bool back = RNA_boolean_get(op->ptr, "back");
56
58 Main *bmain = CTX_data_main(C);
60
61 short mode;
63 BLI_assert(ob != nullptr);
64
65 const bool is_mode_set = (ob->mode & OB_MODE_PAINT_GREASE_PENCIL) != 0;
66 if (!is_mode_set) {
67 Scene *scene = CTX_data_scene(C);
72 }
73 else {
74 mode = OB_MODE_OBJECT;
75 }
76
77 if ((ob->restore_mode) && ((ob->mode & OB_MODE_PAINT_GREASE_PENCIL) == 0) && (back == 1)) {
78 mode = ob->restore_mode;
79 }
80 ob->restore_mode = ob->mode;
81 ob->mode = mode;
82
83 if (mode == OB_MODE_PAINT_GREASE_PENCIL) {
84 /* Be sure we have brushes and Paint settings.
85 * Need Draw and Vertex (used for Tint). */
86 BKE_paint_ensure(ts, (Paint **)&ts->gp_paint);
90
91 /* Ensure Palette by default. */
93
94 Paint *paint = &ts->gp_paint->paint;
95 Brush *brush = BKE_paint_brush(paint);
96 if (brush && !brush->gpencil_settings) {
98 }
100 }
101
102 GreasePencil *grease_pencil = static_cast<GreasePencil *>(ob->data);
104
107
108 WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
109
110 if (G.background == false) {
112 }
113
114 return OPERATOR_FINISHED;
115}
116
118{
119 PropertyRNA *prop;
120
121 ot->name = "Strokes Paint Mode Toggle";
122 ot->idname = "GREASE_PENCIL_OT_paintmode_toggle";
123 ot->description = "Enter/Exit paint mode for Grease Pencil strokes";
124
127
129
130 prop = RNA_def_boolean(
131 ot->srna, "back", false, "Return to Previous Mode", "Return to previous mode");
133}
134
136
137/* -------------------------------------------------------------------- */
140
142{
144 if (ob == nullptr) {
145 return false;
146 }
147 if (ob->type == OB_GREASE_PENCIL) {
148 return ob->data != nullptr;
149 }
150 return false;
151}
152
154{
155 const Object *ob = CTX_data_active_object(C);
156 if (ob == nullptr || (ob->mode & OB_MODE_SCULPT_GREASE_PENCIL) == 0) {
157 return false;
158 }
159 if (CTX_wm_region_view3d(C) == nullptr) {
160 return false;
161 }
162 return true;
163}
164
166{
167 Main *bmain = CTX_data_main(C);
169
170 const bool back = RNA_boolean_get(op->ptr, "back");
171
173 short mode;
175 BLI_assert(ob != nullptr);
176 const bool is_mode_set = (ob->mode & OB_MODE_SCULPT_GREASE_PENCIL) != 0;
177 if (is_mode_set) {
178 mode = OB_MODE_OBJECT;
179 }
180 else {
181 Scene *scene = CTX_data_scene(C);
186 }
187
188 if ((ob->restore_mode) && ((ob->mode & OB_MODE_SCULPT_GREASE_PENCIL) == 0) && (back == 1)) {
189 mode = ob->restore_mode;
190 }
191 ob->restore_mode = ob->mode;
192 ob->mode = mode;
193
194 if (mode == OB_MODE_SCULPT_GREASE_PENCIL) {
198 }
199
200 GreasePencil *grease_pencil = static_cast<GreasePencil *>(ob->data);
202
205
206 WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
207
208 if (G.background == false) {
210 }
211
212 return OPERATOR_FINISHED;
213}
214
216
217/* -------------------------------------------------------------------- */
220
222{
223 PropertyRNA *prop;
224
225 ot->name = "Strokes Sculpt Mode Toggle";
226 ot->idname = "GREASE_PENCIL_OT_sculptmode_toggle";
227 ot->description = "Enter/Exit sculpt mode for Grease Pencil strokes";
228
231
233
234 prop = RNA_def_boolean(
235 ot->srna, "back", false, "Return to Previous Mode", "Return to previous mode");
237}
238
245
247{
249 if ((ob) && ob->type == OB_GREASE_PENCIL) {
250 return ob->data != nullptr;
251 }
252 return false;
253}
254
256{
257 Main *bmain = CTX_data_main(C);
258 Scene *scene = CTX_data_scene(C);
260
261 const bool back = RNA_boolean_get(op->ptr, "back");
262
264 short mode;
266 BLI_assert(ob != nullptr);
267 const bool is_mode_set = (ob->mode & OB_MODE_WEIGHT_GREASE_PENCIL) != 0;
268 if (!is_mode_set) {
270 }
271 else {
272 mode = OB_MODE_OBJECT;
273 }
274
275 if ((ob->restore_mode) && ((ob->mode & OB_MODE_WEIGHT_GREASE_PENCIL) == 0) && (back == 1)) {
276 mode = ob->restore_mode;
277 }
278 ob->restore_mode = ob->mode;
279 ob->mode = mode;
280
281 /* Prepare armature posemode. */
283
284 if (mode == OB_MODE_WEIGHT_GREASE_PENCIL) {
285 /* Be sure we have brushes. */
288
290
292 BKE_paint_brushes_validate(bmain, weight_paint);
293 }
294
295 GreasePencil *grease_pencil = static_cast<GreasePencil *>(ob->data);
297
300
301 WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
302
303 if (G.background == false) {
305 }
306
307 return OPERATOR_FINISHED;
308}
309
311{
312 PropertyRNA *prop;
313
314 ot->name = "Strokes Weight Mode Toggle";
315 ot->idname = "GREASE_PENCIL_OT_weightmode_toggle";
316 ot->description = "Enter/Exit weight paint mode for Grease Pencil strokes";
317
320
322
323 prop = RNA_def_boolean(
324 ot->srna, "back", false, "Return to Previous Mode", "Return to previous mode");
326}
327
329
330/* -------------------------------------------------------------------- */
333
340
342{
344 if ((ob) && ob->type == OB_GREASE_PENCIL) {
345 return ob->data != nullptr;
346 }
347 return false;
348}
349
351{
352 const bool back = RNA_boolean_get(op->ptr, "back");
353
355 Main *bmain = CTX_data_main(C);
356 Scene *scene = CTX_data_scene(C);
358
359 short mode;
361 BLI_assert(ob != nullptr);
362 const bool is_mode_set = (ob->mode & OB_MODE_VERTEX_GREASE_PENCIL) != 0;
363 if (!is_mode_set) {
365 }
366 else {
367 mode = OB_MODE_OBJECT;
368 }
369
370 if ((ob->restore_mode) && ((ob->mode & OB_MODE_VERTEX_GREASE_PENCIL) == 0) && (back == 1)) {
371 mode = ob->restore_mode;
372 }
373 ob->restore_mode = ob->mode;
374 ob->mode = mode;
375
376 if (mode == OB_MODE_VERTEX_GREASE_PENCIL) {
377 /* Be sure we have brushes.
378 * Need Draw as well (used for Palettes). */
379 BKE_paint_ensure(ts, (Paint **)&ts->gp_paint);
383
384 BKE_paint_brushes_ensure(bmain, gp_paint);
385 BKE_paint_brushes_ensure(bmain, vertex_paint);
386 BKE_paint_brushes_validate(bmain, vertex_paint);
387
389
390 /* Ensure Palette by default. */
391 BKE_gpencil_palette_ensure(bmain, scene);
392 }
393
394 GreasePencil *grease_pencil = static_cast<GreasePencil *>(ob->data);
396
399
400 WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
401
402 if (G.background == false) {
404 }
405
406 return OPERATOR_FINISHED;
407}
408
410{
411 PropertyRNA *prop;
412
413 ot->name = "Strokes Vertex Mode Toggle";
414 ot->idname = "GREASE_PENCIL_OT_vertexmode_toggle";
415 ot->description = "Enter/Exit vertex paint mode for Grease Pencil strokes";
416
419
421
422 prop = RNA_def_boolean(
423 ot->srna, "back", false, "Return to Previous Mode", "Return to previous mode");
425}
426
428
429} // namespace blender::ed::greasepencil
430
void BKE_brush_init_gpencil_settings(Brush *brush)
Definition brush.cc:604
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:246
void BKE_paint_brushes_ensure(Main *bmain, Paint *paint)
Definition paint.cc:1752
const uchar PAINT_CURSOR_PAINT_GREASE_PENCIL[3]
Definition paint.cc:245
Paint * BKE_paint_get_active_from_paintmode(Scene *sce, PaintMode mode)
Definition paint.cc:365
void BKE_paint_init(Main *bmain, Scene *sce, PaintMode mode, const uchar col[3], bool ensure_brushes=true)
Definition paint.cc:1769
bool BKE_paint_ensure(ToolSettings *ts, Paint **r_paint)
Definition paint.cc:1675
Brush * BKE_paint_brush(Paint *paint)
Definition paint.cc:636
void BKE_paint_brushes_validate(Main *bmain, Paint *paint)
Definition paint.cc:1109
#define BLI_assert(a)
Definition BLI_assert.h:46
void DEG_id_tag_update(ID *id, unsigned int flags)
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:962
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:982
@ 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
@ OPERATOR_FINISHED
void ED_paint_cursor_start(Paint *paint, bool(*poll)(bContext *C))
@ PROP_SKIP_SAVE
Definition RNA_types.hh:330
@ PROP_HIDDEN
Definition RNA_types.hh:324
#define C
Definition RandGen.cpp:29
#define ND_DATA
Definition WM_types.hh:506
#define ND_GPENCIL_EDITMODE
Definition WM_types.hh:501
#define ND_MODE
Definition WM_types.hh:442
#define NC_SCENE
Definition WM_types.hh:375
#define NC_GPENCIL
Definition WM_types.hh:396
@ OPTYPE_UNDO
Definition WM_types.hh:182
@ OPTYPE_REGISTER
Definition WM_types.hh:180
void ED_operatortypes_grease_pencil_modes()
#define G(x, y, z)
static void GREASE_PENCIL_OT_sculptmode_toggle(wmOperatorType *ot)
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 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)
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
struct PointerRNA * ptr
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition wm_files.cc:4226
#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)