home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / comms / comprgs / term232.lha / Source_Code / termSource / termInfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-18  |  7.0 KB  |  331 lines

  1. /*
  2. **    $Id: termInfo.c,v 1.6 92/08/15 20:14:26 olsen Sta Locker: olsen $
  3. **    $Revision: 1.6 $
  4. **    $Date: 92/08/15 20:14:26 $
  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.     /* ShowInfo():
  15.      *
  16.      *    Open a window, draw the `term' logo, show some text
  17.      *    and wait for user reaction (believe it or not, this took
  18.      *    me two hours to program!).
  19.      */
  20.  
  21. BYTE
  22. ShowInfo(BYTE Ticks)
  23. {
  24.     struct Window        *InfoWindow;
  25.     LONG             i,Length,MaxWidth,Offset = (Ticks ? 0 : 16);
  26.     BYTE             GotRexxMessage = FALSE;
  27.     struct DiskObject    *Icon = NULL;
  28.     LONG             Height,
  29.                  Width;
  30.     struct Image        *Image;
  31.  
  32.     SZ_SizeSetup(Screen,&UserFont,TRUE);
  33.  
  34.     if(IconBase = OpenLibrary("icon.library",0))
  35.     {
  36.         if(WBenchMsg)
  37.         {
  38.             if(WBenchMsg -> sm_ArgList)
  39.             {
  40.                 if(WBenchMsg -> sm_ArgList -> wa_Name)
  41.                     Icon = GetDiskObjectNew(WBenchMsg -> sm_ArgList -> wa_Name);
  42.             }
  43.         }
  44.  
  45.         if(!Icon)
  46.             Icon = GetDiskObjectNew("term");
  47.  
  48.         if(Icon)
  49.         {
  50.             if(Icon -> do_Type != WBTOOL)
  51.             {
  52.                 FreeDiskObject(Icon);
  53.  
  54.                 Icon = NULL;
  55.             }
  56.         }
  57.     }
  58.  
  59.     Offset = Screen -> WBorTop + INTERHEIGHT;
  60.  
  61.     Height = Screen -> WBorTop + INTERHEIGHT + 17 * (UserFontHeight + 1) + INTERHEIGHT + Screen -> WBorBottom;
  62.  
  63.     if(!Ticks)
  64.         Height += SZ_Height(BUTTON_KIND,0,0) + INTERHEIGHT;
  65.  
  66.     if(Icon)
  67.     {
  68.         Image = Icon -> do_Gadget . GadgetRender;
  69.  
  70.         if(Image -> TopEdge + Image -> Height + INTERHEIGHT + Height > Screen -> Height)
  71.         {
  72.             FreeDiskObject(Icon);
  73.  
  74.             Icon = NULL;
  75.         }
  76.         else
  77.         {
  78.             Offset += Image -> TopEdge + Image -> Height + INTERHEIGHT;
  79.  
  80.             Height += Image -> TopEdge + Image -> Height + INTERHEIGHT;
  81.         }
  82.     }
  83.  
  84.         /* Find the longest string. */
  85.  
  86.     for(i = MaxWidth = 0 ; i < 17 ; i++)
  87.     {
  88.         if((Length = SZ_TextWidth(LocaleString(MSG_TERMINFO_INFOTEXT1_TXT + i))) > MaxWidth)
  89.             MaxWidth = Length;
  90.     }
  91.  
  92.     if(Icon)
  93.     {
  94.         if(Image -> LeftEdge + Image -> Width > MaxWidth)
  95.             MaxWidth = Image -> LeftEdge + Image -> Width;
  96.     }
  97.  
  98.     Width = Screen -> WBorLeft + INTERWIDTH + MaxWidth + INTERWIDTH + Screen -> WBorRight;
  99.  
  100.         /* Open the window. */
  101.  
  102.     if(InfoWindow = OpenWindowTags(NULL,
  103.         WA_Left,        (Width < Screen -> Width) ? (Screen -> Width - Width) / 2 : 0,
  104.         WA_Top,            (Height < Screen -> Height) ? (Screen -> Height - Height) / 2 : 0,
  105.         WA_Width,        Width,
  106.         WA_Height,        Height,
  107.         WA_IDCMP,        IDCMP_VANILLAKEY | IDCMP_RAWKEY | IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS | IDCMP_INTUITICKS | IDCMP_INACTIVEWINDOW | BUTTONIDCMP,
  108.         WA_ReportMouse,        TRUE,
  109.         WA_Activate,        TRUE,
  110.         WA_RMBTrap,        TRUE,
  111.         WA_SmartRefresh,    TRUE,
  112.         WA_GimmeZeroZero,    TRUE,
  113.         WA_CustomScreen,    Screen,
  114.     TAG_DONE))
  115.     {
  116.         struct Gadget        *GadgetList    = NULL,
  117.                     *Gadget        = NULL;
  118.  
  119.         if(Ticks)
  120.             goto Skip;
  121.  
  122.         if(Gadget = CreateContext(&GadgetList))
  123.         {
  124.             struct NewGadget    NewGadget;
  125.             WORD            Len;
  126.  
  127.             memset(&NewGadget,0,sizeof(struct NewGadget));
  128.  
  129.             NewGadget . ng_Width        = SZ_Width(BUTTON_KIND,LocaleString(MSG_TERMINFO_CONTINUE_TXT),0,NULL);
  130.             NewGadget . ng_Height        = SZ_Height(BUTTON_KIND,0,0);
  131.             NewGadget . ng_GadgetText    = LocaleString(MSG_TERMINFO_CONTINUE_TXT);
  132.             NewGadget . ng_TextAttr        = &UserFont;
  133.             NewGadget . ng_VisualInfo    = VisualInfo;
  134.             NewGadget . ng_GadgetID        = 0;
  135.             NewGadget . ng_Flags        = NULL;
  136.             NewGadget . ng_LeftEdge        = (InfoWindow -> Width - NewGadget . ng_Width) / 2;
  137.             NewGadget . ng_TopEdge        = InfoWindow -> Height - (Screen -> WBorBottom + INTERHEIGHT + NewGadget . ng_Height);
  138.  
  139.             Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  140.                 GT_Underscore,    '_',
  141.             TAG_DONE);
  142.  
  143. Skip:            if(Gadget || Ticks)
  144.             {
  145.                 struct RastPort        *IPort;
  146.                 LONG             Left,Top;
  147.  
  148.                 struct IntuiMessage    *Massage;
  149.                 BYTE             Terminated = FALSE;
  150.  
  151.                 BYTE             FgPen,BgPen;
  152.                 LONG             TickCount = 0;
  153.                 ULONG             SignalSet;
  154.  
  155.                 UBYTE             TheKey,
  156.                             *Button;
  157.  
  158.                 SetFont(InfoWindow -> RPort,UserTextFont);
  159.  
  160.                 Button = LocaleString(MSG_TERMINFO_CONTINUE_TXT);
  161.  
  162.                 while(*Button)
  163.                 {
  164.                     if(*Button++ == '_')
  165.                     {
  166.                         TheKey = ToUpper(*Button);
  167.  
  168.                         break;
  169.                     }
  170.                 }
  171.  
  172.                 if(Gadget)
  173.                 {
  174.                     AddGList(InfoWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
  175.                     RefreshGList(GadgetList,InfoWindow,NULL,(UWORD)-1);
  176.                     GT_RefreshWindow(InfoWindow,NULL);
  177.                 }
  178.  
  179.                     /* Adapt the rendering pens accordingly. */
  180.  
  181.                 switch(Config . ColourMode)
  182.                 {
  183.                     case COLOUR_EIGHT:    FgPen = 7;
  184.                                 BgPen = 4;
  185.  
  186.                                 break;
  187.  
  188.                     case COLOUR_SIXTEEN:    FgPen = 15;
  189.                                 BgPen = 8;
  190.  
  191.                                 break;
  192.  
  193.                     case COLOUR_AMIGA:    BgPen = 1;
  194.                                 FgPen = 2;
  195.  
  196.                                 break;
  197.  
  198.                     case COLOUR_MONO:    BgPen = 1;
  199.                                 FgPen = 1;
  200.  
  201.                                 break;
  202.                 }
  203.  
  204.                 if(Config . DisableBlinking & TERMINAL_FASTER)
  205.                 {
  206.                     if(FgPen == 2)
  207.                         FgPen = 1;
  208.  
  209.                     BgPen = FgPen;
  210.                 }
  211.  
  212.                     /* Just a shortcut. */
  213.  
  214.                 IPort = InfoWindow -> RPort;
  215.  
  216.                     /* Set up rendering modes. */
  217.  
  218.                 SetDrMd(IPort,JAM1);
  219.  
  220.                     /* Draw the icon if any. */
  221.  
  222.                 if(Icon)
  223.                     DrawImage(IPort,Image,(InfoWindow -> Width - (Image -> Width + Image -> LeftEdge)) / 2,Screen -> WBorTop + INTERHEIGHT);
  224.  
  225.                     /* Determine first line. */
  226.  
  227.                 Top = Offset + UserFontBase;
  228.  
  229.                     /* Walk down the text list. */
  230.  
  231.                 for(i = 0 ; i < 17 ; i++)
  232.                 {
  233.                         /* Can we print this line? */
  234.  
  235.                     if(Len = strlen(LocaleString(MSG_TERMINFO_INFOTEXT1_TXT + i)))
  236.                     {
  237.                         Length = SZ_TextWidth(LocaleString(MSG_TERMINFO_INFOTEXT1_TXT + i));
  238.  
  239.                             /* Centre it. */
  240.  
  241.                         Left = (InfoWindow -> GZZWidth - Length) / 2;
  242.  
  243.                             /* Draw the shadow. */
  244.  
  245.                         if(FgPen != BgPen)
  246.                         {
  247.                             SetAPen(IPort,BgPen);
  248.                             Move(IPort,Left + 1,Top + 1);
  249.                             Text(IPort,LocaleString(MSG_TERMINFO_INFOTEXT1_TXT + i),Len);
  250.                         }
  251.  
  252.                             /* Draw the bright part. */
  253.  
  254.                         SetAPen(IPort,FgPen);
  255.                         Move(IPort,Left,Top);
  256.                         Text(IPort,LocaleString(MSG_TERMINFO_INFOTEXT1_TXT + i),Len);
  257.                     }
  258.  
  259.                         /* Jump to next line. */
  260.  
  261.                     Top += UserFontHeight + 1;
  262.                 }
  263.  
  264.                     /* Ignore any previously received input. */
  265.  
  266.                 while(Massage = (struct IntuiMessage *)GetMsg(InfoWindow -> UserPort))
  267.                     ReplyMsg(Massage);
  268.  
  269.                 if(Ticks)
  270.                     Say(LocaleString(MSG_TERMINFO_WELCOME_TO_TERM_TXT));
  271.  
  272.                 ActivateWindow(InfoWindow);
  273.  
  274.                     /* Wait for mouse/key event. */
  275.  
  276.                 while(!Terminated)
  277.                 {
  278.                     SignalSet = Wait(SIG_REXX | (1 << InfoWindow -> UserPort -> mp_SigBit));
  279.  
  280.                     if(Ticks)
  281.                     {
  282.                         if(SignalSet & SIG_REXX)
  283.                         {
  284.                             GotRexxMessage    = TRUE;
  285.                             Terminated    = TRUE;
  286.                         }
  287.                     }
  288.  
  289.                     while(Massage = (struct IntuiMessage *)GetMsg(InfoWindow -> UserPort))
  290.                     {
  291.                         if(Ticks)
  292.                         {
  293.                             if(Massage -> Class == IDCMP_INTUITICKS)
  294.                             {
  295.                                 if(TickCount++ == 50)
  296.                                     Terminated = TRUE;
  297.                             }
  298.                             else
  299.                                 Terminated = TRUE;
  300.                         }
  301.                         else
  302.                         {
  303.                             if((Massage -> Class == IDCMP_VANILLAKEY && ToUpper(Massage -> Code) == TheKey) || Massage -> Class == IDCMP_GADGETUP)
  304.                                 Terminated = TRUE;
  305.                         }
  306.  
  307.                         ReplyMsg(Massage);
  308.                     }
  309.                 }
  310.  
  311.                 if(Gadget)
  312.                     RemoveGList(InfoWindow,GadgetList,(UWORD)-1);
  313.             }
  314.         }
  315.  
  316.         FreeGadgets(GadgetList);
  317.  
  318.             /* Close the window and exit. */
  319.  
  320.         CloseWindow(InfoWindow);
  321.     }
  322.  
  323.     if(Icon)
  324.         FreeDiskObject(Icon);
  325.  
  326.     if(IconBase)
  327.         CloseLibrary(IconBase);
  328.  
  329.     return(GotRexxMessage);
  330. }
  331.