/*->c.tekpr     */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>


#include "h.os"
#include "h.bbc"
#include "h.sprite"
#include "h.wimp"
#include "h.flex"
#include "h.Drawlevel0"



#include "h.main"
#include "h.wos"

#include "h.pr"
#include "h.xext"

#include "h.tekint"
#include "h.tek"




pset tekpset={0x1,1,100,100,100,100,0,0,1,
                                          0,0,0,0,0,0};



void tekprredraw(int invert,wimp_redrawstr * redrawstr)
{
 wimp_box tbox;

 tbox.x0=0;
 tbox.x1=tekos(TEKW);
 tbox.y1=0;
 tbox.y0=tekos(TEKMAXH);

 redrawstr->scx=redrawstr->scy=0;

 redrawstr->box.x0=0;
 redrawstr->box.y0=0;
 redrawstr->box.x1=tekos(TEKW);
 redrawstr->box.y1=tekos(TEKMAXH);


 if(invert)
 {
  invertdiag(&tekdiag);
  invertdiag(&teklast);
  invertsub(&tekbakpal);
 }

 setgcol(tekbakpal);
 bbc_rectanglefill(0,0,tekos(TEKW),tekos(TEKVISH));

 picrend(&tbox,tekdiag,redrawstr);
 picrend(&tbox,teklast,redrawstr);

 if(invert)
 {
  invertsub(&tekbakpal);
  invertdiag(&tekdiag);
  invertdiag(&teklast);
 }
}




void tekprzoom(int command)
{
 static zoomer przoom;

 switch(command)
 {

  case PRSAVEZOOM:
                  przoom=tekzoom;
                  break;

  case PRLOADZOOM:
                  tekzoom=przoom;
                  break;

 case PRUNITYZOOM:
                  tekzoom.mul=tekzoom.div=1;
                  tekzoom.var=0;
                  break;

 }
}





/* fundamental routine to print Tek screen */

void tekprintfile(int invert)
{
 tekpset.box0=0;
 tekpset.box1=0;
 tekpset.box2=tekos(TEKW);
 tekpset.box3=tekos(TEKVISH);
 tekpset.height=tekint(TEKMAXH);

 printfile(invert,&tekpset,tekprzoom,tekprredraw);
}




/*****************************************************************************/
/* redraw tek printer margins */


#define MARGINCOLOUR 1


void tekredrawprint(wimp_redrawstr * redrawstr)
{
 int xleft;      /* do transform on these vars */
 int xright;
 int xtop;
 int xbot;
 int righth;
 int lefth;
 int ox;
 int oy;

 if(!tekmargins) return;


 ox=redrawstr->box.x0-redrawstr->scx;
 oy=redrawstr->box.y1-redrawstr->scy;


 if(rosprintarea)
 {
  tekpset.width=tekint(TEKW);
  tekpset.height=tekint(TEKMAXH);

  calcprintarea(&tekpset,&xleft,&xright,&xtop,&xbot);

  seteorcolpal(tekbakpal,MARGINCOLOUR);

  /* left hand edge  */

  bbc_rectanglefill(ox,oy,osunits(xleft),-tekos(TEKMAXH));

  lefth=ox+(osunits(xleft) & maskx)+deltax;

  /* right hand edge */

  bbc_rectanglefill(ox+osunits(xright),oy,
                            tekos(TEKW)-osunits(xright),-tekos(TEKMAXH));

  righth=(ox+(osunits(xright) & maskx))-deltax;

  /* bottom edge     */

  bbc_rectanglefill(lefth,oy-tekos(TEKVISH),righth-lefth,osunits(xbot));

  /* top edge        */

  bbc_rectanglefill(lefth,oy-tekos(TEKVISH)+osunits(xtop),righth-lefth,
                                    tekos(TEKVISH)-osunits(xtop));
 }
}



void tekprupdate(void)
{
 if(tekmargins && tekopen) refreshwindow(whandle[TEK]);
}


void tekdumpscreen(int fp)
{
 tekprintfile(!tekdumptype);
 fp=0;
}



void settekversion(int fp)
{
 int vers;
 vers=stack[fp];
 if(vers>=0) tekversion=vers;
}


