private float DrawDownloaderDebug(ResourceRequester requester) { int threadCount = requester.Workers.Count; int size = MathHelper.Clamp((int)Math.Sqrt(threadCount), 1, 3); const float tileWidth = 46; float width = size * tileWidth; float startX = GraphicsDevice.Viewport.Width - width; float offX = 0; float offY = 5; _spriteBatch.Begin(blendState: BlendState.NonPremultiplied); for (int i = 0; i < threadCount; i++) { var request = requester.Workers[i].CurrentRequest; Vector2 pos = new Vector2(startX + offX, offY); offX += tileWidth; if (offX >= width) { offX = 0; offY += 35; } bool working = request == null ? false : true; double progress = 0; if (working) { if (request.ContentLength > 0 && request.BytesDownloaded >= 0) { progress = (double)request.BytesDownloaded / request.ContentLength; } //Console.WriteLine(request.ContentLength + " / " + request.BytesDownloaded); } float actualTileWidth = tileWidth - 5; float cutTileWidth = actualTileWidth * (float)progress; var tileBackColor = new Color(working ? Color.Goldenrod : Color.PaleVioletRed, 0.5f); var tileColor = new Color(Color.LimeGreen, 0.5f); _spriteBatch.DrawFilledRectangle(new RectangleF(pos.X, pos.Y, actualTileWidth, 29), tileBackColor); _spriteBatch.DrawFilledRectangle(new RectangleF(pos.X, pos.Y, cutTileWidth, 29), tileColor); string progresStr = (working ? (int)(progress * 100f) : -1).ToString(); _spriteBatch.DrawString(_font26, progresStr, pos + new Vector2(4, 1), Color.LightCyan); } _spriteBatch.End(); return(startX + offX); }
public PostGraphicsObject(Subreddit.Post post, GraphicsDevice device, ResourceRequester requester) { Post = post; GraphicsDevice = device; Requester = requester; CachedMainText = new ListArray <GlyphSprite>(); CachedStatusText = new ListArray <GlyphSprite>(); IsTextDirty = true; ThumbnailFade = 1; HasThumbnail = Data.HasThumbnail && Data.Thumbnail.Width != -1 && Data.Thumbnail.Height != -1; }