ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
KbAnim Class Reference

#include <src/ckb/kbanim.h>

+ Inheritance diagram for KbAnim:
+ Collaboration diagram for KbAnim:

Public Types

enum  Mode {
  Normal, Add, Subtract, Multiply,
  Divide
}
 

Public Member Functions

 KbAnim (QObject *parent, const KeyMap &map, const QUuid id, CkbSettings &settings)
 
void save (CkbSettings &settings)
 
bool needsSave () const
 
 KbAnim (QObject *parent, const KeyMap &map, const QString &name, const QStringList &keys, const AnimScript *script)
 
 KbAnim (QObject *parent, const KeyMap &map, const KbAnim &other)
 
const KeyMapmap ()
 
void map (const KeyMap &newMap)
 
const QStringList & keys ()
 
void keys (const QStringList &newKeys)
 
bool hasParameter (const QString &name) const
 
QVariant parameter (const QString &name) const
 
void parameter (const QString &name, const QVariant &value)
 
void commitParams ()
 
void resetParams ()
 
void reInit ()
 
void trigger (quint64 timestamp, bool ignoreParameter=false)
 
void keypress (const QString &key, bool pressed, quint64 timestamp)
 
void stop ()
 
bool isActive () const
 
bool isRunning () const
 
void blend (ColorMap &animMap, quint64 timestamp)
 
const QUuid & guid () const
 
void newId ()
 
const QString & name () const
 
void name (const QString &newName)
 
float opacity () const
 
void opacity (float newOpacity)
 
Mode mode () const
 
void mode (Mode newMode)
 
const AnimScriptscript () const
 
const QString & scriptName () const
 

Private Member Functions

QMap< QString, QVariant > effectiveParams ()
 
void updateParams ()
 
void catchUp (quint64 timestamp)
 

Private Attributes

AnimScript_script
 
QUuid _scriptGuid
 
QString _scriptName
 
KeyMap _map
 
QStringList _keys
 
QMap< QString, QVariant > _parameters
 
QMap< QString, QVariant > _tempParameters
 
QString repeatKey
 
quint64 repeatTime
 
quint64 kpRepeatTime
 
quint64 stopTime
 
quint64 kpStopTime
 
int repeatMsec
 
int kpRepeatMsec
 
QUuid _guid
 
QString _name
 
float _opacity
 
Mode _mode
 
bool _isActive
 
bool _isActiveKp
 
bool _needsSave
 

Detailed Description

Definition at line 11 of file kbanim.h.

Member Enumeration Documentation

Enumerator
Normal 
Add 
Subtract 
Multiply 
Divide 

Definition at line 17 of file kbanim.h.

17  {
18  Normal,
19  Add,
20  Subtract,
21  Multiply,
22  Divide
23  };

Constructor & Destructor Documentation

KbAnim::KbAnim ( QObject parent,
const KeyMap map,
const QUuid  id,
CkbSettings settings 
)

Definition at line 8 of file kbanim.cpp.

References _guid, _keys, _map, _mode, _name, _opacity, _parameters, _script, _scriptGuid, _scriptName, CkbSettings::childKeys(), AnimScript::copy(), AnimScript::Param::defaultValue, KeyMap::fromStorage(), AnimScript::Param::INVALID, AnimScript::Param::LABEL, AnimScript::Param::name, AnimScript::name(), name(), Normal, AnimScript::param(), AnimScript::paramIterator(), reInit(), AnimScript::Param::type, and CkbSettings::value().

8  :
9  QObject(parent), _script(0), _map(map),
11  _guid(id), _isActive(false), _isActiveKp(false), _needsSave(false)
12 {
13  SGroup group(settings, _guid.toString().toUpper());
14  _keys = settings.value("Keys").toStringList();
15  // Convert key list from storage names if needed
16  if(!settings.value("UseRealNames").toBool()){
17  QMutableListIterator<QString> i(_keys);
18  while(i.hasNext()){
19  i.next();
20  QString& key = i.value();
21  key = _map.fromStorage(key);
22  }
23  }
24  _name = settings.value("Name").toString().trimmed();
25  _opacity = settings.value("Opacity").toString().toDouble();
26  if(_opacity < 0.)
27  _opacity = 0.;
28  else if(_opacity > 1.)
29  _opacity = 1.;
30  bool modeOk = false;
31  _mode = (Mode)metaObject()->enumerator(metaObject()->indexOfEnumerator("Mode")).keysToValue(settings.value("BlendMode").toString().toLatin1(), &modeOk);
32  if(!modeOk)
33  _mode = Normal;
34  _scriptName = settings.value("ScriptName").toString().trimmed();
35  _scriptGuid = settings.value("ScriptGuid").toString();
36  {
37  SGroup group(settings, "Parameters");
38  foreach(const QString& param, settings.childKeys())
39  _parameters[param.toLower()] = settings.value(param);
40  }
41 
42  if(!_scriptGuid.isNull()){
44  if(_script){
45  // Remove nonexistant parameters
46  foreach(const QString& name, _parameters.keys()){
47  AnimScript::Param param = _script->param(name);
49  _parameters.remove(name);
50  }
51  // Add defaults for unset parameters
52  QListIterator<AnimScript::Param> i = _script->paramIterator();
53  while(i.hasNext()){
54  AnimScript::Param param = i.next();
55  if(!_parameters.contains(param.name) && param.type != AnimScript::Param::LABEL)
56  _parameters[param.name] = param.defaultValue;
57  }
59  reInit();
60  }
61  }
62 }
Param param(const QString &name) const
Definition: animscript.h:73
QStringList childKeys() const
quint64 repeatTime
Definition: kbanim.h:105
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
QMap< QString, QVariant > _parameters
Definition: kbanim.h:94
QVariant defaultValue
Definition: animscript.h:43
const QString & name() const
Definition: kbanim.h:73
Mode _mode
Definition: kbanim.h:113
quint64 stopTime
Definition: kbanim.h:105
QUuid _scriptGuid
Definition: kbanim.h:88
QString fromStorage(const QString &storage)
Definition: keymap.h:151
Definition: keymap.h:49
int repeatMsec
Definition: kbanim.h:106
int kpRepeatMsec
Definition: kbanim.h:106
bool _isActive
Definition: kbanim.h:114
QString _name
Definition: kbanim.h:111
bool _needsSave
Definition: kbanim.h:115
const QString & name() const
Definition: animscript.h:60
QUuid _guid
Definition: kbanim.h:110
float _opacity
Definition: kbanim.h:112
void reInit()
Definition: kbanim.cpp:149
static AnimScript * copy(QObject *parent, const QUuid &id)
Definition: animscript.cpp:67
QListIterator< Param > paramIterator() const
Definition: animscript.h:72
QString _scriptName
Definition: kbanim.h:89
QStringList _keys
Definition: kbanim.h:92
quint64 kpRepeatTime
Definition: kbanim.h:105
AnimScript * _script
Definition: kbanim.h:86
quint64 kpStopTime
Definition: kbanim.h:105
KeyMap _map
Definition: kbanim.h:91
Mode
Definition: kbanim.h:17
bool _isActiveKp
Definition: kbanim.h:114

+ Here is the call graph for this function:

KbAnim::KbAnim ( QObject parent,
const KeyMap map,
const QString &  name,
const QStringList &  keys,
const AnimScript script 
)

Definition at line 84 of file kbanim.cpp.

References _parameters, _script, _scriptGuid, _scriptName, AnimScript::Param::defaultValue, AnimScript::guid(), AnimScript::Param::LABEL, AnimScript::Param::name, AnimScript::name(), AnimScript::paramIterator(), reInit(), and AnimScript::Param::type.

84  :
85  QObject(parent),
86  _script(AnimScript::copy(this, script->guid())), _map(map), _keys(keys),
88  _guid(QUuid::createUuid()), _name(name), _opacity(1.), _mode(Normal), _isActive(false), _isActiveKp(false), _needsSave(true)
89 {
90  if(_script){
91  // Set default parameters
92  QListIterator<AnimScript::Param> i = _script->paramIterator();
93  while(i.hasNext()){
94  AnimScript::Param param = i.next();
95  if(param.type != AnimScript::Param::LABEL)
96  _parameters[param.name] = param.defaultValue;
97  }
98  _scriptGuid = script->guid();
99  _scriptName = script->name();
100  reInit();
101  }
102 }
const QStringList & keys()
Definition: kbanim.h:40
quint64 repeatTime
Definition: kbanim.h:105
QMap< QString, QVariant > _parameters
Definition: kbanim.h:94
QVariant defaultValue
Definition: animscript.h:43
const QString & name() const
Definition: kbanim.h:73
Mode _mode
Definition: kbanim.h:113
quint64 stopTime
Definition: kbanim.h:105
QUuid _scriptGuid
Definition: kbanim.h:88
int repeatMsec
Definition: kbanim.h:106
int kpRepeatMsec
Definition: kbanim.h:106
bool _isActive
Definition: kbanim.h:114
QString _name
Definition: kbanim.h:111
bool _needsSave
Definition: kbanim.h:115
const QString & name() const
Definition: animscript.h:60
QUuid _guid
Definition: kbanim.h:110
float _opacity
Definition: kbanim.h:112
void reInit()
Definition: kbanim.cpp:149
static AnimScript * copy(QObject *parent, const QUuid &id)
Definition: animscript.cpp:67
QListIterator< Param > paramIterator() const
Definition: animscript.h:72
QString _scriptName
Definition: kbanim.h:89
QStringList _keys
Definition: kbanim.h:92
quint64 kpRepeatTime
Definition: kbanim.h:105
AnimScript * _script
Definition: kbanim.h:86
const QUuid & guid() const
Definition: animscript.h:59
quint64 kpStopTime
Definition: kbanim.h:105
KeyMap _map
Definition: kbanim.h:91
bool _isActiveKp
Definition: kbanim.h:114

+ Here is the call graph for this function:

KbAnim::KbAnim ( QObject parent,
const KeyMap map,
const KbAnim other 
)

Definition at line 104 of file kbanim.cpp.

References reInit().

104  :
105  QObject(parent),
107  _map(map), _keys(other._keys), _parameters(other._parameters),
109  _guid(other._guid), _name(other._name), _opacity(other._opacity), _mode(other._mode), _isActive(false), _isActiveKp(false), _needsSave(true)
110 {
111  reInit();
112 }
quint64 repeatTime
Definition: kbanim.h:105
QMap< QString, QVariant > _parameters
Definition: kbanim.h:94
Mode _mode
Definition: kbanim.h:113
quint64 stopTime
Definition: kbanim.h:105
QUuid _scriptGuid
Definition: kbanim.h:88
int repeatMsec
Definition: kbanim.h:106
int kpRepeatMsec
Definition: kbanim.h:106
bool _isActive
Definition: kbanim.h:114
QString _name
Definition: kbanim.h:111
bool _needsSave
Definition: kbanim.h:115
const QString & name() const
Definition: animscript.h:60
QUuid _guid
Definition: kbanim.h:110
float _opacity
Definition: kbanim.h:112
void reInit()
Definition: kbanim.cpp:149
static AnimScript * copy(QObject *parent, const QUuid &id)
Definition: animscript.cpp:67
QString _scriptName
Definition: kbanim.h:89
QStringList _keys
Definition: kbanim.h:92
quint64 kpRepeatTime
Definition: kbanim.h:105
AnimScript * _script
Definition: kbanim.h:86
const QUuid & guid() const
Definition: animscript.h:59
quint64 kpStopTime
Definition: kbanim.h:105
KeyMap _map
Definition: kbanim.h:91
const AnimScript * script() const
Definition: kbanim.h:81
bool _isActiveKp
Definition: kbanim.h:114

+ Here is the call graph for this function:

Member Function Documentation

void KbAnim::blend ( ColorMap animMap,
quint64  timestamp 
)

Definition at line 365 of file kbanim.cpp.

References _mode, _opacity, _script, catchUp(), ColorMap::colors(), AnimScript::colors(), ColorMap::count(), AnimScript::frame(), and functions.

Referenced by KbLight::frameUpdate().

365  {
366  if(!_script)
367  return;
368 
369  // Fetch the next frame from the script
370  catchUp(timestamp);
371  _script->frame(timestamp);
372 
373  // Blend the script's map with the current map
374  int blendMode = (int)_mode;
375  blendFunc blend = functions[blendMode];
376  float fOpacity = _opacity / 255.f; // save some math by pre-dividing the 255 for qAlpha
377 
378  const ColorMap& scriptMap = _script->colors();
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.";
382  return;
383  }
384  QRgb* background = animMap.colors();
385  const QRgb* foreground = scriptMap.colors();
386  for(int i = 0; i < count; i++){
387  // Mix the colors in with the color map according to blend mode and alpha
388  QRgb& bg = background[i];
389  QRgb fg = foreground[i];
390  int alpha = qAlpha(fg);
391  if(alpha == 0)
392  continue;
393  if(blendMode == 0){
394  // Blend: normal
395  // This is the most common use case and it requires much less arithmetic
396  if(alpha == 255){
397  bg = fg;
398  } else {
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));
405  }
406  } else {
407  // Use blend function
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));
414  }
415  }
416 }
QRgb * colors()
Definition: colormap.h:33
void catchUp(quint64 timestamp)
Definition: kbanim.cpp:166
void frame(quint64 timestamp)
Definition: animscript.cpp:430
static blendFunc functions[5]
Definition: kbanim.cpp:363
Mode _mode
Definition: kbanim.h:113
const ColorMap & colors() const
Definition: animscript.h:99
float(* blendFunc)(float, float)
Definition: kbanim.cpp:362
float _opacity
Definition: kbanim.h:112
AnimScript * _script
Definition: kbanim.h:86
int count() const
Definition: colormap.h:31
void blend(ColorMap &animMap, quint64 timestamp)
Definition: kbanim.cpp:365

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbAnim::catchUp ( quint64  timestamp)
private

Definition at line 166 of file kbanim.cpp.

References _isActive, _isActiveKp, _script, effectiveParams(), AnimScript::end(), AnimScript::keypress(), kpRepeatMsec, kpRepeatTime, kpStopTime, repeatKey, repeatMsec, repeatTime, AnimScript::retrigger(), and stopTime.

Referenced by blend(), keypress(), and trigger().

166  {
167  QMap<QString, QVariant> parameters = effectiveParams();
168  // Stop the animation if its time has run out
169  if(stopTime != 0 && timestamp >= stopTime){
170  repeatMsec = repeatTime = 0;
171  if(!parameters.contains("repeat")){
172  // If repeats aren't allowed, stop the animation entirely
173  _script->end();
174  _isActive = false;
175  return;
176  } else
177  // Otherwise, simply stop repeating
178  stopTime = 0;
179  }
180  if(kpStopTime != 0 && timestamp >= kpStopTime){
182  if(!parameters.contains("kprepeat")){
183  _script->end();
184  _isActiveKp = false;
185  return;
186  } else
187  kpStopTime = 0;
188  }
189 
190  // Restart (or start, if there was a delay) the animation if its repeat time is up
191  while(repeatTime > 0 && timestamp >= repeatTime){
193  if(repeatMsec <= 0){
194  repeatTime = 0;
195  break;
196  }
198  }
199  while(kpRepeatTime > 0 && timestamp >= kpRepeatTime){
201  if(kpRepeatMsec <= 0){
202  kpRepeatTime = 0;
203  break;
204  }
206  }
207 }
void retrigger(quint64 timestamp, bool allowPreempt=false)
Definition: animscript.cpp:331
quint64 repeatTime
Definition: kbanim.h:105
quint64 stopTime
Definition: kbanim.h:105
QString repeatKey
Definition: kbanim.h:104
int repeatMsec
Definition: kbanim.h:106
int kpRepeatMsec
Definition: kbanim.h:106
bool _isActive
Definition: kbanim.h:114
QMap< QString, QVariant > effectiveParams()
Definition: kbanim.cpp:138
void keypress(const QString &key, bool pressed, quint64 timestamp)
Definition: animscript.cpp:354
void end()
Definition: animscript.cpp:387
quint64 kpRepeatTime
Definition: kbanim.h:105
AnimScript * _script
Definition: kbanim.h:86
quint64 kpStopTime
Definition: kbanim.h:105
bool _isActiveKp
Definition: kbanim.h:114

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbAnim::commitParams ( )

Definition at line 121 of file kbanim.cpp.

References _needsSave, _parameters, _tempParameters, and effectiveParams().

Referenced by KbLight::addAnim(), KbAnimWidget::on_propertyButton_clicked(), and KbLight::previewAnim().

121  {
122  _needsSave = true;
124  _tempParameters.clear();
125 }
QMap< QString, QVariant > _parameters
Definition: kbanim.h:94
QMap< QString, QVariant > effectiveParams()
Definition: kbanim.cpp:138
bool _needsSave
Definition: kbanim.h:115
QMap< QString, QVariant > _tempParameters
Definition: kbanim.h:96

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QMap< QString, QVariant > KbAnim::effectiveParams ( )
private

Definition at line 138 of file kbanim.cpp.

References _parameters, and _tempParameters.

Referenced by catchUp(), commitParams(), keypress(), reInit(), trigger(), and updateParams().

138  {
139  QMap<QString, QVariant> res = _parameters;
140  // Apply all uncommited parameters
141  QMapIterator<QString, QVariant> i(_tempParameters);
142  while(i.hasNext()){
143  i.next();
144  res[i.key()] = i .value();
145  }
146  return res;
147 }
QMap< QString, QVariant > _parameters
Definition: kbanim.h:94
QMap< QString, QVariant > _tempParameters
Definition: kbanim.h:96

+ Here is the caller graph for this function:

const QUuid& KbAnim::guid ( ) const
inline

Definition at line 71 of file kbanim.h.

References _guid.

Referenced by KbAnimWidget::addAnim(), RebindWidget::applyChanges(), KbLight::findAnim(), KbAnimWidget::on_deleteButton_clicked(), KbAnimWidget::refreshList(), and KbLight::save().

71 { return _guid; }
QUuid _guid
Definition: kbanim.h:110

+ Here is the caller graph for this function:

bool KbAnim::hasParameter ( const QString &  name) const
inline

Definition at line 44 of file kbanim.h.

References _parameters.

Referenced by AnimSettingDialog::AnimSettingDialog().

44 { return _parameters.contains(name); }
QMap< QString, QVariant > _parameters
Definition: kbanim.h:94
const QString & name() const
Definition: kbanim.h:73

+ Here is the caller graph for this function:

bool KbAnim::isActive ( ) const
inline

Definition at line 63 of file kbanim.h.

References _isActive, and _isActiveKp.

Referenced by KeyAction::keyEvent(), and keypress().

63 { return _isActive || _isActiveKp; }
bool _isActive
Definition: kbanim.h:114
bool _isActiveKp
Definition: kbanim.h:114

+ Here is the caller graph for this function:

bool KbAnim::isRunning ( ) const

Definition at line 325 of file kbanim.cpp.

References _script, and AnimScript::hasFrame().

Referenced by KbLight::isStarted().

325  {
326  if(!_script)
327  return true; // If the script wasn't loaded, pretend it's running anyway so it won't lock up
328  return _script->hasFrame();
329 }
bool hasFrame() const
Definition: animscript.h:96
AnimScript * _script
Definition: kbanim.h:86

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbAnim::keypress ( const QString &  key,
bool  pressed,
quint64  timestamp 
)

Definition at line 250 of file kbanim.cpp.

References _isActive, _isActiveKp, _script, catchUp(), effectiveParams(), AnimScript::frame(), isActive(), AnimScript::keypress(), kpRepeatMsec, kpRepeatTime, kpStopTime, repeatKey, repeatMsec, repeatTime, stop(), AnimScript::stop(), and stopTime.

Referenced by KbLight::animKeypress().

250  {
251  if(!_script)
252  return;
253  QMap<QString, QVariant> parameters = effectiveParams();
254  if(pressed && parameters.value("kpmodestop").toBool()){
255  // If stop on key press is enabled, stop mode-wide animation
256  catchUp(timestamp);
257  _script->stop(timestamp);
259  _isActive = false;
260  } else {
261  if(!parameters.value("kptrigger").toBool())
262  return;
263  catchUp(timestamp);
264  }
265 
266  if(pressed){
267  // Key pressed
268  _isActiveKp = true;
269  if(parameters.value("kpmode", 0).toInt() == 2 && isActive())
270  // If mode is start once and a key has already been pressed, do nothing
271  return;
272  int delay = round(parameters.value("kpdelay").toDouble() * 1000.);
273  if(delay > 0){
274  // If delay is enabled, wait to trigger the event
275  timestamp += delay;
276  kpRepeatTime = timestamp;
277  } else
278  _script->keypress(key, pressed, timestamp);
279 
280  int repeat = round(parameters.value("kprepeat").toDouble() * 1000.);
281  if(repeat <= 0){
282  // If no repeat allowed, calculate stop time in seconds
283  kpRepeatMsec = -1;
284  double stop = parameters.value("kpstop").toDouble();
285  if(stop <= 0.)
286  kpStopTime = 0;
287  else
288  kpStopTime = timestamp + round(stop * 1000.);
289  } else {
290  // If repeat is allowed, calculate stop time in repetitions
291  kpRepeatMsec = repeat;
292  if(delay <= 0)
293  kpRepeatTime = timestamp + repeat;
294  int stop = parameters.value("kpstop").toInt();
295  if(stop < 0)
296  kpStopTime = 0;
297  else
298  kpStopTime = timestamp + repeat * (1 + stop);
299  }
300  repeatKey = key;
301  } else {
302  // Key released
303  _isActiveKp = false;
304  _script->keypress(key, pressed, timestamp);
305  if(parameters.value("kprelease").toBool())
306  // Stop repeating keypress if "Stop on key release" is enabled
307  kpStopTime = timestamp;
308  }
309  _script->frame(timestamp);
310 }
void stop()
Definition: kbanim.cpp:312
void catchUp(quint64 timestamp)
Definition: kbanim.cpp:166
bool isActive() const
Definition: kbanim.h:63
quint64 repeatTime
Definition: kbanim.h:105
void frame(quint64 timestamp)
Definition: animscript.cpp:430
quint64 stopTime
Definition: kbanim.h:105
QString repeatKey
Definition: kbanim.h:104
Definition: keymap.h:49
int repeatMsec
Definition: kbanim.h:106
int kpRepeatMsec
Definition: kbanim.h:106
bool _isActive
Definition: kbanim.h:114
QMap< QString, QVariant > effectiveParams()
Definition: kbanim.cpp:138
void keypress(const QString &key, bool pressed, quint64 timestamp)
Definition: animscript.cpp:354
quint64 kpRepeatTime
Definition: kbanim.h:105
AnimScript * _script
Definition: kbanim.h:86
quint64 kpStopTime
Definition: kbanim.h:105
void stop(quint64 timestamp)
Definition: animscript.cpp:344
bool _isActiveKp
Definition: kbanim.h:114

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const QStringList& KbAnim::keys ( )
inline

Definition at line 40 of file kbanim.h.

References _keys.

Referenced by KbLight::animKeypress(), KbLightWidget::changeAnim(), KbAnimWidget::on_keyButton_clicked(), and KbAnimWidget::setCurrent().

40 { return _keys; }
QStringList _keys
Definition: kbanim.h:92

+ Here is the caller graph for this function:

void KbAnim::keys ( const QStringList &  newKeys)

Definition at line 161 of file kbanim.cpp.

References _keys, and reInit().

161  {
162  _keys = newKeys;
163  reInit();
164 }
void reInit()
Definition: kbanim.cpp:149
QStringList _keys
Definition: kbanim.h:92

+ Here is the call graph for this function:

const KeyMap& KbAnim::map ( )
inline

Definition at line 37 of file kbanim.h.

References _map.

Referenced by KbLight::map().

37 { return _map; }
KeyMap _map
Definition: kbanim.h:91

+ Here is the caller graph for this function:

void KbAnim::map ( const KeyMap newMap)

Definition at line 156 of file kbanim.cpp.

References _map, and reInit().

156  {
157  _map = newMap;
158  reInit();
159 }
void reInit()
Definition: kbanim.cpp:149
KeyMap _map
Definition: kbanim.h:91

+ Here is the call graph for this function:

Mode KbAnim::mode ( ) const
inline

Definition at line 77 of file kbanim.h.

References _mode.

Referenced by KbAnimWidget::on_blendBox_activated(), and KbAnimWidget::setCurrent().

77 { return _mode; }
Mode _mode
Definition: kbanim.h:113

+ Here is the caller graph for this function:

void KbAnim::mode ( Mode  newMode)
inline

Definition at line 78 of file kbanim.h.

References _mode, and _needsSave.

78 { _needsSave = true; _mode = newMode; }
Mode _mode
Definition: kbanim.h:113
bool _needsSave
Definition: kbanim.h:115
const QString& KbAnim::name ( ) const
inline
void KbAnim::name ( const QString &  newName)
inline

Definition at line 74 of file kbanim.h.

References _name, and _needsSave.

74 { _needsSave = true; _name = newName; }
QString _name
Definition: kbanim.h:111
bool _needsSave
Definition: kbanim.h:115
bool KbAnim::needsSave ( ) const
inline

Definition at line 29 of file kbanim.h.

References _needsSave.

Referenced by KbLight::needsSave().

29 { return _needsSave; }
bool _needsSave
Definition: kbanim.h:115

+ Here is the caller graph for this function:

void KbAnim::newId ( )
inline

Definition at line 72 of file kbanim.h.

References _guid, and _needsSave.

Referenced by KbLight::duplicateAnim(), and KbMode::newId().

72 { _needsSave = true; _guid = QUuid::createUuid(); }
bool _needsSave
Definition: kbanim.h:115
QUuid _guid
Definition: kbanim.h:110

+ Here is the caller graph for this function:

float KbAnim::opacity ( ) const
inline

Definition at line 75 of file kbanim.h.

References _opacity.

Referenced by KbAnimWidget::on_opacityBox_valueChanged(), and KbAnimWidget::setCurrent().

75 { return _opacity; }
float _opacity
Definition: kbanim.h:112

+ Here is the caller graph for this function:

void KbAnim::opacity ( float  newOpacity)
inline

Definition at line 76 of file kbanim.h.

References _needsSave, and _opacity.

76 { _needsSave = true; _opacity = newOpacity; }
bool _needsSave
Definition: kbanim.h:115
float _opacity
Definition: kbanim.h:112
QVariant KbAnim::parameter ( const QString &  name) const
inline

Definition at line 45 of file kbanim.h.

References _parameters.

Referenced by KbLight::addAnim(), AnimSettingDialog::AnimSettingDialog(), KbLight::previewAnim(), and AnimSettingDialog::updateParam().

45 { return _parameters.value(name); }
QMap< QString, QVariant > _parameters
Definition: kbanim.h:94
const QString & name() const
Definition: kbanim.h:73

+ Here is the caller graph for this function:

void KbAnim::parameter ( const QString &  name,
const QVariant &  value 
)

Definition at line 114 of file kbanim.cpp.

References _script, _tempParameters, AnimScript::hasParam(), name(), and updateParams().

114  {
115  if(!_script->hasParam(name))
116  return;
117  _tempParameters[name] = value;
118  updateParams();
119 }
void updateParams()
Definition: kbanim.cpp:132
const QString & name() const
Definition: kbanim.h:73
bool hasParam(const QString &name) const
Definition: animscript.h:74
AnimScript * _script
Definition: kbanim.h:86
QMap< QString, QVariant > _tempParameters
Definition: kbanim.h:96

+ Here is the call graph for this function:

void KbAnim::reInit ( )

Definition at line 149 of file kbanim.cpp.

References _isActive, _isActiveKp, _keys, _map, _script, effectiveParams(), AnimScript::init(), and repeatKey.

Referenced by KbAnim(), keys(), map(), KbAnimWidget::on_propertyButton_clicked(), and KbLight::previewAnim().

149  {
150  if(_script)
152  repeatKey = "";
153  _isActive = _isActiveKp = false;
154 }
QString repeatKey
Definition: kbanim.h:104
bool _isActive
Definition: kbanim.h:114
QMap< QString, QVariant > effectiveParams()
Definition: kbanim.cpp:138
void init(const KeyMap &map, const QStringList &keys, const QMap< QString, QVariant > &paramValues)
Definition: animscript.cpp:239
QStringList _keys
Definition: kbanim.h:92
AnimScript * _script
Definition: kbanim.h:86
KeyMap _map
Definition: kbanim.h:91
bool _isActiveKp
Definition: kbanim.h:114

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbAnim::resetParams ( )

Definition at line 127 of file kbanim.cpp.

References _tempParameters, and updateParams().

Referenced by KbAnimWidget::on_propertyButton_clicked().

127  {
128  _tempParameters.clear();
129  updateParams();
130 }
void updateParams()
Definition: kbanim.cpp:132
QMap< QString, QVariant > _tempParameters
Definition: kbanim.h:96

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbAnim::save ( CkbSettings settings)

Definition at line 64 of file kbanim.cpp.

References _guid, _keys, _mode, _name, _needsSave, _opacity, _parameters, _scriptGuid, _scriptName, CkbSettings::beginGroup(), CkbSettings::endGroup(), and CkbSettings::setValue().

Referenced by KbLight::save().

64  {
65  _needsSave = false;
66  settings.beginGroup(_guid.toString().toUpper());
67  settings.setValue("UseRealNames", true);
68  settings.setValue("Keys", _keys);
69  settings.setValue("Name", _name);
70  settings.setValue("Opacity", QString::number(_opacity));
71  settings.setValue("BlendMode", metaObject()->enumerator(metaObject()->indexOfEnumerator("Mode")).valueToKey(_mode));
72  settings.setValue("ScriptName", _scriptName);
73  settings.setValue("ScriptGuid", _scriptGuid.toString().toUpper());
74  settings.beginGroup("Parameters");
75  QMapIterator<QString, QVariant> i(_parameters);
76  while(i.hasNext()){
77  i.next();
78  settings.setValue(i.key(), i.value());
79  }
80  settings.endGroup();
81  settings.endGroup();
82 }
void setValue(const QString &key, const QVariant &value)
QMap< QString, QVariant > _parameters
Definition: kbanim.h:94
void endGroup()
Definition: ckbsettings.cpp:85
Mode _mode
Definition: kbanim.h:113
QUuid _scriptGuid
Definition: kbanim.h:88
QString _name
Definition: kbanim.h:111
void beginGroup(const QString &prefix)
Definition: ckbsettings.cpp:81
bool _needsSave
Definition: kbanim.h:115
QUuid _guid
Definition: kbanim.h:110
float _opacity
Definition: kbanim.h:112
QString _scriptName
Definition: kbanim.h:89
QStringList _keys
Definition: kbanim.h:92

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const AnimScript* KbAnim::script ( ) const
inline

Definition at line 81 of file kbanim.h.

References _script.

Referenced by AnimSettingDialog::AnimSettingDialog(), KbAnimWidget::setCurrent(), and AnimSettingDialog::updateParam().

81 { return _script; }
AnimScript * _script
Definition: kbanim.h:86

+ Here is the caller graph for this function:

const QString& KbAnim::scriptName ( ) const
inline

Definition at line 82 of file kbanim.h.

References _scriptName.

Referenced by AnimSettingDialog::AnimSettingDialog(), and KbAnimWidget::setCurrent().

82 { return _scriptName; }
QString _scriptName
Definition: kbanim.h:89

+ Here is the caller graph for this function:

void KbAnim::stop ( )

Definition at line 312 of file kbanim.cpp.

References _isActive, _isActiveKp, _script, AnimScript::end(), kpRepeatMsec, kpRepeatTime, kpStopTime, repeatKey, repeatMsec, repeatTime, and stopTime.

Referenced by KbLight::addAnim(), KbLight::close(), KbLight::duplicateAnim(), KeyAction::keyEvent(), keypress(), KbLight::restartAnimation(), and trigger().

312  {
313  if(_script)
314  _script->end();
315  repeatTime = 0;
316  kpRepeatTime = 0;
317  repeatMsec = 0;
318  kpRepeatMsec = 0;
319  stopTime = 0;
320  kpStopTime = 0;
321  repeatKey = "";
322  _isActive = _isActiveKp = false;
323 }
quint64 repeatTime
Definition: kbanim.h:105
quint64 stopTime
Definition: kbanim.h:105
QString repeatKey
Definition: kbanim.h:104
int repeatMsec
Definition: kbanim.h:106
int kpRepeatMsec
Definition: kbanim.h:106
bool _isActive
Definition: kbanim.h:114
void end()
Definition: animscript.cpp:387
quint64 kpRepeatTime
Definition: kbanim.h:105
AnimScript * _script
Definition: kbanim.h:86
quint64 kpStopTime
Definition: kbanim.h:105
bool _isActiveKp
Definition: kbanim.h:114

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbAnim::trigger ( quint64  timestamp,
bool  ignoreParameter = false 
)

Definition at line 209 of file kbanim.cpp.

References _isActive, _script, catchUp(), effectiveParams(), AnimScript::frame(), repeatMsec, repeatTime, AnimScript::retrigger(), stop(), and stopTime.

Referenced by KbLight::addAnim(), KbLight::duplicateAnim(), KeyAction::keyEvent(), KbLight::open(), KbLight::previewAnim(), and KbLight::restartAnimation().

209  {
210  if(!_script)
211  return;
212  QMap<QString, QVariant> parameters = effectiveParams();
213 
214  catchUp(timestamp);
215  if(parameters.value("trigger").toBool() || ignoreParameter){
216  _isActive = true;
217  int delay = round(parameters.value("delay").toDouble() * 1000.);
218  if(delay > 0){
219  // If delay is enabled, wait to trigger the event
220  timestamp += delay;
221  repeatTime = timestamp;
222  } else
223  _script->retrigger(timestamp, true);
224 
225  int repeat = round(parameters.value("repeat").toDouble() * 1000.);
226  if(repeat <= 0){
227  // If no repeat allowed, calculate stop time in seconds
228  repeatMsec = -1;
229  double stop = parameters.value("stop").toDouble();
230  if(stop <= 0)
231  stopTime = 0;
232  else
233  stopTime = timestamp + round(stop * 1000.);
234  } else {
235  // If repeat is allowed, calculate stop time in repetitions
236  repeatMsec = repeat;
237  if(delay <= 0)
238  repeatTime = timestamp + repeat;
239  int stop = parameters.value("stop").toInt();
240  if(stop < 0)
241  stopTime = 0;
242  else
243  stopTime = timestamp + repeat * (1 + stop);
244  }
245  }
246  // Ask the script for a frame even if we didn't do anything here. This way ckb knows the script is responding.
247  _script->frame(timestamp);
248 }
void stop()
Definition: kbanim.cpp:312
void catchUp(quint64 timestamp)
Definition: kbanim.cpp:166
void retrigger(quint64 timestamp, bool allowPreempt=false)
Definition: animscript.cpp:331
quint64 repeatTime
Definition: kbanim.h:105
void frame(quint64 timestamp)
Definition: animscript.cpp:430
quint64 stopTime
Definition: kbanim.h:105
int repeatMsec
Definition: kbanim.h:106
bool _isActive
Definition: kbanim.h:114
QMap< QString, QVariant > effectiveParams()
Definition: kbanim.cpp:138
AnimScript * _script
Definition: kbanim.h:86

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbAnim::updateParams ( )
private

Definition at line 132 of file kbanim.cpp.

References _script, effectiveParams(), AnimScript::parameters(), and repeatKey.

Referenced by parameter(), and resetParams().

132  {
133  if(_script)
135  repeatKey = "";
136 }
QString repeatKey
Definition: kbanim.h:104
QMap< QString, QVariant > effectiveParams()
Definition: kbanim.cpp:138
AnimScript * _script
Definition: kbanim.h:86
void parameters(const QMap< QString, QVariant > &paramValues)
Definition: animscript.cpp:265

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

QUuid KbAnim::_guid
private

Definition at line 110 of file kbanim.h.

Referenced by guid(), KbAnim(), newId(), and save().

bool KbAnim::_isActive
private

Definition at line 114 of file kbanim.h.

Referenced by catchUp(), isActive(), keypress(), reInit(), stop(), and trigger().

bool KbAnim::_isActiveKp
private

Definition at line 114 of file kbanim.h.

Referenced by catchUp(), isActive(), keypress(), reInit(), and stop().

QStringList KbAnim::_keys
private

Definition at line 92 of file kbanim.h.

Referenced by KbAnim(), keys(), reInit(), and save().

KeyMap KbAnim::_map
private

Definition at line 91 of file kbanim.h.

Referenced by KbAnim(), map(), and reInit().

Mode KbAnim::_mode
private

Definition at line 113 of file kbanim.h.

Referenced by blend(), KbAnim(), mode(), and save().

QString KbAnim::_name
private

Definition at line 111 of file kbanim.h.

Referenced by KbAnim(), name(), and save().

bool KbAnim::_needsSave
private

Definition at line 115 of file kbanim.h.

Referenced by commitParams(), mode(), name(), needsSave(), newId(), opacity(), and save().

float KbAnim::_opacity
private

Definition at line 112 of file kbanim.h.

Referenced by blend(), KbAnim(), opacity(), and save().

QMap<QString, QVariant> KbAnim::_parameters
private

Definition at line 94 of file kbanim.h.

Referenced by commitParams(), effectiveParams(), hasParameter(), KbAnim(), parameter(), and save().

AnimScript* KbAnim::_script
private
QUuid KbAnim::_scriptGuid
private

Definition at line 88 of file kbanim.h.

Referenced by KbAnim(), and save().

QString KbAnim::_scriptName
private

Definition at line 89 of file kbanim.h.

Referenced by KbAnim(), save(), and scriptName().

QMap<QString, QVariant> KbAnim::_tempParameters
private

Definition at line 96 of file kbanim.h.

Referenced by commitParams(), effectiveParams(), parameter(), and resetParams().

int KbAnim::kpRepeatMsec
private

Definition at line 106 of file kbanim.h.

Referenced by catchUp(), keypress(), and stop().

quint64 KbAnim::kpRepeatTime
private

Definition at line 105 of file kbanim.h.

Referenced by catchUp(), keypress(), and stop().

quint64 KbAnim::kpStopTime
private

Definition at line 105 of file kbanim.h.

Referenced by catchUp(), keypress(), and stop().

QString KbAnim::repeatKey
private

Definition at line 104 of file kbanim.h.

Referenced by catchUp(), keypress(), reInit(), stop(), and updateParams().

int KbAnim::repeatMsec
private

Definition at line 106 of file kbanim.h.

Referenced by catchUp(), keypress(), stop(), and trigger().

quint64 KbAnim::repeatTime
private

Definition at line 105 of file kbanim.h.

Referenced by catchUp(), keypress(), stop(), and trigger().

quint64 KbAnim::stopTime
private

Definition at line 105 of file kbanim.h.

Referenced by catchUp(), keypress(), stop(), and trigger().


The documentation for this class was generated from the following files: