Results 1 to 3 of 3

Thread: How simply check if mouse cursor is over specific point[i] and over of any ofpoints ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    How simply check if mouse cursor is over specific point[i] and over of any ofpoints ?

    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:

    Code:
    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;
    Last edited by JC_; 31-08-2013 at 04:36 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •