Merging r44227 through r45619 from trunk into soc-2011-tomato
[blender.git] / source / blender / editors / space_clip / clip_draw.c
index d010ca879fb720afdbb1ff949f7073dafbf93865..a553566ca6951cca716547e42023ac047aef1706 100644 (file)
@@ -73,8 +73,8 @@
 
 void clip_draw_curfra_label(SpaceClip *sc, float x, float y)
 {
-       uiStyle *style= UI_GetStyle();
-       int fontid= style->widget.uifont_id;
+       uiStyle *style = UI_GetStyle();
+       int fontid = style->widget.uifont_id;
        char numstr[32];
        float font_dims[2] = {0.0f, 0.0f};
 
@@ -95,9 +95,9 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc
 {
        float x;
        int *points, totseg, i, a;
-       float sfra= SFRA, efra= EFRA, framelen= ar->winx/(efra-sfra+1);
-       MovieTrackingTrack *act_track= BKE_tracking_active_track(&clip->tracking);
-       MovieTrackingReconstruction *reconstruction= BKE_tracking_get_reconstruction(&clip->tracking);
+       float sfra = SFRA, efra = EFRA, framelen = ar->winx / (efra - sfra + 1);
+       MovieTrackingTrack *act_track = BKE_tracking_active_track(&clip->tracking);
+       MovieTrackingReconstruction *reconstruction = BKE_tracking_get_reconstruction(&clip->tracking);
 
        glEnable(GL_BLEND);
 
@@ -107,83 +107,88 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc
 
        /* cached segments -- could be usefu lto debug caching strategies */
        BKE_movieclip_get_cache_segments(clip, &sc->user, &totseg, &points);
-       if(totseg) {
+       if (totseg) {
                glColor4ub(128, 128, 255, 128);
 
-               for(a= 0; a<totseg; a++) {
+               for (a = 0; a < totseg; a++) {
                        float x1, x2;
 
-                       x1= (points[a*2]-sfra)/(efra-sfra+1)*ar->winx;
-                       x2= (points[a*2+1]-sfra+1)/(efra-sfra+1)*ar->winx;
+                       x1 = (points[a * 2] - sfra) / (efra - sfra + 1) * ar->winx;
+                       x2 = (points[a * 2 + 1] - sfra + 1) / (efra - sfra + 1) * ar->winx;
 
                        glRecti(x1, 0, x2, 8);
                }
        }
 
        /* track */
-       if(act_track) {
-               MovieTrackingTrack *track= act_track;
+       if (act_track) {
+               MovieTrackingTrack *track = act_track;
 
-               for(i= sfra, a= 0; i <= efra; i++) {
+               for (i = sfra, a = 0; i <= efra; i++) {
                        int framenr;
                        MovieTrackingMarker *marker;
 
-                       while(a<track->markersnr) {
-                               if(track->markers[a].framenr>=i)
+                       while (a<track->markersnr) {
+                               if (track->markers[a].framenr >= i)
                                        break;
 
-                               if(a<track->markersnr-1 && track->markers[a+1].framenr>i)
+                               if (a < track->markersnr - 1 && track->markers[a + 1].framenr > i)
                                        break;
 
                                a++;
                        }
 
-                       if(a<track->markersnr) marker= &track->markers[a];
-                       else marker= &track->markers[track->markersnr-1];
+                       if (a < track->markersnr)
+                               marker = &track->markers[a];
+                       else
+                               marker = &track->markers[track->markersnr - 1];
 
-                       if((marker->flag&MARKER_DISABLED)==0) {
-                               framenr= marker->framenr;
+                       if ((marker->flag & MARKER_DISABLED) == 0) {
+                               framenr = marker->framenr;
 
-                               if(framenr!=i) glColor4ub(128, 128, 0, 96);
-                               else if((marker->flag&MARKER_TRACKED)==0) glColor4ub(255, 255, 0, 196);
-                               else glColor4ub(255, 255, 0, 96);
+                               if (framenr != i)
+                                       glColor4ub(128, 128, 0, 96);
+                               else if ((marker->flag & MARKER_TRACKED) == 0)
+                                       glColor4ub(255, 255, 0, 196);
+                               else
+                                       glColor4ub(255, 255, 0, 96);
 
-                               glRecti((i-sfra)*framelen, 0, (i-sfra+1)*framelen, 4);
+                               glRecti((i - sfra) * framelen, 0, (i - sfra + 1)*framelen, 4);
                        }
                }
        }
 
        /* failed frames */
-       if(reconstruction->flag&TRACKING_RECONSTRUCTED) {
-               int n= reconstruction->camnr;
-               MovieReconstructedCamera *cameras= reconstruction->cameras;
+       if (reconstruction->flag & TRACKING_RECONSTRUCTED) {
+               int n = reconstruction->camnr;
+               MovieReconstructedCamera *cameras = reconstruction->cameras;
 
                glColor4ub(255, 0, 0, 96);
 
-               for(i= sfra, a= 0; i <= efra; i++) {
-                       int ok= 0;
+               for (i = sfra, a = 0; i <= efra; i++) {
+                       int ok = FALSE;
 
-                       while(a<n) {
-                               if(cameras[a].framenr==i) {
-                                       ok= 1;
+                       while (a < n) {
+                               if (cameras[a].framenr == i) {
+                                       ok = TRUE;
                                        break;
                                }
-                               else if(cameras[a].framenr>i) {
+                               else if (cameras[a].framenr > i) {
                                        break;
                                }
 
                                a++;
                        }
 
-                       if(!ok)
-                               glRecti((i-sfra)*framelen, 0, (i-sfra+1)*framelen, 8);
+                       if (!ok)
+                               glRecti((i - sfra) * framelen, 0, (i - sfra + 1) * framelen, 8);
                }
        }
 
        glDisable(GL_BLEND);
 
        /* current frame */
-       x= (sc->user.framenr-sfra)/(efra-sfra+1)*ar->winx;
+       x = (sc->user.framenr - sfra) / (efra - sfra + 1) * ar->winx;
 
        UI_ThemeColor(TH_CFRAME);
        glRecti(x, 0, x+framelen, 8);
@@ -193,39 +198,46 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc
 
 static void draw_movieclip_notes(SpaceClip *sc, ARegion *ar)
 {
-       MovieClip *clip= ED_space_clip(sc);
-       MovieTracking *tracking= &clip->tracking;
-       char str[256]= {0};
-       int block= 0;
+       MovieClip *clip = ED_space_clip(sc);
+       MovieTracking *tracking = &clip->tracking;
+       char str[256] = {0};
+       int block = FALSE;
 
-       if(tracking->stats) {
+       if (tracking->stats) {
                BLI_strncpy(str, tracking->stats->message, sizeof(str));
-               block= 1;
-       } else {
-               if(sc->flag&SC_LOCK_SELECTION)
+               block = TRUE;
+       }
+       else {
+               if (sc->flag & SC_LOCK_SELECTION)
                        strcpy(str, "Locked");
        }
 
-       if(str[0])
+       if (str[0])
                ED_region_info_draw(ar, str, block, 0.6f);
 }
 
+static void verify_buffer_float(ImBuf *ibuf)
+{
+       if (ibuf->rect_float && (ibuf->rect == NULL || (ibuf->userflags & IB_RECT_INVALID))) {
+               IMB_rect_from_float(ibuf);
+       }
+}
+
 static void draw_movieclip_buffer(SpaceClip *sc, ARegion *ar, ImBuf *ibuf,
-                       int width, int height, float zoomx, float zoomy)
+                                  int width, int height, float zoomx, float zoomy)
 {
        int x, y;
-       MovieClip *clip= ED_space_clip(sc);
+       MovieClip *clip = ED_space_clip(sc);
 
        /* find window pixel coordinates of origin */
        UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x, &y);
 
-       if(sc->flag&SC_MUTE_FOOTAGE) {
+       if (sc->flag & SC_MUTE_FOOTAGE) {
                glColor3f(0.0f, 0.0f, 0.0f);
-               glRectf(x, y, x+zoomx*width, y+zoomy*height);
-       } else {
-               if(ibuf->rect_float && !ibuf->rect) {
-                       IMB_rect_from_float(ibuf);
-               }
+               glRectf(x, y, x + zoomx * width, y + zoomy * height);
+       }
+       else {
+               verify_buffer_float(ibuf);
 
                if(ibuf->rect) {
                        if(sc->flag & SC_TEXTURE_BUFFER) {
@@ -259,7 +271,7 @@ static void draw_movieclip_buffer(SpaceClip *sc, ARegion *ar, ImBuf *ibuf,
        }
 
        /* draw boundary border for frame if stabilization is enabled */
-       if(sc->flag&SC_SHOW_STABLE && clip->tracking.stabilization.flag&TRACKING_2D_STABILIZATION) {
+       if (sc->flag & SC_SHOW_STABLE && clip->tracking.stabilization.flag & TRACKING_2D_STABILIZATION) {
                glColor3f(0.0f, 0.0f, 0.0f);
                glLineStipple(3, 0xaaaa);
                glEnable(GL_LINE_STIPPLE);
@@ -288,69 +300,72 @@ static void draw_movieclip_buffer(SpaceClip *sc, ARegion *ar, ImBuf *ibuf,
 
 static void draw_track_path(SpaceClip *sc, MovieClip *UNUSED(clip), MovieTrackingTrack *track)
 {
-       int count= sc->path_length;
-       int i, a, b, curindex= -1;
+       int count = sc->path_length;
+       int i, a, b, curindex = -1;
        float path[102][2];
-       int tiny= sc->flag&SC_SHOW_TINY_MARKER, framenr;
+       int tiny = sc->flag&SC_SHOW_TINY_MARKER, framenr;
        MovieTrackingMarker *marker;
 
-       if(count==0)
+       if (count == 0)
                return;
 
-       marker= BKE_tracking_get_marker(track, sc->user.framenr);
-       if(marker->framenr!=sc->user.framenr || marker->flag&MARKER_DISABLED)
+       marker = BKE_tracking_get_marker(track, sc->user.framenr);
+       if (marker->framenr != sc->user.framenr || marker->flag & MARKER_DISABLED)
                return;
 
-       framenr= marker->framenr;
+       framenr = marker->framenr;
 
-       a= count;
-       i= framenr-1;
-       while(i>=framenr-count) {
-               marker= BKE_tracking_get_marker(track, i);
+       a = count;
+       i = framenr - 1;
+       while (i >= framenr - count) {
+               marker = BKE_tracking_get_marker(track, i);
 
-               if(!marker || marker->flag&MARKER_DISABLED)
+               if (!marker || marker->flag & MARKER_DISABLED)
                        break;
 
-               if(marker->framenr==i) {
+               if (marker->framenr == i) {
                        add_v2_v2v2(path[--a], marker->pos, track->offset);
                        ED_clip_point_undistorted_pos(sc, path[a], path[a]);
 
-                       if(marker->framenr==sc->user.framenr)
-                               curindex= a;
-               } else
+                       if (marker->framenr == sc->user.framenr)
+                               curindex = a;
+               }
+               else {
                        break;
+               }
 
                i--;
        }
 
-       b= count;
-       i= framenr;
-       while(i<=framenr+count) {
-               marker= BKE_tracking_get_marker(track, i);
+       b = count;
+       i = framenr;
+       while (i <= framenr+count) {
+               marker = BKE_tracking_get_marker(track, i);
 
-               if(!marker || marker->flag&MARKER_DISABLED)
+               if (!marker || marker->flag & MARKER_DISABLED)
                        break;
 
-               if(marker->framenr==i) {
-                       if(marker->framenr==sc->user.framenr)
+               if (marker->framenr == i) {
+                       if (marker->framenr == sc->user.framenr)
                                curindex= b;
 
                        add_v2_v2v2(path[b++], marker->pos, track->offset);
                        ED_clip_point_undistorted_pos(sc, path[b-1], path[b-1]);
-               } else
+               }
+               else
                        break;
 
                i++;
        }
 
-       if(!tiny) {
+       if (!tiny) {
                UI_ThemeColor(TH_MARKER_OUTLINE);
 
-               if(TRACK_VIEW_SELECTED(sc, track)) {
+               if (TRACK_VIEW_SELECTED(sc, track)) {
                        glPointSize(5.0f);
                        glBegin(GL_POINTS);
-                               for(i= a; i<b; i++) {
-                                       if(i!=curindex)
+                               for (i = a; i < b; i++) {
+                                       if (i != curindex)
                                                glVertex2f(path[i][0], path[i][1]);
                                }
                        glEnd();
@@ -358,7 +373,7 @@ static void draw_track_path(SpaceClip *sc, MovieClip *UNUSED(clip), MovieTrackin
 
                glLineWidth(3.0f);
                glBegin(GL_LINE_STRIP);
-                       for(i= a; i<b; i++)
+                       for (i = a; i < b; i++)
                                glVertex2f(path[i][0], path[i][1]);
                glEnd();
                glLineWidth(1.0f);
@@ -366,14 +381,14 @@ static void draw_track_path(SpaceClip *sc, MovieClip *UNUSED(clip), MovieTrackin
 
        UI_ThemeColor(TH_PATH_BEFORE);
 
-       if(TRACK_VIEW_SELECTED(sc, track)) {
+       if (TRACK_VIEW_SELECTED(sc, track)) {
                glPointSize(3.0f);
                glBegin(GL_POINTS);
-                       for(i= a; i<b; i++) {
-                               if(i==count+1)
+                       for (i = a; i < b; i++) {
+                               if (i == count + 1)
                                        UI_ThemeColor(TH_PATH_AFTER);
 
-                               if(i!=curindex)
+                               if (i != curindex)
                                        glVertex2f(path[i][0], path[i][1]);
                        }
                glEnd();
@@ -382,8 +397,8 @@ static void draw_track_path(SpaceClip *sc, MovieClip *UNUSED(clip), MovieTrackin
        UI_ThemeColor(TH_PATH_BEFORE);
 
        glBegin(GL_LINE_STRIP);
-               for(i= a; i<b; i++) {
-                       if(i==count+1)
+               for (i = a; i < b; i++) {
+                       if (i == count + 1)
                                UI_ThemeColor(TH_PATH_AFTER);
 
                        glVertex2f(path[i][0], path[i][1]);
@@ -394,16 +409,16 @@ static void draw_track_path(SpaceClip *sc, MovieClip *UNUSED(clip), MovieTrackin
 
 static void draw_marker_outline(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, float marker_pos[2], int width, int height)
 {
-       int tiny= sc->flag&SC_SHOW_TINY_MARKER;
-       int show_search= 0;
+       int tiny = sc->flag&SC_SHOW_TINY_MARKER;
+       int show_search = FALSE;
        float px[2];
 
        UI_ThemeColor(TH_MARKER_OUTLINE);
 
-       px[0]= 1.0f/width/sc->zoom;
-       px[1]= 1.0f/height/sc->zoom;
+       px[0] = 1.0f / width / sc->zoom;
+       px[1] = 1.0f / height / sc->zoom;
 
-       if((marker->flag&MARKER_DISABLED)==0) {
+       if ((marker->flag & MARKER_DISABLED) == 0) {
                float pos[2];
                rctf r;
 
@@ -412,15 +427,16 @@ static void draw_marker_outline(SpaceClip *sc, MovieTrackingTrack *track, MovieT
 
                ED_clip_point_undistorted_pos(sc, pos, pos);
 
-               if(BLI_in_rctf(&r, pos[0]-marker_pos[0], pos[1]-marker_pos[1])) {
-                       if(tiny) glPointSize(3.0f);
+               if (BLI_in_rctf(&r, pos[0]-marker_pos[0], pos[1]-marker_pos[1])) {
+                       if (tiny) glPointSize(3.0f);
                        else glPointSize(4.0f);
                        glBegin(GL_POINTS);
                                glVertex2f(pos[0], pos[1]);
                        glEnd();
                        glPointSize(1.0f);
-               } else {
-                       if(!tiny) glLineWidth(3.0f);
+               }
+               else {
+                       if (!tiny) glLineWidth(3.0f);
                        glBegin(GL_LINES);
                                glVertex2f(pos[0] + px[0]*2, pos[1]);
                                glVertex2f(pos[0] + px[0]*8, pos[1]);
@@ -434,7 +450,7 @@ static void draw_marker_outline(SpaceClip *sc, MovieTrackingTrack *track, MovieT
                                glVertex2f(pos[0], pos[1] + px[1]*2);
                                glVertex2f(pos[0], pos[1] + px[1]*8);
                        glEnd();
-                       if(!tiny) glLineWidth(1.0f);
+                       if (!tiny) glLineWidth(1.0f);
                }
        }
 
@@ -442,9 +458,10 @@ static void draw_marker_outline(SpaceClip *sc, MovieTrackingTrack *track, MovieT
        glPushMatrix();
        glTranslatef(marker_pos[0], marker_pos[1], 0);
 
-       if(!tiny) glLineWidth(3.0f);
+       if (!tiny)
+               glLineWidth(3.0f);
 
-       if(sc->flag&SC_SHOW_MARKER_PATTERN) {
+       if (sc->flag & SC_SHOW_MARKER_PATTERN) {
                glBegin(GL_LINE_LOOP);
                        glVertex2f(track->pat_min[0], track->pat_min[1]);
                        glVertex2f(track->pat_max[0], track->pat_min[1]);
@@ -453,8 +470,9 @@ static void draw_marker_outline(SpaceClip *sc, MovieTrackingTrack *track, MovieT
                glEnd();
        }
 
-       show_search= TRACK_VIEW_SELECTED(sc, track) && ((marker->flag&MARKER_DISABLED)==0 || (sc->flag&SC_SHOW_MARKER_PATTERN)==0);
-       if(sc->flag&SC_SHOW_MARKER_SEARCH && show_search) {
+       show_search = TRACK_VIEW_SELECTED(sc, track) &&
+                     ((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0);
+       if (sc->flag & SC_SHOW_MARKER_SEARCH && show_search) {
                glBegin(GL_LINE_LOOP);
                        glVertex2f(track->search_min[0], track->search_min[1]);
                        glVertex2f(track->search_max[0], track->search_min[1]);
@@ -464,21 +482,27 @@ static void draw_marker_outline(SpaceClip *sc, MovieTrackingTrack *track, MovieT
        }
        glPopMatrix();
 
-       if(!tiny) glLineWidth(1.0f);
+       if (!tiny)
+               glLineWidth(1.0f);
 }
 
 static void track_colors(MovieTrackingTrack *track, int act, float col[3], float scol[3])
 {
-       if(track->flag&TRACK_CUSTOMCOLOR) {
-               if(act) UI_GetThemeColor3fv(TH_ACT_MARKER, scol);
-               else copy_v3_v3(scol, track->color);
+       if (track->flag & TRACK_CUSTOMCOLOR) {
+               if (act)
+                       UI_GetThemeColor3fv(TH_ACT_MARKER, scol);
+               else
+                       copy_v3_v3(scol, track->color);
 
                mul_v3_v3fl(col, track->color, 0.5f);
-       } else {
+       }
+       else {
                UI_GetThemeColor3fv(TH_MARKER, col);
 
-               if(act) UI_GetThemeColor3fv(TH_ACT_MARKER, scol);
-               else UI_GetThemeColor3fv(TH_SEL_MARKER, scol);
+               if (act)
+                       UI_GetThemeColor3fv(TH_ACT_MARKER, scol);
+               else
+                       UI_GetThemeColor3fv(TH_SEL_MARKER, scol);
        }
 }
 
@@ -490,34 +514,45 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra
 
        track_colors(track, act, col, scol);
 
-       px[0]= 1.0f/width/sc->zoom;
-       px[1]= 1.0f/height/sc->zoom;
+       px[0]= 1.0f / width / sc->zoom;
+       px[1]= 1.0f / height / sc->zoom;
 
        /* marker position and offset position */
-       if((track->flag&SELECT)==sel && (marker->flag&MARKER_DISABLED)==0) {
+       if ((track->flag&SELECT) == sel && (marker->flag & MARKER_DISABLED) == 0) {
                float pos[2];
                rctf r;
 
-               if(track->flag&TRACK_LOCKED) {
-                       if(act) UI_ThemeColor(TH_ACT_MARKER);
-                       else if(track->flag&SELECT) UI_ThemeColorShade(TH_LOCK_MARKER, 64);
-                       else UI_ThemeColor(TH_LOCK_MARKER);
-               } else {
-                       if(track->flag&SELECT) glColor3fv(scol);
-                       else glColor3fv(col);
+               if (track->flag & TRACK_LOCKED) {
+                       if (act)
+                               UI_ThemeColor(TH_ACT_MARKER);
+                       else if (track->flag & SELECT)
+                               UI_ThemeColorShade(TH_LOCK_MARKER, 64);
+                       else
+                               UI_ThemeColor(TH_LOCK_MARKER);
+               }
+               else {
+                       if (track->flag & SELECT)
+                               glColor3fv(scol);
+                       else
+                               glColor3fv(col);
                }
 
                BLI_init_rctf(&r, track->pat_min[0], track->pat_max[0], track->pat_min[1], track->pat_max[1]);
                add_v2_v2v2(pos, marker->pos, track->offset);
                ED_clip_point_undistorted_pos(sc, pos, pos);
 
-               if(BLI_in_rctf(&r, pos[0]-marker_pos[0], pos[1]-marker_pos[1])) {
-                       if(!tiny) glPointSize(2.0f);
+               if (BLI_in_rctf(&r, pos[0]-marker_pos[0], pos[1]-marker_pos[1])) {
+                       if (!tiny)
+                               glPointSize(2.0f);
+
                        glBegin(GL_POINTS);
                                glVertex2f(pos[0], pos[1]);
                        glEnd();
-                       if(!tiny) glPointSize(1.0f);
-               } else {
+
+                       if (!tiny)
+                               glPointSize(1.0f);
+               }
+               else {
                        glBegin(GL_LINES);
                                glVertex2f(pos[0] + px[0]*3, pos[1]);
                                glVertex2f(pos[0] + px[0]*7, pos[1]);
@@ -552,23 +587,29 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra
        glPushMatrix();
        glTranslatef(marker_pos[0], marker_pos[1], 0);
 
-       if(tiny) {
+       if (tiny) {
                glLineStipple(3, 0xaaaa);
                glEnable(GL_LINE_STIPPLE);
        }
 
-       if((track->pat_flag&SELECT)==sel && (sc->flag&SC_SHOW_MARKER_PATTERN)) {
-               if(track->flag&TRACK_LOCKED) {
-                       if(act) UI_ThemeColor(TH_ACT_MARKER);
-                       else if(track->pat_flag&SELECT) UI_ThemeColorShade(TH_LOCK_MARKER, 64);
+       if ((track->pat_flag & SELECT) == sel && (sc->flag & SC_SHOW_MARKER_PATTERN)) {
+               if (track->flag & TRACK_LOCKED) {
+                       if (act)
+                               UI_ThemeColor(TH_ACT_MARKER);
+                       else if (track->pat_flag & SELECT)
+                               UI_ThemeColorShade(TH_LOCK_MARKER, 64);
                        else UI_ThemeColor(TH_LOCK_MARKER);
                }
-               else if(marker->flag&MARKER_DISABLED) {
-                       if(act) UI_ThemeColor(TH_ACT_MARKER);
-                       else if(track->pat_flag&SELECT) UI_ThemeColorShade(TH_DIS_MARKER, 128);
+               else if (marker->flag & MARKER_DISABLED) {
+                       if (act)
+                               UI_ThemeColor(TH_ACT_MARKER);
+                       else if (track->pat_flag & SELECT)
+                               UI_ThemeColorShade(TH_DIS_MARKER, 128);
                        else UI_ThemeColor(TH_DIS_MARKER);
-               } else {
-                       if(track->pat_flag&SELECT) glColor3fv(scol);
+               }
+               else {
+                       if (track->pat_flag & SELECT)
+                               glColor3fv(scol);
                        else glColor3fv(col);
                }
 
@@ -581,20 +622,28 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra
        }
 
        /* search */
-       show_search= TRACK_VIEW_SELECTED(sc, track) && ((marker->flag&MARKER_DISABLED)==0 || (sc->flag&SC_SHOW_MARKER_PATTERN)==0);
-       if((track->search_flag&SELECT)==sel && (sc->flag&SC_SHOW_MARKER_SEARCH) && show_search) {
-               if(track->flag&TRACK_LOCKED) {
-                       if(act) UI_ThemeColor(TH_ACT_MARKER);
-                       else if(track->search_flag&SELECT) UI_ThemeColorShade(TH_LOCK_MARKER, 64);
+       show_search = TRACK_VIEW_SELECTED(sc, track) &&
+                    ((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0);
+       if ((track->search_flag & SELECT) == sel && (sc->flag & SC_SHOW_MARKER_SEARCH) && show_search) {
+               if (track->flag & TRACK_LOCKED) {
+                       if (act)
+                               UI_ThemeColor(TH_ACT_MARKER);
+                       else if (track->search_flag & SELECT)
+                               UI_ThemeColorShade(TH_LOCK_MARKER, 64);
                        else UI_ThemeColor(TH_LOCK_MARKER);
                }
-               else if(marker->flag&MARKER_DISABLED) {
-                       if(act) UI_ThemeColor(TH_ACT_MARKER);
-                       else if(track->search_flag&SELECT) UI_ThemeColorShade(TH_DIS_MARKER, 128);
+               else if (marker->flag & MARKER_DISABLED) {
+                       if (act)
+                               UI_ThemeColor(TH_ACT_MARKER);
+                       else if (track->search_flag & SELECT)
+                               UI_ThemeColorShade(TH_DIS_MARKER, 128);
                        else UI_ThemeColor(TH_DIS_MARKER);
-               } else {
-                       if(track->search_flag&SELECT) glColor3fv(scol);
-                       else glColor3fv(col);
+               }
+               else {
+                       if (track->search_flag & SELECT)
+                               glColor3fv(scol);
+                       else
+                               glColor3fv(col);
                }
 
                glBegin(GL_LINE_LOOP);
@@ -606,19 +655,29 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra
        }
 
        /* pyramid */
-       if(sel && TRACK_SELECTED(track) && (track->tracker==TRACKER_KLT) && (marker->flag&MARKER_DISABLED)==0) {
-               if(track->flag&TRACK_LOCKED) {
-                       if(act) UI_ThemeColor(TH_ACT_MARKER);
-                       else if(track->pat_flag&SELECT) UI_ThemeColorShade(TH_LOCK_MARKER, 64);
+       if (sel && TRACK_VIEW_SELECTED(sc, track) &&
+           (track->tracker == TRACKER_KLT) &&
+               (marker->flag & MARKER_DISABLED) == 0)
+       {
+               if (track->flag & TRACK_LOCKED) {
+                       if (act)
+                               UI_ThemeColor(TH_ACT_MARKER);
+                       else if (track->pat_flag & SELECT)
+                               UI_ThemeColorShade(TH_LOCK_MARKER, 64);
                        else UI_ThemeColor(TH_LOCK_MARKER);
                }
-               else if(marker->flag&MARKER_DISABLED) {
-                       if(act) UI_ThemeColor(TH_ACT_MARKER);
-                       else if(track->pat_flag&SELECT) UI_ThemeColorShade(TH_DIS_MARKER, 128);
+               else if (marker->flag & MARKER_DISABLED) {
+                       if (act)
+                               UI_ThemeColor(TH_ACT_MARKER);
+                       else if (track->pat_flag & SELECT)
+                               UI_ThemeColorShade(TH_DIS_MARKER, 128);
                        else UI_ThemeColor(TH_DIS_MARKER);
-               } else {
-                       if(track->pat_flag&SELECT) glColor3fv(scol);
-                       else glColor3fv(col);
+               }
+               else {
+                       if (track->pat_flag & SELECT)
+                               glColor3fv(scol);
+                       else
+                               glColor3fv(col);
                }
 
                {
@@ -640,28 +699,28 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra
                }
        }
 
-       if(tiny)
+       if (tiny)
                glDisable(GL_LINE_STIPPLE);
 
        glPopMatrix();
 }
 
 static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker,
-                       float marker_pos[2], int outline, int sel, int act, int width, int height)
+                                    float marker_pos[2], int outline, int sel, int act, int width, int height)
 {
        float x, y, dx, dy, patdx, patdy, searchdx, searchdy, tdx, tdy;
-       int tiny= sc->flag&SC_SHOW_TINY_MARKER;
+       int tiny = sc->flag&SC_SHOW_TINY_MARKER;
        float col[3], scol[3], px[2];
 
-       if((tiny && outline) || (marker->flag&MARKER_DISABLED))
+       if ((tiny && outline) || (marker->flag & MARKER_DISABLED))
                return;
 
-       if(!TRACK_VIEW_SELECTED(sc, track) || track->flag&TRACK_LOCKED)
+       if (!TRACK_VIEW_SELECTED(sc, track) || track->flag & TRACK_LOCKED)
                return;
 
        track_colors(track, act, col, scol);
 
-       if(outline) {
+       if (outline) {
                glLineWidth(3.0f);
                UI_ThemeColor(TH_MARKER_OUTLINE);
        }
@@ -669,34 +728,36 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo
        glPushMatrix();
        glTranslatef(marker_pos[0], marker_pos[1], 0);
 
-       dx= 6.0f/width/sc->zoom;
-       dy= 6.0f/height/sc->zoom;
+       dx = 6.0f / width / sc->zoom;
+       dy = 6.0f / height / sc->zoom;
 
-       patdx= MIN2(dx*2.0f/3.0f, (track->pat_max[0]-track->pat_min[0])/6.0f);
-       patdy= MIN2(dy*2.0f/3.0f, (track->pat_max[1]-track->pat_min[1])/6.0f);
+       patdx = MIN2(dx * 2.0f / 3.0f, (track->pat_max[0] - track->pat_min[0]) / 6.0f);
+       patdy = MIN2(dy * 2.0f / 3.0f, (track->pat_max[1] - track->pat_min[1]) / 6.0f);
 
-       searchdx= MIN2(dx, (track->search_max[0]-track->search_min[0])/6.0f);
-       searchdy= MIN2(dy, (track->search_max[1]-track->search_min[1])/6.0f);
+       searchdx = MIN2(dx, (track->search_max[0] - track->search_min[0]) / 6.0f);
+       searchdy = MIN2(dy, (track->search_max[1] - track->search_min[1]) / 6.0f);
 
-       px[0]= 1.0f/sc->zoom/width/sc->scale;
-       px[1]= 1.0f/sc->zoom/height/sc->scale;
+       px[0] = 1.0f / sc->zoom / width / sc->scale;
+       px[1] = 1.0f / sc->zoom / height / sc->scale;
 
-       if((sc->flag&SC_SHOW_MARKER_SEARCH) && ((track->search_flag&SELECT)==sel || outline)) {
-               if(!outline) {
-                       if(track->search_flag&SELECT) glColor3fv(scol);
-                       else glColor3fv(col);
+       if ((sc->flag & SC_SHOW_MARKER_SEARCH) && ((track->search_flag & SELECT) == sel || outline)) {
+               if (!outline) {
+                       if (track->search_flag & SELECT)
+                               glColor3fv(scol);
+                       else
+                               glColor3fv(col);
                }
 
                /* search offset square */
-               x= track->search_min[0];
-               y= track->search_max[1];
+               x = track->search_min[0];
+               y = track->search_max[1];
 
-               tdx= searchdx;
-               tdy= searchdy;
+               tdx = searchdx;
+               tdy = searchdy;
 
-               if(outline) {
-                       tdx+= px[0];
-                       tdy+= px[1];
+               if (outline) {
+                       tdx += px[0];
+                       tdy += px[1];
                }
 
                glBegin(GL_QUADS);
@@ -706,16 +767,16 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo
                        glVertex3f(x-tdx, y-tdy, 0);
                glEnd();
 
-               /* search resizing triangle */
-               x= track->search_max[0];
-               y= track->search_min[1];
+               /* search re-sizing triangle */
+               x = track->search_max[0];
+               y = track->search_min[1];
 
-               tdx= searchdx*2.0f;
-               tdy= searchdy*2.0f;
+               tdx = searchdx*2.0f;
+               tdy = searchdy*2.0f;
 
-               if(outline) {
-                       tdx+= px[0];
-                       tdy+= px[1];
+               if (outline) {
+                       tdx += px[0];
+                       tdy += px[1];
                }
 
                glBegin(GL_TRIANGLES);
@@ -725,22 +786,24 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo
                glEnd();
        }
 
-       if((sc->flag&SC_SHOW_MARKER_PATTERN) && ((track->pat_flag&SELECT)==sel || outline)) {
-               if(!outline) {
-                       if(track->pat_flag&SELECT) glColor3fv(scol);
-                       else glColor3fv(col);
+       if ((sc->flag & SC_SHOW_MARKER_PATTERN) && ((track->pat_flag & SELECT)==sel || outline)) {
+               if (!outline) {
+                       if (track->pat_flag & SELECT)
+                               glColor3fv(scol);
+                       else
+                               glColor3fv(col);
                }
 
                /* pattern offset square */
-               x= track->pat_min[0];
-               y= track->pat_max[1];
+               x = track->pat_min[0];
+               y = track->pat_max[1];
 
-               tdx= patdx;
-               tdy= patdy;
+               tdx = patdx;
+               tdy = patdy;
 
-               if(outline) {
-                       tdx+= px[0];
-                       tdy+= px[1];
+               if (outline) {
+                       tdx += px[0];
+                       tdy += px[1];
                }
 
                glBegin(GL_QUADS);
@@ -750,16 +813,16 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo
                        glVertex3f(x-tdx, y-tdy, 0);
                glEnd();
 
-               /* pattern resizing triangle */
-               x= track->pat_max[0];
-               y= track->pat_min[1];
+               /* pattern re-sizing triangle */
+               x = track->pat_max[0];
+               y = track->pat_min[1];
 
-               tdx= patdx*2.0f;
-               tdy= patdy*2.0f;
+               tdx = patdx*2.0f;
+               tdy = patdy*2.0f;
 
-               if(outline) {
-                       tdx+= px[0];
-                       tdy+= px[1];
+               if (outline) {
+                       tdx += px[0];
+                       tdy += px[1];
                }
 
                glBegin(GL_TRIANGLES);
@@ -771,73 +834,83 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo
 
        glPopMatrix();
 
-       if(outline)
+       if (outline)
                glLineWidth(1.0f);
 }
 
 static void draw_marker_texts(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, float marker_pos[2], int act,
-                       int width, int height, float zoomx, float zoomy)
+                              int width, int height, float zoomx, float zoomy)
 {
-       char str[128]= {0}, state[64]= {0};
-       float dx= 0.0f, dy= 0.0f, fontsize, pos[3];
-       uiStyle *style= U.uistyles.first;
-       int fontid= style->widget.uifont_id;
+       char str[128] = {0}, state[64] = {0};
+       float dx= 0.0f, dy = 0.0f, fontsize, pos[3];
+       uiStyle *style = U.uistyles.first;
+       int fontid = style->widget.uifont_id;
 
-       if(!TRACK_VIEW_SELECTED(sc, track))
+       if (!TRACK_VIEW_SELECTED(sc, track))
                return;
 
        BLF_size(fontid, 11.0f, U.dpi);
-       fontsize= BLF_height_max(fontid);
-
-       if(marker->flag&MARKER_DISABLED) {
-               if(act) UI_ThemeColor(TH_ACT_MARKER);
-               else UI_ThemeColorShade(TH_DIS_MARKER, 128);
-       } else {
-               if(act) UI_ThemeColor(TH_ACT_MARKER);
-               else UI_ThemeColor(TH_SEL_MARKER);
+       fontsize = BLF_height_max(fontid);
+
+       if (marker->flag & MARKER_DISABLED) {
+               if (act)
+                       UI_ThemeColor(TH_ACT_MARKER);
+               else
+                       UI_ThemeColorShade(TH_DIS_MARKER, 128);
+       }
+       else {
+               if (act)
+                       UI_ThemeColor(TH_ACT_MARKER);
+               else
+                       UI_ThemeColor(TH_SEL_MARKER);
        }
 
-       if((sc->flag&SC_SHOW_MARKER_SEARCH) &&
-          ((marker->flag&MARKER_DISABLED)==0 || (sc->flag&SC_SHOW_MARKER_PATTERN)==0))
+       if ((sc->flag & SC_SHOW_MARKER_SEARCH) &&
+          ((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0))
        {
-               dx= track->search_min[0];
-               dy= track->search_min[1];
-       } else if(sc->flag&SC_SHOW_MARKER_PATTERN) {
-               dx= track->pat_min[0];
-               dy= track->pat_min[1];
+               dx = track->search_min[0];
+               dy = track->search_min[1];
+       }
+       else if (sc->flag & SC_SHOW_MARKER_PATTERN) {
+               dx = track->pat_min[0];
+               dy = track->pat_min[1];
        }
 
-       pos[0]= (marker_pos[0]+dx)*width;
-       pos[1]= (marker_pos[1]+dy)*height;
-       pos[2]= 0.0f;
+       pos[0] = (marker_pos[0] + dx) * width;
+       pos[1] = (marker_pos[1] + dy) * height;
+       pos[2] = 0.0f;
 
        mul_m4_v3(sc->stabmat, pos);
 
-       pos[0]= pos[0]*zoomx;
-       pos[1]= pos[1]*zoomy - fontsize;
+       pos[0] = pos[0]*zoomx;
+       pos[1] = pos[1]*zoomy - fontsize;
 
-       if(marker->flag&MARKER_DISABLED) strcpy(state, "disabled");
-       else if(marker->framenr!=sc->user.framenr) strcpy(state, "estimated");
-       else if(marker->flag&MARKER_TRACKED) strcpy(state, "tracked");
-       else strcpy(state, "keyframed");
+       if (marker->flag & MARKER_DISABLED)
+               strcpy(state, "disabled");
+       else if (marker->framenr != sc->user.framenr)
+               strcpy(state, "estimated");
+       else if (marker->flag & MARKER_TRACKED)
+               strcpy(state, "tracked");
+       else
+               strcpy(state, "keyframed");
 
-       if(state[0])
+       if (state[0])
                BLI_snprintf(str, sizeof(str), "%s: %s", track->name, state);
        else
                BLI_snprintf(str, sizeof(str), "%s", track->name);
 
        BLF_position(fontid, pos[0], pos[1], 0.0f);
        BLF_draw(fontid, str, sizeof(str));
-       pos[1]-= fontsize;
+       pos[1] -= fontsize;
 
-       if(track->flag&TRACK_HAS_BUNDLE) {
+       if (track->flag & TRACK_HAS_BUNDLE) {
                BLI_snprintf(str, sizeof(str), "Average error: %.3f", track->error);
                BLF_position(fontid, pos[0], pos[1], 0.0f);
                BLF_draw(fontid, str, sizeof(str));
-               pos[1]-= fontsize;
+               pos[1] -= fontsize;
        }
 
-       if(track->flag&TRACK_LOCKED) {
+       if (track->flag & TRACK_LOCKED) {
                BLF_position(fontid, pos[0], pos[1], 0.0f);
                BLF_draw(fontid, "locked", 6);
        }
@@ -846,32 +919,32 @@ static void draw_marker_texts(SpaceClip *sc, MovieTrackingTrack *track, MovieTra
 static void view2d_to_region_float(View2D *v2d, float x, float y, float *regionx, float *regiony)
 {
        /* express given coordinates as proportional values */
-       x= -v2d->cur.xmin / (v2d->cur.xmax-v2d->cur.xmin);
-       y= -v2d->cur.ymin / (v2d->cur.ymax-v2d->cur.ymin);
+       x = -v2d->cur.xmin / (v2d->cur.xmax - v2d->cur.xmin);
+       y = -v2d->cur.ymin / (v2d->cur.ymax - v2d->cur.ymin);
 
        /* convert proportional distances to screen coordinates */
-       *regionx= v2d->mask.xmin + x*(v2d->mask.xmax-v2d->mask.xmin);
-       *regiony= v2d->mask.ymin + y*(v2d->mask.ymax-v2d->mask.ymin);
+       *regionx = v2d->mask.xmin + x*(v2d->mask.xmax - v2d->mask.xmin);
+       *regiony = v2d->mask.ymin + y*(v2d->mask.ymax - v2d->mask.ymin);
 }
 
 static void draw_tracking_tracks(SpaceClip *sc, ARegion *ar, MovieClip *clip,
-                       int width, int height, float zoomx, float zoomy)
+                                 int width, int height, float zoomx, float zoomy)
 {
        float x, y;
-       MovieTracking* tracking= &clip->tracking;
-       ListBase *tracksbase= BKE_tracking_get_tracks(tracking);
+       MovieTracking *tracking = &clip->tracking;
+       ListBase *tracksbase = BKE_tracking_get_tracks(tracking);
        MovieTrackingTrack *track, *act_track;
        MovieTrackingMarker *marker;
-       int framenr= sc->user.framenr;
-       int undistort= sc->user.render_flag&MCLIP_PROXY_RENDER_UNDISTORT;
-       float *marker_pos= NULL, *fp, *active_pos= NULL, cur_pos[2];
+       int framenr = sc->user.framenr;
+       int undistort = sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT;
+       float *marker_pos = NULL, *fp, *active_pos = NULL, cur_pos[2];
 
        /* ** find window pixel coordinates of origin ** */
 
        /* UI_view2d_to_region_no_clip return integer values, this could
-          lead to 1px flickering when view is locked to selection during playbeck.
-          to avoid this flickering, calclate base point in the same way as it happens
-          in UI_view2d_to_region_no_clip, but do it in floats here */
+        * lead to 1px flickering when view is locked to selection during playbeck.
+        * to avoid this flickering, calculate base point in the same way as it happens
+        * in UI_view2d_to_region_no_clip, but do it in floats here */
 
        view2d_to_region_float(&ar->v2d, 0.0f, 0.0f, &x, &y);
 
@@ -883,67 +956,67 @@ static void draw_tracking_tracks(SpaceClip *sc, ARegion *ar, MovieClip *clip,
        glMultMatrixf(sc->stabmat);
        glScalef(width, height, 0);
 
-       act_track= BKE_tracking_active_track(tracking);
+       act_track = BKE_tracking_active_track(tracking);
 
-       if(sc->user.render_flag&MCLIP_PROXY_RENDER_UNDISTORT) {
-               int count= 0;
+       if (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT) {
+               int count = 0;
 
                /* count */
-               track= tracksbase->first;
-               while(track) {
-                       if((track->flag&TRACK_HIDDEN)==0) {
-                               marker= BKE_tracking_get_marker(track, framenr);
+               track = tracksbase->first;
+               while (track) {
+                       if ((track->flag & TRACK_HIDDEN)==0) {
+                               marker = BKE_tracking_get_marker(track, framenr);
 
-                               if(MARKER_VISIBLE(sc, marker))
+                               if (MARKER_VISIBLE(sc, marker))
                                        count++;
                        }
 
-                       track= track->next;
+                       track = track->next;
                }
 
                /* undistort */
-               if(count) {
-                       marker_pos= MEM_callocN(2*sizeof(float)*count, "draw_tracking_tracks marker_pos");
+               if (count) {
+                       marker_pos = MEM_callocN(2*sizeof(float)*count, "draw_tracking_tracks marker_pos");
 
-                       track= tracksbase->first;
-                       fp= marker_pos;
-                       while(track) {
-                               if((track->flag&TRACK_HIDDEN)==0) {
-                                       marker= BKE_tracking_get_marker(track, framenr);
+                       track = tracksbase->first;
+                       fp = marker_pos;
+                       while (track) {
+                               if ((track->flag & TRACK_HIDDEN)==0) {
+                                       marker = BKE_tracking_get_marker(track, framenr);
 
-                                       if(MARKER_VISIBLE(sc, marker)) {
+                                       if (MARKER_VISIBLE(sc, marker)) {
                                                ED_clip_point_undistorted_pos(sc, marker->pos, fp);
 
-                                               if(track==act_track)
-                                                       active_pos= fp;
+                                               if (track == act_track)
+                                                       active_pos = fp;
 
-                                               fp+= 2;
+                                               fp += 2;
                                        }
                                }
 
-                               track= track->next;
+                               track = track->next;
                        }
                }
        }
 
-       if(sc->flag&SC_SHOW_TRACK_PATH) {
-               track= tracksbase->first;
-               while(track) {
-                       if((track->flag&TRACK_HIDDEN)==0)
+       if (sc->flag & SC_SHOW_TRACK_PATH) {
+               track = tracksbase->first;
+               while (track) {
+                       if ((track->flag & TRACK_HIDDEN)==0)
                                draw_track_path(sc, clip, track);
 
-                       track= track->next;
+                       track = track->next;
                }
        }
 
        /* markers outline and non-selected areas */
-       track= tracksbase->first;
-       fp= marker_pos;
-       while(track) {
-               if((track->flag&TRACK_HIDDEN)==0) {
-                       marker= BKE_tracking_get_marker(track, framenr);
+       track = tracksbase->first;
+       fp = marker_pos;
+       while (track) {
+               if ((track->flag & TRACK_HIDDEN)==0) {
+                       marker = BKE_tracking_get_marker(track, framenr);
 
-                       if(MARKER_VISIBLE(sc, marker)) {
+                       if (MARKER_VISIBLE(sc, marker)) {
                                copy_v2_v2(cur_pos, fp ? fp : marker->pos);
 
                                draw_marker_outline(sc, track, marker, cur_pos, width, height);
@@ -951,45 +1024,45 @@ static void draw_tracking_tracks(SpaceClip *sc, ARegion *ar, MovieClip *clip,
                                draw_marker_slide_zones(sc, track, marker, cur_pos, 1, 0, 0, width, height);
                                draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 0, 0, width, height);
 
-                               if(fp)
-                                       fp+= 2;
+                               if (fp)
+                                       fp += 2;
                        }
                }
 
-               track= track->next;
+               track = track->next;
        }
 
        /* selected areas only, so selection wouldn't be overlapped by
-          non-selected areas */
-       track= tracksbase->first;
-       fp= marker_pos;
-       while(track) {
-               if((track->flag&TRACK_HIDDEN)==0) {
-                       int act= track==act_track;
-                       marker= BKE_tracking_get_marker(track, framenr);
-
-                       if(MARKER_VISIBLE(sc, marker)) {
-                               if(!act) {
+        * non-selected areas */
+       track = tracksbase->first;
+       fp = marker_pos;
+       while (track) {
+               if ((track->flag & TRACK_HIDDEN)==0) {
+                       int act = track == act_track;
+                       marker = BKE_tracking_get_marker(track, framenr);
+
+                       if (MARKER_VISIBLE(sc, marker)) {
+                               if (!act) {
                                        copy_v2_v2(cur_pos, fp ? fp : marker->pos);
 
                                        draw_marker_areas(sc, track, marker, cur_pos, width, height, 0, 1);
                                        draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 1, 0, width, height);
                                }
 
-                               if(fp)
-                                       fp+= 2;
+                               if (fp)
+                                       fp += 2;
                        }
                }
 
-               track= track->next;
+               track = track->next;
        }
 
        /* active marker would be displayed on top of everything else */
-       if(act_track) {
-               if((act_track->flag&TRACK_HIDDEN)==0) {
-                       marker= BKE_tracking_get_marker(act_track, framenr);
+       if (act_track) {
+               if ((act_track->flag & TRACK_HIDDEN)==0) {
+                       marker = BKE_tracking_get_marker(act_track, framenr);
 
-                       if(MARKER_VISIBLE(sc, marker)) {
+                       if (MARKER_VISIBLE(sc, marker)) {
                                copy_v2_v2(cur_pos, active_pos ? active_pos : marker->pos);
 
                                draw_marker_areas(sc, act_track, marker, cur_pos, width, height, 1, 1);
@@ -998,51 +1071,55 @@ static void draw_tracking_tracks(SpaceClip *sc, ARegion *ar, MovieClip *clip,
                }
        }
 
-       if(sc->flag&SC_SHOW_BUNDLES) {
-               MovieTrackingObject *object= BKE_tracking_active_object(tracking);
+       if (sc->flag & SC_SHOW_BUNDLES) {
+               MovieTrackingObject *object = BKE_tracking_active_object(tracking);
                float pos[4], vec[4], mat[4][4], aspy;
 
                glEnable(GL_POINT_SMOOTH);
                glPointSize(3.0f);
 
-               aspy= 1.0f/clip->tracking.camera.pixel_aspect;
+               aspy = 1.0f / clip->tracking.camera.pixel_aspect;
                BKE_tracking_projection_matrix(tracking, object, framenr, width, height, mat);
 
-               track= tracksbase->first;
-               while(track) {
-                       if((track->flag&TRACK_HIDDEN)==0 && track->flag&TRACK_HAS_BUNDLE) {
+               track = tracksbase->first;
+               while (track) {
+                       if ((track->flag & TRACK_HIDDEN) == 0 && track->flag & TRACK_HAS_BUNDLE) {
                                marker= BKE_tracking_get_marker(track, framenr);
 
-                               if(MARKER_VISIBLE(sc, marker)) {
+                               if (MARKER_VISIBLE(sc, marker)) {
                                        float npos[2];
                                        copy_v4_v4(vec, track->bundle_pos);
                                        vec[3]=1;
 
                                        mul_v4_m4v4(pos, mat, vec);
 
-                                       pos[0]= (pos[0]/(pos[3]*2.0f)+0.5f)*width;
-                                       pos[1]= (pos[1]/(pos[3]*2.0f)+0.5f)*height*aspy;
+                                       pos[0] = (pos[0] / (pos[3] * 2.0f) + 0.5f) * width;
+                                       pos[1] = (pos[1] / (pos[3] * 2.0f) + 0.5f) * height * aspy;
 
                                        BKE_tracking_apply_intrinsics(tracking, pos, npos);
 
-                                       if(npos[0]>=0.0f && npos[1]>=0.0f && npos[0]<=width && npos[1]<=height*aspy) {
-                                               vec[0]= (marker->pos[0]+track->offset[0])*width;
-                                               vec[1]= (marker->pos[1]+track->offset[1])*height*aspy;
+                                       if (npos[0] >= 0.0f && npos[1] >= 0.0f && npos[0] <= width && npos[1] <= height * aspy) {
+                                               vec[0] = (marker->pos[0] + track->offset[0]) * width;
+                                               vec[1] = (marker->pos[1] + track->offset[1]) * height * aspy;
 
                                                sub_v2_v2(vec, npos);
 
-                                               if(len_v2(vec)<3) glColor3f(0.0f, 1.0f, 0.0f);
-                                               else glColor3f(1.0f, 0.0f, 0.0f);
+                                               if (len_v2(vec)< 3.0f)
+                                                       glColor3f(0.0f, 1.0f, 0.0f);
+                                               else
+                                                       glColor3f(1.0f, 0.0f, 0.0f);
 
                                                glBegin(GL_POINTS);
-                                                       if(undistort) glVertex3f(pos[0]/width, pos[1]/(height*aspy), 0);
-                                                       else glVertex3f(npos[0]/width, npos[1]/(height*aspy), 0);
+                                                       if (undistort)
+                                                               glVertex3f(pos[0] / width, pos[1] / (height * aspy), 0);
+                                                       else
+                                                               glVertex3f(npos[0] / width, npos[1] / (height * aspy), 0);
                                                glEnd();
                                        }
                                }
                        }
 
-                       track= track->next;
+                       track = track->next;
                }
 
                glPointSize(1.0f);
@@ -1051,52 +1128,53 @@ static void draw_tracking_tracks(SpaceClip *sc, ARegion *ar, MovieClip *clip,
 
        glPopMatrix();
 
-       if(sc->flag&SC_SHOW_NAMES) {
+       if (sc->flag & SC_SHOW_NAMES) {
                /* scaling should be cleared before drawing texts, otherwise font would also be scaled */
-               track= tracksbase->first;
-               fp= marker_pos;
-               while(track) {
-                       if((track->flag&TRACK_HIDDEN)==0) {
-                               marker= BKE_tracking_get_marker(track, framenr);
+               track = tracksbase->first;
+               fp = marker_pos;
+               while (track) {
+                       if ((track->flag & TRACK_HIDDEN) == 0) {
+                               marker = BKE_tracking_get_marker(track, framenr);
 
-                               if(MARKER_VISIBLE(sc, marker)) {
-                                       int act= track==act_track;
+                               if (MARKER_VISIBLE(sc, marker)) {
+                                       int act = track == act_track;
 
                                        copy_v2_v2(cur_pos, fp ? fp : marker->pos);
 
                                        draw_marker_texts(sc, track, marker, cur_pos, act, width, height, zoomx, zoomy);
 
-                                       if(fp) fp+= 2;
+                                       if (fp)
+                                               fp += 2;
                                }
                        }
 
-                       track= track->next;
+                       track = track->next;
                }
        }
 
        glPopMatrix();
 
-       if(marker_pos)
+       if (marker_pos)
                MEM_freeN(marker_pos);
 }
 
 static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip, int width, int height, float zoomx, float zoomy)
 {
        float x, y;
-       const int n= 10;
+       const int n = 10;
        int i, j, a;
        float pos[2], tpos[2], grid[11][11][2];
-       MovieTracking *tracking= &clip->tracking;
-       float aspy= 1.0f/tracking->camera.pixel_aspect;
-       float dx= (float)width/n, dy= (float)height/n*aspy;
+       MovieTracking *tracking = &clip->tracking;
+       float aspy = 1.0f / tracking->camera.pixel_aspect;
+       float dx = (float)width / n, dy = (float)height / n * aspy;
 
-       if(sc->mode!=SC_MODE_DISTORTION)
+       if (sc->mode != SC_MODE_DISTORTION)
                return;
 
-       if(!tracking->camera.focal)
+       if (!tracking->camera.focal)
                return;
 
-       if((sc->flag&SC_SHOW_GRID)==0 && (sc->flag&SC_MANUAL_CALIBRATION)==0)
+       if ((sc->flag & SC_SHOW_GRID) == 0 && (sc->flag & SC_MANUAL_CALIBRATION) == 0)
                return;
 
        view2d_to_region_float(&ar->v2d, 0.0f, 0.0f, &x, &y);
@@ -1108,47 +1186,51 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip, int wid
        glScalef(width, height, 0);
 
        /* grid */
-       if(sc->flag&SC_SHOW_GRID) {
+       if (sc->flag & SC_SHOW_GRID) {
                float val[4][2], idx[4][2];
                float min[2], max[2];
 
-               for(a=0; a<4; a++) {
-                       if(a<2) val[a][a%2]= FLT_MAX;
-                       else val[a][a%2]= -FLT_MAX;
+               for (a = 0; a < 4; a++) {
+                       if (a < 2)
+                               val[a][a%2] = FLT_MAX;
+                       else
+                               val[a][a%2] = -FLT_MAX;
                }
 
                zero_v2(pos);
-               for(i= 0; i<=n; i++) {
-                       for(j= 0; j<=n; j++) {
-                               if(i==0 || j==0 || i==n || j==n) {
+               for (i = 0; i <= n; i++) {
+                       for (j = 0; j <= n; j++) {
+                               if (i == 0 || j == 0 || i == n || j == n) {
                                        BKE_tracking_apply_intrinsics(tracking, pos, tpos);
 
-                                       for(a=0; a<4; a++) {
+                                       for (a = 0; a < 4; a++) {
                                                int ok;
 
-                                               if(a<2) ok= tpos[a%2] < val[a][a%2];
-                                               else ok= tpos[a%2] > val[a][a%2];
+                                               if (a<2)
+                                                       ok = tpos[a%2] < val[a][a%2];
+                                               else
+                                                       ok= tpos[a%2] > val[a][a%2];
 
-                                               if(ok) {
+                                               if (ok) {
                                                        copy_v2_v2(val[a], tpos);
-                                                       idx[a][0]= j;
-                                                       idx[a][1]= i;
+                                                       idx[a][0] = j;
+                                                       idx[a][1] = i;
                                                }
                                        }
                                }
 
-                               pos[0]+= dx;
+                               pos[0] += dx;
                        }
 
-                       pos[0]= 0.0f;
-                       pos[1]+= dy;
+                       pos[0] = 0.0f;
+                       pos[1] += dy;
                }
 
                INIT_MINMAX2(min, max);
 
-               for(a= 0; a<4; a++) {
-                       pos[0]= idx[a][0]*dx;
-                       pos[1]= idx[a][1]*dy;
+               for (a = 0; a < 4; a++) {
+                       pos[0] = idx[a][0] * dx;
+                       pos[1] = idx[a][1] * dy;
 
                        BKE_tracking_invert_intrinsics(tracking, pos, tpos);
 
@@ -1156,50 +1238,50 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip, int wid
                }
 
                copy_v2_v2(pos, min);
-               dx= (max[0]-min[0])/n;
-               dy= (max[1]-min[1])/n;
+               dx = (max[0] - min[0]) / n;
+               dy = (max[1] - min[1]) / n;
 
-               for(i= 0; i<=n; i++) {
-                       for(j= 0; j<=n; j++) {
+               for (i = 0; i <= n; i++) {
+                       for (j = 0; j <= n; j++) {
                                BKE_tracking_apply_intrinsics(tracking, pos, grid[i][j]);
 
-                               grid[i][j][0]/= width;
-                               grid[i][j][1]/= height*aspy;
+                               grid[i][j][0] /= width;
+                               grid[i][j][1] /= height*aspy;
 
-                               pos[0]+= dx;
+                               pos[0] += dx;
                        }
 
-                       pos[0]= min[0];
-                       pos[1]+= dy;
+                       pos[0] = min[0];
+                       pos[1] += dy;
                }
 
                glColor3f(1.0f, 0.0f, 0.0f);
 
-               for(i= 0; i<=n; i++) {
+               for (i = 0; i <= n; i++) {
                        glBegin(GL_LINE_STRIP);
-                               for(j= 0; j<=n; j++) {
+                               for (j = 0; j <= n; j++) {
                                        glVertex2fv(grid[i][j]);
                                }
                        glEnd();
                }
 
-               for(j= 0; j<=n; j++) {
+               for (j = 0; j <= n; j++) {
                        glBegin(GL_LINE_STRIP);
-                               for(i= 0; i<=n; i++) {
+                               for (i = 0; i <= n; i++) {
                                        glVertex2fv(grid[i][j]);
                                }
                        glEnd();
                }
        }
 
-       if(sc->flag&SC_MANUAL_CALIBRATION && clip->gpd) {
+       if (sc->flag & SC_MANUAL_CALIBRATION && clip->gpd) {
                bGPDlayer *layer= clip->gpd->layers.first;
 
-               while(layer) {
-                       bGPDframe *frame= layer->frames.first;
+               while (layer) {
+                       bGPDframe *frame = layer->frames.first;
 
-                       if(layer->flag & GP_LAYER_HIDE) {
-                               layer= layer->next;
+                       if (layer->flag & GP_LAYER_HIDE) {
+                               layer = layer->next;
                                continue;
                        }
 
@@ -1207,28 +1289,28 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip, int wid
                        glLineWidth(layer->thickness);
                        glPointSize((float)(layer->thickness + 2));
 
-                       while(frame) {
-                               bGPDstroke *stroke= frame->strokes.first;
+                       while (frame) {
+                               bGPDstroke *stroke = frame->strokes.first;
 
-                               while(stroke) {
-                                       if(stroke->flag&GP_STROKE_2DSPACE) {
-                                               if(stroke->totpoints>1) {
+                               while (stroke) {
+                                       if (stroke->flag & GP_STROKE_2DSPACE) {
+                                               if (stroke->totpoints > 1) {
                                                        glBegin(GL_LINE_STRIP);
-                                                               for(i= 0; i<stroke->totpoints-1; i++) {
+                                                               for (i = 0; i < stroke->totpoints - 1; i++) {
                                                                        float npos[2], dpos[2], len;
                                                                        int steps;
 
-                                                                       pos[0]= stroke->points[i].x*width;
-                                                                       pos[1]= stroke->points[i].y*height*aspy;
+                                                                       pos[0] = stroke->points[i].x * width;
+                                                                       pos[1] = stroke->points[i].y * height * aspy;
 
-                                                                       npos[0]= stroke->points[i+1].x*width;
-                                                                       npos[1]= stroke->points[i+1].y*height*aspy;
+                                                                       npos[0] = stroke->points[i+1].x * width;
+                                                                       npos[1] = stroke->points[i+1].y * height * aspy;
 
-                                                                       len= len_v2v2(pos, npos);
+                                                                       len = len_v2v2(pos, npos);
                                                                        steps= ceil(len/5.0f);
 
                                                                        /* we want to distort only long straight lines */
-                                                                       if(stroke->totpoints==2) {
+                                                                       if (stroke->totpoints == 2) {
                                                                                BKE_tracking_invert_intrinsics(tracking, pos, pos);
                                                                                BKE_tracking_invert_intrinsics(tracking, npos, npos);
                                                                        }
@@ -1236,7 +1318,7 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip, int wid
                                                                        sub_v2_v2v2(dpos, npos, pos);
                                                                        mul_v2_fl(dpos, 1.0f/steps);
 
-                                                                       for(j= 0; j<=steps; j++) {
+                                                                       for (j = 0; j <= steps; j++) {
                                                                                BKE_tracking_apply_intrinsics(tracking, pos, tpos);
                                                                                glVertex2f(tpos[0]/width, tpos[1]/(height*aspy));
 
@@ -1245,20 +1327,20 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip, int wid
                                                                }
                                                        glEnd();
                                                }
-                                               else if(stroke->totpoints==1) {
+                                               else if (stroke->totpoints == 1) {
                                                        glBegin(GL_POINTS);
                                                                glVertex2f(stroke->points[0].x, stroke->points[0].y);
                                                        glEnd();
                                                }
                                        }
 
-                                       stroke= stroke->next;
+                                       stroke = stroke->next;
                                }
 
-                               frame= frame->next;
+                               frame = frame->next;
                        }
 
-                       layer= layer->next;
+                       layer = layer->next;
                }
 
                glLineWidth(1.0f);
@@ -1276,22 +1358,22 @@ void clip_draw_main(SpaceClip *sc, ARegion *ar, Scene *scene)
        float zoomx, zoomy;
 
        /* if no clip, nothing to do */
-       if(!clip)
+       if (!clip)
                return;
 
        ED_space_clip_size(sc, &width, &height);
        ED_space_clip_zoom(sc, ar, &zoomx, &zoomy);
 
-       if(sc->flag&SC_SHOW_STABLE) {
+       if (sc->flag & SC_SHOW_STABLE) {
                float smat[4][4], ismat[4][4];
 
-               ibuf= ED_space_clip_get_stable_buffer(sc, sc->loc, &sc->scale, &sc->angle);
+               ibuf = ED_space_clip_get_stable_buffer(sc, sc->loc, &sc->scale, &sc->angle);
 
-               if(ibuf) {
+               if (ibuf) {
                        float loc[2];
-                       float aspect= clip->tracking.camera.pixel_aspect;
+                       float aspect = clip->tracking.camera.pixel_aspect;
 
-                       if(width != ibuf->x)
+                       if (width != ibuf->x)
                                mul_v2_v2fl(loc, sc->loc, (float)width / ibuf->x);
                        else
                                copy_v2_v2(loc, sc->loc);
@@ -1299,22 +1381,23 @@ void clip_draw_main(SpaceClip *sc, ARegion *ar, Scene *scene)
                        BKE_tracking_stabdata_to_mat4(width, height, aspect, loc, sc->scale, sc->angle, sc->stabmat);
 
                        unit_m4(smat);
-                       smat[0][0]= 1.0f/width;
-                       smat[1][1]= 1.0f/height;
+                       smat[0][0] = 1.0f / width;
+                       smat[1][1] = 1.0f / height;
                        invert_m4_m4(ismat, smat);
 
                        mul_serie_m4(sc->unistabmat, smat, sc->stabmat, ismat, NULL, NULL, NULL, NULL, NULL);
                }
-       } else {
-               ibuf= ED_space_clip_get_buffer(sc);
+       }
+       else {
+               ibuf = ED_space_clip_get_buffer(sc);
 
                zero_v2(sc->loc);
-               sc->scale= 1.0f;
+               sc->scale = 1.0f;
                unit_m4(sc->stabmat);
                unit_m4(sc->unistabmat);
        }
 
-       if(ibuf) {
+       if (ibuf) {
                draw_movieclip_buffer(sc, ar, ibuf, width, height, zoomx, zoomy);
                IMB_freeImBuf(ibuf);
 
@@ -1329,20 +1412,20 @@ void clip_draw_main(SpaceClip *sc, ARegion *ar, Scene *scene)
 /* draw grease pencil */
 void clip_draw_grease_pencil(bContext *C, int onlyv2d)
 {
-       SpaceClip *sc= CTX_wm_space_clip(C);
-       MovieClip *clip= ED_space_clip(sc);
+       SpaceClip *sc = CTX_wm_space_clip(C);
+       MovieClip *clip = ED_space_clip(sc);
        ImBuf *ibuf;
 
-       if(!clip)
+       if (!clip)
                return;
 
-       if(onlyv2d) {
-               /* if manual calibration is used then grase pencil data is already
-                   drawed in draw_distortion */
-               if((sc->flag&SC_MANUAL_CALIBRATION)==0 || sc->mode!=SC_MODE_DISTORTION) {
-                       ibuf= ED_space_clip_get_buffer(sc);
+       if (onlyv2d) {
+               /* if manual calibration is used then grease pencil data is already
+                * drawed in draw_distortion */
+               if ((sc->flag & SC_MANUAL_CALIBRATION)==0 || sc->mode != SC_MODE_DISTORTION) {
+                       ibuf = ED_space_clip_get_buffer(sc);
 
-                       if(ibuf) {
+                       if (ibuf) {
                                glPushMatrix();
                                glMultMatrixf(sc->unistabmat);
                                draw_gpencil_2dimage(C, ibuf);
@@ -1351,7 +1434,8 @@ void clip_draw_grease_pencil(bContext *C, int onlyv2d)
                                glPopMatrix();
                        }
                }
-       } else {
+       }
+       else {
                draw_gpencil_view2d(C, 0);
        }
 }