home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 073.lha / XText / main.c < prev    next >
C/C++ Source or Header  |  1987-06-02  |  7KB  |  265 lines

  1.  
  2. /* *** main.c ***************************************************************
  3.  *
  4.  * XText  --  Example Program
  5.  *  from Book 1 of the Amiga Programmers' Suite by RJ Mical
  6.  *
  7.  * Copyright (C) 1986, 1987, Robert J. Mical
  8.  * All Rights Reserved.
  9.  *
  10.  * Created for Amiga developers.
  11.  * Any or all of this code can be used in any program as long as this
  12.  * entire notice is retained, ok?  Thanks.
  13.  *
  14.  * HISTORY       NAME            DESCRIPTION
  15.  * -----------   --------------  --------------------------------------------
  16.  * 27 Oct 86     RJ              Add XText buffer stuff, prepare for release
  17.  * March 86      RJ              Incorporated this code in Sidecar
  18.  * 26 Jan 86     RJ Mical        Created this file (on my birthday!)
  19.  *
  20.  * *********************************************************************** */
  21.  
  22.  
  23. #include "xtext.h"
  24.  
  25. extern struct Window *OpenWindow();
  26. extern struct XTextSupport *MakeXTextSupport();
  27. extern UBYTE *MakeXTextFont();
  28.  
  29.  
  30.  
  31. /* Define XTEXTING if you want to see XText(), comment it out if you want 
  32.  * to see normal Amiga Text() processing.
  33.  */
  34. #define XTEXTING
  35.  
  36. /* If you have asked to see XText() (by defined XTEXTING above), then 
  37.  * define SHOW_SLIM_XTEXTING to see the slower, slimmer version of XText().  
  38.  * Comment out this definition if you want to see the faster, fatter XText().
  39.  */
  40. /* #define SHOW_SLIM_XTEXTING */
  41.  
  42. /* If you have asked to see XText() (by defined XTEXTING above), then 
  43.  * define TOPAZ11_XTEXTING to see the Topaz-11 disk-based font used.  
  44.  * Comment out this definition if you want to see normal Topaz-8 XText.
  45.  */
  46. /* #define TOPAZ11_XTEXTING */
  47.  
  48.  
  49.  
  50.  
  51. struct NewWindow NewXTextWindow =
  52.    {
  53.    0, 0,          /* LeftEdge, TopEdge */
  54.    640, 200,            /* Width, Height */
  55.    -1, -1,           /* Detail/BlockPens */
  56.    CLOSEWINDOW,      /* IDCMP Flags */
  57.    WINDOWDEPTH | WINDOWCLOSE | SMART_REFRESH | ACTIVATE | BORDERLESS
  58.          | NOCAREREFRESH,
  59.                      /* Window Specification Flags */
  60.    NULL,             /* FirstGadget */
  61.    NULL,             /* Checkmark */
  62.    (UBYTE *)"XText Window",  /* WindowTitle */
  63.    NULL,             /* Screen */
  64.    NULL,             /* SuperBitMap */
  65.    96, 30,           /* MinWidth, MinHeight */
  66.    640, 200,         /* MaxWidth, MaxHeight */
  67.    WBENCHSCREEN,
  68.    };
  69.  
  70.  
  71. UBYTE buffer[23][80];
  72.  
  73.  
  74. struct TextAttr DiskFont =
  75.     {
  76.     (UBYTE *)"topaz.font",
  77.     11,
  78.     FS_NORMAL,    /* equal 0 */
  79.     FPB_DISKFONT,
  80.     };
  81.  
  82.  
  83. VOID myAddFont();
  84. VOID infoLine();
  85. VOID advancePens();
  86.  
  87.  
  88.  
  89. VOID main()
  90. {
  91.    struct Window *window;
  92.    struct XTextSupport *xtext;
  93.    SHORT line, nextchar, i, i2, lineindex;
  94.    LONG count;
  95.    struct TextAttr *testfont;
  96.  
  97.    IntuitionBase = (struct IntuitionBase *)
  98.          OpenLibrary("intuition.library", 0);
  99.    GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0);
  100.    if ((IntuitionBase == NULL) || (GfxBase == NULL)) goto DONE;
  101.  
  102.    if ((window = OpenWindow(&NewXTextWindow)) == NULL) goto DONE;
  103.  
  104.    SetAPen(window->RPort, 1);
  105.    RectFill(window->RPort, 28, 0, 586, 9);
  106.    SetWindowTitles(window,
  107.          "                      XText Demonstration Window", -1);
  108.    Move(window->RPort, 216, 32);
  109.    Text(window->RPort, "Please wait a moment ...", 24);
  110.  
  111.  
  112. #ifdef TOPAZ11_XTEXTING
  113.    testfont = &DiskFont;
  114. #else
  115.    testfont = NULL;
  116. #endif
  117.  
  118.  
  119. #ifdef SHOW_SLIM_XTEXTING
  120.    xtext = MakeXTextSupport(window->RPort, testfont, 80, SLIM_XTEXT);
  121. #else
  122.    xtext = MakeXTextSupport(window->RPort, testfont, 80, NULL);
  123. #endif
  124.    if (xtext == NULL) goto DONE;
  125.  
  126.  
  127. #ifdef XTEXTING   /* Do you want to see an example of XText() ? */
  128.    myAddFont(xtext, FSF_BOLD, BOLD_FONT, testfont);
  129.    myAddFont(xtext, FSF_UNDERLINED, ULINE_FONT, testfont);
  130.    myAddFont(xtext, FSF_UNDERLINED | FSF_BOLD, ULINE_BOLD_FONT, testfont);
  131.    myAddFont(xtext, FSF_ITALIC, ITALIC_FONT, testfont);
  132.    myAddFont(xtext, FSF_ITALIC | FSF_BOLD, ITALIC_BOLD_FONT, testfont);
  133.    myAddFont(xtext, FSF_ITALIC | FSF_UNDERLINED, 
  134.          ITALIC_ULINE_FONT, testfont);
  135.    myAddFont(xtext, FSF_ITALIC | FSF_UNDERLINED | FSF_BOLD, 
  136.          ITALIC_ULINE_BOLD_FONT, testfont);
  137. #endif
  138.  
  139.    nextchar = 32;
  140.    for (i = 0; i < 23; i++)
  141.       for (i2 = 0; i2 < 80; i2++)
  142.          {
  143.          buffer[i][i2] = nextchar++;
  144.          if (nextchar >= 256) nextchar = 0;
  145.          }
  146.  
  147.    line = 12;
  148.    lineindex = 0;
  149.    count = 0;
  150.  
  151.    while (NOT GetMsg(window->UserPort))
  152.       {
  153. #ifdef XTEXTING
  154.       if (lineindex == 2) infoLine(xtext, line);
  155.       else XText(xtext, &buffer[lineindex][0], 80, 0, line);
  156. #else
  157.       Move(window->RPort, 0, line);
  158.       Text(window->RPort, &buffer[lineindex][0], 80);
  159. #endif
  160.  
  161.       line += xtext->CharHeight;
  162.       lineindex++;
  163.  
  164.       if (line > 192)
  165.          {
  166.          count++;
  167.          sprintf(&buffer[3][33], "-  %ld  -", count);
  168.          line = 12;
  169.          lineindex = 0;
  170.  
  171.          xtext->FontSelect++;
  172.          if (xtext->FontSelect >= 8)
  173.             {
  174.             xtext->FontSelect = 0;
  175.             advancePens(xtext);
  176.             }
  177. #ifndef XTEXTING
  178.          SetAPen(window->RPort, xtext->FrontPen);
  179.          SetBPen(window->RPort, xtext->BackPen);
  180.          SetSoftStyle(window->RPort, xtext->FontSelect, -1);
  181. #endif
  182.          }
  183.       }
  184.  
  185.  
  186.  
  187. DONE:
  188.  
  189.    if (xtext) UnmakeXTextSupport(xtext);
  190.    if (window) CloseWindow(window);
  191.    if (IntuitionBase) CloseLibrary(IntuitionBase);
  192.    if (GfxBase) CloseLibrary(GfxBase);
  193. }
  194.  
  195.  
  196.  
  197. VOID myAddFont(xtext, style, index, font)
  198. struct XTextSupport *xtext;
  199. SHORT style, index;
  200. struct TextAttr *font;
  201. {
  202.    if (font == NULL) font = &SafeFont;
  203.    font->ta_Style = style;
  204.  
  205.    /* I could check if the next routine returned NULL, but since it
  206.     * doesn't hurt anything if it fails, I just won't bother.  It's ok.
  207.     */
  208.    MakeXTextFont(font, xtext, index);
  209. }
  210.  
  211.  
  212.  
  213. VOID infoLine(xtext, line)
  214. struct XTextSupport *xtext;
  215. SHORT line;
  216. {
  217.    SHORT selectsave, pen;
  218.  
  219.    selectsave = xtext->FontSelect;
  220.  
  221.    pen = xtext->FrontPen;
  222.    xtext->FrontPen = xtext->BackPen;
  223.    xtext->BackPen = pen;
  224.  
  225.    xtext->FontSelect = NORMAL_FONT;
  226.    XText(xtext, 
  227.       "- Every time the color changes the text has been entirely redrawn ", 
  228.       66, 0, line);
  229.    xtext->FontSelect = BOLD_FONT;
  230.    XText(xtext, "eight times! -", -1, 66 * 8, line);
  231.  
  232.    pen = xtext->FrontPen;
  233.    xtext->FrontPen = xtext->BackPen;
  234.    xtext->BackPen = pen;
  235.    xtext->FontSelect = selectsave;
  236. }
  237.  
  238.  
  239.  
  240. VOID advancePens(xtext)
  241. struct XTextSupport *xtext;
  242. {
  243.    SHORT frontpen, backpen;
  244.  
  245.    frontpen = xtext->FrontPen;
  246.    backpen = xtext->BackPen;
  247.  
  248.    backpen++;
  249.    if (backpen == frontpen) backpen++;
  250.    if (backpen > 3)
  251.       {
  252.       backpen = 0;
  253.       frontpen++;
  254.       if (frontpen > 3)
  255.          {
  256.          frontpen = 0;
  257.          backpen = 1;
  258.          }
  259.       }
  260.    xtext->FrontPen = frontpen;
  261.    xtext->BackPen = backpen;
  262. }
  263.  
  264.  
  265.