d37cb4be8fa72a4cf2bb4542d2f4967edfd64f14
[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_armature_types.h"
33 #include "DNA_group_types.h"
34 #include "DNA_lamp_types.h"
35 #include "DNA_object_types.h"
36 #include "DNA_scene_types.h"
37 #include "DNA_sequence_types.h"
38
39 #include "BLI_math.h"
40 #include "BLI_blenlib.h"
41 #include "BLI_utildefines.h"
42 #include "BLI_ghash.h"
43
44 #include "BKE_context.h"
45 #include "BKE_deform.h"
46 #include "BKE_depsgraph.h"
47 #include "BKE_global.h"
48 #include "BKE_library.h"
49 #include "BKE_main.h"
50 #include "BKE_modifier.h"
51 #include "BKE_report.h"
52 #include "BKE_scene.h"
53
54 #include "ED_armature.h"
55 #include "ED_object.h"
56 #include "ED_screen.h"
57
58 #include "WM_api.h"
59 #include "WM_types.h"
60
61 #include "BIF_gl.h"
62 #include "BIF_glutil.h"
63
64 #include "UI_interface.h"
65 #include "UI_interface_icons.h"
66 #include "UI_resources.h"
67 #include "UI_view2d.h"
68
69 #include "RNA_access.h"
70
71 #include "outliner_intern.h"
72
73 /* disable - this is far too slow - campbell */
74 // #define USE_GROUP_SELECT
75
76 /* ****************************************************** */
77 /* Tree Size Functions */
78
79 static void outliner_height(SpaceOops *soops, ListBase *lb, int *h)
80 {
81         TreeElement *te = lb->first;
82         while (te) {
83                 TreeStoreElem *tselem = TREESTORE(te);
84                 if (TSELEM_OPEN(tselem, soops))
85                         outliner_height(soops, &te->subtree, h);
86                 (*h) += UI_UNIT_Y;
87                 te = te->next;
88         }
89 }
90
91 #if 0  // XXX this is currently disabled until te->xend is set correctly
92 static void outliner_width(SpaceOops *soops, ListBase *lb, int *w)
93 {
94         TreeElement *te = lb->first;
95         while (te) {
96 //              TreeStoreElem *tselem = TREESTORE(te);
97                 
98                 // XXX fixme... te->xend is not set yet
99                 if (!TSELEM_OPEN(tselem, soops)) {
100                         if (te->xend > *w)
101                                 *w = te->xend;
102                 }
103                 outliner_width(soops, &te->subtree, w);
104                 te = te->next;
105         }
106 }
107 #endif
108
109 static void outliner_rna_width(SpaceOops *soops, ListBase *lb, int *w, int startx)
110 {
111         TreeElement *te = lb->first;
112         while (te) {
113                 TreeStoreElem *tselem = TREESTORE(te);
114                 // XXX fixme... (currently, we're using a fixed length of 100)!
115 #if 0
116                 if (te->xend) {
117                         if (te->xend > *w)
118                                 *w = te->xend;
119                 }
120 #endif
121                 if (startx + 100 > *w)
122                         *w = startx + 100;
123
124                 if (TSELEM_OPEN(tselem, soops))
125                         outliner_rna_width(soops, &te->subtree, w, startx + UI_UNIT_X);
126                 te = te->next;
127         }
128 }
129
130 /* ****************************************************** */
131
132 static void restrictbutton_view_cb(bContext *C, void *poin, void *poin2)
133 {
134         Scene *scene = (Scene *)poin;
135         Object *ob = (Object *)poin2;
136
137         if (!common_restrict_check(C, ob)) return;
138         
139         /* deselect objects that are invisible */
140         if (ob->restrictflag & OB_RESTRICT_VIEW) {
141                 /* Ouch! There is no backwards pointer from Object to Base, 
142                  * so have to do loop to find it. */
143                 ED_base_object_select(BKE_scene_base_find(scene, ob), BA_DESELECT);
144         }
145         WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
146
147 }
148
149 static void restrictbutton_sel_cb(bContext *C, void *poin, void *poin2)
150 {
151         Scene *scene = (Scene *)poin;
152         Object *ob = (Object *)poin2;
153         
154         if (!common_restrict_check(C, ob)) return;
155         
156         /* if select restriction has just been turned on */
157         if (ob->restrictflag & OB_RESTRICT_SELECT) {
158                 /* Ouch! There is no backwards pointer from Object to Base, 
159                  * so have to do loop to find it. */
160                 ED_base_object_select(BKE_scene_base_find(scene, ob), BA_DESELECT);
161         }
162         WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
163
164 }
165
166 static void restrictbutton_rend_cb(bContext *C, void *poin, void *UNUSED(poin2))
167 {
168         WM_event_add_notifier(C, NC_SCENE | ND_OB_RENDER, poin);
169 }
170
171 static void restrictbutton_r_lay_cb(bContext *C, void *poin, void *UNUSED(poin2))
172 {
173         WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, poin);
174 }
175
176 static void restrictbutton_modifier_cb(bContext *C, void *UNUSED(poin), void *poin2)
177 {
178         Object *ob = (Object *)poin2;
179         
180         DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
181
182         WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
183 }
184
185 static void restrictbutton_bone_cb(bContext *C, void *UNUSED(poin), void *poin2)
186 {
187         Bone *bone = (Bone *)poin2;
188         if (bone && (bone->flag & BONE_HIDDEN_P))
189                 bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
190         WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
191 }
192
193 static void restrictbutton_ebone_cb(bContext *C, void *UNUSED(poin), void *poin2)
194 {
195         EditBone *ebone = (EditBone *)poin2;
196         if (ebone && (ebone->flag & BONE_HIDDEN_A))
197                 ebone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
198
199         WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
200 }
201
202 static int group_restrict_flag(Group *gr, int flag)
203 {
204         GroupObject *gob;
205
206 #ifdef USE_GROUP_SELECT
207         for (gob = gr->gobject.first; gob; gob = gob->next) {
208                 if ((gob->ob->restrictflag & flag) == 0)
209                         return 0;
210         }
211         return 1;
212 #else
213         /* weak but fast */
214         if ((gob = gr->gobject.first))
215                 if ((gob->ob->restrictflag & flag) == 0)
216                         return 0;
217         return 1;
218 #endif
219 }
220
221 static int group_select_flag(Group *gr)
222 {
223         GroupObject *gob;
224
225 #ifdef USE_GROUP_SELECT
226         for (gob = gr->gobject.first; gob; gob = gob->next)
227                 if ((gob->ob->flag & SELECT))
228                         return 1;
229
230         return 0;
231 #else
232         /* weak but fast */
233         if ((gob = gr->gobject.first))
234                 if (gob->ob->flag & SELECT)
235                         return 1;
236         return 0;
237 #endif
238 }
239
240 void restrictbutton_gr_restrict_flag(void *poin, void *poin2, int flag)
241 {       
242         Scene *scene = (Scene *)poin;
243         GroupObject *gob;
244         Group *gr = (Group *)poin2;
245
246         if (group_restrict_flag(gr, flag)) {
247                 for (gob = gr->gobject.first; gob; gob = gob->next) {
248                         gob->ob->restrictflag &= ~flag;
249                         
250                         if (flag == OB_RESTRICT_VIEW)
251                                 if (gob->ob->flag & SELECT)
252                                         ED_base_object_select(BKE_scene_base_find(scene, gob->ob), BA_DESELECT);
253                 }
254         }
255         else {
256                 for (gob = gr->gobject.first; gob; gob = gob->next) {
257                         /* not in editmode */
258                         if (scene->obedit != gob->ob) {
259                                 gob->ob->restrictflag |= flag;
260
261                                 if (ELEM(flag, OB_RESTRICT_SELECT, OB_RESTRICT_VIEW)) {
262                                         if ((gob->ob->flag & SELECT)) {
263                                                 ED_base_object_select(BKE_scene_base_find(scene, gob->ob), BA_DESELECT);
264                                         }
265                                 }
266                         }
267                 }
268         }
269
270
271 static void restrictbutton_gr_restrict_view(bContext *C, void *poin, void *poin2)
272 {
273         restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_VIEW);
274         WM_event_add_notifier(C, NC_GROUP, NULL);
275 }
276 static void restrictbutton_gr_restrict_select(bContext *C, void *poin, void *poin2)
277 {
278         restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_SELECT);
279         WM_event_add_notifier(C, NC_GROUP, NULL);
280 }
281 static void restrictbutton_gr_restrict_render(bContext *C, void *poin, void *poin2)
282 {
283         restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_RENDER);
284         WM_event_add_notifier(C, NC_GROUP, NULL);
285 }
286
287
288 static void namebutton_cb(bContext *C, void *tsep, char *oldname)
289 {
290         SpaceOops *soops = CTX_wm_space_outliner(C);
291         Scene *scene = CTX_data_scene(C);
292         Object *obedit = CTX_data_edit_object(C);
293         TreeStore *ts = soops->treestore;
294         TreeStoreElem *tselem = tsep;
295         
296         if (ts && tselem) {
297                 TreeElement *te = outliner_find_tse(soops, tselem);
298                 
299                 if (tselem->type == 0) {
300                         test_idbutton(tselem->id->name + 2);  // library.c, unique name and alpha sort
301                         
302                         switch (GS(tselem->id->name)) {
303                                 case ID_MA:
304                                         WM_event_add_notifier(C, NC_MATERIAL, NULL); break;
305                                 case ID_TE:
306                                         WM_event_add_notifier(C, NC_TEXTURE, NULL); break;
307                                 case ID_IM:
308                                         WM_event_add_notifier(C, NC_IMAGE, NULL); break;
309                                 case ID_SCE:
310                                         WM_event_add_notifier(C, NC_SCENE, NULL); break;
311                                 default:
312                                         WM_event_add_notifier(C, NC_ID | NA_RENAME, NULL); break;
313                         }
314                         /* Check the library target exists */
315                         if (te->idcode == ID_LI) {
316                                 Library *lib = (Library *)tselem->id;
317                                 char expanded[FILE_MAX];
318
319                                 BKE_library_filepath_set(lib, lib->name);
320
321                                 BLI_strncpy(expanded, lib->name, sizeof(expanded));
322                                 BLI_path_abs(expanded, G.main->name);
323                                 if (!BLI_exists(expanded)) {
324                                         BKE_reportf(CTX_wm_reports(C), RPT_ERROR,
325                                                     "Library path '%s' does not exist, correct this before saving", expanded);
326                                 }
327                         }
328                 }
329                 else {
330                         switch (tselem->type) {
331                                 case TSE_DEFGROUP:
332                                         defgroup_unique_name(te->directdata, (Object *)tselem->id); //  id = object
333                                         break;
334                                 case TSE_NLA_ACTION:
335                                         test_idbutton(tselem->id->name + 2);
336                                         break;
337                                 case TSE_EBONE:
338                                 {
339                                         bArmature *arm = (bArmature *)tselem->id;
340                                         if (arm->edbo) {
341                                                 EditBone *ebone = te->directdata;
342                                                 char newname[sizeof(ebone->name)];
343
344                                                 /* restore bone name */
345                                                 BLI_strncpy(newname, ebone->name, sizeof(ebone->name));
346                                                 BLI_strncpy(ebone->name, oldname, sizeof(ebone->name));
347                                                 ED_armature_bone_rename(obedit->data, oldname, newname);
348                                                 WM_event_add_notifier(C, NC_OBJECT | ND_POSE, OBACT);
349                                         }
350                                 }
351                                 break;
352
353                                 case TSE_BONE:
354                                 {
355                                         Bone *bone = te->directdata;
356                                         Object *ob;
357                                         char newname[sizeof(bone->name)];
358                                         
359                                         // always make current object active
360                                         tree_element_active(C, scene, soops, te, 1); // was set_active_object()
361                                         ob = OBACT;
362                                         
363                                         /* restore bone name */
364                                         BLI_strncpy(newname, bone->name, sizeof(bone->name));
365                                         BLI_strncpy(bone->name, oldname, sizeof(bone->name));
366                                         ED_armature_bone_rename(ob->data, oldname, newname);
367                                         WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
368                                 }
369                                 break;
370                                 case TSE_POSE_CHANNEL:
371                                 {
372                                         bPoseChannel *pchan = te->directdata;
373                                         Object *ob;
374                                         char newname[sizeof(pchan->name)];
375                                         
376                                         // always make current object active
377                                         tree_element_active(C, scene, soops, te, 1); // was set_active_object()
378                                         ob = OBACT;
379                                         
380                                         /* restore bone name */
381                                         BLI_strncpy(newname, pchan->name, sizeof(pchan->name));
382                                         BLI_strncpy(pchan->name, oldname, sizeof(pchan->name));
383                                         ED_armature_bone_rename(ob->data, oldname, newname);
384                                         WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
385                                 }
386                                 break;
387                                 case TSE_POSEGRP:
388                                 {
389                                         Object *ob = (Object *)tselem->id; // id = object
390                                         bActionGroup *grp = te->directdata;
391                                         
392                                         BLI_uniquename(&ob->pose->agroups, grp, "Group", '.', offsetof(bActionGroup, name), sizeof(grp->name));
393                                         WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
394                                 }
395                                 break;
396                                 case TSE_R_LAYER:
397                                         break;
398                         }
399                 }
400                 tselem->flag &= ~TSE_TEXTBUT;
401         }
402 }
403
404 static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops, ListBase *lb)
405 {       
406         uiBut *bt;
407         TreeElement *te;
408         TreeStoreElem *tselem;
409         Object *ob = NULL;
410         Group  *gr = NULL;
411
412         for (te = lb->first; te; te = te->next) {
413                 tselem = TREESTORE(te);
414                 if (te->ys + 2 * UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {
415                         /* objects have toggle-able restriction flags */
416                         if (tselem->type == 0 && te->idcode == ID_OB) {
417                                 PointerRNA ptr;
418                                 
419                                 ob = (Object *)tselem->id;
420                                 RNA_pointer_create((ID *)ob, &RNA_Object, ob, &ptr);
421                                 
422                                 uiBlockSetEmboss(block, UI_EMBOSSN);
423                                 bt = uiDefIconButR(block, ICONTOG, 0, ICON_RESTRICT_VIEW_OFF,
424                                                    (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1,
425                                                    &ptr, "hide", -1, 0, 0, -1, -1, NULL);
426                                 uiButSetFunc(bt, restrictbutton_view_cb, scene, ob);
427                                 
428                                 bt = uiDefIconButR(block, ICONTOG, 0, ICON_RESTRICT_SELECT_OFF,
429                                                    (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1,
430                                                    &ptr, "hide_select", -1, 0, 0, -1, -1, NULL);
431                                 uiButSetFunc(bt, restrictbutton_sel_cb, scene, ob);
432                                 
433                                 bt = uiDefIconButR(block, ICONTOG, 0, ICON_RESTRICT_RENDER_OFF,
434                                                    (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1,
435                                                    &ptr, "hide_render", -1, 0, 0, -1, -1, NULL);
436                                 uiButSetFunc(bt, restrictbutton_rend_cb, scene, ob);
437                                 
438                                 uiBlockSetEmboss(block, UI_EMBOSS);
439                                 
440                         }
441                         if (tselem->type == 0 && te->idcode == ID_GR) {
442                                 int restrict_bool;
443                                 gr = (Group *)tselem->id;
444                                 
445                                 uiBlockSetEmboss(block, UI_EMBOSSN);
446
447                                 restrict_bool = group_restrict_flag(gr, OB_RESTRICT_VIEW);
448                                 bt = uiDefIconBut(block, ICONTOG, 0, restrict_bool ? ICON_RESTRICT_VIEW_ON : ICON_RESTRICT_VIEW_OFF, (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, NULL, 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View");
449                                 uiButSetFunc(bt, restrictbutton_gr_restrict_view, scene, gr);
450
451                                 restrict_bool = group_restrict_flag(gr, OB_RESTRICT_SELECT);
452                                 bt = uiDefIconBut(block, ICONTOG, 0, restrict_bool ? ICON_RESTRICT_SELECT_ON : ICON_RESTRICT_SELECT_OFF, (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, NULL, 0, 0, 0, 0, "Restrict/Allow selection in the 3D View");
453                                 uiButSetFunc(bt, restrictbutton_gr_restrict_select, scene, gr);
454
455                                 restrict_bool = group_restrict_flag(gr, OB_RESTRICT_RENDER);
456                                 bt = uiDefIconBut(block, ICONTOG, 0, restrict_bool ? ICON_RESTRICT_RENDER_ON : ICON_RESTRICT_RENDER_OFF, (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, NULL, 0, 0, 0, 0, "Restrict/Allow renderability");
457                                 uiButSetFunc(bt, restrictbutton_gr_restrict_render, scene, gr);
458
459                                 uiBlockSetEmboss(block, UI_EMBOSS);
460                         }
461                         /* scene render layers and passes have toggle-able flags too! */
462                         else if (tselem->type == TSE_R_LAYER) {
463                                 uiBlockSetEmboss(block, UI_EMBOSSN);
464                                 
465                                 bt = uiDefIconButBitI(block, ICONTOGN, SCE_LAY_DISABLE, 0, ICON_CHECKBOX_HLT - 1,
466                                                       (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, te->directdata, 0, 0, 0, 0, "Render this RenderLayer");
467                                 uiButSetFunc(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
468                                 
469                                 uiBlockSetEmboss(block, UI_EMBOSS);
470                         }
471                         else if (tselem->type == TSE_R_PASS) {
472                                 int *layflag = te->directdata;
473                                 int passflag = 1 << tselem->nr;
474                                 
475                                 uiBlockSetEmboss(block, UI_EMBOSSN);
476                                 
477                                 
478                                 bt = uiDefIconButBitI(block, ICONTOG, passflag, 0, ICON_CHECKBOX_HLT - 1,
479                                                       (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, layflag, 0, 0, 0, 0, "Render this Pass");
480                                 uiButSetFunc(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
481                                 
482                                 layflag++;  /* is lay_xor */
483                                 if (ELEM8(passflag, SCE_PASS_SPEC, SCE_PASS_SHADOW, SCE_PASS_AO, SCE_PASS_REFLECT, SCE_PASS_REFRACT, SCE_PASS_INDIRECT, SCE_PASS_EMIT, SCE_PASS_ENVIRONMENT))
484                                         bt = uiDefIconButBitI(block, TOG, passflag, 0, (*layflag & passflag) ? ICON_DOT : ICON_BLANK1,
485                                                               (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, layflag, 0, 0, 0, 0, "Exclude this Pass from Combined");
486                                 uiButSetFunc(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
487                                 
488                                 uiBlockSetEmboss(block, UI_EMBOSS);
489                         }
490                         else if (tselem->type == TSE_MODIFIER) {
491                                 ModifierData *md = (ModifierData *)te->directdata;
492                                 ob = (Object *)tselem->id;
493                                 
494                                 uiBlockSetEmboss(block, UI_EMBOSSN);
495                                 bt = uiDefIconButBitI(block, ICONTOGN, eModifierMode_Realtime, 0, ICON_RESTRICT_VIEW_OFF,
496                                                       (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, &(md->mode), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View");
497                                 uiButSetFunc(bt, restrictbutton_modifier_cb, scene, ob);
498                                 
499                                 bt = uiDefIconButBitI(block, ICONTOGN, eModifierMode_Render, 0, ICON_RESTRICT_RENDER_OFF,
500                                                       (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, &(md->mode), 0, 0, 0, 0, "Restrict/Allow renderability");
501                                 uiButSetFunc(bt, restrictbutton_modifier_cb, scene, ob);
502                         }
503                         else if (tselem->type == TSE_POSE_CHANNEL) {
504                                 bPoseChannel *pchan = (bPoseChannel *)te->directdata;
505                                 Bone *bone = pchan->bone;
506                                 
507                                 uiBlockSetEmboss(block, UI_EMBOSSN);
508                                 bt = uiDefIconButBitI(block, ICONTOG, BONE_HIDDEN_P, 0, ICON_RESTRICT_VIEW_OFF,
509                                                       (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, &(bone->flag), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View");
510                                 uiButSetFunc(bt, restrictbutton_bone_cb, NULL, bone);
511                                 
512                                 bt = uiDefIconButBitI(block, ICONTOG, BONE_UNSELECTABLE, 0, ICON_RESTRICT_SELECT_OFF,
513                                                       (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, &(bone->flag), 0, 0, 0, 0, "Restrict/Allow selection in the 3D View");
514                                 uiButSetFunc(bt, restrictbutton_bone_cb, NULL, NULL);
515                         }
516                         else if (tselem->type == TSE_EBONE) {
517                                 EditBone *ebone = (EditBone *)te->directdata;
518                                 
519                                 uiBlockSetEmboss(block, UI_EMBOSSN);
520                                 bt = uiDefIconButBitI(block, ICONTOG, BONE_HIDDEN_A, 0, ICON_RESTRICT_VIEW_OFF,
521                                                       (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, &(ebone->flag), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View");
522                                 uiButSetFunc(bt, restrictbutton_ebone_cb, NULL, ebone);
523                                 
524                                 bt = uiDefIconButBitI(block, ICONTOG, BONE_UNSELECTABLE, 0, ICON_RESTRICT_SELECT_OFF,
525                                                       (int)ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX, (int)te->ys, UI_UNIT_X - 1, UI_UNIT_Y - 1, &(ebone->flag), 0, 0, 0, 0, "Restrict/Allow selection in the 3D View");
526                                 uiButSetFunc(bt, restrictbutton_ebone_cb, NULL, NULL);
527                         }
528                 }
529                 
530                 if (TSELEM_OPEN(tselem, soops)) outliner_draw_restrictbuts(block, scene, ar, soops, &te->subtree);
531         }
532 }
533
534 static void outliner_draw_rnacols(ARegion *ar, int sizex)
535 {
536         View2D *v2d = &ar->v2d;
537
538         float miny = v2d->cur.ymin - V2D_SCROLL_HEIGHT;
539         if (miny < v2d->tot.ymin) miny = v2d->tot.ymin;
540
541         UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
542
543         /* draw column separator lines */
544         fdrawline((float)sizex,
545                   v2d->cur.ymax,
546                   (float)sizex,
547                   miny);
548
549         fdrawline((float)sizex + OL_RNA_COL_SIZEX,
550                   v2d->cur.ymax,
551                   (float)sizex + OL_RNA_COL_SIZEX,
552                   miny);
553 }
554
555 static void outliner_draw_rnabuts(uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops, int sizex, ListBase *lb)
556 {       
557         TreeElement *te;
558         TreeStoreElem *tselem;
559         PointerRNA *ptr;
560         PropertyRNA *prop;
561         
562         uiBlockSetEmboss(block, UI_EMBOSST);
563
564         for (te = lb->first; te; te = te->next) {
565                 tselem = TREESTORE(te);
566                 if (te->ys + 2 * UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {
567                         if (tselem->type == TSE_RNA_PROPERTY) {
568                                 ptr = &te->rnaptr;
569                                 prop = te->directdata;
570                                 
571                                 if (!(RNA_property_type(prop) == PROP_POINTER && (TSELEM_OPEN(tselem, soops))) )
572                                         uiDefAutoButR(block, ptr, prop, -1, "", ICON_NONE, sizex, (int)te->ys, OL_RNA_COL_SIZEX, UI_UNIT_Y - 1);
573                         }
574                         else if (tselem->type == TSE_RNA_ARRAY_ELEM) {
575                                 ptr = &te->rnaptr;
576                                 prop = te->directdata;
577                                 
578                                 uiDefAutoButR(block, ptr, prop, te->index, "", ICON_NONE, sizex, (int)te->ys, OL_RNA_COL_SIZEX, UI_UNIT_Y - 1);
579                         }
580                 }
581                 
582                 if (TSELEM_OPEN(tselem, soops)) outliner_draw_rnabuts(block, scene, ar, soops, sizex, &te->subtree);
583         }
584 }
585
586 static void operator_call_cb(struct bContext *UNUSED(C), void *arg_kmi, void *arg2)
587 {
588         wmOperatorType *ot = arg2;
589         wmKeyMapItem *kmi = arg_kmi;
590         
591         if (ot)
592                 BLI_strncpy(kmi->idname, ot->idname, OP_MAX_TYPENAME);
593 }
594
595 static void operator_search_cb(const struct bContext *UNUSED(C), void *UNUSED(arg_kmi),
596                                const char *str, uiSearchItems *items)
597 {
598         GHashIterator *iter = WM_operatortype_iter();
599
600         for (; !BLI_ghashIterator_isDone(iter); BLI_ghashIterator_step(iter)) {
601                 wmOperatorType *ot = BLI_ghashIterator_getValue(iter);
602                 
603                 if (BLI_strcasestr(ot->idname, str)) {
604                         char name[OP_MAX_TYPENAME];
605                         
606                         /* display name for menu */
607                         WM_operator_py_idname(name, ot->idname);
608                         
609                         if (0 == uiSearchItemAdd(items, name, ot, 0))
610                                 break;
611                 }
612         }
613         BLI_ghashIterator_free(iter);
614 }
615
616 /* operator Search browse menu, open */
617 static uiBlock *operator_search_menu(bContext *C, ARegion *ar, void *arg_kmi)
618 {
619         static char search[OP_MAX_TYPENAME];
620         wmEvent event;
621         wmWindow *win = CTX_wm_window(C);
622         wmKeyMapItem *kmi = arg_kmi;
623         wmOperatorType *ot = WM_operatortype_find(kmi->idname, 0);
624         uiBlock *block;
625         uiBut *but;
626         
627         /* clear initial search string, then all items show */
628         search[0] = 0;
629         
630         block = uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
631         uiBlockSetFlag(block, UI_BLOCK_LOOP | UI_BLOCK_REDRAW | UI_BLOCK_SEARCH_MENU);
632         
633         /* fake button, it holds space for search items */
634         uiDefBut(block, LABEL, 0, "", 10, 15, uiSearchBoxWidth(), uiSearchBoxHeight(), NULL, 0, 0, 0, 0, NULL);
635         
636         but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 0, 150, UI_UNIT_Y, 0, 0, "");
637         uiButSetSearchFunc(but, operator_search_cb, arg_kmi, operator_call_cb, ot);
638         
639         uiBoundsBlock(block, 6);
640         uiBlockSetDirection(block, UI_DOWN);
641         uiEndBlock(C, block);
642         
643         event = *(win->eventstate);  /* XXX huh huh? make api call */
644         event.type = EVT_BUT_OPEN;
645         event.val = KM_PRESS;
646         event.customdata = but;
647         event.customdatafree = FALSE;
648         wm_event_add(win, &event);
649         
650         return block;
651 }
652
653 #define OL_KM_KEYBOARD      0
654 #define OL_KM_MOUSE         1
655 #define OL_KM_TWEAK         2
656 #define OL_KM_SPECIALS      3
657
658 static short keymap_menu_type(short type)
659 {
660         if (ISKEYBOARD(type)) return OL_KM_KEYBOARD;
661         if (ISTWEAK(type)) return OL_KM_TWEAK;
662         if (ISMOUSE(type)) return OL_KM_MOUSE;
663 //      return OL_KM_SPECIALS;
664         return 0;
665 }
666
667 static const char *keymap_type_menu(void)
668 {
669         static const char string[] =
670             "Event Type%t"
671             "|Keyboard%x" STRINGIFY(OL_KM_KEYBOARD)
672             "|Mouse%x" STRINGIFY(OL_KM_MOUSE)
673             "|Tweak%x" STRINGIFY(OL_KM_TWEAK)
674 //      "|Specials%x" STRINGIFY(OL_KM_SPECIALS)
675         ;
676
677         return string;
678 }
679
680 static const char *keymap_mouse_menu(void)
681 {
682         static const char string[] =
683             "Mouse Event%t"
684             "|Left Mouse%x" STRINGIFY(LEFTMOUSE)
685             "|Middle Mouse%x" STRINGIFY(MIDDLEMOUSE)
686             "|Right Mouse%x" STRINGIFY(RIGHTMOUSE)
687             "|Middle Mouse%x" STRINGIFY(MIDDLEMOUSE)
688             "|Right Mouse%x" STRINGIFY(RIGHTMOUSE)
689             "|Button4 Mouse%x" STRINGIFY(BUTTON4MOUSE)
690             "|Button5 Mouse%x" STRINGIFY(BUTTON5MOUSE)
691             "|Action Mouse%x" STRINGIFY(ACTIONMOUSE)
692             "|Select Mouse%x" STRINGIFY(SELECTMOUSE)
693             "|Mouse Move%x" STRINGIFY(MOUSEMOVE)
694             "|Wheel Up%x" STRINGIFY(WHEELUPMOUSE)
695             "|Wheel Down%x" STRINGIFY(WHEELDOWNMOUSE)
696             "|Wheel In%x" STRINGIFY(WHEELINMOUSE)
697             "|Wheel Out%x" STRINGIFY(WHEELOUTMOUSE)
698             "|Mouse/Trackpad Pan%x" STRINGIFY(MOUSEPAN)
699             "|Mouse/Trackpad Zoom%x" STRINGIFY(MOUSEZOOM)
700             "|Mouse/Trackpad Rotate%x" STRINGIFY(MOUSEROTATE)
701         ;
702
703         return string;
704 }
705
706 static const char *keymap_tweak_menu(void)
707 {
708         static const char string[] =
709             "Tweak Event%t"
710             "|Left Mouse%x" STRINGIFY(EVT_TWEAK_L)
711             "|Middle Mouse%x" STRINGIFY(EVT_TWEAK_M)
712             "|Right Mouse%x" STRINGIFY(EVT_TWEAK_R)
713             "|Action Mouse%x" STRINGIFY(EVT_TWEAK_A)
714             "|Select Mouse%x" STRINGIFY(EVT_TWEAK_S)
715         ;
716
717         return string;
718 }
719
720 static const char *keymap_tweak_dir_menu(void)
721 {
722         static const char string[] =
723             "Tweak Direction%t"
724             "|Any%x" STRINGIFY(KM_ANY)
725             "|North%x" STRINGIFY(EVT_GESTURE_N)
726             "|North-East%x" STRINGIFY(EVT_GESTURE_NE)
727             "|East%x" STRINGIFY(EVT_GESTURE_E)
728             "|Sout-East%x" STRINGIFY(EVT_GESTURE_SE)
729             "|South%x" STRINGIFY(EVT_GESTURE_S)
730             "|South-West%x" STRINGIFY(EVT_GESTURE_SW)
731             "|West%x" STRINGIFY(EVT_GESTURE_W)
732             "|North-West%x" STRINGIFY(EVT_GESTURE_NW)
733         ;
734
735         return string;
736 }
737
738
739 static void keymap_type_cb(bContext *C, void *kmi_v, void *UNUSED(arg_v))
740 {
741         wmKeyMapItem *kmi = kmi_v;
742         short maptype = keymap_menu_type(kmi->type);
743         
744         if (maptype != kmi->maptype) {
745                 switch (kmi->maptype) {
746                         case OL_KM_KEYBOARD:
747                                 kmi->type = AKEY;
748                                 kmi->val = KM_PRESS;
749                                 break;
750                         case OL_KM_MOUSE:
751                                 kmi->type = LEFTMOUSE;
752                                 kmi->val = KM_PRESS;
753                                 break;
754                         case OL_KM_TWEAK:
755                                 kmi->type = EVT_TWEAK_L;
756                                 kmi->val = KM_ANY;
757                                 break;
758                         case OL_KM_SPECIALS:
759                                 kmi->type = AKEY;
760                                 kmi->val = KM_PRESS;
761                 }
762                 ED_region_tag_redraw(CTX_wm_region(C));
763         }
764 }
765
766 static void outliner_draw_keymapbuts(uiBlock *block, ARegion *ar, SpaceOops *soops, ListBase *lb)
767 {
768         TreeElement *te;
769         TreeStoreElem *tselem;
770         
771         uiBlockSetEmboss(block, UI_EMBOSST);
772         
773         for (te = lb->first; te; te = te->next) {
774                 tselem = TREESTORE(te);
775                 if (te->ys + 2 * UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {
776                         uiBut *but;
777                         const char *str;
778                         int xstart = 240;
779                         int butw1 = UI_UNIT_X; /* operator */
780                         int butw2 = 90; /* event type, menus */
781                         int butw3 = 43; /* modifiers */
782
783                         if (tselem->type == TSE_KEYMAP_ITEM) {
784                                 wmKeyMapItem *kmi = te->directdata;
785                                 
786                                 /* modal map? */
787                                 if (kmi->propvalue) {
788                                         /* pass */
789                                 }
790                                 else {
791                                         uiDefBlockBut(block, operator_search_menu, kmi, "", xstart, (int)te->ys + 1, butw1, UI_UNIT_Y - 1, "Assign new Operator");
792                                 }
793                                 xstart += butw1 + 10;
794                                 
795                                 /* map type button */
796                                 kmi->maptype = keymap_menu_type(kmi->type);
797                                 
798                                 str = keymap_type_menu();
799                                 but = uiDefButS(block, MENU, 0, str,    xstart, (int)te->ys + 1, butw2, UI_UNIT_Y - 1, &kmi->maptype, 0, 0, 0, 0, "Event type");
800                                 uiButSetFunc(but, keymap_type_cb, kmi, NULL);
801                                 xstart += butw2 + 5;
802                                 
803                                 /* edit actual event */
804                                 switch (kmi->maptype) {
805                                         case OL_KM_KEYBOARD:
806                                                 uiDefKeyevtButS(block, 0, "", xstart, (int)te->ys + 1, butw2, UI_UNIT_Y - 1, &kmi->type, "Key code");
807                                                 xstart += butw2 + 5;
808                                                 break;
809                                         case OL_KM_MOUSE:
810                                                 str = keymap_mouse_menu();
811                                                 uiDefButS(block, MENU, 0, str, xstart, (int)te->ys + 1, butw2, UI_UNIT_Y - 1, &kmi->type, 0, 0, 0, 0,  "Mouse button");
812                                                 xstart += butw2 + 5;
813                                                 break;
814                                         case OL_KM_TWEAK:
815                                                 str = keymap_tweak_menu();
816                                                 uiDefButS(block, MENU, 0, str, xstart, (int)te->ys + 1, butw2, UI_UNIT_Y - 1, &kmi->type, 0, 0, 0, 0,  "Tweak gesture");
817                                                 xstart += butw2 + 5;
818                                                 str = keymap_tweak_dir_menu();
819                                                 uiDefButS(block, MENU, 0, str, xstart, (int)te->ys + 1, butw2, UI_UNIT_Y - 1, &kmi->val, 0, 0, 0, 0,  "Tweak gesture direction");
820                                                 xstart += butw2 + 5;
821                                                 break;
822                                 }
823                                 
824                                 /* modifiers */
825                                 uiDefButS(block, OPTION, 0, "Shift",    xstart, (int)te->ys + 1, butw3 + 5, UI_UNIT_Y - 1, &kmi->shift, 0, 0, 0, 0, "Modifier"); xstart += butw3 + 5;
826                                 uiDefButS(block, OPTION, 0, "Ctrl", xstart, (int)te->ys + 1, butw3, UI_UNIT_Y - 1, &kmi->ctrl, 0, 0, 0, 0, "Modifier"); xstart += butw3;
827                                 uiDefButS(block, OPTION, 0, "Alt",  xstart, (int)te->ys + 1, butw3, UI_UNIT_Y - 1, &kmi->alt, 0, 0, 0, 0, "Modifier"); xstart += butw3;
828                                 uiDefButS(block, OPTION, 0, "OS",   xstart, (int)te->ys + 1, butw3, UI_UNIT_Y - 1, &kmi->oskey, 0, 0, 0, 0, "Modifier"); xstart += butw3;
829                                 xstart += 5;
830                                 uiDefKeyevtButS(block, 0, "", xstart, (int)te->ys + 1, butw3, UI_UNIT_Y - 1, &kmi->keymodifier, "Key Modifier code");
831                                 xstart += butw3 + 5;
832                                 
833                                 /* rna property */
834                                 if (kmi->ptr && kmi->ptr->data) {
835                                         uiDefBut(block, LABEL, 0, "(RNA property)", xstart, (int)te->ys + 1, butw2, UI_UNIT_Y - 1, &kmi->oskey, 0, 0, 0, 0, ""); xstart += butw2;
836                                 }
837
838                                 (void)xstart;
839                         }
840                 }
841                 
842                 if (TSELEM_OPEN(tselem, soops)) outliner_draw_keymapbuts(block, ar, soops, &te->subtree);
843         }
844 }
845
846
847 static void outliner_buttons(const bContext *C, uiBlock *block, ARegion *ar, SpaceOops *soops, ListBase *lb)
848 {
849         uiBut *bt;
850         TreeElement *te;
851         TreeStoreElem *tselem;
852         int spx, dx, len;
853         
854         for (te = lb->first; te; te = te->next) {
855                 tselem = TREESTORE(te);
856                 if (te->ys + 2 * UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {
857                         
858                         if (tselem->flag & TSE_TEXTBUT) {
859                                 
860                                 /* If we add support to rename Sequence.
861                                  * need change this.
862                                  */
863                                 if (tselem->type == TSE_POSE_BASE) continue;  // prevent crash when trying to rename 'pose' entry of armature
864                                 
865                                 if (tselem->type == TSE_EBONE) len = sizeof(((EditBone *) 0)->name);
866                                 else if (tselem->type == TSE_MODIFIER) len = sizeof(((ModifierData *) 0)->name);
867                                 else if (tselem->id && GS(tselem->id->name) == ID_LI) len = sizeof(((Library *) 0)->name);
868                                 else len = MAX_ID_NAME - 2;
869                                 
870
871                                 dx = (int)UI_GetStringWidth(te->name);
872                                 if (dx < 100) dx = 100;
873                                 spx = te->xs + 2 * UI_UNIT_X - 4;
874                                 if (spx + dx + 10 > ar->v2d.cur.xmax) dx = ar->v2d.cur.xmax - spx - 10;
875
876                                 bt = uiDefBut(block, TEX, OL_NAMEBUTTON, "", spx, (int)te->ys, dx + 10, UI_UNIT_Y - 1, (void *)te->name, 1.0, (float)len, 0, 0, "");
877                                 uiButSetRenameFunc(bt, namebutton_cb, tselem);
878                                 
879                                 /* returns false if button got removed */
880                                 if (0 == uiButActiveOnly(C, block, bt) )
881                                         tselem->flag &= ~TSE_TEXTBUT;
882                         }
883                 }
884                 
885                 if (TSELEM_OPEN(tselem, soops)) outliner_buttons(C, block, ar, soops, &te->subtree);
886         }
887 }
888
889 /* ****************************************************** */
890 /* Normal Drawing... */
891
892 /* make function calls a bit compacter */
893 struct DrawIconArg {
894         uiBlock *block;
895         ID *id;
896         int xmax, x, y;
897         float alpha;
898 };
899
900 static void tselem_draw_icon_uibut(struct DrawIconArg *arg, int icon)
901 {
902         /* restrict column clip... it has been coded by simply overdrawing, doesnt work for buttons */
903         if (arg->x >= arg->xmax) {
904                 glEnable(GL_BLEND);
905                 UI_icon_draw_aspect(arg->x, arg->y, icon, 1.0f, arg->alpha);
906                 glDisable(GL_BLEND);
907         }
908         else {
909                 /* XXX investigate: button placement of icons is way different than UI_icon_draw? */
910                 float ufac = UI_UNIT_X / 20.0f;
911                 uiBut *but = uiDefIconBut(arg->block, LABEL, 0, icon, arg->x - 3.0f * ufac, arg->y, UI_UNIT_X - 4.0f * ufac, UI_UNIT_Y - 4.0f * ufac, NULL, 0.0, 0.0, 1.0, arg->alpha, (arg->id && arg->id->lib) ? arg->id->lib->name : "");
912                 
913                 if (arg->id)
914                         uiButSetDragID(but, arg->id);
915         }
916
917 }
918
919 static void tselem_draw_icon(uiBlock *block, int xmax, float x, float y, TreeStoreElem *tselem, TreeElement *te, float alpha)
920 {
921         struct DrawIconArg arg;
922         
923         /* make function calls a bit compacter */
924         arg.block = block;
925         arg.id = tselem->id;
926         arg.xmax = xmax;
927         arg.x = x;
928         arg.y = y;
929         arg.alpha = alpha;
930         
931         if (tselem->type) {
932                 switch (tselem->type) {
933                         case TSE_ANIM_DATA:
934                                 UI_icon_draw(x, y, ICON_ANIM_DATA); break; // xxx
935                         case TSE_NLA:
936                                 UI_icon_draw(x, y, ICON_NLA); break;
937                         case TSE_NLA_TRACK:
938                                 UI_icon_draw(x, y, ICON_NLA); break; // XXX
939                         case TSE_NLA_ACTION:
940                                 UI_icon_draw(x, y, ICON_ACTION); break;
941                         case TSE_DRIVER_BASE:
942                                 UI_icon_draw(x, y, ICON_DRIVER); break;
943                         case TSE_DEFGROUP_BASE:
944                                 UI_icon_draw(x, y, ICON_GROUP_VERTEX); break;
945                         case TSE_BONE:
946                         case TSE_EBONE:
947                                 UI_icon_draw(x, y, ICON_BONE_DATA); break;
948                         case TSE_CONSTRAINT_BASE:
949                                 UI_icon_draw(x, y, ICON_CONSTRAINT); break;
950                         case TSE_MODIFIER_BASE:
951                                 UI_icon_draw(x, y, ICON_MODIFIER); break;
952                         case TSE_LINKED_OB:
953                                 UI_icon_draw(x, y, ICON_OBJECT_DATA); break;
954                         case TSE_LINKED_PSYS:
955                                 UI_icon_draw(x, y, ICON_PARTICLES); break;
956                         case TSE_MODIFIER:
957                         {
958                                 Object *ob = (Object *)tselem->id;
959                                 ModifierData *md = BLI_findlink(&ob->modifiers, tselem->nr);
960                                 switch ((ModifierType)md->type) {
961                                         case eModifierType_Subsurf: 
962                                                 UI_icon_draw(x, y, ICON_MOD_SUBSURF); break;
963                                         case eModifierType_Armature: 
964                                                 UI_icon_draw(x, y, ICON_MOD_ARMATURE); break;
965                                         case eModifierType_Lattice: 
966                                                 UI_icon_draw(x, y, ICON_MOD_LATTICE); break;
967                                         case eModifierType_Curve: 
968                                                 UI_icon_draw(x, y, ICON_MOD_CURVE); break;
969                                         case eModifierType_Build: 
970                                                 UI_icon_draw(x, y, ICON_MOD_BUILD); break;
971                                         case eModifierType_Mirror: 
972                                                 UI_icon_draw(x, y, ICON_MOD_MIRROR); break;
973                                         case eModifierType_Decimate: 
974                                                 UI_icon_draw(x, y, ICON_MOD_DECIM); break;
975                                         case eModifierType_Wave: 
976                                                 UI_icon_draw(x, y, ICON_MOD_WAVE); break;
977                                         case eModifierType_Hook: 
978                                                 UI_icon_draw(x, y, ICON_HOOK); break;
979                                         case eModifierType_Softbody: 
980                                                 UI_icon_draw(x, y, ICON_MOD_SOFT); break;
981                                         case eModifierType_Boolean: 
982                                                 UI_icon_draw(x, y, ICON_MOD_BOOLEAN); break;
983                                         case eModifierType_ParticleSystem: 
984                                                 UI_icon_draw(x, y, ICON_MOD_PARTICLES); break;
985                                         case eModifierType_ParticleInstance:
986                                                 UI_icon_draw(x, y, ICON_MOD_PARTICLES); break;
987                                         case eModifierType_EdgeSplit:
988                                                 UI_icon_draw(x, y, ICON_MOD_EDGESPLIT); break;
989                                         case eModifierType_Array:
990                                                 UI_icon_draw(x, y, ICON_MOD_ARRAY); break;
991                                         case eModifierType_UVProject:
992                                                 UI_icon_draw(x, y, ICON_MOD_UVPROJECT); break;
993                                         case eModifierType_Displace:
994                                                 UI_icon_draw(x, y, ICON_MOD_DISPLACE); break;
995                                         case eModifierType_Shrinkwrap:
996                                                 UI_icon_draw(x, y, ICON_MOD_SHRINKWRAP); break;
997                                         case eModifierType_Cast:
998                                                 UI_icon_draw(x, y, ICON_MOD_CAST); break;
999                                         case eModifierType_MeshDeform:
1000                                                 UI_icon_draw(x, y, ICON_MOD_MESHDEFORM); break;
1001                                         case eModifierType_Bevel:
1002                                                 UI_icon_draw(x, y, ICON_MOD_BEVEL); break;
1003                                         case eModifierType_Smooth:
1004                                         case eModifierType_LaplacianSmooth:
1005                                                 UI_icon_draw(x, y, ICON_MOD_SMOOTH); break;
1006                                         case eModifierType_SimpleDeform:
1007                                                 UI_icon_draw(x, y, ICON_MOD_SIMPLEDEFORM); break;
1008                                         case eModifierType_Mask:
1009                                                 UI_icon_draw(x, y, ICON_MOD_MASK); break;
1010                                         case eModifierType_Cloth:
1011                                                 UI_icon_draw(x, y, ICON_MOD_CLOTH); break;
1012                                         case eModifierType_Explode:
1013                                                 UI_icon_draw(x, y, ICON_MOD_EXPLODE); break;
1014                                         case eModifierType_Collision:
1015                                         case eModifierType_Surface:
1016                                                 UI_icon_draw(x, y, ICON_MOD_PHYSICS); break;
1017                                         case eModifierType_Fluidsim:
1018                                                 UI_icon_draw(x, y, ICON_MOD_FLUIDSIM); break;
1019                                         case eModifierType_Multires:
1020                                                 UI_icon_draw(x, y, ICON_MOD_MULTIRES); break;
1021                                         case eModifierType_Smoke:
1022                                                 UI_icon_draw(x, y, ICON_MOD_SMOKE); break;
1023                                         case eModifierType_Solidify:
1024                                                 UI_icon_draw(x, y, ICON_MOD_SOLIDIFY); break;
1025                                         case eModifierType_Screw:
1026                                                 UI_icon_draw(x, y, ICON_MOD_SCREW); break;
1027                                         case eModifierType_Remesh:
1028                                                 UI_icon_draw(x, y, ICON_MOD_REMESH); break;
1029                                         case eModifierType_WeightVGEdit:
1030                                         case eModifierType_WeightVGMix:
1031                                         case eModifierType_WeightVGProximity:
1032                                                 UI_icon_draw(x, y, ICON_MOD_VERTEX_WEIGHT); break;
1033                                         case eModifierType_DynamicPaint:
1034                                                 UI_icon_draw(x, y, ICON_MOD_DYNAMICPAINT); break;
1035                                         case eModifierType_Ocean:
1036                                                 UI_icon_draw(x, y, ICON_MOD_OCEAN); break;
1037                                         case eModifierType_Warp:
1038                                                 UI_icon_draw(x, y, ICON_MOD_WARP); break;
1039                                         case eModifierType_Skin:
1040                                                 UI_icon_draw(x, y, ICON_MOD_SKIN); break;
1041                                         case eModifierType_Triangulate:
1042                                                 UI_icon_draw(x, y, ICON_MOD_TRIANGULATE); break;
1043
1044                                         /* Default */
1045                                         case eModifierType_None:
1046                                         case eModifierType_ShapeKey:
1047                                         case NUM_MODIFIER_TYPES:
1048                                                 UI_icon_draw(x, y, ICON_DOT); break;
1049                                 }
1050                                 break;
1051                         }
1052                         case TSE_SCRIPT_BASE:
1053                                 UI_icon_draw(x, y, ICON_TEXT); break;
1054                         case TSE_POSE_BASE:
1055                                 UI_icon_draw(x, y, ICON_ARMATURE_DATA); break;
1056                         case TSE_POSE_CHANNEL:
1057                                 UI_icon_draw(x, y, ICON_BONE_DATA); break;
1058                         case TSE_PROXY:
1059                                 UI_icon_draw(x, y, ICON_GHOST); break;
1060                         case TSE_R_LAYER_BASE:
1061                                 UI_icon_draw(x, y, ICON_RENDERLAYERS); break;
1062                         case TSE_R_LAYER:
1063                                 UI_icon_draw(x, y, ICON_RENDERLAYERS); break;
1064                         case TSE_LINKED_LAMP:
1065                                 UI_icon_draw(x, y, ICON_LAMP_DATA); break;
1066                         case TSE_LINKED_MAT:
1067                                 UI_icon_draw(x, y, ICON_MATERIAL_DATA); break;
1068                         case TSE_POSEGRP_BASE:
1069                                 UI_icon_draw(x, y, ICON_GROUP_BONE); break;
1070                         case TSE_SEQUENCE:
1071                                 if (te->idcode == SEQ_TYPE_MOVIE)
1072                                         UI_icon_draw(x, y, ICON_SEQUENCE);
1073                                 else if (te->idcode == SEQ_TYPE_META)
1074                                         UI_icon_draw(x, y, ICON_DOT);
1075                                 else if (te->idcode == SEQ_TYPE_SCENE)
1076                                         UI_icon_draw(x, y, ICON_SCENE);
1077                                 else if (te->idcode == SEQ_TYPE_SOUND_RAM)
1078                                         UI_icon_draw(x, y, ICON_SOUND);
1079                                 else if (te->idcode == SEQ_TYPE_IMAGE)
1080                                         UI_icon_draw(x, y, ICON_IMAGE_COL);
1081                                 else
1082                                         UI_icon_draw(x, y, ICON_PARTICLES);
1083                                 break;
1084                         case TSE_SEQ_STRIP:
1085                                 UI_icon_draw(x, y, ICON_LIBRARY_DATA_DIRECT);
1086                                 break;
1087                         case TSE_SEQUENCE_DUP:
1088                                 UI_icon_draw(x, y, ICON_OBJECT_DATA);
1089                                 break;
1090                         case TSE_RNA_STRUCT:
1091                                 if (RNA_struct_is_ID(te->rnaptr.type)) {
1092                                         arg.id = (ID *)te->rnaptr.data;
1093                                         tselem_draw_icon_uibut(&arg, RNA_struct_ui_icon(te->rnaptr.type));
1094                                 }
1095                                 else
1096                                         UI_icon_draw(x, y, RNA_struct_ui_icon(te->rnaptr.type));
1097                                 break;
1098                         default:
1099                                 UI_icon_draw(x, y, ICON_DOT); break;
1100                 }
1101         }
1102         else if (GS(tselem->id->name) == ID_OB) {
1103                 Object *ob = (Object *)tselem->id;
1104                 switch (ob->type) {
1105                         case OB_LAMP:
1106                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_LAMP); break;
1107                         case OB_MESH: 
1108                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_MESH); break;
1109                         case OB_CAMERA: 
1110                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_CAMERA); break;
1111                         case OB_CURVE: 
1112                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_CURVE); break;
1113                         case OB_MBALL: 
1114                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_META); break;
1115                         case OB_LATTICE: 
1116                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_LATTICE); break;
1117                         case OB_ARMATURE: 
1118                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_ARMATURE); break;
1119                         case OB_FONT: 
1120                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_FONT); break;
1121                         case OB_SURF: 
1122                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_SURFACE); break;
1123                         case OB_SPEAKER:
1124                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_SPEAKER); break;
1125                         case OB_EMPTY: 
1126                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_EMPTY); break;
1127                 
1128                 }
1129         }
1130         else {
1131                 switch (GS(tselem->id->name)) {
1132                         case ID_SCE:
1133                                 tselem_draw_icon_uibut(&arg, ICON_SCENE_DATA); break;
1134                         case ID_ME:
1135                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_MESH); break;
1136                         case ID_CU:
1137                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_CURVE); break;
1138                         case ID_MB:
1139                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_META); break;
1140                         case ID_LT:
1141                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_LATTICE); break;
1142                         case ID_LA:
1143                         {
1144                                 Lamp *la = (Lamp *)tselem->id;
1145                                 
1146                                 switch (la->type) {
1147                                         case LA_LOCAL:
1148                                                 tselem_draw_icon_uibut(&arg, ICON_LAMP_POINT); break;
1149                                         case LA_SUN:
1150                                                 tselem_draw_icon_uibut(&arg, ICON_LAMP_SUN); break;
1151                                         case LA_SPOT:
1152                                                 tselem_draw_icon_uibut(&arg, ICON_LAMP_SPOT); break;
1153                                         case LA_HEMI:
1154                                                 tselem_draw_icon_uibut(&arg, ICON_LAMP_HEMI); break;
1155                                         case LA_AREA:
1156                                                 tselem_draw_icon_uibut(&arg, ICON_LAMP_AREA); break;
1157                                         default:
1158                                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_LAMP); break;
1159                                 }
1160                                 break;
1161                         }
1162                         case ID_MA:
1163                                 tselem_draw_icon_uibut(&arg, ICON_MATERIAL_DATA); break;
1164                         case ID_TE:
1165                                 tselem_draw_icon_uibut(&arg, ICON_TEXTURE_DATA); break;
1166                         case ID_IM:
1167                                 tselem_draw_icon_uibut(&arg, ICON_IMAGE_DATA); break;
1168                         case ID_SPK:
1169                         case ID_SO:
1170                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_SPEAKER); break;
1171                         case ID_AR:
1172                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_ARMATURE); break;
1173                         case ID_CA:
1174                                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_CAMERA); break;
1175                         case ID_KE:
1176                                 tselem_draw_icon_uibut(&arg, ICON_SHAPEKEY_DATA); break;
1177                         case ID_WO:
1178                                 tselem_draw_icon_uibut(&arg, ICON_WORLD_DATA); break;
1179                         case ID_AC:
1180                                 tselem_draw_icon_uibut(&arg, ICON_ACTION); break;
1181                         case ID_NLA:
1182                                 tselem_draw_icon_uibut(&arg, ICON_NLA); break;
1183                         case ID_TXT:
1184                                 tselem_draw_icon_uibut(&arg, ICON_SCRIPT); break;
1185                         case ID_GR:
1186                                 tselem_draw_icon_uibut(&arg, ICON_GROUP); break;
1187                         case ID_LI:
1188                                 tselem_draw_icon_uibut(&arg, ICON_LIBRARY_DATA_DIRECT); break;
1189                 }
1190         }
1191 }
1192
1193 static void outliner_draw_iconrow(bContext *C, uiBlock *block, Scene *scene, SpaceOops *soops, ListBase *lb, int level, int xmax, int *offsx, int ys)
1194 {
1195         TreeElement *te;
1196         TreeStoreElem *tselem;
1197         int active;
1198
1199         for (te = lb->first; te; te = te->next) {
1200                 
1201                 /* exit drawing early */
1202                 if ((*offsx) - UI_UNIT_X > xmax)
1203                         break;
1204
1205                 tselem = TREESTORE(te);
1206                 
1207                 /* object hierarchy always, further constrained on level */
1208                 if (level < 1 || (tselem->type == 0 && te->idcode == ID_OB)) {
1209
1210                         /* active blocks get white circle */
1211                         if (tselem->type == 0) {
1212                                 if (te->idcode == ID_OB) active = (OBACT == (Object *)tselem->id);
1213                                 else if (scene->obedit && scene->obedit->data == tselem->id) active = 1;  // XXX use context?
1214                                 else active = tree_element_active(C, scene, soops, te, 0);
1215                         }
1216                         else active = tree_element_type_active(NULL, scene, soops, te, tselem, 0);
1217                         
1218                         if (active) {
1219                                 float ufac = UI_UNIT_X / 20.0f;
1220
1221                                 uiSetRoundBox(UI_CNR_ALL);
1222                                 glColor4ub(255, 255, 255, 100);
1223                                 uiRoundBox((float) *offsx - 0.5f * ufac,
1224                                            (float)ys - 1.0f * ufac,
1225                                            (float)*offsx + UI_UNIT_Y - 3.0f * ufac,
1226                                            (float)ys + UI_UNIT_Y - 3.0f * ufac,
1227                                            (float)UI_UNIT_Y / 2.0f - 2.0f * ufac);
1228                                 glEnable(GL_BLEND); /* roundbox disables */
1229                         }
1230                         
1231                         tselem_draw_icon(block, xmax, (float)*offsx, (float)ys, tselem, te, 0.5f);
1232                         te->xs = (float)*offsx;
1233                         te->ys = (float)ys;
1234                         te->xend = (short)*offsx + UI_UNIT_X;
1235                         te->flag |= TE_ICONROW; // for click
1236                         
1237                         (*offsx) += UI_UNIT_X;
1238                 }
1239                 
1240                 /* this tree element always has same amount of branches, so don't draw */
1241                 if (tselem->type != TSE_R_LAYER)
1242                         outliner_draw_iconrow(C, block, scene, soops, &te->subtree, level + 1, xmax, offsx, ys);
1243         }
1244         
1245 }
1246
1247 /* closed tree element */
1248 static void outliner_set_coord_tree_element(SpaceOops *soops, TreeElement *te, int startx, int *starty)
1249 {
1250         TreeElement *ten;
1251         
1252         /* store coord and continue, we need coordinates for elements outside view too */
1253         te->xs = (float)startx;
1254         te->ys = (float)(*starty);
1255         
1256         for (ten = te->subtree.first; ten; ten = ten->next) {
1257                 outliner_set_coord_tree_element(soops, ten, startx + UI_UNIT_X, starty);
1258         }
1259 }
1260
1261
1262 static void outliner_draw_tree_element(bContext *C, uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, int startx, int *starty)
1263 {
1264         TreeElement *ten;
1265         TreeStoreElem *tselem;
1266         float ufac = UI_UNIT_X / 20.0f;
1267         int offsx = 0, active = 0; // active=1 active obj, else active data
1268         
1269         tselem = TREESTORE(te);
1270
1271         if (*starty + 2 * UI_UNIT_Y >= ar->v2d.cur.ymin && *starty <= ar->v2d.cur.ymax) {
1272                 int xmax = ar->v2d.cur.xmax;
1273                 
1274                 /* icons can be ui buts, we don't want it to overlap with restrict */
1275                 if ((soops->flag & SO_HIDE_RESTRICTCOLS) == 0)
1276                         xmax -= OL_TOGW + UI_UNIT_X;
1277                 
1278                 glEnable(GL_BLEND);
1279
1280                 /* start by highlighting search matches 
1281                  *      we don't expand items when searching in the datablocks but we 
1282                  *      still want to highlight any filter matches. 
1283                  */
1284                 if ((SEARCHING_OUTLINER(soops) || (soops->outlinevis == SO_DATABLOCKS && soops->search_string[0] != 0)) &&
1285                     (tselem->flag & TSE_SEARCHMATCH))
1286                 {
1287                         char col[4];
1288                         UI_GetThemeColorType4ubv(TH_MATCH, SPACE_OUTLINER, col);
1289                         col[3] = 100;
1290                         glColor4ubv((GLubyte *)col);
1291                         glRecti(startx, *starty + 1, ar->v2d.cur.xmax, *starty + UI_UNIT_Y - 1);
1292                 }
1293
1294                 /* colors for active/selected data */
1295                 if (tselem->type == 0) {
1296                         if (te->idcode == ID_SCE) {
1297                                 if (tselem->id == (ID *)scene) {
1298                                         glColor4ub(255, 255, 255, 100);
1299                                         active = 2;
1300                                 }
1301                         }
1302                         else if (te->idcode == ID_GR) {
1303                                 Group *gr = (Group *)tselem->id;
1304                                 if (group_select_flag(gr)) {
1305                                         char col[4];
1306                                         UI_GetThemeColorType4ubv(TH_SELECT, SPACE_VIEW3D, col);
1307                                         col[3] = 100;
1308                                         glColor4ubv((GLubyte *)col);
1309                                         
1310                                         active = 2;
1311                                 }
1312                         }
1313                         else if (te->idcode == ID_OB) {
1314                                 Object *ob = (Object *)tselem->id;
1315                                 
1316                                 if (ob == OBACT || (ob->flag & SELECT)) {
1317                                         char col[4] = {0, 0, 0, 0};
1318                                         
1319                                         /* outliner active ob: always white text, circle color now similar to view3d */
1320                                         
1321                                         active = 2; /* means it draws a color circle */
1322                                         if (ob == OBACT) {
1323                                                 if (ob->flag & SELECT) {
1324                                                         UI_GetThemeColorType4ubv(TH_ACTIVE, SPACE_VIEW3D, col);
1325                                                         col[3] = 100;
1326                                                 }
1327                                                 
1328                                                 active = 1; /* means it draws white text */
1329                                         }
1330                                         else if (ob->flag & SELECT) {
1331                                                 UI_GetThemeColorType4ubv(TH_SELECT, SPACE_VIEW3D, col);
1332                                                 col[3] = 100;
1333                                         }
1334                                         
1335                                         glColor4ubv((GLubyte *)col);
1336                                 }
1337                         
1338                         }
1339                         else if (scene->obedit && scene->obedit->data == tselem->id) {
1340                                 glColor4ub(255, 255, 255, 100);
1341                                 active = 2;
1342                         }
1343                         else {
1344                                 if (tree_element_active(C, scene, soops, te, 0)) {
1345                                         glColor4ub(220, 220, 255, 100);
1346                                         active = 2;
1347                                 }
1348                         }
1349                 }
1350                 else {
1351                         if (tree_element_type_active(NULL, scene, soops, te, tselem, 0) ) active = 2;
1352                         glColor4ub(220, 220, 255, 100);
1353                 }
1354                 
1355                 /* active circle */
1356                 if (active) {
1357                         uiSetRoundBox(UI_CNR_ALL);
1358                         uiRoundBox((float)startx + UI_UNIT_Y - 1.5f * ufac,
1359                                    (float)*starty + 2.0f * ufac,
1360                                    (float)startx + 2.0f * UI_UNIT_Y - 4.0f * ufac,
1361                                    (float)*starty + UI_UNIT_Y - 1.0f * ufac,
1362                                    UI_UNIT_Y / 2.0f - 2.0f * ufac);
1363                         glEnable(GL_BLEND); /* roundbox disables it */
1364                         
1365                         te->flag |= TE_ACTIVE; // for lookup in display hierarchies
1366                 }
1367                 
1368                 /* open/close icon, only when sublevels, except for scene */
1369                 if (te->subtree.first || (tselem->type == 0 && te->idcode == ID_SCE) || (te->flag & TE_LAZY_CLOSED)) {
1370                         int icon_x;
1371                         if (tselem->type == 0 && ELEM(te->idcode, ID_OB, ID_SCE))
1372                                 icon_x = startx;
1373                         else
1374                                 icon_x = startx + 5 * ufac;
1375                         
1376                         // icons a bit higher
1377                         if (TSELEM_OPEN(tselem, soops))
1378                                 UI_icon_draw((float)icon_x, (float)*starty + 2 * ufac, ICON_DISCLOSURE_TRI_DOWN);
1379                         else
1380                                 UI_icon_draw((float)icon_x, (float)*starty + 2 * ufac, ICON_DISCLOSURE_TRI_RIGHT);
1381                 }
1382                 offsx += UI_UNIT_X;
1383                 
1384                 /* datatype icon */
1385                 
1386                 if (!(ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM))) {
1387                         // icons a bit higher
1388                         tselem_draw_icon(block, xmax, (float)startx + offsx - 0.5f * ufac, (float)*starty + 2.0f * ufac, tselem, te, 1.0f);
1389                         
1390                         offsx += UI_UNIT_X;
1391                 }
1392                 else
1393                         offsx += 2 * ufac;
1394                 
1395                 if (tselem->type == 0 && tselem->id->lib) {
1396                         glPixelTransferf(GL_ALPHA_SCALE, 0.5f);
1397                         if (tselem->id->flag & LIB_INDIRECT)
1398                                 UI_icon_draw((float)startx + offsx, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_INDIRECT);
1399                         else
1400                                 UI_icon_draw((float)startx + offsx, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_DIRECT);
1401                         glPixelTransferf(GL_ALPHA_SCALE, 1.0f);
1402                         offsx += UI_UNIT_X;
1403                 }
1404                 glDisable(GL_BLEND);
1405                 
1406                 /* name */
1407                 if (active == 1) UI_ThemeColor(TH_TEXT_HI);
1408                 else if (ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) UI_ThemeColorBlend(TH_BACK, TH_TEXT, 0.75f);
1409                 else UI_ThemeColor(TH_TEXT);
1410                 
1411                 UI_DrawString(startx + offsx, *starty + 5 * ufac, te->name);
1412                 
1413                 offsx += (int)(UI_UNIT_X + UI_GetStringWidth(te->name));
1414                 
1415                 /* closed item, we draw the icons, not when it's a scene, or master-server list though */
1416                 if (!TSELEM_OPEN(tselem, soops)) {
1417                         if (te->subtree.first) {
1418                                 if (tselem->type == 0 && te->idcode == ID_SCE) {
1419                                         /* pass */
1420                                 }
1421                                 else if (tselem->type != TSE_R_LAYER) {
1422                                         /* this tree element always has same amount of branches, so don't draw */
1423
1424                                         int tempx = startx + offsx;
1425                                         
1426                                         /* divider */
1427                                         UI_ThemeColorShade(TH_BACK, -40);
1428                                         glRecti(tempx - 10, *starty + 4, tempx - 8, *starty + UI_UNIT_Y - 4);
1429                                         
1430                                         glEnable(GL_BLEND);
1431                                         glPixelTransferf(GL_ALPHA_SCALE, 0.5);
1432                                         
1433                                         outliner_draw_iconrow(C, block, scene, soops, &te->subtree, 0, xmax, &tempx, *starty + 2);
1434                                         
1435                                         glPixelTransferf(GL_ALPHA_SCALE, 1.0);
1436                                         glDisable(GL_BLEND);
1437                                 }
1438                         }
1439                 }
1440         }
1441         /* store coord and continue, we need coordinates for elements outside view too */
1442         te->xs = (float)startx;
1443         te->ys = (float)*starty;
1444         te->xend = startx + offsx;
1445                 
1446         if (TSELEM_OPEN(tselem, soops)) {
1447                 *starty -= UI_UNIT_Y;
1448                 
1449                 for (ten = te->subtree.first; ten; ten = ten->next)
1450                         outliner_draw_tree_element(C, block, scene, ar, soops, ten, startx + UI_UNIT_X, starty);
1451         }
1452         else {
1453                 for (ten = te->subtree.first; ten; ten = ten->next)
1454                         outliner_set_coord_tree_element(soops, te, startx, starty);
1455                 
1456                 *starty -= UI_UNIT_Y;
1457         }
1458 }
1459
1460 static void outliner_draw_hierarchy(SpaceOops *soops, ListBase *lb, int startx, int *starty)
1461 {
1462         TreeElement *te;
1463         TreeStoreElem *tselem;
1464         int y1, y2;
1465         
1466         if (lb->first == NULL) return;
1467         
1468         y1 = y2 = *starty; /* for vertical lines between objects */
1469         for (te = lb->first; te; te = te->next) {
1470                 y2 = *starty;
1471                 tselem = TREESTORE(te);
1472                 
1473                 /* horizontal line? */
1474                 if (tselem->type == 0 && (te->idcode == ID_OB || te->idcode == ID_SCE))
1475                         glRecti(startx, *starty, startx + UI_UNIT_X, *starty - 1);
1476                         
1477                 *starty -= UI_UNIT_Y;
1478                 
1479                 if (TSELEM_OPEN(tselem, soops))
1480                         outliner_draw_hierarchy(soops, &te->subtree, startx + UI_UNIT_X, starty);
1481         }
1482         
1483         /* vertical line */
1484         te = lb->last;
1485         if (te->parent || lb->first != lb->last) {
1486                 tselem = TREESTORE(te);
1487                 if (tselem->type == 0 && te->idcode == ID_OB) {
1488                         
1489                         glRecti(startx, y1 + UI_UNIT_Y, startx + 1, y2);
1490                 }
1491         }
1492 }
1493
1494 static void outliner_draw_struct_marks(ARegion *ar, SpaceOops *soops, ListBase *lb, int *starty) 
1495 {
1496         TreeElement *te;
1497         TreeStoreElem *tselem;
1498         
1499         for (te = lb->first; te; te = te->next) {
1500                 tselem = TREESTORE(te);
1501                 
1502                 /* selection status */
1503                 if (TSELEM_OPEN(tselem, soops))
1504                         if (tselem->type == TSE_RNA_STRUCT)
1505                                 glRecti(0, *starty + 1, (int)ar->v2d.cur.xmax + V2D_SCROLL_WIDTH, *starty + UI_UNIT_Y - 1);
1506
1507                 *starty -= UI_UNIT_Y;
1508                 if (TSELEM_OPEN(tselem, soops)) {
1509                         outliner_draw_struct_marks(ar, soops, &te->subtree, starty);
1510                         if (tselem->type == TSE_RNA_STRUCT)
1511                                 fdrawline(0, (float)*starty + UI_UNIT_Y, ar->v2d.cur.xmax + V2D_SCROLL_WIDTH, (float)*starty + UI_UNIT_Y);
1512                 }
1513         }
1514 }
1515
1516 static void outliner_draw_selection(ARegion *ar, SpaceOops *soops, ListBase *lb, int *starty) 
1517 {
1518         TreeElement *te;
1519         TreeStoreElem *tselem;
1520         
1521         for (te = lb->first; te; te = te->next) {
1522                 tselem = TREESTORE(te);
1523                 
1524                 /* selection status */
1525                 if (tselem->flag & TSE_SELECTED) {
1526                         glRecti(0, *starty + 1, (int)ar->v2d.cur.xmax, *starty + UI_UNIT_Y - 1);
1527                 }
1528                 *starty -= UI_UNIT_Y;
1529                 if (TSELEM_OPEN(tselem, soops)) outliner_draw_selection(ar, soops, &te->subtree, starty);
1530         }
1531 }
1532
1533
1534 static void outliner_draw_tree(bContext *C, uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops)
1535 {
1536         TreeElement *te;
1537         int starty, startx;
1538         float col[3];
1539                 
1540         glBlendFunc(GL_SRC_ALPHA,  GL_ONE_MINUS_SRC_ALPHA); // only once
1541         
1542         if (ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF)) {
1543                 /* struct marks */
1544                 UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
1545                 //UI_ThemeColorShade(TH_BACK, -20);
1546                 starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y - OL_Y_OFFSET;
1547                 outliner_draw_struct_marks(ar, soops, &soops->tree, &starty);
1548         }
1549         
1550         /* always draw selection fill before hierarchy */
1551         UI_GetThemeColor3fv(TH_SELECT_HIGHLIGHT, col);
1552         glColor3fv(col);
1553         starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y - OL_Y_OFFSET;
1554         outliner_draw_selection(ar, soops, &soops->tree, &starty);
1555         
1556         // gray hierarchy lines
1557         UI_ThemeColorBlend(TH_BACK, TH_TEXT, 0.4f);
1558         starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y / 2 - OL_Y_OFFSET;
1559         startx = 6;
1560         outliner_draw_hierarchy(soops, &soops->tree, startx, &starty);
1561         
1562         // items themselves
1563         starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y - OL_Y_OFFSET;
1564         startx = 0;
1565         for (te = soops->tree.first; te; te = te->next) {
1566                 outliner_draw_tree_element(C, block, scene, ar, soops, te, startx, &starty);
1567         }
1568 }
1569
1570
1571 static void outliner_back(ARegion *ar)
1572 {
1573         int ystart;
1574         
1575         UI_ThemeColorShade(TH_BACK, 6);
1576         ystart = (int)ar->v2d.tot.ymax;
1577         ystart = UI_UNIT_Y * (ystart / (UI_UNIT_Y)) - OL_Y_OFFSET;
1578         
1579         while (ystart + 2 * UI_UNIT_Y > ar->v2d.cur.ymin) {
1580                 glRecti(0, ystart, (int)ar->v2d.cur.xmax + V2D_SCROLL_WIDTH, ystart + UI_UNIT_Y);
1581                 ystart -= 2 * UI_UNIT_Y;
1582         }
1583 }
1584
1585 static void outliner_draw_restrictcols(ARegion *ar)
1586 {
1587         int ystart;
1588         
1589         /* background underneath */
1590         UI_ThemeColor(TH_BACK);
1591         glRecti((int)ar->v2d.cur.xmax - OL_TOGW,
1592                 (int)ar->v2d.cur.ymin - V2D_SCROLL_HEIGHT - 1,
1593                 (int)ar->v2d.cur.xmax + V2D_SCROLL_WIDTH,
1594                 (int)ar->v2d.cur.ymax);
1595         
1596         UI_ThemeColorShade(TH_BACK, 6);
1597         ystart = (int)ar->v2d.tot.ymax;
1598         ystart = UI_UNIT_Y * (ystart / (UI_UNIT_Y)) - OL_Y_OFFSET;
1599         
1600         while (ystart + 2 * UI_UNIT_Y > ar->v2d.cur.ymin) {
1601                 glRecti((int)ar->v2d.cur.xmax - OL_TOGW, ystart, (int)ar->v2d.cur.xmax, ystart + UI_UNIT_Y);
1602                 ystart -= 2 * UI_UNIT_Y;
1603         }
1604         
1605         UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
1606
1607         /* view */
1608         fdrawline(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX,
1609                   ar->v2d.cur.ymax,
1610                   ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX,
1611                   ar->v2d.cur.ymin - V2D_SCROLL_HEIGHT);
1612
1613         /* render */
1614         fdrawline(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX,
1615                   ar->v2d.cur.ymax,
1616                   ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX,
1617                   ar->v2d.cur.ymin - V2D_SCROLL_HEIGHT);
1618
1619         /* render */
1620         fdrawline(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX,
1621                   ar->v2d.cur.ymax,
1622                   ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX,
1623                   ar->v2d.cur.ymin - V2D_SCROLL_HEIGHT);
1624 }
1625
1626 /* ****************************************************** */
1627 /* Main Entrypoint - Draw contents of Outliner editor */
1628  
1629 void draw_outliner(const bContext *C)
1630 {
1631         Main *mainvar = CTX_data_main(C);
1632         Scene *scene = CTX_data_scene(C);
1633         ARegion *ar = CTX_wm_region(C);
1634         View2D *v2d = &ar->v2d;
1635         SpaceOops *soops = CTX_wm_space_outliner(C);
1636         uiBlock *block;
1637         int sizey = 0, sizex = 0, sizex_rna = 0;
1638         
1639         outliner_build_tree(mainvar, scene, soops); // always 
1640         
1641         /* get extents of data */
1642         outliner_height(soops, &soops->tree, &sizey);
1643
1644         if (ELEM3(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF, SO_KEYMAP)) {
1645                 /* RNA has two columns:
1646                  *  - column 1 is (max_width + OL_RNA_COL_SPACEX) or
1647                  *                               (OL_RNA_COL_X), whichever is wider...
1648                  *      - column 2 is fixed at OL_RNA_COL_SIZEX
1649                  *
1650                  *  (*) XXX max width for now is a fixed factor of UI_UNIT_X*(max_indention+100)
1651                  */
1652                  
1653                 /* get actual width of column 1 */
1654                 outliner_rna_width(soops, &soops->tree, &sizex_rna, 0);
1655                 sizex_rna = max_ii(OL_RNA_COLX, sizex_rna + OL_RNA_COL_SPACEX);
1656                 
1657                 /* get width of data (for setting 'tot' rect, this is column 1 + column 2 + a bit extra) */
1658                 if (soops->outlinevis == SO_KEYMAP) 
1659                         sizex = sizex_rna + OL_RNA_COL_SIZEX * 3 + 50;  // XXX this is only really a quick hack to make this wide enough...
1660                 else
1661                         sizex = sizex_rna + OL_RNA_COL_SIZEX + 50;
1662         }
1663         else {
1664                 /* width must take into account restriction columns (if visible) so that entries will still be visible */
1665                 //outliner_width(soops, &soops->tree, &sizex);
1666                 outliner_rna_width(soops, &soops->tree, &sizex, 0); // XXX should use outliner_width instead when te->xend will be set correctly...
1667                 
1668                 /* constant offset for restriction columns */
1669                 // XXX this isn't that great yet...
1670                 if ((soops->flag & SO_HIDE_RESTRICTCOLS) == 0)
1671                         sizex += OL_TOGW * 3;
1672         }
1673         
1674         /* tweak to display last line (when list bigger than window) */
1675         sizey += V2D_SCROLL_HEIGHT;
1676         
1677         /* adds vertical offset */
1678         sizey += OL_Y_OFFSET;
1679
1680         /* update size of tot-rect (extents of data/viewable area) */
1681         UI_view2d_totRect_set(v2d, sizex, sizey);
1682
1683         /* force display to pixel coords */
1684         v2d->flag |= (V2D_PIXELOFS_X | V2D_PIXELOFS_Y);
1685         /* set matrix for 2d-view controls */
1686         UI_view2d_view_ortho(v2d);
1687
1688         /* draw outliner stuff (background, hierachy lines and names) */
1689         outliner_back(ar);
1690         block = uiBeginBlock(C, ar, __func__, UI_EMBOSS);
1691         outliner_draw_tree((bContext *)C, block, scene, ar, soops);
1692         
1693         if (ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF)) {
1694                 /* draw rna buttons */
1695                 outliner_draw_rnacols(ar, sizex_rna);
1696                 outliner_draw_rnabuts(block, scene, ar, soops, sizex_rna, &soops->tree);
1697         }
1698         else if (soops->outlinevis == SO_KEYMAP) {
1699                 outliner_draw_keymapbuts(block, ar, soops, &soops->tree);
1700         }
1701         else if (!(soops->flag & SO_HIDE_RESTRICTCOLS)) {
1702                 /* draw restriction columns */
1703                 outliner_draw_restrictcols(ar);
1704                 outliner_draw_restrictbuts(block, scene, ar, soops, &soops->tree);
1705         }
1706
1707         /* draw edit buttons if nessecery */
1708         outliner_buttons(C, block, ar, soops, &soops->tree);
1709
1710         uiEndBlock(C, block);
1711         uiDrawBlock(C, block);
1712         
1713         /* clear flag that allows quick redraws */
1714         soops->storeflag &= ~SO_TREESTORE_REDRAW;
1715