Ejemplo n.º 1
0
 public Bitmap GetImage(TextureItem item)
 {
     lock (PlaceholderImage)
     {
         return new Bitmap(PlaceholderImage);
     }
 }
Ejemplo n.º 2
0
 public Bitmap GetImage(TextureItem item)
 {
     lock (PlaceholderImage)
     {
         return(new Bitmap(PlaceholderImage));
     }
 }
Ejemplo n.º 3
0
 public void AddTexture(TextureItem item)
 {
     if (Items.ContainsKey(item.Name.ToLowerInvariant()))
     {
         return;
     }
     Items.Add(item.Name.ToLowerInvariant(), item);
 }
Ejemplo n.º 4
0
 public Bitmap GetImage(TextureItem item)
 {
     foreach (var ss in _streams)
     {
         if (ss.HasImage(item)) return ss.GetImage(item);
     }
     return null;
 }
Ejemplo n.º 5
0
 public static void LoadTextureItem(TextureItem item)
 {
     if (item == null || item.Package == null)
     {
         return;
     }
     item.Package.Provider.LoadTextures(new[] { item });
 }
Ejemplo n.º 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));
            }
Ejemplo n.º 7
0
 public void LoadTexture(TextureItem item)
 {
     if (!_loadedItems.ContainsKey(item.Name.ToLowerInvariant()))
     {
         Provider.LoadTexture(item);
         _loadedItems.Add(item.Name.ToLowerInvariant(), item);
     }
 }
Ejemplo n.º 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));
     }
 }
Ejemplo n.º 9
0
 public Bitmap GetImage(TextureItem item)
 {
     foreach (var ss in _streams)
     {
         if (ss.HasImage(item))
         {
             return(ss.GetImage(item));
         }
     }
     return(null);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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();
 }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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));
                }
            }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 16
0
 public void AddTexture(TextureItem item)
 {
     if (Items.ContainsKey(item.Name.ToLowerInvariant())) return;
     Items.Add(item.Name.ToLowerInvariant(), item);
 }
Ejemplo n.º 17
0
 private void TextureChanged(object sender, TextureItem texture)
 {
     Mediator.Publish(EditorMediator.TextureSelected, texture);
 }
Ejemplo n.º 18
0
 private void TexturesListTextureSelected(object sender, TextureItem item)
 {
     OnTextureApply(item);
 }
Ejemplo n.º 19
0
 protected virtual void OnTextureApply(TextureItem texture)
 {
     if (TextureApply != null)
     {
         TextureApply(this, texture);
     }
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 21
0
 public bool HasImage(TextureItem item)
 {
     return(item.Flags.HasFlag(TextureFlags.Missing));
 }
Ejemplo n.º 22
0
 public bool HasImage(TextureItem item)
 {
     return(_streams.Any(x => x.HasFile(item.Name.ToLowerInvariant())));
 }
Ejemplo n.º 23
0
 public bool HasImage(TextureItem item)
 {
     return(_roots.Any(x => x.HasFile(item.PrimarySubItem.Name)));
 }
Ejemplo n.º 24
0
 public bool HasImage(TextureItem item)
 {
     return _roots.Any(x => x.HasFile(item.PrimarySubItem.Name));
 }
Ejemplo n.º 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);
                }
            }
Ejemplo n.º 26
0
 public bool HasImage(TextureItem item)
 {
     return item.Flags.HasFlag(TextureFlags.Missing);
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 28
0
 public void TextureSelected(TextureItem selection)
 {
     _document.TextureCollection.SelectedTexture = selection;
 }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 30
0
 public bool HasImage(TextureItem item)
 {
     return(_packages.Any(x => x.Items.ContainsValue(item)));
 }
Ejemplo n.º 31
0
 public void SetSelectedTexture(TextureItem selection)
 {
     SetHistory(selection);
 }
Ejemplo n.º 32
0
        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();
        }
Ejemplo n.º 33
0
 public void LoadTextureItem(TextureItem item)
 {
     item.Package.LoadTexture(item);
 }
Ejemplo n.º 34
0
 protected virtual void OnTextureChanged(TextureItem texture)
 {
     if (TextureChanged != null)
     {
         TextureChanged(this, texture);
     }
 }
Ejemplo n.º 35
0
 public bool HasImage(TextureItem item)
 {
     return(_streams.Any(x => PackageHasTexture(x, item.Reference)));
 }
Ejemplo n.º 36
0
 private TextureComboBoxItem GetTexture(TextureItem item, bool isHistory)
 {
     return new TextureComboBoxItem { DrawBorder = false, IsHistory = isHistory, Item = item };
 }
Ejemplo n.º 37
0
 private void TextureSelected(TextureItem texture)
 {
     _form.SelectTexture(texture);
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 40
0
 private void TextureSelected(object sender, TextureItem item)
 {
     SelectedTexture = item;
     Close();
 }
Ejemplo n.º 41
0
 public override void LoadTexture(TextureItem item)
 {
     LoadTextures(new[] {item});
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 43
0
 public bool HasImage(TextureItem item)
 {
     return(_streams.Any(x => x.HasImage(item)));
 }
Ejemplo n.º 44
0
 public bool HasImage(TextureItem item)
 {
     return _texturePackages.Any(x => x.Items.ContainsValue(item));
 }
Ejemplo n.º 45
0
 public abstract void LoadTexture(TextureItem item);
Ejemplo n.º 46
0
 public static void LoadTextureItem(TextureItem item)
 {
     item.Package.Provider.LoadTextures(new[] { item });
 }
Ejemplo n.º 47
0
 public static void LoadTextureItem(TextureItem item)
 {
     if (item == null || item.Package == null) return;
     item.Package.Provider.LoadTextures(new[] { item });
 }