Esempio n. 1
0
 /// <summary>Set the font</summary>
 public void SetFont(uint font, Color4 defaultFontColor, DrawTextFormat format)
 {
     // Store data
     FontIndex  = font;
     textFormat = format | DrawTextFormat.ExpandTabs | DrawTextFormat.WordBreak;
     FontColor.Initialize(defaultFontColor);
 }
Esempio n. 2
0
        /// <summary>
        /// Draws the specified text using the Direct3D font object.
        /// </summary>
        /// <param name="text">Text to draw.</param>
        /// <param name="rect">Rectangle to draw the text in.</param>
        public void DrawText(string text, Rectangle rect)
        {
            Sprite         sprite = null;
            DrawTextFormat format = DrawTextFormat.Top | DrawTextFormat.Left | DrawTextFormat.WordBreak;

            RenderText(sprite, text, rect, format);
        }
        private List <string> GetFormattedDescription(string rawDescription)
        {
            string[]       lines            = rawDescription.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
            List <string>  descriptionLines = new List <string>();
            string         text             = "WWWWWWWWWWWWWWWWWWWWWWWW ";
            Font           font             = FontManager.GetFont("Main 10");
            DrawTextFormat dtf   = DrawTextFormat.ExpandTabs | DrawTextFormat.WordBreak | DrawTextFormat.Left | DrawTextFormat.Top;
            Rectangle      area  = font.MeasureString(UI.CurrentHud.SpriteManager, text, dtf, Color.White);
            int            width = area.Width;

            foreach (string line in lines)
            {
                string[] words    = line.Split(' ');
                string   linetext = "";
                for (int i = 0; i < words.Length; i++)
                {
                    string addword = words[i] + (i == words.Length - 1 ? "" : " ");
                    if ((linetext + addword).Length > 25)
                    {
                        Rectangle a = font.MeasureString(UI.CurrentHud.SpriteManager, linetext + addword, dtf, Color.White);
                        if (a.Width > width)
                        {   //Wrap
                            descriptionLines.Add(linetext);
                            linetext = "";
                        }
                    }
                    linetext += addword;
                }
                descriptionLines.Add(linetext);
            }

            return(descriptionLines);
        }
Esempio n. 4
0
 /// <summary>Set the font</summary>
 public void SetFont(uint font, ColorValue defaultFontColor, DrawTextFormat format)
 {
     // Store data
     FontIndex  = font;
     textFormat = format;
     FontColor.Initialize(defaultFontColor);
 }
Esempio n. 5
0
        public Vec2 MeasureString(string text, int height, DrawTextFormat format)
        {
            SlimDX.Direct3D9.Font font      = this.GetFont(height);
            Rectangle             rectangle = font.MeasureString(this.textSprite, text, format);

            return(new Vec2(rectangle.Width, rectangle.Height));
        }
Esempio n. 6
0
 public static StringFormat ToStringFormat(this DrawTextFormat format)
 {
     return(new StringFormat()
     {
         Alignment = (System.Drawing.StringAlignment)format.Alignment,
         LineAlignment = (System.Drawing.StringAlignment)format.LineAlignment,
         FormatFlags = System.Drawing.StringFormatFlags.DirectionRightToLeft
     });
 }
Esempio n. 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="text"></param>
        /// <param name="position"></param>
        /// <param name="color"></param>
        public void Draw(string text, BomberStuff.Core.Drawing.PointF position, System.Drawing.Color color)
        {
            int            x      = (int)(position.X * Form.ClientSize.Width);
            int            y      = (int)(position.Y * Form.ClientSize.Height);
            Rectangle      rect   = new Rectangle(x - 1, y - 1, 2, 2);
            DrawTextFormat format = DrawTextFormat.Center | DrawTextFormat.VerticalCenter | DrawTextFormat.NoClip;

            d3dFont.DrawString(Sprite, text, rect, format, color);
        }
Esempio n. 8
0
 public Vec2 AddTextWithHeight(Vec2 pos, string text, Color color, int height, DrawTextFormat format)
 {
     SlimDX.Direct3D9.Font font = this.GetFont(height);
     Rectangle rectangle = font.MeasureString(this.textSprite, text, format);
     rectangle.X += pos.X;
     rectangle.Y += pos.Y;
     font.DrawString(this.textSprite, text, rectangle, format, color);
     return new Vec2(rectangle.Width, rectangle.Height);
 }
Esempio n. 9
0
        /// <summary>
        /// 渲染标签
        /// </summary>
        /// <param name="drawArgs">绘制参数</param>
        /// <param name="x">标签X位置</param>
        /// <param name="y">标签Y位置</param>
        /// <param name="buttonHeight">按钮高度</param>
        /// <param name="selected">是否被选中</param>
        /// <param name="anchor">菜单位置</param>
        public void RenderLabel(DrawArgs drawArgs, int x, int y, int buttonHeight, bool selected, MenuAnchor anchor)
        {
            if (selected)
            {
                if (buttonHeight == curSize)
                {
                    alpha += alphaStep;
                    if (alpha > 255)
                    {
                        alpha = 255;
                    }
                }
            }
            else
            {
                alpha -= alphaStep;
                if (alpha < 0)
                {
                    alpha = 0;
                    return;
                }
            }

            int halfWidth = (int)(SelectedSize * 0.75);
            int label_x   = x - halfWidth + 1;
            int label_y   = (int)(y + SelectedSize) + 1;

            DrawTextFormat format = DrawTextFormat.NoClip | DrawTextFormat.Center | DrawTextFormat.WordBreak;

            if (anchor == MenuAnchor.Bottom)
            {
                format |= DrawTextFormat.Bottom;
                label_y = y - 202;
            }

            Rectangle rect = new System.Drawing.Rectangle(label_x, label_y, (int)halfWidth * 2, 200);

            if (rect.Right > drawArgs.ScreenWidth)
            {
                rect = Rectangle.FromLTRB(rect.Left, rect.Top, drawArgs.ScreenWidth, rect.Bottom);
            }

            drawArgs.ToolbarFont.DrawText(null, Description, rect, format, black & 0xffffff + (alpha << 24));

            rect.Offset(2, 0);
            drawArgs.ToolbarFont.DrawText(null, Description, rect, format, black & 0xffffff + (alpha << 24));

            rect.Offset(0, 2);
            drawArgs.ToolbarFont.DrawText(null, Description, rect, format, black & 0xffffff + (alpha << 24));

            rect.Offset(-2, 0);
            drawArgs.ToolbarFont.DrawText(null, Description, rect, format, black & 0xffffff + (alpha << 24));

            rect.Offset(1, -1);
            drawArgs.ToolbarFont.DrawText(null, Description, rect, format, white & 0xffffff + (alpha << 24));
        }
Esempio n. 10
0
        /// <summary>
        /// Draw a line of text
        /// </summary>
        public void DrawTextLine(string text, DrawTextFormat flags)
        {
            if (textFont == null)
            {
                throw new InvalidOperationException("You cannot draw text.  There is no font object.");
            }
            // Create the rectangle to draw to
            Rectangle rect = new Rectangle(point, size);

            textFont.DrawText(UI.CurrentHud.SpriteManager, text, rect, flags, color);

            // Increase the line height
            point.Y += lineHeight;
        }
Esempio n. 11
0
        public void Render(DrawArgs drawArgs)
        {
            if (m_Visible)
            {
                if (m_localFont != null && m_drawingFont == null)
                {
                    m_drawingFont = new Font(drawArgs.device, m_localFont);
                }

                DrawTextFormat drawTextFormat = (WordBreak ? DrawTextFormat.WordBreak : DrawTextFormat.SingleLine);

                switch (this.Alignment)
                {
                case Alignment.Left:
                    drawTextFormat |= DrawTextFormat.Left;
                    break;

                case Alignment.Center:
                    drawTextFormat |= DrawTextFormat.Center;
                    break;

                case Alignment.Right:
                    drawTextFormat |= DrawTextFormat.Right;
                    break;
                }

                if (m_drawingFont == null)
                {
                    drawArgs.defaultDrawingFont.DrawText(
                        null,
                        m_Text,
                        new System.Drawing.Rectangle(AbsoluteLocation.X, AbsoluteLocation.Y, m_Size.Width, m_Size.Height),
                        drawTextFormat,
                        m_ForeColor);
                }
                else
                {
                    m_drawingFont.DrawText(
                        null,
                        m_Text,
                        new System.Drawing.Rectangle(AbsoluteLocation.X, AbsoluteLocation.Y, m_Size.Width, m_Size.Height),
                        drawTextFormat,
                        m_ForeColor);
                }
            }
        }
Esempio n. 12
0
        //****************************************************************
        // Painting - Methods for painting a PText.
        //****************************************************************

        /// <summary>
        /// Overridden.  See <see cref="PNode.Paint">PNode.Paint</see>.
        /// </summary>
        protected override void Paint(UMD.HCIL.Piccolo.Util.PPaintContext paintContext)
        {
            base.Paint(paintContext);
            Device device = (paintContext as P3PaintContext).Device;

            PMatrix currMatrix = (paintContext as P3PaintContext).Transform;

            // Scale the matrix down to display font units
            float scale = displayFontSize / font.Size;

            currMatrix.ScaleBy(scale, X, Y);

            float[] piccoloMatrixElements = currMatrix.Elements;
            if (!currMatrix.IsIdentity)
            {
                Matrix m = new Matrix();
                m.M11 = piccoloMatrixElements[0];
                m.M12 = piccoloMatrixElements[1];
                m.M21 = piccoloMatrixElements[2];
                m.M22 = piccoloMatrixElements[3];
                m.M41 = piccoloMatrixElements[4];
                m.M42 = piccoloMatrixElements[5];
                m.M33 = 1;
                m.M44 = 1;
                textSprite.Transform = m;
            }

            textSprite.Begin(SpriteFlags.None);
            DrawTextFormat D3DAlignment = P3Util.GetD3DAlignment(stringFormat.Alignment);

            // Calculate the rectangle with no padding, in actual font units
            scale = 1 / scale;
            int totHzPadding = currLeftPadding + currRightPadding;
            int totVtPadding = currTopPadding + currBottomPadding;

            Rectangle dstRect = new Rectangle((int)(Bounds.X + currLeftPadding * scale), (int)(Bounds.Y + currTopPadding * scale),
                                              (int)((Bounds.Width - totHzPadding) * scale), (int)((Bounds.Height - totVtPadding) * scale));

            // Wrap the string ourselves, instead of letting the draw method do it, since we want to make
            // sure it's consistent with our own MeasureString method.
            String str = P3Util.WrapString(textSprite, D3Dfont, Text, dstRect.Width, (TextBrush as SolidBrush).Color);

            D3Dfont.DrawText(textSprite, str, dstRect, D3DAlignment, (TextBrush as SolidBrush).Color);
            textSprite.End();
        }
Esempio n. 13
0
        public TextStyle(bool bold, bool italic, bool isShadowed, Color standardColor,
                         Color highlightedColor, int size, string fontName, Alignment horizontalAlignment,
                         Alignment verticalAlignment)
        {
            this.bold                = bold;
            this.italic              = italic;
            this.isShadowed          = isShadowed;
            ignoreBounds             = false;
            applyHighlight           = (standardColor != highlightedColor) ? true : false;
            this.standardColor       = standardColor;
            this.highlightedColor    = highlightedColor;
            this.size                = size;
            this.fontName            = fontName;
            this.horizontalAlignment = horizontalAlignment;
            this.verticalAlignment   = verticalAlignment;

            flags = BuildFlags(this);
        }
Esempio n. 14
0
        private int m_SpaceWidth;               //空格的宽度

        public TextBuffer(NRenderFont font)
        {
            m_Text = "";
            m_Font = font;
            if (m_Font == null)
            {
                throw new Exception("Must have a font usable.");
            }
            m_IsAnalyseRequired = true;
            m_StartOffset       = 0;
            m_CaretPos          = new List <int>();

            DrawTextFormat textFormt = DrawTextFormat.Left | DrawTextFormat.Top | DrawTextFormat.NoClip | DrawTextFormat.SingleLine;
            Rect           rc1       = m_Font.MeasureString("w w", textFormt);
            Rect           rc2       = m_Font.MeasureString("ww", textFormt);

            m_SpaceWidth = (int)(rc1.Width - rc2.Width);
        }
Esempio n. 15
0
        public TextStyle(string styleInfo)
        {
            bold           = false;
            italic         = false;
            isShadowed     = false;
            applyHighlight = false;
            ignoreBounds   = false;

            standardColor       = Color.White;
            highlightedColor    = Color.LightBlue;
            size                = StyleManager.GetLabelSize(LabelSize.Large);
            fontName            = FontManager.DefaultFontName;
            horizontalAlignment = Alignment.Left;
            verticalAlignment   = Alignment.Top;

            ParseMarkup(styleInfo);
            flags = BuildFlags(this);
        }
Esempio n. 16
0
        public static DrawTextFormat BuildFlags(TextStyle style)
        {
            DrawTextFormat flags;

            if (style.IgnoreBounds)
            {
                flags = DrawTextFormat.NoClip;
            }
            else
            {
                flags = DrawTextFormat.ExpandTabs | DrawTextFormat.WordBreak;
            }

            switch (style.HorizontalAlignment)
            {
            case Alignment.Left:
                flags |= DrawTextFormat.Left;
                break;

            case Alignment.Right:
                flags |= DrawTextFormat.Right;
                break;

            case Alignment.Center:
                flags |= DrawTextFormat.Center;
                break;
            }

            switch (style.VerticalAlignment)
            {
            case Alignment.Top:
                flags |= DrawTextFormat.Top;
                break;

            case Alignment.Center:
                flags |= DrawTextFormat.VerticalCenter;
                break;

            case Alignment.Bottom:
                flags |= DrawTextFormat.Bottom;
                break;
            }
            return(flags);
        }
Esempio n. 17
0
        /// <summary>
        /// Converts a <see cref="System.Drawing.StringAlignment">
        /// System.Drawing.StringAlignment</see> to the Direct3D equivalent.
        /// </summary>
        /// <param name="alignment">
        /// A <see cref="System.Drawing.StringAlignment">StringAlignment</see>.
        /// </param>
        /// <returns>
        /// A <see cref="Microsoft.DirectX.Direct3D.DrawTextFormat">
        /// Microsoft.DirectX.Direct3D.DrawTextFormat</see> that represents the
        /// specified <see cref="System.Drawing.StringAlignment">StringAlignment</see>.
        /// </returns>
        public static DrawTextFormat GetD3DAlignment(StringAlignment alignment)
        {
            DrawTextFormat D3DAlignment = DrawTextFormat.Left;

            switch (alignment)
            {
            case StringAlignment.Center:
                D3DAlignment = DrawTextFormat.Center;
                break;

            case StringAlignment.Far:
                D3DAlignment = DrawTextFormat.Right;
                break;

            case StringAlignment.Near:
                D3DAlignment = DrawTextFormat.Left;
                break;
            }
            return(D3DAlignment);
        }
        /// <summary>
        /// Cambiar TextAlign y configurar DrawTextFormat
        /// </summary>
        private void changeTextAlign(TextAlign align)
        {
            this.align = align;
            DrawTextFormat fAlign = DrawTextFormat.None;

            switch (align)
            {
            case TextAlign.LEFT:
                fAlign = DrawTextFormat.Left;
                break;

            case TextAlign.RIGHT:
                fAlign = DrawTextFormat.Right;
                break;

            case TextAlign.CENTER:
                fAlign = DrawTextFormat.Center;
                break;
            }
            format = DrawTextFormat.NoClip | DrawTextFormat.ExpandTabs | DrawTextFormat.WordBreak | fAlign;
        }
Esempio n. 19
0
        public Vec2 AddTextWithHeightAndOutline(Vec2 pos, string text, Color color, Color outLine, int height, DrawTextFormat format, int outlineOsset = 1)
        {
            SlimDX.Direct3D9.Font font = this.GetFont(height);
            Rectangle rectangle = font.MeasureString(this.textSprite, text, format);
            rectangle.X += pos.X;
            rectangle.Y += pos.Y;

            rectangle.X -= 1 * outlineOsset;
            rectangle.Y -= 1 * outlineOsset;
            font.DrawString(this.textSprite, text, rectangle, format, outLine);
            rectangle.Y += 2 * outlineOsset;
            font.DrawString(this.textSprite, text, rectangle, format, outLine);
            rectangle.X += 2 * outlineOsset;
            font.DrawString(this.textSprite, text, rectangle, format, outLine);
            rectangle.Y -= 2 * outlineOsset;
            font.DrawString(this.textSprite, text, rectangle, format, outLine);

            rectangle.X -= 1 * outlineOsset;
            rectangle.Y += 1 * outlineOsset;
            font.DrawString(this.textSprite, text, rectangle, format, color);
            return new Vec2(rectangle.Width, rectangle.Height);
        }
Esempio n. 20
0
        //解析字符
        private bool Analyse()
        {
            m_CaretPos.Clear();
            Rect rc = new Rect();

            m_CaretPos.Add(m_StartOffset);
            DrawTextFormat textFormt = DrawTextFormat.Left | DrawTextFormat.Top | DrawTextFormat.NoClip | DrawTextFormat.SingleLine;

            for (int i = 1; i <= m_Text.Length; ++i)
            {
                String text = "";
                text += m_Text[i - 1];
                if (text[0] == ' ')
                {
                    m_CaretPos.Add(m_CaretPos[i - 1] + m_SpaceWidth);
                    continue;
                }
                m_Font.MeasureString(text, textFormt, ref rc);
                m_CaretPos.Add(m_CaretPos[i - 1] + (int)rc.Width);
            }
            m_IsAnalyseRequired = false;
            return(true);
        }
Esempio n. 21
0
        /// <summary>
        /// Helper function to render icon description.  Broken out so that child classes can override this behavior.
        /// </summary>
        /// <param name="drawArgs"></param>
        protected override void RenderDescription(DrawArgs drawArgs, Sprite sprite, Vector3 projectedPoint, int color)
        {
            string description = GeneralInfo() + DetailedInfo() + DescriptionInfo();

            if (description != null)
            {
                // Render description field
                DrawTextFormat format = DrawTextFormat.NoClip | DrawTextFormat.WordBreak | DrawTextFormat.Bottom;
                int            left   = 10;
                if (World.Settings.ShowLayerManager)
                {
                    left += World.Settings.LayerManagerWidth;
                }
                Rectangle rect = Rectangle.FromLTRB(left, 10, drawArgs.screenWidth - 10, drawArgs.screenHeight - 10);

                // Draw description
                rect.Offset(1, -1);
                drawArgs.defaultDrawingFont.DrawText(
                    sprite, description,
                    rect,
                    format, descriptionColor);
            }
        }
Esempio n. 22
0
        protected override void Dispose(bool Disposing)
        {
            if (Disposing)
            {
                AutoSizeChanged = null;
                _AutoSize       = false;

                DrawFormatChanged = null;
                _DrawFormat       = DrawTextFormat.None;

                FontChanged = null;

                if (_Font != null)
                {
                    _Font.Dispose();
                }
                _Font = null;

                if (DXFont != null && !DXFont.Disposed)
                {
                    DXFont.Dispose();
                }
                DXFont = null;

                OutLineChanged = null;
                _OutLine       = false;

                OutLineColorChanged = null;
                _OutLineColor       = Color.Empty;

                TextChanged = null;
                Text        = null;
            }

            base.Dispose(Disposing);
        }
Esempio n. 23
0
        protected void RenderPositionInfo(DrawArgs drawArgs)
        {
            // Render some Development information to screen
            string captionText = "";

            captionText += String.Format("纬度: {0}\n经度: {1}\n海拔高度:{2}",
                                         drawArgs.WorldCamera.Latitude,
                                         drawArgs.WorldCamera.Longitude,
                                         drawArgs.WorldCamera.Altitude) +
                           "\n" +
                           drawArgs.WorldCamera;



            captionText = captionText.Trim();
            DrawTextFormat dtf      = DrawTextFormat.NoClip | DrawTextFormat.WordBreak | DrawTextFormat.Right | DrawTextFormat.Top;
            int            x        = 7;
            int            y        = 7;
            Rectangle      textRect = Rectangle.FromLTRB(x, y, drawArgs.device.Viewport.Width - 8, drawArgs.device.Viewport.Height - 8);

            DrawArgs.Instance.DrawText(null, captionText, textRect, dtf, Color.Gray.ToArgb());
            textRect.Offset(-1, -1);
            DrawArgs.Instance.DrawText(null, captionText, textRect, dtf, Color.White.ToArgb());
        }
Esempio n. 24
0
        public Vec2 AddTextWithHeightAndOutline(Vec2 pos, string text, Color color, Color outLine, int height, DrawTextFormat format, int outlineOsset = 1)
        {
            SlimDX.Direct3D9.Font font      = this.GetFont(height);
            Rectangle             rectangle = font.MeasureString(this.textSprite, text, format);

            rectangle.X += pos.X;
            rectangle.Y += pos.Y;

            rectangle.X -= 1 * outlineOsset;
            rectangle.Y -= 1 * outlineOsset;
            font.DrawString(this.textSprite, text, rectangle, format, outLine);
            rectangle.Y += 2 * outlineOsset;
            font.DrawString(this.textSprite, text, rectangle, format, outLine);
            rectangle.X += 2 * outlineOsset;
            font.DrawString(this.textSprite, text, rectangle, format, outLine);
            rectangle.Y -= 2 * outlineOsset;
            font.DrawString(this.textSprite, text, rectangle, format, outLine);

            rectangle.X -= 1 * outlineOsset;
            rectangle.Y += 1 * outlineOsset;
            font.DrawString(this.textSprite, text, rectangle, format, color);
            return(new Vec2(rectangle.Width, rectangle.Height));
        }
Esempio n. 25
0
        public void Render(IDXLayerIO ForPin, Device OnDevice)
        {
            //concerning the cut characters in some fonts, especially when rendered italic see:
            //http://www.gamedev.net/community/forums/topic.asp?topic_id=441338
            //seems to be an official bug and we'd need to write our very own font rendering to fix that

            if (!FEnabledInput[0])
            {
                return;
            }

            //from the docs: D3DXSPRITE_OBJECTSPACE -> The world, view, and projection transforms are not modified.
            //for view and projection transforms this is exactly what we want: it allows placing the text within the
            //same world as all the other objects. however we don't want to work in object space but in world space
            //that's why we need to to set the world transform to a neutral value: identity
            OnDevice.SetTransform(TransformState.World, Matrix.Identity);
            FTransformIn.SetRenderSpace();

            //set states that are defined via upstream nodes
            FRenderStatePin.SetSliceStates(0);

            DeviceHelpers dh = FDeviceHelpers[OnDevice];

            dh.Sprite.Begin(SpriteFlags.ObjectSpace | SpriteFlags.DoNotAddRefTexture);
            try
            {
                int normalize = FNormalizeInput[0].Index;

                Matrix    preScale = Matrix.Scaling(1, -1, 1);
                Matrix    world;
                string    text;
                Rectangle tmpRect = new Rectangle(0, 0, 0, 0);
                int       hAlign, vAlign;
                float     x, y;
                int       width, height;

                for (int i = 0; i < FSpreadMax; i++)
                {
                    var font = CreateFont(OnDevice, i);

                    text = FTextInput[i];

                    if (string.IsNullOrEmpty(text))
                    {
                        continue;
                    }

                    DrawTextFormat format = DrawTextFormat.NoClip | DrawTextFormat.ExpandTabs;

                    hAlign = FHorizontalAlignInput[i].Index;
                    switch (hAlign)
                    {
                    case 0: format |= DrawTextFormat.Left; break;

                    case 1: format |= DrawTextFormat.Center; break;

                    case 2: format |= DrawTextFormat.Right; break;
                    }

                    vAlign = FVerticalAlignInput[i].Index;
                    switch (vAlign)
                    {
                    case 0: format |= DrawTextFormat.Top; break;

                    case 1: format |= DrawTextFormat.VerticalCenter; break;

                    case 2: format |= DrawTextFormat.Bottom; break;
                    }

                    switch (FTextRenderingModeInput[i].Index)
                    {
                    case 0: format |= DrawTextFormat.SingleLine; break;

                    case 2: format |= DrawTextFormat.WordBreak; break;
                    }

                    tmpRect = new Rectangle(0, 0, FWidth[i], 0);
                    font.MeasureString(dh.Sprite, text, format, ref tmpRect);
                    width  = tmpRect.Width;
                    height = tmpRect.Height;

                    FSizeOutput[i] = new Vector2D(width, height);

                    switch (normalize)
                    {
                    case 1: preScale = Matrix.Scaling(1f / width, -1f / width, 1); break;
                    //"width" means that the texture width will have no influence on the width of the sprite. Width will be always 1.

                    case 2: preScale = Matrix.Scaling(1f / height, -1f / height, 1); break;
                    //"height" means that the texture height will have no influence on the height of the sprite. Height will be always 1.

                    case 3: preScale = Matrix.Scaling(1f / width, -1f / height, 1); break;
                        //"on" means that the particle will always be a unit quad. independant of texture size
                    }

                    FTransformIn.GetRenderWorldMatrix(i, out world);
                    dh.Sprite.Transform = preScale * world;

                    switch (vAlign)
                    {
                    case 1: y = height / 2; break;

                    case 2: y = height; break;

                    default: y = 0; break;
                    }

                    if (FShowBrush[i])
                    {
                        switch (hAlign)
                        {
                        case 1: x = width / 2; break;

                        case 2: x = width; break;

                        default: x = 0; break;
                        }
                        dh.Sprite.Draw(dh.Texture, new Rectangle(0, 0, width, height),
                                       new Vector3(x, y, -0.001f), null, new Color4(FBrushColor[i].Color.ToArgb()));
                    }

                    width = FWidth[i];
                    switch (hAlign)
                    {
                    case 1: x = width / 2; break;

                    case 2: x = width; break;

                    default: x = 0; break;
                    }
                    font.DrawString(dh.Sprite, text, new Rectangle((int)-x, (int)-y, width, height), format, (Color)FColorInput[i]);
                }
            }
            catch (Exception e)
            {
                Logger.Log(e);
            }
            finally
            {
                dh.Sprite.End();
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Draw the icon
        /// </summary>
        protected virtual void Render(DrawArgs drawArgs, Icon icon, Vector3 projectedPoint)
        {
            if (!icon.isInitialized)
            {
                icon.Initialize(drawArgs);
            }

            if (!drawArgs.WorldCamera.ViewFrustum.ContainsPoint(icon.Position))
            {
                return;
            }

            // Check icons for within "visual" range
            double distanceToIcon = Vector3.Length(icon.Position - drawArgs.WorldCamera.Position);

            if (distanceToIcon > icon.MaximumDisplayDistance)
            {
                return;
            }
            if (distanceToIcon < icon.MinimumDisplayDistance)
            {
                return;
            }

            IconTexture iconTexture = GetTexture(icon);
            bool        isMouseOver = icon == mouseOverIcon;

            if (isMouseOver)
            {
                // Mouse is over
                isMouseOver = true;

                if (icon.isSelectable)
                {
                    DrawArgs.MouseCursor = CursorType.Hand;
                }

                string description = icon.Description;
                if (description == null)
                {
                    description = icon.ClickableActionURL;
                }
                if (description != null)
                {
                    // Render description field
                    DrawTextFormat format = DrawTextFormat.NoClip | DrawTextFormat.WordBreak | DrawTextFormat.Bottom;
                    int            left   = 10;
                    if (World.Settings.showLayerManager)
                    {
                        left += World.Settings.layerManagerWidth;
                    }
                    Rectangle rect = Rectangle.FromLTRB(left, 10, drawArgs.screenWidth - 10, drawArgs.screenHeight - 10);

                    // Draw outline
                    drawArgs.defaultDrawingFont.DrawText(
                        m_sprite, description,
                        rect,
                        format, 0xb0 << 24);

                    rect.Offset(2, 0);
                    drawArgs.defaultDrawingFont.DrawText(
                        m_sprite, description,
                        rect,
                        format, 0xb0 << 24);

                    rect.Offset(0, 2);
                    drawArgs.defaultDrawingFont.DrawText(
                        m_sprite, description,
                        rect,
                        format, 0xb0 << 24);

                    rect.Offset(-2, 0);
                    drawArgs.defaultDrawingFont.DrawText(
                        m_sprite, description,
                        rect,
                        format, 0xb0 << 24);

                    // Draw description
                    rect.Offset(1, -1);
                    drawArgs.defaultDrawingFont.DrawText(
                        m_sprite, description,
                        rect,
                        format, descriptionColor);
                }
            }

            int color = isMouseOver ? hotColor : normalColor;

            if (iconTexture == null || isMouseOver || icon.NameAlwaysVisible)
            {
                // Render label
                if (icon.Name != null)
                {
                    // Render name field
                    const int labelWidth = 1000;                     // Dummy value needed for centering the text
                    if (iconTexture == null)
                    {
                        // Center over target as we have no bitmap
                        Rectangle rect = new Rectangle(
                            (int)projectedPoint.X - (labelWidth >> 1),
                            (int)(projectedPoint.Y - (drawArgs.defaultDrawingFont.Description.Height >> 1)),
                            labelWidth,
                            drawArgs.screenHeight);

                        drawArgs.defaultDrawingFont.DrawText(m_sprite, icon.Name, rect, DrawTextFormat.Center, color);
                    }
                    else
                    {
                        // Adjust text to make room for icon
                        int spacing = (int)(icon.Width * 0.3f);
                        if (spacing > 10)
                        {
                            spacing = 10;
                        }
                        int offsetForIcon = (icon.Width >> 1) + spacing;

                        Rectangle rect = new Rectangle(
                            (int)projectedPoint.X + offsetForIcon,
                            (int)(projectedPoint.Y - (drawArgs.defaultDrawingFont.Description.Height >> 1)),
                            labelWidth,
                            drawArgs.screenHeight);

                        drawArgs.defaultDrawingFont.DrawText(m_sprite, icon.Name, rect, DrawTextFormat.WordBreak, color);
                    }
                }
            }

            if (iconTexture != null)
            {
                // Render icon
                float xscale = (float)icon.Width / iconTexture.Width;
                float yscale = (float)icon.Height / iconTexture.Height;
                m_sprite.Transform = Matrix.Scaling(xscale, yscale, 0);

                if (icon.IsRotated)
                {
                    m_sprite.Transform *= Matrix.RotationZ((float)icon.Rotation.Radians - (float)drawArgs.WorldCamera.Heading.Radians);
                }

                m_sprite.Transform *= Matrix.Translation(projectedPoint.X, projectedPoint.Y, 0);
                m_sprite.Draw(iconTexture.Texture,
                              new Vector3(iconTexture.Width >> 1, iconTexture.Height >> 1, 0),
                              Vector3.Empty,
                              color);

                // Reset transform to prepare for text rendering later
                m_sprite.Transform = Matrix.Identity;
            }
        }
Esempio n. 27
0
 /// <summary>Set the font</summary>
 public void SetFont(uint font, ColorValue defaultFontColor, DrawTextFormat format)
 {
     // Store data
     FontIndex = font;
     textFormat = format;
     FontColor.Initialize(defaultFontColor);
 }
Esempio n. 28
0
        public void Render(DrawArgs drawArgs)
        {
            try
            {
                if (m_Visible)
                {
                    if (m_localFont != null && m_drawingFont == null)
                    {
                        m_drawingFont = new Font(drawArgs.device, m_localFont);
                    }

                    DrawTextFormat drawTextFormat = DrawTextFormat.Center;

                    Angle startLatitude  = Angle.NaN;
                    Angle startLongitude = Angle.NaN;

                    Angle endLatitude  = Angle.NaN;
                    Angle endLongitude = Angle.NaN;

                    string displayString = "";

                    drawArgs.WorldCamera.PickingRayIntersection(
                        AbsoluteLocation.X,
                        AbsoluteLocation.Y + ClientSize.Height,
                        out startLatitude,
                        out startLongitude);

                    drawArgs.WorldCamera.PickingRayIntersection(
                        AbsoluteLocation.X + ClientSize.Width,
                        AbsoluteLocation.Y + ClientSize.Height,
                        out endLatitude,
                        out endLongitude);

                    if (startLatitude == Angle.NaN ||
                        startLongitude == Angle.NaN ||
                        endLatitude == Angle.NaN ||
                        endLongitude == Angle.NaN)
                    {
                        //displayString = "Out of Range";
                    }
                    else
                    {
                        double distance = getDistance(startLatitude, startLongitude, endLatitude, endLongitude, World.EquatorialRadius);
                        if (distance > double.MinValue && distance < double.MaxValue)
                        {
                            displayString = GetDisplayString(distance);
                        }
                    }

                    drawArgs.device.TextureState[0].ColorOperation = TextureOperation.SelectArg1;
                    drawArgs.device.TextureState[0].ColorArgument1 = TextureArgument.Diffuse;
                    drawArgs.device.TextureState[0].AlphaOperation = TextureOperation.SelectArg1;
                    drawArgs.device.TextureState[0].AlphaArgument1 = TextureArgument.Diffuse;


                    renderBackbone(drawArgs);

                    if (m_drawingFont == null)
                    {
                        drawArgs.DefauleFont.DrawText(
                            null,
                            displayString,
                            new System.Drawing.Rectangle(AbsoluteLocation.X, AbsoluteLocation.Y, m_Size.Width, m_Size.Height),
                            drawTextFormat,
                            m_ForeColor);
                    }
                    else
                    {
                        drawArgs.DefauleFont.DrawText(
                            null,
                            displayString,
                            new System.Drawing.Rectangle(AbsoluteLocation.X, AbsoluteLocation.Y, m_Size.Width, m_Size.Height),
                            drawTextFormat,
                            m_ForeColor);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
        }
Esempio n. 29
0
 /// <summary>
 /// Cambiar TextAlign y configurar DrawTextFormat
 /// </summary>
 private void changeTextAlign(TextAlign align)
 {
     this.align = align;
     DrawTextFormat fAlign = DrawTextFormat.None;
     switch (align)
     {
         case TextAlign.LEFT:
             fAlign = DrawTextFormat.Left;
             break;
         case TextAlign.RIGHT:
             fAlign = DrawTextFormat.Right;
             break;
         case TextAlign.CENTER:
             fAlign = DrawTextFormat.Center;
             break;
     }
     format = DrawTextFormat.NoClip | DrawTextFormat.ExpandTabs | DrawTextFormat.WordBreak | fAlign;
 }
Esempio n. 30
0
        /// <summary>
        /// Draws the specified text using the Direct3D font object.
        /// </summary>
        /// <param name="text">Text to draw.</param>
        /// <param name="rect">Rectangle to draw the text in.</param>
        /// <param name="format">Text formatting options.</param>
        public void DrawText( string text, Rectangle rect, DrawTextFormat format )
        {
            Sprite sprite = null;

            RenderText( sprite, text, rect, format );
        }
Esempio n. 31
0
        protected override void Render(DrawArgs drawArgs, Icon icon, Vector3 projectedPoint)
        {
            if (!icon.Initialized)
            {
                icon.Initialize(drawArgs);
                return;
            }
            if (!drawArgs.WorldCamera.ViewFrustum.ContainsPoint(icon.Position))
            {
                return;
            }

            // check whether in icon's visual range.
            float distanceToIcon = Vector3.Length(icon.Position - drawArgs.WorldCamera.Position);

            if (distanceToIcon > icon.MaximumDisplayDistance)
            {
                return;
            }
            if (distanceToIcon < icon.MinimumDisplayDistance)
            {
                return;
            }

            IconTexture iconTexture = this.GetTexture(icon);
            // check is mouse over.
            bool isMouseOver = (icon == this.mouseOverIcon);

            if (isMouseOver)
            {
                if (icon.IsSelectable)
                {
                    DrawArgs.MouseCursor = CursorType.Hand;
                }

                // get icon's description.
                string description = icon.Description;
                if (description == null)
                {
                    description = icon.ClickableActionURL;
                }

                if (description != null)
                {
                    // Render the description field.
                    DrawTextFormat descTextFormat = DrawTextFormat.NoClip;
                    descTextFormat |= DrawTextFormat.WordBreak;
                    descTextFormat |= DrawTextFormat.Bottom;

                    int left = 10;
                    //if (World.Settings.ShowLayerManager) {
                    //   left += World.Settings.LayerManagerWidth;
                    //}
                    Rectangle descRectangle = Rectangle.FromLTRB(left, 10, drawArgs.ScreenWidth - 10, drawArgs.ScreenHeight - 10);

                    // Draw outline
                    this.DrawOutline(drawArgs.DefaultDrawingFont, this.m_sprite, description, ref descRectangle, descTextFormat);

                    // Draw description
                    drawArgs.DefaultDrawingFont.DrawText(this.m_sprite, description, descRectangle, descTextFormat, descriptionColor);
                }
            }

            int color = isMouseOver ? hotColor : normalColor;
            // calculate scale
            double scale = (drawArgs.WorldCamera.WorldRadius + icon.Altitude) / (drawArgs.WorldCamera.WorldRadius + distanceToIcon);

            scale *= drawArgs.WorldCamera.TargetDistance / distanceToIcon;
            //
            // render name field.
            if (icon.Name != null)
            {
                Rectangle nameRectangle = drawArgs.DefaultDrawingFont.MeasureString(this.m_sprite, icon.Name, DrawTextFormat.Center, color);
                nameRectangle.X = (int)projectedPoint.X - (nameRectangle.Width >> 1);
                if (iconTexture == null)
                {
                    // by zzm start
                    nameRectangle.Y = (int)projectedPoint.Y - (drawArgs.DefaultDrawingFont.Description.Height >> 1);
                    // by zzm end
                    this.DrawOutline(drawArgs.DefaultDrawingFont, this.m_sprite, icon.Name, ref nameRectangle, DrawTextFormat.Center);
                    drawArgs.DefaultDrawingFont.DrawText(this.m_sprite, icon.Name, nameRectangle, DrawTextFormat.Center, color);
                }
                else
                {
                    // adjust text to make room for icon.
                    int spacing       = 10;
                    int offsetForIcon = (int)(icon.Height * scale) + spacing;
                    nameRectangle.Y = (int)projectedPoint.Y - offsetForIcon - (drawArgs.DefaultDrawingFont.Description.Height >> 1);
                    this.DrawOutline(drawArgs.DefaultDrawingFont, this.m_sprite, icon.Name, ref nameRectangle, DrawTextFormat.Center);
                    drawArgs.DefaultDrawingFont.DrawText(this.m_sprite, icon.Name, nameRectangle, DrawTextFormat.Center, color);
                }
            }

            if (iconTexture != null)
            {
                // render icon
                // get icon's current scale
                float xScale = (float)scale;                  //icon.Width / iconTexture.Width;
                float yScale = (float)scale;                  //icon.Height / iconTexture.Height;
                this.m_sprite.Transform  = Matrix.Scaling(xScale, yScale, 0);
                this.m_sprite.Transform *= Matrix.Translation(projectedPoint.X, projectedPoint.Y, 0);
                this.m_sprite.Draw(iconTexture.Texture, new Vector3(iconTexture.Width, iconTexture.Height, 0), Vector3.Empty, color);
                this.m_sprite.Transform = Matrix.Identity;
            }
        }
Esempio n. 32
0
        public Vec2 AddTextWithHeight(Vec2 pos, string text, Color color, int height, DrawTextFormat format)
        {
            SlimDX.Direct3D9.Font font      = this.GetFont(height);
            Rectangle             rectangle = font.MeasureString(this.textSprite, text, format);

            rectangle.X += pos.X;
            rectangle.Y += pos.Y;
            font.DrawString(this.textSprite, text, rectangle, format, color);
            return(new Vec2(rectangle.Width, rectangle.Height));
        }
Esempio n. 33
0
        public void DrawText(Font font, string text, Rectangle rectangle, DrawTextFormat drawTextFormat, Color color)
        {
            if (text == null) return;

            switch (drawTextFormat)
            {
                case DrawTextFormat.WordBreak: break;
                case DrawTextFormat.SingleLine: break;
                case DrawTextFormat.ExpandTabs: break;

                default: break;
            }

            RectangleF textSize = frameMgr.textPrinter.Measure(text, font).BoundingBox;
			
			int leftPadding;
            if ((drawTextFormat & DrawTextFormat.Right) == DrawTextFormat.Right)
            {
                leftPadding = (int)(rectangle.Width - textSize.Width);
            }
            else if ((drawTextFormat & DrawTextFormat.Center) == DrawTextFormat.Center)
            {
                leftPadding = (int)(rectangle.Width - textSize.Width) / 2;
            }
            else
            {
                leftPadding = 0;
            }

            int topPadding;
            if ((drawTextFormat & DrawTextFormat.VerticalCenter) == DrawTextFormat.VerticalCenter)
            {
                topPadding = (int)(rectangle.Height - textSize.Height) / 2;
            }
            else if ((drawTextFormat & DrawTextFormat.Bottom) == DrawTextFormat.Bottom)
            {
                topPadding = (int)(rectangle.Height - textSize.Height);
            }
            else
            {
                topPadding = 0;
            }

            Vector2 position = new Vector2(rectangle.X + leftPadding, rectangle.Y + topPadding);

            ShaderProgram.UseDefault();
            GL.Disable(EnableCap.Lighting);
            GL.Enable(EnableCap.ScissorTest);
			
            frameMgr.textPrinter.Begin();
            GL.Color3(color);
            GL.Translate(position.X, position.Y, 0);
            GL.Scissor(rectangle.X, frameBuffer.height - rectangle.Bottom, rectangle.Width, rectangle.Height);
			frameMgr.textPrinter.Print(text, font, Color.Black);
			frameMgr.textPrinter.End();			
            GL.Enable(EnableCap.Lighting);
            GL.Disable(EnableCap.ScissorTest);
        }
Esempio n. 34
0
        /// <summary>
        /// Draws the specified text using the Direct3D font object.
        /// </summary>
        /// <param name="text">Text to draw.</param>
        /// <param name="rect">Rectangle to draw the text in.</param>
        /// <param name="format">Text formatting options.</param>
        public void DrawText(string text, Rectangle rect, DrawTextFormat format)
        {
            Sprite sprite = null;

            RenderText(sprite, text, rect, format);
        }
Esempio n. 35
0
 /// <summary>
 /// Draw text outline
 /// </summary>
 /// <param name="font"></param>
 /// <param name="sprite"></param>
 /// <param name="text"></param>
 /// <param name="rect"></param>
 /// <param name="format"></param>
 /// by zzm
 private void DrawOutline(D3Font font, Sprite sprite, string text, ref Rectangle rect, DrawTextFormat format)
 {
     int color = 0xB0 << 24;
     font.DrawText(sprite, text, rect, format, color);
     rect.Offset(2, 0);
     font.DrawText(sprite, text, rect, format, color);
     rect.Offset(0, 2);
     font.DrawText(sprite, text, rect, format, color);
     rect.Offset(-2, 0);
     font.DrawText(sprite, text, rect, format, color);
     rect.Offset(1, -1);
 }
Esempio n. 36
0
        /// <summary>
        /// Draw text outline
        /// </summary>
        /// <param name="font"></param>
        /// <param name="sprite"></param>
        /// <param name="text"></param>
        /// <param name="rect"></param>
        /// <param name="format"></param>
        /// by zzm
        private void DrawOutline(D3Font font, Sprite sprite, string text, ref Rectangle rect, DrawTextFormat format)
        {
            int color = 0xB0 << 24;

            font.DrawText(sprite, text, rect, format, color);
            rect.Offset(2, 0);
            font.DrawText(sprite, text, rect, format, color);
            rect.Offset(0, 2);
            font.DrawText(sprite, text, rect, format, color);
            rect.Offset(-2, 0);
            font.DrawText(sprite, text, rect, format, color);
            rect.Offset(1, -1);
        }
Esempio n. 37
0
 /// <summary>
 /// Draws the specified text using the Direct3D font object.
 /// </summary>
 /// <param name="text">Text to draw.</param>
 /// <param name="rect">Rectangle to draw the text in.</param>
 /// <param name="sprite">Sprite background for the text.</param>
 /// <param name="format">Text formatting options.</param>
 private void RenderText( Sprite sprite, string text, Rectangle rect, DrawTextFormat format )
 {
     _font.DrawText( sprite, text, rect, format, _color.ToArgb() );
 }
Esempio n. 38
0
 /// <summary>
 /// Draws the specified text using the Direct3D font object.
 /// </summary>
 /// <param name="text">Text to draw.</param>
 /// <param name="rect">Rectangle to draw the text in.</param>
 /// <param name="sprite">Sprite background for the text.</param>
 /// <param name="format">Text formatting options.</param>
 private void RenderText(Sprite sprite, string text, Rectangle rect, DrawTextFormat format)
 {
     _font.DrawText(sprite, text, rect, format, _color.ToArgb());
 }
Esempio n. 39
0
 public Vec2 MeasureString(string text, int height, DrawTextFormat format)
 {
     SlimDX.Direct3D9.Font font = this.GetFont(height);
     Rectangle rectangle = font.MeasureString(this.textSprite, text, format);
     return new Vec2(rectangle.Width, rectangle.Height);
 }
Esempio n. 40
0
 public void TextOut2(Rectangle rect, string szString, Color color, Color outlineColor, DrawTextFormat format = DrawTextFormat.Top | DrawTextFormat.Left)
 {
     if ((outlineColor.ToArgb() & 0xff000000) != 0x00)
     {
         m_pFont.DrawText(null, szString, new Rectangle(rect.X + 2, rect.Y + 1, rect.Width, rect.Height), format, outlineColor);
         m_pFont.DrawText(null, szString, new Rectangle(rect.X + 2, rect.Y + 0, rect.Width, rect.Height), format, outlineColor);
         m_pFont.DrawText(null, szString, new Rectangle(rect.X + 2, rect.Y - 1, rect.Width, rect.Height), format, outlineColor);
         m_pFont.DrawText(null, szString, new Rectangle(rect.X + 1, rect.Y + 1, rect.Width, rect.Height), format, outlineColor);
         m_pFont.DrawText(null, szString, new Rectangle(rect.X + 1, rect.Y + 0, rect.Width, rect.Height), format, outlineColor);
         m_pFont.DrawText(null, szString, new Rectangle(rect.X + 1, rect.Y - 1, rect.Width, rect.Height), format, outlineColor);
         m_pFont.DrawText(null, szString, new Rectangle(rect.X + 0, rect.Y + 1, rect.Width, rect.Height), format, outlineColor);
         m_pFont.DrawText(null, szString, new Rectangle(rect.X + 0, rect.Y + 0, rect.Width, rect.Height), format, outlineColor);
         m_pFont.DrawText(null, szString, new Rectangle(rect.X + 0, rect.Y - 1, rect.Width, rect.Height), format, outlineColor);
         m_pFont.DrawText(null, szString, new Rectangle(rect.X - 1, rect.Y + 1, rect.Width, rect.Height), format, outlineColor);
         m_pFont.DrawText(null, szString, new Rectangle(rect.X - 1, rect.Y + 0, rect.Width, rect.Height), format, outlineColor);
         m_pFont.DrawText(null, szString, new Rectangle(rect.X - 1, rect.Y - 1, rect.Width, rect.Height), format, outlineColor);
     }
     m_pFont.DrawText(null, szString, new Rectangle(rect.X + 0, rect.Y, rect.Width, rect.Height), format, color);
     m_pFont.DrawText(null, szString, new Rectangle(rect.X + 1, rect.Y, rect.Width, rect.Height), format, color);
 }
Esempio n. 41
0
        /// <summary>
        /// Stampa a schermo il testo inserito
        /// </summary>
        /// <param name="Text"></param>
        /// <param name="Rectangle"></param>
        /// <param name="Format"></param>
        /// <param name="Color"></param>
        /// <returns></returns>
        public bool Write(string Text, Rectangle Rectangle, DrawTextFormat Format, Color Color)
        {
            try
            {
                font.DrawText(null, Text, Rectangle, Format, Color);
                return true;
            }

            catch
            {
                if (AmICorrect == true)
                    Error("OnWriting");
                return false;
            }
        }