Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System.Windows.Forms
- open System.Drawing
- let cx, cy = 100.f , 100.f
- let mutable selected = false
- type Editor() as this =
- inherit UserControl()
- do
- this.SetStyle(ControlStyles.DoubleBuffer, true)
- this.SetStyle(ControlStyles.UserPaint,true)
- this.SetStyle(ControlStyles.AllPaintingInWmPaint, true)
- let HitTest (p:Point) (h:Point) =
- //p è il punto dove sta cliccando il mouse
- //h è l'estremo del segmento
- let centrox = float(cx)
- let centroy = float(cy)
- let h1x = float(h.X)
- let h1y = float(h.Y)
- let p1x = float(p.X)
- let p1y = float(p.Y)
- let m1 = ((h1y - centroy) / (h1x - centrox)) //coeff angolare retta centro segmento
- let m2 = ((p1y - centroy) / (p1x - centrox)) //coeff angolare retta punto cliccato
- if (centrox < h1x) then
- if (centroy < h1y) then
- (m1 = m2) && (centrox < p1x) && (p1x <= h1x) && (centroy < p1y) && (p1y <= h1y)
- else
- (m1 = m2) && (centrox < p1x) && (p1x <= h1x) && (h1y < p1y) && (p1y <= centroy)
- else
- if (centroy < h1y) then
- (m1 = m2) && (h1x < p1x) && (p1x <= centrox) && (centroy < p1y) && (p1y <= h1y)
- else
- (m1 = m2) && (h1x < p1x) && (p1x <= centrox) && (h1y < p1y) && (p1y <= centroy)
- override this.OnPaint e = (
- let g = e.Graphics
- g.SmoothingMode <- Drawing2D.SmoothingMode.HighQuality
- g.TranslateTransform(cx, cy)
- g.RotateTransform(-90.f)
- let mutable t = System.DateTime.Now
- t <- t.AddHours(1.)
- let mutable s = g.Save()
- g.RotateTransform(single((t.Hour % 12) * 30))
- g.DrawLine(Pens.Black, -5, 0, 60, 0)
- g.Restore(s)
- s <- g.Save()
- g.RotateTransform(single(t.Minute * 6))
- g.DrawLine(Pens.Black, -5, 0, 75, 0)
- g.Restore(s)
- s <- g.Save()
- g.RotateTransform(single(t.Second * 6))
- g.DrawLine(Pens.Red, -5, 0, 75, 0)
- )
- override this.OnMouseDown e = (
- let clicked = e.Location
- printfn "%d %d" clicked.X clicked.Y
- let t1 = System.DateTime.Now
- let an = (float(((t1.Hour % 12) * 30) / 180)) * System.Math.PI
- let hour = new Point (int(sin(an)* float(90)), int( cos (an) * float(90)) )
- selected <- HitTest clicked hour
- // if not selected then
- // let an = (float((t1.Minute * 6) / 180)) * System.Math.PI
- // let min = new Point (int(sin(an)* float(90)), int( cos (an) * float(90)) )
- // selected <- HitTest clicked min
- if selected then
- printfn "ok troia"
- else
- printfn "tu ma puttana"
- )
- override this.OnMouseUp e = ()
- override this.OnMouseMove e = ()
- let f = new Form(Text="Adjustable Clock", Dock=DockStyle.Fill, TopMost=true)
- f.Show()
- f.Paint.Add(fun e ->
- let g = e.Graphics
- g.SmoothingMode <- Drawing2D.SmoothingMode.HighQuality
- g.FillEllipse(Brushes.Aquamarine, 0, 0, 200, 200)
- g.TranslateTransform(cx, cy)
- g.RotateTransform(-90.f)
- g.FillEllipse(Brushes.Black, -5, -5, 10, 10)
- let mutable s = g.Save()
- for i = 1 to 12 do
- g.DrawLine(Pens.Black, 90, 0, 100, 0)
- g.RotateTransform(30.f)
- g.Restore(s)
- s <- g.Save()
- for i = 1 to 60 do
- g.DrawLine(Pens.Black, 95, 0, 100, 0)
- g.RotateTransform(6.f)
- g.Restore(s)
- )
- let lanc = new Editor(Dock=DockStyle.Fill)
- f.Controls.Add(lanc)
- lanc.BackColor <- Color.Transparent
- let timer = new Timer(Interval=1000)
- timer.Start()
- timer.Tick.Add(fun _ ->
- lanc.Invalidate()
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement