예제 #1
0
/* Draw the rook */
void draw_rook(int coord_x, int coord_y, char color)
{
	GR_POINT rook[] = {
		{coord_x+1, coord_y+1}, {coord_x+3, coord_y+1},
		{coord_x+3, coord_y+3}, {coord_x+5, coord_y+3},
		{coord_x+5, coord_y+1}, {coord_x+7, coord_y+1},
		{coord_x+7, coord_y+3}, {coord_x+9, coord_y+3},
		{coord_x+9, coord_y+1}, {coord_x+11, coord_y+1}, 
		{coord_x+11, coord_y+4}, {coord_x+9, coord_y+4},
		{coord_x+9, coord_y+8}, {coord_x+11, coord_y+8},
		{coord_x+11, coord_y+11}, {coord_x+1, coord_y+11}, 
		{coord_x+1, coord_y+8}, {coord_x+3, coord_y+8}, 
		{coord_x+3, coord_y+4}, {coord_x+1, coord_y+4},
		{coord_x+1, coord_y+1}
	};

	if(color == 'w')
	{
		GrSetGCForeground(tuxchess_gc,GR_RGB(255,255,255));
		GrFillPoly(tuxchess_wid,tuxchess_gc,21,rook);
		GrSetGCForeground(tuxchess_gc,GR_RGB(0,0,0));
		GrPoly(tuxchess_wid,tuxchess_gc,21,rook);
	}
	else
	{
		GrSetGCForeground(tuxchess_gc,GR_RGB(0,0,0));
		GrFillPoly(tuxchess_wid,tuxchess_gc,21,rook);
	}
}
예제 #2
0
/* Draw the rook */
void draw_rook(int coord_x, int coord_y, int color)
{
	GR_POINT rook[] = {
		{coord_x+1, coord_y+1}, {coord_x+3, coord_y+1},
		{coord_x+3, coord_y+3}, {coord_x+5, coord_y+3},
		{coord_x+5, coord_y+1}, {coord_x+7, coord_y+1},
		{coord_x+7, coord_y+3}, {coord_x+9, coord_y+3},
		{coord_x+9, coord_y+1}, {coord_x+11, coord_y+1}, 
		{coord_x+11, coord_y+4}, {coord_x+9, coord_y+4},
		{coord_x+9, coord_y+8}, {coord_x+11, coord_y+8},
		{coord_x+11, coord_y+11}, {coord_x+1, coord_y+11}, 
		{coord_x+1, coord_y+8}, {coord_x+3, coord_y+8}, 
		{coord_x+3, coord_y+4}, {coord_x+1, coord_y+4},
		{coord_x+1, coord_y+1}
	};

	if(color == 0)
	{
		GrSetGCForeground(tuxchess_gc,WHITE);
		GrFillPoly(tuxchess_wid,tuxchess_gc,21,rook);
		GrSetGCForeground(tuxchess_gc,BLACK);
		GrPoly(tuxchess_wid,tuxchess_gc,21,rook);
	}
	else
	{
		GrSetGCForeground(tuxchess_gc,BLACK);
		GrFillPoly(tuxchess_wid,tuxchess_gc,21,rook);
	}
}
예제 #3
0
int
XFillPolygon(Display * display, Drawable d, GC gc,
	XPoint * points, int npoints, int shape, int mode)
{
	int i;
	GR_POINT *gr_points;

	gr_points = ALLOCA(npoints * sizeof(GR_POINT));

	if (mode == CoordModeOrigin) {
		for (i = 0; i < npoints; i++) {
			gr_points[i].x = points[i].x;
			gr_points[i].y = points[i].y;
		}
	} else {		/* CoordModePrevious */
		int px = 0, py = 0;
		for (i = 0; i < npoints; i++) {
			gr_points[i].x = px + points[i].x;
			gr_points[i].y = py + points[i].y;

			px += points[i].x;
			py += points[i].y;
		}
	}

	if (shape == Complex || shape == Convex)
		printf("XFillPolygon: Complex/Convex\n");

	GrFillPoly(d, gc->gid, npoints, gr_points);

	FREEA(gr_points);
	return 1;
}
예제 #4
0
void
draw_set(char *name, int mode)
{
	int x;
	int tw, th, tb;
	GR_POINT points[4];
	GR_GC_ID gc = GrNewGC();

	GrSetGCForeground(gc, WHITE);
	GrSetGCBackground(gc, GRAY);

	GrGetGCTextSize(gc, name, -1, GR_TFTOP, &tw, &th, &tb);

	x = g_x + (tw - 50) / 2;

	GrText(g_main, gc, g_x, 5, name, -1, GR_TFTOP);

	g_x += (tw + 10);

	GrSetGCFillMode(gc, mode);

	if (mode == GR_FILL_STIPPLE)
		GrSetGCForeground(gc, YELLOW);
	else {
		GrSetGCForeground(gc, WHITE);
		GrSetGCBackground(gc, BLUE);
	}

	if (mode == GR_FILL_TILE) {
		GrSetGCTile(gc, g_pixmap, 16, 16);
	}

	if (mode == GR_FILL_STIPPLE || mode == GR_FILL_OPAQUE_STIPPLE)
		GrSetGCStipple(gc, g_stipple2, 2, 2);

	GrFillRect(g_main, gc, x, 25, 50, 50);

	if (mode == GR_FILL_STIPPLE || mode == GR_FILL_OPAQUE_STIPPLE)
		GrSetGCStipple(gc, g_stipple1, 7, 7);

	GrFillEllipse(g_main, gc, x + 25, 105, 25, 25);

	if (mode == GR_FILL_STIPPLE || mode == GR_FILL_OPAQUE_STIPPLE)
		GrSetGCStipple(gc, g_stipple3, 3, 2);

	points[0].x = points[3].x = x;
	points[0].y = points[3].y = 165;

	points[1].x = x + 50;
	points[1].y = 165;

	points[2].x = x + 25;
	points[2].y = 215;

	GrFillPoly(g_main, gc, 4, points);

	GrDestroyGC(gc);
}
예제 #5
0
/* FIXME: fails with pointtable size > 64k if sizeof(int) == 2*/
static void
GrFillPolyWrapper(void *r)
{
	nxPolyReq *req = r;
	int        count;

	count = GetReqVarLen(req) / sizeof(GR_POINT);
	GrFillPoly(req->drawid, req->gcid, count, (GR_POINT *)GetReqData(req));
}
예제 #6
0
/* Draw the queen */
void draw_queen(int coord_x, int coord_y, char color)
{
	GR_POINT queen[] = {
		{coord_x+1, coord_y+1}, {coord_x+4, coord_y+4},
		{coord_x+6, coord_y+1}, {coord_x+8, coord_y+4},
		{coord_x+11, coord_y+1}, {coord_x+9, coord_y+10},
		{coord_x+3, coord_y+10}, {coord_x+1, coord_y+1}
	};

	if (color == 'w')
	{
		GrSetGCForeground(tuxchess_gc,GR_RGB(255,255,255));
		GrFillPoly(tuxchess_wid,tuxchess_gc,8,queen);
		GrSetGCForeground(tuxchess_gc,GR_RGB(0,0,0));
		GrPoly(tuxchess_wid,tuxchess_gc,8,queen);
	}
	else
	{
		GrSetGCForeground(tuxchess_gc,GR_RGB(0,0,0));
		GrFillPoly(tuxchess_wid,tuxchess_gc,8,queen);
		GrPoly(tuxchess_wid,tuxchess_gc,8,queen);
	}
}
예제 #7
0
/* Draw the queen */
void draw_queen(int coord_x, int coord_y, int color)
{
	GR_POINT queen[] = {
		{coord_x+1, coord_y+1}, {coord_x+4, coord_y+4},
		{coord_x+6, coord_y+1}, {coord_x+8, coord_y+4},
		{coord_x+11, coord_y+1}, {coord_x+9, coord_y+10},
		{coord_x+3, coord_y+10}, {coord_x+1, coord_y+1}
	};

	if (color == 0)
	{
		GrSetGCForeground(tuxchess_gc,WHITE);
		GrFillPoly(tuxchess_wid,tuxchess_gc,8,queen);
		GrSetGCForeground(tuxchess_gc,BLACK);
		GrPoly(tuxchess_wid,tuxchess_gc,8,queen);
	}
	else
	{
		GrSetGCForeground(tuxchess_gc,BLACK);
		GrFillPoly(tuxchess_wid,tuxchess_gc,8,queen);
		GrPoly(tuxchess_wid,tuxchess_gc,8,queen);
	}
}
예제 #8
0
/* Draw the knight */
void draw_knight(int coord_x, int coord_y, char color)
{
	GR_POINT knight[] = {
		{coord_x+5, coord_y+1}, {coord_x+8, coord_y+3},
		{coord_x+11, coord_y+11}, {coord_x+1, coord_y+11},
		{coord_x+5, coord_y+9}, {coord_x+5, coord_y+4},
		{coord_x+3, coord_y+6}, {coord_x+1, coord_y+6},
		{coord_x+5, coord_y+1}
	};

	if(color == 'w')
	{
		GrSetGCForeground(tuxchess_gc,GR_RGB(255,255,255));
		GrFillPoly(tuxchess_wid,tuxchess_gc,9,knight);
		GrSetGCForeground(tuxchess_gc,GR_RGB(0,0,0));
		GrPoly(tuxchess_wid,tuxchess_gc,9,knight);
	}
	else 
	{
		GrSetGCForeground(tuxchess_gc,GR_RGB(0,0,0));
		GrFillPoly(tuxchess_wid,tuxchess_gc,9,knight);
		GrPoly(tuxchess_wid,tuxchess_gc,9,knight);
	}
}
예제 #9
0
/* Draw the knight */
void draw_knight(int coord_x, int coord_y, int color)
{
	GR_POINT knight[] = {
		{coord_x+5, coord_y+1}, {coord_x+8, coord_y+3},
		{coord_x+11, coord_y+11}, {coord_x+1, coord_y+11},
		{coord_x+5, coord_y+9}, {coord_x+5, coord_y+4},
		{coord_x+3, coord_y+6}, {coord_x+1, coord_y+6},
		{coord_x+5, coord_y+1}
	};

	if(color == 0)
	{
		GrSetGCForeground(tuxchess_gc,WHITE);
		GrFillPoly(tuxchess_wid,tuxchess_gc,9,knight);
		GrSetGCForeground(tuxchess_gc,BLACK);
		GrPoly(tuxchess_wid,tuxchess_gc,9,knight);
	}
	else 
	{
		GrSetGCForeground(tuxchess_gc,BLACK);
		GrFillPoly(tuxchess_wid,tuxchess_gc,9,knight);
		GrPoly(tuxchess_wid,tuxchess_gc,9,knight);
	}
}
예제 #10
0
파일: demo.c 프로젝트: EPiCS/reconos_v2
/*
 * Here when an exposure event occurs.
 */
void
do_exposure(GR_EVENT_EXPOSURE	*ep)
{
	GR_POINT	points[3];

	if (ep->wid != w1)
		return;
	points[0].x = 311;
	points[0].y = 119;
	points[1].x = 350;
	points[1].y = 270;
	points[2].x = 247;
	points[2].y = 147;

	GrFillRect(w1, gc2, 50, 50, 150, 200);
	GrFillPoly(w1, gc2, 3, points);
}
예제 #11
0
/* Draw the bishop */
void draw_bishop(int coord_x, int coord_y, char color)
{
	GR_POINT bishop1[] = {
		{coord_x+7, coord_y+1}, {coord_x+8, coord_y+4},
		{coord_x+8, coord_y+7}, {coord_x+7, coord_y+10},
		{coord_x+4, coord_y+10}, {coord_x+1, coord_y+7},
		{coord_x+1, coord_y+5}, {coord_x+3, coord_y+3}, 
		{coord_x+7, coord_y+1}
	};

	GR_POINT bishop2[] = {
		{coord_x+10, coord_y+1}, {coord_x+11, coord_y+4},
		{coord_x+11, coord_y+7}, {coord_x+10, coord_y+10},
		{coord_x+7, coord_y+10}, {coord_x+4, coord_y+7},
		{coord_x+4, coord_y+5}, {coord_x+6, coord_y+3}, 
		{coord_x+10, coord_y+1}
	};

	GR_POINT bishop3[] = {
		{coord_x+4, coord_y+10}, {coord_x+9, coord_y+10},
		{coord_x+9, coord_y+12}, {coord_x+4, coord_y+12},
		{coord_x+4, coord_y+10}
	};

	if(color == 'w')
	{
		GrSetGCForeground(tuxchess_gc,GR_RGB(255,255,255));
		GrFillPoly(tuxchess_wid,tuxchess_gc,9,bishop2);
		GrFillPoly(tuxchess_wid,tuxchess_gc,5,bishop3);
		GrSetGCForeground(tuxchess_gc,GR_RGB(0,0,0));
		GrPoly(tuxchess_wid,tuxchess_gc,9,bishop2);
		GrPoly(tuxchess_wid,tuxchess_gc,5,bishop3);
		GrSetGCForeground(tuxchess_gc,GR_RGB(255,255,255));
		GrFillPoly(tuxchess_wid,tuxchess_gc,9,bishop1);
		GrSetGCForeground(tuxchess_gc,GR_RGB(0,0,0));
		GrPoly(tuxchess_wid,tuxchess_gc,9,bishop1);
	}
	else 
	{
		GrSetGCForeground(tuxchess_gc,GR_RGB(0,0,0));
		GrFillPoly(tuxchess_wid,tuxchess_gc,9,bishop2);
		GrFillPoly(tuxchess_wid,tuxchess_gc,5,bishop3);
		GrSetGCForeground(tuxchess_gc,GR_RGB(160,160,160));
		GrPoly(tuxchess_wid,tuxchess_gc,9,bishop2);
		GrPoly(tuxchess_wid,tuxchess_gc,5,bishop3);
		GrSetGCForeground(tuxchess_gc,GR_RGB(0,0,0));
		GrFillPoly(tuxchess_wid,tuxchess_gc,9,bishop1);
		GrSetGCForeground(tuxchess_gc,GR_RGB(160,160,160));
		GrPoly(tuxchess_wid,tuxchess_gc,9,bishop1);
	}
}
예제 #12
0
/* Draw the bishop */
void draw_bishop(int coord_x, int coord_y, int color)
{
	GR_POINT bishop1[] = {
		{coord_x+7, coord_y+1}, {coord_x+8, coord_y+4},
		{coord_x+8, coord_y+7}, {coord_x+7, coord_y+10},
		{coord_x+4, coord_y+10}, {coord_x+1, coord_y+7},
		{coord_x+1, coord_y+5}, {coord_x+3, coord_y+3}, 
		{coord_x+7, coord_y+1}
	};

	GR_POINT bishop2[] = {
		{coord_x+10, coord_y+1}, {coord_x+11, coord_y+4},
		{coord_x+11, coord_y+7}, {coord_x+10, coord_y+10},
		{coord_x+7, coord_y+10}, {coord_x+4, coord_y+7},
		{coord_x+4, coord_y+5}, {coord_x+6, coord_y+3}, 
		{coord_x+10, coord_y+1}
	};

	GR_POINT bishop3[] = {
		{coord_x+4, coord_y+10}, {coord_x+9, coord_y+10},
		{coord_x+9, coord_y+12}, {coord_x+4, coord_y+12},
		{coord_x+4, coord_y+10}
	};

	if(color == 0)
	{
		GrSetGCForeground(tuxchess_gc,WHITE);
		GrFillPoly(tuxchess_wid,tuxchess_gc,9,bishop2);
		GrFillPoly(tuxchess_wid,tuxchess_gc,5,bishop3);
		GrSetGCForeground(tuxchess_gc,BLACK);
		GrPoly(tuxchess_wid,tuxchess_gc,9,bishop2);
		GrPoly(tuxchess_wid,tuxchess_gc,5,bishop3);
		GrSetGCForeground(tuxchess_gc,WHITE);
		GrFillPoly(tuxchess_wid,tuxchess_gc,9,bishop1);
		GrSetGCForeground(tuxchess_gc,BLACK);
		GrPoly(tuxchess_wid,tuxchess_gc,9,bishop1);
	}
	else 
	{
		GrSetGCForeground(tuxchess_gc,BLACK);
		GrFillPoly(tuxchess_wid,tuxchess_gc,9,bishop2);
		GrFillPoly(tuxchess_wid,tuxchess_gc,5,bishop3);
		GrSetGCForeground(tuxchess_gc,LTGRAY);
		GrPoly(tuxchess_wid,tuxchess_gc,9,bishop2);
		GrPoly(tuxchess_wid,tuxchess_gc,5,bishop3);
		GrSetGCForeground(tuxchess_gc,BLACK);
		GrFillPoly(tuxchess_wid,tuxchess_gc,9,bishop1);
		GrSetGCForeground(tuxchess_gc,LTGRAY);
		GrPoly(tuxchess_wid,tuxchess_gc,9,bishop1);
	}
}
예제 #13
0
static void cube_draw(void)
{
	int i;
	GR_COLOR colour; // limey alert!
	GR_POINT faces[6][5] = {
		{
			{point2D[0].x, point2D[0].y},
			{point2D[1].x, point2D[1].y},
			{point2D[2].x, point2D[2].y},
			{point2D[3].x, point2D[3].y},
			{point2D[0].x, point2D[0].y},
		},
		{
			{point2D[4].x, point2D[4].y},
			{point2D[5].x, point2D[5].y},
			{point2D[6].x, point2D[6].y},
			{point2D[7].x, point2D[7].y},
			{point2D[4].x, point2D[4].y},
		},
		{
			{point2D[0].x, point2D[0].y},
			{point2D[5].x, point2D[5].y},
			{point2D[6].x, point2D[6].y},
			{point2D[3].x, point2D[3].y},
			{point2D[0].x, point2D[0].y},
		},
		{
			{point2D[1].x, point2D[1].y},
			{point2D[4].x, point2D[4].y},
			{point2D[7].x, point2D[7].y},
			{point2D[2].x, point2D[2].y},
			{point2D[1].x, point2D[1].y},
		},
		{
			{point2D[2].x, point2D[2].y},
			{point2D[3].x, point2D[3].y},
			{point2D[6].x, point2D[6].y},
			{point2D[7].x, point2D[7].y},
			{point2D[2].x, point2D[2].y},
		},
		{
			{point2D[0].x, point2D[0].y},
			{point2D[1].x, point2D[1].y},
			{point2D[4].x, point2D[4].y},
			{point2D[5].x, point2D[5].y},
			{point2D[0].x, point2D[0].y}
		}
	};
	zsort z_avgs_f[6];
	line_2D lines[12] = {
		{0,1}, {1,2}, {2,3}, {3,0},
		{4,5}, {5,6}, {6,7}, {7,4},
		{0,5}, {1,4}, {2,7}, {3,6}
	};
	
	if (solid) {
		for (i = 0; i < 6; i++) {
			z_avgs_f[i].place = i;
		}
		z_avgs_f[0].avg =
			(point3D[0].z + point3D[1].z + point3D[2].z + point3D[3].z)/4;
		z_avgs_f[1].avg =
			(point3D[4].z + point3D[5].z + point3D[6].z + point3D[7].z)/4;
		z_avgs_f[2].avg =
			(point3D[0].z + point3D[5].z + point3D[6].z + point3D[3].z)/4;
		z_avgs_f[3].avg =
			(point3D[1].z + point3D[4].z + point3D[7].z + point3D[2].z)/4;
		z_avgs_f[4].avg =
			(point3D[2].z + point3D[3].z + point3D[6].z + point3D[7].z)/4;
		z_avgs_f[5].avg =
			(point3D[0].z + point3D[1].z + point3D[4].z + point3D[5].z)/4;
		qsort(z_avgs_f, 6, sizeof(zsort), compfunc);
		for (i = 3; i < 6; i++) { /* we can only see the front 3 faces... */
			switch(z_avgs_f[i].place) {
				case 0:
					colour = (photo==0) ? LTGRAY : RED;
					break;
				case 1:
					colour = (photo==0) ? LTGRAY : GREEN;
					break;
				case 2:
					colour = (photo==0) ? GRAY : BLUE;
					break;
				case 3:
					colour = (photo==0) ? GRAY : YELLOW;
					break;
				case 4:
					colour = (photo==0) ? BLACK : MAGENTA;
					break;
				case 5:
					colour = (photo==0) ? BLACK : CYAN;
					break;
			}
			GrSetGCForeground(cube_gc, colour);
			GrFillPoly(temp_pixmap, cube_gc, 5, faces[z_avgs_f[i].place]);
		}
	} else {
		/* polygons not used so hidden lines can be gray in future
		 *  - once i work out how to do it, possibly with GrRegion stuff */
		GrSetGCForeground(cube_gc, BLACK);
		for (i = 0; i < 12; i++) {
			cube_draw_line(lines[i].v1, lines[i].v2);
		}
	}
	
	if (t_disp) {
		GrSetGCForeground(cube_gc, WHITE);
		GrFillRect(temp_pixmap, cube_gc,
			0, screen_info.rows-(HEADER_TOPLINE + 1)-14, screen_info.cols, 14);
		GrSetGCForeground(cube_gc, BLACK);
		GrLine(temp_pixmap, cube_gc,
			0, screen_info.rows-(HEADER_TOPLINE + 1)-14,
			screen_info.cols, screen_info.rows-(HEADER_TOPLINE + 1)-14);
		snprintf(t_buffer, 48, "%s:%d %s:%d %s:%d  |  d:%d ",
			t_ax[0], xs, t_ax[1], ys, t_ax[2], zs, z_off/10);
		GrText(temp_pixmap, cube_gc, 2,
			screen_info.rows-(HEADER_TOPLINE + 1)-2, t_buffer, -1, GR_TFASCII);
	}
	GrCopyArea(cube_wid, cube_gc, 0, 0,
		screen_info.cols, (screen_info.rows - (HEADER_TOPLINE + 1)),
		temp_pixmap, 0, 0, MWROP_SRCCOPY);
}
예제 #14
0
void draw_screen(int full)
{
  int bstart, bend;
  int x = 0, y = 0;

  GR_GC_ID gc = GrNewGC();

  for(y = 0; y < YUNITS; y++)
    {
       bstart = -1;
       bend = 0;
  
    for(x = 0; x < XUNITS; x++)
      {
	if (playground[y][x] == PLAYGROUND_EMPTY)
	  {
	    if (bstart == -1) bend = bstart = x;
	    else bend++;
	    continue;
	  }

	/* Draw the background block */
	
	if (bstart != -1)
	  {
	    GrSetGCForeground(gc, WHITE);
	    GrFillRect(offscreen, gc, (bstart * XUNITSIZE), (y * YUNITSIZE), 
		       (bend - bstart + 1) * XUNITSIZE, YUNITSIZE);
	
	    skipped += (bend - bstart);
	    
	    bstart = -1;
	    bend = 0;
	  }

	if (!full && playground[y][x] == PLAYGROUND_BORDER)
	  continue;
	
	switch(playground[y][x])
	  {
	  case PLAYGROUND_BORDER:
	    GrSetGCForeground(gc, GRAY);
	    break;
	    
	  case PLAYGROUND_SNAKE:
        GrSetGCForeground(gc, BLACK);
	    break;
            
	  case PLAYGROUND_TAIL:
	    GrSetGCForeground(gc, BLACK);
	    break;
	    
	  case PLAYGROUND_NIBBLE:
	    GrSetGCForeground(gc, GRAY);
	    break;
	    
	  }
	
	GrFillRect(offscreen, gc, (x * XUNITSIZE), 
		   (y * YUNITSIZE), XUNITSIZE, YUNITSIZE);

#ifdef NOTUSED
	if (playground[y][x] == PLAYGROUND_NIBBLE && nibble.active)
	  {
	    GR_POINT points[4];
	    
	    points[0].x = (x * XUNITSIZE) + 1;
	    points[0].y = points[2].y = (y * YUNITSIZE) + 1 + ((YUNITSIZE -2) / 2);
	    points[1].x = points[3].x = (x * YUNITSIZE) + 1 + ((XUNITSIZE -2) / 2);
	    points[1].y = (y * YUNITSIZE) + 1;
	    points[2].x = points[0].x + (XUNITSIZE - 2);
	    points[3].y = points[1].y + (YUNITSIZE - 2);
	  
	    GrFillPoly(offscreen, gc, 4, points);
	  }
#endif

	if (playground[y][x] == PLAYGROUND_NIBBLE && nibble.active)
	  {
	    int xpos = (x * XUNITSIZE) + (XUNITSIZE / 2);
	    int ypos = (y * YUNITSIZE) + (YUNITSIZE / 2);

	    GrSetGCForeground(gc, BLACK);

	    GrFillEllipse(offscreen, gc, xpos, ypos,
			  (XUNITSIZE / 2) - 1, (YUNITSIZE / 2) - 1);
	  }

      }

    /* If we have background clear up to the edge, handle that here */

    if (bstart != -1)
      {
	GrSetGCForeground(gc, WHITE);
	GrFillRect(offscreen, gc, (bstart * XUNITSIZE), (y * YUNITSIZE), 
		   (bend - bstart + 1) * XUNITSIZE, YUNITSIZE);
	
	bend = bstart = 0;
      }
    
    }
  
  GrDestroyGC(gc);
}
예제 #15
0
파일: speed.c 프로젝트: LucidOne/Rovio
int main()
{
#ifdef TEST_FOR_X
	Display		*display;
	Window		window;
	GC		gc;
	XGCValues	gcValues;
	Colormap	colormap;
	Pixmap		src_pixmap;
	unsigned long	fgColor, bgColor;
	int		screenNum;
	XPoint		points[NUM_POINTS];
#else
	GR_WINDOW_ID 	window;
	GR_WINDOW_ID	src_pixmap;
	unsigned char*	src_pixmap_buf[320*240*2];
	GR_GC_ID        gc;
	GR_POINT	points[NUM_POINTS];
#endif
	
	int		c, c1,  count=4500;
	int		x, y, x1, y1, x2, y2;

#ifdef TEST_FOR_X
	if(!(display=XOpenDisplay(""))) {
		printf("Cannot connect to X.\n");
	}
	screenNum = DefaultScreen(display);
	colormap = DefaultColormap(display, screenNum);

	bgColor = BlackPixel(display, screenNum);
	fgColor = WhitePixel(display, screenNum);
	window = XCreateSimpleWindow(display, RootWindow(display, screenNum),
		0, 0 , 639, 479, 0,
		fgColor, bgColor);
	src_pixmap = XCreatePixmap(display, window, 320, 240, 16);
	XMapRaised(display, window);
	gcValues.background = bgColor;
	gcValues.foreground = fgColor;
	gcValues.line_width = 1;
	gcValues.line_style = LineSolid;
	gcValues.fill_style = FillSolid;
	gcValues.fill_rule = WindingRule;
	gcValues.arc_mode = ArcPieSlice;
	gc = XCreateGC(display, window,
		GCForeground  | GCBackground | GCLineWidth | GCLineStyle |
		GCFillStyle,
		&gcValues);

#else	
	GrOpen();
	window = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, 639, 479, 0, BLACK, BLUE);
	src_pixmap = GrNewPixmap(640, 480, src_pixmap_buf);
	GrMapWindow(window);
	gc = GrNewGC();
        GrSetGCForeground(gc, WHITE);
	GrSetGCBackground(gc, BLACK);
	GrSetGCMode(gc, GR_MODE_COPY);
#endif




	
	// Horizontal Line
	////////////////////////////////////////////////
	printf("Horizontal Line(XDrawLine)\n");
	start_timer();
	for(c=0; c<count*20; c++)
	{
		y1=random()%480;
#ifdef TEST_FOR_X
		XDrawLine(display, window, gc, 0, y1, 639, y1);
		XFlush(display);
#else
		GrLine(window, gc, 0, y1, 639, y1);
		GrFlush();
#endif
	}
	end_timer();
#ifdef TEST_FOR_X
	XClearWindow(display, window);
#else
	GrClearWindow(window, GR_TRUE);
#endif
	
	// Vertical Line
	/////////////////////////////////////////////////
	printf("Vertical Line(XDrawLine)\n");
	start_timer();
	for(c=0; c<count*19; c++)
	{
		x1=random()%640;
#ifdef TEST_FOR_X
		XDrawLine(display, window, gc, x1, 0, x1, 479);
		XFlush(display);
#else
		GrLine(window, gc, x1, 0, x1, 479);
		GrFlush();
#endif
	}
	end_timer();
#ifdef TEST_FOR_X
	XClearWindow(display, window);
#else
	GrClearWindow(window, GR_TRUE);
#endif

	// General Line
	/////////////////////////////////////////////////
	printf("General Line(XDrawLine)\n");
	start_timer();
	for(c=0; c<count*22; c++)
	{
		x1 = random()%640;
		x2 = random()%640;
		y1 = random()%480;
		y2 = random()%480;
#ifdef TEST_FOR_X
		XDrawLine(display, window, gc, x1, y1, x2, y2);
		XFlush(display);
#else
		GrLine(window, gc, x1, y1, x2, y2);
		GrFlush();
#endif
	}
	end_timer();
#ifdef TEST_FOR_X
	XClearWindow(display, window);
#else
	GrClearWindow(window, GR_TRUE);
#endif

	// Point
	//////////////////////////////////////////////////
	printf("XPoint\n");
	start_timer();
	for(c=0; c<count*25; c++)
	{
		x1 = random()%640;
		y1 = random()%480;
#ifdef TEST_FOR_X
		XDrawPoint(display, window, gc, x1, y1);
		XFlush(display);
#else
		GrPoint(window, gc, x1, y1);
		GrFlush();
#endif
	}
	end_timer();
#ifdef TEST_FOR_X
	XClearWindow(display, window);
#else
	GrClearWindow(window, GR_TRUE);
#endif

	// Rectangle
	//////////////////////////////////////////////////
	printf("XRectangle\n");
	start_timer();
	for(c=0; c<count*20; c++)
	{
		x1=random()%639;
		y1=random()%479;
		x2=random()%(639-x1)+1;
		y2=random()%(479-y1)+1;
#ifdef TEST_FOR_X
		XDrawRectangle(display, window, gc, x1, y1, x2, y2);
		XFlush(display);
#else
		GrRect(window, gc, x1, y1, x2, y2);
		GrFlush();
#endif
	}
	end_timer();
#ifdef TEST_FOR_X
	XClearWindow(display, window);
#else
	GrClearWindow(window, GR_TRUE);
#endif

	// FillRectangle
	//////////////////////////////////////////////////
	printf("XFillRectangle\n");
	start_timer();
	for(c=0; c<count*18; c++)
	{
		x1=random()%639;
		y1=random()%479;
		x2=random()%(639-x1)+1;
		y2=random()%(479-y1)+1;	
#ifdef TEST_FOR_X
		XFillRectangle(display, window, gc, x1, y1, x2, y2);
		XFlush(display);
#else
		GrFillRect(window, gc, x1, y1, x2, y2);
		GrFlush();
#endif
	}
	end_timer();
#ifdef TEST_FOR_X

	XClearWindow(display, window);
#else
	GrClearWindow(window, GR_TRUE);
#endif

	// FillPolygon
	//////////////////////////////////////////////////
	printf("XFillPolygon\n");
	start_timer();
	for(c=0; c<count; c++)
	{
		for(c1=0; c1<NUM_POINTS; c1++)
		{
			points[c1].x = random()%640;
			points[c1].y = random()%480;
		}	
#ifdef TEST_FOR_X
		XFillPolygon(display, window, gc, points, NUM_POINTS,
			0, 0);
		XFlush(display);
#else
		GrFillPoly(window, gc, NUM_POINTS, points);
		GrFlush();
#endif
	}
	end_timer();
#ifdef TEST_FOR_X
	XClearWindow(display, window);
#else
	GrClearWindow(window, GR_TRUE);
#endif


	// CopyArea
	/////////////////////////////////////////////////
	printf("XCopyArea\n");
	start_timer();
	for(c=0; c<count*5; c++)
	{
		x1=random()%320;
		y1=random()%240;
		x2=random()%319+1;
		y2=random()%239+1;
		
#ifdef TEST_FOR_X
		XCopyArea(display, src_pixmap, window, gc,
			0, 0, x2, y2, x1, y1);
		XFlush(display);
#else
		GrCopyArea(window, gc, x1, y1, x2 ,y2, src_pixmap,
			0, 0, 0);
		GrFlush();
#endif
	}
	end_timer();	

#ifdef TEST_FOR_X
	XDestroyWindow(display, window);
#else
	GrClose();
#endif
}