9 QObject(parent), _script(0), _map(map),
10 repeatTime(0), kpRepeatTime(0), stopTime(0), kpStopTime(0), repeatMsec(0), kpRepeatMsec(0),
11 _guid(id), _isActive(false), _isActiveKp(false), _needsSave(false)
16 if(!settings.
value(
"UseRealNames").toBool()){
17 QMutableListIterator<QString> i(_keys);
20 QString&
key = i.value();
24 _name = settings.
value(
"Name").toString().trimmed();
31 _mode = (
Mode)metaObject()->enumerator(metaObject()->indexOfEnumerator(
"Mode")).keysToValue(settings.
value(
"BlendMode").toString().toLatin1(), &modeOk);
37 SGroup group(settings,
"Parameters");
38 foreach(
const QString& param, settings.
childKeys())
67 settings.
setValue(
"UseRealNames",
true);
71 settings.
setValue(
"BlendMode", metaObject()->enumerator(metaObject()->indexOfEnumerator(
"Mode")).valueToKey(
_mode));
78 settings.
setValue(i.key(), i.value());
86 _script(
AnimScript::copy(this, script->guid())), _map(map), _keys(keys),
87 repeatTime(0), kpRepeatTime(0), stopTime(0), kpStopTime(0), repeatMsec(0), kpRepeatMsec(0),
88 _guid(QUuid::createUuid()), _name(name), _opacity(1.), _mode(Normal), _isActive(false), _isActiveKp(false), _needsSave(true)
106 _script(
AnimScript::copy(this, other.script()->guid())), _scriptGuid(_script->guid()), _scriptName(_script->name()),
107 _map(map), _keys(other._keys), _parameters(other._parameters),
108 repeatTime(0), kpRepeatTime(0), stopTime(0), kpStopTime(0), repeatMsec(0), kpRepeatMsec(0),
109 _guid(other._guid), _name(other._name), _opacity(other._opacity), _mode(other._mode), _isActive(false), _isActiveKp(false), _needsSave(true)
144 res[i.key()] = i .value();
171 if(!parameters.contains(
"repeat")){
182 if(!parameters.contains(
"kprepeat")){
215 if(parameters.value(
"trigger").toBool() || ignoreParameter){
217 int delay = round(parameters.value(
"delay").toDouble() * 1000.);
225 int repeat = round(parameters.value(
"repeat").toDouble() * 1000.);
229 double stop = parameters.value(
"stop").toDouble();
233 stopTime = timestamp + round(stop * 1000.);
239 int stop = parameters.value(
"stop").toInt();
254 if(pressed && parameters.value(
"kpmodestop").toBool()){
261 if(!parameters.value(
"kptrigger").toBool())
269 if(parameters.value(
"kpmode", 0).toInt() == 2 &&
isActive())
272 int delay = round(parameters.value(
"kpdelay").toDouble() * 1000.);
280 int repeat = round(parameters.value(
"kprepeat").toDouble() * 1000.);
284 double stop = parameters.value(
"kpstop").toDouble();
294 int stop = parameters.value(
"kpstop").toInt();
305 if(parameters.value(
"kprelease").toBool())
374 int blendMode = (int)
_mode;
379 int count = animMap.
count();
380 if(scriptMap.
count() != count){
381 qDebug() <<
"Script map didn't match base map (" << count <<
" vs " << scriptMap.
count() <<
"). This should never happen.";
384 QRgb* background = animMap.
colors();
385 const QRgb* foreground = scriptMap.
colors();
386 for(
int i = 0; i < count; i++){
388 QRgb& bg = background[i];
389 QRgb fg = foreground[i];
390 int alpha = qAlpha(fg);
399 float r = qRed(bg), g = qGreen(bg), b = qBlue(bg);
400 float a = alpha * fOpacity;
401 r = r * (1.f - a) + qRed(fg) * a;
402 g = g * (1.f - a) + qGreen(fg) * a;
403 b = b * (1.f - a) + qBlue(fg) * a;
404 bg = qRgb(round(r), round(g), round(b));
408 float r = qRed(bg) / 255.f, g = qGreen(bg) / 255.f, b = qBlue(bg) / 255.f;
409 float a = alpha * fOpacity;
410 r = r * (1.f - a) +
blend(r, qRed(fg) / 255.f) * a;
411 g = g * (1.f - a) +
blend(g, qGreen(fg) / 255.f) * a;
412 b = b * (1.f - a) +
blend(b, qBlue(fg) / 255.f) * a;
413 bg = qRgb(round(r * 255.f), round(g * 255.f), round(b * 255.f));
void setValue(const QString &key, const QVariant &value)
Param param(const QString &name) const
QStringList childKeys() const
const QStringList & keys()
void catchUp(quint64 timestamp)
static float blendAdd(float bg, float fg)
void retrigger(quint64 timestamp, bool allowPreempt=false)
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
QMap< QString, QVariant > _parameters
void frame(quint64 timestamp)
void trigger(quint64 timestamp, bool ignoreParameter=false)
static float blendNormal(float bg, float fg)
const QString & name() const
static blendFunc functions[5]
const ColorMap & colors() const
QString fromStorage(const QString &storage)
static float blendMultiply(float bg, float fg)
void save(CkbSettings &settings)
bool hasParam(const QString &name) const
static float blendDivide(float bg, float fg)
QMap< QString, QVariant > effectiveParams()
void beginGroup(const QString &prefix)
static float blendSubtract(float bg, float fg)
KbAnim(QObject *parent, const KeyMap &map, const QUuid id, CkbSettings &settings)
float(* blendFunc)(float, float)
void init(const KeyMap &map, const QStringList &keys, const QMap< QString, QVariant > ¶mValues)
void keypress(const QString &key, bool pressed, quint64 timestamp)
const QString & name() const
static AnimScript * copy(QObject *parent, const QUuid &id)
QListIterator< Param > paramIterator() const
const QUuid & guid() const
QMap< QString, QVariant > _tempParameters
void keypress(const QString &key, bool pressed, quint64 timestamp)
void parameters(const QMap< QString, QVariant > ¶mValues)
void blend(ColorMap &animMap, quint64 timestamp)
QVariant parameter(const QString &name) const
void stop(quint64 timestamp)