Example #1
0
        ////////////////////////////////////////////////////////////////////////////    
        ////////////////////////////////////////////////////////////////////////////
        public void DrawGlyph(Glyph glyph, Rectangle rect)
        {
            Size imageSize = new Size(glyph.Image.Width, glyph.Image.Height);

            if (!glyph.SourceRect.IsEmpty)
            {
                imageSize = new Size(glyph.SourceRect.Width, glyph.SourceRect.Height);
            }

            if (glyph.SizeMode == SizeMode.Centered)
            {
                rect = new Rectangle((rect.X + (rect.Width - imageSize.Width) / 2) + glyph.Offset.X,
                                     (rect.Y + (rect.Height - imageSize.Height) / 2) + glyph.Offset.Y,
                                     imageSize.Width,
                                     imageSize.Height);
            }
            else if (glyph.SizeMode == SizeMode.Normal)
            {
                rect = new Rectangle(rect.X + glyph.Offset.X, rect.Y + glyph.Offset.Y, imageSize.Width, imageSize.Height);
            }
            else if (glyph.SizeMode == SizeMode.Auto)
            {
                rect = new Rectangle(rect.X + glyph.Offset.X, rect.Y + glyph.Offset.Y, imageSize.Width, imageSize.Height);
            }

            if (glyph.SourceRect.IsEmpty)
            {
                Draw(glyph.Image, rect, glyph.Color);
            }
            else
            {
                Draw(glyph.Image, rect, glyph.SourceRect, glyph.Color);
            }
        }
Example #2
0
        /// <summary>
        /// Draws a glyph. (An image on a control.)
        /// </summary>
        /// <param name="glyph">Glyph to draw.</param>
        /// <param name="rect">Destination region where the glyph will be drawn.</param>
        public void DrawGlyph(Glyph glyph, Rectangle rect)
        {
            // Get the dimensions of the glyph image asset.
            Size imageSize = new Size(glyph.Image.Width, glyph.Image.Height);

            // Use the source region if one is specified.
            if (!glyph.SourceRect.IsEmpty)
            {
                imageSize = new Size(glyph.SourceRect.Width, glyph.SourceRect.Height);
            }

            // Glyph is centered?
            if (glyph.SizeMode == SizeMode.Centered)
            {
                // Update destination and apply offsets.
                rect = new Rectangle((rect.X + (rect.Width - imageSize.Width) / 2) + glyph.Offset.X,
                                     (rect.Y + (rect.Height - imageSize.Height) / 2) + glyph.Offset.Y,
                                     imageSize.Width,
                                     imageSize.Height);
            }

            // Glyph is left-aligned?
            else if (glyph.SizeMode == SizeMode.Normal)
            {
                rect = new Rectangle(rect.X + glyph.Offset.X, rect.Y + glyph.Offset.Y, imageSize.Width, imageSize.Height);
            }

            // Glyph is auto-scaled when drawn?
            else if (glyph.SizeMode == SizeMode.Auto)
            {
                rect = new Rectangle(rect.X + glyph.Offset.X, rect.Y + glyph.Offset.Y, imageSize.Width, imageSize.Height);
            }

            // Draw with or without source region argument?
            if (glyph.SourceRect.IsEmpty)
            {
                Draw(glyph.Image, rect, glyph.Color);
            }
            else
            {
                Draw(glyph.Image, rect, glyph.SourceRect, glyph.Color);
            }
        }