/*implementation for Macintosh*/

#include "view.h"

Surface *newSurface(posx,posy,width,height)
int posx,posy,width,height;
{
	Surface *surface;
	
	surface = Malloc(Surface,1);
	surface->posx = posx;
	surface->posy = posy;
	surface->width = width;
	surface->height = height;
	
	/*default viewport*/
	surface->x1 = 0.0;
	surface->x2 = (REAL)(width-1);
	surface->y1 = 0.0;
	surface->y2 = (REAL)(height-1);
	surface->dvx = (surface->x2-surface->x1)/2.0;
	surface->dvy = (surface->y2-surface->y1)/2.0;
#ifdef DRAW
	surface->drawable = newDrawable(posx,posy,width,height);
#endif

	return(surface);
}

void newPolygonOnSurface(surface)
Surface *surface;
{
	surface->polygonSize = 0;
	newPolygonOnDrawable();
}

void addToPolygonOnSurface(surface,s)
Surface *surface;
Point3D *s;
{		
	surface->polygon[surface->polygonSize].x = SCREEN_X(surface,s->x);
	surface->polygon[surface->polygonSize].y = SCREEN_Y(surface,s->y);
    ++surface->polygonSize;
    
}

void displayPolygonOnSurface(surface,shading)
Surface *surface;
Shading *shading;
{
	int x,y,i;
	
	/*set the current drawable*/
	setDrawable(surface->drawable);
	
	/*set the shading*/
	setColourOnDrawable(REDShading(shading),
						GREENShading(shading),
						BLUEShading(shading));
	
	/*set the first point*/
	x = ROUND(surface->polygon[0].x);
	y = ROUND(surface->polygon[0].y);
	startPolygonOnDrawable(x,y);
	
	/*and the subsequent points*/
	for(i=1;i<surface->polygonSize;++i){
		x = ROUND(surface->polygon[i].x);
		y = ROUND(surface->polygon[i].y);
		addToPolygonOnDrawable(x,y);
	}

	/*display the polygon*/
	displayPolygonOnDrawable();
}
	
		

