home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol2 / Archives / Plain / ja92 / Bullet / BulletMain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-18  |  8.6 KB  |  205 lines

  1. ;/* BulletMain.c - Execute me to compile me with SAS/C 5.10a
  2. LC -cfistq -v -y -j73 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. void            main(int argc, char **argv)
  85. {
  86.   struct TagItem *ti;
  87.   struct GlyphEngine *ge;
  88.   struct Window  *w;
  89.  
  90.   UBYTE           xydpi[5];
  91.  
  92.   ULONG           defpointheight = 36;   /* Default values for ReadArgs() */
  93.   ULONG           defxdpi = 68;          /* variables.                    */
  94.   ULONG           defydpi = 27;
  95.   ULONG           defcode = (ULONG) 'A';
  96.   ULONG           defcode2 = 0;
  97.  
  98.   if (GfxBase = OpenLibrary("graphics.library", 37L))
  99.   {
  100.     if (IntuitionBase = OpenLibrary("intuition.library", 37L))
  101.     {
  102.       if (myrda = ReadArgs(readargsstring, args, NULL))
  103.       {
  104.         if (args[XDPI] && args[YDPI]) /* If the user sets the DPI from the command  */
  105.         {            /* line, make sure the environment variable also gets changed. */
  106.           *(ULONG *)xydpi = ( (*(LONG *) args[XDPI]) << 16 | (*(ULONG *) args[YDPI]) );
  107.           SetVar(dpivarname, xydpi, 5,
  108.               GVF_GLOBAL_ONLY | GVF_BINARY_VAR | GVF_DONT_NULL_TERM);
  109.         }
  110.         else                            /* If the user did NOT set the X OR Y DPI...*/
  111.         {
  112.           args[XDPI] = (LONG) &defxdpi; /* ...set to default values and look for    */
  113.           args[YDPI] = (LONG) &defydpi; /* an environment variable called "XYDPI".  */
  114.                                                   /* Read the environment variable, */
  115.           if (GetVar(dpivarname, xydpi, 5,        /* XYDPI, if it exists.           */
  116.               GVF_GLOBAL_ONLY | GVF_BINARY_VAR | GVF_DONT_NULL_TERM))
  117.           {
  118.             if ( (*(ULONG *)xydpi & 0xFFFF0000) && (*(ULONG *)xydpi & 0x0000FFFF) )
  119.             {     /* Make sure the environment variable is OK to use by making sure */
  120.                   /* that neither X or YDPI is zero. If XYDPI is OK, use it as the  */
  121.               defxdpi = ((*(ULONG *)xydpi) & 0xFFFF0000) >> 16;        /* default.  */
  122.               defydpi = (*(ULONG *)xydpi) & 0x0000FFFF;
  123.             }
  124.           }
  125.         }
  126.         if (!(args[SIZE]))
  127.           args[SIZE] = (LONG) &defpointheight;
  128.         if (!(args[CODE]))
  129.           args[CODE] = (LONG) &defcode;
  130.         if (!(args[CODE2]))
  131.           args[CODE2] = (LONG) &defcode2;
  132.         if (!(args[FONT_NAME]))
  133.           args[FONT_NAME] = (LONG) fontstring;
  134.                                            /* Open the ".font" file which contains  */
  135.                                            /* the FontContentsHeader for this font. */
  136.         if (fontfile = Open((STRPTR) args[FONT_NAME], MODE_OLDFILE))
  137.         {
  138.           if (Read(fontfile, &fchid, sizeof(UWORD)))
  139.           {
  140.             if (fchid == OTAG_ID)             /* Does this font have an .otag file? */
  141.             {
  142.               strcpy(buf, (STRPTR) args[FONT_NAME]); /* Put together the otag file  */
  143.               if (otagname = &(buf[strlen(buf) - 4]))/* name from the .font file.   */
  144.               {
  145.                 strcpy(otagname, "otag");
  146.                 if (UtilityBase = OpenLibrary("utility.library", 37L))
  147.                 {
  148.                   if (ti = AllocOtag(buf))      /* open the otag file and copy its  */
  149.                   {                             /* tags into memory.                */
  150.                     if (BulletBase = OpenScalingLibrary(ti)) /* Pass the function   */
  151.                     {                                  /* the OTAG tag list which it*/
  152.                                                        /* needs to open the scaling */
  153.                       if (ge = GetGlyphEngine(ti, buf))/* library.  Open the        */
  154.                       {                                /* library's scaling engine. */
  155.                         if (w = OpenWindowTags(NULL,
  156.                                                WA_Width,         640,
  157.                                                WA_Height,        200,
  158.                                                WA_SmartRefresh,  TRUE,
  159.                                                WA_SizeGadget,    FALSE,
  160.                                                WA_CloseGadget,   TRUE,
  161.                                                WA_IDCMP,         NULL,
  162.                                                WA_DragBar,       TRUE,
  163.                                                WA_DepthGadget,   TRUE,
  164.                                                WA_Title,         (ULONG)argv[0],
  165.                                                TAG_END))
  166.                         {
  167.                           rp = *(w->RPort); /* Clone window's RastPort.  The second */
  168.                                             /* Rastport is for rendering with the   */
  169.                                             /* background color.                    */
  170.  
  171.                           if (drawinfo = GetScreenDrawInfo(w->WScreen)) /* Get the  */
  172.                           {             /* Screen's DrawInfo to get its pen colors. */
  173.                             SetAPen(w->RPort, drawinfo->dri_Pens[TEXTPEN]);
  174.                             SetAPen(&rp, drawinfo->dri_Pens[BACKGROUNDPEN]);
  175.                             FreeScreenDrawInfo(w->WScreen, drawinfo);
  176.  
  177.                             BulletExample(ge, w, &rp, *(ULONG *) args[SIZE],
  178.                                           *(ULONG *) args[XDPI],
  179.                                           *(ULONG *) args[YDPI],
  180.                                           *(ULONG *) args[CODE],
  181.                                           *(ULONG *) args[CODE2]);
  182.                           }
  183.                           CloseWindow(w);
  184.                         }
  185.                         ReleaseGlyphEngine(ge);
  186.                       }
  187.                       CloseScalingLibrary(BulletBase);
  188.                     }
  189.                     FreeOtag(ti);
  190.                   }
  191.                   CloseLibrary(UtilityBase);
  192.                 }
  193.               }
  194.             }
  195.           }
  196.           Close(fontfile);
  197.         }
  198.         FreeArgs(myrda);
  199.       }
  200.       CloseLibrary(IntuitionBase);
  201.     }
  202.     CloseLibrary(GfxBase);
  203.   }
  204. }
  205.