Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2011 Blender Foundation. 00019 * All rights reserved. 00020 * 00021 * 00022 * Contributor(s): Blender Foundation, 00023 * Sergey Sharybin 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00032 #include <string.h> 00033 #include <stdio.h> 00034 00035 #include "MEM_guardedalloc.h" 00036 00037 #include "DNA_scene_types.h" 00038 #include "DNA_screen_types.h" 00039 #include "DNA_space_types.h" 00040 00041 #include "BLI_math.h" 00042 #include "BLI_utildefines.h" 00043 #include "BLI_listbase.h" 00044 00045 #include "BKE_context.h" 00046 #include "BKE_depsgraph.h" 00047 #include "BKE_screen.h" 00048 #include "BKE_movieclip.h" 00049 #include "BKE_tracking.h" 00050 00051 #include "ED_clip.h" 00052 #include "ED_gpencil.h" 00053 00054 #include "UI_interface.h" 00055 #include "UI_resources.h" 00056 00057 #include "RNA_access.h" 00058 00059 #include "WM_api.h" 00060 #include "WM_types.h" 00061 00062 #include "clip_intern.h" // own include 00063 00064 /* Panels */ 00065 00066 void ED_clip_buttons_register(ARegionType *art) 00067 { 00068 PanelType *pt; 00069 00070 pt= MEM_callocN(sizeof(PanelType), "spacetype clip panel gpencil"); 00071 strcpy(pt->idname, "CLIP_PT_gpencil"); 00072 strcpy(pt->label, "Grease Pencil"); 00073 pt->draw= gpencil_panel_standard; 00074 pt->flag|= PNL_DEFAULT_CLOSED; 00075 BLI_addtail(&art->paneltypes, pt); 00076 } 00077 00078 /********************* MovieClip Template ************************/ 00079 00080 void uiTemplateMovieClip(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, int compact) 00081 { 00082 PropertyRNA *prop; 00083 PointerRNA clipptr; 00084 MovieClip *clip; 00085 uiLayout *row, *split; 00086 uiBlock *block; 00087 00088 if(!ptr->data) 00089 return; 00090 00091 prop= RNA_struct_find_property(ptr, propname); 00092 if(!prop) { 00093 printf("%s: property not found: %s.%s\n", 00094 __func__, RNA_struct_identifier(ptr->type), propname); 00095 return; 00096 } 00097 00098 if(RNA_property_type(prop) != PROP_POINTER) { 00099 printf("%s: expected pointer property for %s.%s\n", 00100 __func__, RNA_struct_identifier(ptr->type), propname); 00101 return; 00102 } 00103 00104 clipptr= RNA_property_pointer_get(ptr, prop); 00105 clip= clipptr.data; 00106 00107 uiLayoutSetContextPointer(layout, "edit_movieclip", &clipptr); 00108 00109 if(!compact) 00110 uiTemplateID(layout, C, ptr, propname, NULL, "CLIP_OT_open", NULL); 00111 00112 if(clip) { 00113 row= uiLayoutRow(layout, 0); 00114 block= uiLayoutGetBlock(row); 00115 uiDefBut(block, LABEL, 0, "File Path:", 0, 19, 145, 19, NULL, 0, 0, 0, 0, ""); 00116 00117 row= uiLayoutRow(layout, 0); 00118 split = uiLayoutSplit(row, 0.0, 0); 00119 row= uiLayoutRow(split, 1); 00120 00121 uiItemR(row, &clipptr, "filepath", 0, "", ICON_NONE); 00122 uiItemO(row, "", ICON_FILE_REFRESH, "clip.reload"); 00123 } 00124 } 00125 00126 /********************* Track Template ************************/ 00127 00128 void uiTemplateTrack(uiLayout *layout, PointerRNA *ptr, const char *propname) 00129 { 00130 PropertyRNA *prop; 00131 PointerRNA scopesptr; 00132 uiBlock *block; 00133 rctf rect; 00134 MovieClipScopes *scopes; 00135 00136 if(!ptr->data) 00137 return; 00138 00139 prop= RNA_struct_find_property(ptr, propname); 00140 if(!prop) { 00141 printf("%s: property not found: %s.%s\n", 00142 __func__, RNA_struct_identifier(ptr->type), propname); 00143 return; 00144 } 00145 00146 if(RNA_property_type(prop) != PROP_POINTER) { 00147 printf("%s: expected pointer property for %s.%s\n", 00148 __func__, RNA_struct_identifier(ptr->type), propname); 00149 return; 00150 } 00151 00152 scopesptr= RNA_property_pointer_get(ptr, prop); 00153 scopes= (MovieClipScopes *)scopesptr.data; 00154 00155 rect.xmin= 0; rect.xmax= 200; 00156 rect.ymin= 0; rect.ymax= 120; 00157 00158 block= uiLayoutAbsoluteBlock(layout); 00159 00160 scopes->track_preview_height= (scopes->track_preview_height<=UI_UNIT_Y)?UI_UNIT_Y:scopes->track_preview_height; 00161 00162 uiDefBut(block, TRACKPREVIEW, 0, "", rect.xmin, rect.ymin, rect.xmax-rect.xmin, scopes->track_preview_height, scopes, 0, 0, 0, 0, ""); 00163 } 00164 00165 /********************* Marker Template ************************/ 00166 00167 #define B_MARKER_POS 3 00168 #define B_MARKER_OFFSET 4 00169 #define B_MARKER_PAT_DIM 5 00170 #define B_MARKER_SEARCH_POS 6 00171 #define B_MARKER_SEARCH_DIM 7 00172 #define B_MARKER_FLAG 8 00173 00174 typedef struct { 00175 int compact; /* compact mode */ 00176 00177 MovieClip *clip; 00178 MovieClipUser *user; /* user of clip */ 00179 MovieTrackingTrack *track; 00180 00181 int framenr; /* current frame number */ 00182 float marker_pos[2]; /* position of marker in pixel coords */ 00183 float track_pat[2]; /* position and dimensions of marker pattern in pixel coords */ 00184 float track_offset[2]; /* offset of "parenting" point */ 00185 float track_search_pos[2], track_search[2]; /* position and dimensions of marker search in pixel coords */ 00186 int marker_flag; /* marker's flags */ 00187 } MarkerUpdateCb; 00188 00189 static void to_pixel_space(float r[2], float a[2], int width, int height) 00190 { 00191 copy_v2_v2(r, a); 00192 r[0]*= width; 00193 r[1]*= height; 00194 } 00195 00196 static void marker_update_cb(bContext *C, void *arg_cb, void *UNUSED(arg)) 00197 { 00198 MarkerUpdateCb *cb= (MarkerUpdateCb*) arg_cb; 00199 MovieTrackingMarker *marker; 00200 00201 if(!cb->compact) 00202 return; 00203 00204 marker= BKE_tracking_ensure_marker(cb->track, cb->framenr); 00205 00206 marker->flag= cb->marker_flag; 00207 00208 WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, NULL); 00209 } 00210 00211 static void marker_block_handler(bContext *C, void *arg_cb, int event) 00212 { 00213 MarkerUpdateCb *cb= (MarkerUpdateCb*) arg_cb; 00214 MovieTrackingMarker *marker; 00215 int width, height, ok= 0; 00216 00217 BKE_movieclip_get_size(cb->clip, cb->user, &width, &height); 00218 00219 marker= BKE_tracking_ensure_marker(cb->track, cb->framenr); 00220 00221 if(event==B_MARKER_POS) { 00222 marker->pos[0]= cb->marker_pos[0]/width; 00223 marker->pos[1]= cb->marker_pos[1]/height; 00224 00225 /* to update position of "parented" objects */ 00226 DAG_id_tag_update(&cb->clip->id, 0); 00227 WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, NULL); 00228 00229 ok= 1; 00230 } 00231 else if(event==B_MARKER_PAT_DIM) { 00232 float dim[2], pat_dim[2]; 00233 00234 sub_v2_v2v2(pat_dim, cb->track->pat_max, cb->track->pat_min); 00235 00236 dim[0]= cb->track_pat[0]/width; 00237 dim[1]= cb->track_pat[1]/height; 00238 00239 sub_v2_v2(dim, pat_dim); 00240 mul_v2_fl(dim, 0.5f); 00241 00242 cb->track->pat_min[0]-= dim[0]; 00243 cb->track->pat_min[1]-= dim[1]; 00244 00245 cb->track->pat_max[0]+= dim[0]; 00246 cb->track->pat_max[1]+= dim[1]; 00247 00248 BKE_tracking_clamp_track(cb->track, CLAMP_PAT_DIM); 00249 00250 ok= 1; 00251 } 00252 else if(event==B_MARKER_SEARCH_POS) { 00253 float delta[2], side[2]; 00254 00255 sub_v2_v2v2(side, cb->track->search_max, cb->track->search_min); 00256 mul_v2_fl(side, 0.5f); 00257 00258 delta[0]= cb->track_search_pos[0]/width; 00259 delta[1]= cb->track_search_pos[1]/height; 00260 00261 sub_v2_v2v2(cb->track->search_min, delta, side); 00262 add_v2_v2v2(cb->track->search_max, delta, side); 00263 00264 BKE_tracking_clamp_track(cb->track, CLAMP_SEARCH_POS); 00265 00266 ok= 1; 00267 } 00268 else if(event==B_MARKER_SEARCH_DIM) { 00269 float dim[2], search_dim[2]; 00270 00271 sub_v2_v2v2(search_dim, cb->track->search_max, cb->track->search_min); 00272 00273 dim[0]= cb->track_search[0]/width; 00274 dim[1]= cb->track_search[1]/height; 00275 00276 sub_v2_v2(dim, search_dim); 00277 mul_v2_fl(dim, 0.5f); 00278 00279 cb->track->search_min[0]-= dim[0]; 00280 cb->track->search_min[1]-= dim[1]; 00281 00282 cb->track->search_max[0]+= dim[0]; 00283 cb->track->search_max[1]+= dim[1]; 00284 00285 BKE_tracking_clamp_track(cb->track, CLAMP_SEARCH_DIM); 00286 00287 ok= 1; 00288 } else if(event==B_MARKER_FLAG) { 00289 marker->flag= cb->marker_flag; 00290 00291 ok= 1; 00292 } else if(event==B_MARKER_OFFSET) { 00293 float offset[2], delta[2]; 00294 int i; 00295 00296 offset[0]= cb->track_offset[0]/width; 00297 offset[1]= cb->track_offset[1]/height; 00298 00299 sub_v2_v2v2(delta, offset, cb->track->offset); 00300 copy_v2_v2(cb->track->offset, offset); 00301 00302 for(i=0; i<cb->track->markersnr; i++) 00303 sub_v2_v2(cb->track->markers[i].pos, delta); 00304 00305 /* to update position of "parented" objects */ 00306 DAG_id_tag_update(&cb->clip->id, 0); 00307 WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, NULL); 00308 00309 ok= 1; 00310 } 00311 00312 if(ok) 00313 WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, cb->clip); 00314 } 00315 00316 void uiTemplateMarker(uiLayout *layout, PointerRNA *ptr, const char *propname, PointerRNA *userptr, PointerRNA *trackptr, int compact) 00317 { 00318 PropertyRNA *prop; 00319 uiBlock *block; 00320 uiBut *bt; 00321 PointerRNA clipptr; 00322 MovieClip *clip; 00323 MovieClipUser *user; 00324 MovieTrackingTrack *track; 00325 MovieTrackingMarker *marker; 00326 MarkerUpdateCb *cb; 00327 const char *tip; 00328 00329 if(!ptr->data) 00330 return; 00331 00332 prop= RNA_struct_find_property(ptr, propname); 00333 if(!prop) { 00334 printf("%s: property not found: %s.%s\n", 00335 __func__, RNA_struct_identifier(ptr->type), propname); 00336 return; 00337 } 00338 00339 if(RNA_property_type(prop) != PROP_POINTER) { 00340 printf("%s: expected pointer property for %s.%s\n", 00341 __func__, RNA_struct_identifier(ptr->type), propname); 00342 return; 00343 } 00344 00345 clipptr= RNA_property_pointer_get(ptr, prop); 00346 clip= (MovieClip *)clipptr.data; 00347 user= userptr->data; 00348 track= trackptr->data; 00349 00350 marker= BKE_tracking_get_marker(track, user->framenr); 00351 00352 cb= MEM_callocN(sizeof(MarkerUpdateCb), "uiTemplateMarker update_cb"); 00353 cb->compact= compact; 00354 cb->clip= clip; 00355 cb->user= user; 00356 cb->track= track; 00357 cb->marker_flag= marker->flag; 00358 cb->framenr= user->framenr; 00359 00360 if(compact) { 00361 block= uiLayoutGetBlock(layout); 00362 00363 if(cb->marker_flag&MARKER_DISABLED) 00364 tip= "Marker is disabled at current frame"; 00365 else 00366 tip= "Marker is enabled at current frame"; 00367 00368 bt= uiDefIconButBitI(block, TOGN, MARKER_DISABLED, 0, ICON_RESTRICT_VIEW_OFF, 0, 0, 20, 20, &cb->marker_flag, 0, 0, 1, 0, tip); 00369 uiButSetNFunc(bt, marker_update_cb, cb, NULL); 00370 } else { 00371 int width, height, step, digits; 00372 float pat_dim[2], pat_pos[2], search_dim[2], search_pos[2]; 00373 uiLayout *col; 00374 00375 BKE_movieclip_get_size(clip, user, &width, &height); 00376 00377 if(track->flag&TRACK_LOCKED) { 00378 uiLayoutSetActive(layout, 0); 00379 block= uiLayoutAbsoluteBlock(layout); 00380 uiDefBut(block, LABEL, 0, "Track is locked", 0, 0, 300, 19, NULL, 0, 0, 0, 0, ""); 00381 00382 return; 00383 } 00384 00385 step= 100; 00386 digits= 2; 00387 00388 sub_v2_v2v2(pat_dim, track->pat_max, track->pat_min); 00389 sub_v2_v2v2(search_dim, track->search_max, track->search_min); 00390 00391 add_v2_v2v2(search_pos, track->search_max, track->search_min); 00392 mul_v2_fl(search_pos, 0.5); 00393 00394 add_v2_v2v2(pat_pos, track->pat_max, track->pat_min); 00395 mul_v2_fl(pat_pos, 0.5); 00396 00397 to_pixel_space(cb->marker_pos, marker->pos, width, height); 00398 to_pixel_space(cb->track_pat, pat_dim, width, height); 00399 to_pixel_space(cb->track_search, search_dim, width, height); 00400 to_pixel_space(cb->track_search_pos, search_pos, width, height); 00401 to_pixel_space(cb->track_offset, track->offset, width, height); 00402 00403 cb->marker_flag= marker->flag; 00404 00405 block= uiLayoutAbsoluteBlock(layout); 00406 uiBlockSetHandleFunc(block, marker_block_handler, cb); 00407 uiBlockSetNFunc(block, marker_update_cb, cb, NULL); 00408 00409 if(cb->marker_flag&MARKER_DISABLED) 00410 tip= "Marker is disabled at current frame"; 00411 else 00412 tip= "Marker is enabled at current frame"; 00413 00414 uiDefButBitI(block, OPTIONN, MARKER_DISABLED, B_MARKER_FLAG, "Enabled", 10, 190, 145, 19, &cb->marker_flag, 00415 0, 0, 0, 0, tip); 00416 00417 col= uiLayoutColumn(layout, 1); 00418 uiLayoutSetActive(col, (cb->marker_flag&MARKER_DISABLED)==0); 00419 00420 block= uiLayoutAbsoluteBlock(col); 00421 uiBlockBeginAlign(block); 00422 00423 uiDefBut(block, LABEL, 0, "Position:", 0, 190, 300, 19, NULL, 0, 0, 0, 0, ""); 00424 uiDefButF(block, NUM, B_MARKER_POS, "X:", 10, 171, 145, 19, &cb->marker_pos[0], 00425 -10*width, 10.0*width, step, digits, "X-position of marker at frame in screen coordinates"); 00426 uiDefButF(block, NUM, B_MARKER_POS, "Y:", 165, 171, 145, 19, &cb->marker_pos[1], 00427 -10*height, 10.0*height, step, digits, "Y-position of marker at frame in screen coordinates"); 00428 00429 uiDefBut(block, LABEL, 0, "Offset:", 0, 152, 300, 19, NULL, 0, 0, 0, 0, ""); 00430 uiDefButF(block, NUM, B_MARKER_OFFSET, "X:", 10, 133, 145, 19, &cb->track_offset[0], 00431 -10*width, 10.0*width, step, digits, "X-offset to parenting point"); 00432 uiDefButF(block, NUM, B_MARKER_OFFSET, "Y:", 165, 133, 145, 19, &cb->track_offset[1], 00433 -10*height, 10.0*height, step, digits, "Y-offset to parenting point"); 00434 00435 uiDefBut(block, LABEL, 0, "Pattern Area:", 0, 114, 300, 19, NULL, 0, 0, 0, 0, ""); 00436 uiDefButF(block, NUM, B_MARKER_PAT_DIM, "Width:", 10, 95, 300, 19, &cb->track_pat[0], 3.0f, 00437 10.0*width, step, digits, "Width of marker's pattern in screen coordinates"); 00438 uiDefButF(block, NUM, B_MARKER_PAT_DIM, "Height:", 10, 76, 300, 19, &cb->track_pat[1], 3.0f, 00439 10.0*height, step, digits, "Height of marker's pattern in screen coordinates"); 00440 00441 uiDefBut(block, LABEL, 0, "Search Area:", 0, 57, 300, 19, NULL, 0, 0, 0, 0, ""); 00442 uiDefButF(block, NUM, B_MARKER_SEARCH_POS, "X:", 10, 38, 145, 19, &cb->track_search_pos[0], 00443 -width, width, step, digits, "X-position of search at frame relative to marker's position"); 00444 uiDefButF(block, NUM, B_MARKER_SEARCH_POS, "Y:", 165, 38, 145, 19, &cb->track_search_pos[1], 00445 -height, height, step, digits, "X-position of search at frame relative to marker's position"); 00446 uiDefButF(block, NUM, B_MARKER_SEARCH_DIM, "Width:", 10, 19, 300, 19, &cb->track_search[0], 3.0f, 00447 10.0*width, step, digits, "Width of marker's search in screen soordinates"); 00448 uiDefButF(block, NUM, B_MARKER_SEARCH_DIM, "Height:", 10, 0, 300, 19, &cb->track_search[1], 3.0f, 00449 10.0*height, step, digits, "Height of marker's search in screen soordinates"); 00450 00451 uiBlockEndAlign(block); 00452 } 00453 }