예제 #1
0
        private int GetIndexByHorizontalOrientation(HorizontalOrientation horizontal)
        {
            switch (horizontal)
            {
            case HorizontalOrientation.Left:
                return(0);

            case HorizontalOrientation.Center:
                return(1);

            case HorizontalOrientation.Right:
                return(2);
            }
            return(0);
        }
예제 #2
0
    public static Rect GetScreenRectByOrientation(Vector2 scrPos, HorizontalOrientation hor, VerticalOrientation ver, float width, float height)
    {
        float x = Screen.width * scrPos.x;
        float y = Screen.height * scrPos.y;

        float xMin = 0;
        float xMax = 0;
        float yMin = 0;
        float yMax = 0;

        switch (hor)
        {
        case global::HorizontalOrientation.Left:
            xMin = x;
            xMax = x + width;
            break;

        case global::HorizontalOrientation.Middle:
            xMin = x - 0.5f * width;
            xMax = x + 0.5f * width;
            break;

        case global::HorizontalOrientation.Right:
            xMin = x - width;
            xMax = x;
            break;
        }

        switch (ver)
        {
        case global::VerticalOrientation.Top:
            yMin = y;
            yMax = y + height;
            break;

        case global::VerticalOrientation.Middle:
            yMin = y - 0.5f * height;
            yMax = y + 0.5f * height;
            break;

        case global::VerticalOrientation.Bottom:
            yMin = y - height;
            yMax = y;
            break;
        }
        return(Rect.MinMaxRect(xMin, yMin, xMax, yMax));
    }
예제 #3
0
        /// <summary>
        ///     Maps horizontal text orientation to string format alignment
        /// </summary>
        /// <param name="to"></param>
        /// <param name="strFormat"></param>
        private static void MapStringFormatAlignment(HorizontalOrientation to, StringFormat strFormat)
        {
            switch (to)
            {
            case HorizontalOrientation.Left:
                strFormat.Alignment = StringAlignment.Near;
                break;

            case HorizontalOrientation.Center:
                strFormat.Alignment = StringAlignment.Center;
                break;

            case HorizontalOrientation.Right:
                strFormat.Alignment = StringAlignment.Far;
                break;
            }
        }
예제 #4
0
    public static Rect GetScreenRectByOrientation(Vector2 scrPos, HorizontalOrientation hor, VerticalOrientation ver, float width, float height)
    {
        float x = Screen.width * scrPos.x;
        float y = Screen.height * scrPos.y;

        float xMin = 0;
        float xMax = 0;
        float yMin = 0;
        float yMax = 0;

        switch (hor)
        {
            case global::HorizontalOrientation.Left:
                xMin = x;
                xMax = x + width;
                break;
            case global::HorizontalOrientation.Middle:
                xMin = x - 0.5f * width;
                xMax = x + 0.5f * width;
                break;
            case global::HorizontalOrientation.Right:
                xMin = x - width;
                xMax = x;
                break;
        }

        switch (ver)
        {
            case global::VerticalOrientation.Top:
                yMin = y;
                yMax = y + height;
                break;
            case global::VerticalOrientation.Middle:
                yMin = y - 0.5f * height;
                yMax = y + 0.5f * height;
                break;
            case global::VerticalOrientation.Bottom:
                yMin = y - height;
                yMax = y;
                break;
        }
        return Rect.MinMaxRect(xMin, yMin, xMax, yMax);
    }
예제 #5
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            HorizontalOrientation orientation = (HorizontalOrientation)value;

            if (orientation == HorizontalOrientation.Left)
            {
                if (IsInverted)
                {
                    return(HorizontalAlignment.Right);
                }

                return(HorizontalAlignment.Left);
            }

            if (IsInverted)
            {
                return(HorizontalAlignment.Left);
            }

            return(HorizontalAlignment.Right);
        }
예제 #6
0
        /// <summary>
        ///     Draws lines onto the graphics area
        /// </summary>
        /// <param name="gr">Graphics area</param>
        /// <param name="lines">Lines</param>
        /// <param name="textStartX">Horizontal starting position</param>
        /// <param name="textStartY">Vertical starting position</param>
        /// <param name="textFormatting">Formatting</param>
        /// <param name="orientation">Horizontal orientation</param>
        /// <param name="lineHeight">Line height (text + spacing)</param>
        private void DrawLines(Graphics gr, string[] lines, float textStartX, float textStartY,
                               TextFormatting textFormatting, HorizontalOrientation orientation, float lineHeight)
        {
            var textX = textStartX;
            var textY = textStartY;

            // Set string format
            var strFormat = new StringFormat();

            MapStringFormatAlignment(orientation, strFormat);

            // Shadow
            if (_formatting.ShadowEnabled)
            {
                var size     = textFormatting.Shadow.Size;
                var distance = textFormatting.Shadow.Distance;

                var shadowX = textX - (distance * (float)Math.Cos(Math.PI * (90 + textFormatting.Shadow.Direction) / 180));
                var shadowY = textY - (distance * (float)Math.Sin(Math.PI * (90 + textFormatting.Shadow.Direction) / 180));

                Brush shadodBrush = new SolidBrush(Color.FromArgb(15, textFormatting.Shadow.Color));
                if (_formatting.SmoothShadow)
                {
                    gr.SmoothingMode     = SmoothingMode.HighQuality;
                    gr.InterpolationMode = InterpolationMode.HighQualityBilinear;
                    gr.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
                }

                foreach (var s in lines)
                {
                    for (var x = shadowX - size; x <= shadowX + size; x++)
                    {
                        for (var y = shadowY - size; y <= shadowY + size; y++)
                        {
                            gr.DrawString(s, textFormatting.Font, shadodBrush, x, y, strFormat);
                        }
                    }
                    shadowY += lineHeight;
                }
            }

            // Outline
            if (_formatting.OutlineEnabled)
            {
                var outLineThickness = textFormatting.Outline.Width;
                if (outLineThickness > 0)
                {
                    var outlineX = textX;
                    var outlineY = textY;

                    gr.SmoothingMode     = SmoothingMode.None;
                    gr.InterpolationMode = InterpolationMode.Low;
                    gr.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

                    Brush br = new SolidBrush(textFormatting.Outline.Color);

                    foreach (var s in lines)
                    {
                        for (var x = outlineX - outLineThickness * 2; x <= outlineX + outLineThickness * 2; x += 2)
                        {
                            for (var y = outlineY - outLineThickness * 2; y <= outlineY + outLineThickness * 2; y += 2)
                            {
                                gr.DrawString(s, textFormatting.Font, br, x, y, strFormat);
                            }
                        }
                        outlineY += lineHeight;
                    }
                }
            }
            else
            {
                gr.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;
            }

            // Text
            foreach (var s in lines)
            {
                gr.DrawString(s, textFormatting.Font, new SolidBrush(textFormatting.Color), textX, textY, strFormat);
                textY += lineHeight;
            }
        }
예제 #7
0
 public TextOrientation(VerticalOrientation vertical, HorizontalOrientation horizontal)
 {
     Vertical   = vertical;
     Horizontal = horizontal;
 }