madsobitsoe

Untitled

Jan 15th, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 2.84 KB | None | 0 0
  1. open System.Windows.Forms
  2. open System.Drawing
  3.  
  4. // Lave en display type, der arver fra Form.
  5. type Display() as form =
  6.     inherit Form()
  7.     let fwdButton = new Button ()
  8.     let bckButton = new Button ()
  9.     do form.init
  10.    
  11.     member this.init =
  12.         this.Text <- "Solar System Simulator"
  13.         this.ClientSize <- new Size(800, 600)
  14.         bckButton.Size <- new Size (120, 30)
  15.         bckButton.Location <- new Point (200, 550)
  16.         bckButton.Text <- "Go back in time"
  17.         fwdButton.Size <- new Size (120, 30)
  18.         fwdButton.Location <- new Point (400, 550)
  19.         fwdButton.Text <- "Progress Simulation"
  20. //        fwdButton.Click.Add (fun x -> printfn "Yo!" |> ignore)
  21.  
  22.         this.Controls.Add fwdButton
  23.         this.Controls.Add bckButton
  24.  
  25.     // Tag nogle funktioner og knyt dem til Mouseevents
  26.     member this.setMouseEventFunctions(l) =
  27.         let setEventFunction (tuple: (MouseEventArgs -> unit) * string) =
  28.             match tuple with
  29.             | (_,"mouseDown")  -> this.MouseDown.Add (fst tuple)
  30.                                   printfn "Added mouseDown"
  31.             | (_,"mouseUp")    -> this.MouseUp.Add (fst tuple)
  32.                                   printfn "Added mouseUp"
  33.             | (_,"mouseClick") -> this.MouseClick.Add (fst tuple)
  34.                                   printfn "Added mouseClick"
  35.             | _ -> printfn "Added nothing. \nFunction: %A\nString: %s"
  36.                             (fst tuple) (snd tuple)
  37.         List.map setEventFunction l
  38.     // Tag nogle funktioner og knyt dem til Events
  39.     member this.setButtonEventFunctions(l) =
  40.         let setEventFunction (tuple: (System.EventArgs -> unit) * string) =
  41.             match tuple with
  42.             | (_, "fwdButton") -> fwdButton.Click.Add (fst tuple)
  43.                                   printfn "Added fwdButton"
  44.             | (_, "bckButton") -> bckButton.Click.Add (fst tuple)
  45.                                   printfn "Added bckButton"
  46.             | _ -> printfn "Added nothing. \nFunction: %A\nString: %s"
  47.                             (fst tuple) (snd tuple)
  48.         List.map setEventFunction l
  49.  
  50. type Controller() as controller =
  51.     let myEvent a  (e:MouseEventArgs) =
  52.         printfn "Mouse%s: %A" a e.Location
  53.     let display = new Display()
  54.     do controller.init
  55.     member this.Display = display
  56.     member this.init =
  57.         printfn "Running init"
  58.         display.setMouseEventFunctions([
  59.             (myEvent("Down")               , "mouseDown");
  60.             (myEvent("Up")                 , "mouseUp");
  61.             (myEvent("Click")              , "mouseClick")]) |> ignore
  62.         display.setButtonEventFunctions([
  63.                     ((fun x -> printfn "Forward!") , "fwdButton");
  64.                     ((fun x -> printfn "Back!")    , "bckButton")]) |> ignore
  65.  
  66. let c = new Controller()
  67. Application.Run c.Display
Add Comment
Please, Sign In to add comment