static void draw_keylist(View2D *v2d, DLRBT_Tree *keys, DLRBT_Tree *blocks, float ypos, short channelLocked) { ActKeyColumn *ak; ActKeyBlock *ab; float alpha; float xscale; float iconsize = U.widget_unit / 4.0f; glEnable(GL_BLEND); /* get View2D scaling factor */ UI_view2d_scale_get(v2d, &xscale, NULL); /* locked channels are less strongly shown, as feedback for locked channels in DopeSheet */ /* TODO: allow this opacity factor to be themed? */ alpha = (channelLocked) ? 0.25f : 1.0f; /* draw keyblocks */ if (blocks) { float sel_color[4], unsel_color[4]; /* cache colours first */ UI_GetThemeColor4fv(TH_STRIP_SELECT, sel_color); UI_GetThemeColor4fv(TH_STRIP, unsel_color); sel_color[3] *= alpha; unsel_color[3] *= alpha; /* NOTE: the tradeoff for changing colors between each draw is dwarfed by the cost of checking validity */ for (ab = blocks->first; ab; ab = ab->next) { if (actkeyblock_is_valid(ab, keys)) { /* draw block */ if (ab->sel) glColor4fv(sel_color); else glColor4fv(unsel_color); glRectf(ab->start, ypos - iconsize, ab->end, ypos + iconsize); } } } /* draw keys */ if (keys) { for (ak = keys->first; ak; ak = ak->next) { /* optimization: if keyframe doesn't appear within 5 units (screenspace) in visible area, don't draw * - this might give some improvements, since we current have to flip between view/region matrices */ if (IN_RANGE_INCL(ak->cfra, v2d->cur.xmin, v2d->cur.xmax) == 0) continue; /* draw using OpenGL - uglier but faster */ /* NOTE1: a previous version of this didn't work nice for some intel cards * NOTE2: if we wanted to go back to icons, these are icon = (ak->sel & SELECT) ? ICON_SPACE2 : ICON_SPACE3; */ draw_keyframe_shape(ak->cfra, ypos, xscale, iconsize, (ak->sel & SELECT), ak->key_type, KEYFRAME_SHAPE_BOTH, alpha); } } glDisable(GL_BLEND); }
/* get frame on which the "hold" for the bone ends * XXX: this may not really work that well if a bone moves on some channels and not others * if this happens to be a major issue, scrap this, and just make this happen * independently per F-Curve */ static float pose_propagate_get_boneHoldEndFrame(Object *ob, tPChanFCurveLink *pfl, float startFrame) { DLRBT_Tree keys, blocks; ActKeyBlock *ab; AnimData *adt = ob->adt; LinkData *ld; float endFrame = startFrame; /* set up optimized data-structures for searching for relevant keyframes + holds */ BLI_dlrbTree_init(&keys); BLI_dlrbTree_init(&blocks); for (ld = pfl->fcurves.first; ld; ld = ld->next) { FCurve *fcu = (FCurve *)ld->data; fcurve_to_keylist(adt, fcu, &keys, &blocks); } BLI_dlrbTree_linkedlist_sync(&keys); BLI_dlrbTree_linkedlist_sync(&blocks); /* find the long keyframe (i.e. hold), and hence obtain the endFrame value * - the best case would be one that starts on the frame itself */ ab = (ActKeyBlock *)BLI_dlrbTree_search_exact(&blocks, compare_ab_cfraPtr, &startFrame); if (actkeyblock_is_valid(ab, &keys) == 0) { /* There are only two cases for no-exact match: * 1) the current frame is just before another key but not on a key itself * 2) the current frame is on a key, but that key doesn't link to the next * * If we've got the first case, then we can search for another block, * otherwise forget it, as we'd be overwriting some valid data. */ if (BLI_dlrbTree_search_exact(&keys, compare_ak_cfraPtr, &startFrame) == NULL) { /* we've got case 1, so try the one after */ ab = (ActKeyBlock *)BLI_dlrbTree_search_next(&blocks, compare_ab_cfraPtr, &startFrame); if (actkeyblock_is_valid(ab, &keys) == 0) { /* try the block before this frame then as last resort */ ab = (ActKeyBlock *)BLI_dlrbTree_search_prev(&blocks, compare_ab_cfraPtr, &startFrame); /* whatever happens, stop searching now... */ if (actkeyblock_is_valid(ab, &keys) == 0) { /* restrict range to just the frame itself * i.e. everything is in motion, so no holds to safely overwrite */ ab = NULL; } } } else { /* we've got case 2 - set ab to NULL just in case, since we shouldn't do anything in this case */ ab = NULL; } } /* check if we can go any further than we've already gone */ if (ab) { /* go to next if it is also valid and meets "extension" criteria */ while (ab->next) { ActKeyBlock *abn = (ActKeyBlock *)ab->next; /* must be valid */ if (actkeyblock_is_valid(abn, &keys) == 0) break; /* should start on the same frame that the last ended on */ if (ab->end != abn->start) break; /* should have the same number of curves */ if (ab->totcurve != abn->totcurve) break; /* should have the same value * XXX: this may be a bit fuzzy on larger data sets, so be careful */ if (ab->val != abn->val) break; /* we can extend the bounds to the end of this "next" block now */ ab = abn; } /* end frame can now take the value of the end of the block */ endFrame = ab->end; } /* free temp memory */ BLI_dlrbTree_free(&keys); BLI_dlrbTree_free(&blocks); /* return the end frame we've found */ return endFrame; }