public Text(SystemManagers managers, string text = "Hello") { Visible = true; RenderBoundary = RenderBoundaryDefault; mManagers = managers; mChildren = new List <IPositionedSizedObject>(); mRawText = text; mNeedsBitmapFontRefresh = true; mBounds = new LinePrimitive(this.Renderer.SinglePixelTexture); mBounds.Color = Color.LightGreen; mBounds.Add(0, 0); mBounds.Add(0, 0); mBounds.Add(0, 0); mBounds.Add(0, 0); mBounds.Add(0, 0); HorizontalAlignment = Graphics.HorizontalAlignment.Left; VerticalAlignment = Graphics.VerticalAlignment.Top; #if !TEST if (LoaderManager.Self.DefaultBitmapFont != null) { this.BitmapFont = LoaderManager.Self.DefaultBitmapFont; } #endif UpdateLinePrimitive(); }
public void Render(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, SystemManagers managers) { if (AbsoluteVisible) { // Moved this out of here - it's manually called by the TextManager // This is required because we can't update in the draw call now that // we're using RenderTargets //if (mNeedsBitmapFontRefresh) //{ // UpdateTextureToRender(); //} if (RenderBoundary) { LineRectangle.RenderLinePrimitive(mBounds, spriteBatch, this, managers, false); } if (mTextureToRender == null) { RenderUsingSpriteFont(spriteBatch); } else { RenderUsingBitmapFont(spriteBatch, managers); } } }
public void Render(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, SystemManagers managers) { if (Visible) { mLinePrimitive.Render(spriteBatch, managers); } }
public BitmapFont(string fontFile, SystemManagers managers) { #if ANDROID || IOS fontFile = fontFile.ToLowerInvariant(); #endif string fontContents = FileManager.FromFileText(fontFile); mFontFile = FileManager.Standardize(fontFile); string[] texturesToLoad = GetSourceTextures(fontContents); mTextures = new Texture2D[texturesToLoad.Length]; string directory = FileManager.GetDirectory(fontFile); for (int i = 0; i < mTextures.Length; i++) { if (FileManager.IsRelative(texturesToLoad[i])) { //mTextures[i] = LoaderManager.Self.Load(directory + texturesToLoad[i], managers); mTextures[i] = LoaderManager.Self.LoadContent<Texture2D>(directory + texturesToLoad[i]); } else { //mTextures[i] = LoaderManager.Self.Load(texturesToLoad[i], managers); mTextures[i] = LoaderManager.Self.LoadContent<Texture2D>(texturesToLoad[i]); } } SetFontPattern(fontContents); }
private void DragActivity(Cursor cursor, SystemManagers managers) { if (cursor.PrimaryDown && (cursor.XChange != 0 || cursor.YChange != 0) && mSideGrabbed != ResizeSide.None) { RecordOldValues(); float widthMultiplier = 0; float heightMultiplier = 0; float xMultiplier = 0; float yMultiplier = 0; GetMultipliersFromSideGrabbed(ref widthMultiplier, ref heightMultiplier, ref xMultiplier, ref yMultiplier); xMultiplier /= managers.Renderer.Camera.Zoom; yMultiplier /= managers.Renderer.Camera.Zoom; widthMultiplier /= managers.Renderer.Camera.Zoom; heightMultiplier /= managers.Renderer.Camera.Zoom; this.Left = mCoordinates.X + xMultiplier * cursor.XChange; this.Top = mCoordinates.Y + yMultiplier * cursor.YChange; this.Width = mCoordinates.Width + widthMultiplier * cursor.XChange; this.Height = mCoordinates.Height + heightMultiplier * cursor.YChange; RegionChanged?.Invoke(this, null); shouldRaiseEndRegionChanged = true; } }
public void Render(SpriteRenderer spriteRenderer, SystemManagers managers) { if (AbsoluteVisible) { // Moved this out of here - it's manually called by the TextManager // This is required because we can't update in the draw call now that // we're using RenderTargets //if (mNeedsBitmapFontRefresh) //{ // UpdateTextureToRender(); //} if (RenderBoundary) { LineRectangle.RenderLinePrimitive(mBounds, spriteRenderer, this, managers, false); } if (TextRenderingMode == TextRenderingMode.CharacterByCharacter) { RenderCharacterByCharacter(spriteRenderer); } else // RenderTarget { if (mTextureToRender == null) { RenderUsingSpriteFont(spriteRenderer); } else { RenderUsingBitmapFont(spriteRenderer, managers); } } } }
public LineRectangle(SystemManagers managers) { LocalVisible = true; mManagers = managers; mChildren = new List<IPositionedSizedObject>(); Visible = true; Renderer renderer = null; if (mManagers != null) { renderer = mManagers.Renderer; } else { renderer = Renderer.Self; } mLinePrimitive = new LinePrimitive(renderer.SinglePixelTexture); mLinePrimitive.Add(0, 0); mLinePrimitive.Add(0, 0); mLinePrimitive.Add(0, 0); mLinePrimitive.Add(0, 0); mLinePrimitive.Add(0, 0); UpdatePoints(); IsDotted = true; }
public void Initialize(GraphicsDevice graphicsDevice, SystemManagers managers) { SamplerState = SamplerState.LinearClamp; mCamera = new RenderingLibrary.Camera(managers); mLayersReadOnly = new ReadOnlyCollection <Layer>(mLayers); mLayers.Add(new Layer()); mLayers[0].Name = "Main Layer"; mGraphicsDevice = graphicsDevice; spriteRenderer.Initialize(graphicsDevice); mSinglePixelTexture = new Texture2D(mGraphicsDevice, 1, 1, false, SurfaceFormat.Color); Color[] pixels = new Color[1]; pixels[0] = Color.White; mSinglePixelTexture.Name = "Rendering Library Single Pixel Texture"; mSinglePixelTexture.SetData <Color>(pixels); mDottedLineTexture = new Texture2D(mGraphicsDevice, 2, 1, false, SurfaceFormat.Color); pixels = new Color[2]; pixels[0] = Color.White; pixels[1] = Color.Transparent; mDottedLineTexture.SetData <Color>(pixels); mCamera.UpdateClient(); }
public ImageData(int width, int height, byte[] data, SystemManagers managers) { this.width = width; this.height = height; this.mByteData = data; mManagers = managers; }
public BitmapFont(string fontFile, SystemManagers managers) { #if ANDROID || IOS fontFile = fontFile.ToLowerInvariant(); #endif string fontContents = FileManager.FromFileText(fontFile); mFontFile = FileManager.Standardize(fontFile); string[] texturesToLoad = GetSourceTextures(fontContents); mTextures = new Texture2D[texturesToLoad.Length]; string directory = FileManager.GetDirectory(fontFile); for (int i = 0; i < mTextures.Length; i++) { AtlasedTexture atlasedTexture = CheckForLoadedAtlasTexture(directory + texturesToLoad[i]); if (atlasedTexture != null) { mAtlasedTexture = atlasedTexture; mTextures[i] = mAtlasedTexture.Texture; } else { string fileName; // fnt files treat ./ as relative, but FRB Android treats ./ as // absolute. Since the value comes directly from .fnt, we want to // consider ./ as relative instead of whatever FRB thinks is relative: //if (FileManager.IsRelative(texturesToLoad[i])) bool isRelative = texturesToLoad[i].StartsWith("./") || FileManager.IsRelative(texturesToLoad[i]); if (isRelative) { if (FileManager.IsRelative(directory)) { fileName = FileManager.RelativeDirectory + directory + texturesToLoad[i]; } else { fileName = directory + texturesToLoad[i]; } //mTextures[i] = LoaderManager.Self.Load(directory + texturesToLoad[i], managers); } else { //mTextures[i] = LoaderManager.Self.Load(texturesToLoad[i], managers); fileName = texturesToLoad[i]; } // Don't rely on this - it may be aliased, the internal loader may redirect. Let it do its job: //if (ToolsUtilities.FileManager.FileExists(fileName)) mTextures[i] = LoaderManager.Self.LoadContent <Texture2D>(fileName); } } SetFontPattern(fontContents); }
/// <summary> /// Performs a no-caching load of the texture. This will always go to disk to access a file and /// will always return a unique Texture2D. This should not be used in most cases, as caching is preferred /// </summary> /// <param name="fileName">The filename to load</param> /// <param name="managers">The optional SystemManagers to use when loading the file to obtain a GraphicsDevice</param> /// <returns>The loaded Texture2D</returns> public Texture2D LoadTextureFromFile(string fileName, SystemManagers managers = null) { string fileNameStandardized = FileManager.Standardize(fileName, false, false); if (FileManager.IsRelative(fileNameStandardized)) { fileNameStandardized = FileManager.RelativeDirectory + fileNameStandardized; fileNameStandardized = FileManager.RemoveDotDotSlash(fileNameStandardized); } Texture2D toReturn; string extension = FileManager.GetExtension(fileName); Renderer renderer = null; if (managers == null) { renderer = Renderer.Self; } else { renderer = managers.Renderer; } if (extension == "tga") { #if RENDERING_LIB_SUPPORTS_TGA if (renderer.GraphicsDevice == null) { throw new Exception("The renderer is null - did you forget to call Initialize?"); } Paloma.TargaImage tgaImage = new Paloma.TargaImage(fileName); using (MemoryStream stream = new MemoryStream()) { tgaImage.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Png); stream.Seek(0, SeekOrigin.Begin); //must do this, or error is thrown in next line toReturn = Texture2D.FromStream(renderer.GraphicsDevice, stream); toReturn.Name = fileName; } #else throw new NotImplementedException(); #endif } else { using (var stream = FileManager.GetStreamForFile(fileNameStandardized)) { Texture2D texture = null; texture = Texture2D.FromStream(renderer.GraphicsDevice, stream); texture.Name = fileNameStandardized; toReturn = texture; } } return(toReturn); }
internal static bool TryHandleAsBaseType(string baseType, SystemManagers systemManagers, out IRenderable containedObject) { bool handledAsBaseType = true; containedObject = null; switch (baseType) { case "Container": LineRectangle lineRectangle = new LineRectangle(systemManagers); containedObject = lineRectangle; break; case "Rectangle": LineRectangle rectangle = new LineRectangle(); rectangle.IsDotted = false; containedObject = rectangle; break; case "Circle": LineCircle circle = new LineCircle(); circle.CircleOrigin = CircleOrigin.TopLeft; containedObject = circle; break; case "ColoredRectangle": SolidRectangle solidRectangle = new SolidRectangle(); containedObject = solidRectangle; break; case "Sprite": Texture2D texture = null; Sprite sprite = new Sprite(texture); containedObject = sprite; break; case "NineSlice": { NineSlice nineSlice = new NineSlice(); containedObject = nineSlice; } break; case "Text": { Text text = new Text(systemManagers, ""); containedObject = text; } break; default: handledAsBaseType = false; break; } return(handledAsBaseType); }
public BitmapFont(string fontFile, SystemManagers managers) { #if ANDROID || IOS fontFile = fontFile.ToLowerInvariant(); #endif string fontContents = FileManager.FromFileText(fontFile); mFontFile = FileManager.Standardize(fontFile); string[] texturesToLoad = GetSourceTextures(fontContents); mTextures = new Texture2D[texturesToLoad.Length]; string directory = FileManager.GetDirectory(fontFile); for (int i = 0; i < mTextures.Length; i++) { if (FileManager.IsRelative(texturesToLoad[i])) { //mTextures[i] = LoaderManager.Self.Load(directory + texturesToLoad[i], managers); mTextures[i] = LoaderManager.Self.LoadContent <Texture2D>(directory + texturesToLoad[i]); } else { //mTextures[i] = LoaderManager.Self.Load(texturesToLoad[i], managers); mTextures[i] = LoaderManager.Self.LoadContent <Texture2D>(texturesToLoad[i]); } } SetFontPattern(fontContents); }
internal Texture2D Load(string fileName, SystemManagers managers) { string fileNameStandardized = FileManager.Standardize(fileName, false, false); if (FileManager.IsRelative(fileNameStandardized)) { fileNameStandardized = FileManager.RelativeDirectory + fileNameStandardized; fileNameStandardized = FileManager.RemoveDotDotSlash(fileNameStandardized); } Texture2D toReturn = null; lock (mCachedDisposables) { if (CacheTextures) { if (mCachedDisposables.ContainsKey(fileNameStandardized)) { return((Texture2D)mCachedDisposables[fileNameStandardized]); } } toReturn = LoadTextureFromFile(fileName, managers); if (CacheTextures) { mCachedDisposables.Add(fileNameStandardized, toReturn); } } return(toReturn); }
public LineRectangle(SystemManagers managers) { LocalVisible = true; mManagers = managers; mChildren = new List <IPositionedSizedObject>(); Visible = true; Renderer renderer = null; if (mManagers != null) { renderer = mManagers.Renderer; } else { renderer = Renderer.Self; } mLinePrimitive = new LinePrimitive(renderer.SinglePixelTexture); mLinePrimitive.Add(0, 0); mLinePrimitive.Add(0, 0); mLinePrimitive.Add(0, 0); mLinePrimitive.Add(0, 0); mLinePrimitive.Add(0, 0); UpdatePoints(); IsDotted = true; }
void IRenderable.Render(SpriteRenderer spriteRenderer, SystemManagers managers) { if (AbsoluteVisible) { mLinePrimitive.Position.X = this.GetAbsoluteLeft(); mLinePrimitive.Position.Y = this.GetAbsoluteTop(); Renderer renderer; if (managers != null) { renderer = managers.Renderer; } else { renderer = Renderer.Self; } Texture2D textureToUse = renderer.SinglePixelTexture; if (IsDotted) { textureToUse = renderer.DottedLineTexture; } //mLinePrimitive.Render(spriteRenderer, managers, textureToUse, .2f * renderer.Camera.Zoom); mLinePrimitive.Render(spriteRenderer, managers, textureToUse, .1f * renderer.Camera.Zoom); } }
public LineRectangle(SystemManagers managers) { LocalVisible = true; mManagers = managers; mChildren = new ObservableCollection <IRenderableIpso>(); Visible = true; Renderer renderer = null; if (mManagers != null) { renderer = mManagers.Renderer; } else { renderer = Renderer.Self; } mLinePrimitive = new LinePrimitive(renderer.SinglePixelTexture); mLinePrimitive.Add(0, 0); mLinePrimitive.Add(0, 0); mLinePrimitive.Add(0, 0); mLinePrimitive.Add(0, 0); mLinePrimitive.Add(0, 0); UpdatePoints(); IsDotted = true; }
private void Render(IList <IRenderableIpso> whatToRender, SystemManagers managers, Layer layer) { var count = whatToRender.Count; for (int i = 0; i < count; i++) { var renderable = whatToRender[i]; var oldClip = mRenderStateVariables.ClipRectangle; AdjustRenderStates(mRenderStateVariables, layer, renderable); bool didClipChange = oldClip != mRenderStateVariables.ClipRectangle; renderable.Render(spriteRenderer, managers); if (RenderUsingHierarchy) { Render(renderable.Children, managers, layer); } if (didClipChange) { mRenderStateVariables.ClipRectangle = oldClip; spriteRenderer.BeginSpriteBatch(mRenderStateVariables, layer, BeginType.Begin, mCamera); } } }
public void Render(SpriteRenderer spriteRenderer, SystemManagers managers) { if (Visible) { mLinePrimitive.Render(spriteRenderer, managers); } }
void IRenderable.Render(SpriteRenderer spriteRenderer, SystemManagers managers) { if (this.AbsoluteVisible && this.Width > 0 && this.Height > 0) { Renderer renderer = null; if (managers == null) { renderer = Renderer.Self; } else { renderer = managers.Renderer; } var texture = renderer.SinglePixelTexture; Rectangle?sourceRect = renderer.SinglePixelSourceRectangle; if (mTexture != null) { texture = mTexture; sourceRect = SinglePixelTextureSourceRectangle; } Sprite.Render(managers, spriteRenderer, this, texture, Color, sourceRect, false, this.GetAbsoluteRotation()); } }
public ImageData(int width, int height, byte[] data, SystemManagers managers) { this.width = width; this.height = height; this.mByteData = data; mManagers = managers; }
void IRenderable.Render(SpriteBatch spriteBatch, SystemManagers managers) { if (Visible) { mLinePrimitive.Render(spriteBatch, managers); } }
public BitmapFont(string textureFile, string fontFile, SystemManagers managers) { mTextures = new Texture2D[1]; var atlasedTexture = CheckForLoadedAtlasTexture(FileManager.GetDirectory(fontFile) + textureFile); if (atlasedTexture != null) { mAtlasedTexture = atlasedTexture; mTextures[0] = mAtlasedTexture.Texture; } else { mTextures[0] = LoaderManager.Self.LoadContent <Texture2D>(textureFile); } mTextureNames[0] = mTextures[0].Name; //if (FlatRedBall.IO.FileManager.IsRelative(fontFile)) // fontFile = FlatRedBall.IO.FileManager.MakeAbsolute(fontFile); //FlatRedBall.IO.FileManager.ThrowExceptionIfFileDoesntExist(fontFile); SetFontPatternFromFile(fontFile); }
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 IRenderable.Render(SpriteBatch spriteBatch, SystemManagers managers) { if (AbsoluteVisible && LocalVisible) { // todo - add rotation RenderLinePrimitive(mLinePrimitive, spriteBatch, this, managers, IsDotted); } }
public void Render(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, SystemManagers managers) { if (managers == null) { managers = SystemManagers.Default; } managers.Renderer.RenderLayer(managers, this); }
public void Render(SpriteRenderer spriteRenderer, SystemManagers managers) { if (managers == null) { managers = SystemManagers.Default; } managers.Renderer.RenderLayer(managers, this); }
public void Render(SpriteRenderer spriteRenderer, SystemManagers managers) { if (managers == null) { managers = SystemManagers.Default; } managers.Renderer.RenderLayer(managers, this); }
public StatusTextController(SystemManagers systemManagers) { mManagers = systemManagers; mText = new Text(systemManagers, "Unset Text"); mText.RenderBoundary = false; systemManagers.TextManager.Add(mText); UpdateText(); }
void IRenderable.Render(SpriteRenderer spriteRenderer, SystemManagers managers) { if (AbsoluteVisible) { mLinePrimitive.Position.X = this.GetAbsoluteLeft(); mLinePrimitive.Position.Y = this.GetAbsoluteTop(); mLinePrimitive.Render(spriteRenderer, managers); } }
public void RemoveFromManagers(SystemManagers managers) { mLineRectangle.Z = 1; managers.ShapeManager.Remove(mLineRectangle); foreach (var circle in mHandles) { managers.ShapeManager.Remove(circle); } }
public CameraController(RenderingLibrary.Camera camera, SystemManagers managers, Cursor cursor, Keyboard keyboard, GraphicsDeviceControl control, Ruler topRuler, Ruler leftRuler) { this.TopRuler = topRuler; this.LeftRuler = leftRuler; Cursor = cursor; Camera = camera; Managers = managers; cameraPanningLogic = new CameraPanningLogic(control, managers, cursor, keyboard); }
private void ResizeCircleActivity(SystemManagers managers) { if (Visible && ShowHandles) { foreach (var handle in mHandles) { handle.Radius = HandleSize / managers.Renderer.Camera.Zoom; } } }
public static TextureFlipAnimation FromStringList(List <string> list, SystemManagers managers) { TextureFlipAnimation toReturn = new TextureFlipAnimation(); foreach (string fileName in list) { toReturn.TextureList.Add(LoaderManager.Self.Load(fileName, managers)); } return(toReturn); }
public BitmapFont(string textureFile, string fontFile, SystemManagers managers) { mTextures = new Texture2D[1]; mTextures[0] = LoaderManager.Self.Load(textureFile, managers); mTextureNames[0] = mTextures[0].Name; //if (FlatRedBall.IO.FileManager.IsRelative(fontFile)) // fontFile = FlatRedBall.IO.FileManager.MakeAbsolute(fontFile); //FlatRedBall.IO.FileManager.ThrowExceptionIfFileDoesntExist(fontFile); SetFontPatternFromFile(fontFile); }
public LineGrid(SystemManagers managers) { Visible = true; if (managers != null) { mLinePrimitive = new LinePrimitive(managers.Renderer.SinglePixelTexture); } else { mLinePrimitive = new LinePrimitive(Renderer.Self.SinglePixelTexture); } mLinePrimitive.BreakIntoSegments = true; UpdatePoints(); }
public Line(SystemManagers managers) { mManagers = managers; Visible = true; if (mManagers != null) { mLinePrimitive = new LinePrimitive(mManagers.Renderer.SinglePixelTexture); } else { mLinePrimitive = new LinePrimitive(Renderer.Self.SinglePixelTexture); } mChildren = new List<IPositionedSizedObject>(); UpdatePoints(); }
void IRenderable.Render(SpriteBatch spriteBatch, SystemManagers managers) { if (AbsoluteVisible && LocalVisible) { // todo - add rotation RenderLinePrimitive(mLinePrimitive, spriteBatch, this, managers, IsDotted); } }
public ImageData(int width, int height, SystemManagers managers) : this(width, height, new Color[width * height], managers) { }
void Render(Sprite sprite, SystemManagers managers, SpriteBatch spriteBatch) { Sprite.Render(managers, spriteBatch, sprite, sprite.Texture, sprite.Color, sprite.SourceRectangle, sprite.FlipHorizontal, sprite.FlipVertical, sprite.Rotation, treat0AsFullDimensions:false); }
public static void RenderLinePrimitive(LinePrimitive linePrimitive, SpriteBatch spriteBatch, IPositionedSizedObject 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(spriteBatch, managers, textureToUse, .2f * renderer.Camera.Zoom); }
void IRenderable.Render(SpriteBatch spriteBatch, SystemManagers managers) { if (this.AbsoluteVisible && Width > 0 && Height > 0) { RefreshSourceRectangles(); RefreshSpriteDimensions(); float y = this.GetAbsoluteY(); mTopLeftSprite.X = this.GetAbsoluteX() ; mTopLeftSprite.Y = y; mTopSprite.X = mTopLeftSprite.X + mTopLeftSprite.EffectiveWidth; mTopSprite.Y = y; mTopRightSprite.X = mTopSprite.X + mTopSprite.Width; mTopRightSprite.Y = y; y = mTopLeftSprite.Y + mTopLeftSprite.EffectiveHeight; mLeftSprite.X = this.GetAbsoluteX(); mLeftSprite.Y = y; mCenterSprite.X = mLeftSprite.X + mLeftSprite.EffectiveWidth; mCenterSprite.Y = y; mRightSprite.X = mCenterSprite.X + mCenterSprite.Width; mRightSprite.Y = y; y = mLeftSprite.Y + mLeftSprite.Height; mBottomLeftSprite.X = this.GetAbsoluteX(); mBottomLeftSprite.Y = y; mBottomSprite.X = mBottomLeftSprite.X + mBottomLeftSprite.EffectiveWidth; mBottomSprite.Y = y; mBottomRightSprite.X = mBottomSprite.X + mBottomSprite.Width; mBottomRightSprite.Y = y; Render(mTopLeftSprite, managers, spriteBatch); if (this.mCenterSprite.Width > 0) { Render(mTopSprite, managers, spriteBatch); Render(mBottomSprite, managers, spriteBatch); if (this.mCenterSprite.Height > 0) { Render(mCenterSprite, managers, spriteBatch); } } if (this.mCenterSprite.Height > 0) { Render(mLeftSprite, managers, spriteBatch); Render(mRightSprite, managers, spriteBatch); } Render(mTopRightSprite, managers, spriteBatch); Render(mBottomLeftSprite, managers, spriteBatch); Render(mBottomRightSprite, managers, spriteBatch); } }
public void SetTexturesUsingPattern(string anyOf9Textures, SystemManagers managers) { string absoluteTexture = anyOf9Textures; if(FileManager.IsRelative(absoluteTexture)) { absoluteTexture = FileManager.RelativeDirectory + absoluteTexture; absoluteTexture = FileManager.RemoveDotDotSlash(absoluteTexture); } string extension = FileManager.GetExtension(absoluteTexture); string bareTexture = GetBareTextureForNineSliceTexture(absoluteTexture); string error; if (!string.IsNullOrEmpty(bareTexture)) { TopLeftTexture = LoaderManager.Self.LoadOrInvalid( bareTexture + NineSlice.PossibleNineSliceEndings[NineSliceSections.TopLeft] + "." + extension, managers, out error); TopTexture = LoaderManager.Self.LoadOrInvalid( bareTexture + NineSlice.PossibleNineSliceEndings[NineSliceSections.Top] + "." + extension, managers, out error); TopRightTexture = LoaderManager.Self.LoadOrInvalid( bareTexture + NineSlice.PossibleNineSliceEndings[NineSliceSections.TopRight] + "." + extension, managers, out error); LeftTexture = LoaderManager.Self.LoadOrInvalid( bareTexture + NineSlice.PossibleNineSliceEndings[NineSliceSections.Left] + "." + extension, managers, out error); CenterTexture = LoaderManager.Self.LoadOrInvalid( bareTexture + NineSlice.PossibleNineSliceEndings[NineSliceSections.Center] + "." + extension, managers, out error); RightTexture = LoaderManager.Self.LoadOrInvalid( bareTexture + NineSlice.PossibleNineSliceEndings[NineSliceSections.Right] + "." + extension, managers, out error); BottomLeftTexture = LoaderManager.Self.LoadOrInvalid( bareTexture + NineSlice.PossibleNineSliceEndings[NineSliceSections.BottomLeft] + "." + extension, managers, out error); BottomTexture = LoaderManager.Self.LoadOrInvalid( bareTexture + NineSlice.PossibleNineSliceEndings[NineSliceSections.Bottom] + "." + extension, managers, out error); BottomRightTexture = LoaderManager.Self.LoadOrInvalid( bareTexture + NineSlice.PossibleNineSliceEndings[NineSliceSections.BottomRight] + "." + extension, managers, out error); } }
public void Render(SpriteRenderer spriteRenderer, SystemManagers managers) { if (AbsoluteVisible) { // Moved this out of here - it's manually called by the TextManager // This is required because we can't update in the draw call now that // we're using RenderTargets //if (mNeedsBitmapFontRefresh) //{ // UpdateTextureToRender(); //} if (RenderBoundary) { LineRectangle.RenderLinePrimitive(mBounds, spriteRenderer, this, managers, false); } if (mTextureToRender == null) { RenderUsingSpriteFont(spriteRenderer); } else { RenderUsingBitmapFont(spriteRenderer, managers); } } }
private void RenderUsingBitmapFont(SpriteRenderer spriteRenderer, SystemManagers managers) { if (mTempForRendering == null) { mTempForRendering = new LineRectangle(managers); } mTempForRendering.X = this.X; mTempForRendering.Y = this.Y; mTempForRendering.Width = this.mTextureToRender.Width * mFontScale; mTempForRendering.Height = this.mTextureToRender.Height * mFontScale; //mTempForRendering.Parent = this.Parent; float widthDifference = this.EffectiveWidth - mTempForRendering.Width; if (this.HorizontalAlignment == Graphics.HorizontalAlignment.Center) { mTempForRendering.X += widthDifference / 2.0f; } else if (this.HorizontalAlignment == Graphics.HorizontalAlignment.Right) { mTempForRendering.X += widthDifference; } if (this.VerticalAlignment == Graphics.VerticalAlignment.Center) { mTempForRendering.Y += (this.EffectiveHeight - mTextureToRender.Height) / 2.0f; } else if (this.VerticalAlignment == Graphics.VerticalAlignment.Bottom) { mTempForRendering.Y += this.EffectiveHeight - mTempForRendering.Height; } if(this.Parent != null) { mTempForRendering.X += Parent.GetAbsoluteX(); mTempForRendering.Y += Parent.GetAbsoluteY(); } if (mBitmapFont?.AtlasedTexture != null) { mBitmapFont.RenderAtlasedTextureToScreen(mWrappedText, this.HorizontalAlignment, mTextureToRender.Height, new Color(mRed, mGreen, mBlue, mAlpha), Rotation, mFontScale, managers,spriteRenderer, this); } else { Sprite.Render(managers, spriteRenderer, mTempForRendering, mTextureToRender, new Color(mRed, mGreen, mBlue, mAlpha), null, false, false, Rotation, treat0AsFullDimensions: false, objectCausingRenering: this); } }
/// <summary> /// Used for rendering directly to screen with an atlased texture. /// </summary> public void RenderAtlasedTextureToScreen(List<string> lines, HorizontalAlignment horizontalAlignment, float textureToRenderHeight, Color color, float rotation, float fontScale, SystemManagers managers, SpriteRenderer spriteRenderer, object objectRequestingChange) { var textObject = (Text)objectRequestingChange; var point = new Point(); int requiredWidth; int requiredHeight; List<int> widths; GetRequiredWithAndHeight(lines, out requiredWidth, out requiredHeight, out widths); int lineNumber = 0; if (mCharRect == null) mCharRect = new LineRectangle(managers); var yoffset = 0f; if (textObject.VerticalAlignment == Graphics.VerticalAlignment.Center) { yoffset = (textObject.EffectiveHeight - textureToRenderHeight) / 2.0f; } else if (textObject.VerticalAlignment == Graphics.VerticalAlignment.Bottom) { yoffset = textObject.EffectiveHeight - textureToRenderHeight * fontScale; } foreach (string line in lines) { // scoot over to leave room for the outline point.X = mOutlineThickness; if (horizontalAlignment == HorizontalAlignment.Right) { point.X = (int)(textObject.Width - widths[lineNumber] * fontScale); } else if (horizontalAlignment == HorizontalAlignment.Center) { point.X = (int)(textObject.Width - widths[lineNumber] * fontScale) / 2; } foreach (char c in line) { Rectangle destRect; int pageIndex; var sourceRect = GetCharacterRect(c, lineNumber, ref point, out destRect, out pageIndex, textObject.FontScale); var origin = new Point((int)textObject.X, (int)(textObject.Y + yoffset)); var rotate = (float)-(textObject.Rotation * System.Math.PI / 180f); var rotatingPoint = new Point(origin.X + destRect.X, origin.Y + destRect.Y); MathFunctions.RotatePointAroundPoint(new Point(origin.X, origin.Y), ref rotatingPoint, rotate); mCharRect.X = rotatingPoint.X; mCharRect.Y = rotatingPoint.Y; mCharRect.Width = destRect.Width; mCharRect.Height = destRect.Height; if(textObject.Parent != null) { mCharRect.X += textObject.Parent.GetAbsoluteX(); mCharRect.Y += textObject.Parent.GetAbsoluteY(); } Sprite.Render(managers, spriteRenderer, mCharRect, mTextures[0], color, sourceRect, false, false, rotation, treat0AsFullDimensions: false, objectCausingRenering: objectRequestingChange); } point.X = 0; lineNumber++; } }
public Text(SystemManagers managers, string text = "Hello") { Visible = true; RenderBoundary = RenderBoundaryDefault; mManagers = managers; mChildren = new List<IRenderableIpso>(); mRawText = text; mNeedsBitmapFontRefresh = true; mBounds = new LinePrimitive(this.Renderer.SinglePixelTexture); mBounds.Color = Color.LightGreen; mBounds.Add(0, 0); mBounds.Add(0, 0); mBounds.Add(0, 0); mBounds.Add(0, 0); mBounds.Add(0, 0); HorizontalAlignment = Graphics.HorizontalAlignment.Left; VerticalAlignment = Graphics.VerticalAlignment.Top; #if !TEST if (LoaderManager.Self.DefaultBitmapFont != null) { this.BitmapFont = LoaderManager.Self.DefaultBitmapFont; } #endif UpdateLinePrimitive(); }
private Texture2D RenderToTexture2DUsingImageData(IEnumerable lines, HorizontalAlignment horizontalAlignment, SystemManagers managers) { ImageData[] imageDatas = new ImageData[this.mTextures.Length]; for (int i = 0; i < imageDatas.Length; i++) { // Only use the existing buffer on one-page fonts var bufferToUse = mColorBuffer; if (i > 0) { bufferToUse = null; } imageDatas[i] = ImageData.FromTexture2D(this.mTextures[i], managers, bufferToUse); } Point point = new Point(); int maxWidthSoFar = 0; int requiredWidth = 0; int requiredHeight = 0; List<int> widths = new List<int>(); foreach (string line in lines) { requiredHeight += LineHeightInPixels; requiredWidth = 0; requiredWidth = MeasureString(line); widths.Add(requiredWidth); maxWidthSoFar = System.Math.Max(requiredWidth, maxWidthSoFar); } const int MaxWidthAndHeight = 2048; // change this later? maxWidthSoFar = System.Math.Min(maxWidthSoFar, MaxWidthAndHeight); requiredHeight = System.Math.Min(requiredHeight, MaxWidthAndHeight); ImageData imageData = null; if (maxWidthSoFar != 0) { imageData = new ImageData(maxWidthSoFar, requiredHeight, managers); int lineNumber = 0; foreach (string line in lines) { point.X = 0; if (horizontalAlignment == HorizontalAlignment.Right) { point.X = maxWidthSoFar - widths[lineNumber]; } else if (horizontalAlignment == HorizontalAlignment.Center) { point.X = (maxWidthSoFar - widths[lineNumber]) / 2; } foreach (char c in line) { BitmapCharacterInfo characterInfo = GetCharacterInfo(c); int sourceLeft = characterInfo.GetPixelLeft(Texture); int sourceTop = characterInfo.GetPixelTop(Texture); int sourceWidth = characterInfo.GetPixelRight(Texture) - sourceLeft; int sourceHeight = characterInfo.GetPixelBottom(Texture) - sourceTop; int distanceFromTop = characterInfo.GetPixelDistanceFromTop(LineHeightInPixels); // There could be some offset for this character int xOffset = characterInfo.GetPixelXOffset(LineHeightInPixels); point.X += xOffset; point.Y = lineNumber * LineHeightInPixels + distanceFromTop; Microsoft.Xna.Framework.Rectangle sourceRectangle = new Microsoft.Xna.Framework.Rectangle( sourceLeft, sourceTop, sourceWidth, sourceHeight); int pageIndex = characterInfo.PageNumber; imageData.Blit(imageDatas[pageIndex], sourceRectangle, point); point.X -= xOffset; point.X += characterInfo.GetXAdvanceInPixels(LineHeightInPixels); } point.X = 0; lineNumber++; } } if (imageData != null) { // We don't want // to generate mipmaps // because text is usually // rendered pixel-perfect. const bool generateMipmaps = false; return imageData.ToTexture2D(generateMipmaps); } else { return null; } }
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 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); }
private void RenderTiledSprite(SpriteRenderer spriteRenderer, SystemManagers managers) { float texelsWide = 0; float texelsTall = 0; int fullTexelsWide = 0; int fullTexelsTall = 0; if (this.AtlasedTexture != null) { fullTexelsWide = this.AtlasedTexture.SourceRectangle.Width; fullTexelsTall = this.AtlasedTexture.SourceRectangle.Height; } else { fullTexelsWide = this.Texture.Width; fullTexelsTall = this.Texture.Height; } texelsWide = fullTexelsWide; if (SourceRectangle.HasValue) { texelsWide = SourceRectangle.Value.Width; } texelsTall = fullTexelsTall; if (SourceRectangle.HasValue) { texelsTall = SourceRectangle.Value.Height; } float xRepetitions = texelsWide / (float)fullTexelsWide; float yRepetitions = texelsTall / (float)fullTexelsTall; if (xRepetitions > 0 && yRepetitions > 0) { float eachWidth = this.EffectiveWidth / xRepetitions; float eachHeight = this.EffectiveHeight / yRepetitions; float oldEffectiveWidth = this.EffectiveWidth; float oldEffectiveHeight = this.EffectiveHeight; // We're going to change the width, height, X, and Y of "this" to make rendering code work // by simply passing in the object. At the end of the drawing, we'll revert the values back // to what they were before rendering started. float oldWidth = this.Width; float oldHeight = this.Height; float oldX = this.X; float oldY = this.Y; var oldSource = this.SourceRectangle.Value; float texelsPerWorldUnitX = (float)fullTexelsWide / eachWidth; float texelsPerWorldUnitY = (float)fullTexelsTall / eachHeight; int oldSourceY = oldSource.Y; if (oldSourceY < 0) { int amountToAdd = 1 - (oldSourceY / fullTexelsTall); oldSourceY += amountToAdd * Texture.Height; } if (oldSourceY > 0) { int amountToAdd = System.Math.Abs(oldSourceY) / fullTexelsTall; oldSourceY -= amountToAdd * Texture.Height; } float currentY = -oldSourceY * (1 / texelsPerWorldUnitY); var matrix = this.GetRotationMatrix(); for (int y = 0; y < yRepetitions; y++) { float worldUnitsChoppedOffTop = System.Math.Max(0, oldSourceY * (1 / texelsPerWorldUnitY)); //float worldUnitsChoppedOffBottom = System.Math.Max(0, currentY + eachHeight - (int)oldEffectiveHeight); float worldUnitsChoppedOffBottom = 0; float extraY = yRepetitions - y; if (extraY < 1) { worldUnitsChoppedOffBottom = System.Math.Max(0, (1 - extraY) * eachWidth); } int texelsChoppedOffTop = 0; if (worldUnitsChoppedOffTop > 0) { texelsChoppedOffTop = oldSourceY; } int texelsChoppedOffBottom = RenderingLibrary.Math.MathFunctions.RoundToInt(worldUnitsChoppedOffBottom * texelsPerWorldUnitY); int sourceHeight = (int)(fullTexelsTall - texelsChoppedOffTop - texelsChoppedOffBottom); if (sourceHeight == 0) { break; } this.Height = sourceHeight * 1 / texelsPerWorldUnitY; int oldSourceX = oldSource.X; if (oldSourceX < 0) { int amountToAdd = 1 - (oldSourceX / Texture.Width); oldSourceX += amountToAdd * fullTexelsWide; } if (oldSourceX > 0) { int amountToAdd = System.Math.Abs(oldSourceX) / Texture.Width; oldSourceX -= amountToAdd * fullTexelsWide; } float currentX = -oldSourceX * (1 / texelsPerWorldUnitX) + y * eachHeight * matrix.Up.X; currentY = y * eachHeight * matrix.Up.Y; for (int x = 0; x < xRepetitions; x++) { float worldUnitsChoppedOffLeft = System.Math.Max(0, oldSourceX * (1 / texelsPerWorldUnitX)); float worldUnitsChoppedOffRight = 0; float extra = xRepetitions - x; if (extra < 1) { worldUnitsChoppedOffRight = System.Math.Max(0, (1 - extra) * eachWidth); } int texelsChoppedOffLeft = 0; if (worldUnitsChoppedOffLeft > 0) { // Let's use the hard number to not have any floating point issues: //texelsChoppedOffLeft = worldUnitsChoppedOffLeft * texelsPerWorldUnit; texelsChoppedOffLeft = oldSourceX; } int texelsChoppedOffRight = RenderingLibrary.Math.MathFunctions.RoundToInt(worldUnitsChoppedOffRight * texelsPerWorldUnitX); this.X = oldX + currentX + worldUnitsChoppedOffLeft; this.Y = oldY + currentY + worldUnitsChoppedOffTop; int sourceWidth = (int)(fullTexelsWide - texelsChoppedOffLeft - texelsChoppedOffRight); if (sourceWidth == 0) { break; } this.Width = sourceWidth * 1 / texelsPerWorldUnitX; if (AtlasedTexture != null) { var rectangle = new Rectangle( AtlasedTexture.SourceRectangle.X + RenderingLibrary.Math.MathFunctions.RoundToInt(texelsChoppedOffLeft), AtlasedTexture.SourceRectangle.Y + RenderingLibrary.Math.MathFunctions.RoundToInt(texelsChoppedOffTop), sourceWidth, sourceHeight); Render(managers, spriteRenderer, this, AtlasedTexture.Texture, Color, rectangle, FlipHorizontal, FlipVertical, rotationInDegrees: Rotation); } else { this.SourceRectangle = new Rectangle( RenderingLibrary.Math.MathFunctions.RoundToInt(texelsChoppedOffLeft), RenderingLibrary.Math.MathFunctions.RoundToInt(texelsChoppedOffTop), sourceWidth, sourceHeight); Render(managers, spriteRenderer, this, Texture, Color, SourceRectangle, FlipHorizontal, FlipVertical, rotationInDegrees: Rotation); } currentX = System.Math.Max(0, currentX); currentX += this.Width * matrix.Right.X; currentY += this.Width * matrix.Right.Y; } } this.Width = oldWidth; this.Height = oldHeight; this.X = oldX; this.Y = oldY; this.SourceRectangle = oldSource; } }
void IRenderable.Render(SpriteRenderer spriteRenderer, SystemManagers managers) { if (this.AbsoluteVisible && Width > 0 && Height > 0) { bool shouldTileByMultipleCalls = this.Wrap && (this as IRenderable).Wrap == false; if (shouldTileByMultipleCalls && (this.Texture != null || this.AtlasedTexture != null)) { RenderTiledSprite(spriteRenderer, managers); } else { Rectangle? sourceRectangle = EffectiveRectangle; Texture2D texture = Texture; if (AtlasedTexture != null) { texture = AtlasedTexture.Texture; } Render(managers, spriteRenderer, this, texture, Color, sourceRectangle, FlipHorizontal, FlipVertical, Rotation); } } }
public static ImageData FromTexture2D(Texture2D texture2D, SystemManagers managers) { return FromTexture2D(texture2D, managers, null); }
private Texture2D RenderToTexture2DUsingRenderStates(IEnumerable<string> lines, HorizontalAlignment horizontalAlignment, SystemManagers managers, Texture2D toReplace, object objectRequestingChange) { if (managers == null) { managers = SystemManagers.Default; } ////////////////// Early out ///////////////////////// if (managers.Renderer.GraphicsDevice.GraphicsDeviceStatus != GraphicsDeviceStatus.Normal) { return null; } ///////////////// End early out ////////////////////// RenderTarget2D renderTarget = null; int requiredWidth; int requiredHeight; List<int> widths; GetRequiredWithAndHeight(lines, out requiredWidth, out requiredHeight, out widths); if (requiredWidth != 0) { #if DEBUG foreach (var texture in this.Textures) { if (texture.IsDisposed) { string message = $"The font:\n{this.FontFile}\nis disposed"; throw new InvalidOperationException(message); } } #endif var oldViewport = managers.Renderer.GraphicsDevice.Viewport; if (toReplace != null && requiredWidth == toReplace.Width && requiredHeight == toReplace.Height) { renderTarget = toReplace as RenderTarget2D; } else { renderTarget = new RenderTarget2D(managers.Renderer.GraphicsDevice, requiredWidth, requiredHeight); } // render target has to be set before setting the viewport managers.Renderer.GraphicsDevice.SetRenderTarget(renderTarget); var viewportToSet = new Viewport(0, 0, requiredWidth, requiredHeight); try { managers.Renderer.GraphicsDevice.Viewport = viewportToSet; } catch(Exception exception) { throw new Exception("Error setting graphics device when rendering bitmap font. used values:\n" + $"requiredWidth:{requiredWidth}\nrequiredHeight:{requiredHeight}", exception); } var spriteRenderer = managers.Renderer.SpriteRenderer; managers.Renderer.GraphicsDevice.Clear(Color.Transparent); spriteRenderer.Begin(); DrawLines(lines, horizontalAlignment, objectRequestingChange, requiredWidth, widths, spriteRenderer); spriteRenderer.End(); managers.Renderer.GraphicsDevice.SetRenderTarget(null); managers.Renderer.GraphicsDevice.Viewport = oldViewport; } return renderTarget; }
public BitmapFont(string textureFile, string fontFile, SystemManagers managers) { mTextures = new Texture2D[1]; var atlasedTexture = CheckForLoadedAtlasTexture(FileManager.GetDirectory(fontFile) + textureFile); if (atlasedTexture != null) { mAtlasedTexture = atlasedTexture; mTextures[0] = mAtlasedTexture.Texture; } else { mTextures[0] = LoaderManager.Self.LoadContent<Texture2D>(textureFile); } mTextureNames[0] = mTextures[0].Name; //if (FlatRedBall.IO.FileManager.IsRelative(fontFile)) // fontFile = FlatRedBall.IO.FileManager.MakeAbsolute(fontFile); //FlatRedBall.IO.FileManager.ThrowExceptionIfFileDoesntExist(fontFile); SetFontPatternFromFile(fontFile); }
internal static Texture2D ToTexture2D(Color[] pixelData, int textureWidth, int textureHeight, SystemManagers managers) { return ToTexture2D(pixelData, textureWidth, textureHeight, true, managers); }
internal static Texture2D ToTexture2D(Color[] pixelData, int textureWidth, int textureHeight, bool generateMipmaps, SystemManagers managers) { Texture2D texture = null; Renderer renderer; if (managers == null) { renderer = Renderer.Self; } else { renderer = managers.Renderer; } lock (renderer.GraphicsDevice) { const int startIndex = 0; texture = new Texture2D(renderer.GraphicsDevice, textureWidth, textureHeight, generateMipmaps, SurfaceFormat.Color); texture.SetData<Color>(pixelData, startIndex, textureWidth * textureHeight - startIndex); } return texture; }
public Texture2D RenderToTexture2D(string whatToRender, HorizontalAlignment horizontalAlignment, SystemManagers managers, object objectRequestingRender) { string[] lines = whatToRender.Split('\n'); return RenderToTexture2D(lines, horizontalAlignment, managers, null, objectRequestingRender); }
public static ImageData FromTexture2D(Texture2D texture2D, SystemManagers managers, Color[] colorBuffer) { ImageData imageData = null; switch (texture2D.Format) { case SurfaceFormat.Color: { if (colorBuffer == null) { colorBuffer = new Color[texture2D.Width * texture2D.Height]; } lock (colorBuffer) { texture2D.GetData<Color>(colorBuffer, 0, texture2D.Width * texture2D.Height); imageData = new ImageData( texture2D.Width, texture2D.Height, colorBuffer, managers); } } break; case SurfaceFormat.Dxt3: Byte[] byteData = new byte[texture2D.Width * texture2D.Height]; texture2D.GetData<byte>(byteData); imageData = new ImageData(texture2D.Width, texture2D.Height, byteData, managers); break; default: throw new NotImplementedException("The format " + texture2D.Format + " isn't supported."); //break; } return imageData; }
/// <summary> /// /// </summary> /// <param name="lines"></param> /// <param name="horizontalAlignment"></param> /// <param name="managers"></param> /// <param name="toReplace"></param> /// <param name="objectRequestingRender"></param> /// <param name="charLocations">Used to store char locations for drawing directly to screen.</param> /// <returns></returns> public Texture2D RenderToTexture2D(IEnumerable<string> lines, HorizontalAlignment horizontalAlignment, SystemManagers managers, Texture2D toReplace, object objectRequestingRender) { bool useImageData = false; if (useImageData) { return RenderToTexture2DUsingImageData(lines, horizontalAlignment, managers); } else { return RenderToTexture2DUsingRenderStates(lines, horizontalAlignment, managers, toReplace, objectRequestingRender); } }