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 "DNA_scene_types.h" 00036 #include "DNA_movieclip_types.h" 00037 00038 #include "MEM_guardedalloc.h" 00039 00040 #include "BLI_blenlib.h" 00041 #include "BLI_utildefines.h" 00042 #include "BLI_math.h" 00043 00044 #include "BKE_main.h" 00045 #include "BKE_context.h" 00046 #include "BKE_screen.h" 00047 #include "BKE_movieclip.h" 00048 #include "BKE_tracking.h" 00049 00050 #include "IMB_imbuf_types.h" 00051 00052 #include "ED_screen.h" 00053 #include "ED_clip.h" 00054 #include "ED_transform.h" 00055 00056 #include "IMB_imbuf.h" 00057 00058 #include "BIF_gl.h" 00059 00060 #include "WM_api.h" 00061 #include "WM_types.h" 00062 00063 #include "UI_interface.h" 00064 #include "UI_resources.h" 00065 #include "UI_view2d.h" 00066 00067 #include "RNA_access.h" 00068 00069 00070 #include "clip_intern.h" // own include 00071 00072 static void init_preview_region(const bContext *C, ARegion *ar) 00073 { 00074 Scene *scene= CTX_data_scene(C); 00075 00076 ar->regiontype= RGN_TYPE_PREVIEW; 00077 ar->alignment= RGN_ALIGN_TOP; 00078 ar->flag|= RGN_FLAG_HIDDEN; 00079 00080 ar->v2d.tot.xmin= 0.0f; 00081 ar->v2d.tot.ymin= (float)scene->r.sfra - 10.0f; 00082 ar->v2d.tot.xmax= (float)scene->r.efra; 00083 ar->v2d.tot.ymax= 10.0f; 00084 00085 ar->v2d.cur= ar->v2d.tot; 00086 00087 ar->v2d.min[0]= FLT_MIN; 00088 ar->v2d.min[1]= FLT_MIN; 00089 00090 ar->v2d.max[0]= MAXFRAMEF; 00091 ar->v2d.max[1]= FLT_MAX; 00092 00093 ar->v2d.scroll= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL); 00094 ar->v2d.scroll |= (V2D_SCROLL_LEFT|V2D_SCROLL_SCALE_VERTICAL); 00095 00096 ar->v2d.keeptot= 0; 00097 } 00098 00099 static ARegion *clip_has_preview_region(const bContext *C, ScrArea *sa) 00100 { 00101 ARegion *ar, *arnew; 00102 00103 ar= BKE_area_find_region_type(sa, RGN_TYPE_PREVIEW); 00104 if(ar) 00105 return ar; 00106 00107 /* add subdiv level; after header */ 00108 ar= BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); 00109 00110 /* is error! */ 00111 if(ar==NULL) 00112 return NULL; 00113 00114 arnew= MEM_callocN(sizeof(ARegion), "clip preview region"); 00115 00116 BLI_insertlinkbefore(&sa->regionbase, ar, arnew); 00117 init_preview_region(C, arnew); 00118 00119 return arnew; 00120 } 00121 00122 static void clip_scopes_tag_refresh(ScrArea *sa) 00123 { 00124 SpaceClip *sc= (SpaceClip *)sa->spacedata.first; 00125 ARegion *ar; 00126 00127 if(sc->mode!=SC_MODE_TRACKING) 00128 return; 00129 00130 /* only while proeprties are visible */ 00131 for (ar=sa->regionbase.first; ar; ar=ar->next) { 00132 if (ar->regiontype == RGN_TYPE_UI && ar->flag & RGN_FLAG_HIDDEN) 00133 return; 00134 } 00135 00136 sc->scopes.ok= 0; 00137 } 00138 00139 static void clip_stabilization_tag_refresh(ScrArea *sa) 00140 { 00141 SpaceClip *sc= (SpaceClip *)sa->spacedata.first; 00142 MovieClip *clip= ED_space_clip(sc); 00143 00144 if(clip) { 00145 MovieTrackingStabilization *stab= &clip->tracking.stabilization; 00146 00147 stab->ok= 0; 00148 } 00149 } 00150 00151 /* ******************** default callbacks for clip space ***************** */ 00152 00153 static SpaceLink *clip_new(const bContext *C) 00154 { 00155 ARegion *ar; 00156 SpaceClip *sc; 00157 00158 sc= MEM_callocN(sizeof(SpaceClip), "initclip"); 00159 sc->spacetype= SPACE_CLIP; 00160 sc->flag= SC_SHOW_MARKER_PATTERN|SC_SHOW_TRACK_PATH|SC_SHOW_GPENCIL|SC_MANUAL_CALIBRATION|SC_SHOW_GRAPH_TRACKS|SC_SHOW_GRAPH_FRAMES; 00161 sc->zoom= 1.0f; 00162 sc->path_length= 20; 00163 sc->scopes.track_preview_height= 120; 00164 00165 /* header */ 00166 ar= MEM_callocN(sizeof(ARegion), "header for clip"); 00167 00168 BLI_addtail(&sc->regionbase, ar); 00169 ar->regiontype= RGN_TYPE_HEADER; 00170 ar->alignment= RGN_ALIGN_BOTTOM; 00171 00172 /* tools view */ 00173 ar= MEM_callocN(sizeof(ARegion), "tools for clip"); 00174 00175 BLI_addtail(&sc->regionbase, ar); 00176 ar->regiontype= RGN_TYPE_TOOLS; 00177 ar->alignment= RGN_ALIGN_LEFT; 00178 00179 /* tool properties */ 00180 ar= MEM_callocN(sizeof(ARegion), "tool properties for clip"); 00181 00182 BLI_addtail(&sc->regionbase, ar); 00183 ar->regiontype= RGN_TYPE_TOOL_PROPS; 00184 ar->alignment= RGN_ALIGN_BOTTOM|RGN_SPLIT_PREV; 00185 00186 /* properties view */ 00187 ar= MEM_callocN(sizeof(ARegion), "properties for clip"); 00188 00189 BLI_addtail(&sc->regionbase, ar); 00190 ar->regiontype= RGN_TYPE_UI; 00191 ar->alignment= RGN_ALIGN_RIGHT; 00192 00193 /* preview view */ 00194 ar= MEM_callocN(sizeof(ARegion), "preview for clip"); 00195 00196 BLI_addtail(&sc->regionbase, ar); 00197 init_preview_region(C, ar); 00198 00199 /* main area */ 00200 ar= MEM_callocN(sizeof(ARegion), "main area for clip"); 00201 00202 BLI_addtail(&sc->regionbase, ar); 00203 ar->regiontype= RGN_TYPE_WINDOW; 00204 00205 return (SpaceLink *)sc; 00206 } 00207 00208 /* not spacelink itself */ 00209 static void clip_free(SpaceLink *sl) 00210 { 00211 SpaceClip *sc= (SpaceClip*) sl; 00212 00213 sc->clip= NULL; 00214 00215 if(sc->scopes.track_preview) 00216 IMB_freeImBuf(sc->scopes.track_preview); 00217 } 00218 00219 /* spacetype; init callback */ 00220 static void clip_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa)) 00221 { 00222 00223 } 00224 00225 static SpaceLink *clip_duplicate(SpaceLink *sl) 00226 { 00227 SpaceClip *scn= MEM_dupallocN(sl); 00228 00229 /* clear or remove stuff from old */ 00230 scn->scopes.track_preview= NULL; 00231 scn->scopes.ok= 0; 00232 00233 return (SpaceLink *)scn; 00234 } 00235 00236 static void clip_listener(ScrArea *sa, wmNotifier *wmn) 00237 { 00238 /* context changes */ 00239 switch(wmn->category) { 00240 case NC_SCENE: 00241 switch(wmn->data) { 00242 case ND_FRAME: 00243 clip_scopes_tag_refresh(sa); 00244 /* no break! */ 00245 00246 case ND_FRAME_RANGE: 00247 ED_area_tag_refresh(sa); 00248 ED_area_tag_redraw(sa); 00249 break; 00250 } 00251 break; 00252 case NC_MOVIECLIP: 00253 switch(wmn->data) { 00254 case ND_DISPLAY: 00255 case ND_SELECT: 00256 clip_scopes_tag_refresh(sa); 00257 ED_area_tag_redraw(sa); 00258 break; 00259 } 00260 switch(wmn->action) { 00261 case NA_REMOVED: 00262 case NA_EDITED: 00263 case NA_EVALUATED: 00264 clip_stabilization_tag_refresh(sa); 00265 /* no break! */ 00266 00267 case NA_SELECTED: 00268 clip_scopes_tag_refresh(sa); 00269 ED_area_tag_redraw(sa); 00270 break; 00271 } 00272 break; 00273 case NC_GEOM: 00274 switch(wmn->data) { 00275 case ND_SELECT: 00276 clip_scopes_tag_refresh(sa); 00277 ED_area_tag_redraw(sa); 00278 break; 00279 } 00280 break; 00281 case NC_SCREEN: 00282 if(wmn->data==ND_ANIMPLAY) { 00283 ED_area_tag_redraw(sa); 00284 } 00285 break; 00286 case NC_SPACE: 00287 if(wmn->data==ND_SPACE_CLIP) { 00288 clip_scopes_tag_refresh(sa); 00289 clip_stabilization_tag_refresh(sa); 00290 ED_area_tag_redraw(sa); 00291 } 00292 break; 00293 } 00294 } 00295 00296 static void clip_operatortypes(void) 00297 { 00298 /* ** clip_ops.c ** */ 00299 WM_operatortype_append(CLIP_OT_open); 00300 WM_operatortype_append(CLIP_OT_reload); 00301 WM_operatortype_append(CLIP_OT_view_pan); 00302 WM_operatortype_append(CLIP_OT_view_zoom); 00303 WM_operatortype_append(CLIP_OT_view_zoom_in); 00304 WM_operatortype_append(CLIP_OT_view_zoom_out); 00305 WM_operatortype_append(CLIP_OT_view_zoom_ratio); 00306 WM_operatortype_append(CLIP_OT_view_all); 00307 WM_operatortype_append(CLIP_OT_view_selected); 00308 WM_operatortype_append(CLIP_OT_change_frame); 00309 WM_operatortype_append(CLIP_OT_rebuild_proxy); 00310 WM_operatortype_append(CLIP_OT_mode_set); 00311 00312 /* ** clip_toolbar.c ** */ 00313 WM_operatortype_append(CLIP_OT_tools); 00314 WM_operatortype_append(CLIP_OT_properties); 00315 00316 /* ** tracking_ops.c ** */ 00317 00318 /* navigation */ 00319 WM_operatortype_append(CLIP_OT_frame_jump); 00320 00321 /* foorage */ 00322 WM_operatortype_append(CLIP_OT_set_center_principal); 00323 00324 /* selection */ 00325 WM_operatortype_append(CLIP_OT_select); 00326 WM_operatortype_append(CLIP_OT_select_all); 00327 WM_operatortype_append(CLIP_OT_select_border); 00328 WM_operatortype_append(CLIP_OT_select_circle); 00329 WM_operatortype_append(CLIP_OT_select_grouped); 00330 00331 /* markers */ 00332 WM_operatortype_append(CLIP_OT_add_marker); 00333 WM_operatortype_append(CLIP_OT_slide_marker); 00334 WM_operatortype_append(CLIP_OT_delete_track); 00335 WM_operatortype_append(CLIP_OT_delete_marker); 00336 00337 /* track */ 00338 WM_operatortype_append(CLIP_OT_track_markers); 00339 00340 /* solving */ 00341 WM_operatortype_append(CLIP_OT_solve_camera); 00342 WM_operatortype_append(CLIP_OT_clear_solution); 00343 00344 WM_operatortype_append(CLIP_OT_disable_markers); 00345 WM_operatortype_append(CLIP_OT_hide_tracks); 00346 WM_operatortype_append(CLIP_OT_hide_tracks_clear); 00347 WM_operatortype_append(CLIP_OT_lock_tracks); 00348 00349 /* orientation */ 00350 WM_operatortype_append(CLIP_OT_set_origin); 00351 WM_operatortype_append(CLIP_OT_set_floor); 00352 WM_operatortype_append(CLIP_OT_set_axis); 00353 WM_operatortype_append(CLIP_OT_set_scale); 00354 WM_operatortype_append(CLIP_OT_set_solution_scale); 00355 00356 /* detect */ 00357 WM_operatortype_append(CLIP_OT_detect_features); 00358 00359 /* stabilization */ 00360 WM_operatortype_append(CLIP_OT_stabilize_2d_add); 00361 WM_operatortype_append(CLIP_OT_stabilize_2d_remove); 00362 WM_operatortype_append(CLIP_OT_stabilize_2d_select); 00363 WM_operatortype_append(CLIP_OT_stabilize_2d_set_rotation); 00364 00365 /* clean-up */ 00366 WM_operatortype_append(CLIP_OT_clear_track_path); 00367 WM_operatortype_append(CLIP_OT_join_tracks); 00368 WM_operatortype_append(CLIP_OT_track_copy_color); 00369 00370 WM_operatortype_append(CLIP_OT_clean_tracks); 00371 00372 /* graph editing */ 00373 WM_operatortype_append(CLIP_OT_graph_select); 00374 WM_operatortype_append(CLIP_OT_graph_delete_curve); 00375 WM_operatortype_append(CLIP_OT_graph_delete_knot); 00376 00377 /* object tracking */ 00378 WM_operatortype_append(CLIP_OT_tracking_object_new); 00379 WM_operatortype_append(CLIP_OT_tracking_object_remove); 00380 00381 /* clipboard */ 00382 WM_operatortype_append(CLIP_OT_copy_tracks); 00383 WM_operatortype_append(CLIP_OT_paste_tracks); 00384 } 00385 00386 static void clip_keymap(struct wmKeyConfig *keyconf) 00387 { 00388 wmKeyMap *keymap; 00389 wmKeyMapItem *kmi; 00390 00391 /* ******** Global hotkeys avalaible for all regions ******** */ 00392 00393 keymap= WM_keymap_find(keyconf, "Clip", SPACE_CLIP, 0); 00394 00395 WM_keymap_add_item(keymap, "CLIP_OT_open", OKEY, KM_PRESS, KM_ALT, 0); 00396 00397 WM_keymap_add_item(keymap, "CLIP_OT_tools", TKEY, KM_PRESS, 0, 0); 00398 WM_keymap_add_item(keymap, "CLIP_OT_properties", NKEY, KM_PRESS, 0, 0); 00399 00400 /* 2d tracking */ 00401 kmi= WM_keymap_add_item(keymap, "CLIP_OT_track_markers", LEFTARROWKEY, KM_PRESS, KM_ALT, 0); 00402 RNA_boolean_set(kmi->ptr, "backwards", TRUE); 00403 RNA_boolean_set(kmi->ptr, "sequence", FALSE); 00404 WM_keymap_add_item(keymap, "CLIP_OT_track_markers", RIGHTARROWKEY, KM_PRESS, KM_ALT, 0); 00405 kmi= WM_keymap_add_item(keymap, "CLIP_OT_track_markers", TKEY, KM_PRESS, KM_CTRL, 0); 00406 RNA_boolean_set(kmi->ptr, "backwards", FALSE); 00407 RNA_boolean_set(kmi->ptr, "sequence", TRUE); 00408 kmi= WM_keymap_add_item(keymap, "CLIP_OT_track_markers", TKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0); 00409 RNA_boolean_set(kmi->ptr, "backwards", TRUE); 00410 RNA_boolean_set(kmi->ptr, "sequence", TRUE); 00411 00412 /* mode */ 00413 kmi= WM_keymap_add_item(keymap, "CLIP_OT_mode_set", TABKEY, KM_PRESS, 0, 0); 00414 RNA_enum_set(kmi->ptr, "mode", SC_MODE_RECONSTRUCTION); 00415 RNA_boolean_set(kmi->ptr, "toggle", TRUE); 00416 00417 kmi= WM_keymap_add_item(keymap, "CLIP_OT_mode_set", TABKEY, KM_PRESS, KM_CTRL, 0); 00418 RNA_enum_set(kmi->ptr, "mode", SC_MODE_DISTORTION); 00419 RNA_boolean_set(kmi->ptr, "toggle", TRUE); 00420 00421 /* ******** Hotkeys avalaible for main region only ******** */ 00422 00423 keymap= WM_keymap_find(keyconf, "Clip Editor", SPACE_CLIP, 0); 00424 00425 /* ** View/navigation ** */ 00426 00427 WM_keymap_add_item(keymap, "CLIP_OT_view_pan", MIDDLEMOUSE, KM_PRESS, 0, 0); 00428 WM_keymap_add_item(keymap, "CLIP_OT_view_pan", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0); 00429 WM_keymap_add_item(keymap, "CLIP_OT_view_pan", MOUSEPAN, 0, 0, 0); 00430 00431 WM_keymap_add_item(keymap, "CLIP_OT_view_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0); 00432 WM_keymap_add_item(keymap, "CLIP_OT_view_zoom", MOUSEZOOM, 0, 0, 0); 00433 WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_in", WHEELINMOUSE, KM_PRESS, 0, 0); 00434 WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_out", WHEELOUTMOUSE, KM_PRESS, 0, 0); 00435 WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0); 00436 WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_out", PADMINUS, KM_PRESS, 0, 0); 00437 00438 RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD8, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 8.0f); 00439 RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD4, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 4.0f); 00440 RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD2, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 2.0f); 00441 RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD1, KM_PRESS, 0, 0)->ptr, "ratio", 1.0f); 00442 RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD2, KM_PRESS, 0, 0)->ptr, "ratio", 0.5f); 00443 RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD4, KM_PRESS, 0, 0)->ptr, "ratio", 0.25f); 00444 RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD8, KM_PRESS, 0, 0)->ptr, "ratio", 0.125f); 00445 00446 WM_keymap_add_item(keymap, "CLIP_OT_view_all", HOMEKEY, KM_PRESS, 0, 0); 00447 WM_keymap_add_item(keymap, "CLIP_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0); 00448 00449 /* jump to special frame */ 00450 kmi= WM_keymap_add_item(keymap, "CLIP_OT_frame_jump", LEFTARROWKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0); 00451 RNA_enum_set(kmi->ptr, "position", 0); 00452 00453 kmi= WM_keymap_add_item(keymap, "CLIP_OT_frame_jump", RIGHTARROWKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0); 00454 RNA_enum_set(kmi->ptr, "position", 1); 00455 00456 kmi= WM_keymap_add_item(keymap, "CLIP_OT_frame_jump", LEFTARROWKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0); 00457 RNA_enum_set(kmi->ptr, "position", 2); 00458 00459 kmi= WM_keymap_add_item(keymap, "CLIP_OT_frame_jump", RIGHTARROWKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0); 00460 RNA_enum_set(kmi->ptr, "position", 3); 00461 00462 /* "timeline" */ 00463 WM_keymap_add_item(keymap, "CLIP_OT_change_frame", LEFTMOUSE, KM_PRESS, 0, 0); 00464 00465 /* selection */ 00466 kmi = WM_keymap_add_item(keymap, "CLIP_OT_select", SELECTMOUSE, KM_PRESS, 0, 0); 00467 RNA_boolean_set(kmi->ptr, "extend", FALSE); 00468 kmi = WM_keymap_add_item(keymap, "CLIP_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0); 00469 RNA_boolean_set(kmi->ptr, "extend", TRUE); 00470 kmi = WM_keymap_add_item(keymap, "CLIP_OT_select_all", AKEY, KM_PRESS, 0, 0); 00471 RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE); 00472 kmi = WM_keymap_add_item(keymap, "CLIP_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0); 00473 RNA_enum_set(kmi->ptr, "action", SEL_INVERT); 00474 WM_keymap_add_item(keymap, "CLIP_OT_select_border", BKEY, KM_PRESS, 0, 0); 00475 WM_keymap_add_item(keymap, "CLIP_OT_select_circle", CKEY, KM_PRESS, 0, 0); 00476 WM_keymap_add_menu(keymap, "CLIP_MT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0); 00477 00478 /* marker */ 00479 WM_keymap_add_item(keymap, "CLIP_OT_add_marker_slide", LEFTMOUSE, KM_PRESS, KM_CTRL, 0); 00480 00481 WM_keymap_add_item(keymap, "CLIP_OT_delete_marker", DELKEY, KM_PRESS, KM_SHIFT, 0); 00482 WM_keymap_add_item(keymap, "CLIP_OT_delete_marker", XKEY, KM_PRESS, KM_SHIFT, 0); 00483 00484 WM_keymap_add_item(keymap, "CLIP_OT_slide_marker", LEFTMOUSE, KM_PRESS, 0, 0); 00485 00486 kmi= WM_keymap_add_item(keymap, "CLIP_OT_disable_markers", DKEY, KM_PRESS, KM_SHIFT, 0); 00487 RNA_enum_set(kmi->ptr, "action", 2); /* toggle */ 00488 00489 /* tracks */ 00490 WM_keymap_add_item(keymap, "CLIP_OT_delete_track", DELKEY, KM_PRESS, 0, 0); 00491 WM_keymap_add_item(keymap, "CLIP_OT_delete_track", XKEY, KM_PRESS, 0, 0); 00492 00493 kmi= WM_keymap_add_item(keymap, "CLIP_OT_lock_tracks", LKEY, KM_PRESS, KM_CTRL, 0); 00494 RNA_enum_set(kmi->ptr, "action", 0); /* lock */ 00495 00496 kmi= WM_keymap_add_item(keymap, "CLIP_OT_lock_tracks", LKEY, KM_PRESS, KM_ALT, 0); 00497 RNA_enum_set(kmi->ptr, "action", 1); /* unlock */ 00498 00499 kmi= WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks", HKEY, KM_PRESS, 0, 0); 00500 RNA_boolean_set(kmi->ptr, "unselected", FALSE); 00501 00502 kmi= WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks", HKEY, KM_PRESS, KM_SHIFT, 0); 00503 RNA_boolean_set(kmi->ptr, "unselected", TRUE); 00504 00505 WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks_clear", HKEY, KM_PRESS, KM_ALT, 0); 00506 00507 /* clean-up */ 00508 kmi= WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_ALT, 0); 00509 RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_REMAINED); 00510 kmi= WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_SHIFT, 0); 00511 RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_UPTO); 00512 kmi= WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0); 00513 RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_ALL); 00514 00515 WM_keymap_add_item(keymap, "CLIP_OT_join_tracks", JKEY, KM_PRESS, KM_CTRL, 0); 00516 00517 /* menus */ 00518 WM_keymap_add_menu(keymap, "CLIP_MT_tracking_specials", WKEY, KM_PRESS, 0, 0); 00519 00520 /* display */ 00521 kmi= WM_keymap_add_item(keymap, "WM_OT_context_toggle", LKEY, KM_PRESS, 0, 0); 00522 RNA_string_set(kmi->ptr, "data_path", "space_data.lock_selection"); 00523 00524 kmi= WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); 00525 RNA_string_set(kmi->ptr, "data_path", "space_data.use_mute_footage"); 00526 00527 transform_keymap_for_space(keyconf, keymap, SPACE_CLIP); 00528 00529 /* ******** Hotkeys avalaible for preview region only ******** */ 00530 00531 keymap= WM_keymap_find(keyconf, "Clip Graph Editor", SPACE_CLIP, 0); 00532 00533 /* "timeline" */ 00534 WM_keymap_add_item(keymap, "CLIP_OT_change_frame", ACTIONMOUSE, KM_PRESS, 0, 0); 00535 00536 /* selection */ 00537 kmi = WM_keymap_add_item(keymap, "CLIP_OT_graph_select", SELECTMOUSE, KM_PRESS, 0, 0); 00538 RNA_boolean_set(kmi->ptr, "extend", FALSE); 00539 kmi = WM_keymap_add_item(keymap, "CLIP_OT_graph_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0); 00540 RNA_boolean_set(kmi->ptr, "extend", TRUE); 00541 00542 /* delete */ 00543 WM_keymap_add_item(keymap, "CLIP_OT_graph_delete_curve", DELKEY, KM_PRESS, 0, 0); 00544 WM_keymap_add_item(keymap, "CLIP_OT_graph_delete_curve", XKEY, KM_PRESS, 0, 0); 00545 00546 WM_keymap_add_item(keymap, "CLIP_OT_graph_delete_knot", DELKEY, KM_PRESS, KM_SHIFT, 0); 00547 WM_keymap_add_item(keymap, "CLIP_OT_graph_delete_knot", XKEY, KM_PRESS, KM_SHIFT, 0); 00548 } 00549 00550 const char *clip_context_dir[]= {"edit_movieclip", NULL}; 00551 00552 static int clip_context(const bContext *C, const char *member, bContextDataResult *result) 00553 { 00554 SpaceClip *sc= CTX_wm_space_clip(C); 00555 00556 if(CTX_data_dir(member)) { 00557 CTX_data_dir_set(result, clip_context_dir); 00558 return 1; 00559 } 00560 else if(CTX_data_equals(member, "edit_movieclip")) { 00561 CTX_data_id_pointer_set(result, &sc->clip->id); 00562 return 1; 00563 } 00564 00565 return 0; 00566 } 00567 00568 static void clip_refresh(const bContext *C, ScrArea *sa) 00569 { 00570 wmWindowManager *wm= CTX_wm_manager(C); 00571 wmWindow *window= CTX_wm_window(C); 00572 SpaceClip *sc= (SpaceClip *)sa->spacedata.first; 00573 ARegion *ar_main= BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); 00574 ARegion *ar_preview= clip_has_preview_region(C, sa); 00575 int view_changed= 0; 00576 00577 switch (sc->view) { 00578 case SC_VIEW_CLIP: 00579 if (ar_preview && !(ar_preview->flag & RGN_FLAG_HIDDEN)) { 00580 ar_preview->flag |= RGN_FLAG_HIDDEN; 00581 ar_preview->v2d.flag &= ~V2D_IS_INITIALISED; 00582 WM_event_remove_handlers((bContext*)C, &ar_preview->handlers); 00583 view_changed= 1; 00584 } 00585 if (ar_main && ar_main->alignment != RGN_ALIGN_NONE) { 00586 ar_main->alignment= RGN_ALIGN_NONE; 00587 view_changed= 1; 00588 } 00589 if (ar_preview && ar_preview->alignment != RGN_ALIGN_NONE) { 00590 ar_preview->alignment= RGN_ALIGN_NONE; 00591 view_changed= 1; 00592 } 00593 break; 00594 case SC_VIEW_GRAPH: 00595 if (ar_preview && (ar_preview->flag & RGN_FLAG_HIDDEN)) { 00596 ar_preview->flag &= ~RGN_FLAG_HIDDEN; 00597 ar_preview->v2d.flag &= ~V2D_IS_INITIALISED; 00598 ar_preview->v2d.cur = ar_preview->v2d.tot; 00599 view_changed= 1; 00600 } 00601 if (ar_main && ar_main->alignment != RGN_ALIGN_NONE) { 00602 ar_main->alignment= RGN_ALIGN_NONE; 00603 view_changed= 1; 00604 } 00605 if (ar_preview && ar_preview->alignment != RGN_ALIGN_TOP) { 00606 ar_preview->alignment= RGN_ALIGN_TOP; 00607 view_changed= 1; 00608 } 00609 break; 00610 } 00611 00612 if(view_changed) { 00613 ED_area_initialize(wm, window, sa); 00614 ED_area_tag_redraw(sa); 00615 } 00616 00617 BKE_movieclip_user_set_frame(&sc->user, CTX_data_scene(C)->r.cfra); 00618 } 00619 00620 /********************* main region ********************/ 00621 00622 /* sets up the fields of the View2D from zoom and offset */ 00623 static void movieclip_main_area_set_view2d(SpaceClip *sc, ARegion *ar) 00624 { 00625 MovieClip *clip= ED_space_clip(sc); 00626 float x1, y1, w, h; 00627 int width, height, winx, winy; 00628 00629 ED_space_clip_size(sc, &width, &height); 00630 00631 w= width; 00632 h= height; 00633 00634 if(clip) 00635 h*= clip->aspy/clip->aspx/clip->tracking.camera.pixel_aspect; 00636 00637 winx= ar->winrct.xmax - ar->winrct.xmin + 1; 00638 winy= ar->winrct.ymax - ar->winrct.ymin + 1; 00639 00640 ar->v2d.tot.xmin= 0; 00641 ar->v2d.tot.ymin= 0; 00642 ar->v2d.tot.xmax= w; 00643 ar->v2d.tot.ymax= h; 00644 00645 ar->v2d.mask.xmin= ar->v2d.mask.ymin= 0; 00646 ar->v2d.mask.xmax= winx; 00647 ar->v2d.mask.ymax= winy; 00648 00649 /* which part of the image space do we see? */ 00650 x1= ar->winrct.xmin+(winx-sc->zoom*w)/2.0f; 00651 y1= ar->winrct.ymin+(winy-sc->zoom*h)/2.0f; 00652 00653 x1-= sc->zoom*sc->xof; 00654 y1-= sc->zoom*sc->yof; 00655 00656 /* relative display right */ 00657 ar->v2d.cur.xmin= ((ar->winrct.xmin - (float)x1)/sc->zoom); 00658 ar->v2d.cur.xmax= ar->v2d.cur.xmin + ((float)winx/sc->zoom); 00659 00660 /* relative display left */ 00661 ar->v2d.cur.ymin= ((ar->winrct.ymin-(float)y1)/sc->zoom); 00662 ar->v2d.cur.ymax= ar->v2d.cur.ymin + ((float)winy/sc->zoom); 00663 00664 /* normalize 0.0..1.0 */ 00665 ar->v2d.cur.xmin /= w; 00666 ar->v2d.cur.xmax /= w; 00667 ar->v2d.cur.ymin /= h; 00668 ar->v2d.cur.ymax /= h; 00669 } 00670 00671 /* add handlers, stuff you only do once or on area/region changes */ 00672 static void clip_main_area_init(wmWindowManager *wm, ARegion *ar) 00673 { 00674 wmKeyMap *keymap; 00675 00676 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy); 00677 00678 /* own keymap */ 00679 keymap= WM_keymap_find(wm->defaultconf, "Clip", SPACE_CLIP, 0); 00680 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); 00681 00682 keymap= WM_keymap_find(wm->defaultconf, "Clip Editor", SPACE_CLIP, 0); 00683 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); 00684 } 00685 00686 static void clip_main_area_draw(const bContext *C, ARegion *ar) 00687 { 00688 /* draw entirely, view changes should be handled here */ 00689 SpaceClip *sc= CTX_wm_space_clip(C); 00690 Scene *scene= CTX_data_scene(C); 00691 MovieClip *clip= ED_space_clip(sc); 00692 00693 /* if trcking is in progress, we should sunchronize framenr from clipuser 00694 so latest tracked frame would be shown */ 00695 if(clip && clip->tracking_context) 00696 BKE_tracking_sync_user(&sc->user, clip->tracking_context); 00697 00698 if(sc->flag&SC_LOCK_SELECTION) { 00699 ImBuf *tmpibuf= NULL; 00700 00701 if(clip && clip->tracking.stabilization.flag&TRACKING_2D_STABILIZATION) { 00702 tmpibuf= ED_space_clip_get_stable_buffer(sc, NULL, NULL, NULL); 00703 } 00704 00705 if(ED_clip_view_selection(sc, ar, 0)) { 00706 sc->xof+= sc->xlockof; 00707 sc->yof+= sc->ylockof; 00708 } 00709 00710 if(tmpibuf) 00711 IMB_freeImBuf(tmpibuf); 00712 } 00713 00714 /* clear and setup matrix */ 00715 UI_ThemeClearColor(TH_BACK); 00716 glClear(GL_COLOR_BUFFER_BIT); 00717 00718 /* data... */ 00719 movieclip_main_area_set_view2d(sc, ar); 00720 00721 clip_draw_main(sc, ar, scene); 00722 00723 /* Grease Pencil */ 00724 clip_draw_grease_pencil((bContext *)C, 1); 00725 00726 /* reset view matrix */ 00727 UI_view2d_view_restore(C); 00728 00729 /* draw Grease Pencil - screen space only */ 00730 clip_draw_grease_pencil((bContext *)C, 0); 00731 } 00732 00733 static void clip_main_area_listener(ARegion *ar, wmNotifier *wmn) 00734 { 00735 /* context changes */ 00736 switch(wmn->category) { 00737 case NC_SCREEN: 00738 if (wmn->data==ND_GPENCIL) 00739 ED_region_tag_redraw(ar); 00740 break; 00741 } 00742 } 00743 00744 /****************** preview region ******************/ 00745 00746 static void clip_preview_area_init(wmWindowManager *wm, ARegion *ar) 00747 { 00748 wmKeyMap *keymap; 00749 00750 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy); 00751 00752 /* own keymap */ 00753 keymap= WM_keymap_find(wm->defaultconf, "Clip", SPACE_CLIP, 0); 00754 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); 00755 00756 keymap= WM_keymap_find(wm->defaultconf, "Clip Graph Editor", SPACE_CLIP, 0); 00757 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); 00758 } 00759 00760 static void clip_preview_area_draw(const bContext *C, ARegion *ar) 00761 { 00762 View2D *v2d= &ar->v2d; 00763 View2DScrollers *scrollers; 00764 SpaceClip *sc= CTX_wm_space_clip(C); 00765 Scene *scene= CTX_data_scene(C); 00766 short unitx= V2D_UNIT_FRAMESCALE, unity= V2D_UNIT_VALUES; 00767 00768 /* clear and setup matrix */ 00769 UI_ThemeClearColor(TH_BACK); 00770 glClear(GL_COLOR_BUFFER_BIT); 00771 00772 UI_view2d_view_ortho(v2d); 00773 00774 /* data... */ 00775 clip_draw_graph(sc, ar, scene); 00776 00777 /* reset view matrix */ 00778 UI_view2d_view_restore(C); 00779 00780 /* scrollers */ 00781 scrollers= UI_view2d_scrollers_calc(C, v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP); 00782 UI_view2d_scrollers_draw(C, v2d, scrollers); 00783 UI_view2d_scrollers_free(scrollers); 00784 } 00785 00786 static void clip_preview_area_listener(ARegion *UNUSED(ar), wmNotifier *UNUSED(wmn)) 00787 { 00788 } 00789 00790 /****************** header region ******************/ 00791 00792 /* add handlers, stuff you only do once or on area/region changes */ 00793 static void clip_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar) 00794 { 00795 ED_region_header_init(ar); 00796 } 00797 00798 static void clip_header_area_draw(const bContext *C, ARegion *ar) 00799 { 00800 ED_region_header(C, ar); 00801 } 00802 00803 /****************** tools region ******************/ 00804 00805 /* add handlers, stuff you only do once or on area/region changes */ 00806 static void clip_tools_area_init(wmWindowManager *wm, ARegion *ar) 00807 { 00808 ED_region_panels_init(wm, ar); 00809 } 00810 00811 static void clip_tools_area_draw(const bContext *C, ARegion *ar) 00812 { 00813 ED_region_panels(C, ar, 1, NULL, -1); 00814 } 00815 00816 /****************** tool properties region ******************/ 00817 00818 static void clip_props_area_listener(ARegion *ar, wmNotifier *wmn) 00819 { 00820 /* context changes */ 00821 switch(wmn->category) { 00822 case NC_WM: 00823 if(wmn->data == ND_HISTORY) 00824 ED_region_tag_redraw(ar); 00825 break; 00826 case NC_SCENE: 00827 if(wmn->data == ND_MODE) 00828 ED_region_tag_redraw(ar); 00829 break; 00830 case NC_SPACE: 00831 if(wmn->data == ND_SPACE_CLIP) 00832 ED_region_tag_redraw(ar); 00833 break; 00834 case NC_SCREEN: 00835 if(wmn->data == ND_GPENCIL) 00836 ED_region_tag_redraw(ar); 00837 break; 00838 } 00839 } 00840 00841 /****************** properties region ******************/ 00842 00843 /* add handlers, stuff you only do once or on area/region changes */ 00844 static void clip_properties_area_init(wmWindowManager *wm, ARegion *ar) 00845 { 00846 wmKeyMap *keymap; 00847 00848 ED_region_panels_init(wm, ar); 00849 00850 keymap= WM_keymap_find(wm->defaultconf, "Clip", SPACE_CLIP, 0); 00851 WM_event_add_keymap_handler(&ar->handlers, keymap); 00852 } 00853 00854 static void clip_properties_area_draw(const bContext *C, ARegion *ar) 00855 { 00856 SpaceClip *sc= CTX_wm_space_clip(C); 00857 00858 BKE_movieclip_update_scopes(sc->clip, &sc->user, &sc->scopes); 00859 00860 ED_region_panels(C, ar, 1, NULL, -1); 00861 } 00862 00863 static void clip_properties_area_listener(ARegion *ar, wmNotifier *wmn) 00864 { 00865 /* context changes */ 00866 switch(wmn->category) { 00867 case NC_SCREEN: 00868 if (wmn->data==ND_GPENCIL) 00869 ED_region_tag_redraw(ar); 00870 break; 00871 case NC_BRUSH: 00872 if(wmn->action==NA_EDITED) 00873 ED_region_tag_redraw(ar); 00874 break; 00875 } 00876 } 00877 00878 /********************* registration ********************/ 00879 00880 /* only called once, from space/spacetypes.c */ 00881 void ED_spacetype_clip(void) 00882 { 00883 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype clip"); 00884 ARegionType *art; 00885 00886 st->spaceid= SPACE_CLIP; 00887 strncpy(st->name, "Clip", BKE_ST_MAXNAME); 00888 00889 st->new= clip_new; 00890 st->free= clip_free; 00891 st->init= clip_init; 00892 st->duplicate= clip_duplicate; 00893 st->operatortypes= clip_operatortypes; 00894 st->keymap= clip_keymap; 00895 st->listener= clip_listener; 00896 st->context= clip_context; 00897 st->refresh= clip_refresh; 00898 00899 /* regions: main window */ 00900 art= MEM_callocN(sizeof(ARegionType), "spacetype clip region"); 00901 art->regionid= RGN_TYPE_WINDOW; 00902 art->init= clip_main_area_init; 00903 art->draw= clip_main_area_draw; 00904 art->listener= clip_main_area_listener; 00905 art->keymapflag= ED_KEYMAP_FRAMES|ED_KEYMAP_UI|ED_KEYMAP_GPENCIL; 00906 00907 BLI_addhead(&st->regiontypes, art); 00908 00909 /* preview */ 00910 art= MEM_callocN(sizeof(ARegionType), "spacetype clip region preview"); 00911 art->regionid = RGN_TYPE_PREVIEW; 00912 art->prefsizey = 240; 00913 art->init= clip_preview_area_init; 00914 art->draw= clip_preview_area_draw; 00915 art->listener= clip_preview_area_listener; 00916 art->keymapflag= ED_KEYMAP_FRAMES|ED_KEYMAP_UI|ED_KEYMAP_VIEW2D; 00917 00918 BLI_addhead(&st->regiontypes, art); 00919 00920 /* regions: properties */ 00921 art= MEM_callocN(sizeof(ARegionType), "spacetype clip region properties"); 00922 art->regionid= RGN_TYPE_UI; 00923 art->prefsizex= UI_COMPACT_PANEL_WIDTH; 00924 art->keymapflag= ED_KEYMAP_FRAMES|ED_KEYMAP_UI; 00925 art->init= clip_properties_area_init; 00926 art->draw= clip_properties_area_draw; 00927 art->listener= clip_properties_area_listener; 00928 BLI_addhead(&st->regiontypes, art); 00929 ED_clip_buttons_register(art); 00930 00931 /* regions: tools */ 00932 art= MEM_callocN(sizeof(ARegionType), "spacetype clip region tools"); 00933 art->regionid= RGN_TYPE_TOOLS; 00934 art->prefsizex= UI_COMPACT_PANEL_WIDTH; 00935 art->keymapflag= ED_KEYMAP_FRAMES|ED_KEYMAP_UI; 00936 art->listener= clip_props_area_listener; 00937 art->init= clip_tools_area_init; 00938 art->draw= clip_tools_area_draw; 00939 00940 BLI_addhead(&st->regiontypes, art); 00941 00942 /* tool properties */ 00943 art= MEM_callocN(sizeof(ARegionType), "spacetype clip tool properties region"); 00944 art->regionid = RGN_TYPE_TOOL_PROPS; 00945 art->prefsizex= 0; 00946 art->prefsizey= 120; 00947 art->keymapflag= ED_KEYMAP_FRAMES|ED_KEYMAP_UI; 00948 art->listener= clip_props_area_listener; 00949 art->init= clip_tools_area_init; 00950 art->draw= clip_tools_area_draw; 00951 ED_clip_tool_props_register(art); 00952 00953 BLI_addhead(&st->regiontypes, art); 00954 00955 /* regions: header */ 00956 art= MEM_callocN(sizeof(ARegionType), "spacetype clip region"); 00957 art->regionid= RGN_TYPE_HEADER; 00958 art->prefsizey= HEADERY; 00959 art->keymapflag= ED_KEYMAP_FRAMES|ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_HEADER; 00960 00961 art->init= clip_header_area_init; 00962 art->draw= clip_header_area_draw; 00963 00964 BLI_addhead(&st->regiontypes, art); 00965 00966 BKE_spacetype_register(st); 00967 }