ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 How to Click instead of drag when selecting
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

AndyColmes

USA
351 Posts

Posted - Jan 29 2016 :  15:11:41  Show Profile  Reply
Hello,

I would like to click on one point and another to make a rectangular selection instead of the usual click, hold and drag. Is this possible?

Thanks in advance.

Andy

w2m

USA
1990 Posts

Posted - Jan 29 2016 :  16:04:37  Show Profile  Reply
Of course ImageEn does not allow this per say, but it can be achieved. This can be awkward depending on what your goal is and I would not recommend it, but try this:

var
APoint: TPoint;
APoint2: TPoint;

procedure TForm1.FormCreate(Sender: TObject);
begin
  APoint := Point(-1,-1);
  APoint2 := Point(-1,-1);
end;

procedure TForm1.ImageEnView1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if APoint.X < 0 then
  begin
    APoint := Point(X,Y);
    exit;
  end;
  if APoint.X > 0 then
     APoint2 := Point(X,Y);
  if (SelectOnClick1.Down) and (APoint.X > 0) and (APoint2.X > 0) then
    ImageEnView1.Select(APoint.X, APoint.Y, APoint2.X, APoint2.Y);
end;

On the first click the point of the click is set. On the second click the second point is set. If the points are set then make the selection with ImageEnView1.Select. You will have to add a button or menu item to deselect I(ImageEnView1.Deselect) if you want to clear the selection, and to reset the points to allow making a subsequent selection. You will have to figure out a way to do this to enable dragging the selection after the second click. This code fragment does not allow dragging the selection.

There may be better ways to achieve this, but you will have to do it all in your own code.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Jan 30 2016 :  11:16:09  Show Profile  Reply
Hello Bill, thank you for the code snippet. I will give it a try. I saw this feature in Farstone Capture and I thought it is very neat and easier for the user to make a selection, especially if the selecting is a difficult one.

Thanks again.

Andy
Go to Top of Page

w2m

USA
1990 Posts

Posted - Jan 30 2016 :  14:07:27  Show Profile  Reply
Where do you see click selection in Farstone? My copy of Farstone uses the default ImageEn selections?

This code is a little better than the previous code as the selection can be cleared by clicking outside of the selection and the selection may be dragged and resized as well.

 { Private declarations }
 AClickCount: Integer;
 AStartX: Integer;
 AStartY: Integer;
 AEndX: Integer;
 AEndY: Integer;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ImageEnView1.MouseInteract := [miSelect];
  AClickCount := 0;
end;

procedure TForm1.ImageEnView1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
{ This allows making a selection with two mouse clicks.  Clicking outside of the selection clears the selection }
 { A selection may be moved or resized. }
begin
  if ClickSelect1.Checked then
  begin
    Inc(AClickCount);
    {If selected and clicked outside of selection then deselect}
    if (ImageEnView1.Selected) and
      (not ImageEnView1.IsPointInsideSelection(X, Y)) and (AClickCount >= 3)
    then
    begin
      ImageEnView1.DeSelect;
      AClickCount := 0;
      AStartX := -1;
      AStartY := -1;
      AEndX := -1;
      AEndY := -1;
      exit;
    end;
    if not ImageEnView1.IsPointInsideSelection(X, Y) then
    begin
      if AClickCount = 1 then
      begin
       { set point 1 }
        AStartX := X;
        AStartY := Y;
        Exit;
      end;
      if AClickCount = 2 then
      begin
        { set point 2 }
        AEndX := X;
        AEndY := Y;
        ImageEnView1.Select(AStartX, AStartY, AEndX, AEndY);
      end;
    end;
  end;
  {Note: ImageEnView1.MouseInteract must be [miSelect], otherwise cursor handling must be handled in order to have the correct cursors appear when the mouse is inside the selection or over the resizing grips.
   In addition code to drag or resize the selection must be added if MouseInteract is not [miSelect] }
end;

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Feb 15 2016 :  13:23:59  Show Profile  Reply
Hello Bill, sorry for the delay. I will give the code a try.

I was wrong about the FarStone. I meant to say FastStone Capture.

Andy
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: