home *** CD-ROM | disk | FTP | other *** search
/ Quake++ for Quake / Quake++.iso / quake / edquake / code / grfx.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-12  |  3.5 KB  |  132 lines

  1. /*EdQuake v0.50 source code
  2.   (c) Copyright 1996 Scott Mitting
  3.   email:smitting@netusa1.net
  4.   ----------------------------------
  5.   GRFX.C  -  Functions to assist the SVGACC library
  6.   note: this file is in it's early stages, many new functions
  7.     will be appearing
  8.  
  9.   __variables:
  10.   int RED               -- these are colors for the menu
  11.   int DKGRAY               commands so that you can use
  12.   int LTGRAY               different palettes and still
  13.   int WHITE               use high-level routines. There
  14.   int BLUE               may be an automatic adjuster
  15.   int BLACK               in the future
  16.   int YELLOW
  17.   __functions:
  18.   void fixpal(PaletteData tpal)  -- adjusts 24-bit palette to
  19.                     16-bit for VGA pallette routines
  20.   void impress(int x0, int y0, int x1, int y1)
  21.                  -- makes an impression is greys
  22.   void loadpcx(int x, int y, char *filename)
  23.                  -- loads a PCX file to screen at (x,y)
  24.   void showwadfile(int x, int y, int e)
  25.                  -- shows a console graphic from a wad
  26.   void scalepict(int x, int y, int xsize, int ysize, pict image)
  27.                  -- draws a scaled picture
  28.   void statusbar(int x0, int y0, int x1, int y1, long t1, long t2)
  29.                  -- draws a bar for percent of completion
  30.   ----------------------------------
  31.   the entire source code is under renovation to make it easier
  32.   to understand.  happy coding.
  33. */
  34.  
  35. #include "svgacc.h"
  36. #include "pak.h"
  37. #include "wad.h"
  38. #include "grfx.h"
  39.  
  40. int RED;
  41. int DKGRAY;
  42. int LTGRAY;
  43. int WHITE;
  44. int BLUE;
  45. int BLACK;
  46. int YELLOW;
  47.  
  48. void fixpal(PaletteData tpal)
  49. {
  50.     int i, fixit;
  51.     fixit = 0;
  52.     for(i=0;i<255;i++)
  53.         if((tpal[i].r>63) || (tpal[i].g>63) || (tpal[i].b>63))
  54.         fixit = 1;
  55.     if (fixit)
  56.         for(i=0;i<255;i++) {
  57.         tpal[i].r>>=2;
  58.         tpal[i].g>>=2;
  59.         tpal[i].b>>=2;
  60.         }
  61. }
  62.  
  63. void loadpcx(int x, int y, char *filename)
  64. {
  65.    PaletteData pcxpal;
  66.    int null;
  67.    if (pcxgetinfo(filename,&null,&null,&null,pcxpal))
  68.    {
  69.     fixpal(pcxpal);
  70.     palset(pcxpal,0,255);
  71.     pcxput(SET,x,y,filename);
  72.    }
  73. }
  74.  
  75. void showwadfile(int x, int y, int e)
  76. {
  77.    int xsize, ysize;
  78.    int cx, cy;
  79.    if (e < 0) return;
  80.    getwadentry(e);
  81.    fseek(pak.p, wadentry.loc, 0);
  82.    xsize = fgetl(pak.p);
  83.    ysize = fgetl(pak.p);
  84.    for (cy = 0; cy < ysize; cy++)
  85.      for (cx = 0; cx < xsize; cx++)
  86.        drwpoint(SET,fgetc(pak.p),x+cx,y+cy);
  87. }
  88.  
  89. //takes less memory than SVGACC's
  90. void scalepict(int x, int y, int scale, pict image)
  91. {
  92.    int cx, cy;
  93.    float curx, cury;
  94.    float incx, incy;
  95.    float xsize = image.xsize * ((float)scale / 100);
  96.    float ysize = image.ysize * ((float)scale / 100);
  97.    curx = cury = 0;
  98.    incx = (float)image.xsize / xsize;
  99.    incy = (float)image.ysize / ysize;
  100.    for (cy = 0; cy < ysize; cy++)
  101.    {
  102.       for (cx = 0; cx < xsize; cx++)
  103.       {
  104.      drwpoint(SET,image.data[(image.xsize*(int)cury)+(int)curx],cx+x,cy+y);
  105.      curx+=incx;
  106.       }
  107.       cury+=incy;
  108.       curx=0;
  109.    }
  110. }
  111.  
  112. void impress(int x0, int y0, int x1, int y1)
  113. {
  114.    int cx, cy;
  115.    drwline(SET, DKGRAY, x0, y0, x1, y0);
  116.    drwline(SET, DKGRAY, x0-1, y0-1, x1+1, y0-1);
  117.    drwline(SET, DKGRAY, x0, y0, x0, y1);
  118.    drwline(SET, DKGRAY, x0-1, y0-1, x0-1, y1+1);
  119.    drwline(SET, WHITE, x1, y1, x1, y0);
  120.    drwline(SET, WHITE, x1+1, y1+1, x1+1, y0-1);
  121.    drwline(SET, WHITE, x1, y1, x0, y1);
  122.    drwline(SET, WHITE, x1+1, y1+1, x0-1, y1+1);
  123. }
  124.  
  125. void statusbar(int x0, int y0, int x1, int y1, long t1, long t2)
  126. {
  127.    int curx;
  128.    if (t2 != 0) curx = (x1-x0)*((float)t1/t2);
  129.      else curx = x1;
  130.    drwfillbox(SET, BLACK, x0+curx+1, y0, x1, y1);
  131.    drwfillbox(SET, RED, x0, y0, x0+curx, y1);
  132. }