Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
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);
 }
 /// <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);
 }
Ejemplo n.º 5
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);
Ejemplo n.º 6
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;
 }
 /// <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;
 }
Ejemplo n.º 8
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;
 }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
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;
 }
Ejemplo n.º 11
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);
             }
             else if (length > 10 && CommonUtils.SubStringEquals(str, idx, 4, "rgb(") && str[length - 1] == ')')
             {
                 return GetColorByRgb(str, idx, length, out color);
             }
             else if (length > 13 && CommonUtils.SubStringEquals(str, idx, 5, "rgba(") && str[length - 1] == ')')
             {
                 return GetColorByRgba(str, idx, length, out color);
             }
             else
             {
                 return GetColorByName(str, idx, length, out color);
             }
         }
     }
     catch
     { }
     color = RColor.Black;
     return false;
 }
Ejemplo n.º 12
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);
Ejemplo n.º 13
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);
Ejemplo n.º 14
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);
Ejemplo n.º 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>
 public RBrush GetSolidBrush(RColor color)
 {
     RBrush brush;
     if (!_brushesCache.TryGetValue(color, out brush))
     {
         _brushesCache[color] = brush = CreateSolidBrush(color);
     }
     return brush;
 }
Ejemplo n.º 16
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;
 }