home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************/
- /* */
- /* Amiga C Encyclopedia (ACE) V3.0 Amiga C Club (ACC) */
- /* ------------------------------- ------------------ */
- /* */
- /* Book: ACM Intuition Amiga C Club */
- /* Chapter: Requesters Tulevagen 22 */
- /* File: Example10.c 181 41 LIDINGO */
- /* Author: Anders Bjerin SWEDEN */
- /* Date: 92-05-01 */
- /* Version: 1.10 */
- /* */
- /* Copyright 1992, Anders Bjerin - Amiga C Club (ACC) */
- /* */
- /* Registered members may use this program freely in their */
- /* own commercial/noncommercial programs/articles. */
- /* */
- /***********************************************************/
-
- /* This example demonstrates how you use a requester with a */
- /* predrawn bitmap. This is very useful when you want */
- /* colourful and eye catching requesters. The advantage */
- /* with a special bitmap is that if the window which the */
- /* requester is tied to is resized, the drawing will not be */
- /* destroied. */
- /* */
- /* The graphics data is stored in a separate file called */
- /* "Example10Graphics.c". Both this and the graphical file */
- /* should be compiled separately, then linked together. If */
- /* you have a SAS (Lattice) C Compiler you would do like */
- /* this: */
- /* lc Example10.c */
- /* lc Example10Graphics.c */
- /* blink with Example10.lnk */
- /* */
- /* This program will NOT try to erase the disk! It is ony a */
- /* demonstration how to use a requester. */
-
-
-
- #include <intuition/intuition.h>
-
-
-
- /* The size of the requester: */
- #define WIDTH 310
- #define HEIGHT 180
- #define DEPTH 4
- #define COLOURS 16
-
-
-
- struct IntuitionBase *IntuitionBase;
- struct GfxBase *GfxBase;
-
-
-
-
- /* The graphics for the requester: */
- extern UWORD chip YesNoData[];
-
- /* The sixteen colours: (RGB) */
- UWORD colour[COLOURS]=
- {
- 0x000, 0xFFF, 0x500, 0x900, 0xE00, 0xE60, 0xFE0, 0x06F,
- 0x0AF, 0x04C, 0x666, 0x888, 0xBBB, 0x555, 0x028, 0x0CF
- };
-
- /* The YesNo image structure: */
- struct Image YesNoImage=
- {
- 0, 0, /* LeftEdge, TopEdge */
- 285, 154, DEPTH, /* Width, Height, Depth */
- YesNoData, /* ImageData */
- 0x0F, 0x00, /* PlanePick, PlaneOnOff */
- NULL /* NextImage */
- };
-
- /* The BitMap structure: */
- struct BitMap my_bitmap;
-
- /* The RastPort: */
- struct RastPort my_rast_port;
-
-
-
- /* The YES gadget (the left one): */
- struct Gadget yes_gadget=
- {
- NULL, /* NextGadget, no more gadgets in the list. */
- 44, /* LeftEdge, 44 pixels out. */
- 108, /* TopEdge, 108 lines down. */
- 80, /* Width, 80 pixels wide. */
- 30, /* Height, 30 pixels lines heigh. */
- GADGHCOMP, /* Flags, when this gadget is highlighted, the gadget */
- /* will be rendered in the complement colours. */
- GADGIMMEDIATE| /* Activation, our program will recieve a message when */
- RELVERIFY| /* the user has selected this gadget, and when the user */
- /* has released it. */
- ENDGADGET, /* When the user has selected this gadget, the */
- /* requester is satisfied, and is deactivated. */
- /* IMPORTANT! At least one gadget per requester */
- /* must have the flag ENDGADGET set. If not, the */
- /* requester would never be deactivated! */
-
- BOOLGADGET| /* GadgetType, a Boolean gadget which is connected to */
- REQGADGET, /* a requester. IMPORTANT! Every gadget which is */
- /* connectd to a requester must have the REQGADGET flsg */
- /* set in the GadgetType field. */
- NULL, /* GadgetRender, no rendering. */
- NULL, /* SelectRender, no alternative rendering. */
- NULL, /* GadgetText, no text. */
- NULL, /* MutualExclude, no mutual exclude. */
- NULL, /* SpecialInfo, NULL since this is a Boolean gadget. */
- /* (It is not a Proportional/String or Integer gdget) */
- 0, /* GadgetID, no id. */
- NULL /* UserData, no user data connected to the gadget. */
- };
-
- /* The NO gadget (the right one): */
- struct Gadget no_gadget=
- {
- &yes_gadget, /* NextGadget, pointer to the yes gadget. */
- 200, /* LeftEdge, 200 pixels out. */
- 108, /* TopEdge, 108 lines down. */
- 75, /* Width, 75 pixels wide. */
- 30, /* Height, 30 pixels lines heigh. */
- GADGHCOMP, /* Flags, when this gadget is highlighted, the gadget */
- /* will be rendered in the complement colours. */
- GADGIMMEDIATE| /* Activation, our program will recieve a message when */
- RELVERIFY, /* the user has selected this gadget, and when the user */
- /* has released it. */
- BOOLGADGET| /* GadgetType, a Boolean gadget which is connected to */
- REQGADGET, /* a requester. IMPORTANT! Every gadget which is */
- /* connectd to a requester must have the REQGADGET flsg */
- /* set in the GadgetType field. */
- NULL, /* GadgetRender, no rendering. */
- NULL, /* SelectRender, no alternative rendering. */
- NULL, /* GadgetText, no text. */
- NULL, /* MutualExclude, no mutual exclude. */
- NULL, /* SpecialInfo, NULL since this is a Boolean gadget. */
- /* (It is not a Proportional/String or Integer gdget) */
- 0, /* GadgetID, no id. */
- NULL /* UserData, no user data connected to the gadget. */
- };
-
- /***********************************************************************/
- /* Important notice: */
- /* Remember that every gadget which is connected to a requester must */
- /* have the flag REQGADGET set in the GadgetType field. Remember also */
- /* that at least one gadget per requester must have the ENDGADGET flag */
- /* set in the Activation field. */
- /***********************************************************************/
-
-
-
- /* The request structure: */
- struct Requester my_requester=
- {
- NULL, /* OlderRequester, used by Intuition. */
- 5, 15, /* LeftEdge, TopEdge, 0 pixels out, 0 lines down. */
- WIDTH, HEIGHT, /* Width, Height, 285 pixels wide, 154 lines high. */
- 0, 0, /* RelLeft, RelTop, Since POINTREL flag is not set, */
- /* Intuition ignores these values. */
- &no_gadget, /* ReqGadget, pointer to the first gadget. */
- NULL, /* ReqBorder, no rendering. */
- NULL, /* ReqText, no text. */
- PREDRAWN, /* Flags, we use our own predrawn BitMap. */
- 0, /* BackFill, no backfill. */
- NULL, /* ReqLayer, used by Intuition. Set to NULL. */
- NULL, /* ReqPad1, used by Intuition. Set to NULL. */
- NULL, /* ImageBMap, will later be changed. */
- NULL, /* RWindow, used by Intuition. Set to NULL. */
- NULL /* ReqPad2, used by Intuition. Set to NULL. */
- };
-
-
-
-
- /* A pinter to a Screen structure: */
- struct Screen *my_screen;
-
- /* The NewScreen structure: */
- struct NewScreen my_new_screen=
- {
- 0, /* LeftEdge Should always be 0. */
- 0, /* TopEdge Top of the display.*/
- 320, /* Width We are using a high-resolution screen. */
- 200, /* Height Non-Interlaced NTSC (American) display. */
- DEPTH, /* Depth 4 - 16 colours. */
- 0, /* DetailPen Text should be drawn with colour reg. 0 */
- 1, /* BlockPen Blocks should be drawn with colour reg. 1 */
- NULL, /* ViewModes Low-resolution, non-Interlaced. */
- CUSTOMSCREEN, /* Type Your own customized screen. */
- NULL, /* Font Default font. */
- "MY SCREEN", /* Title The screen' title. */
- NULL, /* Gadget Must for the moment be NULL. */
- NULL /* BitMap No special CustomBitMap. */
- };
-
-
-
- /* A pointer to a Window structure: */
- struct Window *my_window;
-
- /* The NewWindow structure: */
- struct NewWindow my_new_window=
- {
- 0, /* LeftEdge x position of the window. */
- 0, /* TopEdge y positio of the window. */
- 320, /* Width 320 pixels wide. */
- 200, /* Height 200 lines high. */
- 0, /* DetailPen Text should be drawn with colour reg. 0 */
- 1, /* BlockPen Blocks should be drawn with colour reg. 1 */
- CLOSEWINDOW| /* IDCMPFlags The window will give us a message if the */
- /* user has selected the Close window gad, */
- GADGETDOWN| /* or a gadget has been pressed on, or */
- GADGETUP, /* a gadge has been released. */
- SMART_REFRESH| /* Flags Intuition should refresh the window. */
- WINDOWCLOSE| /* Close Gadget. */
- WINDOWDRAG| /* Drag gadget. */
- WINDOWDEPTH| /* Depth arrange Gadgets. */
- WINDOWSIZING| /* Sizing Gadget. */
- ACTIVATE, /* The window should be Active when opened. */
- NULL, /* FirstGadget No gadget connected to this window. */
- NULL, /* CheckMark Use Intuition's default CheckMark. */
- "The Window", /* Title Title of the window. */
- NULL, /* Screen Connected to the Workbench Screen. */
- NULL, /* BitMap No Custom BitMap. */
- 140, /* MinWidth We will not allow the window to become */
- 50, /* MinHeight smaller than 140 x 50, and not bigger */
- 300, /* MaxWidth than 300 x 200. */
- 200, /* MaxHeight */
- CUSTOMSCREEN /* Type Connected to a Custom Screen. */
- };
-
-
-
- /* Declare our functions: */
- void main();
- void clean_up( STRPTR message );
-
-
-
- void main()
- {
- /* Boolean variable used for the while loop: */
- BOOL close_me;
-
- /* Declare a variable in which we will store the IDCMP flag: */
- ULONG class;
-
- /* Declare a pointer to an IntuiMessage structure: */
- struct IntuiMessage *my_message;
-
- /* We use this variable to check if the requester has ben activated */
- /* or not: */
- BOOL result;
-
- /* Used in the loops: */
- int loop;
-
-
-
- /* Before we can use Intuition we need to open the Intuition Library: */
- IntuitionBase = (struct IntuitionBase *)
- OpenLibrary( "intuition.library", 0 );
-
- if( IntuitionBase == NULL )
- clean_up( "Could NOT open the Intuition Library!" );
-
-
- /* Before we can use the function AllocRaster() etc we need to open */
- /* the graphics Library: */
- GfxBase = (struct GfxBase *)
- OpenLibrary( "graphics.library", 0);
-
- if( GfxBase == NULL )
- clean_up( "Could NOT open the Graphics Library!" );
-
-
-
- /* Initialize the BitMap by calling the function: */
- InitBitMap( &my_bitmap, DEPTH, WIDTH, HEIGHT );
- /* &my_bitmap: A pointer to the my_bitmap structure. */
- /* DEPTH: Number of bitplanes to use. */
- /* WIDTH: The width of the BitMap. */
- /* HEIGHT: The height of the BitMap. */
-
-
-
- /* Allocate display memory for the BitMap: */
- for( loop=0; loop < DEPTH; loop++)
- {
- if((my_bitmap.Planes[loop] = (PLANEPTR)
- AllocRaster( WIDTH, HEIGHT )) == NULL )
- clean_up( "Not enough memory for the BitMap!" );
-
- /* Clear the Bitplane: */
- BltClear( my_bitmap.Planes[loop], RASSIZE( WIDTH, HEIGHT ), 0);
- }
-
-
-
- /* Initialize the RastPort structure: */
- InitRastPort( &my_rast_port );
-
- /* Tie the bitmap to the rastport: */
- my_rast_port.BitMap = &my_bitmap;
-
- /* Set the front pen to colour 13: */
- SetAPen( &my_rast_port, 13 );
-
- /* Fill the request: */
- RectFill( &my_rast_port, 0, 0, WIDTH-1, HEIGHT-1 );
-
- /* Draw the image into our own bitmap: */
- DrawImage( &my_rast_port, &YesNoImage, 10, 8 );
-
- /* Give our requester a pointer to our prepared bitmap: */
- my_requester.ImageBMap = &my_bitmap;
-
-
-
- /* We will now try to open the screen: */
- my_screen = (struct Screen *) OpenScreen( &my_new_screen );
-
- /* Have we opened the screen succesfully? */
- if(my_screen == NULL)
- clean_up( "Could not open the Screen!" );
-
-
-
- /* Change colour registers: */
- for( loop = 0; loop < COLOURS; loop++ )
- SetRGB4( &my_screen->ViewPort, loop,
- (colour[ loop ] & 0xF00) >> 8, /* Red */
- (colour[ loop ] & 0x0F0) >> 4, /* Green */
- (colour[ loop ] & 0x00F) /* Blue */
- );
-
-
-
- /* Before we can open the window we need to give the NewWindow */
- /* structure a pointer to the opened Custom Screen: */
- my_new_window.Screen = my_screen;
-
- /* We will now try to open the window: */
- my_window = (struct Window *) OpenWindow( &my_new_window );
-
- /* Have we opened the window succesfully? */
- if(my_window == NULL)
- clean_up( "Could not open the window!" );
-
-
-
- /* We will now try to activate the requester: */
- result=Request( &my_requester, my_window );
-
- if( !result ) /* !result is the same thing as result==FALSE */
- {
- /* Intuition could not activate the requester! */
- /* In this case we do not need to quit since it does not matter if */
- /* the requester was activated or not. I just wanted to show how */
- /* you can check if you have successfully opened requester or not. */
-
- printf("Could not activate the requester!\n");
- }
- else
-
-
-
- close_me = FALSE;
- /* Stay in the while loop until the user has selected the Close window */
- /* gadget. However, in this example the user first need to deactivate */
- /* the requester before he can select the Close window gadget: */
- while( !close_me )
- {
- /* Wait until we have recieved a message: */
- Wait( 1 << my_window->UserPort->mp_SigBit );
-
- /* As long as we collect messages sucessfully: */
- while(my_message=(struct IntuiMessage *) GetMsg(my_window->UserPort))
- {
- /* After we have collected the message we can read it, and save any */
- /* important values which we maybe want to check later: */
- class = my_message->Class;
-
- /* After we have read it we reply as fast as possible: */
- /* REMEMBER! Do never try to read a message after you have replied! */
- /* Some other process has maybe changed it. */
- ReplyMsg( my_message );
-
- /* Check which IDCMP flag was sent: */
- switch( class )
- {
- case CLOSEWINDOW: /* The user selected the Close window gadget! */
-
- /* It is first when the requester has been satisfied, the */
- /* user can close the window. Remember, do never close a */
- /* window if there are any active requester in it. */
-
- close_me=TRUE;
- break;
-
- case GADGETDOWN: /* The user has pressed on a gadget. */
- /* Since there exist only one "nomal" gadget, we do not */
- /* need to check which gadget was selected. */
-
- printf("Down\n");
- break;
-
- case GADGETUP: /* The user has released a gadget. */
- /* Since there exist only one "nomal" gadget, we do not */
- /* need to check which gadget was released. */
-
- printf("Up\n");
-
- /* Once the user releases this gadget the requester will */
- /* be satisfied and deactivated. The user can from now on */
- /* select the Close window gadget. */
-
- printf("Requester satisfied!\n");
- printf("You may now close the window!\n");
- break;
- }
- }
- }
-
-
-
- /* Clean up and quit: */
- clean_up( "THE END" );
- }
-
-
- void clean_up( STRPTR message )
- {
- int loop;
-
-
- /* Close the window: */
- if( my_window )
- CloseWindow( my_window );
-
- /* Close the screen: */
- if( my_screen )
- CloseScreen( my_screen );
-
- /* Deallocate the display memory, Bitplan by Bitplan. */
- for( loop=0; loop < DEPTH; loop++)
- if( my_bitmap.Planes[loop] ) /* Deallocate this Bitplan? */
- FreeRaster( my_bitmap.Planes[loop], WIDTH, HEIGHT );
-
- /* Close the Graphics Library: */
- if( GfxBase )
- CloseLibrary( GfxBase );
-
- /* Close the Intuition Library since we have opened it: */
- if( IntuitionBase )
- CloseLibrary( IntuitionBase );
-
-
- /* Tell the user what has happened: */
- printf( "%s\n", message );
-
- /* Quit: */
- exit( 0 );
- }
-