home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 500-599 / ff589.lza / Term / TermSrc.lha / termInfo.c < prev    next >
C/C++ Source or Header  |  1991-11-24  |  8KB  |  321 lines

  1. /* $Revision Header * Header built automatically - do not edit! *************
  2.  *
  3.  *    (C) Copyright 1991 by Olaf 'Olsen' Barthel & MXM
  4.  *
  5.  *    Name .....: TermInfo.c
  6.  *    Created ..: Saturday 02-Feb-91 20:02
  7.  *    Revision .: 0
  8.  *
  9.  *    Date            Author          Comment
  10.  *    =========       ========        ====================
  11.  *    02-Feb-91       Olsen           Created this file!
  12.  *
  13.  * $Revision Header ********************************************************/
  14.  
  15. #include "TermGlobal.h"
  16.  
  17.     /* We need SetWrMsk(). */
  18.  
  19. #include <graphics/gfxmacros.h>
  20.  
  21.     /* The `term' logo. */
  22.  
  23. STATIC UWORD __chip InfoBits[144] =
  24. {
  25.     0x07C0,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  26.     0x07C0,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  27.     0x07C0,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  28.     0x07C0,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  29.     0xFFFF,0x8003,0xFF00,0x03C0,0xF001,0xF0FE,0x01FE,0x0000,
  30.     0xFFFF,0x801F,0xFFC0,0x03CF,0xF001,0xF7FF,0xCFFF,0x8000,
  31.     0x07C0,0x003E,0x01F0,0x03DF,0x0001,0xFE07,0xFC0F,0xC000,
  32.     0x07C0,0x0078,0x00F0,0x03F8,0x0001,0xF803,0xF003,0xE000,
  33.     0x07C0,0x00F0,0x0078,0x03F0,0x0001,0xF001,0xF003,0xE000,
  34.     0x07C0,0x01FF,0xFFF8,0x03E0,0x0001,0xF001,0xE003,0xE000,
  35.     0x07C0,0x01FF,0xFFF8,0x03E0,0x0001,0xF001,0xE003,0xE000,
  36.     0x07C0,0x01F0,0x0000,0x03E0,0x0001,0xF001,0xE003,0xE000,
  37.     0x07C0,0x00F0,0x0000,0x03E0,0x0001,0xF001,0xE003,0xE000,
  38.     0x07C0,0x00F8,0x0000,0x03E0,0x0001,0xF001,0xE003,0xE000,
  39.     0x07C0,0x007C,0x0000,0x03E0,0x0001,0xF001,0xE003,0xE000,
  40.     0x03E1,0xC03F,0x80F8,0x03E0,0x0001,0xF001,0xE003,0xE000,
  41.     0x03FF,0xC00F,0xFFF0,0x03E0,0x0001,0xF001,0xE003,0xE000,
  42.     0x00FE,0x0000,0xFF00,0x03E0,0x0001,0xF001,0xE003,0xE000
  43. };
  44.  
  45.     /* A dummy image structure. */
  46.  
  47. STATIC struct Image InfoImage =
  48. {
  49.     0,0,
  50.     115,18,1,
  51.     (UWORD *)&InfoBits[0],
  52.     0x03,0x00,
  53.     (struct Image *)NULL
  54. };
  55.  
  56.     /* The real render info. */
  57.  
  58. struct BitMap InfoBitMap;
  59.  
  60.     /* The text we are about to display. */
  61.  
  62. STATIC UBYTE *InfoText[] =
  63. {
  64.     "This is `term', a GIFT-WARE Telecommunications Program",
  65.     "written for use with AmigaOS release 2.0 or higher.",
  66.     "",
  67.     "term © Copyright 1990,91 by Olaf `Olsen' Barthel & MXM",
  68.     "All Rights Reserved",
  69.     "",
  70.     "If you like this program and use it frequently the author",
  71.     "wants you to send him a gift of any kind which you suppose",
  72.     "will do as a `payment' for `term' -- thank you!",
  73.     "",
  74.     "Send suggestions, bug reports, flames & gifts to:",
  75.     "",
  76.     "Olaf `Olsen' Barthel, MXM",
  77.     "Brabeckstrasse 35",
  78.     "D-3000 Hannover 71",
  79.     "",
  80.     "Federal Republic of Germany"
  81. };
  82.  
  83.     /* Height offset for the info window. */
  84.  
  85. #define HEIGHT ((((sizeof(InfoText) >> 2) + 3) << 3) + 2)
  86.  
  87.     /* ShowInfo():
  88.      *
  89.      *    Open a window, draw the `term' logo, show some text
  90.      *    and wait for user reaction (believe it or not, this took
  91.      *    me two hours to program!).
  92.      */
  93.  
  94. VOID
  95. ShowInfo(BYTE Ticks)
  96. {
  97.     struct Window    *InfoWindow;
  98.     LONG         i,Length,MaxWidth,Offset = (Ticks ? 0 : 16);
  99.  
  100.         /* Find the longest string. */
  101.  
  102.     for(i = MaxWidth = 0 ; i < (sizeof(InfoText) >> 2) ; i++)
  103.     {
  104.         if((Length = strlen(InfoText[i])) > MaxWidth)
  105.             MaxWidth = Length;
  106.     }
  107.  
  108.     MaxWidth = (MaxWidth << 3) + 10;
  109.  
  110.         /* Open the window. */
  111.  
  112.     if(InfoWindow = OpenWindowTags(NULL,
  113.         WA_Left,        (Screen -> Width - MaxWidth) >> 1,
  114.         WA_Top,            (Screen -> Height - (HEIGHT + InfoImage . Height + 1 + Offset)) >> 1,
  115.         WA_InnerWidth,        MaxWidth,
  116.         WA_InnerHeight,        HEIGHT + InfoImage . Height + Offset,
  117.         WA_IDCMP,        IDCMP_VANILLAKEY | IDCMP_RAWKEY | IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS | IDCMP_INTUITICKS | IDCMP_INACTIVEWINDOW | BUTTONIDCMP,
  118.         WA_ReportMouse,        TRUE,
  119.         WA_Activate,        TRUE,
  120.         WA_RMBTrap,        TRUE,
  121.         WA_SmartRefresh,    TRUE,
  122.         WA_GimmeZeroZero,    TRUE,
  123.         WA_CustomScreen,    Screen,
  124.     TAG_DONE))
  125.     {
  126.         struct Gadget        *GadgetList = NULL,
  127.                     *Gadget = NULL;
  128.  
  129.         if(Ticks)
  130.             goto Skip;
  131.  
  132.         if(Gadget = CreateContext(&GadgetList))
  133.         {
  134.             struct NewGadget NewGadget;
  135.  
  136.             memset(&NewGadget,0,sizeof(struct NewGadget));
  137.  
  138.             NewGadget . ng_Width        = 80;
  139.             NewGadget . ng_Height        = 16;
  140.             NewGadget . ng_GadgetText    = "_Continue";
  141.             NewGadget . ng_TextAttr        = &DefaultFont;
  142.             NewGadget . ng_VisualInfo    = VisualInfo;
  143.             NewGadget . ng_GadgetID        = 0;
  144.             NewGadget . ng_Flags        = NULL;
  145.             NewGadget . ng_LeftEdge        = (InfoWindow -> Width - NewGadget . ng_Width) >> 1;
  146.             NewGadget . ng_TopEdge        = InfoWindow -> Height - (NewGadget . ng_Height + 8);
  147.  
  148.             Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  149.                 GT_Underscore,    '_',
  150.             TAG_DONE);
  151.  
  152. Skip:            if(Gadget || Ticks)
  153.             {
  154.                 struct RastPort        *IPort;
  155.                 LONG             Left,Top;
  156.  
  157.                 struct IntuiMessage    *Massage;
  158.                 BYTE             Terminated = FALSE;
  159.  
  160.                 BYTE             FgPen,BgPen;
  161.  
  162.                 LONG             TickCount = 0;
  163.  
  164.                 if(Gadget)
  165.                 {
  166.                     AddGList(InfoWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
  167.                     RefreshGList(GadgetList,InfoWindow,NULL,(UWORD)-1);
  168.                     GT_RefreshWindow(InfoWindow,NULL);
  169.                 }
  170.  
  171.                     /* Adapt the rendering pens accordingly. */
  172.  
  173.                 switch(Config . ColourMode)
  174.                 {
  175.                     case COLOUR_EIGHT:    FgPen = 7;
  176.                                 BgPen = 4;
  177.  
  178.                                 break;
  179.  
  180.                     case COLOUR_SIXTEEN:    FgPen = 15;
  181.                                 BgPen = 8;
  182.  
  183.                                 break;
  184.  
  185.                     case COLOUR_AMIGA:    BgPen = 1;
  186.                                 FgPen = 2;
  187.  
  188.                                 break;
  189.  
  190.                     case COLOUR_MONO:    BgPen = 1;
  191.                                 FgPen = 1;
  192.  
  193.                                 break;
  194.                 }
  195.  
  196.                     /* Just a shortcut. */
  197.  
  198.                 IPort = InfoWindow -> RPort;
  199.  
  200.                     /* Set up rendering modes. */
  201.  
  202.                 SetDrMd(IPort,JAM1);
  203.                 SetFont(IPort,Topaz);
  204.  
  205.                     /* Set up the logo. */
  206.  
  207.                 InitBitMap(&InfoBitMap,IPort -> BitMap -> Depth,115,18);
  208.  
  209.                 for(i = 0 ; i < IPort -> BitMap -> Depth ; i++)
  210.                     InfoBitMap . Planes[i] = (PLANEPTR)&InfoBits[0];
  211.  
  212.                 if(Config . ColourMode != COLOUR_MONO)
  213.                 {
  214.                         /* Draw the logo shadow. */
  215.  
  216.                     SetWrMsk(IPort,BgPen);
  217.                     BltBitMapRastPort(&InfoBitMap,0,0,IPort,((InfoWindow -> GZZWidth - InfoImage . Width) >> 1) + 2,8 + 1,InfoImage . Width,InfoImage . Height,0xC0);
  218.  
  219.                         /* Clear out the bright part. */
  220.  
  221.                     SetWrMsk(IPort,~0);
  222.                     BltBitMapRastPort(&InfoBitMap,0,0,IPort,((InfoWindow -> GZZWidth - InfoImage . Width) >> 1),8,InfoImage . Width,InfoImage . Height,0x20);
  223.                 }
  224.  
  225.                     /* Add the bright part. */
  226.  
  227.                 SetWrMsk(IPort,FgPen);
  228.                 BltBitMapRastPort(&InfoBitMap,0,0,IPort,((InfoWindow -> GZZWidth - InfoImage . Width) >> 1),8,InfoImage . Width,InfoImage . Height,0xE0);
  229.  
  230.                     /* Return to normal rendering. */
  231.  
  232.                 SetWrMsk(IPort,~0);
  233.  
  234.                     /* Determine first line. */
  235.  
  236.                 Top = (InfoWindow -> GZZHeight - HEIGHT - Offset) + Topaz -> tf_Baseline - 1 + InfoImage . Height;
  237.  
  238.                     /* Walk down the text list. */
  239.  
  240.                 for(i = 0 ; i < (sizeof(InfoText) >> 2) ; i++)
  241.                 {
  242.                         /* Can we print this line? */
  243.  
  244.                     if(Length = strlen(InfoText[i]))
  245.                     {
  246.                             /* Centre it. */
  247.  
  248.                         Left = (InfoWindow -> GZZWidth - (Length << 3)) >> 1;
  249.  
  250.                             /* Draw the shadow. */
  251.  
  252.                         if(Config . ColourMode != COLOUR_MONO)
  253.                         {
  254.                             SetAPen(IPort,BgPen);
  255.                             Move(IPort,Left + 2,Top + 1);
  256.                             Text(IPort,InfoText[i],Length);
  257.                         }
  258.  
  259.                             /* Draw the bright part. */
  260.  
  261.                         SetAPen(IPort,FgPen);
  262.                         Move(IPort,Left,Top);
  263.                         Text(IPort,InfoText[i],Length);
  264.                     }
  265.  
  266.                         /* Jump to next line. */
  267.  
  268.                     Top += Topaz -> tf_YSize;
  269.                 }
  270.  
  271.                     /* Ignore any previously received input. */
  272.  
  273.                 while(Massage = (struct IntuiMessage *)GetMsg(InfoWindow -> UserPort))
  274.                     ReplyMsg(Massage);
  275.  
  276.                 if(Ticks)
  277.                     Say("Welcome to term.");
  278.  
  279.                 ActivateWindow(InfoWindow);
  280.  
  281.                     /* Wait for mouse/key event. */
  282.  
  283.                 while(!Terminated)
  284.                 {
  285.                     WaitPort(InfoWindow -> UserPort);
  286.  
  287.                     while(Massage = (struct IntuiMessage *)GetMsg(InfoWindow -> UserPort))
  288.                     {
  289.                         if(Ticks)
  290.                         {
  291.                             if(Massage -> Class == IDCMP_INTUITICKS)
  292.                             {
  293.                                 if(TickCount++ == 50)
  294.                                     Terminated = TRUE;
  295.                             }
  296.                             else
  297.                                 Terminated = TRUE;
  298.                         }
  299.                         else
  300.                         {
  301.                             if((Massage -> Class == IDCMP_VANILLAKEY && ToUpper(Massage -> Code) == 'C') || Massage -> Class == IDCMP_GADGETUP)
  302.                                 Terminated = TRUE;
  303.                         }
  304.  
  305.                         ReplyMsg(Massage);
  306.                     }
  307.                 }
  308.  
  309.                 if(Gadget)
  310.                     RemoveGList(InfoWindow,GadgetList,(UWORD)-1);
  311.             }
  312.         }
  313.  
  314.         FreeGadgets(GadgetList);
  315.  
  316.             /* Close the window and exit. */
  317.  
  318.         CloseWindow(InfoWindow);
  319.     }
  320. }
  321.