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
}
예제 #2
0
void HSSExpression::rightChanged(HSSObservableProperty property, void* data)
{
    switch (this->getRight()->getType())
    {
    case HSSParserNodeTypeExpression:
    case HSSParserNodeTypeNumberConstant:
    case HSSParserNodeTypeFunctionCall:
    {
        this->rightval = *(HSSUnit*) data;
        break;
    }

    case HSSParserNodeTypePercentageConstant:
    {
        HSSPercentageConstant::p rightPercentage = qSharedPointerCast<HSSPercentageConstant > (this->getRight());
        this->rightval = rightPercentage->getValue(*(HSSUnit*) data);
        break;
    }

    default:
        std_log1("############ HSSExpression::evaluate() unknwown node type in right member");
        break;
    }
    this->_value = this->calculate(this->leftval, this->rightval);
    this->notifyObservers(HSSObservablePropertyValue, &this->_value);
}
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);
}
예제 #4
0
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;
}
예제 #5
0
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;
}
예제 #6
0
void HSSColorStop::balanceChanged(AXR::HSSObservableProperty source, void *data)
{
    switch (this->dBalance->getType())
    {
    case HSSParserNodeTypeNumberConstant:
    case HSSParserNodeTypeExpression:
    case HSSParserNodeTypeFunctionCall:
        this->balance = *(HSSUnit*) data;
        break;

    case HSSParserNodeTypePercentageConstant:
    {
        HSSPercentageConstant::p percentageValue = qSharedPointerCast<HSSPercentageConstant > (this->dBalance);
        this->balance = percentageValue->getValue(*(HSSUnit*) data);
        break;
    }

    default:
        break;
    }

    this->notifyObservers(HSSObservablePropertyBalance, data);
    this->notifyObservers(HSSObservablePropertyValue, NULL);
}
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;
}
예제 #8
0
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();
}