Tuesday merger of bf-blender into orange branch.
[blender-staging.git] / source / blender / src / drawview.c
index 517071c349c6088ba8b7bc4f2dea971154bba3e1..58b6e759aeeb19f34da1e84a8d7a2b72a7f638fd 100644 (file)
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 #include "BIF_interface.h"
+#include "BIF_interface_icons.h"
 #include "BIF_mywindow.h"
 #include "BIF_poseobject.h"
 #include "BIF_resources.h"
 #include "BSE_view.h"
 
 #include "RE_renderconverter.h"
-
 #include "BPY_extern.h"
 
 #include "blendef.h"
@@ -343,7 +343,6 @@ static void draw_bgpic(void)
                init_render_texture(bgpic->tex);
                free_unused_animimages();
                ima= bgpic->tex->ima;
-               end_render_texture(bgpic->tex);
        }
        else {
                ima= bgpic->ima;
@@ -436,7 +435,7 @@ static void draw_bgpic(void)
        
        glaDefine2DArea(&curarea->winrct);
        glPixelZoom(zoomx, zoomy);
-       glaDrawPixelsSafe(x1, y1, ima->ibuf->x, ima->ibuf->y, bgpic->rect);
+       glaDrawPixelsSafe(x1, y1, ima->ibuf->x, ima->ibuf->y, GL_UNSIGNED_BYTE, bgpic->rect);
        glPixelZoom(1.0, 1.0);
 
        glMatrixMode(GL_PROJECTION);
@@ -867,7 +866,8 @@ static void view3d_get_viewborder_size(View3D *v3d, float size_r[2])
 void calc_viewborder(struct View3D *v3d, rcti *viewborder_r)
 {
        float zoomfac, size[2];
-
+       float dx= 0.0f, dy= 0.0f;
+       
        view3d_get_viewborder_size(v3d, size);
 
                /* magic zoom calculation, no idea what
@@ -889,6 +889,15 @@ void calc_viewborder(struct View3D *v3d, rcti *viewborder_r)
        viewborder_r->ymin= 0.5*v3d->area->winy - 0.5*size[1];
        viewborder_r->xmax= viewborder_r->xmin + size[0];
        viewborder_r->ymax= viewborder_r->ymin + size[1];
+       
+       dx= v3d->area->winx*G.vd->camdx;
+       dy= v3d->area->winy*G.vd->camdy;
+       
+       /* apply offset */
+       viewborder_r->xmin-= dx;
+       viewborder_r->ymin-= dy;
+       viewborder_r->xmax-= dx;
+       viewborder_r->ymax-= dy;
 }
 
 void view3d_set_1_to_1_viewborder(View3D *v3d)
@@ -928,14 +937,15 @@ static void drawviewborder(void)
                glEnable(GL_BLEND);
                glColor4f(0, 0, 0, ca->passepartalpha);
                
-               if (x1 > 0.0) {
+               if (x1 > 0.0)
                        glRectf(0.0, (float)curarea->winy, x1, 0.0);
+               if (x2 < (float)curarea->winx)
                        glRectf(x2, (float)curarea->winy, (float)curarea->winx, 0.0);
-               }
-               if (y1 > 0.0)   {
+               if (y2 < (float)curarea->winy)
                        glRectf(x1, (float)curarea->winy, x2, y2);
+               if (y2 > 0.0) 
                        glRectf(x1, y1, x2, 0.0);
-               }
+
                glDisable(GL_BLEND);
        }
        
@@ -1080,12 +1090,13 @@ static void draw_selected_name(Object *ob)
        char info[128];
 
        if(ob->type==OB_ARMATURE) {
+               bArmature *arm= ob->data;
                char *name= NULL;
                
                if(ob==G.obedit) {
                        EditBone *ebo;
                        for (ebo=G.edbo.first; ebo; ebo=ebo->next){
-                               if (ebo->flag & BONE_ACTIVE) {
+                               if ((ebo->flag & BONE_ACTIVE) && (ebo->layer & arm->layer)) {
                                        name= ebo->name;
                                        break;
                                }
@@ -1094,7 +1105,7 @@ static void draw_selected_name(Object *ob)
                else if(ob->pose && (ob->flag & OB_POSEMODE)) {
                        bPoseChannel *pchan;
                        for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
-                               if(pchan->bone->flag & BONE_ACTIVE) {
+                               if((pchan->bone->flag & BONE_ACTIVE) && (pchan->bone->layer & arm->layer)) {
                                        name= pchan->name;
                                        break;
                                }
@@ -1125,7 +1136,7 @@ static void draw_view_icon(void)
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA,  GL_ONE_MINUS_SRC_ALPHA); 
        
-       BIF_draw_icon(5.0, 5.0, icon);
+       BIF_icon_draw(5.0, 5.0, icon);
        
        glBlendFunc(GL_ONE,  GL_ZERO); 
        glDisable(GL_BLEND);
@@ -1518,7 +1529,8 @@ static void v3d_posearmature_buts(uiBlock *block, Object *ob, float lim)
 
        for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
                bone = pchan->bone;
-               if(bone && (bone->flag & BONE_ACTIVE)) break;
+               if(bone && (bone->flag & BONE_ACTIVE) && (bone->layer & arm->layer))
+                       break;
        }
        if (!pchan) return;
        
@@ -1558,13 +1570,14 @@ static void v3d_posearmature_buts(uiBlock *block, Object *ob, float lim)
 
 static void v3d_editarmature_buts(uiBlock *block, Object *ob, float lim)
 {
+       bArmature *arm= G.obedit->data;
        EditBone *ebone;
        uiBut *but;
        
        ebone= G.edbo.first;
 
        for (ebone = G.edbo.first; ebone; ebone=ebone->next){
-               if (ebone->flag & BONE_ACTIVE)
+               if ((ebone->flag & BONE_ACTIVE) && (ebone->layer & arm->layer))
                        break;
        }
 
@@ -1703,6 +1716,7 @@ void do_viewbuts(unsigned short event)
                                DAG_scene_sort(G.scene);
                                DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
                                allqueue(REDRAWVIEW3D, 1);
+                               allqueue(REDRAWBUTSOBJECT, 0);
                        }
                }
                break;
@@ -1712,9 +1726,9 @@ void do_viewbuts(unsigned short event)
                        bArmature *arm= G.obedit->data;
                        EditBone *ebone, *child;
                        
-                       ebone= G.edbo.first;
                        for (ebone = G.edbo.first; ebone; ebone=ebone->next){
-                               if (ebone->flag & BONE_ACTIVE) break;
+                               if ((ebone->flag & BONE_ACTIVE) && (ebone->layer & arm->layer))
+                                       break;
                        }
                        if (ebone) {
                                ebone->roll= M_PI*ob_eul[0]/180.0;
@@ -1765,7 +1779,8 @@ void do_viewbuts(unsigned short event)
                                
                        for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
                                bone = pchan->bone;
-                               if(bone && (bone->flag & BONE_ACTIVE)) break;
+                               if(bone && (bone->flag & BONE_ACTIVE) && (bone->layer & arm->layer))
+                                       break;
                        }
                        if (!pchan) return;
                        
@@ -1777,6 +1792,7 @@ void do_viewbuts(unsigned short event)
                /* no break, pass on */
        case B_ARMATUREPANEL2:
                {
+                       ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
                        DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
                        allqueue(REDRAWVIEW3D, 1);
                }
@@ -2042,6 +2058,14 @@ static void view3d_blockhandlers(ScrArea *sa)
 
 }
 
+/* ****************** View3d afterdraw *************** */
+
+typedef struct View3DAfter {
+       struct View3DAfter *next, *prev;
+       struct Base *base;
+       int type;
+} View3DAfter;
+
 /* temp storage of Objects that need to be drawn as last */
 void add_view3d_after(View3D *v3d, Base *base, int type)
 {
@@ -2099,6 +2123,45 @@ static void view3d_draw_transp(View3D *v3d, int flag)
 
 }
 
+/* *********************** */
+
+static void draw_dupli_objects(View3D *v3d, Base *base)
+{
+       ListBase *lb;
+       DupliObject *dob;
+       Base tbase;
+       int color= (base->flag & SELECT)?TH_SELECT:TH_WIRE;
+       char dt, dtx;
+       
+       /* debug */
+       if(base->object->dup_group && base->object->dup_group->id.us<1)
+               color= TH_REDALERT;
+       
+       tbase.flag= OB_FROMDUPLI|base->flag;
+       lb= object_duplilist(G.scene, base->object);
+
+       for(dob= lb->first; dob; dob= dob->next) {
+               tbase.object= dob->ob;
+               
+               Mat4CpyMat4(dob->ob->obmat, dob->mat);
+               /* extra service: draw the duplicator in drawtype of parent */
+               dt= tbase.object->dt; tbase.object->dt= base->object->dt;
+               dtx= tbase.object->dtx; tbase.object->dtx= base->object->dtx;
+               
+               BIF_ThemeColorBlend(color, TH_BACK, 0.5);
+               draw_object(&tbase, DRAW_CONSTCOLOR);
+               
+               /* restore */
+               Mat4CpyMat4(dob->ob->obmat, dob->omat);
+               tbase.object->dt= dt;
+               tbase.object->dtx= dtx;
+       }
+       /* Transp afterdraw disabled, afterdraw only stores base pointers, and duplis can be same obj */
+
+       BLI_freelistN(lb);
+                               
+}
+
 void drawview3dspace(ScrArea *sa, void *spacedata)
 {
        View3D *v3d= spacedata;
@@ -2201,21 +2264,7 @@ void drawview3dspace(ScrArea *sa, void *spacedata)
                                draw_object(base, DRAW_CONSTCOLOR);
 
                                if(base->object->transflag & OB_DUPLI) {
-                                       extern ListBase duplilist;
-                                       Base tbase;
-                                       
-                                       tbase= *base;
-                                       
-                                       tbase.flag= OB_FROMDUPLI;
-                                       make_duplilist(setscene, base->object); /* make_duplilist(G.scene->set, base->object); */
-                                       ob= duplilist.first;
-                                       while(ob) {
-                                               tbase.object= ob;
-                                               draw_object(&tbase, DRAW_CONSTCOLOR);
-                                               ob= ob->id.next;
-                                       }
-                                       free_duplilist();
-                                       
+                                       draw_dupli_objects(v3d, base);
                                }
                        }
                        
@@ -2242,21 +2291,7 @@ void drawview3dspace(ScrArea *sa, void *spacedata)
                        
                        /* dupli drawing */
                        if(base->object->transflag & OB_DUPLI) {
-                               extern ListBase duplilist;
-                               Base tbase;
-
-                               BIF_ThemeColorBlend(TH_BACK, TH_WIRE, 0.5);
-                               
-                               tbase.flag= OB_FROMDUPLI;
-                               make_duplilist(G.scene, base->object);
-
-                               ob= duplilist.first;
-                               while(ob) {
-                                       tbase.object= ob;
-                                       draw_object(&tbase, DRAW_CONSTCOLOR);
-                                       ob= ob->id.next;
-                               }
-                               free_duplilist();
+                               draw_dupli_objects(v3d, base);
                        }
                        if((base->flag & SELECT)==0) {
                                if(base->object!=G.obedit) draw_object(base, 0);
@@ -2344,7 +2379,6 @@ void drawview3d_render(struct View3D *v3d)
 {
        extern short v3d_windowmode;
        Base *base;
-       Object *ob;
        Scene *setscene;
 
        update_for_newframe_muted();    /* first, since camera can be animated */
@@ -2403,18 +2437,7 @@ void drawview3d_render(struct View3D *v3d)
                                        draw_object(base, DRAW_CONSTCOLOR);
        
                                        if(base->object->transflag & OB_DUPLI) {
-                                               extern ListBase duplilist;
-                                               Base tbase;
-                                               
-                                               tbase.flag= OB_FROMDUPLI;
-                                               make_duplilist(setscene, base->object); /* make_duplilist(G.scene->set, base->object); */
-                                               ob= duplilist.first;
-                                               while(ob) {
-                                                       tbase.object= ob;
-                                                       draw_object(&tbase, DRAW_CONSTCOLOR);
-                                                       ob= ob->id.next;
-                                               }
-                                               free_duplilist();
+                                               draw_dupli_objects(v3d, base);
                                        }
                                }
                        }
@@ -2439,22 +2462,7 @@ void drawview3d_render(struct View3D *v3d)
                        else {
        
                                if(base->object->transflag & OB_DUPLI) {
-                                       extern ListBase duplilist;
-                                       Base tbase;
-                                       
-                                       draw_object(base, 0);
-                                       
-                                       BIF_ThemeColorBlend(TH_WIRE, TH_BACK, 0.5f);
-                                       
-                                       tbase.flag= OB_FROMDUPLI;
-                                       make_duplilist(G.scene, base->object);
-                                       ob= duplilist.first;
-                                       while(ob) {
-                                               tbase.object= ob;
-                                               draw_object(&tbase, DRAW_CONSTCOLOR);
-                                               ob= ob->id.next;
-                                       }
-                                       free_duplilist();
+                                       draw_dupli_objects(v3d, base);
                                }
                                else if((base->flag & SELECT)==0) {
                                        draw_object(base, 0);