Example #1
0
    /// <summary>
    /// The constructor of the GUILabelControl class.
    /// </summary>
    /// <param name="dwParentID">The parent of this control.</param>
    /// <param name="dwControlId">The ID of this control.</param>
    /// <param name="dwPosX">The X position of this control.</param>
    /// <param name="dwPosY">The Y position of this control.</param>
    /// <param name="dwWidth">The width of this control.</param>
    /// <param name="dwHeight">The height of this control.</param>
    /// <param name="strFont">The indication of the font of this control.</param>
    /// <param name="strLabel">The text of this control.</param>
    /// <param name="dwTextColor">The color of this control.</param>
    /// <param name="dwTextAlign">The alignment of this control.</param>
    /// <param name="dwTextVAlign">The vertical alignment of this control.</param>
    /// <param name="bHasPath">Indicates if the label is containing a path.</param>
    /// <param name="dwShadowAngle">The angle of the shadow; zero degress along x-axis.</param>
    /// <param name="dwShadowDistance">The distance of the shadow.</param>
    /// <param name="dwShadowColor">The color of the shadow.</param>
    public GUILabelControl(int dwParentID, int dwControlId, int dwPosX, int dwPosY, int dwWidth, int dwHeight,
                           string strFont, string strLabel, long dwTextColor, Alignment dwTextAlign,
                           VAlignment dwTextVAlign, bool bHasPath,
                           int dwShadowAngle, int dwShadowDistance, long dwShadowColor)
      : base(dwParentID, dwControlId, dwPosX, dwPosY, dwWidth, dwHeight)
    {
      _labelText = strLabel;
      _fontName = strFont;
      _textColor = dwTextColor;
      _textAlignment = dwTextAlign;
      _textVAlignment = dwTextVAlign;
      _shadowAngle = dwShadowAngle;
      _shadowDistance = dwShadowDistance;
      _shadowColor = dwShadowColor;

      FinalizeConstruction();
    }
Example #2
0
 /// <summary>
 /// The constructor of the GUIFadeLabel class.
 /// </summary>
 /// <param name="dwParentID">The parent of this control.</param>
 /// <param name="dwControlId">The ID of this control.</param>
 /// <param name="dwPosX">The X position of this control.</param>
 /// <param name="dwPosY">The Y position of this control.</param>
 /// <param name="dwWidth">The width of this control.</param>
 /// <param name="dwHeight">The height of this control.</param>
 /// <param name="strFont">The indication of the font of this control.</param>
 /// <param name="dwTextColor">The color of this control.</param>
 /// <param name="dwTextAlign">The alignment of this control.</param>
 /// <param name="dwTextVAlign">The vertical alignment of this control.</param>
 /// <param name="dwShadowAngle">The angle of the shadow; zero degrees along x-axis.</param>
 /// <param name="dwShadowDistance">The distance of the shadow.</param>
 /// <param name="dwShadowColor">The color of the shadow.</param>
 /// <param name="strUserWrapString">The string used to connect a wrapped fade label.</param>
 public GUIFadeLabel(int dwParentID, int dwControlId, int dwPosX, int dwPosY, int dwWidth, int dwHeight,
                     string strFont, long dwTextColor, Alignment dwTextAlign, VAlignment dwTextVAlign,
                     int dwShadowAngle, int dwShadowDistance, long dwShadowColor,
                     string strUserWrapString)
   : base(dwParentID, dwControlId, dwPosX, dwPosY, dwWidth, dwHeight)
 {
   _fontName = strFont;
   _textColor = dwTextColor;
   _textAlignment = dwTextAlign;
   _textVAlignment = dwTextVAlign;
   _shadowAngle = dwShadowAngle;
   _shadowDistance = dwShadowDistance;
   _shadowColor = dwShadowColor;
   _userWrapString = strUserWrapString;
   FinalizeConstruction();
 }
Example #3
0
        public static void DrawString( Graphics g, string text, Font font, Color color, Rectangle rect, Alignment alignment, VAlignment valignment, TextSplitting textSplitting, Ampersands ampersands )
        {
            if( g == null )
            {
                throw new ArgumentNullException( "g" );
            }
            if( text == null )
            {
                throw new ArgumentNullException( "text" );
            }
            if( font == null )
            {
                throw new ArgumentNullException( "font" );
            }

            if( ampersands == Ampersands.Display )
            {
                text = text.Replace( "&", "&&" );
            }

            float[] txValues = g.Transform.Elements;
            IntPtr hClipRgn = g.Clip.GetHrgn( g );
            IntPtr hDC = g.GetHdc();

            Gdi.SelectClipRgn( hDC, hClipRgn );

            int oldGraphicsMode = Gdi.SetGraphicsMode( hDC, 2 );
            XFORM oldXForm = new XFORM();

            Gdi.GetWorldTransform( hDC, ref oldXForm );

            XFORM newXForm = new XFORM();

            newXForm.eM11 = txValues[0];
            newXForm.eM12 = txValues[1];
            newXForm.eM21 = txValues[2];
            newXForm.eM22 = txValues[3];
            newXForm.eDx = txValues[4];
            newXForm.eDy = txValues[5];

            Gdi.SetWorldTransform( hDC, ref newXForm );

            try
            {
                IntPtr hFont = font.ToHfont();
                IntPtr hOldFont = Gdi.SelectObject( hDC, hFont );

                try
                {
                    BinaryComponents.Utility.Win32.Common.RECT r = new BinaryComponents.Utility.Win32.Common.RECT( rect );
                    User.DrawTextFlags uFormat;

                    switch( textSplitting )
                    {
                        case TextSplitting.SingleLineEllipsis:
                            uFormat
                                    = User.DrawTextFlags.DT_WORD_ELLIPSIS
                                        | User.DrawTextFlags.DT_END_ELLIPSIS;
                            break;
                        case TextSplitting.MultiLine:
                            uFormat
                                    = User.DrawTextFlags.DT_WORDBREAK;
                            break;
                        default:
                            throw new InvalidOperationException();
                    }

                    switch( alignment )
                    {
                        case Alignment.Left:
                            break;
                        case Alignment.Center:
                            uFormat
                                    = User.DrawTextFlags.DT_CENTER;
                            break;
                        case Alignment.Right:
                            uFormat
                                    = User.DrawTextFlags.DT_RIGHT;
                            break;
                        default:
                            throw new InvalidOperationException();
                    }
                    switch( valignment )
                    {
                        case VAlignment.Top:
                            break;
                        case VAlignment.Bottom:
                            uFormat |= User.DrawTextFlags.DT_BOTTOM | User.DrawTextFlags.DT_SINGLELINE;
                            break;
                        case VAlignment.Center:
                            uFormat |= User.DrawTextFlags.DT_VCENTER | User.DrawTextFlags.DT_SINGLELINE;
                            break;
                    }

                    uint bgr = (uint)((color.B << 16) | (color.G << 8) | (color.R));
                    uint oldColor = Gdi.SetTextColor( hDC, bgr );

                    try
                    {
                        BackgroundMode oldBackgroundMode = Gdi.SetBkMode( hDC, BackgroundMode.TRANSPARENT );

                        try
                        {
                            User.DrawText( hDC, text, text.Length, ref r, uFormat );
                        }
                        finally
                        {
                            Gdi.SetBkMode( hDC, oldBackgroundMode );
                        }
                    }
                    finally
                    {
                        Gdi.SetTextColor( hDC, oldColor );
                    }
                }
                finally
                {
                    Gdi.SelectObject( hDC, hOldFont );
                    Gdi.DeleteObject( hFont );
                }
            }
            finally
            {
                if( oldGraphicsMode == 1 )
                {
                    oldXForm.eM11 = 1;
                    oldXForm.eM12 = 0;
                    oldXForm.eM21 = 0;
                    oldXForm.eM22 = 1;
                    oldXForm.eDx = 0;
                    oldXForm.eDx = 0;
                }

                Gdi.SetWorldTransform( hDC, ref oldXForm );
                Gdi.SetGraphicsMode( hDC, oldGraphicsMode );

                g.ReleaseHdc( hDC );

                if( hClipRgn != IntPtr.Zero )
                {
                    g.Clip.ReleaseHrgn( hClipRgn );
                }
            }
        }
Example #4
0
 public abstract void DrawText(string text, TextType font, Vector2D pt, HAlignment hAlignment, VAlignment vAlignment, float fAngle);
Example #5
0
File: Box.cs Project: jpx/blazera
        public void AddItem(List<Widget> widgets, UInt32 level = DEFAULT_ITEM_LEVEL, VAlignment vAlignement = DEFAULT_VALIGNMENT)
        {
            foreach (Widget widget in widgets)
            {
                base.AddWidget(widget);

                Levels.Add(widget, level);

                VAlignments.Add(widget, vAlignement);
            }
        }
Example #6
0
File: Box.cs Project: jpx/blazera
        public void AddItemFirst(Widget widget, UInt32 level = DEFAULT_ITEM_LEVEL, VAlignment vAlignement = DEFAULT_VALIGNMENT)
        {
            base.AddFirst(widget);

            Levels.Add(widget, level);

            VAlignments.Add(widget, vAlignement);
        }
Example #7
0
        public override void DrawText(string text, TextType font, Vector2D pt, HAlignment hAlignment, VAlignment vAlignment, float fAngle)
        {
            int alignment = 0;
            switch (hAlignment)
            {
                case HAlignment.VA_CENTER: alignment = PdfContentByte.ALIGN_CENTER; break;
                case HAlignment.VA_LEFT:   alignment = PdfContentByte.ALIGN_LEFT;   break;
                case HAlignment.VA_RIGHT:  alignment = PdfContentByte.ALIGN_RIGHT;  break;
                default: break;
            }

            float fontSize = FontSize(font);
            float fontRise = 0.0f;
            switch (vAlignment)
            {
                case VAlignment.VA_BOTTOM: fontRise =0.5f; break;
                case VAlignment.VA_MIDDLE: fontRise = 0.0f * fontSize; break;
                case VAlignment.VA_TOP: fontRise = -0.5f * fontSize; break;
                default: break;
            }

            _cb.BeginText();
            BaseFont bf = ToBaseFont(font);
            _cb.SetTextRise(fontRise);
            _cb.SetTextMatrix(1.0f, 0.0f, 0.0f, 1.0f, DX(pt.X), DY(pt.Y) - 1.0f * (bf.GetAscentPoint(text, fontSize) - bf.GetDescentPoint(text, fontSize)) * 25.4f/72.0f);
            _cb.ShowTextAligned(alignment, text, DX(pt.X), DY(pt.Y) - 1.0f * (bf.GetAscentPoint(text, fontSize) - bf.GetDescentPoint(text, fontSize)) * 25.4f / 72.0f, 0.0f);
            _cb.EndText();
        }
Example #8
0
 public override void DrawText(string text, TextType font, Vector2D pt, HAlignment hAlignment, VAlignment vAlignment, float fAngle)
 {
     XStringFormat format = new XStringFormat();
     switch (hAlignment)
     {
         case HAlignment.HA_CENTER: format.Alignment = XStringAlignment.Center; break;
         case HAlignment.HA_LEFT: format.Alignment = XStringAlignment.Near; break;
         case HAlignment.HA_RIGHT: format.Alignment = XStringAlignment.Far; break;
         default: break;
     }
     switch (vAlignment)
     {
         case VAlignment.VA_BOTTOM: format.LineAlignment = XLineAlignment.Far; break;
         case VAlignment.VA_MIDDLE: format.LineAlignment = XLineAlignment.Center; break;
         case VAlignment.VA_TOP: format.LineAlignment = XLineAlignment.Near; break;
         default: break;
     }
     this.pdfGfx.DrawString(
         text
         , ToFont(font)
         , LineTypeToPdfBrush(PicGraphics.LT.LT_COTATION)
         , new XPoint(DX(pt.X), DY(pt.Y))
         , format);
 }
Example #9
0
        public BitmapText(IBitmapFont bitmapFont, IBrush brush, string text, TexcoordGenerationMode uMappingMode = TexcoordGenerationMode.FullBoundingBox, TexcoordGenerationMode vMappingMode = TexcoordGenerationMode.FullBoundingBox, HAlignment hAlignment = HAlignment.Middle, VAlignment vAlignment = VAlignment.Middle)
        {
            Transform = (ConstantMatrix) Matrix.Identity;
            Rectangle fullRect = bitmapFont.Measure(text);

            Vector3 centerOffset = Vector3.Zero;
            switch (hAlignment)
            {
                case HAlignment.Left:
                    centerOffset.X = 0;
                    break;

                case HAlignment.Middle:
                    centerOffset.X = fullRect.Width / 2f;
                    break;

                case HAlignment.Right:
                    centerOffset.X = fullRect.Width;
                    break;
            }

            switch (vAlignment)
            {
                case VAlignment.Top:
                    centerOffset.Y = 0;
                    break;

                case VAlignment.Middle:
                    centerOffset.Y = fullRect.Height / 2f;
                    break;

                case VAlignment.Bottom:
                    centerOffset.Y = fullRect.Height;

                    break;
            }

            _bitmapFont = bitmapFont as BitmapFont;
            var pageCount = _bitmapFont.PageLayers.Count;
            _text = text;
            Brush = brush;

            _textQuads = new IIndexedMesh[pageCount];

            var charactersByPage = (from char ch in text
                                   select new KeyValuePair<int, char>(_bitmapFont.Chars[ch].Page, ch)).ToMultiValueDictionary();

            var w = (float)_bitmapFont.ScaleW;
            var h = (float)_bitmapFont.ScaleH;
            var xPos = 0f;

            foreach (var kvp in charactersByPage)
            {
                var charCount = kvp.Value.Count;
                _textQuads[kvp.Key] = new IndexedMesh(charCount * 4, charCount * 6)
                                          {
                                              Brush = new TextBrush { TextLayer = _bitmapFont.PageLayers[kvp.Key], SubBrush = Brush }
                                          };
            }

            var vertexIndexCounts = (from i in Enumerable.Range(0, _bitmapFont.Pages.Count)
                                    select Tuple.Create(0, 0)).ToArray();

            foreach (var ch in text)
            {
                var ci = _bitmapFont.Chars[ch];

                var vertices = _textQuads[ci.Page].Vertices;
                var indices = _textQuads[ci.Page].Indices;

                var vertexCount = vertexIndexCounts[ci.Page].Item1;
                var indexCount = vertexIndexCounts[ci.Page].Item2;

                var saveVertexCount = vertexCount;

                Vector2 quadTopLeft;
                Vector2 quadTopRight;
                Vector2 quadBottomRight;
                Vector2 quadBottomLeft;

                var left = xPos + ci.XOffset;
                var top = 0f + ci.YOffset;

                switch (uMappingMode)
                {
                    case TexcoordGenerationMode.PerQuad:
                        quadTopLeft.X = 0f;
                        quadTopRight.X = 1f;
                        quadBottomRight.X = 1f;
                        quadBottomLeft.X = 0f;

                        break;

                    // These two modes are the same in this case
                    case TexcoordGenerationMode.FullBoundingBox:
                    case TexcoordGenerationMode.Unwrapped_Linear:
                        quadTopLeft.X = left / fullRect.Width;
                        quadTopRight.X = (left + ci.Width) / fullRect.Width;
                        quadBottomRight.X = (left + ci.Width) / fullRect.Width;
                        quadBottomLeft.X = left / fullRect.Width;

                        break;

                    default:
                        throw new NotSupportedException(string.Format("Unsupported texture mapping mode along X-Axis: {0}", uMappingMode));
                }

                switch (vMappingMode)
                {
                    case TexcoordGenerationMode.PerQuad:
                        quadTopLeft.Y = 0f;
                        quadTopRight.Y = 0f;
                        quadBottomRight.Y = 1f;
                        quadBottomLeft.Y = 1f;

                        break;

                    // These two modes are the same in this case
                    case TexcoordGenerationMode.FullBoundingBox:
                    case TexcoordGenerationMode.Unwrapped_Linear:
                        quadTopLeft.Y = top / fullRect.Height;
                        quadTopRight.Y = top / fullRect.Height;
                        quadBottomRight.Y = (top + ci.Height) / fullRect.Height;
                        quadBottomLeft.Y = (top + ci.Height) / fullRect.Height;

                        break;

                    default:
                        throw new NotSupportedException(string.Format("Unsupported texture mapping mode along Y-Axis: {0}", vMappingMode));
                }

                var topLeft = new Texcoords(quadTopLeft, new Vector2(ci.X / w, ci.Y / h));
                var topRight = new Texcoords(quadTopRight, new Vector2(((ci.X + ci.Width) / w), ci.Y / h));
                var bottomRight = new Texcoords(quadBottomRight, new Vector2(((ci.X + ci.Width) / w), ((ci.Y + ci.Height) / h)));
                var bottomLeft = new Texcoords(quadBottomLeft, new Vector2(ci.X / w, ((ci.Y + ci.Height) / h)));

                vertices[vertexCount++] = new Vertex
                {
                    Position = new Vector3(left - centerOffset.X, top - centerOffset.Y, 0f),
                    Texcoords = topLeft,
                    Color = Color.White
                };

                vertices[vertexCount++] = new Vertex
                {
                    Position = new Vector3(left + ci.Width - centerOffset.X, top - centerOffset.Y, 0f),
                    Texcoords = topRight,
                    Color = Color.White
                };

                vertices[vertexCount++] = new Vertex
                {
                    Position = new Vector3(left + ci.Width - centerOffset.X, top + ci.Height - centerOffset.Y, 0f),
                    Texcoords = bottomRight,
                    Color = Color.White
                };

                vertices[vertexCount++] = new Vertex
                {
                    Position = new Vector3(left - centerOffset.X, top + ci.Height - centerOffset.Y, 0f),
                    Texcoords = bottomLeft,
                    Color = Color.White
                };

                xPos += ci.XAdvance;

                indices[indexCount++] = (short)(saveVertexCount + 0);
                indices[indexCount++] = (short)(saveVertexCount + 1);
                indices[indexCount++] = (short)(saveVertexCount + 2);
                indices[indexCount++] = (short)(saveVertexCount + 0);
                indices[indexCount++] = (short)(saveVertexCount + 2);
                indices[indexCount++] = (short)(saveVertexCount + 3);

                vertexIndexCounts[ci.Page] = Tuple.Create(vertexCount, indexCount);
            }
        }
Example #10
0
 public static IBitmapText Build(this IBitmapFont font, string text, IBrush brush, TexcoordGenerationMode uMappingMode = TexcoordGenerationMode.FullBoundingBox, TexcoordGenerationMode vMappingMode = TexcoordGenerationMode.FullBoundingBox, HAlignment hAlignment = HAlignment.Middle, VAlignment vAlignment = VAlignment.Middle)
 {
     return new BitmapText(font as BitmapFont, brush, text, uMappingMode, vMappingMode, hAlignment, vAlignment);
 }
Example #11
0
        public override void DrawText(string text, TextType font, Vector2D pt, HAlignment hAlignment, VAlignment vAlignment, float fAngle)
        {
            // string format
            StringFormat sf = new StringFormat();
            switch (hAlignment)
            {
                case HAlignment.HA_RIGHT:
                    sf.LineAlignment = StringAlignment.Far;
                    break;
                case HAlignment.HA_CENTER:
                    sf.LineAlignment = StringAlignment.Center;
                    break;
                case HAlignment.HA_LEFT:
                    sf.LineAlignment = StringAlignment.Near;
                    break;
                default:
                    throw new Exception("Unknown horizontal alignment");
            }
            switch (vAlignment)
            { 
                case VAlignment.VA_BOTTOM:
                    sf.Alignment = StringAlignment.Far;
                    break;
                case VAlignment.VA_MIDDLE:
                    sf.Alignment = StringAlignment.Center;
                    break;
                case VAlignment.VA_TOP:
                    sf.Alignment = StringAlignment.Near;
                    break;
                default:
                    throw new Exception("Unknown vertical alignment");
            }
            // font & brush
            Brush tb;
            switch (font)
            { 
                case TextType.FT_COTATION:
                    tb = new SolidBrush(System.Drawing.Color.FromArgb(0,140,0));
                    break;
                default:
                    throw new Exception("Unknown text type");
            }

            _gdiGraphics.TranslateTransform(ToPointF(pt).X, ToPointF(pt).Y);
            _gdiGraphics.RotateTransform(fAngle); 
            
            // draw text
            _gdiGraphics.DrawString(text, ToFont(font), tb, new PointF(0, 0), sf);

            _gdiGraphics.ResetTransform();
         }