Example #1
0
 public Frame(string name, Texture image, int duration)
 {
     _imageName = name;
     _image     = image;
     _duration  = duration;
     if (image != null)
     {
         unsafe
         {
             _image.Disposing -= new EventHandler(D3DTexture_Disposing);
             _image.Disposing += new EventHandler(D3DTexture_Disposing);
             IntPtr ptr = DirectShowUtil.GetUnmanagedTexture(_image);
             _textureNumber = DXNative.FontEngineAddTexture(ptr.ToInt32(), true, (void *)ptr.ToPointer());
             if (logTextures)
             {
                 Log.Info("Frame:ctor() fontengine: added texture:{0} {1}", _textureNumber.ToString(), _imageName);
             }
         }
     }
 }
Example #2
0
        public bool Get(string fileName, out float uoffs, out float voffs, out float umax, out float vmax, out int iWidth,
                        out int iHeight, out Texture tex, out int textureNo)
        {
            uoffs     = voffs = umax = vmax = 0.0f;
            iWidth    = iHeight = 0;
            textureNo = -1;
            tex       = null;
            if (_packedTextures == null)
            {
                return(false);
            }

            if (fileName.StartsWith(@"\"))
            {
                fileName = fileName.Remove(0, 1);
            }
            fileName = fileName.ToLowerInvariant();
            if (fileName == string.Empty)
            {
                return(false);
            }

            int               index     = 0;
            PackedTexture     bigOne    = null;
            PackedTextureNode foundNode = null;

            // Look for textures first in the current theme location.  Theme textures override default textures.
            // If the default theme is selected then avoid looking through the theme.
            if (!GUIThemeManager.CurrentThemeIsDefault)
            {
                string skinThemeTexturePath = GUIThemeManager.CurrentTheme + @"\media\";
                skinThemeTexturePath = skinThemeTexturePath.ToLowerInvariant();

                // If a theme texture exists but was not able to be packed then avoid trying to unpack the texture all together.  This prevents
                // a base skin texture from being unpacked and returned when the base texture could be packed but the overriding theme texture
                // could not be packed.
                if (!IsTexturePacked(skinThemeTexturePath + fileName))
                {
                    return(false);
                }

                foreach (PackedTexture texture in _packedTextures)
                {
                    if ((foundNode = texture.root.Get(skinThemeTexturePath + fileName)) != null)
                    {
                        bigOne = texture;
                        break;
                    }
                    index++;
                }
            }

            // No theme texture was found.  Check the default skin location.
            if (foundNode == null)
            {
                index = 0;
                foreach (PackedTexture texture in _packedTextures)
                {
                    if ((foundNode = texture.root.Get(fileName)) != null)
                    {
                        bigOne = texture;
                        break;
                    }
                    index++;
                }
            }

            if (foundNode != null)
            {
                uoffs   = (float)(foundNode.Rect.Left + 1) / bigOne.root.Rect.Width;
                voffs   = (float)(foundNode.Rect.Top + 1) / bigOne.root.Rect.Height;
                umax    = (float)(foundNode.Rect.Width - 2) / bigOne.root.Rect.Width;
                vmax    = (float)(foundNode.Rect.Height - 2) / bigOne.root.Rect.Height;
                iWidth  = foundNode.Rect.Width - 2;
                iHeight = foundNode.Rect.Height - 2;
                if (bigOne.texture == null)
                {
                    LoadPackedGraphics(index);
                }

                tex = bigOne.texture;
                if (bigOne.textureNo == -1)
                {
                    unsafe
                    {
                        IntPtr ptr = DirectShowUtil.GetUnmanagedTexture(bigOne.texture);
                        bigOne.textureNo = DXNative.FontEngineAddTexture(ptr.ToInt32(), true, ptr.ToPointer());
                        Log.Info("TexturePacker: fontengine add texure:{0}", bigOne.textureNo);
                    }
                }
                textureNo = bigOne.textureNo;
                return(true);
            }
            return(false);
        }