Camera tracking integration
[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 /* ******************** default callbacks for clip space ***************** */
88
89 static SpaceLink *clip_new(const bContext *UNUSED(C))
90 {
91         ARegion *ar;
92         SpaceClip *sc;
93
94         sc= MEM_callocN(sizeof(SpaceClip), "initclip");
95         sc->spacetype= SPACE_CLIP;
96         sc->flag= SC_SHOW_MARKER_PATTERN|SC_SHOW_TRACK_PATH;
97         sc->zoom= 1.0f;
98         sc->path_length= 20;
99         sc->scopes.track_preview_height= 120;
100
101         /* header */
102         ar= MEM_callocN(sizeof(ARegion), "header for clip");
103
104         BLI_addtail(&sc->regionbase, ar);
105         ar->regiontype= RGN_TYPE_HEADER;
106         ar->alignment= RGN_ALIGN_BOTTOM;
107
108         /* tools view */
109         ar= MEM_callocN(sizeof(ARegion), "tools for logic");
110
111         BLI_addtail(&sc->regionbase, ar);
112         ar->regiontype= RGN_TYPE_TOOLS;
113         ar->alignment= RGN_ALIGN_LEFT;
114
115         /* properties view */
116         ar= MEM_callocN(sizeof(ARegion), "properties for logic");
117
118         BLI_addtail(&sc->regionbase, ar);
119         ar->regiontype= RGN_TYPE_UI;
120         ar->alignment= RGN_ALIGN_RIGHT;
121
122         /* main area */
123         ar= MEM_callocN(sizeof(ARegion), "main area for clip");
124
125         BLI_addtail(&sc->regionbase, ar);
126         ar->regiontype= RGN_TYPE_WINDOW;
127
128         return (SpaceLink *)sc;
129 }
130
131 /* not spacelink itself */
132 static void clip_free(SpaceLink *sl)
133 {
134         SpaceClip *sc= (SpaceClip*) sl;
135
136         sc->clip= NULL;
137
138         if(sc->scopes.track_preview)
139                 IMB_freeImBuf(sc->scopes.track_preview);
140 }
141
142 /* spacetype; init callback */
143 static void clip_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
144 {
145
146 }
147
148 static SpaceLink *clip_duplicate(SpaceLink *sl)
149 {
150         SpaceClip *scn= MEM_dupallocN(sl);
151
152         /* clear or remove stuff from old */
153         scn->scopes.track_preview= NULL;
154         scn->scopes.ok= 0;
155
156         return (SpaceLink *)scn;
157 }
158
159 static void clip_listener(ScrArea *sa, wmNotifier *wmn)
160 {
161         /* context changes */
162         switch(wmn->category) {
163                 case NC_SCENE:
164                         switch(wmn->data) {
165                                 case ND_FRAME:
166                                         clip_scopes_tag_refresh(sa);
167                                         /* no break! */
168
169                                 case ND_FRAME_RANGE:
170                                         ED_area_tag_refresh(sa);
171                                         ED_area_tag_redraw(sa);
172                                         break;
173                         }
174                         break;
175                 case NC_MOVIECLIP:
176                         switch(wmn->data) {
177                                 case ND_DISPLAY:
178                                 case ND_SELECT:
179                                         clip_scopes_tag_refresh(sa);
180                                         ED_area_tag_redraw(sa);
181                                         break;
182                         }
183                         switch(wmn->action) {
184                                 case NA_REMOVED:
185                                 case NA_SELECTED:
186                                 case NA_EDITED:
187                                 case NA_EVALUATED:
188                                         clip_scopes_tag_refresh(sa);
189                                         ED_area_tag_redraw(sa);
190                                         break;
191                         }
192                         break;
193                 case NC_GEOM:
194                         switch(wmn->data) {
195                                 case ND_SELECT:
196                                         ED_area_tag_redraw(sa);
197                                         clip_scopes_tag_refresh(sa);
198                                         break;
199                         }
200                         break;
201                  case NC_SCREEN:
202                         if(wmn->data==ND_ANIMPLAY) {
203                                 ED_area_tag_redraw(sa);
204                         }
205                         break;
206                 case NC_SPACE:
207                         if(wmn->data==ND_SPACE_CLIP) {
208                                 clip_scopes_tag_refresh(sa);
209                                 ED_area_tag_redraw(sa);
210                         }
211                         break;
212         }
213 }
214
215 static void clip_operatortypes(void)
216 {
217         WM_operatortype_append(CLIP_OT_open);
218         WM_operatortype_append(CLIP_OT_reload);
219         WM_operatortype_append(CLIP_OT_tools);
220          WM_operatortype_append(CLIP_OT_properties);
221         // WM_operatortype_append(CLIP_OT_unlink);
222         WM_operatortype_append(CLIP_OT_view_pan);
223         WM_operatortype_append(CLIP_OT_view_zoom);
224         WM_operatortype_append(CLIP_OT_view_zoom_in);
225         WM_operatortype_append(CLIP_OT_view_zoom_out);
226         WM_operatortype_append(CLIP_OT_view_zoom_ratio);
227         WM_operatortype_append(CLIP_OT_view_all);
228         WM_operatortype_append(CLIP_OT_view_selected);
229
230         WM_operatortype_append(CLIP_OT_select);
231         WM_operatortype_append(CLIP_OT_select_all);
232         WM_operatortype_append(CLIP_OT_select_border);
233         WM_operatortype_append(CLIP_OT_select_circle);
234         WM_operatortype_append(CLIP_OT_select_grouped);
235
236         WM_operatortype_append(CLIP_OT_add_marker);
237         WM_operatortype_append(CLIP_OT_delete_track);
238         WM_operatortype_append(CLIP_OT_delete_marker);
239
240         WM_operatortype_append(CLIP_OT_track_markers);
241         WM_operatortype_append(CLIP_OT_solve_camera);
242         WM_operatortype_append(CLIP_OT_clear_reconstruction);
243
244         WM_operatortype_append(CLIP_OT_disable_markers);
245         WM_operatortype_append(CLIP_OT_hide_tracks);
246         WM_operatortype_append(CLIP_OT_hide_tracks_clear);
247         WM_operatortype_append(CLIP_OT_lock_tracks);
248
249         WM_operatortype_append(CLIP_OT_set_origin);
250         WM_operatortype_append(CLIP_OT_set_floor);
251         WM_operatortype_append(CLIP_OT_set_axis);
252         WM_operatortype_append(CLIP_OT_set_scale);
253
254         WM_operatortype_append(CLIP_OT_set_center_principal);
255
256         WM_operatortype_append(CLIP_OT_clear_track_path);
257         WM_operatortype_append(CLIP_OT_join_tracks);
258         WM_operatortype_append(CLIP_OT_track_copy_color);
259
260         WM_operatortype_append(CLIP_OT_slide_marker);
261
262         WM_operatortype_append(CLIP_OT_frame_jump);
263
264         WM_operatortype_append(CLIP_OT_detect_features);
265 }
266
267 static void clip_keymap(struct wmKeyConfig *keyconf)
268 {
269         wmKeyMap *keymap;
270         wmKeyMapItem *kmi;
271
272         /* ******** Global hotkeys avalaible for all regions ******** */
273
274         keymap= WM_keymap_find(keyconf, "Clip Globals", SPACE_CLIP, 0);
275
276         WM_keymap_add_item(keymap, "CLIP_OT_open", OKEY, KM_PRESS, KM_ALT, 0);
277
278         WM_keymap_add_item(keymap, "CLIP_OT_tools", TKEY, KM_PRESS, 0, 0);
279         WM_keymap_add_item(keymap, "CLIP_OT_properties", NKEY, KM_PRESS, 0, 0);
280
281         kmi= WM_keymap_add_item(keymap, "CLIP_OT_track_markers", LEFTARROWKEY, KM_PRESS, KM_ALT, 0);
282         RNA_boolean_set(kmi->ptr, "backwards", 1);
283         WM_keymap_add_item(keymap, "CLIP_OT_track_markers", RIGHTARROWKEY, KM_PRESS, KM_ALT, 0);
284         kmi= WM_keymap_add_item(keymap, "CLIP_OT_track_markers", TKEY, KM_PRESS, KM_CTRL, 0);
285         RNA_boolean_set(kmi->ptr, "sequence", 1);
286         kmi= WM_keymap_add_item(keymap, "CLIP_OT_track_markers", TKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
287         RNA_boolean_set(kmi->ptr, "backwards", 1);
288         RNA_boolean_set(kmi->ptr, "sequence", 1);
289
290         /* ******** Hotkeys avalaible for main region only ******** */
291
292         keymap= WM_keymap_find(keyconf, "Clip Editor", SPACE_CLIP, 0);
293
294         /* View/navigation */
295
296         WM_keymap_add_item(keymap, "CLIP_OT_view_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
297         WM_keymap_add_item(keymap, "CLIP_OT_view_pan", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);
298         WM_keymap_add_item(keymap, "CLIP_OT_view_pan", MOUSEPAN, 0, 0, 0);
299
300         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
301         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom", MOUSEZOOM, 0, 0, 0);
302         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_in", WHEELINMOUSE, KM_PRESS, 0, 0);
303         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_out", WHEELOUTMOUSE, KM_PRESS, 0, 0);
304         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0);
305         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_out", PADMINUS, KM_PRESS, 0, 0);
306
307         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD8, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 8.0f);
308         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD4, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 4.0f);
309         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD2, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 2.0f);
310         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD1, KM_PRESS, 0, 0)->ptr, "ratio", 1.0f);
311         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD2, KM_PRESS, 0, 0)->ptr, "ratio", 0.5f);
312         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD4, KM_PRESS, 0, 0)->ptr, "ratio", 0.25f);
313         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD8, KM_PRESS, 0, 0)->ptr, "ratio", 0.125f);
314
315         WM_keymap_add_item(keymap, "CLIP_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
316
317         WM_keymap_add_item(keymap, "CLIP_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
318
319         WM_keymap_add_item(keymap, "CLIP_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
320         RNA_boolean_set(WM_keymap_add_item(keymap, "CLIP_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
321         WM_keymap_add_item(keymap, "CLIP_OT_select_all", AKEY, KM_PRESS, 0, 0);
322         RNA_enum_set(WM_keymap_add_item(keymap, "CLIP_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "action", SEL_INVERT);
323         WM_keymap_add_item(keymap, "CLIP_OT_select_border", BKEY, KM_PRESS, 0, 0);
324         WM_keymap_add_item(keymap, "CLIP_OT_select_circle", CKEY, KM_PRESS, 0, 0);
325         WM_keymap_add_menu(keymap, "CLIP_MT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0);
326
327         WM_keymap_add_item(keymap, "CLIP_OT_add_marker_slide", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
328
329         kmi= WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_ALT, 0);
330         RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_REMAINED);
331         kmi= WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_SHIFT, 0);
332         RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_UPTO);
333         kmi= WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0);
334         RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_ALL);
335
336         WM_keymap_add_item(keymap, "CLIP_OT_delete_track", DELKEY, KM_PRESS, 0, 0);
337         WM_keymap_add_item(keymap, "CLIP_OT_delete_track", XKEY, KM_PRESS, 0, 0);
338
339         WM_keymap_add_item(keymap, "CLIP_OT_delete_marker", DELKEY, KM_PRESS, KM_SHIFT, 0);
340
341         kmi= WM_keymap_add_item(keymap, "WM_OT_context_toggle", LKEY, KM_PRESS, 0, 0);
342         RNA_string_set(kmi->ptr, "data_path", "space_data.lock_selection");
343
344         WM_keymap_add_menu(keymap, "CLIP_MT_tracking_specials", WKEY, KM_PRESS, 0, 0);
345
346         WM_keymap_add_item(keymap, "CLIP_OT_slide_marker", LEFTMOUSE, KM_PRESS, 0, 0);
347
348         WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks", HKEY, KM_PRESS, 0, 0);
349         kmi= WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks", HKEY, KM_PRESS, KM_SHIFT, 0);
350         RNA_boolean_set(kmi->ptr, "unselected", 1);
351         WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks_clear", HKEY, KM_PRESS, KM_ALT, 0);
352
353         kmi= WM_keymap_add_item(keymap, "CLIP_OT_disable_markers", DKEY, KM_PRESS, 0, 0);
354         RNA_enum_set(kmi->ptr, "action", 2);
355
356         kmi= WM_keymap_add_item(keymap, "CLIP_OT_lock_tracks", LKEY, KM_PRESS, KM_CTRL, 0);
357         RNA_enum_set(kmi->ptr, "action", 0);
358
359         kmi= WM_keymap_add_item(keymap, "CLIP_OT_lock_tracks", LKEY, KM_PRESS, KM_ALT, 0);
360         RNA_enum_set(kmi->ptr, "action", 1);
361
362         WM_keymap_add_item(keymap, "CLIP_OT_frame_jump", LEFTARROWKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
363         kmi= WM_keymap_add_item(keymap, "CLIP_OT_frame_jump", RIGHTARROWKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
364         RNA_boolean_set(kmi->ptr, "end", 1);
365
366         WM_keymap_add_item(keymap, "CLIP_OT_join_tracks", JKEY, KM_PRESS, KM_CTRL, 0);
367
368         transform_keymap_for_space(keyconf, keymap, SPACE_CLIP);
369 }
370
371 const char *clip_context_dir[]= {"edit_movieclip", NULL};
372
373 static int clip_context(const bContext *C, const char *member, bContextDataResult *result)
374 {
375         SpaceClip *sc= CTX_wm_space_clip(C);
376
377         if(CTX_data_dir(member)) {
378                 CTX_data_dir_set(result, clip_context_dir);
379                 return 1;
380         }
381         else if(CTX_data_equals(member, "edit_movieclip")) {
382                 CTX_data_id_pointer_set(result, &sc->clip->id);
383                 return 1;
384         }
385
386         return 0;
387 }
388
389 static void clip_refresh(const bContext *C, ScrArea *UNUSED(sa))
390 {
391         SpaceClip *sc= CTX_wm_space_clip(C);
392
393         BKE_movieclip_user_set_frame(&sc->user, CTX_data_scene(C)->r.cfra);
394 }
395
396 /********************* main region ********************/
397
398 /* sets up the fields of the View2D from zoom and offset */
399 static void movieclip_main_area_set_view2d(SpaceClip *sc, ARegion *ar)
400 {
401         MovieClip *clip= ED_space_clip(sc);
402         float x1, y1, w, h;
403         int width, height, winx, winy;
404
405         ED_space_clip_size(sc, &width, &height);
406
407         w= width;
408         h= height;
409
410         if(clip)
411                 h*= clip->aspy/clip->aspx;
412
413         winx= ar->winrct.xmax - ar->winrct.xmin + 1;
414         winy= ar->winrct.ymax - ar->winrct.ymin + 1;
415
416         ar->v2d.tot.xmin= 0;
417         ar->v2d.tot.ymin= 0;
418         ar->v2d.tot.xmax= w;
419         ar->v2d.tot.ymax= h;
420
421         ar->v2d.mask.xmin= ar->v2d.mask.ymin= 0;
422         ar->v2d.mask.xmax= winx;
423         ar->v2d.mask.ymax= winy;
424
425         /* which part of the image space do we see? */
426         x1= ar->winrct.xmin+(winx-sc->zoom*w)/2.0f;
427         y1= ar->winrct.ymin+(winy-sc->zoom*h)/2.0f;
428
429         x1-= sc->zoom*sc->xof;
430         y1-= sc->zoom*sc->yof;
431
432         /* relative display right */
433         ar->v2d.cur.xmin= ((ar->winrct.xmin - (float)x1)/sc->zoom);
434         ar->v2d.cur.xmax= ar->v2d.cur.xmin + ((float)winx/sc->zoom);
435
436         /* relative display left */
437         ar->v2d.cur.ymin= ((ar->winrct.ymin-(float)y1)/sc->zoom);
438         ar->v2d.cur.ymax= ar->v2d.cur.ymin + ((float)winy/sc->zoom);
439
440         /* normalize 0.0..1.0 */
441         ar->v2d.cur.xmin /= w;
442         ar->v2d.cur.xmax /= w;
443         ar->v2d.cur.ymin /= h;
444         ar->v2d.cur.ymax /= h;
445 }
446
447 /* add handlers, stuff you only do once or on area/region changes */
448 static void clip_main_area_init(wmWindowManager *wm, ARegion *ar)
449 {
450         wmKeyMap *keymap;
451
452         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
453
454         /* own keymap */
455         keymap= WM_keymap_find(wm->defaultconf, "Clip Globals", SPACE_CLIP, 0);
456         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
457
458         keymap= WM_keymap_find(wm->defaultconf, "Clip Editor", SPACE_CLIP, 0);
459         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
460 }
461
462 static void clip_main_area_draw(const bContext *C, ARegion *ar)
463 {
464         /* draw entirely, view changes should be handled here */
465         SpaceClip *sc= CTX_wm_space_clip(C);
466         Scene *scene= CTX_data_scene(C);
467         MovieClip *clip= ED_space_clip(sc);
468
469         /* if trcking is in progress, we should sunchronize framenr from clipuser
470            so latest tracked frame would be shown */
471         if(clip && clip->tracking_context)
472                 BKE_tracking_sync_user(&sc->user, clip->tracking_context);
473
474         if(sc->flag&SC_LOCK_SELECTION)
475                 ED_clip_view_selection(sc, ar, 0);
476
477         /* clear and setup matrix */
478         UI_ThemeClearColor(TH_BACK);
479         glClear(GL_COLOR_BUFFER_BIT);
480
481         /* data... */
482         movieclip_main_area_set_view2d(sc, ar);
483         draw_clip_main(sc, ar, scene);
484
485         /* reset view matrix */
486         UI_view2d_view_restore(C);
487 }
488
489 /****************** header region ******************/
490
491 /* add handlers, stuff you only do once or on area/region changes */
492 static void clip_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar)
493 {
494         ED_region_header_init(ar);
495 }
496
497 static void clip_header_area_draw(const bContext *C, ARegion *ar)
498 {
499         ED_region_header(C, ar);
500 }
501
502 /****************** tools region ******************/
503
504 /* add handlers, stuff you only do once or on area/region changes */
505 static void clip_tools_area_init(wmWindowManager *wm, ARegion *ar)
506 {
507         ED_region_panels_init(wm, ar);
508 }
509
510 static void clip_tools_area_draw(const bContext *C, ARegion *ar)
511 {
512         ED_region_panels(C, ar, 1, NULL, -1);
513 }
514
515 /****************** properties region ******************/
516
517 /* add handlers, stuff you only do once or on area/region changes */
518 static void clip_properties_area_init(wmWindowManager *wm, ARegion *ar)
519 {
520         wmKeyMap *keymap;
521
522         ED_region_panels_init(wm, ar);
523
524         keymap= WM_keymap_find(wm->defaultconf, "Clip Globals", SPACE_CLIP, 0);
525         WM_event_add_keymap_handler(&ar->handlers, keymap);
526 }
527
528 static void clip_properties_area_draw(const bContext *C, ARegion *ar)
529 {
530         SpaceClip *sc= CTX_wm_space_clip(C);
531
532         BKE_movieclip_update_scopes(sc->clip, &sc->user, &sc->scopes);
533
534         ED_region_panels(C, ar, 1, NULL, -1);
535 }
536
537 /********************* registration ********************/
538
539 /* only called once, from space/spacetypes.c */
540 void ED_spacetype_clip(void)
541 {
542         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype clip");
543         ARegionType *art;
544
545         st->spaceid= SPACE_CLIP;
546         strncpy(st->name, "Clip", BKE_ST_MAXNAME);
547
548         st->new= clip_new;
549         st->free= clip_free;
550         st->init= clip_init;
551         st->duplicate= clip_duplicate;
552         st->operatortypes= clip_operatortypes;
553         st->keymap= clip_keymap;
554         st->listener= clip_listener;
555         st->context= clip_context;
556         st->refresh= clip_refresh;
557
558         /* regions: main window */
559         art= MEM_callocN(sizeof(ARegionType), "spacetype clip region");
560         art->regionid= RGN_TYPE_WINDOW;
561         art->init= clip_main_area_init;
562         art->draw= clip_main_area_draw;
563         art->keymapflag= ED_KEYMAP_FRAMES|ED_KEYMAP_UI;
564
565         BLI_addhead(&st->regiontypes, art);
566
567         /* regions: properties */
568         art= MEM_callocN(sizeof(ARegionType), "spacetype clip region properties");
569         art->regionid= RGN_TYPE_UI;
570         art->prefsizex= UI_COMPACT_PANEL_WIDTH;
571         art->keymapflag= ED_KEYMAP_FRAMES|ED_KEYMAP_UI;
572         art->init= clip_properties_area_init;
573         art->draw= clip_properties_area_draw;
574         BLI_addhead(&st->regiontypes, art);
575         ED_clip_buttons_register(art);
576
577         /* regions: tools */
578         art= MEM_callocN(sizeof(ARegionType), "spacetype clip region tools");
579         art->regionid= RGN_TYPE_TOOLS;
580         art->prefsizex= UI_COMPACT_PANEL_WIDTH;
581         art->keymapflag= ED_KEYMAP_FRAMES|ED_KEYMAP_UI;
582         art->init= clip_tools_area_init;
583         art->draw= clip_tools_area_draw;
584
585         BLI_addhead(&st->regiontypes, art);
586
587         /* regions: header */
588         art= MEM_callocN(sizeof(ARegionType), "spacetype clip region");
589         art->regionid= RGN_TYPE_HEADER;
590         art->prefsizey= HEADERY;
591         art->keymapflag= ED_KEYMAP_FRAMES|ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_HEADER;
592
593         art->init= clip_header_area_init;
594         art->draw= clip_header_area_draw;
595
596         BLI_addhead(&st->regiontypes, art);
597
598         BKE_spacetype_register(st);
599 }