Blender V5.3
wm_toolsystem.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
18
19#include <cstring>
20
21#include "CLG_log.h"
22
23#include "MEM_guardedalloc.h"
24
25#include "BLI_listbase.hh"
26#include "BLI_string.hh"
27#include "BLI_string_utf8.hh"
28#include "BLI_utildefines.hh"
29
30#include "DNA_ID.h"
31#include "DNA_brush_types.h"
32#include "DNA_object_types.h"
33#include "DNA_scene_types.h"
34#include "DNA_space_types.h"
36#include "DNA_workspace_types.h"
37
38#include "BKE_asset_edit.hh"
39#include "BKE_brush.hh"
40#include "BKE_context.hh"
41#include "BKE_global.hh"
42#include "BKE_idprop.hh"
43#include "BKE_layer.hh"
44#include "BKE_lib_id.hh"
45#include "BKE_main.hh"
46#include "BKE_paint.hh"
47#include "BKE_workspace.hh"
48
49#include "RNA_access.hh"
50#include "RNA_enum_types.hh"
51
52#include "WM_api.hh"
53#include "WM_message.hh"
54#include "WM_toolsystem.hh" /* Own include. */
55#include "WM_types.hh"
56
57namespace blender {
58
59static void toolsystem_reinit_with_toolref(bContext *C, WorkSpace * /*workspace*/, bToolRef *tref);
61 WorkSpace *workspace,
62 const bToolKey *tkey,
63 const char *default_tool);
65 WorkSpace *workspace,
66 bToolRef *tref);
67static void toolsystem_ref_set_by_brush_type(bContext *C, const char *brush_type);
68
69static void toolsystem_ref_set_by_id_pending(Main *bmain,
70 bToolRef *tref,
71 const char *idname_pending);
72
73/* -------------------------------------------------------------------- */
76
78{
79 WorkSpace *workspace = CTX_wm_workspace(C);
80 if (workspace == nullptr) {
81 return nullptr;
82 }
83 const Main *bmain = CTX_data_main(C);
84 const Scene *scene = CTX_data_scene(C);
85 ViewLayer *view_layer = CTX_data_view_layer(C);
86 ScrArea *area = CTX_wm_area(C);
87 if ((area == nullptr) || ((1 << area->spacetype) & WM_TOOLSYSTEM_SPACE_MASK) == 0) {
88 return nullptr;
89 }
90 bToolKey tkey{};
91 tkey.space_type = area->spacetype;
92 tkey.mode = WM_toolsystem_mode_from_spacetype(*bmain, scene, view_layer, area, area->spacetype);
93 bToolRef *tref = WM_toolsystem_ref_find(workspace, &tkey);
94 /* We could return 'area->runtime.tool' in this case. */
95 if (area->runtime.is_tool_set) {
96 BLI_assert(tref == area->runtime.tool);
97 }
98 return tref;
99}
100
102{
104 return tref ? tref->runtime : nullptr;
105}
106
108{
110 for (bToolRef &tref : workspace->tools) {
111 if ((tref.space_type == tkey->space_type) && (tref.mode == tkey->mode)) {
112 return &tref;
113 }
114 }
115 return nullptr;
116}
117
119{
120 bToolRef *tref = WM_toolsystem_ref_find(workspace, tkey);
121 return tref ? tref->runtime : nullptr;
122}
123
124bool WM_toolsystem_ref_ensure(WorkSpace *workspace, const bToolKey *tkey, bToolRef **r_tref)
125{
126 bToolRef *tref = WM_toolsystem_ref_find(workspace, tkey);
127 if (tref) {
128 *r_tref = tref;
129 return false;
130 }
131 tref = MEM_new<bToolRef>(__func__);
132 BLI_addhead(&workspace->tools, tref);
133 tref->space_type = tkey->space_type;
134 tref->mode = tkey->mode;
135 *r_tref = tref;
136 return true;
137}
138
143 const Scene *scene,
144 ViewLayer *view_layer,
145 ScrArea *area)
146{
147 bToolKey tkey{};
148
149 if (area && ((1 << area->spacetype) & WM_TOOLSYSTEM_SPACE_MASK)) {
150 tkey.space_type = area->spacetype;
151 tkey.mode = WM_toolsystem_mode_from_spacetype(bmain, scene, view_layer, area, area->spacetype);
152 return tkey;
153 }
154
155 /* Otherwise: Fallback to getting the active tool for 3D views. */
157 tkey.mode = WM_toolsystem_mode_from_spacetype(bmain, scene, view_layer, nullptr, SPACE_VIEW3D);
158 return tkey;
159}
160
169{
170 /* Current space & mode has its own active tool, use that. */
171 const ScrArea *area = CTX_wm_area(C);
172 if (area && ((1 << area->spacetype) & WM_TOOLSYSTEM_SPACE_MASK)) {
174 }
175
176 /* Otherwise: Fallback to getting the active tool for 3D views. */
177 WorkSpace *workspace = CTX_wm_workspace(C);
178 if (workspace == nullptr) {
179 return nullptr;
180 }
181 const Main *bmain = CTX_data_main(C);
182 const Scene *scene = CTX_data_scene(C);
183 ViewLayer *view_layer = CTX_data_view_layer(C);
184 bToolKey tkey{};
186 tkey.mode = WM_toolsystem_mode_from_spacetype(*bmain, scene, view_layer, nullptr, SPACE_VIEW3D);
187 return WM_toolsystem_ref_find(workspace, &tkey);
188}
189
191
192static void toolsystem_unlink_ref(bContext *C, WorkSpace * /*workspace*/, bToolRef *tref)
193{
194 bToolRef_Runtime *tref_rt = tref->runtime;
195
196 if (tref_rt->gizmo_group[0]) {
197 wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(tref_rt->gizmo_group, false);
198 if (gzgt != nullptr) {
199 Main *bmain = CTX_data_main(C);
200 WM_gizmo_group_remove_by_tool(C, bmain, gzgt, tref);
201 }
202 }
203}
204void WM_toolsystem_unlink(bContext *C, WorkSpace *workspace, const bToolKey *tkey)
205{
206 bToolRef *tref = WM_toolsystem_ref_find(workspace, tkey);
207 if (tref && tref->runtime) {
208 toolsystem_unlink_ref(C, workspace, tref);
209 }
210}
211
212/* -------------------------------------------------------------------- */
215
216static const char *brush_type_identifier_get(const int brush_type, const PaintMode paint_mode)
217{
218 const EnumPropertyItem *type_enum = BKE_paint_get_tool_enum_from_paintmode(paint_mode);
219 const int item_idx = RNA_enum_from_value(type_enum, brush_type);
220 if (item_idx == -1) {
221 return "";
222 }
223 return type_enum[item_idx].identifier;
224}
225
226static bool brush_type_matches_active_tool(bContext *C, const int brush_type)
227{
229 if (active_tool == nullptr || active_tool->runtime == nullptr) {
230 /* Should only ever be null in background mode. */
231 BLI_assert(G.background);
232 return false;
233 }
234
235 if (!(active_tool->runtime->flag & TOOLREF_FLAG_USE_BRUSHES)) {
236 return false;
237 }
238
240 return active_tool->runtime->brush_type == brush_type;
241}
242
244 const char *brush_type_name)
245{
246 return static_cast<NamedBrushAssetReference *>(
247 BLI_findstring_ptr(&paint->tool_brush_bindings.active_brush_per_brush_type,
248 brush_type_name,
250}
251
256{
257 MEM_delete(paint->tool_brush_bindings.main_brush_asset_reference);
258 paint->tool_brush_bindings.main_brush_asset_reference = nullptr;
259
260 if (paint->brush != nullptr) {
261 if (std::optional<AssetWeakReference> brush_asset_reference =
263 {
264 paint->tool_brush_bindings.main_brush_asset_reference = MEM_new<AssetWeakReference>(
265 __func__, *brush_asset_reference);
266 }
267 }
268}
269
271 const PaintMode paint_mode,
272 const int brush_type)
273{
274 if (paint->brush == nullptr) {
275 return;
276 }
277 const char *brush_type_name = brush_type_identifier_get(brush_type, paint_mode);
278 if (!brush_type_name || !brush_type_name[0]) {
279 return;
280 }
281
282 /* Update existing reference. */
284 paint, brush_type_name))
285 {
286 MEM_delete(existing_brush_ref->brush_asset_reference);
287 existing_brush_ref->brush_asset_reference = MEM_new<AssetWeakReference>(
288 __func__, *paint->brush_asset_reference);
289 }
290 /* Add new reference. */
291 else {
292 NamedBrushAssetReference *new_brush_ref = MEM_new<NamedBrushAssetReference>(__func__);
293
294 new_brush_ref->name = BLI_strdup(brush_type_name);
295 new_brush_ref->brush_asset_reference = MEM_new<AssetWeakReference>(
296 __func__, *paint->brush_asset_reference);
297 BLI_addhead(&paint->tool_brush_bindings.active_brush_per_brush_type, new_brush_ref);
298 }
299}
300
302{
305
307 /* Avoid switching tool when brush isn't valid for this mode anyway. */
308 return false;
309 }
310
311 /* If necessary, find a compatible tool to switch to. */
312 {
313 std::optional<int> brush_type = BKE_paint_get_brush_type_from_paintmode(brush, paint_mode);
314 if (!brush_type) {
316 WM_toolsystem_ref_set_by_id(C, "builtin.brush");
317 }
318 else if (!brush_type_matches_active_tool(C, *brush_type)) {
319 const char *brush_type_name = brush_type_identifier_get(*brush_type, paint_mode);
320 /* Calls into .py to query available tools. */
321 toolsystem_ref_set_by_brush_type(C, brush_type_name);
322 }
323 }
324
325 /* Do after switching tool, since switching tool will attempt to restore the last used brush of
326 * that tool (in #toolsystem_brush_activate_from_toolref_for_object_paint()). */
328 return false;
329 }
330
331 if (active_tool == nullptr || active_tool->runtime == nullptr) {
332 BLI_assert(G.background);
333 return false;
334 }
335
336 if (active_tool->runtime->brush_type == -1) {
337 /* Only update the main brush binding to reference the newly active brush. */
339 }
340 else {
342 }
343
344 return true;
345}
346
348 const WorkSpace *workspace,
349 const bToolRef *tref)
350{
351 const bToolRef_Runtime *tref_rt = tref->runtime;
352
353 if (!tref_rt->data_block[0]) {
354 return;
355 }
356
358 const int i = RNA_enum_from_identifier(items, tref_rt->data_block);
359 if (i == -1) {
360 return;
361 }
362
363 const wmWindowManager *wm = bmain->wm.first();
364 for (wmWindow &win : wm->windows) {
365 if (workspace == WM_window_get_active_workspace(&win)) {
366 Scene *scene = WM_window_get_active_scene(&win);
367 ToolSettings *ts = scene->toolsettings;
368 ts->particle.brushtype = items[i].value;
369 }
370 }
371}
372
373std::optional<AssetWeakReference> WM_toolsystem_last_brush_asset_from_brush_type(
374 Scene *scene, const int brush_type, const PaintMode paint_mode)
375{
376 Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode);
377 if (!paint) {
378 return {};
379 }
380 if (brush_type != -1) {
381 const char *brush_type_name = brush_type_identifier_get(brush_type, paint_mode);
383 paint, brush_type_name);
384
385 if (brush_ref && brush_ref->brush_asset_reference) {
386 return *brush_ref->brush_asset_reference;
387 }
388 return BKE_paint_brush_type_default_reference(paint->runtime->asset_category, brush_type);
389 }
390
391 if (paint->tool_brush_bindings.main_brush_asset_reference) {
392 return *paint->tool_brush_bindings.main_brush_asset_reference;
393 }
394 return BKE_paint_brush_type_default_reference(paint->runtime->asset_category, std::nullopt);
395}
396
398 const WorkSpace *workspace,
399 const bToolRef *tref)
400{
401 bToolRef_Runtime *tref_rt = tref->runtime;
402
403 const PaintMode paint_mode = BKE_paintmode_get_from_tool(tref);
404 BLI_assert(paint_mode != PaintMode::Invalid);
405
406 wmWindowManager *wm = bmain->wm.first();
407 for (wmWindow &win : wm->windows) {
408 if (workspace != WM_window_get_active_workspace(&win)) {
409 continue;
410 }
411 Scene *scene = WM_window_get_active_scene(&win);
412 BKE_paint_ensure_from_paintmode(scene, paint_mode);
413 Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode);
414
415 /* Attempt to re-activate a brush remembered for this brush type, as stored in a brush
416 * binding. */
417 if (std::optional<AssetWeakReference> brush_asset_reference =
419 {
420 BKE_paint_brush_set(bmain, paint, *brush_asset_reference);
421 if (tref_rt->brush_type == -1) {
422 /* Update the bindings so the main brush reference matches the currently active brush. */
424 }
425 }
426 }
427}
428
433 const WorkSpace *workspace,
434 const bToolRef *tref)
435{
437
438 if (tref->space_type == SPACE_VIEW3D) {
439 if (tref->mode == CTX_MODE_PARTICLE) {
441 }
442 else {
444 }
445 }
446 else if (tref->space_type == SPACE_IMAGE) {
447 if (tref->mode == SI_MODE_PAINT) {
449 }
450 }
451}
452
459 WorkSpace *workspace,
460 bToolRef *tref)
461{
462 if (tref->space_type == SPACE_VIEW3D) {
463 if (tref->mode == CTX_MODE_PAINT_TEXTURE) {
464 bToolKey tkey{};
465 tkey.space_type = SPACE_IMAGE;
466 tkey.mode = SI_MODE_PAINT;
467 bToolRef *tref_other = WM_toolsystem_ref_find(workspace, &tkey);
468 if (tref_other) {
469 toolsystem_ref_set_by_id_pending(bmain, tref_other, tref->idname);
470 }
471 }
472 }
473 else if (tref->space_type == SPACE_IMAGE) {
474 if (tref->mode == SI_MODE_PAINT) {
475 bToolKey tkey{};
478 bToolRef *tref_other = WM_toolsystem_ref_find(workspace, &tkey);
479 if (tref_other) {
480 toolsystem_ref_set_by_id_pending(bmain, tref_other, tref->idname);
481 }
482 }
483 }
484}
486 WorkSpace *workspace,
487 bToolRef *tref)
488{
489 const PaintMode paint_mode = BKE_paintmode_get_from_tool(tref);
490
491 wmWindowManager *wm = bmain->wm.first();
492 for (wmWindow &win : wm->windows) {
493 if (workspace != WM_window_get_active_workspace(&win)) {
494 continue;
495 }
496 Scene *scene = WM_window_get_active_scene(&win);
497 if (Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode)) {
499 }
500 }
501}
502
504
505static void toolsystem_ref_link(Main *bmain, WorkSpace *workspace, bToolRef *tref)
506{
507 bToolRef_Runtime *tref_rt = tref->runtime;
508 if (tref_rt->gizmo_group[0]) {
509 const char *idname = tref_rt->gizmo_group;
510 wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false);
511 if (gzgt != nullptr) {
512 if ((gzgt->flag & WM_GIZMOGROUPTYPE_TOOL_INIT) == 0) {
514 /* Even if the group-type has been linked, it's possible the space types
515 * were not previously using it. (happens with multiple windows). */
518 }
519 }
520 }
521 else {
522 CLOG_WARN(WM_LOG_TOOL_GIZMO, "'%s' widget not found", idname);
523 }
524 }
525
526 if (tref_rt->flag & TOOLREF_FLAG_USE_BRUSHES) {
527 toolsystem_brush_activate_from_toolref(bmain, workspace, tref);
528 toolsystem_brush_sync_for_texture_paint(bmain, workspace, tref);
529 }
530 else {
531 toolsystem_brush_clear_paint_reference(bmain, workspace, tref);
532 }
533}
534
535static void toolsystem_refresh_ref(const bContext *C, WorkSpace *workspace, bToolRef *tref)
536{
537 if (tref->runtime == nullptr) {
538 return;
539 }
540 /* Currently same operation. */
541 toolsystem_ref_link(CTX_data_main(C), workspace, tref);
542}
543void WM_toolsystem_refresh(const bContext *C, WorkSpace *workspace, const bToolKey *tkey)
544{
545 bToolRef *tref = WM_toolsystem_ref_find(workspace, tkey);
546 if (tref) {
547 toolsystem_refresh_ref(C, workspace, tref);
548 }
549}
550
551static void toolsystem_reinit_ref(bContext *C, WorkSpace *workspace, bToolRef *tref)
552{
553 toolsystem_reinit_with_toolref(C, workspace, tref);
554}
555void WM_toolsystem_reinit(bContext *C, WorkSpace *workspace, const bToolKey *tkey)
556{
557 bToolRef *tref = WM_toolsystem_ref_find(workspace, tkey);
558 if (tref) {
559 toolsystem_reinit_ref(C, workspace, tref);
560 }
561}
562
564{
565 for (bToolRef &tref : workspace->tools) {
566 tref.tag = 0;
567 }
568
569 for (bToolRef &tref : workspace->tools) {
570 if (tref.runtime) {
571 if (tref.tag == 0) {
572 toolsystem_unlink_ref(C, workspace, &tref);
573 tref.tag = 1;
574 }
575 }
576 }
577}
578
580{
581 BLI_assert(0);
582 for (bToolRef &tref : workspace->tools) {
583 toolsystem_refresh_ref(C, workspace, &tref);
584 }
585}
587{
589 const Main *bmain = CTX_data_main(C);
590 const Scene *scene = WM_window_get_active_scene(win);
592 for (ScrArea &area : screen->areabase) {
593 if (((1 << area.spacetype) & WM_TOOLSYSTEM_SPACE_MASK) == 0) {
594 continue;
595 }
596
598 bToolKey tkey{};
599 tkey.space_type = area.spacetype;
601 *bmain, scene, view_layer, &area, area.spacetype);
602 bToolRef *tref = WM_toolsystem_ref_find(workspace, &tkey);
603 if (tref) {
604 if (tref->tag == 0) {
605 toolsystem_reinit_ref(C, workspace, tref);
606 tref->tag = 1;
607 }
608 }
609 }
610}
611
613 WorkSpace *workspace,
614 bToolRef *tref,
615 const bToolRef_Runtime *tref_rt,
616 const char *idname)
617{
618 Main *bmain = CTX_data_main(C);
619 wmWindow *win = CTX_wm_window(C);
620
621 if (tref->runtime) {
622 toolsystem_unlink_ref(C, workspace, tref);
623 }
624 if (win) {
625 WM_tooltip_clear(C, win);
626 }
627
628 STRNCPY_UTF8(tref->idname, idname);
629
630 /* This immediate request supersedes any unhandled pending requests. */
631 tref->idname_pending[0] = '\0';
632
633 if (tref->runtime == nullptr) {
634 tref->runtime = MEM_new<bToolRef_Runtime>(__func__);
635 }
636
637 if (tref_rt != tref->runtime) {
638 *tref->runtime = *tref_rt;
639 }
640
641 /* Ideally Python could check this gizmo group flag and not
642 * pass in the argument to begin with. */
643 bool use_fallback_keymap = false;
644
645 if (tref->idname_fallback[0] || tref->runtime->keymap_fallback[0]) {
646 if (tref_rt->flag & TOOLREF_FLAG_FALLBACK_KEYMAP) {
647 use_fallback_keymap = true;
648 }
649 else if (tref_rt->gizmo_group[0]) {
650 wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(tref_rt->gizmo_group, false);
651 if (gzgt) {
653 use_fallback_keymap = true;
654 }
655 }
656 }
657 }
658 if (use_fallback_keymap == false) {
659 tref->idname_fallback[0] = '\0';
660 tref->runtime->keymap_fallback[0] = '\0';
661 }
662
663 toolsystem_ref_link(bmain, workspace, tref);
664
665 toolsystem_refresh_screen_from_active_tool(bmain, workspace, tref);
666
667 /* Set the cursor if possible, if not - it's fine as entering the region will refresh it. */
668 {
669 wmWindow *win = CTX_wm_window(C);
670 if (win != nullptr) {
671 win->addmousemove = true;
672 win->tag_cursor_refresh = true;
673 }
674 }
675
676 {
678 WM_msg_publish_rna_prop(mbus, &workspace->id, workspace, WorkSpace, tools);
679 }
680}
681
683{
684 bToolRef_Runtime *tref_rt = tref->runtime;
685 if ((tref_rt == nullptr) || (tref_rt->data_block[0] == '\0')) {
686 return;
687 }
688 wmWindowManager *wm = bmain->wm.first();
689 for (wmWindow &win : wm->windows) {
690 if (workspace != WM_window_get_active_workspace(&win)) {
691 continue;
692 }
693
694 Scene *scene = WM_window_get_active_scene(&win);
695 ToolSettings *ts = scene->toolsettings;
696 ViewLayer *view_layer = WM_window_get_active_view_layer(&win);
697 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
698 const Object *ob = BKE_view_layer_active_object_get(view_layer);
699 if (ob == nullptr) {
700 /* Pass. */
701 }
702 if ((tref->space_type == SPACE_VIEW3D) && (tref->mode == CTX_MODE_PARTICLE)) {
703 if (ob->mode & OB_MODE_PARTICLE_EDIT) {
705 const int i = RNA_enum_from_value(items, ts->particle.brushtype);
706 const EnumPropertyItem *item = &items[i];
707 if (!STREQ(tref_rt->data_block, item->identifier)) {
708 STRNCPY_UTF8(tref_rt->data_block, item->identifier);
709 SNPRINTF_UTF8(tref->idname, "builtin_brush.%s", item->name);
710 }
711 }
712 }
713 }
714}
715
717{
718 Main *bmain = CTX_data_main(C);
719
720 BLI_assert(CTX_wm_window(C) == nullptr);
721
722 for (WorkSpace &workspace : bmain->workspaces) {
723 for (bToolRef &tref : workspace.tools) {
724 MEM_SAFE_DELETE(tref.runtime);
725 }
726 }
727
728 /* Rely on screen initialization for gizmos. */
729}
730
731static bool toolsystem_key_ensure_check(const bToolKey *tkey)
732{
733 switch (tkey->space_type) {
734 case SPACE_VIEW3D:
735 return true;
736 case SPACE_IMAGE:
738 return true;
739 }
740 break;
741 case SPACE_NODE:
742 return true;
743 case SPACE_SEQ:
744 return true;
745 }
746 return false;
747}
748
750 const Main &bmain, const Scene *scene, ViewLayer *view_layer, ScrArea *area, int space_type)
751{
752 int mode = -1;
753 switch (space_type) {
754 case SPACE_VIEW3D: {
755 /* 'area' may be nullptr in this case. */
756 BKE_view_layer_synced_ensure(bmain, scene, view_layer);
757 Object *obact = BKE_view_layer_active_object_get(view_layer);
758 if (obact != nullptr) {
759 Object *obedit = OBEDIT_FROM_OBACT(obact);
760 mode = CTX_data_mode_enum_ex(obedit, obact, obact->mode);
761 }
762 else {
763 mode = CTX_MODE_OBJECT;
764 }
765 break;
766 }
767 case SPACE_IMAGE: {
768 SpaceImage *sima = area->spacedata.first_as<SpaceImage>();
769 mode = sima->mode;
770 break;
771 }
772 case SPACE_NODE: {
773 mode = 0;
774 break;
775 }
776 case SPACE_SEQ: {
777 SpaceSeq *sseq = area->spacedata.first_as<SpaceSeq>();
778 mode = sseq->view;
779 break;
780 }
781 }
782 return mode;
783}
784
786 const Main &bmain, const Scene *scene, ViewLayer *view_layer, ScrArea *area, bToolKey *tkey)
787{
788 int space_type = SPACE_EMPTY;
789 int mode = -1;
790
791 if (area != nullptr) {
792 space_type = area->spacetype;
793 mode = WM_toolsystem_mode_from_spacetype(bmain, scene, view_layer, area, space_type);
794 }
795
796 if (mode != -1) {
797 tkey->space_type = space_type;
798 tkey->mode = mode;
799 return true;
800 }
801 return false;
802}
803
805{
806 Main *bmain = CTX_data_main(C);
807
808 struct {
809 wmWindow *win;
810 ScrArea *area;
811 ARegion *region;
812 bool is_set;
813 } context_prev = {nullptr};
814
815 for (wmWindowManager *wm = bmain->wm.first(); wm;
816 wm = static_cast<wmWindowManager *>(wm->id.next))
817 {
818 for (wmWindow &win : wm->windows) {
819 WorkSpace *workspace = WM_window_get_active_workspace(&win);
820 bScreen *screen = WM_window_get_active_screen(&win);
821 const Scene *scene = WM_window_get_active_scene(&win);
822 ViewLayer *view_layer = WM_window_get_active_view_layer(&win);
823 /* Could skip loop for modes that don't depend on space type. */
824 int space_type_mask_handled = 0;
825 for (ScrArea &area : screen->areabase) {
826 /* Don't change the space type of the active tool, only update its mode. */
827 const int space_type_mask = (1 << area.spacetype);
828 if ((space_type_mask & WM_TOOLSYSTEM_SPACE_MASK) &&
829 ((space_type_mask_handled & space_type_mask) == 0))
830 {
831 space_type_mask_handled |= space_type_mask;
832 bToolKey tkey{};
833 tkey.space_type = area.spacetype;
835 *bmain, scene, view_layer, &area, area.spacetype);
836 bToolRef *tref = WM_toolsystem_ref_find(workspace, &tkey);
837 if (tref != area.runtime.tool) {
838 if (context_prev.is_set == false) {
839 context_prev.win = CTX_wm_window(C);
840 context_prev.area = CTX_wm_area(C);
841 context_prev.region = CTX_wm_region(C);
842 context_prev.is_set = true;
843 }
844
845 CTX_wm_window_set(C, &win);
846 CTX_wm_area_set(C, &area);
847
848 toolsystem_reinit_ensure_toolref(C, workspace, &tkey, nullptr);
849 }
850 }
851 }
852 }
853 }
854
855 if (context_prev.is_set) {
856 CTX_wm_window_set(C, context_prev.win);
857 CTX_wm_area_set(C, context_prev.area);
858 CTX_wm_region_set(C, context_prev.region);
859 }
860
862
863 for (WorkSpace &workspace : bmain->workspaces) {
864 if (workspace.id.tag & ID_TAG_DOIT) {
865 workspace.id.tag &= ~ID_TAG_DOIT;
866 /* Refresh to ensure data is initialized.
867 * This is needed because undo can load a state which no longer has the underlying DNA data
868 * needed for the tool (un-initialized paint-slots for eg), see: #64339. */
869 for (bToolRef &tref : workspace.tools) {
870 toolsystem_refresh_ref(C, &workspace, &tref);
871 }
872 }
873 }
874}
875
877 WorkSpace *workspace,
878 const Scene *scene,
879 ViewLayer *view_layer,
880 ScrArea *area)
881{
882 const bool is_tool_set_prev = area->runtime.is_tool_set;
883 const bToolRef *tref_prev = area->runtime.tool;
884
885 area->runtime.tool = nullptr;
886 area->runtime.is_tool_set = true;
887 const int mode = WM_toolsystem_mode_from_spacetype(
888 bmain, scene, view_layer, area, area->spacetype);
889 for (bToolRef &tref : workspace->tools) {
890 if (tref.space_type == area->spacetype) {
891 if (tref.mode == mode) {
892 area->runtime.tool = &tref;
893 break;
894 }
895 }
896 }
897 return !(is_tool_set_prev && (tref_prev == area->runtime.tool));
898}
899
901{
903 bool space_type_has_tools[SPACE_TYPE_NUM] = {false};
904 for (bToolRef &tref : workspace->tools) {
905 space_type_has_tools[tref.space_type] = true;
906 }
908 const Scene *scene = WM_window_get_active_scene(win);
910 for (ScrArea &area : screen->areabase) {
911 area.runtime.tool = nullptr;
912 area.runtime.is_tool_set = true;
913 if (space_type_has_tools[area.spacetype]) {
914 WM_toolsystem_refresh_screen_area(bmain, workspace, scene, view_layer, &area);
915 }
916 }
917}
918
920{
921 /* Update all ScrArea's tools. */
922 for (wmWindowManager *wm = bmain->wm.first(); wm;
923 wm = static_cast<wmWindowManager *>(wm->id.next))
924 {
925 for (wmWindow &win : wm->windows) {
927 }
928 }
929}
930
932 WorkSpace *workspace,
933 bToolRef *tref)
934{
935 /* Update all ScrArea's tools. */
936 for (wmWindowManager *wm = bmain->wm.first(); wm;
937 wm = static_cast<wmWindowManager *>(wm->id.next))
938 {
939 for (wmWindow &win : wm->windows) {
940 if (workspace == WM_window_get_active_workspace(&win)) {
941 bScreen *screen = WM_window_get_active_screen(&win);
942 const Scene *scene = WM_window_get_active_scene(&win);
943 ViewLayer *view_layer = WM_window_get_active_view_layer(&win);
944 for (ScrArea &area : screen->areabase) {
945 if (area.spacetype == tref->space_type) {
947 *bmain, scene, view_layer, &area, area.spacetype);
948 if (mode == tref->mode) {
949 area.runtime.tool = tref;
950 area.runtime.is_tool_set = true;
951 }
952 }
953 }
954 }
955 }
956 }
957}
958
960 bContext *C, WorkSpace *workspace, const bToolKey *tkey, const char *name, bool cycle)
961{
962 wmOperatorType *ot = WM_operatortype_find("WM_OT_tool_set_by_id", false);
963 /* On startup, Python operators are not yet loaded. */
964 if (ot == nullptr) {
965 return nullptr;
966 }
967
968/* Some contexts use the current space type (e.g. image editor),
969 * ensure this is set correctly or there is no area. */
970#ifndef NDEBUG
971 /* Exclude this check for some space types where the space type isn't used. */
973 ScrArea *area = CTX_wm_area(C);
974 BLI_assert(area == nullptr || area->spacetype == tkey->space_type);
975 }
976#endif
977
979 RNA_string_set(&op_props, "name", name);
980
982
983 RNA_enum_set(&op_props, "space_type", tkey->space_type);
984 RNA_boolean_set(&op_props, "cycle", cycle);
985
988
989 bToolRef *tref = WM_toolsystem_ref_find(workspace, tkey);
990
991 if (tref) {
992 Main *bmain = CTX_data_main(C);
993 toolsystem_refresh_screen_from_active_tool(bmain, workspace, tref);
994 }
995
996 return (tref && STREQ(tref->idname, name)) ? tref : nullptr;
997}
998
1000{
1001 const Main *bmain = CTX_data_main(C);
1002 const Scene *scene = CTX_data_scene(C);
1003 ViewLayer *view_layer = CTX_data_view_layer(C);
1004 ScrArea *area = CTX_wm_area(C);
1005 bToolKey tkey;
1006 if (WM_toolsystem_key_from_context(*bmain, scene, view_layer, area, &tkey)) {
1007 WorkSpace *workspace = CTX_wm_workspace(C);
1008 return WM_toolsystem_ref_set_by_id_ex(C, workspace, &tkey, name, false);
1009 }
1010 return nullptr;
1011}
1012
1013static void toolsystem_ref_set_by_brush_type(bContext *C, const char *brush_type)
1014{
1015 const Main *bmain = CTX_data_main(C);
1016 const Scene *scene = CTX_data_scene(C);
1017 ViewLayer *view_layer = CTX_data_view_layer(C);
1018 ScrArea *area = CTX_wm_area(C);
1019 const bToolKey tkey = toolsystem_key_from_context_or_view3d(*bmain, scene, view_layer, area);
1020 WorkSpace *workspace = CTX_wm_workspace(C);
1021
1022 wmOperatorType *ot = WM_operatortype_find("WM_OT_tool_set_by_brush_type", false);
1023 /* On startup, Python operators are not yet loaded. */
1024 if (ot == nullptr) {
1025 return;
1026 }
1027
1028/* Some contexts use the current space type (e.g. image editor),
1029 * ensure this is set correctly or there is no area. */
1030#ifndef NDEBUG
1031 /* Exclude this check for some space types where the space type isn't used. */
1033 ScrArea *area = CTX_wm_area(C);
1034 BLI_assert(area == nullptr || area->spacetype == tkey.space_type);
1035 }
1036#endif
1037
1039 RNA_string_set(&op_props, "brush_type", brush_type);
1040
1042
1043 RNA_enum_set(&op_props, "space_type", tkey.space_type);
1044
1046 WM_operator_properties_free(&op_props);
1047
1048 bToolRef *tref = WM_toolsystem_ref_find(workspace, &tkey);
1049
1050 if (tref) {
1051 Main *bmain = CTX_data_main(C);
1052 toolsystem_refresh_screen_from_active_tool(bmain, workspace, tref);
1053 }
1054}
1055
1064 bToolRef *tref,
1065 const char *idname_pending)
1066{
1067 BLI_assert(idname_pending[0]);
1068
1069 /* Check if the pending or current tool is already set to the requested value. */
1070 const bool this_match = STREQ(idname_pending, tref->idname);
1071 if (tref->idname_pending[0]) {
1072 const bool next_match = STREQ(idname_pending, tref->idname_pending);
1073 if (next_match) {
1074 return;
1075 }
1076 /* Highly unlikely but possible the current active tool matches the name.
1077 * In this case clear pending as there is nothing to do. */
1078 if (this_match) {
1079 tref->idname_pending[0] = '\0';
1080 return;
1081 }
1082 }
1083 else {
1084 if (this_match) {
1085 return;
1086 }
1087 }
1088
1089 STRNCPY_UTF8(tref->idname_pending, idname_pending);
1090
1091 /* If there would be a convenient way to know which screens used which work-spaces,
1092 * that could be used here. */
1093 for (bScreen &screen : bmain->screens) {
1094 for (ScrArea &area : screen.areabase) {
1095 if (area.runtime.tool == tref) {
1096 area.runtime.tool = nullptr;
1097 area.runtime.is_tool_set = false;
1099 }
1100 }
1101 }
1102}
1103
1105{
1106 bToolKey tkey{};
1107 tkey.space_type = tref->space_type;
1108 tkey.mode = tref->mode;
1109
1110 const char *idname = tref->idname_pending[0] ? tref->idname_pending : tref->idname;
1111
1112 WM_toolsystem_ref_set_by_id_ex(C, workspace, &tkey, idname, false);
1113
1114 /* Never attempt the pending name again, if it's not found, no need to keep trying. */
1115 tref->idname_pending[0] = '\0';
1116}
1117
1118static const char *toolsystem_default_tool(const bToolKey *tkey)
1119{
1120 switch (tkey->space_type) {
1121 case SPACE_VIEW3D:
1122 switch (tkey->mode) {
1123 case CTX_MODE_SCULPT:
1136 return "builtin.brush";
1137 case CTX_MODE_PARTICLE:
1138 return "builtin_brush.Comb";
1139 case CTX_MODE_EDIT_TEXT:
1140 return "builtin.select_text";
1141 }
1142 break;
1143 case SPACE_IMAGE:
1144 switch (tkey->mode) {
1145 case SI_MODE_PAINT:
1146 return "builtin.brush";
1147 case SI_MODE_VIEW:
1148 return "builtin.sample";
1149 case SI_MODE_MASK:
1150 return "builtin.select_box";
1151 }
1152 break;
1153 case SPACE_NODE: {
1154 return "builtin.select_box";
1155 }
1156 case SPACE_SEQ: {
1157 return "builtin.select_box";
1158 }
1159 }
1160
1161 return "builtin.select_box";
1162}
1163
1168 WorkSpace *workspace,
1169 const bToolKey *tkey,
1170 const char *default_tool)
1171{
1172 bToolRef *tref;
1173 if (WM_toolsystem_ref_ensure(workspace, tkey, &tref)) {
1174 if (default_tool == nullptr) {
1175 default_tool = toolsystem_default_tool(tkey);
1176 }
1177 STRNCPY_UTF8(tref->idname, default_tool);
1178 }
1179 toolsystem_reinit_with_toolref(C, workspace, tref);
1180 return tref;
1181}
1182
1184{
1185 const Main *bmain = CTX_data_main(C);
1186 const Scene *scene = CTX_data_scene(C);
1187 ViewLayer *view_layer = CTX_data_view_layer(C);
1188 int space_type = SPACE_VIEW3D;
1189 bToolKey tkey{};
1190 tkey.space_type = space_type;
1191 tkey.mode = WM_toolsystem_mode_from_spacetype(*bmain, scene, view_layer, nullptr, space_type);
1192 toolsystem_reinit_ensure_toolref(C, workspace, &tkey, nullptr);
1193}
1194
1196{
1197 WorkSpace *workspace = CTX_wm_workspace(C);
1198 if (workspace) {
1200 }
1201
1202 /* Multi window support. */
1203 Main *bmain = CTX_data_main(C);
1204 wmWindowManager *wm = bmain->wm.first();
1205 if (!wm->windows.is_single()) {
1206 wmWindow *win_prev = CTX_wm_window(C);
1207 ScrArea *area_prev = CTX_wm_area(C);
1208 ARegion *region_prev = CTX_wm_region(C);
1209
1210 for (wmWindow &win : wm->windows) {
1211 if (&win != win_prev) {
1212 WorkSpace *workspace_iter = WM_window_get_active_workspace(&win);
1213 if (workspace_iter != workspace) {
1214
1215 CTX_wm_window_set(C, &win);
1216
1218
1219 CTX_wm_window_set(C, win_prev);
1220 CTX_wm_area_set(C, area_prev);
1221 CTX_wm_region_set(C, region_prev);
1222 }
1223 }
1224 }
1225 }
1226}
1227
1229 bContext *C, WorkSpace *workspace, const Scene *scene, ViewLayer *view_layer, ScrArea *area)
1230{
1231 const Main *bmain = CTX_data_main(C);
1232 bToolKey tkey{};
1233 tkey.space_type = area->spacetype;
1234 tkey.mode = WM_toolsystem_mode_from_spacetype(*bmain, scene, view_layer, area, area->spacetype);
1235 if (toolsystem_key_ensure_check(&tkey)) {
1236 toolsystem_reinit_ensure_toolref(C, workspace, &tkey, nullptr);
1237 }
1238}
1239
1241{
1242 const bToolRef_Runtime *tref_rt = WM_toolsystem_runtime_from_context(const_cast<bContext *>(C));
1243 return tref_rt && (tref_rt->flag & TOOLREF_FLAG_USE_BRUSHES);
1244}
1245
1247{
1248 const bToolRef_Runtime *tref_rt = WM_toolsystem_runtime_from_context(const_cast<bContext *>(C));
1249 return tref_rt && (tref_rt->cursor != WM_CURSOR_DEFAULT);
1250}
1251
1253 wmMsgSubscribeKey * /*msg_key*/,
1254 wmMsgSubscribeValue *msg_val)
1255{
1256 ScrArea *area = static_cast<ScrArea *>(msg_val->user_data);
1257 Main *bmain = CTX_data_main(C);
1258 wmWindow *win = bmain->wm.first()->windows.first();
1259 if (win->next != nullptr) {
1260 do {
1261 bScreen *screen = WM_window_get_active_screen(win);
1262 if (BLI_findindex(&screen->areabase, area) != -1) {
1263 break;
1264 }
1265 } while ((win = win->next));
1266 }
1267
1268 WorkSpace *workspace = WM_window_get_active_workspace(win);
1269 const Scene *scene = WM_window_get_active_scene(win);
1270 ViewLayer *view_layer = WM_window_get_active_view_layer(win);
1271
1272 bToolKey tkey{};
1273 tkey.space_type = area->spacetype;
1274 tkey.mode = WM_toolsystem_mode_from_spacetype(*bmain, scene, view_layer, area, area->spacetype);
1275 WM_toolsystem_refresh(C, workspace, &tkey);
1276 WM_toolsystem_refresh_screen_area(*bmain, workspace, scene, view_layer, area);
1277}
1278
1279static IDProperty *idprops_ensure_named_group(IDProperty *group, const char *idname)
1280{
1281 IDProperty *prop = IDP_GetPropertyFromGroup(group, idname);
1282 if ((prop == nullptr) || (prop->type != IDP_GROUP)) {
1283 prop = bke::idprop::create_group(__func__).release();
1284 STRNCPY_UTF8(prop->name, idname);
1285 IDP_ReplaceInGroup_ex(group, prop, nullptr, 0);
1286 }
1287 return prop;
1288}
1289
1291{
1292 IDProperty *group = tref->properties;
1293 if (group == nullptr) {
1294 return nullptr;
1295 }
1296 return IDP_GetPropertyFromGroup(group, tref->idname);
1297}
1298
1300{
1301 if (tref->properties == nullptr) {
1302 tref->properties = bke::idprop::create_group(__func__).release();
1303 }
1304 return idprops_ensure_named_group(tref->properties, tref->idname);
1305}
1306
1308 const char *idname,
1309 StructRNA *type,
1310 PointerRNA *r_ptr)
1311{
1313 IDProperty *prop = group ? IDP_GetPropertyFromGroup(group, idname) : nullptr;
1314 *r_ptr = RNA_pointer_create_discrete(nullptr, type, prop);
1315 return (prop != nullptr);
1316}
1317
1319 const char *idname,
1320 StructRNA *type,
1321 PointerRNA *r_ptr)
1322{
1324 IDProperty *prop = idprops_ensure_named_group(group, idname);
1325 *r_ptr = RNA_pointer_create_discrete(nullptr, type, prop);
1326}
1327
1329 PointerRNA *dst_ptr,
1330 PointerRNA *src_ptr,
1331 wmOperatorType *ot)
1332{
1333 *dst_ptr = *src_ptr;
1334 if (*dst_ptr) {
1335 dst_ptr->data = IDP_CopyProperty(static_cast<const IDProperty *>(dst_ptr->data));
1336 }
1337 else {
1338 dst_ptr->data = bke::idprop::create_group("wmOpItemProp").release();
1339 }
1341 if (group != nullptr) {
1342 IDProperty *prop = IDP_GetPropertyFromGroup(group, ot->idname);
1343 if (prop) {
1344 /* Important key-map items properties don't get overwritten by the tools.
1345 * - When a key-map item doesn't set a property, the tool-systems is used.
1346 * - When it does, it overrides the tool-system.
1347 *
1348 * This way the default action can be to follow the top-bar tool-settings &
1349 * modifier keys can be used to perform different actions that aren't clobbered here.
1350 */
1351 IDP_MergeGroup(static_cast<IDProperty *>(dst_ptr->data), prop, false);
1352 }
1353 }
1354}
1355
1356} // namespace blender
#define SNPRINTF_UTF8(dst, format,...)
#define STRNCPY_UTF8(dst, src)
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
ID and Library types, which are fundamental for SDNA.
Object is a sort of wrapper for general info.
#define OBEDIT_FROM_OBACT(ob)
#define SPACE_TYPE_NUM
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define WM_TOOLSYSTEM_SPACE_MASK
#define WM_TOOLSYSTEM_SPACE_MASK_MODE_FROM_SPACE
#define BLI_assert_unreachable()
#define ELEM(...)
#define STREQ(a, b)
#define offsetof(t, d)
std::unique_ptr< IDProperty, IDPropertyDeleter > create_group(StringRef prop_name, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_GROUP.
std::optional< AssetWeakReference > asset_edit_weak_reference_from_id(const ID &id)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void WM_toolsystem_refresh_active(bContext *C)
ScrArea * CTX_wm_area(const bContext *C)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
std::optional< AssetWeakReference > WM_toolsystem_last_brush_asset_from_brush_type(Scene *scene, const int brush_type, const PaintMode paint_mode)
static void toolsystem_brush_activate_from_toolref(Main *bmain, const WorkSpace *workspace, const bToolRef *tref)
bool WM_gizmo_group_type_ensure_ptr(wmGizmoGroupType *gzgt)
const EnumPropertyItem rna_enum_particle_edit_hair_brush_items[]
void WM_toolsystem_refresh_all(const bContext *C, WorkSpace *workspace)
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:98
WorkSpace * CTX_wm_workspace(const bContext *C)
std::optional< AssetWeakReference > BKE_paint_brush_type_default_reference(bke::paint::AssetCategory asset_category, std::optional< int > brush_type)
void WM_operator_properties_free(PointerRNA *ptr)
int WM_toolsystem_mode_from_spacetype(const Main &bmain, const Scene *scene, ViewLayer *view_layer, ScrArea *area, int space_type)
static void toolsystem_brush_sync_for_texture_paint(Main *bmain, WorkSpace *workspace, bToolRef *tref)
void BKE_paint_previous_asset_reference_clear(Paint *paint)
bToolRef_Runtime * WM_toolsystem_runtime_find(WorkSpace *workspace, const bToolKey *tkey)
static bool toolsystem_key_ensure_check(const bToolKey *tkey)
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
IDProperty * IDP_CopyProperty(const IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:986
void CTX_wm_window_set(bContext *C, wmWindow *win)
IDProperty * IDP_GetPropertyFromGroup(const IDProperty *prop, StringRef name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:818
static void toolsystem_ref_link(Main *bmain, WorkSpace *workspace, bToolRef *tref)
bool WM_toolsystem_activate_brush_and_tool(bContext *C, Paint *paint, Brush *brush)
static bToolRef * toolsystem_reinit_ensure_toolref(bContext *C, WorkSpace *workspace, const bToolKey *tkey, const char *default_tool)
void WM_toolsystem_refresh(const bContext *C, WorkSpace *workspace, const bToolKey *tkey)
PointerRNA WM_operator_properties_create_ptr(wmOperatorType *ot)
bToolRef * WM_toolsystem_ref_find(WorkSpace *workspace, const bToolKey *tkey)
wmWindow * CTX_wm_window(const bContext *C)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
void BKE_workspace_id_tag_all_visible(Main *bmain, int tag) ATTR_NONNULL()
Definition workspace.cc:617
static void toolsystem_main_brush_binding_update_from_active(Paint *paint)
wmGizmoGroupType * WM_gizmogrouptype_find(const StringRef idname, bool quiet)
void WM_tooltip_clear(bContext *C, wmWindow *win)
Definition wm_tooltip.cc:84
@ TOOLREF_FLAG_FALLBACK_KEYMAP
ViewLayer * WM_window_get_active_view_layer(const wmWindow *win)
int RNA_enum_from_value(const EnumPropertyItem *item, const int value)
void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, bool do_overwrite) ATTR_NONNULL()
Definition idprop.cc:783
bool WM_toolsystem_key_from_context(const Main &bmain, const Scene *scene, ViewLayer *view_layer, ScrArea *area, bToolKey *tkey)
@ CTX_MODE_VERTEX_GREASE_PENCIL
@ CTX_MODE_PARTICLE
@ CTX_MODE_EDIT_TEXT
@ CTX_MODE_PAINT_VERTEX
@ CTX_MODE_VERTEX_GPENCIL_LEGACY
@ CTX_MODE_WEIGHT_GPENCIL_LEGACY
@ CTX_MODE_SCULPT_CURVES
@ CTX_MODE_SCULPT
@ CTX_MODE_PAINT_GREASE_PENCIL
@ CTX_MODE_PAINT_GPENCIL_LEGACY
@ CTX_MODE_SCULPT_GREASE_PENCIL
@ CTX_MODE_PAINT_TEXTURE
@ CTX_MODE_SCULPT_GPENCIL_LEGACY
@ CTX_MODE_OBJECT
@ CTX_MODE_WEIGHT_GREASE_PENCIL
@ CTX_MODE_PAINT_WEIGHT
ViewLayer * CTX_data_view_layer(const bContext *C)
void IDP_ReplaceInGroup_ex(IDProperty *group, IDProperty *prop, IDProperty *prop_exist, int flag)
Definition idprop.cc:716
bToolRef_Runtime * WM_toolsystem_runtime_from_context(const bContext *C)
Global G
Definition blender.cc:57
std::optional< int > BKE_paint_get_brush_type_from_paintmode(const Brush *brush, PaintMode mode)
static void toolsystem_ref_set_by_brush_type(bContext *C, const char *brush_type)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
int RNA_enum_from_identifier(const EnumPropertyItem *item, const char *identifier)
void * BLI_findstring_ptr(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:658
Scene * WM_window_get_active_scene(const wmWindow *win)
void WM_toolsystem_ref_set_from_runtime(bContext *C, WorkSpace *workspace, bToolRef *tref, const bToolRef_Runtime *tref_rt, const char *idname)
void WM_toolsystem_refresh_screen_all(Main *bmain)
IDProperty * WM_toolsystem_ref_properties_get_idprops(bToolRef *tref)
static void toolsystem_reinit_with_toolref(bContext *C, WorkSpace *, bToolRef *tref)
void WM_toolsystem_do_msg_notify_tag_refresh(bContext *C, wmMsgSubscribeKey *, wmMsgSubscribeValue *msg_val)
void WM_toolsystem_ref_properties_ensure_ex(bToolRef *tref, const char *idname, StructRNA *type, PointerRNA *r_ptr)
static void toolsystem_unlink_ref(bContext *C, WorkSpace *, bToolRef *tref)
@ OB_MODE_PARTICLE_EDIT
CLG_LogRef * WM_LOG_TOOL_GIZMO
void WM_gizmoconfig_update_tag_group_type_init(wmGizmoMapType *gzmap_type, wmGizmoGroupType *gzgt)
void WM_toolsystem_init(const bContext *C)
static const char * brush_type_identifier_get(const int brush_type, const PaintMode paint_mode)
static NamedBrushAssetReference * toolsystem_brush_type_binding_lookup(const Paint *paint, const char *brush_type_name)
static void toolsystem_brush_clear_paint_reference(Main *bmain, WorkSpace *workspace, bToolRef *tref)
PaintMode BKE_paintmode_get_from_tool(const bToolRef *tref)
void WM_toolsystem_update_from_context_view3d(bContext *C)
static bool brush_type_matches_active_tool(bContext *C, const int brush_type)
WorkSpace * WM_window_get_active_workspace(const wmWindow *win)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
bool BKE_paint_brush_set(Paint *paint, Brush *brush)
void WM_toolsystem_update_from_context(bContext *C, WorkSpace *workspace, const Scene *scene, ViewLayer *view_layer, ScrArea *area)
bToolRef * WM_toolsystem_ref_set_by_id(bContext *C, const char *name)
wmMsgBus * CTX_wm_message_bus(const bContext *C)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
static void toolsystem_brush_type_binding_update(Paint *paint, const PaintMode paint_mode, const int brush_type)
@ WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP
@ WM_GIZMOGROUPTYPE_TOOL_INIT
void WM_toolsystem_unlink(bContext *C, WorkSpace *workspace, const bToolKey *tkey)
bToolRef * WM_toolsystem_ref_set_by_id_ex(bContext *C, WorkSpace *workspace, const bToolKey *tkey, const char *name, bool cycle)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
void WM_toolsystem_ref_properties_init_for_keymap(bToolRef *tref, PointerRNA *dst_ptr, PointerRNA *src_ptr, wmOperatorType *ot)
const EnumPropertyItem * BKE_paint_get_tool_enum_from_paintmode(PaintMode mode)
static void toolsystem_reinit_ref(bContext *C, WorkSpace *workspace, bToolRef *tref)
bool WM_toolsystem_active_tool_has_custom_cursor(const bContext *C)
@ WM_CURSOR_DEFAULT
Definition wm_cursors.hh:17
bool BKE_paint_can_use_brush(const Paint *paint, const Brush *brush)
static void toolsystem_refresh_screen_from_active_tool(Main *bmain, WorkSpace *workspace, bToolRef *tref)
Main * CTX_data_main(const bContext *C)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
bToolRef * WM_toolsystem_ref_from_context(const bContext *C)
bool WM_toolsystem_active_tool_is_brush(const bContext *C)
static const bToolRef * toolsystem_active_tool_from_context_or_view3d(const bContext *C)
Paint * BKE_paint_get_active_from_paintmode(Scene *sce, PaintMode mode)
void WM_gizmo_group_remove_by_tool(bContext *C, Main *bmain, const wmGizmoGroupType *gzgt, const bToolRef *tref)
bool WM_toolsystem_refresh_screen_area(const Main &bmain, WorkSpace *workspace, const Scene *scene, ViewLayer *view_layer, ScrArea *area)
static void toolsystem_refresh_ref(const bContext *C, WorkSpace *workspace, bToolRef *tref)
wmOperatorStatus WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
void WM_toolsystem_unlink_all(bContext *C, WorkSpace *workspace)
@ ID_TAG_DOIT
Definition DNA_ID.h:1029
wmGizmoMapType * WM_gizmomaptype_ensure(const wmGizmoMapType_Params *gzmap_params)
static void toolsystem_brush_activate_from_toolref_for_object_particle(const Main *bmain, const WorkSpace *workspace, const bToolRef *tref)
void WM_toolsystem_ref_sync_from_context(Main *bmain, WorkSpace *workspace, bToolRef *tref)
static const char * toolsystem_default_tool(const bToolKey *tkey)
Scene * CTX_data_scene(const bContext *C)
void CTX_wm_region_set(bContext *C, ARegion *region)
static void toolsystem_brush_activate_from_toolref_for_object_paint(Main *bmain, const WorkSpace *workspace, const bToolRef *tref)
bool WM_toolsystem_ref_ensure(WorkSpace *workspace, const bToolKey *tkey, bToolRef **r_tref)
static bToolKey toolsystem_key_from_context_or_view3d(const Main &bmain, const Scene *scene, ViewLayer *view_layer, ScrArea *area)
IDProperty * WM_toolsystem_ref_properties_ensure_idprops(bToolRef *tref)
bool BKE_paint_ensure_from_paintmode(Scene *sce, PaintMode mode)
bScreen * WM_window_get_active_screen(const wmWindow *win)
void WM_toolsystem_reinit_all(bContext *C, wmWindow *win)
static void wm_toolsystem_update_from_context_view3d_impl(bContext *C, WorkSpace *workspace)
void WM_toolsystem_reinit(bContext *C, WorkSpace *workspace, const bToolKey *tkey)
bool WM_toolsystem_ref_properties_get_ex(bToolRef *tref, const char *idname, StructRNA *type, PointerRNA *r_ptr)
ARegion * CTX_wm_region(const bContext *C)
PaintMode BKE_paintmode_get_active_from_context(const bContext *C)
void WM_toolsystem_refresh_screen_window(const Main &bmain, wmWindow *win)
@ AREA_FLAG_ACTIVE_TOOL_UPDATE
static IDProperty * idprops_ensure_named_group(IDProperty *group, const char *idname)
static void toolsystem_ref_set_by_id_pending(Main *bmain, bToolRef *tref, const char *idname_pending)
void CTX_wm_area_set(bContext *C, ScrArea *area)
enum eContextObjectMode CTX_data_mode_enum_ex(const Object *obedit, const Object *ob, eObjectMode object_mode)
eIDPropertyType type
Definition DNA_ID.h:145
ListBaseT< wmWindowManager > wm
Definition BKE_main.hh:415
ListBaseT< WorkSpace > workspaces
Definition BKE_main.hh:423
ListBaseT< bScreen > screens
Definition BKE_main.hh:400
struct AssetWeakReference * brush_asset_reference
struct ToolSettings * toolsettings
ScrArea_Runtime runtime
ListBaseT< SpaceLink > spacedata
eSpaceImage_Mode mode
eSpaceSeq_Displays view
struct ParticleEditSettings particle
ListBaseT< bToolRef > tools
ListBaseT< struct ScrArea > areabase
ebToolRef_Runtime_Flag flag
bToolRef_Runtime * runtime
wmGizmoMapType_Params gzmap_params
eWM_GizmoFlagGroupTypeFlag flag
bool is_set(uint i)
#define WM_msg_publish_rna_prop(mbus, id_, data_, type_, prop_)