Advertisement
Guest User

Untitled

a guest
Oct 7th, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1.  
  2.  
  3. open System.Windows.Forms
  4. open System.Drawing
  5.  
  6. let DEF_SPEED()=new PointF(0.f,0.f) //velocità di default
  7. let DEF_DENSITY= 1.f
  8.  
  9. let f= new Form(TopMost=true)
  10.  
  11. f.Size <- Size(800,600)
  12.  
  13. f.Show()
  14.  
  15. type Pyshape(d:float32,v:PointF) =
  16. let mutable density = d
  17. let mutable speed = v
  18. abstract member drawshape:Graphics -> unit
  19. default this.drawshape(g:Graphics) = (printfn "metodo del supertipo")
  20.  
  21. type Circle(d,v,c:PointF,r:float32) =
  22. inherit Pyshape(d,v)
  23. let mutable rad = r
  24. let mutable center = c
  25. let mutable mass = r*r*(single System.Math.PI)*d
  26. let getRadius() = r
  27. let setRadius(r1) =
  28. rad <- r1;
  29. override this.drawshape (g:Graphics)=
  30. g.FillEllipse(Brushes.Aquamarine, int center.X - int rad, int center.Y - int rad, 2* int rad, 2* int rad)
  31.  
  32.  
  33.  
  34. type Editor() =
  35. inherit UserControl()
  36.  
  37. let shapes= new System.Collections.Generic.List<Pyshape>()
  38. let mutable tool=0
  39. let mutable tmp_radius = 0.f
  40. let mutable tmp_center = new PointF()
  41. let mutable drawing = false
  42.  
  43. let abort() =
  44. match tool with
  45. |0->
  46. drawing <- false
  47. tmp_radius <- 0.f;
  48. | _ -> ()
  49.  
  50. let acquireShape(list:System.Collections.Generic.List<Pyshape>)=
  51. match tool with
  52. |1->
  53. let c= new Circle(DEF_DENSITY,DEF_SPEED(),tmp_center,tmp_radius)
  54. list.Add(c)
  55. |_-> ()
  56. let pitagora(x1:float32,y1:float32,x2:float32,y2:float32) =
  57. sqrt( (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2) )
  58.  
  59. override this.OnMouseDown e=
  60. let tmp_loc = e.Location
  61. tmp_center <- PointF(single tmp_loc.X, single tmp_loc.Y)
  62. drawing <- true;
  63.  
  64.  
  65. override this.OnMouseMove e=
  66. let tmp_loc = new PointF(single e.Location.X,single e.Location.Y)
  67. match drawing with
  68. |true ->
  69. tmp_radius <- pitagora(tmp_loc.X,tmp_loc.Y,tmp_center.X,tmp_center.Y)
  70. this.Invalidate()
  71.  
  72. |false ->
  73. this.Invalidate()
  74.  
  75. override this.OnMouseUp e=
  76. match drawing with
  77. |true ->
  78. acquireShape(shapes)
  79. drawing <- false;
  80. tmp_radius <- 0.f;
  81. this.Invalidate()
  82. |false ->()
  83.  
  84. override this.OnKeyDown e=
  85.  
  86. match e.KeyCode with
  87. |Keys.Escape ->
  88. match drawing with
  89. |true ->
  90. abort()
  91. this.Invalidate()
  92. | _ -> ()
  93. | _ -> ()
  94.  
  95. override this.OnPaint e =
  96. let g = e.Graphics
  97.  
  98. g.DrawEllipse(Pens.Black, int tmp_center.X - int tmp_radius, int tmp_center.Y - int tmp_radius, 2* int tmp_radius, 2* int tmp_radius);
  99. for c in shapes do(
  100. c.drawshape(g)
  101. )
  102. let e=new Editor(Dock=DockStyle.Fill)
  103.  
  104. f.Controls.Add(e)
  105.  
  106. e.Focus()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement