Blender V5.0
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#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_image.hh"
23#include "ED_object.hh"
24
25#include "DEG_depsgraph.hh"
26
27#include "WM_api.hh"
28#include "WM_message.hh"
29#include "WM_toolsystem.hh"
30
32
33/* -------------------------------------------------------------------- */
36
38{
40 return true;
41 }
42 return false;
43}
44
46{
48 if ((ob) && ob->type == OB_GREASE_PENCIL) {
49 return ob->data != nullptr;
50 }
51 return false;
52}
53
55{
56 const bool back = RNA_boolean_get(op->ptr, "back");
57
59 Main *bmain = CTX_data_main(C);
61
62 short mode;
64 BLI_assert(ob != nullptr);
65
66 const bool is_mode_set = (ob->mode & OB_MODE_PAINT_GREASE_PENCIL) != 0;
67 if (!is_mode_set) {
68 Scene *scene = CTX_data_scene(C);
73 }
74 else {
75 mode = OB_MODE_OBJECT;
76 }
77
78 if ((ob->restore_mode) && ((ob->mode & OB_MODE_PAINT_GREASE_PENCIL) == 0) && (back == 1)) {
79 mode = ob->restore_mode;
80 }
81 ob->restore_mode = ob->mode;
82 ob->mode = mode;
83
84 if (mode == OB_MODE_PAINT_GREASE_PENCIL) {
85 /* Be sure we have brushes and Paint settings.
86 * Need Draw and Vertex (used for Tint). */
87 BKE_paint_ensure(ts, (Paint **)&ts->gp_paint);
91
92 /* Ensure Palette by default. */
94
95 Paint *paint = &ts->gp_paint->paint;
96 Brush *brush = BKE_paint_brush(paint);
97 if (brush && !brush->gpencil_settings) {
99 }
101 }
102
103 GreasePencil *grease_pencil = static_cast<GreasePencil *>(ob->data);
105
108
109 WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
110
111 if (G.background == false) {
113 }
114
115 return OPERATOR_FINISHED;
116}
117
119{
120 PropertyRNA *prop;
121
122 ot->name = "Strokes Paint Mode Toggle";
123 ot->idname = "GREASE_PENCIL_OT_paintmode_toggle";
124 ot->description = "Enter/Exit paint mode for Grease Pencil strokes";
125
128
130
131 prop = RNA_def_boolean(
132 ot->srna, "back", false, "Return to Previous Mode", "Return to previous mode");
134}
135
137
138/* -------------------------------------------------------------------- */
141
143{
145 if (ob == nullptr) {
146 return false;
147 }
148 if (ob->type == OB_GREASE_PENCIL) {
149 return ob->data != nullptr;
150 }
151 return false;
152}
153
155{
156 const Object *ob = CTX_data_active_object(C);
157 if (ob == nullptr || (ob->mode & OB_MODE_SCULPT_GREASE_PENCIL) == 0) {
158 return false;
159 }
160 if (CTX_wm_region_view3d(C) == nullptr) {
161 return false;
162 }
163 return true;
164}
165
167{
168 Main *bmain = CTX_data_main(C);
170
171 const bool back = RNA_boolean_get(op->ptr, "back");
172
174 short mode;
176 BLI_assert(ob != nullptr);
177 const bool is_mode_set = (ob->mode & OB_MODE_SCULPT_GREASE_PENCIL) != 0;
178 if (is_mode_set) {
179 mode = OB_MODE_OBJECT;
180 }
181 else {
182 Scene *scene = CTX_data_scene(C);
187 }
188
189 if ((ob->restore_mode) && ((ob->mode & OB_MODE_SCULPT_GREASE_PENCIL) == 0) && (back == 1)) {
190 mode = ob->restore_mode;
191 }
192 ob->restore_mode = ob->mode;
193 ob->mode = mode;
194
195 if (mode == OB_MODE_SCULPT_GREASE_PENCIL) {
199 }
200
201 GreasePencil *grease_pencil = static_cast<GreasePencil *>(ob->data);
203
206
207 WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
208
209 if (G.background == false) {
211 }
212
213 return OPERATOR_FINISHED;
214}
215
217
218/* -------------------------------------------------------------------- */
221
223{
224 PropertyRNA *prop;
225
226 ot->name = "Strokes Sculpt Mode Toggle";
227 ot->idname = "GREASE_PENCIL_OT_sculptmode_toggle";
228 ot->description = "Enter/Exit sculpt mode for Grease Pencil strokes";
229
232
234
235 prop = RNA_def_boolean(
236 ot->srna, "back", false, "Return to Previous Mode", "Return to previous mode");
238}
239
246
248{
250 if ((ob) && ob->type == OB_GREASE_PENCIL) {
251 return ob->data != nullptr;
252 }
253 return false;
254}
255
257{
258 Main *bmain = CTX_data_main(C);
259 Scene *scene = CTX_data_scene(C);
261
262 const bool back = RNA_boolean_get(op->ptr, "back");
263
265 short mode;
267 BLI_assert(ob != nullptr);
268 const bool is_mode_set = (ob->mode & OB_MODE_WEIGHT_GREASE_PENCIL) != 0;
269 if (!is_mode_set) {
271 }
272 else {
273 mode = OB_MODE_OBJECT;
274 }
275
276 if ((ob->restore_mode) && ((ob->mode & OB_MODE_WEIGHT_GREASE_PENCIL) == 0) && (back == 1)) {
277 mode = ob->restore_mode;
278 }
279 ob->restore_mode = ob->mode;
280 ob->mode = mode;
281
282 /* Prepare armature posemode. */
284
285 if (mode == OB_MODE_WEIGHT_GREASE_PENCIL) {
286 /* Be sure we have brushes. */
289
291
293 BKE_paint_brushes_validate(bmain, weight_paint);
294 }
295
296 GreasePencil *grease_pencil = static_cast<GreasePencil *>(ob->data);
298
301
302 WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
303
304 if (G.background == false) {
306 }
307
308 return OPERATOR_FINISHED;
309}
310
312{
313 PropertyRNA *prop;
314
315 ot->name = "Strokes Weight Mode Toggle";
316 ot->idname = "GREASE_PENCIL_OT_weightmode_toggle";
317 ot->description = "Enter/Exit weight paint mode for Grease Pencil strokes";
318
321
323
324 prop = RNA_def_boolean(
325 ot->srna, "back", false, "Return to Previous Mode", "Return to previous mode");
327}
328
330
331/* -------------------------------------------------------------------- */
334
341
343{
345 if ((ob) && ob->type == OB_GREASE_PENCIL) {
346 return ob->data != nullptr;
347 }
348 return false;
349}
350
352{
353 const bool back = RNA_boolean_get(op->ptr, "back");
354
356 Main *bmain = CTX_data_main(C);
357 Scene *scene = CTX_data_scene(C);
359
360 short mode;
362 BLI_assert(ob != nullptr);
363 const bool is_mode_set = (ob->mode & OB_MODE_VERTEX_GREASE_PENCIL) != 0;
364 if (!is_mode_set) {
366 }
367 else {
368 mode = OB_MODE_OBJECT;
369 }
370
371 if ((ob->restore_mode) && ((ob->mode & OB_MODE_VERTEX_GREASE_PENCIL) == 0) && (back == 1)) {
372 mode = ob->restore_mode;
373 }
374 ob->restore_mode = ob->mode;
375 ob->mode = mode;
376
377 if (mode == OB_MODE_VERTEX_GREASE_PENCIL) {
378 /* Be sure we have brushes.
379 * Need Draw as well (used for Palettes). */
380 BKE_paint_ensure(ts, (Paint **)&ts->gp_paint);
384
385 BKE_paint_brushes_ensure(bmain, gp_paint);
386 BKE_paint_brushes_ensure(bmain, vertex_paint);
387 BKE_paint_brushes_validate(bmain, vertex_paint);
388
390
391 /* Ensure Palette by default. */
392 BKE_gpencil_palette_ensure(bmain, scene);
393 }
394
395 GreasePencil *grease_pencil = static_cast<GreasePencil *>(ob->data);
397
400
401 WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
402
403 if (G.background == false) {
405 }
406
407 return OPERATOR_FINISHED;
408}
409
411{
412 PropertyRNA *prop;
413
414 ot->name = "Strokes Vertex Mode Toggle";
415 ot->idname = "GREASE_PENCIL_OT_vertexmode_toggle";
416 ot->description = "Enter/Exit vertex paint mode for Grease Pencil strokes";
417
420
422
423 prop = RNA_def_boolean(
424 ot->srna, "back", false, "Return to Previous Mode", "Return to previous mode");
426}
427
429
430} // namespace blender::ed::greasepencil
431
void BKE_brush_init_gpencil_settings(Brush *brush)
Definition brush.cc:648
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)
void BKE_paint_brushes_ensure(Main *bmain, Paint *paint)
Definition paint.cc:1823
void BKE_paint_init(Main *bmain, Scene *sce, PaintMode mode, bool ensure_brushes=true)
Definition paint.cc:1840
Paint * BKE_paint_get_active_from_paintmode(Scene *sce, PaintMode mode)
Definition paint.cc:374
bool BKE_paint_ensure(ToolSettings *ts, Paint **r_paint)
Definition paint.cc:1738
Brush * BKE_paint_brush(Paint *paint)
Definition paint.cc:645
void BKE_paint_brushes_validate(Main *bmain, Paint *paint)
Definition paint.cc:1125
#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:1054
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ 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:344
@ PROP_HIDDEN
Definition RNA_types.hh:338
#define C
Definition RandGen.cpp:29
#define ND_DATA
Definition WM_types.hh:509
#define ND_GPENCIL_EDITMODE
Definition WM_types.hh:504
#define ND_MODE
Definition WM_types.hh:445
#define NC_SCENE
Definition WM_types.hh:378
@ OPTYPE_UNDO
Definition WM_types.hh:182
@ OPTYPE_REGISTER
Definition WM_types.hh:180
#define NC_GPENCIL
Definition WM_types.hh:399
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:4237
#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)