home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / fish / code_examples / cmanual_456 / acm1.lzh / Graphics / Example2.c < prev    next >
C/C++ Source or Header  |  1990-01-30  |  5KB  |  145 lines

  1. /* Example2                                                          */
  2. /* This program will open a normal window which is connected to the  */
  3. /* Workbench Screen. We will then draw two rectangles with different */
  4. /* colours. This shows how you can link Border structures to each    */
  5. /* other in order to get the desired effects.                        */
  6.  
  7.  
  8.  
  9. /* If your program is using Intuition you should include intuition.h: */
  10. #include <intuition/intuition.h>
  11.  
  12.  
  13.  
  14. struct IntuitionBase *IntuitionBase;
  15.  
  16.  
  17.  
  18. /* Declare a pointer to a Window structure: */ 
  19. struct Window *my_window;
  20.  
  21. /* Declare and initialize your NewWindow structure: */
  22. struct NewWindow my_new_window=
  23. {
  24.   40,            /* LeftEdge    x position of the window. */
  25.   20,            /* TopEdge     y positio of the window. */
  26.   250,           /* Width       250 pixels wide. */
  27.   150,           /* Height      150 lines high. */
  28.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  29.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  30.   NULL,          /* IDCMPFlags  No IDCMP flags. */
  31.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  32.   WINDOWDRAG|    /*             Drag gadget. */
  33.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  34.   ACTIVATE,      /*             The window should be Active when opened. */
  35.   NULL,          /* FirstGadget No Custom Gadgets. */
  36.   NULL,          /* CheckMark   Use Intuition's default CheckMark (v). */
  37.   "RECTANGLES",  /* Title       Title of the window. */
  38.   NULL,          /* Screen      Connected to the Workbench Screen. */
  39.   NULL,          /* BitMap      No Custom BitMap. */
  40.   0,             /* MinWidth    We do not need to care about these */
  41.   0,             /* MinHeight   since we have not supplied the window */
  42.   0,             /* MaxWidth    with a Sizing Gadget. */
  43.   0,             /* MaxHeight */
  44.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  45. };
  46.  
  47.  
  48.  
  49. /* The coordinates for the small rectangle: */
  50. SHORT small_points[]=
  51. {
  52.    0,  0, /* Start at position (0,0) */
  53.   80,  0, /* Draw a line to the right to position (80,0) */
  54.   80, 40, /* Draw a line down to position (80,40) */
  55.    0, 40, /* Draw a line to the left to position (0,40) */
  56.    0,  0  /* Finish of by drawing a line up to position (0,0) */ 
  57. };
  58.  
  59. /* The coordinates for the big rectangle: */
  60. SHORT big_points[]=
  61. {
  62.     0,  0, /* Start at position (0,0) */
  63.   100,  0, /* Draw a line to the right to position (100,0) */
  64.   100, 50, /* Draw a line down to position (100,50) */
  65.     0, 50, /* Draw a line to the left to position (0,50) */
  66.     0,  0  /* Finish of by drawing a line up to position (0,0) */ 
  67. };
  68.  
  69.  
  70.  
  71. /* The small Border structure: */
  72. struct Border small_rectangle=
  73. {
  74.   10, 5,        /* LeftEdge, TopEdge. */
  75.   3,            /* FrontPen, colour register 3. */
  76.   0,            /* BackPen, for the moment unused. */
  77.   JAM1,         /* DrawMode, draw the lines with colour 3. */
  78.   5,            /* Count, 5 pair of coordinates in the array. */
  79.   small_points, /* XY, pointer to the array with the coordinates. */
  80.   NULL          /* NextBorder, no other Border structures are connected. */
  81. };
  82.  
  83.  
  84.  
  85. /* The BIG Border structure: */
  86. struct Border big_rectangle=
  87. {
  88.   0, 0,             /* LeftEdge, TopEdge. */
  89.   1,                /* FrontPen, colour register 1. */
  90.   0,                /* BackPen, for the moment unused. */
  91.   JAM1,             /* DrawMode, draw the lines with colour 1. */
  92.   5,                /* Count, 5 pair of coordinates in the array. */
  93.   big_points,       /* XY, pointer to the array with the coordinates. */
  94.   &small_rectangle  /* NextBorder, pointing to the small_rectangle. */
  95. };
  96.  
  97.  
  98.  
  99. main()
  100. {
  101.   /* Open the Intuition Library: */
  102.   IntuitionBase = (struct IntuitionBase *)
  103.     OpenLibrary( "intuition.library", 0 );
  104.   
  105.   if( IntuitionBase == NULL )
  106.     exit(); /* Could NOT open the Intuition Library! */
  107.  
  108.  
  109.  
  110.   /* We will now try to open the window: */
  111.   my_window = (struct Window *) OpenWindow( &my_new_window );
  112.   
  113.   /* Have we opened the window succesfully? */
  114.   if(my_window == NULL)
  115.   {
  116.     /* Could NOT open the Window! */
  117.     
  118.     /* Close the Intuition Library since we have opened it: */
  119.     CloseLibrary( IntuitionBase );
  120.  
  121.     exit();  
  122.   }
  123.  
  124.  
  125.  
  126.   /* Tell Intuition to draw the rectangles: */
  127.   DrawBorder( my_window->RPort, &big_rectangle, 10, 15 );
  128.  
  129.  
  130.  
  131.   /* Wait for 30 seconds: */
  132.   Delay( 50 * 30);
  133.  
  134.  
  135.  
  136.   /* We should always close the windows we have opened before we leave: */
  137.   CloseWindow( my_window );
  138.  
  139.  
  140.   
  141.   /* Close the Intuition Library since we have opened it: */
  142.   CloseLibrary( IntuitionBase );
  143.   
  144.   /* THE END */
  145. }