Guest User

Untitled

a guest
Oct 17th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. CGPath pathtotal;
  2. List<CGPath> path;
  3.  
  4. CGPoint initialPoint;
  5. CGPoint latestPoint;
  6.  
  7. DrawDrawerDraw drawDrawerDraw;
  8.  
  9. public DrawGuessView(IntPtr handle) : base(handle)
  10. {
  11. BackgroundColor = UIColor.White;
  12. pathtotal = new CGPath();
  13.  
  14. SocketEventHandler.Add("draw:drawer:draw", onDrawDrawerDraw);
  15. }
  16.  
  17. public void onDrawDrawerDraw(dynamic obj)
  18. {
  19. drawDrawerDraw = (DrawDrawerDraw)obj;
  20.  
  21. for (int i = 0; i <= drawDrawerDraw.coords.Count; i++)
  22. {
  23. if (initialPoint.X != (nfloat)drawDrawerDraw.coords[i].x0 && initialPoint.Y != (nfloat)drawDrawerDraw.coords[i].y0)
  24. {
  25. path[i] = new CGPath();
  26. }
  27.  
  28. initialPoint.X = (nfloat)drawDrawerDraw.coords[i].x0;
  29. initialPoint.Y = (nfloat)drawDrawerDraw.coords[i].y0;
  30.  
  31. latestPoint.X = (nfloat)drawDrawerDraw.coords[i].x1;
  32. latestPoint.Y = (nfloat)drawDrawerDraw.coords[i].y1;
  33.  
  34. //add lines to the touch points
  35. if (path[i].IsEmpty)
  36. {
  37. path[i].AddLines(new CGPoint[] { initialPoint, latestPoint });
  38. }
  39. else
  40. {
  41. path[i].AddLineToPoint(latestPoint);
  42. }
  43. }
  44.  
  45. SetNeedsDisplay();
  46. }
  47.  
  48. public override void Draw(CGRect rect)
  49. {
  50. base.Draw(rect);
  51.  
  52. try
  53. {
  54. foreach (var item in path)
  55. {
  56. if (!initialPoint.IsEmpty)
  57. {
  58. //get graphics context
  59. using (CGContext g = UIGraphics.GetCurrentContext())
  60. {
  61. //set up drawing attributes
  62. g.SetLineWidth(2);
  63. UIColor.Black.SetStroke();
  64.  
  65. //add geometry to graphics context and draw it
  66. pathtotal.AddPath(item);
  67.  
  68. g.AddPath(pathtotal);
  69. g.DrawPath(CGPathDrawingMode.Stroke);
  70. }
  71. }
  72. }
  73. }
  74. catch (Exception e) { }
  75. }
  76. }
Add Comment
Please, Sign In to add comment