Merging r39634 through r39716 from trunk into soc-2011-tomato
authorSergey Sharybin <sergey.vfx@gmail.com>
Fri, 26 Aug 2011 20:12:54 +0000 (20:12 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Fri, 26 Aug 2011 20:12:54 +0000 (20:12 +0000)
17 files changed:
1  2 
CMakeLists.txt
build_files/scons/config/darwin-config.py
release/scripts/startup/bl_ui/space_view3d.py
source/blender/blenloader/intern/writefile.c
source/blender/editors/interface/interface_draw.c
source/blender/editors/interface/interface_handlers.c
source/blender/editors/screen/screen_edit.c
source/blender/editors/screen/screen_ops.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/space_view3d/view3d_select.c
source/blender/editors/space_view3d/view3d_view.c
source/blender/makesdna/DNA_space_types.h
source/blender/makesdna/DNA_view3d_types.h
source/blender/makesrna/intern/rna_scene.c
source/blender/windowmanager/intern/wm_operators.c
source/gameengine/Converter/BL_BlenderDataConversion.cpp

diff --combined CMakeLists.txt
index 5e67657932ffd16829963c60d0f4398df474fd14,366383d277a90af7d035a561b8a73ab4b45ced67..fdfb3bba5b69560783f5dc91b873cca611ea7b75
@@@ -194,9 -194,6 +194,9 @@@ option(WITH_SAMPLERATE    "Enable sampl
  option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
  option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
  
 +# Tracking
 +option(WITH_LIBMV         "Enable libmv structure from motion library" ON)
 +
  # Misc
  option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ON)
  option(WITH_RAYOPTIMIZATION   "Enable use of SIMD (SSE) optimizations for the raytracer" ON) 
@@@ -277,6 -274,11 +277,11 @@@ endif(
  
  TEST_SSE_SUPPORT()
  
+ # don't store paths to libs for portable distrobution
+ if(WITH_INSTALL_PORTABLE)
+       set(CMAKE_SKIP_BUILD_RPATH TRUE)
+ endif()
  #-----------------------------------------------------------------------------
  # Initialize un-cached vars, avoid unused warning
  
@@@ -448,21 -450,20 +453,20 @@@ if(UNIX AND NOT APPLE
        endif()
  
        if(WITH_OPENCOLLADA)
-               set(OPENCOLLADA /usr/local/opencollada CACHE PATH "OpenCollada Directory")
-               mark_as_advanced(OPENCOLLADA)
-               set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
-               set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver pcre ftoa buffer xml2)
-               set(OPENCOLLADA_INCLUDE_DIR ${OPENCOLLADA})
-               set(PCRE /usr CACHE PATH "PCRE Directory")
-               mark_as_advanced(PCRE)
-               set(PCRE_LIBPATH ${PCRE}/lib)
-               set(PCRE_LIB pcre)
+               find_package(OpenCOLLADA)
+               if(OPENCOLLADA_FOUND)
+                       set(PCRE /usr CACHE PATH "PCRE Directory")
+                       mark_as_advanced(PCRE)
+                       set(PCRE_LIBPATH ${PCRE}/lib)
+                       set(PCRE_LIB pcre)
  
-               set(EXPAT /usr CACHE PATH "Expat Directory")
-               mark_as_advanced(EXPAT)
-               set(EXPAT_LIBPATH ${EXPAT}/lib)
-               set(EXPAT_LIB expat)
+                       set(EXPAT /usr CACHE PATH "Expat Directory")
+                       mark_as_advanced(EXPAT)
+                       set(EXPAT_LIBPATH ${EXPAT}/lib)
+                       set(EXPAT_LIB expat)
+               else()
+                       set(WITH_OPENCOLLADA OFF)
+               endif()
        endif()
  
        if(WITH_MEM_JEMALLOC)
@@@ -687,9 -688,15 +691,15 @@@ elseif(WIN32
                endif()
  
                if(WITH_OPENCOLLADA)
-                       set(OPENCOLLADA_INCLUDE_DIR
-                               ${LIBDIR}/opencollada/include
+                       set(OPENCOLLADA_INCLUDE_DIRS
+                               ${LIBDIR}/opencollada/include/COLLADAStreamWriter/include
+                               ${LIBDIR}/opencollada/include/COLLADABaseUtils/include
+                               ${LIBDIR}/opencollada/include/COLLADAFramework/include
+                               ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader/include
+                               ${LIBDIR}/opencollada/include/GeneratedSaxParser/include                        
                        )
                        set(OPENCOLLADA_LIBRARIES
                                ${LIBDIR}/opencollada/lib/OpenCOLLADASaxFrameworkLoader.lib
                                ${LIBDIR}/opencollada/lib/OpenCOLLADAFramework.lib
  
                if(WITH_OPENCOLLADA)
                        set(OPENCOLLADA ${LIBDIR}/gcc/opencollada)
-                       set(OPENCOLLADA_INCLUDE_DIR ${OPENCOLLADA}/include)
+                       set(OPENCOLLADA_INCLUDE_DIRS
+                               ${LIBDIR}/opencollada/include/COLLADAStreamWriter/include
+                               ${LIBDIR}/opencollada/include/COLLADABaseUtils/include
+                               ${LIBDIR}/opencollada/include/COLLADAFramework/include
+                               ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader/include
+                               ${LIBDIR}/opencollada/include/GeneratedSaxParser/include                        
+                       )
                        set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib ${OPENCOLLADA}/lib)
                        set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver expat pcre buffer ftoa)
                        set(PCRE_LIB pcre)
@@@ -1046,7 -1059,15 +1062,15 @@@ elseif(APPLE
  
        if(WITH_OPENCOLLADA)
                set(OPENCOLLADA ${LIBDIR}/opencollada)
-               set(OPENCOLLADA_INCLUDE_DIR ${OPENCOLLADA}/include)
+               set(OPENCOLLADA_INCLUDE_DIRS
+                       ${LIBDIR}/opencollada/include/COLLADAStreamWriter
+                       ${LIBDIR}/opencollada/include/COLLADABaseUtils
+                       ${LIBDIR}/opencollada/include/COLLADAFramework
+                       ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader
+                       ${LIBDIR}/opencollada/include/GeneratedSaxParser
+               )
                set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
                set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lUTF -lxml2 -lbuffer -lftoa" )
                #pcre is bundled with openCollada
index 2737fda62e2428f94958cb33a6642d9381d22979,06abaf468dd8d2a92bf28b840ead7aaad780fb64..eff53cd0e93e1f3f3c5883eec8f0a2757c3dfc9a
@@@ -98,7 -98,7 +98,7 @@@ else
  
  # enable ffmpeg  support
  WITH_BF_FFMPEG = True  # -DWITH_FFMPEG
 -BF_FFMPEG = LIBDIR + '/ffmpeg'
 +BF_FFMPEG = LIBDIR + '/ffmpeg-0.8'
  BF_FFMPEG_INC = "${BF_FFMPEG}/include"
  BF_FFMPEG_LIBPATH='${BF_FFMPEG}/lib'
  BF_FFMPEG_LIB = 'avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg bz2'
@@@ -316,7 -316,11 +316,11 @@@ if WITH_BF_QUICKTIME
                PLATFORM_LINKFLAGS = PLATFORM_LINKFLAGS+['-framework','QuickTime']
  
  #note to build succesfully on 10.3.9 SDK you need to patch  10.3.9 by adding the SystemStubs.a lib from 10.4
- LLIBS = ['stdc++', 'SystemStubs']
+ #for 10.7.sdk, SystemStubs needs to be excluded (lib doesn't exist anymore)
+ if MACOSX_DEPLOYMENT_TARGET == '10.7':
+       LLIBS = ['stdc++']
+ else:
+       LLIBS = ['stdc++', 'SystemStubs']
  
  # some flags shuffling for different OS versions
  if MAC_MIN_VERS == '10.3':
index 0957833a2bd195f70bc1ece6d5e7704723077071,dd705f76feb82f5eccf2bb1e2a4a6195c0238511..28b257102900e6f97f7c02688d142d72e4ea1534
@@@ -2073,9 -2073,11 +2073,11 @@@ class VIEW3D_PT_view3d_properties(Panel
          col.prop(view, "lens")
          col.label(text="Lock to Object:")
          col.prop(view, "lock_object", text="")
-         if view.lock_object and view.lock_object.type == 'ARMATURE':
-             col.prop_search(view, "lock_bone", view.lock_object.data, "bones", text="")
-         elif not view.lock_object:
+         lock_object = view.lock_object
+         if lock_object:
+             if lock_object.type == 'ARMATURE':
+                 col.prop_search(view, "lock_bone", lock_object.data, "edit_bones" if lock_object.mode == 'EDIT' else "bones", text="")
+         else:
              col.prop(view, "lock_cursor", text="Lock to Cursor")
  
          col = layout.column()
@@@ -2176,16 -2178,6 +2178,16 @@@ class VIEW3D_PT_view3d_display(Panel)
  
          layout.separator()
  
 +        layout.prop(view, "show_reconstruction")
 +        if view.show_reconstruction:
 +            layout.label(text="Bundle type:")
 +            layout.prop(view, "bundle_draw_type", text="")
 +            layout.prop(view, "bundle_draw_size")
 +            layout.prop(view, "show_bundle_name")
 +            layout.prop(view, "show_camera_path")
 +
 +        layout.separator()
 +
          region = view.region_quadview
  
          layout.operator("screen.region_quadview", text="Toggle Quad View")
@@@ -2291,10 -2283,8 +2293,10 @@@ class VIEW3D_PT_background_image(Panel)
              box = layout.box()
              row = box.row(align=True)
              row.prop(bg, "show_expanded", text="", emboss=False)
 -            if bg.image:
 +            if bg.source == 'IMAGE' and bg.image:
                  row.prop(bg.image, "name", text="", emboss=False)
 +            if bg.source == 'MOVIE' and bg.clip:
 +                row.prop(bg.clip, "name", text="", emboss=False)
              else:
                  row.label(text="Not Set")
              row.operator("view3d.background_image_remove", text="", emboss=False, icon='X').index = i
  
              if bg.show_expanded:
                  row = box.row()
 -                row.template_ID(bg, "image", open="image.open")
 -                if (bg.image):
 -                    box.template_image(bg, "image", bg.image_user, compact=True)
 +                row.prop(bg, "source", expand=True)
 +
 +                hasbg = False
 +                if bg.source == 'IMAGE':
 +                    row = box.row()
 +                    row.template_ID(bg, "image", open="image.open")
 +                    if (bg.image):
 +                        box.template_image(bg, "image", bg.image_user, compact=True)
 +                        hasbg = True
 +
 +                elif bg.source == 'MOVIE':
 +                    row = box.row()
 +                    row.template_ID(bg, "clip", open="clip.open")
 +
 +                    if bg.clip:
 +                        box.template_movieclip(bg, "clip", compact=True)
 +                        hasbg = True
  
 +                if hasbg:
                      box.prop(bg, "opacity", slider=True)
                      if bg.view_axis != 'CAMERA':
                          box.prop(bg, "size")
index bf4deb6ac1e8a578279a717c17317a8b3aab9ce5,5b7fcc0e935f28b786ec7c68ac971d9b050229e4..a0df87599412647217c2f71b710828882a7c07e1
@@@ -129,7 -129,6 +129,7 @@@ Any case: direct data is ALWAYS after t
  #include "DNA_vfont_types.h"
  #include "DNA_world_types.h"
  #include "DNA_windowmanager_types.h"
 +#include "DNA_movieclip_types.h"
  
  #include "MEM_guardedalloc.h" // MEM_freeN
  #include "BLI_blenlib.h"
@@@ -868,10 -867,12 +868,12 @@@ static void write_particlesettings(Writ
                        for(; dw; dw=dw->next) {
                                /* update indices */
                                dw->index = 0;
-                               go = part->dup_group->gobject.first;
-                               while(go && go->ob != dw->ob) {
-                                       go=go->next;
-                                       dw->index++;
+                               if(part->dup_group) { /* can be NULL if lining fails or set to None */
+                                       go = part->dup_group->gobject.first;
+                                       while(go && go->ob != dw->ob) {
+                                               go=go->next;
+                                               dw->index++;
+                                       }
                                }
                                writestruct(wd, DATA, "ParticleDupliWeight", 1, dw);
                        }
@@@ -2201,9 -2202,6 +2203,9 @@@ static void write_screens(WriteData *wd
                                else if(sl->spacetype==SPACE_USERPREF) {
                                        writestruct(wd, DATA, "SpaceUserPref", 1, sl);
                                }
 +                              else if(sl->spacetype==SPACE_CLIP) {
 +                                      writestruct(wd, DATA, "SpaceClip", 1, sl);
 +                              }
  
                                sl= sl->next;
                        }
@@@ -2435,38 -2433,6 +2437,38 @@@ static void write_scripts(WriteData *wd
        }
  }
  
 +static void write_movieclips(WriteData *wd, ListBase *idbase)
 +{
 +      MovieClip *clip;
 +
 +      clip= idbase->first;
 +      while(clip) {
 +              if(clip->id.us>0 || wd->current) {
 +                      MovieTracking *tracking= &clip->tracking;
 +                      MovieTrackingTrack *track;
 +                      writestruct(wd, ID_MC, "MovieClip", 1, clip);
 +
 +                      if(tracking->reconstruction.camnr)
 +                              writestruct(wd, DATA, "MovieReconstructedCamera", tracking->reconstruction.camnr, tracking->reconstruction.cameras);
 +
 +                      track= tracking->tracks.first;
 +                      while(track) {
 +                              writestruct(wd, DATA, "MovieTrackingTrack", 1, track);
 +
 +                              if(track->markers)
 +                                      writestruct(wd, DATA, "MovieTrackingMarker", track->markersnr, track->markers);
 +
 +                              track= track->next;
 +                      }
 +              }
 +
 +              clip= clip->id.next;
 +      }
 +
 +      /* flush helps the compression for undo-save */
 +      mywrite(wd, MYWRITE_FLUSH, 0);
 +}
 +
  /* context is usually defined by WM, two cases where no WM is available:
   * - for forward compatibility, curscreen has to be saved
   * - for undofile, curscene needs to be saved */
@@@ -2543,7 -2509,6 +2545,7 @@@ static int write_file_handle(Main *main
                write_windowmanagers(wd, &mainvar->wm);
                write_screens  (wd, &mainvar->screen);
        }
 +      write_movieclips (wd, &mainvar->movieclip);
        write_scenes   (wd, &mainvar->scene);
        write_curves   (wd, &mainvar->curve);
        write_mballs   (wd, &mainvar->mball);
index b6cb2f9aae4384cd512c36404534b4e941a8de92,76ed9891b8e5d62c07f7b0cd563e66abe0c4889d..31ba89e27e1bbda0edb215adc522d5d39542831e
@@@ -36,7 -36,6 +36,7 @@@
  #include "DNA_color_types.h"
  #include "DNA_object_types.h"
  #include "DNA_screen_types.h"
 +#include "DNA_movieclip_types.h"
  
  #include "BLI_math.h"
  #include "BLI_rect.h"
@@@ -531,14 -530,11 +531,11 @@@ static void ui_draw_but_CHARTAB(uiBut *
        int charmax = G.charmax;
        
        /* FO_BUILTIN_NAME font in use. There are TTF FO_BUILTIN_NAME and non-TTF FO_BUILTIN_NAME fonts */
-       if(!strcmp(G.selfont->name, FO_BUILTIN_NAME))
-       {
-               if(G.ui_international == TRUE)
-               {
+       if(!strcmp(G.selfont->name, FO_BUILTIN_NAME)) {
+               if(G.ui_international == TRUE) {
                        charmax = 0xff;
                }
-               else
-               {
+               else {
                        charmax = 0xff;
                }
        }
        cs = G.charstart;
  
        /* Set the font, in case it is not FO_BUILTIN_NAME font */
-       if(G.selfont && strcmp(G.selfont->name, FO_BUILTIN_NAME))
-       {
+       if(G.selfont && strcmp(G.selfont->name, FO_BUILTIN_NAME)) {
                // Is the font file packed, if so then use the packed file
-               if(G.selfont->packedfile)
-               {
+               if(G.selfont->packedfile) {
                        pf = G.selfont->packedfile;             
                        FTF_SetFont(pf->data, pf->size, 14.0);
                }
-               else
-               {
+               else {
                        char tmpStr[256];
                        int err;
  
                        err = FTF_SetFont((unsigned char *)tmpStr, 0, 14.0);
                }
        }
-       else
-       {
-               if(G.ui_international == TRUE)
-               {
+       else {
+               if(G.ui_international == TRUE) {
                        FTF_SetFont((unsigned char *) datatoc_bfont_ttf, datatoc_bfont_ttf_size, 14.0);
                }
        }
        glRectf((rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax));
  
        glColor3ub(0,  0,  0);
-       for(y = 0; y < 6; y++)
-       {
+       for(y = 0; y < 6; y++) {
                // Do not draw more than the category allows
                if(cs > charmax) break;
  
        glShadeModel(GL_FLAT);
  
        /* Return Font Settings to original */
-       if(U.fontsize && U.fontname[0])
-       {
+       if(U.fontsize && U.fontname[0]) {
                result = FTF_SetFont((unsigned char *)U.fontname, 0, U.fontsize);
        }
-       else if (U.fontsize)
-       {
+       else if (U.fontsize) {
                result = FTF_SetFont((unsigned char *) datatoc_bfont_ttf, datatoc_bfont_ttf_size, U.fontsize);
        }
  
-       if (result == 0)
-       {
+       if (result == 0) {
                result = FTF_SetFont((unsigned char *) datatoc_bfont_ttf, datatoc_bfont_ttf_size, 11);
        }
        
        /* resets the font size */
-       if(G.ui_international == TRUE)
-       {
+       if(G.ui_international == TRUE) {
                // uiSetCurFont(but->block, UI_HELV);
        }
  }
@@@ -724,7 -710,7 +711,7 @@@ static void draw_scope_end(rctf *rect, 
        /* outline */
        glColor4f(0.f, 0.f, 0.f, 0.5f);
        uiSetRoundBox(15);
 -      uiDrawBox(GL_LINE_LOOP, rect->xmin-1, rect->ymin, rect->xmax+1, rect->ymax+1, 3.0f);
 +      uiDrawBox(GL_LINE_LOOP, rect->xmin-1, rect->ymin-1, rect->xmax+1, rect->ymax+1, 3.0f);
  }
  
  static void histogram_draw_one(float r, float g, float b, float alpha, float x, float y, float w, float h, float *data, int res)
@@@ -1529,114 -1515,6 +1516,114 @@@ void ui_draw_but_CURVE(ARegion *ar, uiB
        fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
  }
  
 +static ImBuf *scale_trackpreview_ibuf(ImBuf *ibuf, float zoomx, float zoomy)
 +{
 +      ImBuf *scaleibuf;
 +      int x, y, w= ibuf->x*zoomx, h= ibuf->y*zoomy;
 +      scaleibuf= IMB_allocImBuf(w, h, 32, IB_rect);
 +
 +      for(y= 0; y<scaleibuf->y; y++) {
 +              for (x= 0; x<scaleibuf->x; x++) {
 +                      int pixel= scaleibuf->x*y + x;
 +                      int orig_pixel= ibuf->x*(int)(((float)y)/zoomy) + (int)(((float)x)/zoomx);
 +                      char *rrgb= (char*)scaleibuf->rect + pixel*4;
 +                      char *orig_rrgb= (char*)ibuf->rect + orig_pixel*4;
 +                      rrgb[0]= orig_rrgb[0];
 +                      rrgb[1]= orig_rrgb[1];
 +                      rrgb[2]= orig_rrgb[2];
 +                      rrgb[3]= orig_rrgb[3];
 +              }
 +      }
 +
 +      return scaleibuf;
 +}
 +
 +void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti)
 +{
 +      rctf rect;
 +      int ok= 0;
 +      GLint scissor[4];
 +      MovieClipScopes *scopes = (MovieClipScopes *)but->poin;
 +
 +      rect.xmin = (float)recti->xmin+1;
 +      rect.xmax = (float)recti->xmax-1;
 +      rect.ymin = (float)recti->ymin+SCOPE_RESIZE_PAD+2;
 +      rect.ymax = (float)recti->ymax-1;
 +
 +      glEnable(GL_BLEND);
 +      glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
 +
 +      /* need scissor test, preview image can draw outside of boundary */
 +      glGetIntegerv(GL_VIEWPORT, scissor);
 +      glScissor(ar->winrct.xmin + (rect.xmin-1), ar->winrct.ymin+(rect.ymin-1), (rect.xmax+1)-(rect.xmin-1), (rect.ymax+1)-(rect.ymin-1));
 +
 +      if(scopes->track_disabled) {
 +              glColor4f(0.7f, 0.3f, 0.3f, 0.3f);
 +              uiSetRoundBox(15);
 +              uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
 +
 +              ok= 1;
 +      }
 +      else if(scopes->track_preview) {
 +              int a, off_x, off_y;
 +              float zoomx, zoomy;
 +              ImBuf *drawibuf;
 +
 +              glPushMatrix();
 +
 +              /* draw content of pattern area */
 +              glScissor(ar->winrct.xmin+rect.xmin, ar->winrct.ymin+rect.ymin, scissor[2], scissor[3]);
 +
 +              zoomx= (rect.xmax-rect.xmin) / (scopes->track_preview->x-2.f);
 +              zoomy= (rect.ymax-rect.ymin) / (scopes->track_preview->y-2.f);
 +
 +              off_x= ((int)scopes->track_pos[0]-scopes->track_pos[0]-0.5)*zoomx;
 +              off_y= ((int)scopes->track_pos[1]-scopes->track_pos[1]-0.5)*zoomy;
 +
 +              drawibuf= scale_trackpreview_ibuf(scopes->track_preview, zoomx, zoomy);
 +              glaDrawPixelsSafe(off_x+rect.xmin, off_y+rect.ymin, rect.xmax-rect.xmin+1.f-off_x, rect.ymax-rect.ymin+1.f-off_y, drawibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, drawibuf->rect);
 +
 +              IMB_freeImBuf(drawibuf);
 +
 +              /* draw cross for pizel position */
 +              glTranslatef(off_x+rect.xmin+scopes->track_pos[0]*zoomx, off_y+rect.ymin+scopes->track_pos[1]*zoomy, 0.f);
 +              glScissor(ar->winrct.xmin + rect.xmin, ar->winrct.ymin+rect.ymin, rect.xmax-rect.xmin, rect.ymax-rect.ymin);
 +
 +              for(a= 0; a< 2; a++) {
 +                      if(a==1) {
 +                              glLineStipple(3, 0xaaaa);
 +                              glEnable(GL_LINE_STIPPLE);
 +                              UI_ThemeColor(TH_SEL_MARKER);
 +                      }
 +                      else {
 +                              UI_ThemeColor(TH_MARKER_OUTLINE);
 +                      }
 +
 +                      glBegin(GL_LINES);
 +                              glVertex2f(-10.0f, 0.0f);
 +                              glVertex2f(10.0f, 0.0f);
 +                              glVertex2f(0.0f, -10.0f);
 +                              glVertex2f(0.0f, 10.0f);
 +                      glEnd();
 +              }
 +
 +              glDisable(GL_LINE_STIPPLE);
 +              glPopMatrix();
 +
 +              ok= 1;
 +      }
 +
 +      if(!ok) {
 +              glColor4f(0.f, 0.f, 0.f, 0.3f);
 +              uiSetRoundBox(15);
 +              uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
 +      }
 +
 +      /* outline, scale gripper */
 +      draw_scope_end(&rect, scissor);
 +
 +      glDisable(GL_BLEND);
 +}
  
  /* ****************************************************** */
  
@@@ -1713,7 -1591,6 +1700,6 @@@ void ui_dropshadow(rctf *rct, float rad
  #endif
        {
                a= i*aspect;
        }
  
        for(; i--; a-=aspect) {
index b36bb1a61b34288a2ad6cefb8ebe380c710b1791,d7eba8c0ac75779aa4d76f1c134a0dbbc54e7cfa..37cc6557032515a0fcc6ebf0f3a48d7c21dc98ba
@@@ -56,7 -56,6 +56,7 @@@
  #include "BKE_idprop.h"
  #include "BKE_report.h"
  #include "BKE_texture.h"
 +#include "BKE_tracking.h"
  #include "BKE_unit.h"
  
  #include "ED_screen.h"
@@@ -254,7 -253,7 +254,7 @@@ static uiBut *ui_but_last(uiBlock *bloc
  static int ui_is_a_warp_but(uiBut *but)
  {
        if(U.uiflag & USER_CONTINUOUS_MOUSE)
 -              if(ELEM3(but->type, NUM, NUMABS, HSVCIRCLE))
 +              if(ELEM4(but->type, NUM, NUMABS, HSVCIRCLE, TRACKPREVIEW))
                        return TRUE;
  
        return FALSE;
@@@ -801,8 -800,7 +801,7 @@@ static void ui_add_smart_controller(bCo
        if(!act_iter) return;
  
        /* (3) add a new controller */
-       if (WM_operator_name_call(C, "LOGIC_OT_controller_add", WM_OP_EXEC_DEFAULT, NULL) & OPERATOR_FINISHED)
-       {
+       if (WM_operator_name_call(C, "LOGIC_OT_controller_add", WM_OP_EXEC_DEFAULT, NULL) & OPERATOR_FINISHED) {
                cont = (bController *)ob->controllers.last;
  
                /* (4) link the sensor->controller->actuator */
@@@ -918,13 -916,6 +917,13 @@@ static void ui_apply_but_WAVEFORM(bCont
        data->applied= 1;
  }
  
 +static void ui_apply_but_TRACKPREVIEW(bContext *C, uiBut *but, uiHandleButtonData *data)
 +{
 +      ui_apply_but_func(C, but);
 +      data->retval= but->retval;
 +      data->applied= 1;
 +}
 +
  
  static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, int interactive)
  {
                case WAVEFORM:
                        ui_apply_but_WAVEFORM(C, but, data);
                        break;
 +              case TRACKPREVIEW:
 +                      ui_apply_but_TRACKPREVIEW(C, but, data);
 +                      break;
                default:
                        break;
        }
@@@ -4072,88 -4060,6 +4071,88 @@@ static int ui_do_but_LINK(bContext *C, 
        return WM_UI_HANDLER_CONTINUE;
  }
  
 +static int ui_numedit_but_TRACKPREVIEW(bContext *C, uiBut *but, uiHandleButtonData *data, int mx, int my, int shift)
 +{
 +      MovieClipScopes *scopes = (MovieClipScopes *)but->poin;
 +      int changed= 1;
 +      float dx, dy;
 +
 +      dx = mx - data->draglastx;
 +      dy = my - data->draglasty;
 +
 +      if(shift) {
 +              dx /= 5.0f;
 +              dy /= 5.0f;
 +      }
 +
 +      if (in_scope_resize_zone(but, data->dragstartx, data->dragstarty)) {
 +               /* resize preview widget itself */
 +              scopes->track_preview_height = (but->y2 - but->y1) + (data->dragstarty - my);
 +      } else {
 +              if(scopes->marker) {
 +                      if(scopes->marker->framenr!=scopes->framenr)
 +                              scopes->marker= BKE_tracking_ensure_marker(scopes->track, scopes->framenr);
 +
 +                      scopes->marker->flag&= ~(MARKER_DISABLED|MARKER_TRACKED);
 +                      scopes->marker->pos[0]+= -dx*scopes->slide_scale[0] / (but->block->maxx-but->block->minx);
 +                      scopes->marker->pos[1]+= -dy*scopes->slide_scale[1] / (but->block->maxy-but->block->miny);
 +
 +                      WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, NULL);
 +              }
 +
 +              scopes->ok= 0;
 +      }
 +
 +      data->draglastx= mx;
 +      data->draglasty= my;
 +
 +      return changed;
 +}
 +
 +static int ui_do_but_TRACKPREVIEW(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, wmEvent *event)
 +{
 +      int mx, my;
 +
 +      mx= event->x;
 +      my= event->y;
 +      ui_window_to_block(data->region, block, &mx, &my);
 +
 +      if(data->state == BUTTON_STATE_HIGHLIGHT) {
 +              if(event->type==LEFTMOUSE && event->val==KM_PRESS) {
 +                      data->dragstartx= mx;
 +                      data->dragstarty= my;
 +                      data->draglastx= mx;
 +                      data->draglasty= my;
 +                      button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
 +
 +                      /* also do drag the first time */
 +                      if(ui_numedit_but_TRACKPREVIEW(C, but, data, mx, my, event->shift))
 +                              ui_numedit_apply(C, block, but, data);
 +
 +                      return WM_UI_HANDLER_BREAK;
 +              }
 +      }
 +      else if(data->state == BUTTON_STATE_NUM_EDITING) {
 +              if(event->type == ESCKEY) {
 +                      data->cancel= 1;
 +                      data->escapecancel= 1;
 +                      button_activate_state(C, but, BUTTON_STATE_EXIT);
 +              }
 +              else if(event->type == MOUSEMOVE) {
 +                      if(mx!=data->draglastx || my!=data->draglasty) {
 +                              if(ui_numedit_but_TRACKPREVIEW(C, but, data, mx, my, event->shift))
 +                                      ui_numedit_apply(C, block, but, data);
 +                      }
 +              }
 +              else if(event->type==LEFTMOUSE && event->val!=KM_PRESS) {
 +                      button_activate_state(C, but, BUTTON_STATE_EXIT);
 +              }
 +              return WM_UI_HANDLER_BREAK;
 +      }
 +
 +      return WM_UI_HANDLER_CONTINUE;
 +}
 +
  static void but_shortcut_name_func(bContext *C, void *arg1, int UNUSED(event))
  {
        uiBut *but = (uiBut *)arg1;
@@@ -4681,9 -4587,6 +4680,9 @@@ static int ui_do_button(bContext *C, ui
        case INLINK:
                retval= ui_do_but_LINK(C, but, data, event);
                break;
 +      case TRACKPREVIEW:
 +              retval= ui_do_but_TRACKPREVIEW(C, block, but, data, event);
 +              break;
        }
        
        return retval;
index c3470a6c56fc504fe92e6d1d5ac78307dfd1a025,5e875e40f148809f9aeffeb8e91ada0898839ab2..45e6290cf18e660f261c078a511f518ae9f16ae4
@@@ -60,7 -60,6 +60,7 @@@
  #include "ED_screen.h"
  #include "ED_screen_types.h"
  #include "ED_fileselect.h"
 +#include "ED_clip.h"
  
  #include "UI_interface.h"
  
@@@ -534,8 -533,7 +534,7 @@@ int screen_area_join(bContext *C, bScre
        dir = area_getorientation(sa1, sa2);
        /*printf("dir is : %i \n", dir);*/
        
-       if (dir < 0)
-       {
+       if (dir < 0) {
                if (sa1 ) sa1->flag &= ~AREA_FLAG_DRAWJOINFROM;
                if (sa2 ) sa2->flag &= ~AREA_FLAG_DRAWJOINTO;
                return 0;
@@@ -1813,8 -1811,6 +1812,8 @@@ void ED_update_for_newframe(Main *bmain
         * call before scene_update_for_newframe so modifiers with textuers dont lag 1 frame */
        ED_image_update_frame(bmain, scene->r.cfra);
  
 +      ED_clip_update_frame(bmain, scene->r.cfra);
 +
        /* this function applies the changes too */
        /* XXX future: do all windows */
        scene_update_for_newframe(bmain, scene, BKE_screen_visible_layers(screen, scene)); /* BKE_scene.h */
index afdd2a3403085a9e55f3cc7ec77cbcd6a26b5be2,0ac30853eaec7e5b3dcc009d4fc03d5bef79e0ab..807152c13a3b835437251ddfc4927477a125f561
@@@ -1544,8 -1544,7 +1544,7 @@@ static int area_max_regionsize(ScrArea 
        
        /* subtractwidth of regions on opposite side 
         * prevents dragging regions into other opposite regions */
-       for (ar=sa->regionbase.first; ar; ar=ar->next)
-       {
+       for (ar=sa->regionbase.first; ar; ar=ar->next) {
                if (ar == scalear)
                        continue;
                
@@@ -2021,12 -2020,12 +2020,12 @@@ static void SCREEN_OT_screen_full_area(
   */
  
  typedef struct sAreaJoinData
      {
-               ScrArea *sa1;   /* first area to be considered */
-               ScrArea *sa2;   /* second area to be considered */
-               ScrArea *scr;   /* designed for removal */
-               
      } sAreaJoinData;
+ {
+       ScrArea *sa1;   /* first area to be considered */
+       ScrArea *sa2;   /* second area to be considered */
+       ScrArea *scr;   /* designed for removal */
+ } sAreaJoinData;
  
  
  /* validate selection inside screen, set variables OK */
@@@ -2770,23 -2769,10 +2769,23 @@@ static int match_region_with_redraws(in
                                if(redraws & TIME_ALL_IMAGE_WIN)
                                        return 1;
                                break;
 +                      case SPACE_CLIP:
 +                              if(redraws & TIME_CLIPS)
 +                                      return 1;
 +                              break;
                                
                }
        }
        else if(regiontype==RGN_TYPE_UI) {
 +              if(spacetype==SPACE_CLIP) {
 +                      /* Track Preview button is on Properties Editor in SpaceClip,
 +                         and it's very common case when users want it be refreshing
 +                         during playback, so asking people to enable special option
 +                         for this is a bit ticky, so add exception here for refreshing
 +                         Properties Editor for SpaceClip always */
 +                      return 1;
 +              }
 +
                if(redraws & TIME_ALL_BUTS_WIN)
                        return 1;
        }
index 28ac3361cad29f71036dc3438390a2e3986850a8,638d197ccf7ddca9cc2abe5ef4f960218eea0329..4a3cee5765bcc2e4933b4363184740bc77604625
@@@ -74,8 -74,6 +74,8 @@@
  #include "BKE_particle.h"
  #include "BKE_pointcache.h"
  #include "BKE_unit.h"
 +#include "BKE_movieclip.h"
 +#include "BKE_tracking.h"
  
  #include "smoke_API.h"
  
@@@ -202,40 -200,6 +202,40 @@@ static void view3d_project_short_noclip
        }
  }
  
 +/* same as view3d_project_short_clip but use persmat instead of persmatob for projection */
 +static void view3d_project_short_clip_persmat(ARegion *ar, float *vec, short *adr, int local)
 +{
 +      RegionView3D *rv3d= ar->regiondata;
 +      float fx, fy, vec4[4];
 +
 +      adr[0]= IS_CLIPPED;
 +
 +      /* clipplanes in eye space */
 +      if(rv3d->rflag & RV3D_CLIPPING) {
 +              if(ED_view3d_test_clipping(rv3d, vec, local))
 +                      return;
 +      }
 +
 +      copy_v3_v3(vec4, vec);
 +      vec4[3]= 1.0;
 +
 +      mul_m4_v4(rv3d->persmat, vec4);
 +
 +      /* clipplanes in window space */
 +      if( vec4[3] > (float)BL_NEAR_CLIP ) {   /* is the NEAR clipping cutoff for picking */
 +              fx= (ar->winx/2)*(1 + vec4[0]/vec4[3]);
 +
 +              if( fx>0 && fx<ar->winx) {
 +
 +                      fy= (ar->winy/2)*(1 + vec4[1]/vec4[3]);
 +
 +                      if(fy > 0.0f && fy < (float)ar->winy) {
 +                              adr[0]= (short)floorf(fx);
 +                              adr[1]= (short)floorf(fy);
 +                      }
 +              }
 +      }
 +}
  /* ************************ */
  
  /* check for glsl drawing */
@@@ -744,12 -708,7 +744,12 @@@ void view3d_cached_text_draw_end(View3
        for(vos= strings->first; vos; vos= vos->next) {
                if(mat && !(vos->flag & V3D_CACHE_TEXT_WORLDSPACE))
                        mul_m4_v3(mat, vos->vec);
 -              view3d_project_short_clip(ar, vos->vec, vos->sco, 0);
 +
 +              if(vos->flag&V3D_CACHE_TEXT_GLOBALSPACE)
 +                      view3d_project_short_clip_persmat(ar, vos->vec, vos->sco, 0);
 +              else
 +                      view3d_project_short_clip(ar, vos->vec, vos->sco, 0);
 +
                if(vos->sco[0]!=IS_CLIPPED)
                        tot++;
        }
@@@ -1376,198 -1335,16 +1376,198 @@@ static void draw_focus_cross(float dist
        glEnd();
  }
  
 +/* ****************** draw clip data *************** */
 +
 +static void draw_bundle_sphere(void)
 +{
 +      static GLuint displist= 0;
 +
 +      if (displist == 0) {
 +              GLUquadricObj *qobj;
 +
 +              displist= glGenLists(1);
 +              glNewList(displist, GL_COMPILE);
 +
 +              qobj= gluNewQuadric();
 +              gluQuadricDrawStyle(qobj, GLU_FILL);
 +              glShadeModel(GL_SMOOTH);
 +              gluSphere(qobj, 0.05, 8, 8);
 +              glShadeModel(GL_FLAT);
 +              gluDeleteQuadric(qobj);
 +
 +              glEndList();
 +      }
 +
 +      glCallList(displist);
 +}
 +
 +static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d, MovieClip *clip, int flag)
 +{
 +      MovieTracking *tracking= &clip->tracking;
 +      MovieTrackingTrack *track;
 +      float mat[4][4], imat[4][4], curcol[4];
 +      unsigned char col[4], scol[4];
 +      int bundlenr= 1;
 +
 +      if((v3d->flag2&V3D_SHOW_RECONSTRUCTION)==0)
 +              return;
 +
 +      if(v3d->flag2&V3D_RENDER_OVERRIDE)
 +              return;
 +
 +      glGetFloatv(GL_CURRENT_COLOR, curcol);
 +
 +      UI_GetThemeColor4ubv(TH_TEXT, col);
 +      UI_GetThemeColor4ubv(TH_SELECT, scol);
 +
 +      BKE_get_tracking_mat(scene, mat);
 +
 +      glEnable(GL_LIGHTING);
 +      glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
 +      glEnable(GL_COLOR_MATERIAL);
 +      glShadeModel(GL_SMOOTH);
 +
 +      /* current ogl matrix is translated in camera space, bundles should
 +         be rendered in world space, so camera matrix should be "removed"
 +         from current ogl matrix */
 +      invert_m4_m4(imat, base->object->obmat);
 +
 +      glPushMatrix();
 +      glMultMatrixf(imat);
 +      glMultMatrixf(mat);
 +
 +      for ( track= tracking->tracks.first; track; track= track->next) {
 +              int selected= track->flag&SELECT || track->pat_flag&SELECT || track->search_flag&SELECT;
 +              if((track->flag&TRACK_HAS_BUNDLE)==0)
 +                      continue;
 +
 +              if(flag&DRAW_PICKING)
 +                      glLoadName(base->selcol + (bundlenr<<16));
 +
 +              glPushMatrix();
 +                      glTranslatef(track->bundle_pos[0], track->bundle_pos[1], track->bundle_pos[2]);
 +                      glScalef(v3d->bundle_size/0.05, v3d->bundle_size/0.05, v3d->bundle_size/0.05);
 +
 +                      if(v3d->drawtype==OB_WIRE) {
 +                              glDisable(GL_LIGHTING);
 +                              glDepthMask(0);
 +
 +                              if(selected) {
 +                                      if(base==BASACT) UI_ThemeColor(TH_ACTIVE);
 +                                      else UI_ThemeColor(TH_SELECT);
 +                              } else {
 +                                      if(track->flag&TRACK_CUSTOMCOLOR) glColor3fv(track->color);
 +                                      else UI_ThemeColor(TH_WIRE);
 +                              }
 +
 +                              drawaxes(0.05f, v3d->bundle_drawtype);
 +
 +                              glDepthMask(1);
 +                              glEnable(GL_LIGHTING);
 +                      } else if(v3d->drawtype>OB_WIRE) {
 +                              if(v3d->bundle_drawtype==OB_EMPTY_SPHERE) {
 +                                      /* selection outline */
 +                                      if(selected) {
 +                                              if(base==BASACT) UI_ThemeColor(TH_ACTIVE);
 +                                              else UI_ThemeColor(TH_SELECT);
 +
 +                                              glDepthMask(0);
 +                                              glLineWidth(2.f);
 +                                              glDisable(GL_LIGHTING);
 +                                              glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
 +
 +                                              draw_bundle_sphere();
 +
 +                                              glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 +                                              glEnable(GL_LIGHTING);
 +                                              glLineWidth(1.f);
 +                                              glDepthMask(1);
 +                                      }
 +
 +                                      if(track->flag&TRACK_CUSTOMCOLOR) glColor3fv(track->color);
 +                                      else UI_ThemeColor(TH_BUNDLE_SOLID);
 +
 +                                      draw_bundle_sphere();
 +                              } else {
 +                                      glDisable(GL_LIGHTING);
 +                                      glDepthMask(0);
 +
 +                                      if(selected) {
 +                                              if(base==BASACT) UI_ThemeColor(TH_ACTIVE);
 +                                              else UI_ThemeColor(TH_SELECT);
 +                                      } else {
 +                                              if(track->flag&TRACK_CUSTOMCOLOR) glColor3fv(track->color);
 +                                              else UI_ThemeColor(TH_WIRE);
 +                                      }
 +
 +                                      drawaxes(0.05f, v3d->bundle_drawtype);
 +
 +                                      glDepthMask(1);
 +                                      glEnable(GL_LIGHTING);
 +                              }
 +                      }
 +
 +              glPopMatrix();
 +
 +              if((flag & DRAW_PICKING)==0 && (v3d->flag2&V3D_SHOW_BUNDLENAME)) {
 +                      float pos[3];
 +                      unsigned char tcol[4];
 +
 +                      if(selected) memcpy(tcol, scol, sizeof(tcol));
 +                      else memcpy(tcol, col, sizeof(tcol));
 +
 +                      mul_v3_m4v3(pos, mat, track->bundle_pos);
 +                      view3d_cached_text_draw_add(pos, track->name, 10, V3D_CACHE_TEXT_GLOBALSPACE, tcol);
 +              }
 +
 +              bundlenr++;
 +      }
 +
 +      if((flag & DRAW_PICKING)==0) {
 +              if(v3d->flag2&V3D_SHOW_CAMERAPATH && clip->tracking.reconstruction.camnr) {
 +                      int a= 0;
 +                      MovieTrackingReconstruction *reconstruction= &tracking->reconstruction;
 +                      MovieReconstructedCamera *camera= tracking->reconstruction.cameras;
 +
 +                      glDisable(GL_LIGHTING);
 +                      UI_ThemeColor(TH_CAMERA_PATH);
 +                      glLineWidth(2.0f);
 +
 +                      glBegin(GL_LINE_STRIP);
 +                              for(a= 0; a<reconstruction->camnr; a++, camera++) {
 +                                      glVertex3f(camera->mat[3][0], camera->mat[3][1], camera->mat[3][2]);
 +                              }
 +                      glEnd();
 +
 +                      glLineWidth(1.0f);
 +                      glEnable(GL_LIGHTING);
 +              }
 +      }
 +
 +      glPopMatrix();
 +
 +      /* restore */
 +      glShadeModel(GL_FLAT);
 +      glDisable(GL_COLOR_MATERIAL);
 +      glDisable(GL_LIGHTING);
 +
 +      glColor4fv(curcol);
 +
 +      if(flag&DRAW_PICKING)
 +              glLoadName(base->selcol);
 +}
 +
  #ifdef VIEW3D_CAMERA_BORDER_HACK
  float view3d_camera_border_hack_col[4];
  short view3d_camera_border_hack_test= FALSE;
  #endif
  
  /* flag similar to draw_object() */
 -static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, int flag)
 +static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int flag)
  {
        /* a standing up pyramid with (0,0,0) as top */
        Camera *cam;
 +      Object *ob= base->object;
        float vec[8][4], facx, facy, depth, aspx, aspy, caspx, caspy, shx, shy;
        int i;
        float drawsize;
        const float scay= 1.0f / len_v3(ob->obmat[1]);
        const float scaz= 1.0f / len_v3(ob->obmat[2]);
  
 +      /* draw data for movie clip set as active for scene */
 +      if(scene->clip)
 +              draw_viewport_reconstruction(scene, base, v3d, scene->clip, flag);
 +
  #ifdef VIEW3D_CAMERA_BORDER_HACK
        if(is_view && !(G.f & G_PICKSEL)) {
                glGetFloatv(GL_CURRENT_COLOR, view3d_camera_border_hack_col);
                if(is_view) {
                        /* fixed depth, variable size (avoids exceeding clipping range) */
                        depth = -(cam->clipsta + 0.1f);
 -                      fac = depth / (cam->lens/-16.0f * scaz);
 +                      fac = depth / (cam->lens/ (cam->sensor_x / 2.0f));
                }
                else {
                        /* fixed size, variable depth (stays a reasonable size in the 3D view) */
@@@ -3071,7 -2844,18 +3071,18 @@@ static int draw_mesh_object(Scene *scen
        Object *obedit= scene->obedit;
        Mesh *me= ob->data;
        EditMesh *em= me->edit_mesh;
-       int do_alpha_pass= 0, drawlinked= 0, retval= 0, glsl, check_alpha;
+       int do_alpha_pass= 0, drawlinked= 0, retval= 0, glsl, check_alpha, i;
+       /* If we are drawing shadows and any of the materials don't cast a shadow,
+        * then don't draw the object */
+       if (v3d->flag2 & V3D_RENDER_SHADOW) {
+               for(i=0; i<ob->totcol; ++i) {
+                       Material *ma= give_current_material(ob, i);
+                       if (ma && !(ma->mode & MA_SHADBUF)) {
+                               return 1;
+                       }
+               }
+       }
        
        if(obedit && ob!=obedit && ob->data==obedit->data) {
                if(ob_get_key(ob) || ob_get_key(obedit));
@@@ -6244,7 -6028,7 +6255,7 @@@ void draw_object(Scene *scene, ARegion 
                        break;
                case OB_CAMERA:
                        if((v3d->flag2 & V3D_RENDER_OVERRIDE)==0 || (rv3d->persp==RV3D_CAMOB && v3d->camera==ob)) /* special exception for active camera */
 -                              drawcamera(scene, v3d, rv3d, ob, flag);
 +                              drawcamera(scene, v3d, rv3d, base, flag);
                        break;
                case OB_LATTICE:
                        if((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) {
        }
  
        /* draw code for smoke */
-       if((md = modifiers_findByType(ob, eModifierType_Smoke)))
-       {
+       if((md = modifiers_findByType(ob, eModifierType_Smoke))) {
                SmokeModifierData *smd = (SmokeModifierData *)md;
  
                // draw collision objects
@@@ -6733,7 -6516,6 +6743,6 @@@ void draw_object_backbufsel(Scene *scen
  
        switch( ob->type) {
        case OB_MESH:
-       {
                if(ob->mode & OB_MODE_EDIT) {
                        Mesh *me= ob->data;
                        EditMesh *em= me->edit_mesh;
  
                        EM_free_index_arrays();
                }
-               else bbs_mesh_solid(scene, ob);
-       }
+               else {
+                       bbs_mesh_solid(scene, ob);
+               }
                break;
        case OB_CURVE:
        case OB_SURF:
index 4803e9036613d6a6bee235b13c3c0c7a3946fb59,80da75bc603344286b98a5cc92e2615415e36407..b37abacff911bc639eb6ac3c976a8c155c122c57
@@@ -63,7 -63,6 +63,7 @@@
  #include "BKE_scene.h"
  #include "BKE_screen.h"
  #include "BKE_unit.h"
 +#include "BKE_movieclip.h"
  
  #include "RE_pipeline.h"      // make_stars
  
@@@ -1142,12 -1141,10 +1142,10 @@@ static void drawviewborder(Scene *scene
        glRectf(x1i, y1i, x2i, y2i);
  
  #ifdef VIEW3D_CAMERA_BORDER_HACK
-       {
-               if(view3d_camera_border_hack_test == TRUE) {
-                       glColor4fv(view3d_camera_border_hack_col);
-                       glRectf(x1i+1, y1i+1, x2i-1, y2i-1);
-                       view3d_camera_border_hack_test= FALSE;
-               }
+       if(view3d_camera_border_hack_test == TRUE) {
+               glColor4fv(view3d_camera_border_hack_col);
+               glRectf(x1i+1, y1i+1, x2i-1, y2i-1);
+               view3d_camera_border_hack_test= FALSE;
        }
  #endif
  
                        uiSetRoundBox(15);
                        uiDrawBox(GL_LINE_LOOP, x1, y1, x2, y2, 12.0);
                }
 +              if (ca && (ca->flag & CAM_SHOWSENSOR)) {
 +                      /* assume fixed sensor width for now */
 +                      float aspx = (float) scene->r.xsch*scene->r.xasp;
 +                      float aspy = (float) scene->r.ysch*scene->r.yasp;
 +                      float sensor_scale = (x2i-x1i) / ca->sensor_x;
 +                      float sensor_height, ymid, sy1, sy2;
 +
 +                      if(aspx < aspy) sensor_height = ca->sensor_x * sensor_scale * aspx / aspy;
 +                      else sensor_height = ca->sensor_x * sensor_scale * aspy / aspx;
 +
 +                      ymid = y1i + (y2i-y1i)/2.f;
 +                      sy1= ymid - sensor_height/2.f;
 +                      sy2= ymid + sensor_height/2.f;
 +
 +                      UI_ThemeColorShade(TH_WIRE, 100);
 +
 +                      uiDrawBox(GL_LINE_LOOP, x1i, sy1, x2i, sy2, 2.0);
 +              }
        }
  
        setlinestyle(0);
@@@ -1500,8 -1479,7 +1498,8 @@@ static void draw_bgpic(Scene *scene, AR
        RegionView3D *rv3d= ar->regiondata;
        BGpic *bgpic;
        Image *ima;
 -      ImBuf *ibuf= NULL;
 +      MovieClip *clip;
 +      ImBuf *ibuf= NULL, *freeibuf;
        float vec[4], fac, asp, zoomx, zoomy;
        float x1, y1, x2, y2, cx, cy;
  
                        (bgpic->view & (1<<rv3d->view)) || /* check agaist flags */
                        (rv3d->persp==RV3D_CAMOB && bgpic->view == (1<<RV3D_VIEW_CAMERA))
                ) {
 -                      ima= bgpic->ima;
 -                      if(ima==NULL)
 -                              continue;
 -                      BKE_image_user_calc_frame(&bgpic->iuser, CFRA, 0);
 -                      ibuf= BKE_image_get_ibuf(ima, &bgpic->iuser);
 -                      if(ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL) )
 +                      freeibuf= NULL;
 +                      if(bgpic->source==V3D_BGPIC_IMAGE) {
 +                              ima= bgpic->ima;
 +                              if(ima==NULL)
 +                                      continue;
 +                              BKE_image_user_calc_frame(&bgpic->iuser, CFRA, 0);
 +                              ibuf= BKE_image_get_ibuf(ima, &bgpic->iuser);
 +                      } else {
 +                              clip= bgpic->clip;
 +                              if(clip==NULL)
 +                                      continue;
 +                              BKE_movieclip_user_set_frame(&bgpic->cuser, CFRA);
 +                              ibuf= BKE_movieclip_acquire_ibuf(clip, &bgpic->cuser);
 +
 +                              /* working with ibuf from image and clip has got different workflow now.
 +                                 ibuf acquired from clip is referenced by cache system and should
 +                                 be dereferenced after usage. */
 +                              freeibuf= ibuf;
 +                      }
 +
 +                      if(ibuf==NULL)
                                continue;
 -                      if(ibuf->channels!=4)
 +
 +                      if((ibuf->rect==NULL && ibuf->rect_float==NULL) || ibuf->channels!=4) { /* invalid image format */
 +                              if(freeibuf)
 +                                      IMB_freeImBuf(freeibuf);
 +
                                continue;
 +                      }
 +
                        if(ibuf->rect==NULL)
                                IMB_rect_from_float(ibuf);
  
  
                        /* complete clip? */
  
 -                      if(x2 < 0 ) continue;
 -                      if(y2 < 0 ) continue;
 -                      if(x1 > ar->winx ) continue;
 -                      if(y1 > ar->winy ) continue;
 +                      if(x2 < 0 || y2 < 0 || x1 > ar->winx || y1 > ar->winy) {
 +                              if(freeibuf)
 +                                      IMB_freeImBuf(freeibuf);
 +
 +                              continue;
 +                      }
  
                        zoomx= (x2-x1)/ibuf->x;
                        zoomy= (y2-y1)/ibuf->y;
  
                        glDepthMask(1);
                        if(v3d->zbuf) glEnable(GL_DEPTH_TEST);
 +
 +                      if(freeibuf)
 +                              IMB_freeImBuf(freeibuf);
                }
        }
  }
@@@ -2201,7 -2153,7 +2199,7 @@@ static void gpu_update_lamps_shadows(Sc
                v3d->drawtype = OB_SOLID;
                v3d->lay &= GPU_lamp_shadow_layer(shadow->lamp);
                v3d->flag2 &= ~V3D_SOLID_TEX;
-               v3d->flag2 |= V3D_RENDER_OVERRIDE;
+               v3d->flag2 |= V3D_RENDER_OVERRIDE | V3D_RENDER_SHADOW;
                
                GPU_lamp_shadow_buffer_bind(shadow->lamp, viewmat, &winsize, winmat);
  
@@@ -2458,10 -2410,10 +2456,10 @@@ ImBuf *ED_view3d_draw_offscreen_imbuf(S
        /* render 3d view */
        if(rv3d->persp==RV3D_CAMOB && v3d->camera) {
                float winmat[4][4];
 -              float _clipsta, _clipend, _lens, _yco, _dx, _dy;
 +              float _clipsta, _clipend, _lens, _yco, _dx, _dy, _sensor_x=0;
                rctf _viewplane;
  
 -              object_camera_matrix(&scene->r, v3d->camera, sizex, sizey, 0, winmat, &_viewplane, &_clipsta, &_clipend, &_lens, &_yco, &_dx, &_dy);
 +              object_camera_matrix(&scene->r, v3d->camera, sizex, sizey, 0, winmat, &_viewplane, &_clipsta, &_clipend, &_lens, &_sensor_x, &_yco, &_dx, &_dy);
  
                ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat);
        }
@@@ -2516,9 -2468,9 +2514,9 @@@ ImBuf *ED_view3d_draw_offscreen_imbuf_s
        invert_m4_m4(rv3d.viewmat, rv3d.viewinv);
  
        {
 -              float _yco, _dx, _dy;
 +              float _yco, _dx, _dy, _sensor_x=0;
                rctf _viewplane;
 -              object_camera_matrix(&scene->r, v3d.camera, width, height, 0, rv3d.winmat, &_viewplane, &v3d.near, &v3d.far, &v3d.lens, &_yco, &_dx, &_dy);
 +              object_camera_matrix(&scene->r, v3d.camera, width, height, 0, rv3d.winmat, &_viewplane, &v3d.near, &v3d.far, &v3d.lens, &_sensor_x, &_yco, &_dx, &_dy);
        }
  
        mul_m4_m4m4(rv3d.persmat, rv3d.viewmat, rv3d.winmat);
index d763ee94b4a0bc385fd8c9c0fb0a118e3ed8da88,65914ead899de7a511965209277c422acab1d89c..035e2993f86b3c6959b5d9ff20ac18f242c960fc
@@@ -44,7 -44,6 +44,7 @@@
  #include "DNA_meshdata_types.h"
  #include "DNA_object_types.h"
  #include "DNA_scene_types.h"
 +#include "DNA_tracking_types.h"
  
  #include "MEM_guardedalloc.h"
  
@@@ -58,8 -57,6 +58,8 @@@
  #include "BKE_context.h"
  #include "BKE_paint.h"
  #include "BKE_armature.h"
 +#include "BKE_movieclip.h"
 +#include "BKE_tracking.h"
  
  
  #include "BIF_gl.h"
@@@ -1234,8 -1231,8 +1234,8 @@@ static int mouse_select(bContext *C, co
        if(BASACT && BASACT->next) startbase= BASACT->next;
        
        /* This block uses the control key to make the object selected by its center point rather than its contents */
-       /* XXX later on, in editmode do not activate */
-       if(vc.obedit==NULL && obcenter) {
+       /* in editmode do not activate */
+       if(obcenter) {
                
                /* note; shift+alt goes to group-flush-selecting */
                if(enumerate) {
                if(hits>0) {
                        int has_bones= 0;
                        
 +                      /* note: bundles are handling in the same way as bones */
                        for(a=0; a<hits; a++) if(buffer[4*a+3] & 0xFFFF0000) has_bones= 1;
  
                        /* note; shift+alt goes to group-flush-selecting */
                        }
                        
                        if(has_bones && basact) {
 -                              if(ED_do_pose_selectbuffer(scene, basact, buffer, hits, extend) ) {     /* then bone is found */
 +                              if(basact->object->type==OB_CAMERA) {
 +                                      if(BASACT==basact) {
 +                                              int i, hitresult;
 +                                              MovieTrackingTrack *track;
 +
 +                                              for (i=0; i< hits; i++) {
 +                                                      hitresult= buffer[3+(i*4)];
 +
 +                                                      /* if there's bundles in buffer select bundles first,
 +                                                         so non-camera elements should be ignored in buffer */
 +                                                      if(basact->selcol != (hitresult & 0xFFFF))
 +                                                              continue;
 +
 +                                                      /* index of bundle is 1<<16-based. if there's no "bone" index
 +                                                         in hight word, this buffer value belongs to camera,. not to bundle */
 +                                                      if(buffer[4*i+3] & 0xFFFF0000) {
 +                                                              track= BKE_tracking_indexed_bundle(&scene->clip->tracking, hitresult >> 16);
 +
 +                                                              if(TRACK_SELECTED(track) && extend) BKE_movieclip_deselect_track(scene->clip, track, TRACK_AREA_ALL);
 +                                                              else BKE_movieclip_select_track(scene->clip, track, TRACK_AREA_ALL, extend);
 +
 +                                                              basact->flag|= SELECT;
 +                                                              basact->object->flag= basact->flag;
 +
 +                                                              retval= 1;
 +
 +                                                              WM_event_add_notifier(C, NC_MOVIECLIP|ND_SELECT, track);
 +                                                              WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
 +
 +                                                              break;
 +                                                      }
 +                                              }
 +                                      }
 +                              }
 +                              else if(ED_do_pose_selectbuffer(scene, basact, buffer, hits, extend) ) {        /* then bone is found */
                                
                                        /* we make the armature selected: 
                                           not-selected active object in posemode won't work well for tools */
@@@ -1803,9 -1765,15 +1803,15 @@@ static int view3d_borderselect_exec(bCo
                case OB_CURVE:
                case OB_SURF:
                        ret= do_nurbs_box_select(&vc, &rect, select, extend);
+                       if(ret & OPERATOR_FINISHED) {
+                               WM_event_add_notifier(C, NC_GEOM|ND_SELECT, vc.obedit->data);
+                       }
                        break;
                case OB_MBALL:
                        ret= do_meta_box_select(&vc, &rect, select, extend);
+                       if(ret & OPERATOR_FINISHED) {
+                               WM_event_add_notifier(C, NC_GEOM|ND_SELECT, vc.obedit->data);
+                       }
                        break;
                case OB_ARMATURE:
                        ret= do_armature_box_select(&vc, &rect, select, extend);
@@@ -1876,11 -1844,22 +1882,22 @@@ static int view3d_select_invoke(bContex
        short extend= RNA_boolean_get(op->ptr, "extend");
        short center= RNA_boolean_get(op->ptr, "center");
        short enumerate= RNA_boolean_get(op->ptr, "enumerate");
+       short object= RNA_boolean_get(op->ptr, "object");
        int     retval = 0;
  
        view3d_operator_needs_opengl(C);
  
-       if(obedit && center==FALSE) {
+       if(object) {
+               obedit= NULL;
+               obact= NULL;
+               /* ack, this is incorrect but to do this correctly we would need an
+                * alternative editmode/objectmode keymap, this copies the functionality
+                * from 2.4x where Ctrl+Select in editmode does object select only */
+               center= FALSE;
+       }
+       if(obedit && object==FALSE) {
                if(obedit->type==OB_MESH)
                        retval = mouse_mesh(C, event->mval, extend);
                else if(obedit->type==OB_ARMATURE)
@@@ -1929,6 -1908,7 +1946,7 @@@ void VIEW3D_OT_select(wmOperatorType *o
        RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend selection instead of deselecting everything first.");
        RNA_def_boolean(ot->srna, "center", 0, "Center", "Use the object center when selecting, in editmode used to extend object selection.");
        RNA_def_boolean(ot->srna, "enumerate", 0, "Enumerate", "List objects under the mouse (object mode only).");
+       RNA_def_boolean(ot->srna, "object", 0, "Object", "Use object selection (editmode only).");
  }
  
  
index acb6f5c1268ade428770163d2b8b2fc7b737952a,c48459108ebd67d93103bd0b2875620d1223a8f7..c06b9ae2cb4be5b0c8e327d20fb0b4cc2e15926d
@@@ -840,8 -840,7 +840,7 @@@ void project_int_noclip(ARegion *ar, co
                adr[0] = (int)floor(fx); 
                adr[1] = (int)floor(fy);
        }
-       else
-       {
+       else {
                adr[0] = ar->winx / 2;
                adr[1] = ar->winy / 2;
        }
@@@ -904,8 -903,7 +903,7 @@@ void project_float_noclip(ARegion *ar, 
                adr[0] = (float)(ar->winx/2.0f)+(ar->winx/2.0f)*vec4[0]/vec4[3];
                adr[1] = (float)(ar->winy/2.0f)+(ar->winy/2.0f)*vec4[1]/vec4[3];
        }
-       else
-       {
+       else {
                adr[0] = ar->winx / 2.0f;
                adr[1] = ar->winy / 2.0f;
        }
@@@ -950,7 -948,7 +948,7 @@@ int ED_view3d_clip_range_get(View3D *v3
  int ED_view3d_viewplane_get(View3D *v3d, RegionView3D *rv3d, int winxi, int winyi, rctf *viewplane, float *clipsta, float *clipend, float *pixsize)
  {
        Camera *cam=NULL;
 -      float lens, fac, x1, y1, x2, y2;
 +      float lens, sensor=32.f, fac, x1, y1, x2, y2;
        float winx= (float)winxi, winy= (float)winyi;
        int orth= 0;
        
                        else if(v3d->camera->type==OB_CAMERA) {
                                cam= v3d->camera->data;
                                lens= cam->lens;
 +                              sensor= cam->sensor_x;
                                *clipsta= cam->clipsta;
                                *clipend= cam->clipend;
                        }
                else {
                        float dfac;
                        
 -                      if(winx>winy) dfac= 64.0f/(fac*winx*lens);
 -                      else dfac= 64.0f/(fac*winy*lens);
 +                      if(winx>winy) dfac= (sensor * 2.0) / (fac*winx*lens);
 +                      else dfac= (sensor * 2.0) / (fac*winy*lens);
                        
                        x1= - *clipsta * winx*dfac;
                        x2= -x1;
                                dy += cam->shifty * cam->ortho_scale;
                        }
                        else {
 -                              dx += cam->shiftx * (cam->clipsta / cam->lens) * 32.0f;
 -                              dy += cam->shifty * (cam->clipsta / cam->lens) * 32.0f;
 +                              dx += cam->shiftx * (cam->clipsta / cam->lens) * sensor;
 +                              dy += cam->shifty * (cam->clipsta / cam->lens) * sensor;
                        }
  
                        x1+= dx;
index d199b7662926be77f89bb72735201952b6f145b5,67899db5538c9bd7bfe8c40a0c25f13b1ee80c65..40d296c7837bf5edb878be4cce53bc5e9f897559
@@@ -39,7 -39,6 +39,7 @@@
  #include "DNA_vec_types.h"
  #include "DNA_outliner_types.h"               /* for TreeStoreElem */
  #include "DNA_image_types.h"  /* ImageUser */
 +#include "DNA_movieclip_types.h"      /* MovieClipUser */
  /* Hum ... Not really nice... but needed for spacebuts. */
  #include "DNA_view2d_types.h"
  
@@@ -65,8 -64,6 +65,8 @@@ struct bScreen
  struct Scene;
  struct wmOperator;
  struct wmTimer;
 +struct MovieClip;
 +struct MovieClipScopes;
  
        /**
         * The base structure all the other spaces
@@@ -270,7 -267,7 +270,7 @@@ typedef struct SpaceImage 
        float centx, centy;                             /* storage for offset while render drawing */
  
        short curtile; /* the currently active tile of the image when tile is enabled, is kept in sync with the active faces tile */
-       short imtypenr;
+       short pad;
        short lock;
        short pin;
        char dt_uv; /* UV draw type */
@@@ -565,29 -562,6 +565,29 @@@ typedef struct SpaceSound 
        int pad2;
  } SpaceSound;
  
 +typedef struct SpaceClip {
 +      SpaceLink *next, *prev;
 +      ListBase regionbase;            /* storage of regions for inactive spaces */
 +      int spacetype;
 +
 +      float xof, yof;                         /* user defined offset, image is centered */
 +      float zoom;                                     /* user defined zoom level */
 +
 +      struct MovieClipUser user;              /* user of clip */
 +      struct MovieClip *clip;                 /* clip data */
 +      struct MovieClipScopes scopes;  /* different scoped displayed in space panels */
 +
 +      int flag;                                       /* flags */
 +      int mode;                                       /*editor mode */
 +
 +      int path_length;                        /* length of displaying path, in frames */
 +
 +      /* current stabilization data */
 +      float loc[2], scale;    /* pre-composed stabilization data */
 +      float stabmat[4][4];    /* current stabilization matrix, defined when drawing
 +                                                         and used for mouse position calculation */
 +} SpaceClip;
 +
  /* view3d  Now in DNA_view3d_types.h */
  
  
@@@ -922,7 -896,6 +922,7 @@@ enum 
  #define TIME_ALL_IMAGE_WIN            64
  #define TIME_CONTINUE_PHYSICS 128
  #define TIME_NODES                            256
 +#define TIME_CLIPS                            512
  
  /* time->cache */
  #define TIME_CACHE_DISPLAY            1
  #define SEQ_PROXY_RENDER_SIZE_75        75
  #define SEQ_PROXY_RENDER_SIZE_FULL      100
  
 +/* SpaceClip->flag */
 +#define SC_SHOW_MARKER_PATTERN        (1<<0)
 +#define SC_SHOW_MARKER_SEARCH (1<<1)
 +#define SC_LOCK_SELECTION             (1<<2)
 +#define SC_SHOW_TINY_MARKER           (1<<3)
 +#define SC_SHOW_TRACK_PATH            (1<<4)
 +#define SC_SHOW_BUNDLES                       (1<<5)
 +#define SC_MUTE_FOOTAGE                       (1<<6)
 +#define SC_HIDE_DISABLED              (1<<7)
 +#define SC_SHOW_NAMES                 (1<<8)
 +#define SC_SHOW_GRID                  (1<<9)
 +#define SC_SHOW_STABLE                        (1<<10)
 +#define SC_MANUAL_CALIBRATION (1<<11)
 +#define SC_SHOW_GPENCIL                       (1<<12)
 +
 +/* SpaceClip->mode */
 +#define SC_MODE_TRACKING              0
 +#define SC_MODE_RECONSTRUCTION        1
 +#define SC_MODE_DISTORTION            2
  
  /* space types, moved from DNA_screen_types.h */
  /* Do NOT change order, append on end. types are hardcoded needed */
@@@ -1002,8 -956,7 +1002,8 @@@ enum 
        SPACE_LOGIC,
        SPACE_CONSOLE,
        SPACE_USERPREF,
 -      SPACEICONMAX = SPACE_USERPREF
 +      SPACE_CLIP,
 +      SPACEICONMAX = SPACE_CLIP
  };
  
  #endif
index 468309ae4cce4efaaa10dd54e3c7438c551c6d18,3c8d20a6f16d65902405ba32b098da05e068dfd5..28bac32db505b3394d806329e9c5ec964535973d
@@@ -40,8 -40,6 +40,8 @@@ struct Tex
  struct SpaceLink;
  struct Base;
  struct BoundBox;
 +struct MovieClip;
 +struct MovieClipUser;
  struct RenderInfo;
  struct bGPdata;
  struct SmoothViewStore;
@@@ -58,7 -56,6 +58,7 @@@ struct wmTimer
  
  #include "DNA_listBase.h"
  #include "DNA_image_types.h"
 +#include "DNA_movieclip_types.h"
  
  /* ******************************** */
  
@@@ -71,12 -68,10 +71,12 @@@ typedef struct BGpic 
  
        struct Image *ima;
        struct ImageUser iuser;
 +      struct MovieClip *clip;
 +      struct MovieClipUser cuser;
        float xof, yof, size, blend;
        short view;
        short flag;
 -      float pad2;
 +      short source, pad;
  } BGpic;
  
  /* ********************************* */
@@@ -151,12 -146,7 +151,12 @@@ typedef struct View3D 
        float blockscale;
        short blockhandler[8];
        
 -      float viewquat[4], dist, pad1;  /* XXX depricated */
 +      float viewquat[4], dist;        /* XXX depricated */
 +
 +      float bundle_size;                      /* size of bundles in reconstructed data */
 +      short bundle_drawtype;          /* display style for bundle */
 +
 +      char pad[6];
        
        unsigned int lay_used; /* used while drawing */
        
  #define V3D_SOLID_TEX                 8
  #define V3D_DISPGP                            16
  #define V3D_LOCK_CAMERA                       32
- #define V3D_SHOW_RECONSTRUCTION       64
- #define V3D_SHOW_CAMERAPATH           128
- #define V3D_SHOW_BUNDLENAME           256
+ #define V3D_RENDER_SHADOW             64 /* This is a runtime only flag that's used to tell draw_mesh_object() that we're doing a shadow pass instead of a regular draw */
++#define V3D_SHOW_RECONSTRUCTION               128
++#define V3D_SHOW_CAMERAPATH           256
++#define V3D_SHOW_BUNDLENAME           512
  
  /* View3D->around */
  #define V3D_CENTER             0
  /* may want to use 1 for select ?*/
  #define V3D_BGPIC_EXPANDED            2
  
 +/* BGPic->source */
 +/* may want to use 1 for select ?*/
 +#define V3D_BGPIC_IMAGE               0
 +#define V3D_BGPIC_MOVIE               1
 +
  #define RV3D_CAMZOOM_MIN -30
  #define RV3D_CAMZOOM_MAX 600
  
index 4570bcf7731d61ac2cdfa254b0a50fd3d374e08d,552ff7b6365b8217be4c1fa60dbd77ce9ee28055..8a4d3ce0b51ba243a38ea7dd3f24c50f94cbdbfa
@@@ -155,6 -155,12 +155,12 @@@ EnumPropertyItem image_type_items[] = 
  #endif
        {0, NULL, 0, NULL, NULL}};
  
+ EnumPropertyItem image_color_mode_items[] ={
+       {R_PLANESBW, "BW", 0, "BW", "Images get saved in 8 bits grayscale (only PNG, JPEG, TGA, TIF)"},
+       {R_PLANES24, "RGB", 0, "RGB", "Images are saved with RGB (color) data"},
+       {R_PLANES32, "RGBA", 0, "RGBA", "Images are saved with RGB and Alpha data (if supported)"},
+       {0, NULL, 0, NULL, NULL}};
  #ifdef RNA_RUNTIME
  
  #include "DNA_anim_types.h"
@@@ -700,8 -706,8 +706,8 @@@ static void rna_RenderSettings_active_l
  {
        RenderData *rd= (RenderData*)ptr->data;
        SceneRenderLayer *srl= (SceneRenderLayer*)value.data;
-       
-       rd->actlay = BLI_findindex(&rd->layers, srl);
+       const int index= BLI_findindex(&rd->layers, srl);
+       if (index != -1) rd->actlay= index;
  }
  
  static void rna_RenderSettings_engine_set(PointerRNA *ptr, int value)
@@@ -1018,15 -1024,6 +1024,15 @@@ static KeyingSet *rna_Scene_keying_set_
        }
  }
  
 +static void rna_SceneCamera_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
 +{
 +      Scene *scene= (Scene*)ptr->id.data;
 +      Object *camera= scene->camera;
 +
 +      if(camera)
 +              DAG_id_tag_update(&camera->id, 0);
 +}
 +
  #else
  
  static void rna_def_transform_orientation(BlenderRNA *brna)
@@@ -1982,7 -1979,7 +1988,7 @@@ static void rna_def_render_layers(Blend
        prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_UNSIGNED);
        RNA_def_property_struct_type(prop, "SceneRenderLayer");
        RNA_def_property_pointer_funcs(prop, "rna_RenderSettings_active_layer_get", "rna_RenderSettings_active_layer_set", NULL, NULL);
-       RNA_def_property_flag(prop, PROP_EDITABLE);
+       RNA_def_property_flag(prop, PROP_EDITABLE|PROP_NEVER_NULL);
        RNA_def_property_ui_text(prop, "Active Render Layer", "Active Render Layer");
        RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
  
@@@ -2008,13 -2005,7 +2014,7 @@@ static void rna_def_scene_render_data(B
                {R_ALPHAPREMUL, "PREMUL", 0, "Premultiplied", "Transparent RGB pixels are multiplied by the alpha channel"},
                {R_ALPHAKEY, "STRAIGHT", 0, "Straight Alpha", "Transparent RGB and alpha pixels are unmodified"},
                {0, NULL, 0, NULL, NULL}};
-               
-       static EnumPropertyItem color_mode_items[] ={
-               {R_PLANESBW, "BW", 0, "BW", "Images get saved in 8 bits grayscale (only PNG, JPEG, TGA, TIF)"},
-               {R_PLANES24, "RGB", 0, "RGB", "Images are saved with RGB (color) data"},
-               {R_PLANES32, "RGBA", 0, "RGBA", "Images are saved with RGB and Alpha data (if supported)"},
-               {0, NULL, 0, NULL, NULL}};
-       
        static EnumPropertyItem display_mode_items[] ={
                {R_OUTPUT_SCREEN, "SCREEN", 0, "Full Screen", "Images are rendered in full Screen"},
                {R_OUTPUT_AREA, "AREA", 0, "Image Editor", "Images are rendered in Image Editor"},
        
        prop= RNA_def_property(srna, "color_mode", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_bitflag_sdna(prop, NULL, "planes");
-       RNA_def_property_enum_items(prop, color_mode_items);
+       RNA_def_property_enum_items(prop, image_color_mode_items);
        RNA_def_property_ui_text(prop, "Color Mode", "Choose BW for saving greyscale images, RGB for saving red, green and blue channels, AND RGBA for saving red, green, blue + alpha channels");
        RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
  
        RNA_def_property_int_sdna(prop, NULL, "xsch");
        RNA_def_property_range(prop, 4, 10000);
        RNA_def_property_ui_text(prop, "Resolution X", "Number of horizontal pixels in the rendered image");
 -      RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
 +      RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, "rna_SceneCamera_update");
        
        prop= RNA_def_property(srna, "resolution_y", PROP_INT, PROP_NONE);
        RNA_def_property_int_sdna(prop, NULL, "ysch");
        RNA_def_property_range(prop, 4, 10000);
        RNA_def_property_ui_text(prop, "Resolution Y", "Number of vertical pixels in the rendered image");
 -      RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
 +      RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, "rna_SceneCamera_update");
        
        prop= RNA_def_property(srna, "resolution_percentage", PROP_INT, PROP_PERCENTAGE);
        RNA_def_property_int_sdna(prop, NULL, "size");
        RNA_def_property_float_sdna(prop, NULL, "xasp");
        RNA_def_property_range(prop, 1.0f, 200.0f);
        RNA_def_property_ui_text(prop, "Pixel Aspect X", "Horizontal aspect ratio - for anamorphic or non-square pixel output");
 -      RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
 +      RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, "rna_SceneCamera_update");
        
        prop= RNA_def_property(srna, "pixel_aspect_y", PROP_FLOAT, PROP_NONE);
        RNA_def_property_float_sdna(prop, NULL, "yasp");
        RNA_def_property_range(prop, 1.0f, 200.0f);
        RNA_def_property_ui_text(prop, "Pixel Aspect Y", "Vertical aspect ratio - for anamorphic or non-square pixel output");
 -      RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
 +      RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, "rna_SceneCamera_update");
        
        /* JPEG and AVI JPEG */
        
@@@ -3477,14 -3468,6 +3477,14 @@@ void RNA_def_scene(BlenderRNA *brna
        RNA_def_property_struct_type(prop, "TransformOrientation");
        RNA_def_property_ui_text(prop, "Transform Orientations", "");
  
 +      /* acctive MovieClip */
 +      prop= RNA_def_property(srna, "clip", PROP_POINTER, PROP_NONE);
 +      RNA_def_property_pointer_sdna(prop, NULL, "clip");
 +      RNA_def_property_flag(prop, PROP_EDITABLE);
 +      RNA_def_property_struct_type(prop, "MovieClip");
 +      RNA_def_property_ui_text(prop, "Active Movie Clip", "Active movie clip used for constraints and viewport drawing");
 +      RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL);
 +
        /* Nestled Data  */
        rna_def_tool_settings(brna);
        rna_def_unit_settings(brna);
index af791ca6cf23be0bc60b6132d86f49ef05693bdc,a4efa8fff848eada9c49329dd9099af436bf65df..c30e48e68eff8dec6eed15250a64210d1bc0a682
@@@ -213,6 -213,7 +213,7 @@@ static int wm_macro_exec(bContext *C, w
                
                if(opm->type->exec) {
                        retval= opm->type->exec(C, opm);
+                       OPERATOR_RETVAL_CHECK(retval);
                
                        if (retval & OPERATOR_FINISHED) {
                                MacroData *md = op->customdata;
@@@ -237,6 -238,8 +238,8 @@@ static int wm_macro_invoke_internal(bCo
                else if(opm->type->exec)
                        retval= opm->type->exec(C, opm);
  
+               OPERATOR_RETVAL_CHECK(retval);
                BLI_movelisttolist(&op->reports->list, &opm->reports->list);
                
                if (retval & OPERATOR_FINISHED) {
@@@ -265,6 -268,7 +268,7 @@@ static int wm_macro_modal(bContext *C, 
                printf("macro error, calling NULL modal()\n");
        else {
                retval = opm->type->modal(C, opm, event);
+               OPERATOR_RETVAL_CHECK(retval);
  
                /* if this one is done but it's not the last operator in the macro */
                if ((retval & OPERATOR_FINISHED) && opm->next) {
@@@ -655,7 -659,9 +659,9 @@@ int WM_menu_invoke(bContext *C, wmOpera
                printf("WM_menu_invoke: %s \"%s\" is not an enum property\n", op->type->idname, RNA_property_identifier(prop));
        }
        else if (RNA_property_is_set(op->ptr, RNA_property_identifier(prop))) {
-               return op->type->exec(C, op);
+               const int retval= op->type->exec(C, op);
+               OPERATOR_RETVAL_CHECK(retval);
+               return retval;
        }
        else {
                pup= uiPupMenuBegin(C, op->type->name, ICON_NONE);
@@@ -2345,7 -2351,6 +2351,6 @@@ static void gesture_circle_apply(bConte
        
        if(op->type->exec)
                op->type->exec(C, op);
  #ifdef GESTURE_MEMORY
        circle_select_size= rect->xmax;
  #endif
@@@ -2566,7 -2571,6 +2571,6 @@@ static void gesture_lasso_apply(bContex
                
        if(op->type->exec)
                op->type->exec(C, op);
-       
  }
  
  int WM_gesture_lasso_modal(bContext *C, wmOperator *op, wmEvent *event)
@@@ -3569,7 -3573,6 +3573,7 @@@ static void gesture_circle_modal_keymap
        /* assign map to operators */
        WM_modalkeymap_assign(keymap, "VIEW3D_OT_select_circle");
        WM_modalkeymap_assign(keymap, "UV_OT_circle_select");
 +      WM_modalkeymap_assign(keymap, "CLIP_OT_select_circle");
  
  }
  
@@@ -3649,7 -3652,6 +3653,7 @@@ static void gesture_border_modal_keymap
        WM_modalkeymap_assign(keymap, "SEQUENCER_OT_select_border");
        WM_modalkeymap_assign(keymap, "SEQUENCER_OT_view_ghost_border");
        WM_modalkeymap_assign(keymap, "UV_OT_select_border");
 +      WM_modalkeymap_assign(keymap, "CLIP_OT_select_border");
        WM_modalkeymap_assign(keymap, "VIEW2D_OT_zoom_border");
        WM_modalkeymap_assign(keymap, "VIEW3D_OT_clip_border");
        WM_modalkeymap_assign(keymap, "VIEW3D_OT_render_border");
index c8d4e76639220c796f114b4c2b34c94257ca4a80,35c319e263b4ced3b099c9b3ca96670aaf1d85a0..47e2a0275504fd27250da3842fe966dbf1b3ef03
@@@ -350,6 -350,8 +350,8 @@@ bool ConvertMaterial
  
                // use lighting?
                material->ras_mode |= ( mat->mode & MA_SHLESS )?0:USE_LIGHT;
+               // cast shadows?
+               material->ras_mode |= ( mat->mode & MA_SHADBUF )?CAST_SHADOW:0;
                MTex *mttmp = 0;
                numchan = getNumTexChannels(mat);
                int valid_index = 0;
@@@ -1690,7 -1692,7 +1692,7 @@@ static KX_LightObject *gamelight_from_b
  
  static KX_Camera *gamecamera_from_bcamera(Object *ob, KX_Scene *kxscene, KX_BlenderSceneConverter *converter) {
        Camera* ca = static_cast<Camera*>(ob->data);
 -      RAS_CameraData camdata(ca->lens, ca->ortho_scale, ca->clipsta, ca->clipend, ca->type == CAM_PERSP, ca->YF_dofdist);
 +      RAS_CameraData camdata(ca->lens, ca->ortho_scale, ca->sensor_x, ca->clipsta, ca->clipend, ca->type == CAM_PERSP, ca->YF_dofdist);
        KX_Camera *gamecamera;
        
        gamecamera= new KX_Camera(kxscene, KX_Scene::m_callbacks, camdata);