Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*Bachmann Gherhard 493593 - MidTerm di PI del 8/11/2016*)
- #load "LWC.fsx"
- #load "IumButton.fsx"
- open System.Windows.Forms
- open System.Drawing
- open LWC
- open IumButton
- let f = new Form(Text="Editor PI",TopMost=true, Size=Size(980,600))
- f.Show()
- type NavBut=
- | Load = 0
- | Save = 1
- type NavBut2 =
- | Up = 0
- | Down = 1
- | Left = 2
- | Right = 3
- | RotateL = 4
- | RotateR = 5
- | ZoomUp = 6
- | ZoomDown = 7
- let mutable erase = false
- type MyImage() as this =
- inherit LWC()
- let mutable tasto = new NavBut()
- let mutable disegna = true
- let transformP (m:Drawing2D.Matrix) (p:PointF) =
- let a = [| PointF(single p.X, single p.Y) |]
- m.TransformPoints(a)
- a.[0]
- member this.Tasto
- with get() = tasto
- and set(v) = tasto <- v
- member this.Disegna
- with get() = disegna
- and set(v) = disegna <- v
- override this.OnMouseDown e =
- printfn "erase : %A" disegna
- if(erase) then
- disegna <- false
- //qui ci sara il selezionamento
- base.OnMouseDown(e)
- type MyEditor() as this =
- inherit LWContainer()
- do
- this.SetStyle(ControlStyles.DoubleBuffer,true)
- this.SetStyle(ControlStyles.AllPaintingInWmPaint,true)
- this.SetStyle(ControlStyles.UserPaint,true)
- let mutable img : Image = null
- let mutable imglist = new ImageList()
- let mutable ratio = 0.
- let buttonsv = [|
- new IumButton(Text="Load",Location=PointF(0.f,single(f.ClientSize.Height)-64.f));
- new IumButton(Text="Save",Location=PointF(64.f,single(f.ClientSize.Height)-64.f));
- |]
- do buttonsv |> Seq.iter (fun b ->
- b.Parent <- this;
- this.LWControls.Add(b)
- )
- do
- buttonsv.[int(NavBut.Load)].MouseDown.Add(fun _ ->
- if img = null then
- let od = new OpenFileDialog()
- od.CheckFileExists <- true
- if od.ShowDialog() = DialogResult.OK then
- img <- Bitmap.FromFile(od.FileName)
- imglist.Images.Add(img)
- ratio <- float(img.Width) / float(img.Height)
- this.Invalidate()
- )
- override this.OnResize _ = this.Invalidate()
- override this.OnPaint e =
- let g = e.Graphics
- if img <> null then
- let r = float(this.Width) / float(this.Height)
- let w, h =
- if r < ratio then
- (this.Width, int(float(this.Width) / ratio))
- else
- (int(float(this.Height) * ratio), this.Height)
- g.DrawImage(img, new Rectangle(0, 0, w, h))
- let p = new MyEditor(Dock=DockStyle.Fill)
- f.Controls.Add(p)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement