Changeset 824
- Timestamp:
- 11/25/18 20:08:56 (6 years ago)
- Location:
- cpp/frams/param
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/param/mutableparam.cpp
r792 r824 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 5Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2018 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 8 8 #define FIELDSTRUCT MutableParam 9 9 ParamEntry MutableParam::pe_tab[] = 10 { 10 { //TODO: these names are visible for scripts in ExpProperties, ShowProperties, etc. add some reserved prefix to avoid conflicts with script-defined properties! 11 11 { "clear", 0, PARAM_DONTSAVE | PARAM_USERHIDDEN, "remove all properties", "p", PROCEDURE(p_clear), }, 12 12 { "add", 0, PARAM_DONTSAVE | PARAM_USERHIDDEN, "add property (id,type,name,help)", "p", PROCEDURE(p_addprop), }, 13 13 { "remove", 0, PARAM_DONTSAVE | PARAM_USERHIDDEN, "remove property (index)", "p", PROCEDURE(p_remprop), }, 14 { "change", 0, PARAM_DONTSAVE | PARAM_USERHIDDEN, "change property (id,type,name,flags,help)", "p", PROCEDURE(p_changeprop), }, 14 15 { "addGroup", 0, PARAM_DONTSAVE | PARAM_USERHIDDEN, "add group (name)", "p", PROCEDURE(p_addgroup), }, 15 16 { "removeGroup", 0, PARAM_DONTSAVE | PARAM_USERHIDDEN, "remove group (index)", "p", PROCEDURE(p_remgroup), }, … … 133 134 if (d && (pe->flags & MUTPARAM_ALLOCDATA)) 134 135 switch (pe->type[0]) 135 {136 { 136 137 case 'd': delete (paInt*)d; break; 137 138 case 'f': delete (double*)d; break; … … 139 140 case 'x': delete (ExtValue*)d; break; 140 141 case 'o': delete (ExtObject*)d; break; 141 }142 } 142 143 entries -= i - staticprops; 143 144 if (pe->flags & MUTPARAM_ALLOCENTRY) … … 184 185 } 185 186 187 static void changeString(const char* (&s), const char* newstr) 188 { 189 if ((newstr != NULL) && (newstr[0] == 0)) newstr = NULL; 190 if ((s == NULL) && (newstr == NULL)) return; 191 if ((s != NULL) && (newstr != NULL) && (strcmp(s, newstr) == 0)) return; 192 if (s != NULL) { free((void*)s); s = NULL; } 193 if (newstr != NULL) s = strdup(newstr); 194 } 195 196 bool MutableParam::changeProperty(int i, const char* id, const char* type, const char* name, const char* help, int flags, int group) 197 { 198 ParamEntry *pe = entry(i); 199 if ((!id) && (!type)) return false; 200 if (!isValidTypeDescription(type)) return false; 201 pe->group = (paInt)group; 202 pe->flags = (pe->flags & (MUTPARAM_ALLOCENTRY | MUTPARAM_ALLOCDATA)) | (flags & ~(MUTPARAM_ALLOCENTRY | MUTPARAM_ALLOCDATA)); 203 changeString(pe->id, id); 204 changeString(pe->name, name); 205 changeString(pe->type, type); 206 changeString(pe->help, help); 207 onchange.action(i); 208 return true; 209 } 210 186 211 void MutableParam::p_addprop(ExtValue *args, ExtValue *ret) 187 212 { 188 213 int i = addProperty(0, args[2].getString().c_str(), args[1].getString().c_str(), args[0].getString().c_str()); 189 214 ret->setInt(i); 215 } 216 217 void MutableParam::p_changeprop(ExtValue *args, ExtValue *ret) 218 { 219 int i = findId(args[4].getString().c_str()); 220 if (i >= staticprops) 221 { 222 changeProperty(i, args[4].getString().c_str(), args[3].getString().c_str(), args[2].getString().c_str(), args[0].getString().c_str(), args[1].getInt(), entry(i)->group); 223 ret->setInt(i); 224 } 225 else 226 ret->setEmpty(); 190 227 } 191 228 -
cpp/frams/param/mutableparam.h
r737 r824 16 16 class MutableParam : public SimpleAbstractParam, public MutableParamInterface 17 17 { 18 static const int staticprops = 7;18 static const int staticprops = 8; 19 19 static ParamEntry pe_tab[]; 20 20 /** group #0 cannot be removed by scripting */ … … 52 52 ParamEntry * removeProperty(int i); 53 53 54 bool changeProperty(int i, const char* id, const char* type, const char* name, const char* help, int flags, int group); 55 54 56 void notify(int id); 55 57 … … 64 66 PARAMPROCDEF(p_addprop); 65 67 PARAMPROCDEF(p_remprop); 68 PARAMPROCDEF(p_changeprop); 66 69 PARAMPROCDEF(p_addgroup); 67 70 PARAMPROCDEF(p_remgroup);
Note: See TracChangeset
for help on using the changeset viewer.