📄 mfbbasic.c
字号:
MFBGenCode(MFBFORMAT.endPlygnSequence); }voidMFBPolygon(p) MFBPOLYGON *p; /* * Notes: * Draws a polygon with n vertices in the current fill pattern. */{ int *xy0,*xy1,n; xy0 = xy1 = p->xy; MFBCurrent->Z = n = p->nvertices; if(n <= 0) return; MFBCurrent->X = *xy1++; MFBCurrent->Y = *xy1++; if(MFBCurrent->fillPattern == 0 && MFBFORMAT.beginSolidPlygnSequence != NULL && *MFBFORMAT.beginSolidPlygnSequence != 0) MFBGenCode(MFBFORMAT.beginSolidPlygnSequence); else MFBGenCode(MFBFORMAT.beginPlygnSequence); n--; while(n--) { MFBCurrent->X = *xy1++; MFBCurrent->Y = *xy1++; MFBGenCode(MFBFORMAT.sendPlygnVertex); } MFBCurrent->X = *xy0; MFBCurrent->Y = *(xy0+1); MFBGenCode(MFBFORMAT.endPlygnSequence);}voidMFBText(text,x,y,phi) char *text; int x,y; int phi; /* angle of rotation in degrees */ /* * Notes: * Draws the string `text' in the current color with the lower * left corner at (x,y). */ { char *c; #ifdef DEBUG MFBCurrent->nChars += strlen(text);#endif if((phi != 0) && (MFBCurrent->textRotateBool == true)){ MFBCurrent->X = phi; MFBGenCode(MFBFORMAT.rotateTextSequence); } /* Move to (x + GTW),(Y + GTH). */ MFBCurrent->X = x + MFBCurrent->fontXOffset; MFBCurrent->Y = y + MFBCurrent->fontYOffset; /* Get ready for graphics text. */ c = text; MFBCurrent->Z = 0; while(*c++ != 0) (MFBCurrent->Z)++; MFBGenCode(MFBFORMAT.graphicsTextStart); /* Output the text. */ while(*text) MFBPutchar(*text++); /* Finish the graphics text */ MFBGenCode(MFBFORMAT.graphicsTextEnd); /* rotate text back to zero */ if((phi != 0) && (MFBCurrent->textRotateBool == true)){ MFBCurrent->X = 0; MFBGenCode(MFBFORMAT.rotateTextSequence); } }voidMFBPixel(x,y) int x,y; /* * Notes: * Sets the indicated pixel to the current foreground color. */ { MFBCurrent->X = x; MFBCurrent->Y = y; MFBGenCode(MFBFORMAT.writePixel); }voidMFBFlood() /* * Notes: * Floods the display with the current (foreground) color. */ { MFBCurrent->X = MFBCurrent->fgColorId; MFBGenCode(MFBFORMAT.screenFlood); /* * MFBFlood may destroy last x/y,so be safe about it. */ MFBCurrent->lastX = MFBCurrent->lastY = -1; }MFBPATH*MFBArcPath(x,y,r,astart,astop,s) int x; /* x coordinate of center */ int y; /* y coordinate of center */ int r; /* radius of arc */ int astart; /* initial angle ( +x axis = 0 degrees ) */ int astop; /* final angle ( +x axis = 0 degrees ) */ int s; /* number of segments in a 360 degree arc */ /* * Notes: * Returns MFBPATH containing an arc. */ { static MFBPATH pth; static int xy[400]; int *ip,i,j; double d; pth.xy = ip = xy; while(astart >= astop) astop += 360; if(s<2 || s>180) s = 20; pth.nvertices = 2; j = MFBmax(1,(astop - astart)/s); d = astart / RadToDeg; *ip++ = x + (int)(r * cos(d)); *ip++ = y + (int)(r * sin(d)); for(i = astart + j; i <= astop; i += j){ d = i / RadToDeg; *ip++ = x + (int)(r * cos(d)); *ip++ = y + (int)(r * sin(d)); ++pth.nvertices; } d = astop / RadToDeg; *ip++ = x + (int)(r * cos(d)); *ip = y + (int)(r * sin(d)); return(&pth); }MFBPOLYGON*MFBEllipse(x,y,rx,ry,s) int x; /* x coordinate of center */ int y; /* y coordinate of center */ int rx; /* radius of ellipse in x direction */ int ry; /* radius of ellipse in y direction */ int s; /* number of line segments in circle (default = 20) */ /* * Notes: * Returns MFBPOLYGON containing an ellipse with no more than 200 coords. */ { static MFBPOLYGON poly; static int xy[400]; int i=0; int j; int *ip; double d=0; poly.xy = ip = xy; *ip++ = x + rx; *ip++ = y; if(s>2 && s<181) j = 360/s; else { j = 18; s = 20; } poly.nvertices = s + 1; while(--s) { i += j; d = i / RadToDeg; *ip++ = x + (int)(rx * cos(d)); *ip++ = y + (int)(ry * sin(d)); } *ip++ = x + rx; *ip++ = y; return(&poly); }/***********************************************************************//*/* WINDOW CONTROL/*/***********************************************************************/#define WNDW MFBCurrent->currentWindow#define VWPRT MFBCurrent->currentViewportintMFBScaleX(X) int X; { int XX; XX = (int)(((double)(X-WNDW.left)*VWPRT.length)/WNDW.length) + VWPRT.left; if(XX < VWPRT.left) XX = VWPRT.left; else if(XX > VWPRT.right) XX = VWPRT.right; return(XX); }intMFBScaleY(Y) int Y; { int YY; YY = (int)(((double)(Y-WNDW.bottom)*VWPRT.width)/WNDW.width) + VWPRT.bottom; if(YY < VWPRT.bottom) YY = VWPRT.bottom; else if(YY > VWPRT.top) YY = VWPRT.top; return(YY); }intMFBDescaleX(X) int X; { int XX; XX = ((X-VWPRT.left)*WNDW.length)/VWPRT.length+WNDW.left; return(XX); }intMFBDescaleY(Y) int Y; { int YY; YY = ((Y-VWPRT.bottom)*WNDW.width)/VWPRT.width+WNDW.bottom; return(YY); }voidMFBSetViewport(left,bottom,right,top) int left,bottom,right,top; { VWPRT.bottom = bottom; VWPRT.top = top; VWPRT.left = left; VWPRT.right = right; VWPRT.length = VWPRT.right - VWPRT.left; VWPRT.width = VWPRT.top - VWPRT.bottom; }voidMFBSetWindow(left,bottom,right,top) int left,bottom,right,top; { WNDW.bottom = bottom; WNDW.top = top; WNDW.left = left; WNDW.right = right; WNDW.length = WNDW.right - WNDW.left; WNDW.width = WNDW.top - WNDW.bottom; }/* This wasn't in here, for some reason. *//* MFBNaiveBoxFill simulates stipple patterns */voidMFBNaiveBoxFill(left, bottom, right, top){ int step; int incr; int incr2; int ll, bb, rr, tt; if (top < bottom) MFBSwapInt (top, bottom); if (right < left) MFBSwapInt (left, right); incr = MFBmax (MFBmax (MFBCurrent->maxX, MFBCurrent->maxY) / 400, 1); step = incr * 5; incr2 = incr + (incr >> 1); ll = left; bb = bottom; rr = right; tt = top; switch (MFBCurrent->fillPattern) { case 0: /* * solid */ if ((right - left) > (top - bottom)) { for (bb = bottom; bb <= top; bb += incr) MFBLine (ll, bb, rr, bb); } else { for (ll = left; ll <= right; ll += incr) MFBLine (ll, bb, ll, tt); } break; case 1: /* * horizontal striped */ for (bb = bottom; bb < top; bb += step) MFBLine (ll, bb, rr, bb); break; case 2: /* * vertical striped */ for (ll = left; ll < right; ll += step) MFBLine (ll, bb, ll, tt); break; case 3: /* * diagonal lines */ ll += step; bb += step; while (ll < right && bb < top) { MFBLine (left, bb, ll, bottom); ll += step; bb += step; } if (ll >= right) { while (bb < top) { MFB_Y_Intercept (left, bb, ll, bottom, right, &tt); MFBLine (left, bb, right, tt); bb += step; ll += step; } } else { while (ll < right) { MFB_X_Intercept (left, bb, ll, bottom, top, &rr); MFBLine (rr, top, ll, bottom); bb += step; ll += step; } } while (rr <= right && tt <= top) { MFB_X_Intercept (left, bb, ll, bottom, top, &rr); MFB_Y_Intercept (left, bb, ll, bottom, right, &tt); if (rr > right || tt > top) break; MFBLine (rr, top, right, tt); bb += step; ll += step; } break; case 4: /* * diagonal lines */ rr -= step; bb += step; while (rr > left && bb < top) { MFBLine (rr, bottom, right, bb); rr -= step; bb += step; } if (rr <= left) { while (bb < top) { MFB_Y_Intercept (rr, bottom, right, bb, left, &tt); MFBLine (left, tt, right, bb); bb += step; rr -= step; } } else { while (rr > left) { MFB_X_Intercept (rr, bottom, right, bb, top, &ll); MFBLine (rr, bottom, ll, top); bb += step; rr -= step; } } while (ll >= left && tt <= top) { MFB_X_Intercept (rr, bottom, right, bb, top, &ll); MFB_Y_Intercept (rr, bottom, right, bb, left, &tt); if (ll < left || tt > top) break; MFBLine (left, tt, ll, top); bb += step; rr -= step; } break; case 5: /* * plus signs */ for (bb = bottom; bb < top; bb += (step + step)) { for (ll = left; ll < right; ll += step) { MFBLine (ll - incr2, bb, ll + incr2, bb); MFBLine (ll, bb - incr2, ll, bb + incr2); } } break; case 6: /* * x's */ for (bb = bottom; bb < top; bb += (step + step)) { for (ll = left; ll < right; ll += step) { MFBLine (ll - incr2, bb - incr2, ll + incr2, bb + incr2); MFBLine (ll - incr2, bb + incr2, ll + incr2, bb - incr2); } } break; default: case 7: /* * outline */ MFBLine (left, bottom, left, top); MFBLine (left, top, right, top); MFBLine (right, top, right, bottom); MFBLine (right, bottom, left, bottom); break; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -