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

  1. /*EdQuake v0.50 source code
  2.   (c) Copyright 1996 Scott Mitting
  3.   email:smitting@netusa1.net
  4.   ----------------------------------
  5.   VIEWER.C  -  Texture and console viewing routines
  6.  
  7.   __variables:
  8.  
  9.   __functions:
  10.   void viewwad(int e)            -- WAD2 graphic viewer /w scaling
  11.   void gfxwad()             -- Select wad file
  12.   void showlmp(int x, int y, int e)
  13.                  -- shows lmp file
  14.  
  15.   ----------------------------------
  16.   the entire source code is under renovation to make it easier
  17.   to understand.  happy coding.
  18. */
  19.  
  20. #include <alloc.h>
  21. #include <stdio.h>
  22. #include "viewer.h"
  23. #include "svgacc.h"
  24. #include "wad.h"
  25. #include "pak.h"
  26. #include "input.h"
  27. #include "grfx.h"
  28. #include "ripper.h"
  29.  
  30. void viewwad(int e)
  31. {
  32.     int cntx, cnty;
  33.     int cx, cy, k = 0;
  34.     int i;
  35.     int size = 100;
  36.     pict gfxblk;
  37.     if (e < 0) return;
  38.     mousehide();
  39.     getwadentry(e);
  40.     fseek(pak.p, wadentry.loc, 0);
  41.     gfxblk.xsize = fgetl(pak.p);
  42.     gfxblk.ysize = fgetl(pak.p);
  43.     fillscreen(0);
  44.     i = (gfxblk.xsize+1)*(gfxblk.ysize+1)+4;
  45.     if (!(gfxblk.data = malloc(i))) return;
  46.     for (cy = 0; cy < gfxblk.ysize; cy++)
  47.       for (cx = 0; cx < gfxblk.xsize; cx++)
  48.     gfxblk.data[(cy * gfxblk.xsize) + cx] = fgetc(pak.p);
  49.  
  50.     fillscreen(0);
  51.     drwstring(SET,7,0,"arrows - move   a/z - zoom in/out   s - save",10,0);
  52.  
  53.     cntx = 320;
  54.     cnty = 240;
  55.  
  56.    while (k != 27)
  57.    {
  58.      scalepict(cntx, cnty, size, gfxblk);
  59.      k = getkey();
  60.      drwfillbox(SET,0,cntx,cnty,800, 600);
  61.      if (k == a_DOWN)  cnty += 40;
  62.      if (k == a_UP)    cnty -= 40;
  63.      if (k == a_LEFT)  cntx -= 40;
  64.      if (k == a_RIGHT) cntx += 40;
  65.      if (k == 'a' || k == 'A')  size +=25;
  66.      if (k == 'z' || k == 'Z')  size -=25;
  67.      if (k == 's' || k == 'S')
  68.      {
  69.     k = 27;
  70.     savewadentry(e);
  71.      }
  72.      if (cntx > 800)   cntx = 800;
  73.      if (cntx < 1)     cntx = 1;
  74.      if (cnty > 600)   cnty = 600;
  75.      if (cnty < 50)     cnty = 50;
  76.     }
  77.     fillscreen(0);
  78.     free(gfxblk.data);
  79.     mouseshow();
  80. }
  81.  
  82. void gfxwad()
  83. {
  84.       int t, t2;
  85.       t = findfile("gfx.wad");
  86.       if (t > 0)
  87.       {
  88.      mousehide();
  89.      openwad(t);
  90.      drwfillbox(SET,BLACK,0,0,800,640);
  91.      t2 = 0;
  92.      mouseshow();
  93.      while (t2 > -1)
  94.      {
  95.        t2 = selectwadentry(t2);
  96.        if (t2 > -1) viewlmp(t2);
  97.      }
  98.       }
  99. }
  100.  
  101. void viewlmp(int e)
  102. {
  103.     int xsize, ysize;
  104.     int cx, cy, k;
  105.     if (e < 0) return;
  106.     mousehide();
  107.     drwfillbox(SET,BLACK,0,0,800,640);
  108.     getentry(e);
  109.     fseek(pak.p, pakentry.loc, 0);
  110.     if ((xsize = fgetl(pak.p)) < 1) return;
  111.     if ((ysize = fgetl(pak.p)) < 1) return;
  112.     fillscreen(0);
  113.     for (cy = 0; cy < ysize; cy++)
  114.      for (cx = 0; cx < xsize; cx++)
  115.       drwfillbox(SET,fgetc(pak.p),(cx*2),(cy*3),(cx*2)+1,(cy*3)+2);
  116.     drwstring(SET,15,0,"esc - leave",640,0);
  117.     drwstring(SET,15,0,"  s - save",640,15);
  118.  
  119.    while (k != 27)
  120.    {
  121.      k = getkey();
  122.      if (k == 's' || k == 'S') saveentry(e);
  123.    }
  124.    mouseshow();
  125. }
  126.  
  127. void lmp()
  128. {
  129.      int t2;
  130.      mousehide();
  131.      t2 = 0;
  132.      mouseshow();
  133.      while (t2 > -1)
  134.      {
  135.        if (kbhit()) getch(); //clear keyboard
  136.        t2 = selectentrykeyword(0, "lmp");
  137.        getentry(t2);
  138.        if (t2 > -1) viewlmp(t2);
  139.      }
  140. }
  141.  
  142. void showlmp(int x, int y, int e)
  143. {
  144.     int xsize, ysize;
  145.     int cx, cy, k;
  146.     if (e < 0) return;
  147.     mousehide();
  148.     getentry(e);
  149.     fseek(pak.p, pakentry.loc, 0);
  150.     if ((xsize = fgetl(pak.p)) < 1) return;
  151.     if ((ysize = fgetl(pak.p)) < 1) return;
  152.     for (cy = 0; cy < ysize; cy++)
  153.      for (cx = 0; cx < xsize; cx++)
  154.        drwpoint(SET,k,cx+x,cy+y);
  155.     mouseshow();
  156. }
  157.