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