예제 #1
0
 protected override RBrush CreateLinearGradientBrush(RRect rect, RColor color1, RColor color2, double angle)
 {
     var startColor = angle <= 180 ? Utils.Convert(color1) : Utils.Convert(color2);
     var endColor = angle <= 180 ? Utils.Convert(color2) : Utils.Convert(color1);
     angle = angle <= 180 ? angle : angle - 180;
     double x = angle < 135 ? Math.Max((angle - 45) / 90, 0) : 1;
     double y = angle <= 45 ? Math.Max(0.5 - angle / 90, 0) : angle > 135 ? Math.Abs(1.5 - angle / 90) : 0;
     return new BrushAdapter(new LinearGradientBrush(startColor, endColor, new Point(x, y), new Point(1 - x, 1 - y)));
 }
예제 #2
0
 /// <summary>
 /// Get solid color brush for the given color.
 /// </summary>
 private static IBrush GetSolidColorBrush(RColor color)
 {
     IBrush solidBrush;
     if (color == RColor.White)
         solidBrush = Brushes.White;
     else if (color == RColor.Black)
         solidBrush = Brushes.Black;
     else if (color.A < 1)
         solidBrush = Brushes.Transparent;
     else
         solidBrush = new SolidColorBrush(Util.Convert(color));
     return solidBrush;
 }
 protected override RBrush CreateLinearGradientBrush(RRect rect, RColor color1, RColor color2, double angle)
 {
     XLinearGradientMode mode;
     if (angle < 45)
         mode = XLinearGradientMode.ForwardDiagonal;
     else if (angle < 90)
         mode = XLinearGradientMode.Vertical;
     else if (angle < 135)
         mode = XLinearGradientMode.BackwardDiagonal;
     else
         mode = XLinearGradientMode.Horizontal;
     return new BrushAdapter(new XLinearGradientBrush(Utils.Convert(rect), Utils.Convert(color1), Utils.Convert(color2), mode));
 }
예제 #4
0
        protected override RBrush CreateSolidBrush(RColor color)
        {
            XBrush solidBrush;
            if (color == RColor.White)
                solidBrush = XBrushes.White;
            else if (color == RColor.Black)
                solidBrush = XBrushes.Black;
            else if (color.A < 1)
                solidBrush = XBrushes.Transparent;
            else
                solidBrush = new XSolidBrush(Utils.Convert(color));

            return new BrushAdapter(solidBrush);
        }
예제 #5
0
        protected override RBrush CreateLinearGradientBrush(RRect rect, RColor color1, RColor color2, double angle)
        {
            var startColor = angle <= 180 ? Util.Convert(color1) : Util.Convert(color2);
            var endColor = angle <= 180 ? Util.Convert(color2) : Util.Convert(color1);
            angle = angle <= 180 ? angle : angle - 180;
            double x = angle < 135 ? Math.Max((angle - 45) / 90, 0) : 1;
            double y = angle <= 45 ? Math.Max(0.5 - angle / 90, 0) : angle > 135 ? Math.Abs(1.5 - angle / 90) : 0;
            return new BrushAdapter(new LinearGradientBrush
            {
                StartPoint = new RelativePoint(x, y, RelativeUnit.Relative), 
                EndPoint = new RelativePoint(1 - x, 1 - y, RelativeUnit.Relative),
                GradientStops =
                {
                    new GradientStop(startColor, 0),
                    new GradientStop(endColor, 1)
                }
            });

        }
예제 #6
0
 /// <summary>
 /// Get cached pen instance for the given color.
 /// </summary>
 /// <param name="color">the color to get pen for</param>
 /// <returns>pen instance</returns>
 protected abstract RPen CreatePen(RColor color);
예제 #7
0
 /// <summary>
 /// Check if the given color is visible if painted (has alpha and color values)
 /// </summary>
 /// <param name="color">the color to check</param>
 /// <returns>true - visible, false - not visible</returns>
 public static bool IsColorVisible(RColor color)
 {
     return color.A > 0;
 }
예제 #8
0
 /// <summary>
 /// Get solid color brush.
 /// </summary>
 /// <param name="color">the color to get the brush for</param>
 /// <returns>solid color brush instance</returns>
 public RBrush GetSolidBrush(RColor color)
 {
     return _adapter.GetSolidBrush(color);
 }
예제 #9
0
 /// <summary>
 /// Draw the given string using the given font and foreground color at given location.
 /// </summary>
 /// <param name="str">the string to draw</param>
 /// <param name="font">the font to use to draw the string</param>
 /// <param name="color">the text color to set</param>
 /// <param name="point">the location to start string draw (top-left)</param>
 /// <param name="size">used to know the size of the rendered text for transparent text support</param>
 /// <param name="rtl">is to render the string right-to-left (true - RTL, false - LTR)</param>
 public abstract void DrawString(String str, RFont font, RColor color, RPoint point, RSize size, bool rtl);
예제 #10
0
 protected override RBrush CreateSolidBrush(RColor color)
 {
     var solidBrush = GetSolidColorBrush(color);
     return new BrushAdapter(solidBrush);
 }
예제 #11
0
        public override void DrawString(string str, RFont font, RColor color, RPoint point, RSize size, bool rtl)
        {
            var colorConv = ((BrushAdapter)_adapter.GetSolidBrush(color)).Brush;

            bool glyphRendered = false;
            GlyphTypeface glyphTypeface = ((FontAdapter)font).GlyphTypeface;
            if (glyphTypeface != null)
            {
                double width = 0;
                ushort[] glyphs = new ushort[str.Length];
                double[] widths = new double[str.Length];

                int i = 0;
                for (; i < str.Length; i++)
                {
                    ushort glyph;
                    if (!glyphTypeface.CharacterToGlyphMap.TryGetValue(str[i], out glyph))
                        break;

                    glyphs[i] = glyph;
                    width += glyphTypeface.AdvanceWidths[glyph];
                    widths[i] = 96d / 72d * font.Size * glyphTypeface.AdvanceWidths[glyph];
                }

                if (i >= str.Length)
                {
                    point.Y += glyphTypeface.Baseline * font.Size * 96d / 72d;
                    point.X += rtl ? 96d / 72d * font.Size * width : 0;

                    glyphRendered = true;
                    var glyphRun = new GlyphRun(glyphTypeface, rtl ? 1 : 0, false, 96d / 72d * font.Size, glyphs, Utils.ConvertRound(point), widths, null, null, null, null, null, null);
                    _g.DrawGlyphRun(colorConv, glyphRun);
                }
            }

            if (!glyphRendered)
            {
                var formattedText = new FormattedText(str, CultureInfo.CurrentCulture, rtl ? FlowDirection.RightToLeft : FlowDirection.LeftToRight, ((FontAdapter)font).Font, 96d / 72d * font.Size, colorConv);
                point.X += rtl ? formattedText.Width : 0;
                _g.DrawText(formattedText, Utils.ConvertRound(point));
            }
        }
예제 #12
0
 /// <summary>
 /// Makes the specified color darker for inset/outset borders.
 /// </summary>
 private static RColor Darken(RColor c)
 {
     return RColor.FromArgb(c.R / 2, c.G / 2, c.B / 2);
 }
예제 #13
0
 /// <summary>
 /// Get pen to be used for border draw respecting its style.
 /// </summary>
 private static RPen GetPen(RGraphics g, string style, RColor color, double width)
 {
     var p = g.GetPen(color);
     p.Width = width;
     switch (style)
     {
         case "solid":
             p.DashStyle = RDashStyle.Solid;
             break;
         case "dotted":
             p.DashStyle = RDashStyle.Dot;
             break;
         case "double":
             p.DashStyle = RDashStyle.Solid;
             break;
         case "dashed":
             p.DashStyle = RDashStyle.Dash;
             break;
     }
     return p;
 }
예제 #14
0
 protected override RBrush CreateSolidBrush(RColor color)
 {
     return new BrushAdapter(GetSolidColorBrush(color));
 }
예제 #15
0
 /// <summary>
 /// Get cached solid brush instance for the given color.
 /// </summary>
 /// <param name="color">the color to get brush for</param>
 /// <returns>brush instance</returns>
 protected abstract RBrush CreateSolidBrush(RColor color);
예제 #16
0
 protected override RPen CreatePen(RColor color)
 {
     return new PenAdapter(GetSolidColorBrush(color));
 }
예제 #17
0
 protected override RBrush CreateLinearGradientBrush(RRect rect, RColor color1, RColor color2, double angle)
 {
     return new BrushAdapter(new LinearGradientBrush(Utils.Convert(rect), Utils.Convert(color1), Utils.Convert(color2), (float)angle), true);
 }
예제 #18
0
 protected override RPen CreatePen(RColor color)
 {
     return new PenAdapter(new XPen(Utils.Convert(color)));
 }
예제 #19
0
 /// <summary>
 /// Convert from core color to WPF color.
 /// </summary>
 public static Color Convert(RColor c)
 {
     return Color.FromArgb(c.A, c.R, c.G, c.B);
 }
예제 #20
0
 public override void DrawString(string str, RFont font, RColor color, RPoint point, RSize size, bool rtl)
 {
     var xBrush = ((BrushAdapter)_adapter.GetSolidBrush(color)).Brush;
     _g.DrawString(str, ((FontAdapter)font).Font, (XBrush)xBrush, point.X, point.Y, _stringFormat);
 }
예제 #21
0
 /// <summary>
 /// Get cached pen instance for the given color.
 /// </summary>
 /// <param name="color">the color to get pen for</param>
 /// <returns>pen instance</returns>
 public RPen GetPen(RColor color)
 {
     RPen pen;
     if (!_penCache.TryGetValue(color, out pen))
     {
         _penCache[color] = pen = CreatePen(color);
     }
     return pen;
 }
예제 #22
0
 /// <summary>
 /// Get color pen.
 /// </summary>
 /// <param name="color">the color to get the pen for</param>
 /// <returns>pen instance</returns>
 public RPen GetPen(RColor color)
 {
     return _adapter.GetPen(color);
 }
예제 #23
0
 /// <summary>
 /// Get cached solid brush instance for the given color.
 /// </summary>
 /// <param name="color">the color to get brush for</param>
 /// <returns>brush instance</returns>
 public RBrush GetSolidBrush(RColor color)
 {
     RBrush brush;
     if (!_brushesCache.TryGetValue(color, out brush))
     {
         _brushesCache[color] = brush = CreateSolidBrush(color);
     }
     return brush;
 }
예제 #24
0
 /// <summary>
 /// Get linear gradient color brush from <paramref name="color1"/> to <paramref name="color2"/>.
 /// </summary>
 /// <param name="rect">the rectangle to get the brush for</param>
 /// <param name="color1">the start color of the gradient</param>
 /// <param name="color2">the end color of the gradient</param>
 /// <param name="angle">the angle to move the gradient from start color to end color in the rectangle</param>
 /// <returns>linear gradient color brush instance</returns>
 public RBrush GetLinearGradientBrush(RRect rect, RColor color1, RColor color2, double angle)
 {
     return _adapter.GetLinearGradientBrush(rect, color1, color2, angle);
 }
예제 #25
0
 /// <summary>
 /// Get linear gradient color brush from <paramref name="color1"/> to <paramref name="color2"/>.
 /// </summary>
 /// <param name="rect">the rectangle to get the brush for</param>
 /// <param name="color1">the start color of the gradient</param>
 /// <param name="color2">the end color of the gradient</param>
 /// <param name="angle">the angle to move the gradient from start color to end color in the rectangle</param>
 /// <returns>linear gradient color brush instance</returns>
 protected abstract RBrush CreateLinearGradientBrush(RRect rect, RColor color1, RColor color2, double angle);
예제 #26
0
 public override void DrawString(string str, RFont font, RColor color, RPoint point, RSize size, bool rtl)
 {
     var text = GetText(str, font);
     text.Constraint = Util.Convert(size);
     _g.DrawText(new SolidColorBrush(Util.Convert(color)), Util.Convert(point), text);
 }
예제 #27
0
        public override void DrawString(string str, RFont font, RColor color, RPoint point, RSize size, bool rtl)
        {
            if (_useGdiPlusTextRendering)
            {
                ReleaseHdc();
                SetRtlAlignGdiPlus(rtl);
                var brush = ((BrushAdapter)_adapter.GetSolidBrush(color)).Brush;
                _g.DrawString(str, ((FontAdapter)font).Font, brush, (int)(Math.Round(point.X) + (rtl ? size.Width : 0)), (int)Math.Round(point.Y), _stringFormat2);
            }
            else
            {
#if !MONO
                var pointConv = Utils.ConvertRound(point);
                var colorConv = Utils.Convert(color);

                if (color.A == 255)
                {
                    SetFont(font);
                    SetTextColor(colorConv);
                    SetRtlAlignGdi(rtl);

                    Win32Utils.TextOut(_hdc, pointConv.X, pointConv.Y, str, str.Length);
                }
                else
                {
                    InitHdc();
                    SetRtlAlignGdi(rtl);
                    DrawTransparentText(_hdc, str, font, pointConv, Utils.ConvertRound(size), colorConv);
                }
#endif
            }
        }