2 * header_nla.c oct-2003
4 * Functions to draw the "NLA Editor" window header
5 * and handle user events sent to it.
9 * ***** BEGIN GPL 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.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software Foundation,
23 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
26 * All rights reserved.
28 * The Original Code is: all of this file.
30 * Contributor(s): none yet.
32 * ***** END GPL LICENSE BLOCK *****
44 #include "DNA_nla_types.h"
45 #include "DNA_scene_types.h"
46 #include "DNA_screen_types.h"
47 #include "DNA_space_types.h"
49 #include "BKE_global.h"
51 #include "BKE_utildefines.h"
53 #include "BIF_interface.h"
54 #include "BIF_resources.h"
55 #include "BIF_screen.h"
56 #include "BIF_space.h"
57 #include "BIF_editnla.h"
58 #include "BIF_editaction.h"
59 #include "BIF_toolbox.h"
61 #include "BSE_drawipo.h"
62 #include "BSE_headerbuttons.h"
70 void do_nla_buttons(unsigned short event)
79 /* i tried to understand nla/action drawing to reveil a 'tot' rect, impossible code! (ton) */
80 v2d->cur.xmin = G.scene->r.sfra-5;
81 v2d->cur.xmax = G.scene->r.efra+5;
82 v2d->cur.ymin= -SCROLLB;
83 v2d->cur.ymax= 5; // at least stuff is visiable then?
85 test_view2d(G.v2d, curarea->winx, curarea->winy);
86 view2d_do_locks(curarea, V2D_LOCK_COPY);
87 addqueue (curarea->win, REDRAW, 1);
93 static void do_nla_viewmenu(void *arg, int event)
95 extern int play_anim(int mode);
98 case 0: /* Update Automatically */
99 if(BTST(G.snla->lock, 0)) G.snla->lock = BCLR(G.snla->lock, 0);
100 else G.snla->lock = BSET(G.snla->lock, 0);
102 case 1: /* Play Back Animation */
105 case 2: /* Play Back Animation in 3D View */
108 case 3: /* View All */
109 do_nla_buttons(B_NLAHOME);
111 case 4: /* Maximize Window */
112 /* using event B_FULL */
114 case 5: /* Update automatically */
115 G.v2d->flag ^= V2D_VIEWLOCK;
116 if(G.v2d->flag & V2D_VIEWLOCK)
117 view2d_do_locks(curarea, 0);
119 case 6: /* Show all objects that have keyframes? */
120 G.snla->flag ^= SNLA_ALLKEYED;
122 case 7: /* Show timing in Frames or Seconds */
123 G.snla->flag ^= SNLA_DRAWTIME;
125 case 8: /* Set Preview Range */
126 anim_previewrange_set();
128 case 9: /* Clear Preview Range */
129 anim_previewrange_clear();
134 static uiBlock *nla_viewmenu(void *arg_unused)
136 /* static short tog=0; */
138 short yco= 0, menuwidth=120;
140 block= uiNewBlock(&curarea->uiblocks, "nla_viewmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
141 uiBlockSetButmFunc(block, do_nla_viewmenu, NULL);
143 uiDefIconTextBut(block, BUTM, 1, (G.snla->flag & SNLA_ALLKEYED)?ICON_CHECKBOX_DEHLT:ICON_CHECKBOX_HLT,
144 "Only Objects On Visible Layers|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
146 if (G.snla->flag & SNLA_DRAWTIME) {
147 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Frames|Ctrl T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
149 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Seconds|Ctrl T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
152 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
154 if(BTST(G.snla->lock, 0)) {
155 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Update Automatically|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
157 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Update Automatically|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
160 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
162 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Play Back Animation|Alt A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
163 //uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Play Back Animation in 3D View|Alt Shift A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
165 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
167 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Set Preview Range|Ctrl P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 8, "");
168 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Clear Preview Range|Alt P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 9, "");
170 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
172 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View All|Home", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
173 uiDefIconTextBut(block, BUTM, 1, (G.v2d->flag & V2D_VIEWLOCK)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT,
174 "Lock Time to Other Windows|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
176 if(!curarea->full) uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Maximize Window|Ctrl UpArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
177 else uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Tile Window|Ctrl DownArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
179 if(curarea->headertype==HEADERTOP) {
180 uiBlockSetDirection(block, UI_DOWN);
183 uiBlockSetDirection(block, UI_TOP);
184 uiBlockFlipOrder(block);
187 uiTextBoundsBlock(block, 50);
192 static void do_nla_selectmenu(void *arg, int event)
197 case 0: /* Border Select */
200 case 1: /* Select/Deselect All Keys */
201 deselect_nlachannel_keys(1);
202 allqueue (REDRAWNLA, 0);
203 allqueue (REDRAWIPO, 0);
205 case 2: /* Select/Deselect All Channel */
206 deselect_nlachannels(1);
207 allqueue (REDRAWVIEW3D, 0);
208 allqueue (REDRAWNLA, 0);
209 allqueue (REDRAWIPO, 0);
211 case 3: /* Select/Deselect All Markers */
212 deselect_markers(1, 0);
213 allqueue(REDRAWMARKER, 0);
215 case 4: /* Borderselect markers */
216 borderselect_markers();
221 static uiBlock *nla_selectmenu(void *arg_unused)
224 short yco= 0, menuwidth=120;
226 block= uiNewBlock(&curarea->uiblocks, "nla_selectmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
227 uiBlockSetButmFunc(block, do_nla_selectmenu, NULL);
229 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Border Select|B", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
230 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Border Select Markers|Ctrl B", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
232 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
234 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select/Deselect All Keys|A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
235 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select/Deselect All Channels", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
236 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select/Deselect All Markers|Ctrl A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
238 if(curarea->headertype==HEADERTOP) {
239 uiBlockSetDirection(block, UI_DOWN);
242 uiBlockSetDirection(block, UI_TOP);
243 uiBlockFlipOrder(block);
246 uiTextBoundsBlock(block, 50);
251 static void do_nla_strip_snapmenu(void *arg, int event)
253 snap_action_strips(event);
255 allqueue(REDRAWIPO, 0);
256 allqueue(REDRAWACTION, 0);
257 allqueue(REDRAWNLA, 0);
260 static uiBlock *nla_strip_snapmenu(void *arg_unused)
263 short yco = 20, menuwidth = 120;
265 block= uiNewBlock(&curarea->uiblocks, "nla_strip_snapmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
266 uiBlockSetButmFunc(block, do_nla_strip_snapmenu, NULL);
268 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Nearest Frame|Shift S, 1", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
269 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Current Frame|Shift S, 2", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
271 uiBlockSetDirection(block, UI_RIGHT);
272 uiTextBoundsBlock(block, 60);
276 static void do_nla_strip_transformmenu(void *arg, int event)
279 case 0: /* grab/move */
280 transform_nlachannel_keys('g', 0);
281 update_for_newframe_muted();
284 transform_nlachannel_keys('s', 0);
285 update_for_newframe_muted();
288 transform_nlachannel_keys('e', 0);
289 update_for_newframe_muted();
292 allqueue(REDRAWVIEW3D, 0);
295 static uiBlock *nla_strip_transformmenu(void *arg_unused)
298 short yco = 20, menuwidth = 120;
300 block= uiNewBlock(&curarea->uiblocks, "nla_strip_transformmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
301 uiBlockSetButmFunc(block, do_nla_strip_transformmenu, NULL);
303 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grab/Move|G", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
304 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grab/Extend from Frame|E", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
305 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Scale|S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
308 uiBlockSetDirection(block, UI_RIGHT);
309 uiTextBoundsBlock(block, 60);
313 static void do_nla_stripmenu(void *arg, int event)
317 case 0: /* Strip Properties */
318 add_blockhandler(curarea, NLA_HANDLER_PROPERTIES, UI_PNL_UNSTOW);
320 case 1: /* Add Action Strip */
323 case 2: /* Duplicate */
324 duplicate_nlachannel_keys();
325 update_for_newframe_muted();
327 case 3: /* Delete Strips */
328 if (okee("Erase selected strips and/or keys")) {
329 delete_nlachannel_keys ();
330 update_for_newframe_muted();
333 case 5: /* Convert Action to NLA Strip */
336 case 6: /* Move Up */
337 shift_nlastrips_up();
339 case 7: /* Move Down */
340 shift_nlastrips_down();
342 case 8: /* reset scale */
343 reset_action_strips(1);
345 case 9: /* reset start/end of action */
346 reset_action_strips(2);
348 case 10: /* add new action as new action strip */
349 add_empty_nlablock();
351 case 11: /* apply scale */
352 reset_action_strips(3);
357 static uiBlock *nla_stripmenu(void *arg_unused)
360 short yco= 0, menuwidth=120;
362 block= uiNewBlock(&curarea->uiblocks, "nla_stripmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
363 uiBlockSetButmFunc(block, do_nla_stripmenu, NULL);
365 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Strip Properties...|N", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
366 uiDefIconTextBlockBut(block, nla_strip_transformmenu, NULL, ICON_RIGHTARROW_THIN, "Transform", 0, yco-=20, 120, 20, "");
367 uiDefIconTextBlockBut(block, nla_strip_snapmenu, NULL, ICON_RIGHTARROW_THIN, "Snap", 0, yco-=20, 120, 20, "");
369 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reset Strip Scale|Alt S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
370 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reset Action Start/End|Alt S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
371 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Apply Strip Scaling|Alt S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 11, "");
373 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
375 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Add Action Strip|Shift A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
376 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Add Blank Action Strip|Shift N", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 10, "");
377 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Convert Action to NLA Strip|C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, "");
379 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Duplicate|Shift D", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
380 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Delete|X", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
382 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
384 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Move Down|Ctrl Page Down", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
385 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Move Up|Ctrl Page Up", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
388 if(curarea->headertype==HEADERTOP) {
389 uiBlockSetDirection(block, UI_DOWN);
392 uiBlockSetDirection(block, UI_TOP);
393 uiBlockFlipOrder(block);
396 uiTextBoundsBlock(block, 50);
401 static void do_nla_markermenu(void *arg, int event)
418 transform_markers('g', 0);
422 allqueue(REDRAWMARKER, 0);
425 static uiBlock *nla_markermenu(void *arg_unused)
428 short yco= 0, menuwidth=120;
430 block= uiNewBlock(&curarea->uiblocks, "nla_markermenu",
431 UI_EMBOSSP, UI_HELV, curarea->headwin);
432 uiBlockSetButmFunc(block, do_nla_markermenu, NULL);
434 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Add Marker|M", 0, yco-=20,
435 menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
436 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Duplicate Marker|Ctrl Shift D", 0, yco-=20,
437 menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
438 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Delete Marker|X", 0, yco-=20,
439 menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
441 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
443 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "(Re)Name Marker|Ctrl M", 0, yco-=20,
444 menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
445 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grab/Move Marker|Ctrl G", 0, yco-=20,
446 menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
448 if(curarea->headertype==HEADERTOP) {
449 uiBlockSetDirection(block, UI_DOWN);
452 uiBlockSetDirection(block, UI_TOP);
453 uiBlockFlipOrder(block);
456 uiTextBoundsBlock(block, 50);
461 void nla_buttons(void)
468 snla= curarea->spacedata.first;
470 sprintf(naam, "header %d", curarea->headwin);
471 block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSS, UI_HELV, curarea->headwin);
473 if(area_is_active_area(curarea)) uiBlockSetCol(block, TH_HEADER);
474 else uiBlockSetCol(block, TH_HEADERDESEL);
476 curarea->butspacetype= SPACE_NLA;
480 uiDefIconTextButC(block, ICONTEXTROW,B_NEWSPACE, ICON_VIEW3D, windowtype_pup(), xco,0,XIC+10,YIC, &(curarea->butspacetype), 1.0, SPACEICONMAX, 0, 0, "Displays Current Window Type. Click for menu of available types.");
484 uiBlockSetEmboss(block, UI_EMBOSSN);
485 if(curarea->flag & HEADER_NO_PULLDOWN) {
486 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_RIGHT,
488 &(curarea->flag), 0, 0, 0, 0, "Show pulldown menus");
490 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_DOWN,
492 &(curarea->flag), 0, 0, 0, 0, "Hide pulldown menus");
494 uiBlockSetEmboss(block, UI_EMBOSS);
497 if((curarea->flag & HEADER_NO_PULLDOWN)==0) {
498 /* pull down menus */
499 uiBlockSetEmboss(block, UI_EMBOSSP);
501 xmax= GetButStringLength("View");
502 uiDefPulldownBut(block, nla_viewmenu, NULL, "View", xco, -2, xmax-3, 24, "");
505 xmax= GetButStringLength("Select");
506 uiDefPulldownBut(block, nla_selectmenu, NULL, "Select", xco, -2, xmax-3, 24, "");
509 xmax= GetButStringLength("Marker");
510 uiDefPulldownBut(block, nla_markermenu, NULL, "Marker", xco, -2, xmax-3, 24, "");
513 xmax= GetButStringLength("Strip");
514 uiDefPulldownBut(block, nla_stripmenu, NULL, "Strip", xco, -2, xmax-3, 24, "");
520 uiBlockSetEmboss(block, UI_EMBOSS);
526 if (G.snla->flag & SNLA_DRAWTIME) {
527 uiDefButS(block, MENU, B_REDR,
528 "Auto-Snap Strips/Keyframes %t|No Snap %x0|Second Step %x1|Nearest Second %x2|Nearest Marker %x3",
529 xco,0,70,YIC, &(G.snla->autosnap), 0, 1, 0, 0,
530 "Auto-snapping mode for strips and keyframes when transforming");
533 uiDefButS(block, MENU, B_REDR,
534 "Auto-Snap Strips/Keyframes %t|No Snap %x0|Frame Step %x1|Nearest Frame %x2|Nearest Marker %x3",
535 xco,0,70,YIC, &(G.snla->autosnap), 0, 1, 0, 0,
536 "Auto-snapping mode for strips and keyframes when transforming");
543 uiDefIconButS(block, ICONTOG, 1, ICON_UNLOCKED, xco,0,XIC,YIC, &(snla->lock), 0, 0, 0, 0, "Toggles forced redraw of other windows to reflect changes in real time");