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