Ignore:
Timestamp:
11/25/18 20:08:56 (6 years ago)
Author:
Maciej Komosinski
Message:

MutableParam? property definition can be changed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/param/mutableparam.cpp

    r792 r824  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    88#define FIELDSTRUCT MutableParam
    99ParamEntry 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!
    1111        { "clear", 0, PARAM_DONTSAVE | PARAM_USERHIDDEN, "remove all properties", "p", PROCEDURE(p_clear), },
    1212        { "add", 0, PARAM_DONTSAVE | PARAM_USERHIDDEN, "add property (id,type,name,help)", "p", PROCEDURE(p_addprop), },
    1313        { "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), },
    1415        { "addGroup", 0, PARAM_DONTSAVE | PARAM_USERHIDDEN, "add group (name)", "p", PROCEDURE(p_addgroup), },
    1516        { "removeGroup", 0, PARAM_DONTSAVE | PARAM_USERHIDDEN, "remove group (index)", "p", PROCEDURE(p_remgroup), },
     
    133134        if (d && (pe->flags & MUTPARAM_ALLOCDATA))
    134135                switch (pe->type[0])
    135         {
     136                {
    136137                case 'd': delete (paInt*)d; break;
    137138                case 'f': delete (double*)d; break;
     
    139140                case 'x': delete (ExtValue*)d; break;
    140141                case 'o': delete (ExtObject*)d; break;
    141         }
     142                }
    142143        entries -= i - staticprops;
    143144        if (pe->flags & MUTPARAM_ALLOCENTRY)
     
    184185}
    185186
     187static 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
     196bool 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
    186211void MutableParam::p_addprop(ExtValue *args, ExtValue *ret)
    187212{
    188213        int i = addProperty(0, args[2].getString().c_str(), args[1].getString().c_str(), args[0].getString().c_str());
    189214        ret->setInt(i);
     215}
     216
     217void 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();
    190227}
    191228
Note: See TracChangeset for help on using the changeset viewer.