home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Atlanta_1990 / Atlanta-Devcon.1 / Libraries / Intuition / boopsi / demoframe.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-26  |  4.2 KB  |  179 lines

  1. /* demoframe.c -- demonstration of         :ts=8
  2.  * "framed" image class.
  3.  */
  4.  
  5. /*
  6. Copyright (c) 1989 Commodore-Amiga, Inc.
  7.  
  8. Executables based on this information may be used in software
  9. for Commodore Amiga computers. All other rights reserved.
  10. This information is provided "as is"; no warranties are made.
  11. All use is at your own risk, and no liability or responsibility
  12. is assumed.
  13. */
  14.  
  15. #include "sysall.h"
  16.  
  17. #define D(x)    x
  18.  
  19. struct  IntuitionBase   *IntuitionBase;
  20. struct  GfxBase         *GfxBase;
  21. struct  Library         *UtilityBase;
  22.  
  23. void    *Frame1Class = NULL;
  24. void    *initFrame1Class();
  25.  
  26. /* from varargs.c -- interface to NewObjectA()    */
  27. Object    *NewObject();
  28.  
  29. ULONG    myiflags = CLOSEWINDOW;
  30.  
  31. struct Image    *frameimage;
  32.  
  33. main()
  34. {
  35.     struct DrawInfo    *GetScreenDrawInfo();
  36.     struct Window     *OpenWindowTags();    /* in varargs.c for now */
  37.     struct Window    *w;
  38.     struct DrawInfo    *drinfo;
  39.     struct IBox        srcbox;
  40.     struct IBox        framebox;
  41.  
  42.     if (!(UtilityBase=(struct Library *)OpenLibrary("utility.library",36L)))
  43.     { cleanup("no V36 utility library\n"); }
  44.  
  45.     if (!(IntuitionBase = 
  46.     (struct IntuitionBase *) OpenLibrary("intuition.library", 36L)))
  47.     { cleanup("no V36 intuition library\n"); }
  48.  
  49.     if (!(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 36L)))
  50.     { cleanup("no V36 graphics library\n"); }
  51.  
  52.     D( printf("about to openwindow\n") );
  53.     w = OpenWindowTags( NULL, 
  54.         WA_Title,    "frameimage Test Window",
  55.         WA_SimpleRefresh, TRUE,
  56.         WA_NoCareRefresh, TRUE,
  57.         WA_DepthGadget,    TRUE,
  58.         WA_DragBar,    TRUE,
  59.         WA_Left,    300,
  60.         WA_Top,        150,
  61.         WA_Width,    280,
  62.         WA_Height,    120,
  63.         WA_IDCMP,    myiflags,
  64.         WA_CloseGadget,    TRUE,
  65.             TAG_END );
  66.     D( printf("window at %lx\n ", w ) );
  67.  
  68.     if ( w == NULL) cleanup( "couldn't open my window.\n");
  69.     drinfo = GetScreenDrawInfo( w->WScreen );
  70.  
  71.     /* create a frame image which can be shared by contents
  72.      * of different sizes
  73.      */
  74.     Frame1Class = initFrame1Class();
  75.     frameimage =  (struct Image *) NewObject( Frame1Class, NULL, TAG_END );
  76.  
  77.     D( printf("init'd fram1class: %lx, image %lx\n", Frame1Class, frameimage ));
  78.  
  79.     /* fake up some contents for the frame    */
  80.     getContentsBox( &srcbox );
  81.  
  82.     /* get the dimensions of the enclosing frame, and the relative
  83.      * offset of the enclosing frame
  84.      */
  85.     DoMethod( frameimage, IM_FRAMEBOX, &srcbox, &framebox, drinfo, 0 );
  86.  
  87.     printf("contents box %d/%d/%d/%d\n",
  88.             srcbox.Left,
  89.             srcbox.Top,
  90.             srcbox.Width,
  91.             srcbox.Height );
  92.  
  93.     printf("frame box %d/%d/%d/%d\n",
  94.             framebox.Left,
  95.             framebox.Top,
  96.             framebox.Width,
  97.             framebox.Height );
  98.  
  99. #define XPOS    (40)
  100. #define YPOS    (20)
  101.  
  102.     /* now draw the frame and the properly centered context    */
  103.     DoMethod( frameimage, IM_DRAWFRAME, 
  104.                   w->RPort, 
  105.               (XPOS<<16)+YPOS,    /* packed position    */
  106.               IDS_NORMAL,        /* state        */
  107.               drinfo,
  108.               (framebox.Width << 16)+framebox.Height );
  109.  
  110.     /* note negative offset of contents, relative to frame    */
  111.     drawContents( w->RPort, XPOS-framebox.Left, YPOS-framebox.Top );
  112.  
  113.     goHandleWindow( w );
  114.  
  115.     FreeScreenDrawInfo( w->WScreen, drinfo );
  116.     CloseWindow( w );
  117.  
  118.     DisposeObject( frameimage );
  119.     freeFrame1Class( Frame1Class );
  120.  
  121.     D( printf("have disposed.\n") );
  122.     cleanup( "all done" );
  123. }
  124.  
  125. cleanup( str )
  126. char    *str;
  127. {
  128.     if (str) printf("%s\n", str);
  129.  
  130.     if (IntuitionBase) CloseLibrary(IntuitionBase);
  131.     if (GfxBase) CloseLibrary(GfxBase);
  132.     if (UtilityBase) CloseLibrary(UtilityBase);
  133.  
  134.     exit (0);
  135. }
  136.  
  137. goHandleWindow( w )
  138. struct Window    *w;
  139. {
  140.     struct IntuiMessage *imsg;
  141.     for(;;)
  142.     {
  143.     WaitPort( w->UserPort );
  144.     while ( imsg = (struct IntuiMessage *) GetMsg( w->UserPort ) )
  145.     {
  146.         switch ( imsg->Class )
  147.         {
  148.         case CLOSEWINDOW:
  149.             ReplyMsg( (struct Message *) imsg );
  150.         return;
  151.  
  152.         default:
  153.         D( printf("unknown message \n", imsg->Class));
  154.         break;
  155.         }
  156.         ReplyMsg( (struct Message *) imsg );
  157.     }
  158.     }
  159. }
  160.  
  161. struct IBox contentsbox = { 3,7,10,5 };
  162.  
  163. getContentsBox( box )
  164. struct IBox    *box;
  165. {
  166.     *box = contentsbox;
  167. }
  168.  
  169. drawContents( rp, xoffset, yoffset )
  170. struct RastPort    *rp;
  171. {
  172.     SetAPen( rp, 3 );
  173.     RectFill( rp,
  174.         xoffset + contentsbox.Left,
  175.     yoffset + contentsbox.Top,
  176.     xoffset + contentsbox.Left + contentsbox.Width -1,
  177.     yoffset + contentsbox.Top + contentsbox.Height -1 );
  178. }
  179.