home *** CD-ROM | disk | FTP | other *** search
/ Amiga Inside! / Amiga FD Inside (1995)(Ultramax).iso / berndspd / devtools / precognition / src / library / precognition_utils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-12  |  4.4 KB  |  211 lines

  1. #define PRECOGNITION_UTILS_BODY
  2.  
  3. #include "precognition_utils.h"
  4. #include "minmax.h"
  5. #ifndef __GNUC__
  6. #include <clib/exec_protos.h>
  7. #include <clib/intuition_protos.h>
  8. #include <clib/graphics_protos.h>
  9. #include <clib/diskfont_protos.h>
  10. #endif
  11. #ifdef __GNUC__
  12. #include <proto/exec.h>
  13. #include <proto/intuition.h>
  14. #include <proto/graphics.h>
  15. #include <proto/diskfont.h>
  16. #endif
  17. #ifdef __SASC
  18. #include <proto/exec.h>
  19. #include <proto/intuition.h>
  20. #include <proto/graphics.h>
  21. #include <proto/diskfont.h>
  22. #endif
  23. #include <stdio.h> /* for debugging printf */
  24.  
  25. #include "amigamem.h"
  26. #include <string.h>
  27.  
  28. /* 1.3 Amiga OS Screen Support */
  29.  
  30. #define RES_MASK (HIRES+LACE)
  31. #define LO_RES             0
  32. #define LO_RES_INTERLACE   LACE
  33. #define HI_RES             HIRES
  34. #define HIRES_INTERLACE    HIRES+LACE
  35.  
  36. tPoint pcg_AspectRatio( USHORT ViewModes )
  37. {
  38.    tPoint ratio;
  39.    USHORT ScreenRes;
  40.  
  41.    ScreenRes = ( ViewModes & ( RES_MASK ) ); /* Ignore other bits. */
  42.    switch( ScreenRes )
  43.    {
  44.       case LO_RES:
  45.       case HIRES_INTERLACE:
  46.          ratio.x = 1;
  47.          ratio.y = 1;
  48.          break;
  49.  
  50.       case LO_RES_INTERLACE:
  51.          ratio.x = 1;
  52.          ratio.y = 2;
  53.          break;
  54.  
  55.       case HIRES:
  56.          ratio.x = 2;
  57.          ratio.y = 1;
  58.          break;
  59.     }
  60.    return ratio;
  61. }
  62.  
  63. /* Chaining Gadget Support */
  64.  
  65. void ChainGadgets( Gadget *start_of_chain, Gadget *gadget )
  66. {
  67.    Gadget *g;
  68.  
  69.    for( g = start_of_chain; g->NextGadget != NULL; g = g->NextGadget );
  70.    g->NextGadget = gadget;
  71. }
  72.  
  73.  
  74. /* Default Font Support */
  75.  
  76. TextAttr pcg_Topaz80 =
  77.    { "topaz.font", TOPAZ_EIGHTY, FS_NORMAL, FPF_ROMFONT };
  78.  
  79. struct TextAttr Helvetica13 = {
  80.   "Helvetica.font",
  81.   13,
  82.   NULL,
  83.   FPF_DISKFONT
  84.   };
  85.  
  86. #define FONTHEIGHT 9
  87. #define FONTWIDTH  8
  88.  
  89.  
  90. void AlignText( PrecogText    *ptext,
  91.                 Point          size  )
  92. {
  93.    PIXELS width;
  94.    UBYTE  flags;
  95.    BYTE   Xpad, Ypad;
  96.    struct TextFont *myfont = NULL;
  97.    int TextFontHeight = FONTHEIGHT;
  98.  
  99.    flags = ptext->alignment.Flags;
  100.    Xpad  = ptext->alignment.Xpad;
  101.    Ypad  = ptext->alignment.Ypad;
  102.  
  103.    if( ptext->ITextFont ) /* non NULL */
  104.       {
  105.   /*
  106.    *    Additions by EDB October 21, 1994
  107.    *    Get Text Width according to ITextFont
  108.    */
  109.       if( myfont = OpenDiskFont( ptext->ITextFont ) )
  110.         {
  111.           if( ptext->IText )
  112.             {
  113.               width = IntuiTextLength( (struct IntuiText *)ptext );
  114.               ptext->TextLength = width;
  115.             }
  116.           else
  117.               width = 0;
  118.  
  119.           /* Change font height variable to match ITextFont */
  120.           TextFontHeight = ptext->ITextFont->ta_YSize;
  121.  
  122.           CloseFont( myfont );
  123.         }
  124.  
  125.       }
  126.    else
  127.       if( ptext->IText ) /* Default Topaz80 font */
  128.       {
  129.          width = strlen( ptext->IText ) * FONTWIDTH;
  130.       }
  131.       else
  132.       {
  133.          width = 0;
  134.       }
  135.  
  136.    /*--------------- ptext->LeftEdge = ? -------------------*/
  137.    if( flags & tx_XCENTER )
  138.    {
  139.       ptext->LeftEdge = size.x/2 - width/2;
  140.    }
  141.    else if( flags & tx_RIGHT )
  142.    {
  143.       if( flags & tx_OUTSIDE )
  144.           ptext->LeftEdge = size.x + Xpad;
  145.       else
  146.          ptext->LeftEdge = size.x - Xpad - width;
  147.    }
  148.    else /* left */
  149.    {
  150.       if( flags & tx_OUTSIDE )
  151.          ptext->LeftEdge = -Xpad - width;
  152.       else
  153.          ptext->LeftEdge = Xpad;
  154.    }
  155.  
  156.    /*--------------- ptext->TopEdge = ? ---------*/
  157.  
  158.    if( flags & tx_YCENTER )
  159.    {
  160.       ptext->TopEdge = size.y/2 - TextFontHeight/2;
  161.    }
  162.    else if( flags & tx_BOTTOM )
  163.    {
  164.       if( flags & tx_OUTSIDE )
  165.           ptext->TopEdge = size.y + Ypad;
  166.       else
  167.           ptext->TopEdge = size.y - Ypad - TextFontHeight;
  168.    }
  169.    else /* Top */
  170.    {
  171.       if( flags & tx_OUTSIDE )
  172.          ptext->TopEdge = -Ypad - TextFontHeight;
  173.       else
  174.          ptext->TopEdge = Ypad;
  175.    }
  176.  
  177. }
  178.  
  179.   /*
  180.    *    Additions by EDB October 21, 1994
  181.    *    Get PrecogText Width according to ITextFont
  182.    */
  183.  
  184. void pcgTextSize( PrecogText    *ptext)
  185.  
  186. {
  187.    LONG width;
  188.    struct TextFont *myfont = NULL;
  189.    if( ptext->ITextFont ) /* non NULL */
  190.       {
  191.       if( myfont = OpenDiskFont( ptext->ITextFont ) )
  192.         {
  193.           if( ptext->IText )
  194.               width = IntuiTextLength( (struct IntuiText *)ptext );
  195.           else
  196.               width = 0;
  197.           CloseFont( myfont );
  198.         }
  199.       }
  200.    else
  201.       if( ptext->IText ) /* Default Topaz80 font */
  202.       {
  203.          width = strlen( ptext->IText ) * FONTWIDTH;
  204.       }
  205.       else
  206.       {
  207.          width = 0;
  208.       }
  209.   ptext->TextLength = width;
  210. }
  211.