[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20511] branches/soc-2009-aligorith/source /blender: NLA SoC: Basic Strip drawing

Joshua Leung aligorith at gmail.com
Sat May 30 02:28:33 CEST 2009


Revision: 20511
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20511
Author:   aligorith
Date:     2009-05-30 02:28:33 +0200 (Sat, 30 May 2009)

Log Message:
-----------
NLA SoC: Basic Strip drawing

Implemented some basic strip-drawing code with some hardcoded colours. These colours will be made into theme colours at some point, but the aim is to use different colours as indicators of the 'state' of the strip (i.e. active/being tweaked, uses the same action as the strip being tweaked, selected, normal). 

This is not yet usable though...

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

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

Modified: branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_draw.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_draw.c	2009-05-29 22:55:06 UTC (rev 20510)
+++ branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_draw.c	2009-05-30 00:28:33 UTC (rev 20511)
@@ -83,7 +83,145 @@
 extern void gl_round_box(int mode, float minx, float miny, float maxx, float maxy, float rad);
 
 /* *********************************************** */
+/* Strips */
 
+static void nla_draw_strip (NlaTrack *nlt, NlaStrip *strip, View2D *v2d, float yminc, float ymaxc)
+{
+	/* draw extrapolation info first (as backdrop) */
+	// TODO...
+	
+	/* draw 'inside' of strip itself */
+		/* set color of strip - color is used to indicate status here */
+	if (strip->flag & NLASTRIP_FLAG_ACTIVE) {
+		/* tweaking strip should be drawn green when it is acting as the tweaking strip */
+		// FIXME: hardcoded temp-hack colors
+		glColor3f(0.3f, 0.95f, 0.1f);
+	}
+	else if (strip->flag & NLASTRIP_FLAG_TWEAKUSER) {
+		/* alert user that this strip is also used by the tweaking track (this is set when going into
+		 * 'editmode' for that strip), since the edits made here may not be what the user anticipated
+		 */
+		// FIXME: hardcoded temp-hack colors
+		glColor3f(0.85f, 0.0f, 0.0f);
+	}
+	else if (strip->flag & NLASTRIP_FLAG_SELECT) {
+		/* selected strip - use theme color for selected */
+		UI_ThemeColor(TH_STRIP_SELECT);
+	}
+	else {
+		/* normal, unselected strip - use standard strip theme color */
+		UI_ThemeColor(TH_STRIP);
+	}
+	uiSetRoundBox(15); /* all corners rounded */
+	gl_round_box(GL_POLYGON, strip->start, yminc, strip->end, ymaxc, 9);
+	
+	/* draw strip outline */
+	if (strip->flag & NLASTRIP_FLAG_ACTIVE) {
+		/* strip should appear 'sunken', so draw a light border around it */
+		glColor3f(0.9f, 1.0f, 0.9f); // FIXME: hardcoded temp-hack colors
+	}
+	else {
+		/* strip should appear to stand out, so draw a dark border around it */
+		glColor3f(0.0f, 0.0f, 0.0f);
+	}
+	gl_round_box(GL_LINES, strip->start, yminc, strip->end, ymaxc, 9);
+} 
+
+/* ---------------------- */
+
+void draw_nla_main_data (bAnimContext *ac, SpaceNla *snla, ARegion *ar)
+{
+	ListBase anim_data = {NULL, NULL};
+	bAnimListElem *ale;
+	int filter;
+	
+	View2D *v2d= &ar->v2d;
+	float y= 0.0f;
+	int items, height;
+	
+	/* build list of channels to draw */
+	filter= (ANIMFILTER_VISIBLE|ANIMFILTER_CHANNELS);
+	items= ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
+	
+	/* Update max-extent of channels here (taking into account scrollers):
+	 * 	- this is done to allow the channel list to be scrollable, but must be done here
+	 * 	  to avoid regenerating the list again and/or also because channels list is drawn first
+	 *	- offset of NLACHANNEL_HEIGHT*2 is added to the height of the channels, as first is for 
+	 *	  start of list offset, and the second is as a correction for the scrollers.
+	 */
+	height= ((items*NLACHANNEL_STEP) + (NLACHANNEL_HEIGHT*2));
+	if (height > (v2d->mask.ymax - v2d->mask.ymin)) {
+		/* don't use totrect set, as the width stays the same 
+		 * (NOTE: this is ok here, the configuration is pretty straightforward) 
+		 */
+		v2d->tot.ymax= (float)(height);
+	}
+	
+	/* loop through channels, and set up drawing depending on their type  */	
+	y= (float)(-NLACHANNEL_FIRST);
+	
+	for (ale= anim_data.first; ale; ale= ale->next) {
+		const float yminc= (float)(y - NLACHANNEL_HEIGHT_HALF);
+		const float ymaxc= (float)(y + NLACHANNEL_HEIGHT_HALF);
+		
+		/* check if visible */
+		if ( IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
+			 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax) ) 
+		{
+			/* data to draw depends on the type of channel */
+			switch (ale->type) {
+				case ANIMTYPE_NLATRACK:
+				{
+					NlaTrack *nlt= (NlaTrack *)ale->data;
+					NlaStrip *strip;
+					
+					/* draw backdrop? */
+					// TODO...
+					
+					/* draw each strip in the track */
+					for (strip= nlt->strips.first; strip; strip= strip->next) {
+						/* 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);
+						}
+					}
+				}
+					break;
+					
+				case ANIMTYPE_NLAACTION:
+				{
+					/* just draw a semi-shaded rect spanning the width of the viewable area if there's data */
+					glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+					glEnable(GL_BLEND);
+					
+					if (ale->data)
+						glColor4f(0.8f, 0.2f, 0.0f, 0.4f);	// reddish color - hardcoded for now 
+					else
+						glColor4f(0.6f, 0.5f, 0.5f, 0.3f); 	// greyish-red color - hardcoded for now
+						
+					glBegin(GL_QUADS);
+						glVertex2f(v2d->cur.xmin, yminc);
+						glVertex2f(v2d->cur.xmin, ymaxc);
+						glVertex2f(v2d->cur.xmax, ymaxc);
+						glVertex2f(v2d->cur.xmax, yminc);
+					glEnd();
+					
+					glDisable(GL_BLEND);
+				}
+					break;
+			}
+		}
+		
+		/* adjust y-position for next one */
+		y += NLACHANNEL_STEP;
+	}
+	
+	/* free tempolary channels */
+	BLI_freelistN(&anim_data);
+}
+
 /* *********************************************** */
 /* Channel List */
 

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-05-29 22:55:06 UTC (rev 20510)
+++ branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_intern.h	2009-05-30 00:28:33 UTC (rev 20511)
@@ -49,6 +49,7 @@
 /* **************************************** */
 /* nla_draw.c */
 
+void draw_nla_main_data(bAnimContext *ac, SpaceNla *snla, ARegion *ar);
 void draw_nla_channel_list(bAnimContext *ac, SpaceNla *snla, ARegion *ar);
 
 /* **************************************** */

Added: branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_ops.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_ops.c	                        (rev 0)
+++ branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_ops.c	2009-05-30 00:28:33 UTC (rev 20511)
@@ -0,0 +1,121 @@
+/**
+ * $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 "DNA_anim_types.h"
+#include "DNA_action_types.h"
+#include "DNA_nla_types.h"
+#include "DNA_object_types.h"
+#include "DNA_space_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_windowmanager_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_report.h"
+#include "BKE_screen.h"
+
+#include "ED_anim_api.h"
+#include "ED_space_api.h"
+#include "ED_screen.h"
+
+#include "BIF_gl.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+#include "UI_view2d.h"
+
+#include "ED_markers.h"
+
+#include "nla_intern.h"	// own include
+
+
+/* ************************** registration - operator types **********************************/
+
+void nla_operatortypes(void)
+{
+	//WM_operatortype_append();
+	
+}
+
+/* ************************** registration - keymaps **********************************/
+
+static void nla_keymap_channels (wmWindowManager *wm, ListBase *keymap)
+{
+	//wmKeymapItem *kmi;
+	
+	
+	
+	/* transform system */
+	//transform_keymap_for_space(wm, keymap, SPACE_NLA);
+}
+
+static void nla_keymap_main (wmWindowManager *wm, ListBase *keymap)
+{
+	//wmKeymapItem *kmi;
+	
+	
+	
+	/* transform system */
+	//transform_keymap_for_space(wm, keymap, SPACE_NLA);
+}
+
+/* --------------- */
+
+void nla_keymap(wmWindowManager *wm)
+{
+	ListBase *keymap;
+	
+	/* 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
+	 * are many similarities with the other Animation Editors.
+	 *
+	 * 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);
+	nla_keymap_channels(wm, keymap);
+	
+	/* data */
+	keymap= WM_keymap_listbase(wm, "NLA_Data", SPACE_NLA, 0);
+	nla_keymap_main(wm, keymap);
+}
+

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-05-29 22:55:06 UTC (rev 20510)
+++ branches/soc-2009-aligorith/source/blender/editors/space_nla/space_nla.c	2009-05-30 00:28:33 UTC (rev 20511)
@@ -246,7 +246,7 @@
 	
 	/* data */
 	if (ANIM_animdata_get_context(C, &ac)) {
-		//draw_channel_strips(&ac, saction, ar);
+		draw_nla_main_data(&ac, snla, ar);
 	}
 	
 	/* current frame */

Modified: branches/soc-2009-aligorith/source/blender/makesdna/DNA_anim_types.h
===================================================================
--- branches/soc-2009-aligorith/source/blender/makesdna/DNA_anim_types.h	2009-05-29 22:55:06 UTC (rev 20510)
+++ branches/soc-2009-aligorith/source/blender/makesdna/DNA_anim_types.h	2009-05-30 00:28:33 UTC (rev 20511)
@@ -444,6 +444,8 @@

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list