Ejemplo n.º 1
0
        private static float AdjustAmountAccordingToUnitType(string baseVariableName, float amount, object unitsVariableAsObject)
        {
            GeneralUnitType generalUnitType = UnitConverter.ConvertToGeneralUnit(unitsVariableAsObject);

            float xAmount;
            float yAmount;

            if (baseVariableName == "X" || baseVariableName == "Width")
            {
                xAmount = amount;
                yAmount = 0;
            }
            else
            {
                xAmount = 0;
                yAmount = amount;
            }


            if (generalUnitType != GeneralUnitType.PixelsFromLarge && generalUnitType != GeneralUnitType.PixelsFromMiddle && generalUnitType != GeneralUnitType.PixelsFromSmall)
            {
                float parentWidth;
                float parentHeight;
                float fileWidth;
                float fileHeight;
                float outX;
                float outY;


                IPositionedSizedObject ipso = WireframeObjectManager.Self.GetSelectedRepresentation();
                ipso.GetFileWidthAndHeight(out fileWidth, out fileHeight);
                ipso.GetParentWidthAndHeight(
                    ProjectManager.Self.GumProjectSave.DefaultCanvasWidth, ProjectManager.Self.GumProjectSave.DefaultCanvasHeight,
                    out parentWidth, out parentHeight);

                UnitConverter.Self.ConvertToUnitTypeCoordinates(xAmount, yAmount, unitsVariableAsObject, unitsVariableAsObject, parentWidth, parentHeight, fileWidth, fileHeight,
                                                                out outX, out outY);

                if (baseVariableName == "X" || baseVariableName == "Width")
                {
                    return(outX);
                }
                else
                {
                    return(outY);
                }
            }
            else
            {
                return(amount);
            }
        }
Ejemplo n.º 2
0
        private void ReactIfChangedMemberIsUnitType(ElementSave parentElement, string changedMember, object oldValue)
        {
            StateSave stateSave = SelectedState.Self.SelectedStateSave;

            IPositionedSizedObject currentIpso =
                WireframeObjectManager.Self.GetSelectedRepresentation();

            float parentWidth  = ObjectFinder.Self.GumProjectSave.DefaultCanvasWidth;
            float parentHeight = ObjectFinder.Self.GumProjectSave.DefaultCanvasHeight;

            float fileWidth  = 0;
            float fileHeight = 0;

            if (currentIpso != null)
            {
                currentIpso.GetFileWidthAndHeight(out fileWidth, out fileHeight);
                if (currentIpso.Parent != null)
                {
                    parentWidth  = currentIpso.Parent.Width;
                    parentHeight = currentIpso.Parent.Height;
                }
            }


            float  outX          = 0;
            float  outY          = 0;
            float  valueToSet    = 0;
            string variableToSet = null;

            bool isWidthOrHeight = false;

            bool wasAnythingSet = false;

            if (changedMember == "X Units" || changedMember == "Y Units" || changedMember == "Width Units" || changedMember == "Height Units")
            {
                object unitType = EditingManager.GetCurrentValueForVariable(changedMember, SelectedState.Self.SelectedInstance);
                XOrY   xOrY     = XOrY.X;
                if (changedMember == "X Units")
                {
                    variableToSet = "X";
                    xOrY          = XOrY.X;
                }
                else if (changedMember == "Y Units")
                {
                    variableToSet = "Y";
                    xOrY          = XOrY.Y;
                }
                else if (changedMember == "Width Units")
                {
                    variableToSet   = "Width";
                    isWidthOrHeight = true;
                    xOrY            = XOrY.X;
                }
                else if (changedMember == "Height Units")
                {
                    variableToSet   = "Height";
                    isWidthOrHeight = true;
                    xOrY            = XOrY.Y;
                }



                float valueOnObject = 0;
                if (stateSave.TryGetValue <float>(GetQualifiedName(variableToSet), out valueOnObject))
                {
                    if (xOrY == XOrY.X)
                    {
                        UnitConverter.Self.ConvertToPixelCoordinates(
                            valueOnObject, 0, oldValue, null, parentWidth, parentHeight, fileWidth, fileHeight, out outX, out outY);

                        UnitConverter.Self.ConvertToUnitTypeCoordinates(
                            outX, outY, unitType, null, parentWidth, parentHeight, fileWidth, fileHeight, out valueToSet, out outY);
                    }
                    else
                    {
                        UnitConverter.Self.ConvertToPixelCoordinates(
                            0, valueOnObject, null, oldValue, parentWidth, parentHeight, fileWidth, fileHeight, out outX, out outY);

                        UnitConverter.Self.ConvertToUnitTypeCoordinates(
                            outX, outY, null, unitType, parentWidth, parentHeight, fileWidth, fileHeight, out outX, out valueToSet);
                    }
                    wasAnythingSet = true;
                }
            }

            if (wasAnythingSet)
            {
                InstanceSave instanceSave = SelectedState.Self.SelectedInstance;
                if (SelectedState.Self.SelectedInstance != null)
                {
                    variableToSet = SelectedState.Self.SelectedInstance.Name + "." + variableToSet;
                }

                stateSave.SetValue(variableToSet, valueToSet, instanceSave);
            }
        }