}                                        //mxd. Needed for inheritance...

        public ImageBrowserItem(ImageData icon, string tooltip, bool showfullname)
        {
            // Initialize
            this.icon         = icon;
            this.itemtype     = ImageBrowserItemType.IMAGE; //mxd
            this.showfullname = showfullname;               //mxd
            this.imageloaded  = icon.IsPreviewLoaded;       //mxd
            this.tooltip      = tooltip;                    //mxd
        }
示例#2
0
        //mxd. This adds a category item
        public void AddFolder(ImageBrowserItemType itemtype, string categoryname)
        {
            switch (itemtype)
            {
            case ImageBrowserItemType.FOLDER:
            case ImageBrowserItemType.FOLDER_UP:
                items.Add(new ImageBrowserCategoryItem(itemtype, categoryname));
                break;

            default: throw new Exception("Unsupported ImageBrowserItemType");
            }
        }
示例#3
0
        }                                        //mxd. Needed for inheritance...

        public ImageBrowserItem(ImageData icon, string tooltip, bool showfullname)
        {
            // Initialize
            this.icon         = icon;
            this.itemtype     = ImageBrowserItemType.IMAGE; //mxd
            this.showfullname = showfullname;               //mxd
            this.imageloaded  = icon.IsPreviewLoaded;       //mxd
            this.tooltip      = tooltip;                    //mxd

            //mxd. Calculate names width
            this.namewidth      = (int)Math.Ceiling(General.Interface.MeasureString(icon.Name, SystemFonts.MessageBoxFont, 10000, StringFormat.GenericTypographic).Width) + 6;
            this.shortnamewidth = (int)Math.Ceiling(General.Interface.MeasureString(icon.ShortName, SystemFonts.MessageBoxFont, 10000, StringFormat.GenericTypographic).Width) + 6;
        }
示例#4
0
        private void DrawTextures(Graphics g)
        {
            // Draw items
            int scrollwidth = (scrollbar.Visible ? scrollbar.Width : 0);

            if (items.Count > 0)
            {
                int y      = scrollbar.Value;
                int height = ClientRectangle.Height;
                int i      = 0;

                ImageBrowserItemType currentType = ImageBrowserItemType.IMAGE; // initialized to random value
                bool currentUsedInMap            = false;

                ImageBrowserItem.SetBrushes(classicview, rectangles[0].X, rectangles[0].Y - y, rectangles[0].Width, rectangles[0].Height);

                foreach (ImageBrowserItemGroup ibig in itemgroups)
                {
                    if (classicview)
                    {
                        // draw corresponding title right above this item.
                        string hdrname = ibig.Title + ":";
                        DrawTextureHeader(g, hdrname, new Rectangle(2, rectangles[i].Y - (SystemFonts.MessageBoxFont.Height + 6) - y, ClientRectangle.Width - scrollwidth - 4, SystemFonts.MessageBoxFont.Height), false);
                        currentType      = items[i].ItemType;
                        currentUsedInMap = items[i].Icon.UsedInMap;
                    }

                    for (int j = 0; j < ibig.Items.Count; j++, i++)
                    {
                        Rectangle rec = rectangles[i];
                        if (rec.Bottom < y)
                        {
                            continue;
                        }
                        if (rec.Top > y + height)
                        {
                            break;
                        }

                        Image bmp = GetPreview(items[i], imagesize);
                        items[i].Draw(g, bmp, rec.X, rec.Y - y, rec.Width, rec.Height, selection.Contains(items[i]), items[i].Icon.UsedInMap, classicview);
                    }
                }
            }

            // Draw title on top of items
            if (!string.IsNullOrEmpty(title) && !classicview)
            {
                DrawTextureHeader(g, title, new Rectangle(2, 2, ClientRectangle.Width - scrollwidth - 4, SystemFonts.MessageBoxFont.Height), true);
            }
        }
        public ImageBrowserCategoryItem(ImageBrowserItemType itemtype, string groupname)
        {
            this.groupname = groupname;
            this.itemtype  = itemtype;

            switch (itemtype)
            {
            case ImageBrowserItemType.FOLDER:
                icon = General.Map.Data.FolderTexture;
                break;

            case ImageBrowserItemType.FOLDER_UP:
                icon = General.Map.Data.FolderUpTexture;
                break;

            default:
                throw new NotImplementedException("Unsupported ItemType");
            }

            // Calculate name width
            this.groupnamewidth = (int)Math.Ceiling(General.Interface.MeasureString(this.groupname, SystemFonts.MessageBoxFont, 10000, StringFormat.GenericTypographic).Width);
        }
        private void DrawTextures(Graphics g)
        {
            // Draw items
            int scrollwidth = (scrollbar.Visible ? scrollbar.Width : 0);

            if (items.Count > 0)
            {
                int y      = scrollbar.Value;
                int height = ClientRectangle.Height;

                ImageBrowserItemType currentType = ImageBrowserItemType.IMAGE; // initialized to random value
                bool currentUsedInMap            = false;

                ImageBrowserItem.SetBrushes(classicview, rectangles[0].X, rectangles[0].Y - y, rectangles[0].Width, rectangles[0].Height);
                for (var i = 0; i < items.Count; i++)
                {
                    if (classicview && (i == 0 || ((currentType == ImageBrowserItemType.IMAGE) != (items[i].ItemType == ImageBrowserItemType.IMAGE)) || (usedtexturesfirst && currentUsedInMap != items[i].Icon.UsedInMap)))
                    {
                        // draw corresponding title right above this item.
                        string hdrname;
                        if (items[i].ItemType == ImageBrowserItemType.IMAGE)
                        {
                            if (usedtexturesfirst && items[i].Icon.UsedInMap)
                            {
                                hdrname = "Used " + contenttype + ":";
                            }
                            else
                            {
                                hdrname = "All " + contenttype + ":";
                            }
                        }
                        else
                        {
                            hdrname = "Directories:";
                        }
                        DrawTextureHeader(g, hdrname, new Rectangle(2, rectangles[i].Y - (SystemFonts.MessageBoxFont.Height + 6) - y, ClientRectangle.Width - scrollwidth - 4, SystemFonts.MessageBoxFont.Height), false);
                        currentType      = items[i].ItemType;
                        currentUsedInMap = items[i].Icon.UsedInMap;
                    }

                    Rectangle rec = rectangles[i];
                    if (rec.Bottom < y)
                    {
                        continue;
                    }
                    if (rec.Top > y + height)
                    {
                        break;
                    }

                    Image bmp = GetPreview(items[i], imagesize);
                    items[i].Draw(g, bmp, rec.X, rec.Y - y, rec.Width, rec.Height, selection.Contains(items[i]), items[i].Icon.UsedInMap, classicview);
                }
            }

            // Draw title on top of items
            if (!string.IsNullOrEmpty(title) && !classicview)
            {
                DrawTextureHeader(g, title, new Rectangle(2, 2, ClientRectangle.Width - scrollwidth - 4, SystemFonts.MessageBoxFont.Height), true);
            }
        }
        internal void UpdateRectangles()
        {
            int w       = ClientRectangle.Width - scrollbar.Width;
            int padhorz = classicview?13:2;
            int padvert = 2;
            int font    = 4 + SystemFonts.MessageBoxFont.Height;
            int cx      = 0;
            int cy      = titleheight;
            int my      = 0;

            rectangles.Clear();

            //
            ImageBrowserItemType currentType = ImageBrowserItemType.IMAGE; // initialized to random value
            bool currentUsedInMap            = false;
            var  firstItem = (items.Count > 0) ? items[0] : null;

            foreach (var ti in items)
            {
                Image preview = GetPreview(ti, imagesize);
                if (classicview && (ti == firstItem || ((currentType == ImageBrowserItemType.IMAGE) != (ti.ItemType == ImageBrowserItemType.IMAGE)) || (usedtexturesfirst && currentUsedInMap != ti.Icon.UsedInMap)))
                {
                    // new row, also provide space for category name.
                    cx               = 0;
                    cy              += SystemFonts.MessageBoxFont.Height + 6 + my + ((ti != firstItem) ? 16 : 0);
                    my               = 0;
                    currentType      = ti.ItemType;
                    currentUsedInMap = ti.Icon.UsedInMap;
                }

                int rw  = w - cx;
                int wid = Math.Max((imagesize > 0 ? imagesize : preview.Width), ti.TextureNameWidth) + padhorz + padhorz;
                int hei = (imagesize > 0 ? imagesize : preview.Height) + padvert + padvert + font;
                // if we draw height below, add another font
                if (General.Settings.ShowTextureSizes && General.Settings.TextureSizesBelow && ti.ItemType == ImageBrowserItemType.IMAGE)
                {
                    hei += font;
                }

                if (rw < wid)
                {
                    // New row
                    cx  = 0;
                    cy += my;
                    my  = 0;
                }

                my = Math.Max(my, hei);
                var rect = new Rectangle(cx + padhorz, cy + padvert, wid - padhorz - padhorz, hei - padvert - padvert - font);
                rectangles.Add(rect);
                cx += wid;
            }

            if (rectangles.Count > 0)
            {
                scrollbar.Maximum     = cy + my;
                scrollbar.SmallChange = (imagesize > 0 ? imagesize : 128) + padvert + padvert + font;
                scrollbar.LargeChange = ClientRectangle.Height;
                scrollbar.Visible     = (scrollbar.Maximum > ClientRectangle.Height);

                if (scrollbar.Value > scrollbar.Maximum - ClientRectangle.Height)
                {
                    scrollbar.Value = Math.Max(0, scrollbar.Maximum - ClientRectangle.Height);
                }
            }
            else
            {
                scrollbar.Visible = false;
            }

            Refresh();
        }