home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / misc / vcb10a.lha / vcbtest.c < prev    next >
C/C++ Source or Header  |  1992-10-29  |  5KB  |  184 lines

  1. /*
  2.  *    COPYRIGHT
  3.  *        The material published in this distribution is Freeware.
  4.  *        Copyright ⌐ 1992 remains at the author, Stefan Reisner.
  5.  *        
  6.  *        It may only be passed on unmodified and in its present
  7.  *        composition. In particular, this copyright notice must be
  8.  *        included and must be intact.
  9.  */
  10. #include <intuition/gadgetclass.h>
  11. #include <intuition/imageclass.h>
  12. #include <intuition/intuition.h>
  13. #include <functions.h>
  14. #include <vcb/vcb.h>
  15.  
  16. struct Library *GfxBase, *IntuitionBase, *UtilityBase;
  17.  
  18. void exposure( struct Hook *hook, Object *object, struct ExposureMsg *xm )
  19. {
  20. #ifndef _LARGE_CODE_
  21.     geta4();
  22. #endif
  23.     if( xm->command == VCBCMD_RENDER )
  24.     {
  25.         int xu, yu, x0, y0,
  26.             left, top,
  27.             xmin, ymin, xmax, ymax;
  28.  
  29.         GetAttr( VCBGA_HUnit, object, (ULONG *)&xu );
  30.         GetAttr( VCBGA_VUnit, object, (ULONG *)&yu );
  31.         GetAttr( VCBGA_XOrigin, object, (ULONG *)&x0 );
  32.         GetAttr( VCBGA_YOrigin, object, (ULONG *)&y0 );
  33.         GetAttr( VCBGA_HOffset, object, (ULONG *)&left );
  34.         GetAttr( VCBGA_VOffset, object, (ULONG *)&top );
  35.  
  36.         xmin = x0 + xm->left * xu;
  37.         ymin = y0 + xm->top * yu;
  38.         xmax = x0 + ( xm->left + xm->width ) * xu - 1;
  39.         ymax = y0 + ( xm->top + xm->height ) * yu - 1;
  40.  
  41.         SetAPen( xm->rp, 1 );
  42.         SetDrMd( xm->rp, JAM1 );
  43.  
  44.         Move( xm->rp, xmin, ymin );
  45.         Draw( xm->rp, xmax, ymax );
  46.         Move( xm->rp, xmin, ymax );
  47.         Draw( xm->rp, xmax, ymin );
  48.     }
  49. }
  50.  
  51. void test( Object *object, struct Window *window )
  52. {
  53.     SetGadgetAttrs( (struct Gadget *)object, window, NULL,
  54.         VCBGA_HOffset, 2, TAG_DONE );
  55.     WaitPort( window->UserPort );
  56.     ReplyMsg( GetMsg( window->UserPort ) );
  57.  
  58.     printf( "setting totals to 3\n" );
  59.     SetGadgetAttrs( (struct Gadget *)object, window, NULL,
  60.         VCBGA_HTotal, 3,
  61.         VCBGA_VTotal, 3,
  62.         TAG_DONE );
  63.     WaitPort( window->UserPort );
  64.     ReplyMsg( GetMsg( window->UserPort ) );
  65.  
  66.     printf( "setting totals to 10\n" );
  67.     SetGadgetAttrs( (struct Gadget *)object, window, NULL,
  68.         VCBGA_HTotal, 10,
  69.         VCBGA_VTotal, 10,
  70.         TAG_DONE );
  71.     WaitPort( window->UserPort );
  72.     ReplyMsg( GetMsg( window->UserPort ) );
  73.  
  74.     printf( "setting totals to 20\n" );
  75.     SetGadgetAttrs( (struct Gadget *)object, window, NULL,
  76.         VCBGA_HTotal, 20,
  77.         VCBGA_VTotal, 20,
  78.         TAG_DONE );
  79.     WaitPort( window->UserPort );
  80.     ReplyMsg( GetMsg( window->UserPort ) );
  81.  
  82.     printf( "setting totals to 30\n" );
  83.     SetGadgetAttrs( (struct Gadget *)object, window, NULL,
  84.         VCBGA_HTotal, 30,
  85.         VCBGA_VTotal, 30,
  86.         TAG_DONE );
  87.     WaitPort( window->UserPort );
  88.     ReplyMsg( GetMsg( window->UserPort ) );
  89. }
  90.  
  91. void main( void )
  92. {
  93.     Class *class;
  94.     struct Hook xh;
  95.     Object *object;
  96.     struct Gadget *glist = NULL, *gadget;
  97.     struct Screen *screen;
  98.     struct DrawInfo *drawinfo;
  99.     APTR vi = NULL;
  100.     struct Window *window;
  101.     struct SignalSemaphore *ss;
  102.  
  103.     if( GfxBase = OpenLibrary( "graphics.library", 0 ) )
  104.     {
  105.         if( IntuitionBase = OpenLibrary( "intuition.library", 0 ) )
  106.         {
  107.             if( UtilityBase = OpenLibrary( "utility.library", 0 ) )
  108.             {
  109.                 if( screen = LockPubScreen( NULL ) )
  110.                 {
  111.                     if( drawinfo = GetScreenDrawInfo( screen ) )
  112.                     {
  113.                         if( class = initVCBClass() )
  114.                         {
  115.                             SetupHook( &xh, exposure, NULL );
  116.                             if( object = NewObject( class, NULL,
  117.                                 VCBGA_ExposureHook, &xh,
  118.                                 GA_Left, screen->WBorLeft,
  119.                                 GA_Top, screen->WBorTop + screen->Font->ta_YSize + 1,
  120.                                 GA_RelWidth, - screen->WBorLeft + 1,
  121.                                 GA_RelHeight, - screen->WBorTop - screen->Font->ta_YSize,
  122.                                 GA_Previous, (ULONG)&glist,
  123.                                 VCBGA_HScroller, 1,
  124.                                 VCBGA_HBorder, 1,
  125.                                 VCBGA_HTotal, 10,
  126.                                 VCBGA_HOffset, 3,
  127.                                 VCBGA_HUnit, 10,
  128.                                 VCBGA_VScroller, 1,
  129.                                 VCBGA_VTotal, 10,
  130.                                 VCBGA_VOffset, 4,
  131.                                 VCBGA_VUnit, 10,
  132.                                 VCBGA_Interim, 1,
  133.                                 SYSIA_DrawInfo, (ULONG)drawinfo,
  134.                                 TAG_DONE ) )
  135.                             {
  136.                                 printf( "glist = %08lx\n", glist );
  137.                                 if( window = OpenWindowTags( NULL,
  138.                                     WA_NoCareRefresh, 1,
  139.                                     WA_Gadgets, glist,
  140.                                     WA_Height, 250,
  141.                                     WA_MinWidth, 100,
  142.                                     WA_MinHeight, 100,
  143.                                     WA_CloseGadget, 1,
  144.                                     WA_SizeGadget, 1,
  145.                                     WA_DepthGadget, 1,
  146.                                     WA_DragBar, 1,
  147.                                     WA_IDCMP, IDCMP_CLOSEWINDOW,
  148.                                     TAG_DONE ) )
  149.                                 {
  150.                                     WaitPort( window->UserPort );
  151.                                     ReplyMsg( GetMsg( window->UserPort ) );
  152.                                     test( object, window );
  153.  
  154.                                     GetAttr( VCBGA_Semaphore, object, (ULONG *)&ss );
  155.                                     printf( "trying to obtain semaphore %08lx...\n", ss );
  156.                                     ObtainSemaphore( ss );
  157.                                     printf( "display to the virtual coordinate box is now locked\n" );
  158.                                     WaitPort( window->UserPort );
  159.                                     ReplyMsg( GetMsg( window->UserPort ) );
  160.  
  161.                                     ReleaseSemaphore( ss );
  162.                                     printf( "display to the virtual coordinate box is now free\n" );
  163.                                     RefreshGList( glist, window, NULL, 1 );
  164.                                     WaitPort( window->UserPort );
  165.                                     ReplyMsg( GetMsg( window->UserPort ) );
  166.  
  167.                                     CloseWindow( window );
  168.                                 }
  169.                                 DisposeObject( object );
  170.                             }
  171.                             freeVCBClass( class );
  172.                         }
  173.                         FreeScreenDrawInfo( screen, drawinfo );
  174.                     }
  175.                     UnlockPubScreen( NULL, screen );
  176.                 }
  177.                 CloseLibrary( UtilityBase );
  178.             }
  179.             CloseLibrary( IntuitionBase );
  180.         }
  181.         CloseLibrary( GfxBase );
  182.     }
  183. }
  184.