コード例 #1
0
ファイル: RGraphics.cs プロジェクト: jcaillon/YamuiFramework
 /// <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);
 }
コード例 #2
0
ファイル: RGraphics.cs プロジェクト: jcaillon/YamuiFramework
 /// <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);
 }
コード例 #3
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
            }
        }
コード例 #4
0
ファイル: RGraphics.cs プロジェクト: jcaillon/YamuiFramework
 /// <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);
コード例 #5
0
ファイル: RAdapter.cs プロジェクト: jcaillon/YamuiFramework
 /// <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);
コード例 #6
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;
 }
コード例 #7
0
 /// <summary>
 /// Parses a color value in CSS style; e.g. #ff0000, RED, RGB(255,0,0), RGB(100%, 0, 0)
 /// </summary>
 /// <param name="str">color substring value to parse</param>
 /// <param name="idx">substring start idx </param>
 /// <param name="length">substring length</param>
 /// <param name="color">return the parsed color</param>
 /// <returns>true - valid color, false - otherwise</returns>
 public bool TryGetColor(string str, int idx, int length, out RColor color)
 {
     try
     {
         if (!string.IsNullOrEmpty(str)) {
             if (length > 1 && str[idx] == '#')
             {
                 return GetColorByHex(str, idx, length, out color);
             }
             if (length > 10 && CommonUtils.SubStringEquals(str, idx, 4, "rgb(") && str[length - 1] == ')')
             {
                 return GetColorByRgb(str, idx, length, out color);
             }
             if (length > 13 && CommonUtils.SubStringEquals(str, idx, 5, "rgba(") && str[length - 1] == ')')
             {
                 return GetColorByRgba(str, idx, length, out color);
             }
             return GetColorByName(str, idx, length, out color);
         }
     }
     catch
     { }
     color = RColor.Black;
     return false;
 }
コード例 #8
0
ファイル: RAdapter.cs プロジェクト: jcaillon/YamuiFramework
 /// <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;
 }
コード例 #9
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 "dashed":
             p.DashStyle = RDashStyle.Dash;
             break;
     }
     return p;
 }
コード例 #10
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);
 }
コード例 #11
0
        protected override RBrush CreateSolidBrush(RColor color)
        {
            Brush 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 SolidBrush(Utils.Convert(color));

            return new BrushAdapter(solidBrush, false);
        }
コード例 #12
0
 protected override RPen CreatePen(RColor color)
 {
     return new PenAdapter(new Pen(Utils.Convert(color)));
 }
コード例 #13
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);
 }
コード例 #14
0
ファイル: RAdapter.cs プロジェクト: jcaillon/YamuiFramework
 /// <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 CreateLinearGradientBrush(rect, color1, color2, angle);
 }
コード例 #15
0
 /// <summary>
 /// Get color by parsing given hex value color string (#A28B34).
 /// </summary>
 /// <returns>true - valid color, false - otherwise</returns>
 private static bool GetColorByHex(string str, int idx, int length, out RColor color)
 {
     int r = -1;
     int g = -1;
     int b = -1;
     if (length == 7)
     {
         r = ParseHexInt(str, idx + 1, 2);
         g = ParseHexInt(str, idx + 3, 2);
         b = ParseHexInt(str, idx + 5, 2);
     }
     else if (length == 4)
     {
         r = ParseHexInt(str, idx + 1, 1);
         r = r * 16 + r;
         g = ParseHexInt(str, idx + 2, 1);
         g = g * 16 + g;
         b = ParseHexInt(str, idx + 3, 1);
         b = b * 16 + b;
     }
     if (r > -1 && g > -1 && b > -1)
     {
         color = RColor.FromArgb(r, g, b);
         return true;
     }
     color = RColor.Empty;
     return false;
 }
コード例 #16
0
ファイル: RAdapter.cs プロジェクト: jcaillon/YamuiFramework
 /// <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;
 }
コード例 #17
0
        /// <summary>
        /// Get color by parsing given RGBA value color string (RGBA(255,180,90,180))
        /// </summary>
        /// <returns>true - valid color, false - otherwise</returns>
        private static bool GetColorByRgba(string str, int idx, int length, out RColor color)
        {
            int r = -1;
            int g = -1;
            int b = -1;
            int a = -1;

            if (length > 13)
            {
                int s = idx + 5;
                r = ParseIntAtIndex(str, ref s);

                if (s < idx + length)
                {
                    g = ParseIntAtIndex(str, ref s);
                }
                if (s < idx + length)
                {
                    b = ParseIntAtIndex(str, ref s);
                }
                if (s < idx + length)
                {
                    a = ParseIntAtIndex(str, ref s);
                }
            }

            if (r > -1 && g > -1 && b > -1 && a > -1)
            {
                color = RColor.FromArgb(a, r, g, b);
                return true;
            }
            color = RColor.Empty;
            return false;
        }
コード例 #18
0
ファイル: RAdapter.cs プロジェクト: jcaillon/YamuiFramework
 /// <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);
コード例 #19
0
 /// <summary>
 /// Get color by given name, including .NET name.
 /// </summary>
 /// <returns>true - valid color, false - otherwise</returns>
 private bool GetColorByName(string str, int idx, int length, out RColor color)
 {
     color = _adapter.GetColor(str.Substring(idx, length));
     return color.A > 0;
 }
コード例 #20
0
ファイル: RAdapter.cs プロジェクト: jcaillon/YamuiFramework
 /// <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);
コード例 #21
0
ファイル: Utils.cs プロジェクト: jcaillon/YamuiFramework
 /// <summary>
 /// Convert from core color to WinForms color.
 /// </summary>
 public static Color Convert(RColor c)
 {
     return Color.FromArgb(c.A, c.R, c.G, c.B);
 }