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
86 #define ACTMENU_SEL_BORDER 0
87 #define ACTMENU_SEL_ALL_KEYS 1
88 #define ACTMENU_SEL_ALL_CHAN 2
90 #define ACTMENU_KEY_DUPLICATE 0
91 #define ACTMENU_KEY_DELETE 1
92 #define ACTMENU_KEY_BAKE 2
94 #define ACTMENU_KEY_TRANSFORM_MOVE 0
95 #define ACTMENU_KEY_TRANSFORM_SCALE 1
97 #define ACTMENU_KEY_HANDLE_AUTO 0
98 #define ACTMENU_KEY_HANDLE_ALIGN 1
99 #define ACTMENU_KEY_HANDLE_FREE 2
100 #define ACTMENU_KEY_HANDLE_VECTOR 3
102 #define ACTMENU_KEY_INTERP_CONST 0
103 #define ACTMENU_KEY_INTERP_LINEAR 1
104 #define ACTMENU_KEY_INTERP_BEZIER 2
106 void do_action_buttons(unsigned short event)
112 bake_action_with_client (G.saction->action, ob, 0.01);
115 set_exprap_action(IPO_HORIZ);
118 // set_exprap_ipo(IPO_DIR);
121 set_exprap_action(IPO_CYCL);
123 // case B_ACTCYCLICX:
124 // set_exprap_ipo(IPO_CYCLX);
128 //v2d= &(G.saction->v2d);
131 G.v2d->cur.ymin=-SCROLLB;
133 if (!G.saction->action){ // here the mesh rvk?
135 G.v2d->cur.xmax= 100;
139 G.v2d->cur.xmin= calc_action_start(G.saction->action);
140 G.v2d->cur.xmax= calc_action_end(G.saction->action);
141 extra= 0.05*(G.v2d->cur.xmax - G.v2d->cur.xmin);
142 G.v2d->cur.xmin-= extra;
143 G.v2d->cur.xmax+= extra;
145 if(G.v2d->cur.xmin==G.v2d->cur.xmax) {
147 G.v2d->cur.xmax= 100;
150 G.v2d->cur.ymin= 0.0f;
151 G.v2d->cur.ymax= 1000.0f;
153 G.v2d->tot= G.v2d->cur;
154 test_view2d(G.v2d, curarea->winx, curarea->winy);
157 addqueue (curarea->win, REDRAW, 1);
162 allqueue(REDRAWVIEW3D, 1);
166 allqueue(REDRAWVIEW3D, 1);
170 allqueue(REDRAWVIEW3D, 1);
173 case B_ACTPIN: /* __PINFAKE */
174 /* if (G.saction->flag & SACTION_PIN){
175 if (G.saction->action)
176 G.saction->action->id.us ++;
180 if (G.saction->action)
181 G.saction->action->id.us --;
184 allqueue(REDRAWACTION, 1);
190 static void do_action_viewmenu(void *arg, int event)
192 extern int play_anim(int mode);
195 case ACTMENU_VIEW_CENTERVIEW: /* Center View to Current Frame */
198 case ACTMENU_VIEW_AUTOUPDATE: /* Update Automatically */
199 if (BTST(G.saction->lock, 0))
200 G.saction->lock = BCLR(G.saction->lock, 0);
202 G.saction->lock = BSET(G.saction->lock, 0);
204 case ACTMENU_VIEW_PLAY3D: /* Play Back Animation */
207 case ACTMENU_VIEW_PLAYALL: /* Play Back Animation in All */
210 case ACTMENU_VIEW_ALL: /* View All */
211 do_action_buttons(B_ACTHOME);
213 case ACTMENU_VIEW_MAXIMIZE: /* Maximize Window */
214 /* using event B_FULL */
217 allqueue(REDRAWVIEW3D, 0);
220 static uiBlock *action_viewmenu(void *arg_unused)
223 short yco= 0, menuwidth=120;
225 block= uiNewBlock(&curarea->uiblocks, "action_viewmenu",
226 UI_EMBOSSP, UI_HELV, curarea->headwin);
227 uiBlockSetButmFunc(block, do_action_viewmenu, NULL);
229 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
230 "Center View to Current Frame|C", 0, yco-=20,
231 menuwidth, 19, NULL, 0.0, 0.0, 1,
232 ACTMENU_VIEW_CENTERVIEW, "");
234 uiDefBut(block, SEPR, 0, "", 0, yco-=6,
235 menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
237 if(BTST(G.saction->lock, 0)) {
238 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT,
239 "Update Automatically|", 0, yco-=20,
240 menuwidth, 19, NULL, 0.0, 0.0, 1,
241 ACTMENU_VIEW_AUTOUPDATE, "");
244 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT,
245 "Update Automatically|", 0, yco-=20,
246 menuwidth, 19, NULL, 0.0, 0.0, 1,
247 ACTMENU_VIEW_AUTOUPDATE, "");
250 uiDefBut(block, SEPR, 0, "", 0, yco-=6,
251 menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
253 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
254 "Play Back Animation|Alt A", 0, yco-=20,
255 menuwidth, 19, NULL, 0.0, 0.0, 1,
256 ACTMENU_VIEW_PLAY3D, "");
257 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
258 "Play Back Animation in 3D View|Alt Shift A", 0, yco-=20,
259 menuwidth, 19, NULL, 0.0, 0.0, 1,
260 ACTMENU_VIEW_PLAYALL, "");
262 uiDefBut(block, SEPR, 0, "", 0, yco-=6,
263 menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
265 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
266 "View All|Home", 0, yco-=20,
267 menuwidth, 19, NULL, 0.0, 0.0, 1,
268 ACTMENU_VIEW_ALL, "");
271 uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1,
272 "Maximize Window|Ctrl UpArrow", 0, yco-=20,
273 menuwidth, 19, NULL, 0.0, 0.0, 0,
274 ACTMENU_VIEW_MAXIMIZE, "");
276 uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1,
277 "Tile Window|Ctrl DownArrow", 0, yco-=20,
278 menuwidth, 19, NULL, 0.0, 0.0, 0,
279 ACTMENU_VIEW_MAXIMIZE, "");
281 if(curarea->headertype==HEADERTOP) {
282 uiBlockSetDirection(block, UI_DOWN);
285 uiBlockSetDirection(block, UI_TOP);
286 uiBlockFlipOrder(block);
289 uiTextBoundsBlock(block, 50);
294 static void do_action_selectmenu(void *arg, int event)
296 SpaceAction *saction;
300 saction = curarea->spacedata.first;
304 act = saction->action;
305 key = get_action_mesh_key();
309 case ACTMENU_SEL_BORDER: /* Border Select */
311 borderselect_mesh(key);
314 borderselect_action();
318 case ACTMENU_SEL_ALL_KEYS: /* Select/Deselect All Keys */
320 deselect_meshchannel_keys(key, 1);
321 allqueue (REDRAWACTION, 0);
322 allqueue(REDRAWNLA, 0);
323 allqueue (REDRAWIPO, 0);
326 deselect_actionchannel_keys (act, 1);
327 allqueue (REDRAWACTION, 0);
328 allqueue(REDRAWNLA, 0);
329 allqueue (REDRAWIPO, 0);
333 case ACTMENU_SEL_ALL_CHAN: /* Select/Deselect All Channels */
334 deselect_actionchannels (act, 1);
335 allqueue (REDRAWVIEW3D, 0);
336 allqueue (REDRAWACTION, 0);
337 allqueue(REDRAWNLA, 0);
338 allqueue (REDRAWIPO, 0);
343 static uiBlock *action_selectmenu(void *arg_unused)
346 short yco= 0, menuwidth=120;
348 block= uiNewBlock(&curarea->uiblocks, "action_selectmenu",
349 UI_EMBOSSP, UI_HELV, curarea->headwin);
350 uiBlockSetButmFunc(block, do_action_selectmenu, NULL);
352 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
353 "Border Select|B", 0, yco-=20,
354 menuwidth, 19, NULL, 0.0, 0.0, 0,
355 ACTMENU_SEL_BORDER, "");
356 uiDefBut(block, SEPR, 0, "", 0, yco-=6,
357 menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
358 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
359 "Select/Deselect All Keys|A", 0, yco-=20,
360 menuwidth, 19, NULL, 0.0, 0.0, 0,
361 ACTMENU_SEL_ALL_KEYS, "");
362 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
363 "Select/Deselect All Channels", 0, yco-=20,
364 menuwidth, 19, NULL, 0.0, 0.0, 0,
365 ACTMENU_SEL_ALL_CHAN, "");
367 if(curarea->headertype==HEADERTOP) {
368 uiBlockSetDirection(block, UI_DOWN);
371 uiBlockSetDirection(block, UI_TOP);
372 uiBlockFlipOrder(block);
375 uiTextBoundsBlock(block, 50);
380 static void do_action_keymenu_transformmenu(void *arg, int event)
382 SpaceAction *saction;
386 key = get_action_mesh_key();
387 saction= curarea->spacedata.first;
393 case ACTMENU_KEY_TRANSFORM_MOVE:
395 transform_meshchannel_keys('g', key);
398 transform_actionchannel_keys ('g', 0);
401 case ACTMENU_KEY_TRANSFORM_SCALE:
403 transform_meshchannel_keys('s', key);
406 transform_actionchannel_keys ('s', 0);
411 scrarea_queue_winredraw(curarea);
414 static uiBlock *action_keymenu_transformmenu(void *arg_unused)
417 short yco= 0, menuwidth=120;
419 block= uiNewBlock(&curarea->uiblocks, "action_keymenu_transformmenu",
420 UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
421 uiBlockSetButmFunc(block, do_action_keymenu_transformmenu, NULL);
423 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
424 "Grab/Move|G", 0, yco-=20,
425 menuwidth, 19, NULL, 0.0, 0.0, 0,
426 ACTMENU_KEY_TRANSFORM_MOVE, "");
427 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
428 "Scale|S", 0, yco-=20,
429 menuwidth, 19, NULL, 0.0, 0.0, 0,
430 ACTMENU_KEY_TRANSFORM_SCALE, "");
432 uiBlockSetDirection(block, UI_RIGHT);
433 uiTextBoundsBlock(block, 60);
438 static void do_action_keymenu_handlemenu(void *arg, int event)
442 key = get_action_mesh_key();
445 case ACTMENU_KEY_HANDLE_AUTO:
447 sethandles_meshchannel_keys(HD_AUTO, key);
449 sethandles_actionchannel_keys(HD_AUTO);
453 case ACTMENU_KEY_HANDLE_ALIGN:
454 case ACTMENU_KEY_HANDLE_FREE:
455 /* OK, this is kinda dumb, need to fix the
456 * toggle crap in sethandles_ipo_keys()
459 sethandles_meshchannel_keys(HD_ALIGN, key);
461 sethandles_actionchannel_keys(HD_ALIGN);
465 case ACTMENU_KEY_HANDLE_VECTOR:
467 sethandles_meshchannel_keys(HD_VECT, key);
469 sethandles_actionchannel_keys(HD_VECT);
475 static uiBlock *action_keymenu_handlemenu(void *arg_unused)
478 short yco= 0, menuwidth=120;
480 block= uiNewBlock(&curarea->uiblocks, "action_keymenu_handlemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
481 uiBlockSetButmFunc(block, do_action_keymenu_handlemenu, NULL);
483 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
484 "Auto|Shift H", 0, yco-=20,
485 menuwidth, 19, NULL, 0.0, 0.0, 0,
486 ACTMENU_KEY_HANDLE_AUTO, "");
487 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
488 "Aligned|H", 0, yco-=20,
489 menuwidth, 19, NULL, 0.0, 0.0, 0,
490 ACTMENU_KEY_HANDLE_ALIGN, "");
491 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
492 "Free|H", 0, yco-=20, menuwidth,
493 19, NULL, 0.0, 0.0, 0,
494 ACTMENU_KEY_HANDLE_FREE, "");
495 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
496 "Vector|V", 0, yco-=20,
497 menuwidth, 19, NULL, 0.0, 0.0, 0,
498 ACTMENU_KEY_HANDLE_VECTOR, "");
500 uiBlockSetDirection(block, UI_RIGHT);
501 uiTextBoundsBlock(block, 60);
506 static void do_action_keymenu_intpolmenu(void *arg, int event)
510 key = get_action_mesh_key();
514 case ACTMENU_KEY_INTERP_CONST:
519 set_ipotype_actionchannels(SET_IPO_CONSTANT);
522 case ACTMENU_KEY_INTERP_LINEAR:
527 set_ipotype_actionchannels(SET_IPO_LINEAR);
530 case ACTMENU_KEY_INTERP_BEZIER:
535 set_ipotype_actionchannels(SET_IPO_BEZIER);
540 scrarea_queue_winredraw(curarea);
543 static uiBlock *action_keymenu_intpolmenu(void *arg_unused)
546 short yco= 0, menuwidth=120;
548 block= uiNewBlock(&curarea->uiblocks, "action_keymenu_intpolmenu",
549 UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
550 uiBlockSetButmFunc(block, do_action_keymenu_intpolmenu, NULL);
552 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
553 "Constant", 0, yco-=20,
554 menuwidth, 19, NULL, 0.0, 0.0, 0,
555 ACTMENU_KEY_INTERP_CONST, "");
556 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
557 "Linear", 0, yco-=20,
558 menuwidth, 19, NULL, 0.0, 0.0, 0,
559 ACTMENU_KEY_INTERP_LINEAR, "");
560 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
561 "Bezier", 0, yco-=20,
562 menuwidth, 19, NULL, 0.0, 0.0, 0,
563 ACTMENU_KEY_INTERP_BEZIER, "");
565 uiBlockSetDirection(block, UI_RIGHT);
566 uiTextBoundsBlock(block, 60);
571 static void do_action_keymenu(void *arg, int event)
573 SpaceAction *saction;
577 saction= curarea->spacedata.first;
581 act = saction->action;
582 key = get_action_mesh_key();
586 case ACTMENU_KEY_DUPLICATE:
588 duplicate_meshchannel_keys(key);
591 duplicate_actionchannel_keys();
592 remake_action_ipos(act);
596 case ACTMENU_KEY_DELETE:
598 delete_meshchannel_keys(key);
601 delete_actionchannel_keys ();
604 case ACTMENU_KEY_BAKE:
605 bake_action_with_client (G.saction->action, OBACT, 0.01);
610 static uiBlock *action_keymenu(void *arg_unused)
613 short yco= 0, menuwidth=120;
615 block= uiNewBlock(&curarea->uiblocks, "action_keymenu",
616 UI_EMBOSSP, UI_HELV, curarea->headwin);
617 uiBlockSetButmFunc(block, do_action_keymenu, NULL);
619 uiDefIconTextBlockBut(block, action_keymenu_transformmenu,
620 NULL, ICON_RIGHTARROW_THIN,
621 "Transform", 0, yco-=20, 120, 20, "");
623 uiDefBut(block, SEPR, 0, "", 0, yco-=6,
624 menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
626 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
627 "Duplicate|Shift D", 0, yco-=20,
628 menuwidth, 19, NULL, 0.0, 0.0, 0,
629 ACTMENU_KEY_DUPLICATE, "");
630 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
631 "Delete|X", 0, yco-=20,
632 menuwidth, 19, NULL, 0.0, 0.0, 0,
633 ACTMENU_KEY_DELETE, "");
635 uiDefBut(block, SEPR, 0, "", 0, yco-=6,
636 menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
638 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
639 "Bake Action to Ipo Keys", 0, yco-=20,
640 menuwidth, 19, NULL, 0.0, 0.0, 0,
641 ACTMENU_KEY_BAKE, "");
643 uiDefBut(block, SEPR, 0, "", 0, yco-=6,
644 menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
646 uiDefIconTextBlockBut(block, action_keymenu_intpolmenu,
647 NULL, ICON_RIGHTARROW_THIN,
648 "Interpolation Mode", 0, yco-=20, 120, 20, "");
649 uiDefIconTextBlockBut(block, action_keymenu_handlemenu,
650 NULL, ICON_RIGHTARROW_THIN,
651 "Handle Type", 0, yco-=20, 120, 20, "");
653 if(curarea->headertype==HEADERTOP) {
654 uiBlockSetDirection(block, UI_DOWN);
657 uiBlockSetDirection(block, UI_TOP);
658 uiBlockFlipOrder(block);
661 uiTextBoundsBlock(block, 50);
666 void action_buttons(void)
677 // copy from drawactionspace....
678 if (!G.saction->pin) {
680 G.saction->action = OBACT->action;
682 G.saction->action=NULL;
685 sprintf(naam, "header %d", curarea->headwin);
686 block= uiNewBlock(&curarea->uiblocks, naam,
687 UI_EMBOSS, UI_HELV, curarea->headwin);
689 if (area_is_active_area(curarea))
690 uiBlockSetCol(block, TH_HEADER);
692 uiBlockSetCol(block, TH_HEADERDESEL);
694 curarea->butspacetype= SPACE_ACTION;
698 uiDefIconTextButC(block, ICONTEXTROW,B_NEWSPACE, ICON_VIEW3D,
699 windowtype_pup(), xco, 0, XIC+10, YIC,
700 &(curarea->butspacetype), 1.0, SPACEICONMAX, 0, 0,
701 "Displays Current Window Type. "
702 "Click for menu of available types.");
706 uiBlockSetEmboss(block, UI_EMBOSSN);
707 if (curarea->flag & HEADER_NO_PULLDOWN) {
708 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU,
709 ICON_DISCLOSURE_TRI_RIGHT,
711 &(curarea->flag), 0, 0, 0, 0,
712 "Show pulldown menus");
715 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU,
716 ICON_DISCLOSURE_TRI_DOWN,
718 &(curarea->flag), 0, 0, 0, 0,
719 "Hide pulldown menus");
721 uiBlockSetEmboss(block, UI_EMBOSS);
724 if((curarea->flag & HEADER_NO_PULLDOWN)==0) {
725 /* pull down menus */
726 uiBlockSetEmboss(block, UI_EMBOSSP);
728 xmax= GetButStringLength("View");
729 uiDefPulldownBut(block, action_viewmenu, NULL,
730 "View", xco, -2, xmax-3, 24, "");
733 xmax= GetButStringLength("Select");
734 uiDefPulldownBut(block, action_selectmenu, NULL,
735 "Select", xco, -2, xmax-3, 24, "");
738 xmax= GetButStringLength("Key");
739 uiDefPulldownBut(block, action_keymenu, NULL,
740 "Key", xco, -2, xmax-3, 24, "");
744 uiBlockSetEmboss(block, UI_EMBOSS);
750 xco= std_libbuttons(block, xco, 0, B_ACTPIN, &G.saction->pin,
751 B_ACTIONBROWSE, (ID*)G.saction->action,
752 from, &(G.saction->actnr), B_ACTALONE,
753 B_ACTLOCAL, B_ACTIONDELETE, 0, 0);
755 /* Draw action baker */
758 uiDefBut(block, BUT, B_ACTBAKE,
759 "Bake", xco, 0, 64, YIC, 0, 0, 0, 0, 0,
760 "Create an action with the constraint effects "
761 "converted into Ipo keys");
768 uiDefIconButS(block, ICONTOG, 1, ICON_UNLOCKED, xco, 0, XIC, YIC,
769 &(G.saction->lock), 0, 0, 0, 0,
770 "Updates other affected window spaces automatically "
771 "to reflect changes in real time");
775 curarea->headbutlen = xco + 2*XIC;