aff87a2c34174d9901b27ab15d2a12ec5861a624
[blender-staging.git] / source / blender / editors / space_action / action_header.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <string.h>
30 #include <stdio.h>
31
32 #include "DNA_anim_types.h"
33 #include "DNA_action_types.h"
34 #include "DNA_key_types.h"
35 #include "DNA_object_types.h"
36 #include "DNA_space_types.h"
37 #include "DNA_scene_types.h"
38 #include "DNA_screen_types.h"
39 #include "DNA_windowmanager_types.h"
40
41 #include "MEM_guardedalloc.h"
42
43 #include "BLI_blenlib.h"
44
45 #include "BKE_context.h"
46 #include "BKE_screen.h"
47
48 #include "ED_anim_api.h"
49 #include "ED_screen.h"
50 #include "ED_types.h"
51 #include "ED_util.h"
52
53 #include "WM_api.h"
54 #include "WM_types.h"
55
56 #include "BIF_gl.h"
57 #include "BIF_glutil.h"
58
59 #include "UI_interface.h"
60 #include "UI_resources.h"
61 #include "UI_view2d.h"
62
63 #include "action_intern.h"
64
65 /* ********************************************************* */
66 /* Menu Defines... */
67
68 /* button events */
69 enum {
70         B_REDR  = 0,
71         B_ACTCOPYKEYS,
72         B_ACTPASTEKEYS,
73 } eActHeader_ButEvents;
74
75 /* ------------------------------- */
76 /* enums declaring constants that are used as menu event codes  */
77
78 enum {
79         ACTMENU_VIEW_CENTERVIEW= 0,
80         ACTMENU_VIEW_AUTOUPDATE,
81         ACTMENU_VIEW_PLAY3D,
82         ACTMENU_VIEW_PLAYALL,
83         ACTMENU_VIEW_ALL,
84         ACTMENU_VIEW_MAXIMIZE,
85         ACTMENU_VIEW_LOCK,
86         ACTMENU_VIEW_SLIDERS,
87         ACTMENU_VIEW_NEXTMARKER,
88         ACTMENU_VIEW_PREVMARKER,
89         ACTMENU_VIEW_NEXTKEYFRAME,
90         ACTMENU_VIEW_PREVKEYFRAME,
91         ACTMENU_VIEW_TIME,
92         ACTMENU_VIEW_NOHIDE,
93         ACTMENU_VIEW_FRANUM,
94         ACTMENU_VIEW_TRANSDELDUPS,
95         ACTMENU_VIEW_HORIZOPTIMISE,
96         ACTMENU_VIEW_GCOLORS,
97         ACTMENU_VIEW_PREVRANGESET,
98         ACTMENU_VIEW_PREVRANGECLEAR,
99         ACTMENU_VIEW_PREVRANGEAUTO
100 };
101
102 enum {
103         ACTMENU_SEL_BORDER = 0,
104         ACTMENU_SEL_BORDERC,
105         ACTMENU_SEL_BORDERM,
106         ACTMENU_SEL_ALL_KEYS,
107         ACTMENU_SEL_ALL_CHAN,
108         ACTMENU_SEL_ALL_MARKERS,
109         ACTMENU_SEL_INVERSE_KEYS,
110         ACTMENU_SEL_INVERSE_MARKERS,
111         ACTMENU_SEL_INVERSE_CHANNELS,
112         ACTMENU_SEL_LEFTKEYS,
113         ACTMENU_SEL_RIGHTKEYS
114 };
115
116 enum {
117         ACTMENU_SEL_COLUMN_KEYS = 1,
118         ACTMENU_SEL_COLUMN_CFRA,
119         ACTMENU_SEL_COLUMN_MARKERSCOLUMN,
120         ACTMENU_SEL_COLUMN_MARKERSBETWEEN 
121 };
122
123 enum {
124         ACTMENU_CHANNELS_OPENLEVELS = 0,
125         ACTMENU_CHANNELS_CLOSELEVELS,
126         ACTMENU_CHANNELS_EXPANDALL,
127         ACTMENU_CHANNELS_SHOWACHANS,
128         ACTMENU_CHANNELS_DELETE
129 };
130
131 enum {
132         ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_UP        = 0,
133         ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_DOWN,
134         ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_TOP,
135         ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_BOTTOM
136 };
137
138 enum {
139         ACTMENU_CHANNELS_GROUP_ADD_TOACTIVE     = 0,
140         ACTMENU_CHANNELS_GROUP_ADD_TONEW,
141         ACTMENU_CHANNELS_GROUP_REMOVE,
142         ACTMENU_CHANNELS_GROUP_SYNCPOSE
143 };
144
145 enum {
146         ACTMENU_CHANNELS_SETTINGS_TOGGLE = 0,
147         ACTMENU_CHANNELS_SETTINGS_ENABLE,
148         ACTMENU_CHANNELS_SETTINGS_DISABLE,
149 };
150
151 enum {
152         ACTMENU_KEY_DUPLICATE = 0,
153         ACTMENU_KEY_DELETE,
154         ACTMENU_KEY_CLEAN,
155         ACTMENU_KEY_SAMPLEKEYS,
156         ACTMENU_KEY_INSERTKEY
157 };
158
159 enum {
160         ACTMENU_KEY_TRANSFORM_MOVE  = 0,
161         ACTMENU_KEY_TRANSFORM_SCALE,
162         ACTMENU_KEY_TRANSFORM_SLIDE,
163         ACTMENU_KEY_TRANSFORM_EXTEND
164 };
165
166 enum {
167         ACTMENU_KEY_HANDLE_AUTO = 0,
168         ACTMENU_KEY_HANDLE_ALIGN,
169         ACTMENU_KEY_HANDLE_FREE,
170         ACTMENU_KEY_HANDLE_VECTOR
171 };
172
173 enum {
174         ACTMENU_KEY_INTERP_CONST = 0,
175         ACTMENU_KEY_INTERP_LINEAR,
176         ACTMENU_KEY_INTERP_BEZIER
177 };
178
179 enum {
180         ACTMENU_KEY_EXTEND_CONST = 0,
181         ACTMENU_KEY_EXTEND_EXTRAPOLATION,
182         ACTMENU_KEY_EXTEND_CYCLIC,
183         ACTMENU_KEY_EXTEND_CYCLICEXTRAPOLATION
184 };
185
186 enum {
187         ACTMENU_KEY_SNAP_NEARFRAME = 1,
188         ACTMENU_KEY_SNAP_CURFRAME,
189         ACTMENU_KEY_SNAP_NEARMARK,
190         ACTMENU_KEY_SNAP_NEARTIME,
191         ACTMENU_KEY_SNAP_CFRA2KEY,
192 };
193
194 enum {
195         ACTMENU_KEY_MIRROR_CURFRAME = 1,
196         ACTMENU_KEY_MIRROR_YAXIS,
197         ACTMENU_KEY_MIRROR_XAXIS,
198         ACTMENU_KEY_MIRROR_MARKER
199 };
200
201 enum {
202         ACTMENU_MARKERS_ADD = 0,
203         ACTMENU_MARKERS_DUPLICATE,
204         ACTMENU_MARKERS_DELETE,
205         ACTMENU_MARKERS_NAME,
206         ACTMENU_MARKERS_MOVE,
207         ACTMENU_MARKERS_LOCALADD,
208         ACTMENU_MARKERS_LOCALRENAME,
209         ACTMENU_MARKERS_LOCALDELETE,
210         ACTMENU_MARKERS_LOCALMOVE
211 };
212
213 /* ------------------------------- */
214 /* macros for easier state testing (only for use here) */
215
216 /* test if active action editor is showing any markers */
217 #if 0
218         #define SACTION_HASMARKERS \
219                 ((saction->action && saction->action->markers.first) \
220                  || (scene->markers.first))
221 #endif
222
223 /* need to find out how to get scene from context */
224 #define SACTION_HASMARKERS (saction->action && saction->action->markers.first)
225
226 /* ------------------------------- */
227
228 /* *************************************************************** */
229 /* menus */
230
231 /* Key menu ---------------------------  */
232
233 static void do_keymenu_transformmenu(bContext *C, void *arg, int event)
234 {
235         switch (event)
236         {
237                 case ACTMENU_KEY_TRANSFORM_MOVE:
238                         //transform_action_keys('g', 0);
239                         break;
240                 case ACTMENU_KEY_TRANSFORM_SCALE:
241                         //transform_action_keys('s', 0);
242                         break;
243                 case ACTMENU_KEY_TRANSFORM_SLIDE:
244                         //transform_action_keys('t', 0);
245                         break;
246                 case ACTMENU_KEY_TRANSFORM_EXTEND:
247                         //transform_action_keys('e', 0);
248                         break;
249         }
250 }
251
252 static uiBlock *action_keymenu_transformmenu(bContext *C, ARegion *ar, void *arg_unused)
253 {
254         uiBlock *block;
255         short yco= 0, menuwidth=120;
256         
257         block= uiBeginBlock(C, ar, "action_keymenu_transformmenu", UI_EMBOSSP, UI_HELV);
258         uiBlockSetButmFunc(block, do_keymenu_transformmenu, NULL);
259
260         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
261                                          "Grab/Move|G", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0,  
262                                          ACTMENU_KEY_TRANSFORM_MOVE, "");
263         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
264                                          "Grab/Extend from Frame|E", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 
265                                          ACTMENU_KEY_TRANSFORM_EXTEND, "");
266         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
267                                          "Scale|S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 
268                                          ACTMENU_KEY_TRANSFORM_SCALE, "");
269         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
270                                          "Time Slide|T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 
271                                          ACTMENU_KEY_TRANSFORM_SLIDE, "");
272         
273         uiBlockSetDirection(block, UI_RIGHT);
274         
275         uiTextBoundsBlock(block, 60);
276         uiEndBlock(C, block);
277         
278         return block;
279 }
280
281 static void do_keymenu_snapmenu(bContext *C, void *arg, int event)
282 {
283         switch(event)
284         {
285                 case ACTMENU_KEY_SNAP_NEARFRAME:
286                 case ACTMENU_KEY_SNAP_CURFRAME:
287                 case ACTMENU_KEY_SNAP_NEARMARK:
288                 case ACTMENU_KEY_SNAP_NEARTIME:
289                         //snap_action_keys(event);
290                         break;
291                         
292                 case ACTMENU_KEY_SNAP_CFRA2KEY:
293                         //snap_cfra_action();
294                         break;
295         }
296 }
297
298 static uiBlock *action_keymenu_snapmenu(bContext *C, ARegion *ar, void *arg_unused)
299 {
300         SpaceAction *saction= (SpaceAction*)CTX_wm_space_data(C);
301         uiBlock *block;
302         short yco= 0, menuwidth=120;
303
304         
305         block= uiBeginBlock(C, ar, "action_keymenu_snapmenu", UI_EMBOSSP, UI_HELV);
306         uiBlockSetButmFunc(block, do_keymenu_snapmenu, NULL);
307
308         if (saction->flag & SACTION_DRAWTIME) {
309                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
310                                                  "Key -> Nearest Second|Shift S, 1", 0, yco-=20, 
311                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
312                                                  ACTMENU_KEY_SNAP_NEARTIME, "");
313                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
314                                                  "Key -> Current Time|Shift S, 2", 0, yco-=20, 
315                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
316                                                  ACTMENU_KEY_SNAP_CURFRAME, "");
317
318         }
319         else {
320                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
321                                                  "Key -> Nearest Frame|Shift S, 1", 0, yco-=20, 
322                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
323                                                  ACTMENU_KEY_SNAP_NEARFRAME, "");
324                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
325                                                  "Key -> Current Frame|Shift S, 2", 0, yco-=20, 
326                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
327                                                  ACTMENU_KEY_SNAP_CURFRAME, "");
328         }
329         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
330                                          "Key -> Nearest Marker|Shift S, 3", 0, yco-=20, 
331                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
332                                          ACTMENU_KEY_SNAP_NEARMARK, "");
333                                          
334         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
335                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
336                          
337         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
338                                          "Current Frame -> Key|Ctrl Shift S", 0, yco-=20, 
339                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
340                                          ACTMENU_KEY_SNAP_NEARMARK, "");
341         
342         uiBlockSetDirection(block, UI_RIGHT);
343         
344         uiTextBoundsBlock(block, 60);
345         uiEndBlock(C, block);
346         
347         return block;
348 }
349
350 static void do_keymenu_mirrormenu(bContext *C, void *arg, int event)
351 {
352         switch(event)
353         {
354                 case ACTMENU_KEY_MIRROR_CURFRAME:
355                 case ACTMENU_KEY_MIRROR_YAXIS:
356                         //mirror_action_keys(event);
357                         break;
358         }
359
360 }
361
362 static uiBlock *action_keymenu_mirrormenu(bContext *C, ARegion *ar, void *arg_unused)
363 {
364         uiBlock *block;
365         short yco= 0, menuwidth=120;
366         
367         block= uiBeginBlock(C, ar, "action_keymenu_mirrormenu", UI_EMBOSSP, UI_HELV);
368         uiBlockSetButmFunc(block, do_keymenu_mirrormenu, NULL);
369
370         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
371                                          "Current Frame|Shift M, 1", 0, yco-=20, 
372                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
373                                          ACTMENU_KEY_MIRROR_CURFRAME, "");
374         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
375                                          "Vertical Axis|Shift M, 2", 0, yco-=20, 
376                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
377                                          ACTMENU_KEY_MIRROR_YAXIS, "");
378         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
379                                          "Horizontal Axis|Shift M, 3", 0, yco-=20, 
380                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
381                                          ACTMENU_KEY_MIRROR_XAXIS, "");
382         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
383                                          "Selected Marker|Shift M, 4", 0, yco-=20, 
384                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
385                                          ACTMENU_KEY_MIRROR_MARKER, "");
386         
387         uiBlockSetDirection(block, UI_RIGHT);
388         
389         uiTextBoundsBlock(block, 60);
390         uiEndBlock(C, block);
391         
392         return block;
393 }
394
395 static void do_keymenu_handlemenu(bContext *C, void *arg, int event)
396 {
397         switch (event) {
398                 case ACTMENU_KEY_HANDLE_AUTO:
399                         //sethandles_action_keys(HD_AUTO);
400                         break;
401
402                 case ACTMENU_KEY_HANDLE_ALIGN:
403                 case ACTMENU_KEY_HANDLE_FREE:
404                         /* OK, this is kinda dumb, need to fix the
405                          * toggle crap in sethandles_ipo_keys() 
406                          */
407                         //sethandles_action_keys(HD_ALIGN);
408                         break;
409
410                 case ACTMENU_KEY_HANDLE_VECTOR:
411                         //sethandles_action_keys(HD_VECT);      
412                         break;
413         }
414 }
415
416 static uiBlock *action_keymenu_handlemenu(bContext *C, ARegion *ar, void *arg_unused)
417 {
418         uiBlock *block;
419         short yco= 0, menuwidth=120;
420         
421         block= uiBeginBlock(C, ar, "action_keymenu_handlemenu", UI_EMBOSSP, UI_HELV);
422         uiBlockSetButmFunc(block, do_keymenu_handlemenu, NULL);
423
424         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
425                                          "Auto|Shift H", 0, yco-=20, 
426                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
427                                          ACTMENU_KEY_HANDLE_AUTO, "");
428         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
429                                          "Aligned|H", 0, yco-=20, 
430                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
431                                          ACTMENU_KEY_HANDLE_ALIGN, "");
432         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
433                                          "Free|H", 0, yco-=20, menuwidth, 
434                                          19, NULL, 0.0, 0.0, 0, 
435                                          ACTMENU_KEY_HANDLE_FREE, "");
436         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
437                                          "Vector|V", 0, yco-=20, 
438                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
439                                          ACTMENU_KEY_HANDLE_VECTOR, "");
440         
441         uiBlockSetDirection(block, UI_RIGHT);
442         
443         uiTextBoundsBlock(block, 60);
444         uiEndBlock(C, block);
445         
446         return block;
447 }
448
449 static void do_keymenu_extendmenu(bContext *C, void *arg, int event)
450 {
451         switch(event)
452         {
453                 case ACTMENU_KEY_EXTEND_CONST:
454                         //action_set_ipo_flags(SET_EXTEND_MENU, SET_EXTEND_CONSTANT);
455                         break;
456                 case ACTMENU_KEY_EXTEND_EXTRAPOLATION:
457                         //action_set_ipo_flags(SET_EXTEND_MENU, SET_EXTEND_EXTRAPOLATION);
458                         break;
459                 case ACTMENU_KEY_EXTEND_CYCLIC:
460                         //action_set_ipo_flags(SET_EXTEND_MENU, SET_EXTEND_CYCLIC);
461                         break;
462                 case ACTMENU_KEY_EXTEND_CYCLICEXTRAPOLATION:
463                         //action_set_ipo_flags(SET_EXTEND_MENU, SET_EXTEND_CYCLICEXTRAPOLATION);
464                         break;
465         }
466 }
467
468 static uiBlock *action_keymenu_extendmenu(bContext *C, ARegion *ar, void *arg_unused)
469 {
470         uiBlock *block;
471         short yco= 0, menuwidth=120;
472         
473         block= uiBeginBlock(C, ar, "action_keymenu_extendmenu", UI_EMBOSSP, UI_HELV);
474         uiBlockSetButmFunc(block, do_keymenu_extendmenu, NULL);
475         
476         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
477                                          "Constant", 0, yco-=20, 
478                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
479                                          ACTMENU_KEY_EXTEND_CONST, "");
480         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
481                                          "Extrapolation", 0, yco-=20, 
482                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
483                                          ACTMENU_KEY_EXTEND_EXTRAPOLATION, "");
484         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
485                                          "Cyclic", 0, yco-=20, 
486                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
487                                          ACTMENU_KEY_EXTEND_CYCLIC, "");
488         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
489                                          "Cyclic Extrapolation", 0, yco-=20, 
490                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
491                                          ACTMENU_KEY_EXTEND_CYCLICEXTRAPOLATION, "");
492         
493         uiBlockSetDirection(block, UI_RIGHT);
494         
495         uiTextBoundsBlock(block, 60);
496         uiEndBlock(C, block);
497         
498         return block;
499 }
500
501 static void do_keymenu_intpolmenu(bContext *C, void *arg, int event)
502 {
503         switch(event)
504         {
505                 case ACTMENU_KEY_INTERP_CONST:
506                         //action_set_ipo_flags(SET_IPO_MENU, SET_IPO_CONSTANT);
507                         break;
508                 case ACTMENU_KEY_INTERP_LINEAR:
509                         //action_set_ipo_flags(SET_IPO_MENU, SET_IPO_LINEAR);
510                         break;
511                 case ACTMENU_KEY_INTERP_BEZIER:
512                         //action_set_ipo_flags(SET_IPO_MENU, SET_IPO_BEZIER);
513                         break;
514         }
515 }
516
517 static uiBlock *action_keymenu_intpolmenu(bContext *C, ARegion *ar, void *arg_unused)
518 {
519         uiBlock *block;
520         short yco= 0, menuwidth=120;
521         
522         block= uiBeginBlock(C, ar, "action_keymenu_intpolmenu", UI_EMBOSSP, UI_HELV);
523         uiBlockSetButmFunc(block, do_keymenu_intpolmenu, NULL);
524         
525         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
526                                          "Constant|Shift T, 1", 0, yco-=20, 
527                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
528                                          ACTMENU_KEY_INTERP_CONST, "");
529         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
530                                          "Linear|Shift T, 2", 0, yco-=20, 
531                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
532                                          ACTMENU_KEY_INTERP_LINEAR, "");
533         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
534                                          "Bezier|Shift T, 3", 0, yco-=20, 
535                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
536                                          ACTMENU_KEY_INTERP_BEZIER, "");
537         
538         uiBlockSetDirection(block, UI_RIGHT);
539         
540         uiTextBoundsBlock(block, 60);
541         uiEndBlock(C, block);
542         
543         return block;
544 }
545
546 static void do_action_keymenu(bContext *C, void *arg, int event)
547 {
548         SpaceAction *saction= (SpaceAction*)CTX_wm_space_data(C);
549         bAction *act;
550         //Key *key;
551         
552         if (!saction) return;
553
554         act = saction->action;
555         //key = get_action_mesh_key();
556
557         switch(event)
558         {
559                 case ACTMENU_KEY_DUPLICATE:
560                         //duplicate_action_keys();
561                         break;
562                 case ACTMENU_KEY_DELETE:
563                         //delete_action_keys();
564                         break;
565                 case ACTMENU_KEY_CLEAN:
566                         //clean_action();
567                         break;
568                 case ACTMENU_KEY_SAMPLEKEYS:
569                         //sample_action_keys();
570                         break;
571                 case ACTMENU_KEY_INSERTKEY:
572                         //insertkey_action();
573                         break;
574         }
575 }
576
577 static uiBlock *action_keymenu(bContext *C, ARegion *ar, void *arg_unused)
578 {
579         ScrArea *curarea= CTX_wm_area(C);
580         uiBlock *block;
581         short yco= 0, menuwidth=120;
582         
583         block= uiBeginBlock(C, ar, "action_keymenu", UI_EMBOSSP, UI_HELV);
584
585
586         uiBlockSetButmFunc(block, do_action_keymenu, NULL);
587         
588         uiDefIconTextBlockBut(block, action_keymenu_transformmenu, 
589                                                   NULL, ICON_RIGHTARROW_THIN, "Transform", 0, yco-=20, 120, 20, "");
590         
591         uiDefIconTextBlockBut(block, action_keymenu_snapmenu, 
592                                                   NULL, ICON_RIGHTARROW_THIN, "Snap", 0, yco-=20, 120, 20, "");
593         
594         uiDefIconTextBlockBut(block, action_keymenu_mirrormenu, 
595                                                   NULL, ICON_RIGHTARROW_THIN, "Mirror", 0, yco-=20, 120, 20, "");
596         
597         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
598                                         menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
599         
600         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
601                                         "Insert Key|I", 0, yco-=20, 
602                                         menuwidth, 19, NULL, 0.0, 0.0, 0, 
603                                         ACTMENU_KEY_INSERTKEY, "");
604
605         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
606                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
607                                         
608         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
609                                         "Duplicate|Shift D", 0, yco-=20, 
610                                         menuwidth, 19, NULL, 0.0, 0.0, 0, 
611                                         ACTMENU_KEY_DUPLICATE, "");
612         
613         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
614                                         "Delete|X", 0, yco-=20, 
615                                         menuwidth, 19, NULL, 0.0, 0.0, 0, 
616                                         ACTMENU_KEY_DELETE, "");
617
618         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
619                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
620
621         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
622                                          "Clean Action|O", 0, yco-=20, 
623                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
624                                          ACTMENU_KEY_CLEAN, "");
625                                          
626         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
627                                          "Sample Keys|Alt O", 0, yco-=20, 
628                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
629                                          ACTMENU_KEY_SAMPLEKEYS, "");
630
631         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
632                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
633
634         uiDefIconTextBlockBut(block, action_keymenu_handlemenu, 
635                                                   NULL, ICON_RIGHTARROW_THIN, 
636                                                   "Handle Type", 0, yco-=20, 120, 20, "");
637         
638         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
639                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
640
641         uiDefIconTextBlockBut(block, action_keymenu_extendmenu, 
642                                                   NULL, ICON_RIGHTARROW_THIN, 
643                                                   "Extend Mode", 0, yco-=20, 120, 20, "");
644         uiDefIconTextBlockBut(block, action_keymenu_intpolmenu, 
645                                                   NULL, ICON_RIGHTARROW_THIN, 
646                                                   "Interpolation Mode", 0, yco-=20, 120, 20, "");
647         
648         if(curarea->headertype==HEADERTOP) {
649                 uiBlockSetDirection(block, UI_DOWN);
650         }
651         else {
652                 uiBlockSetDirection(block, UI_TOP);
653                 uiBlockFlipOrder(block);
654         }
655         
656         uiTextBoundsBlock(block, 50);
657         uiEndBlock(C, block);
658         
659         return block;
660 }
661
662 /* Frame menu ---------------------------  */
663
664
665 // framemenu uses functions from keymenu
666 static uiBlock *action_framemenu(bContext *C, ARegion *ar, void *arg_unused)
667 {
668         ScrArea *curarea= CTX_wm_area(C);
669         uiBlock *block;
670         short yco= 0, menuwidth=120;
671         
672         block= uiBeginBlock(C, ar, "action_framemenu", UI_EMBOSSP, UI_HELV);
673         uiBlockSetButmFunc(block, do_action_keymenu, NULL);
674         
675         uiDefIconTextBlockBut(block, action_keymenu_transformmenu, 
676                                                   NULL, ICON_RIGHTARROW_THIN, "Transform", 0, yco-=20, 120, 20, "");
677         
678         uiDefIconTextBlockBut(block, action_keymenu_snapmenu, 
679                                                   NULL, ICON_RIGHTARROW_THIN, "Snap", 0, yco-=20, 120, 20, "");
680         
681         uiDefIconTextBlockBut(block, action_keymenu_mirrormenu, 
682                                                   NULL, ICON_RIGHTARROW_THIN, "Mirror", 0, yco-=20, 120, 20, "");
683         
684         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
685                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
686                                         
687         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
688                                         "Duplicate|Shift D", 0, yco-=20, 
689                                         menuwidth, 19, NULL, 0.0, 0.0, 0, 
690                                         ACTMENU_KEY_DUPLICATE, "");
691         
692         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
693                                         "Delete|X", 0, yco-=20, 
694                                         menuwidth, 19, NULL, 0.0, 0.0, 0, 
695                                         ACTMENU_KEY_DELETE, "");
696         
697         if(curarea->headertype==HEADERTOP) {
698                 uiBlockSetDirection(block, UI_DOWN);
699         }
700         else {
701                 uiBlockSetDirection(block, UI_TOP);
702                 uiBlockFlipOrder(block);
703         }
704         
705         uiTextBoundsBlock(block, 50);
706         uiEndBlock(C, block);
707         
708         return block;
709 }
710
711 /* Marker menu ---------------------------  */
712
713 static void do_markermenu(bContext *C, void *arg, int event)
714 {
715         switch(event)
716         {
717                 case ACTMENU_MARKERS_ADD:
718                         //add_marker(CFRA);
719                         break;
720                 case ACTMENU_MARKERS_DUPLICATE:
721                         //duplicate_marker();
722                         break;
723                 case ACTMENU_MARKERS_DELETE:
724                         //remove_marker();
725                         break;
726                 case ACTMENU_MARKERS_NAME:
727                         //rename_marker();
728                         break;
729                 case ACTMENU_MARKERS_MOVE:
730                         //transform_markers('g', 0);
731                         break;
732                 case ACTMENU_MARKERS_LOCALADD:
733                         //action_add_localmarker(G.saction->action, CFRA);
734                         break;
735                 case ACTMENU_MARKERS_LOCALDELETE:
736                         //action_remove_localmarkers(G.saction->action);
737                         break;
738                 case ACTMENU_MARKERS_LOCALRENAME:
739                         //action_rename_localmarker(G.saction->action);
740                         break;
741                 case ACTMENU_MARKERS_LOCALMOVE:
742                         /*G.saction->flag |= SACTION_POSEMARKERS_MOVE;
743                         transform_markers('g', 0);
744                         G.saction->flag &= ~SACTION_POSEMARKERS_MOVE;*/
745                         break;
746         }
747 }
748
749 static uiBlock *action_markermenu(bContext *C, ARegion *ar, void *arg_unused)
750 {
751         SpaceAction *saction= (SpaceAction*)CTX_wm_space_data(C);
752         ScrArea *curarea= CTX_wm_area(C);
753         uiBlock *block;
754         short yco= 0, menuwidth=120;
755         
756         block= uiBeginBlock(C, ar, "action_markermenu", UI_EMBOSSP, UI_HELV);
757         uiBlockSetButmFunc(block, do_markermenu, NULL);
758         
759         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Add Marker|M", 0, yco-=20, 
760                                          menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_ADD, "");
761         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Duplicate Marker|Ctrl Shift D", 0, yco-=20, 
762                                          menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_DUPLICATE, "");
763         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Delete Marker|Shift X", 0, yco-=20,
764                                          menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_DELETE, "");
765                                         
766         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
767                                         
768         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "(Re)Name Marker|Ctrl M", 0, yco-=20,
769                                          menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_NAME, "");
770         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grab/Move Marker|Ctrl G", 0, yco-=20,
771                                          menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_MOVE, "");
772                 
773         if (saction->mode == SACTCONT_ACTION) {
774                 uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
775                 
776                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Add Pose Marker|Shift L", 0, yco-=20, 
777                                                  menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_LOCALADD, "");
778                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Rename Pose Marker|Ctrl Shift L", 0, yco-=20, 
779                                                  menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_LOCALRENAME, "");
780                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Delete Pose Marker|Alt L", 0, yco-=20,
781                                                  menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_LOCALDELETE, "");
782                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grab/Move Pose Marker|Ctrl L", 0, yco-=20, 
783                                                  menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_LOCALMOVE, "");
784         }
785         
786         if(curarea->headertype==HEADERTOP) {
787                 uiBlockSetDirection(block, UI_DOWN);
788         }
789         else {
790                 uiBlockSetDirection(block, UI_TOP);
791                 uiBlockFlipOrder(block);
792         }
793         
794         uiTextBoundsBlock(block, 50);
795         uiEndBlock(C, block);
796         
797         return block;
798 }
799
800
801 /* Channel menu ---------------------------  */
802
803 static void do_channelmenu_posmenu(bContext *C, void *arg, int event)
804 {
805         switch(event)
806         {
807                 case ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_DOWN:
808                         //rearrange_action_channels(REARRANGE_ACTCHAN_DOWN);
809                         break;
810                 case ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_UP:
811                         //rearrange_action_channels(REARRANGE_ACTCHAN_UP);
812                         break;
813                 case ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_TOP:
814                         //rearrange_action_channels(REARRANGE_ACTCHAN_TOP);
815                         break;
816                 case ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_BOTTOM:
817                         //rearrange_action_channels(REARRANGE_ACTCHAN_BOTTOM);
818                         break;
819         }
820 }
821
822 static uiBlock *action_channelmenu_posmenu(bContext *C, ARegion *ar, void *arg_unused)
823 {
824         uiBlock *block;
825         short yco= 0, menuwidth=120;
826
827         block= uiBeginBlock(C, ar, "action_channelmenu_posmenu", UI_EMBOSSP, UI_HELV);
828         uiBlockSetButmFunc(block, do_channelmenu_posmenu, NULL);
829
830         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
831                                          "Move Up|Shift Page Up", 0, yco-=20, 
832                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
833                                          ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_UP, "");
834         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
835                                          "Move Down|Shift Page Down", 0, yco-=20, 
836                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
837                                          ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_DOWN, "");
838         
839         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
840                                         menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
841                                         
842         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
843                                          "Move to Top|Ctrl Shift Page Up", 0, yco-=20, 
844                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
845                                          ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_TOP, "");
846         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
847                                          "Move to Bottom|Ctrl Shift Page Down", 0, yco-=20, 
848                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
849                                          ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_BOTTOM, "");
850
851         uiBlockSetDirection(block, UI_RIGHT);
852         uiTextBoundsBlock(block, 60);
853
854         return block;
855 }
856
857 static void do_channelmenu_groupmenu(bContext *C, void *arg, int event)
858 {
859         switch(event)
860         {
861                 case ACTMENU_CHANNELS_GROUP_ADD_TOACTIVE:
862                         //action_groups_group(0);
863                         break;
864                 case ACTMENU_CHANNELS_GROUP_ADD_TONEW:
865                         //action_groups_group(1);
866                         break;
867                 case ACTMENU_CHANNELS_GROUP_REMOVE:
868                         //action_groups_ungroup();
869                         break;
870                 case ACTMENU_CHANNELS_GROUP_SYNCPOSE: /* Syncronise Pose-data and Action-data */
871                         //sync_pchan2achan_grouping();
872                         break;
873         }
874 }
875
876 static uiBlock *action_channelmenu_groupmenu(bContext *C, ARegion *ar, void *arg_unused)
877 {
878         uiBlock *block;
879         short yco= 0, menuwidth=120;
880
881         block= uiBeginBlock(C, ar, "action_channelmenu_groupmenu", UI_EMBOSSP, UI_HELV);
882         uiBlockSetButmFunc(block, do_channelmenu_groupmenu, NULL);
883
884         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
885                                          "Add to Active Group|Shift G", 0, yco-=20, 
886                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
887                                          ACTMENU_CHANNELS_GROUP_ADD_TOACTIVE, "");
888         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
889                                          "Add to New Group|Ctrl Shift G", 0, yco-=20, 
890                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
891                                          ACTMENU_CHANNELS_GROUP_ADD_TONEW, "");
892                 
893         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
894                                         menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
895                                         
896         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
897                                          "Remove From Group|Alt G", 0, yco-=20, 
898                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
899                                          ACTMENU_CHANNELS_GROUP_REMOVE, "");
900                                          
901         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
902                                         menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
903                                         
904         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
905                                          "Synchronise with Armature", 0, yco-=20, 
906                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
907                                          ACTMENU_CHANNELS_GROUP_SYNCPOSE, "");
908
909         uiBlockSetDirection(block, UI_RIGHT);
910         uiTextBoundsBlock(block, 60);
911
912         return block;
913 }
914
915 static void do_channelmenu_settingsmenu(bContext *C, void *arg, int event)
916 {
917         //setflag_action_channels(event);
918 }
919
920 static uiBlock *action_channelmenu_settingsmenu(bContext *C, ARegion *ar, void *arg_unused)
921 {
922         uiBlock *block;
923         short yco= 0, menuwidth=120;
924
925         block= uiBeginBlock(C, ar, "action_channelmenu_settingsmenu", UI_EMBOSSP, UI_HELV);
926         uiBlockSetButmFunc(block, do_channelmenu_settingsmenu, NULL);
927
928         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
929                                          "Toggle a Setting|Shift W", 0, yco-=20, 
930                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
931                                          ACTMENU_CHANNELS_SETTINGS_TOGGLE, "");
932                                          
933         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
934                                          "Enable a Setting|Ctrl Shift W", 0, yco-=20, 
935                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
936                                          ACTMENU_CHANNELS_SETTINGS_ENABLE, "");
937                                         
938         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
939                                          "Disable a Setting|Alt W", 0, yco-=20, 
940                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
941                                          ACTMENU_CHANNELS_SETTINGS_DISABLE, "");
942
943         uiBlockSetDirection(block, UI_RIGHT);
944         uiTextBoundsBlock(block, 60);
945
946         return block;
947 }
948
949 static void do_channelmenu(bContext *C, void *arg, int event)
950 {
951         SpaceAction *saction= (SpaceAction*)CTX_wm_space_data(C);
952         
953         if (saction == NULL) return;
954         
955         switch(event)
956         {
957                 case ACTMENU_CHANNELS_OPENLEVELS: /* Unfold selected channels one step */
958                         //openclose_level_action(1);
959                         break;
960                 case ACTMENU_CHANNELS_CLOSELEVELS: /* Fold selected channels one step */
961                         //openclose_level_action(-1);
962                         break;
963                 case ACTMENU_CHANNELS_EXPANDALL: /* Expands all channels */
964                         //expand_all_action();
965                         break;
966                 case ACTMENU_CHANNELS_SHOWACHANS: /* Unfold groups that are hiding selected achans */
967                         //expand_obscuregroups_action();
968                         break;
969                 case ACTMENU_CHANNELS_DELETE: /* Deletes selected channels */
970                         //delete_action_channels();
971                         break;
972         }
973 }
974
975 static uiBlock *action_channelmenu(bContext *C, ARegion *ar, void *arg_unused)
976 {
977         ScrArea *curarea= CTX_wm_area(C);
978         uiBlock *block;
979         short yco= 0, menuwidth=120;
980         
981         block= uiBeginBlock(C, ar, "action_channelmenu", UI_EMBOSSP, UI_HELV);
982         uiBlockSetButmFunc(block, do_channelmenu, NULL);
983                 
984         uiDefIconTextBlockBut(block, action_channelmenu_groupmenu, 
985                                                   NULL, ICON_RIGHTARROW_THIN, 
986                                                   "Grouping", 0, yco-=20, 120, 20, "");  
987                                                   
988         uiDefIconTextBlockBut(block, action_channelmenu_posmenu, 
989                                                   NULL, ICON_RIGHTARROW_THIN, 
990                                                   "Ordering", 0, yco-=20, 120, 20, "");
991         
992         uiDefIconTextBlockBut(block, action_channelmenu_settingsmenu, 
993                                                   NULL, ICON_RIGHTARROW_THIN, 
994                                                   "Settings", 0, yco-=20, 120, 20, ""); 
995         
996         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
997                                         menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
998         
999         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1000                         "Delete|X", 0, yco-=20,
1001                         menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_CHANNELS_DELETE, "");
1002         
1003         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1004                                         menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1005                 
1006         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1007                         "Toggle Show Hierachy|~", 0, yco-=20,
1008                         menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_CHANNELS_EXPANDALL, "");
1009                         
1010         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1011                         "Show Group-Hidden Channels|Shift ~", 0, yco-=20,
1012                         menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_CHANNELS_SHOWACHANS, "");
1013                         
1014         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1015                         "Expand One Level|Ctrl NumPad+", 0, yco-=20,
1016                         menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_CHANNELS_OPENLEVELS, "");
1017                         
1018         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1019                         "Collapse One Level|Ctrl NumPad-", 0, yco-=20,
1020                         menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_CHANNELS_CLOSELEVELS, "");
1021         
1022         if(curarea->headertype==HEADERTOP) {
1023                 uiBlockSetDirection(block, UI_DOWN);
1024         }
1025         else {
1026                 uiBlockSetDirection(block, UI_TOP);
1027                 uiBlockFlipOrder(block);
1028         }
1029         
1030         uiTextBoundsBlock(block, 50);
1031         uiEndBlock(C, block);
1032         
1033         return block;
1034 }
1035
1036 /* Grease Pencil ---------------------------  */
1037
1038 /* Uses channelmenu functions */
1039 static uiBlock *action_gplayermenu(bContext *C, ARegion *ar, void *arg_unused)
1040 {
1041         ScrArea *curarea= CTX_wm_area(C);
1042         uiBlock *block;
1043         short yco= 0, menuwidth=120;
1044         
1045         block= uiBeginBlock(C, ar, "action_gplayermenu", UI_EMBOSSP, UI_HELV);
1046         uiBlockSetButmFunc(block, do_channelmenu, NULL);
1047                 
1048         uiDefIconTextBlockBut(block, action_channelmenu_settingsmenu, 
1049                                                   NULL, ICON_RIGHTARROW_THIN, 
1050                                                   "Settings", 0, yco-=20, 120, 20, ""); 
1051         
1052         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1053                                         menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1054         
1055         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1056                         "Delete|X", 0, yco-=20,
1057                         menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_CHANNELS_DELETE, "");
1058         
1059         if(curarea->headertype==HEADERTOP) {
1060                 uiBlockSetDirection(block, UI_DOWN);
1061         }
1062         else {
1063                 uiBlockSetDirection(block, UI_TOP);
1064                 uiBlockFlipOrder(block);
1065         }
1066         
1067         uiTextBoundsBlock(block, 50);
1068         uiEndBlock(C, block);
1069         
1070         return block;
1071 }
1072
1073 /* Select menu ---------------------------  */
1074
1075 static void do_selectmenu_columnmenu(bContext *C, void *arg, int event)
1076 {
1077         switch (event) {
1078                 case ACTMENU_SEL_COLUMN_MARKERSBETWEEN:
1079                         //markers_selectkeys_between();
1080                         break;
1081                 case ACTMENU_SEL_COLUMN_KEYS:
1082                         //column_select_action_keys(1);
1083                         break;
1084                 case ACTMENU_SEL_COLUMN_MARKERSCOLUMN:
1085                         //column_select_action_keys(2);
1086                         break;
1087                 case ACTMENU_SEL_COLUMN_CFRA:
1088                         //column_select_action_keys(3);
1089                         break;
1090         }
1091 }
1092
1093 static uiBlock *action_selectmenu_columnmenu(bContext *C, ARegion *ar, void *arg_unused)
1094 {
1095         SpaceAction *saction= (SpaceAction*)CTX_wm_space_data(C);
1096         uiBlock *block;
1097         short yco= 0, menuwidth=120;
1098
1099         block= uiBeginBlock(C, ar, "action_selectmenu_columnmenu", UI_EMBOSSP, UI_HELV);
1100         uiBlockSetButmFunc(block, do_selectmenu_columnmenu, NULL);
1101
1102         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1103                                          "On Selected Keys|K", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0,  
1104                                          ACTMENU_SEL_COLUMN_KEYS, "");
1105         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1106                                          "On Current Frame|Ctrl K", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0,  
1107                                          ACTMENU_SEL_COLUMN_CFRA, "");
1108         
1109         if (SACTION_HASMARKERS) {
1110                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1111                                                  "On Selected Markers|Shift K", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 
1112                                                  ACTMENU_SEL_COLUMN_MARKERSCOLUMN, "");
1113                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1114                                                  "Between Selected Markers|Alt K", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 
1115                                                  ACTMENU_SEL_COLUMN_MARKERSBETWEEN, "");
1116         }
1117         
1118         uiBlockSetDirection(block, UI_RIGHT);
1119         uiTextBoundsBlock(block, 60);
1120
1121         return block;
1122 }
1123
1124 static void do_selectmenu(bContext *C, void *arg, int event)
1125 {
1126         SpaceAction *saction= (SpaceAction*)CTX_wm_space_data(C);
1127         //Key *key;
1128         
1129         if (saction == NULL) return;
1130
1131         //key = get_action_mesh_key();
1132         
1133         switch(event)
1134         {
1135                 case ACTMENU_SEL_BORDER: /* Border Select */
1136                         //borderselect_action();
1137                         break;
1138                         
1139                 case ACTMENU_SEL_BORDERC: /* Border Select */
1140                         //borderselect_actionchannels();
1141                         break;
1142                         
1143                 case ACTMENU_SEL_BORDERM: /* Border Select */
1144                         //borderselect_markers();
1145                         break;
1146                         
1147                 case ACTMENU_SEL_ALL_KEYS: /* Select/Deselect All Keys */
1148                         /*deselect_action_keys(1, 1);
1149                         BIF_undo_push("(De)Select Keys");
1150                         allqueue(REDRAWACTION, 0);
1151                         allqueue(REDRAWNLA, 0);
1152                         allqueue(REDRAWIPO, 0);*/
1153                         break;
1154                         
1155                 case ACTMENU_SEL_ALL_CHAN: /* Select/Deselect All Channels */
1156                         /*deselect_action_channels(1);
1157                         BIF_undo_push("(De)Select Action Channels");
1158                         allqueue(REDRAWVIEW3D, 0);
1159                         allqueue(REDRAWACTION, 0);
1160                         allqueue(REDRAWNLA, 0);
1161                         allqueue(REDRAWIPO, 0);*/
1162                         break;
1163                         
1164                 case ACTMENU_SEL_ALL_MARKERS: /* select/deselect all markers */
1165                         /*deselect_markers(1, 0);
1166                         BIF_undo_push("(De)Select Markers");
1167                         allqueue(REDRAWMARKER, 0);*/
1168                         break;
1169                         
1170                 case ACTMENU_SEL_INVERSE_KEYS: /* invert selection status of keys */
1171                         /*deselect_action_keys(0, 2);
1172                         BIF_undo_push("Inverse Keys");
1173                         allqueue(REDRAWACTION, 0);
1174                         allqueue(REDRAWNLA, 0);
1175                         allqueue(REDRAWIPO, 0);*/
1176                         break;
1177                         
1178                 case ACTMENU_SEL_INVERSE_CHANNELS: /* invert selection status of channels */
1179                         /*deselect_action_channels(2);
1180                         BIF_undo_push("Inverse Action Channels");
1181                         allqueue(REDRAWVIEW3D, 0);
1182                         allqueue(REDRAWACTION, 0);
1183                         allqueue(REDRAWNLA, 0);
1184                         allqueue(REDRAWIPO, 0);*/
1185                         break;
1186                         
1187                 case ACTMENU_SEL_INVERSE_MARKERS: /* invert selection of markers */
1188                         /*deselect_markers(0, 2);
1189                         BIF_undo_push("Inverse Action Channels");
1190                         allqueue(REDRAWMARKER, 0);*/
1191                         break;
1192                         
1193                 case ACTMENU_SEL_LEFTKEYS:
1194                         //selectkeys_leftright(1, SELECT_REPLACE);
1195                         break;
1196                         
1197                 case ACTMENU_SEL_RIGHTKEYS:
1198                         //selectkeys_leftright(0, SELECT_REPLACE);
1199                         break;
1200         }
1201 }
1202
1203 static uiBlock *action_selectmenu(bContext *C, ARegion *ar, void *arg_unused)
1204 {
1205         ScrArea *curarea= CTX_wm_area(C);
1206         SpaceAction *saction= (SpaceAction*)CTX_wm_space_data(C);
1207         uiBlock *block;
1208         short yco= 0, menuwidth=120;
1209         
1210         block= uiBeginBlock(C, ar, "action_selectmenu", UI_EMBOSSP, UI_HELV);
1211         uiBlockSetButmFunc(block, do_selectmenu, NULL);
1212
1213         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1214                                          "Border Select Keys|B", 0, yco-=20, 
1215                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
1216                                          ACTMENU_SEL_BORDER, "");
1217         if (SACTION_HASMARKERS) {
1218                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1219                                                  "Border Select Markers|Ctrl B", 0, yco-=20, 
1220                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
1221                                                  ACTMENU_SEL_BORDERM, "");
1222         }
1223         if (saction->mode != SACTCONT_SHAPEKEY) {
1224                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1225                                                  "Border Select Channels|B", 0, yco-=20, 
1226                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
1227                                                  ACTMENU_SEL_BORDERC, "");
1228         }
1229                                          
1230         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1231                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1232                          
1233         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1234                                          "Select/Deselect All Keys|A", 0, yco-=20, 
1235                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
1236                                          ACTMENU_SEL_ALL_KEYS, "");
1237         if (SACTION_HASMARKERS) {
1238                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1239                                                  "Select/Deselect All Markers|Ctrl A", 0, yco-=20, 
1240                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
1241                                                  ACTMENU_SEL_ALL_MARKERS, "");
1242         }
1243         if (saction->mode != SACTCONT_SHAPEKEY) {
1244                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1245                                                  "Select/Deselect All Channels|A", 0, yco-=20, 
1246                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
1247                                                  ACTMENU_SEL_ALL_CHAN, "");
1248         }
1249                                          
1250         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1251                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1252
1253         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1254                                          "Inverse Keys|Ctrl I", 0, yco-=20, 
1255                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
1256                                          ACTMENU_SEL_INVERSE_KEYS, "");
1257         if (SACTION_HASMARKERS) {
1258                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1259                                                  "Inverse Markers|Ctrl Shift I", 0, yco-=20, 
1260                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
1261                                                  ACTMENU_SEL_INVERSE_MARKERS, "");
1262         }
1263         if (saction->mode != SACTCONT_SHAPEKEY) {
1264                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1265                                                  "Inverse All Channels|Ctrl I", 0, yco-=20, 
1266                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
1267                                                  ACTMENU_SEL_INVERSE_CHANNELS, "");
1268         }
1269                 
1270         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1271                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1272                          
1273         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1274                                          "Back In Time|Alt RMB", 0, yco-=20, 
1275                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
1276                                          ACTMENU_SEL_LEFTKEYS, "");
1277                                                                  
1278         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1279                                          "Ahead In Time|Alt RMB", 0, yco-=20, 
1280                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
1281                                          ACTMENU_SEL_RIGHTKEYS, "");             
1282                          
1283         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1284                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1285                          
1286         uiDefIconTextBlockBut(block, action_selectmenu_columnmenu, 
1287                                                   NULL, ICON_RIGHTARROW_THIN, "Column Select Keys", 0, yco-=20, 120, 20, "");
1288         
1289         if(curarea->headertype==HEADERTOP) {
1290                 uiBlockSetDirection(block, UI_DOWN);
1291         }
1292         else {
1293                 uiBlockSetDirection(block, UI_TOP);
1294                 uiBlockFlipOrder(block);
1295         }
1296         
1297         uiTextBoundsBlock(block, 50);
1298         uiEndBlock(C, block);
1299         
1300         return block;
1301 }
1302
1303 /* View menu ---------------------------  */
1304
1305 static void do_viewmenu(bContext *C, void *arg, int event)
1306 {
1307         switch(event) {
1308                 case ACTMENU_VIEW_CENTERVIEW: /* Center View to Current Frame */
1309                         //center_currframe();
1310                         break;
1311                 case ACTMENU_VIEW_AUTOUPDATE: /* Update Automatically */
1312                         /*if (BTST(G.saction->lock, 0)) 
1313                                 G.saction->lock = BCLR(G.saction->lock, 0);
1314                         else 
1315                                 G.saction->lock = BSET(G.saction->lock, 0);*/
1316                         break;
1317                 case ACTMENU_VIEW_PLAY3D: /* Play Back Animation */
1318                         //play_anim(0);
1319                         break;
1320                 case ACTMENU_VIEW_PLAYALL: /* Play Back Animation in All */
1321                         //play_anim(1);
1322                         break;  
1323                 case ACTMENU_VIEW_ALL: /* View All */
1324                         //do_action_buttons(B_ACTHOME);
1325                         break;
1326                 case ACTMENU_VIEW_LOCK:
1327                         /*G.v2d->flag ^= V2D_VIEWLOCK;
1328                         if (G.v2d->flag & V2D_VIEWLOCK)
1329                                 view2d_do_locks(curarea, 0);*/
1330                         break;
1331                 case ACTMENU_VIEW_SLIDERS:       /* Show sliders (when applicable) */
1332                         //G.saction->flag ^= SACTION_SLIDERS;
1333                         break;
1334                 case ACTMENU_VIEW_MAXIMIZE: /* Maximize Window */
1335                         /* using event B_FULL */
1336                         break;
1337                 case ACTMENU_VIEW_NEXTMARKER: /* Jump to next marker */
1338                         //nextprev_marker(1);
1339                         break;
1340                 case ACTMENU_VIEW_PREVMARKER: /* Jump to previous marker */
1341                         //nextprev_marker(-1);
1342                         break;
1343                 case ACTMENU_VIEW_TIME: /* switch between frames and seconds display */
1344                         //G.saction->flag ^= SACTION_DRAWTIME;
1345                         break;
1346                 case ACTMENU_VIEW_NOHIDE: /* Show hidden channels */
1347                         //G.saction->flag ^= SACTION_NOHIDE;
1348                         break;
1349                 case ACTMENU_VIEW_NEXTKEYFRAME: /* Jump to next keyframe */
1350                         //nextprev_action_keyframe(1);
1351                         break;
1352                 case ACTMENU_VIEW_PREVKEYFRAME: /* Jump to previous keyframe */
1353                         //nextprev_action_keyframe(-1);
1354                         break;
1355                 case ACTMENU_VIEW_TRANSDELDUPS: /* Don't delete duplicate/overlapping keyframes after transform */
1356                         //G.saction->flag ^= SACTION_NOTRANSKEYCULL;
1357                         break;
1358                 case ACTMENU_VIEW_HORIZOPTIMISE: /* Include keyframes not in view (horizontally) when preparing to draw */
1359                         //G.saction->flag ^= SACTION_HORIZOPTIMISEON;
1360                         break;
1361                 case ACTMENU_VIEW_GCOLORS: /* Draw grouped-action channels using its group's color */
1362                         //G.saction->flag ^= SACTION_NODRAWGCOLORS;
1363                         break;
1364                 case ACTMENU_VIEW_PREVRANGESET: /* Set preview range */
1365                         //anim_previewrange_set();
1366                         break;
1367                 case ACTMENU_VIEW_PREVRANGECLEAR: /* Clear preview range */
1368                         //anim_previewrange_clear();
1369                         break;
1370                 case ACTMENU_VIEW_PREVRANGEAUTO: /* Auto preview-range length */
1371                         //action_previewrange_set(G.saction->action);
1372                         break;
1373         }
1374 }
1375
1376 static uiBlock *action_viewmenu(bContext *C, ARegion *ar, void *arg_unused)
1377 {
1378         ScrArea *curarea= CTX_wm_area(C);
1379         SpaceAction *saction= (SpaceAction*)CTX_wm_space_data(C);
1380         View2D *v2d= UI_view2d_fromcontext_rwin(C);
1381         uiBlock *block;
1382         short yco= 0, menuwidth=120;
1383         
1384         block= uiBeginBlock(C, ar, "viewmenu", UI_EMBOSSP, UI_HELV);
1385         uiBlockSetButmFunc(block, do_viewmenu, NULL);
1386         
1387         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1388                                          "Center View to Current Frame|C", 0, yco-=20, 
1389                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 
1390                                          ACTMENU_VIEW_CENTERVIEW, "");
1391                 
1392         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1393                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1394                          
1395         if (saction->flag & SACTION_DRAWTIME) {
1396                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1397                                                 "Show Frames|Ctrl T", 0, yco-=20, 
1398                                                 menuwidth, 19, NULL, 0.0, 0.0, 1, 
1399                                                 ACTMENU_VIEW_TIME, "");
1400         }
1401         else {
1402                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1403                                                 "Show Seconds|Ctrl T", 0, yco-=20, 
1404                                                 menuwidth, 19, NULL, 0.0, 0.0, 1, 
1405                                                 ACTMENU_VIEW_TIME, "");
1406         }
1407         
1408         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1409         
1410         if (saction->mode == SACTCONT_GPENCIL) {
1411                         // this option may get removed in future
1412                 uiDefIconTextBut(block, BUTM, 1, (saction->flag & SACTION_HORIZOPTIMISEON)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, 
1413                                                  "Cull Out-of-View Keys (Time)|", 0, yco-=20, 
1414                                                  menuwidth, 19, NULL, 0.0, 0.0, 1, 
1415                                                  ACTMENU_VIEW_HORIZOPTIMISE, "");
1416         }
1417         else {
1418                 uiDefIconTextBut(block, BUTM, 1, (saction->flag & SACTION_SLIDERS)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, 
1419                                                  "Show Sliders|", 0, yco-=20, 
1420                                                  menuwidth, 19, NULL, 0.0, 0.0, 1, 
1421                                                  ACTMENU_VIEW_SLIDERS, "");
1422                                                  
1423                 uiDefIconTextBut(block, BUTM, 1, (saction->flag & SACTION_NOHIDE)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, 
1424                                                  "Show Hidden Channels|", 0, yco-=20, 
1425                                                  menuwidth, 19, NULL, 0.0, 0.0, 1, 
1426                                                  ACTMENU_VIEW_NOHIDE, "");
1427                                                  
1428                 uiDefIconTextBut(block, BUTM, 1, (saction->flag & SACTION_NODRAWGCOLORS)?ICON_CHECKBOX_DEHLT:ICON_CHECKBOX_HLT, 
1429                                                  "Use Group Colors|", 0, yco-=20, 
1430                                                  menuwidth, 19, NULL, 0.0, 0.0, 1, 
1431                                                  ACTMENU_VIEW_GCOLORS, "");
1432                                                  
1433                         // this option may get removed in future
1434                 uiDefIconTextBut(block, BUTM, 1, (saction->flag & SACTION_HORIZOPTIMISEON)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, 
1435                                                  "Cull Out-of-View Keys (Time)|", 0, yco-=20, 
1436                                                  menuwidth, 19, NULL, 0.0, 0.0, 1, 
1437                                                  ACTMENU_VIEW_HORIZOPTIMISE, "");
1438                 
1439                 uiDefIconTextBut(block, BUTM, 1, (saction->flag & SACTION_NOTRANSKEYCULL)?ICON_CHECKBOX_DEHLT:ICON_CHECKBOX_HLT, 
1440                                                  "AutoMerge Keyframes|", 0, yco-=20, 
1441                                                  menuwidth, 19, NULL, 0.0, 0.0, 1, 
1442                                                  ACTMENU_VIEW_TRANSDELDUPS, "");
1443         }       
1444         
1445                 
1446         uiDefIconTextBut(block, BUTM, 1, (v2d->flag & V2D_VIEWSYNC_SCREEN_TIME)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, 
1447                                          "Lock Time to Other Windows|", 0, yco-=20, 
1448                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 
1449                                          ACTMENU_VIEW_LOCK, "");
1450                                          
1451         /*uiDefIconTextBut(block, BUTM, 1, BTST(saction->lock, 0)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, 
1452                                          "Update Automatically|", 0, yco-=20, 
1453                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 
1454                                          ACTMENU_VIEW_AUTOUPDATE, "");*/
1455
1456         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1457                                         menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1458                 
1459         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1460                                 "Jump To Next Marker|PageUp", 0, yco-=20,
1461                                 menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_VIEW_NEXTMARKER, "");
1462         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1463                                 "Jump To Prev Marker|PageDown", 0, yco-=20, 
1464                                 menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_VIEW_PREVMARKER, "");
1465                                 
1466         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1467                                 "Jump To Next Keyframe|Ctrl PageUp", 0, yco-=20,
1468                                 menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_VIEW_NEXTKEYFRAME, "");
1469         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1470                                 "Jump To Prev Keyframe|Ctrl PageDown", 0, yco-=20, 
1471                                 menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_VIEW_PREVKEYFRAME, "");
1472                                          
1473         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1474                                         menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1475                         
1476         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1477                                          "Play Back Animation|Alt A", 0, yco-=20, 
1478                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 
1479                                          ACTMENU_VIEW_PLAY3D, "");
1480         //uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1481         //                               "Play Back Animation in 3D View|Alt Shift A", 0, yco-=20,
1482         //                               menuwidth, 19, NULL, 0.0, 0.0, 1, 
1483         //                               ACTMENU_VIEW_PLAYALL, "");
1484         
1485         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1486                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1487                 
1488         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1489                                          "Set Preview Range|Ctrl P", 0, yco-=20, 
1490                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 
1491                                          ACTMENU_VIEW_PREVRANGESET, "");
1492         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1493                                          "Clear Preview Range|Alt P", 0, yco-=20,
1494                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 
1495                                          ACTMENU_VIEW_PREVRANGECLEAR, "");
1496                 
1497         if ((saction->mode == SACTCONT_ACTION) && (saction->action)) {
1498                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1499                                          "Preview Range from Action Length|Ctrl Alt P", 0, yco-=20, 
1500                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 
1501                                          ACTMENU_VIEW_PREVRANGEAUTO, "");
1502         }
1503                 
1504         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1505                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1506         
1507         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1508                                          "View All|Home", 0, yco-=20, 
1509                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 
1510                                          ACTMENU_VIEW_ALL, "");
1511         
1512 /*      if (!curarea->full) 
1513                 uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, 
1514                                                  "Maximize Window|Ctrl UpArrow", 0, yco-=20, 
1515                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
1516                                                  ACTMENU_VIEW_MAXIMIZE, "");
1517         else 
1518                 uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, 
1519                                                  "Tile Window|Ctrl DownArrow", 0, yco-=20, 
1520                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
1521                                                  ACTMENU_VIEW_MAXIMIZE, "");
1522 */
1523         
1524         if (curarea->headertype==HEADERTOP) {
1525                 uiBlockSetDirection(block, UI_DOWN);
1526         }
1527         else {
1528                 uiBlockSetDirection(block, UI_TOP);
1529                 uiBlockFlipOrder(block);
1530         }
1531         
1532         uiTextBoundsBlock(block, 50);
1533         uiEndBlock(C, block);
1534         
1535         return block;
1536 }
1537
1538 /* ************************ header area region *********************** */
1539
1540 static void do_action_buttons(bContext *C, void *arg, int event)
1541 {
1542         switch(event) {
1543                 case B_REDR:
1544                         ED_area_tag_redraw(CTX_wm_area(C));
1545                         break;
1546                         
1547                 case B_ACTCOPYKEYS:
1548                         WM_operator_name_call(C, "ACT_OT_keyframes_copy", WM_OP_EXEC_REGION_WIN, NULL);
1549                         break;
1550                 case B_ACTPASTEKEYS:
1551                         WM_operator_name_call(C, "ACT_OT_keyframes_paste", WM_OP_EXEC_REGION_WIN, NULL);
1552                         break;
1553         }
1554 }
1555
1556 static void saction_idpoin_handle(bContext *C, ID *id, int event)
1557 {
1558         SpaceAction *saction= (SpaceAction*)CTX_wm_space_data(C);
1559         Object *obact= CTX_data_active_object(C);
1560         AnimData *adt= BKE_id_add_animdata((ID *)obact);
1561
1562         switch (event) {
1563                 case UI_ID_BROWSE:
1564                 case UI_ID_DELETE:
1565                         /* we must set this action to be the one used by active object (if not pinned) */
1566                         if (saction->pin == 0)
1567                                 obact->adt->action= saction->action;
1568                         
1569                         ED_area_tag_redraw(CTX_wm_area(C));
1570                         ED_undo_push(C, "Assign Action");
1571                         break;
1572                 case UI_ID_RENAME:
1573                         break;
1574                 case UI_ID_ADD_NEW:
1575                         /* XXX not implemented */
1576                         break;
1577                 case UI_ID_OPEN:
1578                         /* XXX not implemented */
1579                         break;
1580                 case UI_ID_ALONE:
1581                         /* XXX not implemented */
1582                         break;
1583                 case UI_ID_PIN:
1584                         break;
1585         }
1586 }
1587
1588 void action_header_buttons(const bContext *C, ARegion *ar)
1589 {
1590         ScrArea *sa= CTX_wm_area(C);
1591         SpaceAction *saction= (SpaceAction *)CTX_wm_space_data(C);
1592         bAnimContext ac;
1593         uiBlock *block;
1594         int xco, yco= 3, xmax;
1595         
1596         block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS, UI_HELV);
1597         uiBlockSetHandleFunc(block, do_action_buttons, NULL);
1598         
1599         xco= ED_area_header_standardbuttons(C, block, yco);
1600         
1601         uiBlockSetEmboss(block, UI_EMBOSS);
1602         
1603         /* get context... (also syncs data) */
1604         ANIM_animdata_get_context(C, &ac);
1605         
1606         if ((sa->flag & HEADER_NO_PULLDOWN)==0) {
1607                 /* pull down menus */
1608                 uiBlockSetEmboss(block, UI_EMBOSSP);
1609                 
1610                 xmax= GetButStringLength("View");
1611                 uiDefPulldownBut(block, action_viewmenu, CTX_wm_area(C), 
1612                                           "View", xco, yco-2, xmax-3, 24, "");
1613                 xco+= xmax;
1614                 
1615                 xmax= GetButStringLength("Select");
1616                 uiDefPulldownBut(block, action_selectmenu, CTX_wm_area(C), 
1617                                           "Select", xco, yco-2, xmax-3, 24, "");
1618                 xco+= xmax;
1619                 
1620                 if ( (saction->mode == SACTCONT_DOPESHEET) ||
1621                          ((saction->action) && (saction->mode==SACTCONT_ACTION)) ) 
1622                 {
1623                         xmax= GetButStringLength("Channel");
1624                         uiDefPulldownBut(block, action_channelmenu, CTX_wm_area(C), 
1625                                                   "Channel", xco, yco-2, xmax-3, 24, "");
1626                         xco+= xmax;
1627                 }
1628                 else if (saction->mode==SACTCONT_GPENCIL) {
1629                         xmax= GetButStringLength("Channel");
1630                         uiDefPulldownBut(block, action_gplayermenu, CTX_wm_area(C), 
1631                                                   "Channel", xco, yco-2, xmax-3, 24, "");
1632                         xco+= xmax;
1633                 }
1634                 
1635                 xmax= GetButStringLength("Marker");
1636                 uiDefPulldownBut(block, action_markermenu, CTX_wm_area(C), 
1637                                           "Marker", xco, yco-2, xmax-3, 24, "");
1638                 xco+= xmax;
1639                 
1640                 if (saction->mode == SACTCONT_GPENCIL) {
1641                         xmax= GetButStringLength("Frame");
1642                         uiDefPulldownBut(block, action_framemenu, CTX_wm_area(C), 
1643                                                   "Frame", xco, yco-2, xmax-3, 24, "");
1644                         xco+= xmax;
1645                 }
1646                 else {
1647                         xmax= GetButStringLength("Key");
1648                         uiDefPulldownBut(block, action_keymenu, CTX_wm_area(C), 
1649                                                   "Key", xco, yco-2, xmax-3, 24, "");
1650                         xco+= xmax;
1651                 }
1652         }
1653
1654         uiBlockSetEmboss(block, UI_EMBOSS);
1655         
1656         /* MODE SELECTOR */
1657         uiDefButC(block, MENU, B_REDR, 
1658                         "Editor Mode %t|DopeSheet %x3|Action Editor %x0|ShapeKey Editor %x1|Grease Pencil %x2", 
1659                         xco,yco,90,YIC, &saction->mode, 0, 1, 0, 0, 
1660                         "Editing modes for this editor");
1661         
1662         
1663         xco += (90 + 8);
1664         
1665         /*if (ac.data)*/ 
1666         {
1667                 /* MODE-DEPENDENT DRAWING */
1668                 if (saction->mode == SACTCONT_DOPESHEET) {
1669                         /* FILTERING OPTIONS */
1670                         xco -= 10;
1671                         
1672                         //uiBlockBeginAlign(block);
1673                                 uiDefIconButBitI(block, TOG, ADS_FILTER_ONLYSEL, B_REDR, ICON_RESTRICT_SELECT_OFF,      (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Only display selected Objects");
1674                         //uiBlockEndAlign(block);
1675                         xco += 5;
1676                         
1677                         uiBlockBeginAlign(block);
1678                                 //uiDefIconButBitI(block, TOGN, ADS_FILTER_NOOBJ, B_REDR, ICON_OBJECT,  (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Non-Armature Objects");
1679                                 //uiDefIconButBitI(block, TOGN, ADS_FILTER_NOARM, B_REDR, ICON_ARMATURE,        (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Armature Objects");
1680                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOSHAPEKEYS, B_REDR, ICON_EDIT,        (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display ShapeKeys");
1681                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOMAT, B_REDR, ICON_MATERIAL,  (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Materials");
1682                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOLAM, B_REDR, ICON_LAMP,      (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Lamps");
1683                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOCAM, B_REDR, ICON_CAMERA,    (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Cameras");
1684                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOCUR, B_REDR, ICON_CURVE,     (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Curves");
1685                         uiBlockEndAlign(block);
1686                         xco += 30;
1687                 }
1688                 else if (saction->mode == SACTCONT_ACTION) { // not too appropriate for shapekeys atm...
1689                         /* NAME ETC */
1690                         //uiClearButLock();
1691                         
1692                         /* NAME ETC (it is assumed that */
1693                         xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID**)&saction->action, ID_AC, &saction->pin, xco, yco,
1694                                 saction_idpoin_handle, UI_ID_BROWSE|UI_ID_RENAME|UI_ID_ADD_NEW|UI_ID_DELETE|UI_ID_FAKE_USER|UI_ID_ALONE|UI_ID_PIN);
1695                         
1696                         xco += 8;
1697                 }
1698                 
1699                 /* COPY PASTE */
1700                 uiBlockBeginAlign(block);
1701                 uiDefIconBut(block, BUT, B_ACTCOPYKEYS, ICON_COPYDOWN,  xco,yco,XIC,YIC, 0, 0, 0, 0, 0, "Copies the selected keyframes from the selected channel(s) to the buffer");
1702                 uiDefIconBut(block, BUT, B_ACTPASTEKEYS, ICON_PASTEDOWN,        xco+=XIC,yco,XIC,YIC, 0, 0, 0, 0, 0, "Pastes the keyframes from the buffer");
1703                 uiBlockEndAlign(block);
1704                 xco += (XIC + 8);
1705                 
1706                 /* draw AUTOSNAP */
1707                 if (saction->mode != SACTCONT_GPENCIL) {
1708                         if (saction->flag & SACTION_DRAWTIME) {
1709                                 uiDefButC(block, MENU, B_REDR,
1710                                                 "Auto-Snap Keyframes %t|No Snap %x0|Second Step %x1|Nearest Second %x2|Nearest Marker %x3", 
1711                                                 xco,yco,70,YIC, &(saction->autosnap), 0, 1, 0, 0, 
1712                                                 "Auto-snapping mode for keyframes when transforming");
1713                         }
1714                         else {
1715                                 uiDefButC(block, MENU, B_REDR, 
1716                                                 "Auto-Snap Keyframes %t|No Snap %x0|Frame Step %x1|Nearest Frame %x2|Nearest Marker %x3", 
1717                                                 xco,yco,70,YIC, &(saction->autosnap), 0, 1, 0, 0, 
1718                                                 "Auto-snapping mode for keyframes when transforming");
1719                         }
1720                         
1721                         xco += (70 + 8);
1722                 }
1723                 
1724                 /* draw LOCK */
1725                         // XXX this feature is probably not relevant anymore!
1726                 //uiDefIconButS(block, ICONTOG, B_LOCK, ICON_UNLOCKED,  xco, yco, XIC, YIC, 
1727                 //                        &(saction->lock), 0, 0, 0, 0, 
1728                 //                        "Updates other affected window spaces automatically "
1729                 //                        "to reflect changes in real time");
1730         }
1731
1732         /* always as last  */
1733         UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, (int)(ar->v2d.tot.ymax-ar->v2d.tot.ymin));
1734         
1735         uiEndBlock(C, block);
1736         uiDrawBlock(C, block);
1737 }
1738
1739