[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20701] branches/soc-2009-aligorith/source /blender/editors/space_nla: NLA SoC: Adding skeleton code for a buttons region in NLA

Joshua Leung aligorith at gmail.com
Sun Jun 7 13:37:16 CEST 2009


Revision: 20701
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20701
Author:   aligorith
Date:     2009-06-07 13:37:15 +0200 (Sun, 07 Jun 2009)

Log Message:
-----------
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.

Modified Paths:
--------------
    branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_intern.h
    branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_ops.c
    branches/soc-2009-aligorith/source/blender/editors/space_nla/space_nla.c

Added Paths:
-----------
    branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_buttons.c

Added: branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_buttons.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_buttons.c	                        (rev 0)
+++ branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_buttons.c	2009-06-07 11:37:15 UTC (rev 20701)
@@ -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 <string.h>
+#include <stdio.h>
+#include <math.h>
+#include <float.h>
+
+#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;
+}

Modified: branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_intern.h
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_intern.h	2009-06-07 11:18:32 UTC (rev 20700)
+++ branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_intern.h	2009-06-07 11:37:15 UTC (rev 20701)
@@ -48,7 +48,14 @@
 /* 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 */
 

Modified: branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_ops.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_ops.c	2009-06-07 11:18:32 UTC (rev 20700)
+++ branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_ops.c	2009-06-07 11:37:15 UTC (rev 20701)
@@ -115,6 +115,9 @@
 
 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 @@
 {
 	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

Modified: branches/soc-2009-aligorith/source/blender/editors/space_nla/space_nla.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/space_nla/space_nla.c	2009-06-07 11:18:32 UTC (rev 20700)
+++ branches/soc-2009-aligorith/source/blender/editors/space_nla/space_nla.c	2009-06-07 11:37:15 UTC (rev 20701)
@@ -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 @@
 	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 @@
 	// 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 @@
 	/* 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 @@
 	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 */

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list