Blender V2.61 - r43446

outliner_draw.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version. 
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2004 Blender Foundation.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): Joshua Leung
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00032 #include <string.h>
00033 #include <stdlib.h>
00034 
00035 #include "MEM_guardedalloc.h"
00036 
00037 #include "DNA_anim_types.h"
00038 #include "DNA_armature_types.h"
00039 #include "DNA_camera_types.h"
00040 #include "DNA_group_types.h"
00041 #include "DNA_key_types.h"
00042 #include "DNA_lamp_types.h"
00043 #include "DNA_material_types.h"
00044 #include "DNA_mesh_types.h"
00045 #include "DNA_meta_types.h"
00046 #include "DNA_particle_types.h"
00047 #include "DNA_scene_types.h"
00048 #include "DNA_world_types.h"
00049 #include "DNA_sequence_types.h"
00050 #include "DNA_object_types.h"
00051 
00052 #include "BLI_blenlib.h"
00053 #include "BLI_utildefines.h"
00054 
00055 #include "BKE_animsys.h"
00056 #include "BKE_context.h"
00057 #include "BKE_deform.h"
00058 #include "BKE_depsgraph.h"
00059 #include "BKE_fcurve.h"
00060 #include "BKE_global.h"
00061 #include "BKE_group.h"
00062 #include "BKE_library.h"
00063 #include "BKE_main.h"
00064 #include "BKE_modifier.h"
00065 #include "BKE_report.h"
00066 #include "BKE_scene.h"
00067 #include "BKE_sequencer.h"
00068 
00069 #include "BLI_ghash.h"
00070 
00071 #include "ED_armature.h"
00072 #include "ED_object.h"
00073 #include "ED_screen.h"
00074 #include "ED_util.h"
00075 
00076 #include "WM_api.h"
00077 #include "WM_types.h"
00078 
00079 #include "BIF_gl.h"
00080 #include "BIF_glutil.h"
00081 
00082 #include "UI_interface.h"
00083 #include "UI_interface_icons.h"
00084 #include "UI_resources.h"
00085 #include "UI_view2d.h"
00086 
00087 #include "RNA_access.h"
00088 #include "RNA_define.h"
00089 
00090 #include "outliner_intern.h"
00091 
00092 /* ****************************************************** */
00093 /* Tree Size Functions */
00094 
00095 static void outliner_height(SpaceOops *soops, ListBase *lb, int *h)
00096 {
00097     TreeElement *te= lb->first;
00098     while(te) {
00099         TreeStoreElem *tselem= TREESTORE(te);
00100         if(TSELEM_OPEN(tselem,soops))
00101             outliner_height(soops, &te->subtree, h);
00102         (*h) += UI_UNIT_Y;
00103         te= te->next;
00104     }
00105 }
00106 
00107 #if 0  // XXX this is currently disabled until te->xend is set correctly
00108 static void outliner_width(SpaceOops *soops, ListBase *lb, int *w)
00109 {
00110     TreeElement *te= lb->first;
00111     while(te) {
00112 //      TreeStoreElem *tselem= TREESTORE(te);
00113         
00114         // XXX fixme... te->xend is not set yet
00115         if(!TSELEM_OPEN(tselem,soops)) {
00116             if (te->xend > *w)
00117                 *w = te->xend;
00118         }
00119         outliner_width(soops, &te->subtree, w);
00120         te= te->next;
00121     }
00122 }
00123 #endif
00124 
00125 static void outliner_rna_width(SpaceOops *soops, ListBase *lb, int *w, int startx)
00126 {
00127     TreeElement *te= lb->first;
00128     while(te) {
00129         TreeStoreElem *tselem= TREESTORE(te);
00130             // XXX fixme... (currently, we're using a fixed length of 100)!
00131         /*if(te->xend) {
00132             if(te->xend > *w)
00133                 *w = te->xend;
00134         }*/
00135         if(startx+100 > *w)
00136             *w = startx+100;
00137 
00138         if(TSELEM_OPEN(tselem,soops))
00139             outliner_rna_width(soops, &te->subtree, w, startx+UI_UNIT_X);
00140         te= te->next;
00141     }
00142 }
00143 
00144 /* ****************************************************** */
00145 
00146 static void restrictbutton_view_cb(bContext *C, void *poin, void *poin2)
00147 {
00148     Scene *scene = (Scene *)poin;
00149     Object *ob = (Object *)poin2;
00150 
00151     if(!common_restrict_check(C, ob)) return;
00152     
00153     /* deselect objects that are invisible */
00154     if (ob->restrictflag & OB_RESTRICT_VIEW) {
00155         /* Ouch! There is no backwards pointer from Object to Base, 
00156          * so have to do loop to find it. */
00157         ED_base_object_select(object_in_scene(ob, scene), BA_DESELECT);
00158     }
00159     WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
00160 
00161 }
00162 
00163 static void restrictbutton_sel_cb(bContext *C, void *poin, void *poin2)
00164 {
00165     Scene *scene = (Scene *)poin;
00166     Object *ob = (Object *)poin2;
00167     
00168     if(!common_restrict_check(C, ob)) return;
00169     
00170     /* if select restriction has just been turned on */
00171     if (ob->restrictflag & OB_RESTRICT_SELECT) {
00172         /* Ouch! There is no backwards pointer from Object to Base, 
00173          * so have to do loop to find it. */
00174         ED_base_object_select(object_in_scene(ob, scene), BA_DESELECT);
00175     }
00176     WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
00177 
00178 }
00179 
00180 static void restrictbutton_rend_cb(bContext *C, void *poin, void *UNUSED(poin2))
00181 {
00182     WM_event_add_notifier(C, NC_SCENE|ND_OB_RENDER, poin);
00183 }
00184 
00185 static void restrictbutton_r_lay_cb(bContext *C, void *poin, void *UNUSED(poin2))
00186 {
00187     WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, poin);
00188 }
00189 
00190 static void restrictbutton_modifier_cb(bContext *C, void *UNUSED(poin), void *poin2)
00191 {
00192     Object *ob = (Object *)poin2;
00193     
00194     DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
00195 
00196     WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
00197 }
00198 
00199 static void restrictbutton_bone_cb(bContext *C, void *UNUSED(poin), void *poin2)
00200 {
00201     Bone *bone= (Bone *)poin2;
00202     if(bone && (bone->flag & BONE_HIDDEN_P))
00203         bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
00204     WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
00205 }
00206 
00207 static void restrictbutton_ebone_cb(bContext *C, void *UNUSED(poin), void *poin2)
00208 {
00209     EditBone *ebone= (EditBone *)poin2;
00210     if(ebone && (ebone->flag & BONE_HIDDEN_A))
00211         ebone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
00212 
00213     WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
00214 }
00215 
00216 static int group_restrict_flag(Group *gr, int flag)
00217 {
00218     GroupObject *gob;
00219 
00220     for(gob= gr->gobject.first; gob; gob= gob->next) {
00221         if((gob->ob->restrictflag & flag) == 0)
00222             return 0;
00223     }
00224 
00225     return 1;
00226 }
00227 
00228 static int group_select_flag(Group *gr)
00229 {
00230     GroupObject *gob;
00231 
00232     for(gob= gr->gobject.first; gob; gob= gob->next)
00233         if((gob->ob->flag & SELECT))
00234             return 1;
00235 
00236     return 0;
00237 }
00238 
00239 void restrictbutton_gr_restrict_flag(void *poin, void *poin2, int flag)
00240 {   
00241     Scene *scene = (Scene *)poin;       
00242     GroupObject *gob;
00243     Group *gr = (Group *)poin2;     
00244 
00245     if(group_restrict_flag(gr, flag)) {
00246         for(gob= gr->gobject.first; gob; gob= gob->next) {
00247             gob->ob->restrictflag &= ~flag;
00248             
00249             if(flag==OB_RESTRICT_VIEW)
00250                 if(gob->ob->flag & SELECT)
00251                     ED_base_object_select(object_in_scene(gob->ob, scene), BA_DESELECT);
00252         }
00253     }
00254     else {
00255         for(gob= gr->gobject.first; gob; gob= gob->next) {
00256             /* not in editmode */
00257             if(scene->obedit!=gob->ob) {
00258                 gob->ob->restrictflag |= flag;
00259                 
00260                 if(flag==OB_RESTRICT_VIEW)
00261                     if((gob->ob->flag & SELECT) == 0)
00262                         ED_base_object_select(object_in_scene(gob->ob, scene), BA_SELECT);
00263             }
00264         }
00265     }
00266 } 
00267 
00268 static void restrictbutton_gr_restrict_view(bContext *C, void *poin, void *poin2)
00269 {
00270     restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_VIEW);
00271     WM_event_add_notifier(C, NC_GROUP, NULL);
00272 }
00273 static void restrictbutton_gr_restrict_select(bContext *C, void *poin, void *poin2)
00274 {
00275     restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_SELECT);
00276     WM_event_add_notifier(C, NC_GROUP, NULL);
00277 }
00278 static void restrictbutton_gr_restrict_render(bContext *C, void *poin, void *poin2)
00279 {
00280     restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_RENDER);
00281     WM_event_add_notifier(C, NC_GROUP, NULL);
00282 }
00283 
00284 
00285 static void namebutton_cb(bContext *C, void *tsep, char *oldname)
00286 {
00287     SpaceOops *soops= CTX_wm_space_outliner(C);
00288     Scene *scene= CTX_data_scene(C);
00289     Object *obedit= CTX_data_edit_object(C);
00290     TreeStore *ts= soops->treestore;
00291     TreeStoreElem *tselem= tsep;
00292     
00293     if(ts && tselem) {
00294         TreeElement *te= outliner_find_tse(soops, tselem);
00295         
00296         if(tselem->type==0) {
00297             test_idbutton(tselem->id->name+2);  // library.c, unique name and alpha sort
00298             
00299             switch(GS(tselem->id->name)) {
00300                 case ID_MA:
00301                     WM_event_add_notifier(C, NC_MATERIAL, NULL); break;
00302                 case ID_TE:
00303                     WM_event_add_notifier(C, NC_TEXTURE, NULL); break;
00304                 case ID_IM:
00305                     WM_event_add_notifier(C, NC_IMAGE, NULL); break;
00306                 case ID_SCE:
00307                     WM_event_add_notifier(C, NC_SCENE, NULL); break;
00308                 default:
00309                     WM_event_add_notifier(C, NC_ID|NA_RENAME, NULL); break;
00310             }                   
00311             /* Check the library target exists */
00312             if (te->idcode == ID_LI) {
00313                 Library *lib= (Library *)tselem->id;
00314                 char expanded[FILE_MAX];
00315 
00316                 BKE_library_filepath_set(lib, lib->name);
00317 
00318                 BLI_strncpy(expanded, lib->name, sizeof(expanded));
00319                 BLI_path_abs(expanded, G.main->name);
00320                 if (!BLI_exists(expanded)) {
00321                     BKE_reportf(CTX_wm_reports(C), RPT_ERROR, "Library path '%s' does not exist, correct this before saving", expanded);
00322                 }
00323             }
00324         }
00325         else {
00326             switch(tselem->type) {
00327             case TSE_DEFGROUP:
00328                 defgroup_unique_name(te->directdata, (Object *)tselem->id); //  id = object
00329                 break;
00330             case TSE_NLA_ACTION:
00331                 test_idbutton(tselem->id->name+2);
00332                 break;
00333             case TSE_EBONE:
00334             {
00335                 bArmature *arm= (bArmature *)tselem->id;
00336                 if(arm->edbo) {
00337                     EditBone *ebone= te->directdata;
00338                     char newname[sizeof(ebone->name)];
00339                     
00340                     /* restore bone name */
00341                     BLI_strncpy(newname, ebone->name, sizeof(ebone->name));
00342                     BLI_strncpy(ebone->name, oldname, sizeof(ebone->name));
00343                     ED_armature_bone_rename(obedit->data, oldname, newname);
00344                     WM_event_add_notifier(C, NC_OBJECT|ND_POSE, OBACT);
00345                 }
00346             }
00347                 break;
00348 
00349             case TSE_BONE:
00350                 {
00351                     Bone *bone= te->directdata;
00352                     Object *ob;
00353                     char newname[sizeof(bone->name)];
00354                     
00355                     // always make current object active
00356                     tree_element_active(C, scene, soops, te, 1); // was set_active_object()
00357                     ob= OBACT;
00358                     
00359                     /* restore bone name */
00360                     BLI_strncpy(newname, bone->name, sizeof(bone->name));
00361                     BLI_strncpy(bone->name, oldname, sizeof(bone->name));
00362                     ED_armature_bone_rename(ob->data, oldname, newname);
00363                     WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob);
00364                 }
00365                 break;
00366             case TSE_POSE_CHANNEL:
00367                 {
00368                     bPoseChannel *pchan= te->directdata;
00369                     Object *ob;
00370                     char newname[sizeof(pchan->name)];
00371                     
00372                     // always make current object active
00373                     tree_element_active(C, scene, soops, te, 1); // was set_active_object()
00374                     ob= OBACT;
00375                     
00376                     /* restore bone name */
00377                     BLI_strncpy(newname, pchan->name, sizeof(pchan->name));
00378                     BLI_strncpy(pchan->name, oldname, sizeof(pchan->name));
00379                     ED_armature_bone_rename(ob->data, oldname, newname);
00380                     WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob);
00381                 }
00382                 break;
00383             case TSE_POSEGRP:
00384                 {
00385                     Object *ob= (Object *)tselem->id; // id = object
00386                     bActionGroup *grp= te->directdata;
00387                     
00388                     BLI_uniquename(&ob->pose->agroups, grp, "Group", '.', offsetof(bActionGroup, name), sizeof(grp->name));
00389                     WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob);
00390                 }
00391                 break;
00392             case TSE_R_LAYER:
00393                 break;
00394             }
00395         }
00396         tselem->flag &= ~TSE_TEXTBUT;
00397     }
00398 }
00399 
00400 static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops, ListBase *lb)
00401 {   
00402     uiBut *bt;
00403     TreeElement *te;
00404     TreeStoreElem *tselem;
00405     Object *ob = NULL;
00406     Group  *gr = NULL;
00407 
00408     for(te= lb->first; te; te= te->next) {
00409         tselem= TREESTORE(te);
00410         if(te->ys+2*UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {  
00411             /* objects have toggle-able restriction flags */
00412             if(tselem->type==0 && te->idcode==ID_OB) {
00413                 PointerRNA ptr;
00414                 
00415                 ob = (Object *)tselem->id;
00416                 RNA_pointer_create((ID *)ob, &RNA_Object, ob, &ptr);
00417                 
00418                 uiBlockSetEmboss(block, UI_EMBOSSN);
00419                 bt= uiDefIconButR(block, ICONTOG, 0, ICON_RESTRICT_VIEW_OFF,
00420                               (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX, (int)te->ys, UI_UNIT_X-1, UI_UNIT_Y-1,
00421                               &ptr, "hide", -1, 0, 0, -1, -1, NULL);
00422                 uiButSetFunc(bt, restrictbutton_view_cb, scene, ob);
00423                 
00424                 bt= uiDefIconButR(block, ICONTOG, 0, ICON_RESTRICT_SELECT_OFF,
00425                                   (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_SELECTX, (int)te->ys, UI_UNIT_X-1, UI_UNIT_Y-1,
00426                                   &ptr, "hide_select", -1, 0, 0, -1, -1, NULL);
00427                 uiButSetFunc(bt, restrictbutton_sel_cb, scene, ob);
00428                 
00429                 bt= uiDefIconButR(block, ICONTOG, 0, ICON_RESTRICT_RENDER_OFF,
00430                                   (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_RENDERX, (int)te->ys, UI_UNIT_X-1, UI_UNIT_Y-1,
00431                                   &ptr, "hide_render", -1, 0, 0, -1, -1, NULL);
00432                 uiButSetFunc(bt, restrictbutton_rend_cb, scene, ob);
00433                 
00434                 uiBlockSetEmboss(block, UI_EMBOSS);
00435                 
00436             }
00437             if(tselem->type==0 && te->idcode==ID_GR){ 
00438                 int restrict_bool;
00439                 gr = (Group *)tselem->id;
00440                 
00441                 uiBlockSetEmboss(block, UI_EMBOSSN);
00442                 
00443                 restrict_bool= group_restrict_flag(gr, OB_RESTRICT_VIEW);
00444                 bt = uiDefIconBut(block, BUT, 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");
00445                 uiButSetFunc(bt, restrictbutton_gr_restrict_view, scene, gr);
00446 
00447                 restrict_bool= group_restrict_flag(gr, OB_RESTRICT_SELECT);
00448                 bt = uiDefIconBut(block, BUT, 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");
00449                 uiButSetFunc(bt, restrictbutton_gr_restrict_select, scene, gr);
00450     
00451                 restrict_bool= group_restrict_flag(gr, OB_RESTRICT_RENDER);
00452                 bt = uiDefIconBut(block, BUT, 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");
00453                 uiButSetFunc(bt, restrictbutton_gr_restrict_render, scene, gr);
00454 
00455                 uiBlockSetEmboss(block, UI_EMBOSS);
00456             }
00457             /* scene render layers and passes have toggle-able flags too! */
00458             else if(tselem->type==TSE_R_LAYER) {
00459                 uiBlockSetEmboss(block, UI_EMBOSSN);
00460                 
00461                 bt= uiDefIconButBitI(block, ICONTOGN, SCE_LAY_DISABLE, 0, ICON_CHECKBOX_HLT-1, 
00462                                      (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");
00463                 uiButSetFunc(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
00464                 
00465                 uiBlockSetEmboss(block, UI_EMBOSS);
00466             }
00467             else if(tselem->type==TSE_R_PASS) {
00468                 int *layflag= te->directdata;
00469                 int passflag= 1<<tselem->nr;
00470                 
00471                 uiBlockSetEmboss(block, UI_EMBOSSN);
00472                 
00473                 
00474                 bt= uiDefIconButBitI(block, ICONTOG, passflag, 0, ICON_CHECKBOX_HLT-1, 
00475                                      (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");
00476                 uiButSetFunc(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
00477                 
00478                 layflag++;  /* is lay_xor */
00479                 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))
00480                     bt= uiDefIconButBitI(block, TOG, passflag, 0, (*layflag & passflag)?ICON_DOT:ICON_BLANK1, 
00481                                      (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");
00482                 uiButSetFunc(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
00483                 
00484                 uiBlockSetEmboss(block, UI_EMBOSS);
00485             }
00486             else if(tselem->type==TSE_MODIFIER)  {
00487                 ModifierData *md= (ModifierData *)te->directdata;
00488                 ob = (Object *)tselem->id;
00489                 
00490                 uiBlockSetEmboss(block, UI_EMBOSSN);
00491                 bt= uiDefIconButBitI(block, ICONTOGN, eModifierMode_Realtime, 0, ICON_RESTRICT_VIEW_OFF, 
00492                         (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");
00493                 uiButSetFunc(bt, restrictbutton_modifier_cb, scene, ob);
00494                 
00495                 bt= uiDefIconButBitI(block, ICONTOGN, eModifierMode_Render, 0, ICON_RESTRICT_RENDER_OFF, 
00496                         (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");
00497                 uiButSetFunc(bt, restrictbutton_modifier_cb, scene, ob);
00498             }
00499             else if(tselem->type==TSE_POSE_CHANNEL)  {
00500                 bPoseChannel *pchan= (bPoseChannel *)te->directdata;
00501                 Bone *bone = pchan->bone;
00502                 
00503                 uiBlockSetEmboss(block, UI_EMBOSSN);
00504                 bt= uiDefIconButBitI(block, ICONTOG, BONE_HIDDEN_P, 0, ICON_RESTRICT_VIEW_OFF, 
00505                         (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");
00506                 uiButSetFunc(bt, restrictbutton_bone_cb, NULL, bone);
00507                 
00508                 bt= uiDefIconButBitI(block, ICONTOG, BONE_UNSELECTABLE, 0, ICON_RESTRICT_SELECT_OFF, 
00509                         (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");
00510                 uiButSetFunc(bt, restrictbutton_bone_cb, NULL, NULL);
00511             }
00512             else if(tselem->type==TSE_EBONE)  {
00513                 EditBone *ebone= (EditBone *)te->directdata;
00514                 
00515                 uiBlockSetEmboss(block, UI_EMBOSSN);
00516                 bt= uiDefIconButBitI(block, ICONTOG, BONE_HIDDEN_A, 0, ICON_RESTRICT_VIEW_OFF, 
00517                         (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");
00518                 uiButSetFunc(bt, restrictbutton_ebone_cb, NULL, ebone);
00519                 
00520                 bt= uiDefIconButBitI(block, ICONTOG, BONE_UNSELECTABLE, 0, ICON_RESTRICT_SELECT_OFF, 
00521                         (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");
00522                 uiButSetFunc(bt, restrictbutton_ebone_cb, NULL, NULL);
00523             }
00524         }
00525         
00526         if(TSELEM_OPEN(tselem,soops)) outliner_draw_restrictbuts(block, scene, ar, soops, &te->subtree);
00527     }
00528 }
00529 
00530 static void outliner_draw_rnacols(ARegion *ar, int sizex)
00531 {
00532     View2D *v2d= &ar->v2d;
00533 
00534     float miny = v2d->cur.ymin-V2D_SCROLL_HEIGHT;
00535     if(miny<v2d->tot.ymin) miny = v2d->tot.ymin;
00536 
00537     UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
00538 
00539     /* draw column separator lines */
00540     fdrawline((float)sizex,
00541         v2d->cur.ymax,
00542         (float)sizex,
00543         miny);
00544 
00545     fdrawline((float)sizex+OL_RNA_COL_SIZEX,
00546         v2d->cur.ymax,
00547         (float)sizex+OL_RNA_COL_SIZEX,
00548         miny);
00549 }
00550 
00551 static void outliner_draw_rnabuts(uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops, int sizex, ListBase *lb)
00552 {   
00553     TreeElement *te;
00554     TreeStoreElem *tselem;
00555     PointerRNA *ptr;
00556     PropertyRNA *prop;
00557     
00558     uiBlockSetEmboss(block, UI_EMBOSST);
00559 
00560     for(te= lb->first; te; te= te->next) {
00561         tselem= TREESTORE(te);
00562         if(te->ys+2*UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {  
00563             if(tselem->type == TSE_RNA_PROPERTY) {
00564                 ptr= &te->rnaptr;
00565                 prop= te->directdata;
00566                 
00567                 if(!(RNA_property_type(prop) == PROP_POINTER && (TSELEM_OPEN(tselem,soops))) )
00568                     uiDefAutoButR(block, ptr, prop, -1, "", ICON_NONE, sizex, (int)te->ys, OL_RNA_COL_SIZEX, UI_UNIT_Y-1);
00569             }
00570             else if(tselem->type == TSE_RNA_ARRAY_ELEM) {
00571                 ptr= &te->rnaptr;
00572                 prop= te->directdata;
00573                 
00574                 uiDefAutoButR(block, ptr, prop, te->index, "", ICON_NONE, sizex, (int)te->ys, OL_RNA_COL_SIZEX, UI_UNIT_Y-1);
00575             }
00576         }
00577         
00578         if(TSELEM_OPEN(tselem,soops)) outliner_draw_rnabuts(block, scene, ar, soops, sizex, &te->subtree);
00579     }
00580 }
00581 
00582 static void operator_call_cb(struct bContext *UNUSED(C), void *arg_kmi, void *arg2)
00583 {
00584     wmOperatorType *ot= arg2;
00585     wmKeyMapItem *kmi= arg_kmi;
00586     
00587     if(ot)
00588         BLI_strncpy(kmi->idname, ot->idname, OP_MAX_TYPENAME);
00589 }
00590 
00591 static void operator_search_cb(const struct bContext *UNUSED(C), void *UNUSED(arg_kmi), const char *str, uiSearchItems *items)
00592 {
00593     GHashIterator *iter= WM_operatortype_iter();
00594 
00595     for( ; !BLI_ghashIterator_isDone(iter); BLI_ghashIterator_step(iter)) {
00596         wmOperatorType *ot= BLI_ghashIterator_getValue(iter);
00597         
00598         if(BLI_strcasestr(ot->idname, str)) {
00599             char name[OP_MAX_TYPENAME];
00600             
00601             /* display name for menu */
00602             WM_operator_py_idname(name, ot->idname);
00603             
00604             if(0==uiSearchItemAdd(items, name, ot, 0))
00605                 break;
00606         }
00607     }
00608     BLI_ghashIterator_free(iter);
00609 }
00610 
00611 /* operator Search browse menu, open */
00612 static uiBlock *operator_search_menu(bContext *C, ARegion *ar, void *arg_kmi)
00613 {
00614     static char search[OP_MAX_TYPENAME];
00615     wmEvent event;
00616     wmWindow *win= CTX_wm_window(C);
00617     wmKeyMapItem *kmi= arg_kmi;
00618     wmOperatorType *ot= WM_operatortype_find(kmi->idname, 0);
00619     uiBlock *block;
00620     uiBut *but;
00621     
00622     /* clear initial search string, then all items show */
00623     search[0]= 0;
00624     
00625     block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
00626     uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1);
00627     
00628     /* fake button, it holds space for search items */
00629     uiDefBut(block, LABEL, 0, "", 10, 15, 150, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
00630     
00631     but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 0, 150, UI_UNIT_Y, 0, 0, "");
00632     uiButSetSearchFunc(but, operator_search_cb, arg_kmi, operator_call_cb, ot);
00633     
00634     uiBoundsBlock(block, 6);
00635     uiBlockSetDirection(block, UI_DOWN);    
00636     uiEndBlock(C, block);
00637     
00638     event= *(win->eventstate);  /* XXX huh huh? make api call */
00639     event.type= EVT_BUT_OPEN;
00640     event.val= KM_PRESS;
00641     event.customdata= but;
00642     event.customdatafree= FALSE;
00643     wm_event_add(win, &event);
00644     
00645     return block;
00646 }
00647 
00648 #define OL_KM_KEYBOARD      0
00649 #define OL_KM_MOUSE         1
00650 #define OL_KM_TWEAK         2
00651 #define OL_KM_SPECIALS      3
00652 
00653 static short keymap_menu_type(short type)
00654 {
00655     if(ISKEYBOARD(type)) return OL_KM_KEYBOARD;
00656     if(ISTWEAK(type)) return OL_KM_TWEAK;
00657     if(ISMOUSE(type)) return OL_KM_MOUSE;
00658 //  return OL_KM_SPECIALS;
00659     return 0;
00660 }
00661 
00662 static const char *keymap_type_menu(void)
00663 {
00664     static const char string[]=
00665     "Event Type%t"
00666     "|Keyboard%x" STRINGIFY(OL_KM_KEYBOARD)
00667     "|Mouse%x" STRINGIFY(OL_KM_MOUSE)
00668     "|Tweak%x" STRINGIFY(OL_KM_TWEAK)
00669 //  "|Specials%x" STRINGIFY(OL_KM_SPECIALS)
00670     ;
00671 
00672     return string;
00673 }
00674 
00675 static const char *keymap_mouse_menu(void)
00676 {
00677     static const char string[]=
00678     "Mouse Event%t"
00679     "|Left Mouse%x" STRINGIFY(LEFTMOUSE)
00680     "|Middle Mouse%x" STRINGIFY(MIDDLEMOUSE)
00681     "|Right Mouse%x" STRINGIFY(RIGHTMOUSE)
00682     "|Middle Mouse%x" STRINGIFY(MIDDLEMOUSE)
00683     "|Right Mouse%x" STRINGIFY(RIGHTMOUSE)
00684     "|Button4 Mouse%x" STRINGIFY(BUTTON4MOUSE)
00685     "|Button5 Mouse%x" STRINGIFY(BUTTON5MOUSE)
00686     "|Action Mouse%x" STRINGIFY(ACTIONMOUSE)
00687     "|Select Mouse%x" STRINGIFY(SELECTMOUSE)
00688     "|Mouse Move%x" STRINGIFY(MOUSEMOVE)
00689     "|Wheel Up%x" STRINGIFY(WHEELUPMOUSE)
00690     "|Wheel Down%x" STRINGIFY(WHEELDOWNMOUSE)
00691     "|Wheel In%x" STRINGIFY(WHEELINMOUSE)
00692     "|Wheel Out%x" STRINGIFY(WHEELOUTMOUSE)
00693     "|Mouse/Trackpad Pan%x" STRINGIFY(MOUSEPAN)
00694     "|Mouse/Trackpad Zoom%x" STRINGIFY(MOUSEZOOM)
00695     "|Mouse/Trackpad Rotate%x" STRINGIFY(MOUSEROTATE)
00696     ;
00697 
00698     return string;
00699 }
00700 
00701 static const char *keymap_tweak_menu(void)
00702 {
00703     static const char string[]=
00704     "Tweak Event%t"
00705     "|Left Mouse%x" STRINGIFY(EVT_TWEAK_L)
00706     "|Middle Mouse%x" STRINGIFY(EVT_TWEAK_M)
00707     "|Right Mouse%x" STRINGIFY(EVT_TWEAK_R)
00708     "|Action Mouse%x" STRINGIFY(EVT_TWEAK_A)
00709     "|Select Mouse%x" STRINGIFY(EVT_TWEAK_S)
00710     ;
00711 
00712     return string;
00713 }
00714 
00715 static const char *keymap_tweak_dir_menu(void)
00716 {
00717     static const char string[]=
00718     "Tweak Direction%t"
00719     "|Any%x" STRINGIFY(KM_ANY)
00720     "|North%x" STRINGIFY(EVT_GESTURE_N)
00721     "|North-East%x" STRINGIFY(EVT_GESTURE_NE)
00722     "|East%x" STRINGIFY(EVT_GESTURE_E)
00723     "|Sout-East%x" STRINGIFY(EVT_GESTURE_SE)
00724     "|South%x" STRINGIFY(EVT_GESTURE_S)
00725     "|South-West%x" STRINGIFY(EVT_GESTURE_SW)
00726     "|West%x" STRINGIFY(EVT_GESTURE_W)
00727     "|North-West%x" STRINGIFY(EVT_GESTURE_NW)
00728     ;
00729 
00730     return string;
00731 }
00732 
00733 
00734 static void keymap_type_cb(bContext *C, void *kmi_v, void *UNUSED(arg_v))
00735 {
00736     wmKeyMapItem *kmi= kmi_v;
00737     short maptype= keymap_menu_type(kmi->type);
00738     
00739     if(maptype!=kmi->maptype) {
00740         switch(kmi->maptype) {
00741             case OL_KM_KEYBOARD:
00742                 kmi->type= AKEY;
00743                 kmi->val= KM_PRESS;
00744                 break;
00745             case OL_KM_MOUSE:
00746                 kmi->type= LEFTMOUSE;
00747                 kmi->val= KM_PRESS;
00748                 break;
00749             case OL_KM_TWEAK:
00750                 kmi->type= EVT_TWEAK_L;
00751                 kmi->val= KM_ANY;
00752                 break;
00753             case OL_KM_SPECIALS:
00754                 kmi->type= AKEY;
00755                 kmi->val= KM_PRESS;
00756         }
00757         ED_region_tag_redraw(CTX_wm_region(C));
00758     }
00759 }
00760 
00761 static void outliner_draw_keymapbuts(uiBlock *block, ARegion *ar, SpaceOops *soops, ListBase *lb)
00762 {
00763     TreeElement *te;
00764     TreeStoreElem *tselem;
00765     
00766     uiBlockSetEmboss(block, UI_EMBOSST);
00767     
00768     for(te= lb->first; te; te= te->next) {
00769         tselem= TREESTORE(te);
00770         if(te->ys+2*UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {
00771             uiBut *but;
00772             const char *str;
00773             int xstart= 240;
00774             int butw1= UI_UNIT_X; /* operator */
00775             int butw2= 90; /* event type, menus */
00776             int butw3= 43; /* modifiers */
00777 
00778             if(tselem->type == TSE_KEYMAP_ITEM) {
00779                 wmKeyMapItem *kmi= te->directdata;
00780                 
00781                 /* modal map? */
00782                 if(kmi->propvalue);
00783                 else {
00784                     uiDefBlockBut(block, operator_search_menu, kmi, "", xstart, (int)te->ys+1, butw1, UI_UNIT_Y-1, "Assign new Operator");
00785                 }
00786                 xstart+= butw1+10;
00787                 
00788                 /* map type button */
00789                 kmi->maptype= keymap_menu_type(kmi->type);
00790                 
00791                 str= keymap_type_menu();
00792                 but= uiDefButS(block, MENU, 0, str, xstart, (int)te->ys+1, butw2, UI_UNIT_Y-1, &kmi->maptype, 0, 0, 0, 0, "Event type");
00793                 uiButSetFunc(but, keymap_type_cb, kmi, NULL);
00794                 xstart+= butw2+5;
00795                 
00796                 /* edit actual event */
00797                 switch(kmi->maptype) {
00798                     case OL_KM_KEYBOARD:
00799                         uiDefKeyevtButS(block, 0, "", xstart, (int)te->ys+1, butw2, UI_UNIT_Y-1, &kmi->type, "Key code");
00800                         xstart+= butw2+5;
00801                         break;
00802                     case OL_KM_MOUSE:
00803                         str= keymap_mouse_menu();
00804                         uiDefButS(block, MENU, 0, str, xstart,(int)te->ys+1, butw2, UI_UNIT_Y-1, &kmi->type, 0, 0, 0, 0,  "Mouse button");  
00805                         xstart+= butw2+5;
00806                         break;
00807                     case OL_KM_TWEAK:
00808                         str= keymap_tweak_menu();
00809                         uiDefButS(block, MENU, 0, str, xstart, (int)te->ys+1, butw2, UI_UNIT_Y-1, &kmi->type, 0, 0, 0, 0,  "Tweak gesture");    
00810                         xstart+= butw2+5;
00811                         str= keymap_tweak_dir_menu();
00812                         uiDefButS(block, MENU, 0, str, xstart, (int)te->ys+1, butw2, UI_UNIT_Y-1, &kmi->val, 0, 0, 0, 0,  "Tweak gesture direction");   
00813                         xstart+= butw2+5;
00814                         break;
00815                 }
00816                 
00817                 /* modifiers */
00818                 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;
00819                 uiDefButS(block, OPTION, 0, "Ctrl", xstart, (int)te->ys+1, butw3, UI_UNIT_Y-1, &kmi->ctrl, 0, 0, 0, 0, "Modifier"); xstart+= butw3;
00820                 uiDefButS(block, OPTION, 0, "Alt",  xstart, (int)te->ys+1, butw3, UI_UNIT_Y-1, &kmi->alt, 0, 0, 0, 0, "Modifier"); xstart+= butw3;
00821                 uiDefButS(block, OPTION, 0, "OS",   xstart, (int)te->ys+1, butw3, UI_UNIT_Y-1, &kmi->oskey, 0, 0, 0, 0, "Modifier"); xstart+= butw3;
00822                 xstart+= 5;
00823                 uiDefKeyevtButS(block, 0, "", xstart, (int)te->ys+1, butw3, UI_UNIT_Y-1, &kmi->keymodifier, "Key Modifier code");
00824                 xstart+= butw3+5;
00825                 
00826                 /* rna property */
00827                 if(kmi->ptr && kmi->ptr->data) {
00828                     uiDefBut(block, LABEL, 0, "(RNA property)", xstart, (int)te->ys+1, butw2, UI_UNIT_Y-1, &kmi->oskey, 0, 0, 0, 0, ""); xstart+= butw2;
00829                 }
00830 
00831                 (void)xstart;
00832             }
00833         }
00834         
00835         if(TSELEM_OPEN(tselem,soops)) outliner_draw_keymapbuts(block, ar, soops, &te->subtree);
00836     }
00837 }
00838 
00839 
00840 static void outliner_buttons(const bContext *C, uiBlock *block, ARegion *ar, SpaceOops *soops, ListBase *lb)
00841 {
00842     uiBut *bt;
00843     TreeElement *te;
00844     TreeStoreElem *tselem;
00845     int spx, dx, len;
00846     
00847     for(te= lb->first; te; te= te->next) {
00848         tselem= TREESTORE(te);
00849         if(te->ys+2*UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {
00850             
00851             if(tselem->flag & TSE_TEXTBUT) {
00852                 
00853                 /* If we add support to rename Sequence.
00854                  * need change this.
00855                  */
00856                 if(tselem->type == TSE_POSE_BASE) continue; // prevent crash when trying to rename 'pose' entry of armature
00857                 
00858                 if(tselem->type==TSE_EBONE) len = sizeof(((EditBone*) 0)->name);
00859                 else if (tselem->type==TSE_MODIFIER) len = sizeof(((ModifierData*) 0)->name);
00860                 else if(tselem->id && GS(tselem->id->name)==ID_LI) len = sizeof(((Library*) 0)->name);
00861                 else len= MAX_ID_NAME-2;
00862                 
00863 
00864                 dx= (int)UI_GetStringWidth(te->name);
00865                 if(dx<100) dx= 100;
00866                 spx=te->xs+2*UI_UNIT_X-4;
00867                 if(spx+dx+10>ar->v2d.cur.xmax) dx = ar->v2d.cur.xmax-spx-10;
00868 
00869                 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, "");
00870                 uiButSetRenameFunc(bt, namebutton_cb, tselem);
00871                 
00872                 /* returns false if button got removed */
00873                 if( 0 == uiButActiveOnly(C, block, bt) )
00874                     tselem->flag &= ~TSE_TEXTBUT;
00875             }
00876         }
00877         
00878         if(TSELEM_OPEN(tselem,soops)) outliner_buttons(C, block, ar, soops, &te->subtree);
00879     }
00880 }
00881 
00882 /* ****************************************************** */
00883 /* Normal Drawing... */
00884 
00885 /* make function calls a bit compacter */
00886 struct DrawIconArg {
00887     uiBlock *block;
00888     ID *id;
00889     int xmax, x, y;
00890     float alpha;
00891 };
00892 
00893 static void tselem_draw_icon_uibut(struct DrawIconArg *arg, int icon)
00894 {
00895     /* restrict collumn clip... it has been coded by simply overdrawing, doesnt work for buttons */
00896     if(arg->x >= arg->xmax) {
00897         glEnable(GL_BLEND);
00898         UI_icon_draw_aspect(arg->x, arg->y, icon, 1.0f, arg->alpha);
00899         glDisable(GL_BLEND);
00900     } else {
00901         /* XXX investigate: button placement of icons is way different than UI_icon_draw? */
00902         float ufac= UI_UNIT_X/20.0f;
00903         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 : "");
00904         
00905         if(arg->id)
00906             uiButSetDragID(but, arg->id);
00907     }
00908 
00909 }
00910 
00911 static void tselem_draw_icon(uiBlock *block, int xmax, float x, float y, TreeStoreElem *tselem, TreeElement *te, float alpha)
00912 {
00913     struct DrawIconArg arg;
00914     
00915     /* make function calls a bit compacter */
00916     arg.block= block;
00917     arg.id= tselem->id;
00918     arg.xmax= xmax;
00919     arg.x= x;
00920     arg.y= y;
00921     arg.alpha= alpha;
00922     
00923     if(tselem->type) {
00924         switch( tselem->type) {
00925             case TSE_ANIM_DATA:
00926                 UI_icon_draw(x, y, ICON_ANIM_DATA); break; // xxx
00927             case TSE_NLA:
00928                 UI_icon_draw(x, y, ICON_NLA); break;
00929             case TSE_NLA_TRACK:
00930                 UI_icon_draw(x, y, ICON_NLA); break; // XXX
00931             case TSE_NLA_ACTION:
00932                 UI_icon_draw(x, y, ICON_ACTION); break;
00933             case TSE_DRIVER_BASE:
00934                 UI_icon_draw(x, y, ICON_DRIVER); break;
00935             case TSE_DEFGROUP_BASE:
00936                 UI_icon_draw(x, y, ICON_GROUP_VERTEX); break;
00937             case TSE_BONE:
00938             case TSE_EBONE:
00939                 UI_icon_draw(x, y, ICON_BONE_DATA); break;
00940             case TSE_CONSTRAINT_BASE:
00941                 UI_icon_draw(x, y, ICON_CONSTRAINT); break;
00942             case TSE_MODIFIER_BASE:
00943                 UI_icon_draw(x, y, ICON_MODIFIER); break;
00944             case TSE_LINKED_OB:
00945                 UI_icon_draw(x, y, ICON_OBJECT_DATA); break;
00946             case TSE_LINKED_PSYS:
00947                 UI_icon_draw(x, y, ICON_PARTICLES); break;
00948             case TSE_MODIFIER:
00949             {
00950                 Object *ob= (Object *)tselem->id;
00951                 ModifierData *md= BLI_findlink(&ob->modifiers, tselem->nr);
00952                 switch(md->type) {
00953                     case eModifierType_Subsurf: 
00954                         UI_icon_draw(x, y, ICON_MOD_SUBSURF); break;
00955                     case eModifierType_Armature: 
00956                         UI_icon_draw(x, y, ICON_MOD_ARMATURE); break;
00957                     case eModifierType_Lattice: 
00958                         UI_icon_draw(x, y, ICON_MOD_LATTICE); break;
00959                     case eModifierType_Curve: 
00960                         UI_icon_draw(x, y, ICON_MOD_CURVE); break;
00961                     case eModifierType_Build: 
00962                         UI_icon_draw(x, y, ICON_MOD_BUILD); break;
00963                     case eModifierType_Mirror: 
00964                         UI_icon_draw(x, y, ICON_MOD_MIRROR); break;
00965                     case eModifierType_Decimate: 
00966                         UI_icon_draw(x, y, ICON_MOD_DECIM); break;
00967                     case eModifierType_Wave: 
00968                         UI_icon_draw(x, y, ICON_MOD_WAVE); break;
00969                     case eModifierType_Hook: 
00970                         UI_icon_draw(x, y, ICON_HOOK); break;
00971                     case eModifierType_Softbody: 
00972                         UI_icon_draw(x, y, ICON_MOD_SOFT); break;
00973                     case eModifierType_Boolean: 
00974                         UI_icon_draw(x, y, ICON_MOD_BOOLEAN); break;
00975                     case eModifierType_ParticleSystem: 
00976                         UI_icon_draw(x, y, ICON_MOD_PARTICLES); break;
00977                     case eModifierType_ParticleInstance:
00978                         UI_icon_draw(x, y, ICON_MOD_PARTICLES); break;
00979                     case eModifierType_EdgeSplit:
00980                         UI_icon_draw(x, y, ICON_MOD_EDGESPLIT); break;
00981                     case eModifierType_Array:
00982                         UI_icon_draw(x, y, ICON_MOD_ARRAY); break;
00983                     case eModifierType_UVProject:
00984                         UI_icon_draw(x, y, ICON_MOD_UVPROJECT); break;
00985                     case eModifierType_Displace:
00986                         UI_icon_draw(x, y, ICON_MOD_DISPLACE); break;
00987                     case eModifierType_Shrinkwrap:
00988                         UI_icon_draw(x, y, ICON_MOD_SHRINKWRAP); break;
00989                     case eModifierType_Cast:
00990                         UI_icon_draw(x, y, ICON_MOD_CAST); break;
00991                     case eModifierType_MeshDeform:
00992                         UI_icon_draw(x, y, ICON_MOD_MESHDEFORM); break;
00993                     case eModifierType_Bevel:
00994                         UI_icon_draw(x, y, ICON_MOD_BEVEL); break;
00995                     case eModifierType_Smooth:
00996                         UI_icon_draw(x, y, ICON_MOD_SMOOTH); break;
00997                     case eModifierType_SimpleDeform:
00998                         UI_icon_draw(x, y, ICON_MOD_SIMPLEDEFORM); break;
00999                     case eModifierType_Mask:
01000                         UI_icon_draw(x, y, ICON_MOD_MASK); break;
01001                     case eModifierType_Cloth:
01002                         UI_icon_draw(x, y, ICON_MOD_CLOTH); break;
01003                     case eModifierType_Explode:
01004                         UI_icon_draw(x, y, ICON_MOD_EXPLODE); break;
01005                     case eModifierType_Collision:
01006                         UI_icon_draw(x, y, ICON_MOD_PHYSICS); break;
01007                     case eModifierType_Fluidsim:
01008                         UI_icon_draw(x, y, ICON_MOD_FLUIDSIM); break;
01009                     case eModifierType_Multires:
01010                         UI_icon_draw(x, y, ICON_MOD_MULTIRES); break;
01011                     case eModifierType_Smoke:
01012                         UI_icon_draw(x, y, ICON_MOD_SMOKE); break;
01013                     case eModifierType_Solidify:
01014                         UI_icon_draw(x, y, ICON_MOD_SOLIDIFY); break;
01015                     case eModifierType_Screw:
01016                         UI_icon_draw(x, y, ICON_MOD_SCREW); break;
01017                     case eModifierType_Remesh:
01018                         UI_icon_draw(x, y, ICON_MOD_REMESH); break;
01019                     case eModifierType_WeightVGEdit:
01020                     case eModifierType_WeightVGMix:
01021                     case eModifierType_WeightVGProximity:
01022                         UI_icon_draw(x, y, ICON_MOD_VERTEX_WEIGHT); break;
01023                     case eModifierType_DynamicPaint:
01024                         UI_icon_draw(x, y, ICON_MOD_DYNAMICPAINT); break;
01025                     default:
01026                         UI_icon_draw(x, y, ICON_DOT); break;
01027                 }
01028                 break;
01029             }
01030             case TSE_SCRIPT_BASE:
01031                 UI_icon_draw(x, y, ICON_TEXT); break;
01032             case TSE_POSE_BASE:
01033                 UI_icon_draw(x, y, ICON_ARMATURE_DATA); break;
01034             case TSE_POSE_CHANNEL:
01035                 UI_icon_draw(x, y, ICON_BONE_DATA); break;
01036             case TSE_PROXY:
01037                 UI_icon_draw(x, y, ICON_GHOST); break;
01038             case TSE_R_LAYER_BASE:
01039                 UI_icon_draw(x, y, ICON_RENDERLAYERS); break;
01040             case TSE_R_LAYER:
01041                 UI_icon_draw(x, y, ICON_RENDERLAYERS); break;
01042             case TSE_LINKED_LAMP:
01043                 UI_icon_draw(x, y, ICON_LAMP_DATA); break;
01044             case TSE_LINKED_MAT:
01045                 UI_icon_draw(x, y, ICON_MATERIAL_DATA); break;
01046             case TSE_POSEGRP_BASE:
01047                 UI_icon_draw(x, y, ICON_VERTEXSEL); break;
01048             case TSE_SEQUENCE:
01049                 if(te->idcode==SEQ_MOVIE)
01050                     UI_icon_draw(x, y, ICON_SEQUENCE);
01051                 else if(te->idcode==SEQ_META)
01052                     UI_icon_draw(x, y, ICON_DOT);
01053                 else if(te->idcode==SEQ_SCENE)
01054                     UI_icon_draw(x, y, ICON_SCENE);
01055                 else if(te->idcode==SEQ_SOUND)
01056                     UI_icon_draw(x, y, ICON_SOUND);
01057                 else if(te->idcode==SEQ_IMAGE)
01058                     UI_icon_draw(x, y, ICON_IMAGE_COL);
01059                 else
01060                     UI_icon_draw(x, y, ICON_PARTICLES);
01061                 break;
01062             case TSE_SEQ_STRIP:
01063                 UI_icon_draw(x, y, ICON_LIBRARY_DATA_DIRECT);
01064                 break;
01065             case TSE_SEQUENCE_DUP:
01066                 UI_icon_draw(x, y, ICON_OBJECT_DATA);
01067                 break;
01068             case TSE_RNA_STRUCT:
01069                 if(RNA_struct_is_ID(te->rnaptr.type)) {
01070                     arg.id= (ID *)te->rnaptr.data;
01071                     tselem_draw_icon_uibut(&arg, RNA_struct_ui_icon(te->rnaptr.type));
01072                 }
01073                 else
01074                     UI_icon_draw(x, y, RNA_struct_ui_icon(te->rnaptr.type));
01075                 break;
01076             default:
01077                 UI_icon_draw(x, y, ICON_DOT); break;
01078         }
01079     }
01080     else if (GS(tselem->id->name) == ID_OB) {
01081         Object *ob= (Object *)tselem->id;
01082         switch (ob->type) {
01083             case OB_LAMP:
01084                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_LAMP); break;
01085             case OB_MESH: 
01086                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_MESH); break;
01087             case OB_CAMERA: 
01088                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_CAMERA); break;
01089             case OB_CURVE: 
01090                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_CURVE); break;
01091             case OB_MBALL: 
01092                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_META); break;
01093             case OB_LATTICE: 
01094                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_LATTICE); break;
01095             case OB_ARMATURE: 
01096                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_ARMATURE); break;
01097             case OB_FONT: 
01098                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_FONT); break;
01099             case OB_SURF: 
01100                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_SURFACE); break;
01101             case OB_SPEAKER:
01102                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_SPEAKER); break;
01103             case OB_EMPTY: 
01104                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_OB_EMPTY); break;
01105         
01106         }
01107     }
01108     else {
01109         switch( GS(tselem->id->name)) {
01110             case ID_SCE:
01111                 tselem_draw_icon_uibut(&arg, ICON_SCENE_DATA); break;
01112             case ID_ME:
01113                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_MESH); break;
01114             case ID_CU:
01115                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_CURVE); break;
01116             case ID_MB:
01117                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_META); break;
01118             case ID_LT:
01119                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_LATTICE); break;
01120             case ID_LA:
01121             {
01122                 Lamp *la= (Lamp *)tselem->id;
01123                 
01124                 switch(la->type) {
01125                     case LA_LOCAL:
01126                         tselem_draw_icon_uibut(&arg, ICON_LAMP_POINT); break;
01127                     case LA_SUN:
01128                         tselem_draw_icon_uibut(&arg, ICON_LAMP_SUN); break;
01129                     case LA_SPOT:
01130                         tselem_draw_icon_uibut(&arg, ICON_LAMP_SPOT); break;
01131                     case LA_HEMI:
01132                         tselem_draw_icon_uibut(&arg, ICON_LAMP_HEMI); break;
01133                     case LA_AREA:
01134                         tselem_draw_icon_uibut(&arg, ICON_LAMP_AREA); break;
01135                     default:
01136                         tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_LAMP); break;
01137                 }
01138                 break;
01139             }
01140             case ID_MA:
01141                 tselem_draw_icon_uibut(&arg, ICON_MATERIAL_DATA); break;
01142             case ID_TE:
01143                 tselem_draw_icon_uibut(&arg, ICON_TEXTURE_DATA); break;
01144             case ID_IM:
01145                 tselem_draw_icon_uibut(&arg, ICON_IMAGE_DATA); break;
01146             case ID_SPK:
01147             case ID_SO:
01148                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_SPEAKER); break;
01149             case ID_AR:
01150                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_ARMATURE); break;
01151             case ID_CA:
01152                 tselem_draw_icon_uibut(&arg, ICON_OUTLINER_DATA_CAMERA); break;
01153             case ID_KE:
01154                 tselem_draw_icon_uibut(&arg, ICON_SHAPEKEY_DATA); break;
01155             case ID_WO:
01156                 tselem_draw_icon_uibut(&arg, ICON_WORLD_DATA); break;
01157             case ID_AC:
01158                 tselem_draw_icon_uibut(&arg, ICON_ACTION); break;
01159             case ID_NLA:
01160                 tselem_draw_icon_uibut(&arg, ICON_NLA); break;
01161             case ID_TXT:
01162                 tselem_draw_icon_uibut(&arg, ICON_SCRIPT); break;
01163             case ID_GR:
01164                 tselem_draw_icon_uibut(&arg, ICON_GROUP); break;
01165             case ID_LI:
01166                 tselem_draw_icon_uibut(&arg, ICON_LIBRARY_DATA_DIRECT); break;
01167         }
01168     }
01169 }
01170 
01171 static void outliner_draw_iconrow(bContext *C, uiBlock *block, Scene *scene, SpaceOops *soops, ListBase *lb, int level, int xmax, int *offsx, int ys)
01172 {
01173     TreeElement *te;
01174     TreeStoreElem *tselem;
01175     int active;
01176 
01177     for(te= lb->first; te; te= te->next) {
01178         
01179         /* exit drawing early */
01180         if((*offsx) - UI_UNIT_X > xmax)
01181             break;
01182 
01183         tselem= TREESTORE(te);
01184         
01185         /* object hierarchy always, further constrained on level */
01186         if(level<1 || (tselem->type==0 && te->idcode==ID_OB)) {
01187 
01188             /* active blocks get white circle */
01189             if(tselem->type==0) {
01190                 if(te->idcode==ID_OB) active= (OBACT==(Object *)tselem->id);
01191                 else if(scene->obedit && scene->obedit->data==tselem->id) active= 1;    // XXX use context?
01192                 else active= tree_element_active(C, scene, soops, te, 0);
01193             }
01194             else active= tree_element_type_active(NULL, scene, soops, te, tselem, 0);
01195             
01196             if(active) {
01197                 float ufac= UI_UNIT_X/20.0f;
01198 
01199                 uiSetRoundBox(UI_CNR_ALL);
01200                 glColor4ub(255, 255, 255, 100);
01201                 uiRoundBox( (float)*offsx-0.5f*ufac, (float)ys-1.0f*ufac, (float)*offsx+UI_UNIT_Y-3.0f*ufac, (float)ys+UI_UNIT_Y-3.0f*ufac, UI_UNIT_Y/2.0f-2.0f*ufac);
01202                 glEnable(GL_BLEND); /* roundbox disables */
01203             }
01204             
01205             tselem_draw_icon(block, xmax, (float)*offsx, (float)ys, tselem, te, 0.5f);
01206             te->xs= (float)*offsx;
01207             te->ys= (float)ys;
01208             te->xend= (short)*offsx+UI_UNIT_X;
01209             te->flag |= TE_ICONROW; // for click
01210             
01211             (*offsx) += UI_UNIT_X;
01212         }
01213         
01214         /* this tree element always has same amount of branches, so dont draw */
01215         if(tselem->type!=TSE_R_LAYER)
01216             outliner_draw_iconrow(C, block, scene, soops, &te->subtree, level+1, xmax, offsx, ys);
01217     }
01218     
01219 }
01220 
01221 /* closed tree element */
01222 static void outliner_set_coord_tree_element(SpaceOops *soops, TreeElement *te, int startx, int *starty)
01223 {
01224     TreeElement *ten;
01225     
01226     /* store coord and continue, we need coordinates for elements outside view too */
01227     te->xs= (float)startx;
01228     te->ys= (float)(*starty);
01229     
01230     for(ten= te->subtree.first; ten; ten= ten->next) {
01231         outliner_set_coord_tree_element(soops, ten, startx+UI_UNIT_X, starty);
01232     }   
01233 }
01234 
01235 
01236 static void outliner_draw_tree_element(bContext *C, uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, int startx, int *starty)
01237 {
01238     TreeElement *ten;
01239     TreeStoreElem *tselem;
01240     float ufac= UI_UNIT_X/20.0f;
01241     int offsx= 0, active=0; // active=1 active obj, else active data
01242     
01243     tselem= TREESTORE(te);
01244 
01245     if(*starty+2*UI_UNIT_Y >= ar->v2d.cur.ymin && *starty<= ar->v2d.cur.ymax) {
01246         int xmax= ar->v2d.cur.xmax;
01247         
01248         /* icons can be ui buts, we dont want it to overlap with restrict */
01249         if((soops->flag & SO_HIDE_RESTRICTCOLS)==0)
01250             xmax-= OL_TOGW+UI_UNIT_X;
01251         
01252         glEnable(GL_BLEND);
01253 
01254         /* start by highlighting search matches 
01255          *  we don't expand items when searching in the datablocks but we 
01256          *  still want to highlight any filter matches. 
01257          */
01258         if ( (SEARCHING_OUTLINER(soops) || (soops->outlinevis==SO_DATABLOCKS && soops->search_string[0]!=0)) && 
01259              (tselem->flag & TSE_SEARCHMATCH)) 
01260         {
01261             /* TODO - add search highlight color to theme? */
01262             glColor4f(0.2f, 0.5f, 0.2f, 0.3f);
01263             glRecti(startx, *starty+1, ar->v2d.cur.xmax, *starty+UI_UNIT_Y-1);
01264         }
01265 
01266         /* colors for active/selected data */
01267         if(tselem->type==0) {
01268             if(te->idcode==ID_SCE) {
01269                 if(tselem->id == (ID *)scene) {
01270                     glColor4ub(255, 255, 255, 100);
01271                     active= 2;
01272                 }
01273             }
01274             else if(te->idcode==ID_GR) {
01275                 Group *gr = (Group *)tselem->id;
01276                 
01277                 if(group_select_flag(gr)) {
01278                     char col[4];
01279                     UI_GetThemeColorType4ubv(TH_SELECT, SPACE_VIEW3D, col);
01280                     col[3]= 100;
01281                     glColor4ubv((GLubyte *)col);
01282                     
01283                     active= 2;
01284                 }
01285             }
01286             else if(te->idcode==ID_OB) {
01287                 Object *ob= (Object *)tselem->id;
01288                 
01289                 if(ob==OBACT || (ob->flag & SELECT)) {
01290                     char col[4]= {0, 0, 0, 0};
01291                     
01292                     /* outliner active ob: always white text, circle color now similar to view3d */
01293                     
01294                     active= 2; /* means it draws a color circle */
01295                     if(ob==OBACT) {
01296                         if(ob->flag & SELECT) {
01297                             UI_GetThemeColorType4ubv(TH_ACTIVE, SPACE_VIEW3D, col);
01298                             col[3]= 100;
01299                         }
01300                         
01301                         active= 1; /* means it draws white text */
01302                     }
01303                     else if(ob->flag & SELECT) {
01304                         UI_GetThemeColorType4ubv(TH_SELECT, SPACE_VIEW3D, col);
01305                         col[3]= 100;
01306                     }
01307                     
01308                     glColor4ubv((GLubyte *)col);
01309                 }
01310             
01311             }
01312             else if(scene->obedit && scene->obedit->data==tselem->id) {
01313                 glColor4ub(255, 255, 255, 100);
01314                 active= 2;
01315             }
01316             else {
01317                 if(tree_element_active(C, scene, soops, te, 0)) {
01318                     glColor4ub(220, 220, 255, 100);
01319                     active= 2;
01320                 }
01321             }
01322         }
01323         else {
01324             if( tree_element_type_active(NULL, scene, soops, te, tselem, 0) ) active= 2;
01325             glColor4ub(220, 220, 255, 100);
01326         }
01327         
01328         /* active circle */
01329         if(active) {
01330             uiSetRoundBox(UI_CNR_ALL);
01331             uiRoundBox( (float)startx+UI_UNIT_Y-1.5f*ufac, (float)*starty+2.0f*ufac, (float)startx+2.0f*UI_UNIT_Y-4.0f*ufac, (float)*starty+UI_UNIT_Y-1.0f*ufac, UI_UNIT_Y/2.0f-2.0f*ufac);
01332             glEnable(GL_BLEND); /* roundbox disables it */
01333             
01334             te->flag |= TE_ACTIVE; // for lookup in display hierarchies
01335         }
01336         
01337         /* open/close icon, only when sublevels, except for scene */
01338         if(te->subtree.first || (tselem->type==0 && te->idcode==ID_SCE) || (te->flag & TE_LAZY_CLOSED)) {
01339             int icon_x;
01340             if(tselem->type==0 && ELEM(te->idcode, ID_OB, ID_SCE))
01341                 icon_x = startx;
01342             else
01343                 icon_x = startx+5*ufac;
01344             
01345                 // icons a bit higher
01346             if(TSELEM_OPEN(tselem,soops)) 
01347                 UI_icon_draw((float)icon_x, (float)*starty+2*ufac, ICON_DISCLOSURE_TRI_DOWN);
01348             else
01349                 UI_icon_draw((float)icon_x, (float)*starty+2*ufac, ICON_DISCLOSURE_TRI_RIGHT);
01350         }
01351         offsx+= UI_UNIT_X;
01352         
01353         /* datatype icon */
01354         
01355         if(!(ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM))) {
01356             // icons a bit higher
01357             tselem_draw_icon(block, xmax, (float)startx+offsx - 0.5f*ufac, (float)*starty+2.0f*ufac, tselem, te, 1.0f);
01358             
01359             offsx+= UI_UNIT_X;
01360         }
01361         else
01362             offsx+= 2*ufac;
01363         
01364         if(tselem->type==0 && tselem->id->lib) {
01365             glPixelTransferf(GL_ALPHA_SCALE, 0.5f);
01366             if(tselem->id->flag & LIB_INDIRECT)
01367                 UI_icon_draw((float)startx+offsx, (float)*starty+2*ufac, ICON_LIBRARY_DATA_INDIRECT);
01368             else
01369                 UI_icon_draw((float)startx+offsx, (float)*starty+2*ufac, ICON_LIBRARY_DATA_DIRECT);
01370             glPixelTransferf(GL_ALPHA_SCALE, 1.0f);
01371             offsx+= UI_UNIT_X;
01372         }       
01373         glDisable(GL_BLEND);
01374         
01375         /* name */
01376         if(active==1) UI_ThemeColor(TH_TEXT_HI);
01377         else if(ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) UI_ThemeColorBlend(TH_BACK, TH_TEXT, 0.75f);
01378         else UI_ThemeColor(TH_TEXT);
01379         
01380         UI_DrawString(startx+offsx, *starty+5*ufac, te->name);
01381         
01382         offsx+= (int)(UI_UNIT_X + UI_GetStringWidth(te->name));
01383         
01384         /* closed item, we draw the icons, not when it's a scene, or master-server list though */
01385         if(!TSELEM_OPEN(tselem,soops)) {
01386             if(te->subtree.first) {
01387                 if(tselem->type==0 && te->idcode==ID_SCE);
01388                 else if(tselem->type!=TSE_R_LAYER) { /* this tree element always has same amount of branches, so dont draw */
01389                     int tempx= startx+offsx;
01390                     
01391                     // divider
01392                     UI_ThemeColorShade(TH_BACK, -40);
01393                     glRecti(tempx -10, *starty+4, tempx -8, *starty+UI_UNIT_Y-4);
01394                     
01395                     glEnable(GL_BLEND);
01396                     glPixelTransferf(GL_ALPHA_SCALE, 0.5);
01397                     
01398                     outliner_draw_iconrow(C, block, scene, soops, &te->subtree, 0, xmax, &tempx, *starty+2);
01399                     
01400                     glPixelTransferf(GL_ALPHA_SCALE, 1.0);
01401                     glDisable(GL_BLEND);
01402                 }
01403             }
01404         }
01405     }   
01406     /* store coord and continue, we need coordinates for elements outside view too */
01407     te->xs= (float)startx;
01408     te->ys= (float)*starty;
01409     te->xend= startx+offsx;
01410         
01411     if(TSELEM_OPEN(tselem,soops)) {
01412         *starty-= UI_UNIT_Y;
01413         
01414         for(ten= te->subtree.first; ten; ten= ten->next)
01415             outliner_draw_tree_element(C, block, scene, ar, soops, ten, startx+UI_UNIT_X, starty);
01416     }   
01417     else {
01418         for(ten= te->subtree.first; ten; ten= ten->next)
01419             outliner_set_coord_tree_element(soops, te, startx, starty);
01420         
01421         *starty-= UI_UNIT_Y;
01422     }
01423 }
01424 
01425 static void outliner_draw_hierarchy(SpaceOops *soops, ListBase *lb, int startx, int *starty)
01426 {
01427     TreeElement *te;
01428     TreeStoreElem *tselem;
01429     int y1, y2;
01430     
01431     if(lb->first==NULL) return;
01432     
01433     y1=y2= *starty; /* for vertical lines between objects */
01434     for(te=lb->first; te; te= te->next) {
01435         y2= *starty;
01436         tselem= TREESTORE(te);
01437         
01438         /* horizontal line? */
01439         if(tselem->type==0 && (te->idcode==ID_OB || te->idcode==ID_SCE))
01440             glRecti(startx, *starty, startx+UI_UNIT_X, *starty-1);
01441             
01442         *starty-= UI_UNIT_Y;
01443         
01444         if(TSELEM_OPEN(tselem,soops))
01445             outliner_draw_hierarchy(soops, &te->subtree, startx+UI_UNIT_X, starty);
01446     }
01447     
01448     /* vertical line */
01449     te= lb->last;
01450     if(te->parent || lb->first!=lb->last) {
01451         tselem= TREESTORE(te);
01452         if(tselem->type==0 && te->idcode==ID_OB) {
01453             
01454             glRecti(startx, y1+UI_UNIT_Y, startx+1, y2);
01455         }
01456     }
01457 }
01458 
01459 static void outliner_draw_struct_marks(ARegion *ar, SpaceOops *soops, ListBase *lb, int *starty) 
01460 {
01461     TreeElement *te;
01462     TreeStoreElem *tselem;
01463     
01464     for(te= lb->first; te; te= te->next) {
01465         tselem= TREESTORE(te);
01466         
01467         /* selection status */
01468         if(TSELEM_OPEN(tselem,soops))
01469             if(tselem->type == TSE_RNA_STRUCT)
01470                 glRecti(0, *starty+1, (int)ar->v2d.cur.xmax+V2D_SCROLL_WIDTH, *starty+UI_UNIT_Y-1);
01471 
01472         *starty-= UI_UNIT_Y;
01473         if(TSELEM_OPEN(tselem,soops)) {
01474             outliner_draw_struct_marks(ar, soops, &te->subtree, starty);
01475             if(tselem->type == TSE_RNA_STRUCT)
01476                 fdrawline(0, (float)*starty+UI_UNIT_Y, ar->v2d.cur.xmax+V2D_SCROLL_WIDTH, (float)*starty+UI_UNIT_Y);
01477         }
01478     }
01479 }
01480 
01481 static void outliner_draw_selection(ARegion *ar, SpaceOops *soops, ListBase *lb, int *starty) 
01482 {
01483     TreeElement *te;
01484     TreeStoreElem *tselem;
01485     
01486     for(te= lb->first; te; te= te->next) {
01487         tselem= TREESTORE(te);
01488         
01489         /* selection status */
01490         if(tselem->flag & TSE_SELECTED) {
01491             glRecti(0, *starty+1, (int)ar->v2d.cur.xmax, *starty+UI_UNIT_Y-1);
01492         }
01493         *starty-= UI_UNIT_Y;
01494         if(TSELEM_OPEN(tselem,soops)) outliner_draw_selection(ar, soops, &te->subtree, starty);
01495     }
01496 }
01497 
01498 
01499 static void outliner_draw_tree(bContext *C, uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops)
01500 {
01501     TreeElement *te;
01502     int starty, startx;
01503     float col[4];
01504         
01505     glBlendFunc(GL_SRC_ALPHA,  GL_ONE_MINUS_SRC_ALPHA); // only once
01506     
01507     if (ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF)) {
01508         /* struct marks */
01509         UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
01510         //UI_ThemeColorShade(TH_BACK, -20);
01511         starty= (int)ar->v2d.tot.ymax-UI_UNIT_Y-OL_Y_OFFSET;
01512         outliner_draw_struct_marks(ar, soops, &soops->tree, &starty);
01513     }
01514     
01515     /* always draw selection fill before hierarchy */
01516     UI_GetThemeColor3fv(TH_BACK, col);
01517     glColor3f(col[0]+0.06f, col[1]+0.08f, col[2]+0.10f);
01518     starty= (int)ar->v2d.tot.ymax-UI_UNIT_Y-OL_Y_OFFSET;
01519     outliner_draw_selection(ar, soops, &soops->tree, &starty);
01520     
01521     // grey hierarchy lines
01522     UI_ThemeColorBlend(TH_BACK, TH_TEXT, 0.4f);
01523     starty= (int)ar->v2d.tot.ymax-UI_UNIT_Y/2-OL_Y_OFFSET;
01524     startx= 6;
01525     outliner_draw_hierarchy(soops, &soops->tree, startx, &starty);
01526     
01527     // items themselves
01528     starty= (int)ar->v2d.tot.ymax-UI_UNIT_Y-OL_Y_OFFSET;
01529     startx= 0;
01530     for(te= soops->tree.first; te; te= te->next) {
01531         outliner_draw_tree_element(C, block, scene, ar, soops, te, startx, &starty);
01532     }
01533 }
01534 
01535 
01536 static void outliner_back(ARegion *ar)
01537 {
01538     int ystart;
01539     
01540     UI_ThemeColorShade(TH_BACK, 6);
01541     ystart= (int)ar->v2d.tot.ymax;
01542     ystart= UI_UNIT_Y*(ystart/(UI_UNIT_Y))-OL_Y_OFFSET;
01543     
01544     while(ystart+2*UI_UNIT_Y > ar->v2d.cur.ymin) {
01545         glRecti(0, ystart, (int)ar->v2d.cur.xmax+V2D_SCROLL_WIDTH, ystart+UI_UNIT_Y);
01546         ystart-= 2*UI_UNIT_Y;
01547     }
01548 }
01549 
01550 static void outliner_draw_restrictcols(ARegion *ar)
01551 {
01552     int ystart;
01553     
01554     /* background underneath */
01555     UI_ThemeColor(TH_BACK);
01556     glRecti((int)ar->v2d.cur.xmax-OL_TOGW, (int)ar->v2d.cur.ymin-V2D_SCROLL_HEIGHT-1, (int)ar->v2d.cur.xmax+V2D_SCROLL_WIDTH, (int)ar->v2d.cur.ymax);
01557     
01558     UI_ThemeColorShade(TH_BACK, 6);
01559     ystart= (int)ar->v2d.tot.ymax;
01560     ystart= UI_UNIT_Y*(ystart/(UI_UNIT_Y))-OL_Y_OFFSET;
01561     
01562     while(ystart+2*UI_UNIT_Y > ar->v2d.cur.ymin) {
01563         glRecti((int)ar->v2d.cur.xmax-OL_TOGW, ystart, (int)ar->v2d.cur.xmax, ystart+UI_UNIT_Y);
01564         ystart-= 2*UI_UNIT_Y;
01565     }
01566     
01567     UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
01568 
01569     /* view */
01570     fdrawline(ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX,
01571         ar->v2d.cur.ymax,
01572         ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX,
01573         ar->v2d.cur.ymin - V2D_SCROLL_HEIGHT);
01574 
01575     /* render */
01576     fdrawline(ar->v2d.cur.xmax-OL_TOG_RESTRICT_SELECTX,
01577         ar->v2d.cur.ymax,
01578         ar->v2d.cur.xmax-OL_TOG_RESTRICT_SELECTX,
01579         ar->v2d.cur.ymin - V2D_SCROLL_HEIGHT);
01580 
01581     /* render */
01582     fdrawline(ar->v2d.cur.xmax-OL_TOG_RESTRICT_RENDERX,
01583         ar->v2d.cur.ymax,
01584         ar->v2d.cur.xmax-OL_TOG_RESTRICT_RENDERX,
01585         ar->v2d.cur.ymin - V2D_SCROLL_HEIGHT);
01586 }
01587 
01588 /* ****************************************************** */
01589 /* Main Entrypoint - Draw contents of Outliner editor */
01590  
01591 void draw_outliner(const bContext *C)
01592 {
01593     Main *mainvar= CTX_data_main(C);
01594     Scene *scene= CTX_data_scene(C);
01595     ARegion *ar= CTX_wm_region(C);
01596     View2D *v2d= &ar->v2d;
01597     SpaceOops *soops= CTX_wm_space_outliner(C);
01598     uiBlock *block;
01599     int sizey= 0, sizex= 0, sizex_rna= 0;
01600     
01601     outliner_build_tree(mainvar, scene, soops); // always 
01602     
01603     /* get extents of data */
01604     outliner_height(soops, &soops->tree, &sizey);
01605 
01606     if (ELEM3(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF, SO_KEYMAP)) {
01607         /* RNA has two columns:
01608          *  - column 1 is (max_width + OL_RNA_COL_SPACEX) or
01609          *               (OL_RNA_COL_X), whichever is wider...
01610          *  - column 2 is fixed at OL_RNA_COL_SIZEX
01611          *
01612          *  (*) XXX max width for now is a fixed factor of UI_UNIT_X*(max_indention+100)
01613          */
01614          
01615         /* get actual width of column 1 */
01616         outliner_rna_width(soops, &soops->tree, &sizex_rna, 0);
01617         sizex_rna= MAX2(OL_RNA_COLX, sizex_rna+OL_RNA_COL_SPACEX);
01618         
01619         /* get width of data (for setting 'tot' rect, this is column 1 + column 2 + a bit extra) */
01620         if (soops->outlinevis == SO_KEYMAP) 
01621             sizex= sizex_rna + OL_RNA_COL_SIZEX*3 + 50; // XXX this is only really a quick hack to make this wide enough...
01622         else
01623             sizex= sizex_rna + OL_RNA_COL_SIZEX + 50;
01624     }
01625     else {
01626         /* width must take into account restriction columns (if visible) so that entries will still be visible */
01627         //outliner_width(soops, &soops->tree, &sizex);
01628         outliner_rna_width(soops, &soops->tree, &sizex, 0); // XXX should use outliner_width instead when te->xend will be set correctly...
01629         
01630         /* constant offset for restriction columns */
01631         // XXX this isn't that great yet...
01632         if ((soops->flag & SO_HIDE_RESTRICTCOLS)==0)
01633             sizex += OL_TOGW*3;
01634     }
01635     
01636     /* tweak to display last line (when list bigger than window) */
01637     sizey += V2D_SCROLL_HEIGHT;
01638     
01639     /* adds vertical offset */
01640     sizey += OL_Y_OFFSET;
01641 
01642     /* update size of tot-rect (extents of data/viewable area) */
01643     UI_view2d_totRect_set(v2d, sizex, sizey);
01644 
01645     /* force display to pixel coords */
01646     v2d->flag |= (V2D_PIXELOFS_X|V2D_PIXELOFS_Y);
01647     /* set matrix for 2d-view controls */
01648     UI_view2d_view_ortho(v2d);
01649 
01650     /* draw outliner stuff (background, hierachy lines and names) */
01651     outliner_back(ar);
01652     block= uiBeginBlock(C, ar, __func__, UI_EMBOSS);
01653     outliner_draw_tree((bContext *)C, block, scene, ar, soops);
01654     
01655     if(ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF)) {
01656         /* draw rna buttons */
01657         outliner_draw_rnacols(ar, sizex_rna);
01658         outliner_draw_rnabuts(block, scene, ar, soops, sizex_rna, &soops->tree);
01659     }
01660     else if(soops->outlinevis == SO_KEYMAP) {
01661         outliner_draw_keymapbuts(block, ar, soops, &soops->tree);
01662     }
01663     else if (!(soops->flag & SO_HIDE_RESTRICTCOLS)) {
01664         /* draw restriction columns */
01665         outliner_draw_restrictcols(ar);
01666         outliner_draw_restrictbuts(block, scene, ar, soops, &soops->tree);
01667     }
01668 
01669     /* draw edit buttons if nessecery */
01670     outliner_buttons(C, block, ar, soops, &soops->tree);    
01671 
01672     uiEndBlock(C, block);
01673     uiDrawBlock(C, block);
01674     
01675     /* clear flag that allows quick redraws */
01676     soops->storeflag &= ~SO_TREESTORE_REDRAW;
01677 }