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

  1. ;/* Rotate.c - Execute me to compile me with SAS/C 6.56
  2. sc NMINC STRMERGE STREQ NOSTKCHK SAVEDS IGNORE=73 Rotate.c
  3. slink FROM LIB:c.o,BulletMain.o,engine.o,Rotate.o TO Rotate LIBRARY LIB:sc.lib,LIB:amiga.lib
  4. quit ;*/
  5.  
  6. /* (c)  Copyright 1992 Commodore-Amiga, Inc.   All rights reserved.       */
  7. /* The information contained herein is subject to change without notice,  */
  8. /* and is provided "as is" without warranty of any kind, either expressed */
  9. /* or implied.  The entire risk as to the use of this information is      */
  10. /* assumed by the user.                                                   */
  11.  
  12. #include <exec/types.h>
  13. #include <diskfont/diskfonttag.h>
  14. #include <diskfont/diskfont.h>
  15. #include <diskfont/glyph.h>
  16. #include <diskfont/oterrors.h>
  17. #include <graphics/gfx.h>
  18. #include <graphics/regions.h>
  19. #include <utility/tagitem.h>
  20. #include <intuition/intuition.h>
  21. #include <devices/timer.h>
  22.  
  23. #include <clib/alib_stdio_protos.h>
  24. #include <clib/alib_protos.h>
  25. #include <clib/bullet_protos.h>
  26. #include <clib/exec_protos.h>
  27. #include <clib/layers_protos.h>
  28. #include <clib/graphics_protos.h>
  29. #include <clib/intuition_protos.h>
  30.  
  31. extern struct Library *BulletBase, *UtilityBase, *GfxBase, *IntuitionBase;
  32. struct Library *LayersBase;
  33. void            BulletExample(struct GlyphEngine *,
  34.                               struct Window *,
  35.                               struct RastPort *,
  36.                               ULONG, ULONG, ULONG, ULONG, ULONG);
  37.  
  38. UBYTE          *vers = "\0$VER: Rotate 38.10";
  39.  
  40. #define TABLE_ENTRIES 24
  41. #define SINE_INDEX    0
  42. #define COSINE_INDEX  1
  43.  
  44. /* precalculated sine and cosine */
  45. LONG            table[TABLE_ENTRIES][2] =
  46. {
  47.   {0x0, 0x10000},             /* 0   degrees */ /* Notice that the sine and cosine  */
  48.   {0x424e, 0xf747},           /* 15  degrees */ /* values have to correspond to the */
  49.   {0x8000, 0xddb4},           /* 30  degrees */ /* same angle.  The IntelliFont     */
  50.   {0xb505, 0xb505},           /* 45  degrees */ /* engine will have severe mental   */
  51.   {0xddb4, 0x8000},           /* 60  degrees */ /* problems if the values aren't    */
  52.   {0xf747, 0x424e},           /* 75  degrees */ /* close to representing the same   */
  53.   {0x10000, 0x0},             /* 90  degrees */ /* angle.                           */
  54.   {0xf747, 0xffffbdbe},       /* 105 degrees */
  55.   {0xddb4, 0xffff8000},       /* 120 degrees */
  56.   {0xb505, 0xffff4afb},       /* 135 degrees */
  57.   {0x8000, 0xffff224c},       /* 150 degrees */
  58.   {0x424e, 0xffff08b9},       /* 165 degrees */
  59.   {0x0, 0xffff0000},          /* 180 degrees */
  60.   {0xffffbdbe, 0xffff08b9},   /* 195 degrees */
  61.   {0xffff8000, 0xffff224c},   /* 210 degrees */
  62.   {0xffff4afb, 0xffff4afb},   /* 225 degrees */
  63.   {0xffff224c, 0xffff8000},   /* 240 degrees */
  64.   {0xffff08b9, 0xffffbdbe},   /* 255 degrees */
  65.   {0xffff0000, 0x0},          /* 270 degrees */
  66.   {0xffff08b9, 0x424e},       /* 285 degrees */
  67.   {0xffff224c, 0x8000},       /* 300 degrees */
  68.   {0xffff4afb, 0xb505},       /* 315 degrees */
  69.   {0xffff8000, 0xddb4},       /* 330 degrees */
  70.   {0xffffbdbe, 0xf747}        /* 345 degrees */
  71. };
  72.  
  73. struct Rectangle rectangle;
  74. struct Region    *region;
  75.  
  76. void
  77. BulletExample(struct GlyphEngine * ge,
  78.               struct Window * w, struct RastPort * rp,
  79.      ULONG pointheight, ULONG xdpi, ULONG ydpi, ULONG unicode, ULONG unicode2)
  80. {
  81.   struct GlyphMap *gm;
  82.   PLANEPTR        tempbitmap;
  83.   ULONG           centerx, centery, x, y, dx, dy, sin, cos, oldx, oldy, olddx,
  84.                   olddy, emheight, emwidth;
  85.   ULONG           i = 0;
  86.  
  87.   struct IntuiMessage *mymsg;
  88.   BOOL            done = FALSE;
  89.  
  90.   if (pointheight > 180) pointheight = 180;
  91.  
  92.   if (SetInfo(ge,
  93.               OT_DeviceDPI, ((ULONG) xdpi) << 16 | ydpi,
  94.               TAG_END) != OTERR_Success)
  95.         return;
  96.  
  97.   emheight = (pointheight * ydpi) / 72; /* Calculate the pixel dimensions */
  98.   emwidth  = (pointheight * xdpi) / 72; /* of the EM square.              */
  99.   centerx  = w->BorderLeft + emheight;
  100.   centery  = w->BorderTop  + emwidth;
  101.  
  102.   dx = (2 * emwidth) + w->BorderLeft + w->BorderRight;  /* Calculate window size to */
  103.   dy = (2 * emheight) + w->BorderTop + w->BorderBottom; /* fit around glyph com-    */
  104.   dx = (dx > 640) ? 640 : dx;                           /* fortablely.              */
  105.   dy = (dy > 200) ? 200 : dy;
  106.   dx = (dx < 80) ? 80: dx;
  107.   dy = (dy < 50) ? 50: dy;
  108.  
  109.   if (ModifyIDCMP(w, IDCMP_CHANGEWINDOW))
  110.   {
  111.     ChangeWindowBox(w, w->LeftEdge, w->TopEdge, dx, dy);        /* Set window size  */
  112.     WaitPort(w->UserPort);                                      /* and wait for the */
  113.     while (mymsg = (struct IntuiMessage *) GetMsg(w->UserPort)) /* dimension change */
  114.       ReplyMsg((struct Message *) mymsg);                       /* to take place.   */
  115.     if (!(ModifyIDCMP(w, NULL))) return;  /* Quit if there is a problem with IDCMP. */
  116.   }
  117.  
  118.   x = centerx; /* calculate original rendering position. */
  119.   y = centery;
  120.   dx = 1;   /* Since dx and dy are no longer necessary for figuring out the window  */
  121.   dy = 1;   /* dimensions, I use them to measure the full width and height of the   */
  122.             /* glyph bitmap supplied by bullet.  I need this to erase the glyph.    */
  123.  
  124.   if (LayersBase = OpenLibrary("layers.library", 37L)) /* These lines are       */
  125.   {                                                    /* here to install       */
  126.     rectangle.MinX = w->BorderLeft;                    /* a clipping            */
  127.     rectangle.MinY = w->BorderTop;                     /* region to the         */
  128.     rectangle.MaxX = w->Width  - w->BorderRight - 1;   /* window to keep        */
  129.     rectangle.MaxY = w->Height - w->BorderBottom - 1;  /* the glyph within      */
  130.                                                        /* window bounds.        */
  131.     if (region = NewRegion())                          /* For more information, */
  132.     {                                                  /* see the "Layers"      */
  133.       if (OrRectRegion(region, &rectangle))            /* chapter of the        */
  134.       {                                                /* RKRM: Libraries       */
  135.         InstallClipRegion(w->WLayer, region);          /* Manual.               */
  136.  
  137.         if (SetInfo(ge,
  138.                     OT_GlyphCode, unicode,                      /* Set the glyph to */
  139.                     OT_PointHeight, (ULONG) pointheight << 16,  /* rotate and its   */
  140.                     TAG_END) == OTERR_Success)                  /* pointsize.       */
  141.         {
  142.           SetDrMd(w->RPort, JAM1);
  143.           if (tempbitmap = AllocRaster(640, 200))
  144.           {
  145.             if (ModifyIDCMP(w, IDCMP_CLOSEWINDOW)) /* Turn on close window reports  */
  146.             {                                      /* so the example can quit.      */
  147.               for (i = 0; done == FALSE; i++)
  148.               {
  149.                 if (i == TABLE_ENTRIES)
  150.                   i = 0;
  151.  
  152.                 sin = table[i][SINE_INDEX];   /* Step through the sine/cosine array */
  153.                 cos = table[i][COSINE_INDEX]; /* 360 degrees @ 15 degree increments */
  154.  
  155.                 if (SetInfo(ge,                  /* Set the current rotation angle. */
  156.                             OT_RotateSin, sin,
  157.                             OT_RotateCos, cos,
  158.                             TAG_END) == OTERR_Success)
  159.                 {
  160.                   if ((ObtainInfo(ge, OT_GlyphMap, &gm, TAG_END)) == OTERR_Success)
  161.                   {
  162.                     oldx = x;               /* Calculate the dimension and position */
  163.                     oldy = y;               /* of the new glyph's bitmap and save   */
  164.                     olddx = dx;             /* the old values so we can erase the   */
  165.                     olddy = dy;             /* glyph that is still on the screen.   */
  166.                     x = centerx - gm->glm_X0;
  167.                     y = centery - gm->glm_Y0;
  168.                     dx = gm->glm_BMModulo * 8;
  169.                     dy = gm->glm_BMRows;
  170.  
  171.                     CopyMem(gm->glm_BitMap,/* Copy the glyph's bitmap into Chip RAM */
  172.                             tempbitmap,    /* so we can blit it into a RastPort.    */
  173.                             gm->glm_BMModulo * gm->glm_BMRows);
  174.  
  175.                                                             /* Erase the old glyph. */
  176.                     RectFill(rp, oldx, oldy, oldx + olddx, oldy + olddy);
  177.  
  178.                     WaitBlit();                 /* Wait for the old glyph to erase. */
  179.  
  180.                     BltTemplate(                   /* Blit the new glyph into the   */
  181.                                  tempbitmap,       /* window's RastPort.            */
  182.                                  0,
  183.                                  gm->glm_BMModulo,
  184.                                  w->RPort,
  185.                                  x,
  186.                                  y,
  187.                                  dx,
  188.                                  dy);          /* Running several instances of this */
  189.                                                /* example simultaneously can really */
  190.                                                /* slow the system, so we give other */
  191.                     TimeDelay(UNIT_VBLANK, 0, 250000);  /*   tasks a chance to run. */
  192.                     ReleaseInfo(ge, OT_GlyphMap, gm, TAG_END);
  193.                   }
  194.                 }                               /* Check for a CLOSEWINDOW message. */
  195.                 while (mymsg = (struct IntuiMessage *) GetMsg(w->UserPort))
  196.                 {
  197.                   ReplyMsg((struct Message *) mymsg);
  198.                   done = TRUE;
  199.                 }
  200.               }
  201.             }
  202.             FreeRaster(tempbitmap, 640, 200);
  203.           }
  204.         }
  205.       }
  206.       DisposeRegion(region);
  207.     }
  208.     CloseLibrary(LayersBase);
  209.   }
  210. }
  211.