home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Extras / Development / Example_Code_v37 / Libraries / Intuition / boopsi / demoframe.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-27  |  4.1 KB  |  176 lines

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