code cleanup: function naming, use BKE_*type* prefix.
[blender.git] / source / blender / editors / space_view3d / view3d_draw.c
index 59a19782f1daa1ef3ac924d5365ad72c41771649..7ede8e01194d72a1776e14b9e65413630c0c12da 100644 (file)
@@ -98,7 +98,7 @@
 
 static void star_stuff_init_func(void)
 {
-       cpack(-1);
+       cpack(0xFFFFFF);
        glPointSize(1.0);
        glBegin(GL_POINTS);
 }
@@ -119,7 +119,7 @@ void circf(float x, float y, float rad)
        
        glPushMatrix(); 
        
-       glTranslatef(x,  y, 0.); 
+       glTranslatef(x, y, 0.0);
        
        gluDisk(qobj, 0.0,  rad, 32, 1);
        
@@ -136,7 +136,7 @@ void circ(float x, float y, float rad)
        
        glPushMatrix(); 
        
-       glTranslatef(x,  y, 0.); 
+       glTranslatef(x, y, 0.0);
        
        gluDisk(qobj, 0.0,  rad, 32, 1);
        
@@ -313,15 +313,15 @@ static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, const char **
                                double scalar = bUnit_GetScaler(usys, i);
 
                                dx_scalar = dx * scalar / unit->scale_length;
-                               if (dx_scalar < (GRID_MIN_PX * 2))
+                               if (dx_scalar < (GRID_MIN_PX * 2.0))
                                        continue;
 
                                /* Store the smallest drawn grid size units name so users know how big each grid cell is */
                                if (*grid_unit == NULL) {
                                        *grid_unit = bUnit_GetNameDisplay(usys, i);
-                                       rv3d->gridview = (scalar * v3d->grid) / unit->scale_length;
+                                       rv3d->gridview = (float)((scalar * v3d->grid) / (double)unit->scale_length);
                                }
-                               blend_fac = 1 - ((GRID_MIN_PX * 2) / dx_scalar);
+                               blend_fac = 1.0f - ((GRID_MIN_PX * 2.0f) / (float)dx_scalar);
 
                                /* tweak to have the fade a bit nicer */
                                blend_fac = (blend_fac * blend_fac) * 2.0f;
@@ -355,7 +355,7 @@ static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, const char **
                                        }
                                }
                                else {  // start blending out
-                                       UI_ThemeColorBlend(TH_BACK, TH_GRID, dx / (GRID_MIN_PX * 6));
+                                       UI_ThemeColorBlend(TH_BACK, TH_GRID, dx / (GRID_MIN_PX * 6.0f));
                                        drawgrid_draw(ar, wx, wy, x, y, dx);
 
                                        UI_ThemeColor(TH_GRID);
@@ -363,7 +363,7 @@ static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, const char **
                                }
                        }
                        else {  // start blending out (GRID_MIN_PX < dx < (GRID_MIN_PX*10))
-                               UI_ThemeColorBlend(TH_BACK, TH_GRID, dx / (GRID_MIN_PX * 6));
+                               UI_ThemeColorBlend(TH_BACK, TH_GRID, dx / (GRID_MIN_PX * 6.0f));
                                drawgrid_draw(ar, wx, wy, x, y, dx);
 
                                UI_ThemeColor(TH_GRID);
@@ -939,21 +939,21 @@ static void view3d_camera_border(Scene *scene, ARegion *ar, View3D *v3d, RegionV
        rctf rect_view, rect_camera;
 
        /* get viewport viewplane */
-       camera_params_init(&params);
-       camera_params_from_view3d(&params, v3d, rv3d);
+       BKE_camera_params_init(&params);
+       BKE_camera_params_from_view3d(&params, v3d, rv3d);
        if (no_zoom)
                params.zoom = 1.0f;
-       camera_params_compute_viewplane(&params, ar->winx, ar->winy, 1.0f, 1.0f);
+       BKE_camera_params_compute_viewplane(&params, ar->winx, ar->winy, 1.0f, 1.0f);
        rect_view = params.viewplane;
 
        /* get camera viewplane */
-       camera_params_init(&params);
-       camera_params_from_object(&params, v3d->camera);
+       BKE_camera_params_init(&params);
+       BKE_camera_params_from_object(&params, v3d->camera);
        if (no_shift) {
                params.shiftx = 0.0f;
                params.shifty = 0.0f;
        }
-       camera_params_compute_viewplane(&params, scene->r.xsch, scene->r.ysch, scene->r.xasp, scene->r.yasp);
+       BKE_camera_params_compute_viewplane(&params, scene->r.xsch, scene->r.ysch, scene->r.xasp, scene->r.yasp);
        rect_camera = params.viewplane;
 
        /* get camera border within viewport */
@@ -1226,7 +1226,7 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
                         * assume and square sensor and only use sensor_x */
                        float sizex = scene->r.xsch * scene->r.xasp;
                        float sizey = scene->r.ysch * scene->r.yasp;
-                       int sensor_fit = camera_sensor_fit(ca->sensor_fit, sizex, sizey);
+                       int sensor_fit = BKE_camera_sensor_fit(ca->sensor_fit, sizex, sizey);
                        float sensor_x = ca->sensor_x;
                        float sensor_y = (ca->sensor_fit == CAMERA_SENSOR_FIT_AUTO) ? ca->sensor_x : ca->sensor_y;
 
@@ -1515,7 +1515,7 @@ exit:
 
 /* ************************************************************* */
 
-static void draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d)
+static void draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d, int foreground)
 {
        RegionView3D *rv3d = ar->regiondata;
        BGpic *bgpic;
@@ -1524,10 +1524,13 @@ static void draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d)
        ImBuf *ibuf = NULL, *freeibuf;
        float vec[4], fac, asp, zoomx, zoomy;
        float x1, y1, x2, y2, cx, cy;
-
+       int fg_flag = foreground ? V3D_BGPIC_FOREGROUND : 0;
 
        for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) {
 
+               if ((bgpic->flag & V3D_BGPIC_FOREGROUND) != fg_flag)
+                       continue;
+
                if ((bgpic->view == 0) || /* zero for any */
                    (bgpic->view & (1 << rv3d->view)) || /* check agaist flags */
                    (rv3d->persp == RV3D_CAMOB && bgpic->view == (1 << RV3D_VIEW_CAMERA)))
@@ -1549,7 +1552,7 @@ static void draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d)
 
                                if (bgpic->flag & V3D_BGPIC_CAMERACLIP) {
                                        if (scene->camera)
-                                               clip = object_get_movieclip(scene, scene->camera, 1);
+                                               clip = BKE_object_movieclip_get(scene, scene->camera, 1);
                                }
                                else clip = bgpic->clip;
 
@@ -1680,6 +1683,26 @@ static void draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d)
        }
 }
 
+static void draw_bgpics(Scene *scene, ARegion *ar, View3D *v3d, int foreground)
+{
+       RegionView3D *rv3d = ar->regiondata;
+
+       if ((v3d->flag & V3D_DISPBGPICS) == 0)
+               return;
+
+       if (v3d->flag2 & V3D_RENDER_OVERRIDE)
+               return;
+
+       if ((rv3d->view == RV3D_VIEW_USER) || (rv3d->persp != RV3D_ORTHO)) {
+               if (rv3d->persp == RV3D_CAMOB) {
+                       draw_bgpic(scene, ar, v3d, foreground);
+               }
+       }
+       else {
+                       draw_bgpic(scene, ar, v3d, foreground);
+       }
+}
+
 /* ****************** View3d afterdraw *************** */
 
 typedef struct View3DAfter {
@@ -1843,7 +1866,7 @@ static void draw_dupli_objects_color(Scene *scene, ARegion *ar, View3D *v3d, Bas
                            /* lamp drawing messes with matrices, could be handled smarter... but this works */
                            (dob->ob->type == OB_LAMP) ||
                            (dob->type == OB_DUPLIGROUP && dob->animated) ||
-                           !(bb_tmp = object_get_boundbox(dob->ob)))
+                           !(bb_tmp = BKE_object_boundbox_get(dob->ob)))
                        {
                                // printf("draw_dupli_objects_color: skipping displist for %s\n", dob->ob->id.name+2);
                                use_displist = 0;
@@ -1853,7 +1876,7 @@ static void draw_dupli_objects_color(Scene *scene, ARegion *ar, View3D *v3d, Bas
                                bb = *bb_tmp; /* must make a copy  */
 
                                /* disable boundbox check for list creation */
-                               object_boundbox_flag(dob->ob, OB_BB_DISABLED, 1);
+                               BKE_object_boundbox_flag(dob->ob, OB_BB_DISABLED, 1);
                                /* need this for next part of code */
                                unit_m4(dob->ob->obmat);    /* obmat gets restored */
 
@@ -1863,7 +1886,7 @@ static void draw_dupli_objects_color(Scene *scene, ARegion *ar, View3D *v3d, Bas
                                glEndList();
 
                                use_displist = 1;
-                               object_boundbox_flag(dob->ob, OB_BB_DISABLED, 0);
+                               BKE_object_boundbox_flag(dob->ob, OB_BB_DISABLED, 0);
                        }
                }
                if (use_displist) {
@@ -2020,7 +2043,7 @@ void draw_depth_gpencil(Scene *scene, ARegion *ar, View3D *v3d)
        RegionView3D *rv3d = ar->regiondata;
 
        setwinmatrixview3d(ar, v3d, NULL);  /* 0= no pick rect */
-       setviewmatrixview3d(scene, v3d, rv3d);  /* note: calls where_is_object for camera... */
+       setviewmatrixview3d(scene, v3d, rv3d);  /* note: calls BKE_object_where_is_calc for camera... */
 
        mult_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat);
        invert_m4_m4(rv3d->persinv, rv3d->persmat);
@@ -2055,7 +2078,7 @@ void draw_depth(Scene *scene, ARegion *ar, View3D *v3d, int (*func)(void *))
        U.obcenter_dia = 0;
        
        setwinmatrixview3d(ar, v3d, NULL);  /* 0= no pick rect */
-       setviewmatrixview3d(scene, v3d, rv3d);  /* note: calls where_is_object for camera... */
+       setviewmatrixview3d(scene, v3d, rv3d);  /* note: calls BKE_object_where_is_calc for camera... */
        
        mult_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat);
        invert_m4_m4(rv3d->persinv, rv3d->persmat);
@@ -2344,7 +2367,7 @@ void ED_view3d_update_viewmat(Scene *scene, View3D *v3d, ARegion *ar, float view
        if (viewmat)
                copy_m4_m4(rv3d->viewmat, viewmat);
        else
-               setviewmatrixview3d(scene, v3d, rv3d);  /* note: calls where_is_object for camera... */
+               setviewmatrixview3d(scene, v3d, rv3d);  /* note: calls BKE_object_where_is_calc for camera... */
 
        /* update utilitity matrices */
        mult_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat);
@@ -2589,10 +2612,10 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar,
        if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
                CameraParams params;
 
-               camera_params_init(&params);
-               camera_params_from_object(&params, v3d->camera);
-               camera_params_compute_viewplane(&params, sizex, sizey, scene->r.xasp, scene->r.yasp);
-               camera_params_compute_matrix(&params);
+               BKE_camera_params_init(&params);
+               BKE_camera_params_from_object(&params, v3d->camera);
+               BKE_camera_params_compute_viewplane(&params, sizex, sizey, scene->r.xasp, scene->r.yasp);
+               BKE_camera_params_compute_matrix(&params);
 
                ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, params.winmat, draw_background);
        }
@@ -2650,10 +2673,10 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Scene *scene, Object *camera, int w
        {
                CameraParams params;
 
-               camera_params_init(&params);
-               camera_params_from_object(&params, v3d.camera);
-               camera_params_compute_viewplane(&params, width, height, scene->r.xasp, scene->r.yasp);
-               camera_params_compute_matrix(&params);
+               BKE_camera_params_init(&params);
+               BKE_camera_params_from_object(&params, v3d.camera);
+               BKE_camera_params_compute_viewplane(&params, width, height, scene->r.xasp, scene->r.yasp);
+               BKE_camera_params_compute_matrix(&params);
 
                copy_m4_m4(rv3d.winmat, params.winmat);
                v3d.near = params.clipsta;
@@ -2750,13 +2773,16 @@ static int view3d_main_area_draw_engine(const bContext *C, ARegion *ar)
 
        /* render result draw */
        if (v3d->flag & V3D_DISPBGPICS)
-               draw_bgpic(scene, ar, v3d);
+               draw_bgpic(scene, ar, v3d, FALSE);
        else
                fdrawcheckerboard(0, 0, ar->winx, ar->winy);
 
        type = rv3d->render_engine->type;
        type->view_draw(rv3d->render_engine, C);
 
+       if (v3d->flag & V3D_DISPBGPICS)
+               draw_bgpic(scene, ar, v3d, TRUE);
+
        return 1;
 }
 
@@ -2837,9 +2863,6 @@ static void view3d_main_area_draw_objects(const bContext *C, ARegion *ar, const
                                                      star_stuff_term_func);
                                }
                        }
-                       if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
-                               if (v3d->flag & V3D_DISPBGPICS) draw_bgpic(scene, ar, v3d);
-                       }
                }
        }
        else {
@@ -2851,13 +2874,11 @@ static void view3d_main_area_draw_objects(const bContext *C, ARegion *ar, const
                        glLoadMatrixf(rv3d->winmat);
                        glMatrixMode(GL_MODELVIEW);
                        glLoadMatrixf(rv3d->viewmat);
-
-                       if (v3d->flag & V3D_DISPBGPICS) {
-                               draw_bgpic(scene, ar, v3d);
-                       }
                }
        }
-       
+
+       draw_bgpics(scene, ar, v3d, FALSE);
+
        if (rv3d->rflag & RV3D_CLIPPING)
                ED_view3d_clipping_set(rv3d);
 
@@ -2915,6 +2936,8 @@ static void view3d_main_area_draw_objects(const bContext *C, ARegion *ar, const
                }
        }
 
+       draw_bgpics(scene, ar, v3d, TRUE);
+
 //     REEB_draw();
 
        if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {