linsyking/messenger-core/17.1.0

NOTE: the latest version is 20.0.0

Renamed to elm-messenger/messenger-core. That is where the repository lives now. It has not been published as a package under the new name.

Versions published as linsyking/messenger-core still install under that name. 34 versions of 52 come from the new location (see their notes). 7 versions could not be recovered and cannot be installed.

Messenger.Coordinate.Coordinates

Coordinate

This module deals with the coordinate transformation.

Normally, users do not need to use this module directly, as Messenger will handle the coordinate transformation for you.

fixedPosToReal : InternalData -> ( Float, Float ) -> ( Float, Float )

Same as posToReal, but add the initial position of canvas. That is to say, the function returns the actual coordinate of the point on the whole screen of your computer, so it is dependent on the location of your browser windows.

Example: If your screen is 2560*1440, the virtual canvas size is 1920*1080 and the actual window size 960*540 at the center of screen, then the function will map (600,300) to (2560/2-960/2+(960/1920)*600,1440/2-540/2+(540/1080)*300) = (1100,600)

posToReal : InternalData -> ( Float, Float ) -> ( Float, Float )

Transform from the virtual coordinate system to the real pixel system.

For example, if you virtual canvas is 1920*1080 but your real window is 960*540, then the function will map a point at (1200,600) to (600,300).

Usage : posToReal gd ( x, y ) where (x,y) is the virtual coordinates and gd the internal data.

The function returns the position in real canvas.

posToVirtual : InternalData -> ( Float, Float ) -> ( Float, Float )

Inverse of posToReal. This is helpful if you need to render sprite with real coordinates.

Usage : posToReal gd ( x, y ) where (x,y) is the real coordinates and gd the internal data. The function returns the coordinate in virtual coordinate system.

lengthToReal : InternalData -> Float -> Float

Use this if you want to draw something based on the length. It turns the virtual length to real length. For example, if the actual window is 960*540 and the virtual one is 1920*1080, then the function will map 300(virtual length) to 150(real length)

  • Note: In the case the actual width-length ratio of the window is different from the virtual ratio, the zooming ratio is calculated based on the WIDTH ratio between the real and virtual canvas size.

Usage: lengthToReal gd x

  • gd is the internal data.
  • x is the length in virtual coordinate system.

The function returns the length in real coordinate system.

fromRealLength : InternalData -> Float -> Float

The inverse function of widthToReal. Turns the length in real length to virtual length.

  • Note: In the case the actual width-length ratio of the window is different from the virtual ratio, the zooming ratio is calculated based on the WIDTH ratio between the real and virtual canvas size. Usage: lengthToReal gd x

  • gd is the internal data.

  • x is the length in real coordinate system.

The function returns the length in virtual coordinate system.

maxHandW : ( Float, Float ) -> ( Float, Float ) -> ( Float, Float )

Used internally.

getStartPoint : ( Float, Float ) -> ( Float, Float ) -> ( Float, Float )

Get the start point of the virtual canvas in the real canvas.

Used internally.

judgeMouseRect : ( Float, Float ) -> ( Float, Float ) -> ( Float, Float ) -> Bool

Judge whether the mouse position is in the rectangle. Usage: judgeMouseRect ( mx, my ) ( x, y ) ( w, h )

  • (mx,my) is the coordinate of the mouse, which you can get easily from globalData.
  • (x,y) is the starting point(left-top corner) of the desired rectangle.
  • (w,h) is the width and length of the desired rectangle.

The function returns a bool indicating whether the mouse is in the rectangle.

judgeMouseCircle : ( Float, Float ) -> ( Float, Float ) -> Float -> Bool

Judge whether the mouse position is in the circle.

InternalData
-> Camera
-> ( Float, Float )
-> ( Float, Float )
-> ( Float, Float )
-> Bool

Judge whether the mouse position is in the rectangle, with camera.

fromMouseToVirtual : InternalData -> ( Float, Float ) -> ( Float, Float )

fromMouseToVirtual conveys the mouse position in the Screen coordinate to the virtual coordinate. In most cases Messenger does this for you.

The coordinate in the globalData is already in virtual coordinates.