private void SetUpParentRelationship(IEnumerable <GraphicalUiElement> siblings, List <ElementWithState> elementStack, IEnumerable <InstanceSave> childrenInstances) { // Now that we have created all instances, we can establish parent relationships foreach (GraphicalUiElement contained in siblings) { if (contained.Tag is InstanceSave) { InstanceSave childInstanceSave = contained.Tag as InstanceSave; RecursiveVariableFinder rvf = new DataTypes.RecursiveVariableFinder(childInstanceSave, elementStack); string parentName = rvf.GetValue <string>("Parent"); if (!string.IsNullOrEmpty(parentName) && parentName != AvailableInstancesConverter.ScreenBoundsName) { IRenderableIpso newParent = siblings.FirstOrDefault(item => item.Name == parentName); // This may have bad XML so if it doesn't exist, then let's ignore this: if (newParent != null) { contained.Parent = newParent; } } } } }
public void Add(IRenderableIpso renderable) { lock (mRenderables) { mRenderables.Add(renderable); } }
public void SetValuesFrom(IRenderableIpso ipso) { //if(ipso is GraphicalUiElement gue && (gue.RenderableComponent as IRenderableIpso) != null) //{ // ipso = (gue.RenderableComponent as IRenderableIpso); //} this.mX = ipso.GetAbsoluteX(); this.mY = ipso.GetAbsoluteY(); this.mWidth = ipso.Width; this.mHeight = ipso.Height; this.mRotation = ipso.GetAbsoluteRotation(); if (ipso is GraphicalUiElement) { var asGue = ipso as GraphicalUiElement; originDisplay.SetOriginXPosition(asGue); originDisplay.UpdateTo(asGue); } UpdateToProperties(); }
private static void GetElementOrInstanceForIpso(IRenderableIpso representation, List <ElementWithState> elementStack, out InstanceSave selectedInstance, out ElementSave selectedElement) { selectedInstance = null; selectedElement = null; IRenderableIpso ipsoToUse = representation; while (ipsoToUse != null && ipsoToUse.Parent != null && WireframeObjectManager.Self.AllIpsos.Contains(ipsoToUse) == false) { ipsoToUse = ipsoToUse.Parent; } if (ipsoToUse != null) { if (ipsoToUse.Tag is InstanceSave) { selectedInstance = ipsoToUse.Tag as InstanceSave; } else if (ipsoToUse.Tag is ElementSave) { selectedElement = ipsoToUse.Tag as ElementSave; } else { throw new Exception("This should never happen"); } } if (selectedInstance == null && selectedElement == null) { throw new Exception("Either the selected element or instance should not be null"); } }
public void Add(IRenderableIpso renderable) { lock (mRenderables) { mRenderables.Add(renderable); } }
public static void GetFileWidthAndHeightOrDefault(this IRenderableIpso ipso, out float fileWidth, out float fileHeight) { // to prevent divide-by-zero issues fileWidth = 32; fileHeight = 32; Microsoft.Xna.Framework.Graphics.Texture2D texture = null; if (ipso is Sprite) { texture = ((Sprite)ipso).Texture; } else if (ipso is GraphicalUiElement && ((GraphicalUiElement)ipso).RenderableComponent is Sprite) { var sprite = ((GraphicalUiElement)ipso).RenderableComponent as Sprite; texture = sprite.Texture; } if (texture != null) { fileWidth = texture.Width; fileHeight = texture.Height; } }
public static void RenderLinePrimitive(LinePrimitive linePrimitive, SpriteRenderer spriteRenderer, IRenderableIpso ipso, SystemManagers managers, bool isDotted) { linePrimitive.Position.X = ipso.GetAbsoluteX(); linePrimitive.Position.Y = ipso.GetAbsoluteY(); Renderer renderer; if (managers != null) { renderer = managers.Renderer; } else { renderer = Renderer.Self; } Texture2D textureToUse = renderer.SinglePixelTexture; if (isDotted) { textureToUse = renderer.DottedLineTexture; } linePrimitive.Render(spriteRenderer, managers, textureToUse, .2f * renderer.Camera.Zoom); }
private string StripGuideOrParentNameIfNecessaryName(string qualifiedName, IRenderableIpso representation) { foreach (NamedRectangle rectangle in ObjectFinder.Self.GumProjectSave.Guides) { if (qualifiedName.StartsWith(rectangle.Name + ".")) { return(qualifiedName.Substring(rectangle.Name.Length + 1)); } } if (representation.Parent != null && representation.Parent.Tag is InstanceSave && representation.Tag is InstanceSave) { // strip this off! if ((representation.Parent.Tag as InstanceSave).ParentContainer == (representation.Tag as InstanceSave).ParentContainer) { string whatToTakeOff = (representation.Parent.Tag as InstanceSave).Name + "."; int index = qualifiedName.IndexOf(whatToTakeOff); return(qualifiedName.Replace(whatToTakeOff, "")); //return qualifiedName.Substring((representation.Parent.Tag as InstanceSave).Name.Length + 1); } } return(qualifiedName); }
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.PixelsFromMiddleInverted) { return(amount * -1); } else if (generalUnitType != GeneralUnitType.PixelsFromLarge && generalUnitType != GeneralUnitType.PixelsFromMiddle && generalUnitType != GeneralUnitType.PixelsFromSmall) { float parentWidth; float parentHeight; float fileWidth; float fileHeight; float outX; float outY; IRenderableIpso ipso = WireframeObjectManager.Self.GetSelectedRepresentation(); ipso.GetFileWidthAndHeightOrDefault(out fileWidth, out fileHeight); ipso.GetParentWidthAndHeight( ProjectManager.Self.GumProjectSave.DefaultCanvasWidth, ProjectManager.Self.GumProjectSave.DefaultCanvasHeight, out parentWidth, out parentHeight); var unitsVariable = UnitConverter.ConvertToGeneralUnit(unitsVariableAsObject); UnitConverter.Self.ConvertToUnitTypeCoordinates(xAmount, yAmount, unitsVariable, unitsVariable, ipso.Width, ipso.Height, parentWidth, parentHeight, fileWidth, fileHeight, out outX, out outY); if (baseVariableName == "X" || baseVariableName == "Width") { return(outX); } else { return(outY); } } else { return(amount); } }
public static void UpdateLinePrimitive(LinePrimitive linePrimitive, IRenderableIpso ipso) { Matrix matrix = Matrix.CreateRotationZ(-MathHelper.ToRadians(ipso.GetAbsoluteRotation())); linePrimitive.Replace(0, Vector2.Zero); linePrimitive.Replace(1, Vector2.Transform(new Vector2(ipso.Width, 0), matrix)); linePrimitive.Replace(2, Vector2.Transform(new Vector2(ipso.Width, ipso.Height), matrix)); linePrimitive.Replace(3, Vector2.Transform(new Vector2(0, ipso.Height), matrix)); linePrimitive.Replace(4, Vector2.Zero); // close back on itself }
public static SKRect?GetEffectiveClipRect(this IRenderableIpso renderableIpso) { if (renderableIpso is InvisibleRenderable invisibleRenderable && invisibleRenderable.ClipsChildren) { var left = renderableIpso.GetAbsoluteX(); var top = renderableIpso.GetAbsoluteY(); var right = left + renderableIpso.Width; var bottom = top + renderableIpso.Height; return(new SKRect(left, top, right, bottom)); }
private void GetRequiredDimensionsFromContents(IRenderableIpso parentIpso, out float requiredWidth, out float requiredHeight) { requiredWidth = 0; requiredHeight = 0; foreach (var child in parentIpso.Children) { requiredWidth = System.Math.Max(requiredWidth, child.X + child.Width); requiredHeight = System.Math.Max(requiredHeight, child.Y + child.Height); } }
internal void RemoveRenderable(IRenderableIpso renderable) { foreach (Layer layer in this.Layers) { if (layer.Renderables.Contains(renderable)) { layer.Remove(renderable); } } }
public static IRenderableIpso GetTopParent(this IRenderableIpso ipso) { if (ipso.Parent == null) { return(ipso); } else { return(ipso.Parent.GetTopParent()); } }
public static float GetAbsoluteRotation(this IRenderableIpso ipso) { if (ipso.Parent == null) { return(ipso.Rotation); } else { return(ipso.Rotation + ipso.Parent.GetAbsoluteRotation()); } }
/// <summary> /// Returns the world Y coordinate of the argument RenderableIpso. /// </summary> /// <param name="ipso">The RenderableIpso to return the value for.</param> /// <returns>The world Y coordinate.</returns> public static float GetAbsoluteY(this IRenderableIpso ipso) { if (ipso.Parent == null) { return(ipso.Y); } else { return(ipso.Y + ipso.Parent.GetAbsoluteY()); } }
public static string GetQualifiedPrefixWithDot(IRenderableIpso ipso, ElementSave elementSaveForIpso, ElementSave containerElement) { string qualifiedVariablePrefixWithDot = ipso.Name + "."; IRenderableIpso parent = ipso.Parent; while (parent != null) { qualifiedVariablePrefixWithDot = parent.Name + "." + qualifiedVariablePrefixWithDot; parent = parent.Parent; } if ( // Not sure why we checked to make sure it doesn't contain a dot. It always will because // of the first line: //!qualifiedVariablePrefixWithDot.Contains(".") && elementSaveForIpso == containerElement) { qualifiedVariablePrefixWithDot = ""; } if (containerElement is ComponentSave || containerElement is StandardElementSave) { // If the containerElement is a ComponentSave, then we assume (currently) that the ipso is attached to it. Since we'll be using // the container element to get the variable, we don't want to include the name of the element, so let's get rid of the first part. // Update June 13, 2012 // If we pass a Text object // that is the child of a Button // and the Button is the container // element, we want to return "TextInstance." // as the prefix. The code below prevents that. // I now have unit tests for this so I'm going to // remove the code below and modify it later if it // turns out we really do need it. // Update June 13, 2012 // Now we climb up the parent/child // relationship until we get to the root // If the containerElement is a ComponentSave // or StandardElementSave (although maybe this // case will never happen) we need to remove the // first name before the dot because it's the element // itself. If it's a Screen there is no attachment so // the first name won't be the name of the Screen. int indexOfDot = qualifiedVariablePrefixWithDot.IndexOf('.'); if (indexOfDot != -1) { qualifiedVariablePrefixWithDot = qualifiedVariablePrefixWithDot.Substring(indexOfDot + 1, qualifiedVariablePrefixWithDot.Length - (indexOfDot + 1)); } } return(qualifiedVariablePrefixWithDot); }
/// <summary> /// Returns the InstanceSave that uses this representation or the /// instance that has a a contained instance that uses this representation. /// </summary> /// <param name="representation">The representation in question.</param> /// <returns>The InstanceSave or null if one isn't found.</returns> public InstanceSave GetInstance(IRenderableIpso representation, InstanceFetchType fetchType, List <ElementWithState> elementStack) { ElementSave selectedElement = SelectedState.Self.SelectedElement; string prefix = selectedElement.Name + "."; if (selectedElement is ScreenSave) { prefix = ""; } return(GetInstance(representation, selectedElement, prefix, fetchType, elementStack)); }
public static void GetParentWidthAndHeight(this IRenderableIpso ipso, float canvasWidth, float canvasHeight, out float parentWidth, out float parentHeight) { if (ipso.Parent == null) { parentWidth = canvasWidth; parentHeight = canvasHeight; } else { parentWidth = ipso.Parent.Width; parentHeight = ipso.Parent.Height; } }
private void SetLineRectangleAroundIpso(LineRectangle rectangle, IRenderableIpso pso) { float adjustedSelectionBorder = SelectionBorder / Renderer.Self.Camera.Zoom; rectangle.Visible = true; rectangle.X = pso.GetAbsoluteX() - adjustedSelectionBorder; rectangle.Y = pso.GetAbsoluteY() - adjustedSelectionBorder; rectangle.Width = pso.Width + adjustedSelectionBorder * 2; rectangle.Height = pso.Height + adjustedSelectionBorder * 2; rectangle.Rotation = pso.GetAbsoluteRotation(); }
public static string GetAttachmentQualifiedName(this IRenderableIpso ipso, List <ElementWithState> elementStack) { IRenderableIpso parent = ipso.Parent; IRenderableIpso child = ipso; while (parent != null) { if (parent.Tag is ElementSave || parent.Tag == null) { // we found it, so break! break; } else { InstanceSave thisInstance = child.Tag as InstanceSave; if (thisInstance.IsParentASibling(elementStack)) { child = parent; parent = parent.Parent; } else { // we found it, so break; break; } } } if (parent == null) { return(ipso.Name); } else { var parentName = parent.GetAttachmentQualifiedName(elementStack); if (!string.IsNullOrEmpty(parentName)) { return(parentName + "." + ipso.Name); } else { return(ipso.Name); } } }
public static Matrix GetAbsoluteRotationMatrix(this IRenderableIpso ipso) { var flipHorizontal = ipso.GetAbsoluteFlipHorizontal(); float rotationDegrees; if (flipHorizontal) { rotationDegrees = -ipso.GetAbsoluteRotation(); } else { rotationDegrees = ipso.GetAbsoluteRotation(); } return(Matrix.CreateRotationZ(-MathHelper.ToRadians(rotationDegrees))); }
internal IRenderableIpso CreateRenderableForType(string type) { IRenderableIpso toReturn = null; CallMethodOnPlugin( (plugin) => { var innerToReturn = plugin.CallCreateRenderableForType(type); if (innerToReturn != null) { toReturn = innerToReturn; } }, nameof(CreateRenderableForType)); return(toReturn); }
public static bool HasCursorOver(this IRenderableIpso ipso, float x, float y) { float absoluteX = ipso.GetAbsoluteX(); float absoluteY = ipso.GetAbsoluteY(); // put the cursor in object space: x -= absoluteX; y -= absoluteY; // normally it's negative, but we are going to * -1 to rotate the other way var matrix = Matrix.CreateRotationZ(-MathHelper.ToRadians(ipso.Rotation) * -1); var relativePosition = new Vector2(x, y); relativePosition = Vector2.Transform(relativePosition, matrix); bool isXInRange = false; if (ipso.Width < 0) { isXInRange = relativePosition.X <0 && relativePosition.X> ipso.Width; } else { isXInRange = relativePosition.X > 0 && relativePosition.X < ipso.Width; } bool isYInRange = false; if (ipso.Height < 0) { isYInRange = relativePosition.Y <0 && relativePosition.Y> ipso.Height; } else { isYInRange = relativePosition.Y > 0 && relativePosition.Y < ipso.Height; } return(isXInRange && isYInRange); }
/// <summary> /// Returns the top-left world X coordinate of the argument RenderableIpso. /// </summary> /// <param name="ipso">The RenderableIpso to return the value for.</param> /// <returns>The world X coordinate.</returns> public static float GetAbsoluteX(this IRenderableIpso ipso) { if (ipso.Parent == null) { return(ipso.X); } else { //var parentFlip = ipso.Parent.GetAbsoluteFlipHorizontal(); //if (parentFlip) //{ // return // -ipso.X - ipso.Width + // ipso.Parent.GetAbsoluteX() + ipso.Parent.Width; //} //else { return(ipso.X + ipso.Parent.GetAbsoluteX()); } } }
internal Microsoft.Xna.Framework.Rectangle GetScissorRectangleFor(Camera camera, IRenderableIpso ipso) { if (ipso == null) { return new Microsoft.Xna.Framework.Rectangle( 0, 0, camera.ClientWidth, camera.ClientHeight ); } else { float worldX = ipso.GetAbsoluteLeft(); float worldY = ipso.GetAbsoluteTop(); float screenX; float screenY; camera.WorldToScreen(worldX, worldY, out screenX, out screenY); int left = global::RenderingLibrary.Math.MathFunctions.RoundToInt(screenX); int top = global::RenderingLibrary.Math.MathFunctions.RoundToInt(screenY); worldX = ipso.GetAbsoluteRight(); worldY = ipso.GetAbsoluteBottom(); camera.WorldToScreen(worldX, worldY, out screenX, out screenY); int right = global::RenderingLibrary.Math.MathFunctions.RoundToInt(screenX); int bottom = global::RenderingLibrary.Math.MathFunctions.RoundToInt(screenY); left = System.Math.Max(0, left); top = System.Math.Max(0, top); right = System.Math.Max(0, right); bottom = System.Math.Max(0, bottom); left = System.Math.Min(left, camera.ClientWidth); right = System.Math.Min(right, camera.ClientWidth); top = System.Math.Min(top, camera.ClientHeight); bottom = System.Math.Min(bottom, camera.ClientHeight); int width = System.Math.Max(0, right - left); int height = System.Math.Max(0, bottom - top); Microsoft.Xna.Framework.Rectangle thisRectangle = new Microsoft.Xna.Framework.Rectangle( left, top, width, height); return thisRectangle; } }
private void AdjustRenderStates(RenderStateVariables renderState, Layer layer, IRenderableIpso renderable) { BlendState renderBlendState = renderable.BlendState; bool wrap = renderable.Wrap; bool shouldResetStates = false; if (renderBlendState == null) { renderBlendState = BlendState.NonPremultiplied; } if (renderState.BlendState != renderBlendState) { renderState.BlendState = renderable.BlendState; shouldResetStates = true; } if (renderState.Wrap != wrap) { renderState.Wrap = wrap; shouldResetStates = true; } if (renderable.ClipsChildren) { Rectangle clipRectangle = GetScissorRectangleFor(Camera, renderable); if (renderState.ClipRectangle == null || clipRectangle != renderState.ClipRectangle.Value) { //todo: Don't just overwrite it, constrain this rect to the existing one, if it's not null: var adjustedRectangle = clipRectangle; if (renderState.ClipRectangle != null) { adjustedRectangle = ConstrainRectangle(clipRectangle, renderState.ClipRectangle.Value); } renderState.ClipRectangle = adjustedRectangle; shouldResetStates = true; } } if (shouldResetStates) { spriteRenderer.BeginSpriteBatch(renderState, layer, BeginType.Begin, mCamera); } }
internal void RemoveRenderable(IRenderableIpso renderable) { foreach (Layer layer in this.Layers) { if (layer.Renderables.Contains(renderable)) { layer.Remove(renderable); } } }
private void AdjustRenderStates(RenderStateVariables renderState, Layer layer, IRenderableIpso renderable) { BlendState renderBlendState = renderable.BlendState; bool wrap = renderable.Wrap; bool shouldResetStates = false; if (renderBlendState == null) { renderBlendState = Renderer.NormalBlendState; } if (renderState.BlendState != renderBlendState) { // This used to set this, but not sure why...I think it should set the renderBlendState: //renderState.BlendState = renderable.BlendState; renderState.BlendState = renderBlendState; shouldResetStates = true; } if (renderState.Wrap != wrap) { renderState.Wrap = wrap; shouldResetStates = true; } if (renderable.ClipsChildren) { Rectangle clipRectangle = GetScissorRectangleFor(Camera, renderable); if (renderState.ClipRectangle == null || clipRectangle != renderState.ClipRectangle.Value) { //todo: Don't just overwrite it, constrain this rect to the existing one, if it's not null: var adjustedRectangle = clipRectangle; if (renderState.ClipRectangle != null) { adjustedRectangle = ConstrainRectangle(clipRectangle, renderState.ClipRectangle.Value); } renderState.ClipRectangle = adjustedRectangle; shouldResetStates = true; } } if (shouldResetStates) { spriteRenderer.BeginSpriteBatch(renderState, layer, BeginType.Begin, mCamera); } }
internal Microsoft.Xna.Framework.Rectangle GetScissorRectangleFor(Camera camera, IRenderableIpso ipso) { if (ipso == null) { return(new Microsoft.Xna.Framework.Rectangle( 0, 0, camera.ClientWidth, camera.ClientHeight )); } else { float worldX = ipso.GetAbsoluteLeft(); float worldY = ipso.GetAbsoluteTop(); float screenX; float screenY; camera.WorldToScreen(worldX, worldY, out screenX, out screenY); int left = global::RenderingLibrary.Math.MathFunctions.RoundToInt(screenX); int top = global::RenderingLibrary.Math.MathFunctions.RoundToInt(screenY); worldX = ipso.GetAbsoluteRight(); worldY = ipso.GetAbsoluteBottom(); camera.WorldToScreen(worldX, worldY, out screenX, out screenY); int right = global::RenderingLibrary.Math.MathFunctions.RoundToInt(screenX); int bottom = global::RenderingLibrary.Math.MathFunctions.RoundToInt(screenY); left = System.Math.Max(0, left); top = System.Math.Max(0, top); right = System.Math.Max(0, right); bottom = System.Math.Max(0, bottom); left = System.Math.Min(left, camera.ClientWidth); right = System.Math.Min(right, camera.ClientWidth); top = System.Math.Min(top, camera.ClientHeight); bottom = System.Math.Min(bottom, camera.ClientHeight); int width = System.Math.Max(0, right - left); int height = System.Math.Max(0, bottom - top); // ScissorRectangles are relative to the viewport in Gum, so we need to adjust for that: left += this.GraphicsDevice.Viewport.X; right += this.GraphicsDevice.Viewport.X; top += this.GraphicsDevice.Viewport.Y; bottom += this.GraphicsDevice.Viewport.Y; Microsoft.Xna.Framework.Rectangle thisRectangle = new Microsoft.Xna.Framework.Rectangle( left, top, width, height); return(thisRectangle); } }
public static void Render(SystemManagers managers, SpriteRenderer spriteRenderer, IRenderableIpso ipso, Texture2D texture, Color color, Rectangle?sourceRectangle = null, bool flipVertical = false, float rotationInDegrees = 0, bool treat0AsFullDimensions = false, // In the case of Text objects, we send in a line rectangle, but we want the Text object to be the owner of any resulting render states object objectCausingRenering = null ) { if (objectCausingRenering == null) { objectCausingRenering = ipso; } Renderer renderer = null; if (managers == null) { renderer = Renderer.Self; } else { renderer = managers.Renderer; } Texture2D textureToUse = texture; if (textureToUse == null) { textureToUse = LoaderManager.Self.InvalidTexture; if (textureToUse == null) { return; } } SpriteEffects effects = SpriteEffects.None; var flipHorizontal = ipso.GetAbsoluteFlipHorizontal(); var effectiveParentFlipHorizontal = ipso.Parent?.GetAbsoluteFlipHorizontal() ?? false; if (flipHorizontal) { effects |= SpriteEffects.FlipHorizontally; //rotationInDegrees *= -1; } var rotationInRadians = MathHelper.ToRadians(rotationInDegrees); float leftAbsolute = ipso.GetAbsoluteX(); float topAbsolute = ipso.GetAbsoluteY(); Vector2 origin = Vector2.Zero; //if(flipHorizontal) //{ // var offsetX = (float)System.Math.Cos(rotationInRadians); // var offsetY = (float)System.Math.Sin(rotationInRadians); // origin.X = 1; //} if (flipVertical) { effects |= SpriteEffects.FlipVertically; } var modifiedColor = color; if (Renderer.NormalBlendState == BlendState.AlphaBlend) { // we are using premult textures, so we need to premult the color: var alphaRatio = color.A / 255.0f; modifiedColor.R = (byte)(color.R * alphaRatio); modifiedColor.G = (byte)(color.G * alphaRatio); modifiedColor.B = (byte)(color.B * alphaRatio); } if ((ipso.Width > 0 && ipso.Height > 0) || treat0AsFullDimensions == false) { Vector2 scale = Vector2.One; if (textureToUse == null) { scale = new Vector2(ipso.Width, ipso.Height); } else { float ratioWidth = 1; float ratioHeight = 1; if (sourceRectangle.HasValue) { ratioWidth = sourceRectangle.Value.Width / (float)textureToUse.Width; ratioHeight = sourceRectangle.Value.Height / (float)textureToUse.Height; } scale = new Vector2(ipso.Width / (ratioWidth * textureToUse.Width), ipso.Height / (ratioHeight * textureToUse.Height)); } #if DEBUG if (textureToUse != null && textureToUse.IsDisposed) { throw new ObjectDisposedException($"Texture is disposed. Texture name: {textureToUse.Name}, sprite scale: {scale}, Sprite name: {ipso.Name}"); } #endif spriteRenderer.Draw(textureToUse, new Vector2(leftAbsolute, topAbsolute), sourceRectangle, modifiedColor, -rotationInRadians, origin, scale, effects, 0, objectCausingRenering); } else { int width = textureToUse.Width; int height = textureToUse.Height; if (sourceRectangle != null && sourceRectangle.HasValue) { width = sourceRectangle.Value.Width; height = sourceRectangle.Value.Height; } Rectangle destinationRectangle = new Rectangle( (int)(leftAbsolute), (int)(topAbsolute), width, height); spriteRenderer.Draw(textureToUse, destinationRectangle, sourceRectangle, modifiedColor, rotationInRadians, origin, effects, 0, objectCausingRenering ); } }
public static void Render(SystemManagers managers, SpriteRenderer spriteRenderer, IRenderableIpso ipso, Texture2D texture, Color color, Rectangle? sourceRectangle = null, bool flipHorizontal = false, bool flipVertical = false, float rotationInDegrees = 0, bool treat0AsFullDimensions = false, // In the case of Text objects, we send in a line rectangle, but we want the Text object to be the owner of any resulting render states object objectCausingRenering = null ) { if (objectCausingRenering == null) { objectCausingRenering = ipso; } Renderer renderer = null; if (managers == null) { renderer = Renderer.Self; } else { renderer = managers.Renderer; } Texture2D textureToUse = texture; if (textureToUse == null) { textureToUse = LoaderManager.Self.InvalidTexture; if (textureToUse == null) { return; } } SpriteEffects effects = SpriteEffects.None; if (flipHorizontal) { effects |= SpriteEffects.FlipHorizontally; } if (flipVertical) { effects |= SpriteEffects.FlipVertically; } var modifiedColor = color; if (Renderer.NormalBlendState == BlendState.AlphaBlend) { // we are using premult textures, so we need to premult the color: var alphaRatio = color.A / 255.0f; modifiedColor.R = (byte)(color.R * alphaRatio); modifiedColor.G = (byte)(color.G * alphaRatio); modifiedColor.B = (byte)(color.B * alphaRatio); } if ((ipso.Width > 0 && ipso.Height > 0) || treat0AsFullDimensions == false) { Vector2 scale = Vector2.One; if (textureToUse == null) { scale = new Vector2(ipso.Width, ipso.Height); } else { float ratioWidth = 1; float ratioHeight = 1; if (sourceRectangle.HasValue) { ratioWidth = sourceRectangle.Value.Width / (float)textureToUse.Width; ratioHeight = sourceRectangle.Value.Height / (float)textureToUse.Height; } scale = new Vector2(ipso.Width / (ratioWidth * textureToUse.Width), ipso.Height / (ratioHeight * textureToUse.Height)); } if (textureToUse != null && textureToUse.IsDisposed) { throw new ObjectDisposedException("Texture is disposed. Texture name: " + textureToUse.Name + ", sprite scale: " + scale); } spriteRenderer.Draw(textureToUse, new Vector2(ipso.GetAbsoluteX(), ipso.GetAbsoluteY()), sourceRectangle, modifiedColor, Microsoft.Xna.Framework.MathHelper.TwoPi * -rotationInDegrees / 360.0f, Vector2.Zero, scale, effects, 0, objectCausingRenering); } else { int width = textureToUse.Width; int height = textureToUse.Height; if (sourceRectangle != null && sourceRectangle.HasValue) { width = sourceRectangle.Value.Width; height = sourceRectangle.Value.Height; } Rectangle destinationRectangle = new Rectangle( (int)(ipso.GetAbsoluteX()), (int)(ipso.GetAbsoluteY()), width, height); spriteRenderer.Draw(textureToUse, destinationRectangle, sourceRectangle, modifiedColor, rotationInDegrees / 360.0f, Vector2.Zero, effects, 0, objectCausingRenering ); } }
public static void RenderLinePrimitive(LinePrimitive linePrimitive, SpriteRenderer spriteRenderer, IRenderableIpso ipso, SystemManagers managers, bool isDotted) { linePrimitive.Position.X = ipso.GetAbsoluteX(); linePrimitive.Position.Y = ipso.GetAbsoluteY(); Renderer renderer; if (managers != null) { renderer = managers.Renderer; } else { renderer = Renderer.Self; } Texture2D textureToUse = renderer.SinglePixelTexture; if (isDotted) { textureToUse = renderer.DottedLineTexture; } linePrimitive.Render(spriteRenderer, managers, textureToUse, .2f * renderer.Camera.Zoom); }
void IRenderableIpso.SetParentDirect(IRenderableIpso parent) { mContainedObjectAsIpso.SetParentDirect(parent); }
public void SetContainedObject(IRenderable containedObject) { if (containedObject == this) { throw new ArgumentException("The argument containedObject cannot be 'this'"); } mContainedObjectAsIpso = containedObject as IRenderableIpso; mContainedObjectAsIVisible = containedObject as IVisible; if (containedObject is global::RenderingLibrary.Math.Geometry.LineRectangle) { // All elements use line rectangles to draw themselves, but we don't // want them to show up in runtime (usually). We have a LocalVisible bool // which can be set to false to prevent the rectangles from drawing. // Update: We used to only set the LocalVisible if the object was a container, // but elements also inherit from container. We could check the base type, but then // elements that inherit from other elements would still show up. We'll ignore the element // name and just set LineRectangles to invisible if we're dealing with elements, no matter what. //if (this.ElementSave != null && ElementSave.Name == "Container") if (this.ElementSave != null) { (containedObject as global::RenderingLibrary.Math.Geometry.LineRectangle).LocalVisible = ShowLineRectangles; } } UpdateLayout(); }
public InstanceSave GetInstance(IRenderableIpso representation, ElementSave instanceContainer, string prefix, InstanceFetchType fetchType, List <ElementWithState> elementStack) { if (instanceContainer == null) { return(null); } InstanceSave toReturn = null; string qualifiedName = representation.GetAttachmentQualifiedName(elementStack); // strip off the guide name if it starts with a guide qualifiedName = StripGuideOrParentNameIfNecessaryName(qualifiedName, representation); foreach (InstanceSave instanceSave in instanceContainer.Instances) { if (prefix + instanceSave.Name == qualifiedName) { toReturn = instanceSave; break; } } if (toReturn == null) { foreach (InstanceSave instanceSave in instanceContainer.Instances) { ElementSave instanceElement = instanceSave.GetBaseElementSave(); bool alreadyInStack = elementStack.Any(item => item.Element == instanceElement); if (!alreadyInStack) { var elementWithState = new ElementWithState(instanceElement); elementStack.Add(elementWithState); toReturn = GetInstance(representation, instanceElement, prefix + instanceSave.Name + ".", fetchType, elementStack); if (toReturn != null) { if (fetchType == InstanceFetchType.DeepInstance) { // toReturn will be toReturn, no need to do anything } else // fetchType == InstanceInCurrentElement { toReturn = instanceSave; } break; } elementStack.Remove(elementWithState); } } } return(toReturn); }
public void SetParentDirect(IRenderableIpso newParent) { throw new NotImplementedException(); }
public static void Render(SystemManagers managers, SpriteRenderer spriteRenderer, IRenderableIpso ipso, Texture2D texture) { Color color = new Color(1.0f, 1.0f, 1.0f, 1.0f); // White Render(managers, spriteRenderer, ipso, texture, color); }
void IRenderableIpso.SetParentDirect(IRenderableIpso parent) { mParent = parent; }
public void Remove(IRenderableIpso renderable) { mRenderables.Remove(renderable); }
void IRenderableIpso.SetParentDirect(IRenderableIpso parent) { mParent = parent; }
public static void Render(SystemManagers managers, SpriteRenderer spriteRenderer, IRenderableIpso ipso, Texture2D texture) { Color color = new Color(1.0f, 1.0f, 1.0f, 1.0f); // White Render(managers, spriteRenderer, ipso, texture, color); }