bool FloatNode::applyDiff(const DefinitionDiff *diff, bool backward) { if (!DefinitionNode::applyDiff(diff, backward)) { return false; } assert(diff->getTypeName() == "float"); auto float_diff = dynamic_cast<const FloatDiff *>(diff); if (float_diff) { double previous = backward ? float_diff->getNewValue() : float_diff->getOldValue(); double next = backward ? float_diff->getOldValue() : float_diff->getNewValue(); if (value == previous) { value = next; return true; } else { Logs::error("Definition") << "Can't apply float diff " << previous << " => " << next << " to " << getName() << endl; return false; } } else { Logs::error("Could not cast DefinitionDiff to IntDiff"); return false; } }
void DefinitionWatcher::nodeChanged(const DefinitionNode *node, const DefinitionDiff *diff, const DefinitionNode *) { string type_name = node->getTypeName(); if (type_name == "int") { auto int_diff = static_cast<const IntDiff *>(diff); intNodeChanged(node->getPath(), int_diff->getNewValue(), int_diff->getOldValue()); } else if (type_name == "float") { auto float_diff = static_cast<const FloatDiff *>(diff); floatNodeChanged(node->getPath(), float_diff->getNewValue(), float_diff->getOldValue()); } }
//------------------------------------------------------------------------ void CVuMeter::draw (CDrawContext *_pContext) { if (!getOnBitmap ()) return; CRect _rectOn (rectOn); CRect _rectOff (rectOff); CPoint pointOn; CPoint pointOff; CDrawContext *pContext = _pContext; bounceValue (); float newValue = getOldValue () - decreaseValue; if (newValue < value) newValue = value; setOldValue (newValue); newValue = (newValue - getMin ()) / getRange (); // normalize if (style & kHorizontal) { CCoord tmp = (CCoord)(((int32_t)(nbLed * newValue + 0.5f) / (float)nbLed) * getOnBitmap ()->getWidth ()); pointOff (tmp, 0); _rectOff.left += tmp; _rectOn.right = tmp + rectOn.left; } else { CCoord tmp = (CCoord)(((int32_t)(nbLed * (1.f - newValue) + 0.5f) / (float)nbLed) * getOnBitmap ()->getHeight ()); pointOn (0, tmp); _rectOff.bottom = tmp + rectOff.top; _rectOn.top += tmp; } if (getOffBitmap ()) { getOffBitmap ()->draw (pContext, _rectOff, pointOff); } getOnBitmap ()->draw (pContext, _rectOn, pointOn); setDirty (false); }
//------------------------------------------------------------------------ void CVuMeter::onIdle () { if (getOldValue () != value) invalid (); }