diff options
author | Joshua Leung <aligorith@gmail.com> | 2009-07-08 16:30:09 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2009-07-08 16:30:09 +0400 |
commit | 5f5ddb00146884d28414811bc92311af56d55904 (patch) | |
tree | 6cd08b398d2f9cc721aff27ab4c69667cbcd86b0 /source | |
parent | 665938191df7e831ba22f101b00ab9b99bdde654 (diff) |
NLA SoC: Little optimisation + Drawing bugfix
* Text labels on NLA-Strips should now draw properly for most short-strips now. Previously, the padding on the text was a bit too extreme, so for very short strips (less than 4 frames or so), the text was often pushed down into the bottom-right corner of view.
* Optimised the keyframe-highlighting code for buttons a bit. Replaced the custom linear-search with the binary-search used when inserting keyframes (and for the 3d-view keyframe-indicator). There should be some theoretical improvements due to this at least...
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_fcurve.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/fcurve.c | 14 | ||||
-rw-r--r-- | source/blender/editors/animation/keyframing.c | 41 | ||||
-rw-r--r-- | source/blender/editors/include/ED_keyframing.h | 5 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_anim.c | 4 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_draw.c | 15 |
6 files changed, 43 insertions, 39 deletions
diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h index 4dcb08dc0df..cda64c6b241 100644 --- a/source/blender/blenkernel/BKE_fcurve.h +++ b/source/blender/blenkernel/BKE_fcurve.h @@ -153,9 +153,6 @@ void copy_fcurves(ListBase *dst, ListBase *src); /* find matching F-Curve in the given list of F-Curves */ struct FCurve *list_find_fcurve(ListBase *list, const char rna_path[], const int array_index); -/* test if there is a keyframe at cfra */ -short on_keyframe_fcurve(struct FCurve *fcu, float cfra); - /* get the time extents for F-Curve */ void calc_fcurve_range(struct FCurve *fcu, float *min, float *max); diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 4c2ba61fc71..ebd94b94f8c 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -200,20 +200,6 @@ FCurve *list_find_fcurve (ListBase *list, const char rna_path[], const int array return NULL; } -short on_keyframe_fcurve(FCurve *fcu, float cfra) -{ - BezTriple *bezt; - unsigned i; - - bezt= fcu->bezt; - for (i=0; i<fcu->totvert; i++, bezt++) { - if (IS_EQ(bezt->vec[1][0], cfra)) - return 1; - } - - return 0; -} - /* Calculate the extents of F-Curve's data */ void calc_fcurve_bounds (FCurve *fcu, float *xmin, float *xmax, float *ymin, float *ymax) { diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index ac195f42f03..dd4c4c23f1e 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -1430,6 +1430,31 @@ void ANIM_OT_delete_keyframe_button (wmOperatorType *ot) /* --------------- API/Per-Datablock Handling ------------------- */ +/* Checks if some F-Curve has a keyframe for a given frame */ +short fcurve_frame_has_keyframe (FCurve *fcu, float frame, short filter) +{ + /* quick sanity check */ + if (fcu == NULL) + return 0; + + /* we either include all regardless of muting, or only non-muted */ + if ((filter & ANIMFILTER_KEYS_MUTED) || (fcu->flag & FCURVE_MUTED)==0) { + short replace = -1; + int i = binarysearch_bezt_index(fcu->bezt, frame, fcu->totvert, &replace); + + /* binarysearch_bezt_index will set replace to be 0 or 1 + * - obviously, 1 represents a match + */ + if (replace) { + /* sanity check: 'i' may in rare cases exceed arraylen */ + if ((i >= 0) && (i < fcu->totvert)) + return 1; + } + } + + return 0; +} + /* Checks whether an Action has a keyframe for a given frame * Since we're only concerned whether a keyframe exists, we can simply loop until a match is found... */ @@ -1451,20 +1476,8 @@ short action_frame_has_keyframe (bAction *act, float frame, short filter) for (fcu= act->curves.first; fcu; fcu= fcu->next) { /* only check if there are keyframes (currently only of type BezTriple) */ if (fcu->bezt && fcu->totvert) { - /* we either include all regardless of muting, or only non-muted */ - if ((filter & ANIMFILTER_KEYS_MUTED) || (fcu->flag & FCURVE_MUTED)==0) { - short replace = -1; - int i = binarysearch_bezt_index(fcu->bezt, frame, fcu->totvert, &replace); - - /* binarysearch_bezt_index will set replace to be 0 or 1 - * - obviously, 1 represents a match - */ - if (replace) { - /* sanity check: 'i' may in rare cases exceed arraylen */ - if ((i >= 0) && (i < fcu->totvert)) - return 1; - } - } + if (fcurve_frame_has_keyframe(fcu, frame, filter)) + return 1; } } diff --git a/source/blender/editors/include/ED_keyframing.h b/source/blender/editors/include/ED_keyframing.h index ffebb42ce99..503d71b0d3e 100644 --- a/source/blender/editors/include/ED_keyframing.h +++ b/source/blender/editors/include/ED_keyframing.h @@ -199,6 +199,11 @@ void ANIM_OT_remove_driver_button(struct wmOperatorType *ot); /* ************ Keyframe Checking ******************** */ +/* Lesser Keyframe Checking API call: + * - Used for the buttons to check for keyframes... + */ +short fcurve_frame_has_keyframe(struct FCurve *fcu, float frame, short filter); + /* Main Keyframe Checking API call: * Checks whether a keyframe exists for the given ID-block one the given frame. * - It is recommended to call this method over the other keyframe-checkers directly, diff --git a/source/blender/editors/interface/interface_anim.c b/source/blender/editors/interface/interface_anim.c index 4a26db29160..be4087de525 100644 --- a/source/blender/editors/interface/interface_anim.c +++ b/source/blender/editors/interface/interface_anim.c @@ -18,6 +18,8 @@ #include "RNA_access.h" #include "RNA_types.h" +#include "ED_keyframing.h" + #include "UI_interface.h" #include "WM_api.h" @@ -47,7 +49,7 @@ void ui_but_anim_flag(uiBut *but, float cfra) if (fcu) { but->flag |= UI_BUT_ANIMATED; - if (on_keyframe_fcurve(fcu, cfra)) + if (fcurve_frame_has_keyframe(fcu, cfra, 0)) but->flag |= UI_BUT_ANIMATED_KEY; } } diff --git a/source/blender/editors/space_nla/nla_draw.c b/source/blender/editors/space_nla/nla_draw.c index 7b9f2faf08a..bbb666d01cc 100644 --- a/source/blender/editors/space_nla/nla_draw.c +++ b/source/blender/editors/space_nla/nla_draw.c @@ -291,6 +291,9 @@ static void nla_draw_strip (AnimData *adt, NlaTrack *nlt, NlaStrip *strip, View2 gl_round_box_shade(GL_POLYGON, strip->start, yminc, strip->end, ymaxc, 0.0, 0.5, 0.1); + /* draw influence 'curve' */ + // TODO: + /* draw strip outline * - color used here is to indicate active vs non-active */ @@ -378,11 +381,9 @@ static void nla_draw_strip_text (NlaTrack *nlt, NlaStrip *strip, int index, View case NLASTRIP_TYPE_CLIP: /* Action-Clip (default) */ default: - if (strip->act) - sprintf(str, "%d | Act: %s | %.2f %s %.2f", - index, strip->act->id.name+2, strip->start, dir, strip->end); - else - sprintf(str, "%d | Act: <NONE>", index); // xxx... need a better format? + sprintf(str, "%d | Act: %s | %.2f %s %.2f", + index, ((strip->act)?strip->act->id.name+2:"<NONE>"), + strip->start, dir, strip->end); break; } @@ -396,9 +397,9 @@ static void nla_draw_strip_text (NlaTrack *nlt, NlaStrip *strip, int index, View * - padding of 2 'units' on either side */ // TODO: make this centered? - rect.xmin= strip->start + 2; + rect.xmin= strip->start + 0.5f; rect.ymin= yminc; - rect.xmax= strip->end - 2; + rect.xmax= strip->end - 0.5f; rect.ymax= ymaxc; /* add this string to the cache of texts to draw*/ |