Minor Code Cleanup (ShapeKeys):

Added a new API method for ShapeKeys, which is useful for finding a certain KeyBlock from a Key.
This commit is contained in:
2007-08-22 10:07:42 +00:00
parent 59016f9f5d
commit f237a466c1
5 changed files with 41 additions and 28 deletions

View File

@@ -59,6 +59,7 @@ int do_ob_key(struct Object *ob);
struct Key *ob_get_key(struct Object *ob);
struct KeyBlock *ob_get_keyblock(struct Object *ob);
struct KeyBlock *key_get_keyblock(struct Key *key, int index);
#endif

View File

@@ -1386,3 +1386,23 @@ KeyBlock *ob_get_keyblock(Object *ob)
return NULL;
}
/* get the appropriate KeyBlock given an index */
KeyBlock *key_get_keyblock(Key *key, int index)
{
KeyBlock *kb;
int i;
if (key) {
kb= key->block.first;
for (i= 1; i < key->totkey; i++) {
kb= kb->next;
if (index==i)
return kb;
}
}
return NULL;
}

View File

@@ -160,14 +160,14 @@ static void meshactionbuts(SpaceAction *saction, Object *ob, Key *key)
glRects(NAMEWIDTH, 0, NAMEWIDTH+SLIDERWIDTH, curarea->winy);
uiBlockSetEmboss(block, UI_EMBOSS);
for (i=1 ; i < key->totkey ; ++ i) {
for (i=1; i < key->totkey; i++) {
make_rvk_slider(block, ob, i,
x, y, SLIDERWIDTH-2, CHANNELHEIGHT-1, "Slider to control Shape Keys");
y-=CHANNELHEIGHT+CHANNELSKIP;
/* see sliderval array in editkey.c */
if(i>=255) break;
if(i >= 255) break;
}
}
uiDrawBlock(block);

View File

@@ -1652,20 +1652,20 @@ static void clever_keyblock_names (Key *key, short *mval)
* an invalid key number (and we don't deal
* with the speed ipo).
*/
keynum = get_nearest_key_num(key, mval, &x);
if ( (keynum < 1) || (keynum >= key->totkey) )
return;
kb= key->block.first;
for (i=0; i<keynum; ++i) kb = kb->next;
if (kb->name[0] == '\0') {
kb= key_get_keyblock(key, keynum);
if (kb == NULL)
return;
if (kb->name[0] == '\0')
sprintf(str, "Key %d", keynum);
}
else {
else
strcpy(str, kb->name);
}
if ( (kb->slidermin >= kb->slidermax) ) {
kb->slidermin = 0.0;

View File

@@ -148,24 +148,16 @@ char *getname_ipocurve(IpoCurve *icu, Object *ob)
{
static char name[32];
Key *key= ob_get_key(ob);
KeyBlock *kb= key_get_keyblock(key, icu->adrcode);
if (key) {
KeyBlock *kb= key->block.first;
int i;
for (i= 1; i < key->totkey; i++) {
kb= kb->next;
if (icu->adrcode == i) {
/* only return name if it has been set, otherwise use
* default method using static string (Key #)
*/
if (kb->name[0] == '\0')
break; /* stop looping through keyblocks */
else
return kb->name; /* return keyblock's name */
}
}
if (kb) {
/* only return name if it has been set, otherwise use
* default method using static string (Key #)
*/
if (kb->name[0] == '\0')
break; /* stop looping through keyblocks */
else
return kb->name; /* return keyblock's name */
}
/* in case keyblock is not named or no key/keyblock was found */