/// <summary> /// Draw stat on the screen /// </summary> /// <param name="e"></param> protected override void onDraw(XnaDrawArgs e) { // For test purposes only. Texture2D pixel = new Texture2D(e.SpriteBatch.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); pixel.SetData(new[] { Color.White }); }
protected override void onDraw(XnaDrawArgs e) { Texture2D pixel = new Texture2D(e.SpriteBatch.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); pixel.SetData(new[] { Color.White }); //e.SpriteBatch.Draw(pixel, e.Location, new Rectangle(0, 0, 1, 1), Color.Teal); }
protected override void onDraw(XnaDrawArgs e) { SpriteFont font = ((XnaUITestGame)Game).Font; Vector2 destPos = new Vector2((float)e.Location.X, (float)e.Location.Y); if (alignment.Equals("right")) { Vector2 desiredSize = font.MeasureString(text); destPos.X += (float)e.Location.Width - desiredSize.X; } e.SpriteBatch.DrawString(font, text, destPos, color); }
/// <summary> /// upon drawing this textbox on the screen event /// </summary> /// <param name="e"></param> protected override void onDraw(XnaDrawArgs e) { SpriteFont font = ((XnaUITestGame)Game).Font; Vector2 destPos = new Vector2((float)e.Location.X, (float)e.Location.Y); if (alignment.Equals("right")) { Vector2 desiredSize = font.MeasureString(text); destPos.X += (float)e.Location.Width - desiredSize.X; } e.SpriteBatch.DrawString(font, text, destPos, color); }
/// <summary> /// Draw stat of this unit if being selected /// </summary> /// <param name="e"></param> protected override void onDraw(XnaDrawArgs e) { base.onDraw(e); if (selected && !unit.IsZombie) { // Draw a healthbox for the Unit. Rectangle healthBG = new Rectangle(e.Location.X, e.Location.Y + e.Location.Height - 8, e.Location.Width, 8); e.SpriteBatch.Draw(pixel, healthBG, Color.Black); int healthWidth = (int)(e.Location.Width * (1.0 * unit.CurrentHealth / unit.MaxHealth)); Color healthColor = Color.LimeGreen; if (1.0 * unit.CurrentHealth / unit.MaxHealth < 0.25) { healthColor = Color.Red; } else if (1.0 * unit.CurrentHealth / unit.MaxHealth < 0.5) { healthColor = Color.Yellow; } Rectangle healthRect = new Rectangle(e.Location.X, e.Location.Y + e.Location.Height - 8, healthWidth, 8); e.SpriteBatch.Draw(pixel, healthRect, healthColor); Color neoGreen = new Color(111, 245, 30); // Draw a Rectangle around the unit to show that it is selected. Rectangle leftRect = new Rectangle(e.Location.X, e.Location.Y, 2, e.Location.Height); Rectangle rightRect = new Rectangle(e.Location.X + e.Location.Width - 2, e.Location.Y, 2, e.Location.Height); Rectangle topRect = new Rectangle(e.Location.X, e.Location.Y, e.Location.Width, 2); Rectangle bottomRect = new Rectangle(e.Location.X, e.Location.Y + e.Location.Height - 2, e.Location.Width, 2); e.SpriteBatch.Draw(pixel, leftRect, neoGreen); e.SpriteBatch.Draw(pixel, topRect, neoGreen); e.SpriteBatch.Draw(pixel, rightRect, neoGreen); e.SpriteBatch.Draw(pixel, bottomRect, neoGreen); } }
protected override void onDraw(XnaDrawArgs e) { Rectangle actualDraw = e.Location; e.SpriteBatch.Draw(((XnaUITestGame)Game).SpriteSheet, actualDraw, sourceRect, tint); }
protected override void onDraw(XnaDrawArgs e) { }
protected override void onDraw(XnaDrawArgs e) { // Do nothing }
/// <summary> /// Draw stat of the selected building /// </summary> /// <param name="e"></param> protected override void onDraw(XnaDrawArgs e) { base.onDraw(e); if (selected) { // Draw a healthbox for the Building. Rectangle healthBG = new Rectangle(e.Location.X, e.Location.Y + e.Location.Height - 8, e.Location.Width, 8); e.SpriteBatch.Draw(pixel, healthBG, Color.Black); int healthWidth = (int)(e.Location.Width * (1.0 * building.CurrentHealth / building.MaxHealth)); Color healthColor = Color.LimeGreen; if (1.0 * building.CurrentHealth / building.MaxHealth < 0.25) { healthColor = Color.Red; } else if (1.0 * building.CurrentHealth / building.MaxHealth < 0.5) { healthColor = Color.Yellow; } Rectangle healthRect = new Rectangle(e.Location.X, e.Location.Y + e.Location.Height - 8, healthWidth, 8); e.SpriteBatch.Draw(pixel, healthRect, healthColor); Color neoGreen = new Color(111, 245, 30); // Draw a Rectangle around the building to show that it is selected. Rectangle leftRect = new Rectangle(e.Location.X, e.Location.Y, 2, e.Location.Height); Rectangle rightRect = new Rectangle(e.Location.X + e.Location.Width - 2, e.Location.Y, 2, e.Location.Height); Rectangle topRect = new Rectangle(e.Location.X, e.Location.Y, e.Location.Width, 2); Rectangle bottomRect = new Rectangle(e.Location.X, e.Location.Y + e.Location.Height - 2, e.Location.Width, 2); e.SpriteBatch.Draw(pixel, leftRect, neoGreen); e.SpriteBatch.Draw(pixel, topRect, neoGreen); e.SpriteBatch.Draw(pixel, rightRect, neoGreen); e.SpriteBatch.Draw(pixel, bottomRect, neoGreen); } }
// UI Methods public override void Draw(GameTime gameTime) { if (Visible && drawBox.Width > 0 && drawBox.Height > 0) { Viewport currentViewport = Game.GraphicsDevice.Viewport; int viewportMaxX = currentViewport.X + currentViewport.Width; int viewportMaxY = currentViewport.Y + currentViewport.Height; int offsetX = drawBox.X; int offsetY = drawBox.Y; if (container != null) { offsetX -= container.ScrollX; offsetY -= container.ScrollY; } // Ensure that it is inbounds. if (((offsetX + drawBox.Width) > 0) && (offsetX < currentViewport.Width) && ((offsetY + drawBox.Height) > 0) && (offsetY < currentViewport.Height)) { XnaDrawArgs e = new XnaDrawArgs(); e.gameTime = gameTime; e.SpriteBatch = GetSpriteBatch(this); e.Location = new Rectangle(0, 0, drawBox.Width, drawBox.Height); Viewport componentViewport = currentViewport; componentViewport.X = Math.Max(offsetX + currentViewport.X, currentViewport.X); componentViewport.Y = Math.Max(offsetY + currentViewport.Y, currentViewport.Y); // Fix the argument location if it is offset in the negative direction (cropped due to scrolling). if (offsetX < 0) { e.Location.X = offsetX; componentViewport.Width = Math.Max(currentViewport.Width, (offsetX + drawBox.Width)); } else { componentViewport.Width = Math.Min(drawBox.Width, (currentViewport.Width - offsetX)); } if (offsetY < 0) { e.Location.Y = offsetY; componentViewport.Height = Math.Max(currentViewport.Height, (offsetY + drawBox.Height)); } else { componentViewport.Height = Math.Min(drawBox.Height, (currentViewport.Height - offsetY)); } // Likewise fix the height Game.GraphicsDevice.Viewport = componentViewport; // Do Draw work. e.SpriteBatch.Begin(); onDraw(e); e.SpriteBatch.End(); // Call draw on all children foreach (XnaUIComponent child in components) { child.Draw(gameTime); } // Repair the viewport Game.GraphicsDevice.Viewport = currentViewport; } } }
protected abstract void onDraw(XnaDrawArgs e);
protected override void onDraw(XnaDrawArgs e) { //e.SpriteBatch.Draw(pixel, e.Location, new Rectangle(0, 0, 1, 1), color); }
protected override void onDraw(XnaDrawArgs e) { //throw new NotImplementedException(); }
protected override void onDraw(XnaDrawArgs e) { e.SpriteBatch.Draw(((XnaUITestGame)Game).SpriteSheet, e.Location, new Rectangle(0, 0, 1, 1), Color.Green); }
protected override void onDraw(XnaDrawArgs e) { // Determine all of the cells in view ZRTSModel.Map map = ((XnaUITestGame)Game).Model.GetScenario().GetGameWorld().GetMap(); Point upperLeftCell = new Point(ScrollX / CellDimension, ScrollY / CellDimension); Point lowerRightCell = new Point(Math.Min((ScrollX + DrawBox.Width) / CellDimension, map.GetWidth() - 1), Math.Min((ScrollY + DrawBox.Height) / CellDimension, map.GetHeight() - 1)); Point offset = new Point(ScrollX % CellDimension, ScrollY % CellDimension); // Draw all of the tiles for (int x = upperLeftCell.X; x <= lowerRightCell.X; x++) { for (int y = upperLeftCell.Y; y <= lowerRightCell.Y; y++) { CellComponent cell = map.GetCellAt(x, y); Tile tile = cell.GetTile(); DrawTileVisitor drawer = new DrawTileVisitor(e.SpriteBatch, ((XnaUITestGame)Game).SpriteSheet, new Rectangle((x - upperLeftCell.X) * CellDimension - offset.X, (y - upperLeftCell.Y) * CellDimension - offset.Y, CellDimension, CellDimension)); tile.Accept(drawer); } } }
/// <summary> /// upon drawing on the screen /// </summary> /// <param name="e"></param> protected override void onDraw(XnaDrawArgs e) { Texture2D pixel = new Texture2D(e.SpriteBatch.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); pixel.SetData(new[] { Color.White }); }