From 019baf8b8fc0cae24b8706a557a296e598290615 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Sun, 7 Jun 2009 11:37:15 +0000 Subject: NLA SoC: Adding skeleton code for a buttons region in NLA If anyone's doing any testing at this point, please check if this works ok for files with new/old NLA Editors, as I was having some problems with one of my testing (saved from this branch) files with this. --- source/blender/editors/space_nla/nla_buttons.c | 198 +++++++++++++++++++++++++ source/blender/editors/space_nla/nla_intern.h | 7 + source/blender/editors/space_nla/nla_ops.c | 7 + source/blender/editors/space_nla/space_nla.c | 104 +++++++++++++ 4 files changed, 316 insertions(+) create mode 100644 source/blender/editors/space_nla/nla_buttons.c (limited to 'source/blender/editors/space_nla') diff --git a/source/blender/editors/space_nla/nla_buttons.c b/source/blender/editors/space_nla/nla_buttons.c new file mode 100644 index 00000000000..118dc988dfb --- /dev/null +++ b/source/blender/editors/space_nla/nla_buttons.c @@ -0,0 +1,198 @@ +/** + * $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. + * All rights reserved. + * + * + * Contributor(s): Blender Foundation, Joshua Leung + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include +#include +#include +#include + +#include "DNA_anim_types.h" +#include "DNA_action_types.h" +#include "DNA_object_types.h" +#include "DNA_space_types.h" +#include "DNA_scene_types.h" +#include "DNA_screen_types.h" +#include "DNA_userdef_types.h" + +#include "MEM_guardedalloc.h" + +#include "BLI_arithb.h" +#include "BLI_blenlib.h" +#include "BLI_editVert.h" +#include "BLI_rand.h" + +#include "BKE_animsys.h" +#include "BKE_nla.h" +#include "BKE_action.h" +#include "BKE_context.h" +#include "BKE_curve.h" +#include "BKE_customdata.h" +#include "BKE_depsgraph.h" +#include "BKE_fcurve.h" +#include "BKE_object.h" +#include "BKE_global.h" +#include "BKE_scene.h" +#include "BKE_screen.h" +#include "BKE_utildefines.h" + +#include "BIF_gl.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "RNA_access.h" +#include "RNA_define.h" + +#include "ED_anim_api.h" +#include "ED_keyframing.h" +#include "ED_screen.h" +#include "ED_types.h" +#include "ED_util.h" + +#include "UI_interface.h" +#include "UI_resources.h" +#include "UI_view2d.h" + +#include "nla_intern.h" // own include + + +/* ******************* nla editor space & buttons ************** */ + +#define B_NOP 1 +#define B_REDR 2 + +/* -------------- */ + +static void do_nla_region_buttons(bContext *C, void *arg, int event) +{ + //Scene *scene= CTX_data_scene(C); + + switch(event) { + + } + + /* default for now */ + //WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob); +} + +static int nla_panel_context(const bContext *C, bAnimListElem **ale, NlaTrack **nlt) +{ + bAnimContext ac; + bAnimListElem *elem= NULL; + + /* for now, only draw if we could init the anim-context info (necessary for all animation-related tools) + * to work correctly is able to be correctly retrieved. There's no point showing empty panels? + */ + if (ANIM_animdata_get_context(C, &ac) == 0) + return 0; + + // XXX + return 1; + + /* try to find 'active' F-Curve */ + //elem= get_active_fcurve_channel(&ac); + if(elem == NULL) + return 0; + + if(nlt) + *nlt= (NlaTrack*)elem->data; + if(ale) + *ale= elem; + else + MEM_freeN(elem); + + return 1; +} + +static int nla_panel_poll(const bContext *C, PanelType *pt) +{ + return nla_panel_context(C, NULL, NULL); +} + +static void nla_panel_properties(const bContext *C, Panel *pa) +{ + bAnimListElem *ale; + NlaTrack *nlt; + uiBlock *block; + char name[128]; + + if(!nla_panel_context(C, &ale, &nlt)) + return; + + block= uiLayoutFreeBlock(pa->layout); + uiBlockSetHandleFunc(block, do_nla_region_buttons, NULL); + + /* Info - Active F-Curve */ + uiDefBut(block, LABEL, 1, "Active NLA Strip:", 10, 200, 150, 19, NULL, 0.0, 0.0, 0, 0, ""); + + + //MEM_freeN(ale); +} + + +/* ******************* general ******************************** */ + + +void nla_buttons_register(ARegionType *art) +{ + PanelType *pt; + + pt= MEM_callocN(sizeof(PanelType), "spacetype nla panel properties"); + strcpy(pt->idname, "NLA_PT_properties"); + strcpy(pt->label, "Properties"); + pt->draw= nla_panel_properties; + pt->poll= nla_panel_poll; + BLI_addtail(&art->paneltypes, pt); +} + +static int nla_properties(bContext *C, wmOperator *op) +{ + ScrArea *sa= CTX_wm_area(C); + ARegion *ar= nla_has_buttons_region(sa); + + if(ar) { + ar->flag ^= RGN_FLAG_HIDDEN; + ar->v2d.flag &= ~V2D_IS_INITIALISED; /* XXX should become hide/unhide api? */ + + ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa); + ED_area_tag_redraw(sa); + } + return OPERATOR_FINISHED; +} + +void NLAEDIT_OT_properties(wmOperatorType *ot) +{ + ot->name= "Properties"; + ot->idname= "NLAEDIT_OT_properties"; + + ot->exec= nla_properties; + ot->poll= ED_operator_nla_active; + + /* flags */ + ot->flag= 0; +} diff --git a/source/blender/editors/space_nla/nla_intern.h b/source/blender/editors/space_nla/nla_intern.h index 3d8cb7548c0..00de0498e4b 100644 --- a/source/blender/editors/space_nla/nla_intern.h +++ b/source/blender/editors/space_nla/nla_intern.h @@ -48,6 +48,13 @@ /* channel toggle-buttons */ #define NLACHANNEL_BUTTON_WIDTH 16 +/* **************************************** */ +/* space_nla.c / nla_buttons.c */ + +ARegion *nla_has_buttons_region(ScrArea *sa); + +void nla_buttons_register(ARegionType *art); +void NLAEDIT_OT_properties(wmOperatorType *ot); /* **************************************** */ /* nla_draw.c */ diff --git a/source/blender/editors/space_nla/nla_ops.c b/source/blender/editors/space_nla/nla_ops.c index 057e4b05656..f59cbd9c1d4 100644 --- a/source/blender/editors/space_nla/nla_ops.c +++ b/source/blender/editors/space_nla/nla_ops.c @@ -115,6 +115,9 @@ int nlaop_poll_tweakmode_on (bContext *C) void nla_operatortypes(void) { + /* view */ + WM_operatortype_append(NLAEDIT_OT_properties); + /* channels */ WM_operatortype_append(NLA_OT_channels_click); WM_operatortype_append(NLA_OT_channels_select_border); @@ -197,6 +200,10 @@ void nla_keymap(wmWindowManager *wm) { ListBase *keymap; + /* keymap for all regions */ + keymap= WM_keymap_listbase(wm, "NLA Generic", SPACE_NLA, 0); + WM_keymap_add_item(keymap, "NLAEDIT_OT_properties", NKEY, KM_PRESS, 0, 0); + /* channels */ /* Channels are not directly handled by the NLA Editor module, but are inherited from the Animation module. * Most of the relevant operations, keymaps, drawing, etc. can therefore all be found in that module instead, as there diff --git a/source/blender/editors/space_nla/space_nla.c b/source/blender/editors/space_nla/space_nla.c index 32ced127831..5490f40eb03 100644 --- a/source/blender/editors/space_nla/space_nla.c +++ b/source/blender/editors/space_nla/space_nla.c @@ -66,6 +66,39 @@ #include "nla_intern.h" // own include +/* ******************** manage regions ********************* */ + +ARegion *nla_has_buttons_region(ScrArea *sa) +{ + ARegion *ar, *arnew; + + for (ar= sa->regionbase.first; ar; ar= ar->next) { + if (ar->regiontype==RGN_TYPE_UI) + return ar; + } + + /* add subdiv level; after main */ + for (ar= sa->regionbase.first; ar; ar= ar->next) { + if (ar->regiontype==RGN_TYPE_WINDOW) + break; + } + + /* is error! */ + if (ar==NULL) return NULL; + + arnew= MEM_callocN(sizeof(ARegion), "buttons for nla"); + + BLI_insertlinkafter(&sa->regionbase, ar, arnew); + arnew->regiontype= RGN_TYPE_UI; + arnew->alignment= RGN_ALIGN_RIGHT; + + arnew->flag = RGN_FLAG_HIDDEN; + + return arnew; +} + + + /* ******************** default callbacks for nla space ***************** */ static SpaceLink *nla_new(const bContext *C) @@ -130,6 +163,14 @@ static SpaceLink *nla_new(const bContext *C) ar->v2d.align= V2D_ALIGN_NO_NEG_Y; ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL; + /* ui buttons */ + ar= MEM_callocN(sizeof(ARegion), "buttons area for nla"); + + BLI_addtail(&snla->regionbase, ar); + ar->regiontype= RGN_TYPE_UI; + ar->alignment= RGN_ALIGN_RIGHT; + ar->flag = RGN_FLAG_HIDDEN; + return (SpaceLink *)snla; } @@ -178,6 +219,8 @@ static void nla_channel_area_init(wmWindowManager *wm, ARegion *ar) // TODO: cannot use generic copy, need special NLA version 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); + keymap= WM_keymap_listbase(wm, "NLA Generic", SPACE_NLA, 0); + WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); } /* draw entirely, view changes should be handled here */ @@ -221,6 +264,8 @@ static void nla_main_area_init(wmWindowManager *wm, ARegion *ar) /* own keymap */ 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); + keymap= WM_keymap_listbase(wm, "NLA Generic", SPACE_NLA, 0); + WM_event_add_keymap_handler(&ar->handlers, keymap); } static void nla_main_area_draw(const bContext *C, ARegion *ar) @@ -309,6 +354,52 @@ static void nla_header_area_draw(const bContext *C, ARegion *ar) UI_view2d_view_restore(C); } +/* add handlers, stuff you only do once or on area/region changes */ +static void nla_buttons_area_init(wmWindowManager *wm, ARegion *ar) +{ + ListBase *keymap; + + ED_region_panels_init(wm, ar); + + keymap= WM_keymap_listbase(wm, "NLA Generic", SPACE_NLA, 0); + WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); +} + +static void nla_buttons_area_draw(const bContext *C, ARegion *ar) +{ + ED_region_panels(C, ar, 1, NULL); +} + +static void nla_region_listener(ARegion *ar, wmNotifier *wmn) +{ + /* context changes */ + switch(wmn->category) { + case NC_SCENE: + switch(wmn->data) { + case ND_OB_ACTIVE: + case ND_FRAME: + case ND_MARKERS: + ED_region_tag_redraw(ar); + break; + } + break; + case NC_OBJECT: + switch(wmn->data) { + case ND_BONE_ACTIVE: + case ND_BONE_SELECT: + case ND_KEYS: + ED_region_tag_redraw(ar); + break; + } + break; + default: + if(wmn->data==ND_KEYS) + ED_region_tag_redraw(ar); + + } +} + + static void nla_main_area_listener(ARegion *ar, wmNotifier *wmn) { /* context changes */ @@ -439,6 +530,19 @@ void ED_spacetype_nla(void) BLI_addhead(&st->regiontypes, art); + /* regions: UI buttons */ + art= MEM_callocN(sizeof(ARegionType), "spacetype nla region"); + art->regionid = RGN_TYPE_UI; + art->minsizex= 200; + art->keymapflag= ED_KEYMAP_UI; + art->listener= nla_region_listener; + art->init= nla_buttons_area_init; + art->draw= nla_buttons_area_draw; + + BLI_addhead(&st->regiontypes, art); + + nla_buttons_register(art); + BKE_spacetype_register(st); } -- cgit v1.2.3