Advertisement
wandrake

Untitled

Feb 22nd, 2012
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.56 KB | None | 0 0
  1. // Ulteriori informazioni su F# all'indirizzo http://fsharp.net
  2.  
  3. open System
  4. open System.Drawing
  5. open System.Windows.Forms
  6.  
  7. let form =
  8.     let temp = new Form(Text = "Ciao!", Height = 600, Width = 800)
  9.  
  10.     let pointsMasterList = ref []
  11.     let pointsTempList = ref[]
  12.     let mouseDown = ref false
  13.     let pen = ref(new Pen(Color.Black))
  14.  
  15.     temp.MouseDown.Add(fun _ -> mouseDown := true)
  16.  
  17.     let leftMouse, rightMouse =
  18.         temp.MouseDown
  19.         |> Event.partition (fun e -> e.Button = MouseButtons.Left)
  20.  
  21.     leftMouse.Add(fun _ -> pen := new Pen(Color.Black))
  22.     rightMouse.Add(fun _ -> pen := new Pen(Color.Red))
  23.  
  24.     let mouseUp _ =
  25.         mouseDown := false
  26.         if List.length !pointsTempList > 1 then
  27.             let points = List.toArray !pointsTempList
  28.             pointsMasterList :=
  29.                 (!pen, points) :: !pointsMasterList
  30.         pointsTempList := []
  31.         temp.Invalidate()
  32.  
  33.     let mouseMove (e: MouseEventArgs) =
  34.         pointsTempList := e.Location :: !pointsTempList
  35.         temp.Invalidate()
  36.  
  37.     let paint (e: PaintEventArgs) =
  38.         if List.length !pointsTempList > 1 then
  39.             e.Graphics.DrawLines
  40.                 (!pen, List.toArray !pointsTempList)
  41.         !pointsMasterList
  42.         |> List.iter
  43.             (fun (pen, points) ->
  44.                 e.Graphics.DrawLines(pen, points))
  45.  
  46.     temp.MouseUp |> Event.add mouseUp
  47.     temp.MouseMove
  48.         |> Event.filter(fun _ -> !mouseDown)
  49.         |> Event.add mouseMove
  50.  
  51.     temp.Paint |> Event.add paint
  52.  
  53.     temp
  54.  
  55. Application.Run(form)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement