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