home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / CDTools / ClassAct / Examples / BitMap / BitMapExample.c < prev    next >
C/C++ Source or Header  |  1997-07-09  |  6KB  |  172 lines

  1. /* ClassAct Example
  2.  * Copyright 1995 Phantom Development LLC.
  3.  * All Rights Reserved.
  4.  *
  5.  * This Example Shows ClassAct's bitmap.image
  6.  */
  7.  
  8. #include <proto/intuition.h>
  9.  
  10. #include <classact.h>
  11.  
  12. #include <clib/exec_protos.h>
  13. #include <clib/alib_protos.h>
  14. #include <clib/intuition_protos.h>
  15.  
  16. struct ClassLibrary *WindowBase;
  17. struct ClassLibrary *LayoutBase;
  18. struct ClassLibrary *ButtonBase;
  19. struct ClassLibrary *BitMapBase;
  20.  
  21. static struct Image *image;
  22. static struct Screen *screen;
  23. static struct Gadget *gadget;
  24.  
  25. int main( void )
  26. {  Object *Win_Object;
  27.    Object *But_Object;
  28.    struct Window *window;
  29.    struct Image *image1=NULL,*image2=NULL,*image3=NULL;
  30.    struct BitMap *bitmap;
  31.    ULONG result,signal;
  32.    BOOL done=FALSE;
  33.  
  34.    /* Open the classes we will use. Note, classlib.lib SAS/C or DICE autoinit
  35.     * can do this for you automatically.
  36.     */
  37.    if( (WindowBase = (struct ClassLibrary *)OpenLibrary("window.class",0L) )
  38.    &&  (LayoutBase = (struct ClassLibrary *)OpenLibrary("gadgets/layout.gadget",0L) )
  39.    &&  (ButtonBase = (struct ClassLibrary *)OpenLibrary("gadgets/button.gadget",0L) )
  40.    &&  (BitMapBase = (struct ClassLibrary *)OpenLibrary("images/bitmap.image",0L) )
  41.    )
  42.    {
  43.       if(screen=LockPubScreen(NULL))
  44.       {  
  45.          /* Make an image out of an IFF file.
  46.           * The image will be included in the window layout, and is
  47.           * used to clip two other images from
  48.           */
  49.          image1=BitMapObject,
  50.             BITMAP_SourceFile,"PROGDIR:buttons.iff",
  51.             BITMAP_OffsetX, 0,
  52.             BITMAP_OffsetY, 0,
  53.             BITMAP_Width, 577,
  54.             BITMAP_Height, 30,
  55.             BITMAP_Screen,screen,
  56.          EndImage;
  57.  
  58.          if(image1)
  59.          {  
  60.             /* Get the bitmap of the image
  61.              */
  62.             GetAttr(BITMAP_BitMap,image1,(ULONG *)&bitmap);
  63.  
  64.             Win_Object = WindowObject,
  65.                WA_ScreenTitle, "ClassAct Copyright 1995,1996 ClassAct Development Team..",
  66.                WA_Title, "BitMap Example",
  67.                WA_SizeGadget, TRUE,
  68.                WA_Left, 40,
  69.                WA_Top, 30,
  70.                WA_InnerWidth,100,
  71.                WA_DepthGadget, TRUE,
  72.                WA_DragBar, TRUE,
  73.                WA_CloseGadget, TRUE,
  74.                WA_Activate, TRUE,
  75.                WA_PubScreen,screen,
  76.                WINDOW_ParentGroup, VGroupObject,
  77.                   LAYOUT_SpaceOuter, TRUE,
  78.                   LAYOUT_HorizAlignment,LALIGN_CENTER,
  79.                   
  80.                   StartImage,image1,
  81.                   CHILD_NoDispose,TRUE,
  82.  
  83.                   /* Add a button with its imagery read from two
  84.                    * transparent GIF files. BITMAP_Masking,TRUE will
  85.                    * make the imagery appear transparent.
  86.                    */
  87.                   StartMember, But_Object = ButtonObject,
  88.                      GA_ReadOnly, TRUE,
  89.                      GA_Image,image2=BitMapObject,
  90.                         BITMAP_BitMap,bitmap,
  91.                         BITMAP_OffsetX,0,
  92.                         BITMAP_OffsetY,0,
  93.                         BITMAP_Width,120,
  94.                         BITMAP_Height,30,
  95.                         BITMAP_SelectBitMap,bitmap,
  96.                         BITMAP_SelectOffsetX,30,
  97.                         BITMAP_SelectOffsetY,0,
  98.                         BITMAP_SelectWidth,120,
  99.                         BITMAP_SelectHeight,30,
  100.                         BITMAP_Masking,TRUE,
  101.                       EndImage,
  102.                   EndMember,
  103.                   CHILD_WeightedWidth, 0,
  104.                   CHILD_WeightedHeight, 0,
  105.  
  106.                EndMember,
  107.             EndWindow;
  108.              /*  Object creation sucessful?
  109.              */
  110.             if( Win_Object )
  111.             {
  112.                /*  Open the window.
  113.                 */
  114.                if( window = (struct Window *) CA_OpenWindow(Win_Object) )
  115.                {
  116.                   ULONG wait;
  117.                
  118.                   /* Obtain the window wait signal mask.
  119.                    */
  120.                   GetAttr( WINDOW_SigMask, Win_Object, &signal );
  121.                    /* Input Event Loop
  122.                    */
  123.                   while( !done )
  124.                   {
  125.                      SetAttrs(image2, BITMAP_OffsetX, 32, TAG_END);
  126.  
  127.                      wait = Wait(signal|SIGBREAKF_CTRL_C);
  128.  
  129.                      if (wait & SIGBREAKF_CTRL_C) done = TRUE;
  130.                      else
  131.                       while ((result = CA_HandleInput(Win_Object,NULL)) != WMHI_LASTMSG)
  132.                      {
  133.                         switch(result)
  134.                         {
  135.                            case WMHI_CLOSEWINDOW:
  136.                               done = TRUE;
  137.                               break;
  138.                         }
  139.                      }
  140.                   }
  141.                }
  142.                 /* Disposing of the window object will
  143.                 * also close the window if it is
  144.                 * already opened and it will dispose of
  145.                 * all objects attached to it.
  146.                 */
  147.                DisposeObject( Win_Object );
  148.             }
  149.             
  150.             /* Dispose the images ourselves as button.gadget doesn't
  151.              * do this for its GA_Image...
  152.              */
  153.             if(image2) DisposeObject(image2);
  154.             if(image3) DisposeObject(image3);
  155.             if(image1) DisposeObject(image1);
  156.             
  157.          }
  158.  
  159.          UnlockPubScreen(NULL,screen);
  160.       }
  161.    }
  162.  
  163.    /* Close the classes.
  164.     */
  165.    if (BitMapBase) CloseLibrary( (struct Library *)BitMapBase );
  166.    if (ButtonBase) CloseLibrary( (struct Library *)ButtonBase );
  167.    if (LayoutBase) CloseLibrary( (struct Library *)LayoutBase );
  168.    if (WindowBase) CloseLibrary( (struct Library *)WindowBase );
  169.    
  170. }
  171.  
  172.