home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / thx / source / utils / gmice.cpp < prev    next >
C/C++ Source or Header  |  1995-03-24  |  2KB  |  103 lines

  1. #include <fstream.h>
  2. #include <stdlib.h>
  3. #include <fastgraf.h>
  4. #include <dir.h>
  5. #include <string.h>
  6. #include "pcx.h"
  7. #include "utils.h"
  8.  
  9. static ofstream cfile;
  10.  
  11. // ------ hotspot table ( add to this for new cursors )
  12. static struct hs {
  13.     char *fn;
  14.     int x, y;
  15. } HotSpots[] = {
  16.     { "LF",  0,  1 },
  17.     { "RT", 15,  1 },
  18.     { "DN", 14, 15 },
  19.     { "UP", 14,  0 },
  20.     { "UL",  0,  0 },
  21.     { "UR", 15,  0 },
  22.     { "LR", 15, 15 },
  23.     { "LL",  0, 15 },
  24.     { "CN",  7,  0 },
  25.     { "DE",  0,  0 },
  26.     {    0,  0,  0 }
  27. };
  28.  
  29. void bld_cursors(char *fname)
  30. {
  31.     static pcx_header header;
  32.     fg_pcxhead(fname,(char*)&header);
  33.     int w = header.width+1-header.x;
  34.     int h = header.height+1-header.y;
  35.     if (w != 16 && h != 16)    {
  36.         fg_setmode(3);
  37.         cerr << "Invalid ht/wd: " << h << '/' << w;
  38.         exit(1);
  39.     }
  40.     fg_setcolor(0);
  41.     fg_rect(0,319,0,239);
  42.     fg_move(0,0);
  43.     fg_showpcx(fname,2);
  44.  
  45.     long size=fg_imagesiz(w,h);
  46.     if (size != 256)    {
  47.         fg_setmode(3);
  48.         cerr << "Invalid # of colors: " << size;
  49.         exit(1);
  50.     }
  51.  
  52.     static char curs[512];
  53.  
  54.     for (int i = 0; i < 16; i++)    {
  55.         fg_move(0,i);
  56.         fg_getimage(curs+256+i*16,16,1);
  57.     }
  58.  
  59.     for (i = 0; i < 256; i++)
  60.         curs[i] = (curs[256+i]) ? 0 : 0xff;
  61.  
  62.     char arname[MAXFILE];
  63.     _splitpath(fname, 0, 0, arname, 0);
  64.  
  65.  
  66.     // --- base hotspot value on 1st 2 characters of file name
  67.     hs *hsp = HotSpots;
  68.     while (hsp->fn != 0)    {
  69.         if (strncmp(hsp->fn, arname, 2) == 0)
  70.             break;
  71.         hsp++;
  72.     }
  73.     int x = hsp->x;
  74.     int y = hsp->y;
  75.  
  76.     cfile << "\nchar " << arname << "[] = { "
  77.           << x << ", " << y << ", // hotspot x/y";
  78.  
  79.     for (i = 0; i < 512; i++)    {
  80.         if ((i % 16) == 0)
  81.             cfile << "\n\t";
  82.         cfile.width(3);
  83.         cfile.fill(' ');
  84.         cfile << dec << (curs[i] & 0xff);
  85.         if (i < 511)
  86.             cfile << ',';
  87.     }
  88.     cfile << "\n};";
  89. }
  90.  
  91. int main(int argc, char *argv[])
  92. {
  93.     if (argc > 2)    {
  94.         cfile.open(argv[1]);
  95.         fg_setmode(22);
  96.         parse_cmdline(argc-2, argv+2, bld_cursors);
  97.         fg_setmode(3);
  98.         return 0;
  99.     }
  100.     return 1;
  101. }
  102.  
  103.