web_color GetDefaultFontColor() { var defaultColor = UIColor.DarkTextColor; // Use components for color values because AppKit.NSColor.LabelColor (and others) // do not work with NSColor.GetRgba or NSColor.GetComponents var components = defaultColor.CGColor.Components; var retVal = new web_color(); if (components.Length == 2) { retVal.red = retVal.green = retVal.blue = (byte)(byte.MaxValue * components[0]); retVal.alpha = (byte)(byte.MaxValue * components[1]); } else if (components.Length == 4) { retVal.red = (byte)(byte.MaxValue * components[0]); retVal.green = (byte)(byte.MaxValue * components[1]); retVal.blue = (byte)(byte.MaxValue * components[2]); retVal.alpha = (byte)(byte.MaxValue * components[3]); } else { // Default to Black retVal.red = retVal.green = retVal.blue = 0; retVal.alpha = byte.MaxValue; } return(retVal); }
public void assignTo(background val) { attachment = val._attachment; baseurl = val._baseurl; image = val._image; repeat = val._repeat; color = val._color; }
protected override void DrawText(string text, UIntPtr font, ref web_color color, ref position pos) { text = text.Replace(' ', (char)160); var fontInfo = GetFont(font); var formattedText = fontInfo.GetFormattedText(text); formattedText.SetForegroundBrush(color.GetBrush()); DrawingContext.DrawText(formattedText, new Point(pos.x, pos.y)); }
public void draw_text(object hdc, string text, object hFont, web_color color, position pos) { apply_clip((Graphics)hdc); var rcText = new RectangleF(pos.left, pos.top, pos.right, pos.bottom); var format = new StringFormat(); using (var brush = new SolidBrush(Color.FromArgb(color.red, color.green, color.blue))) ((Graphics)hdc).DrawString(text, (Font)hFont, brush, rcText, format); release_clip((Graphics)hdc); }
public background_paint() { color = new web_color(0, 0, 0, 0); position_x = 0; position_y = 0; position_z = 0; //:h3ml attachment = background_attachment.scroll; repeat = background_repeat.repeat; is_root = false; }
private void DrawCurvedPath(Point p1, Point p2, Point p3, Point p4, ref web_color color, double thickness) { var geometry = new PathGeometry(); PathSegmentCollection path = new PathSegmentCollection(); path.Add(new LineSegment(p2, true)); path.Add(new QuadraticBezierSegment(p3, p4, true)); geometry.Figures.Add(new PathFigure(p1, path, false)); DrawingContext.DrawGeometry(null, color.GetPen(thickness), geometry); }
public static Brush GetBrush(this web_color color) { var key = color.red.ToString() + color.green.ToString() + color.blue.ToString() + color.alpha.ToString(); if (!_brushes.TryGetValue(key, out var result)) { result = new SolidBrush(Color.FromArgb(color.alpha, color.red, color.green, color.blue)); _brushes.Add(key, result); } return(result); }
public static Pen GetPen(this web_color color, float thickness) { var key = color.red.ToString() + color.green.ToString() + color.blue.ToString() + thickness; if (!_pens.TryGetValue(key, out var result)) { var brush = color.GetBrush(); result = new Pen(brush, thickness); _pens.Add(key, result); } return(result); }
public void draw_text(object hdc, string text, object hFont, web_color color, position pos) { // https://stackoverflow.com/questions/6391911/c-sharp-winforms-anyone-know-of-a-c-sharp-gdi-library-not-slow-gdi var gdi = (Graphics)hdc; apply_clip(gdi); //var rcText = new Rectangle(pos.left, pos.top, pos.right, pos.bottom); TextRenderer.DrawText(gdi, text, (Font)hFont, new Point(pos.left, pos.top), Color.FromArgb(color.red, color.green, color.blue)); //var rcText = new RectangleF(pos.left, pos.top, pos.right, pos.bottom); //var format = new StringFormat(); //using (var brush = new SolidBrush(Color.FromArgb(color.red, color.green, color.blue))) // gdi.DrawString(text, (Font)hFont, brush, rcText, format); release_clip(gdi); }
public static Pen GetPen(this web_color color, double thickness) { string key = color.red.ToString() + color.green.ToString() + color.blue.ToString() + thickness; Pen result = null; if (!_pens.TryGetValue(key, out result)) { Brush brush = color.GetBrush(); result = new Pen(brush, thickness); _pens.Add(key, result); } return(result); }
public background_paint(background_paint val) { image = val.image; baseurl = val.baseurl; attachment = val.attachment; repeat = val.repeat; color = val.color; clip_box = val.clip_box; origin_box = val.origin_box; border_box = val.border_box; border_radius = val.border_radius; image_size = val.image_size; position_x = val.position_x; position_y = val.position_y; position_z = val.position_z; //:h3ml is_root = val.is_root; }
public NSAttributedString GetAttributedString(string text, web_color color) { Attributes.ForegroundColor = color.ToCGColor(); // CoreText won't draw underlines for whitespace so draw a transparent dot if (text == " ") { text = "."; Attributes.ForegroundColor = new CGColor(0, 0, 0, 0); } else if (text == null) { text = ""; } var range = new NSRange(0, text.Length); var attrString = new NSMutableAttributedString(text, Attributes); // these styles can only be applied to the NSAttributedString if (Decoration.HasFlag(font_decoration.font_decoration_linethrough)) { attrString.AddAttribute((NSString)"NSStrikethrough", new NSNumber(1), range); } if (Decoration.HasFlag(font_decoration.font_decoration_underline)) { attrString.AddAttribute((NSString)"NSUnderline", new NSNumber(1), range); attrString.AddAttribute((NSString)"NSUnderlineColor", new NSObject(color.ToCGColor().Handle), range); } if (Decoration.HasFlag(font_decoration.font_decoration_overline)) { } if (Weight > 400) { #if __MOBILE__ var boldFontDescriptor = UIKit.UIFont.FromName(FaceName, Size).FontDescriptor.CreateWithTraits(UIKit.UIFontDescriptorSymbolicTraits.Bold); var boldFont = UIKit.UIFont.FromDescriptor(boldFontDescriptor, 0); attrString.AddAttribute(UIKit.UIStringAttributeKey.Font, boldFont, new NSRange(0, text.Length)); #else AppKit.NSMutableAttributedStringAppKitAddons.ApplyFontTraits(attrString, AppKit.NSFontTraitMask.Bold, new NSRange(0, text.Length)); #endif } return(attrString); }
public void draw_text(object hdc, string text, object hFont, web_color color, position pos) { var root = (GameObject)hdc; var font = ((UnityFont)hFont).Font; var obj = new GameObject("Text"); obj.transform.SetParent(root.transform); obj.transform.localPosition = ToUnityVector(new Vector3(pos.left, pos.top, pos.depth)); //obj.transform.localScale = new Vector3(1, 1, 0); var textMesh = obj.AddComponent <TextMesh>(); textMesh.font = font; textMesh.text = text; textMesh.color = new Color(color.red, color.green, color.blue); var mat = obj.GetComponent <MeshRenderer>().material; mat.mainTexture = font.material.mainTexture; mat.shader = Shader.Find("GUI/3D Text Shader"); }
protected override void DrawText(string text, UIntPtr fontId, ref web_color color, ref position pos) { var fontHolder = GetFont(fontId); var attrString = fontHolder.GetAttributedString(text, color); Context.SaveState(); Context.TranslateCTM(pos.x, pos.y + fontHolder.Attributes.Font.AscentMetric); Context.ScaleCTM(1, -1); Context.TextMatrix = CGAffineTransform.MakeIdentity(); /*Context.SetAllowsAntialiasing(true); * Context.SetShouldAntialias(true); * Context.SetAllowsFontSmoothing(true); * Context.SetShouldSmoothFonts(true);*/ using (var textLine = new CTLine(attrString)) { textLine.Draw(Context); } Context.RestoreState(); }
public css_border(css_border val) { width = val.width; style = val.style; color = val.color; }
public virtual void fill_rect(object hdc, position pos, web_color color, css_border_radius radius) { apply_clip((Graphics)hdc); fill_rect(hdc, pos.x, pos.y, pos.width, pos.height, color, radius); release_clip((Graphics)hdc); }
protected override void DrawBackground(UIntPtr hdc, string image, background_repeat repeat, ref web_color color, ref position pos, ref border_radiuses br, ref position borderBox, bool isRoot) { var cgColor = color.ToCGColor(); var rect = pos.ToRect(); if (string.IsNullOrEmpty(image)) { CGPath path = new CGPath(); path.MoveToPoint(rect.Left + br.top_left_x, rect.Top); path.AddLineToPoint(rect.Right - br.top_right_x, rect.Top); path.AddQuadCurveToPoint(rect.Right, rect.Top, rect.Right, rect.Top + br.top_right_y); path.AddLineToPoint(rect.Right, rect.Bottom - br.bottom_right_y); path.AddQuadCurveToPoint(rect.Right, rect.Bottom, rect.Right - br.bottom_right_x, rect.Bottom); path.AddLineToPoint(rect.Left + br.bottom_left_x, rect.Bottom); path.AddQuadCurveToPoint(rect.Left, rect.Bottom, rect.Left, rect.Bottom - br.bottom_left_y); path.AddLineToPoint(rect.Left, rect.Top + br.top_left_y); path.AddQuadCurveToPoint(rect.Left, rect.Top, rect.Left + br.top_left_x, rect.Top); Context.SetFillColor(cgColor); Context.AddPath(path); Context.FillPath(); } else { DrawImage(image, rect); } }
protected override void DrawListMarker(string image, string baseURL, list_style_type marker_type, ref web_color color, ref position pos) { DrawRect(pos.x, pos.y, pos.width, pos.height, color.GetBrush()); }
protected override void DrawListMarker(string image, string baseURL, list_style_type marker_type, ref web_color color, ref position pos) { Context.SetFillColor(color.ToCGColor()); switch (marker_type) { case list_style_type.list_style_type_square: Context.FillRect(pos.ToRect()); break; case list_style_type.list_style_type_circle: default: Context.FillEllipseInRect(pos.ToRect()); break; } }
public void draw_text(object hdc, string text, object hFont, web_color color, position pos) { }
protected void fill_rect(Graphics hdc, int x, int y, int width, int height, web_color color, css_border_radius radius) { var brush = new SolidBrush(Color.FromArgb(color.alpha, color.red, color.green, color.blue)); hdc.FillRectangle(brush, x, y, width, height); }
public static CGColor ToCGColor(this web_color wc) { return(new CGColor(wc.red / MaxByteAsFloat, wc.green / MaxByteAsFloat, wc.blue / MaxByteAsFloat, wc.alpha / MaxByteAsFloat)); }
public border(css_border val) { width = (int)val.width.val; style = val.style; color = val.color; }
public border(border val) { width = val.width; style = val.style; color = val.color; }
protected void fill_rect(GameObject hdc, int x, int y, int width, int height, web_color color, css_border_radius radius) { }
protected void draw_ellipse(GameObject hdc, int x, int y, int width, int height, web_color color, int line_width) { }
protected void fill_ellipse(Graphics hdc, int x, int y, int width, int height, web_color color) { hdc.CompositingQuality = CompositingQuality.HighQuality; hdc.SmoothingMode = SmoothingMode.AntiAlias; var brush = new SolidBrush(Color.FromArgb(color.alpha, color.red, color.green, color.blue)); hdc.FillEllipse(brush, x, y, width, height); }
protected void draw_ellipse(Graphics hdc, int x, int y, int width, int height, web_color color, int line_width) { hdc.CompositingQuality = CompositingQuality.HighQuality; hdc.SmoothingMode = SmoothingMode.AntiAlias; var pen = new Pen(Color.FromArgb(color.alpha, color.red, color.green, color.blue)); hdc.DrawEllipse(pen, x, y, width, height); }
protected override void DrawBackground(UIntPtr hdc, string image, background_repeat repeat, ref web_color color, ref position pos, ref border_radiuses br, ref position borderBox, bool isRoot) { if (pos.width > 0 && pos.height > 0) { if (!String.IsNullOrEmpty(image)) { var bitmap = LoadImage(image); if (bitmap != null) { DrawImage(bitmap, new Rect(pos.x, pos.y, pos.width, pos.height)); } } else { Rect rect = new Rect(pos.x, pos.y, pos.width, pos.height); var geometry = new PathGeometry(); PathSegmentCollection path = new PathSegmentCollection(); path.Add(new LineSegment(new Point(rect.Right - br.top_right_x, rect.Top), false)); path.Add(new QuadraticBezierSegment(new Point(rect.Right, rect.Top), new Point(rect.Right, rect.Top + br.top_right_y), false)); path.Add(new LineSegment(new Point(rect.Right, rect.Bottom - br.bottom_right_y), false)); path.Add(new QuadraticBezierSegment(new Point(rect.Right, rect.Bottom), new Point(rect.Right - br.bottom_right_x, rect.Bottom), false)); path.Add(new LineSegment(new Point(rect.Left + br.bottom_left_x, rect.Bottom), false)); path.Add(new QuadraticBezierSegment(new Point(rect.Left, rect.Bottom), new Point(rect.Left, rect.Bottom - br.bottom_left_y), false)); path.Add(new LineSegment(new Point(rect.Left, rect.Top + br.top_left_y), false)); path.Add(new QuadraticBezierSegment(new Point(rect.Left, rect.Top), new Point(rect.Left + br.top_left_x, rect.Top), false)); geometry.Figures.Add(new PathFigure(new Point(rect.Left + br.top_left_x, rect.Top), path, true)); DrawingContext.DrawGeometry(color.GetBrush(), null, geometry); } } }
protected void fill_ellipse(GameObject hdc, int x, int y, int width, int height, web_color color) { }