home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol2 / v-23 / bulletmain.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  9KB  |  211 lines

  1. ;/* BulletMain.c - Execute me to compile me with SAS/C 6.56
  2. sc NMINC STRMERGE STREQ NOSTKCHK SAVEDS IGNORE=73 BulletMain.c
  3. quit ;*/
  4.  
  5. /* (c)  Copyright 1992 Commodore-Amiga, Inc.   All rights reserved.       */
  6. /* The information contained herein is subject to change without notice,  */
  7. /* and is provided "as is" without warranty of any kind, either expressed */
  8. /* or implied.  The entire risk as to the use of this information is      */
  9. /* assumed by the user.                                                   */
  10.  
  11. #include <exec/types.h>
  12. #include <exec/memory.h>
  13. #include <dos/rdargs.h>
  14. #include <dos/dos.h>
  15. #include <dos/var.h>
  16. #include <diskfont/diskfonttag.h>
  17. #include <diskfont/diskfont.h>
  18. #include <diskfont/glyph.h>
  19. #include <diskfont/oterrors.h>
  20. #include <utility/tagitem.h>
  21. #include <string.h>
  22. #include <graphics/displayinfo.h>
  23. #include <intuition/intuition.h>
  24. #include <intuition/screens.h>
  25.  
  26. #include <clib/dos_protos.h>
  27. #include <clib/graphics_protos.h>
  28. #include <clib/exec_protos.h>
  29. #include <clib/utility_protos.h>
  30. #include <clib/bullet_protos.h>
  31. #include <clib/intuition_protos.h>
  32.  
  33. #define OTAG_ID 0x0f03
  34.  
  35. #ifdef LATTICE
  36. int CXBRK(void) { return (0);} /* Disable Lattice CTRL/C handling */
  37. int chkabort(void) { return (0);}
  38. #endif
  39.  
  40. UBYTE   *readargsstring = "FontName,Size/N,XDPI/N,YDPI/N,CharCode/N,CharCode2/N\n";
  41. UBYTE   *librarystring = ".library";
  42. UBYTE   *fontstring     = "fonts:cgtimes.font";
  43. UBYTE   *dpivarname = "XYDPI";  /* Name of an X/Y DPI environment variable. */
  44.                                 /* If this ENV: variable exists, this code  */
  45.                                 /* will use the X and Y DPI stored there.   */
  46.                                 /* This code will also save the X and Y DPI */
  47.                                 /* in XYDPI if the user supplies a DPI.     */
  48.                                 /* XYDPI encodes the DPI just like the      */
  49.                                 /* OT_DeviceDPI tag.                        */
  50. extern struct TagItem *AllocOtag(STRPTR);
  51. extern void     FreeOtag(void *);
  52. extern struct Library *OpenScalingLibrary(struct TagItem *);
  53. extern void     CloseScalingLibrary(struct Library *);
  54. extern struct GlyphEngine *GetGlyphEngine(struct TagItem *, STRPTR);
  55. extern void     ReleaseGlyphEngine(struct GlyphEngine *);
  56. extern void
  57. BulletExample(struct GlyphEngine *,
  58.               struct Window *,
  59.               struct RastPort *, ULONG, ULONG, ULONG, ULONG, ULONG);
  60.  
  61. #define BUFSIZE     256
  62.  
  63. #define NUM_ARGS    6    /* Arguments for ReadArgs(). */
  64. #define FONT_NAME   0
  65. #define SIZE        1
  66. #define XDPI        2
  67. #define YDPI        3
  68. #define CODE        4
  69. #define CODE2       5
  70. LONG            args[NUM_ARGS];
  71. struct RDargs  *myrda;
  72.  
  73. struct Library *BulletBase, *UtilityBase, *GfxBase, *IntuitionBase;
  74.  
  75. UBYTE           buf[BUFSIZE];
  76. BPTR            fontfile, dpifile;
  77. UBYTE          *otagname;
  78. UWORD           fchid;
  79.  
  80. struct GlyphEngine *ge;
  81.  
  82. struct DrawInfo *drawinfo;
  83. struct RastPort rp;
  84.  
  85. void            main(int argc, char **argv)
  86. {
  87.   struct TagItem *ti;
  88.   struct GlyphEngine *ge;
  89.   struct Window  *w;
  90.  
  91.   UBYTE           xydpi[5];
  92.  
  93.   ULONG           defpointheight = 36;   /* Default values for ReadArgs() */
  94.   ULONG           defxdpi = 68;          /* variables.                    */
  95.   ULONG           defydpi = 27;
  96.   ULONG           defcode = (ULONG) 'A';
  97.   ULONG           defcode2 = 0;
  98.  
  99.   if (GfxBase = OpenLibrary("graphics.library", 37L))
  100.   {
  101.     if (IntuitionBase = OpenLibrary("intuition.library", 37L))
  102.     {
  103.       if (myrda = ReadArgs(readargsstring, args, NULL))
  104.       {
  105.         if (args[XDPI] && args[YDPI]) /* If the user sets the DPI from the command  */
  106.         {            /* line, make sure the environment variable also gets changed. */
  107.           *(ULONG *)xydpi = ( (*(LONG *) args[XDPI]) << 16 | (*(ULONG *) args[YDPI]) );
  108.           SetVar(dpivarname, xydpi, 5,
  109.               GVF_GLOBAL_ONLY | GVF_BINARY_VAR | GVF_DONT_NULL_TERM);
  110.         }
  111.         else                            /* If the user did NOT set the X OR Y DPI...*/
  112.         {
  113.           args[XDPI] = (LONG) &defxdpi; /* ...set to default values and look for    */
  114.           args[YDPI] = (LONG) &defydpi; /* an environment variable called "XYDPI".  */
  115.                                                   /* Read the environment variable, */
  116.           if ((GetVar(dpivarname, xydpi, 5,        /* XYDPI, if it exists.          */
  117.               GVF_GLOBAL_ONLY | GVF_BINARY_VAR | GVF_DONT_NULL_TERM)) != -1)
  118.  
  119.      /* BUG!: In the original publication of this code, the line above erroneously  */
  120.      /* tested for the wrong return value.  It caused unexpected results when using */
  121.      /* the default X and Y DPI values.  This bug was also present in BulletMain.c. */
  122.  
  123.           {
  124.             if ( (*(ULONG *)xydpi & 0xFFFF0000) && (*(ULONG *)xydpi & 0x0000FFFF) )
  125.             {     /* Make sure the environment variable is OK to use by making sure */
  126.                   /* that neither X or YDPI is zero. If XYDPI is OK, use it as the  */
  127.               defxdpi = ((*(ULONG *)xydpi) & 0xFFFF0000) >> 16;        /* default.  */
  128.               defydpi = (*(ULONG *)xydpi) & 0x0000FFFF;
  129.             }
  130.           }
  131.         }
  132.         if (!(args[SIZE]))
  133.           args[SIZE] = (LONG) &defpointheight;
  134.         if (!(args[CODE]))
  135.           args[CODE] = (LONG) &defcode;
  136.         if (!(args[CODE2]))
  137.           args[CODE2] = (LONG) &defcode2;
  138.         if (!(args[FONT_NAME]))
  139.           args[FONT_NAME] = (LONG) fontstring;
  140.                                            /* Open the ".font" file which contains  */
  141.                                            /* the FontContentsHeader for this font. */
  142.         if (fontfile = Open((STRPTR) args[FONT_NAME], MODE_OLDFILE))
  143.         {
  144.           if (Read(fontfile, &fchid, sizeof(UWORD)))
  145.           {
  146.             if (fchid == OTAG_ID)             /* Does this font have an .otag file? */
  147.             {
  148.               strcpy(buf, (STRPTR) args[FONT_NAME]); /* Put together the otag file  */
  149.               if (otagname = &(buf[strlen(buf) - 4]))/* name from the .font file.   */
  150.               {
  151.                 strcpy(otagname, "otag");
  152.                 if (UtilityBase = OpenLibrary("utility.library", 37L))
  153.                 {
  154.                   if (ti = AllocOtag(buf))      /* open the otag file and copy its  */
  155.                   {                             /* tags into memory.                */
  156.                     if (BulletBase = OpenScalingLibrary(ti)) /* Pass the function   */
  157.                     {                                  /* the OTAG tag list which it*/
  158.                                                        /* needs to open the scaling */
  159.                       if (ge = GetGlyphEngine(ti, buf))/* library.  Open the        */
  160.                       {                                /* library's scaling engine. */
  161.                         if (w = OpenWindowTags(NULL,
  162.                                                WA_Width,         640,
  163.                                                WA_Height,        200,
  164.                                                WA_SmartRefresh,  TRUE,
  165.                                                WA_SizeGadget,    FALSE,
  166.                                                WA_CloseGadget,   TRUE,
  167.                                                WA_IDCMP,         NULL,
  168.                                                WA_DragBar,       TRUE,
  169.                                                WA_DepthGadget,   TRUE,
  170.                                                WA_Title,         (ULONG)argv[0],
  171.                                                TAG_END))
  172.                         {
  173.                           rp = *(w->RPort); /* Clone window's RastPort.  The second */
  174.                                             /* Rastport is for rendering with the   */
  175.                                             /* background color.                    */
  176.  
  177.                           if (drawinfo = GetScreenDrawInfo(w->WScreen)) /* Get the  */
  178.                           {             /* Screen's DrawInfo to get its pen colors. */
  179.                             SetAPen(w->RPort, drawinfo->dri_Pens[TEXTPEN]);
  180.                             SetAPen(&rp, drawinfo->dri_Pens[BACKGROUNDPEN]);
  181.                             FreeScreenDrawInfo(w->WScreen, drawinfo);
  182.  
  183.                             BulletExample(ge, w, &rp, *(ULONG *) args[SIZE],
  184.                                           *(ULONG *) args[XDPI],
  185.                                           *(ULONG *) args[YDPI],
  186.                                           *(ULONG *) args[CODE],
  187.                                           *(ULONG *) args[CODE2]);
  188.                           }
  189.                           CloseWindow(w);
  190.                         }
  191.                         ReleaseGlyphEngine(ge);
  192.                       }
  193.                       CloseScalingLibrary(BulletBase);
  194.                     }
  195.                     FreeOtag(ti);
  196.                   }
  197.                   CloseLibrary(UtilityBase);
  198.                 }
  199.               }
  200.             }
  201.           }
  202.           Close(fontfile);
  203.         }
  204.         FreeArgs(myrda);
  205.       }
  206.       CloseLibrary(IntuitionBase);
  207.     }
  208.     CloseLibrary(GfxBase);
  209.   }
  210. }
  211.