[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [35590] trunk/blender: Bugfix [#26505] zoom in selected keys on graph editor
Joshua Leung
aligorith at gmail.com
Thu Mar 17 11:02:37 CET 2011
Revision: 35590
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35590
Author: aligorith
Date: 2011-03-17 10:02:37 +0000 (Thu, 17 Mar 2011)
Log Message:
-----------
Bugfix [#26505] zoom in selected keys on graph editor
Not really a "bug", but it was on my todo anyways. Based on patch
[#26508] by Campbell, with a few modifications including extending
this to the Action/DopeSheet editor too.
Modified Paths:
--------------
trunk/blender/release/scripts/ui/space_dopesheet.py
trunk/blender/release/scripts/ui/space_graph.py
trunk/blender/source/blender/blenkernel/BKE_fcurve.h
trunk/blender/source/blender/blenkernel/intern/action.c
trunk/blender/source/blender/blenkernel/intern/fcurve.c
trunk/blender/source/blender/blenlib/BLI_utildefines.h
trunk/blender/source/blender/editors/space_action/action_edit.c
trunk/blender/source/blender/editors/space_action/action_intern.h
trunk/blender/source/blender/editors/space_action/action_ops.c
trunk/blender/source/blender/editors/space_graph/graph_edit.c
trunk/blender/source/blender/editors/space_graph/graph_intern.h
trunk/blender/source/blender/editors/space_graph/graph_ops.c
trunk/blender/source/blender/editors/space_graph/space_graph.c
trunk/blender/source/blender/makesrna/intern/rna_fcurve.c
Modified: trunk/blender/release/scripts/ui/space_dopesheet.py
===================================================================
--- trunk/blender/release/scripts/ui/space_dopesheet.py 2011-03-17 09:09:48 UTC (rev 35589)
+++ trunk/blender/release/scripts/ui/space_dopesheet.py 2011-03-17 10:02:37 UTC (rev 35590)
@@ -159,6 +159,7 @@
layout.separator()
layout.operator("action.frame_jump")
layout.operator("action.view_all")
+ layout.operator("action.view_selected")
layout.separator()
layout.operator("screen.area_dupli")
Modified: trunk/blender/release/scripts/ui/space_graph.py
===================================================================
--- trunk/blender/release/scripts/ui/space_graph.py 2011-03-17 09:09:48 UTC (rev 35589)
+++ trunk/blender/release/scripts/ui/space_graph.py 2011-03-17 10:02:37 UTC (rev 35590)
@@ -100,6 +100,7 @@
layout.separator()
layout.operator("graph.frame_jump")
layout.operator("graph.view_all")
+ layout.operator("graph.view_selected")
layout.separator()
layout.operator("screen.area_dupli")
Modified: trunk/blender/source/blender/blenkernel/BKE_fcurve.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_fcurve.h 2011-03-17 09:09:48 UTC (rev 35589)
+++ trunk/blender/source/blender/blenkernel/BKE_fcurve.h 2011-03-17 10:02:37 UTC (rev 35590)
@@ -215,10 +215,10 @@
int binarysearch_bezt_index(struct BezTriple array[], float frame, int arraylen, short *replace);
/* get the time extents for F-Curve */
-void calc_fcurve_range(struct FCurve *fcu, float *min, float *max);
+void calc_fcurve_range(struct FCurve *fcu, float *min, float *max, const short selOnly);
/* get the bounding-box extents for F-Curve */
-void calc_fcurve_bounds(struct FCurve *fcu, float *xmin, float *xmax, float *ymin, float *ymax);
+void calc_fcurve_bounds(struct FCurve *fcu, float *xmin, float *xmax, float *ymin, float *ymax, const short selOnly);
/* .............. */
Modified: trunk/blender/source/blender/blenkernel/intern/action.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/action.c 2011-03-17 09:09:48 UTC (rev 35589)
+++ trunk/blender/source/blender/blenkernel/intern/action.c 2011-03-17 10:02:37 UTC (rev 35590)
@@ -867,7 +867,8 @@
float nmin, nmax;
/* get extents for this curve */
- calc_fcurve_range(fcu, &nmin, &nmax);
+ // TODO: allow enabling/disabling this?
+ calc_fcurve_range(fcu, &nmin, &nmax, FALSE);
/* compare to the running tally */
min= MIN2(min, nmin);
Modified: trunk/blender/source/blender/blenkernel/intern/fcurve.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/fcurve.c 2011-03-17 09:09:48 UTC (rev 35589)
+++ trunk/blender/source/blender/blenkernel/intern/fcurve.c 2011-03-17 10:02:37 UTC (rev 35590)
@@ -426,8 +426,52 @@
return start;
}
+/* ...................................... */
+
+/* helper for calc_fcurve_* functions -> find first and last BezTriple to be used */
+static void get_fcurve_end_keyframes (FCurve *fcu, BezTriple **first, BezTriple **last, const short selOnly)
+{
+ /* init outputs */
+ *first = NULL;
+ *last = NULL;
+
+ /* sanity checks */
+ if (fcu->bezt == NULL)
+ return;
+
+ /* only include selected items? */
+ if (selOnly) {
+ BezTriple *bezt;
+ unsigned int i;
+
+ /* find first selected */
+ bezt = fcu->bezt;
+ for (i=0; i < fcu->totvert; bezt++, i++) {
+ if (BEZSELECTED(bezt)) {
+ *first= bezt;
+ break;
+ }
+ }
+
+ /* find last selected */
+ bezt = ARRAY_LAST_ITEM(fcu->bezt, BezTriple, sizeof(BezTriple), fcu->totvert);
+ for (i=0; i < fcu->totvert; bezt--, i++) {
+ if (BEZSELECTED(bezt)) {
+ *last= bezt;
+ break;
+ }
+ }
+ }
+ else {
+ /* just full array */
+ *first = fcu->bezt;
+ *last = ARRAY_LAST_ITEM(fcu->bezt, BezTriple, sizeof(BezTriple), fcu->totvert);
+ }
+}
+
+
/* Calculate the extents of F-Curve's data */
-void calc_fcurve_bounds (FCurve *fcu, float *xmin, float *xmax, float *ymin, float *ymax)
+void calc_fcurve_bounds (FCurve *fcu, float *xmin, float *xmax, float *ymin, float *ymax, const short selOnly)
{
float xminv=999999999.0f, xmaxv=-999999999.0f;
float yminv=999999999.0f, ymaxv=-999999999.0f;
@@ -436,21 +480,31 @@
if (fcu->totvert) {
if (fcu->bezt) {
- /* frame range can be directly calculated from end verts */
+ BezTriple *bezt_first= NULL, *bezt_last= NULL;
+
if (xmin || xmax) {
- xminv= MIN2(xminv, fcu->bezt[0].vec[1][0]);
- xmaxv= MAX2(xmaxv, fcu->bezt[fcu->totvert-1].vec[1][0]);
+ /* get endpoint keyframes */
+ get_fcurve_end_keyframes(fcu, &bezt_first, &bezt_last, selOnly);
+
+ if (bezt_first) {
+ BLI_assert(bezt_last != NULL);
+
+ xminv= MIN2(xminv, bezt_first->vec[1][0]);
+ xmaxv= MAX2(xmaxv, bezt_last->vec[1][0]);
+ }
}
/* only loop over keyframes to find extents for values if needed */
- if (ymin || ymax) {
+ if (ymin || ymax) {
BezTriple *bezt;
for (bezt=fcu->bezt, i=0; i < fcu->totvert; bezt++, i++) {
- if (bezt->vec[1][1] < yminv)
- yminv= bezt->vec[1][1];
- if (bezt->vec[1][1] > ymaxv)
- ymaxv= bezt->vec[1][1];
+ if ((selOnly == 0) || BEZSELECTED(bezt)) {
+ if (bezt->vec[1][1] < yminv)
+ yminv= bezt->vec[1][1];
+ if (bezt->vec[1][1] > ymaxv)
+ ymaxv= bezt->vec[1][1];
+ }
}
}
}
@@ -497,15 +551,24 @@
}
/* Calculate the extents of F-Curve's keyframes */
-void calc_fcurve_range (FCurve *fcu, float *start, float *end)
+void calc_fcurve_range (FCurve *fcu, float *start, float *end, const short selOnly)
{
float min=999999999.0f, max=-999999999.0f;
short foundvert=0;
if (fcu->totvert) {
if (fcu->bezt) {
- min= MIN2(min, fcu->bezt[0].vec[1][0]);
- max= MAX2(max, fcu->bezt[fcu->totvert-1].vec[1][0]);
+ BezTriple *bezt_first= NULL, *bezt_last= NULL;
+
+ /* get endpoint keyframes */
+ get_fcurve_end_keyframes(fcu, &bezt_first, &bezt_last, selOnly);
+
+ if (bezt_first) {
+ BLI_assert(bezt_last != NULL);
+
+ min= MIN2(min, bezt_first->vec[1][0]);
+ max= MAX2(max, bezt_last->vec[1][0]);
+ }
}
else if (fcu->fpt) {
min= MIN2(min, fcu->fpt[0].vec[0]);
Modified: trunk/blender/source/blender/blenlib/BLI_utildefines.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_utildefines.h 2011-03-17 09:09:48 UTC (rev 35589)
+++ trunk/blender/source/blender/blenlib/BLI_utildefines.h 2011-03-17 10:02:37 UTC (rev 35590)
@@ -130,6 +130,9 @@
#define IN_RANGE(a, b, c) ((b < c)? ((b<a && a<c)? 1:0) : ((c<a && a<b)? 1:0))
#define IN_RANGE_INCL(a, b, c) ((b < c)? ((b<=a && a<=c)? 1:0) : ((c<=a && a<=b)? 1:0))
+/* array helpers */
+#define ARRAY_LAST_ITEM(arr_start, arr_dtype, elem_size, tot) (arr_dtype *)((char*)arr_start + (elem_size*tot))
+#define ARRAY_HAS_ITEM(item, arr_start, arr_dtype, elem_size, tot) ((item >= arr_start) && (item <= ARRAY_LAST_ITEM(arr_start, arr_dtype, elem_size, tot)))
/* This one rotates the bytes in an int64, int (32) and short (16) */
#define SWITCH_INT64(a) { \
Modified: trunk/blender/source/blender/editors/space_action/action_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_action/action_edit.c 2011-03-17 09:09:48 UTC (rev 35589)
+++ trunk/blender/source/blender/editors/space_action/action_edit.c 2011-03-17 10:02:37 UTC (rev 35590)
@@ -227,7 +227,7 @@
/* *************************** Calculate Range ************************** */
/* Get the min/max keyframes*/
-static void get_keyframe_extents (bAnimContext *ac, float *min, float *max)
+static void get_keyframe_extents (bAnimContext *ac, float *min, float *max, const short onlySel)
{
ListBase anim_data = {NULL, NULL};
bAnimListElem *ale;
@@ -249,8 +249,8 @@
FCurve *fcu= (FCurve *)ale->key_data;
float tmin, tmax;
- /* get range and apply necessary scaling before */
- calc_fcurve_range(fcu, &tmin, &tmax);
+ /* get range and apply necessary scaling before processing */
+ calc_fcurve_range(fcu, &tmin, &tmax, onlySel);
if (adt) {
tmin= BKE_nla_tweakedit_remap(adt, tmin, NLATIME_CONVERT_MAP);
@@ -295,7 +295,7 @@
scene= ac.scene;
/* set the range directly */
- get_keyframe_extents(&ac, &min, &max);
+ get_keyframe_extents(&ac, &min, &max, FALSE);
scene->r.flag |= SCER_PRV_RANGE;
scene->r.psfra= (int)floor(min + 0.5f);
scene->r.pefra= (int)floor(max + 0.5f);
@@ -324,7 +324,7 @@
/* ****************** View-All Operator ****************** */
-static int actkeys_viewall_exec(bContext *C, wmOperator *UNUSED(op))
+static int actkeys_viewall(bContext *C, const short onlySel)
{
bAnimContext ac;
View2D *v2d;
@@ -336,7 +336,7 @@
v2d= &ac.ar->v2d;
/* set the horizontal range, with an extra offset so that the extreme keys will be in view */
- get_keyframe_extents(&ac, &v2d->cur.xmin, &v2d->cur.xmax);
+ get_keyframe_extents(&ac, &v2d->cur.xmin, &v2d->cur.xmax, onlySel);
extra= 0.1f * (v2d->cur.xmax - v2d->cur.xmin);
v2d->cur.xmin -= extra;
@@ -354,6 +354,20 @@
return OPERATOR_FINISHED;
}
+
+/* ......... */
+
+static int actkeys_viewall_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ /* whole range */
+ return actkeys_viewall(C, FALSE);
+}
+
+static int actkeys_viewsel_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ /* only selected */
+ return actkeys_viewall(C, TRUE);
+}
void ACTION_OT_view_all (wmOperatorType *ot)
{
@@ -370,6 +384,21 @@
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
+void ACTION_OT_view_selected (wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "View Selected";
+ ot->idname= "ACTION_OT_view_selected";
+ ot->description= "Reset viewable area to show selected keyframes range";
+
+ /* api callbacks */
+ ot->exec= actkeys_viewsel_exec;
+ ot->poll= ED_operator_action_active;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
/* ************************************************************************** */
/* GENERAL STUFF */
Modified: trunk/blender/source/blender/editors/space_action/action_intern.h
===================================================================
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list