AggPas - Anti-Grain Geomertry for Object Pascal

TAgg2D.ScreenToWorld(x, y)

Description

Transforms surface (screen) coordinates into world (user) coordinates.

This method is useful for hit test detection. Typically operating system sends information about position of the mouse in surface (screen) coordinates, but the output on screen might come from totally different coordinates, which were transformed by the vector engine during the rendering process.

Parameters

x: PDouble

Pointer to the screen X coordinate [in subpixels]. This parameter receives also the result of conversion — world X coordinate [in subpixels].

y: PDouble

Pointer to the screen Y coordinate [in subpixels]. This parameter receives also the result of conversion — world Y coordinate [in subpixels].

Example

var
  x, y: double;
begin
  if VG.Attach(Image1.Picture.Bitmap) then begin

    VG.ClearAll (255, 255, 255);

    // Coordinates system shift (on X + 10, on Y + 20)
    VG.Translate(10, 20);

    // Find out where the mouse position X & Y is targetting
    // our user drawing (before rendering transformations)
    x := 25;
    y := 35;

    VG.ScreenToWorld(@x, @y);
    // X should be 15 (25 - 10), Y should be 15 (35 - 20)

  end;
end;