How update correctly PO coordenates on code below?
Have a look at my code, I store the positions of
all 9 dots in my fDots[0..2,0..2] - array (.Pos is the center point, .Bounds is the bounding rectangle). This is done once in the CalcDotPositions method.
In the Paintbox MouseDown event I use the MouseNearDots()-function to see if the current mouse position (X,Y) is near of one of the nine dots. Drawing does
not start from anywhere, you need to be near of one of the dots (= bounding rectangle + MOUSE_SLACK).
If drawing starts I save the x/y-index of the starting dot within my fPO variable.
In PBMouseMove I also use MouseNearDots() to decide, if another dot (except already selected ones) is reached. If another dot is reached its fDots[].Selected member is set to TRUE, it is linked to the previous dot (.LinkTo := fPO)
and fPO is set to be the
new starting point (fPO := PointIdx())!
Otherwise just the current mouse position is stored (fCurPos).
Note that all drawing is done in the OnPaint event (first the nine dots are drawn, then all the segments wich are already connected and finally the current segment).
So I think you dont need just the size of your mobile devices screen, you also will need the positions of the nine dots to provide the correct coordinates for your .SendText function.
Another option might be the use of relative movement. In MouseDown you could use 'moveto' to provide the start coordinates and in MouseMove some sort of 'swipeto' which only sends the relative movement changes:
Code:
procedure TForm1.PBMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
fPO := Point(X,Y);
fDown := TRUE;
Form1.ServerSocket1.Socket.Connections[Index].SendText(format('moveto%d<|>%d'#13#10, [X,Y]));
end;
procedure TForm1.PBMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
if fDown then
begin
Form1.ServerSocket1.Socket.Connections[Index].SendText(format('swipeto%d<|>%d'#13#10, [X-fPO.X,Y-fPO.Y]));
fPO := Point(X,Y);
end;
end;
I can not test this, nor do I know if you are able to implement such commands on the mobile device. The main point here is to
not provide a line with always the same starting point but to just send the current mouse position (either relative like in the code above or may be even absolute).