⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xdriver.c

📁 占星术4.0源码
💻 C
📖 第 1 页 / 共 3 页
字号:
          case 'n'-'`': coldrw = DKBLUE;  break;
          case 'u'-'`': coldrw = PURPLE;  break;
          case 'k'-'`': coldrw = DKCYAN;  break;
          case 'l'-'`': coldrw = LTGRAY;  break;
          case 'd'-'`': coldrw = DKGRAY;  break;
          case 'r'-'`': coldrw = RED;     break;
          case 'g'-'`': coldrw = GREEN;   break;
          case 'y'-'`': coldrw = YELLOW;  break;
          case 'b'-'`': coldrw = BLUE;    break;
          case 'v'-'`': coldrw = MAGENTA; break;
          case 'j'-'`': coldrw = CYAN;    break;
          case 'a'-'`': coldrw = WHITE;   break;
#endif
          case 'q': case ESCAPE: case '\3':
            xbreak = TRUE;
            break;
          default:
            if (i > '0' && i <= '9') {
#ifdef MSG
              if (xnow)
#endif
                /* Process numbers 1..9 signifying animation rate. */
                dir = (dir > 0 ? 1 : -1)*(i-'0');
#ifdef MSG
              else {
                /* If we aren't in animation mode, then 1..9 refers to the */
                /* clipping "quadrant" to use if chart size > screen size. */
                xcorner = i-'0';
                xresize = TRUE;
              }
#endif
            break;
            }
            printc(BELL);    /* Any key not bound will sound a beep. */
          }  /* switch */
        }  /* if */
#ifdef X11
      default:
        ;
      }  /* switch */
    }  /* if */
#endif
  }  /* while */
}


/* This is called right before program termination to get rid of the window. */

void XEnd()
{
#ifdef X11
  XFreeGC(disp, gc);
  XFreeGC(disp, pmgc);
  XFreePixmap(disp, pixmap);
  XDestroyWindow(disp, window);
  XCloseDisplay(disp);
#else
  _setvideomode(_DEFAULTMODE);
#endif
}
#endif /* ISG */


/*
******************************************************************************
** Main graphics processing
******************************************************************************
*/

/* Print a list of every command switch dealing with the graphics features  */
/* that can be passed to the program, and a description of what it does.    */
/* This is part of what the -H switch prints, if graphics were compiled in. */

void XDisplaySwitches()
{
  Prints(" _X: Create a graphics chart instead of displaying it as text.");
#ifdef ISG
  Prints(" _Xb: Create bitmap file instead of putting graphics on screen.");
#endif
  Prints(" _Xb[n,c,v,a,b]: Set bitmap file output mode to X11 normal,");
  Prints("     compacted, very compact, Ascii (bmtoa), or Windows bmp.");
#ifdef PS
  Prints(" _Xp: Create PostScript stroke graphic instead of bitmap file.");
  Prints(" _Xp0: Like _Xp but create complete instead of encapsulated file.");
#endif
#ifdef META
  Prints(" _XM[0]: Create Windows metafile stroke graphic instead of bitmap.");
#endif
  Prints(" _Xo <file>: Write output bitmap or graphic to specified file.");
#ifdef X11
  Prints(" _XB: Display X chart on root instead of in a separate window.");
#endif
  Prints(" _Xm: Create monochrome graphic instead of one in color.");
  Prints(" _Xr: Create chart graphic in reversed colors (white background).");
#ifdef X11
  Prints(" _Xw <hor> [<ver>], _ge[..]: Change the size of chart graphic.");
#else
  Prints(" _Xw <hor> [<ver>]: Change the size of chart graphic.");
#endif
  Prints(" _Xs <100,200,300>: Change the size of map or characters by n%.");
  Prints(" _Xi: Create chart graphic in slightly modified form.");
  Prints(" _XT: Inhibit display of chart info at bottom of graphic.");
  Prints(" _Xl: Inhibit labeling of object points in chart graphic.");
  Prints(" _X1 <object>: Rotate wheel charts so object is at left edge.");
  Prints(" _X2 <object>: Rotate wheel charts so object is at top edge.");
#ifdef X11
  Prints(" _Xd <name>, _di[..] <name>: Open X window on specified display.");
#endif
  Prints(" _XW: Simply create an image of the world map.");
  Prints(" _XW0: Like _XW but do a non-rectangular Mollewide projection.");
  Prints(" _XP: Create just the world map, but from a polar projection.");
  Prints(" _XG [<degrees>]: Display the image of the world as a globe.");
#ifdef ISG
  Prints(" _Xn [<mode>]: Start up chart or globe display in animation mode.");
  Prints("Also, press 'H' while running for list of key press options.");
#endif
}


/* Process a command line switch passed to the program dealing with the      */
/* graphics features. This is just like the processing of each switch in the */
/* main program; however, here each switch has been prefixed with an 'X'.    */

int XProcessSwitches(argc, argv, pos)
int argc, pos;
char **argv;
{
  int i = 0;
  char string[STRING], c;

  switch (argv[0][pos]) {
  case '\0':
    break;

  case 'b':
    c = CAP(argv[0][pos+1]);
    if (IsValidBmpmode(c))
      bitmapmode = c;
    xbitmap = TRUE;
    psfile = metafile = FALSE;
    break;

#ifdef PS
  case 'p':
    psfile = TRUE + (argv[0][pos+1] != '0');
    xbitmap = metafile = FALSE;
    break;
#endif

#ifdef META
  case 'M':
    if (argv[0][pos+1] == '0')
      xfont = !xfont;
    metafile = TRUE;
    xbitmap = psfile = FALSE;
    break;
#endif

  case 'o':
    if (argc <= 1) {
      TooFew("Xo");
      return -1;
    }
    if (!xbitmap && !psfile && !metafile)
      xbitmap = TRUE;
    outputfile = argv[1];
    i++;
    break;

#ifdef X11
  case 'B':
    xroot = !xroot;
    break;
#endif

  case 'm':
    xcolor = !xcolor;
    break;

  case 'r':
    xreverse = !xreverse;
    break;

  case 'w':
    if (argc <= 1) {
      TooFew("Xw");
      return -1;
    }
    chartx = atoi(argv[1]);
    if (argc > 2 && (charty = atoi(argv[2]))) {
      argc--; argv++;
      i++;
    } else
      charty = chartx;
    if (!IsValidGraphx(chartx)) {
      BadVal("Xw", chartx);
      return -1;
    }
    if (!IsValidGraphy(charty)) {
      BadVal("Xw", charty);
      return -1;
    }
    i++;
    break;

  case 's':
    if (argc <= 1) {
      TooFew("Xs");
      return -1;
    }
    scale = atoi(argv[1]);
    if (scale < 100)
      scale *= 100;
    if (!IsValidScale(scale)) {
      BadVal("Xs", scale);
      return -1;
    }
    i++;
    break;

  case 'i':
    xbonus = !xbonus;
    break;

  case 'T':
    xtext = !xtext;
    break;

  case 'l':
    xlabel = !xlabel;
    break;

  case '1':
    if (argc <= 1) {
      TooFew("X1");
      return -1;
    }
    xeast = atoi(argv[1]);
    if (!IsItem(xeast)) {
      BadVal("X1", xeast);
      return -1;
    }
    i++;
    break;

  case '2':
    if (argc <= 1) {
      TooFew("X2");
      return -1;
    }
    xeast = atoi(argv[1]);
    if (!IsItem(xeast)) {
      BadVal("X2", xeast);
      return -1;
    }
    xeast = -xeast;
    i++;
    break;

  case 'd':
    if (argc <= 1) {
      TooFew("Xd");
      return -1;
    }
    dispname = argv[1];
    i++;
    break;

  case 'W':
    if (argc > 1 && ((degree = atoi(argv[1])) || argv[1][0] == '0')) {
      i++;
      if (degree < 0 || degree >= DEGR) {
        BadVal("XW", degree);
        return -1;
      }
    } else
      degree = 0;
    modex = MODEW;
    if (argv[0][pos+1] == '0')
      exdisplay |= DASHXW0;
    autom = TRUE;
    break;

  case 'P':
    if (argc > 1 && ((degree = atoi(argv[1])) || argv[1][0] == '0')) {
      i++;
      if (degree < 0 || degree >= DEGR) {
        BadVal("XP", degree);
        return -1;
      }
    } else
      degree = 0;
    modex = MODEP;
    if (argv[0][pos+1] == '0')
      exdisplay |= DASHXP0;
    autom = TRUE;
    break;

  case 'G':
    if (argc > 1 && ((degree = atoi(argv[1])) || argv[1][0] == '0')) {
      i++;
      if (degree < 0 || degree >= DEGR) {
        BadVal("XG", degree);
        return -1;
      }
      if (argc > 2 && ((tilt = atof(argv[2])) || argv[2][0] == '0')) {
        i++;
        if (tilt < -DEGQUAD || tilt > DEGQUAD) {
          BadVal2("XG", tilt);
          return -1;
        }
      }
    }
    modex = MODEG;
    autom = TRUE;
    break;

#ifdef ISG
  case 'n':
    if (argc > 1 && (xnow = atoi(argv[1])))
      i++;
    else
      xnow = 10;
    if (xnow < 1 || xnow > 10) {
      BadVal("Xn", xnow);
      return -1;
    }
    break;
#endif

  default:
    sprintf(string, "Unknown switch '%s'", argv[0]);
    PrintError(string);
    return -1;
  }
  return i;    /* 'i' contains the value to be added to argc when we return. */
}


/* This is the main interface to all the graphics features. This routine     */
/* is called from the main program if any of the -X switches were specified, */
/* and it sets up for and goes and generates the appropriate graphics chart. */
/* We return TRUE if successfull, FALSE if some non-fatal error occurred.    */

bool XAction()
{
  char string[STRING];

  xfile = (xbitmap || psfile || metafile);

  /* First figure out what graphic mode to generate the chart in, based on */
  /* various non-X command switches, e.g. -L combined with -X, -g combined */
  /* with -X, and so on, and determine the size the window is to be, too.  */

  if (modex == MODEv) {
    if (todisplay & DASHw)
      modex = MODEw;
    else if (todisplay & DASHL)
      modex = MODEL;
    else if ((todisplay & DASHg) | (todisplay & DASHm)) {
      modex = MODEg;
      if (relation <= DASHr0 &&
        (todisplay & DASHm) > 0 && (exdisplay & DASHm0) == 0)
        exdisplay |= DASHg0;
      chartx = charty =
				(gridobjects + (relation <= DASHr0))*CELLSIZE*SCALE + 1;
    } else if (todisplay & DASHZ)
      modex = MODEZ;
    else if (todisplay & DASHS)
      modex = MODES;
    else if (todisplay & DASHE)
      modex = MODEE;
    else if (relation == DASHrb)
      modex = MODEb;
  }
  if ((modex == MODEv || modex == MODEw) && !(exdisplay & DASHv0))
    chartx += SIDESIZE;
  if (modex == MODEL || modex == MODEW) {
    chartx = DEGR*SCALE+2;
    charty = (90*2+1)*SCALE+2;
  }
  if (xfile) {                       /* Initialize bitmap or window. */
    if (chartx > BITMAPX)
      chartx = BITMAPX;
    if (charty > BITMAPY)
      charty = BITMAPY;
    if (xbitmap) {
      bitmaprow = (chartx + 1) >> 1;
      Allocate(bm, (long)bitmaprow * charty, bitmap);
      if (bm == NULL) {
        sprintf(string,
          "Not enough memory for %d by %d bitmap (%ld bytes).",
          chartx, charty, (long)bitmaprow * charty);
        PrintError(string);
        return FALSE;
      }
    }
#ifdef PS
    else if (psfile)
    	PSbegin();
#endif
    else {
      Allocate(bm, MAXMETA, bitmap);
      if (bm == NULL) {
        sprintf(string,
          "Not enough memory for metafile. (%ld bytes.)", MAXMETA);
        PrintError(string);
        return FALSE;
      }
      chartx *= METAMUL;    /* Increase chart sizes and scales behind the */
      charty *= METAMUL;    /* scenes to make graphics look smoother.     */
      scale  *= METAMUL;
    }
    XColorInit();
  }
#ifdef ISG
  else
    XBegin();
#endif
  if (xroot || xfile)    /* Go draw the graphic chart. */
    XChart();
  if (xfile) {    /* Write bitmap to file if in that mode. */
    WriteFile();
    if (!psfile)
      Deallocate(bm);
  }
#ifdef ISG
  else {
#ifdef X11
    if (xroot) {
      XSetWindowBackgroundPixmap(disp, root, pixmap);    /* Process -XB. */
      XClearWindow(disp, root);

      /* If -Xn in effect with -XB, then enter infinite loop where we */
      /* calculate and animate chart, displaying on the root window.  */
      if (xnow)
        loop {
          Animate(xnow, 1);
          if (relation > DASHr0 || (modex != MODEZ && modex != MODES))
            XFillRectangle(disp, pixmap, pmgc, 0, 0, chartx, charty);
          XChart();
          XSetWindowBackgroundPixmap(disp, root, pixmap);
          XClearWindow(disp, root);
        }
    } else
#endif
      XSpin();    /* Window's up; process commands given to window now. */
    XEnd();
    return TRUE;
  }
#endif /* ISG */
}
#endif /* GRAPH */

/* xdriver.c */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -