#ifndef ZPRMOUSE_H
#define ZPRMOUSE_H

#include <point.h>
#include <zpr.h>

/*!
\brief Conversion functions for mouse coordinate spaces. 

Top left is origin. So positive y is downward direction.

Local pixel coordinate system, Local ratio coordinate system,
 world near plane supported.

The local ratio is the screen mapped to a unit square.
 So could specify a point in local ratio and this 
 would have meaning in all different screen rectangles.
*/
class zprmouse
{
public:
  
  /** Reference to actual mouse state. */
  zpr& zz;

  /** Constructor. */
  zprmouse(zpr& zz_)
    : zz(zz_) {}

  /** Get the screen coordinates. */
  point2<uint> const mouse() const
    { return point2<uint>(zz.mouseX,zz.mouseY); }
  /** Return the position as a point in integers. */
  point2<int> const mouseint() const
    { return point2<int>(zz.mouseX,zz.mouseY); }

  template<typename T>
  void mouse(T & p) const
    { p.x = zz.mouseX; p.y = zz.mouseY; }

  /** Convert screen point to ratio. */
  point2<double> const mouseratio(point2<uint> const & p) const;
  /** Convert actual mouse screen point to ratio. */
  point2<double> const mouseratio() const;

  point2<uint> const mouseratioInv(point2<double> const & p) const
  {
    assert(p.x<=1.0);
    assert(p.y<=1.0);
    assert(p.x>=0.0);
    assert(p.y>=0.0);
    return point2<uint>(p.x*zz.width,p.y*zz.height);
  }

  point3<double> const world(point2<uint> const & p) const;

  /** Convert ratio to pixel screen point, then to world. */
  point3<double> const world(point2<double> const & p) const;

  /** Convert actual mouse screen point to near world point. */
  point3<double> const world() const;

  void update()
    { zz.update(); }

};


#endif


