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
 Cursor Position over vector canvas
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

John

USA
94 Posts

Posted - Oct 15 2013 :  21:56:47  Show Profile  Reply
Hello

Using a button.OnClick event I would like to be able to toggle on/off the ability to display the x and y coordinates of the cursor (an arrow) as I move the cursor over an ImageEnVect component with a mouse. The code would be placed in the OnMouseMove event.

I could find no mechanism to accomplish this. Does anyone have a suggestion?

TIA

John

xequte

39109 Posts

Posted - Oct 16 2013 :  02:09:47  Show Profile  Reply
Hi John

This would be fairly easy to accomplish.

In the MouseMove event you would save the current X and Y, then invalidate the control.

In the OnDrawCanvasyou would then output the text (e.g. using TCanvas.TextOut):

http://www.imageen.com/help/TImageEnView.OnDrawCanvas.html


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

John

USA
94 Posts

Posted - Oct 16 2013 :  22:06:00  Show Profile  Reply
Nigel

Thanks for the reply, but I am still missing something. Actually, I suspect it relates to your comments about invalidating the control.

Using the ImageEn AdvancedText demo I have added the two procedures below.

procedure TForm1.ImageEnVect1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  tempCurrent_X := X;
  tempCurrent_Y := Y;

  if tempDisplayCurrentPosition = True then  // variable attached to the Down property of a SpeedButton
    begin
      EditCurrentX.Text := IntToStr(tempCurrent_X);
      EditCurrentY.Text := IntToStr(tempCurrent_Y);

      if ImageEnVect1.ObjectsCount >= 1 then
        begin
          ImageEnVect1.RemoveObject(-2);
        end;

      tempLastAnnot_ID := ImageEnVect1.AddNewObject(iekLINELABEL, Rect(tempCurrent_X, tempCurrent_Y, 
                                                                   tempCurrent_X + 150, tempCurrent_Y), clRed);
      ImageEnVect1.ObjText[-2] :=  'Cursor Position - X = ' + IntToStr(tempCurrent_X) + '  Y = ' + IntToStr(tempCurrent_Y);

    end;

  Edit1.Text := 'Cursor Position - X = ' + IntToStr(tempCurrent_X) + '  Y = ' + IntToStr(tempCurrent_Y);
end;

procedure TForm1.ImageEnVect1DrawCanvas(Sender: TObject; ACanvas: TCanvas; ARect: TRect);
begin
  if tempDisplayCurrentPosition = True then
    begin
     ACanvas.TextOut(100, 100, 'Cursor Position - X = ' + IntToStr(tempCurrent_X) + '  Y = ' + IntToStr(tempCurrent_Y));
    end;
end;

Scenario A)
With the above code, both the Edit1 and ACanvas.TextOut text displays as expected.  In addition. the iekLineLabel follows the cursor and displays the ObjText. 


Scenario B) 
If I remark out the following two lines of code in the MouseMove event, both the iekLineLable and the ACanvas.TextOut components disappear.  

// tempLastAnnot_ID := ImageEnVect1.AddNewObject(iekLINELABEL, Rect(tempCurrent_X, tempCurrent_Y, 
//                                                           tempCurrent_X + 150, tempCurrent_Y), clRed);
// ImageEnVect1.ObjText[-2] :=  'Cursor Position - X = ' + IntToStr(tempCurrent_X) + '  Y = ' + IntToStr(tempCurrent_Y);

I suspect the answer relates to your comment about invalidation, but since the ACanvas.TextOut does not return a parameter I am stumped. Can you explain how to display and update the ACanvas.TextOut when the mouse moves without including the iekLineLabel?

TIA

John

Go to Top of Page

xequte

39109 Posts

Posted - Oct 17 2013 :  13:47:14  Show Profile  Reply
Hi John

You need to tell the control that needs to be repainted so that it clears the old content and calls ImageEnVect1DrawCanvas again.

You are doing this indirectly when you change the objects on the TImageEnVect because it forces the control to repaint itself, but you can also do it by calling invalidate (repaint or update will also work but there will likely be performance issues).

i.e.

procedure TForm1.ImageEnVect1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  tempCurrent_X := X;
  tempCurrent_Y := Y;

  if tempDisplayCurrentPosition = True then  // variable attached to the Down property of a SpeedButton
  begin
    EditCurrentX.Text := IntToStr(tempCurrent_X);
    EditCurrentY.Text := IntToStr(tempCurrent_Y);
    ImageEnVect1.Invalidate;
  end;

  Edit1.Text := 'Cursor Position - X = ' + IntToStr(tempCurrent_X) + '  Y = ' + IntToStr(tempCurrent_Y);
end;



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

John

USA
94 Posts

Posted - Oct 18 2013 :  13:24:40  Show Profile  Reply
Nigel

Thanks for the explanation

John
Go to Top of Page

John

USA
94 Posts

Posted - Nov 06 2013 :  20:53:32  Show Profile  Reply
The scenario involves an image being loaded into a vector canvas and ImageEnVect.Fit being called which results in either left and right borders on each side of the image or top and bottom borders.

With the discussion earlier in this thread, one can see how to locate the X coordinates in the case of left and right borders or the Y coordinates in the case of top and bottom borders using the OnMouseMove event. The question is whether there is a mechanism to identify these coordinates via code, i.e. without dynamic action by the user? These coordinates would obviously change as the size and proportion of the vector canvas changed so I would anticipate that they could also be called via the OnResize event.

TIA


John
Go to Top of Page

xequte

39109 Posts

Posted - Nov 09 2013 :  12:49:43  Show Profile  Reply
Hi John

Sorry I should have advised you to convert the screen coordinates to BMP ones using XScr2Bmp/YScr2Bmp.

I.e.

procedure TForm1.ImageEnVect1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  tempCurrent_X := XScr2Bmp(X);
  tempCurrent_Y := YScr2Bmp(Y);
...


Then the border of the image and use of Fit won't matter.

Does that cover it?



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

John

USA
94 Posts

Posted - Nov 10 2013 :  22:24:38  Show Profile  Reply
Nigel

Yes, that is exactly what I needed.

Thanks

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