From 33bfd7397b8b0031bd2cf46d2037a8da4ef40888 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 20 Jul 2009 16:21:55 +0000 Subject: BGE Button types panel, can edit existing buttons but not add new ones yet. World Physics panel too though Im not sure if we'll eventually move this into another struct. --- source/blender/blenkernel/intern/property.c | 64 +++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 8 deletions(-) (limited to 'source/blender/blenkernel/intern/property.c') diff --git a/source/blender/blenkernel/intern/property.c b/source/blender/blenkernel/intern/property.c index 261b58454bd..5cae527957b 100644 --- a/source/blender/blenkernel/intern/property.c +++ b/source/blender/blenkernel/intern/property.c @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef HAVE_CONFIG_H #include @@ -99,25 +100,18 @@ void init_property(bProperty *prop) if(prop->poin && prop->poin != &prop->data) MEM_freeN(prop->poin); prop->poin= 0; - prop->otype= prop->type; prop->data= 0; switch(prop->type) { case GPROP_BOOL: - prop->poin= &prop->data; - break; case GPROP_INT: - prop->poin= &prop->data; - break; case GPROP_FLOAT: + case GPROP_TIME: prop->poin= &prop->data; break; case GPROP_STRING: prop->poin= MEM_callocN(MAX_PROPSTRING, "property string"); break; - case GPROP_TIME: - prop->poin= &prop->data; - break; } } @@ -136,6 +130,60 @@ bProperty *new_property(int type) return prop; } +/* used by unique_property() only */ +static bProperty *get_property__internal(bProperty *first, bProperty *self, const char *name) +{ + bProperty *p; + for(p= first; p; p= p->next) { + if (p!=self && (strcmp(p->name, name)==0)) + return p; + } + return NULL; +} +void unique_property(bProperty *first, bProperty *prop, int force) +{ + bProperty *p; + + /* set the first if its not set */ + if(first==NULL) { + first= prop; + while(first->prev) { + first= first->prev; + } + } + + if(force) { + /* change other names to make them unique */ + while((p = get_property__internal(first, prop, prop->name))) { + unique_property(first, p, 0); + } + }else { + /* change our own name until its unique */ + if(get_property__internal(first, prop, prop->name)) { + /* there is a collision */ + char new_name[sizeof(prop->name)]; + char base_name[sizeof(prop->name)]; + char num[sizeof(prop->name)]; + int i= 0; + + /* strip numbers */ + strcpy(base_name, prop->name); + for(i= strlen(base_name)-1; (i>=0 && isdigit(base_name[i])); i--) { + base_name[i]= '\0'; + } + i= 0; + + do { /* ensure we have enough chars for the new number in the name */ + sprintf(num, "%d", i++); + BLI_strncpy(new_name, base_name, sizeof(prop->name) - strlen(num)); + strcat(new_name, num); + } while(get_property__internal(first, prop, new_name)); + + strcpy(prop->name, new_name); + } + } +} + bProperty *get_ob_property(Object *ob, char *name) { bProperty *prop; -- cgit v1.2.3