Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. (*Bachmann Gherhard 493593 - MidTerm di PI del 8/11/2016*)
  2.  
  3. #load "LWC.fsx"
  4. #load "IumButton.fsx"
  5.  
  6. open System.Windows.Forms
  7. open System.Drawing
  8. open LWC
  9. open IumButton
  10.  
  11. let f = new Form(Text="Editor PI",TopMost=true, Size=Size(980,600))
  12. f.Show()
  13.  
  14. type NavBut=
  15. | Load = 0
  16. | Save = 1
  17.  
  18. type NavBut2 =
  19. | Up = 0
  20. | Down = 1
  21. | Left = 2
  22. | Right = 3
  23. | RotateL = 4
  24. | RotateR = 5
  25. | ZoomUp = 6
  26. | ZoomDown = 7
  27. let mutable erase = false
  28.  
  29. type MyImage() as this =
  30. inherit LWC()
  31.  
  32. let mutable tasto = new NavBut()
  33. let mutable disegna = true
  34. let transformP (m:Drawing2D.Matrix) (p:PointF) =
  35. let a = [| PointF(single p.X, single p.Y) |]
  36. m.TransformPoints(a)
  37. a.[0]
  38.  
  39. member this.Tasto
  40. with get() = tasto
  41. and set(v) = tasto <- v
  42. member this.Disegna
  43. with get() = disegna
  44. and set(v) = disegna <- v
  45.  
  46. override this.OnMouseDown e =
  47. printfn "erase : %A" disegna
  48. if(erase) then
  49. disegna <- false
  50. //qui ci sara il selezionamento
  51.  
  52. base.OnMouseDown(e)
  53.  
  54. type MyEditor() as this =
  55. inherit LWContainer()
  56. do
  57. this.SetStyle(ControlStyles.DoubleBuffer,true)
  58. this.SetStyle(ControlStyles.AllPaintingInWmPaint,true)
  59. this.SetStyle(ControlStyles.UserPaint,true)
  60.  
  61. let mutable img : Image = null
  62. let mutable imglist = new ImageList()
  63. let mutable ratio = 0.
  64. let buttonsv = [|
  65. new IumButton(Text="Load",Location=PointF(0.f,single(f.ClientSize.Height)-64.f));
  66. new IumButton(Text="Save",Location=PointF(64.f,single(f.ClientSize.Height)-64.f));
  67. |]
  68.  
  69. do buttonsv |> Seq.iter (fun b ->
  70. b.Parent <- this;
  71. this.LWControls.Add(b)
  72. )
  73. do
  74. buttonsv.[int(NavBut.Load)].MouseDown.Add(fun _ ->
  75. if img = null then
  76. let od = new OpenFileDialog()
  77. od.CheckFileExists <- true
  78. if od.ShowDialog() = DialogResult.OK then
  79. img <- Bitmap.FromFile(od.FileName)
  80. imglist.Images.Add(img)
  81. ratio <- float(img.Width) / float(img.Height)
  82. this.Invalidate()
  83.  
  84. )
  85.  
  86. override this.OnResize _ = this.Invalidate()
  87.  
  88. override this.OnPaint e =
  89. let g = e.Graphics
  90.  
  91. if img <> null then
  92. let r = float(this.Width) / float(this.Height)
  93. let w, h =
  94. if r < ratio then
  95. (this.Width, int(float(this.Width) / ratio))
  96. else
  97. (int(float(this.Height) * ratio), this.Height)
  98. g.DrawImage(img, new Rectangle(0, 0, w, h))
  99.  
  100. let p = new MyEditor(Dock=DockStyle.Fill)
  101. f.Controls.Add(p)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement