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