Example #1
0
        internal static Image GenerateTabImage(Tab tab, bool mouseOver)
        {
            List<System.Drawing.Bitmap> images = new List<System.Drawing.Bitmap>();
            System.Drawing.Bitmap finalImage = null;

            Image img = new Image();
            int offset = mouseOver ? 26 : 0;

            string key = tab.srcL + tab.srcC + tab.srcR + tab.Name + mouseOver.ToString();

            if (!imageCache.ContainsKey(key))
                finalImage = buildImage(tab, images, finalImage, offset, key);

            img.Source = imageCache[key];
            img.Tag = tab;

            return img;
        }
        private void inject(Character character, IEnumerable<Item> inventory)
        {
            ApplicationState.Stash[character.League].NumberOfTabs++;
            var tabID = ApplicationState.Stash[character.League].NumberOfTabs;
            var inventoryID = tabID + 1;

            List<Item> characterItems = CharacterStashBuilder.GetCharacterStashItems(character.Name, inventory, inventoryID);

            Tab characterTab = new Tab
            {
                IsFakeTab = true,
                Name = character.Name,
                i = tabID,
                srcC = tabImageCenter,
                srcL = tabImageLeft,
                srcR = tabImageRight,

            };

            ApplicationState.Stash[character.League].AddCharacterTab(characterTab, characterItems);
        }
Example #3
0
 public void AddCharacterTab(Tab tab, List <Item> characterItems)
 {
     items.AddRange(characterItems);
     Tabs.Add(tab);
 }
Example #4
0
 public IEnumerable<Stream> GetImage(Tab tab)
 {
     onImageLoaded(POEEventState.BeforeEvent, tab.Name);
     yield return transport.GetImage(tab.srcL);
     yield return transport.GetImage(tab.srcC);
     yield return transport.GetImage(tab.srcR);
     onImageLoaded(POEEventState.AfterEvent, tab.Name);
 }
 private Image getImage(Tab tab, bool mouseOver)
 {
     return StashHelper.GenerateTabImage(tab, mouseOver);
 }
Example #6
0
        private static System.Drawing.Bitmap buildImage(Tab tab, List<System.Drawing.Bitmap> images, System.Drawing.Bitmap finalImage, int offset, string key)
        {
            try
            {
                System.Drawing.Font font = new System.Drawing.Font(ApplicationState.FontCollection.Families[0], 11);
                int width = 0;
                int height = 0;
                int count = 0;
                float middleWidth = 0;
                foreach (Stream stream in ApplicationState.Model.GetImage(tab))
                {
                    System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(stream);

                    if (count == 1)
                    {
                        using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(new System.Drawing.Bitmap(200, 200)))
                        {
                            System.Drawing.SizeF measured = g.MeasureString(tab.Name, font);
                            width += (int)measured.Width;
                            middleWidth = measured.Width;
                        }
                    }
                    else
                    {
                        width += bitmap.Width;
                    }
                    height = bitmap.Height > height ? bitmap.Height : height;
                    images.Add(bitmap);
                    count++;
                }

                finalImage = new System.Drawing.Bitmap(width, height);
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(finalImage))
                {
                    //set background color
                    g.Clear(System.Drawing.Color.Transparent);

                    //go through each image and draw it on the final image
                    int woffset = 0;
                    count = 0;
                    foreach (System.Drawing.Bitmap image in images)
                    {
                        int iwidth = image.Width;
                        if (count == 1)
                            iwidth = (int)middleWidth;
                        g.DrawImage(image, new System.Drawing.Rectangle(woffset, 0, iwidth, image.Height));
                        woffset += iwidth;
                        if (count == 1)
                            woffset -= 3; //The right image didn't align, similar to forums
                        count++;
                    }

                    g.DrawString(tab.Name, font, System.Drawing.Brushes.Yellow, images[0].Width - 2, 6); //Top
                    g.DrawString(tab.Name, font, System.Drawing.Brushes.Yellow, images[0].Width - 2, 32); //Mouse over version
                }

                using (MemoryStream stream = new MemoryStream())
                {
                    finalImage.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                    stream.Position = 0;
                    var bitmap = new BitmapImage();
                    bitmap.BeginInit();
                    bitmap.StreamSource = stream;
                    bitmap.CacheOption = BitmapCacheOption.OnLoad;
                    bitmap.EndInit();

                    BitmapImage bitmapclone = (BitmapImage)bitmap.Clone();
                    bitmap = null;
                    imageCache.Add(key, new CroppedBitmap(bitmapclone, new Int32Rect(0, offset, (int)bitmapclone.Width, 26)));
                }
            }
            catch (Exception ex)
            {
                if (finalImage != null)
                    finalImage.Dispose();

                throw ex;
            }
            finally
            {
                foreach (System.Drawing.Bitmap image in images)
                    image.Dispose();
            }
            return finalImage;
        }