static void reset_board() { int index; for(index = 0; index < 9; index++) board[index] = '-'; difficulty = 6; gameRunning = 1; currSquare = 0; draw_header(); /* Clear the window */ GrClearWindow (tictactoe_wid, GR_FALSE); GrSetGCUseBackground(tictactoe_gc, GR_TRUE); GrSetGCBackground(tictactoe_gc, WHITE); GrSetGCForeground(tictactoe_gc, BLACK); GrLine(tictactoe_wid, tictactoe_gc, wi.width * .90, (wi.height / 2.) - (wi.height / 2. * .33), wi.width - wi.width * .90, (wi.height / 2.) - (wi.height / 2. * .33)); GrLine(tictactoe_wid, tictactoe_gc, wi.width * .90, (wi.height / 2.) + (wi.height / 2. * .33), wi.width - wi.width * .90, (wi.height / 2.) + (wi.height / 2. * .33)); GrLine(tictactoe_wid, tictactoe_gc, (wi.width / 2.) - (wi.width / 2. * .33), wi.height * .90, (wi.width / 2.) - (wi.width / 2. * .33), wi.height - wi.height * .90); GrLine(tictactoe_wid, tictactoe_gc, (wi.width / 2.) + (wi.width / 2. * .33), wi.height * .90, (wi.width / 2.) + (wi.width / 2. * .33), wi.height - wi.height * .90); currSquare = 0; drawXO(currSquare, GRAY, 'x'); }
/* Draw the message if it's a mini */ void draw_message(char *msg1, char *msg2) { int offset; /* Clear the window */ GrClearWindow(message_wid, GR_FALSE); /* Put the foreground and background in good shapes */ GrSetGCForeground(tuxchess_gc, GR_RGB(0,0,0)); GrSetGCBackground(tuxchess_gc, GR_RGB(255,255,255)); /* Draw the "window" */ GrLine(message_wid, tuxchess_gc, 1, 0, 34, 0); GrLine(message_wid, tuxchess_gc, 1, 16, 34, 16); GrLine(message_wid, tuxchess_gc, 1, 0, 1, 110); GrLine(message_wid, tuxchess_gc, 34, 0, 34, 110); GrLine(message_wid, tuxchess_gc, 1, 110, 34, 110); GrText(message_wid, tuxchess_gc, 3,13, "Chess", -1, GR_TFASCII); /* Title in the text box */ GrText(message_wid, tuxchess_gc, 3,73, msg1, -1, GR_TFASCII); if ((strcmp(msg2, "Play") == 0) || (strcmp(msg2, " ") == 0)) { offset = 3; msg2 = "Play"; } else { offset = 0; } GrText(message_wid, tuxchess_gc, 4+offset,53, msg2, -1, GR_TFASCII); }
static void chopRenderTerrain(CTerrain *ter) { int i=1; GrSetGCForeground(chopGC, GR_RGB(BLACK)); while(i < ter->iNodesCount) { int x = ter->mNodes[i-1].x - iCameraPosX; int y = ter->mNodes[i-1].y; int x2 = ter->mNodes[i].x - iCameraPosX; int y2 = ter->mNodes[i].y; GrLine(chopBuffer, chopGC, x,y,x2,y2); GrLine(chopBuffer, chopGC, x,y - 1,x2,y2 - 1); GrLine(chopBuffer, chopGC, x,y + 1,x2,y2 + 1); //Draw a number above it to aid with debugging /* char num[2]; sprintf(num,"%d",i); GrText(chopBuffer, gc, x2, y2, num, -1, GR_TFASCII);*/ i++; } }
/* ***********************************************************/ void draw_historic(void) { /* Clear the window */ GrClearWindow (historic_wid, GR_FALSE); /* Put the foreground and background in good shapes */ GrSetGCForeground(tuxchess_gc, GR_RGB(0,0,0)); GrSetGCBackground(tuxchess_gc, GR_RGB(255,255,255)); /* Draw the "window" */ GrLine(historic_wid, tuxchess_gc, 1, 1, 55, 1); GrLine(historic_wid, tuxchess_gc, 1, 1, 1, 104); GrLine(historic_wid, tuxchess_gc, 1, 105, 55, 105); GrLine(historic_wid, tuxchess_gc, 55, 1, 55, 105); GrText(historic_wid, tuxchess_gc, 14,14, "Moves", -1, GR_TFASCII); /* Title in the text box */ GrLine(historic_wid, tuxchess_gc, 1, 17, 56, 17); /* So ugly code since char* arrays seem to confuse my iPod - writes 6 lines */ GrText(historic_wid, tuxchess_gc, 6, 33, historic_line1, -1, GR_TFASCII); GrText(historic_wid, tuxchess_gc, 6, 46, historic_line2, -1, GR_TFASCII); GrText(historic_wid, tuxchess_gc, 6, 59, historic_line3, -1, GR_TFASCII); GrText(historic_wid, tuxchess_gc, 6, 72, historic_line4, -1, GR_TFASCII); GrText(historic_wid, tuxchess_gc, 6, 85, historic_line5, -1, GR_TFASCII); GrText(historic_wid, tuxchess_gc, 6, 99, historic_line6, -1, GR_TFASCII); }
U0 Init(CDC *dc) { I64 i,w=Fs->win_pixel_width,h=Fs->win_pixel_height; F64 scale=h/5.0; DocClear; DCFill(dc); dc->color=BLACK; GrLine(dc,0,h/2,w-1,h/2); GrLine(dc,w/2,0,w/2,h-1); for (i=-2;i<=2;i++) { dc->color=BLACK; GrLine(dc,w/2-3,h/2-scale*i,w/2+3,h/2-scale*i); if (i) { dc->color=DKGRAY; GrPrintF(dc,w/2+5,h/2-scale*i-FONT_HEIGHT/2,"%5.1f",ToF64(i)); } } for (i=-4;i<=4;i++) { dc->color=BLACK; GrLine(dc,w/2+scale*i,h/2-3,w/2+scale*i,h/2+3); if (i) { dc->color=DKGRAY; GrPrintF(dc,w/2+scale*i-7*FONT_WIDTH/2,h/2+5+FONT_HEIGHT,"%5.1f*T",ToF64(i)); } } }
U0 DrawSliderCtrl(CDC *dc,CCtrl *c) { CSliderState *s=c->state; dc->color=LTRED; GrRect(dc, c->left,c->top,SLIDER_SPACING*3+2,SLIDER_SPACING*2+SLIDER_RANGE); dc->color=BLUE; GrRect(dc, c->left+SLIDER_BORDER,c->top+SLIDER_BORDER, SLIDER_SPACING*3+2-2*SLIDER_BORDER,SLIDER_SPACING*2+SLIDER_RANGE-2*SLIDER_BORDER); dc->color=BLACK; GrLine(dc,c->left+1*SLIDER_SPACING+0,c->top+SLIDER_SPACING, c->left+1*SLIDER_SPACING+0,c->top+SLIDER_SPACING+SLIDER_RANGE-1); GrLine(dc,c->left+2*SLIDER_SPACING+1,c->top+SLIDER_SPACING, c->left+2*SLIDER_SPACING+1,c->top+SLIDER_SPACING+SLIDER_RANGE-1); dc->color=LTRED; GrPrintF(dc,c->left+1*SLIDER_SPACING+0-FONT_WIDTH/2, c->top+SLIDER_SPACING+SLIDER_RANGE+3, "%d",s->left_pos*10/SLIDER_RANGE); GrPrintF(dc,c->left+2*SLIDER_SPACING+1-FONT_WIDTH/2, c->top+SLIDER_SPACING+SLIDER_RANGE+3, "%d",s->right_pos*10/SLIDER_RANGE); GrRect(dc,c->left+1*SLIDER_SPACING+0-3,c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->left_pos-2,7,5); GrRect(dc,c->left+2*SLIDER_SPACING+1-3,c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->right_pos-2,7,5); dc->color=YELLOW; GrRect(dc,c->left+1*SLIDER_SPACING+0-2,c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->left_pos-1,5,3); GrRect(dc,c->left+2*SLIDER_SPACING+1-2,c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->right_pos-1,5,3); }
static void idw_draw_sheet(TSheet *sheet) { GR_SIZE width, height, base; char str[50], *ap; int i; if (sheet == NULL) { sheet = game.screen->menuitems[game.select].sheet; } // draw the title pz_draw_header (sheet->title); GrGetGCTextSize(idw_gc, sheet->button, -1, GR_TFASCII, &width, &height, &base); height+=4; // (left, top, right, bottom) GrSetGCForeground(idw_gc, BLACK); GrLine(idw_wid, idw_gc, 20, 0, 20, screen_info.rows-44); GrLine(idw_wid, idw_gc, 20, screen_info.rows-44, screen_info.cols-20, screen_info.rows-44); GrLine(idw_wid, idw_gc, screen_info.cols-20, 0, screen_info.cols-20, screen_info.rows-44); GrSetGCForeground(idw_gc, WHITE); GrFillRect(idw_wid, idw_gc, 21, 0, screen_info.cols-41, screen_info.rows-44); GrSetGCForeground(idw_gc, BLACK); GrSetGCUseBackground(idw_gc, GR_FALSE); GrSetGCMode(idw_gc, GR_MODE_SET); ap = strtok(sheet->text, "\n"); for (i=0; ap != NULL; i++) { GrText(idw_wid, idw_gc, 30, 1 + ((i + 1) * height - 4), ap, -1, GR_TFASCII); ap = strtok(NULL, "\n"); } if (sheet->ammount != -1) { // print ammount sprintf(str, "Ammount: %d", game.ammount); GrText(idw_wid, idw_gc, 30, 50, str, -1, GR_TFASCII); } else { // the next time the user presses the middle button the sheet will disappear game.dismiss_sheet = 1; } // print the single menu option GrSetGCForeground(idw_gc, BLACK); GrFillRect(idw_wid, idw_gc, 21, 1 + 4 * height-4, screen_info.cols-41, height-1); GrSetGCForeground(idw_gc, WHITE); GrSetGCUseBackground(idw_gc, GR_TRUE); GrText(idw_wid, idw_gc, (screen_info.cols/2)-width+4, (5 * height - 8), sheet->button, -1, GR_TFASCII); // we're in a transaction game.in_transaction = 1; }
static void draw_first() { GrLine(ipobble_wid,ipobble_gc, BRD_MINX, 0, BRD_MINX, BRD_MAXY+ME_RADIUS); GrLine(ipobble_wid,ipobble_gc, BRD_MAXX, 0, BRD_MAXX, BRD_MAXY+ME_RADIUS); GrLine(ipobble_wid,ipobble_gc, 0, BRD_MAXY+ME_RADIUS, BRD_MAXX, BRD_MAXY+ME_RADIUS); update_score(); }
/* Draw the king */ void draw_king(int coord_x, int coord_y, int color) { GrSetGCForeground(tuxchess_gc,BLACK); GrLine(tuxchess_wid,tuxchess_gc,coord_x+6,coord_y+1,coord_x+6,coord_y+4); GrLine(tuxchess_wid,tuxchess_gc,coord_x+4,coord_y+2,coord_x+8,coord_y+2); if(color == 0) GrSetGCForeground(tuxchess_gc,WHITE); GrFillEllipse(tuxchess_wid,tuxchess_gc,coord_x+6,coord_y+8,4,4); GrSetGCForeground(tuxchess_gc,BLACK); GrEllipse(tuxchess_wid,tuxchess_gc,coord_x+6,coord_y+8,4,4); }
/* Draw the king */ void draw_king(int coord_x, int coord_y, char color) { GrSetGCForeground(tuxchess_gc,GR_RGB(0,0,0)); GrLine(tuxchess_wid,tuxchess_gc,coord_x+6,coord_y+1,coord_x+6,coord_y+4); GrLine(tuxchess_wid,tuxchess_gc,coord_x+4,coord_y+2,coord_x+8,coord_y+2); if(color == 'w') GrSetGCForeground(tuxchess_gc,GR_RGB(255,255,255)); GrFillEllipse(tuxchess_wid,tuxchess_gc,coord_x+6,coord_y+8,4,4); GrSetGCForeground(tuxchess_gc,GR_RGB(0,0,0)); GrEllipse(tuxchess_wid,tuxchess_gc,coord_x+6,coord_y+8,4,4); }
U0 DrawIt(CTask *,CDC *dc) { I64 i,x,y; x=30+50*((tM-t0)%3); y=40; SpritePlot3(dc,x,y,0,$IB,"<1>",1$); dc->color=YELLOW; for (i=0;i<5;i++) GrLine(dc,x,y,x+RandI16%100,y+RandI16%50+50); dc->color=WHITE; for (i=0;i<5;i++) GrLine(dc,x,y,x+RandI16%100,y+RandI16%50+50); }
//------------------------------------------------------------------------------ // blob_vertices has 3 vertices in it, 4th must be computed void DrawBlobOutline (void) { fix v3x, v3y; v3x = blob_vertices[4] - blob_vertices[2] + blob_vertices[0]; v3y = blob_vertices[5] - blob_vertices[3] + blob_vertices[1]; GrSetColorRGB (255, 255, 255, 255); GrLine (blob_vertices[0], blob_vertices[1], blob_vertices[2], blob_vertices[3]); GrLine (blob_vertices[2], blob_vertices[3], blob_vertices[4], blob_vertices[5]); GrLine (blob_vertices[4], blob_vertices[5], v3x, v3y); GrLine (v3x, v3y, blob_vertices[0], blob_vertices[1]); }
/* * Here when a keyboard press occurs. */ void do_keystroke(GR_EVENT_KEYSTROKE *kp) { GR_SIZE width; /* width of character */ GR_SIZE height; /* height of character */ GR_SIZE base; /* height of baseline */ if (kp->wid == w4) { if (lineok) { GrLine(w4, gc4, xorxpos, xorypos, linexpos, lineypos); lineok = GR_FALSE; } return; } GrGetGCTextSize(gc1, &kp->ch, 1, GR_TFASCII, &width, &height, &base); if ((kp->ch == '\r') || (kp->ch == '\n')) { xpos = begxpos; ypos += height; return; } if (kp->ch == '\b') { /* assumes fixed width font!! */ if (xpos <= begxpos) return; xpos -= width; GrSetGCForeground(gc3, BROWN); GrFillRect(w1, gc3, xpos, ypos - height + base + 1, width, height); return; } GrText(w1, gc1, xpos, ypos + base, &kp->ch, 1, 0); xpos += width; }
static void draw_first() { GrLine(invaders_wid,invaders_gc, 0, screen_info.rows-HEADER_TOPLINE-2-4, screen_info.cols-1, screen_info.rows-HEADER_TOPLINE-2-4); update_score(); onetime=0; }
static void GrLineWrapper(void *r) { nxLineReq *req = r; GrLine(req->drawid, req->gcid, req->x1, req->y1, req->x2, req->y2); }
U0 FunDraw2(CDC *dc,F64 (*f)(F64 t,F64 p),F64 T) { I64 i,w=Fs->win_pixel_width,h=Fs->win_pixel_height; F64 scale=h/5.0; for (i=-w/2;i<=w/2;i++) GrLine(dc,w/2+i,h/2-scale*f(i/scale,T),w/2+i+1,h/2-scale*f((i+1)/scale,T)); }
static void draw_special(void) { int xpos = MSCURSOR->xcord; int ypos = MSCURSOR->ycord; int check = MOUINFO->docheck; GrContext csave; MOUINFO->docheck = FALSE; GrSaveContext(&csave); GrSetContext(SCRN); switch (CURSORMODE) { case GR_M_CUR_RUBBER: GrBox(xpos, ypos, MOUINFO->x1, MOUINFO->y1, MOUINFO->curscolor); break; case GR_M_CUR_LINE: GrLine(xpos, ypos, MOUINFO->x1, MOUINFO->y1, MOUINFO->curscolor); break; case GR_M_CUR_BOX: GrBox((xpos+MOUINFO->x1), (ypos+MOUINFO->y1), (xpos+MOUINFO->x2), (ypos+MOUINFO->y2), MOUINFO->curscolor); break; } GrSetContext(&csave); MOUINFO->docheck = check; }
static void draw_screen(void) { GR_POINT tri[4] = { {5, 115}, {105, 115}, {55, 200}, {5, 115} }; GR_WINDOW_INFO winfo; GR_GC_ID gc; char dash1[2] = { 10, 5 }; char dash2[4] = { 5, 2, 1, 2 }; char dash3[4] = { 5, 2, 5, 5 }; char dash4[2] = { 2, 2 }; GrGetWindowInfo(g_main, &winfo); /* Draw several lines and a few boxes */ gc = GrNewGC(); GrSetGCLineAttributes(gc, GR_LINE_ONOFF_DASH); /* Draw a dashed box */ GrSetGCDash(gc, dash1, 2); GrRect(g_main, gc, 5, 5, 100, 100); GrSetGCDash(gc, dash2, 4); GrLine(g_main, gc, 10, 10, 95, 95); GrSetGCDash(gc, dash3, 4); GrEllipse(g_main, gc, 160, 55, 50, 50); GrSetGCDash(gc, dash4, 2); GrPoly(g_main, gc, 4, tri); GrDestroyGC(gc); }
int XDrawLines(Display * dpy, Drawable d, GC gc, XPoint * points, int npoints, int mode) // FIXME: mode ignored { GR_POINT beg, end; if (npoints < 1) return 1; if (npoints == 1) { GrPoint(d, gc->gid, points->x, points->y); return 1; } /* must copy since X points are shorts, Nano-X are MWCOORDs (int) */ beg.x = points->x; beg.y = points->y; ++points; while (--npoints > 0) { end.x = points->x; end.y = points->y; ++points; GrLine(d, gc->gid, beg.x, beg.y, end.x, end.y); beg = end; } return 1; }
//This routine updates the window. It is called //by the window mgr system task. The task refers to //the task which owns the window. U0 DrawIt(CTask *task,CDC *dc) { I64 i,j; //<CTRL-T> now to see the hidden part //where the sprite num is encoded. IB stands //for "insert ptr to binary object". SpritePlot3(dc,x,y,0,$IB,"<1>",1$); i=shots_out; while (i!=shots_in) { j=i++ &(MAX_SHOTS-1); GrLine(dc,sx[j],sy[j],sx[j]-2,sy[j]); } i=dead_out; while (i!=dead_in) { j=i++ &(MAX_SHOTS-1); if (!g_dead[j]) { if (gx[j]%10>5) SpritePlot3(dc,gx[j],gy[j],0,$IB,"<2>",2$); else SpritePlot3(dc,gx[j],gy[j],0,$IB,"<3>",3$); } } i=0; PlotWinStr(task,"If you aspire to making games,",BLUE<<4+YELLOW,0,i++); PlotWinStr(task,"you must learn to make-up rules.",BLUE<<4+YELLOW,0,i++); }
/* Draw a line with color c to bitmap bm. */ void ws_bmdrawline(struct ws_bitmap *bm, int x1, int y1, int x2, int y2, int c, int xor) { GrSetContext( (GrContext *)bm->bitmap ); GrLine( x1, y1, x2, y2, c | (xor ? GrXOR : 0) ); GrSetContext(NULL); }
void redraw(GR_WINDOW_ID wid, GR_GC_ID *gc) { int i, y; for(i = 0; i < NUMGCS; i++) for(y = 40; y < WINDOW_HEIGHT; y += 3) GrLine(wid, gc[i], 0, y, WINDOW_WIDTH - 1, y - 40); }
/* * Here when a button is released. */ void do_buttonup(GR_EVENT_BUTTON *bp) { if (bp->wid == w4) { if (lineok) { GrLine(w4, gc4, xorxpos, xorypos, linexpos, lineypos); GrLine(w4, gc3, bp->x, bp->y, linexpos, lineypos); } lineok = GR_FALSE; return; } if (bp->wid == w2) { GrClose(); exit(0); } }
/* * Redraw the board. */ static void drawboard(void) { GR_COORD row; GR_COORD col; for (row = 1; row < size; row++) { GrLine(boardwid, boardgc, 0, row * yp - 1, size * xp - 1, row * yp - 1); GrLine(boardwid, boardgc, row * xp - 1, 0, row * xp - 1, size * yp - 1); } for (row = 0; row < FULLSIZE; row++) { for (col = 0; col < FULLSIZE; col++) { drawcell(boardpos(row, col)); } } }
/* * Here when a button is released. */ void do_buttonup(GR_EVENT_BUTTON *bp) { if (bp->wid == w4) { if (lineok) { GrLine(w4, gc4, xorxpos, xorypos, linexpos, lineypos); GrLine(w4, gc3, bp->x, bp->y, linexpos, lineypos); } lineok = GR_FALSE; GrCopyArea(w1, gc4, 200,200, 200,200, p1,0,0,MWROP_COPY); return; } if (bp->wid == w2) { GrClose(); exit(0); } }
// width=x2, height=y2 void CObjectLine::Draw() { if(m_wid && m_gc) { GrSetGCForeground(m_gc, m_Color); if(m_isDash) { GrSetGCLineAttributes(m_gc, GR_LINE_ONOFF_DASH); GrSetGCDash(m_gc, g_dash_patern, 2); GrLine(m_wid, m_gc, m_rect.x, m_rect.y, m_rect.w, m_rect.h); GrSetGCLineAttributes(m_gc, GR_LINE_SOLID); } else { GrLine(m_wid, m_gc, m_rect.x, m_rect.y, m_rect.w, m_rect.h); } } }
/* * Here when the mouse has a motion event. */ void do_motion(GR_EVENT_MOUSE *mp) { if (mp->wid == w4) { if (lineok) { GrLine(w4, gc4, xorxpos, xorypos, linexpos, lineypos); xorxpos = mp->x; xorypos = mp->y; GrLine(w4, gc4, xorxpos, xorypos, linexpos, lineypos); } return; } if (mp->wid == w3) { GrPoint(w3, gc3, mp->x, mp->y); return; } }
U0 DotNet() { I64 i; CDC *dc=DCAlias; DocClear; //Clear text dc->color=RED; for (i=0;i<480;i+=20) GrLine(dc,i,0,0,480-i,3); DCDel(dc); PressAKey; DCFill; }
static void idw_draw_screen() { int i, dif=0, max=0; GR_SIZE width, height, base; // This white line is printed because the sheet leaves two pixels GrSetGCForeground(idw_gc, WHITE); GrLine(idw_wid, idw_gc, 0, 0, screen_info.cols, 0); GrSetGCForeground(idw_gc, BLACK); // calculate the biggest space you can leave for the right-side column for (i=0; i < game.screen->count; i++) { GrGetGCTextSize(idw_gc, game.screen->menuitems[i].value, -1, GR_TFASCII, &width, &height, &base); width+=5; if (width > max) max = width; } GrGetGCTextSize(idw_gc, "M", -1, GR_TFASCII, &width, &height, &base); height += 4; // print all the menus for (i=0; i < game.screen->count; i++) { if ((game.select == i) && (game.screen->menuitems[i].sheet)) { GrSetGCForeground(idw_gc, BLACK); GrFillRect(idw_wid, idw_gc, 0, 1 + i * height, screen_info.cols, height); GrSetGCForeground(idw_gc, WHITE); GrSetGCUseBackground(idw_gc, GR_TRUE); } else { GrSetGCUseBackground(idw_gc, GR_FALSE); GrSetGCForeground(idw_gc, WHITE); GrFillRect(idw_wid, idw_gc, 0, 1 + i * height, screen_info.cols, height); GrSetGCForeground(idw_gc, BLACK); } // highlite drug's name if you can make a positive sale if ((game.screen == &sell) && (game.drugs[i])) { dif = (game.price[i]*game.drugs[i] - game.old_price[i]); if (dif > 0) { GrText(idw_wid, idw_gc, 9, 1 + ((i + 1) * height - 4), game.screen->menuitems[i].caption, -1, GR_TFASCII); } } GrText(idw_wid, idw_gc, 8, 1 + ((i + 1) * height - 4), game.screen->menuitems[i].caption, -1, GR_TFASCII); // right-side column GrText(idw_wid, idw_gc, screen_info.cols - max, 1 + ((i + 1) * height - 4), game.screen->menuitems[i].value, -1, GR_TFASCII); } }
int XDrawSegments(Display * dpy, Drawable d, GC gc, XSegment * segments, int nsegments) { int i; for (i = 0; i < nsegments; i++) { GrLine(d, gc->gid, segments[i].x1, segments[i].y1, segments[i].x2, segments[i].y2); } return 1; }