diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-07-20 20:21:55 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-07-20 20:21:55 +0400 |
commit | 33bfd7397b8b0031bd2cf46d2037a8da4ef40888 (patch) | |
tree | b956392c96cc696052ef1fc46279f02d84e6adf8 /source/blender/blenkernel/intern | |
parent | cc69f1301387ea920a225b6eb49283e3c03e1b06 (diff) |
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.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/property.c | 64 |
1 files changed, 56 insertions, 8 deletions
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 <stdio.h> #include <stdlib.h> #include <string.h> +#include <ctype.h> #ifdef HAVE_CONFIG_H #include <config.h> @@ -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; |