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 / demoimage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-27  |  3.5 KB  |  151 lines

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