Comment je peux changer le system de coordonné du canvas ?

Résolu
MUFUSU Messages postés 2 Date d'inscription samedi 20 août 2005 Statut Membre Dernière intervention 21 août 2005 - 21 août 2005 à 00:28
neodelphi Messages postés 442 Date d'inscription jeudi 4 avril 2002 Statut Membre Dernière intervention 11 août 2008 - 21 août 2005 à 20:29
Salut tous,
Je ne suis pas bien ecrire en Français.Ce pour ça que Je vais continue en English. Je puex lire et comprendre. Vous pouvvez me repondre en Français.

I have a project in Visual basic which uses the form for drawing the lines etc.
I use the Form.ScaleLeft, Form.ScaleTop properties for changing the orjin of coordinate system. You can also choose the negative coordinates. You can inverse the coordinate system of the form. (0,0) Left,Bottom.
(Also Form.ScaleHeigh et Form.ScaleWidht for the zooms).

1) I want to draw on the Canvas of a MDIChild in World coordinates system and be able to change the form height a width for seeing a part of the drawings(zooms)
How can I do that with Delphi ? Can I change the canvas orjin ?

2) I need the coordinates of the mouse (X,Y) in reel number which I get with mousemove event. Like ( X=-454.326 , Y= 555.987). But in the procedure mousemove they are integer. How can I transform them and get the parts after decimal.

Merci d'avance.

3 réponses

neodelphi Messages postés 442 Date d'inscription jeudi 4 avril 2002 Statut Membre Dernière intervention 11 août 2008
21 août 2005 à 20:29
To have your own coordinate system, you can have 4 conversion methods.
PositionToScreenX, wich converts an absciss in screen coordinates
PositionToScreenY, for the Y component,
ScreenToPositionX,
ScreenToPositionY;

PositionToScreen functions will allow you to draw your shapes on the screen, while ScreenToPosition functions will let you know the converted coordinates of the mouse over the form.

If the right border of the form corresponds to XMax and the left border of the form corresponds to XMin you will have the following relation:
PositionToScreenX( XMax ) = width of the form
PositionToScreenX( XMin ) = 0

idem for the Y component:
PositionToScreenY( YMax ) = 0
PositionToScreenY( YMin ) = height of the form

With theses properties, a rectangle in your coordinate system will correspond the client rect of the form.

This is the code you can write for ScreenToPositionX:

<HR>
// The form coordinate system is in pixel, so this function should return an interger.
function ScreenToPositionX(value: double): integer;
begin
ScreenToPositionX := round( ((value-XMin)/(XMax-XMin))*form1.width );
end;

<HR>

The code for ScreenToPositionY should look like this:

<HR>
function ScreenToPositionY(value: double): integer;
begin
ScreenToPositionY := round( form1.height - (form1.height*(value-YMin)/(YMax-YMin)) );
end;

<HR>

I hope I didn't miss anything. The to write the methods ScreenToPositionX and ScreenToPositionY, just resolve the equations
ScreenToPositionX( PositionToScreenX( value ) ) = value;
ScreenToPositionY( PositionToScreenY( value ) ) = value;

neodelphi
3
neodelphi Messages postés 442 Date d'inscription jeudi 4 avril 2002 Statut Membre Dernière intervention 11 août 2008
21 août 2005 à 18:47
I dont think it's possible. However you can handle a different coordinate system yourself by writing conversion methods to change coordinate system for drawing and geting mouse position.

When you have do draw a line you will write:
form1.canvas.lineTo(PosToScreenX(xposition), PosToScreenY(yposition));

I think this is better than changing the coordinate system of the form because you get more control, and you will be latter able to handle a rotating camera or 3d coordinate system.

neodelphi
0
MUFUSU Messages postés 2 Date d'inscription samedi 20 août 2005 Statut Membre Dernière intervention 21 août 2005
21 août 2005 à 20:07
Thank's to Neodelphi for replying me.

Now I know that it's not possible to change the coordinate system of the canvas.
Is there anyone who can explain me how can I write some codes to change the coordinate system. Because I don't know how to do this.

For example :
I have a line from (-25.342,-35.445) to ( 20.678,44.556). The negative coordinates inticates Bottom_Left of the form.
I want that the form limites have to be (Xmin-4),(Ymin-4)and (Xmax+4),(Ymax+4).
And after with a rectangle I want to choose a zone for see the image bigger.

Also, how can I get the coordinates of the mouse in real type. I need minimum three number after decimal.

Thank to everybody who will reply me.
You can write in French. I can read a understand.
Merci d'avance.
0
Rejoignez-nous