LEFT | RIGHT |
(no file at all) | |
| 1 /* |
| 2 * ***** BEGIN GPL LICENSE BLOCK ***** |
| 3 * |
| 4 * This program is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU General Public License |
| 6 * as published by the Free Software Foundation; either version 2 |
| 7 * of the License, or (at your option) any later version. |
| 8 * |
| 9 * This program is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with this program; if not, write to the Free Software Foundation, |
| 16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 * |
| 18 * The Original Code is Copyright (C) 2011 Blender Foundation. |
| 19 * All rights reserved. |
| 20 * |
| 21 * |
| 22 * Contributor(s): Blender Foundation, |
| 23 * Sergey Sharybin |
| 24 * |
| 25 * ***** END GPL LICENSE BLOCK ***** |
| 26 */ |
| 27 |
| 28 /** \file blender/editors/space_clip/clip_draw_graph.c |
| 29 * \ingroup spclip |
| 30 */ |
| 31 |
| 32 #include "DNA_movieclip_types.h" |
| 33 #include "DNA_scene_types.h" |
| 34 #include "DNA_object_types.h" /* SELECT */ |
| 35 |
| 36 #include "MEM_guardedalloc.h" |
| 37 |
| 38 #include "BKE_context.h" |
| 39 #include "BKE_movieclip.h" |
| 40 #include "BKE_tracking.h" |
| 41 |
| 42 #include "BLI_utildefines.h" |
| 43 #include "BLI_math.h" |
| 44 #include "BLI_string.h" |
| 45 |
| 46 #include "ED_screen.h" |
| 47 #include "ED_clip.h" |
| 48 |
| 49 #include "BIF_gl.h" |
| 50 |
| 51 #include "WM_types.h" |
| 52 |
| 53 #include "UI_interface.h" |
| 54 #include "UI_resources.h" |
| 55 #include "UI_view2d.h" |
| 56 |
| 57 #include "BLF_api.h" |
| 58 |
| 59 #include "clip_intern.h" // own include |
| 60 |
| 61 static void draw_graph_cfra(SpaceClip *sc, ARegion *ar, Scene *scene) |
| 62 { |
| 63 View2D *v2d= &ar->v2d; |
| 64 uiStyle *style= UI_GetStyle(); |
| 65 int fontid= style->widget.uifont_id, fontsize; |
| 66 float xscale, yscale, x, y; |
| 67 char str[32] = " t"; /* t is the character to start replacing from */ |
| 68 short slen; |
| 69 float vec[2]; |
| 70 |
| 71 /* Draw a light green line to indicate current frame */ |
| 72 vec[0]= (float)(sc->user.framenr * scene->r.framelen); |
| 73 |
| 74 UI_ThemeColor(TH_CFRAME); |
| 75 glLineWidth(2.0); |
| 76 |
| 77 glBegin(GL_LINE_STRIP); |
| 78 vec[1]= v2d->cur.ymin; |
| 79 glVertex2fv(vec); |
| 80 |
| 81 vec[1]= v2d->cur.ymax; |
| 82 glVertex2fv(vec); |
| 83 glEnd(); |
| 84 |
| 85 glLineWidth(1.0); |
| 86 |
| 87 UI_view2d_view_orthoSpecial(ar, v2d, 1); |
| 88 |
| 89 /* because the frame number text is subject to the same scaling as the c
ontents of the view */ |
| 90 UI_view2d_getscale(v2d, &xscale, &yscale); |
| 91 glScalef(1.0f/xscale, 1.0f, 1.0f); |
| 92 |
| 93 BLI_snprintf(&str[4], sizeof(str)-4, "%d", sc->user.framenr); |
| 94 slen= BLF_width(fontid, str); |
| 95 fontsize= BLF_height(fontid, str); |
| 96 |
| 97 /* get starting coordinates for drawing */ |
| 98 x= (float)sc->user.framenr * xscale; |
| 99 y= 18; |
| 100 |
| 101 /* draw green box around/behind text */ |
| 102 UI_ThemeColorShade(TH_CFRAME, 0); |
| 103 glRectf(x, y, x+slen, y+fontsize+4); |
| 104 |
| 105 /* draw current frame number - black text */ |
| 106 UI_ThemeColor(TH_TEXT); |
| 107 BLF_position(fontid, x-5, y+2, 0.f); |
| 108 BLF_draw(fontid, str, strlen(str)); |
| 109 |
| 110 /* restore view transform */ |
| 111 glScalef(xscale, 1.0, 1.0); |
| 112 } |
| 113 |
| 114 static void draw_clip_tracks_curves(SpaceClip *sc) |
| 115 { |
| 116 MovieClip *clip= ED_space_clip(sc); |
| 117 MovieTracking *tracking= &clip->tracking; |
| 118 MovieTrackingTrack *track; |
| 119 int size[2]; |
| 120 |
| 121 static float colors[2][3] = {{1.f, 0.f, 0.f}, |
| 122 {0.f, 1.f, 0.f}}
; |
| 123 |
| 124 |
| 125 BKE_movieclip_get_size(clip, &sc->user, &size[0], &size[1]); |
| 126 |
| 127 if(!size[0] || !size[1]) |
| 128 return; |
| 129 |
| 130 track= tracking->tracks.first; |
| 131 while(track) { |
| 132 if(TRACK_VIEW_SELECTED(sc, track)) { |
| 133 int coord; |
| 134 |
| 135 for(coord= 0; coord<2; coord++) { |
| 136 int i, lines= 0, prevfra= 0; |
| 137 float prevval= 0.f; |
| 138 |
| 139 glColor3fv(colors[coord]); |
| 140 |
| 141 for(i= 0; i<track->markersnr; i++) { |
| 142 MovieTrackingMarker *marker= &track->mar
kers[i]; |
| 143 |
| 144 if(marker->flag&MARKER_DISABLED) |
| 145 continue; |
| 146 |
| 147 if(lines && marker->framenr!=prevfra+1)
{ |
| 148 glEnd(); |
| 149 lines= 0; |
| 150 } |
| 151 |
| 152 if(!lines) { |
| 153 glBegin(GL_LINE_STRIP); |
| 154 lines= 1; |
| 155 prevval= marker->pos[coord]; |
| 156 } |
| 157 |
| 158 glVertex2f(marker->framenr, (marker->pos
[coord] - prevval) * size[coord]); |
| 159 |
| 160 prevval= marker->pos[coord]; |
| 161 prevfra= marker->framenr; |
| 162 } |
| 163 |
| 164 if(lines) |
| 165 glEnd(); |
| 166 } |
| 167 } |
| 168 |
| 169 track= track->next; |
| 170 } |
| 171 } |
| 172 |
| 173 static void draw_clip_frame_curves(SpaceClip *sc) |
| 174 { |
| 175 MovieClip *clip= ED_space_clip(sc); |
| 176 MovieTracking *tracking= &clip->tracking; |
| 177 MovieTrackingReconstruction *reconstruction= &tracking->reconstruction; |
| 178 int i, lines= 0, prevfra= 0; |
| 179 |
| 180 glColor3f(0.f, 0.f, 1.f); |
| 181 |
| 182 for(i= 0; i<reconstruction->camnr; i++) { |
| 183 MovieReconstructedCamera *camera= &reconstruction->cameras[i]; |
| 184 |
| 185 if(lines && camera->framenr!=prevfra+1) { |
| 186 glEnd(); |
| 187 lines= 0; |
| 188 } |
| 189 |
| 190 if(!lines) { |
| 191 glBegin(GL_LINE_STRIP); |
| 192 lines= 1; |
| 193 } |
| 194 |
| 195 glVertex2f(camera->framenr, camera->error); |
| 196 |
| 197 prevfra= camera->framenr; |
| 198 } |
| 199 |
| 200 if(lines) |
| 201 glEnd(); |
| 202 } |
| 203 |
| 204 void draw_clip_graph(SpaceClip *sc, ARegion *ar, Scene *scene) |
| 205 { |
| 206 View2D *v2d= &ar->v2d; |
| 207 View2DGrid *grid; |
| 208 short unitx= V2D_UNIT_FRAMESCALE, unity= V2D_UNIT_VALUES; |
| 209 |
| 210 /* grid */ |
| 211 grid= UI_view2d_grid_calc(scene, v2d, unitx, V2D_GRID_NOCLAMP, unity, V2
D_GRID_NOCLAMP, ar->winx, ar->winy); |
| 212 UI_view2d_grid_draw(v2d, grid, V2D_GRIDLINES_ALL); |
| 213 UI_view2d_grid_free(grid); |
| 214 |
| 215 if(sc->flag&SC_SHOW_GRAPH_TRACKS) |
| 216 draw_clip_tracks_curves(sc); |
| 217 |
| 218 if(sc->flag&SC_SHOW_GRAPH_FRAMES) |
| 219 draw_clip_frame_curves(sc); |
| 220 |
| 221 /* current frame */ |
| 222 draw_graph_cfra(sc, ar, scene); |
| 223 } |
LEFT | RIGHT |