home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / comms / comprgs / t22bi2.lha / Source_Code / termSource / termInfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-09  |  7.7 KB  |  326 lines

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