예제 #1
0
        //---------------------------------------------------------------------------

        public void Draw(SpriteBatch batch, CameraData data, float deltaTime)
        {
            if (Icon != null)
            {
                UITransformComponent transform = GetComponent <UITransformComponent>();
                if (transform != null)
                {
                    batch.Draw(Icon,
                               transform.Bounds(),
                               Icon.Bounds,
                               Color.White,
                               0,
                               Vector2.Zero,
                               SpriteEffects.None,
                               1.0f);
                }
            }
        }
예제 #2
0
        //---------------------------------------------------------------------------

        public void Draw(SpriteBatch batch, float deltaTime)
        {
            if (Image != null)
            {
                UITransformComponent transform = GetComponent <UITransformComponent>();
                if (transform != null)
                {
                    Rectangle bounds = transform.Bounds();

                    switch (Alignment)
                    {
                    case EImageAlignment.Center:
                        break;

                    case EImageAlignment.UniformStretch:
                        double xFactor = (double)bounds.Width / Image.Width;
                        double yFactor = (double)bounds.Height / Image.Height;

                        Point size = new Point(
                            (xFactor < yFactor ? bounds.Width : (int)(Image.Width * yFactor)),
                            (xFactor < yFactor ? (int)(Image.Height * xFactor) : bounds.Height));
                        bounds = new Rectangle(
                            bounds.X + (bounds.Width - size.X) / 2,
                            bounds.Y + (bounds.Height - size.Y) / 2,
                            size.X,
                            size.Y);
                        break;
                    }

                    batch.Draw(Image,
                               bounds,
                               Image.Bounds,
                               Color.White,
                               0,
                               Vector2.Zero,
                               SpriteEffects.None,
                               1.0f);
                }
            }
        }
예제 #3
0
        //---------------------------------------------------------------------------

        public void Draw(SpriteBatch batch, float deltaTime)
        {
            if (Font != null)
            {
                UITransformComponent transform = GetComponent <UITransformComponent>();
                if (transform != null)
                {
                    Rectangle bounds = transform.Bounds();

                    int offset = 0;
                    int width  = 0;
                    int height = (int)Font.MeasureString("X").Y + Spacing;
                    int line   = 0;
                    List <TextSegment> segments = ParseToSegments();
                    foreach (TextSegment segment in segments)
                    {
                        width += (int)Font.MeasureString(segment.Text).X;
                    }

                    if (IsWrapping)
                    {
                        foreach (LineSegment lineSegment in ParseToLines(segments, bounds.Width))
                        {
                            foreach (TextSegment textSegment in lineSegment.Texts)
                            {
                                switch (TextAlignment)
                                {
                                case EHorizontalAlignment.Left:
                                    DrawText(batch, textSegment.Text, new Vector2(bounds.X + offset, bounds.Y + lineSegment.LineIndex * height), textSegment.Color, true);
                                    break;

                                case EHorizontalAlignment.Right:
                                    DrawText(batch, textSegment.Text, new Vector2((bounds.X + bounds.Width) - lineSegment.Width + offset, bounds.Y + lineSegment.LineIndex * height), textSegment.Color, true);
                                    break;

                                case EHorizontalAlignment.Center:
                                    DrawText(batch, textSegment.Text, new Vector2((bounds.X + bounds.Width / 2) - lineSegment.Width / 2 + offset, bounds.Y + lineSegment.LineIndex * height), textSegment.Color, true);
                                    break;
                                }
                                offset += textSegment.GetWidth(Font);
                            }
                            offset = 0;
                        }
                    }

                    foreach (TextSegment segment in segments)
                    {
                        if (IsWrapping)
                        {
                            //int wrapIndex = 0;
                            //do
                            //{
                            //    int newWrapIndex = 0;
                            //    bool isWrapping = (Wrap(segment.Text.Substring(wrapIndex), bounds.Width - offset, out newWrapIndex));
                            //    string substring = segment.Text.Substring(wrapIndex, newWrapIndex);
                            //    if (offset == 0) substring = substring.TrimStart(' ');
                            //    switch (TextAlignment)
                            //    {
                            //        case EHorizontalAlignment.Left:
                            //            DrawText(batch, substring, new Vector2(bounds.X + offset, bounds.Y + line * height), segment.Color, true);
                            //            break;
                            //        case EHorizontalAlignment.Right:
                            //            DrawText(batch, substring, new Vector2((bounds.X + bounds.Width) - width + offset, bounds.Y + line * height), segment.Color, true);
                            //            break;
                            //        case EHorizontalAlignment.Center:
                            //            DrawText(batch, substring, new Vector2((bounds.X + bounds.Width / 2) - width / 2 + offset, bounds.Y + line * height), segment.Color, true);
                            //            break;
                            //    }
                            //    if (isWrapping)
                            //    {
                            //        line++;
                            //        offset = 0;
                            //    }
                            //    else
                            //    {
                            //        offset += (int)Font.MeasureString(segment.Text.Substring(wrapIndex, newWrapIndex)).X;
                            //    }
                            //    wrapIndex += newWrapIndex;
                            //}
                            //while (wrapIndex < segment.Text.Length);
                        }
                        else
                        {
                            switch (TextAlignment)
                            {
                            case EHorizontalAlignment.Left:
                                DrawText(batch, segment.Text, new Vector2(bounds.X + offset, bounds.Y + line * height), segment.Color, true);
                                break;

                            case EHorizontalAlignment.Right:
                                DrawText(batch, segment.Text, new Vector2((bounds.X + bounds.Width) - width + offset, bounds.Y + line * height), segment.Color, true);
                                break;

                            case EHorizontalAlignment.Center:
                                DrawText(batch, segment.Text, new Vector2((bounds.X + bounds.Width / 2) - width / 2 + offset, bounds.Y + line * height), segment.Color, true);
                                break;
                            }

                            offset += (int)Font.MeasureString(segment.Text).X;
                        }
                    }
                }
            }
        }
예제 #4
0
        //---------------------------------------------------------------------------

        public Rectangle Bounds()
        {
            Rectangle            bounds    = new Rectangle();
            UITransformComponent transform = GetComponent <UITransformComponent>();

            if (transform != null)
            {
                Rectangle            parentBounds;
                UITransformComponent parentTransform = GetComponentInParent <UITransformComponent>();
                if (parentTransform != null)
                {
                    parentBounds = parentTransform.Bounds();
                }
                else
                {
                    parentBounds = UIManager.Get().ScreenBounds;
                }
                parentBounds = new Rectangle(
                    parentBounds.X + transform.Margin.X,
                    parentBounds.Y + transform.Margin.Y,
                    parentBounds.Width - (transform.Margin.X + transform.Margin.Width),
                    parentBounds.Height - (transform.Margin.Y + transform.Margin.Height));

                Point vertical = new Point();
                switch (transform.VerticalAlignment)
                {
                case EVerticalAlignment.Top:
                    vertical = new Point(parentBounds.Top, parentBounds.Top + transform.Size.Y);
                    break;

                case EVerticalAlignment.Center:
                    vertical = new Point(parentBounds.Center.Y - transform.Size.Y / 2, parentBounds.Center.Y + transform.Size.Y / 2);
                    break;

                case EVerticalAlignment.Bottom:
                    vertical = new Point(parentBounds.Bottom - transform.Size.Y, parentBounds.Bottom);
                    break;

                case EVerticalAlignment.Stretch:
                    vertical = new Point(parentBounds.Top, parentBounds.Bottom);
                    break;
                }

                Point horizontal = new Point();
                switch (transform.HorizontalAlignment)
                {
                case EHorizontalAlignment.Left:
                    horizontal = new Point(parentBounds.Left, parentBounds.Left + transform.Size.X);
                    break;

                case EHorizontalAlignment.Center:
                    horizontal = new Point(parentBounds.Center.X - transform.Size.X / 2, parentBounds.Center.X + transform.Size.X / 2);
                    break;

                case EHorizontalAlignment.Right:
                    horizontal = new Point(parentBounds.Right - transform.Size.X, parentBounds.Right);
                    break;

                case EHorizontalAlignment.Stretch:
                    horizontal = new Point(parentBounds.Left, parentBounds.Right);
                    break;
                }

                bounds = new Rectangle(horizontal.X, vertical.X, horizontal.Y - horizontal.X, vertical.Y - vertical.X);
            }
            return(bounds);
        }