Ejemplo n.º 1
0
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);
}
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;
}