home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format 49
/
af049sub.adf
/
DisplayText
/
DisplayText.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-24
|
7KB
|
196 lines
/* DisplayText Version 1.0 By DM Hollway (4.3.93) */
/* */
/* Internet addresses: dmh11@vaxa.york.ac.uk OR dmh-a@minster.york.ac.uk */
/* SnailMail: DM Hollway, Langwith College, University Of York, */
/* Heslington, York, YO1 5DD */
/* */
/* SYNOPSIS: Displays up to 7 lines of text in a KickStart(TM) 2 style */
/* window, with an optional title. */
/* */
/* USAGE: DisplayText [?]/[TITLE],[TEXT] For example: */
/* */
/* DisplayText ? */
/* - displays usage information */
/* DisplayText "About" "This Program" "" "is" "" "FREEWARE" */
/* - displays a window with the title 'About' */
/* containing the text: */
/* About---------------[] */
/* | This Program | */
/* | | */
/* | is | */
/* | | */
/* | FREEWARE | */
/* | __________ | */
/* | | Continue | | */
/* |_____----------_____| */
/* */
/* REQUIRES: Workbench 1.3 onwards (tested on my 1200, 500 and 500+) */
/* (might work under 1.2, but I don't have a 1.2 machine to */
/* test it on) */
/* Include the Commodore Includes */
#include <intuition/intuition.h>
/* Let's have ANSI colour in the USAGE info */
#define c_one "\x9b""31m"
#define c_two "\x9b""32m"
struct IntuitionBase *IntuitionBase;
/* The co-ords for the 3D 'Continue'gadget */
SHORT gad_light[]=
{ 1,1,1,12,0,13,0,0,79,0 };
SHORT gad_dark[]=
{ 79,12,79,1,80,0,80,13,1,13 };
/* The Border structure: */
struct Border gad_bli=
{ 0,0,2,0,JAM1,5,gad_light,NULL};
struct Border gad_bda=
{ 0,0,1,0,JAM1,5,gad_dark,&gad_bli};
/* Allocate space for a 30-character window title */
char title[30];
/* We want to use the topaz80 font for the gadget */
struct TextAttr Font=
{"topaz.font",TOPAZ_EIGHTY,FS_NORMAL,FPF_ROMFONT};
/* Declare & initialize an IntuiText structure */
struct IntuiText continue_text=
{ 1,0,JAM2,8,3,&Font,"Continue",NULL,};
struct Gadget continue_gadget=
{ NULL, 59, 86, 81, 14, GADGHCOMP, GADGIMMEDIATE|RELVERIFY, BOOLGADGET,
(APTR) &gad_bda, NULL, &continue_text, NULL, NULL, 0, NULL
};
/* Declare a pointer to the Window structure */
struct Window *display_window;
/* Now let's declare and initialize the NewWindow structure */
struct NewWindow display_new_window=
{ 210, 50, 200, 105, 0, 1, CLOSEWINDOW|GADGETDOWN|GADGETUP,
SMART_REFRESH|WINDOWCLOSE|WINDOWDRAG|WINDOWDEPTH|ACTIVATE,
&continue_gadget, NULL, title, NULL, NULL, 200, 105, 200, 105,
WBENCHSCREEN
};
/* points for the inverse bevel-box */
SHORT bev_l[]= { 1,1,1,66,0,67,0,0,179,0 };
SHORT bev_d[]= { 179,66,179,1,180,0,180,67,1,67 };
/* declare & initialise the bevel-box border */
struct Border bev_sd=
{ 0,0,2,0,JAM1,5,bev_d,NULL };
struct Border bev_sl=
{ 0,0,1,0,JAM1,5,bev_l,&bev_sd };
main(argc,argv) /* takes CLI arguments */
int argc;
char *argv[];
{
int i, r;
i = 1;
r = 0;
/* Did the user specify a title ? */
if ( argc == 1 ) strcpy (title, "Information" ) ;
/* No, so we set title to 'Information' */
if ( argc > 1)
{
/* copy the user's title into the window structure */
strcpy (title, argv[1]) ;
/* Did the user ask for info? */
if ( title[0] == '?' )
{
printf("%sDisplayText%s by DM Hollway\n",c_two, c_one);
printf("Usage: DisplayText [TITLE], [TEXT]\n");
exit();
}
}
/* Boolean variable used to terminate the WHILE loop */
BOOL close_gadget;
/* Somewhere to store the IDCMP flags */
ULONG class;
/* A pointer to an IntuiMessage structure */
struct IntuiMessage *int_message;
/* Try to open the Intuition.library (any version will do) */
IntuitionBase = (struct IntuitionBase *)
OpenLibrary( "intuition.library", 0 );
if( IntuitionBase == NULL )
exit(); /* Oh no! What a personal disaster! We couldn't open it! */
/* Well, we seem to have opened intuition OK, let's open the window */
display_window = (struct Window *) OpenWindow( &display_new_window );
if(display_window == NULL)
{
/* It's one of those days.. We couldn't open the window */
/* so let's close the Intuition.library and exit the program */
CloseLibrary( IntuitionBase );
exit();
}
/* Window's opened OK. Now draw the inverse bevel-box with DrawBorder() */
DrawBorder(display_window->RPort,&bev_sl,10,14);
/* Now display up to 7 lines of text */
if (argc > 2)
{
do
{
i = i + 1;
r = 100 - (strlen(argv[i]) * 4);
Move(display_window->RPort,r,5 + (9 * i));
SetAPen(display_window->RPort,1);
Text(display_window->RPort,argv[i],strlen(argv[i]));
} while (i <= argc && i < 8);
}
close_gadget = FALSE;
/* Now the main loop */
while( close_gadget == FALSE )
{
/* Wait until we get an IntuiMessage */
Wait( 1 << display_window->UserPort->mp_SigBit );
/* then collect it */
int_message = (struct IntuiMessage *) GetMsg( display_window->UserPort );
/* Did we collect it OK? */
if(int_message)
{
class = int_message->Class;
ReplyMsg( int_message );
/* Which IDCMP flag was the message? */
switch( class )
{
case CLOSEWINDOW: /* The user clicked the CloseWindow gadget */
close_gadget=TRUE;
break;
case GADGETDOWN: /* The user pressed the 'Continue' gadget */
break;
case GADGETUP: /* The user released the 'Continue' gadget */
close_gadget=TRUE;
break;
}
}
}
/* Nearly finished, but we should close the windows first */
CloseWindow( display_window );
/* Close the Intuition Library before finishing */
CloseLibrary( IntuitionBase );
}