//mxd. Clears the list without redrawing it
 public void Clear()
 {
     selection.Clear();
     items.Clear();
     lastselecteditem = null;
     rectangles.Clear();
 }
        public void ScrollToItem(ImageBrowserItem item)
        {
            int index = items.IndexOf(item);

            if (index < 0)
            {
                return;
            }

            Rectangle rec = rectangles[index];

            //mxd. Already visible?
            int ymin = scrollbar.Value - titleheight;
            int ymax = ymin + this.ClientRectangle.Height + titleheight;

            if (rec.Top - 3 >= ymin && rec.Bottom + 3 <= ymax)
            {
                return;
            }

            int yscroll = Math.Max(0, Math.Min(rec.Top - titleheight - 3, scrollbar.Maximum - ClientRectangle.Height));

            scrollbar.Value = yscroll;
            Refresh();
        }
Пример #3
0
        // This selects an item by longname (mxd - changed from name to longname)
        public void SelectItem(long longname)
        {
            // Not when selecting is prevented
            if (preventselection)
            {
                return;
            }

            // Search for item
            ImageBrowserItem target = null;             //mxd

            foreach (ImageBrowserItem item in items)
            {
                if (item.Icon.LongName == longname)                //mxd
                {
                    target = item;
                    break;
                }
            }

            if (target != null)
            {
                // Select the item
                list.SetSelectedItem(target);
            }
        }
Пример #4
0
        // This validates an item
        private bool ValidateItem(ImageBrowserItem item, ImageBrowserItem previtem)
        {
            //mxd. mixMode: 0 = All, 1 = Textures, 2 = Flats, 3 = Based on BrowseFlats
            //if (!splitter.Panel2Collapsed)
            {
                if (texturetype == 0 && previtem != null && item.TextureName == previtem.TextureName)
                {
                    return(false);
                }
                if (texturetype == 1 && item.Icon.IsFlat)
                {
                    return(false);
                }
                if (texturetype == 2 && !item.Icon.IsFlat)
                {
                    return(false);
                }
                if (texturetype == 3 && (browseflats != item.Icon.IsFlat))
                {
                    return(false);
                }
            }
            //else if (previtem != null && item.TextureName == previtem.TextureName) return false;

            return(item.TextureName.ToUpperInvariant().Contains(objectname.Text.ToUpperInvariant()));
        }
Пример #5
0
        // This validates an item
        private bool ValidateItem(ImageBrowserItem item, ImageBrowserItem previtem)
        {
            //mxd. Don't show duplicate items
            if (previtem != null && item.TextureName == previtem.TextureName && item.Group == previtem.Group)
            {
                return(false);                                                                                                         //mxd
            }
            //mxd. mixMode: 0 = All, 1 = Textures, 2 = Flats, 3 = Based on BrowseFlats
            if (!splitter.Panel2Collapsed)
            {
                if (mixMode == 1 && item.Icon.IsFlat)
                {
                    return(false);
                }
                if (mixMode == 2 && !item.Icon.IsFlat)
                {
                    return(false);
                }
                if (mixMode == 3 && (browseFlats != item.Icon.IsFlat))
                {
                    return(false);
                }
                if (!showtexturesfromsubdirs && item.Icon.Level > currentlevel)
                {
                    return(false);
                }
            }

            return(item.Text.ToUpperInvariant().Contains(objectname.Text.ToUpperInvariant()));
        }
 private void OnItemDoubleClicked(ImageBrowserItem item)
 {
     if (ItemDoubleClicked != null)
     {
         ItemDoubleClicked(this, item);
     }
 }
Пример #7
0
        private static Image GetPreview(ImageBrowserItem item, int imagesize)
        {
            if (!item.IsPreviewLoaded)
            {
                return(item.Icon.GetPreview());
            }
            if (!texturecache.ContainsKey(imagesize))
            {
                texturecache.Add(imagesize, new Dictionary <long, Image>());
            }

            // Generate preview?
            if (!texturecache[imagesize].ContainsKey(item.Icon.LongName))
            {
                Image img = item.Icon.GetPreview();

                // Determine preview size
                float scalex, scaley;
                if (item.ItemType == ImageBrowserItemType.IMAGE)
                {
                    scalex = (imagesize == 0 ? 1.0f : (imagesize / (float)img.Width));
                    scaley = (imagesize == 0 ? 1.0f :(imagesize / (float)img.Height));
                }
                else
                {
                    // Don't upscale folder icons
                    scalex = (imagesize == 0 ? 1.0f : ((img.Width > imagesize) ? (imagesize / (float)img.Width) : 1.0f));
                    scaley = (imagesize == 0 ? 1.0f : ((img.Height > imagesize) ? (imagesize / (float)img.Height) : 1.0f));
                }

                float scale         = Math.Min(scalex, scaley);
                int   previewwidth  = (int)(img.Width * scale);
                int   previewheight = (int)(img.Height * scale);
                if (previewwidth < 1)
                {
                    previewwidth = 1;
                }
                if (previewheight < 1)
                {
                    previewheight = 1;
                }

                // Make new image
                Bitmap preview = new Bitmap(previewwidth, previewheight, PixelFormat.Format32bppArgb);
                using (Graphics g = Graphics.FromImage(preview))
                {
                    g.PageUnit          = GraphicsUnit.Pixel;
                    g.InterpolationMode = InterpolationMode.NearestNeighbor;
                    g.PixelOffsetMode   = PixelOffsetMode.Half;

                    g.DrawImage(img, new Rectangle(0, 0, previewwidth, previewheight));
                }

                texturecache[imagesize][item.Icon.LongName] = preview;
            }

            // Get preview
            return(texturecache[imagesize][item.Icon.LongName]);
        }
        // This adds an item
        public void Add(string text, ImageData image, object tag, ListViewGroup group)
        {
            ImageBrowserItem i = new ImageBrowserItem(text, image, tag);

            i.ListGroup = group;
            i.Group     = group;
            items.Add(i);
        }
        //mxd
        public void ClearSelection()
        {
            selection.Clear();
            lastselecteditem = null;

            OnSelectionChanged(selection);
            Refresh();
        }
Пример #10
0
        // This adds an item
        public void Add(ImageData image, object tag, ListViewGroup group, string tooltiptext)
        {
            ImageBrowserItem i = new ImageBrowserItem(image, tag, uselongtexturenames);             //mxd

            i.ListGroup   = group;
            i.Group       = group;
            i.ToolTipText = tooltiptext;
            items.Add(i);
        }
Пример #11
0
        // This adds an item
        // [ZZ] having nice string.Empty does not justify having two functions doing the same thing, with one parameter difference.
        //      C# not Java.
        public void AddItem(ImageData image, string tooltip = "")
        {
            // check if there are already items with this texturename.
            // remove them.
            ImageBrowserItem newItem = new ImageBrowserItem(image, tooltip, uselongtexturenames);

            items.RemoveAll(item => item.TextureName == newItem.TextureName);
            items.Add(newItem);
        }
Пример #12
0
        // This adds an item
        public void Add(string text, ImageData image, object tag, ListViewGroup group, string tooltiptext)
        {
            ImageBrowserItem i = new ImageBrowserItem(text, image, tag);

            i.ListGroup   = group;
            i.Group       = group;
            i.ToolTipText = tooltiptext;
            items.Add(i);
        }
Пример #13
0
 // Doublelicking an item
 private void list_ItemDoubleClicked(object sender, ImageBrowserItem item)
 {
     if (!preventselection && (list.SelectedItems.Count > 0))
     {
         if (SelectedItemDoubleClicked != null)
         {
             SelectedItemDoubleClicked(item);
         }
     }
 }
        public void SetItems(IEnumerable <ImageBrowserItem> items)
        {
            this.items.Clear();
            lastselecteditem = null;
            selection.Clear();
            this.items.AddRange(items);

            OnSelectionChanged(selection);
            UpdateRectangles();
        }
Пример #15
0
        //mxd
        private int SortItems(ImageBrowserItem item1, ImageBrowserItem item2)
        {
            if (usedtexturesfirst.Checked &&
                item1.ItemType == ImageBrowserItemType.IMAGE &&
                item2.ItemType == ImageBrowserItemType.IMAGE &&
                item1.Icon.UsedInMap != item2.Icon.UsedInMap)
            {
                // Push used items to the top
                return(item1.Icon.UsedInMap ? -1 : 1);
            }

            return(item1.CompareTo(item2));
        }
Пример #16
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);
            }
        }
Пример #17
0
 //mxd. This validates an item's texture size
 private static bool ValidateItemSize(ImageBrowserItem i, int w, int h)
 {
     if (!i.Icon.IsPreviewLoaded)
     {
         return(true);
     }
     if (w > 0 && i.Icon.Width != w)
     {
         return(false);
     }
     if (h > 0 && i.Icon.Height != h)
     {
         return(false);
     }
     return(true);
 }
Пример #18
0
        public void SetItems(IEnumerable <ImageBrowserItemGroup> itemgroups)
        {
            this.items.Clear();
            lastselecteditem = null;
            selection.Clear();
            this.itemgroups.Clear();

            foreach (ImageBrowserItemGroup ibig in itemgroups)
            {
                this.items.AddRange(ibig.Items);
                this.itemgroups.Add(ibig);
            }

            OnSelectionChanged(selection);
            UpdateRectangles();
        }
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            this.Focus();

            if (!allowselection)
            {
                return;
            }
            if (!allowmultipleselection || !General.Interface.CtrlState)
            {
                selection.Clear();
            }

            int x = e.X;
            int y = scrollbar.Value + e.Y;

            int clickedIndex = GetIndexAt(x, y);
            var item         = (clickedIndex >= 0 && clickedIndex < items.Count ? items[clickedIndex] : null);

            if (item == null)
            {
                selection.Clear();
            }
            else if (allowmultipleselection && General.Interface.CtrlState && selection.Contains(item))
            {
                selection.Remove(item);
                lastselecteditem = null;
            }
            else if (allowmultipleselection && General.Interface.ShiftState && lastselecteditem != null)
            {
                int bef   = items.IndexOf(lastselecteditem);
                var start = Math.Min(bef, clickedIndex);
                var count = Math.Abs(clickedIndex - bef) + 1;
                selection.AddRange(items.GetRange(start, count).Where(i => !selection.Contains(i)));
            }
            else
            {
                selection.Add(item);
                lastselecteditem = item;
            }

            OnSelectionChanged(selection);
            Refresh();
        }
Пример #20
0
        private static bool ValidateItemColor(ImageBrowserItem i, PixelColor?c, int intensity)
        {
            if (c == null)
            {
                return(true);
            }

            double iy = CalculateColorY(i.Icon.AverageColor);
            double cy = CalculateColorY(c.Value);

            double iu = CalculateColorU(iy, i.Icon.AverageColor);
            double cu = CalculateColorU(cy, c.Value);

            double iv = CalculateColorV(iy, i.Icon.AverageColor);
            double cv = CalculateColorV(cy, c.Value);

            double distance = Math.Sqrt(Math.Pow(iy - cy, 2) + Math.Pow(iu - cu, 2) + Math.Pow(iv - cv, 2));

            return(distance < intensity);
        }
Пример #21
0
 // This updates the texture size label
 private void UpdateTextureSizeLabel()
 {
     if ((list.SelectedItems.Count == 0) ||
         (splitter.Panel2.ClientSize.Width < (texturesize.Location.X + texturesize.Size.Width)))
     {
         texturesizetimer.Start();
     }
     else
     {
         texturesizetimer.Stop();
         ImageBrowserItem lvi = (list.SelectedItems[0] as ImageBrowserItem);
         if (lvi.icon.IsPreviewLoaded)
         {
             texturesize.Text = lvi.icon.Width + " x " + lvi.icon.Height;
         }
         else
         {
             texturesize.Text = "unknown";
         }
         texturesize.Visible      = true;
         texturesizelabel.Visible = true;
     }
 }
Пример #22
0
        // This selects an item by longname (mxd - changed from name to longname)
        public void SelectItem(long longname, ListViewGroup preferredgroup)
        {
            ImageBrowserItem lvi = null;             //mxd

            // Not when selecting is prevented
            if (preventselection)
            {
                return;
            }

            // Search in preferred group first
            if (preferredgroup != null)
            {
                foreach (ListViewItem item in list.Items)
                {
                    ImageBrowserItem curitem = item as ImageBrowserItem;
                    if (curitem != null && longname == curitem.Icon.LongName)                    //mxd
                    {
                        lvi = curitem;
                        if (item.Group == preferredgroup)
                        {
                            break;
                        }
                    }
                }
            }

            // Select the item
            if (lvi != null)
            {
                // Select this item
                list.SelectedItems.Clear();
                lvi.Selected = true;
                lvi.EnsureVisible();
            }
        }
Пример #23
0
        /// <summary>
        /// Jumps back and forth between the currently selected texture at the top and in the pile of all textures
        /// </summary>
        /// <param name="item">The item to jump back and forth between</param>
        public void JumpBetweenItems(ImageBrowserItem item)
        {
            // The item has to exist twice, once in the used textures at the top and in the pile, so get the indexes
            int index1 = items.IndexOf(item);
            int index2 = items.LastIndexOf(item);

            // Item only exists once, so stop here
            if (index1 == index2)
            {
                return;
            }

            Rectangle rect1 = rectangles[index1];
            Rectangle rect2 = rectangles[index2];

            // Get the distance to the two images. Count from the center of the currently scrolled to position and take the bottom
            // of the first image and the top of the second image
            int distance1 = Math.Abs(rect1.Bottom - (scrollbar.Value + ClientRectangle.Height / 2));
            int distance2 = Math.Abs(rect2.Top - (scrollbar.Value + ClientRectangle.Height / 2));

            int yscroll;

            // Get the y position we want to scroll to
            if (centeritem)
            {
                yscroll = (distance1 > distance2 ? (rect1.Top + rect1.Height / 2) : (rect2.Top + rect2.Height / 2)) - ClientRectangle.Height / 2;
            }
            else
            {
                yscroll = distance1 > distance2 ? rect1.Top : rect2.Top;
            }

            // The desired y position might be outside of the range we can scroll to, so clamp the value
            scrollbar.Value = Math.Max(0, Math.Min(yscroll, scrollbar.Maximum - ClientRectangle.Height));
            Refresh();
        }
Пример #24
0
 // This validates an item
 private bool ValidateItem(ImageBrowserItem i)
 {
     return(i.Text.ToUpperInvariant().Contains(objectname.Text));
 }
Пример #25
0
 // This validates an item
 private bool ValidateItem(ImageBrowserItem i)
 {
     return(i.Text.Contains(objectname.Text));
 }
 public void SetSelectedItem(ImageBrowserItem item)
 {
     SetSelectedItems(new List <ImageBrowserItem> {
         item
     });
 }
        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);
            }
        }
Пример #28
0
        // This fills the list based on the objectname filter
        private void RefillList(bool selectfirst)
        {
            visibleitems = new List <ImageBrowserItem>();

            //mxd. Store info about currently selected item
            string selectedname = string.Empty;

            if (!selectfirst && keepselected == -1 && list.SelectedItems.Count > 0)
            {
                selectedname = list.SelectedItems[0].Icon.Name;
            }

            // Clear list first
            list.Clear();
            list.Title = (usedtexturesfirst.Checked ? usedfirstgroup : availgroup);

            //mxd. Anything to do?
            if (items.Count == 0)
            {
                return;
            }

            //mxd. Filtering by texture size?
            int w = filterWidth.GetResult(-1);
            int h = filterHeight.GetResult(-1);

            PixelColor?c;

            if (filterColorCheckBox.Checked)
            {
                c = new PixelColor(255, filterColor.BackColor.R, filterColor.BackColor.G, filterColor.BackColor.B);
            }
            else
            {
                c = null;
            }
            int intensity = filterColorIntensity.Value;

            // Go for all items
            ImageBrowserItem previtem = null;             //mxd

            for (int i = items.Count - 1; i > -1; i--)
            {
                // Add item if valid
                items[i].ShowFullName = uselongtexturenames;                 //mxd
                switch (items[i].ItemType)
                {
                case ImageBrowserItemType.IMAGE:
                    if (ValidateItem(items[i], previtem) && ValidateItemSize(items[i], w, h) && ValidateItemColor(items[i], c, intensity))
                    {
                        visibleitems.Add(items[i]);
                        previtem = items[i];
                    }
                    break;

                case ImageBrowserItemType.FOLDER_UP:                         //mxd. "Browse Up" items are always valid
                    visibleitems.Add(items[i]);
                    break;

                case ImageBrowserItemType.FOLDER:                         //mxd. Only apply name filtering to "Folder" items
                    if (items[i].TextureName.ToUpperInvariant().Contains(objectname.Text.ToUpperInvariant()))
                    {
                        visibleitems.Add(items[i]);
                    }
                    break;

                default: throw new NotImplementedException("Unknown ImageBrowserItemType");
                }
            }

            // Fill list
            visibleitems.Sort(SortItems);
            list.SetItems(visibleitems);

            // Make selection?
            if (!preventselection && list.Items.Count > 0)
            {
                // Select specific item?
                if (keepselected > -1)
                {
                    list.SetSelectedItem(list.Items[keepselected]);
                }
                // Select first item?
                else if (selectfirst)
                {
                    SelectFirstItem();
                }
                //mxd. Try reselecting the same/next closest item
                else if (!string.IsNullOrEmpty(selectedname))
                {
                    ImageBrowserItem bestmatch = null;
                    int charsmatched           = 1;
                    foreach (ImageBrowserItem item in list.Items)
                    {
                        if (item.ItemType == ImageBrowserItemType.IMAGE && item.Icon.Name[0] == selectedname[0])
                        {
                            if (item.Icon.Name == selectedname)
                            {
                                bestmatch = item;
                                break;
                            }

                            for (int i = 1; i < Math.Min(item.Icon.Name.Length, selectedname.Length); i++)
                            {
                                if (item.Icon.Name[i] != selectedname[i])
                                {
                                    if (i > charsmatched)
                                    {
                                        bestmatch    = item;
                                        charsmatched = i;
                                    }
                                    break;
                                }
                            }
                        }
                    }

                    // Select found item
                    if (bestmatch != null)
                    {
                        list.SetSelectedItem(bestmatch);
                    }
                    else
                    {
                        SelectFirstItem();
                    }
                }
            }

            // Raise event
            if ((SelectedItemChanged != null) && !preventselection)
            {
                SelectedItemChanged(list.SelectedItems.Count > 0 ? list.SelectedItems[0] : null);
            }
        }
Пример #29
0
        // This fills the list based on the objectname filter
        private void RefillList(bool selectfirst)
        {
            ImageBrowserItemGroup directoryitems = new ImageBrowserItemGroup("Directories");
            ImageBrowserItemGroup useditems      = new ImageBrowserItemGroup("Used textures");
            ImageBrowserItemGroup visibleitems   = new ImageBrowserItemGroup("All textures");

            // Clear list first
            list.Clear();
            list.Title = (usedtexturesfirst.Checked ? usedfirstgroup : availgroup);

            //mxd. Anything to do?
            if (items.Count == 0)
            {
                return;
            }

            //mxd. Filtering by texture size?
            int w = filterWidth.GetResult(-1);
            int h = filterHeight.GetResult(-1);

            // Go for all items
            ImageBrowserItem previtem = null;             //mxd

            for (int i = items.Count - 1; i > -1; i--)
            {
                // Add item if valid
                items[i].ShowFullName = uselongtexturenames;                 //mxd
                switch (items[i].ItemType)
                {
                case ImageBrowserItemType.IMAGE:
                    if (ValidateItem(items[i], previtem) && ValidateItemSize(items[i], w, h))
                    {
                        visibleitems.Items.Add(items[i]);

                        if (items[i].Icon.UsedInMap)
                        {
                            useditems.Items.Add(items[i]);
                        }

                        previtem = items[i];
                    }
                    break;

                case ImageBrowserItemType.FOLDER_UP:                         //mxd. "Browse Up" items are always valid
                    directoryitems.Items.Add(items[i]);
                    break;

                case ImageBrowserItemType.FOLDER:                         //mxd. Only apply name filtering to "Folder" items
                    if (items[i].TextureName.ToUpperInvariant().Contains(objectname.Text.ToUpperInvariant()))
                    {
                        directoryitems.Items.Add(items[i]);
                    }
                    break;

                default: throw new NotImplementedException("Unknown ImageBrowserItemType");
                }
            }

            // Fill list
            directoryitems.Items.Sort();
            useditems.Items.Sort();
            visibleitems.Items.Sort();

            List <ImageBrowserItemGroup> itemgroups = new List <ImageBrowserItemGroup>();

            // Always add the directories
            itemgroups.Add(directoryitems);

            // Add used textures if the user wants to and there are any
            if (usedtexturesfirst.Checked && useditems.Items.Count > 0)
            {
                itemgroups.Add(useditems);
            }

            // Finally add all items
            if (visibleitems.Items.Count > 0)
            {
                itemgroups.Add(visibleitems);
            }

            list.SetItems(itemgroups);

            // Make selection?
            if (!preventselection && list.Items.Count > 0)
            {
                // Select specific item?
                if (keepselected > -1)
                {
                    // If the last item doesn't exist anymore select the new last item
                    if (keepselected >= list.Items.Count)
                    {
                        list.SetSelectedItem(list.Items[list.Items.Count - 1]);
                    }
                    else
                    {
                        list.SetSelectedItem(list.Items[keepselected]);
                    }
                }
                // Select first item?
                else if (selectfirst)
                {
                    SelectFirstItem();
                }
                //mxd. Try reselecting the same/next closest item
                else if (!string.IsNullOrEmpty(objectname.Text))
                {
                    ImageBrowserItem bestmatch = null;
                    int charsmatched           = 1;
                    foreach (ImageBrowserItem item in list.Items)
                    {
                        if (item.ItemType == ImageBrowserItemType.IMAGE && item.Icon.Name[0] == objectname.Text[0])
                        {
                            if (bestmatch == null)
                            {
                                bestmatch = item;
                            }

                            if (item.Icon.Name == objectname.Text)
                            {
                                bestmatch = item;
                                break;
                            }

                            for (int i = 1; i < Math.Min(item.Icon.Name.Length, objectname.Text.Length); i++)
                            {
                                if (item.Icon.Name[i] == objectname.Text[i])
                                {
                                    if (i > charsmatched)
                                    {
                                        bestmatch    = item;
                                        charsmatched = i;
                                    }
                                    break;
                                }
                            }
                        }
                    }

                    // Select found item
                    if (bestmatch != null)
                    {
                        list.SetSelectedItem(bestmatch);
                    }
                    else
                    {
                        SelectFirstItem();
                    }
                }
            }

            // Raise event
            if ((SelectedItemChanged != null) && !preventselection)
            {
                SelectedItemChanged(list.SelectedItems.Count > 0 ? list.SelectedItems[0] : null);
            }
        }
Пример #30
0
        // This adds an item
        // [ZZ] having nice string.Empty does not justify having two functions doing the same thing, with one parameter difference.
        //      C# not Java.
        public void AddItem(ImageData image, string tooltip = "")
        {
            ImageBrowserItem newItem = new ImageBrowserItem(image, tooltip, uselongtexturenames);

            items.Add(newItem);
        }