home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / misc / vcb.lha / vcb / test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-15  |  4.8 KB  |  175 lines

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