Merging r38898 through r38940 from trunk into soc-2011-tomato
[blender.git] / source / blender / editors / space_clip / space_clip.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2011 Blender Foundation.
21  * All rights reserved.
22  *
23  *
24  * Contributor(s): Blender Foundation,
25  *                 Sergey Sharybin
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 /** \file blender/editors/space_clip/space_clip.c
31  *  \ingroup spclip
32  */
33
34 #include <string.h>
35 #include <stdio.h>
36
37 #include "DNA_scene_types.h"
38 #include "DNA_movieclip_types.h"
39
40 #include "MEM_guardedalloc.h"
41
42 #include "BLI_blenlib.h"
43 #include "BLI_utildefines.h"
44
45 #include "BKE_main.h"
46 #include "BKE_context.h"
47 #include "BKE_screen.h"
48 #include "BKE_movieclip.h"
49 #include "BKE_tracking.h"
50
51 #include "IMB_imbuf_types.h"
52
53 #include "ED_screen.h"
54 #include "ED_clip.h"
55 #include "ED_transform.h"
56
57 #include "IMB_imbuf.h"
58
59 #include "BIF_gl.h"
60
61 #include "WM_api.h"
62 #include "WM_types.h"
63
64 #include "UI_interface.h"
65 #include "UI_resources.h"
66 #include "UI_view2d.h"
67
68 #include "RNA_access.h"
69
70
71 #include "clip_intern.h"        // own include
72
73 static void clip_scopes_tag_refresh(ScrArea *sa)
74 {
75         SpaceClip *sc= (SpaceClip *)sa->spacedata.first;
76         ARegion *ar;
77
78         /* only while proeprties are visible */
79         for (ar=sa->regionbase.first; ar; ar=ar->next) {
80                 if (ar->regiontype == RGN_TYPE_UI && ar->flag & RGN_FLAG_HIDDEN)
81                         return;
82         }
83
84         sc->scopes.ok= 0;
85 }
86
87 static void clip_stabilization_tag_refresh(ScrArea *sa)
88 {
89         SpaceClip *sc= (SpaceClip *)sa->spacedata.first;
90         MovieClip *clip= ED_space_clip(sc);
91         MovieTrackingStabilization *stab= &clip->tracking.stabilization;
92
93         stab->ok= 0;
94 }
95
96 /* ******************** default callbacks for clip space ***************** */
97
98 static SpaceLink *clip_new(const bContext *UNUSED(C))
99 {
100         ARegion *ar;
101         SpaceClip *sc;
102
103         sc= MEM_callocN(sizeof(SpaceClip), "initclip");
104         sc->spacetype= SPACE_CLIP;
105         sc->flag= SC_SHOW_MARKER_PATTERN|SC_SHOW_TRACK_PATH;
106         sc->zoom= 1.0f;
107         sc->path_length= 20;
108         sc->scopes.track_preview_height= 120;
109
110         /* header */
111         ar= MEM_callocN(sizeof(ARegion), "header for clip");
112
113         BLI_addtail(&sc->regionbase, ar);
114         ar->regiontype= RGN_TYPE_HEADER;
115         ar->alignment= RGN_ALIGN_BOTTOM;
116
117         /* tools view */
118         ar= MEM_callocN(sizeof(ARegion), "tools for logic");
119
120         BLI_addtail(&sc->regionbase, ar);
121         ar->regiontype= RGN_TYPE_TOOLS;
122         ar->alignment= RGN_ALIGN_LEFT;
123
124         /* properties view */
125         ar= MEM_callocN(sizeof(ARegion), "properties for logic");
126
127         BLI_addtail(&sc->regionbase, ar);
128         ar->regiontype= RGN_TYPE_UI;
129         ar->alignment= RGN_ALIGN_RIGHT;
130
131         /* main area */
132         ar= MEM_callocN(sizeof(ARegion), "main area for clip");
133
134         BLI_addtail(&sc->regionbase, ar);
135         ar->regiontype= RGN_TYPE_WINDOW;
136
137         return (SpaceLink *)sc;
138 }
139
140 /* not spacelink itself */
141 static void clip_free(SpaceLink *sl)
142 {
143         SpaceClip *sc= (SpaceClip*) sl;
144
145         sc->clip= NULL;
146
147         if(sc->scopes.track_preview)
148                 IMB_freeImBuf(sc->scopes.track_preview);
149 }
150
151 /* spacetype; init callback */
152 static void clip_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
153 {
154
155 }
156
157 static SpaceLink *clip_duplicate(SpaceLink *sl)
158 {
159         SpaceClip *scn= MEM_dupallocN(sl);
160
161         /* clear or remove stuff from old */
162         scn->scopes.track_preview= NULL;
163         scn->scopes.ok= 0;
164
165         return (SpaceLink *)scn;
166 }
167
168 static void clip_listener(ScrArea *sa, wmNotifier *wmn)
169 {
170         /* context changes */
171         switch(wmn->category) {
172                 case NC_SCENE:
173                         switch(wmn->data) {
174                                 case ND_FRAME:
175                                         clip_scopes_tag_refresh(sa);
176                                         /* no break! */
177
178                                 case ND_FRAME_RANGE:
179                                         ED_area_tag_refresh(sa);
180                                         ED_area_tag_redraw(sa);
181                                         break;
182                         }
183                         break;
184                 case NC_MOVIECLIP:
185                         switch(wmn->data) {
186                                 case ND_DISPLAY:
187                                 case ND_SELECT:
188                                         clip_scopes_tag_refresh(sa);
189                                         ED_area_tag_redraw(sa);
190                                         break;
191                         }
192                         switch(wmn->action) {
193                                 case NA_REMOVED:
194                                 case NA_EDITED:
195                                 case NA_EVALUATED:
196                                         clip_stabilization_tag_refresh(sa);
197                                         /* no break! */
198
199                                 case NA_SELECTED:
200                                         clip_scopes_tag_refresh(sa);
201                                         ED_area_tag_redraw(sa);
202                                         break;
203                         }
204                         break;
205                 case NC_GEOM:
206                         switch(wmn->data) {
207                                 case ND_SELECT:
208                                         clip_scopes_tag_refresh(sa);
209                                         ED_area_tag_redraw(sa);
210                                         break;
211                         }
212                         break;
213                  case NC_SCREEN:
214                         if(wmn->data==ND_ANIMPLAY) {
215                                 ED_area_tag_redraw(sa);
216                         }
217                         break;
218                 case NC_SPACE:
219                         if(wmn->data==ND_SPACE_CLIP) {
220                                 clip_scopes_tag_refresh(sa);
221                                 clip_stabilization_tag_refresh(sa);
222                                 ED_area_tag_redraw(sa);
223                         }
224                         break;
225         }
226 }
227
228 static void clip_operatortypes(void)
229 {
230         WM_operatortype_append(CLIP_OT_open);
231         WM_operatortype_append(CLIP_OT_reload);
232         WM_operatortype_append(CLIP_OT_tools);
233          WM_operatortype_append(CLIP_OT_properties);
234         // WM_operatortype_append(CLIP_OT_unlink);
235         WM_operatortype_append(CLIP_OT_view_pan);
236         WM_operatortype_append(CLIP_OT_view_zoom);
237         WM_operatortype_append(CLIP_OT_view_zoom_in);
238         WM_operatortype_append(CLIP_OT_view_zoom_out);
239         WM_operatortype_append(CLIP_OT_view_zoom_ratio);
240         WM_operatortype_append(CLIP_OT_view_all);
241         WM_operatortype_append(CLIP_OT_view_selected);
242
243         WM_operatortype_append(CLIP_OT_select);
244         WM_operatortype_append(CLIP_OT_select_all);
245         WM_operatortype_append(CLIP_OT_select_border);
246         WM_operatortype_append(CLIP_OT_select_circle);
247         WM_operatortype_append(CLIP_OT_select_grouped);
248
249         WM_operatortype_append(CLIP_OT_add_marker);
250         WM_operatortype_append(CLIP_OT_delete_track);
251         WM_operatortype_append(CLIP_OT_delete_marker);
252
253         WM_operatortype_append(CLIP_OT_track_markers);
254         WM_operatortype_append(CLIP_OT_solve_camera);
255         WM_operatortype_append(CLIP_OT_clear_reconstruction);
256
257         WM_operatortype_append(CLIP_OT_disable_markers);
258         WM_operatortype_append(CLIP_OT_hide_tracks);
259         WM_operatortype_append(CLIP_OT_hide_tracks_clear);
260         WM_operatortype_append(CLIP_OT_lock_tracks);
261
262         WM_operatortype_append(CLIP_OT_set_origin);
263         WM_operatortype_append(CLIP_OT_set_floor);
264         WM_operatortype_append(CLIP_OT_set_axis);
265         WM_operatortype_append(CLIP_OT_set_scale);
266
267         WM_operatortype_append(CLIP_OT_set_center_principal);
268
269         WM_operatortype_append(CLIP_OT_clear_track_path);
270         WM_operatortype_append(CLIP_OT_join_tracks);
271         WM_operatortype_append(CLIP_OT_track_copy_color);
272
273         WM_operatortype_append(CLIP_OT_slide_marker);
274
275         WM_operatortype_append(CLIP_OT_frame_jump);
276
277         WM_operatortype_append(CLIP_OT_detect_features);
278
279         WM_operatortype_append(CLIP_OT_stabilize_2d_add);
280         WM_operatortype_append(CLIP_OT_stabilize_2d_remove);
281         WM_operatortype_append(CLIP_OT_stabilize_2d_select);
282 }
283
284 static void clip_keymap(struct wmKeyConfig *keyconf)
285 {
286         wmKeyMap *keymap;
287         wmKeyMapItem *kmi;
288
289         /* ******** Global hotkeys avalaible for all regions ******** */
290
291         keymap= WM_keymap_find(keyconf, "Clip Globals", SPACE_CLIP, 0);
292
293         WM_keymap_add_item(keymap, "CLIP_OT_open", OKEY, KM_PRESS, KM_ALT, 0);
294
295         WM_keymap_add_item(keymap, "CLIP_OT_tools", TKEY, KM_PRESS, 0, 0);
296         WM_keymap_add_item(keymap, "CLIP_OT_properties", NKEY, KM_PRESS, 0, 0);
297
298         kmi= WM_keymap_add_item(keymap, "CLIP_OT_track_markers", LEFTARROWKEY, KM_PRESS, KM_ALT, 0);
299         RNA_boolean_set(kmi->ptr, "backwards", 1);
300         WM_keymap_add_item(keymap, "CLIP_OT_track_markers", RIGHTARROWKEY, KM_PRESS, KM_ALT, 0);
301         kmi= WM_keymap_add_item(keymap, "CLIP_OT_track_markers", TKEY, KM_PRESS, KM_CTRL, 0);
302         RNA_boolean_set(kmi->ptr, "sequence", 1);
303         kmi= WM_keymap_add_item(keymap, "CLIP_OT_track_markers", TKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
304         RNA_boolean_set(kmi->ptr, "backwards", 1);
305         RNA_boolean_set(kmi->ptr, "sequence", 1);
306
307         /* ******** Hotkeys avalaible for main region only ******** */
308
309         keymap= WM_keymap_find(keyconf, "Clip Editor", SPACE_CLIP, 0);
310
311         /* View/navigation */
312
313         WM_keymap_add_item(keymap, "CLIP_OT_view_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
314         WM_keymap_add_item(keymap, "CLIP_OT_view_pan", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);
315         WM_keymap_add_item(keymap, "CLIP_OT_view_pan", MOUSEPAN, 0, 0, 0);
316
317         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
318         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom", MOUSEZOOM, 0, 0, 0);
319         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_in", WHEELINMOUSE, KM_PRESS, 0, 0);
320         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_out", WHEELOUTMOUSE, KM_PRESS, 0, 0);
321         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0);
322         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_out", PADMINUS, KM_PRESS, 0, 0);
323
324         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD8, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 8.0f);
325         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD4, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 4.0f);
326         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD2, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 2.0f);
327         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD1, KM_PRESS, 0, 0)->ptr, "ratio", 1.0f);
328         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD2, KM_PRESS, 0, 0)->ptr, "ratio", 0.5f);
329         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD4, KM_PRESS, 0, 0)->ptr, "ratio", 0.25f);
330         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD8, KM_PRESS, 0, 0)->ptr, "ratio", 0.125f);
331
332         WM_keymap_add_item(keymap, "CLIP_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
333
334         WM_keymap_add_item(keymap, "CLIP_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
335
336         WM_keymap_add_item(keymap, "CLIP_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
337         RNA_boolean_set(WM_keymap_add_item(keymap, "CLIP_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
338         WM_keymap_add_item(keymap, "CLIP_OT_select_all", AKEY, KM_PRESS, 0, 0);
339         RNA_enum_set(WM_keymap_add_item(keymap, "CLIP_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "action", SEL_INVERT);
340         WM_keymap_add_item(keymap, "CLIP_OT_select_border", BKEY, KM_PRESS, 0, 0);
341         WM_keymap_add_item(keymap, "CLIP_OT_select_circle", CKEY, KM_PRESS, 0, 0);
342         WM_keymap_add_menu(keymap, "CLIP_MT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0);
343
344         WM_keymap_add_item(keymap, "CLIP_OT_add_marker_slide", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
345
346         kmi= WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_ALT, 0);
347         RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_REMAINED);
348         kmi= WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_SHIFT, 0);
349         RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_UPTO);
350         kmi= WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0);
351         RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_ALL);
352
353         WM_keymap_add_item(keymap, "CLIP_OT_delete_track", DELKEY, KM_PRESS, 0, 0);
354         WM_keymap_add_item(keymap, "CLIP_OT_delete_track", XKEY, KM_PRESS, 0, 0);
355
356         WM_keymap_add_item(keymap, "CLIP_OT_delete_marker", DELKEY, KM_PRESS, KM_SHIFT, 0);
357
358         kmi= WM_keymap_add_item(keymap, "WM_OT_context_toggle", LKEY, KM_PRESS, 0, 0);
359         RNA_string_set(kmi->ptr, "data_path", "space_data.lock_selection");
360
361         WM_keymap_add_menu(keymap, "CLIP_MT_tracking_specials", WKEY, KM_PRESS, 0, 0);
362
363         WM_keymap_add_item(keymap, "CLIP_OT_slide_marker", LEFTMOUSE, KM_PRESS, 0, 0);
364
365         WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks", HKEY, KM_PRESS, 0, 0);
366         kmi= WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks", HKEY, KM_PRESS, KM_SHIFT, 0);
367         RNA_boolean_set(kmi->ptr, "unselected", 1);
368         WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks_clear", HKEY, KM_PRESS, KM_ALT, 0);
369
370         kmi= WM_keymap_add_item(keymap, "CLIP_OT_disable_markers", DKEY, KM_PRESS, 0, 0);
371         RNA_enum_set(kmi->ptr, "action", 2);
372
373         kmi= WM_keymap_add_item(keymap, "CLIP_OT_lock_tracks", LKEY, KM_PRESS, KM_CTRL, 0);
374         RNA_enum_set(kmi->ptr, "action", 0);
375
376         kmi= WM_keymap_add_item(keymap, "CLIP_OT_lock_tracks", LKEY, KM_PRESS, KM_ALT, 0);
377         RNA_enum_set(kmi->ptr, "action", 1);
378
379         WM_keymap_add_item(keymap, "CLIP_OT_frame_jump", LEFTARROWKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
380         kmi= WM_keymap_add_item(keymap, "CLIP_OT_frame_jump", RIGHTARROWKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
381         RNA_boolean_set(kmi->ptr, "end", 1);
382
383         WM_keymap_add_item(keymap, "CLIP_OT_join_tracks", JKEY, KM_PRESS, KM_CTRL, 0);
384
385         transform_keymap_for_space(keyconf, keymap, SPACE_CLIP);
386 }
387
388 const char *clip_context_dir[]= {"edit_movieclip", NULL};
389
390 static int clip_context(const bContext *C, const char *member, bContextDataResult *result)
391 {
392         SpaceClip *sc= CTX_wm_space_clip(C);
393
394         if(CTX_data_dir(member)) {
395                 CTX_data_dir_set(result, clip_context_dir);
396                 return 1;
397         }
398         else if(CTX_data_equals(member, "edit_movieclip")) {
399                 CTX_data_id_pointer_set(result, &sc->clip->id);
400                 return 1;
401         }
402
403         return 0;
404 }
405
406 static void clip_refresh(const bContext *C, ScrArea *UNUSED(sa))
407 {
408         SpaceClip *sc= CTX_wm_space_clip(C);
409
410         BKE_movieclip_user_set_frame(&sc->user, CTX_data_scene(C)->r.cfra);
411 }
412
413 /********************* main region ********************/
414
415 /* sets up the fields of the View2D from zoom and offset */
416 static void movieclip_main_area_set_view2d(SpaceClip *sc, ARegion *ar)
417 {
418         MovieClip *clip= ED_space_clip(sc);
419         float x1, y1, w, h;
420         int width, height, winx, winy;
421
422         ED_space_clip_size(sc, &width, &height);
423
424         w= width;
425         h= height;
426
427         if(clip)
428                 h*= clip->aspy/clip->aspx;
429
430         winx= ar->winrct.xmax - ar->winrct.xmin + 1;
431         winy= ar->winrct.ymax - ar->winrct.ymin + 1;
432
433         ar->v2d.tot.xmin= 0;
434         ar->v2d.tot.ymin= 0;
435         ar->v2d.tot.xmax= w;
436         ar->v2d.tot.ymax= h;
437
438         ar->v2d.mask.xmin= ar->v2d.mask.ymin= 0;
439         ar->v2d.mask.xmax= winx;
440         ar->v2d.mask.ymax= winy;
441
442         /* which part of the image space do we see? */
443         x1= ar->winrct.xmin+(winx-sc->zoom*w)/2.0f;
444         y1= ar->winrct.ymin+(winy-sc->zoom*h)/2.0f;
445
446         x1-= sc->zoom*sc->xof;
447         y1-= sc->zoom*sc->yof;
448
449         /* relative display right */
450         ar->v2d.cur.xmin= ((ar->winrct.xmin - (float)x1)/sc->zoom);
451         ar->v2d.cur.xmax= ar->v2d.cur.xmin + ((float)winx/sc->zoom);
452
453         /* relative display left */
454         ar->v2d.cur.ymin= ((ar->winrct.ymin-(float)y1)/sc->zoom);
455         ar->v2d.cur.ymax= ar->v2d.cur.ymin + ((float)winy/sc->zoom);
456
457         /* normalize 0.0..1.0 */
458         ar->v2d.cur.xmin /= w;
459         ar->v2d.cur.xmax /= w;
460         ar->v2d.cur.ymin /= h;
461         ar->v2d.cur.ymax /= h;
462 }
463
464 /* add handlers, stuff you only do once or on area/region changes */
465 static void clip_main_area_init(wmWindowManager *wm, ARegion *ar)
466 {
467         wmKeyMap *keymap;
468
469         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
470
471         /* own keymap */
472         keymap= WM_keymap_find(wm->defaultconf, "Clip Globals", SPACE_CLIP, 0);
473         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
474
475         keymap= WM_keymap_find(wm->defaultconf, "Clip Editor", SPACE_CLIP, 0);
476         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
477 }
478
479 static void clip_main_area_draw(const bContext *C, ARegion *ar)
480 {
481         /* draw entirely, view changes should be handled here */
482         SpaceClip *sc= CTX_wm_space_clip(C);
483         Scene *scene= CTX_data_scene(C);
484         MovieClip *clip= ED_space_clip(sc);
485
486         /* if trcking is in progress, we should sunchronize framenr from clipuser
487            so latest tracked frame would be shown */
488         if(clip && clip->tracking_context)
489                 BKE_tracking_sync_user(&sc->user, clip->tracking_context);
490
491         if(sc->flag&SC_LOCK_SELECTION) {
492                 ImBuf *tmpibuf= NULL;
493
494                 if(clip && clip->tracking.stabilization.flag&TRACKING_2D_STABILIZATION) {
495                         tmpibuf= ED_space_clip_acquire_stable_buffer(sc, NULL, NULL);
496                 }
497
498                 ED_clip_view_selection(sc, ar, 0);
499
500                 if(tmpibuf)
501                         IMB_freeImBuf(tmpibuf);
502         }
503
504         /* clear and setup matrix */
505         UI_ThemeClearColor(TH_BACK);
506         glClear(GL_COLOR_BUFFER_BIT);
507
508         /* data... */
509         movieclip_main_area_set_view2d(sc, ar);
510         draw_clip_main(sc, ar, scene);
511
512         /* reset view matrix */
513         UI_view2d_view_restore(C);
514 }
515
516 /****************** header region ******************/
517
518 /* add handlers, stuff you only do once or on area/region changes */
519 static void clip_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar)
520 {
521         ED_region_header_init(ar);
522 }
523
524 static void clip_header_area_draw(const bContext *C, ARegion *ar)
525 {
526         ED_region_header(C, ar);
527 }
528
529 /****************** tools region ******************/
530
531 /* add handlers, stuff you only do once or on area/region changes */
532 static void clip_tools_area_init(wmWindowManager *wm, ARegion *ar)
533 {
534         ED_region_panels_init(wm, ar);
535 }
536
537 static void clip_tools_area_draw(const bContext *C, ARegion *ar)
538 {
539         ED_region_panels(C, ar, 1, NULL, -1);
540 }
541
542 /****************** properties region ******************/
543
544 /* add handlers, stuff you only do once or on area/region changes */
545 static void clip_properties_area_init(wmWindowManager *wm, ARegion *ar)
546 {
547         wmKeyMap *keymap;
548
549         ED_region_panels_init(wm, ar);
550
551         keymap= WM_keymap_find(wm->defaultconf, "Clip Globals", SPACE_CLIP, 0);
552         WM_event_add_keymap_handler(&ar->handlers, keymap);
553 }
554
555 static void clip_properties_area_draw(const bContext *C, ARegion *ar)
556 {
557         SpaceClip *sc= CTX_wm_space_clip(C);
558
559         BKE_movieclip_update_scopes(sc->clip, &sc->user, &sc->scopes);
560
561         ED_region_panels(C, ar, 1, NULL, -1);
562 }
563
564 /********************* registration ********************/
565
566 /* only called once, from space/spacetypes.c */
567 void ED_spacetype_clip(void)
568 {
569         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype clip");
570         ARegionType *art;
571
572         st->spaceid= SPACE_CLIP;
573         strncpy(st->name, "Clip", BKE_ST_MAXNAME);
574
575         st->new= clip_new;
576         st->free= clip_free;
577         st->init= clip_init;
578         st->duplicate= clip_duplicate;
579         st->operatortypes= clip_operatortypes;
580         st->keymap= clip_keymap;
581         st->listener= clip_listener;
582         st->context= clip_context;
583         st->refresh= clip_refresh;
584
585         /* regions: main window */
586         art= MEM_callocN(sizeof(ARegionType), "spacetype clip region");
587         art->regionid= RGN_TYPE_WINDOW;
588         art->init= clip_main_area_init;
589         art->draw= clip_main_area_draw;
590         art->keymapflag= ED_KEYMAP_FRAMES|ED_KEYMAP_UI;
591
592         BLI_addhead(&st->regiontypes, art);
593
594         /* regions: properties */
595         art= MEM_callocN(sizeof(ARegionType), "spacetype clip region properties");
596         art->regionid= RGN_TYPE_UI;
597         art->prefsizex= UI_COMPACT_PANEL_WIDTH;
598         art->keymapflag= ED_KEYMAP_FRAMES|ED_KEYMAP_UI;
599         art->init= clip_properties_area_init;
600         art->draw= clip_properties_area_draw;
601         BLI_addhead(&st->regiontypes, art);
602         ED_clip_buttons_register(art);
603
604         /* regions: tools */
605         art= MEM_callocN(sizeof(ARegionType), "spacetype clip region tools");
606         art->regionid= RGN_TYPE_TOOLS;
607         art->prefsizex= UI_COMPACT_PANEL_WIDTH;
608         art->keymapflag= ED_KEYMAP_FRAMES|ED_KEYMAP_UI;
609         art->init= clip_tools_area_init;
610         art->draw= clip_tools_area_draw;
611
612         BLI_addhead(&st->regiontypes, art);
613
614         /* regions: header */
615         art= MEM_callocN(sizeof(ARegionType), "spacetype clip region");
616         art->regionid= RGN_TYPE_HEADER;
617         art->prefsizey= HEADERY;
618         art->keymapflag= ED_KEYMAP_FRAMES|ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_HEADER;
619
620         art->init= clip_header_area_init;
621         art->draw= clip_header_area_draw;
622
623         BLI_addhead(&st->regiontypes, art);
624
625         BKE_spacetype_register(st);
626 }