# Lazarus

## Programming => Graphics and Multimedia => Graphics => Topic started by: xinyiman on October 01, 2018, 12:13:31 pm

Title: Draw on image and get proportional coordinates
Post by: xinyiman on October 01, 2018, 12:13:31 pm
Hi guys, I have a need. I have to draw some dots on a proportional image and then if I click on one of the dots with the mouse, I have to return the id of the dot. So to understand we have to draw a football field, then above the disposition of the players, the problem is that the field must be resizable. I attach a project that does not work as I would like.

Url of example:
www.lazaruspascal.it/esempi/test_cc.zip
Title: Re: Draw on image and get proportional coordinates
Post by: GetMem on October 01, 2018, 01:29:47 pm
You're method seems overcomplicated to me. Why don't you use regions to determine the position of the players?
Title: Re: Draw on image and get proportional coordinates
Post by: xinyiman on October 01, 2018, 02:17:51 pm
How? One example
Title: Re: Draw on image and get proportional coordinates
Post by: GetMem on October 01, 2018, 02:20:05 pm
Quote
How? One example
Here you go:
Code: Pascal  [Select]
1. uses LCLType, LCLIntf;
2.
3. type
4.   TData = record
5.     FX, FY, FR: Integer;
6.     FRgn: HRGN;
7.   end;
8.
9. var
10.   Data: array of TData;
11.
12. procedure TForm1.FormCreate(Sender: TObject);
13. begin
14.   //just some random circles
15.   SetLength(Data, 3);
16.   with Data[0] do
17.   begin
18.     FX := 10; FY := 10; FR := 30;
19.     FRgn := CreateEllipticRgn(FX, FY, FX + FR, FY + FR);
20.   end;
21.
22.   with Data[1] do
23.   begin
24.     FX := 120; FY := 130; FR := 30;
25.     FRgn := CreateEllipticRgn(FX, FY, FX + FR, FY + FR);
26.   end;
27.
28.   with Data[2] do
29.   begin
30.     FX := 100; FY := 40; FR := 30;
31.     FRgn := CreateEllipticRgn(FX, FY, FX + FR, FY + FR);
32.   end;
33. end;
34.
35. procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
36.   Shift: TShiftState; X, Y: Integer);
37. var
38.   Res: Bool;
39.   I: Integer;
40. begin
41.   for I := Low(Data) to High(Data) do
42.   begin
43.     Res := PtInRegion(Data[I].FRgn, X, Y);
44.     if Res then
45.     begin
46.       ShowMessage('You clicked circle ' + IntToStr(I + 1));
47.       Break;
48.     end;
49.   end;
50. end;
51.
52. procedure TForm1.FormPaint(Sender: TObject);
53. var
54.   I: Integer;
55. begin
56.   with Self.Canvas do
57.   begin
58.     Pen.Width := 2;
59.     Pen.Color := clBlack;
60.     Brush.Color := clRed;
61.  end;
62.
63.  for I := Low(Data) to High(Data) do
64.    Self.Canvas.Ellipse(Data[I].FX, Data[I].FY, Data[I].FX + Data[I].FR, Data[I].FY + Data[I].FR);
65. end;
66.
Title: Re: Draw on image and get proportional coordinates
Post by: xinyiman on October 01, 2018, 04:45:41 pm
Thank you very much