Example #1
0
 public Bitmap GetImage(TextureItem item)
 {
     lock (PlaceholderImage)
     {
         return new Bitmap(PlaceholderImage);
     }
 }
Example #2
0
 public Bitmap GetImage(TextureItem item)
 {
     lock (PlaceholderImage)
     {
         return(new Bitmap(PlaceholderImage));
     }
 }
Example #3
0
 public void AddTexture(TextureItem item)
 {
     if (Items.ContainsKey(item.Name.ToLowerInvariant()))
     {
         return;
     }
     Items.Add(item.Name.ToLowerInvariant(), item);
 }
Example #4
0
 public Bitmap GetImage(TextureItem item)
 {
     foreach (var ss in _streams)
     {
         if (ss.HasImage(item)) return ss.GetImage(item);
     }
     return null;
 }
Example #5
0
 public static void LoadTextureItem(TextureItem item)
 {
     if (item == null || item.Package == null)
     {
         return;
     }
     item.Package.Provider.LoadTextures(new[] { item });
 }
Example #6
0
            public Bitmap GetImage(TextureItem item)
            {
                var  stream = _streams.First(x => PackageHasTexture(x, item.Reference));
                var  bmp    = Pk3Provider.OpenImage(stream, item.Reference);
                bool hasTransparency;

                return(PostProcessBitmap(item.Package.PackageRelativePath, item.Name.ToLowerInvariant(), bmp, out hasTransparency));
            }
Example #7
0
 public void LoadTexture(TextureItem item)
 {
     if (!_loadedItems.ContainsKey(item.Name.ToLowerInvariant()))
     {
         Provider.LoadTexture(item);
         _loadedItems.Add(item.Name.ToLowerInvariant(), item);
     }
 }
Example #8
0
 public Bitmap GetImage(TextureItem item)
 {
     using (var stream = _streams.First(x => x.HasFile(item.Name.ToLowerInvariant())).OpenFile(item.Name.ToLowerInvariant()))
     {
         bool hasTransparency;
         return(PostProcessBitmap(item.Package.PackageRelativePath, item.Name.ToLowerInvariant(), new Bitmap(stream), out hasTransparency));
     }
 }
Example #9
0
 public Bitmap GetImage(TextureItem item)
 {
     foreach (var ss in _streams)
     {
         if (ss.HasImage(item))
         {
             return(ss.GetImage(item));
         }
     }
     return(null);
 }
Example #10
0
 public Bitmap GetImage(TextureItem item)
 {
     foreach (var root in item.Package.PackageRoot.Split(';'))
     {
         var file = Path.Combine(root, item.Name);
         if (File.Exists(file))
         {
             return(Parse(file));
         }
     }
     return(null);
 }
Example #11
0
        private static void SetSprite(Entity entity, TextureItem tex)
        {
            entity.MetaData.Set(SpriteMetaKey, tex.Name);
            var bb = new Coordinate(tex.Width, tex.Width, tex.Height);

            // Don't set the bounding box if the sprite comes from the iconsprite gamedata
            if (entity.GameData == null || !entity.GameData.Behaviours.Any(x => String.Equals(x.Name, "iconsprite", StringComparison.CurrentCultureIgnoreCase)))
            {
                entity.MetaData.Set(SpriteBoundingBoxMetaKey, new Box(-bb / 2, bb / 2));
                entity.MetaData.Set("RotateBoundingBox", false); // todo rotations
                entity.UpdateBoundingBox();
            }
        }
Example #12
0
 public TextureCollection(List <TexturePackage> packages)
 {
     _packages = packages;
     _items    = new Dictionary <string, TextureItem>();
     foreach (var item in packages.SelectMany(x => x.Items))
     {
         var k = item.Key.ToLowerInvariant();
         if (!_items.ContainsKey(k))
         {
             _items.Add(k, item.Value);
         }
     }
     _recentTextures = new List <TextureItem>();
     SelectedTexture = GetDefaultSelection();
 }
Example #13
0
        private static void SetSprite(Entity entity, TextureItem tex)
        {
            entity.MetaData.Set(SpriteMetaKey, tex.Name);
            var scale = 1m;
            if (entity.GameData != null && entity.GameData.Properties.Any(x => String.Equals(x.Name, "scale", StringComparison.CurrentCultureIgnoreCase)))
            {
                var scaleStr = entity.GetEntityData().GetPropertyValue("scale");
                if (!Decimal.TryParse(scaleStr, out scale)) scale = 1;
                if (scale <= 0.1m) scale = 1;
            }
            var bb = new Coordinate(tex.Width, tex.Width, tex.Height) * scale;

            // Don't set the bounding box if the sprite comes from the iconsprite gamedata
            if (entity.GameData == null || !entity.GameData.Behaviours.Any(x => String.Equals(x.Name, "iconsprite", StringComparison.CurrentCultureIgnoreCase)))
            {
                entity.MetaData.Set(SpriteBoundingBoxMetaKey, new Box(-bb / 2, bb / 2));
                entity.MetaData.Set("RotateBoundingBox", false); // todo rotations
                entity.UpdateBoundingBox();
            }
        }
Example #14
0
            public Bitmap GetImage(TextureItem item)
            {
                var root = _roots.FirstOrDefault(x => x.HasFile(item.PrimarySubItem.Name));

                if (root == null)
                {
                    return(null);
                }
                var stream = root.OpenFile(item.PrimarySubItem.Name);

                if (stream == null)
                {
                    return(null);
                }

                using (stream)
                {
                    return(Vtf.VtfProvider.GetImage(stream, _maxWidth, _maxHeight));
                }
            }
Example #15
0
        private TexturePackage CreatePackage(string package)
        {
            try
            {
                var fi = new FileInfo(package);
                if (!fi.Exists)
                {
                    return(null);
                }

                var tp = new TexturePackage(package, Path.GetFileNameWithoutExtension(package), this);
                if (LoadFromCache(tp))
                {
                    return(tp);
                }

                var pack = _roots.Values.FirstOrDefault(x => x.Package.PackageFile.FullName == fi.FullName);
                if (pack == null)
                {
                    _roots.Add(tp, pack = new Pk3Stream(new ZipPackage(fi)));
                }

                foreach (var file in pack.Package.SearchFiles("textures", @"\.(jpg|png|tga)$", true))
                {
                    var size  = GetImageSize(pack.StreamSource, file);
                    var fname = file.Substring("textures/".Length);
                    fname = fname.Substring(0, fname.Length - 4);
                    var ti = new TextureItem(tp, fname, GetFlags(fname), size.Width, size.Height)
                    {
                        Reference = file
                    };
                    tp.AddTexture(ti);
                }
                SaveToCache(tp);
                return(tp);
            }
            catch
            {
                return(null);
            }
        }
Example #16
0
 public void AddTexture(TextureItem item)
 {
     if (Items.ContainsKey(item.Name.ToLowerInvariant())) return;
     Items.Add(item.Name.ToLowerInvariant(), item);
 }
Example #17
0
 private void TextureChanged(object sender, TextureItem texture)
 {
     Mediator.Publish(EditorMediator.TextureSelected, texture);
 }
 private void TexturesListTextureSelected(object sender, TextureItem item)
 {
     OnTextureApply(item);
 }
 protected virtual void OnTextureApply(TextureItem texture)
 {
     if (TextureApply != null)
     {
         TextureApply(this, texture);
     }
 }
Example #20
0
 private void TextureSelected(TextureItem selection)
 {
     var dis = TextureSelectionPictureBox.Image;
     TextureSelectionPictureBox.Image = null;
     if (dis != null) dis.Dispose();
     TextureSizeLabel.Text = "";
     if (selection == null || DocumentManager.CurrentDocument == null) return;
     TextureComboBox.SetSelectedTexture(selection);
     using (var tp = DocumentManager.CurrentDocument.TextureCollection.GetStreamSource())
     {
         var bmp = tp.GetImage(selection);
         if (bmp.Width > TextureSelectionPictureBox.Width || bmp.Height > TextureSelectionPictureBox.Height)
             TextureSelectionPictureBox.SizeMode = PictureBoxSizeMode.Zoom;
         else
             TextureSelectionPictureBox.SizeMode = PictureBoxSizeMode.CenterImage;
         TextureSelectionPictureBox.Image = bmp;
     }
     TextureSizeLabel.Text = string.Format("{0} x {1}", selection.Width, selection.Height);
 }
Example #21
0
 public bool HasImage(TextureItem item)
 {
     return(item.Flags.HasFlag(TextureFlags.Missing));
 }
Example #22
0
 public bool HasImage(TextureItem item)
 {
     return(_streams.Any(x => x.HasFile(item.Name.ToLowerInvariant())));
 }
Example #23
0
 public bool HasImage(TextureItem item)
 {
     return(_roots.Any(x => x.HasFile(item.PrimarySubItem.Name)));
 }
Example #24
0
 public bool HasImage(TextureItem item)
 {
     return _roots.Any(x => x.HasFile(item.PrimarySubItem.Name));
 }
Example #25
0
            public Bitmap GetImage(TextureItem item)
            {
                var root = _roots.FirstOrDefault(x => x.HasFile(item.PrimarySubItem.Name));
                if (root == null) return null;
                var stream = root.OpenFile(item.PrimarySubItem.Name);
                if (stream == null) return null;

                using (stream)
                {
                    return Vtf.VtfProvider.GetImage(stream, _maxWidth, _maxHeight);
                }
            }
Example #26
0
 public bool HasImage(TextureItem item)
 {
     return item.Flags.HasFlag(TextureFlags.Missing);
 }
Example #27
0
 public Bitmap GetImage(TextureItem item)
 {
     var file = item.Package.PackageFile;
     var child = file.GetFile(item.Name);
     if (child != null && child.Exists)
     {
         return Parse(child);
     }
     return null;
 }
 public void TextureSelected(TextureItem selection)
 {
     _document.TextureCollection.SelectedTexture = selection;
 }
Example #29
0
        private void OwnerDrawItem(System.Drawing.Graphics g, Image bmp, TextureItem ti, Rectangle bounds, Color textColour, Font font, bool drawBorder)
        {
            if (bmp == null) return;
            var lineHeight = (int) Font.GetHeight();
            var imageSize = bounds.Height - lineHeight - 9;

            var iw = bmp.Width;
            var ih = bmp.Height;
            if (iw > imageSize && iw >= ih)
            {
                ih = (int)Math.Floor(imageSize * (ih / (float)iw));
                iw = imageSize;
            }
            else if (ih > imageSize)
            {
                iw = (int)Math.Floor(imageSize * (iw / (float)ih));
                ih = imageSize;
            }

            using (var brush = new SolidBrush(textColour))
            {
                g.DrawString(ti.Name, font, brush, bounds.X + 3, bounds.Y + 3);
                g.DrawString(ti.Width + " x " + ti.Height, font, brush, bounds.X + 6 + imageSize, bounds.Y + lineHeight + 6);
            }

            g.DrawImage(bmp, bounds.X + 3, bounds.Y + lineHeight + 6, iw, ih);

            if (drawBorder)
            {
                using (var pen = new Pen(ForeColor))
                {
                    var liney = bounds.Y + bounds.Height - 1;
                    g.DrawLine(pen, bounds.X, liney, bounds.X + bounds.Width, liney);
                }
            }
        }
Example #30
0
 public bool HasImage(TextureItem item)
 {
     return(_packages.Any(x => x.Items.ContainsValue(item)));
 }
Example #31
0
 public void SetSelectedTexture(TextureItem selection)
 {
     SetHistory(selection);
 }
        public void SelectTexture(TextureItem item)
        {
            if (item == null)
            {
                SelectedTexturesList.SetSelectedTextures(new TextureItem[0]);
                return;
            }

            UpdateRecentTextureList();

            // If the texture is in the list of selected faces, select the texture in that list
            var sl = SelectedTexturesList.GetTextures();
            if (sl.Contains(item))
            {
                SelectedTexturesList.SetSelectedTextures(new[] { item });
                SelectedTexturesList.ScrollToItem(item);
            }
            else if (RecentTexturesList.GetTextures().Contains(item))
            {
                // Otherwise, select the texture in the recent list
                RecentTexturesList.SetSelectedTextures(new[] {item});
                RecentTexturesList.ScrollToItem(item);
            }
            RecentTexturesList.Refresh();
            SelectedTexturesList.Refresh();
        }
Example #33
0
 public void LoadTextureItem(TextureItem item)
 {
     item.Package.LoadTexture(item);
 }
 protected virtual void OnTextureChanged(TextureItem texture)
 {
     if (TextureChanged != null)
     {
         TextureChanged(this, texture);
     }
 }
Example #35
0
 public bool HasImage(TextureItem item)
 {
     return(_streams.Any(x => PackageHasTexture(x, item.Reference)));
 }
Example #36
0
 private TextureComboBoxItem GetTexture(TextureItem item, bool isHistory)
 {
     return new TextureComboBoxItem { DrawBorder = false, IsHistory = isHistory, Item = item };
 }
Example #37
0
 private void TextureSelected(TextureItem texture)
 {
     _form.SelectTexture(texture);
 }
Example #38
0
 private void SetHistory(TextureItem ti)
 {
     if (ti == null) return;
     var rem = FindItem(ti.Name, true) ?? GetTexture(ti.Name, true);
     Items.Remove(rem);
     Items.Insert(0, rem);
     FixHistoryBorder();
     SelectedItem = rem;
 }
Example #39
0
 public Bitmap GetImage(TextureItem item)
 {
     var root = _packages[item.Package.PackageFile];
     var search = root.Item2.GetItemByName(item.Name + ".bmp", HLLib.FindType.Files);
     if (search.Exists)
     {
         using (var stream = root.Item1.CreateStream(search))
         {
             var bmp = new Bitmap(new MemoryStream(stream.ReadAll()));
             bool hasTransparency;
             return PostProcessBitmap(item.Name, bmp, out hasTransparency);
         }
     }
     return null;
 }
Example #40
0
 private void TextureSelected(object sender, TextureItem item)
 {
     SelectedTexture = item;
     Close();
 }
Example #41
0
 public override void LoadTexture(TextureItem item)
 {
     LoadTextures(new[] {item});
 }
Example #42
0
        public void SelectTexture(TextureItem item)
        {
            if (_freeze) return;

            if (item == null)
            {
                SelectedTexturesList.SetSelectedTextures(new TextureItem[0]);
                return;
            }

            UpdateRecentTextureList();

            // If the texture is in the list of selected faces, select the texture in that list
            var sl = SelectedTexturesList.GetTextures();
            if (sl.Any(x => String.Equals(x.Name, item.Name, StringComparison.InvariantCultureIgnoreCase)))
            {
                SelectedTexturesList.SetSelectedTextures(new[] { item });
                SelectedTexturesList.ScrollToItem(item);
            }
            else if (RecentTexturesList.GetTextures().Contains(item))
            {
                // Otherwise, select the texture in the recent list
                RecentTexturesList.SetSelectedTextures(new[] {item});
                RecentTexturesList.ScrollToItem(item);
            }
            RecentTexturesList.Refresh();
            SelectedTexturesList.Refresh();
        }
Example #43
0
 public bool HasImage(TextureItem item)
 {
     return(_streams.Any(x => x.HasImage(item)));
 }
Example #44
0
 public bool HasImage(TextureItem item)
 {
     return _texturePackages.Any(x => x.Items.ContainsValue(item));
 }
Example #45
0
 public abstract void LoadTexture(TextureItem item);
Example #46
0
 public static void LoadTextureItem(TextureItem item)
 {
     item.Package.Provider.LoadTextures(new[] { item });
 }
Example #47
0
 public static void LoadTextureItem(TextureItem item)
 {
     if (item == null || item.Package == null) return;
     item.Package.Provider.LoadTextures(new[] { item });
 }