/*                        COPYRIGHT (c) 1989 BY                             *
 *        PARADIGM ASSOCIATES INCORPORATED, CAMBRIDGE, MASSACHUSETTS.       *
 *			   ALL RIGHTS RESERVED                              *

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Paradigm Associates Inc
not be used in advertising or publicity pertaining to distribution of
the software without specific, written prior permission.

PARADIGM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
PARADIGM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

*/



#include <stdio.h>

#include "xtek.h"

extern int tv_mode;
extern int mbx_mode;

int tv_simulate_transform(xa,xb,ya,yb,x)
     int xa,xb,ya,yb,x;
{return((((xa-x)*yb)+((x-xb)*ya))/(xa-xb));}


int tv_border = 10;

#define tv_height() plotx_height()
#define tv_width() plotx_width()

xtek_init()
{if(!plotx_init())
   {fprintf(stderr,"can't open x-display\n");
    exit(1);}}

int tv_transform_x (x)
     int x;
{return(tv_simulate_transform(0,XDIM,tv_border,tv_width()-tv_border,x));}

int tv_transform_y (y)
     int y;
{return(tv_simulate_transform(0,YDIM,tv_height()-tv_border,tv_border,y));}

xtek_scale(scale_factor)
     double scale_factor;
{if (tv_mode)
   fprintf(stderr,"xtek_scale?\n");
 else
   fprintf(stdout,"%f %f scale\n", scale_factor, scale_factor);}
   

xtek_char(c,cx,cy)
     int c,cx,cy;
{if (tv_mode)
   plotx_char(tv_transform_x(cx),tv_transform_y(cy),c);
 else
   fprintf(stdout,"(%c) %d %d PR\n", (char) c, cx, cy);}

int tv_x,tv_y;

xtek_moveto(cx,cy)
     int cx,cy;
{if (tv_mode)
   {tv_x = cx;
    tv_y = cy;}
 else
   fprintf(stdout,"%d %d moveto\n",cx, cy);}


xtek_ltsm(cx,cy)
     int cx,cy;
{if (tv_mode)
   {plotx_line(tv_transform_x(tv_x),
	       tv_transform_y(tv_y),
	       tv_transform_x(cx),
	       tv_transform_y(cy));
    tv_x = cx;
    tv_y = cy;}
 else
   fprintf(stdout,"%d %d lineto stroke %d %d moveto\n", cx, cy, cx, cy);}

xtek_mtarc(cx,cy)
     int cx,cy;
{if (tv_mode)
   fprintf(stderr,"xtek_moveto?\n");
 else
   fprintf(stdout,"%d %d moveto %d %d 1 0 360 arc\n", cx, cy, cx, cy);}
   
xtek_smt(cx,cy)
     int cx,cy;
{if (tv_mode)
   {tv_x = cx;
    tv_y = cy;}
 else
   fprintf(stdout,"stroke %d %d moveto\n", cx, cy);}
   
xtek_lineto(cx,cy)
     int cx,cy;
{if (tv_mode)
   {plotx_line(tv_transform_x(tv_x),
	       tv_transform_y(tv_y),
	       tv_transform_x(cx),
	       tv_transform_y(cy));
    tv_x = cx;
    tv_y = cy;}
 else
   fprintf(stdout,"%d %d lineto\n", cx, cy);}

     
xtek_DP(tsizey)
     int tsizey;
{if (tv_mode)
   {}
 else
   fprintf(stdout, "%d DP\n", tsizey);}


xtek_copypage()
{if (tv_mode)
   {}
 else
   fprintf(stdout, "copypage\n");}

xtek_DDV()
{if (tv_mode)
   {}
 else
   fprintf(stdout,"DDV\n");}

xtek_DFntL()
{if (tv_mode)
   {}
 else
   fprintf(stdout,"DFntL\n");}

xtek_DFntM()
{if (tv_mode)
   {}
 else
   fprintf(stdout,"DFntM\n");}

xtek_DFntS()
{if (tv_mode)
   {}
 else
   fprintf(stdout,"DFntS\n");}

xtek_DV()
{if (tv_mode)
   {}
 else
   fprintf(stdout,"DV\n");}

xtek_DZ()
{if (tv_mode)
   {}
 else
   fprintf(stdout,"DZ\n");}

xtek_FntH_setfont()
{if (tv_mode)
   {}
 else
   fprintf(stdout,"FntH setfont\n");}

xtek_FntL_setfont()
{if (tv_mode)
   {}
 else
   fprintf(stdout,"FntL setfont\n");}

xtek_FntM_setfont()
{if (tv_mode)
   {}
 else
   fprintf(stdout,"FntM setfont\n");}

xtek_FntS_setfont()
{if (tv_mode)
   {}
 else
   fprintf(stdout,"FntS setfont\n");}

xtek_FZ()
{if (tv_mode)
   {}
 else
   fprintf(stdout,"FZ\n");}

xtek_LDV()
{if (tv_mode)
   {}
 else
   fprintf(stdout,"LDV\n");}

xtek_NV()
{if (tv_mode)
   {}
 else
   fprintf(stdout,"NV\n");}

xtek_SDV()
{if (tv_mode)
   {}
 else
   fprintf(stdout,"SDV\n");}


xtek_showpage()
{if (tv_mode)
   {if (mbx_mode)
      plotx_force_output();
   else
     {char buffer[512];
      plotx_bell();
      fgets(buffer,sizeof(buffer),stdin);}}
 else
   fprintf(stdout,"showpage\n");}
 
xtek_showpage_NP()
{if (tv_mode)
   {xtek_showpage();
    if (mbx_mode) plotx_clear();}
 else
  fprintf(stdout,"showpage\nNP\n");}


