public async Task <Stream> GetWidgetAsync(LootWidgetOptions lootWidgetOptions) { var headerStream = ResourceExtensions.GetStreamCopy(typeof(Program), "RS3Bot.Cli.Images.Loot_Head.png"); using (var headerImage = Image.FromStream(headerStream)) using (var footerStream = ResourceExtensions.GetStreamCopy(typeof(Program), "RS3Bot.Cli.Images.Loot_Footer.png")) using (var footerImage = Image.FromStream(footerStream)) { var rowAmount = (int)Math.Ceiling(lootWidgetOptions.Items.Count / (double)MaxRowSize); var headerHeight = headerImage.Height; using (var lootImage = new Bitmap(headerImage.Width, headerHeight + (rowAmount * RowHeight) + FooterHeight)) using (var font = new Font(_fontCollection.Families[0], 8)) using (var titleFont = new Font(_fontCollection.Families[0], 12)) using (var rowStream = ResourceExtensions.GetStreamCopy(typeof(Program), "RS3Bot.Cli.Images.Loot_Row.png")) using (var rowImage = Image.FromStream(rowStream)) using (Graphics g = Graphics.FromImage(lootImage)) { g.DrawImage(headerImage, 0, 0); for (int i = 0; i < lootWidgetOptions.Items.Count; i++) { var row = (int)Math.Floor(i / (double)MaxRowSize); var addNewRow = i % MaxRowSize == 0; var itemX = 20 + ((i % MaxRowSize) * 45); var itemY = 45 + (row * RowHeight); var item = lootWidgetOptions.Items[i]; if (addNewRow) { g.DrawImage(rowImage, 0, headerHeight + (row * RowHeight)); } using (var itemStream = await _imageGrabber.GetAsync(item.Item.ItemId)) using (var imageStream = Image.FromStream(itemStream)) using (SolidBrush drawBrush = new SolidBrush(StackFormatter.GetColor(item.Item.Amount))) { var horizontalCenter = itemY + ((32 - imageStream.Height) / 2); var verticalCenter = itemX + ((32 - imageStream.Width) / 2); g.DrawImage(imageStream, verticalCenter, horizontalCenter, imageStream.Width, imageStream.Height); g.DrawString(StackFormatter.QuantityToRSStackSize((long)item.Item.Amount), font, drawBrush, itemX - 7, itemY - 4); } } g.DrawImage(footerImage, 0, lootImage.Height - FooterHeight); headerStream.Position = 0; lootImage.Save(headerStream, System.Drawing.Imaging.ImageFormat.Png); headerStream.Position = 0; } return(headerStream); } }
public async Task <Stream> GetWidgetAsync(ShopWidgetOptions lootWidgetOptions) { var headerStream = ResourceExtensions.GetStreamCopy(typeof(Program), "RS3Bot.Cli.Images.Shop_Header.png"); using (var headerImage = Image.FromStream(headerStream)) using (var footerStream = ResourceExtensions.GetStreamCopy(typeof(Program), "RS3Bot.Cli.Images.Shop_Footer.png")) using (var footerImage = Image.FromStream(footerStream)) { var rowAmount = (int)Math.Ceiling(lootWidgetOptions.Items.Count / (double)MaxRowSize); var headerHeight = headerImage.Height; using (var lootImage = new Bitmap(headerImage.Width, headerHeight + (rowAmount * YSpacing) + FooterHeight)) using (var font = new Font(_fontCollection.Families[0], 8)) using (var shopItem = ResourceExtensions.GetStreamCopy(typeof(Program), "RS3Bot.Cli.Images.Shop_Item.png")) using (var rowStream = ResourceExtensions.GetStreamCopy(typeof(Program), "RS3Bot.Cli.Images.Shop_Row.png")) using (var rowImage = Image.FromStream(rowStream)) using (var shopItemImage = Image.FromStream(shopItem)) using (var titleFont = new Font(_fontCollection.Families[0], 40)) using (Graphics g = Graphics.FromImage(lootImage)) { g.DrawImage(headerImage, 0, 0); g.DrawString(lootWidgetOptions.Title, font, Brushes.Gold, 26, 12); for (int i = 0; i < lootWidgetOptions.Items.Count; i++) { var row = (int)Math.Floor(i / (double)MaxRowSize); var addNewRow = i % MaxRowSize == 0; var itemX = 30 + ((i % MaxRowSize) * XSpacing); var itemY = 80 + (row * YSpacing); var item = lootWidgetOptions.Items[i]; if (addNewRow) { g.DrawImage(rowImage, 0, headerHeight + (row * YSpacing)); } using (var itemStream = await _imageGrabber.GetAsync(item.Item.ItemId)) using (var imageStream = Image.FromStream(itemStream)) using (SolidBrush drawBrush = new SolidBrush(StackFormatter.GetColor(item.Item.Amount))) { var itemName = ItemDefinition.GetItemName(item.Item.ItemId); var itemNameLines = Split(itemName, MaxItemChar); var horizontalCenter = itemY + ((32 - imageStream.Height) / 2); var verticalCenter = itemX + ((32 - imageStream.Width) / 2); g.DrawImage(shopItemImage, itemX - 20, itemY - 15); g.DrawImage(imageStream, verticalCenter, horizontalCenter, imageStream.Width, imageStream.Height); g.DrawString(StackFormatter.QuantityToRSStackSize((long)item.Item.Amount), font, drawBrush, itemX - 7, itemY - 4); g.DrawString(itemName, font, Brushes.White, new RectangleF(new PointF(itemX + 34f, itemY - 0f), new SizeF(95, 36))); var amountStr = StackFormatter.QuantityToRSStackSize(item.Price); var amountMeasure = g.MeasureString(amountStr, font); g.DrawString(amountStr, font, Brushes.White, itemX + 113 - (amountMeasure.Width / 2), itemY + 26); } } g.DrawImage(footerImage, 0, lootImage.Height - FooterHeight); headerStream.Position = 0; lootImage.Save(headerStream, System.Drawing.Imaging.ImageFormat.Png); headerStream.Position = 0; } return(headerStream); } }
public async Task <Stream> GetWidgetAsync(BankWidgetOptions bankWidgetOptions) { var memoryStream = ResourceExtensions.GetStreamCopy(typeof(Program), "RS3Bot.Cli.Images.Bank_Interface.png"); using (var backInterface = new Bitmap(Image.FromStream(memoryStream))) { var bankInterfaceHeight = backInterface.Height; int amountCount = 0; // Set format of string. StringFormat drawFormat = new StringFormat(); drawFormat.FormatFlags = StringFormatFlags.NoWrap; var maxItemsPerRow = 12; var maxItemSquareSize = 32; using (var font = new Font(_fontCollection.Families[0], 8)) using (var titleFont = new Font(_fontCollection.Families[0], 12)) { using (Graphics g = Graphics.FromImage(backInterface)) { var bankTitle = bankWidgetOptions.Title; var size = g.MeasureString(bankTitle, titleFont); g.DrawString(bankTitle, titleFont, Brushes.Gold, 280 - (size.Width / 2), size.Height + 2); foreach (var item in bankWidgetOptions.Items) { using (var rawStream = await _itemImageGrabber.GetAsync(item.Item.ItemId)) { using (var imageStream = Image.FromStream(rawStream)) { using (SolidBrush drawBrush = new SolidBrush(StackFormatter.GetColor(item.Item.Amount))) { var row = (int)Math.Floor(amountCount / (double)maxItemsPerRow); var itemX = 18 + ((amountCount % maxItemsPerRow) * 45); int itemY = 55 + (row * 40); var horizontalCenter = itemY + ((maxItemSquareSize - imageStream.Height) / 2); var verticalCenter = itemX + ((maxItemSquareSize - imageStream.Width) / 2); g.DrawImage(imageStream, verticalCenter, horizontalCenter, imageStream.Width, imageStream.Height); g.DrawString(StackFormatter.QuantityToRSStackSize((long)item.Item.Amount), font, drawBrush, itemX - 5, itemY - 7, drawFormat); if (bankWidgetOptions.Options.ShowId) { g.DrawString(item.Item.ItemId.ToString(), font, Brushes.White, itemX - 10, itemY + 30, drawFormat); } amountCount += 1; } } } } } } memoryStream.Position = 0; backInterface.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png); memoryStream.Position = 0; return(memoryStream); } }