Change startup defaults
[blender.git] / source / blender / editors / space_clip / space_clip.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2011 Blender Foundation.
19  * All rights reserved.
20  *
21  *
22  * Contributor(s): Blender Foundation,
23  *                 Sergey Sharybin
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file blender/editors/space_clip/space_clip.c
29  *  \ingroup spclip
30  */
31
32 #include <string.h>
33 #include <stdio.h>
34
35 #include "DNA_scene_types.h"
36 #include "DNA_mask_types.h"
37 #include "DNA_movieclip_types.h"
38 #include "DNA_view3d_types.h"  /* for pivot point */
39
40 #include "MEM_guardedalloc.h"
41
42 #include "BLI_blenlib.h"
43 #include "BLI_utildefines.h"
44 #include "BLI_math.h"
45
46 #include "BKE_context.h"
47 #include "BKE_screen.h"
48 #include "BKE_library.h"
49 #include "BKE_movieclip.h"
50 #include "BKE_tracking.h"
51
52 #include "IMB_imbuf_types.h"
53
54 #include "ED_anim_api.h" /* for timeline cursor drawing */
55 #include "ED_mask.h"
56 #include "ED_space_api.h"
57 #include "ED_screen.h"
58 #include "ED_clip.h"
59 #include "ED_transform.h"
60 #include "ED_uvedit.h"  /* just for ED_image_draw_cursor */
61
62 #include "IMB_imbuf.h"
63
64 #include "GPU_glew.h"
65 #include "GPU_matrix.h"
66
67 #include "WM_api.h"
68 #include "WM_types.h"
69
70 #include "UI_interface.h"
71 #include "UI_resources.h"
72 #include "UI_view2d.h"
73
74 #include "RNA_access.h"
75
76
77 #include "clip_intern.h"  /* own include */
78
79 static void init_preview_region(const Scene *scene, const ScrArea *sa, const SpaceClip *sc, ARegion *ar)
80 {
81         ar->regiontype = RGN_TYPE_PREVIEW;
82         ar->alignment = RGN_ALIGN_TOP;
83         ar->flag |= RGN_FLAG_HIDDEN;
84
85         if (sc->view == SC_VIEW_DOPESHEET) {
86                 ar->v2d.tot.xmin = -10.0f;
87                 ar->v2d.tot.ymin = (float)(-sa->winy) / 3.0f;
88                 ar->v2d.tot.xmax = (float)(sa->winx);
89                 ar->v2d.tot.ymax = 0.0f;
90
91                 ar->v2d.cur = ar->v2d.tot;
92
93                 ar->v2d.min[0] = 0.0f;
94                 ar->v2d.min[1] = 0.0f;
95
96                 ar->v2d.max[0] = MAXFRAMEF;
97                 ar->v2d.max[1] = FLT_MAX;
98
99                 ar->v2d.minzoom = 0.01f;
100                 ar->v2d.maxzoom = 50;
101                 ar->v2d.scroll = (V2D_SCROLL_BOTTOM | V2D_SCROLL_SCALE_HORIZONTAL);
102                 ar->v2d.scroll |= (V2D_SCROLL_RIGHT);
103                 ar->v2d.keepzoom = V2D_LOCKZOOM_Y;
104                 ar->v2d.keepofs = V2D_KEEPOFS_Y;
105                 ar->v2d.align = V2D_ALIGN_NO_POS_Y;
106                 ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
107         }
108         else {
109                 ar->v2d.tot.xmin = 0.0f;
110                 ar->v2d.tot.ymin = -10.0f;
111                 ar->v2d.tot.xmax = (float)scene->r.efra;
112                 ar->v2d.tot.ymax = 10.0f;
113
114                 ar->v2d.cur = ar->v2d.tot;
115
116                 ar->v2d.min[0] = FLT_MIN;
117                 ar->v2d.min[1] = FLT_MIN;
118
119                 ar->v2d.max[0] = MAXFRAMEF;
120                 ar->v2d.max[1] = FLT_MAX;
121
122                 ar->v2d.scroll = (V2D_SCROLL_BOTTOM | V2D_SCROLL_SCALE_HORIZONTAL);
123                 ar->v2d.scroll |= (V2D_SCROLL_LEFT | V2D_SCROLL_SCALE_VERTICAL);
124
125                 ar->v2d.minzoom = 0.0f;
126                 ar->v2d.maxzoom = 0.0f;
127                 ar->v2d.keepzoom = 0;
128                 ar->v2d.keepofs = 0;
129                 ar->v2d.align = 0;
130                 ar->v2d.flag = 0;
131
132                 ar->v2d.keeptot = 0;
133         }
134 }
135
136 static void reinit_preview_region(const bContext *C, ARegion *ar)
137 {
138         Scene *scene = CTX_data_scene(C);
139         ScrArea *sa = CTX_wm_area(C);
140         SpaceClip *sc = CTX_wm_space_clip(C);
141
142         if (sc->view == SC_VIEW_DOPESHEET) {
143                 if ((ar->v2d.flag & V2D_VIEWSYNC_AREA_VERTICAL) == 0)
144                         init_preview_region(scene, sa, sc, ar);
145         }
146         else {
147                 if (ar->v2d.flag & V2D_VIEWSYNC_AREA_VERTICAL)
148                         init_preview_region(scene, sa, sc, ar);
149         }
150 }
151
152 static ARegion *ED_clip_has_preview_region(const bContext *C, ScrArea *sa)
153 {
154         ARegion *ar, *arnew;
155
156         ar = BKE_area_find_region_type(sa, RGN_TYPE_PREVIEW);
157         if (ar)
158                 return ar;
159
160         /* add subdiv level; after header */
161         ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
162
163         /* is error! */
164         if (ar == NULL)
165                 return NULL;
166
167         arnew = MEM_callocN(sizeof(ARegion), "clip preview region");
168
169         BLI_insertlinkbefore(&sa->regionbase, ar, arnew);
170         init_preview_region(CTX_data_scene(C), sa, CTX_wm_space_clip(C), arnew);
171
172         return arnew;
173 }
174
175 static ARegion *ED_clip_has_channels_region(ScrArea *sa)
176 {
177         ARegion *ar, *arnew;
178
179         ar = BKE_area_find_region_type(sa, RGN_TYPE_CHANNELS);
180         if (ar)
181                 return ar;
182
183         /* add subdiv level; after header */
184         ar = BKE_area_find_region_type(sa, RGN_TYPE_PREVIEW);
185
186         /* is error! */
187         if (ar == NULL)
188                 return NULL;
189
190         arnew = MEM_callocN(sizeof(ARegion), "clip channels region");
191
192         BLI_insertlinkbefore(&sa->regionbase, ar, arnew);
193         arnew->regiontype = RGN_TYPE_CHANNELS;
194         arnew->alignment = RGN_ALIGN_LEFT;
195
196         arnew->v2d.scroll = V2D_SCROLL_BOTTOM;
197         arnew->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
198
199         return arnew;
200 }
201
202 static void clip_scopes_tag_refresh(ScrArea *sa)
203 {
204         SpaceClip *sc = (SpaceClip *)sa->spacedata.first;
205         ARegion *ar;
206
207         if (sc->mode != SC_MODE_TRACKING)
208                 return;
209
210         /* only while properties are visible */
211         for (ar = sa->regionbase.first; ar; ar = ar->next) {
212                 if (ar->regiontype == RGN_TYPE_UI && ar->flag & RGN_FLAG_HIDDEN)
213                         return;
214         }
215
216         sc->scopes.ok = false;
217 }
218
219 static void clip_scopes_check_gpencil_change(ScrArea *sa)
220 {
221         SpaceClip *sc = (SpaceClip *)sa->spacedata.first;
222
223         if (sc->gpencil_src == SC_GPENCIL_SRC_TRACK) {
224                 clip_scopes_tag_refresh(sa);
225         }
226 }
227
228 /* ******************** default callbacks for clip space ***************** */
229
230 static SpaceLink *clip_new(const ScrArea *sa, const Scene *scene)
231 {
232         ARegion *ar;
233         SpaceClip *sc;
234
235         sc = MEM_callocN(sizeof(SpaceClip), "initclip");
236         sc->spacetype = SPACE_CLIP;
237         sc->flag = SC_SHOW_MARKER_PATTERN | SC_SHOW_TRACK_PATH |
238                    SC_SHOW_GRAPH_TRACKS_MOTION | SC_SHOW_GRAPH_FRAMES | SC_SHOW_GPENCIL;
239         sc->zoom = 1.0f;
240         sc->path_length = 20;
241         sc->scopes.track_preview_height = 120;
242         sc->around = V3D_AROUND_LOCAL_ORIGINS;
243
244         /* header */
245         ar = MEM_callocN(sizeof(ARegion), "header for clip");
246
247         BLI_addtail(&sc->regionbase, ar);
248         ar->regiontype = RGN_TYPE_HEADER;
249         ar->alignment = RGN_ALIGN_TOP;
250
251         /* tools view */
252         ar = MEM_callocN(sizeof(ARegion), "tools for clip");
253
254         BLI_addtail(&sc->regionbase, ar);
255         ar->regiontype = RGN_TYPE_TOOLS;
256         ar->alignment = RGN_ALIGN_LEFT;
257
258         /* properties view */
259         ar = MEM_callocN(sizeof(ARegion), "properties for clip");
260
261         BLI_addtail(&sc->regionbase, ar);
262         ar->regiontype = RGN_TYPE_UI;
263         ar->alignment = RGN_ALIGN_RIGHT;
264
265         /* channels view */
266         ar = MEM_callocN(sizeof(ARegion), "channels for clip");
267
268         BLI_addtail(&sc->regionbase, ar);
269         ar->regiontype = RGN_TYPE_CHANNELS;
270         ar->alignment = RGN_ALIGN_LEFT;
271
272         ar->v2d.scroll = V2D_SCROLL_BOTTOM;
273         ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
274
275         /* preview view */
276         ar = MEM_callocN(sizeof(ARegion), "preview for clip");
277
278         BLI_addtail(&sc->regionbase, ar);
279         init_preview_region(scene, sa, sc, ar);
280
281         /* main region */
282         ar = MEM_callocN(sizeof(ARegion), "main region for clip");
283
284         BLI_addtail(&sc->regionbase, ar);
285         ar->regiontype = RGN_TYPE_WINDOW;
286
287         return (SpaceLink *) sc;
288 }
289
290 /* not spacelink itself */
291 static void clip_free(SpaceLink *sl)
292 {
293         SpaceClip *sc = (SpaceClip *) sl;
294
295         sc->clip = NULL;
296
297         if (sc->scopes.track_preview)
298                 IMB_freeImBuf(sc->scopes.track_preview);
299
300         if (sc->scopes.track_search)
301                 IMB_freeImBuf(sc->scopes.track_search);
302 }
303
304 /* spacetype; init callback */
305 static void clip_init(struct wmWindowManager *UNUSED(wm), ScrArea *sa)
306 {
307         ListBase *lb = WM_dropboxmap_find("Clip", SPACE_CLIP, 0);
308
309         /* add drop boxes */
310         WM_event_add_dropbox_handler(&sa->handlers, lb);
311 }
312
313 static SpaceLink *clip_duplicate(SpaceLink *sl)
314 {
315         SpaceClip *scn = MEM_dupallocN(sl);
316
317         /* clear or remove stuff from old */
318         scn->scopes.track_search = NULL;
319         scn->scopes.track_preview = NULL;
320         scn->scopes.ok = false;
321
322         return (SpaceLink *)scn;
323 }
324
325 static void clip_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn, Scene *UNUSED(scene),
326                           WorkSpace *UNUSED(workspace))
327 {
328         /* context changes */
329         switch (wmn->category) {
330                 case NC_SCENE:
331                         switch (wmn->data) {
332                                 case ND_FRAME:
333                                         clip_scopes_tag_refresh(sa);
334                                         ATTR_FALLTHROUGH;
335
336                                 case ND_FRAME_RANGE:
337                                         ED_area_tag_redraw(sa);
338                                         break;
339                         }
340                         break;
341                 case NC_MOVIECLIP:
342                         switch (wmn->data) {
343                                 case ND_DISPLAY:
344                                 case ND_SELECT:
345                                         clip_scopes_tag_refresh(sa);
346                                         ED_area_tag_redraw(sa);
347                                         break;
348                         }
349                         switch (wmn->action) {
350                                 case NA_REMOVED:
351                                 case NA_EDITED:
352                                 case NA_EVALUATED:
353                                         /* fall-through */
354
355                                 case NA_SELECTED:
356                                         clip_scopes_tag_refresh(sa);
357                                         ED_area_tag_redraw(sa);
358                                         break;
359                         }
360                         break;
361                 case NC_MASK:
362                         switch (wmn->data) {
363                                 case ND_SELECT:
364                                 case ND_DATA:
365                                 case ND_DRAW:
366                                         ED_area_tag_redraw(sa);
367                                         break;
368                         }
369                         switch (wmn->action) {
370                                 case NA_SELECTED:
371                                         ED_area_tag_redraw(sa);
372                                         break;
373                                 case NA_EDITED:
374                                         ED_area_tag_redraw(sa);
375                                         break;
376                         }
377                         break;
378                 case NC_GEOM:
379                         switch (wmn->data) {
380                                 case ND_SELECT:
381                                         clip_scopes_tag_refresh(sa);
382                                         ED_area_tag_redraw(sa);
383                                         break;
384                         }
385                         break;
386                 case NC_SCREEN:
387                         switch (wmn->data) {
388                                 case ND_ANIMPLAY:
389                                         ED_area_tag_redraw(sa);
390                                         break;
391                         }
392                         break;
393                 case NC_SPACE:
394                         if (wmn->data == ND_SPACE_CLIP) {
395                                 clip_scopes_tag_refresh(sa);
396                                 ED_area_tag_redraw(sa);
397                         }
398                         break;
399                 case NC_GPENCIL:
400                         if (wmn->action == NA_EDITED) {
401                                 clip_scopes_check_gpencil_change(sa);
402                                 ED_area_tag_redraw(sa);
403                         }
404                         else if (wmn->data & ND_GPENCIL_EDITMODE) {
405                                 ED_area_tag_redraw(sa);
406                         }
407                         break;
408         }
409 }
410
411 static void clip_operatortypes(void)
412 {
413         /* ** clip_ops.c ** */
414         WM_operatortype_append(CLIP_OT_open);
415         WM_operatortype_append(CLIP_OT_reload);
416         WM_operatortype_append(CLIP_OT_view_pan);
417         WM_operatortype_append(CLIP_OT_view_zoom);
418         WM_operatortype_append(CLIP_OT_view_zoom_in);
419         WM_operatortype_append(CLIP_OT_view_zoom_out);
420         WM_operatortype_append(CLIP_OT_view_zoom_ratio);
421         WM_operatortype_append(CLIP_OT_view_all);
422         WM_operatortype_append(CLIP_OT_view_selected);
423         WM_operatortype_append(CLIP_OT_change_frame);
424         WM_operatortype_append(CLIP_OT_rebuild_proxy);
425         WM_operatortype_append(CLIP_OT_mode_set);
426 #ifdef WITH_INPUT_NDOF
427         WM_operatortype_append(CLIP_OT_view_ndof);
428 #endif
429         WM_operatortype_append(CLIP_OT_prefetch);
430         WM_operatortype_append(CLIP_OT_set_scene_frames);
431         WM_operatortype_append(CLIP_OT_cursor_set);
432
433         /* ** clip_toolbar.c ** */
434         WM_operatortype_append(CLIP_OT_tools);
435         WM_operatortype_append(CLIP_OT_properties);
436
437         /* ** tracking_ops.c ** */
438
439         /* navigation */
440         WM_operatortype_append(CLIP_OT_frame_jump);
441
442         /* set optical center to frame center */
443         WM_operatortype_append(CLIP_OT_set_center_principal);
444
445         /* selection */
446         WM_operatortype_append(CLIP_OT_select);
447         WM_operatortype_append(CLIP_OT_select_all);
448         WM_operatortype_append(CLIP_OT_select_border);
449         WM_operatortype_append(CLIP_OT_select_lasso);
450         WM_operatortype_append(CLIP_OT_select_circle);
451         WM_operatortype_append(CLIP_OT_select_grouped);
452
453         /* markers */
454         WM_operatortype_append(CLIP_OT_add_marker);
455         WM_operatortype_append(CLIP_OT_add_marker_at_click);
456         WM_operatortype_append(CLIP_OT_slide_marker);
457         WM_operatortype_append(CLIP_OT_delete_track);
458         WM_operatortype_append(CLIP_OT_delete_marker);
459
460         /* track */
461         WM_operatortype_append(CLIP_OT_track_markers);
462         WM_operatortype_append(CLIP_OT_refine_markers);
463
464         /* solving */
465         WM_operatortype_append(CLIP_OT_solve_camera);
466         WM_operatortype_append(CLIP_OT_clear_solution);
467
468         WM_operatortype_append(CLIP_OT_disable_markers);
469         WM_operatortype_append(CLIP_OT_hide_tracks);
470         WM_operatortype_append(CLIP_OT_hide_tracks_clear);
471         WM_operatortype_append(CLIP_OT_lock_tracks);
472
473         WM_operatortype_append(CLIP_OT_set_solver_keyframe);
474
475         /* orientation */
476         WM_operatortype_append(CLIP_OT_set_origin);
477         WM_operatortype_append(CLIP_OT_set_plane);
478         WM_operatortype_append(CLIP_OT_set_axis);
479         WM_operatortype_append(CLIP_OT_set_scale);
480         WM_operatortype_append(CLIP_OT_set_solution_scale);
481         WM_operatortype_append(CLIP_OT_apply_solution_scale);
482
483         /* detect */
484         WM_operatortype_append(CLIP_OT_detect_features);
485
486         /* stabilization */
487         WM_operatortype_append(CLIP_OT_stabilize_2d_add);
488         WM_operatortype_append(CLIP_OT_stabilize_2d_remove);
489         WM_operatortype_append(CLIP_OT_stabilize_2d_select);
490         WM_operatortype_append(CLIP_OT_stabilize_2d_rotation_add);
491         WM_operatortype_append(CLIP_OT_stabilize_2d_rotation_remove);
492         WM_operatortype_append(CLIP_OT_stabilize_2d_rotation_select);
493
494         /* clean-up */
495         WM_operatortype_append(CLIP_OT_clear_track_path);
496         WM_operatortype_append(CLIP_OT_join_tracks);
497         WM_operatortype_append(CLIP_OT_track_copy_color);
498
499         WM_operatortype_append(CLIP_OT_clean_tracks);
500
501         /* object tracking */
502         WM_operatortype_append(CLIP_OT_tracking_object_new);
503         WM_operatortype_append(CLIP_OT_tracking_object_remove);
504
505         /* clipboard */
506         WM_operatortype_append(CLIP_OT_copy_tracks);
507         WM_operatortype_append(CLIP_OT_paste_tracks);
508
509         /* Plane tracker */
510         WM_operatortype_append(CLIP_OT_create_plane_track);
511         WM_operatortype_append(CLIP_OT_slide_plane_marker);
512
513         WM_operatortype_append(CLIP_OT_keyframe_insert);
514         WM_operatortype_append(CLIP_OT_keyframe_delete);
515
516         /* ** clip_graph_ops.c  ** */
517
518         /* graph editing */
519
520         /* selection */
521         WM_operatortype_append(CLIP_OT_graph_select);
522         WM_operatortype_append(CLIP_OT_graph_select_border);
523         WM_operatortype_append(CLIP_OT_graph_select_all_markers);
524
525         WM_operatortype_append(CLIP_OT_graph_delete_curve);
526         WM_operatortype_append(CLIP_OT_graph_delete_knot);
527         WM_operatortype_append(CLIP_OT_graph_view_all);
528         WM_operatortype_append(CLIP_OT_graph_center_current_frame);
529
530         WM_operatortype_append(CLIP_OT_graph_disable_markers);
531
532         /* ** clip_dopesheet_ops.c  ** */
533
534         WM_operatortype_append(CLIP_OT_dopesheet_select_channel);
535         WM_operatortype_append(CLIP_OT_dopesheet_view_all);
536 }
537
538 static void clip_keymap(struct wmKeyConfig *keyconf)
539 {
540         wmKeyMap *keymap;
541         wmKeyMapItem *kmi;
542
543         /* ******** Global hotkeys avalaible for all regions ******** */
544
545         keymap = WM_keymap_find(keyconf, "Clip", SPACE_CLIP, 0);
546
547         WM_keymap_add_item(keymap, "CLIP_OT_open", OKEY, KM_PRESS, KM_ALT, 0);
548
549         WM_keymap_add_item(keymap, "CLIP_OT_tools", TKEY, KM_PRESS, 0, 0);
550         WM_keymap_add_item(keymap, "CLIP_OT_properties", NKEY, KM_PRESS, 0, 0);
551
552         /* 2d tracking */
553         kmi = WM_keymap_add_item(keymap, "CLIP_OT_track_markers", LEFTARROWKEY, KM_PRESS, KM_ALT, 0);
554         RNA_boolean_set(kmi->ptr, "backwards", true);
555         RNA_boolean_set(kmi->ptr, "sequence", false);
556         kmi = WM_keymap_add_item(keymap, "CLIP_OT_track_markers", RIGHTARROWKEY, KM_PRESS, KM_ALT, 0);
557         RNA_boolean_set(kmi->ptr, "backwards", false);
558         RNA_boolean_set(kmi->ptr, "sequence", false);
559         kmi = WM_keymap_add_item(keymap, "CLIP_OT_track_markers", TKEY, KM_PRESS, KM_CTRL, 0);
560         RNA_boolean_set(kmi->ptr, "backwards", false);
561         RNA_boolean_set(kmi->ptr, "sequence", true);
562         kmi = WM_keymap_add_item(keymap, "CLIP_OT_track_markers", TKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
563         RNA_boolean_set(kmi->ptr, "backwards", true);
564         RNA_boolean_set(kmi->ptr, "sequence", true);
565
566         /* mode */
567         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle_enum", TABKEY, KM_PRESS, 0, 0);
568         RNA_string_set(kmi->ptr, "data_path", "space_data.mode");
569         RNA_string_set(kmi->ptr, "value_1", "TRACKING");
570         RNA_string_set(kmi->ptr, "value_2", "MASK");
571
572         WM_keymap_add_item(keymap, "CLIP_OT_solve_camera", SKEY, KM_PRESS, KM_SHIFT, 0);
573
574         kmi = WM_keymap_add_item(keymap, "CLIP_OT_set_solver_keyframe", QKEY, KM_PRESS, 0, 0);
575         RNA_enum_set(kmi->ptr, "keyframe", 0);
576
577         kmi = WM_keymap_add_item(keymap, "CLIP_OT_set_solver_keyframe", EKEY, KM_PRESS, 0, 0);
578         RNA_enum_set(kmi->ptr, "keyframe", 1);
579
580         /* io/playback */
581         WM_keymap_add_item(keymap, "CLIP_OT_prefetch", PKEY, KM_PRESS, 0, 0);
582
583         /* ******** Hotkeys avalaible for main region only ******** */
584
585         keymap = WM_keymap_find(keyconf, "Clip Editor", SPACE_CLIP, 0);
586 //      keymap->poll = ED_space_clip_tracking_poll;
587         /* ** View/navigation ** */
588
589         WM_keymap_add_item(keymap, "CLIP_OT_view_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
590         WM_keymap_add_item(keymap, "CLIP_OT_view_pan", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);
591         WM_keymap_add_item(keymap, "CLIP_OT_view_pan", MOUSEPAN, 0, 0, 0);
592
593         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
594         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom", MOUSEZOOM, 0, 0, 0);
595         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom", MOUSEPAN, 0, KM_CTRL, 0);
596         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_in", WHEELINMOUSE, KM_PRESS, 0, 0);
597         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_out", WHEELOUTMOUSE, KM_PRESS, 0, 0);
598         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0);
599         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_out", PADMINUS, KM_PRESS, 0, 0);
600
601         /* ctrl now works as well, shift + numpad works as arrow keys on Windows */
602         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD8, KM_PRESS, KM_CTRL, 0)->ptr, "ratio", 8.0f);
603         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD4, KM_PRESS, KM_CTRL, 0)->ptr, "ratio", 4.0f);
604         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD2, KM_PRESS, KM_CTRL, 0)->ptr, "ratio", 2.0f);
605         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD8, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 8.0f);
606         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD4, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 4.0f);
607         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD2, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 2.0f);
608
609         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD1, KM_PRESS, 0, 0)->ptr, "ratio", 1.0f);
610         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD2, KM_PRESS, 0, 0)->ptr, "ratio", 0.5f);
611         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD4, KM_PRESS, 0, 0)->ptr, "ratio", 0.25f);
612         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD8, KM_PRESS, 0, 0)->ptr, "ratio", 0.125f);
613
614         WM_keymap_add_item(keymap, "CLIP_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
615
616         kmi = WM_keymap_add_item(keymap, "CLIP_OT_view_all", FKEY, KM_PRESS, 0, 0);
617         RNA_boolean_set(kmi->ptr, "fit_view", true);
618
619         WM_keymap_add_item(keymap, "CLIP_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
620
621 #ifdef WITH_INPUT_NDOF
622         WM_keymap_add_item(keymap, "CLIP_OT_view_all", NDOF_BUTTON_FIT, KM_PRESS, 0, 0);
623         WM_keymap_add_item(keymap, "CLIP_OT_view_ndof", NDOF_MOTION, 0, 0, 0);
624 #endif
625
626         /* jump to special frame */
627         kmi = WM_keymap_add_item(keymap, "CLIP_OT_frame_jump", LEFTARROWKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
628         RNA_enum_set(kmi->ptr, "position", 0);
629
630         kmi = WM_keymap_add_item(keymap, "CLIP_OT_frame_jump", RIGHTARROWKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
631         RNA_enum_set(kmi->ptr, "position", 1);
632
633         kmi = WM_keymap_add_item(keymap, "CLIP_OT_frame_jump", LEFTARROWKEY, KM_PRESS, KM_ALT | KM_SHIFT, 0);
634         RNA_enum_set(kmi->ptr, "position", 2);
635
636         kmi = WM_keymap_add_item(keymap, "CLIP_OT_frame_jump", RIGHTARROWKEY, KM_PRESS, KM_ALT | KM_SHIFT, 0);
637         RNA_enum_set(kmi->ptr, "position", 3);
638
639         /* "timeline" */
640         WM_keymap_add_item(keymap, "CLIP_OT_change_frame", LEFTMOUSE, KM_PRESS, 0, 0);
641
642         /* selection */
643         kmi = WM_keymap_add_item(keymap, "CLIP_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
644         RNA_boolean_set(kmi->ptr, "extend", false);
645         kmi = WM_keymap_add_item(keymap, "CLIP_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
646         RNA_boolean_set(kmi->ptr, "extend", true);
647         kmi = WM_keymap_add_item(keymap, "CLIP_OT_select_all", AKEY, KM_PRESS, 0, 0);
648         RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
649         kmi = WM_keymap_add_item(keymap, "CLIP_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
650         RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
651         WM_keymap_add_item(keymap, "CLIP_OT_select_border", BKEY, KM_PRESS, 0, 0);
652         WM_keymap_add_item(keymap, "CLIP_OT_select_circle", CKEY, KM_PRESS, 0, 0);
653         WM_keymap_add_menu(keymap, "CLIP_MT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0);
654
655         kmi = WM_keymap_add_item(keymap, "CLIP_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL | KM_ALT, 0);
656         RNA_boolean_set(kmi->ptr, "deselect", false);
657         kmi = WM_keymap_add_item(keymap, "CLIP_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL | KM_SHIFT | KM_ALT, 0);
658         RNA_boolean_set(kmi->ptr, "deselect", true);
659
660         /* marker */
661         WM_keymap_add_item(keymap, "CLIP_OT_add_marker_slide", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
662
663         WM_keymap_add_item(keymap, "CLIP_OT_delete_marker", DELKEY, KM_PRESS, KM_SHIFT, 0);
664         WM_keymap_add_item(keymap, "CLIP_OT_delete_marker", XKEY, KM_PRESS, KM_SHIFT, 0);
665
666         WM_keymap_add_item(keymap, "CLIP_OT_slide_marker", LEFTMOUSE, KM_PRESS, 0, 0);
667
668         kmi = WM_keymap_add_item(keymap, "CLIP_OT_disable_markers", DKEY, KM_PRESS, KM_SHIFT, 0);
669         RNA_enum_set(kmi->ptr, "action", 2);    /* toggle */
670
671         /* tracks */
672         WM_keymap_add_item(keymap, "CLIP_OT_delete_track", DELKEY, KM_PRESS, 0, 0);
673         WM_keymap_add_item(keymap, "CLIP_OT_delete_track", XKEY, KM_PRESS, 0, 0);
674
675         kmi = WM_keymap_add_item(keymap, "CLIP_OT_lock_tracks", LKEY, KM_PRESS, KM_CTRL, 0);
676         RNA_enum_set(kmi->ptr, "action", 0);    /* lock */
677
678         kmi = WM_keymap_add_item(keymap, "CLIP_OT_lock_tracks", LKEY, KM_PRESS, KM_ALT, 0);
679         RNA_enum_set(kmi->ptr, "action", 1);    /* unlock */
680
681         kmi = WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks", HKEY, KM_PRESS, 0, 0);
682         RNA_boolean_set(kmi->ptr, "unselected", false);
683
684         kmi = WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks", HKEY, KM_PRESS, KM_SHIFT, 0);
685         RNA_boolean_set(kmi->ptr, "unselected", true);
686
687         WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks_clear", HKEY, KM_PRESS, KM_ALT, 0);
688
689         /* plane tracks */
690         WM_keymap_add_item(keymap, "CLIP_OT_slide_plane_marker", ACTIONMOUSE, KM_PRESS, 0, 0);
691
692         WM_keymap_add_item(keymap, "CLIP_OT_keyframe_insert", IKEY, KM_PRESS, 0, 0);
693         WM_keymap_add_item(keymap, "CLIP_OT_keyframe_delete", IKEY, KM_PRESS, KM_ALT, 0);
694
695         /* clean-up */
696         WM_keymap_add_item(keymap, "CLIP_OT_join_tracks", JKEY, KM_PRESS, KM_CTRL, 0);
697
698         /* menus */
699         WM_keymap_add_menu(keymap, "CLIP_MT_tracking_specials", WKEY, KM_PRESS, 0, 0);
700
701         /* display */
702         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", LKEY, KM_PRESS, 0, 0);
703         RNA_string_set(kmi->ptr, "data_path", "space_data.lock_selection");
704
705         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", DKEY, KM_PRESS, KM_ALT, 0);
706         RNA_string_set(kmi->ptr, "data_path", "space_data.show_disabled");
707
708         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", SKEY, KM_PRESS, KM_ALT, 0);
709         RNA_string_set(kmi->ptr, "data_path", "space_data.show_marker_search");
710
711         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0);
712         RNA_string_set(kmi->ptr, "data_path", "space_data.use_mute_footage");
713
714         transform_keymap_for_space(keyconf, keymap, SPACE_CLIP);
715
716         /* clean-up */
717         kmi = WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_ALT, 0);
718         RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_REMAINED);
719         RNA_boolean_set(kmi->ptr, "clear_active", false);
720         kmi = WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_SHIFT, 0);
721         RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_UPTO);
722         RNA_boolean_set(kmi->ptr, "clear_active", false);
723         kmi = WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_ALT | KM_SHIFT, 0);
724         RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_ALL);
725         RNA_boolean_set(kmi->ptr, "clear_active", false);
726
727         /* Cursor */
728         WM_keymap_add_item(keymap, "CLIP_OT_cursor_set", ACTIONMOUSE, KM_PRESS, 0, 0);
729
730         /* pivot point */
731         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", COMMAKEY, KM_PRESS, 0, 0);
732         RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point");
733         RNA_string_set(kmi->ptr, "value", "BOUNDING_BOX_CENTER");
734
735         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", COMMAKEY, KM_PRESS, KM_CTRL, 0); /* 2.4x allowed Comma+Shift too, rather not use both */
736         RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point");
737         RNA_string_set(kmi->ptr, "value", "MEDIAN_POINT");
738
739         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", PERIODKEY, KM_PRESS, 0, 0);
740         RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point");
741         RNA_string_set(kmi->ptr, "value", "CURSOR");
742
743         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", PERIODKEY, KM_PRESS, KM_CTRL, 0);
744         RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point");
745         RNA_string_set(kmi->ptr, "value", "INDIVIDUAL_ORIGINS");
746
747         /* Copy-paste */
748         WM_keymap_add_item(keymap, "CLIP_OT_copy_tracks", CKEY, KM_PRESS, KM_CTRL, 0);
749         WM_keymap_add_item(keymap, "CLIP_OT_paste_tracks", VKEY, KM_PRESS, KM_CTRL, 0);
750
751         /* ******** Hotkeys avalaible for preview region only ******** */
752
753         keymap = WM_keymap_find(keyconf, "Clip Graph Editor", SPACE_CLIP, 0);
754
755         /* "timeline" */
756         WM_keymap_add_item(keymap, "CLIP_OT_change_frame", ACTIONMOUSE, KM_PRESS, 0, 0);
757
758         /* selection */
759         kmi = WM_keymap_add_item(keymap, "CLIP_OT_graph_select", SELECTMOUSE, KM_PRESS, 0, 0);
760         RNA_boolean_set(kmi->ptr, "extend", false);
761         kmi = WM_keymap_add_item(keymap, "CLIP_OT_graph_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
762         RNA_boolean_set(kmi->ptr, "extend", true);
763
764         kmi = WM_keymap_add_item(keymap, "CLIP_OT_graph_select_all_markers", AKEY, KM_PRESS, 0, 0);
765         RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
766         kmi = WM_keymap_add_item(keymap, "CLIP_OT_graph_select_all_markers", IKEY, KM_PRESS, KM_CTRL, 0);
767         RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
768
769         WM_keymap_add_item(keymap, "CLIP_OT_graph_select_border", BKEY, KM_PRESS, 0, 0);
770
771         /* delete */
772         WM_keymap_add_item(keymap, "CLIP_OT_graph_delete_curve", DELKEY, KM_PRESS, 0, 0);
773         WM_keymap_add_item(keymap, "CLIP_OT_graph_delete_curve", XKEY, KM_PRESS, 0, 0);
774
775         WM_keymap_add_item(keymap, "CLIP_OT_graph_delete_knot", DELKEY, KM_PRESS, KM_SHIFT, 0);
776         WM_keymap_add_item(keymap, "CLIP_OT_graph_delete_knot", XKEY, KM_PRESS, KM_SHIFT, 0);
777
778         /* view */
779         WM_keymap_add_item(keymap, "CLIP_OT_graph_view_all", HOMEKEY, KM_PRESS, 0, 0);
780 #ifdef WITH_INPUT_NDOF
781         WM_keymap_add_item(keymap, "CLIP_OT_graph_view_all", NDOF_BUTTON_FIT, KM_PRESS, 0, 0);
782 #endif
783         WM_keymap_add_item(keymap, "CLIP_OT_graph_center_current_frame", PADPERIOD, KM_PRESS, 0, 0);
784
785         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", LKEY, KM_PRESS, 0, 0);
786         RNA_string_set(kmi->ptr, "data_path", "space_data.lock_time_cursor");
787
788         /* clean-up */
789         kmi = WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_ALT, 0);
790         RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_REMAINED);
791         RNA_boolean_set(kmi->ptr, "clear_active", true);
792         kmi = WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_SHIFT, 0);
793         RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_UPTO);
794         RNA_boolean_set(kmi->ptr, "clear_active", true);
795         kmi = WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_ALT | KM_SHIFT, 0);
796         RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_ALL);
797         RNA_boolean_set(kmi->ptr, "clear_active", true);
798
799         /* tracks */
800         kmi = WM_keymap_add_item(keymap, "CLIP_OT_graph_disable_markers", DKEY, KM_PRESS, KM_SHIFT, 0);
801         RNA_enum_set(kmi->ptr, "action", 2);    /* toggle */
802
803         transform_keymap_for_space(keyconf, keymap, SPACE_CLIP);
804
805         /* ******** Hotkeys avalaible for channels region only ******** */
806
807         keymap = WM_keymap_find(keyconf, "Clip Dopesheet Editor", SPACE_CLIP, 0);
808
809         kmi = WM_keymap_add_item(keymap, "CLIP_OT_dopesheet_select_channel", LEFTMOUSE, KM_PRESS, 0, 0);
810         RNA_boolean_set(kmi->ptr, "extend", true);  /* toggle */
811
812         WM_keymap_add_item(keymap, "CLIP_OT_dopesheet_view_all", HOMEKEY, KM_PRESS, 0, 0);
813 #ifdef WITH_INPUT_NDOF
814         WM_keymap_add_item(keymap, "CLIP_OT_dopesheet_view_all", NDOF_BUTTON_FIT, KM_PRESS, 0, 0);
815 #endif
816 }
817
818 /* DO NOT make this static, this hides the symbol and breaks API generation script. */
819 const char *clip_context_dir[] = {"edit_movieclip", "edit_mask", NULL};
820
821 static int clip_context(const bContext *C, const char *member, bContextDataResult *result)
822 {
823         SpaceClip *sc = CTX_wm_space_clip(C);
824
825         if (CTX_data_dir(member)) {
826                 CTX_data_dir_set(result, clip_context_dir);
827
828                 return true;
829         }
830         else if (CTX_data_equals(member, "edit_movieclip")) {
831                 if (sc->clip)
832                         CTX_data_id_pointer_set(result, &sc->clip->id);
833                 return true;
834         }
835         else if (CTX_data_equals(member, "edit_mask")) {
836                 if (sc->mask_info.mask)
837                         CTX_data_id_pointer_set(result, &sc->mask_info.mask->id);
838                 return true;
839         }
840
841         return false;
842 }
843
844 /* dropboxes */
845 static int clip_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
846 {
847         if (drag->type == WM_DRAG_PATH)
848                 if (ELEM(drag->icon, 0, ICON_FILE_IMAGE, ICON_FILE_MOVIE, ICON_FILE_BLANK)) /* rule might not work? */
849                         return true;
850
851         return false;
852 }
853
854 static void clip_drop_copy(wmDrag *drag, wmDropBox *drop)
855 {
856         PointerRNA itemptr;
857         char dir[FILE_MAX], file[FILE_MAX];
858
859         BLI_split_dirfile(drag->path, dir, file, sizeof(dir), sizeof(file));
860
861         RNA_string_set(drop->ptr, "directory", dir);
862
863         RNA_collection_clear(drop->ptr, "files");
864         RNA_collection_add(drop->ptr, "files", &itemptr);
865         RNA_string_set(&itemptr, "name", file);
866 }
867
868 /* area+region dropbox definition */
869 static void clip_dropboxes(void)
870 {
871         ListBase *lb = WM_dropboxmap_find("Clip", SPACE_CLIP, 0);
872
873         WM_dropbox_add(lb, "CLIP_OT_open", clip_drop_poll, clip_drop_copy);
874 }
875
876 static void clip_refresh(const bContext *C, ScrArea *sa)
877 {
878         wmWindowManager *wm = CTX_wm_manager(C);
879         wmWindow *window = CTX_wm_window(C);
880         Scene *scene = CTX_data_scene(C);
881         SpaceClip *sc = (SpaceClip *)sa->spacedata.first;
882         ARegion *ar_main = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
883         ARegion *ar_tools = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS);
884         ARegion *ar_preview = ED_clip_has_preview_region(C, sa);
885         ARegion *ar_properties = ED_clip_has_properties_region(sa);
886         ARegion *ar_channels = ED_clip_has_channels_region(sa);
887         bool main_visible = false, preview_visible = false, tools_visible = false;
888         bool properties_visible = false, channels_visible = false;
889         bool view_changed = false;
890
891         switch (sc->view) {
892                 case SC_VIEW_CLIP:
893                         main_visible = true;
894                         preview_visible = false;
895                         tools_visible = true;
896                         properties_visible = true;
897                         channels_visible = false;
898                         break;
899                 case SC_VIEW_GRAPH:
900                         main_visible = false;
901                         preview_visible = true;
902                         tools_visible = false;
903                         properties_visible = false;
904                         channels_visible = false;
905
906                         reinit_preview_region(C, ar_preview);
907                         break;
908                 case SC_VIEW_DOPESHEET:
909                         main_visible = false;
910                         preview_visible = true;
911                         tools_visible = false;
912                         properties_visible = false;
913                         channels_visible = true;
914
915                         reinit_preview_region(C, ar_preview);
916                         break;
917         }
918
919         if (main_visible) {
920                 if (ar_main && (ar_main->flag & RGN_FLAG_HIDDEN)) {
921                         ar_main->flag &= ~RGN_FLAG_HIDDEN;
922                         ar_main->v2d.flag &= ~V2D_IS_INITIALISED;
923                         view_changed = true;
924                 }
925
926                 if (ar_main && ar_main->alignment != RGN_ALIGN_NONE) {
927                         ar_main->alignment = RGN_ALIGN_NONE;
928                         view_changed = true;
929                 }
930         }
931         else {
932                 if (ar_main && !(ar_main->flag & RGN_FLAG_HIDDEN)) {
933                         ar_main->flag |= RGN_FLAG_HIDDEN;
934                         ar_main->v2d.flag &= ~V2D_IS_INITIALISED;
935                         WM_event_remove_handlers((bContext *)C, &ar_main->handlers);
936                         view_changed = true;
937                 }
938                 if (ar_main && ar_main->alignment != RGN_ALIGN_NONE) {
939                         ar_main->alignment = RGN_ALIGN_NONE;
940                         view_changed = true;
941                 }
942         }
943
944         if (properties_visible) {
945                 if (ar_properties && (ar_properties->flag & RGN_FLAG_HIDDEN)) {
946                         ar_properties->flag &= ~RGN_FLAG_HIDDEN;
947                         ar_properties->v2d.flag &= ~V2D_IS_INITIALISED;
948                         view_changed = true;
949                 }
950                 if (ar_properties && ar_properties->alignment != RGN_ALIGN_RIGHT) {
951                         ar_properties->alignment = RGN_ALIGN_RIGHT;
952                         view_changed = true;
953                 }
954         }
955         else {
956                 if (ar_properties && !(ar_properties->flag & RGN_FLAG_HIDDEN)) {
957                         ar_properties->flag |= RGN_FLAG_HIDDEN;
958                         ar_properties->v2d.flag &= ~V2D_IS_INITIALISED;
959                         WM_event_remove_handlers((bContext *)C, &ar_properties->handlers);
960                         view_changed = true;
961                 }
962                 if (ar_properties && ar_properties->alignment != RGN_ALIGN_NONE) {
963                         ar_properties->alignment = RGN_ALIGN_NONE;
964                         view_changed = true;
965                 }
966         }
967
968         if (tools_visible) {
969                 if (ar_tools && (ar_tools->flag & RGN_FLAG_HIDDEN)) {
970                         ar_tools->flag &= ~RGN_FLAG_HIDDEN;
971                         ar_tools->v2d.flag &= ~V2D_IS_INITIALISED;
972                         view_changed = true;
973                 }
974                 if (ar_tools && ar_tools->alignment != RGN_ALIGN_LEFT) {
975                         ar_tools->alignment = RGN_ALIGN_LEFT;
976                         view_changed = true;
977                 }
978         }
979         else {
980                 if (ar_tools && !(ar_tools->flag & RGN_FLAG_HIDDEN)) {
981                         ar_tools->flag |= RGN_FLAG_HIDDEN;
982                         ar_tools->v2d.flag &= ~V2D_IS_INITIALISED;
983                         WM_event_remove_handlers((bContext *)C, &ar_tools->handlers);
984                         view_changed = true;
985                 }
986                 if (ar_tools && ar_tools->alignment != RGN_ALIGN_NONE) {
987                         ar_tools->alignment = RGN_ALIGN_NONE;
988                         view_changed = true;
989                 }
990         }
991
992         if (preview_visible) {
993                 if (ar_preview && (ar_preview->flag & RGN_FLAG_HIDDEN)) {
994                         ar_preview->flag &= ~RGN_FLAG_HIDDEN;
995                         ar_preview->v2d.flag &= ~V2D_IS_INITIALISED;
996                         ar_preview->v2d.cur = ar_preview->v2d.tot;
997                         view_changed = true;
998                 }
999                 if (ar_preview && ar_preview->alignment != RGN_ALIGN_NONE) {
1000                         ar_preview->alignment = RGN_ALIGN_NONE;
1001                         view_changed = true;
1002                 }
1003         }
1004         else {
1005                 if (ar_preview && !(ar_preview->flag & RGN_FLAG_HIDDEN)) {
1006                         ar_preview->flag |= RGN_FLAG_HIDDEN;
1007                         ar_preview->v2d.flag &= ~V2D_IS_INITIALISED;
1008                         WM_event_remove_handlers((bContext *)C, &ar_preview->handlers);
1009                         view_changed = true;
1010                 }
1011                 if (ar_preview && ar_preview->alignment != RGN_ALIGN_NONE) {
1012                         ar_preview->alignment = RGN_ALIGN_NONE;
1013                         view_changed = true;
1014                 }
1015         }
1016
1017         if (channels_visible) {
1018                 if (ar_channels && (ar_channels->flag & RGN_FLAG_HIDDEN)) {
1019                         ar_channels->flag &= ~RGN_FLAG_HIDDEN;
1020                         ar_channels->v2d.flag &= ~V2D_IS_INITIALISED;
1021                         view_changed = true;
1022                 }
1023                 if (ar_channels && ar_channels->alignment != RGN_ALIGN_LEFT) {
1024                         ar_channels->alignment = RGN_ALIGN_LEFT;
1025                         view_changed = true;
1026                 }
1027         }
1028         else {
1029                 if (ar_channels && !(ar_channels->flag & RGN_FLAG_HIDDEN)) {
1030                         ar_channels->flag |= RGN_FLAG_HIDDEN;
1031                         ar_channels->v2d.flag &= ~V2D_IS_INITIALISED;
1032                         WM_event_remove_handlers((bContext *)C, &ar_channels->handlers);
1033                         view_changed = true;
1034                 }
1035                 if (ar_channels && ar_channels->alignment != RGN_ALIGN_NONE) {
1036                         ar_channels->alignment = RGN_ALIGN_NONE;
1037                         view_changed = true;
1038                 }
1039         }
1040
1041         if (view_changed) {
1042                 ED_area_initialize(wm, window, sa);
1043                 ED_area_tag_redraw(sa);
1044         }
1045
1046         BKE_movieclip_user_set_frame(&sc->user, scene->r.cfra);
1047 }
1048
1049 /********************* main region ********************/
1050
1051 /* sets up the fields of the View2D from zoom and offset */
1052 static void movieclip_main_area_set_view2d(const bContext *C, ARegion *ar)
1053 {
1054         SpaceClip *sc = CTX_wm_space_clip(C);
1055         float x1, y1, w, h, aspx, aspy;
1056         int width, height, winx, winy;
1057
1058         ED_space_clip_get_size(sc, &width, &height);
1059         ED_space_clip_get_aspect(sc, &aspx, &aspy);
1060
1061         w = width * aspx;
1062         h = height * aspy;
1063
1064         winx = BLI_rcti_size_x(&ar->winrct) + 1;
1065         winy = BLI_rcti_size_y(&ar->winrct) + 1;
1066
1067         ar->v2d.tot.xmin = 0;
1068         ar->v2d.tot.ymin = 0;
1069         ar->v2d.tot.xmax = w;
1070         ar->v2d.tot.ymax = h;
1071
1072         ar->v2d.mask.xmin = ar->v2d.mask.ymin = 0;
1073         ar->v2d.mask.xmax = winx;
1074         ar->v2d.mask.ymax = winy;
1075
1076         /* which part of the image space do we see? */
1077         x1 = ar->winrct.xmin + (winx - sc->zoom * w) / 2.0f;
1078         y1 = ar->winrct.ymin + (winy - sc->zoom * h) / 2.0f;
1079
1080         x1 -= sc->zoom * sc->xof;
1081         y1 -= sc->zoom * sc->yof;
1082
1083         /* relative display right */
1084         ar->v2d.cur.xmin = (ar->winrct.xmin - (float)x1) / sc->zoom;
1085         ar->v2d.cur.xmax = ar->v2d.cur.xmin + ((float)winx / sc->zoom);
1086
1087         /* relative display left */
1088         ar->v2d.cur.ymin = (ar->winrct.ymin - (float)y1) / sc->zoom;
1089         ar->v2d.cur.ymax = ar->v2d.cur.ymin + ((float)winy / sc->zoom);
1090
1091         /* normalize 0.0..1.0 */
1092         ar->v2d.cur.xmin /= w;
1093         ar->v2d.cur.xmax /= w;
1094         ar->v2d.cur.ymin /= h;
1095         ar->v2d.cur.ymax /= h;
1096 }
1097
1098 /* add handlers, stuff you only do once or on area/region changes */
1099 static void clip_main_region_init(wmWindowManager *wm, ARegion *ar)
1100 {
1101         wmKeyMap *keymap;
1102
1103         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
1104
1105         /* mask polls mode */
1106         keymap = WM_keymap_find(wm->defaultconf, "Mask Editing", 0, 0);
1107         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
1108
1109         /* own keymap */
1110         keymap = WM_keymap_find(wm->defaultconf, "Clip", SPACE_CLIP, 0);
1111         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
1112
1113         keymap = WM_keymap_find(wm->defaultconf, "Clip Editor", SPACE_CLIP, 0);
1114         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
1115 }
1116
1117 static void clip_main_region_draw(const bContext *C, ARegion *ar)
1118 {
1119         /* draw entirely, view changes should be handled here */
1120         SpaceClip *sc = CTX_wm_space_clip(C);
1121         MovieClip *clip = ED_space_clip_get_clip(sc);
1122         float aspx, aspy, zoomx, zoomy, x, y;
1123         int width, height;
1124         bool show_cursor = false;
1125
1126         /* if tracking is in progress, we should synchronize framenr from clipuser
1127          * so latest tracked frame would be shown */
1128         if (clip && clip->tracking_context)
1129                 BKE_autotrack_context_sync_user(clip->tracking_context, &sc->user);
1130
1131         if (sc->flag & SC_LOCK_SELECTION) {
1132                 ImBuf *tmpibuf = NULL;
1133
1134                 if (clip && clip->tracking.stabilization.flag & TRACKING_2D_STABILIZATION) {
1135                         tmpibuf = ED_space_clip_get_stable_buffer(sc, NULL, NULL, NULL);
1136                 }
1137
1138                 if (ED_clip_view_selection(C, ar, 0)) {
1139                         sc->xof += sc->xlockof;
1140                         sc->yof += sc->ylockof;
1141                 }
1142
1143                 if (tmpibuf)
1144                         IMB_freeImBuf(tmpibuf);
1145         }
1146
1147         /* clear and setup matrix */
1148         UI_ThemeClearColor(TH_BACK);
1149         glClear(GL_COLOR_BUFFER_BIT);
1150
1151         /* data... */
1152         movieclip_main_area_set_view2d(C, ar);
1153
1154         clip_draw_main(C, sc, ar);
1155
1156         /* TODO(sergey): would be nice to find a way to de-duplicate all this space conversions */
1157         UI_view2d_view_to_region_fl(&ar->v2d, 0.0f, 0.0f, &x, &y);
1158         ED_space_clip_get_size(sc, &width, &height);
1159         ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy);
1160         ED_space_clip_get_aspect(sc, &aspx, &aspy);
1161
1162         if (sc->mode == SC_MODE_MASKEDIT) {
1163                 Mask *mask = CTX_data_edit_mask(C);
1164                 if (mask && clip) {
1165                         ScrArea *sa = CTX_wm_area(C);
1166                         int mask_width, mask_height;
1167                         ED_mask_get_size(sa, &mask_width, &mask_height);
1168                         ED_mask_draw_region(mask, ar,
1169                                             sc->mask_info.draw_flag,
1170                                             sc->mask_info.draw_type,
1171                                             sc->mask_info.overlay_mode,
1172                                             mask_width, mask_height,
1173                                             aspx, aspy,
1174                                             true, true,
1175                                             sc->stabmat, C);
1176                 }
1177         }
1178
1179         show_cursor |= sc->mode == SC_MODE_MASKEDIT;
1180         show_cursor |= sc->around == V3D_AROUND_CURSOR;
1181
1182         if (show_cursor) {
1183                 gpuPushMatrix();
1184                 gpuTranslate2f(x, y);
1185                 gpuScale2f(zoomx, zoomy);
1186                 gpuMultMatrix(sc->stabmat);
1187                 gpuScale2f(width, height);
1188                 ED_image_draw_cursor(ar, sc->cursor);
1189                 gpuPopMatrix();
1190         }
1191
1192         clip_draw_cache_and_notes(C, sc, ar);
1193
1194         if (sc->flag & SC_SHOW_GPENCIL) {
1195                 /* Grease Pencil */
1196                 clip_draw_grease_pencil((bContext *)C, true);
1197         }
1198
1199         /* reset view matrix */
1200         UI_view2d_view_restore(C);
1201
1202         if (sc->flag & SC_SHOW_GPENCIL) {
1203                 /* draw Grease Pencil - screen space only */
1204                 clip_draw_grease_pencil((bContext *)C, false);
1205         }
1206 }
1207
1208 static void clip_main_region_listener(
1209         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
1210         wmNotifier *wmn, const Scene *UNUSED(scene))
1211 {
1212         /* context changes */
1213         switch (wmn->category) {
1214                 case NC_GPENCIL:
1215                         if (wmn->action == NA_EDITED)
1216                                 ED_region_tag_redraw(ar);
1217                         else if (wmn->data & ND_GPENCIL_EDITMODE)
1218                                 ED_region_tag_redraw(ar);
1219                         break;
1220         }
1221 }
1222
1223 /****************** preview region ******************/
1224
1225 static void clip_preview_region_init(wmWindowManager *wm, ARegion *ar)
1226 {
1227         wmKeyMap *keymap;
1228
1229         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
1230
1231         /* own keymap */
1232         keymap = WM_keymap_find(wm->defaultconf, "Clip", SPACE_CLIP, 0);
1233         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
1234
1235         keymap = WM_keymap_find(wm->defaultconf, "Clip Graph Editor", SPACE_CLIP, 0);
1236         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
1237
1238         keymap = WM_keymap_find(wm->defaultconf, "Clip Dopesheet Editor", SPACE_CLIP, 0);
1239         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
1240 }
1241
1242 static void graph_region_draw(const bContext *C, ARegion *ar)
1243 {
1244         View2D *v2d = &ar->v2d;
1245         View2DScrollers *scrollers;
1246         SpaceClip *sc = CTX_wm_space_clip(C);
1247         Scene *scene = CTX_data_scene(C);
1248         short unitx, unity;
1249         short cfra_flag = 0;
1250
1251         if (sc->flag & SC_LOCK_TIMECURSOR)
1252                 ED_clip_graph_center_current_frame(scene, ar);
1253
1254         /* clear and setup matrix */
1255         UI_ThemeClearColor(TH_BACK);
1256         glClear(GL_COLOR_BUFFER_BIT);
1257
1258         UI_view2d_view_ortho(v2d);
1259
1260         /* data... */
1261         clip_draw_graph(sc, ar, scene);
1262
1263         /* current frame indicator line */
1264         if (sc->flag & SC_SHOW_SECONDS) cfra_flag |= DRAWCFRA_UNIT_SECONDS;
1265         ANIM_draw_cfra(C, v2d, cfra_flag);
1266
1267         /* reset view matrix */
1268         UI_view2d_view_restore(C);
1269
1270         /* scrollers */
1271         unitx = (sc->flag & SC_SHOW_SECONDS) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMES;
1272         unity = V2D_UNIT_VALUES;
1273         scrollers = UI_view2d_scrollers_calc(C, v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP);
1274         UI_view2d_scrollers_draw(C, v2d, scrollers);
1275         UI_view2d_scrollers_free(scrollers);
1276         
1277         /* currnt frame indicator */
1278         if (sc->flag & SC_SHOW_SECONDS) cfra_flag |= DRAWCFRA_UNIT_SECONDS;
1279         UI_view2d_view_orthoSpecial(ar, v2d, 1);
1280         ANIM_draw_cfra_number(C, v2d, cfra_flag);
1281 }
1282
1283 static void dopesheet_region_draw(const bContext *C, ARegion *ar)
1284 {
1285         Scene *scene = CTX_data_scene(C);
1286         SpaceClip *sc = CTX_wm_space_clip(C);
1287         MovieClip *clip = ED_space_clip_get_clip(sc);
1288         View2D *v2d = &ar->v2d;
1289         View2DGrid *grid;
1290         View2DScrollers *scrollers;
1291         short unit = 0, cfra_flag = 0;
1292
1293         if (clip)
1294                 BKE_tracking_dopesheet_update(&clip->tracking);
1295
1296         /* clear and setup matrix */
1297         UI_ThemeClearColor(TH_BACK);
1298         glClear(GL_COLOR_BUFFER_BIT);
1299
1300         UI_view2d_view_ortho(v2d);
1301
1302         /* time grid */
1303         unit = (sc->flag & SC_SHOW_SECONDS) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMES;
1304         grid = UI_view2d_grid_calc(scene, v2d, unit, V2D_GRID_CLAMP,
1305                                    V2D_ARG_DUMMY, V2D_ARG_DUMMY, ar->winx, ar->winy);
1306         UI_view2d_grid_draw(v2d, grid, V2D_GRIDLINES_ALL);
1307         UI_view2d_grid_free(grid);
1308
1309         /* data... */
1310         clip_draw_dopesheet_main(sc, ar, scene);
1311
1312         /* current frame indicator line */
1313         if (sc->flag & SC_SHOW_SECONDS) cfra_flag |= DRAWCFRA_UNIT_SECONDS;
1314         ANIM_draw_cfra(C, v2d, cfra_flag);
1315
1316         /* reset view matrix */
1317         UI_view2d_view_restore(C);
1318
1319         /* scrollers */
1320         scrollers = UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
1321         UI_view2d_scrollers_draw(C, v2d, scrollers);
1322         UI_view2d_scrollers_free(scrollers);
1323         
1324         /* currnt frame number indicator */
1325         UI_view2d_view_orthoSpecial(ar, v2d, 1);
1326         ANIM_draw_cfra_number(C, v2d, cfra_flag);
1327 }
1328
1329 static void clip_preview_region_draw(const bContext *C, ARegion *ar)
1330 {
1331         SpaceClip *sc = CTX_wm_space_clip(C);
1332
1333         if (sc->view == SC_VIEW_GRAPH)
1334                 graph_region_draw(C, ar);
1335         else if (sc->view == SC_VIEW_DOPESHEET)
1336                 dopesheet_region_draw(C, ar);
1337 }
1338
1339 static void clip_preview_region_listener(
1340         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *UNUSED(ar),
1341         wmNotifier *UNUSED(wmn), const Scene *UNUSED(scene))
1342 {
1343 }
1344
1345 /****************** channels region ******************/
1346
1347 static void clip_channels_region_init(wmWindowManager *wm, ARegion *ar)
1348 {
1349         wmKeyMap *keymap;
1350
1351         /* ensure the 2d view sync works - main region has bottom scroller */
1352         ar->v2d.scroll = V2D_SCROLL_BOTTOM;
1353
1354         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
1355
1356         keymap = WM_keymap_find(wm->defaultconf, "Clip Dopesheet Editor", SPACE_CLIP, 0);
1357         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
1358 }
1359
1360 static void clip_channels_region_draw(const bContext *C, ARegion *ar)
1361 {
1362         SpaceClip *sc = CTX_wm_space_clip(C);
1363         MovieClip *clip = ED_space_clip_get_clip(sc);
1364         View2D *v2d = &ar->v2d;
1365
1366         if (clip)
1367                 BKE_tracking_dopesheet_update(&clip->tracking);
1368
1369         /* clear and setup matrix */
1370         UI_ThemeClearColor(TH_BACK);
1371         glClear(GL_COLOR_BUFFER_BIT);
1372
1373         UI_view2d_view_ortho(v2d);
1374
1375         /* data... */
1376         clip_draw_dopesheet_channels(C, ar);
1377
1378         /* reset view matrix */
1379         UI_view2d_view_restore(C);
1380 }
1381
1382 static void clip_channels_region_listener(
1383         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *UNUSED(ar),
1384         wmNotifier *UNUSED(wmn), const Scene *UNUSED(scene))
1385 {
1386 }
1387
1388 /****************** header region ******************/
1389
1390 /* add handlers, stuff you only do once or on area/region changes */
1391 static void clip_header_region_init(wmWindowManager *UNUSED(wm), ARegion *ar)
1392 {
1393         ED_region_header_init(ar);
1394 }
1395
1396 static void clip_header_region_draw(const bContext *C, ARegion *ar)
1397 {
1398         ED_region_header(C, ar);
1399 }
1400
1401 static void clip_header_region_listener(
1402         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
1403         wmNotifier *wmn, const Scene *UNUSED(scene))
1404 {
1405         /* context changes */
1406         switch (wmn->category) {
1407                 case NC_SCENE:
1408                         switch (wmn->data) {
1409                                 /* for proportional editmode only */
1410                                 case ND_TOOLSETTINGS:
1411                                         /* TODO - should do this when in mask mode only but no datas available */
1412                                         // if (sc->mode == SC_MODE_MASKEDIT)
1413                                 {
1414                                         ED_region_tag_redraw(ar);
1415                                         break;
1416                                 }
1417                         }
1418                         break;
1419         }
1420 }
1421
1422
1423 /****************** tools region ******************/
1424
1425 /* add handlers, stuff you only do once or on area/region changes */
1426 static void clip_tools_region_init(wmWindowManager *wm, ARegion *ar)
1427 {
1428         wmKeyMap *keymap;
1429
1430         ED_region_panels_init(wm, ar);
1431
1432         keymap = WM_keymap_find(wm->defaultconf, "Clip", SPACE_CLIP, 0);
1433         WM_event_add_keymap_handler(&ar->handlers, keymap);
1434 }
1435
1436 static void clip_tools_region_draw(const bContext *C, ARegion *ar)
1437 {
1438         ED_region_panels(C, ar, NULL, -1, true);
1439 }
1440
1441 /****************** tool properties region ******************/
1442
1443 static void clip_props_region_listener(
1444         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
1445         wmNotifier *wmn, const Scene *UNUSED(scene))
1446 {
1447         /* context changes */
1448         switch (wmn->category) {
1449                 case NC_WM:
1450                         if (wmn->data == ND_HISTORY)
1451                                 ED_region_tag_redraw(ar);
1452                         break;
1453                 case NC_SCENE:
1454                         if (wmn->data == ND_MODE)
1455                                 ED_region_tag_redraw(ar);
1456                         break;
1457                 case NC_SPACE:
1458                         if (wmn->data == ND_SPACE_CLIP)
1459                                 ED_region_tag_redraw(ar);
1460                         break;
1461                 case NC_GPENCIL:
1462                         if (wmn->action == NA_EDITED)
1463                                 ED_region_tag_redraw(ar);
1464                         break;
1465         }
1466 }
1467
1468 /****************** properties region ******************/
1469
1470 /* add handlers, stuff you only do once or on area/region changes */
1471 static void clip_properties_region_init(wmWindowManager *wm, ARegion *ar)
1472 {
1473         wmKeyMap *keymap;
1474
1475         ED_region_panels_init(wm, ar);
1476
1477         keymap = WM_keymap_find(wm->defaultconf, "Clip", SPACE_CLIP, 0);
1478         WM_event_add_keymap_handler(&ar->handlers, keymap);
1479 }
1480
1481 static void clip_properties_region_draw(const bContext *C, ARegion *ar)
1482 {
1483         SpaceClip *sc = CTX_wm_space_clip(C);
1484
1485         BKE_movieclip_update_scopes(sc->clip, &sc->user, &sc->scopes);
1486
1487         ED_region_panels(C, ar, NULL, -1, true);
1488 }
1489
1490 static void clip_properties_region_listener(
1491         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
1492         wmNotifier *wmn, const Scene *UNUSED(scene))
1493 {
1494         /* context changes */
1495         switch (wmn->category) {
1496                 case NC_GPENCIL:
1497                         if (ELEM(wmn->data, ND_DATA, ND_GPENCIL_EDITMODE))
1498                                 ED_region_tag_redraw(ar);
1499                         break;
1500                 case NC_BRUSH:
1501                         if (wmn->action == NA_EDITED)
1502                                 ED_region_tag_redraw(ar);
1503                         break;
1504         }
1505 }
1506
1507 /********************* registration ********************/
1508
1509 static void clip_id_remap(ScrArea *UNUSED(sa), SpaceLink *slink, ID *old_id, ID *new_id)
1510 {
1511         SpaceClip *sclip = (SpaceClip *)slink;
1512
1513         if (!ELEM(GS(old_id->name), ID_MC, ID_MSK)) {
1514                 return;
1515         }
1516
1517         if ((ID *)sclip->clip == old_id) {
1518                 sclip->clip = (MovieClip *)new_id;
1519                 id_us_ensure_real(new_id);
1520         }
1521
1522         if ((ID *)sclip->mask_info.mask == old_id) {
1523                 sclip->mask_info.mask = (Mask *)new_id;
1524                 id_us_ensure_real(new_id);
1525         }
1526 }
1527
1528 /* only called once, from space/spacetypes.c */
1529 void ED_spacetype_clip(void)
1530 {
1531         SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype clip");
1532         ARegionType *art;
1533
1534         st->spaceid = SPACE_CLIP;
1535         strncpy(st->name, "Clip", BKE_ST_MAXNAME);
1536
1537         st->new = clip_new;
1538         st->free = clip_free;
1539         st->init = clip_init;
1540         st->duplicate = clip_duplicate;
1541         st->operatortypes = clip_operatortypes;
1542         st->keymap = clip_keymap;
1543         st->listener = clip_listener;
1544         st->context = clip_context;
1545         st->dropboxes = clip_dropboxes;
1546         st->refresh = clip_refresh;
1547         st->id_remap = clip_id_remap;
1548
1549         /* regions: main window */
1550         art = MEM_callocN(sizeof(ARegionType), "spacetype clip region");
1551         art->regionid = RGN_TYPE_WINDOW;
1552         art->init = clip_main_region_init;
1553         art->draw = clip_main_region_draw;
1554         art->listener = clip_main_region_listener;
1555         art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_UI | ED_KEYMAP_GPENCIL;
1556
1557         BLI_addhead(&st->regiontypes, art);
1558
1559         /* preview */
1560         art = MEM_callocN(sizeof(ARegionType), "spacetype clip region preview");
1561         art->regionid = RGN_TYPE_PREVIEW;
1562         art->prefsizey = 240;
1563         art->init = clip_preview_region_init;
1564         art->draw = clip_preview_region_draw;
1565         art->listener = clip_preview_region_listener;
1566         art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_UI | ED_KEYMAP_VIEW2D;
1567
1568         BLI_addhead(&st->regiontypes, art);
1569
1570         /* regions: properties */
1571         art = MEM_callocN(sizeof(ARegionType), "spacetype clip region properties");
1572         art->regionid = RGN_TYPE_UI;
1573         art->prefsizex = UI_COMPACT_PANEL_WIDTH;
1574         art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_UI;
1575         art->init = clip_properties_region_init;
1576         art->draw = clip_properties_region_draw;
1577         art->listener = clip_properties_region_listener;
1578         BLI_addhead(&st->regiontypes, art);
1579         ED_clip_buttons_register(art);
1580
1581         /* regions: tools */
1582         art = MEM_callocN(sizeof(ARegionType), "spacetype clip region tools");
1583         art->regionid = RGN_TYPE_TOOLS;
1584         art->prefsizex = UI_COMPACT_PANEL_WIDTH;
1585         art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_UI;
1586         art->listener = clip_props_region_listener;
1587         art->init = clip_tools_region_init;
1588         art->draw = clip_tools_region_draw;
1589
1590         BLI_addhead(&st->regiontypes, art);
1591
1592         /* regions: header */
1593         art = MEM_callocN(sizeof(ARegionType), "spacetype clip region");
1594         art->regionid = RGN_TYPE_HEADER;
1595         art->prefsizey = HEADERY;
1596         art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_HEADER;
1597
1598         art->init = clip_header_region_init;
1599         art->draw = clip_header_region_draw;
1600         art->listener = clip_header_region_listener;
1601
1602         BLI_addhead(&st->regiontypes, art);
1603
1604         BKE_spacetype_register(st);
1605
1606         /* channels */
1607         art = MEM_callocN(sizeof(ARegionType), "spacetype clip channels region");
1608         art->regionid = RGN_TYPE_CHANNELS;
1609         art->prefsizex = UI_COMPACT_PANEL_WIDTH;
1610         art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_UI;
1611         art->listener = clip_channels_region_listener;
1612         art->init = clip_channels_region_init;
1613         art->draw = clip_channels_region_draw;
1614
1615         BLI_addhead(&st->regiontypes, art);
1616 }