public unsafe void DrawQuad(Rectangle screenRect, Rectangle textCoords, Color color) { fixed(Vertex *verts = m_verticies) { verts[vertIndexCounter].Position.X = screenRect.Left; verts[vertIndexCounter].Position.Y = screenRect.Top; verts[vertIndexCounter].TexCoords.X = textCoords.Left; verts[vertIndexCounter].TexCoords.Y = textCoords.Top; verts[vertIndexCounter].Color = color; vertIndexCounter++; verts[vertIndexCounter].Position.X = screenRect.Width; // SadConsole w/SFML changed Width to be left + width... verts[vertIndexCounter].Position.Y = screenRect.Top; verts[vertIndexCounter].TexCoords.X = textCoords.Width; verts[vertIndexCounter].TexCoords.Y = textCoords.Top; verts[vertIndexCounter].Color = color; vertIndexCounter++; verts[vertIndexCounter].Position.X = screenRect.Width; verts[vertIndexCounter].Position.Y = screenRect.Height; verts[vertIndexCounter].TexCoords.X = textCoords.Width; verts[vertIndexCounter].TexCoords.Y = textCoords.Height; verts[vertIndexCounter].Color = color; vertIndexCounter++; verts[vertIndexCounter].Position.X = screenRect.Left; verts[vertIndexCounter].Position.Y = screenRect.Height; verts[vertIndexCounter].TexCoords.X = textCoords.Left; verts[vertIndexCounter].TexCoords.Y = textCoords.Height; verts[vertIndexCounter].Color = color; vertIndexCounter++; } }
/// <summary> /// Resets all layer areas. /// </summary> protected override void ResetArea() { if (!initDone) { return; } RenderRects = new Rectangle[area.Width * area.Height]; for (int l = 0; l < LayerCount; l++) { ResetAreaLayer(layers[l]); } int index = 0; for (int y = 0; y < area.Height; y++) { for (int x = 0; x < area.Width; x++) { RenderRects[index] = Font.GetRenderRect(x, y); index++; } } // TODO: Optimization by calculating AbsArea and seeing if it's diff from current, if so, don't create new RenderRects AbsoluteArea = new Rectangle(0, 0, area.Width * Font.Size.X, area.Height * Font.Size.Y); }
public static Rectangle FromFramework(FrameworkRect rect) { return(new Rectangle() { X = rect.Left, Y = rect.Top, Width = rect.Width, Height = rect.Height }); }
void updateMovement() { if (m_leftSteps > 0) { SFML.Graphics.IntRect Intersect = new SFML.Graphics.IntRect(m_boundingBox.Left, m_boundingBox.Top, m_boundingBox.Width, m_boundingBox.Height); Intersect.Left += (int)m_direction.X; Intersect.Top += (int)m_direction.Y; Vector2u FieldIndex = getField(new Vec2f(Intersect.Left, Intersect.Top)); bool intersection = false; bool computed = false; for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { if ((FieldIndex.X + i) >= 0 && (FieldIndex.Y + j) >= 0 && FieldIndex.X + i < m_map.getFieldNum().X&& FieldIndex.Y + j < m_map.getFieldNum().Y) { intersection = Intersect.Intersects(m_map.m_map[FieldIndex.X + i, FieldIndex.Y + j].m_boundingBox); } else if (!computed) { intersection = !(Intersect.Left >= 0) || !(Intersect.Top >= 0) || !(Intersect.Left + Intersect.Width < m_map.getFieldNum().X *Camera.m_FieldSize) || !(Intersect.Top + Intersect.Height < m_map.getFieldNum().Y *Camera.m_FieldSize); computed = true; } if (intersection) { break; } } if (intersection) { break; } } if (!intersection) { m_position += m_direction; setBox(); } else { MineField(); } m_leftSteps = 0; } m_leftSteps -= m_speed; if (m_leftSteps < 0 && m_leftSteps > -10) { m_direction = new Vec2f(0, -1); updateSprite(); } }
/// <summary> /// Gets an XML node attribute as a SFML IntRect. /// </summary> /// <returns>The attribute value or the default value.</returns> /// <param name="node">Node.</param> /// <param name="attributeName">Attribute name.</param> /// <param name="def">Default value that will be returned on errors.</param> static public SFML.Graphics.IntRect GetIntRect(XmlNode node, string attributeName, SFML.Graphics.IntRect def) { try { var buff = XmlUtilities.GetIntArray(node, attributeName); var res = new SFML.Graphics.IntRect(buff[0], buff[1], buff[2], buff[3]); return(res); } catch { return(def); } }
public OrientedBoundingBox(SFML.Graphics.Sprite Object) // Calculate the four points of the OBB from a transformed (scaled, rotated...) sprite { Points = new SFML.Window.Vector2f[4]; SFML.Graphics.Transform trans = Object.Transform; SFML.Graphics.IntRect local = Object.TextureRect; Points[0] = trans.TransformPoint(0.0f, 0.0f); Points[1] = trans.TransformPoint(local.Width, 0.0f); Points[2] = trans.TransformPoint(local.Width, local.Height); Points[3] = trans.TransformPoint(0.0f, local.Height); }
/// <summary> /// Forces the area of this text surface to always be the full width and height. /// </summary> protected override void ResetArea() { // Sub views are not allowed on animated text surfaces. Enforce full view. area = new Rectangle(0, 0, width, height); base.ResetArea(); if (Frames.Count > 0) { UpdateFrameReferences(); } }
/// <summary> /// Default constructor of the control. /// </summary> public ControlBase(int width, int height) : base(new TextSurface(width, height, Engine.DefaultFont)) { IsDirty = true; TabStop = true; IsVisible = true; FocusOnClick = true; CanFocus = false; position = new Point(); CanUseMouse = true; CanUseKeyboard = true; bounds = new Rectangle(0, 0, width, height); }
public bool HandlerMouse(IConsole console, MouseInfo info) { if (console.IsVisible && console.CanUseMouse) { info.Fill(console); bool doDrag = (info.LeftButtonDown && CanMoveWithLeftButton) || (info.RightButtonDown && CanMoveWithRightButton); if (info.Console == console && doDrag) { // Mouse just went down on us. if (!_mouseDown) { _mouseDown = true; _mouseLastLocation = new Point(info.ConsoleLocation.X, info.ConsoleLocation.Y); console.ExclusiveFocus = true; } else { // Mouse has been down, still is Point currentLocation = new Point(info.ConsoleLocation.X, info.ConsoleLocation.Y); if (currentLocation != _mouseLastLocation) { Rectangle viewport = console.TextSurface.RenderArea; #if SFML viewport.Left += _mouseLastLocation.X - currentLocation.X; viewport.Top += _mouseLastLocation.Y - currentLocation.Y; #elif MONOGAME viewport.X += _mouseLastLocation.X - currentLocation.X; viewport.Y += _mouseLastLocation.Y - currentLocation.Y; #endif _mouseLastLocation = currentLocation; console.TextSurface.RenderArea = viewport; } } return(true); } if (!doDrag && _mouseDown) { console.ExclusiveFocus = false; _mouseDown = false; } } return(false); }
public unsafe void DrawQuad(Rectangle screenRect, Rectangle textCoords, Color color, Texture texture) { if (lastDrawCall.Texture != texture && lastDrawCall.Texture != null) { //drawCalls.Add(lastDrawCall); End(); lastDrawCall.VertIndex = 0; } lastDrawCall.Texture = texture; if (lastDrawCall.VertIndex >= maxIndex) { global::System.Array.Resize(ref lastDrawCall.Verticies, lastDrawCall.Verticies.Length + lastDrawCall.Verticies.Length / 2); maxIndex = lastDrawCall.Verticies.Length - 200; } fixed(Vertex *verts = lastDrawCall.Verticies) { verts[lastDrawCall.VertIndex].Position.X = screenRect.Left; verts[lastDrawCall.VertIndex].Position.Y = screenRect.Top; verts[lastDrawCall.VertIndex].TexCoords.X = textCoords.Left; verts[lastDrawCall.VertIndex].TexCoords.Y = textCoords.Top; verts[lastDrawCall.VertIndex].Color = color; lastDrawCall.VertIndex++; verts[lastDrawCall.VertIndex].Position.X = screenRect.Width; // SadConsole w/SFML changed Width to be left + width... verts[lastDrawCall.VertIndex].Position.Y = screenRect.Top; verts[lastDrawCall.VertIndex].TexCoords.X = textCoords.Width; verts[lastDrawCall.VertIndex].TexCoords.Y = textCoords.Top; verts[lastDrawCall.VertIndex].Color = color; lastDrawCall.VertIndex++; verts[lastDrawCall.VertIndex].Position.X = screenRect.Width; verts[lastDrawCall.VertIndex].Position.Y = screenRect.Height; verts[lastDrawCall.VertIndex].TexCoords.X = textCoords.Width; verts[lastDrawCall.VertIndex].TexCoords.Y = textCoords.Height; verts[lastDrawCall.VertIndex].Color = color; lastDrawCall.VertIndex++; verts[lastDrawCall.VertIndex].Position.X = screenRect.Left; verts[lastDrawCall.VertIndex].Position.Y = screenRect.Height; verts[lastDrawCall.VertIndex].TexCoords.X = textCoords.Left; verts[lastDrawCall.VertIndex].TexCoords.Y = textCoords.Height; verts[lastDrawCall.VertIndex].Color = color; lastDrawCall.VertIndex++; } //lastDrawCall.Verticies.AddRange(singleDrawVerticies); }
/// <summary> /// Resets all of the rects of the animation based on <see cref="UsePixelPositioning"/> and if <see cref="RepositionRects"/> is true. /// </summary> /// <param name="position">The position of the game object.</param> /// <param name="force">When true, always repositions rects.</param> protected void UpdateRects(Point position, bool force = false) { if (repositionRects || force) { var width = Animation.Width; var height = Animation.Height; var font = Animation.Font; Point offset; var rects = new Rectangle[width * height]; if (repositionRects && usePixelPositioning) { offset = position + renderOffset - new Point(animation.Center.X * font.Size.X, animation.Center.Y * font.Size.Y); } else if (repositionRects) { offset = position + renderOffset - animation.Center; offset = new Point(offset.X * font.Size.X, offset.Y * font.Size.Y); } else { offset = new Point(); } #if SFML animation.AbsoluteArea = new Rectangle(offset.X, offset.Y, (width * font.Size.X) + offset.X, (height * font.Size.Y) + offset.Y); #elif MONOGAME animation.AbsoluteArea = new Rectangle(offset.X, offset.Y, width * font.Size.X, height * font.Size.Y); #endif int index = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { #if SFML rects[index] = new Rectangle(x * font.Size.X + offset.X, y * font.Size.Y + offset.Y, font.Size.X + (x * font.Size.X + offset.X), font.Size.Y + (y * font.Size.Y + offset.Y)); #elif MONOGAME rects[index] = new Rectangle(x * font.Size.X + offset.X, y * font.Size.Y + offset.Y, font.Size.X, font.Size.Y); #endif index++; } } animation.RenderRects = rects; } }
internal override SFML.Graphics.Glyph GetGlyph(char c, int size, bool bold) { var rect = new SFML.Graphics.IntRect(); var bounds = new SFML.Graphics.FloatRect(); var advance = 0; if (DataType == BitmapFontDataType.None) { var width = Texture.Width; var height = Texture.Height; var offsetChar = (int)c - CharCodeOffset; rect.Left = Util.TwoDeeX(offsetChar * CharacterWidth, width) + CharacterOffsetX; rect.Top = Util.TwoDeeY(offsetChar * CharacterHeight, width) * CharacterHeight + CharacterOffsetY; rect.Width = CharacterWidth; rect.Height = CharacterHeight; bounds.Top = 0; bounds.Left = 0; bounds.Width = CharacterWidth; bounds.Height = CharacterHeight; advance = CharacterWidth; } else { var data = charData[c]; rect.Left = data.X; rect.Top = data.Y; rect.Width = data.Width; rect.Height = data.Height; bounds.Left = data.OffsetX; bounds.Top = data.OffsetY; bounds.Width = data.Width; bounds.Height = data.Height; advance = data.Advance; } return(new SFML.Graphics.Glyph() { Advance = advance, Bounds = bounds, TextureRect = rect }); }
public void Start(ITextSurfaceRendered surface, Matrix transform, int additionalDraws = 250) { fillRect = surface.AbsoluteArea; texture = surface.Font.FontImage; solidRect = surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex]; this.transform = transform; int count = ((surface.RenderCells.Length + 8 + additionalDraws) * 4 * 2); if (m_verticies.Length != count) { m_verticies = new Vertex[count]; } vertIndexCounter = 0; }
public unsafe void DrawQuad(Rectangle screenRect, Rectangle textCoords, Color color, Texture texture) { if (_lastDrawCall.Texture != texture && _lastDrawCall.Texture != null) { End(); _lastDrawCall.VertIndex = 0; } _lastDrawCall.Texture = texture; if (_lastDrawCall.VertIndex >= _maxIndex) { global::System.Array.Resize(ref _lastDrawCall.Verticies, _lastDrawCall.Verticies.Length + _lastDrawCall.Verticies.Length / 2); _maxIndex = _lastDrawCall.Verticies.Length - 200; } fixed(Vertex *verts = _lastDrawCall.Verticies) { verts[_lastDrawCall.VertIndex].Position.X = screenRect.Left; verts[_lastDrawCall.VertIndex].Position.Y = screenRect.Top; verts[_lastDrawCall.VertIndex].TexCoords.X = textCoords.Left; verts[_lastDrawCall.VertIndex].TexCoords.Y = textCoords.Top; verts[_lastDrawCall.VertIndex].Color = color; _lastDrawCall.VertIndex++; verts[_lastDrawCall.VertIndex].Position.X = screenRect.Width; verts[_lastDrawCall.VertIndex].Position.Y = screenRect.Top; verts[_lastDrawCall.VertIndex].TexCoords.X = textCoords.Width; verts[_lastDrawCall.VertIndex].TexCoords.Y = textCoords.Top; verts[_lastDrawCall.VertIndex].Color = color; _lastDrawCall.VertIndex++; verts[_lastDrawCall.VertIndex].Position.X = screenRect.Width; verts[_lastDrawCall.VertIndex].Position.Y = screenRect.Height; verts[_lastDrawCall.VertIndex].TexCoords.X = textCoords.Width; verts[_lastDrawCall.VertIndex].TexCoords.Y = textCoords.Height; verts[_lastDrawCall.VertIndex].Color = color; _lastDrawCall.VertIndex++; verts[_lastDrawCall.VertIndex].Position.X = screenRect.Left; verts[_lastDrawCall.VertIndex].Position.Y = screenRect.Height; verts[_lastDrawCall.VertIndex].TexCoords.X = textCoords.Left; verts[_lastDrawCall.VertIndex].TexCoords.Y = textCoords.Height; verts[_lastDrawCall.VertIndex].Color = color; _lastDrawCall.VertIndex++; } }
private void updateSprites() { if (m_type == FieldType.Dirt) { m_sprite_ground = Helper.Upper; m_sprite_front = null; m_sprite_minimap.Color = new SFML.Graphics.Color(139, 105, 20); //GoldenRod m_boundingBox = new SFML.Graphics.IntRect((int)m_index.X * 80 - Camera.FieldDelta, (int)m_index.Y * 80 - Camera.FieldDelta, 80 + 2 * (Camera.FieldDelta), 80 + 2 * (Camera.FieldDelta)); } else { m_boundingBox = new SFML.Graphics.IntRect(0, 0, 0, 0); m_sprite_minimap.Color = new SFML.Graphics.Color(210, 180, 140); //tan if (m_4neighborSum == 0) { m_sprite_ground = Helper.Ground; m_sprite_front = null; if (m_8neighbors[0] == FieldType.Dirt) { m_sprite_ground = Helper.UpLeftInner; m_sprite_front = null; } if (m_8neighbors[1] == FieldType.Dirt) { m_sprite_ground = Helper.UpRightInner; m_sprite_front = null; } if (m_8neighbors[2] == FieldType.Dirt) { m_sprite_front = Helper.DownRightInner; } if (m_8neighbors[3] == FieldType.Dirt) { m_sprite_front = Helper.DownLeftInner; } } else { if (m_4neighborSum == 1) { if (m_4neighbors[0] == FieldType.Dirt) { m_sprite_front = Helper.Left; m_sprite_ground = Helper.Ground; } if (m_4neighbors[1] == FieldType.Dirt) { m_sprite_ground = Helper.UpperMid; m_sprite_front = null; } if (m_4neighbors[2] == FieldType.Dirt) { m_sprite_ground = Helper.Right; m_sprite_front = null; } if (m_4neighbors[3] == FieldType.Dirt) { m_sprite_front = Helper.LowerMid; m_sprite_ground = Helper.Ground; } } else { if (m_4neighbors[1] == FieldType.Dirt) { m_sprite_front = null; if (m_4neighbors[0] == FieldType.Dirt) { m_sprite_ground = Helper.UpperLeft; } else { m_sprite_ground = Helper.UpperRight; } } if (m_4neighbors[3] == FieldType.Dirt) { if (m_4neighbors[0] == FieldType.Dirt) { m_sprite_front = Helper.LowerLeft; m_sprite_ground = Helper.Ground; } else { m_sprite_front = Helper.LowerRight; m_sprite_ground = Helper.Ground; } } } } } }
protected void setBox() { m_boundingBox = new SFML.Graphics.IntRect((int)m_position.X, (int)m_position.Y, 10, 10); }
private static SFML.Window.Vector2f GetSpriteSize(SFML.Graphics.Shape Object) { SFML.Graphics.IntRect OriginalSize = Object.TextureRect; SFML.Window.Vector2f Scale = Object.Scale; return(new SFML.Window.Vector2f(OriginalSize.Width * Scale.X, OriginalSize.Height * Scale.Y)); }
public unsafe void DrawCell(Cell cell, Rectangle screenRect, Color defaultBackground, SadConsole.Font font) { if (cell.IsVisible) { var glyphRect = font.GlyphIndexRects[cell.ActualGlyphIndex]; if ((cell.ActualSpriteEffect & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally) { var temp = glyphRect.Left; glyphRect.Left = glyphRect.Width; glyphRect.Width = temp; } if ((cell.ActualSpriteEffect & SpriteEffects.FlipVertically) == SpriteEffects.FlipVertically) { var temp = glyphRect.Top; glyphRect.Top = glyphRect.Height; glyphRect.Height = temp; } fixed(Vertex *verts = m_verticies) { if (cell.ActualBackground != Color.Transparent && cell.ActualBackground != defaultBackground) { // Background verts[vertIndexCounter].Position.X = screenRect.Left; verts[vertIndexCounter].Position.Y = screenRect.Top; verts[vertIndexCounter].TexCoords.X = solidRect.Left; verts[vertIndexCounter].TexCoords.Y = solidRect.Top; verts[vertIndexCounter].Color = cell.ActualBackground; vertIndexCounter++; verts[vertIndexCounter].Position.X = screenRect.Width; // SadConsole w/SFML changed Width to be left + width... verts[vertIndexCounter].Position.Y = screenRect.Top; verts[vertIndexCounter].TexCoords.X = solidRect.Width; verts[vertIndexCounter].TexCoords.Y = solidRect.Top; verts[vertIndexCounter].Color = cell.ActualBackground; vertIndexCounter++; verts[vertIndexCounter].Position.X = screenRect.Width; verts[vertIndexCounter].Position.Y = screenRect.Height; verts[vertIndexCounter].TexCoords.X = solidRect.Width; verts[vertIndexCounter].TexCoords.Y = solidRect.Height; verts[vertIndexCounter].Color = cell.ActualBackground; vertIndexCounter++; verts[vertIndexCounter].Position.X = screenRect.Left; verts[vertIndexCounter].Position.Y = screenRect.Height; verts[vertIndexCounter].TexCoords.X = solidRect.Left; verts[vertIndexCounter].TexCoords.Y = solidRect.Height; verts[vertIndexCounter].Color = cell.ActualBackground; vertIndexCounter++; } if (cell.ActualForeground != Color.Transparent) { // Foreground verts[vertIndexCounter].Position.X = screenRect.Left; verts[vertIndexCounter].Position.Y = screenRect.Top; verts[vertIndexCounter].TexCoords.X = glyphRect.Left; verts[vertIndexCounter].TexCoords.Y = glyphRect.Top; verts[vertIndexCounter].Color = cell.ActualForeground; vertIndexCounter++; verts[vertIndexCounter].Position.X = screenRect.Width; // SadConsole w/SFML changed Width to be left + width... verts[vertIndexCounter].Position.Y = screenRect.Top; verts[vertIndexCounter].TexCoords.X = glyphRect.Width; verts[vertIndexCounter].TexCoords.Y = glyphRect.Top; verts[vertIndexCounter].Color = cell.ActualForeground; vertIndexCounter++; verts[vertIndexCounter].Position.X = screenRect.Width; verts[vertIndexCounter].Position.Y = screenRect.Height; verts[vertIndexCounter].TexCoords.X = glyphRect.Width; verts[vertIndexCounter].TexCoords.Y = glyphRect.Height; verts[vertIndexCounter].Color = cell.ActualForeground; vertIndexCounter++; verts[vertIndexCounter].Position.X = screenRect.Left; verts[vertIndexCounter].Position.Y = screenRect.Height; verts[vertIndexCounter].TexCoords.X = glyphRect.Left; verts[vertIndexCounter].TexCoords.Y = glyphRect.Height; verts[vertIndexCounter].Color = cell.ActualForeground; vertIndexCounter++; } } } }
public unsafe void DrawCell(Cell cell, Rectangle screenRect, Rectangle solidRect, Color defaultBackground, SadConsole.Font font) { if (lastDrawCall.Texture != font.FontImage && lastDrawCall.Texture != null) { End(); lastDrawCall.VertIndex = 0; } lastDrawCall.Texture = font.FontImage; if (lastDrawCall.VertIndex >= maxIndex) { global::System.Array.Resize(ref lastDrawCall.Verticies, lastDrawCall.Verticies.Length + lastDrawCall.Verticies.Length / 2); maxIndex = lastDrawCall.Verticies.Length - 200; } var glyphRect = font.GlyphIndexRects[cell.ActualGlyphIndex]; if ((cell.ActualSpriteEffect & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally) { var temp = glyphRect.Left; glyphRect.Left = glyphRect.Width; glyphRect.Width = temp; } if ((cell.ActualSpriteEffect & SpriteEffects.FlipVertically) == SpriteEffects.FlipVertically) { var temp = glyphRect.Top; glyphRect.Top = glyphRect.Height; glyphRect.Height = temp; } fixed(Vertex *verts = lastDrawCall.Verticies) { if (cell.ActualBackground != Color.Transparent && cell.ActualBackground != defaultBackground) { // Background verts[lastDrawCall.VertIndex].Position.X = screenRect.Left; verts[lastDrawCall.VertIndex].Position.Y = screenRect.Top; verts[lastDrawCall.VertIndex].TexCoords.X = solidRect.Left; verts[lastDrawCall.VertIndex].TexCoords.Y = solidRect.Top; verts[lastDrawCall.VertIndex].Color = cell.ActualBackground; lastDrawCall.VertIndex++; verts[lastDrawCall.VertIndex].Position.X = screenRect.Width; // SadConsole w/SFML changed Width to be left + width... verts[lastDrawCall.VertIndex].Position.Y = screenRect.Top; verts[lastDrawCall.VertIndex].TexCoords.X = solidRect.Width; verts[lastDrawCall.VertIndex].TexCoords.Y = solidRect.Top; verts[lastDrawCall.VertIndex].Color = cell.ActualBackground; lastDrawCall.VertIndex++; verts[lastDrawCall.VertIndex].Position.X = screenRect.Width; verts[lastDrawCall.VertIndex].Position.Y = screenRect.Height; verts[lastDrawCall.VertIndex].TexCoords.X = solidRect.Width; verts[lastDrawCall.VertIndex].TexCoords.Y = solidRect.Height; verts[lastDrawCall.VertIndex].Color = cell.ActualBackground; lastDrawCall.VertIndex++; verts[lastDrawCall.VertIndex].Position.X = screenRect.Left; verts[lastDrawCall.VertIndex].Position.Y = screenRect.Height; verts[lastDrawCall.VertIndex].TexCoords.X = solidRect.Left; verts[lastDrawCall.VertIndex].TexCoords.Y = solidRect.Height; verts[lastDrawCall.VertIndex].Color = cell.ActualBackground; lastDrawCall.VertIndex++; //lastDrawCall.Verticies.AddRange(singleDrawVerticies); } if (cell.ActualForeground != Color.Transparent) { // Foreground verts[lastDrawCall.VertIndex].Position.X = screenRect.Left; verts[lastDrawCall.VertIndex].Position.Y = screenRect.Top; verts[lastDrawCall.VertIndex].TexCoords.X = glyphRect.Left; verts[lastDrawCall.VertIndex].TexCoords.Y = glyphRect.Top; verts[lastDrawCall.VertIndex].Color = cell.ActualForeground; lastDrawCall.VertIndex++; verts[lastDrawCall.VertIndex].Position.X = screenRect.Width; // SadConsole w/SFML changed Width to be left + width... verts[lastDrawCall.VertIndex].Position.Y = screenRect.Top; verts[lastDrawCall.VertIndex].TexCoords.X = glyphRect.Width; verts[lastDrawCall.VertIndex].TexCoords.Y = glyphRect.Top; verts[lastDrawCall.VertIndex].Color = cell.ActualForeground; lastDrawCall.VertIndex++; verts[lastDrawCall.VertIndex].Position.X = screenRect.Width; verts[lastDrawCall.VertIndex].Position.Y = screenRect.Height; verts[lastDrawCall.VertIndex].TexCoords.X = glyphRect.Width; verts[lastDrawCall.VertIndex].TexCoords.Y = glyphRect.Height; verts[lastDrawCall.VertIndex].Color = cell.ActualForeground; lastDrawCall.VertIndex++; verts[lastDrawCall.VertIndex].Position.X = screenRect.Left; verts[lastDrawCall.VertIndex].Position.Y = screenRect.Height; verts[lastDrawCall.VertIndex].TexCoords.X = glyphRect.Left; verts[lastDrawCall.VertIndex].TexCoords.Y = glyphRect.Height; verts[lastDrawCall.VertIndex].Color = cell.ActualForeground; lastDrawCall.VertIndex++; //lastDrawCall.Verticies.AddRange(singleDrawVerticies); } } }
public unsafe void DrawCell(Cell cell, Rectangle screenRect, Rectangle solidRect, Color defaultBackground, SadConsole.Font font) { if (lastDrawCall.Texture != font.FontImage && lastDrawCall.Texture != null) { End(); lastDrawCall.VertIndex = 0; } lastDrawCall.Texture = font.FontImage; if (lastDrawCall.VertIndex >= maxIndex) { global::System.Array.Resize(ref lastDrawCall.Verticies, lastDrawCall.Verticies.Length + lastDrawCall.Verticies.Length / 2); maxIndex = lastDrawCall.Verticies.Length - 200; } var glyphRect = font.GlyphIndexRects[cell.ActualGlyphIndex]; if ((cell.ActualSpriteEffect & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally) { var temp = glyphRect.Left; glyphRect.Left = glyphRect.Width; glyphRect.Width = temp; } if ((cell.ActualSpriteEffect & SpriteEffects.FlipVertically) == SpriteEffects.FlipVertically) { var temp = glyphRect.Top; glyphRect.Top = glyphRect.Height; glyphRect.Height = temp; } fixed (Vertex* verts = lastDrawCall.Verticies) { if (cell.ActualBackground != Color.Transparent && cell.ActualBackground != defaultBackground) { // Background verts[lastDrawCall.VertIndex].Position.X = screenRect.Left; verts[lastDrawCall.VertIndex].Position.Y = screenRect.Top; verts[lastDrawCall.VertIndex].TexCoords.X = solidRect.Left; verts[lastDrawCall.VertIndex].TexCoords.Y = solidRect.Top; verts[lastDrawCall.VertIndex].Color = cell.ActualBackground; lastDrawCall.VertIndex++; verts[lastDrawCall.VertIndex].Position.X = screenRect.Width; // SadConsole w/SFML changed Width to be left + width... verts[lastDrawCall.VertIndex].Position.Y = screenRect.Top; verts[lastDrawCall.VertIndex].TexCoords.X = solidRect.Width; verts[lastDrawCall.VertIndex].TexCoords.Y = solidRect.Top; verts[lastDrawCall.VertIndex].Color = cell.ActualBackground; lastDrawCall.VertIndex++; verts[lastDrawCall.VertIndex].Position.X = screenRect.Width; verts[lastDrawCall.VertIndex].Position.Y = screenRect.Height; verts[lastDrawCall.VertIndex].TexCoords.X = solidRect.Width; verts[lastDrawCall.VertIndex].TexCoords.Y = solidRect.Height; verts[lastDrawCall.VertIndex].Color = cell.ActualBackground; lastDrawCall.VertIndex++; verts[lastDrawCall.VertIndex].Position.X = screenRect.Left; verts[lastDrawCall.VertIndex].Position.Y = screenRect.Height; verts[lastDrawCall.VertIndex].TexCoords.X = solidRect.Left; verts[lastDrawCall.VertIndex].TexCoords.Y = solidRect.Height; verts[lastDrawCall.VertIndex].Color = cell.ActualBackground; lastDrawCall.VertIndex++; //lastDrawCall.Verticies.AddRange(singleDrawVerticies); } if (cell.ActualForeground != Color.Transparent) { // Foreground verts[lastDrawCall.VertIndex].Position.X = screenRect.Left; verts[lastDrawCall.VertIndex].Position.Y = screenRect.Top; verts[lastDrawCall.VertIndex].TexCoords.X = glyphRect.Left; verts[lastDrawCall.VertIndex].TexCoords.Y = glyphRect.Top; verts[lastDrawCall.VertIndex].Color = cell.ActualForeground; lastDrawCall.VertIndex++; verts[lastDrawCall.VertIndex].Position.X = screenRect.Width; // SadConsole w/SFML changed Width to be left + width... verts[lastDrawCall.VertIndex].Position.Y = screenRect.Top; verts[lastDrawCall.VertIndex].TexCoords.X = glyphRect.Width; verts[lastDrawCall.VertIndex].TexCoords.Y = glyphRect.Top; verts[lastDrawCall.VertIndex].Color = cell.ActualForeground; lastDrawCall.VertIndex++; verts[lastDrawCall.VertIndex].Position.X = screenRect.Width; verts[lastDrawCall.VertIndex].Position.Y = screenRect.Height; verts[lastDrawCall.VertIndex].TexCoords.X = glyphRect.Width; verts[lastDrawCall.VertIndex].TexCoords.Y = glyphRect.Height; verts[lastDrawCall.VertIndex].Color = cell.ActualForeground; lastDrawCall.VertIndex++; verts[lastDrawCall.VertIndex].Position.X = screenRect.Left; verts[lastDrawCall.VertIndex].Position.Y = screenRect.Height; verts[lastDrawCall.VertIndex].TexCoords.X = glyphRect.Left; verts[lastDrawCall.VertIndex].TexCoords.Y = glyphRect.Height; verts[lastDrawCall.VertIndex].Color = cell.ActualForeground; lastDrawCall.VertIndex++; //lastDrawCall.Verticies.AddRange(singleDrawVerticies); } } }
public unsafe void DrawQuad(Rectangle screenRect, Rectangle textCoords, Color color, Texture texture) { if (lastDrawCall.Texture != texture && lastDrawCall.Texture != null) { //drawCalls.Add(lastDrawCall); End(); lastDrawCall.VertIndex = 0; } lastDrawCall.Texture = texture; if (lastDrawCall.VertIndex >= maxIndex) { global::System.Array.Resize(ref lastDrawCall.Verticies, lastDrawCall.Verticies.Length + lastDrawCall.Verticies.Length / 2); maxIndex = lastDrawCall.Verticies.Length - 200; } fixed (Vertex* verts = lastDrawCall.Verticies) { verts[lastDrawCall.VertIndex].Position.X = screenRect.Left; verts[lastDrawCall.VertIndex].Position.Y = screenRect.Top; verts[lastDrawCall.VertIndex].TexCoords.X = textCoords.Left; verts[lastDrawCall.VertIndex].TexCoords.Y = textCoords.Top; verts[lastDrawCall.VertIndex].Color = color; lastDrawCall.VertIndex++; verts[lastDrawCall.VertIndex].Position.X = screenRect.Width; // SadConsole w/SFML changed Width to be left + width... verts[lastDrawCall.VertIndex].Position.Y = screenRect.Top; verts[lastDrawCall.VertIndex].TexCoords.X = textCoords.Width; verts[lastDrawCall.VertIndex].TexCoords.Y = textCoords.Top; verts[lastDrawCall.VertIndex].Color = color; lastDrawCall.VertIndex++; verts[lastDrawCall.VertIndex].Position.X = screenRect.Width; verts[lastDrawCall.VertIndex].Position.Y = screenRect.Height; verts[lastDrawCall.VertIndex].TexCoords.X = textCoords.Width; verts[lastDrawCall.VertIndex].TexCoords.Y = textCoords.Height; verts[lastDrawCall.VertIndex].Color = color; lastDrawCall.VertIndex++; verts[lastDrawCall.VertIndex].Position.X = screenRect.Left; verts[lastDrawCall.VertIndex].Position.Y = screenRect.Height; verts[lastDrawCall.VertIndex].TexCoords.X = textCoords.Left; verts[lastDrawCall.VertIndex].TexCoords.Y = textCoords.Height; verts[lastDrawCall.VertIndex].Color = color; lastDrawCall.VertIndex++; } //lastDrawCall.Verticies.AddRange(singleDrawVerticies); }
public unsafe void DrawQuad(Rectangle screenRect, Rectangle textCoords, Color color) { fixed (Vertex* verts = m_verticies) { verts[vertIndexCounter].Position.X = screenRect.Left; verts[vertIndexCounter].Position.Y = screenRect.Top; verts[vertIndexCounter].TexCoords.X = textCoords.Left; verts[vertIndexCounter].TexCoords.Y = textCoords.Top; verts[vertIndexCounter].Color = color; vertIndexCounter++; verts[vertIndexCounter].Position.X = screenRect.Width; // SadConsole w/SFML changed Width to be left + width... verts[vertIndexCounter].Position.Y = screenRect.Top; verts[vertIndexCounter].TexCoords.X = textCoords.Width; verts[vertIndexCounter].TexCoords.Y = textCoords.Top; verts[vertIndexCounter].Color = color; vertIndexCounter++; verts[vertIndexCounter].Position.X = screenRect.Width; verts[vertIndexCounter].Position.Y = screenRect.Height; verts[vertIndexCounter].TexCoords.X = textCoords.Width; verts[vertIndexCounter].TexCoords.Y = textCoords.Height; verts[vertIndexCounter].Color = color; vertIndexCounter++; verts[vertIndexCounter].Position.X = screenRect.Left; verts[vertIndexCounter].Position.Y = screenRect.Height; verts[vertIndexCounter].TexCoords.X = textCoords.Left; verts[vertIndexCounter].TexCoords.Y = textCoords.Height; verts[vertIndexCounter].Color = color; vertIndexCounter++; } }
public unsafe void DrawCell(Cell cell, Rectangle screenRect, Color defaultBackground, SadConsole.Font font) { if (cell.IsVisible) { var glyphRect = font.GlyphIndexRects[cell.ActualGlyphIndex]; if ((cell.ActualSpriteEffect & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally) { var temp = glyphRect.Left; glyphRect.Left = glyphRect.Width; glyphRect.Width = temp; } if ((cell.ActualSpriteEffect & SpriteEffects.FlipVertically) == SpriteEffects.FlipVertically) { var temp = glyphRect.Top; glyphRect.Top = glyphRect.Height; glyphRect.Height = temp; } fixed (Vertex* verts = m_verticies) { if (cell.ActualBackground != Color.Transparent && cell.ActualBackground != defaultBackground) { // Background verts[vertIndexCounter].Position.X = screenRect.Left; verts[vertIndexCounter].Position.Y = screenRect.Top; verts[vertIndexCounter].TexCoords.X = solidRect.Left; verts[vertIndexCounter].TexCoords.Y = solidRect.Top; verts[vertIndexCounter].Color = cell.ActualBackground; vertIndexCounter++; verts[vertIndexCounter].Position.X = screenRect.Width; // SadConsole w/SFML changed Width to be left + width... verts[vertIndexCounter].Position.Y = screenRect.Top; verts[vertIndexCounter].TexCoords.X = solidRect.Width; verts[vertIndexCounter].TexCoords.Y = solidRect.Top; verts[vertIndexCounter].Color = cell.ActualBackground; vertIndexCounter++; verts[vertIndexCounter].Position.X = screenRect.Width; verts[vertIndexCounter].Position.Y = screenRect.Height; verts[vertIndexCounter].TexCoords.X = solidRect.Width; verts[vertIndexCounter].TexCoords.Y = solidRect.Height; verts[vertIndexCounter].Color = cell.ActualBackground; vertIndexCounter++; verts[vertIndexCounter].Position.X = screenRect.Left; verts[vertIndexCounter].Position.Y = screenRect.Height; verts[vertIndexCounter].TexCoords.X = solidRect.Left; verts[vertIndexCounter].TexCoords.Y = solidRect.Height; verts[vertIndexCounter].Color = cell.ActualBackground; vertIndexCounter++; } if (cell.ActualForeground != Color.Transparent) { // Foreground verts[vertIndexCounter].Position.X = screenRect.Left; verts[vertIndexCounter].Position.Y = screenRect.Top; verts[vertIndexCounter].TexCoords.X = glyphRect.Left; verts[vertIndexCounter].TexCoords.Y = glyphRect.Top; verts[vertIndexCounter].Color = cell.ActualForeground; vertIndexCounter++; verts[vertIndexCounter].Position.X = screenRect.Width; // SadConsole w/SFML changed Width to be left + width... verts[vertIndexCounter].Position.Y = screenRect.Top; verts[vertIndexCounter].TexCoords.X = glyphRect.Width; verts[vertIndexCounter].TexCoords.Y = glyphRect.Top; verts[vertIndexCounter].Color = cell.ActualForeground; vertIndexCounter++; verts[vertIndexCounter].Position.X = screenRect.Width; verts[vertIndexCounter].Position.Y = screenRect.Height; verts[vertIndexCounter].TexCoords.X = glyphRect.Width; verts[vertIndexCounter].TexCoords.Y = glyphRect.Height; verts[vertIndexCounter].Color = cell.ActualForeground; vertIndexCounter++; verts[vertIndexCounter].Position.X = screenRect.Left; verts[vertIndexCounter].Position.Y = screenRect.Height; verts[vertIndexCounter].TexCoords.X = glyphRect.Left; verts[vertIndexCounter].TexCoords.Y = glyphRect.Height; verts[vertIndexCounter].Color = cell.ActualForeground; vertIndexCounter++; } } } }
internal override SFML.Graphics.Glyph GetGlyph(char c, int size, bool bold) { var rect = new SFML.Graphics.IntRect(); var bounds = new SFML.Graphics.IntRect(); var advance = 0; if (DataType == BitmapFontDataType.None) { var width = Texture.Width; var height = Texture.Height; var offsetChar = (int)c - CharCodeOffset; rect.Left = Util.TwoDeeX(offsetChar * CharacterWidth, width) + CharacterOffsetX; rect.Top = Util.TwoDeeY(offsetChar * CharacterHeight, width) * CharacterHeight + CharacterOffsetY; rect.Width = CharacterWidth; rect.Height = CharacterHeight; bounds.Top = 0; bounds.Left = 0; bounds.Width = CharacterWidth; bounds.Height = CharacterHeight; advance = CharacterWidth; } else { var data = charData[c]; rect.Left = data.X; rect.Top = data.Y; rect.Width = data.Width; rect.Height = data.Height; bounds.Left = data.OffsetX; bounds.Top = data.OffsetY; bounds.Width = data.Width; bounds.Height = data.Height; advance = data.Advance; } return new SFML.Graphics.Glyph() { Advance = advance, Bounds = bounds, TextureRect = rect }; }
public void Start(ITextSurfaceRendered surface, Matrix transform, int additionalDraws = 250) { fillRect = surface.AbsoluteArea; texture = surface.Font.FontImage; solidRect = surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex]; this.transform = transform; int count = ((surface.RenderCells.Length + 8 + additionalDraws) * 4 * 2); if (m_verticies.Length != count) m_verticies = new Vertex[count]; vertIndexCounter = 0; }
private void AfterDeserialized(StreamingContext context) { IsDirty = true; bounds = new Rectangle(position.X, position.Y, Width, Height); }
public unsafe void DrawCell(ColoredGlyph cell, Rectangle screenRect, bool drawBackground, SadConsole.IFont font) { Rectangle solidRect = font.SolidGlyphRectangle.ToIntRect(); if (_lastDrawCall.Texture != ((SadConsole.Host.GameTexture)font.Image).Texture && _lastDrawCall.Texture != null) { End(); _lastDrawCall.VertIndex = 0; } _lastDrawCall.Texture = ((SadConsole.Host.GameTexture)font.Image).Texture; if (_lastDrawCall.VertIndex >= _maxIndex) { global::System.Array.Resize(ref _lastDrawCall.Verticies, _lastDrawCall.Verticies.Length + _lastDrawCall.Verticies.Length / 2); _maxIndex = _lastDrawCall.Verticies.Length - 200; } var glyphRect = font.GetGlyphSourceRectangle(cell.Glyph).ToIntRect(); var background = cell.Background.ToSFMLColor(); var foreground = cell.Foreground.ToSFMLColor(); if ((cell.Mirror & Mirror.Horizontal) == Mirror.Horizontal) { var temp = glyphRect.Left; glyphRect.Left = glyphRect.Width; glyphRect.Width = temp; } if ((cell.Mirror & Mirror.Vertical) == Mirror.Vertical) { var temp = glyphRect.Top; glyphRect.Top = glyphRect.Height; glyphRect.Height = temp; } fixed(Vertex *verts = _lastDrawCall.Verticies) { if (background != Color.Transparent && drawBackground) { // Background verts[_lastDrawCall.VertIndex].Position.X = screenRect.Left; verts[_lastDrawCall.VertIndex].Position.Y = screenRect.Top; verts[_lastDrawCall.VertIndex].TexCoords.X = solidRect.Left; verts[_lastDrawCall.VertIndex].TexCoords.Y = solidRect.Top; verts[_lastDrawCall.VertIndex].Color = background; _lastDrawCall.VertIndex++; verts[_lastDrawCall.VertIndex].Position.X = screenRect.Width; // SadConsole w/SFML changed Width to be left + width... verts[_lastDrawCall.VertIndex].Position.Y = screenRect.Top; verts[_lastDrawCall.VertIndex].TexCoords.X = solidRect.Width; verts[_lastDrawCall.VertIndex].TexCoords.Y = solidRect.Top; verts[_lastDrawCall.VertIndex].Color = background; _lastDrawCall.VertIndex++; verts[_lastDrawCall.VertIndex].Position.X = screenRect.Width; verts[_lastDrawCall.VertIndex].Position.Y = screenRect.Height; verts[_lastDrawCall.VertIndex].TexCoords.X = solidRect.Width; verts[_lastDrawCall.VertIndex].TexCoords.Y = solidRect.Height; verts[_lastDrawCall.VertIndex].Color = background; _lastDrawCall.VertIndex++; verts[_lastDrawCall.VertIndex].Position.X = screenRect.Left; verts[_lastDrawCall.VertIndex].Position.Y = screenRect.Height; verts[_lastDrawCall.VertIndex].TexCoords.X = solidRect.Left; verts[_lastDrawCall.VertIndex].TexCoords.Y = solidRect.Height; verts[_lastDrawCall.VertIndex].Color = background; _lastDrawCall.VertIndex++; //lastDrawCall.Verticies.AddRange(singleDrawVerticies); } if (foreground != Color.Transparent) { // Foreground verts[_lastDrawCall.VertIndex].Position.X = screenRect.Left; verts[_lastDrawCall.VertIndex].Position.Y = screenRect.Top; verts[_lastDrawCall.VertIndex].TexCoords.X = glyphRect.Left; verts[_lastDrawCall.VertIndex].TexCoords.Y = glyphRect.Top; verts[_lastDrawCall.VertIndex].Color = foreground; _lastDrawCall.VertIndex++; verts[_lastDrawCall.VertIndex].Position.X = screenRect.Width; // SadConsole w/SFML changed Width to be left + width... verts[_lastDrawCall.VertIndex].Position.Y = screenRect.Top; verts[_lastDrawCall.VertIndex].TexCoords.X = glyphRect.Width; verts[_lastDrawCall.VertIndex].TexCoords.Y = glyphRect.Top; verts[_lastDrawCall.VertIndex].Color = foreground; _lastDrawCall.VertIndex++; verts[_lastDrawCall.VertIndex].Position.X = screenRect.Width; verts[_lastDrawCall.VertIndex].Position.Y = screenRect.Height; verts[_lastDrawCall.VertIndex].TexCoords.X = glyphRect.Width; verts[_lastDrawCall.VertIndex].TexCoords.Y = glyphRect.Height; verts[_lastDrawCall.VertIndex].Color = foreground; _lastDrawCall.VertIndex++; verts[_lastDrawCall.VertIndex].Position.X = screenRect.Left; verts[_lastDrawCall.VertIndex].Position.Y = screenRect.Height; verts[_lastDrawCall.VertIndex].TexCoords.X = glyphRect.Left; verts[_lastDrawCall.VertIndex].TexCoords.Y = glyphRect.Height; verts[_lastDrawCall.VertIndex].Color = foreground; _lastDrawCall.VertIndex++; //lastDrawCall.Verticies.AddRange(singleDrawVerticies); } if (cell.Decorators.Length != 0) { foreach (var decorator in cell.Decorators) { glyphRect = font.GetGlyphSourceRectangle(decorator.Glyph).ToIntRect(); foreground = decorator.Color.ToSFMLColor(); if ((cell.Mirror & Mirror.Horizontal) == Mirror.Horizontal) { var temp = glyphRect.Left; glyphRect.Left = glyphRect.Width; glyphRect.Width = temp; } if ((cell.Mirror & Mirror.Vertical) == Mirror.Vertical) { var temp = glyphRect.Top; glyphRect.Top = glyphRect.Height; glyphRect.Height = temp; } if (foreground != Color.Transparent) { // Foreground verts[_lastDrawCall.VertIndex].Position.X = screenRect.Left; verts[_lastDrawCall.VertIndex].Position.Y = screenRect.Top; verts[_lastDrawCall.VertIndex].TexCoords.X = glyphRect.Left; verts[_lastDrawCall.VertIndex].TexCoords.Y = glyphRect.Top; verts[_lastDrawCall.VertIndex].Color = foreground; _lastDrawCall.VertIndex++; verts[_lastDrawCall.VertIndex].Position.X = screenRect.Width; // SadConsole w/SFML changed Width to be left + width... verts[_lastDrawCall.VertIndex].Position.Y = screenRect.Top; verts[_lastDrawCall.VertIndex].TexCoords.X = glyphRect.Width; verts[_lastDrawCall.VertIndex].TexCoords.Y = glyphRect.Top; verts[_lastDrawCall.VertIndex].Color = foreground; _lastDrawCall.VertIndex++; verts[_lastDrawCall.VertIndex].Position.X = screenRect.Width; verts[_lastDrawCall.VertIndex].Position.Y = screenRect.Height; verts[_lastDrawCall.VertIndex].TexCoords.X = glyphRect.Width; verts[_lastDrawCall.VertIndex].TexCoords.Y = glyphRect.Height; verts[_lastDrawCall.VertIndex].Color = foreground; _lastDrawCall.VertIndex++; verts[_lastDrawCall.VertIndex].Position.X = screenRect.Left; verts[_lastDrawCall.VertIndex].Position.Y = screenRect.Height; verts[_lastDrawCall.VertIndex].TexCoords.X = glyphRect.Left; verts[_lastDrawCall.VertIndex].TexCoords.Y = glyphRect.Height; verts[_lastDrawCall.VertIndex].Color = foreground; _lastDrawCall.VertIndex++; } } } } }
//////////////////////___METHODS___////////////////////// #region Methods public void initializeStatics() { SFML.Graphics.IntRect rect = new SFML.Graphics.IntRect(0, 0, (int)Camera.m_FieldSize, (int)Camera.m_FieldSize); }