home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / FNTPAK32.ZIP / C.EXE / DEMOFNT2.C < prev    next >
C/C++ Source or Header  |  1995-08-16  |  7KB  |  229 lines

  1. /**********************************************************************
  2.     DemoFnt2.C                  Copyright 1994, Rob W. Smetana
  3.  
  4.     Turn Screen Swapping ON if appropriate.
  5.  
  6.     Demonstrate how to load Font Pak fonts from disk.
  7.  
  8.     Demonstrate how to use TryToLoadFont, a LOCAL function, to load
  9.     fonts -OR- print an error message (eg., font file not found) and exit.
  10.  
  11.     Run DemoFnt1.C for a demo of how to CALL fonts, and use two fonts
  12.     on the screen at once.
  13.  
  14.     *** BEFORE running this, BE SURE the font files Oldeng_5.F16  ***
  15.     *** and Script_3.F16 are on the CURRENT drive/directory.      ***
  16.  
  17. **********************************************************************/
  18.  
  19. #include <font_pak.h>       /* for declarations -- PLEASE READ */
  20.  
  21.  
  22. /*
  23.          Block = 0-3 (EGA) or 0-7 (VGA)
  24.  
  25. Syntax:  LOADFONTFILE (FontFileName, Block);
  26.  
  27. Syntax:  RSWHICHFONTS(LowIntensity, HiIntensity);
  28.  
  29. Syntax:  RSLOADDefault(FontSize, Block);  FontSize = 8, 14 or 16
  30.  
  31. */
  32.  
  33. /*
  34.   TryToLoadFont is a LOCAL function that loads a font file -OR-
  35.   prints an error message and exits.
  36.   int TryToLoadFont ();
  37. */
  38.  
  39. int GetFontSize ();          /* local get-monitor function to detect EGA/VGA
  40.                                 and return size of default font (14/16)
  41.                                 -or- print error message if appropriate */
  42.  
  43.  
  44. int main (void)
  45.  
  46. {
  47.     int block1, block2, fontsize, returncode;
  48.  
  49.     char fontfile[64];
  50.  
  51.  
  52.     /*
  53.       We'll load font into blocks 1 and 2 -- leaving the default (0) alone.
  54.     */
  55.  
  56.     block1 = 1;
  57.     block2 = 2;
  58.  
  59.     /*
  60.       PRE-Load blocks 1 & 2.  This will ensure that if we load
  61.       a partial font (with NO line draw characters) we'll have
  62.       something to draw with.
  63.     */
  64.  
  65.     fontsize = GetFontSize ();
  66.     if (fontsize == 0)
  67.        return (-99);
  68.  
  69.     RSLOADDEFAULT (fontsize, block1);
  70.     RSLOADDEFAULT (fontsize, block2);
  71.  
  72.  
  73.     printf("\n\n\n\n\n\n\n\n\n\n\n\n");
  74.     printf("\n  ┌─░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓ Font Pak Pro: Demo ▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░─┐\n");
  75.     printf(" ░│                                                                          │\n");
  76.     printf(" ░│          If you changed line-draw characters they'll differ too.         │\n");
  77.     printf(" ░│                                           ╒═══════╕   ╓──╖        ╓───╖  │\n");
  78.     printf(" ░│ ┌──────┼─────┐ ╔══════╦═══════╗     ╒═════╧═════╕ │   ║ ─╫───╫────╜   ║  │\n");
  79.     printf(" ░│ │      ├──── │ ║      ╚════╗  ╬═╗   │     ╒═════╪═╛   ║  ║   ║  ─rws─ ║  │\n");
  80.     printf(" ░│ └──────┼─────┘ ╚═══════════╬══╝ ║   ╘═════╪═════╛     ║  ╙───╫────────╜  │\n");
  81.     printf(" ░│        │                   ╚════╝         ╘═════════  ╙──────╜           │\n");
  82.     printf(" ░└──────────────────────────────────────────────────────────────────────────┘\n");
  83.     printf(" ░░░░░░░░░░░░░░░░░░░░░░░░ Press <SPACE> to change fonts ░░░░░░░░░░░░░░░░░░░░░\n");
  84.     printf("\n\n\n");
  85.  
  86.  
  87.     printf("\t\tHere's the default font.  Press <SPACE>.");
  88.     getch();
  89.  
  90.     /*
  91.       Try different fonts below.
  92.       Be SURE font files are on the CURRENT path before you run this.
  93.     */
  94.  
  95.      strcpy (fontfile, "script_3.F16");
  96.  
  97.     /*
  98.       Here's the direct way to load a font
  99.  
  100.       returncode = LOADFONTFILE (fontfile, block1);
  101.  
  102.       But we'll use a local function to ensure the file's here. If not, exit.
  103.     */
  104.  
  105.     returncode = TryToLoadFont(fontfile, block1);
  106.  
  107.     strcpy (fontfile, "oldeng_5.F16");
  108.     returncode = TryToLoadFont(fontfile, block2);
  109.  
  110.  
  111.     /*
  112.       select block 1 -- exclusively
  113.     */
  114.     RSWHICHFONTS (block1, block1);
  115.  
  116.     printf("\n\n\t\tHere's the font you loaded into block %d.  Press <SPACE>.",block1);
  117.     getch();
  118.  
  119.     /*
  120.       select block 2 -- exclusively
  121.     */
  122.     RSWHICHFONTS (block2, block2);
  123.  
  124.     printf("\n\n\t\tHere's the font you loaded into block %d.  Press <SPACE>.",block2);
  125.     getch();
  126.  
  127.     /*
  128.       Stick the default font back into the blocks we changed.
  129.     */
  130.  
  131.     fontsize = GetFontSize ();
  132.     RSLOADDEFAULT (fontsize, block1);
  133.     RSLOADDEFAULT (fontsize, block2);
  134.  
  135.  
  136.     /*
  137.       return to block 0 exclusively
  138.     */
  139.     block1 = 0;
  140.     block2 = 0;
  141.     RSWHICHFONTS (block1, block2);
  142.  
  143.     printf("\n\n\t\tAnd back to normal.\n");
  144.  
  145.     return (0);
  146.  
  147. }   /* end main */
  148.  
  149.  
  150. /*******************************************************************
  151.  Function TryToLoadFont calls LOADFONTFILE.
  152.  If an error occurs, it prints a message and ends.
  153. *******************************************************************/
  154.  
  155. int TryToLoadFont (fontfile, block)
  156.  
  157. char *fontfile;
  158. int block;
  159.  
  160. {
  161.     int returncode;
  162.     returncode = LOADFONTFILE (fontfile, block);
  163.  
  164.     if (returncode != 0)  {
  165.           printf ("\n\n  Error %d occurred loading [%s].. \n\n",returncode, fontfile);
  166.  
  167.           switch (returncode)  {
  168.              case -99:
  169.                printf ("  Font [%s] NOT found  -or-  it wasn't one of our font files. \n\n",fontfile);
  170.                break;
  171.              case -66:
  172.                printf ("  malloc failed -- couldn't allocate memory needed to load font.\n\n");
  173.                break;
  174.              case -77:
  175.                printf ("  Loading characters beyond 255.  Header may be corrupt.  Re-save font.\n\n");
  176.                break;
  177.              case -88:
  178.                printf ("  File-read failed (should never happen -- bad disk?).\n\n");
  179.                break;
  180.           }
  181.           exit(returncode);
  182.     }
  183.     return (0);
  184. }
  185.  
  186. /*******************************************************************
  187.  Function:  GetFontSize
  188.  
  189.  Purpose:   Check for EGA/VGA and return 14 (EGA 8x14), 16 (VGA 8x16)
  190.             or 0 if we're not using an EGA/VGA
  191.             Print error message and end if no EGA/VGA
  192.             Return FontSize for use in other functions
  193.  
  194. GetMonitor returns an integer (0 - 8) indicating the type of monitor
  195.            in use.  If two monitors are being used, GetMonitor returns
  196.            the type of the primary monitor.
  197.  
  198.            0 = None (no monitor)    3 = EGA (or MultiSync)
  199.            4 = Color (CGA)          5 = Monochrome
  200.            7 = VGA Monochrome       8 = VGA Color (or MultiSync)
  201.  
  202. *******************************************************************/
  203.  
  204. int GetFontSize ()
  205.  
  206. {
  207.     int MonType;
  208.     MonType = GETMONITOR();
  209.  
  210.     switch (MonType)  {
  211.        case 0, 4, 5:        /* no monitor, Mono or CGA */
  212.          printf ("Sorry.  An EGA or VGA monitor is required to run this demo. \n\n");
  213.          return (0);
  214.          break;
  215.        case 3:              /* EGA.  Set fontsize to 8x14 */
  216.          return (14);
  217.          break;
  218.        case 7, 8:           /* VGA.  Set fontsize to 8x16 */
  219.          return (16);
  220.          break;
  221.        default:
  222.          printf ("Unknown monitor type.  Sorry.  An EGA or VGA monitor is required to run this. \n\n");
  223.          return (0);
  224.          break;
  225.     }
  226.  
  227. }
  228.  
  229.