diff options
author | Joshua Leung <aligorith@gmail.com> | 2009-05-30 14:41:41 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2009-05-30 14:41:41 +0400 |
commit | 32d0533f78c63d5d95b693e1e6e65144203dc42a (patch) | |
tree | b602e71ceb4f7a9fbfbaeba97585da8c3c6eac0e /source/blender/editors/space_nla | |
parent | 72205f45e4e4dfd14460d693ccda30f7677ae9be (diff) |
NLA SoC: More UI work + 'Push down' tool
'UI Work'
* Added more drawing code for drawing NLA data
* Made the operators for the 'channel-list' of NLA work. A special version of borderselect for the NLA channel-list (due to the different vertical order) still needs to be coded though.
'Push Down' tool
The active action of each AnimData block, represented by the reddy/orange channel, can be added to the NLA stack as a new action by using the 'snow-flake' icon/button (probably need a special icon for this later). This will add a new NLA track and an NLA strip referencing this action. The AnimData block's 'active action' slot will then be left empty.
(Unfortunately, there still seems to be a bug here, which I'll check on later)
Diffstat (limited to 'source/blender/editors/space_nla')
-rw-r--r-- | source/blender/editors/space_nla/nla_channels.c | 336 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_draw.c | 28 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_edit.c | 7 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_intern.h | 17 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_ops.c | 44 | ||||
-rw-r--r-- | source/blender/editors/space_nla/space_nla.c | 17 |
6 files changed, 419 insertions, 30 deletions
diff --git a/source/blender/editors/space_nla/nla_channels.c b/source/blender/editors/space_nla/nla_channels.c new file mode 100644 index 00000000000..658ce69cc10 --- /dev/null +++ b/source/blender/editors/space_nla/nla_channels.c @@ -0,0 +1,336 @@ +/** + * $Id: + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2009 Blender Foundation, Joshua Leung + * All rights reserved. + * + * + * Contributor(s): Joshua Leung (major recode) + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> + +#include "DNA_listBase.h" +#include "DNA_anim_types.h" +#include "DNA_action_types.h" +#include "DNA_armature_types.h" +#include "DNA_camera_types.h" +#include "DNA_curve_types.h" +#include "DNA_object_types.h" +#include "DNA_screen_types.h" +#include "DNA_scene_types.h" +#include "DNA_space_types.h" +#include "DNA_key_types.h" +#include "DNA_lamp_types.h" +#include "DNA_material_types.h" +#include "DNA_userdef_types.h" +#include "DNA_windowmanager_types.h" +#include "DNA_world_types.h" + +#include "MEM_guardedalloc.h" + +#include "BLI_blenlib.h" +#include "BLI_arithb.h" +#include "BLI_rand.h" + +#include "BKE_animsys.h" +#include "BKE_nla.h" +#include "BKE_context.h" +#include "BKE_screen.h" +#include "BKE_utildefines.h" + +#include "ED_anim_api.h" +#include "ED_keyframes_edit.h" +#include "ED_markers.h" +#include "ED_space_api.h" +#include "ED_screen.h" + +#include "RNA_access.h" +#include "RNA_define.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "UI_interface.h" +#include "UI_interface_icons.h" +#include "UI_resources.h" +#include "UI_view2d.h" + +#include "nla_intern.h" // own include + +/* *********************************************** */ +/* Operators for NLA channels-list which need to be different from the standard Animation Editor ones */ + +// TODO: implemented borderselect too, since that also relies on ranges of buttons + +/* ******************** Mouse-Click Operator *********************** */ +/* Depending on the channel that was clicked on, the mouse click will activate whichever + * part of the channel is relevant. + * + * NOTE: eventually, this should probably be phased out when many of these things are replaced with buttons + */ + +static void mouse_nla_channels (bAnimContext *ac, float x, int channel_index, short selectmode) +{ + ListBase anim_data = {NULL, NULL}; + bAnimListElem *ale; + int filter; + + /* get the channel that was clicked on */ + /* filter channels */ + filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CHANNELS); + filter= ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); + + /* get channel from index */ + ale= BLI_findlink(&anim_data, channel_index); + if (ale == NULL) { + /* channel not found */ + printf("Error: animation channel (index = %d) not found in mouse_anim_channels() \n", channel_index); + + BLI_freelistN(&anim_data); + return; + } + + /* action to take depends on what channel we've got */ + switch (ale->type) { + case ANIMTYPE_SCENE: + { + Scene *sce= (Scene *)ale->data; + + if (x < 16) { + /* toggle expand */ + sce->flag ^= SCE_DS_COLLAPSED; + } + else { + /* set selection status */ + if (selectmode == SELECT_INVERT) { + /* swap select */ + sce->flag ^= SCE_DS_SELECTED; + } + else { + sce->flag |= SCE_DS_SELECTED; + } + } + } + break; + case ANIMTYPE_OBJECT: + { + bDopeSheet *ads= (bDopeSheet *)ac->data; + Scene *sce= (Scene *)ads->source; + Base *base= (Base *)ale->data; + Object *ob= base->object; + + if (x < 16) { + /* toggle expand */ + ob->nlaflag ^= OB_ADS_COLLAPSED; // XXX + } + else { + /* set selection status */ + if (selectmode == SELECT_INVERT) { + /* swap select */ + base->flag ^= SELECT; + ob->flag= base->flag; + } + else { + Base *b; + + /* deleselect all */ + for (b= sce->base.first; b; b= b->next) { + b->flag &= ~SELECT; + b->object->flag= b->flag; + } + + /* select object now */ + base->flag |= SELECT; + ob->flag |= SELECT; + } + + /* xxx should be ED_base_object_activate(), but we need context pointer for that... */ + //set_active_base(base); + } + } + break; + case ANIMTYPE_FILLMATD: + { + Object *ob= (Object *)ale->data; + ob->nlaflag ^= OB_ADS_SHOWMATS; // XXX + } + break; + + case ANIMTYPE_DSMAT: + { + Material *ma= (Material *)ale->data; + ma->flag ^= MA_DS_EXPAND; + } + break; + case ANIMTYPE_DSLAM: + { + Lamp *la= (Lamp *)ale->data; + la->flag ^= LA_DS_EXPAND; + } + break; + case ANIMTYPE_DSCAM: + { + Camera *ca= (Camera *)ale->data; + ca->flag ^= CAM_DS_EXPAND; + } + break; + case ANIMTYPE_DSCUR: + { + Curve *cu= (Curve *)ale->data; + cu->flag ^= CU_DS_EXPAND; + } + break; + case ANIMTYPE_DSSKEY: + { + Key *key= (Key *)ale->data; + key->flag ^= KEYBLOCK_DS_EXPAND; + } + break; + case ANIMTYPE_DSWOR: + { + World *wo= (World *)ale->data; + wo->flag ^= WO_DS_EXPAND; + } + break; + + case ANIMTYPE_NLATRACK: + { + NlaTrack *nlt= (NlaTrack *)ale->data; + + if (x >= (NLACHANNEL_NAMEWIDTH-NLACHANNEL_BUTTON_WIDTH)) { + /* toggle protection (only if there's a toggle there) */ + nlt->flag ^= NLATRACK_PROTECTED; + } + else if (x >= (NLACHANNEL_NAMEWIDTH-2*NLACHANNEL_BUTTON_WIDTH)) { + /* toggle mute */ + nlt->flag ^= NLATRACK_MUTED; + } + else { + /* set selection */ + if (selectmode == SELECT_INVERT) { + /* inverse selection status of this F-Curve only */ + nlt->flag ^= NLATRACK_SELECTED; + } + else { + /* select F-Curve by itself */ + ANIM_deselect_anim_channels(ac->data, ac->datatype, 0, ACHANNEL_SETFLAG_CLEAR); + nlt->flag |= NLATRACK_SELECTED; + } + + /* if NLA-Track is selected now, make NLA-Track the 'active' one in the visible list */ + if (nlt->flag & NLATRACK_SELECTED) + ANIM_set_active_channel(ac->data, ac->datatype, filter, nlt, ANIMTYPE_NLATRACK); + } + } + break; + case ANIMTYPE_NLAACTION: + { + AnimData *adt= BKE_animdata_from_id(ale->owner); /* this won't crash, right? */ + + /* for now, only do something if user clicks on the 'push-down' button */ + if (x >= (NLACHANNEL_NAMEWIDTH-NLACHANNEL_BUTTON_WIDTH)) { + /* activate push-down operator */ + // TODO: make this use the operator instead of calling the function directly + // however, calling the operator requires that we supply the args, and that works with proper buttons only + BKE_nla_action_pushdown(adt); + } + } + break; + + default: + printf("Error: Invalid channel type in mouse_nla_channels() \n"); + } + + /* free channels */ + BLI_freelistN(&anim_data); +} + +/* ------------------- */ + +/* handle clicking */ +static int nlachannels_mouseclick_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + bAnimContext ac; + Scene *scene; + ARegion *ar; + View2D *v2d; + int mval[2], channel_index; + short selectmode; + float x, y; + + /* get editor data */ + if (ANIM_animdata_get_context(C, &ac) == 0) + return OPERATOR_CANCELLED; + + /* get useful pointers from animation context data */ + scene= ac.scene; + ar= ac.ar; + v2d= &ar->v2d; + + /* get mouse coordinates (in region coordinates) */ + mval[0]= (event->x - ar->winrct.xmin); + mval[1]= (event->y - ar->winrct.ymin); + + /* select mode is either replace (deselect all, then add) or add/extend */ + if (RNA_boolean_get(op->ptr, "extend")) + selectmode= SELECT_INVERT; + else + selectmode= SELECT_REPLACE; + + /* figure out which channel user clicked in + * Note: although channels technically start at y= ACHANNEL_FIRST, we need to adjust by half a channel's height + * so that the tops of channels get caught ok. Since NLACHANNEL_FIRST is really NLACHANNEL_HEIGHT, we simply use + * NLACHANNEL_HEIGHT_HALF. + */ + UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, &y); + UI_view2d_listview_view_to_cell(v2d, NLACHANNEL_NAMEWIDTH, NLACHANNEL_STEP, 0, (float)NLACHANNEL_HEIGHT_HALF, x, y, NULL, &channel_index); + + /* handle mouse-click in the relevant channel then */ + mouse_nla_channels(&ac, x, channel_index, selectmode); + + /* set notifier tha things have changed */ + ANIM_animdata_send_notifiers(C, &ac, ANIM_CHANGED_CHANNELS); + + return OPERATOR_FINISHED; +} + +void NLA_OT_channels_click (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Mouse Click on Channels"; + ot->idname= "NLA_OT_channels_click"; + + /* api callbacks */ + ot->invoke= nlachannels_mouseclick_invoke; + ot->poll= ED_operator_areaactive; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* id-props */ + RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); // SHIFTKEY +} + +/* *********************************************** */ diff --git a/source/blender/editors/space_nla/nla_draw.c b/source/blender/editors/space_nla/nla_draw.c index 8da59ced436..081064317d6 100644 --- a/source/blender/editors/space_nla/nla_draw.c +++ b/source/blender/editors/space_nla/nla_draw.c @@ -85,8 +85,10 @@ extern void gl_round_box(int mode, float minx, float miny, float maxx, float max /* *********************************************** */ /* Strips */ -static void nla_draw_strip (NlaTrack *nlt, NlaStrip *strip, View2D *v2d, float yminc, float ymaxc) +static void nla_draw_strip (NlaTrack *nlt, NlaStrip *strip, int index, View2D *v2d, float yminc, float ymaxc) { + char name[128]; + /* draw extrapolation info first (as backdrop) */ // TODO... @@ -125,6 +127,15 @@ static void nla_draw_strip (NlaTrack *nlt, NlaStrip *strip, View2D *v2d, float y glColor3f(0.0f, 0.0f, 0.0f); } gl_round_box(GL_LINES, strip->start, yminc, strip->end, ymaxc, 9); + + /* draw some identifying info on the strip (index and name of action if there's room) */ + // XXX for now, just the index + if (strip->flag & NLASTRIP_FLAG_SELECT) + UI_ThemeColor(TH_TEXT_HI); + else + UI_ThemeColor(TH_TEXT); + sprintf(name, "%d |", index); + UI_DrawString(strip->start, yminc+8, name); } /* ---------------------- */ @@ -174,17 +185,18 @@ void draw_nla_main_data (bAnimContext *ac, SpaceNla *snla, ARegion *ar) { NlaTrack *nlt= (NlaTrack *)ale->data; NlaStrip *strip; + int index; /* draw backdrop? */ // TODO... /* draw each strip in the track */ - for (strip= nlt->strips.first; strip; strip= strip->next) { + for (strip=nlt->strips.first, index=1; strip; strip= strip->next, index++) { /* only draw if at least part of the strip is within view */ if ( IN_RANGE(v2d->cur.xmin, strip->start, strip->end) || IN_RANGE(v2d->cur.xmax, strip->start, strip->end) ) { - nla_draw_strip(nlt, strip, v2d, yminc, ymaxc); + nla_draw_strip(nlt, strip, index, v2d, yminc, ymaxc); } } } @@ -601,6 +613,16 @@ void draw_nla_channel_list (bAnimContext *ac, SpaceNla *snla, ARegion *ar) /* draw action 'push-down' */ if (ale->type == ANIMTYPE_NLAACTION) { offset += 16; + + /* XXX firstly draw a little rect to help identify that it's different from the toggles */ + glBegin(GL_LINES); + glVertex2f((float)NLACHANNEL_NAMEWIDTH-offset-1, y-7); + glVertex2f((float)NLACHANNEL_NAMEWIDTH-offset-1, y+7); + glVertex2f((float)NLACHANNEL_NAMEWIDTH-1, y-7; + glVertex2f((float)NLACHANNEL_NAMEWIDTH-1, y+7); + glEnd(); // GL_LINES + + /* now draw the icon */ UI_icon_draw((float)NLACHANNEL_NAMEWIDTH-offset, ydatac, ICON_FREEZE); } diff --git a/source/blender/editors/space_nla/nla_edit.c b/source/blender/editors/space_nla/nla_edit.c index d9d0e5528ae..ce9ae7de7a9 100644 --- a/source/blender/editors/space_nla/nla_edit.c +++ b/source/blender/editors/space_nla/nla_edit.c @@ -51,10 +51,12 @@ #include "BKE_screen.h" #include "ED_anim_api.h" +#include "ED_markers.h" #include "ED_space_api.h" #include "ED_screen.h" -#include "BIF_gl.h" +#include "RNA_access.h" +#include "RNA_define.h" #include "WM_api.h" #include "WM_types.h" @@ -63,13 +65,10 @@ #include "UI_resources.h" #include "UI_view2d.h" -#include "ED_markers.h" - #include "nla_intern.h" // own include /* *********************************************** */ - /* *********************************************** */ /* *********************************************** */ diff --git a/source/blender/editors/space_nla/nla_intern.h b/source/blender/editors/space_nla/nla_intern.h index 3728ba2cbc8..37eb7774696 100644 --- a/source/blender/editors/space_nla/nla_intern.h +++ b/source/blender/editors/space_nla/nla_intern.h @@ -57,6 +57,23 @@ void draw_nla_channel_list(bAnimContext *ac, SpaceNla *snla, ARegion *ar); void nla_header_buttons(const bContext *C, ARegion *ar); +/* **************************************** */ +/* nla_select.c */ + + +/* **************************************** */ +/* nla_edit.c */ + +/* **************************************** */ +/* nla_channels.c */ + +void NLA_OT_channels_click(wmOperatorType *ot); + +/* **************************************** */ +/* nla_ops.c */ + +void nla_operatortypes(void); +void nla_keymap(wmWindowManager *wm); #endif /* ED_NLA_INTERN_H */ diff --git a/source/blender/editors/space_nla/nla_ops.c b/source/blender/editors/space_nla/nla_ops.c index f0e3bd5bca5..ea450a08475 100644 --- a/source/blender/editors/space_nla/nla_ops.c +++ b/source/blender/editors/space_nla/nla_ops.c @@ -54,17 +54,15 @@ #include "ED_space_api.h" #include "ED_screen.h" -#include "BIF_gl.h" - #include "WM_api.h" #include "WM_types.h" +#include "RNA_access.h" + #include "UI_interface.h" #include "UI_resources.h" #include "UI_view2d.h" -#include "ED_markers.h" - #include "nla_intern.h" // own include @@ -72,20 +70,46 @@ void nla_operatortypes(void) { - //WM_operatortype_append(); + /* channels */ + WM_operatortype_append(NLA_OT_channels_click); + /* select */ + // ... } /* ************************** registration - keymaps **********************************/ static void nla_keymap_channels (wmWindowManager *wm, ListBase *keymap) { - //wmKeymapItem *kmi; + /* NLA-specific (different to standard channels keymap) -------------------------- */ + /* selection */ + /* click-select */ + // XXX for now, only leftmouse.... + WM_keymap_add_item(keymap, "NLA_OT_channels_click", LEFTMOUSE, KM_PRESS, 0, 0); + RNA_boolean_set(WM_keymap_add_item(keymap, "NLA_OT_channels_click", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1); + /* General Animation Channels keymap (see anim_channels.c) ----------------------- */ + /* deselect all */ + WM_keymap_add_item(keymap, "ANIM_OT_channels_select_all_toggle", AKEY, KM_PRESS, 0, 0); + RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "invert", 1); + /* borderselect */ + WM_keymap_add_item(keymap, "ANIM_OT_channels_select_border", BKEY, KM_PRESS, 0, 0); - /* transform system */ - //transform_keymap_for_space(wm, keymap, SPACE_NLA); + /* settings */ + WM_keymap_add_item(keymap, "ANIM_OT_channels_setting_toggle", WKEY, KM_PRESS, KM_SHIFT, 0); + WM_keymap_add_item(keymap, "ANIM_OT_channels_setting_enable", WKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0); + WM_keymap_add_item(keymap, "ANIM_OT_channels_setting_disable", WKEY, KM_PRESS, KM_ALT, 0); + + /* settings - specialised hotkeys */ + WM_keymap_add_item(keymap, "ANIM_OT_channels_editable_toggle", TABKEY, KM_PRESS, 0, 0); + + /* expand/collapse */ + WM_keymap_add_item(keymap, "ANIM_OT_channels_expand", PADPLUSKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "ANIM_OT_channels_collapse", PADMINUS, KM_PRESS, 0, 0); + + RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_expand", PADPLUSKEY, KM_PRESS, KM_CTRL, 0)->ptr, "all", 1); + RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_collapse", PADMINUS, KM_PRESS, KM_CTRL, 0)->ptr, "all", 1); } static void nla_keymap_main (wmWindowManager *wm, ListBase *keymap) @@ -111,11 +135,11 @@ void nla_keymap(wmWindowManager *wm) * * However, those operations which involve clicking on channels and/or the placement of them in the view are implemented here instead */ - keymap= WM_keymap_listbase(wm, "NLA_Channels", SPACE_NLA, 0); + keymap= WM_keymap_listbase(wm, "NLA Channels", SPACE_NLA, 0); nla_keymap_channels(wm, keymap); /* data */ - keymap= WM_keymap_listbase(wm, "NLA_Data", SPACE_NLA, 0); + keymap= WM_keymap_listbase(wm, "NLA Data", SPACE_NLA, 0); nla_keymap_main(wm, keymap); } diff --git a/source/blender/editors/space_nla/space_nla.c b/source/blender/editors/space_nla/space_nla.c index bf122227a8b..1313b4d915d 100644 --- a/source/blender/editors/space_nla/space_nla.c +++ b/source/blender/editors/space_nla/space_nla.c @@ -167,14 +167,14 @@ static SpaceLink *nla_duplicate(SpaceLink *sl) /* add handlers, stuff you only do once or on area/region changes */ static void nla_channel_area_init(wmWindowManager *wm, ARegion *ar) { - //ListBase *keymap; + ListBase *keymap; UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STACK, ar->winx, ar->winy); /* own keymap */ // TODO: cannot use generic copy, need special NLA version - //keymap= WM_keymap_listbase(wm, "Animation_Channels", 0, 0); /* XXX weak? */ - //WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + keymap= WM_keymap_listbase(wm, "NLA Channels", SPACE_NLA, 0); /* XXX weak? */ + WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); } /* draw entirely, view changes should be handled here */ @@ -216,7 +216,7 @@ static void nla_main_area_init(wmWindowManager *wm, ARegion *ar) UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy); /* own keymap */ - keymap= WM_keymap_listbase(wm, "NLA", SPACE_NLA, 0); /* XXX weak? */ + keymap= WM_keymap_listbase(wm, "NLA Data", SPACE_NLA, 0); /* XXX weak? */ WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); } @@ -271,15 +271,6 @@ static void nla_main_area_draw(const bContext *C, ARegion *ar) UI_view2d_scrollers_free(scrollers); } -void nla_operatortypes(void) -{ - -} - -void nla_keymap(struct wmWindowManager *wm) -{ - -} /* add handlers, stuff you only do once or on area/region changes */ static void nla_header_area_init(wmWindowManager *wm, ARegion *ar) |