2 * header_action.c oct-2003
4 * Functions to draw the "Action Editor" window header
5 * and handle user events sent to it.
9 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version. The Blender
15 * Foundation also sells licenses for use in proprietary software under
16 * the Blender License. See http://www.blender.org/BL/ for information
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
29 * All rights reserved.
31 * The Original Code is: all of this file.
33 * Contributor(s): none yet.
35 * ***** END GPL/BL DUAL LICENSE BLOCK *****
46 #include "DNA_action_types.h"
47 #include "DNA_curve_types.h"
49 #include "DNA_ipo_types.h"
50 #include "DNA_key_types.h"
51 #include "DNA_object_types.h"
52 #include "DNA_scene_types.h"
53 #include "DNA_screen_types.h"
54 #include "DNA_space_types.h"
56 #include "BIF_editaction.h"
57 #include "BIF_interface.h"
58 #include "BIF_poseobject.h"
59 #include "BIF_resources.h"
60 #include "BIF_screen.h"
61 #include "BIF_space.h"
63 #include "BKE_action.h"
64 #include "BKE_armature.h"
65 #include "BKE_constraint.h"
66 #include "BKE_depsgraph.h"
67 #include "BKE_global.h"
69 #include "BKE_utildefines.h"
71 #include "BSE_drawipo.h"
72 #include "BSE_headerbuttons.h"
79 #define ACTMENU_VIEW_CENTERVIEW 0
80 #define ACTMENU_VIEW_AUTOUPDATE 1
81 #define ACTMENU_VIEW_PLAY3D 2
82 #define ACTMENU_VIEW_PLAYALL 3
83 #define ACTMENU_VIEW_ALL 4
84 #define ACTMENU_VIEW_MAXIMIZE 5
85 #define ACTMENU_VIEW_LOCK 6
87 #define ACTMENU_SEL_BORDER 0
88 #define ACTMENU_SEL_ALL_KEYS 1
89 #define ACTMENU_SEL_ALL_CHAN 2
91 #define ACTMENU_KEY_DUPLICATE 0
92 #define ACTMENU_KEY_DELETE 1
93 #define ACTMENU_KEY_BAKE 2
95 #define ACTMENU_KEY_TRANSFORM_MOVE 0
96 #define ACTMENU_KEY_TRANSFORM_SCALE 1
98 #define ACTMENU_KEY_HANDLE_AUTO 0
99 #define ACTMENU_KEY_HANDLE_ALIGN 1
100 #define ACTMENU_KEY_HANDLE_FREE 2
101 #define ACTMENU_KEY_HANDLE_VECTOR 3
103 #define ACTMENU_KEY_INTERP_CONST 0
104 #define ACTMENU_KEY_INTERP_LINEAR 1
105 #define ACTMENU_KEY_INTERP_BEZIER 2
107 void do_action_buttons(unsigned short event)
113 bake_action_with_client (G.saction->action, ob, 0.01);
116 set_exprap_action(IPO_HORIZ);
119 // set_exprap_ipo(IPO_DIR);
122 set_exprap_action(IPO_CYCL);
124 // case B_ACTCYCLICX:
125 // set_exprap_ipo(IPO_CYCLX);
129 //v2d= &(G.saction->v2d);
132 G.v2d->cur.ymin=-SCROLLB;
134 if (!G.saction->action){ // here the mesh rvk?
136 G.v2d->cur.xmax= 100;
140 G.v2d->cur.xmin= calc_action_start(G.saction->action);
141 G.v2d->cur.xmax= calc_action_end(G.saction->action);
142 extra= 0.05*(G.v2d->cur.xmax - G.v2d->cur.xmin);
143 G.v2d->cur.xmin-= extra;
144 G.v2d->cur.xmax+= extra;
146 if(G.v2d->cur.xmin==G.v2d->cur.xmax) {
148 G.v2d->cur.xmax= 100;
151 G.v2d->cur.ymin= 0.0f;
152 G.v2d->cur.ymax= 1000.0f;
154 G.v2d->tot= G.v2d->cur;
155 test_view2d(G.v2d, curarea->winx, curarea->winy);
156 view2d_do_locks(curarea, V2D_LOCK_COPY);
158 addqueue (curarea->win, REDRAW, 1);
163 allqueue(REDRAWVIEW3D, 1);
167 allqueue(REDRAWVIEW3D, 1);
171 allqueue(REDRAWVIEW3D, 1);
174 case B_ACTPIN: /* __PINFAKE */
175 /* if (G.saction->flag & SACTION_PIN){
176 if (G.saction->action)
177 G.saction->action->id.us ++;
181 if (G.saction->action)
182 G.saction->action->id.us --;
185 allqueue(REDRAWACTION, 1);
191 static void do_action_viewmenu(void *arg, int event)
193 extern int play_anim(int mode);
196 case ACTMENU_VIEW_CENTERVIEW: /* Center View to Current Frame */
199 case ACTMENU_VIEW_AUTOUPDATE: /* Update Automatically */
200 if (BTST(G.saction->lock, 0))
201 G.saction->lock = BCLR(G.saction->lock, 0);
203 G.saction->lock = BSET(G.saction->lock, 0);
205 case ACTMENU_VIEW_PLAY3D: /* Play Back Animation */
208 case ACTMENU_VIEW_PLAYALL: /* Play Back Animation in All */
211 case ACTMENU_VIEW_ALL: /* View All */
212 do_action_buttons(B_ACTHOME);
214 case ACTMENU_VIEW_LOCK:
215 G.v2d->flag ^= V2D_VIEWLOCK;
216 if(G.v2d->flag & V2D_VIEWLOCK)
217 view2d_do_locks(curarea, 0);
219 case ACTMENU_VIEW_MAXIMIZE: /* Maximize Window */
220 /* using event B_FULL */
223 allqueue(REDRAWVIEW3D, 0);
226 static uiBlock *action_viewmenu(void *arg_unused)
229 short yco= 0, menuwidth=120;
231 block= uiNewBlock(&curarea->uiblocks, "action_viewmenu",
232 UI_EMBOSSP, UI_HELV, curarea->headwin);
233 uiBlockSetButmFunc(block, do_action_viewmenu, NULL);
235 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
236 "Center View to Current Frame|C", 0, yco-=20,
237 menuwidth, 19, NULL, 0.0, 0.0, 1,
238 ACTMENU_VIEW_CENTERVIEW, "");
240 uiDefIconTextBut(block, BUTM, 1, (G.v2d->flag & V2D_VIEWLOCK)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT,
241 "Lock Time to Other Windows|", 0, yco-=20,
242 menuwidth, 19, NULL, 0.0, 0.0, 1,
243 ACTMENU_VIEW_LOCK, "");
245 uiDefBut(block, SEPR, 0, "", 0, yco-=6,
246 menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
248 uiDefIconTextBut(block, BUTM, 1, BTST(G.saction->lock, 0)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT,
249 "Update Automatically|", 0, yco-=20,
250 menuwidth, 19, NULL, 0.0, 0.0, 1,
251 ACTMENU_VIEW_AUTOUPDATE, "");
253 uiDefBut(block, SEPR, 0, "", 0, yco-=6,
254 menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
256 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
257 "Play Back Animation|Alt A", 0, yco-=20,
258 menuwidth, 19, NULL, 0.0, 0.0, 1,
259 ACTMENU_VIEW_PLAY3D, "");
260 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
261 "Play Back Animation in 3D View|Alt Shift A", 0, yco-=20,
262 menuwidth, 19, NULL, 0.0, 0.0, 1,
263 ACTMENU_VIEW_PLAYALL, "");
265 uiDefBut(block, SEPR, 0, "", 0, yco-=6,
266 menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
268 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
269 "View All|Home", 0, yco-=20,
270 menuwidth, 19, NULL, 0.0, 0.0, 1,
271 ACTMENU_VIEW_ALL, "");
274 uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1,
275 "Maximize Window|Ctrl UpArrow", 0, yco-=20,
276 menuwidth, 19, NULL, 0.0, 0.0, 0,
277 ACTMENU_VIEW_MAXIMIZE, "");
279 uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1,
280 "Tile Window|Ctrl DownArrow", 0, yco-=20,
281 menuwidth, 19, NULL, 0.0, 0.0, 0,
282 ACTMENU_VIEW_MAXIMIZE, "");
284 if(curarea->headertype==HEADERTOP) {
285 uiBlockSetDirection(block, UI_DOWN);
288 uiBlockSetDirection(block, UI_TOP);
289 uiBlockFlipOrder(block);
292 uiTextBoundsBlock(block, 50);
297 static void do_action_selectmenu(void *arg, int event)
299 SpaceAction *saction;
303 saction = curarea->spacedata.first;
307 act = saction->action;
308 key = get_action_mesh_key();
312 case ACTMENU_SEL_BORDER: /* Border Select */
314 borderselect_mesh(key);
317 borderselect_action();
321 case ACTMENU_SEL_ALL_KEYS: /* Select/Deselect All Keys */
323 deselect_meshchannel_keys(key, 1);
324 allqueue (REDRAWACTION, 0);
325 allqueue(REDRAWNLA, 0);
326 allqueue (REDRAWIPO, 0);
329 deselect_actionchannel_keys (act, 1);
330 allqueue (REDRAWACTION, 0);
331 allqueue(REDRAWNLA, 0);
332 allqueue (REDRAWIPO, 0);
336 case ACTMENU_SEL_ALL_CHAN: /* Select/Deselect All Channels */
337 deselect_actionchannels (act, 1);
338 allqueue (REDRAWVIEW3D, 0);
339 allqueue (REDRAWACTION, 0);
340 allqueue(REDRAWNLA, 0);
341 allqueue (REDRAWIPO, 0);
346 static uiBlock *action_selectmenu(void *arg_unused)
349 short yco= 0, menuwidth=120;
351 block= uiNewBlock(&curarea->uiblocks, "action_selectmenu",
352 UI_EMBOSSP, UI_HELV, curarea->headwin);
353 uiBlockSetButmFunc(block, do_action_selectmenu, NULL);
355 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
356 "Border Select|B", 0, yco-=20,
357 menuwidth, 19, NULL, 0.0, 0.0, 0,
358 ACTMENU_SEL_BORDER, "");
359 uiDefBut(block, SEPR, 0, "", 0, yco-=6,
360 menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
361 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
362 "Select/Deselect All Keys|A", 0, yco-=20,
363 menuwidth, 19, NULL, 0.0, 0.0, 0,
364 ACTMENU_SEL_ALL_KEYS, "");
365 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
366 "Select/Deselect All Channels", 0, yco-=20,
367 menuwidth, 19, NULL, 0.0, 0.0, 0,
368 ACTMENU_SEL_ALL_CHAN, "");
370 if(curarea->headertype==HEADERTOP) {
371 uiBlockSetDirection(block, UI_DOWN);
374 uiBlockSetDirection(block, UI_TOP);
375 uiBlockFlipOrder(block);
378 uiTextBoundsBlock(block, 50);
383 static void do_action_keymenu_transformmenu(void *arg, int event)
385 SpaceAction *saction;
389 key = get_action_mesh_key();
390 saction= curarea->spacedata.first;
396 case ACTMENU_KEY_TRANSFORM_MOVE:
398 transform_meshchannel_keys('g', key);
401 transform_actionchannel_keys ('g', 0);
404 case ACTMENU_KEY_TRANSFORM_SCALE:
406 transform_meshchannel_keys('s', key);
409 transform_actionchannel_keys ('s', 0);
414 scrarea_queue_winredraw(curarea);
417 static uiBlock *action_keymenu_transformmenu(void *arg_unused)
420 short yco= 0, menuwidth=120;
422 block= uiNewBlock(&curarea->uiblocks, "action_keymenu_transformmenu",
423 UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
424 uiBlockSetButmFunc(block, do_action_keymenu_transformmenu, NULL);
426 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
427 "Grab/Move|G", 0, yco-=20,
428 menuwidth, 19, NULL, 0.0, 0.0, 0,
429 ACTMENU_KEY_TRANSFORM_MOVE, "");
430 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
431 "Scale|S", 0, yco-=20,
432 menuwidth, 19, NULL, 0.0, 0.0, 0,
433 ACTMENU_KEY_TRANSFORM_SCALE, "");
435 uiBlockSetDirection(block, UI_RIGHT);
436 uiTextBoundsBlock(block, 60);
441 static void do_action_keymenu_handlemenu(void *arg, int event)
445 key = get_action_mesh_key();
448 case ACTMENU_KEY_HANDLE_AUTO:
450 sethandles_meshchannel_keys(HD_AUTO, key);
452 sethandles_actionchannel_keys(HD_AUTO);
456 case ACTMENU_KEY_HANDLE_ALIGN:
457 case ACTMENU_KEY_HANDLE_FREE:
458 /* OK, this is kinda dumb, need to fix the
459 * toggle crap in sethandles_ipo_keys()
462 sethandles_meshchannel_keys(HD_ALIGN, key);
464 sethandles_actionchannel_keys(HD_ALIGN);
468 case ACTMENU_KEY_HANDLE_VECTOR:
470 sethandles_meshchannel_keys(HD_VECT, key);
472 sethandles_actionchannel_keys(HD_VECT);
478 static uiBlock *action_keymenu_handlemenu(void *arg_unused)
481 short yco= 0, menuwidth=120;
483 block= uiNewBlock(&curarea->uiblocks, "action_keymenu_handlemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
484 uiBlockSetButmFunc(block, do_action_keymenu_handlemenu, NULL);
486 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
487 "Auto|Shift H", 0, yco-=20,
488 menuwidth, 19, NULL, 0.0, 0.0, 0,
489 ACTMENU_KEY_HANDLE_AUTO, "");
490 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
491 "Aligned|H", 0, yco-=20,
492 menuwidth, 19, NULL, 0.0, 0.0, 0,
493 ACTMENU_KEY_HANDLE_ALIGN, "");
494 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
495 "Free|H", 0, yco-=20, menuwidth,
496 19, NULL, 0.0, 0.0, 0,
497 ACTMENU_KEY_HANDLE_FREE, "");
498 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
499 "Vector|V", 0, yco-=20,
500 menuwidth, 19, NULL, 0.0, 0.0, 0,
501 ACTMENU_KEY_HANDLE_VECTOR, "");
503 uiBlockSetDirection(block, UI_RIGHT);
504 uiTextBoundsBlock(block, 60);
509 static void do_action_keymenu_intpolmenu(void *arg, int event)
513 key = get_action_mesh_key();
517 case ACTMENU_KEY_INTERP_CONST:
522 set_ipotype_actionchannels(SET_IPO_CONSTANT);
525 case ACTMENU_KEY_INTERP_LINEAR:
530 set_ipotype_actionchannels(SET_IPO_LINEAR);
533 case ACTMENU_KEY_INTERP_BEZIER:
538 set_ipotype_actionchannels(SET_IPO_BEZIER);
543 scrarea_queue_winredraw(curarea);
546 static uiBlock *action_keymenu_intpolmenu(void *arg_unused)
549 short yco= 0, menuwidth=120;
551 block= uiNewBlock(&curarea->uiblocks, "action_keymenu_intpolmenu",
552 UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
553 uiBlockSetButmFunc(block, do_action_keymenu_intpolmenu, NULL);
555 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
556 "Constant", 0, yco-=20,
557 menuwidth, 19, NULL, 0.0, 0.0, 0,
558 ACTMENU_KEY_INTERP_CONST, "");
559 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
560 "Linear", 0, yco-=20,
561 menuwidth, 19, NULL, 0.0, 0.0, 0,
562 ACTMENU_KEY_INTERP_LINEAR, "");
563 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
564 "Bezier", 0, yco-=20,
565 menuwidth, 19, NULL, 0.0, 0.0, 0,
566 ACTMENU_KEY_INTERP_BEZIER, "");
568 uiBlockSetDirection(block, UI_RIGHT);
569 uiTextBoundsBlock(block, 60);
574 static void do_action_keymenu(void *arg, int event)
576 SpaceAction *saction;
580 saction= curarea->spacedata.first;
584 act = saction->action;
585 key = get_action_mesh_key();
589 case ACTMENU_KEY_DUPLICATE:
591 duplicate_meshchannel_keys(key);
594 duplicate_actionchannel_keys();
595 remake_action_ipos(act);
599 case ACTMENU_KEY_DELETE:
601 delete_meshchannel_keys(key);
604 delete_actionchannel_keys ();
607 case ACTMENU_KEY_BAKE:
608 bake_action_with_client (G.saction->action, OBACT, 0.01);
613 static uiBlock *action_keymenu(void *arg_unused)
616 short yco= 0, menuwidth=120;
618 block= uiNewBlock(&curarea->uiblocks, "action_keymenu",
619 UI_EMBOSSP, UI_HELV, curarea->headwin);
620 uiBlockSetButmFunc(block, do_action_keymenu, NULL);
622 uiDefIconTextBlockBut(block, action_keymenu_transformmenu,
623 NULL, ICON_RIGHTARROW_THIN,
624 "Transform", 0, yco-=20, 120, 20, "");
626 uiDefBut(block, SEPR, 0, "", 0, yco-=6,
627 menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
629 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
630 "Duplicate|Shift D", 0, yco-=20,
631 menuwidth, 19, NULL, 0.0, 0.0, 0,
632 ACTMENU_KEY_DUPLICATE, "");
633 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
634 "Delete|X", 0, yco-=20,
635 menuwidth, 19, NULL, 0.0, 0.0, 0,
636 ACTMENU_KEY_DELETE, "");
638 uiDefBut(block, SEPR, 0, "", 0, yco-=6,
639 menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
641 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
642 "Bake Action to Ipo Keys", 0, yco-=20,
643 menuwidth, 19, NULL, 0.0, 0.0, 0,
644 ACTMENU_KEY_BAKE, "");
646 uiDefBut(block, SEPR, 0, "", 0, yco-=6,
647 menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
649 uiDefIconTextBlockBut(block, action_keymenu_intpolmenu,
650 NULL, ICON_RIGHTARROW_THIN,
651 "Interpolation Mode", 0, yco-=20, 120, 20, "");
652 uiDefIconTextBlockBut(block, action_keymenu_handlemenu,
653 NULL, ICON_RIGHTARROW_THIN,
654 "Handle Type", 0, yco-=20, 120, 20, "");
656 if(curarea->headertype==HEADERTOP) {
657 uiBlockSetDirection(block, UI_DOWN);
660 uiBlockSetDirection(block, UI_TOP);
661 uiBlockFlipOrder(block);
664 uiTextBoundsBlock(block, 50);
669 void action_buttons(void)
680 // copy from drawactionspace....
681 if (!G.saction->pin) {
683 G.saction->action = OBACT->action;
685 G.saction->action=NULL;
688 sprintf(naam, "header %d", curarea->headwin);
689 block= uiNewBlock(&curarea->uiblocks, naam,
690 UI_EMBOSS, UI_HELV, curarea->headwin);
692 if (area_is_active_area(curarea))
693 uiBlockSetCol(block, TH_HEADER);
695 uiBlockSetCol(block, TH_HEADERDESEL);
697 curarea->butspacetype= SPACE_ACTION;
701 uiDefIconTextButC(block, ICONTEXTROW,B_NEWSPACE, ICON_VIEW3D,
702 windowtype_pup(), xco, 0, XIC+10, YIC,
703 &(curarea->butspacetype), 1.0, SPACEICONMAX, 0, 0,
704 "Displays Current Window Type. "
705 "Click for menu of available types.");
709 uiBlockSetEmboss(block, UI_EMBOSSN);
710 if (curarea->flag & HEADER_NO_PULLDOWN) {
711 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU,
712 ICON_DISCLOSURE_TRI_RIGHT,
714 &(curarea->flag), 0, 0, 0, 0,
715 "Show pulldown menus");
718 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU,
719 ICON_DISCLOSURE_TRI_DOWN,
721 &(curarea->flag), 0, 0, 0, 0,
722 "Hide pulldown menus");
724 uiBlockSetEmboss(block, UI_EMBOSS);
727 if((curarea->flag & HEADER_NO_PULLDOWN)==0) {
728 /* pull down menus */
729 uiBlockSetEmboss(block, UI_EMBOSSP);
731 xmax= GetButStringLength("View");
732 uiDefPulldownBut(block, action_viewmenu, NULL,
733 "View", xco, -2, xmax-3, 24, "");
736 xmax= GetButStringLength("Select");
737 uiDefPulldownBut(block, action_selectmenu, NULL,
738 "Select", xco, -2, xmax-3, 24, "");
741 xmax= GetButStringLength("Key");
742 uiDefPulldownBut(block, action_keymenu, NULL,
743 "Key", xco, -2, xmax-3, 24, "");
747 uiBlockSetEmboss(block, UI_EMBOSS);
753 xco= std_libbuttons(block, xco, 0, B_ACTPIN, &G.saction->pin,
754 B_ACTIONBROWSE, (ID*)G.saction->action,
755 from, &(G.saction->actnr), B_ACTALONE,
756 B_ACTLOCAL, B_ACTIONDELETE, 0, 0);
758 /* Draw action baker */
761 uiDefBut(block, BUT, B_ACTBAKE,
762 "Bake", xco, 0, 64, YIC, 0, 0, 0, 0, 0,
763 "Create an action with the constraint effects "
764 "converted into Ipo keys");
771 uiDefIconButS(block, ICONTOG, 1, ICON_UNLOCKED, xco, 0, XIC, YIC,
772 &(G.saction->lock), 0, 0, 0, 0,
773 "Updates other affected window spaces automatically "
774 "to reflect changes in real time");
778 curarea->headbutlen = xco + 2*XIC;