Esempio n. 1
0
 void Term(out ClLinearExpression e)
 {
     e = null; ClLinearExpression e1;
     Factor(out e);
     while (la.kind == 8 || la.kind == 9)
     {
         if (la.kind == 8)
         {
             Get();
             Factor(out e1);
             e = Cl.Times(e, e1);
         }
         else
         {
             Get();
             Factor(out e1);
             e = Cl.Divide(e, e1);
         }
     }
 }
        protected ClVariable GetCompositeVariableFromViewAndAttribute(T view, LayoutAttribute attribute)
        {
            if (HasVariableForViewAndAttribute(view, attribute))
            {
                return(GetVariableFromViewAndAttribute(view, attribute));
            }

            switch (attribute)
            {
            case LayoutAttribute.Width:
            {
                var leftVar  = GetVariableFromViewAndAttribute(view, LayoutAttribute.Left);
                var rightVar = GetVariableFromViewAndAttribute(view, LayoutAttribute.Right);

                var widthExpression = Cl.Minus(
                    new ClLinearExpression(rightVar),
                    new ClLinearExpression(leftVar)
                    );

                var widthVariable = new ClVariable(viewEngine.GetViewName(view) + ".Width");

                solver.AddConstraint(new ClLinearEquation(
                                         widthVariable,
                                         widthExpression,
                                         ClStrength.Required
                                         ));

                AddVariableForViewAndAttribute(view, attribute, widthVariable);
                return(widthVariable);
            }

            case LayoutAttribute.Height:
            {
                var topVar    = GetVariableFromViewAndAttribute(view, LayoutAttribute.Top);
                var bottomVar = GetVariableFromViewAndAttribute(view, LayoutAttribute.Bottom);

                var heightExpression = Cl.Minus(
                    new ClLinearExpression(bottomVar),
                    new ClLinearExpression(topVar)
                    );

                var heightVariable = new ClVariable(viewEngine.GetViewName(view) + ".Height");

                solver.AddConstraint(new ClLinearEquation(
                                         heightVariable,
                                         heightExpression,
                                         ClStrength.Required
                                         ));


                solver.AddConstraint(new ClLinearInequality(
                                         heightVariable,
                                         Cl.Operator.GreaterThanOrEqualTo,
                                         new ClLinearExpression(0)
                                         ));


                AddVariableForViewAndAttribute(view, attribute, heightVariable);
                return(heightVariable);
            }

            case LayoutAttribute.CenterX:
            {
                var leftVar  = GetVariableFromViewAndAttribute(view, LayoutAttribute.Left);
                var rightVar = GetVariableFromViewAndAttribute(view, LayoutAttribute.Right);

                var centerXExpression = Cl.Plus(
                    Cl.Divide(new ClLinearExpression(leftVar), new ClLinearExpression(2)),
                    Cl.Divide(new ClLinearExpression(rightVar), new ClLinearExpression(2))
                    );

                var centerXVariable = new ClVariable(viewEngine.GetViewName(view) + ".CenterX");
                solver.AddConstraint(new ClLinearEquation(
                                         centerXVariable,
                                         centerXExpression,
                                         ClStrength.Required
                                         ));

                AddVariableForViewAndAttribute(view, attribute, centerXVariable);
                return(centerXVariable);
            }

            case LayoutAttribute.CenterY:
            {
                var topVar    = GetVariableFromViewAndAttribute(view, LayoutAttribute.Top);
                var bottomVar = GetVariableFromViewAndAttribute(view, LayoutAttribute.Bottom);

                var centerYExpression = Cl.Plus(
                    Cl.Divide(new ClLinearExpression(topVar), new ClLinearExpression(2)),
                    Cl.Divide(new ClLinearExpression(bottomVar), new ClLinearExpression(2))
                    );

                var centerYVariable = new ClVariable(viewEngine.GetViewName(view) + ".CenterY");
                solver.AddConstraint(new ClLinearEquation(
                                         centerYVariable,
                                         centerYExpression,
                                         ClStrength.Required
                                         ));

                AddVariableForViewAndAttribute(view, attribute, centerYVariable);
                return(centerYVariable);
            }
            }

            return(null);
        }