void HSSDisplayObject::heightChanged(HSSObservableProperty source, void *data) { HSSParserNodeType nodeType = this->dHeight->getType(); switch (nodeType) { case HSSParserNodeTypePercentageConstant: { HSSPercentageConstant::p heightValue = boost::static_pointer_cast<HSSPercentageConstant>(this->dHeight); this->height = heightValue->getValue(*(long double*)data); break; } case HSSParserNodeTypeExpression: { HSSExpression::p heightExpression = boost::static_pointer_cast<HSSExpression>(this->dHeight); this->height = heightExpression->evaluate(); break; } default: break; } this->notifyObservers(HSSObservablePropertyHeight, &this->height); this->setNeedsSurface(true); this->setDirty(true); }
void HSSDisplayObject::anchorYChanged(HSSObservableProperty source, void *data) { HSSParserNodeType nodeType = this->dAnchorY->getType(); switch (nodeType) { case HSSParserNodeTypePercentageConstant: { HSSPercentageConstant::p percentageValue = boost::static_pointer_cast<HSSPercentageConstant>(this->dAnchorY); this->anchorY = percentageValue->getValue(*(long double*)data); break; } case HSSParserNodeTypeExpression: { HSSExpression::p expressionValue = boost::static_pointer_cast<HSSExpression>(this->dAnchorY); this->anchorY = expressionValue->evaluate(); break; } default: break; } this->notifyObservers(HSSObservablePropertyAnchorY, &this->anchorY); #if AXR_DEBUG_LEVEL > 0 this->setDirty(true); #endif }
void HSSExpression::setScope(HSSSimpleSelection::p newScope) { this->scope = newScope; //propagate values if (this->left && this->left->isA(HSSParserNodeTypeExpression)) { HSSExpression::p leftExpression = qSharedPointerCast<HSSExpression > (this->left); leftExpression->setScope(newScope); } else if (this->left && this->left->isA(HSSParserNodeTypeFunctionCall)) { HSSFunction::p leftFunction = qSharedPointerCast<HSSFunction > (this->left); leftFunction->setScope(newScope); } if (this->right && this->right->isA(HSSParserNodeTypeExpression)) { HSSExpression::p rightExpression = qSharedPointerCast<HSSExpression > (this->right); rightExpression->setScope(newScope); } else if (this->right && this->right->isA(HSSParserNodeTypeFunctionCall)) { HSSFunction::p rightFunction = qSharedPointerCast<HSSFunction > (this->right); rightFunction->setScope(newScope); } this->setDirty(true); }
void HSSExpression::setPercentageObserved(HSSObservableProperty property, HSSObservable *observed) { this->percentageObserved = observed; this->percentageObservedProperty = property; //propagate values if (this->left && this->left->isA(HSSParserNodeTypeExpression)) { HSSExpression::p leftExpression = qSharedPointerCast<HSSExpression > (this->left); leftExpression->setPercentageObserved(property, observed); } else if (this->left && this->left->isA(HSSParserNodeTypeFunctionCall)) { HSSFunction::p leftFunction = qSharedPointerCast<HSSFunction > (this->left); leftFunction->setPercentageObserved(property, observed); } if (this->right && this->right->isA(HSSParserNodeTypeExpression)) { HSSExpression::p rightExpression = qSharedPointerCast<HSSExpression > (this->right); rightExpression->setPercentageObserved(property, observed); } else if (this->right && this->right->isA(HSSParserNodeTypeFunctionCall)) { HSSFunction::p rightFunction = qSharedPointerCast<HSSFunction > (this->right); rightFunction->setPercentageObserved(property, observed); } this->setDirty(true); }
void HSSExpression::setPercentageBase(HSSUnit value) { this->percentageBase = value; //propagate values if (this->left && this->left->isA(HSSParserNodeTypeExpression)) { HSSExpression::p leftExpression = qSharedPointerCast<HSSExpression > (this->left); leftExpression->setPercentageBase(value); } else if (this->left && this->left->isA(HSSParserNodeTypeFunctionCall)) { HSSFunction::p leftFunction = qSharedPointerCast<HSSFunction > (this->left); leftFunction->setPercentageBase(value); } if (this->right && this->right->isA(HSSParserNodeTypeExpression)) { HSSExpression::p rightExpression = qSharedPointerCast<HSSExpression > (this->right); rightExpression->setPercentageBase(value); } else if (this->right && this->right->isA(HSSParserNodeTypeFunctionCall)) { HSSFunction::p rightFunction = qSharedPointerCast<HSSFunction > (this->right); rightFunction->setPercentageBase(value); } this->setDirty(true); }
long double HSSRgb::_setLDProperty( void(HSSRgb::*callback)(HSSObservableProperty property, void* data), HSSParserNode::p value, long double percentageBase, HSSObservableProperty observedSourceProperty, HSSObservable * &observedStore, HSSObservableProperty &observedStoreProperty ) { long double ret; HSSParserNodeType nodeType = value->getType(); switch (nodeType) { case HSSParserNodeTypeNumberConstant: { HSSNumberConstant::p numberValue = boost::static_pointer_cast<HSSNumberConstant>(value); ret = numberValue->getValue(); break; } case HSSParserNodeTypePercentageConstant: { HSSPercentageConstant::p percentageValue = boost::static_pointer_cast<HSSPercentageConstant>(value); ret = percentageValue->getValue(percentageBase); break; } case HSSParserNodeTypeExpression: { HSSExpression::p expressionValue = boost::static_pointer_cast<HSSExpression>(value); expressionValue->setPercentageBase(percentageBase); //expressionValue->setScope(scope); ret = expressionValue->evaluate(); if(callback != NULL){ expressionValue->observe(HSSObservablePropertyValue, observedSourceProperty, this, new HSSValueChangedCallback<HSSRgb>(this, callback)); observedStore = expressionValue.get(); observedStoreProperty = HSSObservablePropertyValue; } break; } case HSSParserNodeTypeKeywordConstant: break; default: throw AXRError::p(new AXRError("HSSRgb", "Unknown parser node type "+HSSParserNode::parserNodeStringRepresentation(nodeType)+" while setting value for HSSRgb property")); break; } return ret; }
void HSSFunction::setScope(HSSSimpleSelection::p newScope) { this->scope = newScope; std::deque<HSSParserNode::p>::const_iterator it; for (it = this->_arguments.begin(); it != this->_arguments.end(); ++it) { const HSSParserNode::p node = (*it); switch (node->getType()) { case HSSParserNodeTypeFunctionCall: { HSSFunction::p func = qSharedPointerCast<HSSFunction > (node); func->setScope(newScope); break; } case HSSParserNodeTypeExpression: { HSSExpression::p exp = qSharedPointerCast<HSSExpression > (node); exp->setScope(newScope); break; } default: break; } switch (node->getStatementType()) { case HSSStatementTypeObjectDefinition: { HSSObjectDefinition::p objdef = qSharedPointerCast<HSSObjectDefinition > (node); objdef->setScope(newScope); break; } default: break; } } }
HSSUnit HSSColorStop::_evaluatePropertyValue( void(HSSColorStop::*callback)(HSSObservableProperty property, void* data), HSSParserNode::p value, HSSUnit percentageBase, HSSObservableProperty observedSourceProperty, HSSObservable * &observedStore, HSSObservableProperty &observedStoreProperty ) { HSSUnit ret; HSSParserNodeType nodeType = value->getType(); switch (nodeType) { case HSSParserNodeTypeNumberConstant: { HSSNumberConstant::p numberValue = qSharedPointerCast<HSSNumberConstant > (value); ret = numberValue->getValue(); break; } case HSSParserNodeTypePercentageConstant: { HSSPercentageConstant::p percentageValue = qSharedPointerCast<HSSPercentageConstant > (value); ret = percentageValue->getValue(percentageBase); break; } case HSSParserNodeTypeExpression: { HSSExpression::p expressionValue = qSharedPointerCast<HSSExpression > (value); expressionValue->setPercentageBase(percentageBase); expressionValue->setScope(this->scope); expressionValue->setThisObj(this->getThisObj()); ret = expressionValue->evaluate(); if (callback) { expressionValue->observe(HSSObservablePropertyValue, observedSourceProperty, this, new HSSValueChangedCallback<HSSColorStop > (this, callback)); } break; } case HSSParserNodeTypeKeywordConstant: break; default: AXRWarning("HSSColorStop", "Unknown parser node type while setting value for HSSLineGradient property").raise(); break; } return ret; }
long double HSSDisplayObject::_setLDProperty( void(HSSDisplayObject::*callback)(HSSObservableProperty property, void* data), HSSParserNode::p value, long double percentageBase, HSSObservableProperty observedProperty, HSSObservable * observedObject, HSSObservable * &observedStore, HSSObservableProperty &observedStoreProperty, const std::vector<HSSDisplayObject::p> * scope ) { long double ret; HSSParserNodeType nodeType = value->getType(); switch (nodeType) { case HSSParserNodeTypeNumberConstant: { HSSNumberConstant::p numberValue = boost::static_pointer_cast<HSSNumberConstant>(value); ret = numberValue->getValue(); break; } case HSSParserNodeTypePercentageConstant: { HSSPercentageConstant::p percentageValue = boost::static_pointer_cast<HSSPercentageConstant>(value); ret = percentageValue->getValue(percentageBase); if(callback != NULL) { observedObject->observe(observedProperty, this, new HSSValueChangedCallback<HSSDisplayObject>(this, callback)); observedStore = observedObject; observedStoreProperty = observedProperty; } break; } case HSSParserNodeTypeExpression: { HSSExpression::p expressionValue = boost::static_pointer_cast<HSSExpression>(value); expressionValue->setPercentageBase(percentageBase); expressionValue->setPercentageObserved(observedProperty, observedObject); expressionValue->setScope(scope); ret = expressionValue->evaluate(); if(callback != NULL){ expressionValue->observe(HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSDisplayObject>(this, callback)); observedStore = expressionValue.get(); observedStoreProperty = HSSObservablePropertyValue; } break; } case HSSParserNodeTypeKeywordConstant: break; default: throw "unknown parser node type while setting dHeight"; break; } return ret; }
HSSUnit HSSExpression::evaluate() { if (this->isDirty()) { this->setDirty(false); //left switch (this->getLeft()->getType()) { case HSSParserNodeTypeExpression: { HSSExpression::p leftExpression = qSharedPointerCast<HSSExpression > (this->getLeft()); this->leftval = leftExpression->evaluate(); if (this->leftObserved) { this->leftObserved->removeObserver(this->leftObservedProperty, HSSObservablePropertyValue, this); } leftExpression->observe(HSSObservablePropertyValue, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::leftChanged)); this->leftObserved = leftExpression.data(); this->leftObservedProperty = HSSObservablePropertyValue; break; } case HSSParserNodeTypeNumberConstant: { HSSNumberConstant::p leftNumber = qSharedPointerCast<HSSNumberConstant > (this->getLeft()); this->leftval = leftNumber->getValue(); break; } case HSSParserNodeTypePercentageConstant: { HSSPercentageConstant::p leftPercentage = qSharedPointerCast<HSSPercentageConstant > (this->getLeft()); this->leftval = leftPercentage->getValue(this->percentageBase); if (this->leftObserved) { this->leftObserved->removeObserver(this->leftObservedProperty, HSSObservablePropertyValue, this); } this->percentageObserved->observe(this->percentageObservedProperty, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::leftChanged)); this->leftObserved = this->percentageObserved; this->leftObservedProperty = this->percentageObservedProperty; break; } case HSSParserNodeTypeFunctionCall: { HSSFunction::p leftFunction = qSharedPointerCast<HSSFunction > (this->getLeft()); QVariant remoteValue = leftFunction->evaluate(); if (remoteValue.canConvert<HSSUnit*>()) { this->leftval = *remoteValue.value<HSSUnit*>(); if (this->leftObserved) { this->leftObserved->removeObserver(this->leftObservedProperty, HSSObservablePropertyValue, this); } leftFunction->observe(HSSObservablePropertyValue, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::leftChanged)); this->leftObserved = leftFunction.data(); this->leftObservedProperty = HSSObservablePropertyValue; } else { this->rightval = 0.; } break; } default: std_log1("############ HSSExpression::evaluate() unknwown node type in left member"); break; } //right switch (this->getRight()->getType()) { case HSSParserNodeTypeExpression: { HSSExpression::p rightExpression = qSharedPointerCast<HSSExpression > (this->getRight()); this->rightval = rightExpression->evaluate(); if (this->rightObserved) { this->rightObserved->removeObserver(this->rightObservedProperty, HSSObservablePropertyValue, this); } rightExpression->observe(HSSObservablePropertyValue, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::rightChanged)); this->rightObserved = rightExpression.data(); this->rightObservedProperty = HSSObservablePropertyValue; break; } case HSSParserNodeTypeNumberConstant: { HSSNumberConstant::p rightNumber = qSharedPointerCast<HSSNumberConstant > (this->getRight()); this->rightval = rightNumber->getValue(); break; } case HSSParserNodeTypePercentageConstant: { HSSPercentageConstant::p rightPercentage = qSharedPointerCast<HSSPercentageConstant > (this->getRight()); this->rightval = rightPercentage->getValue(this->percentageBase); if (this->rightObserved) { this->rightObserved->removeObserver(this->rightObservedProperty, HSSObservablePropertyValue, this); } this->percentageObserved->observe(this->percentageObservedProperty, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::rightChanged)); this->rightObserved = this->percentageObserved; this->rightObservedProperty = this->percentageObservedProperty; break; } case HSSParserNodeTypeFunctionCall: { HSSFunction::p rightFunction = qSharedPointerCast<HSSFunction > (this->getRight()); QVariant remoteValue = rightFunction->evaluate(); if (remoteValue.canConvert<HSSUnit*>()) { this->rightval = *remoteValue.value<HSSUnit*>(); if (this->rightObserved) { this->rightObserved->removeObserver(this->rightObservedProperty, HSSObservablePropertyValue, this); } rightFunction->observe(HSSObservablePropertyValue, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::rightChanged)); this->rightObserved = rightFunction.data(); this->rightObservedProperty = HSSObservablePropertyValue; } else { this->rightval = 0.; } break; } default: std_log1("############ HSSExpression::evaluate() unknwown node type in right member"); break; } this->setValue(this->calculate(this->leftval, this->rightval)); } return this->getValue(); }