home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 49 / af049sub.adf / DisplayText / DisplayText.c < prev    next >
C/C++ Source or Header  |  1993-05-24  |  7KB  |  196 lines

  1. /*           DisplayText Version 1.0 By DM Hollway  (4.3.93)             */
  2. /*                                                                       */
  3. /* Internet addresses: dmh11@vaxa.york.ac.uk OR dmh-a@minster.york.ac.uk */
  4. /* SnailMail: DM Hollway, Langwith College, University Of York,          */
  5. /*                     Heslington, York, YO1 5DD                         */
  6. /*                                                                       */
  7. /* SYNOPSIS:   Displays up to 7 lines of text in a KickStart(TM) 2 style */
  8. /*             window, with an optional title.                           */
  9. /*                                                                       */
  10. /* USAGE:      DisplayText [?]/[TITLE],[TEXT]  For example:              */
  11. /*                                                                       */
  12. /*             DisplayText ?                                             */
  13. /*                          - displays usage information                 */
  14. /*             DisplayText "About" "This Program" "" "is" "" "FREEWARE"  */
  15. /*                          - displays a window with the title 'About'   */
  16. /*                            containing the text:                       */
  17. /*                   About---------------[]                              */
  18. /*                   |    This Program    |                              */
  19. /*                   |                    |                              */
  20. /*                   |         is         |                              */
  21. /*                   |                    |                              */
  22. /*                   |      FREEWARE      |                              */
  23. /*                   |     __________     |                              */
  24. /*                   |    | Continue |    |                              */
  25. /*                   |_____----------_____|                              */
  26. /*                                                                       */
  27. /* REQUIRES: Workbench 1.3 onwards (tested on my 1200, 500 and 500+)     */
  28. /*           (might work under 1.2, but I don't have a 1.2 machine to    */
  29. /*           test it on)                                                 */
  30.  
  31. /* Include the Commodore Includes */
  32. #include <intuition/intuition.h>
  33.  
  34. /* Let's have ANSI colour in the USAGE info */
  35. #define c_one "\x9b""31m"
  36. #define c_two "\x9b""32m"
  37.  
  38. struct IntuitionBase *IntuitionBase;
  39.  
  40. /* The co-ords for the 3D 'Continue'gadget */
  41. SHORT gad_light[]=
  42. {  1,1,1,12,0,13,0,0,79,0 };
  43. SHORT gad_dark[]=
  44. {  79,12,79,1,80,0,80,13,1,13 };
  45.  
  46. /* The Border structure: */
  47. struct Border gad_bli=
  48. { 0,0,2,0,JAM1,5,gad_light,NULL};
  49.  
  50. struct Border gad_bda=
  51. { 0,0,1,0,JAM1,5,gad_dark,&gad_bli};
  52.  
  53. /* Allocate space for a 30-character window title */
  54. char title[30];
  55.  
  56. /* We want to use the topaz80 font for the gadget */
  57. struct TextAttr Font=
  58.  {"topaz.font",TOPAZ_EIGHTY,FS_NORMAL,FPF_ROMFONT};
  59.  
  60. /* Declare & initialize an IntuiText structure */
  61. struct IntuiText continue_text=
  62. { 1,0,JAM2,8,3,&Font,"Continue",NULL,};
  63.  
  64. struct Gadget continue_gadget=
  65. { NULL, 59, 86, 81, 14, GADGHCOMP, GADGIMMEDIATE|RELVERIFY, BOOLGADGET,
  66.   (APTR) &gad_bda, NULL, &continue_text, NULL, NULL, 0, NULL
  67. };
  68.  
  69. /* Declare a pointer to the Window structure */
  70. struct Window *display_window;
  71.  
  72. /* Now let's declare and initialize the NewWindow structure */
  73. struct NewWindow display_new_window=
  74. { 210, 50, 200, 105, 0, 1, CLOSEWINDOW|GADGETDOWN|GADGETUP,
  75.   SMART_REFRESH|WINDOWCLOSE|WINDOWDRAG|WINDOWDEPTH|ACTIVATE,
  76.   &continue_gadget, NULL, title, NULL, NULL, 200, 105, 200, 105,
  77.   WBENCHSCREEN
  78. };
  79.  
  80. /* points for the inverse bevel-box */
  81. SHORT bev_l[]= { 1,1,1,66,0,67,0,0,179,0 };
  82. SHORT bev_d[]= { 179,66,179,1,180,0,180,67,1,67 };
  83.  
  84. /* declare & initialise the bevel-box border */
  85. struct Border bev_sd=
  86. { 0,0,2,0,JAM1,5,bev_d,NULL };
  87. struct Border bev_sl=
  88. { 0,0,1,0,JAM1,5,bev_l,&bev_sd };
  89.  
  90.  
  91. main(argc,argv) /* takes CLI arguments */
  92.   int argc;
  93.   char *argv[];
  94. {
  95.   int i, r;
  96.   i = 1;
  97.   r = 0;
  98.   /* Did the user specify a title ? */
  99.   if ( argc == 1 ) strcpy (title, "Information" ) ;
  100.   /* No, so we set title to 'Information' */
  101.   if ( argc > 1)
  102.     {
  103.       /* copy the user's title into the window structure */
  104.       strcpy (title, argv[1]) ;
  105.       /* Did the user ask for info? */
  106.       if ( title[0] == '?' )
  107.          {
  108.            printf("%sDisplayText%s by DM Hollway\n",c_two, c_one);
  109.            printf("Usage: DisplayText [TITLE], [TEXT]\n");
  110.            exit();
  111.          }
  112.     }
  113.   /* Boolean variable used to terminate the WHILE loop */
  114.   BOOL close_gadget;
  115.  
  116.   /* Somewhere to store the IDCMP flags */
  117.   ULONG class;
  118.   
  119.   /* A pointer to an IntuiMessage structure */
  120.   struct IntuiMessage *int_message;
  121.  
  122.   /* Try to open the Intuition.library (any version will do) */
  123.   IntuitionBase = (struct IntuitionBase *)
  124.     OpenLibrary( "intuition.library", 0 );
  125.   
  126.   if( IntuitionBase == NULL )
  127.     exit(); /* Oh no! What a personal disaster! We couldn't open it! */
  128.  
  129.   /* Well, we seem to have opened intuition OK, let's open the window */
  130.   display_window = (struct Window *) OpenWindow( &display_new_window );
  131.   
  132.   if(display_window == NULL)
  133.    {
  134.     /* It's one of those days.. We couldn't open the window */
  135.     /* so let's close the Intuition.library and exit the program */
  136.     CloseLibrary( IntuitionBase );
  137.     exit();  
  138.    }
  139.   /* Window's opened OK. Now draw the inverse bevel-box with DrawBorder() */
  140.   DrawBorder(display_window->RPort,&bev_sl,10,14);
  141.  
  142.   /* Now display up to 7 lines of text */
  143.   if (argc > 2)
  144.   {
  145.     do
  146.       {
  147.        i = i + 1;
  148.        r = 100 - (strlen(argv[i]) * 4);
  149.        Move(display_window->RPort,r,5 + (9 * i));
  150.        SetAPen(display_window->RPort,1);
  151.        Text(display_window->RPort,argv[i],strlen(argv[i]));
  152.       } while (i <= argc && i < 8);
  153.   }
  154.  
  155.   close_gadget = FALSE;
  156.   /* Now the main loop */
  157.   while( close_gadget == FALSE )
  158.   {
  159.     /* Wait until we get an IntuiMessage */
  160.     Wait( 1 << display_window->UserPort->mp_SigBit );
  161.  
  162.     /* then collect it */
  163.     int_message = (struct IntuiMessage *) GetMsg( display_window->UserPort );
  164.  
  165.     /* Did we collect it OK? */
  166.     if(int_message)
  167.       {
  168.         class = int_message->Class;
  169.  
  170.         ReplyMsg( int_message );
  171.  
  172.         /* Which IDCMP flag was the message? */
  173.         switch( class )
  174.          {
  175.            case CLOSEWINDOW:  /* The user clicked the CloseWindow gadget */
  176.                   close_gadget=TRUE;
  177.                   break;
  178.                
  179.            case GADGETDOWN:   /* The user pressed the 'Continue' gadget */
  180.                   break;
  181.              
  182.            case GADGETUP:     /* The user released the 'Continue' gadget */
  183.                   close_gadget=TRUE;
  184.                   break;
  185.          }
  186.       }
  187.   }
  188.   /* Nearly finished, but we should close the windows first */
  189.   CloseWindow( display_window );
  190.  
  191.   /* Close the Intuition Library before finishing */
  192.   CloseLibrary( IntuitionBase );
  193.   
  194. }
  195.  
  196.