public void RefreshSelector(ImageRegionSelectionControl control) { // early out if (control.RectangleSelector != null && control.RectangleSelector.SideGrabbed != FlatRedBall.SpecializedXnaControls.RegionSelection.ResizeSide.None) { return; } if (shouldRefreshAccordingToVariableSets == false) { return; } //////////////end early out/////////////////////////////// var shouldClearOut = true; if (SelectedState.Self.SelectedStateSave != null) { var graphicalUiElement = SelectedState.Self.SelectedIpso as GraphicalUiElement; var rfv = new RecursiveVariableFinder(SelectedState.Self.SelectedStateSave); var instancePrefix = SelectedState.Self.SelectedInstance?.Name; if (!string.IsNullOrEmpty(instancePrefix)) { instancePrefix += "."; } var textureAddress = rfv.GetValue <Gum.Managers.TextureAddress>($"{instancePrefix}Texture Address"); if (textureAddress == Gum.Managers.TextureAddress.Custom) { shouldClearOut = false; control.DesiredSelectorCount = 1; var selector = control.RectangleSelector; selector.Left = rfv.GetValue <int>($"{instancePrefix}Texture Left"); selector.Width = rfv.GetValue <int>($"{instancePrefix}Texture Width"); selector.Top = rfv.GetValue <int>($"{instancePrefix}Texture Top"); selector.Height = rfv.GetValue <int>($"{instancePrefix}Texture Height"); selector.Visible = true; selector.ShowHandles = true; selector.ShowMoveCursorWhenOver = true; control.SystemManagers.Renderer.Camera.X = selector.Left + selector.Width / 2.0f; control.SystemManagers.Renderer.Camera.Y = selector.Top + selector.Height / 2.0f; } } if (shouldClearOut) { control.DesiredSelectorCount = 0; } }
private static void TryGetFontReferences(TopLevelOrRecursive topLevelOrRecursive, List <string> listToFill, Gum.DataTypes.Variables.StateSave state) { Gum.DataTypes.RecursiveVariableFinder rvf = new RecursiveVariableFinder(state); foreach (var variable in state.Variables.Where(item => (item.GetRootName() == "Font" || item.GetRootName() == "FontSize" || item.GetRootName() == "OutlineThickness") && item.Value != null )) { string prefix = null; if (variable.Name.Contains('.')) { prefix = FileManager.RemoveExtension(variable.Name) + "."; } bool useCustomFont = rvf.GetValue <bool>(prefix + "UseCustomFont"); if (!useCustomFont) { var fontSizeVariableName = prefix + "FontSize"; var fontNameVariableName = prefix + "Font"; var fontOutlineVariableName = prefix + "OutlineThickness"; int fontSizeValue = rvf.GetValue <int>(fontSizeVariableName); string fontNameValue = rvf.GetValue <string>(fontNameVariableName); int outlineThickness = rvf.GetValue <int>(fontOutlineVariableName); TryAddFontFromSizeAndName(topLevelOrRecursive, listToFill, fontSizeValue, fontNameValue, outlineThickness); } } }
static Microsoft.Xna.Framework.Color ColorFromRvf(RecursiveVariableFinder rvf) { Microsoft.Xna.Framework.Color color = new Microsoft.Xna.Framework.Color( rvf.GetValue <int>("Red"), rvf.GetValue <int>("Green"), rvf.GetValue <int>("Blue"), rvf.GetValue <int>("Alpha") ); return(color); }
private NamedObjectSave CreateNosFor(InstanceSave instance, IElement container) { NamedObjectSave nos = new NamedObjectSave(); string name = instance.Name; // See if this name is already used by RFS's var allRfss = container.GetAllReferencedFileSavesRecursively(); while (allRfss.Any(item => item.GetInstanceName() == name) || container.ReferencedFiles.Any(item => item.Name == name)) { name = name + instance.BaseType; } nos.InstanceName = name; RecursiveVariableFinder rvf = new RecursiveVariableFinder(instance, instance.ParentContainer); if (instance.BaseType == "Sprite") { nos.SourceType = SourceType.FlatRedBallType; nos.SourceClassType = "Sprite"; float width = rvf.GetValue <float>("Width"); float height = rvf.GetValue <float>("Height"); if (width == 0 && height == 0) { nos.SetPropertyValue("TextureScale", 1.0f); } else { // Eventually handle width/height nos.SetPropertyValue("Width", width); nos.SetPropertyValue("Height", height); } SetPositionValuesOn(nos, instance); string texture = rvf.GetValue <string>("SourceFile"); string fileInstanceName = FileManager.RemoveExtension(FileManager.RemovePath(texture)); var added = nos.SetPropertyValue("Texture", fileInstanceName); added.Type = "Texture2D"; } return(nos); }
private NamedObjectSave CreateNosFor(InstanceSave instance, IElement container) { NamedObjectSave nos = new NamedObjectSave(); string name = instance.Name; // See if this name is already used by RFS's var allRfss = container.GetAllReferencedFileSavesRecursively(); while (allRfss.Any(item => item.GetInstanceName() == name) || container.ReferencedFiles.Any(item => item.Name == name)) { name = name + instance.BaseType; } nos.InstanceName = name; RecursiveVariableFinder rvf = new RecursiveVariableFinder(instance, instance.ParentContainer); if (instance.BaseType == "Sprite") { nos.SourceType = SourceType.FlatRedBallType; nos.SourceClassType = "Sprite"; float width = rvf.GetValue<float>("Width"); float height = rvf.GetValue<float>("Height"); if (width == 0 && height == 0) { nos.SetPropertyValue("TextureScale", 1.0f); } else { // Eventually handle width/height nos.SetPropertyValue("Width", width); nos.SetPropertyValue("Height", height); } SetPositionValuesOn(nos, instance); string texture = rvf.GetValue<string>("SourceFile"); string fileInstanceName = FileManager.RemoveExtension(FileManager.RemovePath(texture)); var added = nos.SetPropertyValue("Texture", fileInstanceName); added.Type = "Texture2D"; } return nos; }
private static void ProcessColorForLabel(List <VariableSave> variablesToConsider, StateSave defaultState, InstanceSave instance, StringBuilder stringBuilder) { var instanceName = instance.Name; var rfv = new RecursiveVariableFinder(defaultState); var red = rfv.GetValue <int>(instanceName + ".Red"); var green = rfv.GetValue <int>(instanceName + ".Green"); var blue = rfv.GetValue <int>(instanceName + ".Blue"); var alpha = rfv.GetValue <int>(instanceName + ".Alpha"); variablesToConsider.RemoveAll(item => item.Name == instanceName + ".Red"); variablesToConsider.RemoveAll(item => item.Name == instanceName + ".Green"); variablesToConsider.RemoveAll(item => item.Name == instanceName + ".Blue"); variablesToConsider.RemoveAll(item => item.Name == instanceName + ".Alpha"); stringBuilder.AppendLine($"{instanceName}.TextColor = Color.FromRgba({red}, {green}, {blue}, {alpha});"); }
private void FillListWithReferencedFiles(List <string> files, ElementSave element) { RecursiveVariableFinder rvf; string value; foreach (var state in element.AllStates) { rvf = new RecursiveVariableFinder(element.DefaultState); value = rvf.GetValue <string>("SourceFile"); if (!string.IsNullOrEmpty(value)) { files.Add(value); } value = rvf.GetValue <string>("CustomFontFile"); if (!string.IsNullOrEmpty(value)) { files.Add(value); } List <Gum.Wireframe.ElementWithState> elementStack = new List <Wireframe.ElementWithState>(); var elementWithState = new Gum.Wireframe.ElementWithState(element); elementWithState.StateName = state.Name; elementStack.Add(elementWithState); foreach (InstanceSave instance in element.Instances) { rvf = new RecursiveVariableFinder(instance, elementStack); value = rvf.GetValue <string>("SourceFile"); if (!string.IsNullOrEmpty(value)) { files.Add(value); } value = rvf.GetValue <string>("CustomFontFile"); if (!string.IsNullOrEmpty(value)) { files.Add(value); } } } }
public float GetEffectiveHeight(InstanceSave instance) { RecursiveVariableFinder rvf = new RecursiveVariableFinder(instance, instance.ParentContainer); float height = rvf.GetValue <float>("Height"); if (height == 0) { string sourceFile = rvf.GetValue <string>("SourceFile"); if (instance.BaseType == "Sprite") { if (!string.IsNullOrEmpty(sourceFile)) { string fullFileName = FileManager.GetDirectory(GumProjectSave.FullFileName) + sourceFile; height = ImageHeader.GetDimensions(fullFileName).Height; } } } return(height); }
public static bool IsParentASibling(this InstanceSave instanceSave, List<ElementWithState> elementStack) { if (instanceSave == null) { throw new ArgumentException("InstanceSave must not be null"); } RecursiveVariableFinder rvf = new RecursiveVariableFinder(instanceSave, elementStack); string parent = rvf.GetValue<string>("Parent"); bool found = false; if (!string.IsNullOrEmpty(parent) && parent != AvailableInstancesConverter.ScreenBoundsName) { ElementSave parentElement = instanceSave.ParentContainer; found = parentElement.Instances.Any(item => item.Name == parent); } return found; }
private void FillListWithReferencedFiles(List <string> files, ElementSave element) { RecursiveVariableFinder rvf; string value; foreach (var state in element.AllStates) { rvf = new RecursiveVariableFinder(element.DefaultState); value = rvf.GetValue <string>("SourceFile"); if (!string.IsNullOrEmpty(value)) { files.Add(value); } value = rvf.GetValue <string>("CustomFontFile"); if (!string.IsNullOrEmpty(value)) { files.Add(value); } List <Gum.Wireframe.ElementWithState> elementStack = new List <Wireframe.ElementWithState>(); var elementWithState = new Gum.Wireframe.ElementWithState(element); elementWithState.StateName = state.Name; elementStack.Add(elementWithState); foreach (InstanceSave instance in element.Instances) { // August 5, 2018 - why are we not considering // the file name of the element? Isn't that a referenced // file? var instanceElement = GetElementSave(instance); if (instanceElement != null) { string prefix = FileManager.GetDirectory(GumProjectSave.FullFileName); if (instanceElement is ComponentSave) { prefix += "Components/"; } else // standard element { prefix += "Standards/"; } files.Add(prefix + instanceElement.Name + "." + instanceElement.FileExtension); } rvf = new RecursiveVariableFinder(instance, elementStack); value = rvf.GetValue <string>("SourceFile"); if (!string.IsNullOrEmpty(value)) { files.Add(value); } value = rvf.GetValue <string>("CustomFontFile"); if (!string.IsNullOrEmpty(value)) { files.Add(value); } } } }
private static void SetAlignmentValues(Text text, RecursiveVariableFinder rvf) { //Could these potentially be out of bounds? text.HorizontalAlignment = rvf.GetValue <HorizontalAlignment>("HorizontalAlignment"); text.VerticalAlignment = rvf.GetValue <VerticalAlignment>("VerticalAlignment"); }
public float GetEffectiveHeight(InstanceSave instance) { RecursiveVariableFinder rvf = new RecursiveVariableFinder(instance, instance.ParentContainer); float height = rvf.GetValue<float>("Height"); if (height == 0) { string sourceFile = rvf.GetValue<string>("SourceFile"); if (instance.BaseType == "Sprite") { if (!string.IsNullOrEmpty(sourceFile)) { string fullFileName = FileManager.GetDirectory(GumProjectSave.FullFileName) + sourceFile; height = ImageHeader.GetDimensions(fullFileName).Height; } } } return height; }
private static void SetAlignmentValues(Text text, RecursiveVariableFinder rvf) { //Could these potentially be out of bounds? text.HorizontalAlignment = rvf.GetValue<HorizontalAlignment>("HorizontalAlignment"); text.VerticalAlignment = rvf.GetValue<VerticalAlignment>("VerticalAlignment"); }
static Microsoft.Xna.Framework.Color ColorFromRvf(RecursiveVariableFinder rvf) { Microsoft.Xna.Framework.Color color = new Microsoft.Xna.Framework.Color( rvf.GetValue<int>("Red"), rvf.GetValue<int>("Green"), rvf.GetValue<int>("Blue"), rvf.GetValue<int>("Alpha") ); return color; }
private static bool TryHandleAssigningMultipleVariables(ElementSave gumElement, GumInstance gumInstance, string variableName, GlueElement glueElement, FlatRedBall.Glue.SaveClasses.NamedObjectSave foundNos, object gumValue) { var isTextureValue = variableName == "Texture Address" || variableName == "Texture Left" || variableName == "Texture Top" || variableName == "Texture Width" || variableName == "Texture Height"; var handled = false; if (isTextureValue) { string variablePrefix = null; if (gumInstance != null) { variablePrefix = $"{gumInstance.Name}."; } var state = SelectedState.Self.SelectedStateSave; var addressValueGumCurrent = state.GetValue($"{variablePrefix}Texture Address"); var textureLeftValueGumCurrent = state.GetValue($"{variablePrefix}Texture Left"); var textureWidthValueGumCurrent = state.GetValue($"{variablePrefix}Texture Width"); var textureTopValueGumCurrent = state.GetValue($"{variablePrefix}Texture Top"); var textureHeightValueGumCurrent = state.GetValue($"{variablePrefix}Texture Height"); var setsAny = addressValueGumCurrent != null || textureLeftValueGumCurrent != null || textureWidthValueGumCurrent != null || textureTopValueGumCurrent != null || textureHeightValueGumCurrent != null; if (setsAny) { var rvf = new RecursiveVariableFinder(state); var addressValueGumRecursive = rvf.GetValue <TextureAddress>($"{variablePrefix}Texture Address"); // set them all if (addressValueGumRecursive == TextureAddress.EntireTexture) { // null them out: HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Left", glueElement, foundNos, null); HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Right", glueElement, foundNos, null); HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Top", glueElement, foundNos, null); HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Bottom", glueElement, foundNos, null); } else { // set the values: HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Left", glueElement, foundNos, IntToNullOrFloat(textureLeftValueGumCurrent)); HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Top", glueElement, foundNos, IntToNullOrFloat(textureTopValueGumCurrent)); // right and bottom depend on left/top plus width/height if (textureLeftValueGumCurrent != null && textureWidthValueGumCurrent != null) { var combined = (int)textureLeftValueGumCurrent + (int)textureWidthValueGumCurrent; HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Right", glueElement, foundNos, (float)combined); } else { HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Right", glueElement, foundNos, IntToNullOrFloat(null)); } if (textureTopValueGumCurrent != null && textureHeightValueGumCurrent != null) { var combined = (int)textureTopValueGumCurrent + (int)textureHeightValueGumCurrent; HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Bottom", glueElement, foundNos, (float)combined); } else { HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Bottom", glueElement, foundNos, null); } } } else { // null them all HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Left", glueElement, foundNos, null); HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Right", glueElement, foundNos, null); HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Top", glueElement, foundNos, null); HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Bottom", glueElement, foundNos, null); } handled = true; } return(handled); }
private static void ProcessPositionAndSize(List <VariableSave> variablesToConsider, StateSave defaultState, InstanceSave instance, StringBuilder stringBuilder, int tabCount) { string prefix = instance?.Name == null ? "" : instance.Name + "."; var setsAny = defaultState.Variables.Any(item => item.Name == prefix + "X" || item.Name == prefix + "Y" || item.Name == prefix + "Width" || item.Name == prefix + "Height" || item.Name == prefix + "X Units" || item.Name == prefix + "Y Units" || item.Name == prefix + "Width Units" || item.Name == prefix + "Height Units" || item.Name == prefix + "X Origin" || item.Name == prefix + "Y Origin" ); if (setsAny) { var variableFinder = new RecursiveVariableFinder(defaultState); var x = variableFinder.GetValue <float>(prefix + "X"); var y = variableFinder.GetValue <float>(prefix + "Y"); var width = variableFinder.GetValue <float>(prefix + "Width"); var height = variableFinder.GetValue <float>(prefix + "Height"); var xUnits = variableFinder.GetValue <PositionUnitType>(prefix + "X Units"); var yUnits = variableFinder.GetValue <PositionUnitType>(prefix + "Y Units"); var widthUnits = variableFinder.GetValue <DimensionUnitType>(prefix + "Width Units"); var heightUnits = variableFinder.GetValue <DimensionUnitType>(prefix + "Height Units"); var xOrigin = variableFinder.GetValue <HorizontalAlignment>(prefix + "X Origin"); var yOrigin = variableFinder.GetValue <VerticalAlignment>(prefix + "Y Origin"); variablesToConsider.RemoveAll(item => item.Name == prefix + "X"); variablesToConsider.RemoveAll(item => item.Name == prefix + "Y"); variablesToConsider.RemoveAll(item => item.Name == prefix + "Width"); variablesToConsider.RemoveAll(item => item.Name == prefix + "Height"); variablesToConsider.RemoveAll(item => item.Name == prefix + "X Units"); variablesToConsider.RemoveAll(item => item.Name == prefix + "Y Units"); variablesToConsider.RemoveAll(item => item.Name == prefix + "Width Units"); variablesToConsider.RemoveAll(item => item.Name == prefix + "Height Units"); List <string> proportionalFlags = new List <string>(); const string WidthProportionalFlag = "AbsoluteLayoutFlags.WidthProportional"; const string HeightProportionalFlag = "AbsoluteLayoutFlags.HeightProportional"; const string XProportionalFlag = "AbsoluteLayoutFlags.XProportional"; const string YProportionalFlag = "AbsoluteLayoutFlags.YProportional"; if (widthUnits == DimensionUnitType.Percentage) { width /= 100.0f; proportionalFlags.Add(WidthProportionalFlag); } else if (widthUnits == DimensionUnitType.RelativeToContainer) { if (width == 0) { width = 1; proportionalFlags.Add(WidthProportionalFlag); } else { // not allowed!!! } } if (heightUnits == DimensionUnitType.Percentage) { height /= 100.0f; proportionalFlags.Add(HeightProportionalFlag); } else if (heightUnits == DimensionUnitType.RelativeToContainer) { if (height == 0) { height = 1; proportionalFlags.Add(HeightProportionalFlag); } else { // not allowed! } } // special case // If we're using the center with x=0 we'll pretend it's the same as 50% if (xUnits == PositionUnitType.PixelsFromCenterX && widthUnits == DimensionUnitType.Absolute && xOrigin == HorizontalAlignment.Center) { if (x == 0) { // treat it like it's 50%: x = .5f; proportionalFlags.Add(XProportionalFlag); } } // Xamarin forms uses a weird anchoring system to combine both position and anchor into one value. Gum splits those into two values // We need to convert from the gum units to xamforms units: // for now assume it's all %'s: else if (xUnits == PositionUnitType.PercentageWidth) { x /= 100.0f; var adjustedCanvasWidth = 1 - width; if (adjustedCanvasWidth > 0) { x /= adjustedCanvasWidth; } proportionalFlags.Add(XProportionalFlag); } else if (xUnits == PositionUnitType.PixelsFromLeft) { } else if (xUnits == PositionUnitType.PixelsFromCenterX) { if (widthUnits == DimensionUnitType.Absolute) { x = (CanvasWidth - width) / 2.0f; } } if (yUnits == PositionUnitType.PixelsFromCenterY && heightUnits == DimensionUnitType.Absolute && yOrigin == VerticalAlignment.Center) { if (y == 0) { y = .5f; proportionalFlags.Add(YProportionalFlag); } } else if (yUnits == PositionUnitType.PercentageHeight) { y /= 100.0f; var adjustedCanvasHeight = 1 - height; if (adjustedCanvasHeight > 0) { y /= adjustedCanvasHeight; } proportionalFlags.Add(YProportionalFlag); } else if (yUnits == PositionUnitType.PixelsFromCenterY) { if (heightUnits == DimensionUnitType.Absolute) { y = (CanvasHeight - height) / 2.0f; } } else if (yUnits == PositionUnitType.PixelsFromBottom) { y += CanvasHeight; if (yOrigin == VerticalAlignment.Bottom) { y -= height; } } var xString = x.ToString(CultureInfo.InvariantCulture) + "f"; var yString = y.ToString(CultureInfo.InvariantCulture) + "f"; var widthString = width.ToString(CultureInfo.InvariantCulture) + "f"; var heightString = height.ToString(CultureInfo.InvariantCulture) + "f"; if (AdjustPixelValuesForDensity) { if (proportionalFlags.Contains(XProportionalFlag) == false) { xString += "/Xamarin.Essentials.DeviceDisplay.MainDisplayInfo.Density"; } if (proportionalFlags.Contains(YProportionalFlag) == false) { yString += "/Xamarin.Essentials.DeviceDisplay.MainDisplayInfo.Density"; } if (proportionalFlags.Contains(WidthProportionalFlag) == false) { widthString += "/Xamarin.Essentials.DeviceDisplay.MainDisplayInfo.Density"; } if (proportionalFlags.Contains(HeightProportionalFlag) == false) { heightString += "/Xamarin.Essentials.DeviceDisplay.MainDisplayInfo.Density"; } } string boundsText = $"{ToTabs(tabCount)}AbsoluteLayout.SetLayoutBounds({instance?.Name ?? "this"}, new Rectangle({xString}, {yString}, {widthString}, {heightString}));"; string flagsText = null; if (proportionalFlags.Count > 0) { string flagsArguments = null; for (int i = 0; i < proportionalFlags.Count; i++) { if (i > 0) { flagsArguments += " | "; } flagsArguments += proportionalFlags[i]; } flagsText = $"{ToTabs(tabCount)}AbsoluteLayout.SetLayoutFlags({instance?.Name ?? "this"}, {flagsArguments});"; } // assume every object has X, which it won't, so we will have to improve this if (string.IsNullOrWhiteSpace(flagsText)) { stringBuilder.AppendLine(boundsText); } else { stringBuilder.AppendLine($"{boundsText}\n{flagsText}"); } } }
private static void TryGetFontReferences(TopLevelOrRecursive topLevelOrRecursive, List <string> listToFill, Gum.DataTypes.Variables.StateSave state) { Gum.DataTypes.RecursiveVariableFinder rvf = new RecursiveVariableFinder(state); foreach (var variable in state.Variables.Where(item => (item.GetRootName() == "Font" || item.GetRootName() == "FontSize" || item.GetRootName() == "OutlineThickness" || item.GetRootName() == "UseFontSmoothing" ) && item.Value != null )) { string prefix = null; // Just because this has a variable for Font or FontSize or whatever doesn't // necessarily mean that this is a text object - it could have been an instance // that at one time was a text object, but was later converted to a different type // which no longer uses fonts. To handle this case we want to only consider this a referenced // file if Coo var isTextObject = true; if (variable.Name.Contains('.')) { var instanceName = FileManager.RemoveExtension(variable.Name); prefix = FileManager.RemoveExtension(variable.Name) + "."; var instance = state.ParentContainer.GetInstance(instanceName); if (instance != null) { var basicElement = ObjectFinder.Self.GetRootStandardElementSave(instance.GetBaseElementSave()); isTextObject = basicElement?.Name == "Text"; } else { // This code is used to // determine whether a referenced // file is necessary in the project. // Since the instance doesn't exist, we // won't actually use the variable for the // instance, so we don't want to track the file. // We can do this by marking isTextObject as false. isTextObject = false; } } if (isTextObject) { bool useCustomFont = rvf.GetValue <bool>(prefix + "UseCustomFont"); if (!useCustomFont) { var fontSizeVariableName = prefix + "FontSize"; var fontNameVariableName = prefix + "Font"; var fontOutlineVariableName = prefix + "OutlineThickness"; var fontSmoothingVariableName = prefix + "UseFontSmoothing"; int fontSizeValue = rvf.GetValue <int>(fontSizeVariableName); string fontNameValue = rvf.GetValue <string>(fontNameVariableName); int outlineThickness = rvf.GetValue <int>(fontOutlineVariableName); bool useFontSmoothing = rvf.GetValue <bool>(fontSmoothingVariableName); TryAddFontFromSizeAndName(topLevelOrRecursive, listToFill, fontSizeValue, fontNameValue, outlineThickness, useFontSmoothing); } } } }
private void SetPositionValuesOn(Glue.SaveClasses.NamedObjectSave nos, InstanceSave instance) { RecursiveVariableFinder rvf = new RecursiveVariableFinder(instance, instance.ParentContainer); float x = rvf.GetValue <float>("X"); float y = rvf.GetValue <float>("Y"); #region Adjust values according to object origin float effectiveWidth = GetEffectiveWidth(instance); float effectiveHeight = GetEffectiveHeight(instance); HorizontalAlignment horizontalOrigin = rvf.GetValue <HorizontalAlignment>("X Origin"); VerticalAlignment verticalOrigin = rvf.GetValue <VerticalAlignment>("Y Origin"); switch (horizontalOrigin) { case HorizontalAlignment.Left: x += effectiveWidth / 2.0f; break; case HorizontalAlignment.Right: x -= effectiveWidth / 2.0f; break; } switch (verticalOrigin) { case VerticalAlignment.Top: y += effectiveHeight / 2.0f; break; case VerticalAlignment.Bottom: y -= effectiveHeight / 2.0f; break; } #endregion #region Adjust values according to alignment float parentWidth = GetParentWidth(instance); float parentHeight = GetParentHeight(instance); PositionUnitType xUnits = rvf.GetValue <PositionUnitType>("X Units"); PositionUnitType yUnits = rvf.GetValue <PositionUnitType>("Y Units"); switch (xUnits) { case PositionUnitType.PixelsFromLeft: x -= parentWidth / 2.0f; break; case PositionUnitType.PixelsFromCenterX: // do nothing break; default: throw new NotImplementedException(); break; } switch (yUnits) { case PositionUnitType.PixelsFromTop: y -= parentHeight / 2.0f; break; case PositionUnitType.PixelsFromCenterY: // do nothing break; default: break; } #endregion nos.SetPropertyValue("X", x); // Invert Y because FRB uses positive Y is up nos.SetPropertyValue("Y", -y); }
private void SetPositionValuesOn(Glue.SaveClasses.NamedObjectSave nos, InstanceSave instance) { RecursiveVariableFinder rvf = new RecursiveVariableFinder(instance, instance.ParentContainer); float x = rvf.GetValue<float>("X"); float y = rvf.GetValue<float>("Y"); #region Adjust values according to object origin float effectiveWidth = GetEffectiveWidth(instance); float effectiveHeight = GetEffectiveHeight(instance); HorizontalAlignment horizontalOrigin = rvf.GetValue<HorizontalAlignment>("X Origin"); VerticalAlignment verticalOrigin = rvf.GetValue<VerticalAlignment>("Y Origin"); switch (horizontalOrigin) { case HorizontalAlignment.Left: x += effectiveWidth / 2.0f; break; case HorizontalAlignment.Right: x -= effectiveWidth / 2.0f; break; } switch (verticalOrigin) { case VerticalAlignment.Top: y += effectiveHeight / 2.0f; break; case VerticalAlignment.Bottom: y -= effectiveHeight / 2.0f; break; } #endregion #region Adjust values according to alignment float parentWidth = GetParentWidth(instance); float parentHeight = GetParentHeight(instance); PositionUnitType xUnits = rvf.GetValue<PositionUnitType>("X Units"); PositionUnitType yUnits = rvf.GetValue<PositionUnitType>("Y Units"); switch (xUnits) { case PositionUnitType.PixelsFromLeft: x -= parentWidth / 2.0f; break; case PositionUnitType.PixelsFromCenterX: // do nothing break; default: throw new NotImplementedException(); break; } switch (yUnits) { case PositionUnitType.PixelsFromTop: y -= parentHeight / 2.0f; break; case PositionUnitType.PixelsFromCenterY: // do nothing break; default: break; } #endregion nos.SetPropertyValue("X", x); // Invert Y because FRB uses positive Y is up nos.SetPropertyValue("Y", -y); }