Beispiel #1
0
 public void Dispose()
 {
     Log.Info("TexturePacker:Dispose()");
     if (_packedTextures != null)
     {
         foreach (PackedTexture bigOne in _packedTextures)
         {
             if (bigOne.textureNo >= 0)
             {
                 Log.Info("TexturePacker: remove texture:{0}", bigOne.textureNo);
                 DXNative.FontEngineRemoveTexture(bigOne.textureNo);
                 if (Disposing != null)
                 {
                     Disposing(this, bigOne.textureNo);
                 }
             }
             if (bigOne.texture != null)
             {
                 if (!bigOne.texture.Disposed)
                 {
                     try
                     {
                         bigOne.texture.Disposing -= TextureDisposing;
                         bigOne.texture.SafeDispose();
                     }
                     catch (Exception) {}
                 }
                 bigOne.texture = null;
             }
         }
     }
 }
Beispiel #2
0
 private void TextureDisposing(object sender, EventArgs e)
 {
     if ((sender as Texture) == null)
     {
         return;
     }
     foreach (PackedTexture bigOne in _packedTextures)
     {
         if (bigOne.texture == (Texture)sender)
         {
             if (bigOne.textureNo >= 0)
             {
                 Log.Info("TexturePacker: disposing texture:{0}", bigOne.textureNo);
                 DXNative.FontEngineRemoveTexture(bigOne.textureNo);
                 if (Disposing != null)
                 {
                     Disposing(this, bigOne.textureNo);
                 }
             }
             bigOne.texture   = null;
             bigOne.textureNo = -1;
             return;
         }
     }
 }
 public static void ReleaseUnmanagedResources()
 {
     unsafe
     {
         DXNative.FontEngineSetDevice(null);
     }
 }
Beispiel #4
0
            /// <summary>
            /// Draw a texture rotated around (x,y) blended with a diffuse texture.
            /// </summary>
            /// <param name="x"></param>
            /// <param name="y"></param>
            /// <param name="nw"></param>
            /// <param name="nh"></param>
            /// <param name="zrot"></param>
            /// <param name="uoff"></param>
            /// <param name="voff"></param>
            /// <param name="umax"></param>
            /// <param name="vmax"></param>
            /// <param name="color"></param>
            /// <param name="diffuseTextureNo"></param>
            /// <param name="uoffd"></param>
            /// <param name="voffd"></param>
            /// <param name="umaxd"></param>
            /// <param name="vmaxd"></param>
            public void Draw(float x, float y, float nw, float nh, float zrot, float uoff, float voff, float umax, float vmax,
                             uint color, int blendableTextureNo, float uoffd, float voffd, float umaxd, float vmaxd,
                             FontEngineBlendMode blendMode)
            {
                if (_textureNumber >= 0)
                {
                    // Rotate around the x,y point of the specified rectangle; maintain aspect ratio (1.0f)
                    TransformMatrix localTransform = new TransformMatrix();
                    localTransform.SetZRotation(zrot, x, y, 1.0f);
                    TransformMatrix finalTransform = GUIGraphicsContext.GetFinalTransform();
                    localTransform = finalTransform.multiply(localTransform);

                    DXNative.FontEngineDrawTexture2(_textureNumber, x, y, nw, nh, uoff, voff, umax, vmax,
                                                    color, localTransform.Matrix,
                                                    blendableTextureNo, uoffd, voffd, umaxd, vmaxd,
                                                    blendMode);
                }
                else
                {
                    if (logTextures)
                    {
                        Log.Info("fontengine:Draw() ERROR. Texture is disposed:{0} {1}", _textureNumber.ToString(), _imageName);
                    }
                }
            }
Beispiel #5
0
            private void DisposeUnmanagedResources()
            {
                //Log.Debug("Frame.DisposeUnmanagedResources mainthread: {0}", !(GUIGraphicsContext.form.InvokeRequired));
                if (_image != null)
                {
                    if (logTextures)
                    {
                        Log.Info("Frame: dispose() fontengine: remove texture:" + _textureNumber.ToString());
                    }
                    try
                    {
                        if (_textureNumber >= 0)
                        {
                            DXNative.FontEngineRemoveTexture(_textureNumber);
                            _textureNumber = -1;
                        }

                        if (_image != null && !_image.Disposed)
                        {
                            _image.Disposing -= new EventHandler(D3DTexture_Disposing);
                            _image.SafeDispose();
                        }
                    }
                    catch (Exception)
                    {
                        //image already disposed?
                    }
                    _image = null;
                }
            }
 private void texture_Disposing(object sender, EventArgs e)
 {
     if ((sender as Texture) == null)
     {
         return;
     }
     for (int i = 0; i < _packedTextures.Count; ++i)
     {
         PackedTexture bigOne = _packedTextures[i];
         if (bigOne.texture == (Texture)sender)
         {
             if (bigOne.textureNo >= 0)
             {
                 Log.Info("TexturePacker: disposing texture:{0}", bigOne.textureNo);
                 DXNative.FontEngineRemoveTexture(bigOne.textureNo);
                 if (Disposing != null)
                 {
                     Disposing(this, bigOne.textureNo);
                 }
             }
             bigOne.texture   = null;
             bigOne.textureNo = -1;
             return;
         }
     }
 }
 public static void SetDeviceNull()
 {
     Log.Debug("GUIFontManager SetDeviceNull()");
     unsafe
     {
         DXNative.FontEngineSetDevice(null);
     }
 }
        /// <summary>
        /// Sets the device and the FVF.
        /// </summary>
        public static void SetDevice()
        {
            Log.Debug("GUIFontManager SetDevice()");
            IntPtr upDevice = DirectShowUtil.GetUnmanagedDevice(GUIGraphicsContext.DX9Device);

            unsafe
            {
                DXNative.FontEngineSetDevice(upDevice.ToPointer());
            }
        }
Beispiel #9
0
 /// <summary>
 /// Draw a texture.
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="nw"></param>
 /// <param name="nh"></param>
 /// <param name="uoff"></param>
 /// <param name="voff"></param>
 /// <param name="umax"></param>
 /// <param name="vmax"></param>
 /// <param name="color"></param>
 public void Draw(float x, float y, float nw, float nh, float uoff, float voff, float umax, float vmax, uint color)
 {
     //string logline=String.Format("draw:#{0} {1} {2} {3} {4}",_textureNumber,x,y,nw,nh);
     //Trace.WriteLine(logline);
     if (_textureNumber >= 0)
     {
         float[,] matrix = GUIGraphicsContext.GetFinalMatrix();
         DXNative.FontEngineDrawTexture(_textureNumber, x, y, nw, nh, uoff, voff, umax, vmax, color, matrix);
     }
     else
     {
         if (logTextures)
         {
             Log.Info("fontengine:Draw() ERROR. Texture is disposed:{0} {1}", _textureNumber.ToString(), _imageName);
         }
     }
 }
Beispiel #10
0
        /// <summary>
        /// Initializes the device objects of the GUIFonts.
        /// </summary>
        public static void InitializeDeviceObjects()
        {
            lock (Renderlock)
            {
                Log.Debug("GUIFontManager InitializeDeviceObjects()");
                IntPtr upDevice = DirectShowUtil.GetUnmanagedDevice(GUIGraphicsContext.DX9Device);

                unsafe
                {
                    DXNative.FontEngineSetDevice(upDevice.ToPointer());
                }
                foreach (GUIFont font in ListFonts)
                {
                    font.InitializeDeviceObjects();
                }
            }
        }
Beispiel #11
0
 /// <summary>
 /// Draw a masked texture.
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="nw"></param>
 /// <param name="nh"></param>
 /// <param name="uoff"></param>
 /// <param name="voff"></param>
 /// <param name="umax"></param>
 /// <param name="vmax"></param>
 /// <param name="color"></param>
 /// <param name="maskTextureNo"></param>
 /// <param name="uoffm"></param>
 /// <param name="voffm"></param>
 /// <param name="umaxm"></param>
 /// <param name="vmaxm"></param>
 public void DrawMasked(float x, float y, float nw, float nh, float uoff, float voff, float umax, float vmax,
                        uint color, int maskTextureNo, float uoffm, float voffm, float umaxm, float vmaxm)
 {
     if (_textureNumber >= 0)
     {
         float[,] matrix = GUIGraphicsContext.GetFinalMatrix();
         DXNative.FontEngineDrawMaskedTexture(_textureNumber, x, y, nw, nh, uoff, voff, umax, vmax,
                                              color, matrix,
                                              maskTextureNo, uoffm, voffm, umaxm, vmaxm);
     }
     else
     {
         if (logTextures)
         {
             Log.Info("fontengine:Draw() ERROR. Texture is disposed:{0} {1}", _textureNumber.ToString(), _imageName);
         }
     }
 }
Beispiel #12
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);
             }
         }
     }
 }
Beispiel #13
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);
        }
        public static void Present()
        {
            lock (Renderlock)
            {
                DXNative.FontEnginePresentTexturesSync();
                foreach (GUIFont font in ListFonts)
                {
                    font.Present();
                }

                if (_spriteUsed)
                {
                    if (_sprite == null)
                    {
                        _sprite = new Sprite(GUIGraphicsContext.DX9Device);
                    }
                    _sprite.Begin(SpriteFlags.AlphaBlend | SpriteFlags.SortTexture);
                    Viewport orgView = GUIGraphicsContext.DX9Device.Viewport;
                    Matrix   orgProj = GUIGraphicsContext.DX9Device.Transform.View;
                    Matrix   projm   = orgProj;

                    foreach (FontManagerDrawText draw in _listDrawText)
                    {
                        Matrix finalm;
                        finalm.M11        = draw.Matrix[0, 0];
                        finalm.M21        = draw.Matrix[0, 1];
                        finalm.M31        = draw.Matrix[0, 2];
                        finalm.M41        = draw.Matrix[0, 3];
                        finalm.M12        = draw.Matrix[1, 0];
                        finalm.M22        = draw.Matrix[1, 1];
                        finalm.M32        = draw.Matrix[1, 2];
                        finalm.M42        = draw.Matrix[1, 3];
                        finalm.M13        = draw.Matrix[2, 0];
                        finalm.M23        = draw.Matrix[2, 1];
                        finalm.M33        = draw.Matrix[2, 2];
                        finalm.M43        = draw.Matrix[2, 3];
                        finalm.M14        = 0;
                        finalm.M24        = 0;
                        finalm.M34        = 0;
                        finalm.M44        = 1.0f;
                        _sprite.Transform = finalm;
                        GUIGraphicsContext.DX9Device.Viewport = draw.Viewport;
                        float wfactor = (float)orgView.Width / draw.Viewport.Width;
                        float hfactor = (float)orgView.Height / draw.Viewport.Height;
                        float xoffset = (float)orgView.X - draw.Viewport.X;
                        float yoffset = (float)orgView.Y - draw.Viewport.Y;
                        projm.M11 = (orgProj.M11 + orgProj.M14 * xoffset) * wfactor;
                        projm.M21 = (orgProj.M21 + orgProj.M24 * xoffset) * wfactor;
                        projm.M31 = (orgProj.M31 + orgProj.M34 * xoffset) * wfactor;
                        projm.M41 = (orgProj.M41 + orgProj.M44 * xoffset) * wfactor;
                        projm.M12 = (orgProj.M12 + orgProj.M14 * yoffset) * hfactor;
                        projm.M22 = (orgProj.M22 + orgProj.M24 * yoffset) * hfactor;
                        projm.M32 = (orgProj.M32 + orgProj.M34 * yoffset) * hfactor;
                        projm.M42 = (orgProj.M42 + orgProj.M44 * yoffset) * hfactor;
                        GUIGraphicsContext.DX9Device.Transform.View = projm;
                        if (GUIGraphicsContext.IsDirectX9ExUsed())
                        {
                            DrawTextUsingTexture(draw, draw.FontHeight);
                        }
                        else
                        {
                            draw.Fnt.DrawText(_sprite, draw.Text, new Rectangle((int)draw.Xpos,
                                                                                (int)draw.Ypos, 0, 0), DrawTextFormat.NoClip,
                                              draw.Color);
                        }

                        _sprite.Flush();
                    }

                    GUIGraphicsContext.DX9Device.Viewport       = orgView;
                    GUIGraphicsContext.DX9Device.Transform.View = orgProj;
                    _sprite.End();
                    _listDrawText = new List <FontManagerDrawText>();
                    _spriteUsed   = false;
                }
            }
        }