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 / demopubi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-26  |  3.6 KB  |  155 lines

  1. /* demopubi.c -- demonstration of         :ts=8
  2.  * public image class.
  3.  */
  4.  
  5. /*
  6. Copyright (c) 1989, 1990 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)    ;
  18.  
  19. struct  IntuitionBase   *IntuitionBase;
  20. struct  GfxBase         *GfxBase;
  21. struct  Library         *UtilityBase;
  22.  
  23. /* class pointer is an abstract handle, which
  24.  * one never uses for "public" access to a class,
  25.  * but we as class owner can use for private access,
  26.  * or to free the class.
  27.  */
  28. void    *initEmbBClass();
  29. void    *EmbBClass;
  30.  
  31. Object    *NewObject();
  32.  
  33. ULONG    myiflags = CLOSEWINDOW;
  34.  
  35. struct Image    *myimage;
  36.  
  37. main()
  38. {
  39.     struct DrawInfo    *GetScreenDrawInfo();
  40.     struct Window     *OpenWindowTags();    /* in varargs.c for now */
  41.     struct Window    *w;
  42.     struct DrawInfo    *drinfo;
  43.  
  44.     openAll();    /* get libraries open    */
  45.  
  46.     D( printf("about to openwindow\n") );
  47.     w = OpenWindowTags( NULL, 
  48.         WA_Title,    "Public Image Test Window",
  49.         WA_SimpleRefresh, TRUE,
  50.         WA_NoCareRefresh, TRUE,
  51.         WA_DepthGadget,    TRUE,
  52.         WA_DragBar,    TRUE,
  53.         WA_Left,    300,
  54.         WA_Top,        50,
  55.         WA_Width,    280,
  56.         WA_Height,    120,
  57.         WA_IDCMP,    myiflags,
  58.         WA_CloseGadget,    TRUE,
  59.             TAG_END );
  60.     D( printf("window at %lx\n ", w ) );
  61.     if ( w == NULL) cleanup( "couldn't open my window.\n");
  62.  
  63.     drinfo = GetScreenDrawInfo( w->WScreen );
  64.  
  65.     /* init the public class    */
  66.     EmbBClass = initEmbBClass();
  67.  
  68.     /* create an image from my public class    */
  69.     myimage =  (struct Image *) NewObject(  NULL,  "emboxclass",
  70.             IA_WIDTH, 20,
  71.             IA_HEIGHT, 10,
  72.                 TAG_END );
  73.  
  74. #define XPOS    (40)
  75. #define YPOS    (20)
  76. #define XPOS2    (XPOS + 30)
  77.  
  78.     /* draw the image    */
  79.     DrawImageState( w->RPort, myimage, XPOS, YPOS, IDS_NORMAL, drinfo );
  80.  
  81.     /* draw the image    */
  82.     DrawImageState( w->RPort, myimage, XPOS2, YPOS, IDS_SELECTED, drinfo );
  83.  
  84.     /* go away and be done    */
  85.     goHandleWindow( w );
  86.  
  87.     FreeScreenDrawInfo( w->WScreen, drinfo );
  88.     CloseWindow( w );
  89.  
  90.     DisposeObject( myimage );
  91.     D( printf("have disposed.\n") );
  92.  
  93.     /* get rid of the public class.
  94.      * Don't really exit unless the class can be free'd,
  95.      * since that would mean that somebody might want to use
  96.      * your class's implementation routines after you're gone.
  97.      */
  98.     if ( ! freeEmbBClass( EmbBClass ) )
  99.     {
  100.     cleanup( "PANIC: exiting with class not free'd!\n" );
  101.     }
  102.  
  103.     cleanup( "all done" );
  104. }
  105.  
  106. cleanup( str )
  107. char    *str;
  108. {
  109.     if (str) printf("%s\n", str);
  110.  
  111.     if (IntuitionBase) CloseLibrary(IntuitionBase);
  112.     if (GfxBase) CloseLibrary(GfxBase);
  113.     if (UtilityBase) CloseLibrary(UtilityBase);
  114.  
  115.     exit (0);
  116. }
  117.  
  118. /* exits via cleanup() if failure    */
  119. openAll()
  120. {
  121.     if (!(UtilityBase=(struct Library *)OpenLibrary("utility.library",36L)))
  122.     { cleanup("no V36 utility library\n"); }
  123.  
  124.     if (!(IntuitionBase = 
  125.     (struct IntuitionBase *) OpenLibrary("intuition.library", 36L)))
  126.     { cleanup("no V36 intuition library\n"); }
  127.  
  128.     if (!(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 36L)))
  129.     { cleanup("no V36 graphics library\n"); }
  130. }
  131.  
  132. goHandleWindow( w )
  133. struct Window    *w;
  134. {
  135.     struct IntuiMessage *imsg;
  136.     for(;;)
  137.     {
  138.     WaitPort( w->UserPort );
  139.     while ( imsg = (struct IntuiMessage *) GetMsg( w->UserPort ) )
  140.     {
  141.         switch ( imsg->Class )
  142.         {
  143.         case CLOSEWINDOW:
  144.             ReplyMsg( (struct Message *) imsg );
  145.         return;
  146.  
  147.         default:
  148.         D( printf("unknown message \n", imsg->Class));
  149.         break;
  150.         }
  151.         ReplyMsg( (struct Message *) imsg );
  152.     }
  153.     }
  154. }
  155.