Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / space_outliner / outliner_draw.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2004 Blender Foundation.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): Joshua Leung
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file blender/editors/space_outliner/outliner_draw.c
29  *  \ingroup spoutliner
30  */
31
32 #include "DNA_anim_types.h"
33 #include "DNA_armature_types.h"
34 #include "DNA_gpencil_types.h"
35 #include "DNA_group_types.h"
36 #include "DNA_lamp_types.h"
37 #include "DNA_lightprobe_types.h"
38 #include "DNA_object_types.h"
39 #include "DNA_scene_types.h"
40 #include "DNA_sequence_types.h"
41
42 #include "BLI_math.h"
43 #include "BLI_blenlib.h"
44 #include "BLI_string_utils.h"
45 #include "BLI_utildefines.h"
46 #include "BLI_mempool.h"
47
48 #include "BLT_translation.h"
49
50 #include "BKE_context.h"
51 #include "BKE_deform.h"
52 #include "BKE_fcurve.h"
53 #include "BKE_global.h"
54 #include "BKE_layer.h"
55 #include "BKE_library.h"
56 #include "BKE_main.h"
57 #include "BKE_modifier.h"
58 #include "BKE_report.h"
59 #include "BKE_scene.h"
60 #include "BKE_object.h"
61
62 #include "DEG_depsgraph.h"
63 #include "DEG_depsgraph_build.h"
64
65 #include "ED_armature.h"
66 #include "ED_keyframing.h"
67 #include "ED_object.h"
68 #include "ED_screen.h"
69
70 #include "WM_api.h"
71 #include "WM_types.h"
72
73 #include "GPU_immediate.h"
74
75 #include "UI_interface.h"
76 #include "UI_interface_icons.h"
77 #include "UI_resources.h"
78 #include "UI_view2d.h"
79
80 #include "RNA_access.h"
81
82 #include "outliner_intern.h"
83
84 /* disable - this is far too slow - campbell */
85 // #define USE_GROUP_SELECT
86
87 /* ****************************************************** */
88 /* Tree Size Functions */
89
90 static void outliner_height(SpaceOops *soops, ListBase *lb, int *h)
91 {
92         TreeElement *te = lb->first;
93         while (te) {
94                 TreeStoreElem *tselem = TREESTORE(te);
95                 if (TSELEM_OPEN(tselem, soops))
96                         outliner_height(soops, &te->subtree, h);
97                 (*h) += UI_UNIT_Y;
98                 te = te->next;
99         }
100 }
101
102 #if 0  // XXX this is currently disabled until te->xend is set correctly
103 static void outliner_width(SpaceOops *soops, ListBase *lb, int *w)
104 {
105         TreeElement *te = lb->first;
106         while (te) {
107 //              TreeStoreElem *tselem = TREESTORE(te);
108
109                 // XXX fixme... te->xend is not set yet
110                 if (!TSELEM_OPEN(tselem, soops)) {
111                         if (te->xend > *w)
112                                 *w = te->xend;
113                 }
114                 outliner_width(soops, &te->subtree, w);
115                 te = te->next;
116         }
117 }
118 #endif
119
120 static void outliner_rna_width(SpaceOops *soops, ListBase *lb, int *w, int startx)
121 {
122         TreeElement *te = lb->first;
123         while (te) {
124                 TreeStoreElem *tselem = TREESTORE(te);
125                 // XXX fixme... (currently, we're using a fixed length of 100)!
126 #if 0
127                 if (te->xend) {
128                         if (te->xend > *w)
129                                 *w = te->xend;
130                 }
131 #endif
132                 if (startx + 100 > *w)
133                         *w = startx + 100;
134
135                 if (TSELEM_OPEN(tselem, soops))
136                         outliner_rna_width(soops, &te->subtree, w, startx + UI_UNIT_X);
137                 te = te->next;
138         }
139 }
140
141 /**
142  * The active object is only needed for reference.
143  */
144 static bool is_object_data_in_editmode(const ID *id, const Object *obact)
145 {
146         const short id_type = GS(id->name);
147         return (
148                 (obact && (obact->mode & OB_MODE_EDIT)) &&
149                 (id && OB_DATA_SUPPORT_EDITMODE(id_type)) &&
150                 (GS(((ID *)obact->data)->name) == id_type) &&
151                 BKE_object_data_is_in_editmode(id)
152         );
153 }
154
155 /* ****************************************************** */
156
157 static void restrictbutton_recursive_ebone(bContext *C, EditBone *ebone_parent, int flag, bool set_flag)
158 {
159         Object *obedit = CTX_data_edit_object(C);
160         bArmature *arm = obedit->data;
161         EditBone *ebone;
162
163         for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
164                 if (ED_armature_ebone_is_child_recursive(ebone_parent, ebone)) {
165                         if (set_flag) {
166                                 ebone->flag &= ~(BONE_TIPSEL | BONE_SELECTED | BONE_ROOTSEL);
167                                 ebone->flag |= flag;
168                         }
169                         else {
170                                 ebone->flag &= ~flag;
171                         }
172                 }
173         }
174 }
175
176 static void restrictbutton_recursive_bone(Bone *bone_parent, int flag, bool set_flag)
177 {
178         Bone *bone;
179         for (bone = bone_parent->childbase.first; bone; bone = bone->next) {
180                 if (set_flag) {
181                         bone->flag &= ~(BONE_TIPSEL | BONE_SELECTED | BONE_ROOTSEL);
182                         bone->flag |= flag;
183                 }
184                 else {
185                         bone->flag &= ~flag;
186                 }
187                 restrictbutton_recursive_bone(bone, flag, set_flag);
188         }
189
190 }
191
192 static void restrictbutton_r_lay_cb(bContext *C, void *poin, void *UNUSED(poin2))
193 {
194         WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, poin);
195 }
196
197 static void restrictbutton_modifier_cb(bContext *C, void *UNUSED(poin), void *poin2)
198 {
199         Object *ob = (Object *)poin2;
200
201         DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
202         WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
203 }
204
205 static void restrictbutton_bone_visibility_cb(bContext *C, void *UNUSED(poin), void *poin2)
206 {
207         Bone *bone = (Bone *)poin2;
208         if (bone->flag & BONE_HIDDEN_P)
209                 bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
210
211         if (CTX_wm_window(C)->eventstate->ctrl) {
212                 restrictbutton_recursive_bone(bone, BONE_HIDDEN_P, (bone->flag & BONE_HIDDEN_P) != 0);
213         }
214
215         WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
216 }
217
218 static void restrictbutton_bone_select_cb(bContext *C, void *UNUSED(poin), void *poin2)
219 {
220         Bone *bone = (Bone *)poin2;
221         if (bone->flag & BONE_UNSELECTABLE)
222                 bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
223
224         if (CTX_wm_window(C)->eventstate->ctrl) {
225                 restrictbutton_recursive_bone(bone, BONE_UNSELECTABLE, (bone->flag & BONE_UNSELECTABLE) != 0);
226         }
227
228         WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
229 }
230
231 static void restrictbutton_ebone_select_cb(bContext *C, void *UNUSED(poin), void *poin2)
232 {
233         EditBone *ebone = (EditBone *)poin2;
234
235         if (ebone->flag & BONE_UNSELECTABLE) {
236                 ebone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
237         }
238
239         if (CTX_wm_window(C)->eventstate->ctrl) {
240                 restrictbutton_recursive_ebone(C, ebone, BONE_UNSELECTABLE, (ebone->flag & BONE_UNSELECTABLE) != 0);
241         }
242
243         WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
244 }
245
246 static void restrictbutton_ebone_visibility_cb(bContext *C, void *UNUSED(poin), void *poin2)
247 {
248         EditBone *ebone = (EditBone *)poin2;
249         if (ebone->flag & BONE_HIDDEN_A) {
250                 ebone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
251         }
252
253         if (CTX_wm_window(C)->eventstate->ctrl) {
254                 restrictbutton_recursive_ebone(C, ebone, BONE_HIDDEN_A, (ebone->flag & BONE_HIDDEN_A) != 0);
255         }
256
257         WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
258 }
259
260 static void restrictbutton_gp_layer_flag_cb(bContext *C, void *UNUSED(poin), void *UNUSED(poin2))
261 {
262         WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
263 }
264
265 static void restrictbutton_id_user_toggle(bContext *UNUSED(C), void *poin, void *UNUSED(poin2))
266 {
267         ID *id = (ID *)poin;
268
269         BLI_assert(id != NULL);
270
271         if (id->flag & LIB_FAKEUSER) {
272                 id_us_plus(id);
273         }
274         else {
275                 id_us_min(id);
276         }
277 }
278
279 static void namebutton_cb(bContext *C, void *tsep, char *oldname)
280 {
281         Main *bmain = CTX_data_main(C);
282         SpaceOops *soops = CTX_wm_space_outliner(C);
283         Object *obedit = CTX_data_edit_object(C);
284         BLI_mempool *ts = soops->treestore;
285         TreeStoreElem *tselem = tsep;
286
287         if (ts && tselem) {
288                 TreeElement *te = outliner_find_tree_element(&soops->tree, tselem);
289
290                 if (tselem->type == 0) {
291                         BLI_libblock_ensure_unique_name(bmain, tselem->id->name);
292
293                         switch (GS(tselem->id->name)) {
294                                 case ID_MA:
295                                         WM_event_add_notifier(C, NC_MATERIAL, NULL); break;
296                                 case ID_TE:
297                                         WM_event_add_notifier(C, NC_TEXTURE, NULL); break;
298                                 case ID_IM:
299                                         WM_event_add_notifier(C, NC_IMAGE, NULL); break;
300                                 case ID_SCE:
301                                         WM_event_add_notifier(C, NC_SCENE, NULL); break;
302                                 default:
303                                         WM_event_add_notifier(C, NC_ID | NA_RENAME, NULL); break;
304                         }
305                         /* Check the library target exists */
306                         if (te->idcode == ID_LI) {
307                                 Library *lib = (Library *)tselem->id;
308                                 char expanded[FILE_MAX];
309
310                                 BKE_library_filepath_set(bmain, lib, lib->name);
311
312                                 BLI_strncpy(expanded, lib->name, sizeof(expanded));
313                                 BLI_path_abs(expanded, bmain->name);
314                                 if (!BLI_exists(expanded)) {
315                                         BKE_reportf(CTX_wm_reports(C), RPT_ERROR,
316                                                     "Library path '%s' does not exist, correct this before saving", expanded);
317                                 }
318                                 else if (lib->id.tag & LIB_TAG_MISSING) {
319                                         BKE_reportf(CTX_wm_reports(C), RPT_INFO,
320                                                     "Library path '%s' is now valid, please reload the library", expanded);
321                                         lib->id.tag &= ~LIB_TAG_MISSING;
322                                 }
323                         }
324                 }
325                 else {
326                         switch (tselem->type) {
327                                 case TSE_DEFGROUP:
328                                         defgroup_unique_name(te->directdata, (Object *)tselem->id); //  id = object
329                                         break;
330                                 case TSE_NLA_ACTION:
331                                         BLI_libblock_ensure_unique_name(bmain, tselem->id->name);
332                                         break;
333                                 case TSE_EBONE:
334                                 {
335                                         bArmature *arm = (bArmature *)tselem->id;
336                                         if (arm->edbo) {
337                                                 EditBone *ebone = te->directdata;
338                                                 char newname[sizeof(ebone->name)];
339
340                                                 /* restore bone name */
341                                                 BLI_strncpy(newname, ebone->name, sizeof(ebone->name));
342                                                 BLI_strncpy(ebone->name, oldname, sizeof(ebone->name));
343                                                 ED_armature_bone_rename(obedit->data, oldname, newname);
344                                                 WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
345                                         }
346                                         break;
347                                 }
348
349                                 case TSE_BONE:
350                                 {
351                                         ViewLayer *view_layer = CTX_data_view_layer(C);
352                                         Scene *scene = CTX_data_scene(C);
353                                         bArmature *arm = (bArmature *)tselem->id;
354                                         Bone *bone = te->directdata;
355                                         char newname[sizeof(bone->name)];
356
357                                         /* always make current object active */
358                                         tree_element_active(C, scene, view_layer, soops, te, OL_SETSEL_NORMAL, true);
359
360                                         /* restore bone name */
361                                         BLI_strncpy(newname, bone->name, sizeof(bone->name));
362                                         BLI_strncpy(bone->name, oldname, sizeof(bone->name));
363                                         ED_armature_bone_rename(arm, oldname, newname);
364                                         WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
365                                         break;
366                                 }
367                                 case TSE_POSE_CHANNEL:
368                                 {
369                                         Scene *scene = CTX_data_scene(C);
370                                         ViewLayer *view_layer = CTX_data_view_layer(C);
371                                         Object *ob = (Object *)tselem->id;
372                                         bPoseChannel *pchan = te->directdata;
373                                         char newname[sizeof(pchan->name)];
374
375                                         /* always make current pose-bone active */
376                                         tree_element_active(C, scene, view_layer, soops, te, OL_SETSEL_NORMAL, true);
377
378                                         BLI_assert(ob->type == OB_ARMATURE);
379
380                                         /* restore bone name */
381                                         BLI_strncpy(newname, pchan->name, sizeof(pchan->name));
382                                         BLI_strncpy(pchan->name, oldname, sizeof(pchan->name));
383                                         ED_armature_bone_rename(ob->data, oldname, newname);
384                                         WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
385                                         break;
386                                 }
387                                 case TSE_POSEGRP:
388                                 {
389                                         Object *ob = (Object *)tselem->id; // id = object
390                                         bActionGroup *grp = te->directdata;
391
392                                         BLI_uniquename(&ob->pose->agroups, grp, CTX_DATA_(BLT_I18NCONTEXT_ID_ACTION, "Group"), '.',
393                                                        offsetof(bActionGroup, name), sizeof(grp->name));
394                                         WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
395                                         break;
396                                 }
397                                 case TSE_GP_LAYER:
398                                 {
399                                         bGPdata *gpd = (bGPdata *)tselem->id; // id = GP Datablock
400                                         bGPDlayer *gpl = te->directdata;
401
402                                         // XXX: name needs translation stuff
403                                         BLI_uniquename(&gpd->layers, gpl, "GP Layer", '.',
404                                                        offsetof(bGPDlayer, info), sizeof(gpl->info));
405                                         WM_event_add_notifier(C, NC_GPENCIL | ND_DATA, gpd);
406                                         break;
407                                 }
408                                 case TSE_R_LAYER:
409                                 {
410                                         Scene *scene = (Scene *)tselem->id;
411                                         ViewLayer *view_layer = te->directdata;
412
413                                         /* Restore old name. */
414                                         char newname[sizeof(view_layer->name)];
415                                         BLI_strncpy(newname, view_layer->name, sizeof(view_layer->name));
416                                         BLI_strncpy(view_layer->name, oldname, sizeof(view_layer->name));
417
418                                         /* Rename, preserving animation and compositing data. */
419                                         BKE_view_layer_rename(bmain, scene, view_layer, newname);
420                                         WM_event_add_notifier(C, NC_ID | NA_RENAME, NULL);
421                                         break;
422                                 }
423                                 case TSE_LAYER_COLLECTION:
424                                 {
425                                         BLI_libblock_ensure_unique_name(bmain, tselem->id->name);
426                                         WM_event_add_notifier(C, NC_ID | NA_RENAME, NULL);
427                                         break;
428                                 }
429                         }
430                 }
431                 tselem->flag &= ~TSE_TEXTBUT;
432         }
433 }
434
435 static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops, ListBase *lb)
436 {
437         uiBut *bt;
438         TreeElement *te;
439         TreeStoreElem *tselem;
440         Object *ob = NULL;
441
442         /* get RNA properties (once for speed) */
443         PropertyRNA *collection_prop_hide_viewport;
444         PropertyRNA *collection_prop_hide_select;
445         PropertyRNA *collection_prop_hide_render;
446         collection_prop_hide_select = RNA_struct_type_find_property(&RNA_Collection, "hide_select");
447         collection_prop_hide_viewport = RNA_struct_type_find_property(&RNA_Collection, "hide_viewport");
448         collection_prop_hide_render = RNA_struct_type_find_property(&RNA_Collection, "hide_render");
449         BLI_assert(collection_prop_hide_viewport &&
450                    collection_prop_hide_select &&
451                    collection_prop_hide_render);
452
453         for (te = lb->first; te; te = te->next) {
454                 tselem = TREESTORE(te);
455                 if (te->ys + 2 * UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {
456                         if (tselem->type == TSE_R_LAYER && (soops->outlinevis == SO_SCENES)) {
457                                 /* View layer render toggle. */
458                                 ViewLayer *view_layer = te->directdata;
459
460                                 UI_block_emboss_set(block, UI_EMBOSS_NONE);
461
462                                 bt = uiDefIconButBitS(block, UI_BTYPE_ICON_TOGGLE_N, VIEW_LAYER_RENDER, 0, ICON_RESTRICT_RENDER_OFF,
463                                                       (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X,
464                                                       UI_UNIT_Y, &view_layer->flag, 0, 0, 0, 0, TIP_("Use view layer for rendering"));
465                                 UI_but_func_set(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
466                                 UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
467
468                                 UI_block_emboss_set(block, UI_EMBOSS);
469                         }
470                         else if (tselem->type == TSE_MODIFIER) {
471                                 ModifierData *md = (ModifierData *)te->directdata;
472                                 ob = (Object *)tselem->id;
473
474                                 UI_block_emboss_set(block, UI_EMBOSS_NONE);
475                                 bt = uiDefIconButBitI(block, UI_BTYPE_ICON_TOGGLE_N, eModifierMode_Realtime, 0, ICON_RESTRICT_VIEW_OFF,
476                                                       (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X,
477                                                       UI_UNIT_Y, &(md->mode), 0, 0, 0, 0,
478                                                       TIP_("Restrict/Allow visibility in the 3D View"));
479                                 UI_but_func_set(bt, restrictbutton_modifier_cb, scene, ob);
480                                 UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
481
482                                 bt = uiDefIconButBitI(block, UI_BTYPE_ICON_TOGGLE_N, eModifierMode_Render, 0, ICON_RESTRICT_RENDER_OFF,
483                                                       (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X,
484                                                       UI_UNIT_Y, &(md->mode), 0, 0, 0, 0, TIP_("Restrict/Allow renderability"));
485                                 UI_but_func_set(bt, restrictbutton_modifier_cb, scene, ob);
486                                 UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
487
488                                 UI_block_emboss_set(block, UI_EMBOSS);
489                         }
490                         else if (tselem->type == TSE_POSE_CHANNEL) {
491                                 bPoseChannel *pchan = (bPoseChannel *)te->directdata;
492                                 Bone *bone = pchan->bone;
493                                 ob = (Object *)tselem->id;
494
495                                 UI_block_emboss_set(block, UI_EMBOSS_NONE);
496                                 bt = uiDefIconButBitI(block, UI_BTYPE_ICON_TOGGLE, BONE_HIDDEN_P, 0, ICON_RESTRICT_VIEW_OFF,
497                                                       (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X,
498                                                       UI_UNIT_Y, &(bone->flag), 0, 0, 0, 0,
499                                                       TIP_("Restrict/Allow visibility in the 3D View"));
500                                 UI_but_func_set(bt, restrictbutton_bone_visibility_cb, ob->data, bone);
501                                 UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
502
503                                 bt = uiDefIconButBitI(block, UI_BTYPE_ICON_TOGGLE, BONE_UNSELECTABLE, 0, ICON_RESTRICT_SELECT_OFF,
504                                                       (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X,
505                                                       UI_UNIT_Y, &(bone->flag), 0, 0, 0, 0,
506                                                       TIP_("Restrict/Allow selection in the 3D View"));
507                                 UI_but_func_set(bt, restrictbutton_bone_select_cb, ob->data, bone);
508                                 UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
509
510                                 UI_block_emboss_set(block, UI_EMBOSS);
511                         }
512                         else if (tselem->type == TSE_EBONE) {
513                                 EditBone *ebone = (EditBone *)te->directdata;
514
515                                 UI_block_emboss_set(block, UI_EMBOSS_NONE);
516                                 bt = uiDefIconButBitI(block, UI_BTYPE_ICON_TOGGLE, BONE_HIDDEN_A, 0, ICON_RESTRICT_VIEW_OFF,
517                                                       (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X,
518                                                       UI_UNIT_Y, &(ebone->flag), 0, 0, 0, 0,
519                                                       TIP_("Restrict/Allow visibility in the 3D View"));
520                                 UI_but_func_set(bt, restrictbutton_ebone_visibility_cb, NULL, ebone);
521                                 UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
522
523                                 bt = uiDefIconButBitI(block, UI_BTYPE_ICON_TOGGLE, BONE_UNSELECTABLE, 0, ICON_RESTRICT_SELECT_OFF,
524                                                       (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X,
525                                                       UI_UNIT_Y, &(ebone->flag), 0, 0, 0, 0,
526                                                       TIP_("Restrict/Allow selection in the 3D View"));
527                                 UI_but_func_set(bt, restrictbutton_ebone_select_cb, NULL, ebone);
528                                 UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
529
530                                 UI_block_emboss_set(block, UI_EMBOSS);
531                         }
532                         else if (tselem->type == TSE_GP_LAYER) {
533                                 bGPDlayer *gpl = (bGPDlayer *)te->directdata;
534
535                                 UI_block_emboss_set(block, UI_EMBOSS_NONE);
536
537                                 bt = uiDefIconButBitS(block, UI_BTYPE_ICON_TOGGLE, GP_LAYER_HIDE, 0, ICON_RESTRICT_VIEW_OFF,
538                                                       (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X,
539                                                       UI_UNIT_Y, &gpl->flag, 0, 0, 0, 0,
540                                                       TIP_("Restrict/Allow visibility in the 3D View"));
541                                 UI_but_func_set(bt, restrictbutton_gp_layer_flag_cb, NULL, gpl);
542                                 UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
543
544                                 bt = uiDefIconButBitS(block, UI_BTYPE_ICON_TOGGLE, GP_LAYER_LOCKED, 0, ICON_UNLOCKED,
545                                                       (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X,
546                                                       UI_UNIT_Y, &gpl->flag, 0, 0, 0, 0,
547                                                       TIP_("Restrict/Allow editing of strokes and keyframes in this layer"));
548                                 UI_but_func_set(bt, restrictbutton_gp_layer_flag_cb, NULL, gpl);
549                                 UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
550
551                                 /* TODO: visibility in renders */
552
553                                 UI_block_emboss_set(block, UI_EMBOSS);
554                         }
555                         else if (outliner_is_collection_tree_element(te)) {
556                                 LayerCollection *lc = (tselem->type == TSE_LAYER_COLLECTION) ? te->directdata : NULL;
557                                 Collection *collection = outliner_collection_from_tree_element(te);
558
559                                 UI_block_emboss_set(block, UI_EMBOSS_NONE);
560
561                                 if ((!lc || !(lc->flag & LAYER_COLLECTION_EXCLUDE)) &&
562                                     !(collection->flag & COLLECTION_IS_MASTER))
563                                 {
564                                         PointerRNA collection_ptr;
565                                         RNA_id_pointer_create(&collection->id, &collection_ptr);
566
567                                         bt = uiDefIconButR_prop(block, UI_BTYPE_ICON_TOGGLE, 0, ICON_RESTRICT_VIEW_OFF,
568                                                                 (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X,
569                                                                 UI_UNIT_Y, &collection_ptr, collection_prop_hide_viewport, -1, 0, 0, 0, 0, NULL);
570                                         UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
571
572                                         bt = uiDefIconButR_prop(block, UI_BTYPE_ICON_TOGGLE, 0, ICON_RESTRICT_RENDER_OFF,
573                                                                 (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X,
574                                                                 UI_UNIT_Y, &collection_ptr, collection_prop_hide_render, -1, 0, 0, 0, 0, NULL);
575                                         UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
576
577                                         bt = uiDefIconButR_prop(block, UI_BTYPE_ICON_TOGGLE, 0, ICON_RESTRICT_SELECT_OFF,
578                                                                 (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X,
579                                                                 UI_UNIT_Y, &collection_ptr, collection_prop_hide_select, -1, 0, 0, 0, 0, NULL);
580                                         UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
581                                 }
582
583                                 UI_block_emboss_set(block, UI_EMBOSS);
584                         }
585                 }
586
587                 if (TSELEM_OPEN(tselem, soops)) outliner_draw_restrictbuts(block, scene, ar, soops, &te->subtree);
588         }
589 }
590
591 static void outliner_draw_userbuts(uiBlock *block, ARegion *ar, SpaceOops *soops, ListBase *lb)
592 {
593         uiBut *bt;
594         TreeElement *te;
595         TreeStoreElem *tselem;
596
597         for (te = lb->first; te; te = te->next) {
598                 tselem = TREESTORE(te);
599                 if (te->ys + 2 * UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {
600                         if (tselem->type == 0) {
601                                 ID *id = tselem->id;
602                                 const char *tip = NULL;
603                                 int icon = ICON_NONE;
604                                 char buf[16] = "";
605                                 int but_flag = UI_BUT_DRAG_LOCK;
606
607                                 if (ID_IS_LINKED(id))
608                                         but_flag |= UI_BUT_DISABLED;
609
610                                 UI_block_emboss_set(block, UI_EMBOSS_NONE);
611
612                                 if (id->flag & LIB_FAKEUSER) {
613                                         icon = ICON_FILE_TICK;
614                                         tip  = TIP_("Data-block will be retained using a fake user");
615                                 }
616                                 else {
617                                         icon = ICON_X;
618                                         tip  = TIP_("Data-block has no users and will be deleted");
619                                 }
620                                 bt = uiDefIconButBitS(block, UI_BTYPE_TOGGLE, LIB_FAKEUSER, 1, icon,
621                                                       (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X, UI_UNIT_Y,
622                                                       &id->flag, 0, 0, 0, 0, tip);
623                                 UI_but_func_set(bt, restrictbutton_id_user_toggle, id, NULL);
624                                 UI_but_flag_enable(bt, but_flag);
625
626
627                                 BLI_str_format_int_grouped(buf, id->us);
628                                 bt = uiDefBut(block, UI_BTYPE_BUT, 1, buf,
629                                               (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys,
630                                               UI_UNIT_X, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0,
631                                               TIP_("Number of users of this data-block"));
632                                 UI_but_flag_enable(bt, but_flag);
633
634
635                                 bt = uiDefButBitS(block, UI_BTYPE_TOGGLE, LIB_FAKEUSER, 1, (id->flag & LIB_FAKEUSER) ? "F" : " ",
636                                                   (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X, UI_UNIT_Y,
637                                                   &id->flag, 0, 0, 0, 0,
638                                                   TIP_("Data-block has a 'fake' user which will keep it in the file "
639                                                        "even if nothing else uses it"));
640                                 UI_but_func_set(bt, restrictbutton_id_user_toggle, id, NULL);
641                                 UI_but_flag_enable(bt, but_flag);
642
643                                 UI_block_emboss_set(block, UI_EMBOSS);
644                         }
645                 }
646
647                 if (TSELEM_OPEN(tselem, soops)) outliner_draw_userbuts(block, ar, soops, &te->subtree);
648         }
649 }
650
651 static void outliner_draw_rnacols(ARegion *ar, int sizex)
652 {
653         View2D *v2d = &ar->v2d;
654
655         float miny = v2d->cur.ymin;
656         if (miny < v2d->tot.ymin) miny = v2d->tot.ymin;
657
658         glLineWidth(1.0f);
659
660         unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
661         immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
662         immUniformThemeColorShadeAlpha(TH_BACK, -15, -200);
663
664         immBegin(GWN_PRIM_LINES, 4);
665
666         immVertex2f(pos, sizex, v2d->cur.ymax);
667         immVertex2f(pos, sizex, miny);
668
669         immVertex2f(pos, sizex + OL_RNA_COL_SIZEX, v2d->cur.ymax);
670         immVertex2f(pos, sizex + OL_RNA_COL_SIZEX, miny);
671
672         immEnd();
673
674         immUnbindProgram();
675 }
676
677 static void outliner_draw_rnabuts(uiBlock *block, ARegion *ar, SpaceOops *soops, int sizex, ListBase *lb)
678 {
679         TreeElement *te;
680         TreeStoreElem *tselem;
681         PointerRNA *ptr;
682         PropertyRNA *prop;
683
684         for (te = lb->first; te; te = te->next) {
685                 tselem = TREESTORE(te);
686                 if (te->ys + 2 * UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {
687                         if (tselem->type == TSE_RNA_PROPERTY) {
688                                 ptr = &te->rnaptr;
689                                 prop = te->directdata;
690
691                                 if (!TSELEM_OPEN(tselem, soops)) {
692                                         if (RNA_property_type(prop) == PROP_POINTER) {
693                                                 uiBut *but = uiDefAutoButR(block, ptr, prop, -1, "", ICON_NONE, sizex, te->ys,
694                                                                            OL_RNA_COL_SIZEX, UI_UNIT_Y - 1);
695                                                 UI_but_flag_enable(but, UI_BUT_DISABLED);
696                                         }
697                                         else if (RNA_property_type(prop) == PROP_ENUM) {
698                                                 uiDefAutoButR(block, ptr, prop, -1, NULL, ICON_NONE, sizex, te->ys, OL_RNA_COL_SIZEX,
699                                                               UI_UNIT_Y - 1);
700                                         }
701                                         else {
702                                                 uiDefAutoButR(block, ptr, prop, -1, "", ICON_NONE, sizex, te->ys, OL_RNA_COL_SIZEX,
703                                                               UI_UNIT_Y - 1);
704                                         }
705                                 }
706                         }
707                         else if (tselem->type == TSE_RNA_ARRAY_ELEM) {
708                                 ptr = &te->rnaptr;
709                                 prop = te->directdata;
710
711                                 uiDefAutoButR(block, ptr, prop, te->index, "", ICON_NONE, sizex, te->ys, OL_RNA_COL_SIZEX,
712                                               UI_UNIT_Y - 1);
713                         }
714                 }
715
716                 if (TSELEM_OPEN(tselem, soops)) outliner_draw_rnabuts(block, ar, soops, sizex, &te->subtree);
717         }
718
719         UI_block_emboss_set(block, UI_EMBOSS);
720 }
721
722 static void outliner_buttons(const bContext *C, uiBlock *block, ARegion *ar, TreeElement *te)
723 {
724         uiBut *bt;
725         TreeStoreElem *tselem;
726         int spx, dx, len;
727
728         tselem = TREESTORE(te);
729
730         BLI_assert(tselem->flag & TSE_TEXTBUT);
731         /* If we add support to rename Sequence.
732          * need change this.
733          */
734
735         if (tselem->type == TSE_EBONE) len = sizeof(((EditBone *) 0)->name);
736         else if (tselem->type == TSE_MODIFIER) len = sizeof(((ModifierData *) 0)->name);
737         else if (tselem->id && GS(tselem->id->name) == ID_LI) len = sizeof(((Library *) 0)->name);
738         else len = MAX_ID_NAME - 2;
739
740         spx = te->xs + 1.8f * UI_UNIT_X;
741         dx = ar->v2d.cur.xmax - (spx + 3.2f * UI_UNIT_X);
742
743         bt = uiDefBut(block, UI_BTYPE_TEXT, OL_NAMEBUTTON, "", spx, te->ys, dx, UI_UNIT_Y - 1, (void *)te->name,
744                       1.0, (float)len, 0, 0, "");
745         UI_but_func_rename_set(bt, namebutton_cb, tselem);
746
747         /* returns false if button got removed */
748         if (false == UI_but_active_only(C, ar, block, bt)) {
749                 tselem->flag &= ~TSE_TEXTBUT;
750
751                 /* bad! (notifier within draw) without this, we don't get a refesh */
752                 WM_event_add_notifier(C, NC_SPACE | ND_SPACE_OUTLINER, NULL);
753         }
754 }
755
756 /* ****************************************************** */
757 /* Normal Drawing... */
758
759 /* make function calls a bit compacter */
760 struct DrawIconArg {
761         uiBlock *block;
762         ID *id;
763         float xmax, x, y, xb, yb;
764         float alpha;
765 };
766
767 static void tselem_draw_icon_uibut(struct DrawIconArg *arg, int icon)
768 {
769         /* restrict column clip... it has been coded by simply overdrawing, doesnt work for buttons */
770         if (arg->x >= arg->xmax) {
771                 glEnable(GL_BLEND);
772                 UI_icon_draw_alpha(arg->x, arg->y, icon, arg->alpha);
773                 glDisable(GL_BLEND);
774         }
775         else {
776                 uiBut *but = uiDefIconBut(arg->block, UI_BTYPE_LABEL, 0, icon, arg->xb, arg->yb, UI_UNIT_X, UI_UNIT_Y, NULL,
777                                           0.0, 0.0, 1.0, arg->alpha,
778                                           (arg->id && ID_IS_LINKED(arg->id)) ? arg->id->lib->name : "");
779
780                 if (arg->id)
781                         UI_but_drag_set_id(but, arg->id);
782         }
783
784 }
785
786 static void UNUSED_FUNCTION(tselem_draw_gp_icon_uibut)(struct DrawIconArg *arg, ID *id, bGPDlayer *gpl)
787 {
788         /* restrict column clip - skip it for now... */
789         if (arg->x >= arg->xmax) {
790                 /* pass */
791         }
792         else {
793                 PointerRNA ptr;
794                 const float eps = 0.001f;
795                 const bool is_stroke_visible = (gpl->color[3] > eps);
796                 const bool is_fill_visible = (gpl->fill[3] > eps);
797                 float w = 0.5f  * UI_UNIT_X;
798                 float h = 0.85f * UI_UNIT_Y;
799
800                 RNA_pointer_create(id, &RNA_GPencilLayer, gpl, &ptr);
801
802                 UI_block_align_begin(arg->block);
803
804                 UI_block_emboss_set(arg->block, is_stroke_visible ? UI_EMBOSS : UI_EMBOSS_NONE);
805                 uiDefButR(arg->block, UI_BTYPE_COLOR, 1, "", arg->xb, arg->yb, w, h,
806                           &ptr, "color", -1,
807                           0, 0, 0, 0, NULL);
808
809                 UI_block_emboss_set(arg->block, is_fill_visible ? UI_EMBOSS : UI_EMBOSS_NONE);
810                 uiDefButR(arg->block, UI_BTYPE_COLOR, 1, "", arg->xb + w, arg->yb, w, h,
811                           &ptr, "fill_color", -1,
812                           0, 0, 0, 0, NULL);
813
814                 UI_block_emboss_set(arg->block, UI_EMBOSS_NONE);
815                 UI_block_align_end(arg->block);
816         }
817 }
818
819 static void tselem_draw_icon(uiBlock *block, int xmax, float x, float y, TreeStoreElem *tselem, TreeElement *te,
820                              float alpha)
821 {
822         struct DrawIconArg arg;
823         float aspect;
824
825         /* make function calls a bit compacter */
826         arg.block = block;
827         arg.id = tselem->id;
828         arg.xmax = xmax;
829         arg.xb = x;     /* for ui buttons */
830         arg.yb = y;
831         arg.alpha = alpha;
832
833         /* placement of icons, copied from interface_widgets.c */
834         aspect = (0.8f * UI_UNIT_Y) / ICON_DEFAULT_HEIGHT;
835         x += 2.0f * aspect;
836         y += 2.0f * aspect;
837         arg.x = x;
838         arg.y = y;
839
840 #define ICON_DRAW(_icon) UI_icon_draw_alpha(x, y, _icon, alpha)
841
842         if (tselem->type) {
843                 switch (tselem->type) {
844                         case TSE_ANIM_DATA:
845                                 ICON_DRAW(ICON_ANIM_DATA); /* XXX */
846                                 break;
847                         case TSE_NLA:
848                                 ICON_DRAW(ICON_NLA);
849                                 break;
850                         case TSE_NLA_TRACK:
851                                 ICON_DRAW(ICON_NLA); /* XXX */
852                                 break;
853                         case TSE_NLA_ACTION:
854                                 ICON_DRAW(ICON_ACTION);
855                                 break;
856                         case TSE_DRIVER_BASE:
857                                 ICON_DRAW(ICON_DRIVER);
858                                 break;
859                         case TSE_DEFGROUP_BASE:
860                                 ICON_DRAW(ICON_GROUP_VERTEX);
861                                 break;
862                         case TSE_BONE:
863                         case TSE_EBONE:
864                                 ICON_DRAW(ICON_BONE_DATA);
865                                 break;
866                         case TSE_CONSTRAINT_BASE:
867                                 ICON_DRAW(ICON_CONSTRAINT);
868                                 break;
869                         case TSE_MODIFIER_BASE:
870                                 ICON_DRAW(ICON_MODIFIER);
871                                 break;
872                         case TSE_LINKED_OB:
873                                 ICON_DRAW(ICON_OBJECT_DATA);
874                                 break;
875                         case TSE_LINKED_PSYS:
876                                 ICON_DRAW(ICON_PARTICLES);
877                                 break;
878                         case TSE_MODIFIER:
879                         {
880                                 Object *ob = (Object *)tselem->id;
881                                 ModifierData *md = BLI_findlink(&ob->modifiers, tselem->nr);
882                                 switch ((ModifierType)md->type) {
883                                         case eModifierType_Subsurf:
884                                                 ICON_DRAW(ICON_MOD_SUBSURF);
885                                                 break;
886                                         case eModifierType_Armature:
887                                                 ICON_DRAW(ICON_MOD_ARMATURE);
888                                                 break;
889                                         case eModifierType_Lattice:
890                                                 ICON_DRAW(ICON_MOD_LATTICE);
891                                                 break;
892                                         case eModifierType_Curve:
893                                                 ICON_DRAW(ICON_MOD_CURVE);
894                                                 break;
895                                         case eModifierType_Build:
896                                                 ICON_DRAW(ICON_MOD_BUILD);
897                                                 break;
898                                         case eModifierType_Mirror:
899                                                 ICON_DRAW(ICON_MOD_MIRROR);
900                                                 break;
901                                         case eModifierType_Decimate:
902                                                 ICON_DRAW(ICON_MOD_DECIM);
903                                                 break;
904                                         case eModifierType_Wave:
905                                                 ICON_DRAW(ICON_MOD_WAVE);
906                                                 break;
907                                         case eModifierType_Hook:
908                                                 ICON_DRAW(ICON_HOOK);
909                                                 break;
910                                         case eModifierType_Softbody:
911                                                 ICON_DRAW(ICON_MOD_SOFT);
912                                                 break;
913                                         case eModifierType_Boolean:
914                                                 ICON_DRAW(ICON_MOD_BOOLEAN);
915                                                 break;
916                                         case eModifierType_ParticleSystem:
917                                                 ICON_DRAW(ICON_MOD_PARTICLES);
918                                                 break;
919                                         case eModifierType_ParticleInstance:
920                                                 ICON_DRAW(ICON_MOD_PARTICLES);
921                                                 break;
922                                         case eModifierType_EdgeSplit:
923                                                 ICON_DRAW(ICON_MOD_EDGESPLIT);
924                                                 break;
925                                         case eModifierType_Array:
926                                                 ICON_DRAW(ICON_MOD_ARRAY);
927                                                 break;
928                                         case eModifierType_UVProject:
929                                         case eModifierType_UVWarp:  /* TODO, get own icon */
930                                                 ICON_DRAW(ICON_MOD_UVPROJECT);
931                                                 break;
932                                         case eModifierType_Displace:
933                                                 ICON_DRAW(ICON_MOD_DISPLACE);
934                                                 break;
935                                         case eModifierType_Shrinkwrap:
936                                                 ICON_DRAW(ICON_MOD_SHRINKWRAP);
937                                                 break;
938                                         case eModifierType_Cast:
939                                                 ICON_DRAW(ICON_MOD_CAST);
940                                                 break;
941                                         case eModifierType_MeshDeform:
942                                         case eModifierType_SurfaceDeform:
943                                                 ICON_DRAW(ICON_MOD_MESHDEFORM);
944                                                 break;
945                                         case eModifierType_Bevel:
946                                                 ICON_DRAW(ICON_MOD_BEVEL);
947                                                 break;
948                                         case eModifierType_Smooth:
949                                         case eModifierType_LaplacianSmooth:
950                                         case eModifierType_CorrectiveSmooth:
951                                                 ICON_DRAW(ICON_MOD_SMOOTH);
952                                                 break;
953                                         case eModifierType_SimpleDeform:
954                                                 ICON_DRAW(ICON_MOD_SIMPLEDEFORM);
955                                                 break;
956                                         case eModifierType_Mask:
957                                                 ICON_DRAW(ICON_MOD_MASK);
958                                                 break;
959                                         case eModifierType_Cloth:
960                                                 ICON_DRAW(ICON_MOD_CLOTH);
961                                                 break;
962                                         case eModifierType_Explode:
963                                                 ICON_DRAW(ICON_MOD_EXPLODE);
964                                                 break;
965                                         case eModifierType_Collision:
966                                         case eModifierType_Surface:
967                                                 ICON_DRAW(ICON_MOD_PHYSICS);
968                                                 break;
969                                         case eModifierType_Fluidsim:
970                                                 ICON_DRAW(ICON_MOD_FLUIDSIM);
971                                                 break;
972                                         case eModifierType_Multires:
973                                                 ICON_DRAW(ICON_MOD_MULTIRES);
974                                                 break;
975                                         case eModifierType_Smoke:
976                                                 ICON_DRAW(ICON_MOD_SMOKE);
977                                                 break;
978                                         case eModifierType_Solidify:
979                                                 ICON_DRAW(ICON_MOD_SOLIDIFY);
980                                                 break;
981                                         case eModifierType_Screw:
982                                                 ICON_DRAW(ICON_MOD_SCREW);
983                                                 break;
984                                         case eModifierType_Remesh:
985                                                 ICON_DRAW(ICON_MOD_REMESH);
986                                                 break;
987                                         case eModifierType_WeightVGEdit:
988                                         case eModifierType_WeightVGMix:
989                                         case eModifierType_WeightVGProximity:
990                                                 ICON_DRAW(ICON_MOD_VERTEX_WEIGHT);
991                                                 break;
992                                         case eModifierType_DynamicPaint:
993                                                 ICON_DRAW(ICON_MOD_DYNAMICPAINT);
994                                                 break;
995                                         case eModifierType_Ocean:
996                                                 ICON_DRAW(ICON_MOD_OCEAN);
997                                                 break;
998                                         case eModifierType_Warp:
999                                                 ICON_DRAW(ICON_MOD_WARP);
1000                                                 break;
1001                                         case eModifierType_Skin:
1002                                                 ICON_DRAW(ICON_MOD_SKIN);
1003                                                 break;
1004                                         case eModifierType_Triangulate:
1005                                                 ICON_DRAW(ICON_MOD_TRIANGULATE);
1006                                                 break;
1007                                         case eModifierType_MeshCache:
1008                                                 ICON_DRAW(ICON_MOD_MESHDEFORM); /* XXX, needs own icon */
1009                                                 break;
1010                                         case eModifierType_MeshSequenceCache:
1011                                                 ICON_DRAW(ICON_MOD_MESHDEFORM); /* XXX, needs own icon */
1012                                                 break;
1013                                         case eModifierType_Wireframe:
1014                                                 ICON_DRAW(ICON_MOD_WIREFRAME);
1015                                                 break;
1016                                         case eModifierType_LaplacianDeform:
1017                                                 ICON_DRAW(ICON_MOD_MESHDEFORM); /* XXX, needs own icon */
1018                                                 break;
1019                                         case eModifierType_DataTransfer:
1020                                                 ICON_DRAW(ICON_MOD_DATA_TRANSFER);
1021                                                 break;
1022                                         case eModifierType_NormalEdit:
1023                                                 ICON_DRAW(ICON_MOD_NORMALEDIT);
1024                                                 break;
1025                                         /* Default */
1026                                         case eModifierType_None:
1027                                         case eModifierType_ShapeKey:
1028                                         case NUM_MODIFIER_TYPES:
1029                                                 ICON_DRAW(ICON_DOT);
1030                                                 break;
1031                                 }
1032                                 break;
1033                         }
1034                         case TSE_POSE_BASE:
1035                                 ICON_DRAW(ICON_ARMATURE_DATA);
1036                                 break;
1037                         case TSE_POSE_CHANNEL:
1038                                 ICON_DRAW(ICON_BONE_DATA);
1039                                 break;
1040                         case TSE_PROXY:
1041                                 ICON_DRAW(ICON_GHOST);
1042                                 break;
1043                         case TSE_R_LAYER_BASE:
1044                                 ICON_DRAW(ICON_RENDERLAYERS);
1045                                 break;
1046                         case TSE_SCENE_OBJECTS_BASE:
1047                                 ICON_DRAW(ICON_OUTLINER_OB_GROUP_INSTANCE);
1048                                 break;
1049                         case TSE_R_LAYER:
1050                                 ICON_DRAW(ICON_RENDER_RESULT);
1051                                 break;
1052                         case TSE_LINKED_LAMP:
1053                                 ICON_DRAW(ICON_LAMP_DATA);
1054                                 break;
1055                         case TSE_LINKED_MAT:
1056                                 ICON_DRAW(ICON_MATERIAL_DATA);
1057                                 break;
1058                         case TSE_POSEGRP_BASE:
1059                                 ICON_DRAW(ICON_GROUP_BONE);
1060                                 break;
1061                         case TSE_SEQUENCE:
1062                                 if (te->idcode == SEQ_TYPE_MOVIE)
1063                                         ICON_DRAW(ICON_SEQUENCE);
1064                                 else if (te->idcode == SEQ_TYPE_META)
1065                                         ICON_DRAW(ICON_DOT);
1066                                 else if (te->idcode == SEQ_TYPE_SCENE)
1067                                         ICON_DRAW(ICON_SCENE);
1068                                 else if (te->idcode == SEQ_TYPE_SOUND_RAM)
1069                                         ICON_DRAW(ICON_SOUND);
1070                                 else if (te->idcode == SEQ_TYPE_IMAGE)
1071                                         ICON_DRAW(ICON_IMAGE_COL);
1072                                 else
1073                                         ICON_DRAW(ICON_PARTICLES);
1074                                 break;
1075                         case TSE_SEQ_STRIP:
1076                                 ICON_DRAW(ICON_LIBRARY_DATA_DIRECT);
1077                                 break;
1078                         case TSE_SEQUENCE_DUP:
1079                                 ICON_DRAW(ICON_OBJECT_DATA);
1080                                 break;
1081                         case TSE_RNA_STRUCT:
1082                                 if (RNA_struct_is_ID(te->rnaptr.type)) {
1083                                         arg.id = (ID *)te->rnaptr.data;
1084                                         tselem_draw_icon_uibut(&arg, RNA_struct_ui_icon(te->rnaptr.type));
1085                                 }
1086                                 else {
1087                                         int icon = RNA_struct_ui_icon(te->rnaptr.type);
1088                                         ICON_DRAW(icon);
1089                                 }
1090                                 break;
1091                         case TSE_LAYER_COLLECTION:
1092                         case TSE_SCENE_COLLECTION_BASE:
1093                         case TSE_VIEW_COLLECTION_BASE:
1094                                 ICON_DRAW(ICON_GROUP);
1095                                 break;
1096                         /* Removed the icons from outliner. Need a better structure with Layers, Palettes and Colors */
1097 #if 0
1098                         case TSE_GP_LAYER:
1099                                 tselem_draw_gp_icon_uibut(&arg, tselem->id, te->directdata);
1100                                 break;
1101 #endif
1102                         default:
1103                                 ICON_DRAW(ICON_DOT);
1104                                 break;
1105                 }
1106         }
1107         else if (tselem->id) {
1108                 if (GS(tselem->id->name) == ID_OB) {
1109                         Object *ob = (Object *)tselem->id;
1110                         switch (ob->type) {
1111                                 case OB_LAMP:
1112                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_LAMP); break;
1113                                 case OB_MESH:
1114                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_MESH); break;
1115                                 case OB_CAMERA:
1116                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_CAMERA); break;
1117                                 case OB_CURVE:
1118                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_CURVE); break;
1119                                 case OB_MBALL:
1120                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_META); break;
1121                                 case OB_LATTICE:
1122                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_LATTICE); break;
1123                                 case OB_ARMATURE:
1124                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_ARMATURE); break;
1125                                 case OB_FONT:
1126                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_FONT); break;
1127                                 case OB_SURF:
1128                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_SURFACE); break;
1129                                 case OB_SPEAKER:
1130                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_SPEAKER); break;
1131                                 case OB_LIGHTPROBE:
1132                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_LIGHTPROBE); break;
1133                                 case OB_EMPTY:
1134                                         if (ob->dup_group) {
1135                                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_GROUP_INSTANCE);
1136                                         }
1137                                         else {
1138                                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_EMPTY);
1139                                         }
1140                                         break;
1141                         }
1142                 }
1143                 else {
1144                         /* TODO(sergey): Casting to short here just to handle ID_NLA which is
1145                          * NOT inside of IDType enum.
1146                          */
1147                         switch ((short)GS(tselem->id->name)) {
1148                                 case ID_SCE:
1149                                         tselem_draw_icon_uibut(&arg, ICON_SCENE_DATA); break;
1150                                 case ID_ME:
1151                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_MESH); break;
1152                                 case ID_CU:
1153                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_CURVE); break;
1154                                 case ID_MB:
1155                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_META); break;
1156                                 case ID_LT:
1157                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_LATTICE); break;
1158                                 case ID_LA:
1159                                 {
1160                                         Lamp *la = (Lamp *)tselem->id;
1161                                         switch (la->type) {
1162                                                 case LA_LOCAL:
1163                                                         tselem_draw_icon_uibut(&arg, ICON_LAMP_POINT); break;
1164                                                 case LA_SUN:
1165                                                         tselem_draw_icon_uibut(&arg, ICON_LAMP_SUN); break;
1166                                                 case LA_SPOT:
1167                                                         tselem_draw_icon_uibut(&arg, ICON_LAMP_SPOT); break;
1168                                                 case LA_HEMI:
1169                                                         tselem_draw_icon_uibut(&arg, ICON_LAMP_HEMI); break;
1170                                                 case LA_AREA:
1171                                                         tselem_draw_icon_uibut(&arg, ICON_LAMP_AREA); break;
1172                                                 default:
1173                                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_LAMP); break;
1174                                         }
1175                                         break;
1176                                 }
1177                                 case ID_MA:
1178                                         tselem_draw_icon_uibut(&arg, ICON_MATERIAL_DATA); break;
1179                                 case ID_TE:
1180                                         tselem_draw_icon_uibut(&arg, ICON_TEXTURE_DATA); break;
1181                                 case ID_IM:
1182                                         tselem_draw_icon_uibut(&arg, ICON_IMAGE_DATA); break;
1183                                 case ID_SPK:
1184                                 case ID_SO:
1185                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_SPEAKER); break;
1186                                 case ID_AR:
1187                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_ARMATURE); break;
1188                                 case ID_CA:
1189                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_CAMERA); break;
1190                                 case ID_KE:
1191                                         tselem_draw_icon_uibut(&arg, ICON_SHAPEKEY_DATA); break;
1192                                 case ID_WO:
1193                                         tselem_draw_icon_uibut(&arg, ICON_WORLD_DATA); break;
1194                                 case ID_AC:
1195                                         tselem_draw_icon_uibut(&arg, ICON_ACTION); break;
1196                                 case ID_NLA:
1197                                         tselem_draw_icon_uibut(&arg, ICON_NLA); break;
1198                                 case ID_TXT:
1199                                         tselem_draw_icon_uibut(&arg, ICON_SCRIPT); break;
1200                                 case ID_GR:
1201                                         tselem_draw_icon_uibut(&arg, ICON_GROUP); break;
1202                                 case ID_LI:
1203                                         if (tselem->id->tag & LIB_TAG_MISSING) {
1204                                                 tselem_draw_icon_uibut(&arg, ICON_LIBRARY_DATA_BROKEN);
1205                                         }
1206                                         else if (((Library *)tselem->id)->parent) {
1207                                                 tselem_draw_icon_uibut(&arg, ICON_LIBRARY_DATA_INDIRECT);
1208                                         }
1209                                         else {
1210                                                 tselem_draw_icon_uibut(&arg, ICON_LIBRARY_DATA_DIRECT);
1211                                         }
1212                                         break;
1213                                 case ID_LS:
1214                                         tselem_draw_icon_uibut(&arg, ICON_LINE_DATA); break;
1215                                 case ID_GD:
1216                                         tselem_draw_icon_uibut(&arg, ICON_GREASEPENCIL); break;
1217                                 case ID_LP:
1218                                 {
1219                                         LightProbe * lp = (LightProbe *)tselem->id;
1220                                         switch (lp->type) {
1221                                                 case LIGHTPROBE_TYPE_CUBE:
1222                                                         tselem_draw_icon_uibut(&arg, ICON_LIGHTPROBE_CUBEMAP); break;
1223                                                 case LIGHTPROBE_TYPE_PLANAR:
1224                                                         tselem_draw_icon_uibut(&arg, ICON_LIGHTPROBE_PLANAR); break;
1225                                                 case LIGHTPROBE_TYPE_GRID:
1226                                                         tselem_draw_icon_uibut(&arg, ICON_LIGHTPROBE_GRID); break;
1227                                                 default:
1228                                                         tselem_draw_icon_uibut(&arg, ICON_LIGHTPROBE_CUBEMAP); break;
1229                                         }
1230                                         break;
1231                                 }
1232                                 case ID_BR:
1233                                         tselem_draw_icon_uibut(&arg, ICON_BRUSH_DATA); break;
1234                                 case ID_SCR:
1235                                 case ID_WS:
1236                                         tselem_draw_icon_uibut(&arg, ICON_SPLITSCREEN); break;
1237                                 default:
1238                                         break;
1239                         }
1240                 }
1241         }
1242
1243 #undef ICON_DRAW
1244 }
1245
1246 static void outliner_draw_iconrow(
1247         bContext *C, uiBlock *block, Scene *scene, ViewLayer *view_layer, SpaceOops *soops,
1248         ListBase *lb, int level, int xmax, int *offsx, int ys, float alpha_fac)
1249 {
1250         TreeElement *te;
1251         TreeStoreElem *tselem;
1252         eOLDrawState active;
1253         const Object *obact = OBACT(view_layer);
1254
1255         for (te = lb->first; te; te = te->next) {
1256                 /* exit drawing early */
1257                 if ((*offsx) - UI_UNIT_X > xmax)
1258                         break;
1259
1260                 tselem = TREESTORE(te);
1261
1262                 /* object hierarchy always, further constrained on level */
1263                 if (level < 1 || (tselem->type == 0 && te->idcode == ID_OB)) {
1264                         /* active blocks get white circle */
1265                         if (tselem->type == 0) {
1266                                 if (te->idcode == ID_OB) {
1267                                         active = (OBACT(view_layer) == (Object *)tselem->id) ? OL_DRAWSEL_NORMAL : OL_DRAWSEL_NONE;
1268                                 }
1269                                 else if (is_object_data_in_editmode(tselem->id, obact)) {
1270                                         active = OL_DRAWSEL_NORMAL;
1271                                 }
1272                                 else {
1273                                         active = tree_element_active(C, scene, view_layer, soops, te, OL_SETSEL_NONE, false);
1274                                 }
1275                         }
1276                         else {
1277                                 active = tree_element_type_active(C, scene, view_layer, soops, te, tselem, OL_SETSEL_NONE, false);
1278                         }
1279
1280                         if (active != OL_DRAWSEL_NONE) {
1281                                 float ufac = UI_UNIT_X / 20.0f;
1282                                 float color[4] = {1.0f, 1.0f, 1.0f, 0.4f};
1283
1284                                 UI_draw_roundbox_corner_set(UI_CNR_ALL);
1285                                 color[3] *= alpha_fac;
1286
1287                                 UI_draw_roundbox_aa(
1288                                         true,
1289                                         (float) *offsx + 1.0f * ufac,
1290                                         (float)ys + 1.0f * ufac,
1291                                         (float)*offsx + UI_UNIT_X - 1.0f * ufac,
1292                                         (float)ys + UI_UNIT_Y - ufac,
1293                                         (float)UI_UNIT_Y / 2.0f - ufac,
1294                                         color);
1295                                 glEnable(GL_BLEND); /* roundbox disables */
1296                         }
1297
1298                         tselem_draw_icon(block, xmax, (float)*offsx, (float)ys, tselem, te, 0.5f * alpha_fac);
1299                         te->xs = *offsx;
1300                         te->ys = ys;
1301                         te->xend = (short)*offsx + UI_UNIT_X;
1302                         te->flag |= TE_ICONROW; // for click
1303
1304                         (*offsx) += UI_UNIT_X;
1305                 }
1306
1307                 /* this tree element always has same amount of branches, so don't draw */
1308                 if (tselem->type != TSE_R_LAYER) {
1309                         outliner_draw_iconrow(
1310                                 C, block, scene, view_layer, soops,
1311                                 &te->subtree, level + 1, xmax, offsx, ys, alpha_fac);
1312                 }
1313         }
1314
1315 }
1316
1317 /* closed tree element */
1318 static void outliner_set_coord_tree_element(TreeElement *te, int startx, int starty)
1319 {
1320         TreeElement *ten;
1321
1322         /* closed items may be displayed in row of parent, don't change their coordinate! */
1323         if ((te->flag & TE_ICONROW) == 0) {
1324                 /* store coord and continue, we need coordinates for elements outside view too */
1325                 te->xs = startx;
1326                 te->ys = starty;
1327         }
1328
1329         for (ten = te->subtree.first; ten; ten = ten->next) {
1330                 outliner_set_coord_tree_element(ten, startx + UI_UNIT_X, starty);
1331         }
1332 }
1333
1334
1335 static void outliner_draw_tree_element(
1336         bContext *C, uiBlock *block, const uiFontStyle *fstyle, Scene *scene, ViewLayer *view_layer,
1337         ARegion *ar, SpaceOops *soops, TreeElement *te, bool draw_grayed_out,
1338         int startx, int *starty, TreeElement **te_edit, TreeElement **te_floating)
1339 {
1340         TreeStoreElem *tselem;
1341         float ufac = UI_UNIT_X / 20.0f;
1342         int offsx = 0;
1343         eOLDrawState active = OL_DRAWSEL_NONE;
1344         float color[4];
1345         tselem = TREESTORE(te);
1346
1347         if (*starty + 2 * UI_UNIT_Y >= ar->v2d.cur.ymin && *starty <= ar->v2d.cur.ymax) {
1348                 const float alpha_fac = ((te->flag & TE_DISABLED) || draw_grayed_out) ? 0.5f : 1.0f;
1349                 const float alpha = 0.5f * alpha_fac;
1350                 int xmax = ar->v2d.cur.xmax;
1351
1352                 if ((tselem->flag & TSE_TEXTBUT) && (*te_edit == NULL)) {
1353                         *te_edit = te;
1354                 }
1355                 if ((te->drag_data != NULL) && (*te_floating == NULL)) {
1356                         *te_floating = te;
1357                 }
1358
1359                 /* icons can be ui buts, we don't want it to overlap with restrict */
1360                 if ((soops->flag & SO_HIDE_RESTRICTCOLS) == 0)
1361                         xmax -= OL_TOGW + UI_UNIT_X;
1362
1363                 glEnable(GL_BLEND);
1364
1365                 /* colors for active/selected data */
1366                 if (tselem->type == 0) {
1367                         const Object *obact = OBACT(view_layer);
1368                         if (te->idcode == ID_SCE) {
1369                                 if (tselem->id == (ID *)scene) {
1370                                         rgba_float_args_set(color, 1.0f, 1.0f, 1.0f, alpha);
1371                                         active = OL_DRAWSEL_ACTIVE;
1372                                 }
1373                         }
1374                         else if (te->idcode == ID_OB) {
1375                                 Object *ob = (Object *)tselem->id;
1376                                 Base *base = (Base *)te->directdata;
1377                                 const bool is_selected = (base != NULL) && ((base->flag & BASE_SELECTED) != 0);
1378
1379                                 if (ob == obact || is_selected) {
1380                                         char col[4] = {0, 0, 0, 0};
1381
1382                                         /* outliner active ob: always white text, circle color now similar to view3d */
1383
1384                                         active = OL_DRAWSEL_ACTIVE;
1385                                         if (ob == obact) {
1386                                                 if (is_selected) {
1387                                                         UI_GetThemeColorType4ubv(TH_ACTIVE, SPACE_VIEW3D, col);
1388                                                         col[3] = alpha;
1389                                                 }
1390
1391                                                 active = OL_DRAWSEL_NORMAL;
1392                                         }
1393                                         else if (is_selected) {
1394                                                 UI_GetThemeColorType4ubv(TH_SELECT, SPACE_VIEW3D, col);
1395                                                 col[3] = alpha;
1396                                         }
1397                                         rgba_float_args_set(color, (float)col[0] / 255, (float)col[1] / 255, (float)col[2] / 255, alpha);
1398                                 }
1399                         }
1400                         else if (is_object_data_in_editmode(tselem->id, obact)) {
1401                                 rgba_float_args_set(color, 1.0f, 1.0f, 1.0f, alpha);
1402                                 active = OL_DRAWSEL_ACTIVE;
1403                         }
1404                         else {
1405                                 if (tree_element_active(C, scene, view_layer, soops, te, OL_SETSEL_NONE, false)) {
1406                                         rgba_float_args_set(color, 0.85f, 0.85f, 1.0f, alpha);
1407                                         active = OL_DRAWSEL_ACTIVE;
1408                                 }
1409                         }
1410                 }
1411                 else {
1412                         active = tree_element_type_active(C, scene, view_layer, soops, te, tselem, OL_SETSEL_NONE, false);
1413                         rgba_float_args_set(color, 0.85f, 0.85f, 1.0f, alpha);
1414                 }
1415
1416                 /* active circle */
1417                 if (active != OL_DRAWSEL_NONE) {
1418                         UI_draw_roundbox_corner_set(UI_CNR_ALL);
1419                         UI_draw_roundbox_aa(
1420                                 true,
1421                                 (float)startx + UI_UNIT_X + 1.0f * ufac,
1422                                 (float)*starty + 1.0f * ufac,
1423                                 (float)startx + 2.0f * UI_UNIT_X - 1.0f * ufac,
1424                                 (float)*starty + UI_UNIT_Y - 1.0f * ufac,
1425                                 UI_UNIT_Y / 2.0f - 1.0f * ufac, color);
1426                         glEnable(GL_BLEND); /* roundbox disables it */
1427
1428                         te->flag |= TE_ACTIVE; // for lookup in display hierarchies
1429                 }
1430
1431                 if (tselem->type == TSE_VIEW_COLLECTION_BASE) {
1432                         /* Scene collection in view layer can't expand/collapse. */
1433                 }
1434                 else if (te->subtree.first || (tselem->type == 0 && te->idcode == ID_SCE) || (te->flag & TE_LAZY_CLOSED)) {
1435                         /* open/close icon, only when sublevels, except for scene */
1436                         int icon_x = startx;
1437
1438                         // icons a bit higher
1439                         if (TSELEM_OPEN(tselem, soops))
1440                                 UI_icon_draw_alpha((float)icon_x + 2 * ufac, (float)*starty + 1 * ufac, ICON_DISCLOSURE_TRI_DOWN,
1441                                                    alpha_fac);
1442                         else
1443                                 UI_icon_draw_alpha((float)icon_x + 2 * ufac, (float)*starty + 1 * ufac, ICON_DISCLOSURE_TRI_RIGHT,
1444                                                    alpha_fac);
1445                 }
1446                 offsx += UI_UNIT_X;
1447
1448                 /* datatype icon */
1449
1450                 if (!(ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM, TSE_ID_BASE))) {
1451                         tselem_draw_icon(block, xmax, (float)startx + offsx, (float)*starty, tselem, te, alpha_fac);
1452                         offsx += UI_UNIT_X + 2 * ufac;
1453                 }
1454                 else
1455                         offsx += 2 * ufac;
1456
1457                 if (ELEM(tselem->type, 0, TSE_LAYER_COLLECTION) && ID_IS_LINKED(tselem->id)) {
1458                         if (tselem->id->tag & LIB_TAG_MISSING) {
1459                                 UI_icon_draw_alpha((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_BROKEN,
1460                                                    alpha_fac);
1461                         }
1462                         else if (tselem->id->tag & LIB_TAG_INDIRECT) {
1463                                 UI_icon_draw_alpha((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_INDIRECT,
1464                                                    alpha_fac);
1465                         }
1466                         else {
1467                                 UI_icon_draw_alpha((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_DIRECT,
1468                                                    alpha_fac);
1469                         }
1470                         offsx += UI_UNIT_X + 2 * ufac;
1471                 }
1472                 else if (ELEM(tselem->type, 0, TSE_LAYER_COLLECTION) && ID_IS_STATIC_OVERRIDE(tselem->id)) {
1473                         UI_icon_draw_alpha((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_OVERRIDE,
1474                                            alpha_fac);
1475                         offsx += UI_UNIT_X + 2 * ufac;
1476                 }
1477                 glDisable(GL_BLEND);
1478
1479                 /* name */
1480                 if ((tselem->flag & TSE_TEXTBUT) == 0) {
1481                         unsigned char text_col[4];
1482
1483                         if (active == OL_DRAWSEL_NORMAL) {
1484                                 UI_GetThemeColor4ubv(TH_TEXT_HI, text_col);
1485                         }
1486                         else if (ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) {
1487                                 UI_GetThemeColorBlend3ubv(TH_BACK, TH_TEXT, 0.75f, text_col);
1488                                 text_col[3] = 255;
1489                         }
1490                         else {
1491                                 UI_GetThemeColor4ubv(TH_TEXT, text_col);
1492                         }
1493                         text_col[3] *= alpha_fac;
1494
1495                         UI_fontstyle_draw_simple(fstyle, startx + offsx, *starty + 5 * ufac, te->name, text_col);
1496                 }
1497
1498                 offsx += (int)(UI_UNIT_X + UI_fontstyle_string_width(fstyle, te->name));
1499
1500                 /* closed item, we draw the icons, not when it's a scene, or master-server list though */
1501                 if (!TSELEM_OPEN(tselem, soops)) {
1502                         if (te->subtree.first) {
1503                                 if (tselem->type == 0 && te->idcode == ID_SCE) {
1504                                         /* pass */
1505                                 }
1506                                 /* this tree element always has same amount of branches, so don't draw */
1507                                 else if (tselem->type != TSE_R_LAYER) {
1508                                         int tempx = startx + offsx;
1509
1510                                         glEnable(GL_BLEND);
1511
1512                                         /* divider */
1513                                         {
1514                                                 Gwn_VertFormat *format = immVertexFormat();
1515                                                 unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
1516                                                 unsigned char col[4];
1517
1518                                                 immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
1519                                                 UI_GetThemeColorShade4ubv(TH_BACK, -40, col);
1520                                                 col[3] *= alpha_fac;
1521
1522                                                 immUniformColor4ubv(col);
1523                                                 immRecti(pos, tempx   - 10.0f * ufac,
1524                                                          *starty +  4.0f * ufac,
1525                                                          tempx   -  8.0f * ufac,
1526                                                          *starty + UI_UNIT_Y - 4.0f * ufac);
1527                                                 immUnbindProgram();
1528                                         }
1529
1530                                         outliner_draw_iconrow(
1531                                                 C, block, scene, view_layer, soops, &te->subtree, 0, xmax, &tempx,
1532                                                 *starty, alpha_fac);
1533
1534                                         glDisable(GL_BLEND);
1535                                 }
1536                         }
1537                 }
1538         }
1539         /* store coord and continue, we need coordinates for elements outside view too */
1540         te->xs = startx;
1541         te->ys = *starty;
1542         te->xend = startx + offsx;
1543
1544         if (TSELEM_OPEN(tselem, soops)) {
1545                 *starty -= UI_UNIT_Y;
1546
1547                 for (TreeElement *ten = te->subtree.first; ten; ten = ten->next) {
1548                         /* check if element needs to be drawn grayed out, but also gray out
1549                          * childs of a grayed out parent (pass on draw_grayed_out to childs) */
1550                         bool draw_childs_grayed_out = draw_grayed_out || (ten->drag_data != NULL);
1551                         outliner_draw_tree_element(
1552                                 C, block, fstyle, scene, view_layer,
1553                                 ar, soops, ten, draw_childs_grayed_out,
1554                                 startx + UI_UNIT_X, starty, te_edit, te_floating);
1555                 }
1556         }
1557         else {
1558                 for (TreeElement *ten = te->subtree.first; ten; ten = ten->next) {
1559                         outliner_set_coord_tree_element(ten, startx, *starty);
1560                 }
1561
1562                 *starty -= UI_UNIT_Y;
1563         }
1564 }
1565
1566 static void outliner_draw_tree_element_floating(
1567         const ARegion *ar, const TreeElement *te_floating)
1568 {
1569         const TreeElement *te_insert = te_floating->drag_data->insert_handle;
1570         const int line_width = 2;
1571
1572         unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
1573         int coord_y = te_insert->ys;
1574         int coord_x = te_insert->xs;
1575         float col[4];
1576
1577         if (te_insert == te_floating) {
1578                 /* don't draw anything */
1579                 return;
1580         }
1581
1582         UI_GetThemeColorShade4fv(TH_BACK, -40, col);
1583         immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
1584         glEnable(GL_BLEND);
1585
1586         if (ELEM(te_floating->drag_data->insert_type, TE_INSERT_BEFORE, TE_INSERT_AFTER)) {
1587                 if (te_floating->drag_data->insert_type == TE_INSERT_BEFORE) {
1588                         coord_y += UI_UNIT_Y;
1589                 }
1590                 immUniformColor4fv(col);
1591                 glLineWidth(line_width);
1592
1593                 immBegin(GWN_PRIM_LINE_STRIP, 2);
1594                 immVertex2f(pos, coord_x, coord_y);
1595                 immVertex2f(pos, ar->v2d.cur.xmax, coord_y);
1596                 immEnd();
1597         }
1598         else {
1599                 BLI_assert(te_floating->drag_data->insert_type == TE_INSERT_INTO);
1600                 immUniformColor3fvAlpha(col, col[3] * 0.5f);
1601
1602                 immBegin(GWN_PRIM_TRI_STRIP, 4);
1603                 immVertex2f(pos, coord_x, coord_y + UI_UNIT_Y);
1604                 immVertex2f(pos, coord_x, coord_y);
1605                 immVertex2f(pos, ar->v2d.cur.xmax, coord_y + UI_UNIT_Y);
1606                 immVertex2f(pos, ar->v2d.cur.xmax, coord_y);
1607                 immEnd();
1608         }
1609
1610         glDisable(GL_BLEND);
1611         immUnbindProgram();
1612 }
1613
1614 static void outliner_draw_hierarchy_lines_recursive(unsigned pos, SpaceOops *soops, ListBase *lb, int startx,
1615                                                     const unsigned char col[4], bool draw_grayed_out,
1616                                                     int *starty)
1617 {
1618         TreeElement *te, *te_vertical_line_last = NULL;
1619         TreeStoreElem *tselem;
1620         int y1, y2;
1621
1622         if (BLI_listbase_is_empty(lb)) {
1623                 return;
1624         }
1625
1626         const unsigned char grayed_alpha = col[3] / 2;
1627
1628         /* For vertical lines between objects. */
1629         y1 = y2 = *starty;
1630         for (te = lb->first; te; te = te->next) {
1631                 bool draw_childs_grayed_out = draw_grayed_out || (te->drag_data != NULL);
1632                 tselem = TREESTORE(te);
1633
1634                 if (draw_childs_grayed_out) {
1635                         immUniformColor3ubvAlpha(col, grayed_alpha);
1636                 }
1637                 else {
1638                         immUniformColor4ubv(col);
1639                 }
1640
1641                 /* Horizontal Line? */
1642                 if (tselem->type == 0 && (te->idcode == ID_OB || te->idcode == ID_SCE)) {
1643                         immRecti(pos, startx, *starty, startx + UI_UNIT_X, *starty - 1);
1644
1645                         /* Vertical Line? */
1646                         if (te->idcode == ID_OB) {
1647                                 te_vertical_line_last = te;
1648                                 y2 = *starty;
1649                         }
1650                 }
1651
1652                 *starty -= UI_UNIT_Y;
1653
1654                 if (TSELEM_OPEN(tselem, soops))
1655                         outliner_draw_hierarchy_lines_recursive(pos, soops, &te->subtree, startx + UI_UNIT_X,
1656                                                                 col, draw_childs_grayed_out, starty);
1657         }
1658
1659         if (draw_grayed_out) {
1660                 immUniformColor3ubvAlpha(col, grayed_alpha);
1661         }
1662         else {
1663                 immUniformColor4ubv(col);
1664         }
1665
1666         /* Vertical line. */
1667         te = te_vertical_line_last;
1668         if ((te != NULL) && (te->parent || lb->first != lb->last)) {
1669                 immRecti(pos, startx, y1 + UI_UNIT_Y, startx + 1, y2);
1670         }
1671 }
1672
1673 static void outliner_draw_hierarchy_lines(SpaceOops *soops, ListBase *lb, int startx, int *starty)
1674 {
1675         Gwn_VertFormat *format = immVertexFormat();
1676         unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
1677         unsigned char col[4];
1678
1679         immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
1680         UI_GetThemeColorBlend3ubv(TH_BACK, TH_TEXT, 0.4f, col);
1681         col[3] = 255;
1682
1683         glEnable(GL_BLEND);
1684         outliner_draw_hierarchy_lines_recursive(pos, soops, lb, startx, col, false, starty);
1685         glDisable(GL_BLEND);
1686
1687         immUnbindProgram();
1688 }
1689
1690 static void outliner_draw_struct_marks(ARegion *ar, SpaceOops *soops, ListBase *lb, int *starty)
1691 {
1692         TreeElement *te;
1693         TreeStoreElem *tselem;
1694
1695         for (te = lb->first; te; te = te->next) {
1696                 tselem = TREESTORE(te);
1697
1698                 /* selection status */
1699                 if (TSELEM_OPEN(tselem, soops))
1700                         if (tselem->type == TSE_RNA_STRUCT) {
1701                                 Gwn_VertFormat *format = immVertexFormat();
1702                                 unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
1703                                 immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
1704                                 immThemeColorShadeAlpha(TH_BACK, -15, -200);
1705                                 immRecti(pos, 0, *starty + 1, (int)ar->v2d.cur.xmax, *starty + UI_UNIT_Y - 1);
1706                                 immUnbindProgram();
1707                         }
1708
1709                 *starty -= UI_UNIT_Y;
1710                 if (TSELEM_OPEN(tselem, soops)) {
1711                         outliner_draw_struct_marks(ar, soops, &te->subtree, starty);
1712                         if (tselem->type == TSE_RNA_STRUCT) {
1713                                 Gwn_VertFormat *format = immVertexFormat();
1714                                 unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
1715                                 immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
1716                                 immThemeColorShadeAlpha(TH_BACK, -15, -200);
1717
1718                                 immBegin(GWN_PRIM_LINES, 2);
1719                                 immVertex2f(pos, 0, (float)*starty + UI_UNIT_Y);
1720                                 immVertex2f(pos, ar->v2d.cur.xmax, (float)*starty + UI_UNIT_Y);
1721                                 immEnd();
1722
1723                                 immUnbindProgram();
1724                         }
1725                 }
1726         }
1727 }
1728
1729 static void outliner_draw_highlights_recursive(
1730         unsigned pos, const ARegion *ar, const SpaceOops *soops, const ListBase *lb,
1731         const float col_selection[4], const float col_highlight[4], const float col_searchmatch[4],
1732         int start_x, int *io_start_y)
1733 {
1734         const bool is_searching = SEARCHING_OUTLINER(soops) ||
1735                                   (soops->outlinevis == SO_DATA_API &&
1736                                    (soops->filter & SO_FILTER_SEARCH) &&
1737                                    soops->search_string[0] != 0);
1738
1739         for (TreeElement *te = lb->first; te; te = te->next) {
1740                 const TreeStoreElem *tselem = TREESTORE(te);
1741                 const int start_y = *io_start_y;
1742
1743                 /* selection status */
1744                 if (tselem->flag & TSE_SELECTED) {
1745                         immUniformColor4fv(col_selection);
1746                         immRecti(pos, 0, start_y + 1, (int)ar->v2d.cur.xmax, start_y + UI_UNIT_Y - 1);
1747                 }
1748
1749                 /* search match highlights
1750                  *   we don't expand items when searching in the datablocks but we
1751                  *   still want to highlight any filter matches. */
1752                 if (is_searching && (tselem->flag & TSE_SEARCHMATCH)) {
1753                         immUniformColor4fv(col_searchmatch);
1754                         immRecti(pos, start_x, start_y + 1, ar->v2d.cur.xmax, start_y + UI_UNIT_Y - 1);
1755                 }
1756
1757                 /* mouse hover highlights */
1758                 if ((tselem->flag & TSE_HIGHLIGHTED) || (te->drag_data != NULL)) {
1759                         immUniformColor4fv(col_highlight);
1760                         immRecti(pos, 0, start_y + 1, (int)ar->v2d.cur.xmax, start_y + UI_UNIT_Y - 1);
1761                 }
1762
1763                 *io_start_y -= UI_UNIT_Y;
1764                 if (TSELEM_OPEN(tselem, soops)) {
1765                         outliner_draw_highlights_recursive(
1766                                 pos, ar, soops, &te->subtree, col_selection, col_highlight, col_searchmatch,
1767                                 start_x + UI_UNIT_X, io_start_y);
1768                 }
1769         }
1770 }
1771
1772 static void outliner_draw_highlights(ARegion *ar, SpaceOops *soops, int startx, int *starty)
1773 {
1774         const float col_highlight[4] = {1.0f, 1.0f, 1.0f, 0.13f};
1775         float col_selection[4], col_searchmatch[4];
1776
1777         UI_GetThemeColor3fv(TH_SELECT_HIGHLIGHT, col_selection);
1778         col_selection[3] = 1.0f; /* no alpha */
1779         UI_GetThemeColor4fv(TH_MATCH, col_searchmatch);
1780         col_searchmatch[3] = 0.5f;
1781
1782         glEnable(GL_BLEND);
1783         Gwn_VertFormat *format = immVertexFormat();
1784         unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
1785         immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
1786         outliner_draw_highlights_recursive(pos, ar, soops, &soops->tree, col_selection, col_highlight, col_searchmatch,
1787                                            startx, starty);
1788         immUnbindProgram();
1789         glDisable(GL_BLEND);
1790 }
1791
1792 static void outliner_draw_tree(
1793         bContext *C, uiBlock *block, Scene *scene, ViewLayer *view_layer,
1794         ARegion *ar, SpaceOops *soops, const bool has_restrict_icons,
1795         TreeElement **te_edit)
1796 {
1797         const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
1798         TreeElement *te_floating = NULL;
1799         int starty, startx;
1800
1801         glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); // only once
1802
1803         if (soops->outlinevis == SO_DATA_API) {
1804                 /* struct marks */
1805                 starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y - OL_Y_OFFSET;
1806                 outliner_draw_struct_marks(ar, soops, &soops->tree, &starty);
1807         }
1808
1809         /* draw highlights before hierarchy */
1810         starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y - OL_Y_OFFSET;
1811         startx = 0;
1812         outliner_draw_highlights(ar, soops, startx, &starty);
1813
1814         /* set scissor so tree elements or lines can't overlap restriction icons */
1815         GLfloat scissor[4] = {0};
1816         if (has_restrict_icons) {
1817                 int mask_x = BLI_rcti_size_x(&ar->v2d.mask) - (int)OL_TOGW + 1;
1818                 CLAMP_MIN(mask_x, 0);
1819
1820                 glGetFloatv(GL_SCISSOR_BOX, scissor);
1821                 glScissor(0, 0, mask_x, ar->winy);
1822         }
1823
1824         // gray hierarchy lines
1825
1826         starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y / 2 - OL_Y_OFFSET;
1827         startx = UI_UNIT_X / 2 - 1.0f;
1828         outliner_draw_hierarchy_lines(soops, &soops->tree, startx, &starty);
1829
1830         // items themselves
1831         starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y - OL_Y_OFFSET;
1832         startx = 0;
1833         for (TreeElement *te = soops->tree.first; te; te = te->next) {
1834                 outliner_draw_tree_element(
1835                         C, block, fstyle, scene, view_layer,
1836                         ar, soops, te, te->drag_data != NULL,
1837                         startx, &starty, te_edit, &te_floating);
1838         }
1839         if (te_floating && te_floating->drag_data->insert_handle) {
1840                 outliner_draw_tree_element_floating(ar, te_floating);
1841         }
1842
1843         if (has_restrict_icons) {
1844                 /* reset scissor */
1845                 glScissor(UNPACK4(scissor));
1846         }
1847 }
1848
1849
1850 static void outliner_back(ARegion *ar)
1851 {
1852         int ystart;
1853
1854         ystart = (int)ar->v2d.tot.ymax;
1855         ystart = UI_UNIT_Y * (ystart / (UI_UNIT_Y)) - OL_Y_OFFSET;
1856
1857         Gwn_VertFormat *format = immVertexFormat();
1858         unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
1859
1860         immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
1861         immUniformThemeColorShade(TH_BACK, 6);
1862
1863         const float x1 = 0.0f, x2 = ar->v2d.cur.xmax;
1864         float y1 = ystart, y2;
1865         int tot = (int)floor(ystart - ar->v2d.cur.ymin + 2 * UI_UNIT_Y) / (2 * UI_UNIT_Y);
1866
1867         if (tot > 0) {
1868                 immBegin(GWN_PRIM_TRIS, 6 * tot);
1869                 while (tot--) {
1870                         y1 -= 2 * UI_UNIT_Y;
1871                         y2 = y1 + UI_UNIT_Y;
1872                         immVertex2f(pos, x1, y1);
1873                         immVertex2f(pos, x2, y1);
1874                         immVertex2f(pos, x2, y2);
1875
1876                         immVertex2f(pos, x1, y1);
1877                         immVertex2f(pos, x2, y2);
1878                         immVertex2f(pos, x1, y2);
1879                 }
1880                 immEnd();
1881         }
1882         immUnbindProgram();
1883 }
1884
1885 static void outliner_draw_restrictcols(ARegion *ar)
1886 {
1887         glLineWidth(1.0f);
1888
1889         unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
1890         immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
1891         immUniformThemeColorShadeAlpha(TH_BACK, -15, -200);
1892         immBegin(GWN_PRIM_LINES, 6);
1893
1894         immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), (int)ar->v2d.cur.ymax);
1895         immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), (int)ar->v2d.cur.ymin);
1896
1897         immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), (int)ar->v2d.cur.ymax);
1898         immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), (int)ar->v2d.cur.ymin);
1899
1900         immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), (int)ar->v2d.cur.ymax);
1901         immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), (int)ar->v2d.cur.ymin);
1902
1903         immEnd();
1904         immUnbindProgram();
1905 }
1906
1907 /* ****************************************************** */
1908 /* Main Entrypoint - Draw contents of Outliner editor */
1909
1910 void draw_outliner(const bContext *C)
1911 {
1912         Main *mainvar = CTX_data_main(C);
1913         Scene *scene = CTX_data_scene(C);
1914         ViewLayer *view_layer = CTX_data_view_layer(C);
1915         ARegion *ar = CTX_wm_region(C);
1916         View2D *v2d = &ar->v2d;
1917         SpaceOops *soops = CTX_wm_space_outliner(C);
1918         uiBlock *block;
1919         int sizey = 0, sizex = 0, sizex_rna = 0;
1920         TreeElement *te_edit = NULL;
1921         bool has_restrict_icons;
1922
1923         outliner_build_tree(mainvar, scene, view_layer, soops, ar); // always
1924
1925         /* get extents of data */
1926         outliner_height(soops, &soops->tree, &sizey);
1927
1928         if (soops->outlinevis == SO_DATA_API) {
1929                 /* RNA has two columns:
1930                  *  - column 1 is (max_width + OL_RNA_COL_SPACEX) or
1931                  *                               (OL_RNA_COL_X), whichever is wider...
1932                  *      - column 2 is fixed at OL_RNA_COL_SIZEX
1933                  *
1934                  *  (*) XXX max width for now is a fixed factor of (UI_UNIT_X * (max_indention + 100))
1935                  */
1936
1937                 /* get actual width of column 1 */
1938                 outliner_rna_width(soops, &soops->tree, &sizex_rna, 0);
1939                 sizex_rna = max_ii(OL_RNA_COLX, sizex_rna + OL_RNA_COL_SPACEX);
1940
1941                 /* get width of data (for setting 'tot' rect, this is column 1 + column 2 + a bit extra) */
1942                 sizex = sizex_rna + OL_RNA_COL_SIZEX + 50;
1943                 has_restrict_icons = false;
1944         }
1945         else {
1946                 /* width must take into account restriction columns (if visible) so that entries will still be visible */
1947                 //outliner_width(soops, &soops->tree, &sizex);
1948                 // XXX should use outliner_width instead when te->xend will be set correctly...
1949                 outliner_rna_width(soops, &soops->tree, &sizex, 0);
1950
1951                 /* constant offset for restriction columns */
1952                 // XXX this isn't that great yet...
1953                 if ((soops->flag & SO_HIDE_RESTRICTCOLS) == 0) {
1954                         sizex += OL_TOGW * 3;
1955                 }
1956
1957                 has_restrict_icons = !(soops->flag & SO_HIDE_RESTRICTCOLS);
1958         }
1959
1960         /* adds vertical offset */
1961         sizey += OL_Y_OFFSET;
1962
1963         /* update size of tot-rect (extents of data/viewable area) */
1964         UI_view2d_totRect_set(v2d, sizex, sizey);
1965
1966         /* force display to pixel coords */
1967         v2d->flag |= (V2D_PIXELOFS_X | V2D_PIXELOFS_Y);
1968         /* set matrix for 2d-view controls */
1969         UI_view2d_view_ortho(v2d);
1970
1971         /* draw outliner stuff (background, hierarchy lines and names) */
1972         outliner_back(ar);
1973         block = UI_block_begin(C, ar, __func__, UI_EMBOSS);
1974         outliner_draw_tree(
1975                 (bContext *)C, block, scene, view_layer,
1976                 ar, soops, has_restrict_icons, &te_edit);
1977
1978         if (soops->outlinevis == SO_DATA_API) {
1979                 /* draw rna buttons */
1980                 outliner_draw_rnacols(ar, sizex_rna);
1981                 outliner_draw_rnabuts(block, ar, soops, sizex_rna, &soops->tree);
1982         }
1983         else if ((soops->outlinevis == SO_ID_ORPHANS) && has_restrict_icons) {
1984                 /* draw user toggle columns */
1985                 outliner_draw_restrictcols(ar);
1986                 outliner_draw_userbuts(block, ar, soops, &soops->tree);
1987         }
1988         else if (has_restrict_icons) {
1989                 /* draw restriction columns */
1990                 outliner_draw_restrictcols(ar);
1991                 outliner_draw_restrictbuts(block, scene, ar, soops, &soops->tree);
1992         }
1993
1994         /* draw edit buttons if nessecery */
1995         if (te_edit) {
1996                 outliner_buttons(C, block, ar, te_edit);
1997         }
1998
1999         UI_block_end(C, block);
2000         UI_block_draw(C, block);
2001 }