static char *sccs_id= (sccs_id, "@(#)DrawDyn.c	1.2 7/28/92");

/*
 * This file demonstrates GEO's capability to dynamically load
 * your own defined QueryShapes.
 *
 * Warning: The dynload routines do not call static constructors
 * contained in this file !!!
 *
 * So do not use: MetaDef() and MetaImpl() macros !
 */

#include "Class.h"
#include "OverView.h"
#include "IconShape.h"

class DemoDynShape: public QueryShape {
  char	*the_str;
  float	lng, lat;
public:
  DemoDynShape(MapView *, int n, char **str);
  ~DemoDynShape();

  int Distance(Point p);
  void CompBBox();
  void Draw();
};


extern "C" QueryShape *make_dyn();

QueryShape *make_dyn(MapView *dv, int n, char **str)
{
  QueryShape *qs= new DemoDynShape(dv, n, str);
  return qs;
}


DemoDynShape::DemoDynShape(MapView *d, int n, char **str): (d)
{
  the_str= strsave(str[0]);
  lng= atof(str[1]+1);
  lat= atof(index(str[1], ',')+1);
  labelpos= dv->GeoToPoint(lng,lat) + Point(20,0);
}

DemoDynShape::~DemoDynShape()
{
  delete the_str;
}

int DemoDynShape::Distance(Point p)
{
  int xdist= bbox.origin.x - p.x;
  int ydist= bbox.origin.y - p.y;

  xdist= abs(xdist);
  ydist= abs(ydist);

  return (xdist > ydist) ? xdist: ydist;
}

void DemoDynShape::CompBBox()
{
  Rectangle r(dv->GeoToPoint(lng,lat), Point(30,30));
  SetBBox(r);
}

void DemoDynShape::Draw()
{
  QueryShape::Draw();

  GrSetPenInk(ePatBlack);
  GrStrokeRect(bbox);

  GrTextMoveto(bbox.origin+Point(10,15));
  GrDrawString(the_str);
}
