Merge branch 'blender2.8' into soc-2018-bevel
[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, BKE_main_blendfile_path(bmain));
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(bmain, 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(bmain, 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(bmain, 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                                         case eModifierType_WeightedNormal:
1024                                                 ICON_DRAW(ICON_MOD_NORMALEDIT);
1025                                                 break;
1026                                         /* Default */
1027                                         case eModifierType_None:
1028                                         case eModifierType_ShapeKey:
1029                                         case NUM_MODIFIER_TYPES:
1030                                                 ICON_DRAW(ICON_DOT);
1031                                                 break;
1032                                 }
1033                                 break;
1034                         }
1035                         case TSE_POSE_BASE:
1036                                 ICON_DRAW(ICON_ARMATURE_DATA);
1037                                 break;
1038                         case TSE_POSE_CHANNEL:
1039                                 ICON_DRAW(ICON_BONE_DATA);
1040                                 break;
1041                         case TSE_PROXY:
1042                                 ICON_DRAW(ICON_GHOST);
1043                                 break;
1044                         case TSE_R_LAYER_BASE:
1045                                 ICON_DRAW(ICON_RENDERLAYERS);
1046                                 break;
1047                         case TSE_SCENE_OBJECTS_BASE:
1048                                 ICON_DRAW(ICON_OUTLINER_OB_GROUP_INSTANCE);
1049                                 break;
1050                         case TSE_R_LAYER:
1051                                 ICON_DRAW(ICON_RENDER_RESULT);
1052                                 break;
1053                         case TSE_LINKED_LAMP:
1054                                 ICON_DRAW(ICON_LAMP_DATA);
1055                                 break;
1056                         case TSE_LINKED_MAT:
1057                                 ICON_DRAW(ICON_MATERIAL_DATA);
1058                                 break;
1059                         case TSE_POSEGRP_BASE:
1060                                 ICON_DRAW(ICON_GROUP_BONE);
1061                                 break;
1062                         case TSE_SEQUENCE:
1063                                 if (te->idcode == SEQ_TYPE_MOVIE)
1064                                         ICON_DRAW(ICON_SEQUENCE);
1065                                 else if (te->idcode == SEQ_TYPE_META)
1066                                         ICON_DRAW(ICON_DOT);
1067                                 else if (te->idcode == SEQ_TYPE_SCENE)
1068                                         ICON_DRAW(ICON_SCENE);
1069                                 else if (te->idcode == SEQ_TYPE_SOUND_RAM)
1070                                         ICON_DRAW(ICON_SOUND);
1071                                 else if (te->idcode == SEQ_TYPE_IMAGE)
1072                                         ICON_DRAW(ICON_IMAGE_COL);
1073                                 else
1074                                         ICON_DRAW(ICON_PARTICLES);
1075                                 break;
1076                         case TSE_SEQ_STRIP:
1077                                 ICON_DRAW(ICON_LIBRARY_DATA_DIRECT);
1078                                 break;
1079                         case TSE_SEQUENCE_DUP:
1080                                 ICON_DRAW(ICON_OBJECT_DATA);
1081                                 break;
1082                         case TSE_RNA_STRUCT:
1083                                 if (RNA_struct_is_ID(te->rnaptr.type)) {
1084                                         arg.id = (ID *)te->rnaptr.data;
1085                                         tselem_draw_icon_uibut(&arg, RNA_struct_ui_icon(te->rnaptr.type));
1086                                 }
1087                                 else {
1088                                         int icon = RNA_struct_ui_icon(te->rnaptr.type);
1089                                         ICON_DRAW(icon);
1090                                 }
1091                                 break;
1092                         case TSE_LAYER_COLLECTION:
1093                         case TSE_SCENE_COLLECTION_BASE:
1094                         case TSE_VIEW_COLLECTION_BASE:
1095                                 ICON_DRAW(ICON_GROUP);
1096                                 break;
1097                         /* Removed the icons from outliner. Need a better structure with Layers, Palettes and Colors */
1098 #if 0
1099                         case TSE_GP_LAYER:
1100                                 tselem_draw_gp_icon_uibut(&arg, tselem->id, te->directdata);
1101                                 break;
1102 #endif
1103                         default:
1104                                 ICON_DRAW(ICON_DOT);
1105                                 break;
1106                 }
1107         }
1108         else if (tselem->id) {
1109                 if (GS(tselem->id->name) == ID_OB) {
1110                         Object *ob = (Object *)tselem->id;
1111                         switch (ob->type) {
1112                                 case OB_LAMP:
1113                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_LAMP); break;
1114                                 case OB_MESH:
1115                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_MESH); break;
1116                                 case OB_CAMERA:
1117                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_CAMERA); break;
1118                                 case OB_CURVE:
1119                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_CURVE); break;
1120                                 case OB_MBALL:
1121                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_META); break;
1122                                 case OB_LATTICE:
1123                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_LATTICE); break;
1124                                 case OB_ARMATURE:
1125                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_ARMATURE); break;
1126                                 case OB_FONT:
1127                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_FONT); break;
1128                                 case OB_SURF:
1129                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_SURFACE); break;
1130                                 case OB_SPEAKER:
1131                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_SPEAKER); break;
1132                                 case OB_LIGHTPROBE:
1133                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_LIGHTPROBE); break;
1134                                 case OB_EMPTY:
1135                                         if (ob->dup_group) {
1136                                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_GROUP_INSTANCE);
1137                                         }
1138                                         else {
1139                                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_EMPTY);
1140                                         }
1141                                         break;
1142                         }
1143                 }
1144                 else {
1145                         /* TODO(sergey): Casting to short here just to handle ID_NLA which is
1146                          * NOT inside of IDType enum.
1147                          */
1148                         switch ((short)GS(tselem->id->name)) {
1149                                 case ID_SCE:
1150                                         tselem_draw_icon_uibut(&arg, ICON_SCENE_DATA); break;
1151                                 case ID_ME:
1152                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_MESH); break;
1153                                 case ID_CU:
1154                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_CURVE); break;
1155                                 case ID_MB:
1156                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_META); break;
1157                                 case ID_LT:
1158                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_LATTICE); break;
1159                                 case ID_LA:
1160                                 {
1161                                         Lamp *la = (Lamp *)tselem->id;
1162                                         switch (la->type) {
1163                                                 case LA_LOCAL:
1164                                                         tselem_draw_icon_uibut(&arg, ICON_LAMP_POINT); break;
1165                                                 case LA_SUN:
1166                                                         tselem_draw_icon_uibut(&arg, ICON_LAMP_SUN); break;
1167                                                 case LA_SPOT:
1168                                                         tselem_draw_icon_uibut(&arg, ICON_LAMP_SPOT); break;
1169                                                 case LA_HEMI:
1170                                                         tselem_draw_icon_uibut(&arg, ICON_LAMP_HEMI); break;
1171                                                 case LA_AREA:
1172                                                         tselem_draw_icon_uibut(&arg, ICON_LAMP_AREA); break;
1173                                                 default:
1174                                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_LAMP); break;
1175                                         }
1176                                         break;
1177                                 }
1178                                 case ID_MA:
1179                                         tselem_draw_icon_uibut(&arg, ICON_MATERIAL_DATA); break;
1180                                 case ID_TE:
1181                                         tselem_draw_icon_uibut(&arg, ICON_TEXTURE_DATA); break;
1182                                 case ID_IM:
1183                                         tselem_draw_icon_uibut(&arg, ICON_IMAGE_DATA); break;
1184                                 case ID_SPK:
1185                                 case ID_SO:
1186                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_SPEAKER); break;
1187                                 case ID_AR:
1188                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_ARMATURE); break;
1189                                 case ID_CA:
1190                                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_CAMERA); break;
1191                                 case ID_KE:
1192                                         tselem_draw_icon_uibut(&arg, ICON_SHAPEKEY_DATA); break;
1193                                 case ID_WO:
1194                                         tselem_draw_icon_uibut(&arg, ICON_WORLD_DATA); break;
1195                                 case ID_AC:
1196                                         tselem_draw_icon_uibut(&arg, ICON_ACTION); break;
1197                                 case ID_NLA:
1198                                         tselem_draw_icon_uibut(&arg, ICON_NLA); break;
1199                                 case ID_TXT:
1200                                         tselem_draw_icon_uibut(&arg, ICON_SCRIPT); break;
1201                                 case ID_GR:
1202                                         tselem_draw_icon_uibut(&arg, ICON_GROUP); break;
1203                                 case ID_LI:
1204                                         if (tselem->id->tag & LIB_TAG_MISSING) {
1205                                                 tselem_draw_icon_uibut(&arg, ICON_LIBRARY_DATA_BROKEN);
1206                                         }
1207                                         else if (((Library *)tselem->id)->parent) {
1208                                                 tselem_draw_icon_uibut(&arg, ICON_LIBRARY_DATA_INDIRECT);
1209                                         }
1210                                         else {
1211                                                 tselem_draw_icon_uibut(&arg, ICON_LIBRARY_DATA_DIRECT);
1212                                         }
1213                                         break;
1214                                 case ID_LS:
1215                                         tselem_draw_icon_uibut(&arg, ICON_LINE_DATA); break;
1216                                 case ID_GD:
1217                                         tselem_draw_icon_uibut(&arg, ICON_GREASEPENCIL); break;
1218                                 case ID_LP:
1219                                 {
1220                                         LightProbe * lp = (LightProbe *)tselem->id;
1221                                         switch (lp->type) {
1222                                                 case LIGHTPROBE_TYPE_CUBE:
1223                                                         tselem_draw_icon_uibut(&arg, ICON_LIGHTPROBE_CUBEMAP); break;
1224                                                 case LIGHTPROBE_TYPE_PLANAR:
1225                                                         tselem_draw_icon_uibut(&arg, ICON_LIGHTPROBE_PLANAR); break;
1226                                                 case LIGHTPROBE_TYPE_GRID:
1227                                                         tselem_draw_icon_uibut(&arg, ICON_LIGHTPROBE_GRID); break;
1228                                                 default:
1229                                                         tselem_draw_icon_uibut(&arg, ICON_LIGHTPROBE_CUBEMAP); break;
1230                                         }
1231                                         break;
1232                                 }
1233                                 case ID_BR:
1234                                         tselem_draw_icon_uibut(&arg, ICON_BRUSH_DATA); break;
1235                                 case ID_SCR:
1236                                 case ID_WS:
1237                                         tselem_draw_icon_uibut(&arg, ICON_SPLITSCREEN); break;
1238                                 default:
1239                                         break;
1240                         }
1241                 }
1242         }
1243
1244 #undef ICON_DRAW
1245 }
1246
1247 static void outliner_draw_iconrow(
1248         bContext *C, uiBlock *block, Scene *scene, ViewLayer *view_layer, SpaceOops *soops,
1249         ListBase *lb, int level, int xmax, int *offsx, int ys, float alpha_fac)
1250 {
1251         TreeElement *te;
1252         TreeStoreElem *tselem;
1253         eOLDrawState active;
1254         const Object *obact = OBACT(view_layer);
1255
1256         for (te = lb->first; te; te = te->next) {
1257                 /* exit drawing early */
1258                 if ((*offsx) - UI_UNIT_X > xmax)
1259                         break;
1260
1261                 tselem = TREESTORE(te);
1262
1263                 /* object hierarchy always, further constrained on level */
1264                 if (level < 1 || (tselem->type == 0 && te->idcode == ID_OB)) {
1265                         /* active blocks get white circle */
1266                         if (tselem->type == 0) {
1267                                 if (te->idcode == ID_OB) {
1268                                         active = (OBACT(view_layer) == (Object *)tselem->id) ? OL_DRAWSEL_NORMAL : OL_DRAWSEL_NONE;
1269                                 }
1270                                 else if (is_object_data_in_editmode(tselem->id, obact)) {
1271                                         active = OL_DRAWSEL_NORMAL;
1272                                 }
1273                                 else {
1274                                         active = tree_element_active(C, scene, view_layer, soops, te, OL_SETSEL_NONE, false);
1275                                 }
1276                         }
1277                         else {
1278                                 active = tree_element_type_active(C, scene, view_layer, soops, te, tselem, OL_SETSEL_NONE, false);
1279                         }
1280
1281                         if (active != OL_DRAWSEL_NONE) {
1282                                 float ufac = UI_UNIT_X / 20.0f;
1283                                 float color[4] = {1.0f, 1.0f, 1.0f, 0.4f};
1284
1285                                 UI_draw_roundbox_corner_set(UI_CNR_ALL);
1286                                 color[3] *= alpha_fac;
1287
1288                                 UI_draw_roundbox_aa(
1289                                         true,
1290                                         (float) *offsx + 1.0f * ufac,
1291                                         (float)ys + 1.0f * ufac,
1292                                         (float)*offsx + UI_UNIT_X - 1.0f * ufac,
1293                                         (float)ys + UI_UNIT_Y - ufac,
1294                                         (float)UI_UNIT_Y / 2.0f - ufac,
1295                                         color);
1296                                 glEnable(GL_BLEND); /* roundbox disables */
1297                         }
1298
1299                         tselem_draw_icon(block, xmax, (float)*offsx, (float)ys, tselem, te, 0.5f * alpha_fac);
1300                         te->xs = *offsx;
1301                         te->ys = ys;
1302                         te->xend = (short)*offsx + UI_UNIT_X;
1303                         te->flag |= TE_ICONROW; // for click
1304
1305                         (*offsx) += UI_UNIT_X;
1306                 }
1307
1308                 /* this tree element always has same amount of branches, so don't draw */
1309                 if (tselem->type != TSE_R_LAYER) {
1310                         outliner_draw_iconrow(
1311                                 C, block, scene, view_layer, soops,
1312                                 &te->subtree, level + 1, xmax, offsx, ys, alpha_fac);
1313                 }
1314         }
1315
1316 }
1317
1318 /* closed tree element */
1319 static void outliner_set_coord_tree_element(TreeElement *te, int startx, int starty)
1320 {
1321         TreeElement *ten;
1322
1323         /* closed items may be displayed in row of parent, don't change their coordinate! */
1324         if ((te->flag & TE_ICONROW) == 0) {
1325                 /* store coord and continue, we need coordinates for elements outside view too */
1326                 te->xs = startx;
1327                 te->ys = starty;
1328         }
1329
1330         for (ten = te->subtree.first; ten; ten = ten->next) {
1331                 outliner_set_coord_tree_element(ten, startx + UI_UNIT_X, starty);
1332         }
1333 }
1334
1335
1336 static void outliner_draw_tree_element(
1337         bContext *C, uiBlock *block, const uiFontStyle *fstyle, Scene *scene, ViewLayer *view_layer,
1338         ARegion *ar, SpaceOops *soops, TreeElement *te, bool draw_grayed_out,
1339         int startx, int *starty, TreeElement **te_edit, TreeElement **te_floating)
1340 {
1341         TreeStoreElem *tselem;
1342         float ufac = UI_UNIT_X / 20.0f;
1343         int offsx = 0;
1344         eOLDrawState active = OL_DRAWSEL_NONE;
1345         float color[4];
1346         tselem = TREESTORE(te);
1347
1348         if (*starty + 2 * UI_UNIT_Y >= ar->v2d.cur.ymin && *starty <= ar->v2d.cur.ymax) {
1349                 const float alpha_fac = ((te->flag & TE_DISABLED) || draw_grayed_out) ? 0.5f : 1.0f;
1350                 const float alpha = 0.5f * alpha_fac;
1351                 int xmax = ar->v2d.cur.xmax;
1352
1353                 if ((tselem->flag & TSE_TEXTBUT) && (*te_edit == NULL)) {
1354                         *te_edit = te;
1355                 }
1356                 if ((te->drag_data != NULL) && (*te_floating == NULL)) {
1357                         *te_floating = te;
1358                 }
1359
1360                 /* icons can be ui buts, we don't want it to overlap with restrict */
1361                 if ((soops->flag & SO_HIDE_RESTRICTCOLS) == 0)
1362                         xmax -= OL_TOGW + UI_UNIT_X;
1363
1364                 glEnable(GL_BLEND);
1365
1366                 /* colors for active/selected data */
1367                 if (tselem->type == 0) {
1368                         const Object *obact = OBACT(view_layer);
1369                         if (te->idcode == ID_SCE) {
1370                                 if (tselem->id == (ID *)scene) {
1371                                         rgba_float_args_set(color, 1.0f, 1.0f, 1.0f, alpha);
1372                                         active = OL_DRAWSEL_ACTIVE;
1373                                 }
1374                         }
1375                         else if (te->idcode == ID_OB) {
1376                                 Object *ob = (Object *)tselem->id;
1377                                 Base *base = (Base *)te->directdata;
1378                                 const bool is_selected = (base != NULL) && ((base->flag & BASE_SELECTED) != 0);
1379
1380                                 if (ob == obact || is_selected) {
1381                                         char col[4] = {0, 0, 0, 0};
1382
1383                                         /* outliner active ob: always white text, circle color now similar to view3d */
1384
1385                                         active = OL_DRAWSEL_ACTIVE;
1386                                         if (ob == obact) {
1387                                                 if (is_selected) {
1388                                                         UI_GetThemeColorType4ubv(TH_ACTIVE, SPACE_VIEW3D, col);
1389                                                         col[3] = alpha;
1390                                                 }
1391
1392                                                 active = OL_DRAWSEL_NORMAL;
1393                                         }
1394                                         else if (is_selected) {
1395                                                 UI_GetThemeColorType4ubv(TH_SELECT, SPACE_VIEW3D, col);
1396                                                 col[3] = alpha;
1397                                         }
1398                                         rgba_float_args_set(color, (float)col[0] / 255, (float)col[1] / 255, (float)col[2] / 255, alpha);
1399                                 }
1400                         }
1401                         else if (is_object_data_in_editmode(tselem->id, obact)) {
1402                                 rgba_float_args_set(color, 1.0f, 1.0f, 1.0f, alpha);
1403                                 active = OL_DRAWSEL_ACTIVE;
1404                         }
1405                         else {
1406                                 if (tree_element_active(C, scene, view_layer, soops, te, OL_SETSEL_NONE, false)) {
1407                                         rgba_float_args_set(color, 0.85f, 0.85f, 1.0f, alpha);
1408                                         active = OL_DRAWSEL_ACTIVE;
1409                                 }
1410                         }
1411                 }
1412                 else {
1413                         active = tree_element_type_active(C, scene, view_layer, soops, te, tselem, OL_SETSEL_NONE, false);
1414                         rgba_float_args_set(color, 0.85f, 0.85f, 1.0f, alpha);
1415                 }
1416
1417                 /* active circle */
1418                 if (active != OL_DRAWSEL_NONE) {
1419                         UI_draw_roundbox_corner_set(UI_CNR_ALL);
1420                         UI_draw_roundbox_aa(
1421                                 true,
1422                                 (float)startx + UI_UNIT_X + 1.0f * ufac,
1423                                 (float)*starty + 1.0f * ufac,
1424                                 (float)startx + 2.0f * UI_UNIT_X - 1.0f * ufac,
1425                                 (float)*starty + UI_UNIT_Y - 1.0f * ufac,
1426                                 UI_UNIT_Y / 2.0f - 1.0f * ufac, color);
1427                         glEnable(GL_BLEND); /* roundbox disables it */
1428
1429                         te->flag |= TE_ACTIVE; // for lookup in display hierarchies
1430                 }
1431
1432                 if (tselem->type == TSE_VIEW_COLLECTION_BASE) {
1433                         /* Scene collection in view layer can't expand/collapse. */
1434                 }
1435                 else if (te->subtree.first || (tselem->type == 0 && te->idcode == ID_SCE) || (te->flag & TE_LAZY_CLOSED)) {
1436                         /* open/close icon, only when sublevels, except for scene */
1437                         int icon_x = startx;
1438
1439                         // icons a bit higher
1440                         if (TSELEM_OPEN(tselem, soops))
1441                                 UI_icon_draw_alpha((float)icon_x + 2 * ufac, (float)*starty + 1 * ufac, ICON_DISCLOSURE_TRI_DOWN,
1442                                                    alpha_fac);
1443                         else
1444                                 UI_icon_draw_alpha((float)icon_x + 2 * ufac, (float)*starty + 1 * ufac, ICON_DISCLOSURE_TRI_RIGHT,
1445                                                    alpha_fac);
1446                 }
1447                 offsx += UI_UNIT_X;
1448
1449                 /* datatype icon */
1450
1451                 if (!(ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM, TSE_ID_BASE))) {
1452                         tselem_draw_icon(block, xmax, (float)startx + offsx, (float)*starty, tselem, te, alpha_fac);
1453                         offsx += UI_UNIT_X + 2 * ufac;
1454                 }
1455                 else
1456                         offsx += 2 * ufac;
1457
1458                 if (ELEM(tselem->type, 0, TSE_LAYER_COLLECTION) && ID_IS_LINKED(tselem->id)) {
1459                         if (tselem->id->tag & LIB_TAG_MISSING) {
1460                                 UI_icon_draw_alpha((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_BROKEN,
1461                                                    alpha_fac);
1462                         }
1463                         else if (tselem->id->tag & LIB_TAG_INDIRECT) {
1464                                 UI_icon_draw_alpha((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_INDIRECT,
1465                                                    alpha_fac);
1466                         }
1467                         else {
1468                                 UI_icon_draw_alpha((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_DIRECT,
1469                                                    alpha_fac);
1470                         }
1471                         offsx += UI_UNIT_X + 2 * ufac;
1472                 }
1473                 else if (ELEM(tselem->type, 0, TSE_LAYER_COLLECTION) && ID_IS_STATIC_OVERRIDE(tselem->id)) {
1474                         UI_icon_draw_alpha((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_OVERRIDE,
1475                                            alpha_fac);
1476                         offsx += UI_UNIT_X + 2 * ufac;
1477                 }
1478                 glDisable(GL_BLEND);
1479
1480                 /* name */
1481                 if ((tselem->flag & TSE_TEXTBUT) == 0) {
1482                         unsigned char text_col[4];
1483
1484                         if (active == OL_DRAWSEL_NORMAL) {
1485                                 UI_GetThemeColor4ubv(TH_TEXT_HI, text_col);
1486                         }
1487                         else if (ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) {
1488                                 UI_GetThemeColorBlend3ubv(TH_BACK, TH_TEXT, 0.75f, text_col);
1489                                 text_col[3] = 255;
1490                         }
1491                         else {
1492                                 UI_GetThemeColor4ubv(TH_TEXT, text_col);
1493                         }
1494                         text_col[3] *= alpha_fac;
1495
1496                         UI_fontstyle_draw_simple(fstyle, startx + offsx, *starty + 5 * ufac, te->name, text_col);
1497                 }
1498
1499                 offsx += (int)(UI_UNIT_X + UI_fontstyle_string_width(fstyle, te->name));
1500
1501                 /* closed item, we draw the icons, not when it's a scene, or master-server list though */
1502                 if (!TSELEM_OPEN(tselem, soops)) {
1503                         if (te->subtree.first) {
1504                                 if (tselem->type == 0 && te->idcode == ID_SCE) {
1505                                         /* pass */
1506                                 }
1507                                 /* this tree element always has same amount of branches, so don't draw */
1508                                 else if (tselem->type != TSE_R_LAYER) {
1509                                         int tempx = startx + offsx;
1510
1511                                         glEnable(GL_BLEND);
1512
1513                                         /* divider */
1514                                         {
1515                                                 Gwn_VertFormat *format = immVertexFormat();
1516                                                 unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
1517                                                 unsigned char col[4];
1518
1519                                                 immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
1520                                                 UI_GetThemeColorShade4ubv(TH_BACK, -40, col);
1521                                                 col[3] *= alpha_fac;
1522
1523                                                 immUniformColor4ubv(col);
1524                                                 immRecti(pos, tempx   - 10.0f * ufac,
1525                                                          *starty +  4.0f * ufac,
1526                                                          tempx   -  8.0f * ufac,
1527                                                          *starty + UI_UNIT_Y - 4.0f * ufac);
1528                                                 immUnbindProgram();
1529                                         }
1530
1531                                         outliner_draw_iconrow(
1532                                                 C, block, scene, view_layer, soops, &te->subtree, 0, xmax, &tempx,
1533                                                 *starty, alpha_fac);
1534
1535                                         glDisable(GL_BLEND);
1536                                 }
1537                         }
1538                 }
1539         }
1540         /* store coord and continue, we need coordinates for elements outside view too */
1541         te->xs = startx;
1542         te->ys = *starty;
1543         te->xend = startx + offsx;
1544
1545         if (TSELEM_OPEN(tselem, soops)) {
1546                 *starty -= UI_UNIT_Y;
1547
1548                 for (TreeElement *ten = te->subtree.first; ten; ten = ten->next) {
1549                         /* check if element needs to be drawn grayed out, but also gray out
1550                          * childs of a grayed out parent (pass on draw_grayed_out to childs) */
1551                         bool draw_childs_grayed_out = draw_grayed_out || (ten->drag_data != NULL);
1552                         outliner_draw_tree_element(
1553                                 C, block, fstyle, scene, view_layer,
1554                                 ar, soops, ten, draw_childs_grayed_out,
1555                                 startx + UI_UNIT_X, starty, te_edit, te_floating);
1556                 }
1557         }
1558         else {
1559                 for (TreeElement *ten = te->subtree.first; ten; ten = ten->next) {
1560                         outliner_set_coord_tree_element(ten, startx, *starty);
1561                 }
1562
1563                 *starty -= UI_UNIT_Y;
1564         }
1565 }
1566
1567 static void outliner_draw_tree_element_floating(
1568         const ARegion *ar, const TreeElement *te_floating)
1569 {
1570         const TreeElement *te_insert = te_floating->drag_data->insert_handle;
1571         const int line_width = 2;
1572
1573         unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
1574         int coord_y = te_insert->ys;
1575         int coord_x = te_insert->xs;
1576         float col[4];
1577
1578         if (te_insert == te_floating) {
1579                 /* don't draw anything */
1580                 return;
1581         }
1582
1583         UI_GetThemeColorShade4fv(TH_BACK, -40, col);
1584         immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
1585         glEnable(GL_BLEND);
1586
1587         if (ELEM(te_floating->drag_data->insert_type, TE_INSERT_BEFORE, TE_INSERT_AFTER)) {
1588                 if (te_floating->drag_data->insert_type == TE_INSERT_BEFORE) {
1589                         coord_y += UI_UNIT_Y;
1590                 }
1591                 immUniformColor4fv(col);
1592                 glLineWidth(line_width);
1593
1594                 immBegin(GWN_PRIM_LINE_STRIP, 2);
1595                 immVertex2f(pos, coord_x, coord_y);
1596                 immVertex2f(pos, ar->v2d.cur.xmax, coord_y);
1597                 immEnd();
1598         }
1599         else {
1600                 BLI_assert(te_floating->drag_data->insert_type == TE_INSERT_INTO);
1601                 immUniformColor3fvAlpha(col, col[3] * 0.5f);
1602
1603                 immBegin(GWN_PRIM_TRI_STRIP, 4);
1604                 immVertex2f(pos, coord_x, coord_y + UI_UNIT_Y);
1605                 immVertex2f(pos, coord_x, coord_y);
1606                 immVertex2f(pos, ar->v2d.cur.xmax, coord_y + UI_UNIT_Y);
1607                 immVertex2f(pos, ar->v2d.cur.xmax, coord_y);
1608                 immEnd();
1609         }
1610
1611         glDisable(GL_BLEND);
1612         immUnbindProgram();
1613 }
1614
1615 static void outliner_draw_hierarchy_lines_recursive(unsigned pos, SpaceOops *soops, ListBase *lb, int startx,
1616                                                     const unsigned char col[4], bool draw_grayed_out,
1617                                                     int *starty)
1618 {
1619         TreeElement *te, *te_vertical_line_last = NULL;
1620         TreeStoreElem *tselem;
1621         int y1, y2;
1622
1623         if (BLI_listbase_is_empty(lb)) {
1624                 return;
1625         }
1626
1627         const unsigned char grayed_alpha = col[3] / 2;
1628
1629         /* For vertical lines between objects. */
1630         y1 = y2 = *starty;
1631         for (te = lb->first; te; te = te->next) {
1632                 bool draw_childs_grayed_out = draw_grayed_out || (te->drag_data != NULL);
1633                 tselem = TREESTORE(te);
1634
1635                 if (draw_childs_grayed_out) {
1636                         immUniformColor3ubvAlpha(col, grayed_alpha);
1637                 }
1638                 else {
1639                         immUniformColor4ubv(col);
1640                 }
1641
1642                 /* Horizontal Line? */
1643                 if (tselem->type == 0 && (te->idcode == ID_OB || te->idcode == ID_SCE)) {
1644                         immRecti(pos, startx, *starty, startx + UI_UNIT_X, *starty - 1);
1645
1646                         /* Vertical Line? */
1647                         if (te->idcode == ID_OB) {
1648                                 te_vertical_line_last = te;
1649                                 y2 = *starty;
1650                         }
1651                 }
1652
1653                 *starty -= UI_UNIT_Y;
1654
1655                 if (TSELEM_OPEN(tselem, soops))
1656                         outliner_draw_hierarchy_lines_recursive(pos, soops, &te->subtree, startx + UI_UNIT_X,
1657                                                                 col, draw_childs_grayed_out, starty);
1658         }
1659
1660         if (draw_grayed_out) {
1661                 immUniformColor3ubvAlpha(col, grayed_alpha);
1662         }
1663         else {
1664                 immUniformColor4ubv(col);
1665         }
1666
1667         /* Vertical line. */
1668         te = te_vertical_line_last;
1669         if ((te != NULL) && (te->parent || lb->first != lb->last)) {
1670                 immRecti(pos, startx, y1 + UI_UNIT_Y, startx + 1, y2);
1671         }
1672 }
1673
1674 static void outliner_draw_hierarchy_lines(SpaceOops *soops, ListBase *lb, int startx, int *starty)
1675 {
1676         Gwn_VertFormat *format = immVertexFormat();
1677         unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
1678         unsigned char col[4];
1679
1680         immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
1681         UI_GetThemeColorBlend3ubv(TH_BACK, TH_TEXT, 0.4f, col);
1682         col[3] = 255;
1683
1684         glEnable(GL_BLEND);
1685         outliner_draw_hierarchy_lines_recursive(pos, soops, lb, startx, col, false, starty);
1686         glDisable(GL_BLEND);
1687
1688         immUnbindProgram();
1689 }
1690
1691 static void outliner_draw_struct_marks(ARegion *ar, SpaceOops *soops, ListBase *lb, int *starty)
1692 {
1693         TreeElement *te;
1694         TreeStoreElem *tselem;
1695
1696         for (te = lb->first; te; te = te->next) {
1697                 tselem = TREESTORE(te);
1698
1699                 /* selection status */
1700                 if (TSELEM_OPEN(tselem, soops))
1701                         if (tselem->type == TSE_RNA_STRUCT) {
1702                                 Gwn_VertFormat *format = immVertexFormat();
1703                                 unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
1704                                 immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
1705                                 immThemeColorShadeAlpha(TH_BACK, -15, -200);
1706                                 immRecti(pos, 0, *starty + 1, (int)ar->v2d.cur.xmax, *starty + UI_UNIT_Y - 1);
1707                                 immUnbindProgram();
1708                         }
1709
1710                 *starty -= UI_UNIT_Y;
1711                 if (TSELEM_OPEN(tselem, soops)) {
1712                         outliner_draw_struct_marks(ar, soops, &te->subtree, starty);
1713                         if (tselem->type == TSE_RNA_STRUCT) {
1714                                 Gwn_VertFormat *format = immVertexFormat();
1715                                 unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
1716                                 immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
1717                                 immThemeColorShadeAlpha(TH_BACK, -15, -200);
1718
1719                                 immBegin(GWN_PRIM_LINES, 2);
1720                                 immVertex2f(pos, 0, (float)*starty + UI_UNIT_Y);
1721                                 immVertex2f(pos, ar->v2d.cur.xmax, (float)*starty + UI_UNIT_Y);
1722                                 immEnd();
1723
1724                                 immUnbindProgram();
1725                         }
1726                 }
1727         }
1728 }
1729
1730 static void outliner_draw_highlights_recursive(
1731         unsigned pos, const ARegion *ar, const SpaceOops *soops, const ListBase *lb,
1732         const float col_selection[4], const float col_highlight[4], const float col_searchmatch[4],
1733         int start_x, int *io_start_y)
1734 {
1735         const bool is_searching = SEARCHING_OUTLINER(soops) ||
1736                                   (soops->outlinevis == SO_DATA_API &&
1737                                    (soops->filter & SO_FILTER_SEARCH) &&
1738                                    soops->search_string[0] != 0);
1739
1740         for (TreeElement *te = lb->first; te; te = te->next) {
1741                 const TreeStoreElem *tselem = TREESTORE(te);
1742                 const int start_y = *io_start_y;
1743
1744                 /* selection status */
1745                 if (tselem->flag & TSE_SELECTED) {
1746                         immUniformColor4fv(col_selection);
1747                         immRecti(pos, 0, start_y + 1, (int)ar->v2d.cur.xmax, start_y + UI_UNIT_Y - 1);
1748                 }
1749
1750                 /* search match highlights
1751                  *   we don't expand items when searching in the datablocks but we
1752                  *   still want to highlight any filter matches. */
1753                 if (is_searching && (tselem->flag & TSE_SEARCHMATCH)) {
1754                         immUniformColor4fv(col_searchmatch);
1755                         immRecti(pos, start_x, start_y + 1, ar->v2d.cur.xmax, start_y + UI_UNIT_Y - 1);
1756                 }
1757
1758                 /* mouse hover highlights */
1759                 if ((tselem->flag & TSE_HIGHLIGHTED) || (te->drag_data != NULL)) {
1760                         immUniformColor4fv(col_highlight);
1761                         immRecti(pos, 0, start_y + 1, (int)ar->v2d.cur.xmax, start_y + UI_UNIT_Y - 1);
1762                 }
1763
1764                 *io_start_y -= UI_UNIT_Y;
1765                 if (TSELEM_OPEN(tselem, soops)) {
1766                         outliner_draw_highlights_recursive(
1767                                 pos, ar, soops, &te->subtree, col_selection, col_highlight, col_searchmatch,
1768                                 start_x + UI_UNIT_X, io_start_y);
1769                 }
1770         }
1771 }
1772
1773 static void outliner_draw_highlights(ARegion *ar, SpaceOops *soops, int startx, int *starty)
1774 {
1775         const float col_highlight[4] = {1.0f, 1.0f, 1.0f, 0.13f};
1776         float col_selection[4], col_searchmatch[4];
1777
1778         UI_GetThemeColor3fv(TH_SELECT_HIGHLIGHT, col_selection);
1779         col_selection[3] = 1.0f; /* no alpha */
1780         UI_GetThemeColor4fv(TH_MATCH, col_searchmatch);
1781         col_searchmatch[3] = 0.5f;
1782
1783         glEnable(GL_BLEND);
1784         Gwn_VertFormat *format = immVertexFormat();
1785         unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
1786         immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
1787         outliner_draw_highlights_recursive(pos, ar, soops, &soops->tree, col_selection, col_highlight, col_searchmatch,
1788                                            startx, starty);
1789         immUnbindProgram();
1790         glDisable(GL_BLEND);
1791 }
1792
1793 static void outliner_draw_tree(
1794         bContext *C, uiBlock *block, Scene *scene, ViewLayer *view_layer,
1795         ARegion *ar, SpaceOops *soops, const bool has_restrict_icons,
1796         TreeElement **te_edit)
1797 {
1798         const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
1799         TreeElement *te_floating = NULL;
1800         int starty, startx;
1801
1802         glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); // only once
1803
1804         if (soops->outlinevis == SO_DATA_API) {
1805                 /* struct marks */
1806                 starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y - OL_Y_OFFSET;
1807                 outliner_draw_struct_marks(ar, soops, &soops->tree, &starty);
1808         }
1809
1810         /* draw highlights before hierarchy */
1811         starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y - OL_Y_OFFSET;
1812         startx = 0;
1813         outliner_draw_highlights(ar, soops, startx, &starty);
1814
1815         /* set scissor so tree elements or lines can't overlap restriction icons */
1816         GLfloat scissor[4] = {0};
1817         if (has_restrict_icons) {
1818                 int mask_x = BLI_rcti_size_x(&ar->v2d.mask) - (int)OL_TOGW + 1;
1819                 CLAMP_MIN(mask_x, 0);
1820
1821                 glGetFloatv(GL_SCISSOR_BOX, scissor);
1822                 glScissor(0, 0, mask_x, ar->winy);
1823         }
1824
1825         // gray hierarchy lines
1826
1827         starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y / 2 - OL_Y_OFFSET;
1828         startx = UI_UNIT_X / 2 - 1.0f;
1829         outliner_draw_hierarchy_lines(soops, &soops->tree, startx, &starty);
1830
1831         // items themselves
1832         starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y - OL_Y_OFFSET;
1833         startx = 0;
1834         for (TreeElement *te = soops->tree.first; te; te = te->next) {
1835                 outliner_draw_tree_element(
1836                         C, block, fstyle, scene, view_layer,
1837                         ar, soops, te, te->drag_data != NULL,
1838                         startx, &starty, te_edit, &te_floating);
1839         }
1840         if (te_floating && te_floating->drag_data->insert_handle) {
1841                 outliner_draw_tree_element_floating(ar, te_floating);
1842         }
1843
1844         if (has_restrict_icons) {
1845                 /* reset scissor */
1846                 glScissor(UNPACK4(scissor));
1847         }
1848 }
1849
1850
1851 static void outliner_back(ARegion *ar)
1852 {
1853         int ystart;
1854
1855         ystart = (int)ar->v2d.tot.ymax;
1856         ystart = UI_UNIT_Y * (ystart / (UI_UNIT_Y)) - OL_Y_OFFSET;
1857
1858         Gwn_VertFormat *format = immVertexFormat();
1859         unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
1860
1861         immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
1862         immUniformThemeColorShade(TH_BACK, 6);
1863
1864         const float x1 = 0.0f, x2 = ar->v2d.cur.xmax;
1865         float y1 = ystart, y2;
1866         int tot = (int)floor(ystart - ar->v2d.cur.ymin + 2 * UI_UNIT_Y) / (2 * UI_UNIT_Y);
1867
1868         if (tot > 0) {
1869                 immBegin(GWN_PRIM_TRIS, 6 * tot);
1870                 while (tot--) {
1871                         y1 -= 2 * UI_UNIT_Y;
1872                         y2 = y1 + UI_UNIT_Y;
1873                         immVertex2f(pos, x1, y1);
1874                         immVertex2f(pos, x2, y1);
1875                         immVertex2f(pos, x2, y2);
1876
1877                         immVertex2f(pos, x1, y1);
1878                         immVertex2f(pos, x2, y2);
1879                         immVertex2f(pos, x1, y2);
1880                 }
1881                 immEnd();
1882         }
1883         immUnbindProgram();
1884 }
1885
1886 static void outliner_draw_restrictcols(ARegion *ar)
1887 {
1888         glLineWidth(1.0f);
1889
1890         unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
1891         immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
1892         immUniformThemeColorShadeAlpha(TH_BACK, -15, -200);
1893         immBegin(GWN_PRIM_LINES, 6);
1894
1895         immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), (int)ar->v2d.cur.ymax);
1896         immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), (int)ar->v2d.cur.ymin);
1897
1898         immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), (int)ar->v2d.cur.ymax);
1899         immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), (int)ar->v2d.cur.ymin);
1900
1901         immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), (int)ar->v2d.cur.ymax);
1902         immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), (int)ar->v2d.cur.ymin);
1903
1904         immEnd();
1905         immUnbindProgram();
1906 }
1907
1908 /* ****************************************************** */
1909 /* Main Entrypoint - Draw contents of Outliner editor */
1910
1911 void draw_outliner(const bContext *C)
1912 {
1913         Main *mainvar = CTX_data_main(C);
1914         Scene *scene = CTX_data_scene(C);
1915         ViewLayer *view_layer = CTX_data_view_layer(C);
1916         ARegion *ar = CTX_wm_region(C);
1917         View2D *v2d = &ar->v2d;
1918         SpaceOops *soops = CTX_wm_space_outliner(C);
1919         uiBlock *block;
1920         int sizey = 0, sizex = 0, sizex_rna = 0;
1921         TreeElement *te_edit = NULL;
1922         bool has_restrict_icons;
1923
1924         outliner_build_tree(mainvar, scene, view_layer, soops, ar); // always
1925
1926         /* get extents of data */
1927         outliner_height(soops, &soops->tree, &sizey);
1928
1929         if (soops->outlinevis == SO_DATA_API) {
1930                 /* RNA has two columns:
1931                  *  - column 1 is (max_width + OL_RNA_COL_SPACEX) or
1932                  *                               (OL_RNA_COL_X), whichever is wider...
1933                  *      - column 2 is fixed at OL_RNA_COL_SIZEX
1934                  *
1935                  *  (*) XXX max width for now is a fixed factor of (UI_UNIT_X * (max_indention + 100))
1936                  */
1937
1938                 /* get actual width of column 1 */
1939                 outliner_rna_width(soops, &soops->tree, &sizex_rna, 0);
1940                 sizex_rna = max_ii(OL_RNA_COLX, sizex_rna + OL_RNA_COL_SPACEX);
1941
1942                 /* get width of data (for setting 'tot' rect, this is column 1 + column 2 + a bit extra) */
1943                 sizex = sizex_rna + OL_RNA_COL_SIZEX + 50;
1944                 has_restrict_icons = false;
1945         }
1946         else {
1947                 /* width must take into account restriction columns (if visible) so that entries will still be visible */
1948                 //outliner_width(soops, &soops->tree, &sizex);
1949                 // XXX should use outliner_width instead when te->xend will be set correctly...
1950                 outliner_rna_width(soops, &soops->tree, &sizex, 0);
1951
1952                 /* constant offset for restriction columns */
1953                 // XXX this isn't that great yet...
1954                 if ((soops->flag & SO_HIDE_RESTRICTCOLS) == 0) {
1955                         sizex += OL_TOGW * 3;
1956                 }
1957
1958                 has_restrict_icons = !(soops->flag & SO_HIDE_RESTRICTCOLS);
1959         }
1960
1961         /* adds vertical offset */
1962         sizey += OL_Y_OFFSET;
1963
1964         /* update size of tot-rect (extents of data/viewable area) */
1965         UI_view2d_totRect_set(v2d, sizex, sizey);
1966
1967         /* force display to pixel coords */
1968         v2d->flag |= (V2D_PIXELOFS_X | V2D_PIXELOFS_Y);
1969         /* set matrix for 2d-view controls */
1970         UI_view2d_view_ortho(v2d);
1971
1972         /* draw outliner stuff (background, hierarchy lines and names) */
1973         outliner_back(ar);
1974         block = UI_block_begin(C, ar, __func__, UI_EMBOSS);
1975         outliner_draw_tree(
1976                 (bContext *)C, block, scene, view_layer,
1977                 ar, soops, has_restrict_icons, &te_edit);
1978
1979         if (soops->outlinevis == SO_DATA_API) {
1980                 /* draw rna buttons */
1981                 outliner_draw_rnacols(ar, sizex_rna);
1982                 outliner_draw_rnabuts(block, ar, soops, sizex_rna, &soops->tree);
1983         }
1984         else if ((soops->outlinevis == SO_ID_ORPHANS) && has_restrict_icons) {
1985                 /* draw user toggle columns */
1986                 outliner_draw_restrictcols(ar);
1987                 outliner_draw_userbuts(block, ar, soops, &soops->tree);
1988         }
1989         else if (has_restrict_icons) {
1990                 /* draw restriction columns */
1991                 outliner_draw_restrictcols(ar);
1992                 outliner_draw_restrictbuts(block, scene, ar, soops, &soops->tree);
1993         }
1994
1995         /* draw edit buttons if nessecery */
1996         if (te_edit) {
1997                 outliner_buttons(C, block, ar, te_edit);
1998         }
1999
2000         UI_block_end(C, block);
2001         UI_block_draw(C, block);
2002 }