quiet unused warnings
[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_movieclip_types.h"
37
38 #include "MEM_guardedalloc.h"
39
40 #include "BLI_blenlib.h"
41 #include "BLI_utildefines.h"
42 #include "BLI_math.h"
43
44 #include "BKE_main.h"
45 #include "BKE_context.h"
46 #include "BKE_screen.h"
47 #include "BKE_movieclip.h"
48 #include "BKE_tracking.h"
49
50 #include "IMB_imbuf_types.h"
51
52 #include "ED_screen.h"
53 #include "ED_clip.h"
54 #include "ED_transform.h"
55
56 #include "IMB_imbuf.h"
57
58 #include "BIF_gl.h"
59
60 #include "WM_api.h"
61 #include "WM_types.h"
62
63 #include "UI_interface.h"
64 #include "UI_resources.h"
65 #include "UI_view2d.h"
66
67 #include "RNA_access.h"
68
69
70 #include "clip_intern.h"        // own include
71
72 static void init_preview_region(const bContext *C, ARegion *ar)
73 {
74         Scene *scene = CTX_data_scene(C);
75
76         ar->regiontype = RGN_TYPE_PREVIEW;
77         ar->alignment = RGN_ALIGN_TOP;
78         ar->flag |= RGN_FLAG_HIDDEN;
79
80         ar->v2d.tot.xmin = 0.0f;
81         ar->v2d.tot.ymin = -10.0f;
82         ar->v2d.tot.xmax = (float)scene->r.efra;
83         ar->v2d.tot.ymax = 10.0f;
84
85         ar->v2d.cur = ar->v2d.tot;
86
87         ar->v2d.min[0] = FLT_MIN;
88         ar->v2d.min[1] = FLT_MIN;
89
90         ar->v2d.max[0] = MAXFRAMEF;
91         ar->v2d.max[1] = FLT_MAX;
92
93         ar->v2d.scroll = (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
94         ar->v2d.scroll |= (V2D_SCROLL_LEFT|V2D_SCROLL_SCALE_VERTICAL);
95
96         ar->v2d.keeptot = 0;
97 }
98
99 static ARegion *ED_clip_has_preview_region(const bContext *C, ScrArea *sa)
100 {
101         ARegion *ar, *arnew;
102
103         ar = BKE_area_find_region_type(sa, RGN_TYPE_PREVIEW);
104         if (ar)
105                 return ar;
106
107         /* add subdiv level; after header */
108         ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
109
110         /* is error! */
111         if (ar == NULL)
112                 return NULL;
113
114         arnew = MEM_callocN(sizeof(ARegion), "clip preview region");
115
116         BLI_insertlinkbefore(&sa->regionbase, ar, arnew);
117         init_preview_region(C, arnew);
118
119         return arnew;
120 }
121
122 static void clip_scopes_tag_refresh(ScrArea *sa)
123 {
124         SpaceClip *sc = (SpaceClip *)sa->spacedata.first;
125         ARegion *ar;
126
127         if (sc->mode != SC_MODE_TRACKING)
128                 return;
129
130         /* only while proeprties are visible */
131         for (ar = sa->regionbase.first; ar; ar = ar->next) {
132                 if (ar->regiontype == RGN_TYPE_UI && ar->flag & RGN_FLAG_HIDDEN)
133                         return;
134         }
135
136         sc->scopes.ok = FALSE;
137 }
138
139 static void clip_stabilization_tag_refresh(ScrArea *sa)
140 {
141         SpaceClip *sc = (SpaceClip *) sa->spacedata.first;
142         MovieClip *clip = ED_space_clip(sc);
143
144         if (clip) {
145                 MovieTrackingStabilization *stab = &clip->tracking.stabilization;
146
147                 stab->ok = FALSE;
148         }
149 }
150
151 /* ******************** default callbacks for clip space ***************** */
152
153 static SpaceLink *clip_new(const bContext *C)
154 {
155         ARegion *ar;
156         SpaceClip *sc;
157
158         sc = MEM_callocN(sizeof(SpaceClip), "initclip");
159         sc->spacetype = SPACE_CLIP;
160         sc->flag = SC_SHOW_MARKER_PATTERN|SC_SHOW_TRACK_PATH|SC_MANUAL_CALIBRATION|SC_SHOW_GRAPH_TRACKS|SC_SHOW_GRAPH_FRAMES;
161         sc->zoom = 1.0f;
162         sc->path_length = 20;
163         sc->scopes.track_preview_height = 120;
164
165         /* header */
166         ar = MEM_callocN(sizeof(ARegion), "header for clip");
167
168         BLI_addtail(&sc->regionbase, ar);
169         ar->regiontype = RGN_TYPE_HEADER;
170         ar->alignment = RGN_ALIGN_BOTTOM;
171
172         /* tools view */
173         ar = MEM_callocN(sizeof(ARegion), "tools for clip");
174
175         BLI_addtail(&sc->regionbase, ar);
176         ar->regiontype = RGN_TYPE_TOOLS;
177         ar->alignment = RGN_ALIGN_LEFT;
178
179         /* tool properties */
180         ar = MEM_callocN(sizeof(ARegion), "tool properties for clip");
181
182         BLI_addtail(&sc->regionbase, ar);
183         ar->regiontype = RGN_TYPE_TOOL_PROPS;
184         ar->alignment = RGN_ALIGN_BOTTOM|RGN_SPLIT_PREV;
185
186         /* properties view */
187         ar = MEM_callocN(sizeof(ARegion), "properties for clip");
188
189         BLI_addtail(&sc->regionbase, ar);
190         ar->regiontype = RGN_TYPE_UI;
191         ar->alignment = RGN_ALIGN_RIGHT;
192
193         /* preview view */
194         ar = MEM_callocN(sizeof(ARegion), "preview for clip");
195
196         BLI_addtail(&sc->regionbase, ar);
197         init_preview_region(C, ar);
198
199         /* main area */
200         ar = MEM_callocN(sizeof(ARegion), "main area for clip");
201
202         BLI_addtail(&sc->regionbase, ar);
203         ar->regiontype = RGN_TYPE_WINDOW;
204
205         return (SpaceLink *) sc;
206 }
207
208 /* not spacelink itself */
209 static void clip_free(SpaceLink *sl)
210 {
211         SpaceClip *sc = (SpaceClip*) sl;
212
213         sc->clip = NULL;
214
215         if (sc->scopes.track_preview)
216                 IMB_freeImBuf(sc->scopes.track_preview);
217 }
218
219 /* spacetype; init callback */
220 static void clip_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
221 {
222
223 }
224
225 static SpaceLink *clip_duplicate(SpaceLink *sl)
226 {
227         SpaceClip *scn = MEM_dupallocN(sl);
228
229         /* clear or remove stuff from old */
230         scn->scopes.track_preview = NULL;
231         scn->scopes.ok = FALSE;
232
233         return (SpaceLink *)scn;
234 }
235
236 static void clip_listener(ScrArea *sa, wmNotifier *wmn)
237 {
238         /* context changes */
239         switch (wmn->category) {
240                 case NC_SCENE:
241                         switch (wmn->data) {
242                                 case ND_FRAME:
243                                         clip_scopes_tag_refresh(sa);
244                                         /* no break! */
245
246                                 case ND_FRAME_RANGE:
247                                         ED_area_tag_redraw(sa);
248                                         break;
249                         }
250                         break;
251                 case NC_MOVIECLIP:
252                         switch (wmn->data) {
253                                 case ND_DISPLAY:
254                                 case ND_SELECT:
255                                         clip_scopes_tag_refresh(sa);
256                                         ED_area_tag_redraw(sa);
257                                         break;
258                         }
259                         switch (wmn->action) {
260                                 case NA_REMOVED:
261                                 case NA_EDITED:
262                                 case NA_EVALUATED:
263                                         clip_stabilization_tag_refresh(sa);
264                                         /* no break! */
265
266                                 case NA_SELECTED:
267                                         clip_scopes_tag_refresh(sa);
268                                         ED_area_tag_redraw(sa);
269                                         break;
270                         }
271                         break;
272                 case NC_GEOM:
273                         switch (wmn->data) {
274                                 case ND_SELECT:
275                                         clip_scopes_tag_refresh(sa);
276                                         ED_area_tag_redraw(sa);
277                                         break;
278                         }
279                         break;
280                  case NC_SCREEN:
281                         if (wmn->data ==ND_ANIMPLAY) {
282                                 ED_area_tag_redraw(sa);
283                         }
284                         break;
285                 case NC_SPACE:
286                         if (wmn->data ==ND_SPACE_CLIP) {
287                                 clip_scopes_tag_refresh(sa);
288                                 clip_stabilization_tag_refresh(sa);
289                                 ED_area_tag_redraw(sa);
290                         }
291                         break;
292         }
293 }
294
295 static void clip_operatortypes(void)
296 {
297         /* ** clip_ops.c ** */
298         WM_operatortype_append(CLIP_OT_open);
299         WM_operatortype_append(CLIP_OT_reload);
300         WM_operatortype_append(CLIP_OT_view_pan);
301         WM_operatortype_append(CLIP_OT_view_zoom);
302         WM_operatortype_append(CLIP_OT_view_zoom_in);
303         WM_operatortype_append(CLIP_OT_view_zoom_out);
304         WM_operatortype_append(CLIP_OT_view_zoom_ratio);
305         WM_operatortype_append(CLIP_OT_view_all);
306         WM_operatortype_append(CLIP_OT_view_selected);
307         WM_operatortype_append(CLIP_OT_change_frame);
308         WM_operatortype_append(CLIP_OT_rebuild_proxy);
309         WM_operatortype_append(CLIP_OT_mode_set);
310
311         /* ** clip_toolbar.c ** */
312         WM_operatortype_append(CLIP_OT_tools);
313         WM_operatortype_append(CLIP_OT_properties);
314
315         /* ** tracking_ops.c ** */
316
317         /* navigation */
318         WM_operatortype_append(CLIP_OT_frame_jump);
319
320         /* foorage */
321         WM_operatortype_append(CLIP_OT_set_center_principal);
322
323         /* selection */
324         WM_operatortype_append(CLIP_OT_select);
325         WM_operatortype_append(CLIP_OT_select_all);
326         WM_operatortype_append(CLIP_OT_select_border);
327         WM_operatortype_append(CLIP_OT_select_circle);
328         WM_operatortype_append(CLIP_OT_select_grouped);
329
330         /* markers */
331         WM_operatortype_append(CLIP_OT_add_marker);
332         WM_operatortype_append(CLIP_OT_slide_marker);
333         WM_operatortype_append(CLIP_OT_delete_track);
334         WM_operatortype_append(CLIP_OT_delete_marker);
335
336         /* track */
337         WM_operatortype_append(CLIP_OT_track_markers);
338
339         /* solving */
340         WM_operatortype_append(CLIP_OT_solve_camera);
341         WM_operatortype_append(CLIP_OT_clear_solution);
342
343         WM_operatortype_append(CLIP_OT_disable_markers);
344         WM_operatortype_append(CLIP_OT_hide_tracks);
345         WM_operatortype_append(CLIP_OT_hide_tracks_clear);
346         WM_operatortype_append(CLIP_OT_lock_tracks);
347
348         /* orientation */
349         WM_operatortype_append(CLIP_OT_set_origin);
350         WM_operatortype_append(CLIP_OT_set_plane);
351         WM_operatortype_append(CLIP_OT_set_axis);
352         WM_operatortype_append(CLIP_OT_set_scale);
353         WM_operatortype_append(CLIP_OT_set_solution_scale);
354
355         /* detect */
356         WM_operatortype_append(CLIP_OT_detect_features);
357
358         /* stabilization */
359         WM_operatortype_append(CLIP_OT_stabilize_2d_add);
360         WM_operatortype_append(CLIP_OT_stabilize_2d_remove);
361         WM_operatortype_append(CLIP_OT_stabilize_2d_select);
362         WM_operatortype_append(CLIP_OT_stabilize_2d_set_rotation);
363
364         /* clean-up */
365         WM_operatortype_append(CLIP_OT_clear_track_path);
366         WM_operatortype_append(CLIP_OT_join_tracks);
367         WM_operatortype_append(CLIP_OT_track_copy_color);
368
369         WM_operatortype_append(CLIP_OT_clean_tracks);
370
371         /* object tracking */
372         WM_operatortype_append(CLIP_OT_tracking_object_new);
373         WM_operatortype_append(CLIP_OT_tracking_object_remove);
374
375         /* clipboard */
376         WM_operatortype_append(CLIP_OT_copy_tracks);
377         WM_operatortype_append(CLIP_OT_paste_tracks);
378
379         /* ** clip_graph_ops.c  ** */
380
381         /* graph editing */
382
383         /* selection */
384         WM_operatortype_append(CLIP_OT_graph_select);
385         WM_operatortype_append(CLIP_OT_graph_select_border);
386         WM_operatortype_append(CLIP_OT_graph_select_all_markers);
387
388         WM_operatortype_append(CLIP_OT_graph_delete_curve);
389         WM_operatortype_append(CLIP_OT_graph_delete_knot);
390         WM_operatortype_append(CLIP_OT_graph_view_all);
391         WM_operatortype_append(CLIP_OT_graph_center_current_frame);
392
393         WM_operatortype_append(CLIP_OT_graph_disable_markers);
394 }
395
396 static void clip_keymap(struct wmKeyConfig *keyconf)
397 {
398         wmKeyMap *keymap;
399         wmKeyMapItem *kmi;
400
401         /* ******** Global hotkeys avalaible for all regions ******** */
402
403         keymap = WM_keymap_find(keyconf, "Clip", SPACE_CLIP, 0);
404
405         WM_keymap_add_item(keymap, "CLIP_OT_open", OKEY, KM_PRESS, KM_ALT, 0);
406
407         WM_keymap_add_item(keymap, "CLIP_OT_tools", TKEY, KM_PRESS, 0, 0);
408         WM_keymap_add_item(keymap, "CLIP_OT_properties", NKEY, KM_PRESS, 0, 0);
409
410         /* 2d tracking */
411         kmi = WM_keymap_add_item(keymap, "CLIP_OT_track_markers", LEFTARROWKEY, KM_PRESS, KM_ALT, 0);
412         RNA_boolean_set(kmi->ptr, "backwards", TRUE);
413         RNA_boolean_set(kmi->ptr, "sequence", FALSE);
414         kmi = WM_keymap_add_item(keymap, "CLIP_OT_track_markers", RIGHTARROWKEY, KM_PRESS, KM_ALT, 0);
415         RNA_boolean_set(kmi->ptr, "backwards", FALSE);
416         RNA_boolean_set(kmi->ptr, "sequence", FALSE);
417         kmi = WM_keymap_add_item(keymap, "CLIP_OT_track_markers", TKEY, KM_PRESS, KM_CTRL, 0);
418         RNA_boolean_set(kmi->ptr, "backwards", FALSE);
419         RNA_boolean_set(kmi->ptr, "sequence", TRUE);
420         kmi = WM_keymap_add_item(keymap, "CLIP_OT_track_markers", TKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
421         RNA_boolean_set(kmi->ptr, "backwards", TRUE);
422         RNA_boolean_set(kmi->ptr, "sequence", TRUE);
423
424         /* mode */
425         kmi = WM_keymap_add_item(keymap, "CLIP_OT_mode_set", TABKEY, KM_PRESS, 0, 0);
426         RNA_enum_set(kmi->ptr, "mode", SC_MODE_RECONSTRUCTION);
427         RNA_boolean_set(kmi->ptr, "toggle", TRUE);
428
429         kmi = WM_keymap_add_item(keymap, "CLIP_OT_mode_set", TABKEY, KM_PRESS, KM_CTRL, 0);
430         RNA_enum_set(kmi->ptr, "mode", SC_MODE_DISTORTION);
431         RNA_boolean_set(kmi->ptr, "toggle", TRUE);
432
433         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle_enum", ZKEY, KM_PRESS, 0, 0);
434         RNA_string_set(kmi->ptr, "data_path", "space_data.view");
435         RNA_string_set(kmi->ptr, "value_1", "CLIP");
436         RNA_string_set(kmi->ptr, "value_2", "GRAPH");
437
438         WM_keymap_add_item(keymap, "CLIP_OT_solve_camera", SKEY, KM_PRESS, KM_SHIFT, 0);
439
440         /* ******** Hotkeys avalaible for main region only ******** */
441
442         keymap = WM_keymap_find(keyconf, "Clip Editor", SPACE_CLIP, 0);
443
444         /* ** View/navigation ** */
445
446         WM_keymap_add_item(keymap, "CLIP_OT_view_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
447         WM_keymap_add_item(keymap, "CLIP_OT_view_pan", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);
448         WM_keymap_add_item(keymap, "CLIP_OT_view_pan", MOUSEPAN, 0, 0, 0);
449
450         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
451         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom", MOUSEZOOM, 0, 0, 0);
452         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_in", WHEELINMOUSE, KM_PRESS, 0, 0);
453         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_out", WHEELOUTMOUSE, KM_PRESS, 0, 0);
454         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0);
455         WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_out", PADMINUS, KM_PRESS, 0, 0);
456
457         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD8, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 8.0f);
458         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD4, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 4.0f);
459         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD2, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 2.0f);
460         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD1, KM_PRESS, 0, 0)->ptr, "ratio", 1.0f);
461         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD2, KM_PRESS, 0, 0)->ptr, "ratio", 0.5f);
462         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD4, KM_PRESS, 0, 0)->ptr, "ratio", 0.25f);
463         RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD8, KM_PRESS, 0, 0)->ptr, "ratio", 0.125f);
464
465         WM_keymap_add_item(keymap, "CLIP_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
466
467         kmi = WM_keymap_add_item(keymap, "CLIP_OT_view_all", FKEY, KM_PRESS, 0, 0);
468         RNA_boolean_set(kmi->ptr, "fit_view", TRUE);
469
470         WM_keymap_add_item(keymap, "CLIP_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
471
472         /* jump to special frame */
473         kmi = WM_keymap_add_item(keymap, "CLIP_OT_frame_jump", LEFTARROWKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
474         RNA_enum_set(kmi->ptr, "position", 0);
475
476         kmi = WM_keymap_add_item(keymap, "CLIP_OT_frame_jump", RIGHTARROWKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
477         RNA_enum_set(kmi->ptr, "position", 1);
478
479         kmi = WM_keymap_add_item(keymap, "CLIP_OT_frame_jump", LEFTARROWKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0);
480         RNA_enum_set(kmi->ptr, "position", 2);
481
482         kmi = WM_keymap_add_item(keymap, "CLIP_OT_frame_jump", RIGHTARROWKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0);
483         RNA_enum_set(kmi->ptr, "position", 3);
484
485         /* "timeline" */
486         WM_keymap_add_item(keymap, "CLIP_OT_change_frame", LEFTMOUSE, KM_PRESS, 0, 0);
487
488         /* selection */
489         kmi = WM_keymap_add_item(keymap, "CLIP_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
490         RNA_boolean_set(kmi->ptr, "extend", FALSE);
491         kmi = WM_keymap_add_item(keymap, "CLIP_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
492         RNA_boolean_set(kmi->ptr, "extend", TRUE);
493         kmi = WM_keymap_add_item(keymap, "CLIP_OT_select_all", AKEY, KM_PRESS, 0, 0);
494         RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
495         kmi = WM_keymap_add_item(keymap, "CLIP_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
496         RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
497         WM_keymap_add_item(keymap, "CLIP_OT_select_border", BKEY, KM_PRESS, 0, 0);
498         WM_keymap_add_item(keymap, "CLIP_OT_select_circle", CKEY, KM_PRESS, 0, 0);
499         WM_keymap_add_menu(keymap, "CLIP_MT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0);
500
501         /* marker */
502         WM_keymap_add_item(keymap, "CLIP_OT_add_marker_slide", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
503
504         WM_keymap_add_item(keymap, "CLIP_OT_delete_marker", DELKEY, KM_PRESS, KM_SHIFT, 0);
505         WM_keymap_add_item(keymap, "CLIP_OT_delete_marker", XKEY, KM_PRESS, KM_SHIFT, 0);
506
507         WM_keymap_add_item(keymap, "CLIP_OT_slide_marker", LEFTMOUSE, KM_PRESS, 0, 0);
508
509         kmi = WM_keymap_add_item(keymap, "CLIP_OT_disable_markers", DKEY, KM_PRESS, KM_SHIFT, 0);
510         RNA_enum_set(kmi->ptr, "action", 2);    /* toggle */
511
512         /* tracks */
513         WM_keymap_add_item(keymap, "CLIP_OT_delete_track", DELKEY, KM_PRESS, 0, 0);
514         WM_keymap_add_item(keymap, "CLIP_OT_delete_track", XKEY, KM_PRESS, 0, 0);
515
516         kmi = WM_keymap_add_item(keymap, "CLIP_OT_lock_tracks", LKEY, KM_PRESS, KM_CTRL, 0);
517         RNA_enum_set(kmi->ptr, "action", 0);    /* lock */
518
519         kmi = WM_keymap_add_item(keymap, "CLIP_OT_lock_tracks", LKEY, KM_PRESS, KM_ALT, 0);
520         RNA_enum_set(kmi->ptr, "action", 1);    /* unlock */
521
522         kmi = WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks", HKEY, KM_PRESS, 0, 0);
523         RNA_boolean_set(kmi->ptr, "unselected", FALSE);
524
525         kmi = WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks", HKEY, KM_PRESS, KM_SHIFT, 0);
526         RNA_boolean_set(kmi->ptr, "unselected", TRUE);
527
528         WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks_clear", HKEY, KM_PRESS, KM_ALT, 0);
529
530         /* clean-up */
531         WM_keymap_add_item(keymap, "CLIP_OT_join_tracks", JKEY, KM_PRESS, KM_CTRL, 0);
532
533         /* menus */
534         WM_keymap_add_menu(keymap, "CLIP_MT_tracking_specials", WKEY, KM_PRESS, 0, 0);
535
536         /* display */
537         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", LKEY, KM_PRESS, 0, 0);
538         RNA_string_set(kmi->ptr, "data_path", "space_data.lock_selection");
539
540         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", DKEY, KM_PRESS, KM_ALT, 0);
541         RNA_string_set(kmi->ptr, "data_path", "space_data.show_disabled");
542
543         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", SKEY, KM_PRESS, KM_ALT, 0);
544         RNA_string_set(kmi->ptr, "data_path", "space_data.show_marker_search");
545
546         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0);
547         RNA_string_set(kmi->ptr, "data_path", "space_data.use_mute_footage");
548
549         transform_keymap_for_space(keyconf, keymap, SPACE_CLIP);
550
551         /* clean-up */
552         kmi = WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_ALT, 0);
553         RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_REMAINED);
554         RNA_boolean_set(kmi->ptr, "clear_active", FALSE);
555         kmi = WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_SHIFT, 0);
556         RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_UPTO);
557         RNA_boolean_set(kmi->ptr, "clear_active", FALSE);
558         kmi = WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0);
559         RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_ALL);
560         RNA_boolean_set(kmi->ptr, "clear_active", FALSE);
561
562         /* ******** Hotkeys avalaible for preview region only ******** */
563
564         keymap = WM_keymap_find(keyconf, "Clip Graph Editor", SPACE_CLIP, 0);
565
566         /* "timeline" */
567         WM_keymap_add_item(keymap, "CLIP_OT_change_frame", ACTIONMOUSE, KM_PRESS, 0, 0);
568
569         /* selection */
570         kmi = WM_keymap_add_item(keymap, "CLIP_OT_graph_select", SELECTMOUSE, KM_PRESS, 0, 0);
571         RNA_boolean_set(kmi->ptr, "extend", FALSE);
572         kmi = WM_keymap_add_item(keymap, "CLIP_OT_graph_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
573         RNA_boolean_set(kmi->ptr, "extend", TRUE);
574
575         kmi = WM_keymap_add_item(keymap, "CLIP_OT_graph_select_all_markers", AKEY, KM_PRESS, 0, 0);
576         RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
577         kmi = WM_keymap_add_item(keymap, "CLIP_OT_graph_select_all_markers", IKEY, KM_PRESS, KM_CTRL, 0);
578         RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
579
580         WM_keymap_add_item(keymap, "CLIP_OT_graph_select_border", BKEY, KM_PRESS, 0, 0);
581
582         /* delete */
583         WM_keymap_add_item(keymap, "CLIP_OT_graph_delete_curve", DELKEY, KM_PRESS, 0, 0);
584         WM_keymap_add_item(keymap, "CLIP_OT_graph_delete_curve", XKEY, KM_PRESS, 0, 0);
585
586         WM_keymap_add_item(keymap, "CLIP_OT_graph_delete_knot", DELKEY, KM_PRESS, KM_SHIFT, 0);
587         WM_keymap_add_item(keymap, "CLIP_OT_graph_delete_knot", XKEY, KM_PRESS, KM_SHIFT, 0);
588
589         /* view */
590         WM_keymap_add_item(keymap, "CLIP_OT_graph_view_all", HOMEKEY, KM_PRESS, 0, 0);
591         WM_keymap_add_item(keymap, "CLIP_OT_graph_center_current_frame", PADPERIOD, KM_PRESS, 0, 0);
592
593         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", LKEY, KM_PRESS, 0, 0);
594         RNA_string_set(kmi->ptr, "data_path", "space_data.lock_time_cursor");
595
596         /* clean-up */
597         kmi = WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_ALT, 0);
598         RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_REMAINED);
599         RNA_boolean_set(kmi->ptr, "clear_active", TRUE);
600         kmi = WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_SHIFT, 0);
601         RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_UPTO);
602         RNA_boolean_set(kmi->ptr, "clear_active", TRUE);
603         kmi = WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0);
604         RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_ALL);
605         RNA_boolean_set(kmi->ptr, "clear_active", TRUE);
606
607         /* tracks */
608         kmi = WM_keymap_add_item(keymap, "CLIP_OT_graph_disable_markers", DKEY, KM_PRESS, KM_SHIFT, 0);
609         RNA_enum_set(kmi->ptr, "action", 2);    /* toggle */
610
611         transform_keymap_for_space(keyconf, keymap, SPACE_CLIP);
612 }
613
614 const char *clip_context_dir[]= {"edit_movieclip", NULL};
615
616 static int clip_context(const bContext *C, const char *member, bContextDataResult *result)
617 {
618         SpaceClip *sc = CTX_wm_space_clip(C);
619
620         if (CTX_data_dir(member)) {
621                 CTX_data_dir_set(result, clip_context_dir);
622
623                 return TRUE;
624         }
625         else if (CTX_data_equals(member, "edit_movieclip")) {
626                 if (sc->clip)
627                         CTX_data_id_pointer_set(result, &sc->clip->id);
628
629                 return TRUE;
630         }
631
632         return FALSE;
633 }
634
635 static void clip_refresh(const bContext *C, ScrArea *sa)
636 {
637         wmWindowManager *wm = CTX_wm_manager(C);
638         wmWindow *window = CTX_wm_window(C);
639         Scene *scene = CTX_data_scene(C);
640         SpaceClip *sc = (SpaceClip *)sa->spacedata.first;
641         ARegion *ar_main = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
642         ARegion *ar_tools = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS);
643         ARegion *ar_tool_props = BKE_area_find_region_type(sa, RGN_TYPE_TOOL_PROPS);
644         ARegion *ar_preview = ED_clip_has_preview_region(C, sa);
645         ARegion *ar_properties = ED_clip_has_properties_region(sa);
646         int main_visible = FALSE, preview_visible = FALSE, tools_visible = FALSE;
647         int tool_props_visible = FALSE, properties_visible = FALSE;
648         int view_changed = FALSE;
649
650         switch (sc->view) {
651                 case SC_VIEW_CLIP:
652                         main_visible = TRUE;
653                         preview_visible = FALSE;
654                         tools_visible = TRUE;
655                         tool_props_visible = TRUE;
656                         properties_visible = TRUE;
657                         break;
658                 case SC_VIEW_GRAPH:
659                         main_visible = TRUE;
660                         preview_visible = TRUE;
661                         tools_visible = TRUE;
662                         tool_props_visible = TRUE;
663                         properties_visible = TRUE;
664                         break;
665         }
666
667         if (main_visible) {
668                 if (ar_main && (ar_main->flag & RGN_FLAG_HIDDEN)) {
669                         ar_main->flag &= ~RGN_FLAG_HIDDEN;
670                         ar_main->v2d.flag &= ~V2D_IS_INITIALISED;
671                         view_changed = TRUE;
672                 }
673
674                 if (ar_main && ar_main->alignment != RGN_ALIGN_NONE) {
675                         ar_main->alignment = RGN_ALIGN_NONE;
676                         view_changed = TRUE;
677                 }
678         }
679         else {
680                 if (ar_main && !(ar_main->flag & RGN_FLAG_HIDDEN)) {
681                         ar_main->flag |= RGN_FLAG_HIDDEN;
682                         ar_main->v2d.flag &= ~V2D_IS_INITIALISED;
683                         WM_event_remove_handlers((bContext *)C, &ar_main->handlers);
684                         view_changed = TRUE;
685                 }
686                 if (ar_main && ar_main->alignment != RGN_ALIGN_NONE) {
687                         ar_main->alignment = RGN_ALIGN_NONE;
688                         view_changed = TRUE;
689                 }
690         }
691
692         if (properties_visible) {
693                 if (ar_properties && (ar_properties->flag & RGN_FLAG_HIDDEN)) {
694                         ar_properties->flag &= ~RGN_FLAG_HIDDEN;
695                         ar_properties->v2d.flag &= ~V2D_IS_INITIALISED;
696                         view_changed = TRUE;
697                 }
698                 if (ar_properties && ar_properties->alignment != RGN_ALIGN_RIGHT) {
699                         ar_properties->alignment = RGN_ALIGN_RIGHT;
700                         view_changed = TRUE;
701                 }
702         }
703         else {
704                 if (ar_properties && !(ar_properties->flag & RGN_FLAG_HIDDEN)) {
705                         ar_properties->flag |= RGN_FLAG_HIDDEN;
706                         ar_properties->v2d.flag &= ~V2D_IS_INITIALISED;
707                         WM_event_remove_handlers((bContext *)C, &ar_properties->handlers);
708                         view_changed = TRUE;
709                 }
710                 if (ar_properties && ar_properties->alignment != RGN_ALIGN_NONE) {
711                         ar_properties->alignment = RGN_ALIGN_NONE;
712                         view_changed = TRUE;
713                 }
714         }
715
716         if (tools_visible) {
717                 if (ar_tools && (ar_tools->flag & RGN_FLAG_HIDDEN)) {
718                         ar_tools->flag &= ~RGN_FLAG_HIDDEN;
719                         ar_tools->v2d.flag &= ~V2D_IS_INITIALISED;
720                         view_changed = TRUE;
721                 }
722                 if (ar_tools && ar_tools->alignment != RGN_ALIGN_LEFT) {
723                         ar_tools->alignment = RGN_ALIGN_LEFT;
724                         view_changed = TRUE;
725                 }
726         }
727         else {
728                 if (ar_tools && !(ar_tools->flag & RGN_FLAG_HIDDEN)) {
729                         ar_tools->flag |= RGN_FLAG_HIDDEN;
730                         ar_tools->v2d.flag &= ~V2D_IS_INITIALISED;
731                         WM_event_remove_handlers((bContext *)C, &ar_tools->handlers);
732                         view_changed = TRUE;
733                 }
734                 if (ar_tools && ar_tools->alignment != RGN_ALIGN_NONE) {
735                         ar_tools->alignment = RGN_ALIGN_NONE;
736                         view_changed = TRUE;
737                 }
738         }
739
740         if (tool_props_visible) {
741                 if (ar_tool_props && (ar_tool_props->flag & RGN_FLAG_HIDDEN)) {
742                         ar_tool_props->flag &= ~RGN_FLAG_HIDDEN;
743                         ar_tool_props->v2d.flag &= ~V2D_IS_INITIALISED;
744                         view_changed = TRUE;
745                 }
746                 if (ar_tool_props && (ar_tool_props->alignment != (RGN_ALIGN_BOTTOM|RGN_SPLIT_PREV))) {
747                         ar_tool_props->alignment = RGN_ALIGN_BOTTOM|RGN_SPLIT_PREV;
748                         view_changed = TRUE;
749                 }
750         }
751         else {
752                 if (ar_tool_props && !(ar_tool_props->flag & RGN_FLAG_HIDDEN)) {
753                         ar_tool_props->flag |= RGN_FLAG_HIDDEN;
754                         ar_tool_props->v2d.flag &= ~V2D_IS_INITIALISED;
755                         WM_event_remove_handlers((bContext *)C, &ar_tool_props->handlers);
756                         view_changed = TRUE;
757                 }
758                 if (ar_tool_props && ar_tool_props->alignment != RGN_ALIGN_NONE) {
759                         ar_tool_props->alignment = RGN_ALIGN_NONE;
760                         view_changed = TRUE;
761                 }
762         }
763
764         if (preview_visible) {
765                 if (ar_preview && (ar_preview->flag & RGN_FLAG_HIDDEN)) {
766                         ar_preview->flag &= ~RGN_FLAG_HIDDEN;
767                         ar_preview->v2d.flag &= ~V2D_IS_INITIALISED;
768                         ar_preview->v2d.cur = ar_preview->v2d.tot;
769                         view_changed = TRUE;
770                 }
771                 if (ar_preview && !ELEM(ar_preview->alignment, RGN_ALIGN_TOP,  RGN_ALIGN_BOTTOM)) {
772                         if (sc->runtime_flag & SC_GRAPH_BOTTOM)
773                                 ar_preview->alignment = RGN_ALIGN_BOTTOM;
774                         else
775                                 ar_preview->alignment = RGN_ALIGN_TOP;
776
777                         view_changed = TRUE;
778                 }
779         }
780         else {
781                 /* store graph region align */
782                 if (ar_preview->alignment == RGN_ALIGN_TOP)
783                         sc->runtime_flag &= ~SC_GRAPH_BOTTOM;
784                 else if (ar_preview->alignment == RGN_ALIGN_BOTTOM)
785                         sc->runtime_flag |= SC_GRAPH_BOTTOM;
786
787                 if (ar_preview && !(ar_preview->flag & RGN_FLAG_HIDDEN)) {
788                         ar_preview->flag |= RGN_FLAG_HIDDEN;
789                         ar_preview->v2d.flag &= ~V2D_IS_INITIALISED;
790                         WM_event_remove_handlers((bContext *)C, &ar_preview->handlers);
791                         view_changed = TRUE;
792                 }
793                 if (ar_preview && ar_preview->alignment != RGN_ALIGN_NONE) {
794                         ar_preview->alignment = RGN_ALIGN_NONE;
795                         view_changed = TRUE;
796                 }
797         }
798
799         if (view_changed) {
800                 ED_area_initialize(wm, window, sa);
801                 ED_area_tag_redraw(sa);
802         }
803
804         BKE_movieclip_user_set_frame(&sc->user, scene->r.cfra);
805 }
806
807 /********************* main region ********************/
808
809 /* sets up the fields of the View2D from zoom and offset */
810 static void movieclip_main_area_set_view2d(SpaceClip *sc, ARegion *ar)
811 {
812         MovieClip *clip = ED_space_clip(sc);
813         float x1, y1, w, h;
814         int width, height, winx, winy;
815
816         ED_space_clip_size(sc, &width, &height);
817
818         w = width;
819         h = height;
820
821         if (clip)
822                 h *= clip->aspy / clip->aspx / clip->tracking.camera.pixel_aspect;
823
824         winx = ar->winrct.xmax - ar->winrct.xmin + 1;
825         winy = ar->winrct.ymax - ar->winrct.ymin + 1;
826
827         ar->v2d.tot.xmin = 0;
828         ar->v2d.tot.ymin = 0;
829         ar->v2d.tot.xmax = w;
830         ar->v2d.tot.ymax = h;
831
832         ar->v2d.mask.xmin = ar->v2d.mask.ymin = 0;
833         ar->v2d.mask.xmax = winx;
834         ar->v2d.mask.ymax = winy;
835
836         /* which part of the image space do we see? */
837         x1= ar->winrct.xmin + (winx-sc->zoom * w) / 2.0f;
838         y1= ar->winrct.ymin + (winy-sc->zoom * h) / 2.0f;
839
840         x1-= sc->zoom * sc->xof;
841         y1-= sc->zoom * sc->yof;
842
843         /* relative display right */
844         ar->v2d.cur.xmin = (ar->winrct.xmin - (float)x1) / sc->zoom;
845         ar->v2d.cur.xmax = ar->v2d.cur.xmin + ((float)winx / sc->zoom);
846
847         /* relative display left */
848         ar->v2d.cur.ymin = (ar->winrct.ymin - (float)y1) / sc->zoom;
849         ar->v2d.cur.ymax = ar->v2d.cur.ymin + ((float)winy / sc->zoom);
850
851         /* normalize 0.0..1.0 */
852         ar->v2d.cur.xmin /= w;
853         ar->v2d.cur.xmax /= w;
854         ar->v2d.cur.ymin /= h;
855         ar->v2d.cur.ymax /= h;
856 }
857
858 /* add handlers, stuff you only do once or on area/region changes */
859 static void clip_main_area_init(wmWindowManager *wm, ARegion *ar)
860 {
861         wmKeyMap *keymap;
862
863         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
864
865         /* own keymap */
866         keymap = WM_keymap_find(wm->defaultconf, "Clip", SPACE_CLIP, 0);
867         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
868
869         keymap = WM_keymap_find(wm->defaultconf, "Clip Editor", SPACE_CLIP, 0);
870         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
871 }
872
873 static void clip_main_area_draw(const bContext *C, ARegion *ar)
874 {
875         /* draw entirely, view changes should be handled here */
876         SpaceClip *sc = CTX_wm_space_clip(C);
877         Scene *scene = CTX_data_scene(C);
878         MovieClip *clip = ED_space_clip(sc);
879
880         /* if tracking is in progress, we should synchronize framenr from clipuser
881          * so latest tracked frame would be shown */
882         if (clip && clip->tracking_context)
883                 BKE_tracking_sync_user(&sc->user, clip->tracking_context);
884
885         if (sc->flag & SC_LOCK_SELECTION) {
886                 ImBuf *tmpibuf = NULL;
887
888                 if (clip && clip->tracking.stabilization.flag & TRACKING_2D_STABILIZATION) {
889                         tmpibuf = ED_space_clip_get_stable_buffer(sc, NULL, NULL, NULL);
890                 }
891
892                 if (ED_clip_view_selection(sc, ar, 0)) {
893                         sc->xof += sc->xlockof;
894                         sc->yof += sc->ylockof;
895                 }
896
897                 if (tmpibuf)
898                         IMB_freeImBuf(tmpibuf);
899         }
900
901         /* clear and setup matrix */
902         UI_ThemeClearColor(TH_BACK);
903         glClear(GL_COLOR_BUFFER_BIT);
904
905         /* data... */
906         movieclip_main_area_set_view2d(sc, ar);
907
908         clip_draw_main(sc, ar, scene);
909
910         /* Grease Pencil */
911         clip_draw_grease_pencil((bContext *)C, 1);
912
913         /* reset view matrix */
914         UI_view2d_view_restore(C);
915
916         /* draw Grease Pencil - screen space only */
917         clip_draw_grease_pencil((bContext *)C, 0);
918 }
919
920 static void clip_main_area_listener(ARegion *ar, wmNotifier *wmn)
921 {
922         /* context changes */
923         switch (wmn->category) {
924                 case NC_SCREEN:
925                         if (wmn->data == ND_GPENCIL)
926                                 ED_region_tag_redraw(ar);
927                 break;
928         }
929 }
930
931 /****************** preview region ******************/
932
933 static void clip_preview_area_init(wmWindowManager *wm, ARegion *ar)
934 {
935         wmKeyMap *keymap;
936
937         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
938
939         /* own keymap */
940         keymap = WM_keymap_find(wm->defaultconf, "Clip", SPACE_CLIP, 0);
941         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
942
943         keymap = WM_keymap_find(wm->defaultconf, "Clip Graph Editor", SPACE_CLIP, 0);
944         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
945 }
946
947 static void graph_area_draw(const bContext *C, ARegion *ar)
948 {
949         View2D *v2d = &ar->v2d;
950         View2DScrollers *scrollers;
951         SpaceClip *sc = CTX_wm_space_clip(C);
952         Scene *scene = CTX_data_scene(C);
953         short unitx, unity;
954
955         if (sc->flag & SC_LOCK_TIMECURSOR)
956                 ED_clip_graph_center_current_frame(scene, ar);
957
958         /* clear and setup matrix */
959         UI_ThemeClearColor(TH_BACK);
960         glClear(GL_COLOR_BUFFER_BIT);
961
962         UI_view2d_view_ortho(v2d);
963
964         /* data... */
965         clip_draw_graph(sc, ar, scene);
966
967         /* reset view matrix */
968         UI_view2d_view_restore(C);
969
970         /* scrollers */
971         unitx = (sc->flag & SC_SHOW_SECONDS)? V2D_UNIT_SECONDS : V2D_UNIT_FRAMES;
972         unity = V2D_UNIT_VALUES;
973         scrollers = UI_view2d_scrollers_calc(C, v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP);
974         UI_view2d_scrollers_draw(C, v2d, scrollers);
975         UI_view2d_scrollers_free(scrollers);
976 }
977
978 static void clip_preview_area_draw(const bContext *C, ARegion *ar)
979 {
980         /* SpaceClip *sc = CTX_wm_space_clip(C); */ /* UNUSED */
981
982         graph_area_draw(C, ar);
983 }
984
985 static void clip_preview_area_listener(ARegion *UNUSED(ar), wmNotifier *UNUSED(wmn))
986 {
987 }
988
989 /****************** header region ******************/
990
991 /* add handlers, stuff you only do once or on area/region changes */
992 static void clip_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar)
993 {
994         ED_region_header_init(ar);
995 }
996
997 static void clip_header_area_draw(const bContext *C, ARegion *ar)
998 {
999         ED_region_header(C, ar);
1000 }
1001
1002 /****************** tools region ******************/
1003
1004 /* add handlers, stuff you only do once or on area/region changes */
1005 static void clip_tools_area_init(wmWindowManager *wm, ARegion *ar)
1006 {
1007         ED_region_panels_init(wm, ar);
1008 }
1009
1010 static void clip_tools_area_draw(const bContext *C, ARegion *ar)
1011 {
1012         ED_region_panels(C, ar, 1, NULL, -1);
1013 }
1014
1015 /****************** tool properties region ******************/
1016
1017 static void clip_props_area_listener(ARegion *ar, wmNotifier *wmn)
1018 {
1019         /* context changes */
1020         switch (wmn->category) {
1021                 case NC_WM:
1022                         if (wmn->data == ND_HISTORY)
1023                                 ED_region_tag_redraw(ar);
1024                         break;
1025                 case NC_SCENE:
1026                         if (wmn->data == ND_MODE)
1027                                 ED_region_tag_redraw(ar);
1028                         break;
1029                 case NC_SPACE:
1030                         if (wmn->data == ND_SPACE_CLIP)
1031                                 ED_region_tag_redraw(ar);
1032                         break;
1033                 case NC_SCREEN:
1034                         if (wmn->data == ND_GPENCIL)
1035                                 ED_region_tag_redraw(ar);
1036                         break;
1037         }
1038 }
1039
1040 /****************** properties region ******************/
1041
1042 /* add handlers, stuff you only do once or on area/region changes */
1043 static void clip_properties_area_init(wmWindowManager *wm, ARegion *ar)
1044 {
1045         wmKeyMap *keymap;
1046
1047         ED_region_panels_init(wm, ar);
1048
1049         keymap = WM_keymap_find(wm->defaultconf, "Clip", SPACE_CLIP, 0);
1050         WM_event_add_keymap_handler(&ar->handlers, keymap);
1051 }
1052
1053 static void clip_properties_area_draw(const bContext *C, ARegion *ar)
1054 {
1055         SpaceClip *sc = CTX_wm_space_clip(C);
1056
1057         BKE_movieclip_update_scopes(sc->clip, &sc->user, &sc->scopes);
1058
1059         ED_region_panels(C, ar, 1, NULL, -1);
1060 }
1061
1062 static void clip_properties_area_listener(ARegion *ar, wmNotifier *wmn)
1063 {
1064         /* context changes */
1065         switch (wmn->category) {
1066                 case NC_SCREEN:
1067                         if (wmn->data ==ND_GPENCIL)
1068                                 ED_region_tag_redraw(ar);
1069                         break;
1070                 case NC_BRUSH:
1071                         if (wmn->action ==NA_EDITED)
1072                                 ED_region_tag_redraw(ar);
1073                         break;
1074         }
1075 }
1076
1077 /********************* registration ********************/
1078
1079 /* only called once, from space/spacetypes.c */
1080 void ED_spacetype_clip(void)
1081 {
1082         SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype clip");
1083         ARegionType *art;
1084
1085         st->spaceid = SPACE_CLIP;
1086         strncpy(st->name, "Clip", BKE_ST_MAXNAME);
1087
1088         st->new = clip_new;
1089         st->free = clip_free;
1090         st->init = clip_init;
1091         st->duplicate = clip_duplicate;
1092         st->operatortypes = clip_operatortypes;
1093         st->keymap = clip_keymap;
1094         st->listener = clip_listener;
1095         st->context = clip_context;
1096         st->refresh = clip_refresh;
1097
1098         /* regions: main window */
1099         art = MEM_callocN(sizeof(ARegionType), "spacetype clip region");
1100         art->regionid = RGN_TYPE_WINDOW;
1101         art->init = clip_main_area_init;
1102         art->draw = clip_main_area_draw;
1103         art->listener = clip_main_area_listener;
1104         art->keymapflag = ED_KEYMAP_FRAMES|ED_KEYMAP_UI|ED_KEYMAP_GPENCIL;
1105
1106         BLI_addhead(&st->regiontypes, art);
1107
1108         /* preview */
1109         art = MEM_callocN(sizeof(ARegionType), "spacetype clip region preview");
1110         art->regionid = RGN_TYPE_PREVIEW;
1111         art->prefsizey = 240;
1112         art->init = clip_preview_area_init;
1113         art->draw = clip_preview_area_draw;
1114         art->listener = clip_preview_area_listener;
1115         art->keymapflag = ED_KEYMAP_FRAMES|ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
1116
1117         BLI_addhead(&st->regiontypes, art);
1118
1119         /* regions: properties */
1120         art = MEM_callocN(sizeof(ARegionType), "spacetype clip region properties");
1121         art->regionid = RGN_TYPE_UI;
1122         art->prefsizex = UI_COMPACT_PANEL_WIDTH;
1123         art->keymapflag = ED_KEYMAP_FRAMES|ED_KEYMAP_UI;
1124         art->init = clip_properties_area_init;
1125         art->draw = clip_properties_area_draw;
1126         art->listener = clip_properties_area_listener;
1127         BLI_addhead(&st->regiontypes, art);
1128         ED_clip_buttons_register(art);
1129
1130         /* regions: tools */
1131         art = MEM_callocN(sizeof(ARegionType), "spacetype clip region tools");
1132         art->regionid = RGN_TYPE_TOOLS;
1133         art->prefsizex = UI_COMPACT_PANEL_WIDTH;
1134         art->keymapflag = ED_KEYMAP_FRAMES|ED_KEYMAP_UI;
1135         art->listener = clip_props_area_listener;
1136         art->init = clip_tools_area_init;
1137         art->draw = clip_tools_area_draw;
1138
1139         BLI_addhead(&st->regiontypes, art);
1140
1141         /* tool properties */
1142         art = MEM_callocN(sizeof(ARegionType), "spacetype clip tool properties region");
1143         art->regionid = RGN_TYPE_TOOL_PROPS;
1144         art->prefsizex = 0;
1145         art->prefsizey = 120;
1146         art->keymapflag = ED_KEYMAP_FRAMES|ED_KEYMAP_UI;
1147         art->listener = clip_props_area_listener;
1148         art->init = clip_tools_area_init;
1149         art->draw = clip_tools_area_draw;
1150         ED_clip_tool_props_register(art);
1151
1152         BLI_addhead(&st->regiontypes, art);
1153
1154         /* regions: header */
1155         art = MEM_callocN(sizeof(ARegionType), "spacetype clip region");
1156         art->regionid = RGN_TYPE_HEADER;
1157         art->prefsizey = HEADERY;
1158         art->keymapflag = ED_KEYMAP_FRAMES|ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_HEADER;
1159
1160         art->init = clip_header_area_init;
1161         art->draw = clip_header_area_draw;
1162
1163         BLI_addhead(&st->regiontypes, art);
1164
1165         BKE_spacetype_register(st);
1166 }