Blender V5.3
outliner_draw.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
13#include "DNA_key_types.h"
14#include "DNA_layer_types.h"
15#include "DNA_light_types.h"
17#include "DNA_object_types.h"
18#include "DNA_scene_types.h"
19#include "DNA_sequence_types.h"
20#include "DNA_text_types.h"
21
22#include "BLI_fileops.hh"
23#include "BLI_listbase.hh"
24#include "BLI_math_vector_c.hh"
25#include "BLI_path_utils.hh"
26#include "BLI_string.hh"
27#include "BLI_string_utf8.hh"
28#include "BLI_string_utils.hh"
29#include "BLI_utildefines.hh"
30
31#include "BLT_translation.hh"
32
33#include "BKE_action.hh"
34#include "BKE_annotations.h"
35#include "BKE_armature.hh"
36#include "BKE_context.hh"
37#include "BKE_curve.hh"
38#include "BKE_deform.hh"
39#include "BKE_grease_pencil.hh"
40#include "BKE_idtype.hh"
41#include "BKE_image.hh"
42#include "BKE_key.hh"
43#include "BKE_layer.hh"
44#include "BKE_lib_id.hh"
45#include "BKE_lib_override.hh"
46#include "BKE_library.hh"
47#include "BKE_main.hh"
48#include "BKE_main_namemap.hh"
49#include "BKE_modifier.hh"
50#include "BKE_node.hh"
51#include "BKE_object.hh"
52#include "BKE_particle.h"
53#include "BKE_report.hh"
54#include "BKE_scene.hh"
55
56#include "ANIM_armature.hh"
58#include "ANIM_keyframing.hh"
59
60#include "DEG_depsgraph.hh"
62
63#include "ED_armature.hh"
64#include "ED_fileselect.hh"
65#include "ED_id_management.hh"
66#include "ED_outliner.hh"
67#include "ED_screen.hh"
68#include "ED_undo.hh"
69
70#include "WM_api.hh"
71#include "WM_message.hh"
72#include "WM_types.hh"
73
74#include "GPU_immediate.hh"
75#include "GPU_state.hh"
76
77#include "UI_interface.hh"
78#include "UI_interface_icons.hh"
79#include "UI_resources.hh"
80#include "UI_view2d.hh"
81
82#include "RNA_access.hh"
83
84#include "outliner_intern.hh"
85#include "tree/tree_element.hh"
91#include "tree/tree_iterator.hh"
92
93namespace blender {
94
95namespace ed::outliner {
96
97/* -------------------------------------------------------------------- */
100
102 ListBaseT<TreeElement> *lb,
103 int *width,
104 int *height)
105{
106 for (TreeElement &te : *lb) {
107 *width = std::max(*width, int(te.xend));
108 if (height != nullptr) {
109 *height += UI_UNIT_Y;
110 }
111
112 TreeStoreElem *tselem = TREESTORE(&te);
113 if (TSELEM_OPEN(tselem, space_outliner)) {
114 outliner_tree_dimensions_impl(space_outliner, &te.subtree, width, height);
115 }
116 else {
117 outliner_tree_dimensions_impl(space_outliner, &te.subtree, width, nullptr);
118 }
119 }
120}
121
122void outliner_tree_dimensions(SpaceOutliner *space_outliner, int *r_width, int *r_height)
123{
124 *r_width = 0;
125 *r_height = 0;
126 outliner_tree_dimensions_impl(space_outliner, &space_outliner->runtime->tree, r_width, r_height);
127}
128
132static bool is_object_data_in_editmode(const ID *id, const Object *obact)
133{
134 if (id == nullptr) {
135 return false;
136 }
137
138 const short id_type = GS(id->name);
139
140 return ((obact && (obact->mode & OB_MODE_EDIT)) && (id && OB_DATA_SUPPORT_EDITMODE(id_type)) &&
141 (GS(((ID *)obact->data)->name) == id_type) && BKE_object_data_is_in_editmode(obact, id));
142}
143
145
146/* -------------------------------------------------------------------- */
149
151 EditBone *ebone_parent,
152 eBone_Flag flag,
153 bool set_flag)
154{
155 for (EditBone &ebone : *arm->edbo) {
156 if (ED_armature_ebone_is_child_recursive(ebone_parent, &ebone)) {
157 if (set_flag) {
159 ebone.flag |= flag;
160 }
161 else {
162 ebone.flag &= ~flag;
163 }
164 }
165 }
166}
167
168static void restrictbutton_recursive_bone(Bone *bone_parent, eBone_Flag flag, bool set_flag)
169{
170 for (Bone &bone : bone_parent->childbase) {
171 if (set_flag) {
173 bone.flag |= flag;
174 }
175 else {
176 bone.flag &= ~flag;
177 }
178 restrictbutton_recursive_bone(&bone, flag, set_flag);
179 }
180}
181
182static void restrictbutton_r_lay_fn(bContext *C, void *poin, void * /*poin2*/)
183{
185}
186
187static void restrictbutton_bone_visibility_fn(bContext *C, void *poin, void *poin2)
188{
189 Object *ob = static_cast<Object *>(poin);
190 bPoseChannel *pchan = static_cast<bPoseChannel *>(poin2);
191 if (CTX_wm_window(C)->runtime->eventstate->modifier & KM_SHIFT) {
192 animrig::pose_bone_descendent_iterator(*ob, *pchan, [&](bPoseChannel &descendent) {
193 if (pchan->drawflag & PCHAN_DRAW_HIDDEN) {
194 descendent.drawflag |= PCHAN_DRAW_HIDDEN;
195 }
196 else {
197 descendent.drawflag &= ~PCHAN_DRAW_HIDDEN;
198 }
199 });
200 }
201}
202
203static void restrictbutton_bone_select_fn(bContext *C, void *poin, void *poin2)
204{
205 bArmature *arm = static_cast<bArmature *>(poin);
206 Bone *bone = static_cast<Bone *>(poin2);
207
208 if (bone->flag & BONE_UNSELECTABLE) {
210 }
211
212 if (CTX_wm_window(C)->runtime->eventstate->modifier & KM_SHIFT) {
214 }
215
218}
219
220static void restrictbutton_ebone_select_fn(bContext *C, void *poin, void *poin2)
221{
222 bArmature *arm = static_cast<bArmature *>(poin);
223 EditBone *ebone = static_cast<EditBone *>(poin2);
224
225 if (ebone->flag & BONE_UNSELECTABLE) {
227 }
228
229 if (CTX_wm_window(C)->runtime->eventstate->modifier & KM_SHIFT) {
231 arm, ebone, BONE_UNSELECTABLE, (ebone->flag & BONE_UNSELECTABLE) != 0);
232 }
233
235}
236
237static void restrictbutton_ebone_visibility_fn(bContext *C, void *poin, void *poin2)
238{
239 bArmature *arm = static_cast<bArmature *>(poin);
240 EditBone *ebone = static_cast<EditBone *>(poin2);
241 if (ebone->flag & BONE_HIDDEN_A) {
243 }
244
245 if (CTX_wm_window(C)->runtime->eventstate->modifier & KM_SHIFT) {
247 }
248
250}
251
252static void restrictbutton_gp_layer_flag_fn(bContext *C, void *poin, void * /*poin2*/)
253{
254 ID *id = static_cast<ID *>(poin);
255
258}
259
261 Base *base,
262 Object *ob,
263 const char *propname)
264{
265 Main *bmain = CTX_data_main(C);
266 wmWindow *win = CTX_wm_window(C);
267 Scene *scene = CTX_data_scene(C);
268 ViewLayer *view_layer = CTX_data_view_layer(C);
269
270 bool extend = (win->runtime->eventstate->modifier & KM_SHIFT);
271
272 if (!extend) {
273 return;
274 }
275
276 /* Create PointerRNA and PropertyRNA for either Object or Base. */
277 ID *id = ob ? &ob->id : &scene->id;
278 StructRNA *struct_rna = ob ? RNA_Object : RNA_ObjectBase;
279 void *data = ob ? static_cast<void *>(ob) : static_cast<void *>(base);
280
281 PointerRNA ptr = RNA_pointer_create_discrete(id, struct_rna, data);
282 PropertyRNA *base_or_object_prop = RNA_struct_type_find_property(struct_rna, propname);
283 const bool value = RNA_property_boolean_get(&ptr, base_or_object_prop);
284
285 Object *ob_parent = ob ? ob : base->object;
286
287 for (Object *ob_iter = bmain->objects.first(); ob_iter;
288 ob_iter = static_cast<Object *>(ob_iter->id.next))
289 {
290 if (BKE_object_is_child_recursive(ob_parent, ob_iter)) {
291 if (ob) {
292 ptr = RNA_id_pointer_create(&ob_iter->id);
294 }
295 else {
296 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
297 Base *base_iter = BKE_view_layer_base_find(view_layer, ob_iter);
298 /* Child can be in a collection excluded from view-layer. */
299 if (base_iter == nullptr) {
300 continue;
301 }
302 ptr = RNA_pointer_create_discrete(&scene->id, RNA_ObjectBase, base_iter);
303 }
304 RNA_property_boolean_set(&ptr, base_or_object_prop, value);
306 C, scene, &ptr, base_or_object_prop, -1, BKE_scene_frame_get(scene), true);
307 }
308 }
309
310 /* We don't call RNA_property_update() due to performance, so we batch update them. */
311 if (ob) {
314 }
315 else {
318 }
319}
320
324static void outliner__object_set_flag_recursive_fn(bContext *C, void *poin, void *poin2)
325{
326 Object *ob = static_cast<Object *>(poin);
327 const char *propname = static_cast<const char *>(poin2);
328 outliner_object_set_flag_recursive_fn(C, nullptr, ob, propname);
329}
330
334static void outliner__base_set_flag_recursive_fn(bContext *C, void *poin, void *poin2)
335{
336 Base *base = static_cast<Base *>(poin);
337 const char *propname = static_cast<const char *>(poin2);
338 outliner_object_set_flag_recursive_fn(C, base, nullptr, propname);
339}
340
343 LayerCollection *layer_collection,
344 Collection *collection,
345 PointerRNA *ptr)
346{
347 if (collection) {
348 *ptr = RNA_id_pointer_create(&collection->id);
349 }
350 else {
351 *ptr = RNA_pointer_create_discrete(&scene->id, RNA_LayerCollection, layer_collection);
352 }
353}
354
357 Scene *scene,
358 ViewLayer *view_layer,
359 Collection *collection,
360 Object *ob,
361 PointerRNA *ptr)
362{
363 if (collection) {
364 *ptr = RNA_id_pointer_create(&ob->id);
365 }
366 else {
367 BKE_view_layer_synced_ensure(bmain, scene, view_layer);
368 Base *base = BKE_view_layer_base_find(view_layer, ob);
369 *ptr = RNA_pointer_create_discrete(&scene->id, RNA_ObjectBase, base);
370 }
371}
372
373/* NOTE: Collection is only valid when we want to change the collection data, otherwise we get it
374 * from layer collection. Layer collection is valid whenever we are looking at a view layer. */
376 Scene *scene,
377 ViewLayer *view_layer,
378 LayerCollection *layer_collection,
379 Collection *collection,
380 PropertyRNA *layer_or_collection_prop,
381 PropertyRNA *base_or_object_prop,
382 const bool value)
383{
384 if (!layer_collection) {
385 return;
386 }
387
388 PointerRNA ptr;
389 outliner_layer_or_collection_pointer_create(scene, layer_collection, collection, &ptr);
390 if (layer_or_collection_prop && !RNA_property_editable(&ptr, layer_or_collection_prop)) {
391 return;
392 }
393
394 RNA_property_boolean_set(&ptr, layer_or_collection_prop, value);
395
396 /* Set the same flag for the nested objects as well. */
397 if (base_or_object_prop && !(layer_collection->flag & LAYER_COLLECTION_EXCLUDE)) {
398 /* NOTE: We can't use BKE_collection_object_cache_get()
399 * otherwise we would not take collection exclusion into account. */
400 for (CollectionObject &cob : layer_collection->collection->gobject) {
401
402 outliner_base_or_object_pointer_create(bmain, scene, view_layer, collection, cob.ob, &ptr);
403 if (!RNA_property_editable(&ptr, base_or_object_prop)) {
404 continue;
405 }
406
407 RNA_property_boolean_set(&ptr, base_or_object_prop, value);
408
409 if (collection) {
411 }
412 }
413 }
414
415 /* Keep going recursively. */
416 if (layer_collection) {
417 for (LayerCollection &layer_collection_iter : layer_collection->layer_collections) {
419 scene,
420 view_layer,
421 &layer_collection_iter,
422 collection ? layer_collection_iter.collection :
423 nullptr,
424 layer_or_collection_prop,
425 base_or_object_prop,
426 value);
427 }
428 }
429 else {
430 for (CollectionChild &child : collection->children) {
432 scene,
433 view_layer,
434 nullptr,
435 child.collection,
436 layer_or_collection_prop,
437 base_or_object_prop,
438 value);
439 }
440 }
441
442 if (collection) {
444 }
445}
446
458 const LayerCollection *layer_collection_cmp,
459 const Collection *collection_cmp,
460 const bool value_cmp,
461 PropertyRNA *layer_or_collection_prop,
462 LayerCollection *layer_collection,
463 Collection *collection)
464{
465 PointerRNA ptr;
466 outliner_layer_or_collection_pointer_create(scene, layer_collection, collection, &ptr);
467 const bool value = RNA_property_boolean_get(&ptr, layer_or_collection_prop);
468 Collection *collection_ensure = collection ? collection : layer_collection->collection;
469 const Collection *collection_ensure_cmp = collection_cmp ? collection_cmp :
470 layer_collection_cmp->collection;
471
472 /* Exclude linked collections, otherwise toggling property won't reset the visibility for
473 * editable collections, see: #130579. */
474 if (layer_or_collection_prop && !RNA_property_editable(&ptr, layer_or_collection_prop)) {
475 return true;
476 }
477
478 if (collection_ensure->flag & COLLECTION_IS_MASTER) {
479 }
480 else if (collection_ensure == collection_ensure_cmp) {
481 }
482 else if (BKE_collection_has_collection(collection_ensure,
483 const_cast<Collection *>(collection_ensure_cmp)) ||
484 BKE_collection_has_collection(const_cast<Collection *>(collection_ensure_cmp),
485 collection_ensure))
486 {
487 /* This collection is either a parent or a child of the collection.
488 * We expect it to be set "visible" already. */
489 if (value != value_cmp) {
490 return false;
491 }
492 }
493 else {
494 /* This collection is neither a parent nor a child of the collection.
495 * We expect it to be "invisible". */
496 if (value == value_cmp) {
497 return false;
498 }
499 }
500
501 /* Keep going recursively. */
502 if (layer_collection) {
503 for (LayerCollection &layer_collection_iter : layer_collection->layer_collections) {
504 if (layer_collection_iter.flag & LAYER_COLLECTION_EXCLUDE) {
505 continue;
506 }
508 layer_collection_cmp,
509 collection_cmp,
510 value_cmp,
511 layer_or_collection_prop,
512 &layer_collection_iter,
513 collection ? layer_collection_iter.collection :
514 nullptr))
515 {
516 return false;
517 }
518 }
519 }
520 else {
521 for (CollectionChild &child : collection->children) {
523 layer_collection_cmp,
524 collection_cmp,
525 value_cmp,
526 layer_or_collection_prop,
527 nullptr,
528 child.collection))
529 {
530 return false;
531 }
532 }
533 }
534
535 return true;
536}
537
539 Scene *scene,
540 ViewLayer *view_layer,
541 LayerCollection *layer_collection,
542 Collection *collection,
543 PropertyRNA *layer_or_collection_prop,
544 const char *propname,
545 const bool value)
546{
547 PointerRNA ptr;
548 const bool is_hide = strstr(propname, "hide_") || STREQ(propname, "exclude");
549
550 LayerCollection *top_layer_collection = layer_collection ?
551 static_cast<LayerCollection *>(
552 view_layer->layer_collections.first_) :
553 nullptr;
554 Collection *top_collection = collection ? scene->master_collection : nullptr;
555
556 bool was_isolated = (value == is_hide);
557 was_isolated &= outliner_collection_is_isolated(scene,
558 layer_collection,
559 collection,
560 !is_hide,
561 layer_or_collection_prop,
562 top_layer_collection,
563 top_collection);
564
565 if (was_isolated) {
566 const bool default_value = RNA_property_boolean_get_default(nullptr, layer_or_collection_prop);
567 /* Make every collection go back to its default "visibility" state. */
569 scene,
570 view_layer,
571 top_layer_collection,
572 top_collection,
573 layer_or_collection_prop,
574 nullptr,
575 default_value);
576 return;
577 }
578
579 /* Make every collection "invisible". */
581 scene,
582 view_layer,
583 top_layer_collection,
584 top_collection,
585 layer_or_collection_prop,
586 nullptr,
587 is_hide);
588
589 /* Make this collection and its children collections the only "visible". */
591 scene,
592 view_layer,
593 layer_collection,
594 collection,
595 layer_or_collection_prop,
596 nullptr,
597 !is_hide);
598
599 /* Make this collection direct parents also "visible". */
600 if (layer_collection) {
601 LayerCollection *lc_parent = layer_collection;
602 for (LayerCollection &lc_iter : top_layer_collection->layer_collections) {
603 if (BKE_layer_collection_has_layer_collection(&lc_iter, layer_collection)) {
604 lc_parent = &lc_iter;
605 break;
606 }
607 }
608
609 while (lc_parent != layer_collection) {
611 scene, lc_parent, collection ? lc_parent->collection : nullptr, &ptr);
612 RNA_property_boolean_set(&ptr, layer_or_collection_prop, !is_hide);
613
614 for (LayerCollection &lc_iter : lc_parent->layer_collections) {
615 if (BKE_layer_collection_has_layer_collection(&lc_iter, layer_collection)) {
616 lc_parent = &lc_iter;
617 break;
618 }
619 }
620 }
621 }
622 else {
623 CollectionParent *parent;
624 Collection *child = collection;
625 while ((parent = child->runtime->parents.first())) {
626 if (parent->collection->flag & COLLECTION_IS_MASTER) {
627 break;
628 }
629 ptr = RNA_id_pointer_create(&parent->collection->id);
630 RNA_property_boolean_set(&ptr, layer_or_collection_prop, !is_hide);
631 child = parent->collection;
632 }
633 }
634}
635
637 LayerCollection *layer_collection,
638 Collection *collection,
639 const char *propname)
640{
641 Main *bmain = CTX_data_main(C);
642 wmWindow *win = CTX_wm_window(C);
643 Scene *scene = CTX_data_scene(C);
644 ViewLayer *view_layer = CTX_data_view_layer(C);
645
646 bool do_isolate = (win->runtime->eventstate->modifier & KM_CTRL);
647 bool extend = (win->runtime->eventstate->modifier & KM_SHIFT);
648
649 if (!ELEM(true, do_isolate, extend)) {
650 return;
651 }
652
653 /* Create PointerRNA and PropertyRNA for either Collection or LayerCollection. */
654 ID *id = collection ? &collection->id : &scene->id;
655 StructRNA *struct_rna = collection ? RNA_Collection : RNA_LayerCollection;
656 void *data = collection ? static_cast<void *>(collection) :
657 static_cast<void *>(layer_collection);
658
659 PointerRNA ptr = RNA_pointer_create_discrete(id, struct_rna, data);
660 outliner_layer_or_collection_pointer_create(scene, layer_collection, collection, &ptr);
661 PropertyRNA *layer_or_collection_prop = RNA_struct_type_find_property(struct_rna, propname);
662 const bool value = RNA_property_boolean_get(&ptr, layer_or_collection_prop);
663
664 PropertyRNA *base_or_object_prop = nullptr;
665 if (layer_collection != nullptr) {
666 /* If we are toggling Layer collections we still want to change the properties of the base
667 * or the objects. If we have a matching property, toggle it as well, it can be nullptr. */
668 struct_rna = collection ? RNA_Object : RNA_ObjectBase;
669 base_or_object_prop = RNA_struct_type_find_property(struct_rna, propname);
670 }
671
672 if (extend) {
674 scene,
675 view_layer,
676 layer_collection,
677 collection,
678 layer_or_collection_prop,
679 base_or_object_prop,
680 value);
681 }
682 else {
684 scene,
685 view_layer,
686 layer_collection,
687 collection,
688 layer_or_collection_prop,
689 propname,
690 value);
691 }
692
693 /* We don't call RNA_property_update() due to performance, so we batch update them. */
696}
697
703 void *poin,
704 void *poin2)
705{
706 LayerCollection *layer_collection = static_cast<LayerCollection *>(poin);
707 const char *propname = static_cast<const char *>(poin2);
708 outliner_collection_set_flag_recursive_fn(C, layer_collection, nullptr, propname);
709}
710
715static void view_layer__collection_set_flag_recursive_fn(bContext *C, void *poin, void *poin2)
716{
717 LayerCollection *layer_collection = static_cast<LayerCollection *>(poin);
718 const char *propname = static_cast<const char *>(poin2);
720 C, layer_collection, layer_collection->collection, propname);
721}
722
727static void scenes__collection_set_flag_recursive_fn(bContext *C, void *poin, void *poin2)
728{
729 Collection *collection = static_cast<Collection *>(poin);
730 const char *propname = static_cast<const char *>(poin2);
731 outliner_collection_set_flag_recursive_fn(C, nullptr, collection, propname);
732}
733
734static void namebutton_fn(bContext *C, TreeStoreElem *tselem, const char *oldname)
735{
736 Main *bmain = CTX_data_main(C);
737 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
739 BLI_mempool *ts = space_outliner->treestore;
740
741 const char *undo_str = nullptr;
742
743 /* Unfortunately at this point, the name of the ID has already been set to its new value. Revert
744 * it to its old name, to be able to use the generic 'rename' function for IDs.
745 *
746 * NOTE: While utterly inelegant, performances are not really a concern here, so this is an
747 * acceptable solution for now. */
748 auto id_rename_helper = [bmain, tselem, oldname]() -> bool {
749 std::string new_name = tselem->id->name + 2;
750 BLI_strncpy_utf8(tselem->id->name + 2, oldname, sizeof(tselem->id->name) - 2);
751 return ED_id_rename(*bmain, *tselem->id, new_name);
752 };
753
754 if (ts && tselem) {
755 TreeElement *te = outliner_find_tree_element(&space_outliner->runtime->tree, tselem);
756
757 if (ELEM(tselem->type, TSE_SOME_ID, TSE_LINKED_NODE_TREE)) {
758 if (id_rename_helper()) {
759 undo_str = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Rename Data-Block");
760 }
761
762 WM_msg_publish_rna_prop(mbus, tselem->id, tselem->id, ID, name);
763
764 switch (GS(tselem->id->name)) {
765 case ID_MA:
767 break;
768 case ID_TE:
770 break;
771 case ID_IM:
773 break;
774 case ID_SCE:
776 break;
777 default:
778 break;
779 }
781
782 /* Check the library target exists */
783 if (te->idcode == ID_LI) {
784 Library *lib = id_cast<Library *>(tselem->id);
785 char expanded[FILE_MAX];
786
787 BKE_library_filepath_set(bmain, lib, lib->filepath);
788
789 STRNCPY(expanded, lib->filepath);
790 BLI_path_abs(expanded, BKE_main_blendfile_path(bmain));
791 if (!BLI_exists(expanded)) {
793 RPT_ERROR,
794 "Library path '%s' does not exist, correct this before saving",
795 expanded);
796 }
797 else if (lib->id.tag & ID_TAG_MISSING) {
799 RPT_INFO,
800 "Library path '%s' is now valid, please reload the library",
801 expanded);
802 lib->id.tag &= ~ID_TAG_MISSING;
803 }
804 }
805
807 }
808 else {
809 switch (tselem->type) {
810 case TSE_DEFGROUP: {
811 Object *ob = id_cast<Object *>(tselem->id);
812 bDeformGroup *vg = static_cast<bDeformGroup *>(te->directdata);
814 WM_msg_publish_rna_prop(mbus, &ob->id, vg, VertexGroup, name);
816 undo_str = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Rename Vertex Group");
817 break;
818 }
819 case TSE_NLA_ACTION: {
820 /* The #tselem->id is a #bAction. */
821 if (id_rename_helper()) {
822 undo_str = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Rename Data-Block");
823 }
824 WM_msg_publish_rna_prop(mbus, tselem->id, tselem->id, ID, name);
826 break;
827 }
828 case TSE_NLA_TRACK: {
830 undo_str = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Rename NLA Track");
831 break;
832 }
833 case TSE_MODIFIER: {
836 undo_str = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Rename Modifier");
837
838 break;
839 }
840 case TSE_EBONE: {
841 bArmature *arm = id_cast<bArmature *>(tselem->id);
842 if (arm->edbo) {
843 EditBone *ebone = static_cast<EditBone *>(te->directdata);
844 char newname[sizeof(ebone->name)];
845
846 /* restore bone name */
847 STRNCPY_UTF8(newname, ebone->name);
848 STRNCPY_UTF8(ebone->name, oldname);
849 ED_armature_bone_rename(bmain, arm, oldname, newname);
850 WM_msg_publish_rna_prop(mbus, &arm->id, ebone, EditBone, name);
854 undo_str = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Rename Edit Bone");
855 }
856 break;
857 }
858
859 case TSE_BONE: {
860 TreeViewContext tvc;
862
863 bArmature *arm = id_cast<bArmature *>(tselem->id);
864 Bone *bone = static_cast<Bone *>(te->directdata);
865 char newname[sizeof(bone->name)];
866
867 /* always make current object active */
869
870 /* restore bone name */
871 STRNCPY_UTF8(newname, bone->name);
872 STRNCPY_UTF8(bone->name, oldname);
873 ED_armature_bone_rename(bmain, arm, oldname, newname);
874 WM_msg_publish_rna_prop(mbus, &arm->id, bone, Bone, name);
878 undo_str = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Rename Bone");
879 break;
880 }
881 case TSE_POSE_CHANNEL: {
882 TreeViewContext tvc;
884
885 Object *ob = id_cast<Object *>(tselem->id);
886 bArmature *arm = id_cast<bArmature *>(ob->data);
887 bPoseChannel *pchan = static_cast<bPoseChannel *>(te->directdata);
888 char newname[sizeof(pchan->name)];
889
890 /* always make current pose-bone active */
892
894
895 /* restore bone name */
896 STRNCPY_UTF8(newname, pchan->name);
897 STRNCPY_UTF8(pchan->name, oldname);
898 ED_armature_bone_rename(bmain, id_cast<bArmature *>(ob->data), oldname, newname);
899 WM_msg_publish_rna_prop(mbus, &arm->id, pchan->bone_get(*ob), Bone, name);
904 undo_str = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Rename Pose Bone");
905 break;
906 }
907 case TSE_GP_LAYER: {
908 bGPdata *gpd = id_cast<bGPdata *>(tselem->id); /* id = GP Datablock */
909 bGPDlayer *gpl = static_cast<bGPDlayer *>(te->directdata);
910
911 /* always make layer active */
913
914 /* XXX: name needs translation stuff. */
916 &gpd->layers, gpl, "GP Layer", '.', offsetof(bGPDlayer, info), sizeof(gpl->info));
917
918 WM_msg_publish_rna_prop(mbus, &gpd->id, gpl, AnnotationLayer, info);
922 undo_str = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Rename Annotation Layer");
923 break;
924 }
926 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(tselem->id);
929
930 /* The node already has the new name set. To properly rename the node, we need to first
931 * store the new name, restore the old name in the node, and then call the rename
932 * function. */
933 std::string new_name(node.name());
934 node.set_name(oldname);
935 grease_pencil.rename_node(*bmain, node, new_name);
938 undo_str = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Rename Grease Pencil Drawing");
939 break;
940 }
941 case TSE_R_LAYER: {
942 Scene *scene = id_cast<Scene *>(tselem->id);
943 ViewLayer *view_layer = static_cast<ViewLayer *>(te->directdata);
944
945 /* Restore old name. */
946 char newname[sizeof(view_layer->name)];
947 STRNCPY_UTF8(newname, view_layer->name);
948 STRNCPY_UTF8(view_layer->name, oldname);
949
950 /* Rename, preserving animation and compositing data. */
951 BKE_view_layer_rename(bmain, scene, view_layer, newname);
952 WM_msg_publish_rna_prop(mbus, &scene->id, view_layer, ViewLayer, name);
955 undo_str = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Rename View Layer");
956 break;
957 }
959 /* The #tselem->id is a #Collection, not a #LayerCollection */
960 if (id_rename_helper()) {
961 undo_str = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Rename Data-Block");
962 }
963 WM_msg_publish_rna_prop(mbus, tselem->id, tselem->id, ID, name);
966 break;
967 }
968
969 case TSE_BONE_COLLECTION: {
970 bArmature *arm = id_cast<bArmature *>(tselem->id);
971 BoneCollection *bcoll = static_cast<BoneCollection *>(te->directdata);
972
973 ANIM_armature_bonecoll_name_set(*bmain, arm, bcoll, bcoll->name);
974 WM_msg_publish_rna_prop(mbus, &arm->id, bcoll, BoneCollection, name);
977 undo_str = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Rename Bone Collection");
978 break;
979 }
980
981 case TSE_ACTION_SLOT: {
983 undo_str = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Rename Action Slot");
984 break;
985 }
986 case TSE_SHAPE_KEY_BLOCK: {
987 Key *key = id_cast<Key *>(tselem->id);
988 KeyBlock *keyblock = static_cast<KeyBlock *>(te->directdata);
989 /* Outliner renaming already sets the new name to the KeyBlock. Restore the old name
990 * before calling rename function which will ensure unique name. */
991 char newname[sizeof(keyblock->name)];
992 STRNCPY_UTF8(newname, keyblock->name);
993 STRNCPY_UTF8(keyblock->name, oldname);
994 BKE_keyblock_rename(*bmain, key, keyblock, newname);
997 undo_str = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Rename Shape Key");
998 break;
999 }
1000 default:
1001 break;
1002 }
1003 }
1004 tselem->flag &= ~TSE_TEXTBUT;
1005 }
1006
1007 if (undo_str) {
1008 ED_undo_push(C, undo_str);
1009 }
1010}
1011
1025
1026/* We don't care about the value of the property
1027 * but whether the property should be active or grayed out. */
1047
1049 PointerRNA *collection_ptr, RestrictProperties *props, RestrictPropertiesActive *props_active)
1050{
1051 if (props_active->collection_hide_render) {
1053 collection_ptr, props->collection_hide_render);
1054 if (!props_active->collection_hide_render) {
1055 props_active->layer_collection_holdout = false;
1056 props_active->layer_collection_indirect_only = false;
1057 props_active->object_hide_render = false;
1058 props_active->modifier_show_render = false;
1059 props_active->constraint_enable = false;
1060 }
1061 }
1062
1063 if (props_active->collection_hide_viewport) {
1065 collection_ptr, props->collection_hide_viewport);
1066 if (!props_active->collection_hide_viewport) {
1067 props_active->collection_hide_select = false;
1068 props_active->object_hide_select = false;
1069 props_active->layer_collection_hide_viewport = false;
1070 props_active->object_hide_viewport = false;
1071 props_active->base_hide_viewport = false;
1072 props_active->modifier_show_viewport = false;
1073 props_active->constraint_enable = false;
1074 }
1075 }
1076
1077 if (props_active->collection_hide_select) {
1079 collection_ptr, props->collection_hide_select);
1080 if (!props_active->collection_hide_select) {
1081 props_active->object_hide_select = false;
1082 }
1083 }
1084}
1085
1087 PointerRNA *layer_collection_ptr,
1088 PointerRNA *collection_ptr,
1089 RestrictProperties *props,
1090 RestrictPropertiesActive *props_active)
1091{
1092 /* Inherit from parent. */
1093 props_active->layer_collection_holdout = props_active->object_holdout;
1094 props_active->layer_collection_indirect_only = props_active->object_indirect_only;
1095
1096 outliner_restrict_properties_enable_collection_set(collection_ptr, props, props_active);
1097
1098 if (props_active->layer_collection_hide_viewport) {
1100 layer_collection_ptr, props->layer_collection_hide_viewport);
1101
1102 if (!props_active->layer_collection_hide_viewport) {
1103 props_active->base_hide_viewport = false;
1104 props_active->collection_hide_select = false;
1105 props_active->object_hide_select = false;
1106 }
1107 }
1108
1109 if (props_active->layer_collection_exclude) {
1111 layer_collection_ptr, props->layer_collection_exclude);
1112
1113 if (!props_active->layer_collection_exclude) {
1114 props_active->collection_hide_viewport = false;
1115 props_active->collection_hide_select = false;
1116 props_active->collection_hide_render = false;
1117 props_active->layer_collection_hide_viewport = false;
1118 props_active->layer_collection_holdout = false;
1119 props_active->layer_collection_indirect_only = false;
1120 }
1121 }
1122
1123 /* Gray out properties overridden by parent collection. */
1124 const bool holdout = RNA_property_boolean_get(layer_collection_ptr,
1126 const bool indirect_only = RNA_property_boolean_get(layer_collection_ptr,
1128
1129 if (holdout) {
1130 /* Indirect only has no effect in rendering when holdout is enabled. */
1131 props_active->layer_collection_indirect_only = false;
1132 }
1133
1134 props_active->object_holdout = props_active->layer_collection_holdout && !holdout;
1135 props_active->object_indirect_only = props_active->layer_collection_indirect_only &&
1136 !indirect_only;
1137}
1138
1140 TreeElement *te,
1141 PointerRNA *collection_ptr,
1142 PointerRNA *layer_collection_ptr,
1143 RestrictProperties *props,
1144 RestrictPropertiesActive *props_active)
1145{
1146 TreeStoreElem *tselem = TREESTORE(te);
1147 LayerCollection *layer_collection = (tselem->type == TSE_LAYER_COLLECTION) ?
1148 static_cast<LayerCollection *>(te->directdata) :
1149 nullptr;
1151
1152 if (collection->flag & COLLECTION_IS_MASTER) {
1153 return false;
1154 }
1155
1156 /* Create the PointerRNA. */
1157 *collection_ptr = RNA_id_pointer_create(&collection->id);
1158 if (layer_collection != nullptr) {
1159 *layer_collection_ptr = RNA_pointer_create_discrete(
1160 &scene->id, RNA_LayerCollection, layer_collection);
1161 }
1162
1163 /* Update the restriction column values for the collection children. */
1164 if (layer_collection) {
1166 layer_collection_ptr, collection_ptr, props, props_active);
1167 }
1168 else {
1169 outliner_restrict_properties_enable_collection_set(collection_ptr, props, props_active);
1170 }
1171 return true;
1172}
1173
1175 const Main &bmain,
1176 Scene *scene,
1177 ViewLayer *view_layer,
1178 ARegion *region,
1179 SpaceOutliner *space_outliner,
1180 ListBaseT<TreeElement> *lb,
1181 RestrictPropertiesActive props_active_parent)
1182{
1183 /* Get RNA properties (once for speed). */
1184 static RestrictProperties props = {false};
1185 if (!props.initialized) {
1186 props.object_hide_viewport = RNA_struct_type_find_property(RNA_Object, "hide_viewport");
1187 props.object_hide_select = RNA_struct_type_find_property(RNA_Object, "hide_select");
1188 props.object_hide_render = RNA_struct_type_find_property(RNA_Object, "hide_render");
1189 props.object_holdout = RNA_struct_type_find_property(RNA_Object, "is_holdout");
1190 props.object_indirect_only = RNA_struct_type_find_property(RNA_Object, "visible_camera");
1191 props.base_hide_viewport = RNA_struct_type_find_property(RNA_ObjectBase, "hide_viewport");
1193 "hide_viewport");
1194 props.collection_hide_select = RNA_struct_type_find_property(RNA_Collection, "hide_select");
1195 props.collection_hide_render = RNA_struct_type_find_property(RNA_Collection, "hide_render");
1196 props.layer_collection_exclude = RNA_struct_type_find_property(RNA_LayerCollection, "exclude");
1197 props.layer_collection_holdout = RNA_struct_type_find_property(RNA_LayerCollection, "holdout");
1199 "indirect_only");
1201 "hide_viewport");
1202 props.modifier_show_viewport = RNA_struct_type_find_property(RNA_Modifier, "show_viewport");
1203 props.modifier_show_render = RNA_struct_type_find_property(RNA_Modifier, "show_render");
1204
1205 props.constraint_enable = RNA_struct_type_find_property(RNA_Constraint, "enabled");
1206
1207 props.bone_hide_viewport = RNA_struct_type_find_property(RNA_PoseBone, "hide");
1208
1209 props.initialized = true;
1210 }
1211
1212 struct {
1213 int enable;
1214 int select;
1215 int hide;
1216 int viewport;
1217 int render;
1218 int indirect_only;
1219 int holdout;
1220 } restrict_offsets = {0};
1221 int restrict_column_offset = 0;
1222
1223 /* This will determine the order of drawing from RIGHT to LEFT. */
1224 if (ELEM(space_outliner->outlinevis, SO_VIEW_LAYER, SO_SCENES)) {
1225 /* Users column is the rightmost in both View Layer and Scenes; reserve its slot. */
1226 if (space_outliner->flag & SO_USERS_COLUMN) {
1227 restrict_column_offset++;
1228 }
1229 }
1230 if (space_outliner->outlinevis == SO_VIEW_LAYER) {
1231 if (space_outliner->show_restrict_flags & SO_RESTRICT_INDIRECT_ONLY) {
1232 restrict_offsets.indirect_only = (++restrict_column_offset) * UI_UNIT_X + V2D_SCROLL_WIDTH;
1233 }
1234 if (space_outliner->show_restrict_flags & SO_RESTRICT_HOLDOUT) {
1235 restrict_offsets.holdout = (++restrict_column_offset) * UI_UNIT_X + V2D_SCROLL_WIDTH;
1236 }
1237 }
1238 if (space_outliner->show_restrict_flags & SO_RESTRICT_RENDER) {
1239 restrict_offsets.render = (++restrict_column_offset) * UI_UNIT_X + V2D_SCROLL_WIDTH;
1240 }
1241 if (space_outliner->show_restrict_flags & SO_RESTRICT_VIEWPORT) {
1242 restrict_offsets.viewport = (++restrict_column_offset) * UI_UNIT_X + V2D_SCROLL_WIDTH;
1243 }
1244 if (space_outliner->show_restrict_flags & SO_RESTRICT_HIDE) {
1245 restrict_offsets.hide = (++restrict_column_offset) * UI_UNIT_X + V2D_SCROLL_WIDTH;
1246 }
1247 if (space_outliner->show_restrict_flags & SO_RESTRICT_SELECT) {
1248 restrict_offsets.select = (++restrict_column_offset) * UI_UNIT_X + V2D_SCROLL_WIDTH;
1249 }
1250 if (space_outliner->outlinevis == SO_VIEW_LAYER &&
1251 space_outliner->show_restrict_flags & SO_RESTRICT_ENABLE)
1252 {
1253 restrict_offsets.enable = (++restrict_column_offset) * UI_UNIT_X + V2D_SCROLL_WIDTH;
1254 }
1255
1256 BLI_assert((restrict_column_offset * UI_UNIT_X + V2D_SCROLL_WIDTH) ==
1257 outliner_right_columns_width(space_outliner));
1258
1259 /* Create buttons. */
1260 ui::Button *bt;
1261
1262 for (TreeElement &te : *lb) {
1263 TreeStoreElem *tselem = TREESTORE(&te);
1264 RestrictPropertiesActive props_active = props_active_parent;
1265
1266 if (te.ys + 2 * UI_UNIT_Y >= region->v2d.cur.ymin && te.ys <= region->v2d.cur.ymax) {
1267 if (tselem->type == TSE_R_LAYER &&
1268 ELEM(space_outliner->outlinevis, SO_SCENES, SO_VIEW_LAYER))
1269 {
1270 if (space_outliner->show_restrict_flags & SO_RESTRICT_RENDER) {
1271 /* View layer render toggle. */
1272 ViewLayer *layer = static_cast<ViewLayer *>(te.directdata);
1273
1274 bt = uiDefIconButBit(block,
1277 ICON_RESTRICT_RENDER_OFF,
1278 int(region->v2d.cur.xmax - restrict_offsets.render),
1279 te.ys,
1280 UI_UNIT_X,
1281 UI_UNIT_Y,
1282 &layer->flag,
1283 0,
1284 0,
1285 TIP_("Use view layer for rendering"));
1286 button_func_set(bt, restrictbutton_r_lay_fn, tselem->id, nullptr);
1287 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1288 button_drawflag_enable(bt, ui::BUT_ICON_REVERSE);
1289 }
1290 }
1291 else if (((tselem->type == TSE_SOME_ID) && (te.idcode == ID_OB)) &&
1292 (te.flag & TE_CHILD_NOT_IN_COLLECTION))
1293 {
1294 /* Don't show restrict columns for children that are not directly inside the collection. */
1295 }
1296 else if ((tselem->type == TSE_SOME_ID) && (te.idcode == ID_OB)) {
1297 Object *ob = id_cast<Object *>(tselem->id);
1299
1300 if (space_outliner->show_restrict_flags & SO_RESTRICT_HIDE) {
1301 BKE_view_layer_synced_ensure(bmain, scene, view_layer);
1302 Base *base = (te.directdata) ? static_cast<Base *>(te.directdata) :
1303 BKE_view_layer_base_find(view_layer, ob);
1304 if (base) {
1305 PointerRNA base_ptr = RNA_pointer_create_discrete(&scene->id, RNA_ObjectBase, base);
1306 bt = uiDefIconButR_prop(block,
1308 ICON_NONE,
1309 int(region->v2d.cur.xmax - restrict_offsets.hide),
1310 te.ys,
1311 UI_UNIT_X,
1312 UI_UNIT_Y,
1313 &base_ptr,
1314 props.base_hide_viewport,
1315 -1,
1316 0,
1317 0,
1318 TIP_("Temporarily hide in viewport\n"
1319 " \u2022 Shift to set children"));
1320 button_func_set(
1321 bt, outliner__base_set_flag_recursive_fn, base, (void *)"hide_viewport");
1322 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1323 if (!props_active.base_hide_viewport) {
1324 button_flag_enable(bt, ui::BUT_INACTIVE);
1325 }
1326 }
1327 }
1328
1329 if (space_outliner->show_restrict_flags & SO_RESTRICT_SELECT) {
1330 bt = uiDefIconButR_prop(block,
1332 ICON_NONE,
1333 int(region->v2d.cur.xmax - restrict_offsets.select),
1334 te.ys,
1335 UI_UNIT_X,
1336 UI_UNIT_Y,
1337 &ptr,
1338 props.object_hide_select,
1339 -1,
1340 0,
1341 0,
1342 TIP_("Disable selection in viewport\n"
1343 " \u2022 Shift to set children"));
1344 button_func_set(
1345 bt, outliner__object_set_flag_recursive_fn, ob, const_cast<char *>("hide_select"));
1346 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1347 if (!props_active.object_hide_select) {
1348 button_flag_enable(bt, ui::BUT_INACTIVE);
1349 }
1350 }
1351
1352 if (space_outliner->show_restrict_flags & SO_RESTRICT_VIEWPORT) {
1353 bt = uiDefIconButR_prop(block,
1355 ICON_NONE,
1356 int(region->v2d.cur.xmax - restrict_offsets.viewport),
1357 te.ys,
1358 UI_UNIT_X,
1359 UI_UNIT_Y,
1360 &ptr,
1362 -1,
1363 0,
1364 0,
1365 TIP_("Globally disable in viewports\n"
1366 " \u2022 Shift to set children"));
1367 button_func_set(bt, outliner__object_set_flag_recursive_fn, ob, (void *)"hide_viewport");
1368 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1369 if (!props_active.object_hide_viewport) {
1370 button_flag_enable(bt, ui::BUT_INACTIVE);
1371 }
1372 }
1373
1374 if (space_outliner->show_restrict_flags & SO_RESTRICT_RENDER) {
1375 bt = uiDefIconButR_prop(block,
1377 ICON_NONE,
1378 int(region->v2d.cur.xmax - restrict_offsets.render),
1379 te.ys,
1380 UI_UNIT_X,
1381 UI_UNIT_Y,
1382 &ptr,
1383 props.object_hide_render,
1384 -1,
1385 0,
1386 0,
1387 TIP_("Globally disable in renders\n"
1388 " \u2022 Shift to set children"));
1389 button_func_set(
1390 bt, outliner__object_set_flag_recursive_fn, ob, const_cast<char *>("hide_render"));
1391 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1392 if (!props_active.object_hide_render) {
1393 button_flag_enable(bt, ui::BUT_INACTIVE);
1394 }
1395 }
1396
1397 if (space_outliner->outlinevis == SO_VIEW_LAYER) {
1398 if (space_outliner->show_restrict_flags & SO_RESTRICT_HOLDOUT) {
1399 bt = uiDefIconButR_prop(block,
1401 ICON_NONE,
1402 int(region->v2d.cur.xmax - restrict_offsets.holdout),
1403 te.ys,
1404 UI_UNIT_X,
1405 UI_UNIT_Y,
1406 &ptr,
1407 props.object_holdout,
1408 -1,
1409 0,
1410 0,
1411 TIP_("Render object as holdout\n"
1412 " \u2022 Shift to set children"));
1413 button_func_set(
1414 bt, outliner__object_set_flag_recursive_fn, ob, const_cast<char *>("is_holdout"));
1415 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1416 if (!props_active.object_holdout) {
1417 button_flag_enable(bt, ui::BUT_INACTIVE);
1418 }
1419 }
1420 if (space_outliner->show_restrict_flags & SO_RESTRICT_INDIRECT_ONLY) {
1421 if (OB_TYPE_IS_GEOMETRY(ob->type) && ob->type != OB_GREASE_PENCIL) {
1422 bt = uiDefIconButR_prop(block,
1424 ICON_NONE,
1425 int(region->v2d.cur.xmax - restrict_offsets.indirect_only),
1426 te.ys,
1427 UI_UNIT_X,
1428 UI_UNIT_Y,
1429 &ptr,
1431 -1,
1432 0,
1433 0,
1434 TIP_("Object will contribute indirectly as shadows\n"
1435 " \u2022 Shift to set children"));
1436 button_func_set(bt,
1438 ob,
1439 const_cast<char *>("visible_camera"));
1440 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1441 if (!props_active.object_indirect_only ||
1443 {
1444 button_flag_enable(bt, ui::BUT_INACTIVE);
1445 }
1446 }
1447 }
1448 }
1449 }
1450 else if (tselem->type == TSE_CONSTRAINT) {
1451 bConstraint *con = static_cast<bConstraint *>(te.directdata);
1452
1453 PointerRNA ptr = RNA_pointer_create_discrete(tselem->id, RNA_Constraint, con);
1454
1455 if (space_outliner->show_restrict_flags & SO_RESTRICT_HIDE) {
1456 bt = uiDefIconButR_prop(block,
1458 ICON_NONE,
1459 int(region->v2d.cur.xmax - restrict_offsets.hide),
1460 te.ys,
1461 UI_UNIT_X,
1462 UI_UNIT_Y,
1463 &ptr,
1464 props.constraint_enable,
1465 -1,
1466 0,
1467 0,
1468 nullptr);
1469 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1470 if (!props_active.constraint_enable) {
1471 button_flag_enable(bt, ui::BUT_INACTIVE);
1472 }
1473 }
1474 }
1475 else if (tselem->type == TSE_MODIFIER) {
1476 ModifierData *md = static_cast<ModifierData *>(te.directdata);
1477
1478 PointerRNA ptr = RNA_pointer_create_discrete(tselem->id, RNA_Modifier, md);
1479
1480 if (space_outliner->show_restrict_flags & SO_RESTRICT_VIEWPORT) {
1481 bt = uiDefIconButR_prop(block,
1483 ICON_NONE,
1484 int(region->v2d.cur.xmax - restrict_offsets.viewport),
1485 te.ys,
1486 UI_UNIT_X,
1487 UI_UNIT_Y,
1488 &ptr,
1490 -1,
1491 0,
1492 0,
1493 std::nullopt);
1494 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1495 if (!props_active.modifier_show_viewport) {
1496 button_flag_enable(bt, ui::BUT_INACTIVE);
1497 }
1498 }
1499
1500 if (space_outliner->show_restrict_flags & SO_RESTRICT_RENDER) {
1501 bt = uiDefIconButR_prop(block,
1503 ICON_NONE,
1504 int(region->v2d.cur.xmax - restrict_offsets.render),
1505 te.ys,
1506 UI_UNIT_X,
1507 UI_UNIT_Y,
1508 &ptr,
1510 -1,
1511 0,
1512 0,
1513 std::nullopt);
1514 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1515 if (!props_active.modifier_show_render) {
1516 button_flag_enable(bt, ui::BUT_INACTIVE);
1517 }
1518 }
1519 }
1520 else if (tselem->type == TSE_POSE_CHANNEL) {
1521 bPoseChannel *pchan = static_cast<bPoseChannel *>(te.directdata);
1522 Object *ob = id_cast<Object *>(tselem->id);
1523 bArmature *arm = id_cast<bArmature *>(ob->data);
1524
1525 PointerRNA ptr = RNA_pointer_create_discrete(&arm->id, RNA_PoseBone, pchan);
1526
1527 if (space_outliner->show_restrict_flags & SO_RESTRICT_VIEWPORT) {
1528 bt = uiDefIconButR_prop(block,
1530 ICON_NONE,
1531 int(region->v2d.cur.xmax - restrict_offsets.viewport),
1532 te.ys,
1533 UI_UNIT_X,
1534 UI_UNIT_Y,
1535 &ptr,
1536 props.bone_hide_viewport,
1537 -1,
1538 0,
1539 0,
1540 TIP_("Restrict visibility in the 3D View\n"
1541 " \u2022 Shift to set children"));
1542 button_func_set(bt, restrictbutton_bone_visibility_fn, ob, pchan);
1543 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1544 button_drawflag_enable(bt, ui::BUT_ICON_REVERSE);
1545 }
1546
1547 if (space_outliner->show_restrict_flags & SO_RESTRICT_SELECT) {
1548 Bone *bone = pchan->bone_get(*ob);
1549 bt = uiDefIconButBit(block,
1552 ICON_RESTRICT_SELECT_OFF,
1553 int(region->v2d.cur.xmax - restrict_offsets.select),
1554 te.ys,
1555 UI_UNIT_X,
1556 UI_UNIT_Y,
1557 &bone->flag,
1558 0,
1559 0,
1560 TIP_("Restrict selection in the 3D View\n"
1561 " \u2022 Shift to set children"));
1562 button_func_set(bt, restrictbutton_bone_select_fn, ob->data, bone);
1563 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1564 button_drawflag_enable(bt, ui::BUT_ICON_REVERSE);
1565 }
1566 }
1567 else if (tselem->type == TSE_EBONE) {
1568 bArmature *arm = id_cast<bArmature *>(tselem->id);
1569 EditBone *ebone = static_cast<EditBone *>(te.directdata);
1570
1571 if (space_outliner->show_restrict_flags & SO_RESTRICT_VIEWPORT) {
1572 bt = uiDefIconButBit(block,
1575 ICON_RESTRICT_VIEW_OFF,
1576 int(region->v2d.cur.xmax - restrict_offsets.viewport),
1577 te.ys,
1578 UI_UNIT_X,
1579 UI_UNIT_Y,
1580 &ebone->flag,
1581 0,
1582 0,
1583 TIP_("Restrict visibility in the 3D View\n"
1584 " \u2022 Shift to set children"));
1585 button_func_set(bt, restrictbutton_ebone_visibility_fn, arm, ebone);
1586 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1587 button_drawflag_enable(bt, ui::BUT_ICON_REVERSE);
1588 }
1589
1590 if (space_outliner->show_restrict_flags & SO_RESTRICT_SELECT) {
1591 bt = uiDefIconButBit(block,
1594 ICON_RESTRICT_SELECT_OFF,
1595 int(region->v2d.cur.xmax - restrict_offsets.select),
1596 te.ys,
1597 UI_UNIT_X,
1598 UI_UNIT_Y,
1599 &ebone->flag,
1600 0,
1601 0,
1602 TIP_("Restrict selection in the 3D View\n"
1603 " \u2022 Shift to set children"));
1604 button_func_set(bt, restrictbutton_ebone_select_fn, arm, ebone);
1605 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1606 button_drawflag_enable(bt, ui::BUT_ICON_REVERSE);
1607 }
1608 }
1609 else if (tselem->type == TSE_GP_LAYER) {
1610 ID *id = tselem->id;
1611 bGPDlayer *gpl = static_cast<bGPDlayer *>(te.directdata);
1612
1613 if (space_outliner->show_restrict_flags & SO_RESTRICT_HIDE) {
1614 bt = uiDefIconButBit(block,
1617 ICON_HIDE_OFF,
1618 int(region->v2d.cur.xmax - restrict_offsets.hide),
1619 te.ys,
1620 UI_UNIT_X,
1621 UI_UNIT_Y,
1622 &gpl->flag,
1623 0,
1624 0,
1625 TIP_("Restrict visibility in the 3D View"));
1626 button_func_set(bt, restrictbutton_gp_layer_flag_fn, id, gpl);
1627 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1628 button_drawflag_enable(bt, ui::BUT_ICON_REVERSE);
1629 }
1630
1631 if (space_outliner->show_restrict_flags & SO_RESTRICT_SELECT) {
1632 bt = uiDefIconButBit(block,
1635 ICON_UNLOCKED,
1636 int(region->v2d.cur.xmax - restrict_offsets.select),
1637 te.ys,
1638 UI_UNIT_X,
1639 UI_UNIT_Y,
1640 &gpl->flag,
1641 0,
1642 0,
1643 TIP_("Restrict editing of strokes and keyframes in this layer"));
1644 button_func_set(bt, restrictbutton_gp_layer_flag_fn, id, gpl);
1645 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1646 }
1647 }
1648 else if (tselem->type == TSE_GREASE_PENCIL_NODE) {
1651 PointerRNA ptr;
1652 PropertyRNA *hide_prop;
1653 if (node.is_layer()) {
1654 ptr = RNA_pointer_create_discrete(tselem->id, RNA_GreasePencilLayer, &node);
1655 hide_prop = RNA_struct_type_find_property(RNA_GreasePencilLayer, "hide");
1656 }
1657 else if (node.is_group()) {
1658 ptr = RNA_pointer_create_discrete(tselem->id, RNA_GreasePencilLayerGroup, &node);
1659 hide_prop = RNA_struct_type_find_property(RNA_GreasePencilLayerGroup, "hide");
1660 }
1661
1662 if (space_outliner->show_restrict_flags & SO_RESTRICT_HIDE) {
1663 bt = uiDefIconButR_prop(block,
1665 0,
1666 int(region->v2d.cur.xmax - restrict_offsets.hide),
1667 te.ys,
1668 UI_UNIT_X,
1669 UI_UNIT_Y,
1670 &ptr,
1671 hide_prop,
1672 -1,
1673 0,
1674 0,
1675 std::nullopt);
1676 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1677 if (node.parent_group() && !node.parent_group()->is_visible()) {
1678 button_flag_enable(bt, ui::BUT_INACTIVE);
1679 }
1680 }
1681 }
1683 PointerRNA collection_ptr;
1684 PointerRNA layer_collection_ptr;
1685
1687 scene, &te, &collection_ptr, &layer_collection_ptr, &props, &props_active))
1688 {
1689
1690 LayerCollection *layer_collection = (tselem->type == TSE_LAYER_COLLECTION) ?
1691 static_cast<LayerCollection *>(te.directdata) :
1692 nullptr;
1694
1695 if (layer_collection != nullptr) {
1696 if (space_outliner->show_restrict_flags & SO_RESTRICT_ENABLE) {
1697 bt = uiDefIconButR_prop(block,
1699 ICON_NONE,
1700 int(region->v2d.cur.xmax) - restrict_offsets.enable,
1701 te.ys,
1702 UI_UNIT_X,
1703 UI_UNIT_Y,
1704 &layer_collection_ptr,
1706 -1,
1707 0,
1708 0,
1709 std::nullopt);
1710 button_func_set(bt,
1712 layer_collection,
1713 const_cast<char *>("exclude"));
1714 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1715 }
1716
1717 if (space_outliner->show_restrict_flags & SO_RESTRICT_HIDE) {
1718 bt = uiDefIconButR_prop(block,
1720 ICON_NONE,
1721 int(region->v2d.cur.xmax - restrict_offsets.hide),
1722 te.ys,
1723 UI_UNIT_X,
1724 UI_UNIT_Y,
1725 &layer_collection_ptr,
1727 -1,
1728 0,
1729 0,
1730 TIP_("Temporarily hide in viewport\n"
1731 " \u2022 Ctrl to isolate collection\n"
1732 " \u2022 Shift to set inside collections and objects"));
1733 button_func_set(bt,
1735 layer_collection,
1736 const_cast<char *>("hide_viewport"));
1737 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1738 if (!props_active.layer_collection_hide_viewport) {
1739 button_flag_enable(bt, ui::BUT_INACTIVE);
1740 }
1741 }
1742
1743 if (space_outliner->show_restrict_flags & SO_RESTRICT_HOLDOUT) {
1744 bt = uiDefIconButR_prop(block,
1746 ICON_NONE,
1747 int(region->v2d.cur.xmax - restrict_offsets.holdout),
1748 te.ys,
1749 UI_UNIT_X,
1750 UI_UNIT_Y,
1751 &layer_collection_ptr,
1753 -1,
1754 0,
1755 0,
1756 TIP_("Mask out objects in collection from view layer\n"
1757 " \u2022 Ctrl to isolate collection\n"
1758 " \u2022 Shift to set inside collections"));
1759 button_func_set(bt,
1761 layer_collection,
1762 const_cast<char *>("holdout"));
1763 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1764 if (!props_active.layer_collection_holdout) {
1765 button_flag_enable(bt, ui::BUT_INACTIVE);
1766 }
1767 }
1768
1769 if (space_outliner->show_restrict_flags & SO_RESTRICT_INDIRECT_ONLY) {
1770 bt = uiDefIconButR_prop(
1771 block,
1773 ICON_NONE,
1774 int(region->v2d.cur.xmax - restrict_offsets.indirect_only),
1775 te.ys,
1776 UI_UNIT_X,
1777 UI_UNIT_Y,
1778 &layer_collection_ptr,
1780 -1,
1781 0,
1782 0,
1783 TIP_("Objects in collection only contribute indirectly (through shadows and "
1784 "reflections) in the view layer\n"
1785 " \u2022 Ctrl to isolate collection\n"
1786 " \u2022 Shift to set inside collections"));
1787 button_func_set(bt,
1789 layer_collection,
1790 const_cast<char *>("indirect_only"));
1791 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1792 if (!props_active.layer_collection_indirect_only) {
1793 button_flag_enable(bt, ui::BUT_INACTIVE);
1794 }
1795 }
1796 }
1797
1798 if (space_outliner->show_restrict_flags & SO_RESTRICT_VIEWPORT) {
1799 bt = uiDefIconButR_prop(block,
1801 ICON_NONE,
1802 int(region->v2d.cur.xmax - restrict_offsets.viewport),
1803 te.ys,
1804 UI_UNIT_X,
1805 UI_UNIT_Y,
1806 &collection_ptr,
1808 -1,
1809 0,
1810 0,
1811 TIP_("Globally disable in viewports\n"
1812 " \u2022 Ctrl to isolate collection\n"
1813 " \u2022 Shift to set inside collections and objects"));
1814 if (layer_collection != nullptr) {
1815 button_func_set(bt,
1817 layer_collection,
1818 const_cast<char *>("hide_viewport"));
1819 }
1820 else {
1821 button_func_set(bt,
1823 collection,
1824 const_cast<char *>("hide_viewport"));
1825 }
1826 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1827 if (!props_active.collection_hide_viewport) {
1828 button_flag_enable(bt, ui::BUT_INACTIVE);
1829 }
1830 }
1831
1832 if (space_outliner->show_restrict_flags & SO_RESTRICT_RENDER) {
1833 bt = uiDefIconButR_prop(block,
1835 ICON_NONE,
1836 int(region->v2d.cur.xmax - restrict_offsets.render),
1837 te.ys,
1838 UI_UNIT_X,
1839 UI_UNIT_Y,
1840 &collection_ptr,
1842 -1,
1843 0,
1844 0,
1845 TIP_("Globally disable in renders\n"
1846 " \u2022 Ctrl to isolate collection\n"
1847 " \u2022 Shift to set inside collections and objects"));
1848 if (layer_collection != nullptr) {
1849 button_func_set(bt,
1851 layer_collection,
1852 const_cast<char *>("hide_render"));
1853 }
1854 else {
1855 button_func_set(bt,
1857 collection,
1858 const_cast<char *>("hide_render"));
1859 }
1860 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1861 if (!props_active.collection_hide_render) {
1862 button_flag_enable(bt, ui::BUT_INACTIVE);
1863 }
1864 }
1865
1866 if (space_outliner->show_restrict_flags & SO_RESTRICT_SELECT) {
1867 bt = uiDefIconButR_prop(block,
1869 ICON_NONE,
1870 int(region->v2d.cur.xmax - restrict_offsets.select),
1871 te.ys,
1872 UI_UNIT_X,
1873 UI_UNIT_Y,
1874 &collection_ptr,
1876 -1,
1877 0,
1878 0,
1879 TIP_("Disable selection in viewport\n"
1880 " \u2022 Ctrl to isolate collection\n"
1881 " \u2022 Shift to set inside collections and objects"));
1882 if (layer_collection != nullptr) {
1883 button_func_set(bt,
1885 layer_collection,
1886 const_cast<char *>("hide_select"));
1887 }
1888 else {
1889 button_func_set(bt,
1891 collection,
1892 const_cast<char *>("hide_select"));
1893 }
1894 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
1895 if (!props_active.collection_hide_select) {
1896 button_flag_enable(bt, ui::BUT_INACTIVE);
1897 }
1898 }
1899 }
1900 }
1901 }
1903 PointerRNA collection_ptr;
1904 PointerRNA layer_collection_ptr;
1906 scene, &te, &collection_ptr, &layer_collection_ptr, &props, &props_active);
1907 }
1908
1909 if (TSELEM_OPEN(tselem, space_outliner)) {
1911 block, bmain, scene, view_layer, region, space_outliner, &te.subtree, props_active);
1912 }
1913 }
1914}
1915
1921
1922static std::string user_tooltip_func(bContext * /*C*/, void *argN, const StringRef /*tip*/)
1923{
1924 const UserTooltip_Store *arg = static_cast<UserTooltip_Store *>(argN);
1925 const bool has_fake_user = arg->has_fake_user;
1926 const bool is_linked = arg->is_linked;
1927 const int real_users = arg->real_users;
1928
1929 if (has_fake_user) {
1930 return is_linked ? TIP_("Item is protected from deletion") :
1931 TIP_("Click to remove protection from deletion");
1932 }
1933
1934 if (real_users) {
1935 return is_linked ? TIP_("Item is not protected from deletion") :
1936 TIP_("Click to add protection from deletion");
1937 }
1938
1939 return is_linked ?
1940 TIP_("Item has no users and will be removed") :
1941 TIP_("Item has no users and will be removed.\nClick to protect from deletion");
1942}
1943
1945 const ARegion *region,
1946 const SpaceOutliner *space_outliner)
1947{
1948 const int xmax_offset = ELEM(space_outliner->outlinevis, SO_VIEW_LAYER, SO_SCENES) ?
1951
1952 tree_iterator::all_open(*space_outliner, [&](const TreeElement *te) {
1953 if (!outliner_is_element_in_view(te, &region->v2d)) {
1954 return;
1955 }
1956
1957 const TreeStoreElem *tselem = TREESTORE(te);
1958
1959 if (tselem->type != TSE_SOME_ID && tselem->type != TSE_LAYER_COLLECTION) {
1960 return;
1961 }
1962
1963 ID *id = tselem->id;
1964 if (!id || id->tag & ID_TAG_EXTRAUSER) {
1965 return;
1966 }
1967
1968 ui::Button *bt;
1969 const int real_users = id->us - ID_FAKE_USERS(id);
1970 const bool has_fake_user = id->flag & ID_FLAG_FAKEUSER;
1971 const bool is_linked = ID_IS_LINKED(id);
1972 const bool is_object = GS(id->name) == ID_OB;
1973 char overlay[5];
1975
1976 if (is_object) {
1977 bt = uiDefBut(block,
1979 overlay,
1980 int(region->v2d.cur.xmax - xmax_offset),
1981 te->ys,
1982 UI_UNIT_X,
1983 UI_UNIT_Y,
1984 nullptr,
1985 0.0,
1986 0.0,
1987 TIP_("Number of users"));
1988 }
1989 else {
1991 bt = uiDefIconButR(block,
1993 ICON_FAKE_USER_OFF,
1994 int(region->v2d.cur.xmax - xmax_offset),
1995 te->ys,
1996 UI_UNIT_X,
1997 UI_UNIT_Y,
1998 &idptr,
1999 "use_fake_user",
2000 -1,
2001 0,
2002 0,
2003 nullptr);
2004
2006 tip_arg->has_fake_user = has_fake_user;
2007 tip_arg->is_linked = is_linked;
2008 tip_arg->real_users = real_users;
2009 button_func_tooltip_set(bt, user_tooltip_func, tip_arg, MEM_delete_void);
2010
2011 if (is_linked) {
2013 "Cannot edit fake user on a linked datablock, consider "
2014 "referencing it through a Custom Property");
2015 }
2016 else {
2017 /* Allow _inaccurate_ dragging over multiple toggles. */
2018 button_flag_enable(bt, ui::BUT_DRAG_LOCK);
2019 }
2020
2021 if (!real_users && !has_fake_user) {
2022 uchar overlay_color[4];
2023 ui::theme::get_color_4ubv(TH_REDALERT, overlay_color);
2024 button_icon_indicator_color_set(bt, overlay_color);
2025 }
2026 button_icon_indicator_set(bt, overlay);
2027 }
2028 });
2029}
2030
2032 const ARegion *region,
2033 const SpaceOutliner *space_outliner,
2034 const ListBaseT<TreeElement> *lb,
2035 const int x)
2036{
2037 const float pad_x = 2.0f * UI_SCALE_FAC;
2038 const float pad_y = 0.5f * U.pixelsize;
2039 const float item_max_width = round_fl_to_int(OL_RNA_COL_SIZEX - 2 * pad_x);
2040 const float item_height = round_fl_to_int(UI_UNIT_Y - 2.0f * pad_y);
2041
2042 for (const TreeElement &te : *lb) {
2043 const TreeStoreElem *tselem = TREESTORE(&te);
2044 if (TSELEM_OPEN(tselem, space_outliner)) {
2045 outliner_draw_overrides_rna_buts(block, region, space_outliner, &te.subtree, x);
2046 }
2047
2048 if (!outliner_is_element_in_view(&te, &region->v2d)) {
2049 continue;
2050 }
2052 &te);
2053 if (!override_elem) {
2054 continue;
2055 }
2056
2057 if (!override_elem->is_rna_path_valid) {
2058 ui::Button *but = uiDefBut(block,
2060 override_elem->rna_path,
2061 x + pad_x,
2062 te.ys + pad_y,
2063 item_max_width,
2064 item_height,
2065 nullptr,
2066 0.0f,
2067 0.0f,
2068 "");
2069 button_flag_enable(but, ui::BUT_REDALERT);
2070 continue;
2071 }
2072
2073 if (const TreeElementOverridesPropertyOperation *override_op_elem =
2075 {
2076 StringRefNull op_label = override_op_elem->get_override_operation_label();
2077 if (!op_label.is_empty()) {
2078 StringRefNull op_tooltip = override_op_elem->get_override_operation_tooltip();
2079 uiDefBut(block,
2081 op_label,
2082 x + pad_x,
2083 te.ys + pad_y,
2084 item_max_width,
2085 item_height,
2086 nullptr,
2087 0,
2088 0,
2089 op_tooltip);
2090 continue;
2091 }
2092 }
2093
2094 PointerRNA *ptr = &override_elem->override_rna_ptr;
2095 PropertyRNA *prop = &override_elem->override_rna_prop;
2096 const PropertyType prop_type = RNA_property_type(prop);
2097
2098 ui::Button *auto_but = uiDefAutoButR(block,
2099 ptr,
2100 prop,
2101 -1,
2102 (prop_type == PROP_ENUM) ? std::nullopt :
2103 std::optional(""),
2104 ICON_NONE,
2105 x + pad_x,
2106 te.ys + pad_y,
2107 item_max_width,
2108 item_height);
2109 /* Added the button successfully, nothing else to do. Otherwise, cases for multiple buttons
2110 * need to be handled. */
2111 if (auto_but) {
2112 continue;
2113 }
2114
2115 if (!auto_but) {
2116 /* TODO what if the array is longer, and doesn't fit nicely? What about multi-dimension
2117 * arrays? */
2118 uiDefAutoButsArrayR(
2119 block, ptr, prop, ICON_NONE, x + pad_x, te.ys + pad_y, item_max_width, item_height);
2120 }
2121 }
2122}
2123
2125{
2126 const std::optional<int64_t> session_uid_a = button_context_int_get(a, "session_uid");
2127 const std::optional<int64_t> session_uid_b = button_context_int_get(b, "session_uid");
2128 if (!session_uid_a || !session_uid_b) {
2129 return false;
2130 }
2131 /* Using session UID to compare is safer than using the pointer. */
2132 return session_uid_a == session_uid_b;
2133}
2134
2136 ui::Block *block,
2137 const ARegion *region,
2138 const SpaceOutliner *space_outliner,
2139 const ListBaseT<TreeElement> *lb,
2140 const int x)
2141{
2142 for (const TreeElement &te : *lb) {
2143 const TreeStoreElem *tselem = TREESTORE(&te);
2144 if (TSELEM_OPEN(tselem, space_outliner)) {
2145 outliner_draw_overrides_restrictbuts(bmain, block, region, space_outliner, &te.subtree, x);
2146 }
2147
2148 if (!outliner_is_element_in_view(&te, &region->v2d)) {
2149 continue;
2150 }
2152 if (!te_id) {
2153 continue;
2154 }
2155
2156 ID &id = te_id->get_ID();
2157 if (ID_IS_LINKED(&id)) {
2158 continue;
2159 }
2160 if (!ID_IS_OVERRIDE_LIBRARY(&id)) {
2161 /* Some items may not be liboverrides, e.g. the root item for all linked libraries (see
2162 * #TreeDisplayOverrideLibraryHierarchies::build_tree). */
2163 continue;
2164 }
2165
2166 const bool is_system_override = BKE_lib_override_library_is_system_defined(bmain, &id);
2167 const BIFIconID icon = is_system_override ? ICON_LIBRARY_DATA_OVERRIDE_NONEDITABLE :
2168 ICON_LIBRARY_DATA_OVERRIDE;
2169 ui::Button *but = uiDefIconButO(block,
2171 "ED_OT_lib_id_override_editable_toggle",
2173 icon,
2174 x,
2175 te.ys,
2176 UI_UNIT_X,
2177 UI_UNIT_Y,
2178 "");
2179 /* "id" is used by the operator #ED_OT_lib_id_override_editable_toggle. */
2180 PointerRNA idptr = RNA_id_pointer_create(&id);
2181 button_context_ptr_set(block, but, "id", &idptr);
2182
2183 /* "session_uid" is used to compare buttons (in redraws). */
2184 button_context_int_set(block, but, "session_uid", id.session_uid);
2185 button_func_identity_compare_set(but, outliner_but_identity_cmp_context_id_fn);
2186
2187 button_flag_enable(but, ui::BUT_DRAG_LOCK);
2188 }
2189}
2190
2191static void outliner_draw_separator(ARegion *region, const int x)
2192{
2193 View2D *v2d = &region->v2d;
2194
2195 GPU_line_width(1.0f);
2196
2197 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
2200
2202
2203 immVertex2f(pos, x, v2d->cur.ymax);
2204 immVertex2f(pos, x, v2d->cur.ymin);
2205
2206 immEnd();
2207
2209}
2210
2212 ARegion *region,
2213 SpaceOutliner *space_outliner,
2214 int sizex)
2215{
2216 PointerRNA ptr;
2217 PropertyRNA *prop;
2218
2219 tree_iterator::all_open(*space_outliner, [&](TreeElement *te) {
2220 TreeStoreElem *tselem = TREESTORE(te);
2221
2222 if (!outliner_is_element_in_view(te, &region->v2d)) {
2223 return;
2224 }
2225
2227 ptr = te_rna_prop->get_pointer_rna();
2228 prop = te_rna_prop->get_property_rna();
2229
2230 if (!TSELEM_OPEN(tselem, space_outliner)) {
2231 if (RNA_property_type(prop) == PROP_POINTER) {
2232 ui::Button *but = uiDefAutoButR(block,
2233 &ptr,
2234 prop,
2235 -1,
2236 "",
2237 ICON_NONE,
2238 sizex,
2239 te->ys,
2241 UI_UNIT_Y - 1);
2242 button_flag_enable(but, ui::BUT_DISABLED);
2243 }
2244 else if (RNA_property_type(prop) == PROP_ENUM) {
2245 uiDefAutoButR(block,
2246 &ptr,
2247 prop,
2248 -1,
2249 std::nullopt,
2250 ICON_NONE,
2251 sizex,
2252 te->ys,
2254 UI_UNIT_Y - 1);
2255 }
2256 else {
2257 uiDefAutoButR(block,
2258 &ptr,
2259 prop,
2260 -1,
2261 "",
2262 ICON_NONE,
2263 sizex,
2264 te->ys,
2266 UI_UNIT_Y - 1);
2267 }
2268 }
2269 }
2270 else if (TreeElementRNAArrayElement *te_rna_array_elem =
2272 {
2273 ptr = te_rna_array_elem->get_pointer_rna();
2274 prop = te_rna_array_elem->get_property_rna();
2275
2276 uiDefAutoButR(block,
2277 &ptr,
2278 prop,
2279 te->index,
2280 "",
2281 ICON_NONE,
2282 sizex,
2283 te->ys,
2285 UI_UNIT_Y - 1);
2286 }
2287 });
2288}
2289
2290static void outliner_buttons(const bContext *C,
2291 ui::Block *block,
2292 ARegion *region,
2293 const float restrict_column_width,
2294 TreeElement *te)
2295{
2296 ui::Button *bt;
2297 TreeStoreElem *tselem;
2298 int spx, dx, len;
2299
2300 tselem = TREESTORE(te);
2301
2302 BLI_assert(tselem->flag & TSE_TEXTBUT);
2303 /* If we add support to rename Sequence, need change this. */
2304
2305 if (tselem->type == TSE_EBONE) {
2306 len = sizeof(EditBone::name);
2307 }
2308 else if (tselem->type == TSE_MODIFIER) {
2309 len = sizeof(ModifierData::name);
2310 }
2311 else if (tselem->id && GS(tselem->id->name) == ID_LI) {
2312 len = sizeof(Library::filepath);
2313 }
2314 else {
2315 len = MAX_ID_NAME - 2;
2316 }
2317
2318 spx = te->xs + 1.8f * UI_UNIT_X;
2319 dx = region->v2d.cur.xmax - (spx + restrict_column_width + 0.2f * UI_UNIT_X);
2320
2321 bt = uiDefBut(block,
2323 "",
2324 spx,
2325 te->ys,
2326 dx,
2327 UI_UNIT_Y - 1,
2328 (void *)te->name,
2329 1.0,
2330 float(len),
2331 "");
2332 /* Handle undo through the #template_id_cb set below. Default undo handling from the button
2333 * code (see #apply_but_undo) would not work here, as the new name is not yet applied to the
2334 * ID. */
2335 button_flag_disable(bt, ui::BUT_UNDO);
2336 text_button_func_rename_set(bt, [tselem](bContext &C, StringRefNull oldname) {
2337 namebutton_fn(&C, tselem, oldname.c_str());
2338 });
2339
2340 /* Returns false if button got removed. */
2341 if (false == button_active_only(C, region, block, bt)) {
2342 tselem->flag &= ~TSE_TEXTBUT;
2343
2344 /* Bad! (notifier within draw) without this, we don't get a refresh. */
2346 }
2347}
2348
2349static void outliner_mode_toggle_fn(bContext *C, void *tselem_poin, void * /*arg2*/)
2350{
2351 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
2352 TreeStoreElem *tselem = static_cast<TreeStoreElem *>(tselem_poin);
2353 TreeViewContext tvc;
2355
2356 TreeElement *te = outliner_find_tree_element(&space_outliner->runtime->tree, tselem);
2357 if (!te) {
2358 return;
2359 }
2360
2361 /* Check that the item is actually an object. */
2362 BLI_assert(tselem->id != nullptr && GS(tselem->id->name) == ID_OB);
2363
2364 Object *ob = id_cast<Object *>(tselem->id);
2365 const bool object_data_shared = (ob->data == tvc.obact->data);
2366
2367 wmWindow *win = CTX_wm_window(C);
2368 const bool do_extend = (win->runtime->eventstate->modifier & KM_CTRL) && !object_data_shared;
2369 outliner_item_mode_toggle(C, tvc, te, do_extend);
2370}
2371
2372/* Draw icons for adding and removing objects from the current interaction mode. */
2374 const TreeViewContext &tvc,
2375 TreeElement *te,
2376 const bool lock_object_modes)
2377{
2378 TreeStoreElem *tselem = TREESTORE(te);
2379 if ((tselem->type != TSE_SOME_ID) || (te->idcode != ID_OB)) {
2380 return;
2381 }
2382
2383 Object *ob = id_cast<Object *>(tselem->id);
2384 Object *ob_active = tvc.obact;
2385 const int x_pad = 3 * UI_SCALE_FAC;
2386
2387 /* Not all objects support particle systems. */
2388 if (ob_active->mode == OB_MODE_PARTICLE_EDIT && !psys_get_current(ob)) {
2389 return;
2390 }
2391
2392 /* Only for objects with the same type. */
2393 if (ob->type != ob_active->type) {
2394 return;
2395 }
2396
2397 if (ob->mode == OB_MODE_OBJECT && BKE_object_is_in_editmode(ob)) {
2398 /* Another object has our (shared) data in edit mode, so nothing we can change. */
2399 ui::Button *but = uiDefIconBut(block,
2401 ui::icon_from_object_mode(ob_active->mode),
2402 x_pad,
2403 te->ys,
2404 UI_UNIT_X,
2405 UI_UNIT_Y,
2406 nullptr,
2407 0.0,
2408 0.0,
2409 TIP_("Another object has this shared data in edit mode"));
2410 button_flag_enable(but, ui::BUT_DISABLED);
2411 return;
2412 }
2413
2414 bool draw_active_icon = ob->mode == ob_active->mode;
2415
2416 /* When not locking object modes, objects can remain in non-object modes. For modes that do not
2417 * allow multi-object editing, these other objects should still show be viewed as not in the
2418 * mode. Otherwise multiple objects show the same mode icon in the outliner even though only
2419 * one object is actually editable in the mode. */
2420 if (!lock_object_modes && ob != ob_active && !(tvc.ob_edit || tvc.ob_pose)) {
2421 draw_active_icon = false;
2422 }
2423
2424 const bool object_data_shared = (ob->data == ob_active->data);
2425 draw_active_icon = draw_active_icon || object_data_shared;
2426
2427 int icon;
2428 StringRef tip;
2429 if (draw_active_icon) {
2430 icon = ui::icon_from_object_mode(ob_active->mode);
2431 tip = object_data_shared ? TIP_("Change the object in the current mode") :
2432 TIP_("Remove from the current mode");
2433 }
2434 else {
2435 icon = ICON_DOT;
2436 tip = TIP_(
2437 "Change the object in the current mode\n"
2438 " \u2022 Ctrl to add to the current mode");
2439 }
2440 block_emboss_set(block, ui::EmbossType::NoneOrStatus);
2441 ui::Button *but = uiDefIconBut(block,
2443 icon,
2444 x_pad,
2445 te->ys,
2446 UI_UNIT_X,
2447 UI_UNIT_Y,
2448 nullptr,
2449 0.0,
2450 0.0,
2451 tip);
2452 button_func_set(but, outliner_mode_toggle_fn, tselem, nullptr);
2453 /* To make drag toggle work, though it only works as expected when Control is held.
2454 * Otherwise it doesn't really work as expected and only leaves one object in this mode. */
2455 button_func_pushed_state_set(
2456 but, [draw_active_icon](const ui::Button &) { return draw_active_icon; });
2457 button_flag_enable(but, ui::BUT_DRAG_LOCK);
2458 /* Mode toggling handles its own undo state because undo steps need to be grouped. */
2459 button_flag_disable(but, ui::BUT_UNDO);
2460
2461 if (!ID_IS_EDITABLE(&ob->id) ||
2464 {
2465 button_disable(but, "Cannot edit library or non-editable override data");
2466 }
2467}
2468
2470 TreeViewContext &tvc,
2471 SpaceOutliner *space_outliner)
2472{
2473 const bool lock_object_modes = tvc.scene->toolsettings->object_flag & SCE_OBJECT_MODE_LOCK;
2474
2475 tree_iterator::all_open(*space_outliner, [&](TreeElement *te) {
2476 if (tvc.obact && tvc.obact->mode != OB_MODE_OBJECT) {
2477 outliner_draw_mode_column_toggle(block, tvc, te, lock_object_modes);
2478 }
2479 });
2480}
2481
2483{
2484 for (const TreeElement &sub_te : parent_te->subtree) {
2485 const AbstractTreeElement *abstract_te = tree_element_cast<AbstractTreeElement>(&sub_te);
2486 StringRefNull warning_msg = abstract_te ? abstract_te->get_warning() : "";
2487
2488 if (!warning_msg.is_empty()) {
2489 return warning_msg;
2490 }
2491
2493 if (!warning_msg.is_empty()) {
2494 return warning_msg;
2495 }
2496 }
2497
2498 return "";
2499}
2500
2502 const TreeElement *te)
2503{
2505 const StringRefNull warning_msg = abstract_te ? abstract_te->get_warning() : "";
2506
2507 if (!warning_msg.is_empty()) {
2508 return warning_msg;
2509 }
2510
2511 /* If given element has no warning, recursively try to display the first sub-element's warning.
2512 */
2513 if (!TSELEM_OPEN(te->store_elem, &space_outliner)) {
2515 }
2516
2517 return "";
2518}
2519
2521 const SpaceOutliner *space_outliner,
2522 const StringRef warning_msg,
2523 const bool use_mode_column,
2524 const int te_ys)
2525{
2526 /* Move the warnings a unit left in view layer mode. */
2527 const short mode_column_offset = (use_mode_column && (space_outliner->outlinevis == SO_SCENES)) ?
2528 UI_UNIT_X :
2529 0;
2530
2531 block_emboss_set(block, ui::EmbossType::NoneOrStatus);
2532 ui::Button *but = uiDefIconBut(block,
2534 ICON_STATUS_WARNING,
2535 mode_column_offset,
2536 te_ys,
2537 UI_UNIT_X,
2538 UI_UNIT_Y,
2539 nullptr,
2540 0.0,
2541 0.0,
2542 warning_msg);
2543 /* No need for undo here, this is a pure info widget. */
2544 button_flag_disable(but, ui::BUT_UNDO);
2545}
2546
2548 const SpaceOutliner *space_outliner,
2549 const bool use_mode_column)
2550{
2551 tree_iterator::all_open(*space_outliner, [&](const TreeElement *te) {
2552 /* Get warning for this element, or if there is none and the element is collapsed, the first
2553 * warning in the collapsed sub-tree. */
2554 StringRefNull warning_msg = outliner_draw_get_warning_tree_element(*space_outliner, te);
2555
2556 if (!warning_msg.is_empty()) {
2558 block, space_outliner, warning_msg, use_mode_column, te->ys);
2559 }
2560 });
2561}
2562
2564
2565/* -------------------------------------------------------------------- */
2568
2570{
2571 if (GS(id->name) == ID_OB) {
2572 return ui::icon_from_object_type(id_cast<Object *>(const_cast<ID *>(id)));
2573 }
2574
2575 /* TODO(sergey): Casting to short here just to handle ID_NLA which is
2576 * NOT inside of IDType enum.
2577 */
2578 switch (short(GS(id->name))) {
2579 case ID_SCE:
2580 return ICON_SCENE_DATA;
2581 case ID_ME:
2582 return ICON_OUTLINER_DATA_MESH;
2583 case ID_CU_LEGACY: {
2584 const Curve *cu = id_cast<Curve *>(const_cast<ID *>(id));
2585 switch (cu->ob_type) {
2586 case OB_FONT:
2587 return ICON_OUTLINER_DATA_FONT;
2588 case OB_SURF:
2589 return ICON_OUTLINER_DATA_SURFACE;
2590 default:
2591 return ICON_OUTLINER_DATA_CURVE;
2592 }
2593 break;
2594 }
2595 case ID_MB:
2596 return ICON_OUTLINER_DATA_META;
2597 case ID_LT:
2598 return ICON_OUTLINER_DATA_LATTICE;
2599 case ID_LA: {
2600 const Light *la = id_cast<Light *>(const_cast<ID *>(id));
2601 switch (la->type) {
2602 case LA_LOCAL:
2603 return ICON_LIGHT_POINT;
2604 case LA_SUN:
2605 return ICON_LIGHT_SUN;
2606 case LA_SPOT:
2607 return ICON_LIGHT_SPOT;
2608 case LA_AREA:
2609 return ICON_LIGHT_AREA;
2610 default:
2611 return ICON_OUTLINER_DATA_LIGHT;
2612 }
2613 }
2614 case ID_MA:
2615 return ICON_MATERIAL_DATA;
2616 case ID_TE:
2617 return ICON_TEXTURE_DATA;
2618 case ID_IM:
2619 return ICON_IMAGE_DATA;
2620 case ID_SPK:
2621 case ID_SO:
2622 return ICON_OUTLINER_DATA_SPEAKER;
2623 case ID_AR:
2624 return ICON_OUTLINER_DATA_ARMATURE;
2625 case ID_CA:
2626 return ICON_OUTLINER_DATA_CAMERA;
2627 case ID_KE:
2628 return ICON_SHAPEKEY_DATA;
2629 case ID_WO:
2630 return ICON_WORLD_DATA;
2631 case ID_AC:
2632 return ICON_ACTION;
2633 case ID_NLA:
2634 return ICON_NLA;
2635 case ID_TXT: {
2636 const Text *text = id_cast<Text *>(const_cast<ID *>(id));
2637 if (text->filepath == nullptr || (text->flags & TXT_ISMEM)) {
2638 return ICON_FILE_TEXT;
2639 }
2640 /* Helps distinguish text-based formats like the file-browser does. */
2641 return ED_file_extension_icon(text->filepath);
2642 }
2643 case ID_GR:
2644 return ICON_OUTLINER_COLLECTION;
2645 case ID_CV:
2646 return ICON_OUTLINER_DATA_CURVES;
2647 case ID_PT:
2648 return ICON_OUTLINER_DATA_POINTCLOUD;
2649 case ID_VO:
2650 return ICON_OUTLINER_DATA_VOLUME;
2651 case ID_LI:
2652 if (id->tag & ID_TAG_MISSING) {
2653 return ICON_LIBRARY_DATA_BROKEN;
2654 }
2655 else if (reinterpret_cast<const Library *>(id)->flag & LIBRARY_FLAG_IS_ARCHIVE) {
2656 return ICON_PACKAGE;
2657 }
2658 else if ((id_cast<Library *>(const_cast<ID *>(id)))->runtime->parent) {
2659 return ICON_LIBRARY_DATA_INDIRECT;
2660 }
2661 else {
2662 return ICON_LIBRARY_DATA_DIRECT;
2663 }
2664 case ID_LS:
2665 return ICON_LINE_DATA;
2666 case ID_GP:
2667 case ID_GD_LEGACY:
2668 return ICON_OUTLINER_DATA_GREASEPENCIL;
2669 case ID_LP: {
2670 const LightProbe *lp = id_cast<LightProbe *>(const_cast<ID *>(id));
2671 switch (lp->type) {
2673 return ICON_LIGHTPROBE_SPHERE;
2675 return ICON_LIGHTPROBE_PLANE;
2677 return ICON_LIGHTPROBE_VOLUME;
2678 default:
2679 return ICON_LIGHTPROBE_SPHERE;
2680 }
2681 }
2682 case ID_BR:
2683 return ICON_BRUSH_DATA;
2684 case ID_SCR:
2685 case ID_WS:
2686 return ICON_WORKSPACE;
2687 case ID_MSK:
2688 return ICON_MOD_MASK;
2689 case ID_NT: {
2690 const bNodeTree *ntree = id_cast<bNodeTree *>(const_cast<ID *>(id));
2691 const bke::bNodeTreeType *ntreetype = ntree->typeinfo;
2692 return ntreetype->ui_icon;
2693 }
2694 case ID_MC:
2695 return ICON_SEQUENCE;
2696 case ID_PC:
2697 return ICON_CURVE_BEZCURVE;
2698 case ID_PA:
2699 return ICON_PARTICLES;
2700 case ID_PAL:
2701 return ICON_COLOR;
2702 case ID_VF:
2703 return ICON_FILE_FONT;
2704 default:
2705 return ICON_NONE;
2706 }
2707}
2708
2710{
2711 TreeElementIcon data = {nullptr, nullptr, ICON_DOT};
2712
2713 if (tselem->type != TSE_SOME_ID) {
2714 switch (tselem->type) {
2715 case TSE_CONSTRAINT:
2717 case TSE_MODIFIER_BASE:
2718 case TSE_MODIFIER:
2720 case TSE_GPENCIL_EFFECT:
2721 data.drag_id = tselem->id;
2722 break;
2725 data.icon = tree_element_get_icon_from_id(&base_te->id);
2726 break;
2727 }
2732 if (collection && !(collection->flag & COLLECTION_IS_MASTER)) {
2733 data.drag_id = tselem->id;
2734 data.drag_parent = (data.drag_id && te->parent) ? TREESTORE(te->parent)->id : nullptr;
2735 }
2736
2737 data.icon = ICON_OUTLINER_COLLECTION;
2738 break;
2739 }
2740 default:
2741 break;
2742 }
2743 }
2744 else if (tselem->id) {
2745 data.drag_id = tselem->id;
2746 data.drag_parent = (data.drag_id && te->parent) ? TREESTORE(te->parent)->id : nullptr;
2747 data.icon = tree_element_get_icon_from_id(tselem->id);
2748 }
2749
2750 if (!te->abstract_element) {
2751 /* Pass */
2752 }
2753 else if (auto icon = te->abstract_element->get_icon()) {
2754 data.icon = *icon;
2755 }
2756
2757 return data;
2758}
2759
2763static bool tselem_draw_icon(ui::Block *block,
2764 int xmax,
2765 float x,
2766 float y,
2767 TreeStoreElem *tselem,
2768 TreeElement *te,
2769 float alpha,
2770 const bool is_clickable,
2771 const int num_elements)
2772{
2774 if (data.icon == 0) {
2775 return false;
2776 }
2777
2778 const bool is_collection = outliner_is_collection_tree_element(te);
2779 ui::IconTextOverlay text_overlay;
2780 icon_text_overlay_init_from_count(&text_overlay, num_elements);
2781
2782 /* Collection colors and icons covered by restrict buttons. */
2783 if (!is_clickable || x >= xmax || is_collection) {
2784 /* Placement of icons, copied from `interface_widgets.cc`. */
2785 float aspect = (0.8f * UI_UNIT_Y) / ICON_DEFAULT_HEIGHT;
2786 x += 2.0f * aspect;
2787 y += 2.0f * aspect;
2788 const bTheme *btheme = ui::theme::theme_get();
2789
2790 if (is_collection) {
2792 if (collection->color_tag != COLLECTION_COLOR_NONE) {
2793 icon_draw_ex(x,
2794 y,
2795 ICON_COLLECTION_COLOR_01 + int(collection->color_tag),
2797 alpha,
2798 0.0f,
2799 btheme->collection_color[collection->color_tag].color,
2800 btheme->tui.icon_border_intensity > 0.0f,
2801 &text_overlay);
2802 return true;
2803 }
2804 }
2805
2806 /* Reduce alpha to match icon buttons */
2807 alpha *= 0.8f;
2808
2809 /* Restrict column clip. it has been coded by simply overdrawing, doesn't work for buttons. */
2810 uchar color[4];
2811 if (ui::icon_get_theme_color(data.icon, color)) {
2812 icon_draw_ex(x,
2813 y,
2814 data.icon,
2816 alpha,
2817 0.0f,
2818 color,
2819 btheme->tui.icon_border_intensity > 0.0f,
2820 &text_overlay);
2821 }
2822 else {
2823 icon_draw_ex(x, y, data.icon, UI_INV_SCALE_FAC, alpha, 0.0f, nullptr, false, &text_overlay);
2824 }
2825 }
2826 else {
2827 ui::Button *but = uiDefIconBut(
2828 block,
2830 data.icon,
2831 x,
2832 y,
2833 UI_UNIT_X,
2834 UI_UNIT_Y,
2835 nullptr,
2836 0.0,
2837 0.0,
2838 (data.drag_id && ID_IS_LINKED(data.drag_id)) ? data.drag_id->lib->filepath : "");
2839 button_label_alpha_factor_set(but, alpha);
2840 }
2841
2842 return true;
2843}
2844
2845static void outliner_icon_background_colors(float icon_color[4], float icon_border[4])
2846{
2847 float text[4];
2849
2850 copy_v3_v3(icon_color, text);
2851 icon_color[3] = 0.4f;
2852 copy_v3_v3(icon_border, text);
2853 icon_border[3] = 0.2f;
2854}
2855
2856/* Draw a rounded rectangle behind icons of active elements. */
2857static void outliner_draw_active_indicator(const float minx,
2858 const float miny,
2859 const float maxx,
2860 const float maxy,
2861 const float icon_color[4],
2862 const float icon_border[4])
2863{
2864 const float ufac = UI_UNIT_X / 20.0f;
2865 const float radius = UI_UNIT_Y / 4.0f;
2866 rctf rect{};
2867 BLI_rctf_init(&rect, minx, maxx, miny + ufac, maxy - ufac);
2868
2869 draw_roundbox_corner_set(ui::CNR_ALL);
2870 ui::draw_roundbox_aa(&rect, true, radius, icon_color);
2871 ui::draw_roundbox_aa(&rect, false, radius, icon_border);
2872 GPU_blend(GPU_BLEND_ALPHA); /* Round-box disables. */
2873}
2874
2876 TreeElement *te,
2877 int xmax,
2878 int *offsx,
2879 int ys,
2880 float alpha_fac,
2881 const eOLDrawState active,
2882 const int num_elements)
2883{
2884 TreeStoreElem *tselem = TREESTORE(te);
2885
2886 if (active != OL_DRAWSEL_NONE) {
2887 float icon_color[4], icon_border[4];
2888 outliner_icon_background_colors(icon_color, icon_border);
2889 if (active == OL_DRAWSEL_ACTIVE) {
2891 icon_border[3] = 0.3f;
2892 }
2893
2894 outliner_draw_active_indicator(float(*offsx),
2895 float(ys),
2896 float(*offsx) + UI_UNIT_X,
2897 float(ys) + UI_UNIT_Y,
2898 icon_color,
2899 icon_border);
2900 }
2901
2902 if (tselem->flag & TSE_HIGHLIGHTED_ICON) {
2903 alpha_fac += 0.5;
2904 }
2906 block, xmax, float(*offsx), float(ys), tselem, te, alpha_fac, false, num_elements);
2907 te->xs = *offsx;
2908 te->ys = ys;
2909 te->xend = short(*offsx) + UI_UNIT_X;
2910
2911 if (num_elements > 1) {
2912 te->flag |= TE_ICONROW_MERGED;
2913 }
2914 else {
2915 te->flag |= TE_ICONROW;
2916 }
2917
2918 (*offsx) += UI_UNIT_X;
2919}
2920
2922{
2923 TreeStoreElem *tselem = TREESTORE(te);
2924
2925 int id_index = 0;
2926 if (tselem->type == TSE_SOME_ID) {
2927 id_index = BKE_idtype_idcode_to_index(te->idcode);
2928 }
2929 else if (tselem->type == TSE_GREASE_PENCIL_NODE) {
2930 /* Use the index of the grease pencil ID for the grease pencil tree nodes (which are not IDs).
2931 * All the Grease Pencil layer tree stats are stored in this index in #MergedIconRow. */
2932 id_index = INDEX_ID_GP;
2933 }
2934 else {
2935 id_index = INDEX_ID_GR;
2936 }
2937
2938 if (id_index < INDEX_ID_OB) {
2939 return id_index;
2940 }
2941 if (id_index == INDEX_ID_OB) {
2942 const Object *ob = id_cast<Object *>(tselem->id);
2943 return int(INDEX_ID_OB) + int(ob->type);
2944 }
2945 return id_index + OB_TYPE_MAX;
2946}
2947
2953
2955 const uiFontStyle *fstyle,
2956 const TreeViewContext &tvc,
2957 SpaceOutliner *space_outliner,
2958 ListBaseT<TreeElement> *lb,
2959 int level,
2960 int xmax,
2961 int *offsx,
2962 int ys,
2963 float alpha_fac,
2964 bool in_bone_hierarchy,
2965 const bool is_grease_pencil_node_hierarchy,
2966 MergedIconRow *merged)
2967{
2969
2970 for (TreeElement &te : *lb) {
2971 TreeStoreElem *tselem = TREESTORE(&te);
2972 te.flag &= ~(TE_ICONROW | TE_ICONROW_MERGED);
2973
2974 /* object hierarchy always, further constrained on level */
2975 /* Bones are also hierarchies and get a merged count, but we only start recursing into them if
2976 * an they are at the root level of a collapsed subtree (e.g. not "hidden" in a collapsed
2977 * collection). */
2978 const bool is_bone = ELEM(tselem->type, TSE_BONE, TSE_EBONE, TSE_POSE_CHANNEL);
2979 /* The Grease Pencil layer tree is a hierarchy where we merge and count the total number of
2980 * layers in a node. We merge the counts for all the layers and skip counting nodes that are
2981 * layer groups (for less visual clutter in the outliner). */
2982 const bool is_grease_pencil_node = (tselem->type == TSE_GREASE_PENCIL_NODE);
2983 if ((level < 1) || ((tselem->type == TSE_SOME_ID) && (te.idcode == ID_OB)) ||
2984 (is_grease_pencil_node_hierarchy && is_grease_pencil_node) ||
2985 (in_bone_hierarchy && is_bone))
2986 {
2987 /* active blocks get white circle */
2988 if (tselem->type == TSE_SOME_ID) {
2989 if (te.idcode == ID_OB) {
2990 active = (tvc.obact == id_cast<Object *>(tselem->id)) ? OL_DRAWSEL_NORMAL :
2992 }
2993 else if (is_object_data_in_editmode(tselem->id, tvc.obact)) {
2994 active = OL_DRAWSEL_ACTIVE;
2995 }
2996 else {
2997 active = tree_element_active_state_get(tvc, &te, tselem);
2998 }
2999 }
3000 else {
3001 active = tree_element_type_active_state_get(tvc, &te, tselem);
3002 }
3003
3004 if (!ELEM(tselem->type,
3014 TSE_BONE,
3015 TSE_EBONE,
3020 TSE_NLA_TRACK) &&
3021 tselem->type != TSE_SHAPE_KEY_BLOCK)
3022 {
3023 outliner_draw_iconrow_doit(block, &te, xmax, offsx, ys, alpha_fac, active, 1);
3024 }
3025 else if (tselem->type == TSE_GREASE_PENCIL_NODE &&
3026 tree_element_cast<TreeElementGreasePencilNode>(&te)->node().is_group())
3027 {
3028 /* Grease Pencil layer groups are tree nodes, but they shouldn't be counted. We only want
3029 * to keep track of the nodes that are layers and show the total number of layers in a
3030 * node. Adding the count of groups would add a lot of clutter. */
3031 }
3032 else {
3033 const int index = tree_element_id_type_to_index(&te);
3034 merged->num_elements[index]++;
3035 if ((merged->tree_element[index] == nullptr) || (active > merged->active[index])) {
3036 merged->tree_element[index] = &te;
3037 }
3038 merged->active[index] = std::max(active, merged->active[index]);
3039 }
3040 }
3041
3042 /* TSE_R_LAYER tree element always has same amount of branches, so don't draw. */
3043 /* Also only recurse into bone hierarchies if a direct child of the collapsed element to
3044 * merge into. */
3045 const bool is_root_level_bone = is_bone && (level == 0);
3046 in_bone_hierarchy |= is_root_level_bone;
3047 /* Recurse into the grease pencil layer tree if we already are in the hierarchy or if we're at
3048 * the root level and find a grease pencil node. */
3049 const bool in_grease_pencil_node_hierarchy = is_grease_pencil_node_hierarchy ||
3050 (is_grease_pencil_node && level == 0);
3052 in_bone_hierarchy || in_grease_pencil_node_hierarchy)
3053 {
3055 fstyle,
3056 tvc,
3057 space_outliner,
3058 &te.subtree,
3059 level + 1,
3060 xmax,
3061 offsx,
3062 ys,
3063 alpha_fac,
3064 in_bone_hierarchy,
3065 in_grease_pencil_node_hierarchy,
3066 merged);
3067 }
3068 }
3069
3070 if (level == 0) {
3071 for (int i = 0; i < INDEX_ID_MAX; i++) {
3072 const int num_subtypes = (i == INDEX_ID_OB) ? OB_TYPE_MAX : 1;
3073 /* See tree_element_id_type_to_index for the index logic. */
3074 int index_base = i;
3075 if (i > INDEX_ID_OB) {
3076 index_base += OB_TYPE_MAX;
3077 }
3078 for (int j = 0; j < num_subtypes; j++) {
3079 const int index = index_base + j;
3080 if (merged->num_elements[index] != 0) {
3082 merged->tree_element[index],
3083 xmax,
3084 offsx,
3085 ys,
3086 alpha_fac,
3087 merged->active[index],
3088 merged->num_elements[index]);
3089 }
3090 }
3091 }
3092 }
3093}
3094
3095/* closed tree element */
3097{
3098 tree_iterator::all(te->subtree, [&](TreeElement *te) {
3099 /* closed items may be displayed in row of parent, don't change their coordinate! */
3100 if ((te->flag & TE_ICONROW) == 0 && (te->flag & TE_ICONROW_MERGED) == 0) {
3101 te->xs = 0;
3102 te->ys = 0;
3103 te->xend = 0;
3104 }
3105 });
3106}
3107
3109 const TreeElement *te,
3110 const TreeStoreElem *tselem)
3111{
3112 if (tselem->type == TSE_SOME_ID) {
3113 switch (te->idcode) {
3114 case ID_OB: {
3115 const Object *ob = id_cast<const Object *>(tselem->id);
3116 /* Lookup in view layer is logically const as it only checks a cache. */
3118 const Base *base = (te->directdata) ?
3119 static_cast<const Base *>(te->directdata) :
3120 BKE_view_layer_base_find(static_cast<ViewLayer *>(tvc.view_layer),
3121 const_cast<Object *>(ob));
3122 const bool is_visible = (base != nullptr) &&
3125
3126 return !is_visible;
3127 }
3128 default: {
3129 if (te->parent) {
3130 return element_should_draw_faded(tvc, te->parent, te->parent->store_elem);
3131 }
3132 }
3133 }
3134 }
3135 switch (tselem->type) {
3136 case TSE_LAYER_COLLECTION: {
3137 const LayerCollection *layer_collection = static_cast<const LayerCollection *>(
3138 te->directdata);
3139 const bool is_visible = layer_collection->runtime_flag & LAYER_COLLECTION_VISIBLE_VIEW_LAYER;
3140 const bool is_excluded = layer_collection->flag & LAYER_COLLECTION_EXCLUDE;
3141 return !is_visible || is_excluded;
3142 }
3146 return !node.is_visible();
3147 }
3148 default: {
3149 if (te->parent) {
3150 return element_should_draw_faded(tvc, te->parent, te->parent->store_elem);
3151 }
3152 }
3153 }
3154
3155 if (te->flag & TE_CHILD_NOT_IN_COLLECTION) {
3156 return true;
3157 }
3158
3159 return false;
3160}
3161
3163 const uiFontStyle *fstyle,
3164 const TreeViewContext &tvc,
3165 ARegion *region,
3166 SpaceOutliner *space_outliner,
3167 TreeElement *te,
3168 bool draw_grayed_out,
3169 int startx,
3170 int *starty,
3171 const float restrict_column_width,
3172 TreeElement **te_edit)
3173{
3174 TreeStoreElem *tselem = TREESTORE(te);
3175 float ufac = UI_UNIT_X / 20.0f;
3176 int offsx = 0;
3178 uchar text_color[4];
3180 float icon_bgcolor[4], icon_border[4];
3181 outliner_icon_background_colors(icon_bgcolor, icon_border);
3182
3183 if (*starty + 2 * UI_UNIT_Y >= region->v2d.cur.ymin && *starty <= region->v2d.cur.ymax) {
3184 const float alpha_fac = element_should_draw_faded(tvc, te, tselem) ? 0.5f : 1.0f;
3185 int xmax = region->v2d.cur.xmax;
3186
3187 if ((tselem->flag & TSE_TEXTBUT) && (*te_edit == nullptr)) {
3188 *te_edit = te;
3189 }
3190
3191 /* Icons can be UI buts, we don't want it to overlap with restrict. */
3192 if (restrict_column_width > 0) {
3193 xmax -= restrict_column_width + UI_UNIT_X;
3194 }
3195
3197
3198 /* Colors for active/selected data. */
3199 if (tselem->type == TSE_SOME_ID) {
3200 if (te->idcode == ID_OB) {
3201 Object *ob = id_cast<Object *>(tselem->id);
3203 Base *base = (te->directdata) ? static_cast<Base *>(te->directdata) :
3205 const bool is_selected = (base != nullptr) && ((base->flag & BASE_SELECTED) != 0);
3206
3207 if (ob == tvc.obact) {
3208 active = OL_DRAWSEL_ACTIVE;
3209 }
3210
3211 if (is_selected) {
3212 if (ob == tvc.obact) {
3213 /* Active selected object. */
3215 text_color[3] = 255;
3216 }
3217 else {
3218 /* Other selected objects. */
3220 text_color[3] = 255;
3221 }
3222 }
3223 }
3224 else if (is_object_data_in_editmode(tselem->id, tvc.obact)) {
3225 /* Objects being edited. */
3227 icon_border[3] = 0.3f;
3228 active = OL_DRAWSEL_ACTIVE;
3229 }
3230 else {
3231 if (tree_element_active_state_get(tvc, te, tselem)) {
3232 /* Active items like camera or material. */
3233 icon_bgcolor[3] = 0.2f;
3234 active = OL_DRAWSEL_ACTIVE;
3235 if (te->idcode == ID_SCE) {
3237 text_color[3] = 255;
3238 }
3239 }
3240 }
3241 }
3242 else {
3243 active = tree_element_type_active_state_get(tvc, te, tselem);
3244 if (active != OL_DRAWSEL_NONE) {
3246 text_color[3] = 255;
3247 }
3248 }
3249
3250 /* Active circle. */
3251 if (active != OL_DRAWSEL_NONE) {
3252 outliner_draw_active_indicator(float(startx) + offsx + UI_UNIT_X,
3253 float(*starty),
3254 float(startx) + offsx + 2.0f * UI_UNIT_X,
3255 float(*starty) + UI_UNIT_Y,
3256 icon_bgcolor,
3257 icon_border);
3258
3259 te->flag |= TE_ACTIVE; /* For lookup in display hierarchies. */
3260 }
3261
3262 if (tselem->type == TSE_VIEW_COLLECTION_BASE) {
3263 /* Scene collection in view layer can't expand/collapse. */
3264 }
3265 else if (te->subtree.first() || (te->flag & TE_PRETEND_HAS_CHILDREN)) {
3266 /* Open/close icon, only when sub-levels, except for scene. */
3267 int icon_x = startx;
3268
3269 /* Icons a bit higher. */
3270 if (TSELEM_OPEN(tselem, space_outliner)) {
3272 float(icon_x) + 2 * ufac, float(*starty) + 1 * ufac, ICON_DOWNARROW_HLT, alpha_fac);
3273 }
3274 else {
3276 float(icon_x) + 2 * ufac, float(*starty) + 1 * ufac, ICON_RIGHTARROW, alpha_fac);
3277 }
3278 }
3279 offsx += UI_UNIT_X;
3280
3281 /* Data-type icon. */
3283 tselem_draw_icon(block,
3284 xmax,
3285 float(startx) + offsx,
3286 float(*starty),
3287 tselem,
3288 te,
3289 (tselem->flag & TSE_HIGHLIGHTED_ICON) ? alpha_fac + 0.5f : alpha_fac,
3290 true,
3291 1))
3292 {
3293 offsx += UI_UNIT_X + 4 * ufac;
3294 }
3295 else {
3296 offsx += 2 * ufac;
3297 }
3298
3301 (te_rna_struct && RNA_struct_is_ID(te_rna_struct->get_pointer_rna().type)))
3302 {
3303 const BIFIconID lib_icon = ui::icon_from_library(tselem->id);
3304 if (lib_icon != ICON_NONE) {
3306 float(startx) + offsx + 2 * ufac, float(*starty) + 2 * ufac, lib_icon, alpha_fac);
3307 offsx += UI_UNIT_X + 4 * ufac;
3308 }
3309
3310 if ((lib_icon == ICON_NONE) && (GS(tselem->id->name) == ID_IM)) {
3311 const Image *image = id_cast<Image *>(tselem->id);
3313 ui::icon_draw_alpha(float(startx) + offsx + 2 * ufac,
3314 float(*starty) + 2 * ufac,
3315 ICON_PACKAGE,
3316 alpha_fac);
3317 offsx += UI_UNIT_X + 4 * ufac;
3318 }
3319 }
3320
3321 if (tselem->type == TSE_LAYER_COLLECTION) {
3322 const Collection *collection = id_cast<Collection *>(tselem->id);
3323 const bool has_importer = collection->importer != nullptr;
3324 const bool has_exporters = !collection->exporters.is_empty();
3325
3326 if (has_importer || has_exporters) {
3327 const int icon_io = (has_importer && has_exporters) ? ICON_IMPORT_EXPORT :
3328 (has_importer) ? ICON_IMPORT :
3329 (has_exporters) ? ICON_EXPORT :
3330 ICON_NONE;
3331
3333 float(startx) + offsx + 2 * ufac, float(*starty) + 2 * ufac, icon_io, alpha_fac);
3334 offsx += UI_UNIT_X + 4 * ufac;
3335 }
3336 }
3337 }
3339
3340 /* Name. */
3341 if ((tselem->flag & TSE_TEXTBUT) == 0) {
3343 ui::theme::get_color_blend_3ubv(TH_BACK, TH_TEXT, 0.75f, text_color);
3344 text_color[3] = 255;
3345 }
3346 text_color[3] *= alpha_fac;
3347 ui::fontstyle_draw_simple(fstyle, startx + offsx, *starty + 5 * ufac, te->name, text_color);
3348 }
3349
3350 offsx += int(UI_UNIT_X + ui::fontstyle_string_width(fstyle, te->name));
3351
3352 /* Closed item, we draw the icons, not when it's a scene, or master-server list though. */
3353 if (!TSELEM_OPEN(tselem, space_outliner)) {
3354 if (te->subtree.first()) {
3355 if ((tselem->type == TSE_SOME_ID) && (te->idcode == ID_SCE)) {
3356 /* Pass. */
3357 }
3358 /* this tree element always has same amount of branches, so don't draw */
3359 else if (tselem->type != TSE_R_LAYER) {
3360 int tempx = startx + offsx;
3361
3363
3364 MergedIconRow merged{};
3366 fstyle,
3367 tvc,
3368 space_outliner,
3369 &te->subtree,
3370 0,
3371 xmax,
3372 &tempx,
3373 *starty,
3374 alpha_fac,
3375 false,
3376 false,
3377 &merged);
3378
3380 }
3381 }
3382 }
3383 }
3384 /* Store coord and continue, we need coordinates for elements outside view too. */
3385 te->xs = startx;
3386 te->ys = *starty;
3387 te->xend = startx + offsx;
3388
3389 if (TSELEM_OPEN(tselem, space_outliner)) {
3390 *starty -= UI_UNIT_Y;
3391
3392 for (TreeElement &ten : te->subtree) {
3393 /* Check if element needs to be drawn grayed out, but also gray out
3394 * children of a grayed out parent (pass on draw_grayed_out to children). */
3395 bool draw_children_grayed_out = draw_grayed_out || (ten.flag & TE_DRAGGING);
3397 fstyle,
3398 tvc,
3399 region,
3400 space_outliner,
3401 &ten,
3402 draw_children_grayed_out,
3403 startx + UI_UNIT_X,
3404 starty,
3405 restrict_column_width,
3406 te_edit);
3407 }
3408 }
3409 else {
3411 *starty -= UI_UNIT_Y;
3412 }
3413}
3414
3415static bool subtree_contains_object(ListBaseT<TreeElement> *lb)
3416{
3417 for (TreeElement &te : *lb) {
3418 TreeStoreElem *tselem = TREESTORE(&te);
3419 if ((tselem->type == TSE_SOME_ID) && (te.idcode == ID_OB)) {
3420 return true;
3421 }
3422 }
3423 return false;
3424}
3425
3427 const uint pos, const int x, const int y1, const int y2, const bool draw_dashed)
3428{
3429 /* Small vertical padding. */
3430 const short line_padding = UI_UNIT_Y / 4.0f;
3431
3432 /* >= is 1.0 for un-dashed lines. */
3433 immUniform1f("udash_factor", draw_dashed ? 0.5f : 1.0f);
3434
3436 /* Intentionally draw from top to bottom, so collapsing a child item doesn't make the dashes
3437 * appear to move. */
3438 immVertex2f(pos, x, y2 + line_padding);
3439 immVertex2f(pos, x, y1 - line_padding);
3440 immEnd();
3441}
3442
3444 SpaceOutliner *space_outliner,
3445 ListBaseT<TreeElement> *lb,
3446 const TreeViewContext &tvc,
3447 int startx,
3448 const uchar col[4],
3449 bool draw_grayed_out,
3450 int *starty)
3451{
3452 const bTheme *btheme = ui::theme::theme_get();
3453 int y = *starty;
3454
3455 /* Draw vertical lines between collections */
3456 bool draw_hierarchy_line;
3457 bool use_dashed_line;
3458 for (TreeElement &te : *lb) {
3459 TreeStoreElem *tselem = TREESTORE(&te);
3460 draw_hierarchy_line = false;
3461 use_dashed_line = false;
3462 *starty -= UI_UNIT_Y;
3463 short color_tag = COLLECTION_COLOR_NONE;
3464
3465 /* Only draw hierarchy lines for expanded collections and objects with children. */
3466 if (TSELEM_OPEN(tselem, space_outliner) && !te.subtree.is_empty()) {
3467 if (tselem->type == TSE_LAYER_COLLECTION) {
3468 draw_hierarchy_line = true;
3469
3471 color_tag = collection->color_tag;
3472
3473 y = *starty;
3474 }
3475 else if ((tselem->type == TSE_SOME_ID) && (te.idcode == ID_OB)) {
3476 if (subtree_contains_object(&te.subtree)) {
3477 draw_hierarchy_line = true;
3478 use_dashed_line = true;
3479 y = *starty;
3480 }
3481 }
3482 else if (tselem->type == TSE_GREASE_PENCIL_NODE) {
3485 if (node.is_group() && node.as_group().num_direct_nodes() > 0) {
3486 draw_hierarchy_line = true;
3487 y = *starty;
3488 }
3489 }
3490 else if (ELEM(tselem->type, TSE_BONE, TSE_EBONE, TSE_POSE_CHANNEL)) {
3491 draw_hierarchy_line = true;
3492 use_dashed_line = true;
3493 y = *starty;
3494 }
3495
3497 pos, space_outliner, &te.subtree, tvc, startx + UI_UNIT_X, col, draw_grayed_out, starty);
3498 }
3499
3500 if (draw_hierarchy_line) {
3501 const short alpha_fac = element_should_draw_faded(tvc, &te, tselem) ? 127 : 255;
3502 uchar line_color[4];
3503 if (color_tag != COLLECTION_COLOR_NONE) {
3504 copy_v4_v4_uchar(line_color, btheme->collection_color[color_tag].color);
3505 }
3506 else {
3507 copy_v4_v4_uchar(line_color, col);
3508 }
3509
3510 line_color[3] = alpha_fac;
3511 immUniformColor4ubv(line_color);
3512 outliner_draw_hierarchy_line(pos, startx, y, *starty, use_dashed_line);
3513 }
3514 }
3515}
3516
3518 ListBaseT<TreeElement> *lb,
3519 const TreeViewContext &tvc,
3520 int startx,
3521 int *starty)
3522{
3523 GPUVertFormat *format = immVertexFormat();
3524 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
3525 uchar col[4];
3526
3528
3529 float viewport_size[4];
3530 GPU_viewport_size_get_f(viewport_size);
3531 immUniform2f("viewport_size", viewport_size[2] / UI_SCALE_FAC, viewport_size[3] / UI_SCALE_FAC);
3532 immUniform1i("colors_len", 0); /* "simple" mode */
3533 immUniform1f("dash_width", 8.0f);
3535 col[3] = 255;
3536
3537 GPU_line_width(1.0f);
3540 pos, space_outliner, lb, tvc, startx, col, false, starty);
3542
3544}
3545
3547 SpaceOutliner *space_outliner,
3548 ListBaseT<TreeElement> *lb,
3549 int *starty)
3550{
3551 for (TreeElement &te : *lb) {
3552 TreeStoreElem *tselem = TREESTORE(&te);
3553
3554 /* Selection status. */
3555 if (TSELEM_OPEN(tselem, space_outliner)) {
3556 if (tselem->type == TSE_RNA_STRUCT) {
3557 GPUVertFormat *format = immVertexFormat();
3558 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
3560 immThemeColorShadeAlpha(TH_BACK, -15, -200);
3561 immRectf(pos, 0, *starty + 1, int(region->v2d.cur.xmax), *starty + UI_UNIT_Y - 1);
3563 }
3564 }
3565
3566 *starty -= UI_UNIT_Y;
3567 if (TSELEM_OPEN(tselem, space_outliner)) {
3568 outliner_draw_struct_marks(region, space_outliner, &te.subtree, starty);
3569 if (tselem->type == TSE_RNA_STRUCT) {
3570 GPUVertFormat *format = immVertexFormat();
3571 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
3573 immThemeColorShadeAlpha(TH_BACK, -15, -200);
3574
3576 immVertex2f(pos, 0, float(*starty) + UI_UNIT_Y);
3577 immVertex2f(pos, region->v2d.cur.xmax, float(*starty) + UI_UNIT_Y);
3578 immEnd();
3579
3581 }
3582 }
3583 }
3584}
3585
3586static void outliner_draw_highlights(const ARegion *region,
3587 const SpaceOutliner *space_outliner,
3588 const float col_selection[4],
3589 const float col_active[4],
3590 const float col_highlight[4],
3591 const float col_searchmatch[4],
3592 int /* start_x */,
3593 int *io_start_y)
3594{
3595 const bool is_searching = (SEARCHING_OUTLINER(space_outliner) ||
3596 (space_outliner->outlinevis == SO_DATA_API &&
3597 space_outliner->search_string[0] != 0));
3598
3599 tree_iterator::all_open(*space_outliner, [&](const TreeElement *te) {
3600 const TreeStoreElem *tselem = TREESTORE(te);
3601 const int start_y = *io_start_y;
3602
3603 const float ufac = UI_UNIT_X / 20.0f;
3604 const float radius = UI_UNIT_Y / 8.0f;
3605 const int padding_x = 3 * UI_SCALE_FAC;
3606 rctf rect{};
3607 BLI_rctf_init(&rect,
3608 padding_x,
3609 int(region->v2d.cur.xmax) - padding_x,
3610 start_y + ufac,
3611 start_y + UI_UNIT_Y - ufac);
3612 draw_roundbox_corner_set(ui::CNR_ALL);
3613
3614 /* Selection status. */
3615 if ((tselem->flag & TSE_ACTIVE) && (tselem->flag & TSE_SELECTED)) {
3616 ui::draw_roundbox_4fv(&rect, true, radius, col_active);
3617
3618 float col_active_outline[4];
3619 ui::theme::get_color_shade_4fv(TH_SELECT_ACTIVE, 40, col_active_outline);
3620 ui::draw_roundbox_4fv(&rect, false, radius, col_active_outline);
3621 }
3622 else if (tselem->flag & TSE_SELECTED) {
3623 ui::draw_roundbox_4fv(&rect, true, radius, col_selection);
3624 }
3625
3626 /* Highlights. */
3627 if (tselem->flag & (TSE_DRAG_ANY | TSE_HIGHLIGHTED | TSE_SEARCHMATCH)) {
3628 if (tselem->flag & TSE_DRAG_ANY) {
3629 /* Drag and drop highlight. */
3630 float col_outline[4];
3631 ui::theme::get_color_blend_4f(TH_TEXT, TH_BACK, 0.4f, col_outline);
3632
3633 if (tselem->flag & TSE_DRAG_BEFORE) {
3634 rect.ymax += (1.0f * UI_SCALE_FAC) + (1.0f * U.pixelsize);
3635 rect.ymin = rect.ymax - (2.0f * U.pixelsize);
3636 ui::draw_roundbox_4fv(&rect, true, 0.0f, col_outline);
3637 }
3638 else if (tselem->flag & TSE_DRAG_AFTER) {
3639 rect.ymin -= (1.0f * UI_SCALE_FAC) + (1.0f * U.pixelsize);
3640 rect.ymax = rect.ymin + (2.0f * U.pixelsize);
3641 ui::draw_roundbox_4fv(&rect, true, 0.0f, col_outline);
3642 }
3643 else {
3644 float col_bg[4];
3646 ui::draw_roundbox_4fv_ex(&rect, col_bg, nullptr, 1.0f, col_outline, U.pixelsize, radius);
3647 }
3648 }
3649 else {
3650 if (is_searching && (tselem->flag & TSE_SEARCHMATCH)) {
3651 /* Search match highlights. We don't expand items when searching in the data-blocks,
3652 * but we still want to highlight any filter matches. */
3653 ui::draw_roundbox_4fv(&rect, true, radius, col_searchmatch);
3654 }
3655 else if (tselem->flag & TSE_HIGHLIGHTED) {
3656 /* Mouse hover highlight. */
3657 ui::draw_roundbox_4fv(&rect, true, radius, col_highlight);
3658 }
3659 }
3660 }
3661
3662 *io_start_y -= UI_UNIT_Y;
3663 });
3664}
3665
3667 SpaceOutliner *space_outliner,
3668 int startx,
3669 int *starty)
3670{
3671 const float col_highlight[4] = {1.0f, 1.0f, 1.0f, 0.13f};
3672 float col_selection[4], col_active[4], col_searchmatch[4];
3673
3675 col_selection[3] = 1.0f; /* No alpha. */
3677 col_active[3] = 1.0f; /* No alpha. */
3678 ui::theme::get_color_4fv(TH_MATCH, col_searchmatch);
3679 col_searchmatch[3] = 0.5f;
3680
3683 space_outliner,
3684 col_selection,
3685 col_active,
3686 col_highlight,
3687 col_searchmatch,
3688 startx,
3689 starty);
3691}
3692
3694 const TreeViewContext &tvc,
3695 ARegion *region,
3696 SpaceOutliner *space_outliner,
3697 const float right_column_width,
3698 const bool use_mode_column,
3699 const bool use_warning_column,
3700 TreeElement **te_edit)
3701{
3702 const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
3703
3704 short columns_offset = use_mode_column ? UI_UNIT_X : 0;
3705
3706 /* Move the tree a unit left in view layer mode */
3707 if ((space_outliner->outlinevis == SO_VIEW_LAYER) &&
3708 !(space_outliner->filter & SO_FILTER_NO_COLLECTION) &&
3709 (space_outliner->filter & SO_FILTER_NO_VIEW_LAYERS))
3710 {
3711 columns_offset -= UI_UNIT_X;
3712 }
3713
3714 if (use_warning_column) {
3715 columns_offset += UI_UNIT_X;
3716 }
3717
3718 GPU_blend(GPU_BLEND_ALPHA); /* Only once. */
3719
3720 if (space_outliner->outlinevis == SO_DATA_API) {
3721 /* struct marks */
3722 int starty = int(region->v2d.tot.ymax) - UI_UNIT_Y - OL_Y_OFFSET;
3723 outliner_draw_struct_marks(region, space_outliner, &space_outliner->runtime->tree, &starty);
3724 }
3725
3726 /* Draw highlights before hierarchy. */
3727 int scissor[4] = {0};
3728 {
3729 int starty = int(region->v2d.tot.ymax) - UI_UNIT_Y - OL_Y_OFFSET;
3730 int startx = 0;
3731 outliner_draw_highlights(region, space_outliner, startx, &starty);
3732
3733 /* Set scissor so tree elements or lines can't overlap restriction icons. */
3734 if (right_column_width > 0.0f) {
3735 int mask_x = BLI_rcti_size_x(&region->v2d.mask) - int(right_column_width) + 1;
3736 CLAMP_MIN(mask_x, 0);
3737
3738 GPU_scissor_get(scissor);
3739 GPU_scissor(0, 0, mask_x, region->winy);
3740 }
3741 }
3742
3743 /* Draw hierarchy lines for collections and object children. */
3744 {
3745 int starty = int(region->v2d.tot.ymax) - OL_Y_OFFSET;
3746 int startx = columns_offset + UI_UNIT_X / 2 - (U.pixelsize + 1) / 2;
3748 space_outliner, &space_outliner->runtime->tree, tvc, startx, &starty);
3749 }
3750
3751 /* Items themselves. */
3752 {
3753 int starty = int(region->v2d.tot.ymax) - UI_UNIT_Y - OL_Y_OFFSET;
3754 int startx = columns_offset;
3755 for (TreeElement &te : space_outliner->runtime->tree) {
3757 fstyle,
3758 tvc,
3759 region,
3760 space_outliner,
3761 &te,
3762 (te.flag & TE_DRAGGING) != 0,
3763 startx,
3764 &starty,
3765 right_column_width,
3766 te_edit);
3767 }
3768
3769 if (right_column_width > 0.0f) {
3770 /* Reset scissor. */
3771 GPU_scissor(UNPACK4(scissor));
3772 }
3773 }
3774}
3775
3776static void outliner_back(ARegion *region)
3777{
3778 int ystart;
3779
3780 ystart = int(region->v2d.tot.ymax);
3781 ystart = UI_UNIT_Y * (ystart / (UI_UNIT_Y)) - OL_Y_OFFSET;
3782
3783 GPUVertFormat *format = immVertexFormat();
3784 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
3785
3787
3788 float col_alternating[4];
3791
3792 const float x1 = 0.0f, x2 = region->v2d.cur.xmax;
3793 float y1 = ystart, y2;
3794 int tot = int(floor(ystart - region->v2d.cur.ymin + 2 * UI_UNIT_Y)) / (2 * UI_UNIT_Y);
3795
3796 if (tot > 0) {
3797 immBegin(GPU_PRIM_TRIS, 6 * tot);
3798 while (tot--) {
3799 y1 -= 2 * UI_UNIT_Y;
3800 y2 = y1 + UI_UNIT_Y;
3801 immVertex2f(pos, x1, y1);
3802 immVertex2f(pos, x2, y1);
3803 immVertex2f(pos, x2, y2);
3804
3805 immVertex2f(pos, x1, y1);
3806 immVertex2f(pos, x2, y2);
3807 immVertex2f(pos, x1, y2);
3808 }
3809 immEnd();
3810 }
3812}
3813
3814static int outliner_data_api_buttons_start_x(int max_tree_width)
3815{
3816 return max_ii(OL_RNA_COLX, max_tree_width + OL_RNA_COL_SPACEX);
3817}
3818
3819static int outliner_width(SpaceOutliner *space_outliner,
3820 int max_tree_width,
3821 float right_column_width)
3822{
3823 if (space_outliner->outlinevis == SO_DATA_API) {
3824 return outliner_data_api_buttons_start_x(max_tree_width) + OL_RNA_COL_SIZEX +
3825 10 * UI_SCALE_FAC;
3826 }
3827 return max_tree_width + right_column_width;
3828}
3829
3831 SpaceOutliner *space_outliner,
3832 int tree_width,
3833 int tree_height,
3834 float right_column_width)
3835{
3836 int sizex = outliner_width(space_outliner, tree_width, right_column_width);
3837 int sizey = tree_height;
3838
3839 /* Extend size to allow for horizontal scroll-bar and extra offset. */
3840 sizey += V2D_SCROLL_HEIGHT + OL_Y_OFFSET;
3841
3842 ui::view2d_totRect_set(&region->v2d, sizex, sizey);
3843}
3844
3846
3847/* -------------------------------------------------------------------- */
3852
3853void draw_outliner(const bContext *C, bool do_rebuild)
3854{
3855 Main *mainvar = CTX_data_main(C);
3856 WorkSpace *workspace = CTX_wm_workspace(C);
3857 ARegion *region = CTX_wm_region(C);
3858 View2D *v2d = &region->v2d;
3859 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
3860 ui::Block *block;
3861 TreeElement *te_edit = nullptr;
3862
3863 TreeViewContext tvc;
3865
3866 /* FIXME(@ideasman42): There is an order of initialization problem here between
3867 * `v2d->cur` & `v2d->tot` where this function reads from `v2d->cur` for the scroll position
3868 * but may reset the scroll position *without* drawing into the clamped position.
3869 *
3870 * The `on_scroll` argument is used for an optional second draw pass.
3871 *
3872 * See `USE_OUTLINER_DRAW_CLAMPS_SCROLL_HACK` & #128346 for a full description. */
3873
3874 if (do_rebuild) {
3876 mainvar, workspace, tvc.scene, tvc.view_layer, space_outliner, region); /* Always. */
3877
3878 /* If global sync select is dirty, flag other outliners. */
3881 }
3882
3883 /* Sync selection state from view layer. */
3884 if (space_outliner->flag & SO_SYNC_SELECT) {
3885 if (!ELEM(space_outliner->outlinevis,
3890 {
3891 short idcode = 0;
3892 if (outliner_sync_selection(C, tvc, space_outliner, idcode) &&
3893 (space_outliner->flag & SO_SCROLL_TO_ACTIVE))
3894 {
3895 outliner_scroll_to_active(space_outliner, region, idcode);
3896 }
3897 }
3898 }
3899 }
3900
3901 /* Force display to pixel coords. */
3903 /* Set matrix for 2D-view controls. */
3905
3906 /* Only show mode column in View Layers and Scenes view. */
3907 const bool use_mode_column = outliner_shows_mode_column(*space_outliner);
3908 const bool use_warning_column = outliner_has_element_warnings(*space_outliner);
3909
3910 /* Draw outliner stuff (background, hierarchy lines and names). */
3911 const float right_column_width = outliner_right_columns_width(space_outliner);
3912 outliner_back(region);
3913 block = block_begin(C, region, __func__, ui::EmbossType::Emboss);
3914 outliner_draw_tree(block,
3915 tvc,
3916 region,
3917 space_outliner,
3918 right_column_width,
3919 use_mode_column,
3920 use_warning_column,
3921 &te_edit);
3922
3923 /* Compute outliner dimensions after it has been drawn. */
3924 int tree_width, tree_height;
3925 outliner_tree_dimensions(space_outliner, &tree_width, &tree_height);
3926
3927 /* Default to no emboss for outliner UI. */
3928 block_emboss_set(block, ui::EmbossType::NoneOrStatus);
3929
3930 if (space_outliner->outlinevis == SO_DATA_API) {
3931 int buttons_start_x = outliner_data_api_buttons_start_x(tree_width);
3932 /* draw rna buttons */
3933 outliner_draw_separator(region, buttons_start_x);
3934 outliner_draw_separator(region, buttons_start_x + OL_RNA_COL_SIZEX);
3935
3936 block_emboss_set(block, ui::EmbossType::Emboss);
3937 outliner_draw_rnabuts(block, region, space_outliner, buttons_start_x);
3938 block_emboss_set(block, ui::EmbossType::NoneOrStatus);
3939 }
3940 else if (ELEM(space_outliner->outlinevis, SO_ID_ORPHANS, SO_LIBRARIES)) {
3941 outliner_draw_userbuts(block, region, space_outliner);
3942 }
3943 else if (space_outliner->outlinevis == SO_OVERRIDES_LIBRARY) {
3944 const int x = region->v2d.cur.xmax - right_column_width;
3945 outliner_draw_separator(region, x);
3947 block_emboss_set(block, ui::EmbossType::Emboss);
3948 block_flag_enable(block, ui::BLOCK_NO_DRAW_OVERRIDDEN_STATE);
3950 block, region, space_outliner, &space_outliner->runtime->tree, x);
3951 block_emboss_set(block, ui::EmbossType::NoneOrStatus);
3952 }
3953 else if (space_outliner->lib_override_view_mode == SO_LIB_OVERRIDE_VIEW_HIERARCHIES) {
3955 mainvar, block, region, space_outliner, &space_outliner->runtime->tree, x);
3956 }
3957 }
3958 else if (right_column_width > 0.0f) {
3959 /* draw restriction columns */
3960 RestrictPropertiesActive props_active;
3961 memset(&props_active, 1, sizeof(RestrictPropertiesActive));
3963 *tvc.bmain,
3964 tvc.scene,
3965 tvc.view_layer,
3966 region,
3967 space_outliner,
3968 &space_outliner->runtime->tree,
3969 props_active);
3970
3971 /* For View Layer and Scenes, draw the optional users column as the rightmost column. */
3972 if (ELEM(space_outliner->outlinevis, SO_VIEW_LAYER, SO_SCENES) &&
3973 (space_outliner->flag & SO_USERS_COLUMN))
3974 {
3975 outliner_draw_userbuts(block, region, space_outliner);
3976 }
3977 }
3978
3979 /* Draw mode icons */
3980 if (use_mode_column) {
3981 outliner_draw_mode_column(block, tvc, space_outliner);
3982 }
3983
3984 /* Draw warning icons */
3985 if (use_warning_column) {
3986 outliner_draw_warning_column(block, space_outliner, use_mode_column);
3987 }
3988
3989 block_emboss_set(block, ui::EmbossType::Emboss);
3990
3991 /* Draw edit buttons if necessary. */
3992 if (te_edit) {
3993 outliner_buttons(C, block, region, right_column_width, te_edit);
3994 }
3995
3996 block_end(C, block);
3997 block_draw(C, block);
3998
3999 /* Update total viewable region. */
4001 region, space_outliner, tree_width, tree_height, right_column_width);
4002}
4003
4005
4006} // namespace ed::outliner
4007
4012
4014{
4015 return !((space_outliner->outlinevis == SO_OVERRIDES_LIBRARY) &&
4017}
4018
4019} // namespace blender
Functions to deal with Armatures.
C++ functions to deal with Armature collections (i.e. the successor of bone layers).
Functions to insert, delete or modify keyframes.
Blender kernel action and pose functionality.
support for deformation groups and hooks.
Low-level operations for grease pencil.
General operations, lookup, etc. for blender objects.
File and directory operations.
#define FILE_MAX
#define STRNCPY_UTF8(dst, src)
#define CTX_N_(context, msgid)
#define TIP_(msgid)
#define BLT_I18NCONTEXT_OPERATOR_DEFAULT
#define ID_FAKE_USERS(id)
Definition DNA_ID.h:658
#define ID_IS_OVERRIDE_LIBRARY_REAL(_id)
Definition DNA_ID.h:729
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define MAX_ID_NAME
Definition DNA_ID.h:367
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
#define INDEX_ID_MAX
Definition DNA_ID.h:1362
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:736
#define ID_NLA
Object groups, one object can be in many groups at once.
Object is a sort of wrapper for general info.
#define OB_TYPE_IS_GEOMETRY(_type)
#define OB_DATA_SUPPORT_EDITMODE(_type)
#define UI_SCALE_FAC
#define UI_INV_SCALE_FAC
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_FSTYLE_WIDGET
#define UI_UNIT_X
#define ICON_DEFAULT_HEIGHT
#define V2D_SCROLL_HEIGHT
Definition UI_view2d.hh:78
#define V2D_SCROLL_WIDTH
Definition UI_view2d.hh:79
#define NC_ID
Definition WM_types.hh:408
#define ND_DATA
Definition WM_types.hh:552
#define ND_RENDER_OPTIONS
Definition WM_types.hh:454
#define NC_ANIMATION
Definition WM_types.hh:401
#define NC_SCENE
Definition WM_types.hh:391
#define ND_MODIFIER
Definition WM_types.hh:503
#define NA_EDITED
Definition WM_types.hh:634
#define NC_MATERIAL
Definition WM_types.hh:393
#define NC_IMAGE
Definition WM_types.hh:397
#define ND_ARMATURE_STRUCTURE
Definition WM_types.hh:501
#define NC_GPENCIL
Definition WM_types.hh:412
#define NC_TEXTURE
Definition WM_types.hh:394
#define ND_BONE_COLLECTION
Definition WM_types.hh:515
#define NA_RENAME
Definition WM_types.hh:638
#define ND_BONE_SELECT
Definition WM_types.hh:491
#define NC_OBJECT
Definition WM_types.hh:392
#define ND_ANIMCHAN
Definition WM_types.hh:539
#define NC_SPACE
Definition WM_types.hh:405
#define NA_SELECTED
Definition WM_types.hh:639
#define ND_SPACE_OUTLINER
Definition WM_types.hh:570
#define UNPACK4(a)
#define ELEM(...)
#define STREQ(a, b)
#define CLAMP_MIN(a, b)
constexpr const char * c_str() const
constexpr bool is_empty() const
virtual StringRefNull get_warning() const
#define offsetof(t, d)
#define layer
#define floor
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
bool autokeyframe_property(bContext *C, Scene *scene, PointerRNA *ptr, PropertyRNA *prop, int rnaindex, float cfra, bool only_if_property_keyed)
void pose_bone_descendent_iterator(Object &pose_ob, bPoseChannel &pchan, FunctionRef< void(bPoseChannel &child_bone)> callback)
void all_open(const SpaceOutliner &space_outliner, const ConstVisitorFn visitor)
void all(const SpaceOutliner &space_outliner, const ConstVisitorFn visitor)
static void outliner_draw_hierarchy_lines(SpaceOutliner *space_outliner, ListBaseT< TreeElement > *lb, const TreeViewContext &tvc, int startx, int *starty)
static void outliner_draw_rnabuts(ui::Block *block, ARegion *region, SpaceOutliner *space_outliner, int sizex)
static void outliner_collection_set_flag_recursive_fn(bContext *C, LayerCollection *layer_collection, Collection *collection, const char *propname)
static void outliner_restrict_properties_enable_layer_collection_set(PointerRNA *layer_collection_ptr, PointerRNA *collection_ptr, RestrictProperties *props, RestrictPropertiesActive *props_active)
static void restrictbutton_gp_layer_flag_fn(bContext *C, void *poin, void *)
eOLDrawState tree_element_type_active_state_get(const TreeViewContext &tvc, const TreeElement *te, const TreeStoreElem *tselem)
static StringRefNull outliner_draw_get_warning_tree_element(const SpaceOutliner &space_outliner, const TreeElement *te)
static bool is_object_data_in_editmode(const ID *id, const Object *obact)
static void outliner_icon_background_colors(float icon_color[4], float icon_border[4])
bool outliner_is_collection_tree_element(const TreeElement *te)
static bool subtree_contains_object(ListBaseT< TreeElement > *lb)
static void outliner_update_viewable_area(ARegion *region, SpaceOutliner *space_outliner, int tree_width, int tree_height, float right_column_width)
static void outliner_buttons(const bContext *C, ui::Block *block, ARegion *region, const float restrict_column_width, TreeElement *te)
static void outliner_tree_dimensions_impl(SpaceOutliner *space_outliner, ListBaseT< TreeElement > *lb, int *width, int *height)
static void outliner_draw_overrides_restrictbuts(Main *bmain, ui::Block *block, const ARegion *region, const SpaceOutliner *space_outliner, const ListBaseT< TreeElement > *lb, const int x)
static void outliner_draw_active_indicator(const float minx, const float miny, const float maxx, const float maxy, const float icon_color[4], const float icon_border[4])
static void namebutton_fn(bContext *C, TreeStoreElem *tselem, const char *oldname)
float outliner_right_columns_width(const SpaceOutliner *space_outliner)
static void outliner_draw_highlights(const ARegion *region, const SpaceOutliner *space_outliner, const float col_selection[4], const float col_active[4], const float col_highlight[4], const float col_searchmatch[4], int, int *io_start_y)
static int outliner_data_api_buttons_start_x(int max_tree_width)
static void outliner_draw_warning_tree_element(ui::Block *block, const SpaceOutliner *space_outliner, const StringRef warning_msg, const bool use_mode_column, const int te_ys)
void tree_element_activate(bContext *C, const TreeViewContext &tvc, TreeElement *te, eOLSetState set, bool handle_all_types)
static void outliner_draw_iconrow_doit(ui::Block *block, TreeElement *te, int xmax, int *offsx, int ys, float alpha_fac, const eOLDrawState active, const int num_elements)
TreeElementIcon tree_element_get_icon(TreeStoreElem *tselem, TreeElement *te)
static void outliner__object_set_flag_recursive_fn(bContext *C, void *poin, void *poin2)
static bool outliner_collection_is_isolated(Scene *scene, const LayerCollection *layer_collection_cmp, const Collection *collection_cmp, const bool value_cmp, PropertyRNA *layer_or_collection_prop, LayerCollection *layer_collection, Collection *collection)
static bool outliner_but_identity_cmp_context_id_fn(const ui::Button *a, const ui::Button *b)
static void outliner_draw_restrictbuts(ui::Block *block, const Main &bmain, Scene *scene, ViewLayer *view_layer, ARegion *region, SpaceOutliner *space_outliner, ListBaseT< TreeElement > *lb, RestrictPropertiesActive props_active_parent)
void outliner_scroll_to_active(SpaceOutliner *space_outliner, ARegion *region, short idcode)
static void outliner_draw_mode_column(ui::Block *block, TreeViewContext &tvc, SpaceOutliner *space_outliner)
static void outliner_draw_hierarchy_lines_recursive(uint pos, SpaceOutliner *space_outliner, ListBaseT< TreeElement > *lb, const TreeViewContext &tvc, int startx, const uchar col[4], bool draw_grayed_out, int *starty)
static void restrictbutton_bone_visibility_fn(bContext *C, void *poin, void *poin2)
static void outliner_object_set_flag_recursive_fn(bContext *C, Base *base, Object *ob, const char *propname)
void outliner_item_mode_toggle(bContext *C, const TreeViewContext &tvc, TreeElement *te, bool do_extend)
static bool tselem_draw_icon(ui::Block *block, int xmax, float x, float y, TreeStoreElem *tselem, TreeElement *te, float alpha, const bool is_clickable, const int num_elements)
void outliner_viewcontext_init(const bContext *C, TreeViewContext *tvc)
bool outliner_is_element_in_view(const TreeElement *te, const View2D *v2d)
static void restrictbutton_ebone_select_fn(bContext *C, void *poin, void *poin2)
Collection * outliner_collection_from_tree_element(const TreeElement *te)
int tree_element_id_type_to_index(TreeElement *te)
static void outliner_layer_or_collection_pointer_create(Scene *scene, LayerCollection *layer_collection, Collection *collection, PointerRNA *ptr)
static void view_layer__layer_collection_set_flag_recursive_fn(bContext *C, void *poin, void *poin2)
static void outliner_draw_separator(ARegion *region, const int x)
static int outliner_width(SpaceOutliner *space_outliner, int max_tree_width, float right_column_width)
static void outliner_draw_warning_column(ui::Block *block, const SpaceOutliner *space_outliner, const bool use_mode_column)
static StringRefNull outliner_draw_get_warning_tree_element_subtree(const TreeElement *parent_te)
static void outliner_draw_iconrow(ui::Block *block, const uiFontStyle *fstyle, const TreeViewContext &tvc, SpaceOutliner *space_outliner, ListBaseT< TreeElement > *lb, int level, int xmax, int *offsx, int ys, float alpha_fac, bool in_bone_hierarchy, const bool is_grease_pencil_node_hierarchy, MergedIconRow *merged)
bool outliner_sync_selection(const bContext *C, const TreeViewContext &tvc, SpaceOutliner *space_outliner, short &idcode)
static void outliner_draw_tree(ui::Block *block, const TreeViewContext &tvc, ARegion *region, SpaceOutliner *space_outliner, const float right_column_width, const bool use_mode_column, const bool use_warning_column, TreeElement **te_edit)
TreeElementT * tree_element_cast(const TreeElement *te)
static void outliner_back(ARegion *region)
static void scenes__collection_set_flag_recursive_fn(bContext *C, void *poin, void *poin2)
static void outliner_draw_mode_column_toggle(ui::Block *block, const TreeViewContext &tvc, TreeElement *te, const bool lock_object_modes)
TreeElement * outliner_find_tree_element(ListBaseT< TreeElement > *lb, const TreeStoreElem *store_elem)
static void outliner_mode_toggle_fn(bContext *C, void *tselem_poin, void *)
static void outliner_restrict_properties_enable_collection_set(PointerRNA *collection_ptr, RestrictProperties *props, RestrictPropertiesActive *props_active)
static void restrictbutton_bone_select_fn(bContext *C, void *poin, void *poin2)
void outliner_collection_isolate_flag(const Main &bmain, Scene *scene, ViewLayer *view_layer, LayerCollection *layer_collection, Collection *collection, PropertyRNA *layer_or_collection_prop, const char *propname, const bool value)
static void restrictbutton_r_lay_fn(bContext *C, void *poin, void *)
static void outliner_draw_userbuts(ui::Block *block, const ARegion *region, const SpaceOutliner *space_outliner)
static void outliner_draw_hierarchy_line(const uint pos, const int x, const int y1, const int y2, const bool draw_dashed)
static std::string user_tooltip_func(bContext *, void *argN, const StringRef)
static void outliner_draw_tree_element(ui::Block *block, const uiFontStyle *fstyle, const TreeViewContext &tvc, ARegion *region, SpaceOutliner *space_outliner, TreeElement *te, bool draw_grayed_out, int startx, int *starty, const float restrict_column_width, TreeElement **te_edit)
void outliner_tree_dimensions(SpaceOutliner *space_outliner, int *r_width, int *r_height)
static void outliner_draw_overrides_rna_buts(ui::Block *block, const ARegion *region, const SpaceOutliner *space_outliner, const ListBaseT< TreeElement > *lb, const int x)
static bool element_should_draw_faded(const TreeViewContext &tvc, const TreeElement *te, const TreeStoreElem *tselem)
static void restrictbutton_ebone_visibility_fn(bContext *C, void *poin, void *poin2)
bool outliner_has_element_warnings(const SpaceOutliner &space_outliner)
static void view_layer__collection_set_flag_recursive_fn(bContext *C, void *poin, void *poin2)
static void outliner_set_subtree_coords(TreeElement *te)
static void outliner__base_set_flag_recursive_fn(bContext *C, void *poin, void *poin2)
bool outliner_shows_mode_column(const SpaceOutliner &space_outliner)
eOLDrawState tree_element_active_state_get(const TreeViewContext &tvc, const TreeElement *te, const TreeStoreElem *tselem)
void outliner_build_tree(Main *mainvar, WorkSpace *workspace, Scene *scene, ViewLayer *view_layer, SpaceOutliner *space_outliner, ARegion *region)
static void restrictbutton_recursive_bone(Bone *bone_parent, eBone_Flag flag, bool set_flag)
void draw_outliner(const bContext *C, bool do_rebuild)
static void outliner_base_or_object_pointer_create(const Main &bmain, Scene *scene, ViewLayer *view_layer, Collection *collection, Object *ob, PointerRNA *ptr)
static void outliner_collection_set_flag_recursive(const Main &bmain, Scene *scene, ViewLayer *view_layer, LayerCollection *layer_collection, Collection *collection, PropertyRNA *layer_or_collection_prop, PropertyRNA *base_or_object_prop, const bool value)
static void restrictbutton_recursive_ebone(bArmature *arm, EditBone *ebone_parent, eBone_Flag flag, bool set_flag)
static bool outliner_restrict_properties_collection_set(Scene *scene, TreeElement *te, PointerRNA *collection_ptr, PointerRNA *layer_collection_ptr, RestrictProperties *props, RestrictPropertiesActive *props_active)
static BIFIconID tree_element_get_icon_from_id(const ID *id)
static void outliner_draw_struct_marks(ARegion *region, SpaceOutliner *space_outliner, ListBaseT< TreeElement > *lb, int *starty)
void get_color_4ubv(int colorid, unsigned char col[4])
void get_color_3fv(int colorid, float col[3])
void get_color_4fv(int colorid, float col[4])
void get_color_shade_4fv(int colorid, int offset, float col[4])
const bTheme * theme_get()
void get_color_blend_3ubv(int colorid1, int colorid2, float fac, unsigned char col[3])
void get_color_blend_4f(int colorid1, int colorid2, float fac, float r_col[4])
void get_color_3ubv(int colorid, unsigned char col[3])
int icon_from_object_type(const Object *object)
void view2d_view_ortho(const View2D *v2d)
Definition view2d.cc:1080
void view2d_totRect_set(View2D *v2d, int width, int height)
Definition view2d.cc:1021
int fontstyle_string_width(const uiFontStyle *fs, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
bool icon_get_theme_color(int icon_id, unsigned char color[4])
int icon_from_object_mode(int mode)
@ BLOCK_NO_DRAW_OVERRIDDEN_STATE
void button_disable(Button *but, const char *disabled_hint)
void draw_roundbox_aa(const rctf *rect, bool filled, float rad, const float color[4])
void fontstyle_draw_simple(const uiFontStyle *fs, float x, float y, const char *str, const uchar col[4])
void draw_roundbox_4fv_ex(const rctf *rect, const float inner1[4], const float inner2[4], float shade_dir, const float outline[4], float outline_width, float rad)
void icon_draw_alpha(float x, float y, int icon_id, float alpha)
int icon_from_library(const ID *id)
void draw_roundbox_4fv(const rctf *rect, bool filled, float rad, const float col[4])
BMesh Iterators.
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BKE_object_defgroup_unique_name(bDeformGroup *dg, Object *ob)
Definition deform.cc:758
void BKE_annotations_layer_active_set(struct bGPdata *gpd, struct bGPDlayer *active)
@ SO_FILTER_NO_VIEW_LAYERS
@ SO_FILTER_NO_COLLECTION
void immUniformThemeColorBlend(int color_id1, int color_id2, float fac)
char * STRNCPY(char(&dst)[N], const char *src)
void immEnd()
bool ED_outliner_support_searching(const SpaceOutliner *space_outliner)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
WorkSpace * CTX_wm_workspace(const bContext *C)
SpaceOutliner * CTX_wm_space_outliner(const bContext *C)
struct ParticleSystem * psys_get_current(struct Object *ob)
Definition particle.cc:571
MINLINE int round_fl_to_int(float a)
PointerRNA RNA_id_pointer_create(ID *id)
void immUniform2f(const char *name, float x, float y)
@ BASE_ENABLED_AND_VISIBLE_IN_DEFAULT_VIEWPORT
bool ED_armature_ebone_is_child_recursive(EditBone *ebone_parent, EditBone *ebone_child)
GPUVertFormat * immVertexFormat()
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:404
void immThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset)
void immBegin(GPUPrimType, uint vertex_len)
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
wmWindow * CTX_wm_window(const bContext *C)
bool ED_outliner_select_sync_is_dirty(const bContext *C)
MINLINE int max_ii(int a, int b)
@ TH_SELECT_HIGHLIGHT
@ TH_SELECTED_OBJECT
int ED_file_extension_icon(const char *path)
Definition filelist.cc:1946
bool BKE_layer_collection_has_layer_collection(LayerCollection *lc_parent, LayerCollection *lc_child)
bool BKE_lib_override_library_is_system_defined(const Main *bmain, const ID *id)
void BKE_keyblock_rename(Main &bmain, Key *key, KeyBlock *kb, const char *newname)
Definition key.cc:1916
void MEM_delete_void(void *vmemh)
void BKE_view_layer_need_resync_tag(ViewLayer *view_layer)
@ LIBOVERRIDE_FLAG_SYSTEM_DEFINED
Definition DNA_ID.h:308
void immUnbindProgram()
@ TSE_LIBRARY_OVERRIDE_BASE
@ TSE_SCENE_COLLECTION_BASE
@ TSE_LIBRARY_OVERRIDE_OPERATION
ViewLayer * CTX_data_view_layer(const bContext *C)
void GPU_line_width(float width)
Definition gpu_state.cc:151
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
@ SO_RESTRICT_INDIRECT_ONLY
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
Definition main.cc:1058
void ED_armature_bone_rename(Main *bmain, bArmature *arm, const char *oldnamep, const char *newnamep)
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
bool BKE_main_collection_sync_remap(const Main *bmain)
PropertyType RNA_property_type(PropertyRNA *prop)
void BLI_uniquename(const ListBase *list, void *vlink, const char *defname, char delim, int name_offset, size_t name_maxncpy) ATTR_NONNULL(1
void immUniform1f(const char *name, float x)
void immVertex2f(uint attr_id, float x, float y)
unsigned char uchar
Definition BKE_text.h:58
@ PROP_POINTER
Definition RNA_types.hh:215
void GPU_viewport_size_get_f(float coords[4])
Definition gpu_state.cc:258
void DEG_id_tag_update(ID *id, unsigned int flags)
float BKE_scene_frame_get(const Scene *scene)
Definition scene.cc:2595
@ OB_MODE_PARTICLE_EDIT
BMesh const char void * data
@ LAYER_COLLECTION_EXCLUDE
@ GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR
void GPU_scissor_get(int coords[4])
Definition gpu_state.cc:253
void ED_undo_push(bContext *C, const char *str, UndoEncodeHints hints=UndoEncodeHints(0))
Definition ed_undo.cc:103
void BKE_view_layer_rename(Main *bmain, Scene *scene, ViewLayer *view_layer, const char *newname)
bool BKE_object_data_is_in_editmode(const Object *ob, const ID *id)
Definition object.cc:1932
int BKE_idtype_idcode_to_index(short idcode)
Definition idtype.cc:338
@ LAYER_COLLECTION_VISIBLE_VIEW_LAYER
int ED_outliner_icon_from_id(const ID &id)
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)
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
bool BKE_collection_has_collection(const Collection *parent, const Collection *collection)
void immUniformThemeColorShadeAlpha(int color_id, int color_offset, int alpha_offset)
@ LIBRARY_FLAG_IS_ARCHIVE
MINLINE void copy_v4_v4_uchar(unsigned char r[4], const unsigned char a[4])
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmMsgBus * CTX_wm_message_bus(const bContext *C)
bool RNA_struct_is_ID(const StructRNA *type)
int BIFIconID
Definition ED_asset.hh:30
bool BKE_object_is_in_editmode(const Object *ob)
Definition object.cc:1898
void BKE_library_filepath_set(Main *bmain, Library *lib, const char *filepath)
Definition library.cc:249
void GPU_scissor(int x, int y, int width, int height)
Definition gpu_state.cc:178
@ SO_LIB_OVERRIDE_VIEW_PROPERTIES
@ SO_LIB_OVERRIDE_VIEW_HIERARCHIES
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
bool ED_id_rename(Main &bmain, ID &id, StringRefNull name)
Main * CTX_data_main(const bContext *C)
@ INDEX_ID_GR
Definition DNA_ID.h:1342
@ INDEX_ID_OB
Definition DNA_ID.h:1341
@ INDEX_ID_GP
Definition DNA_ID.h:1338
void BLI_str_format_integer_unit(char dst[BLI_STR_FORMAT_INT32_INTEGER_UNIT_SIZE], int number_to_format) ATTR_NONNULL(1)
void ED_outliner_select_sync_flag_outliners(const bContext *C)
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ ID_RECALC_BASE_FLAGS
Definition DNA_ID.h:1104
ID_Type GS(const char *name)
Definition DNA_ID.h:410
Base * BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
@ ID_TAG_MISSING
Definition DNA_ID.h:870
@ ID_TAG_EXTRAUSER
Definition DNA_ID.h:881
bool BKE_object_is_child_recursive(const Object *ob_parent, const Object *ob_child)
Definition object.cc:4922
bool RNA_property_editable(const PointerRNA *ptr, PropertyRNA *prop)
void DEG_relations_tag_update(Main *bmain)
void ANIM_armature_bonecoll_name_set(Main &bmain, bArmature *armature, BoneCollection *bcoll, const char *name)
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
Scene * CTX_data_scene(const bContext *C)
@ ID_FLAG_FAKEUSER
Definition DNA_ID.h:770
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
void immUniform1i(const char *name, int x)
bool BKE_image_has_packedfile(const Image *image)
ReportList * CTX_wm_reports(const bContext *C)
void immUniformColor4ubv(const unsigned char rgba[4])
void immRectf(uint pos, float x1, float y1, float x2, float y2)
ARegion * CTX_wm_region(const bContext *C)
bool RNA_property_boolean_get_default(PointerRNA *ptr, PropertyRNA *prop)
void BLI_rctf_init(struct rctf *rect, float xmin, float xmax, float ymin, float ymax)
Definition rct.cc:418
#define SEARCHING_OUTLINER(sov)
#define OL_RNA_COL_SPACEX
#define OL_RNA_COLX
#define OL_Y_OFFSET
#define TREESTORE(a)
#define OL_RNA_COL_SIZEX
#define OL_TOG_USER_BUTS_USERS
#define TSELEM_OPEN(telm, sv)
unsigned char color[4]
float icon_border_intensity
ThemeUI tui
ThemeCollectionColor collection_color[8]
struct Object * object
ListBaseT< Bone > childbase
struct Collection * collection
bke::CollectionRuntime * runtime
ListBaseT< CollectionExport > exporters
ListBaseT< CollectionChild > children
ListBaseT< CollectionObject > gobject
CollectionColorTag color_tag
CollectionImport * importer
eID_OverrideLib_Flag flag
Definition DNA_ID.h:356
char name[258]
Definition DNA_ID.h:433
IDOverrideLibrary * override_library
Definition DNA_ID.h:495
eLayerCollection_Flag flag
struct Collection * collection
ListBaseT< LayerCollection > layer_collections
eLayerCollection_RuntimeFlag runtime_flag
char filepath[1024]
Definition DNA_ID.h:562
ListBaseT< Object > objects
Definition BKE_main.hh:388
StructRNA * type
Definition RNA_types.hh:63
struct Collection * master_collection
struct ToolSettings * toolsettings
eSpaceOutliner_Mode outlinevis
ed::outliner::SpaceOutliner_Runtime * runtime
eSpaceOutliner_Flag flag
eSpaceOutliner_Filter filter
eSpaceOutliner_LibOverrideViewMode lib_override_view_mode
eSpaceOutliner_ShowRestrictFlag show_restrict_flags
struct BLI_mempool * treestore
eTreeStoreElem_Flag flag
ListBaseT< LayerCollection > layer_collections
ListBaseT< EditBone > * edbo
ListBaseT< bGPDlayer > layers
bke::bNodeTreeType * typeinfo
ListBaseT< CollectionParent > parents
eOLDrawState active[INDEX_ID_MAX+OB_TYPE_MAX]
TreeElement * tree_element[INDEX_ID_MAX+OB_TYPE_MAX]
int num_elements[INDEX_ID_MAX+OB_TYPE_MAX]
ListBaseT< ed::outliner::TreeElement > tree
std::unique_ptr< AbstractTreeElement > abstract_element
wmEventModifierFlag modifier
Definition WM_types.hh:834
bke::WindowRuntime * runtime
#define WM_msg_publish_rna_prop(mbus, id_, data_, type_, prop_)