home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / monitors / rsys / source.lha / src / RSysGfxCtrl.c < prev    next >
C/C++ Source or Header  |  1995-01-09  |  3KB  |  142 lines

  1. /*
  2. ***************************************************************************
  3. *
  4. * Datei:
  5. *    RSysGfxCtrl.c
  6. *
  7. * Inhalt:
  8. *    int TextLen(struct TextFont *tf, struct RastPort *RP, char *text);
  9. *    short compute(unsigned short offset, unsigned short xy, int measure);
  10. *    unsigned short ComputeX(unsigned short value);
  11. *    unsigned short ComputeY(unsigned short value);
  12. *    void ComputeFont(struct Screen *wndscr, unsigned short width, unsigned short height);
  13. *
  14. * Bemerkungen:
  15. *    Graphics-Routinen für die Unterstützung fontsensitiver
  16. *    Benutzeroberflächen.
  17. *
  18. * Erstellungsdatum:
  19. *    25-Jun-93    Rolf Böhme
  20. *
  21. * Änderungen:
  22. *    25-Jun-93    Rolf Böhme    Erstellung
  23. *
  24. ***************************************************************************
  25. */
  26.  
  27. #include "RSysDebug.h"
  28. #include "RSysFunc.h"
  29.  
  30.    /*
  31.     * TextLen() berechnet die Länge eines Strings in einem gewählten
  32.     * RastPort bezüglich des verwendeten TextFonts. Dabei werden
  33.     * auch proportionale Schriften und das Kerning berücksichtigt
  34.     */
  35. int
  36. TextLen(struct TextFont *tf, struct RastPort *RP, char *text)
  37. {
  38.    int   retlen = 0,
  39.          slen = strlen(text),
  40.          i;
  41.    WORD *charspace = (WORD *) tf->tf_CharSpace;
  42.  
  43.    DPOS;
  44.  
  45.    if (tf->tf_CharSpace == NULL)
  46.       retlen = TextLength(RP, (UBYTE *) text, strlen(text));
  47.    else
  48.       for (i = 0; i < slen; i++)
  49.          retlen += charspace[(int)text[i]];
  50.  
  51.    return (retlen);
  52. }
  53.  
  54.    /*
  55.     * compute() berechnet die fontsensitiven Abmessungen von
  56.     * Intuition-Objekten
  57.     */
  58. WORD
  59. compute(UWORD offset, UWORD xy, int measure)
  60. {
  61.    return (offset + ((xy * (measure * FRAC)) / FULL));
  62. }
  63.  
  64.    /*
  65.     * computeX() berechnet einen Wert bezüglich der
  66.     * Fontbreite
  67.     */
  68. UWORD
  69. ComputeX(UWORD value)
  70. {
  71.    return ((UWORD) (((FontX * value) + 4) / 8));
  72. }
  73.  
  74.    /*
  75.     * computeY() berechnet einen Wert bezüglich der
  76.     * Fonthöhe
  77.     */
  78. UWORD
  79. ComputeY(UWORD value)
  80. {
  81.    return ((UWORD) (((FontY * value) + 4) / 8));
  82. }
  83.  
  84.    /*
  85.     * ComputeFont() berechnet die korrekte Breite und Höhe eines
  86.     * Fonts. Passen Höhe und Breite eines Abschnittes, verknüpft
  87.     * mit den Fontdaten nicht auf den angegebenen Screen, wird der
  88.     * System-Standard-Font topaz in der Größe 8 verwendet
  89.     */
  90. void
  91. ComputeFont(struct Screen *wndscr, UWORD width, UWORD height)
  92. {
  93.    char *test = "abcdefghijklmnopqrstuvwxyz"
  94.    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  95.    "1234567890"
  96.    ",.-;:!()=?[]{} ";
  97.  
  98.    DPOS;
  99.  
  100.    if (Flags.sysfont)
  101.    {
  102.       Font = &Topaz80;
  103.       FontX = 8;
  104. /*      FontY = ((wndscr->Font->ta_YSize > 8) ? wndscr->Font->ta_YSize : 8);*/
  105.       FontY = 8;
  106.    }
  107.    else
  108.    {
  109.       Font = wndscr->Font;
  110.       Forbid();
  111.       FontX = (TextLen(GfxBase->DefaultFont, &wndscr->RastPort, test) + 4) / strlen(test);
  112.       Permit();
  113.       FontY = Font->ta_YSize;
  114.    }
  115.  
  116.     OffX = wndscr->WBorLeft;
  117.     OffY = wndscr->RastPort.TxHeight + Scr->WBorTop + 1;
  118.  
  119.    if (width && height)
  120.    {
  121.       if ((ComputeX(width) + OffX + wndscr->WBorRight) > wndscr->Width)
  122.          goto UseTopaz;
  123.       if ((ComputeY(height) + OffY + wndscr->WBorBottom) > wndscr->Height)
  124.          goto UseTopaz;
  125.    }
  126.  
  127.    return;
  128.  
  129.  UseTopaz:
  130.    ErrorHandle(FONT_ERR, SIZE_FAIL, NO_KILL);
  131.  
  132.    Font = &Topaz80;
  133.    FontX = 8;
  134.    FontY = 8;
  135.    Font->ta_YSize = 8;
  136.  
  137.    Flags.sysfont = 1;
  138.  
  139.    return;
  140. }
  141.  
  142.