JC_
31-08-2013, 01:04 PM
There is a better solution to this simple problem? In array of points i will check if is mouse over one specific point[i] and if is on any of points.
after a long time.. :) i found this:
Type
TPoint2D = record
X, Y : Single; // position
mouseover : boolean; // mouse over specific point
Rect : TRect; // mouse vs point
end;
Var
Point : array of TPoint2D;
Count : integer;
selectedPointID : integer;
TrueCount, FalseCount : integer;
moveWithPoint : boolean;
..
Begin
trueCount := 0;
falseCount := 0;
for i := 0 to Count-1 do begin
// mouse over one specific point
if col2d_PointInRect( mousecur.x, mousecur.y, point[i].PointRect ) then
point[i].mouseover := true else point[i].mouseover := false;
// Mouseover
if Point[i].mouseover then begin
inc(trueCount);
if not moveWithPoint then selectedPointID := i + 1; // i can select only one point
end else
inc(falseCount);
// is any point selected ?
if falseCount = shape.count then
begin
selectedPointID := 0; // none
..
end;
// mouse button interaction, move with point
if mouse_Down( 0 ) and (selectedPointID > 0) then begin
moveWithPoint := true;
point[selectedPointID - 1].x := mousecur.x;
point[selectedPointID - 1].y := mousecur.y;
point[selectedPointID - 1].Rect.x := mousecur.x - 5;
point[selectedPointID - 1].Rect.y := mousecur.y - 5;
end;
if not mouse_Down( 0 ) then moveWithPoint := false;
after a long time.. :) i found this:
Type
TPoint2D = record
X, Y : Single; // position
mouseover : boolean; // mouse over specific point
Rect : TRect; // mouse vs point
end;
Var
Point : array of TPoint2D;
Count : integer;
selectedPointID : integer;
TrueCount, FalseCount : integer;
moveWithPoint : boolean;
..
Begin
trueCount := 0;
falseCount := 0;
for i := 0 to Count-1 do begin
// mouse over one specific point
if col2d_PointInRect( mousecur.x, mousecur.y, point[i].PointRect ) then
point[i].mouseover := true else point[i].mouseover := false;
// Mouseover
if Point[i].mouseover then begin
inc(trueCount);
if not moveWithPoint then selectedPointID := i + 1; // i can select only one point
end else
inc(falseCount);
// is any point selected ?
if falseCount = shape.count then
begin
selectedPointID := 0; // none
..
end;
// mouse button interaction, move with point
if mouse_Down( 0 ) and (selectedPointID > 0) then begin
moveWithPoint := true;
point[selectedPointID - 1].x := mousecur.x;
point[selectedPointID - 1].y := mousecur.y;
point[selectedPointID - 1].Rect.x := mousecur.x - 5;
point[selectedPointID - 1].Rect.y := mousecur.y - 5;
end;
if not mouse_Down( 0 ) then moveWithPoint := false;