home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377a.lha / libraries / graphics / primitives / BoxFill.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-02-04  |  3.7 KB  |  120 lines

  1. /* BoxFill
  2.    Three methods of rendering a filled rectangle.
  3.    Insert this routine into the "wrapper" code at the end of the TEXT chapter.
  4.  
  5.    Copyright (c) 1990 Commodore-Amiga, Inc.
  6.   
  7.    This example is provided in electronic form by Commodore-Amiga, Inc. for
  8.    use with the 1.3 revisions of the Addison-Wesley Amiga reference manuals. 
  9.    The 1.3 Addison-Wesley Amiga Reference Manual series contains additional
  10.    information on the correct usage of the techniques and operating system
  11.    functions presented in this example.  The source and executable code of
  12.    this example may only be distributed in free electronic form, via bulletin
  13.    board or as part of a fully non-commercial and freely redistributable
  14.    diskette.  Both the source and executable code (including comments) must
  15.    be included, without modification, in any copy.  This example may not be
  16.    published in printed form or distributed with any commercial product.
  17.    However, the programming techniques and support routines set forth in
  18.    this example may be used in the development of original executable
  19.    software products for Commodore Amiga computers.
  20.    All other rights reserved.
  21.    This example is provided "as-is" and is subject to change; no warranties
  22.    are made.  All use is at your own risk.  No liability or responsibility
  23.    is assumed.
  24. */
  25.  
  26. #include <graphics/gfxmacros.h>
  27.  
  28. #define AREA_SIZE 200
  29.  
  30. #define COLOR0 0
  31. #define COLOR1 1
  32. #define COLOR3 3
  33.  
  34. BOOL example(struct Window *window)
  35. {
  36. register USHORT i;
  37. SHORT xLow, xHigh, yLow, yHigh;
  38. WORD areabuffer[AREA_SIZE];
  39. UWORD height, width;
  40. PLANEPTR planePtr = NULL;
  41. struct RastPort *rastPort = window->RPort;
  42. struct TmpRas tmpRas;
  43. struct AreaInfo areaInfo;
  44.  
  45. xLow = window->BorderLeft;
  46. xHigh = window->GZZWidth - window->BorderRight;
  47. yLow = window->BorderTop;
  48. yHigh = window->GZZHeight - window->BorderBottom;
  49.  
  50. height = GfxBase->NormalDisplayRows;
  51. width  = GfxBase->NormalDisplayColumns;
  52.  
  53. /*  The AreaInfo structure is needed only by the Area...() calls.  */
  54. planePtr = AllocRaster(width, height);
  55. if (planePtr)
  56.     {
  57.     for (i=0; i<AREA_SIZE; i++)
  58.         areabuffer[i] = 0;
  59.  
  60.     InitArea(&areaInfo, areabuffer, (AREA_SIZE*2)/5);
  61.     rastPort->AreaInfo = &areaInfo;
  62.  
  63.     InitTmpRas(&tmpRas, planePtr, RASSIZE(width, height));
  64.     rastPort->TmpRas = &tmpRas;
  65.  
  66.     SetRast(rastPort, COLOR0);
  67.  
  68.     /* Area-fill a rectangular area. */
  69.     TITLE(window, "AreaMove(), AreaDraw(), AreaEnd()");
  70.     Delay(2L * TICKS_PER_SECOND);
  71.     SetAPen(rastPort, COLOR1);
  72.     SetOPen(rastPort, COLOR3);
  73.     AreaMove(rastPort, xLow, yLow);
  74.     AreaDraw(rastPort, xLow, yHigh);
  75.     AreaDraw(rastPort, xHigh, yHigh);
  76.     AreaDraw(rastPort, xHigh, yLow);
  77.     /*  AreaEnd() will complete the rectangle automatically.  */
  78.     AreaEnd(rastPort);
  79.  
  80.  
  81.     Delay(5L * TICKS_PER_SECOND);
  82.     SetRast(rastPort, COLOR0);
  83.  
  84.  
  85.     /* Flood-fill a rectangular area. */
  86.     TITLE(window, "Move(), Draw(), Flood()");
  87.     Delay(2L * TICKS_PER_SECOND);
  88.     SetAPen(rastPort, COLOR3);
  89.     BNDRYOFF(rastPort);
  90.     Move(rastPort, xLow, yLow);
  91.     Draw(rastPort, xLow, yHigh);
  92.     Draw(rastPort, xHigh, yHigh);
  93.     Draw(rastPort, xHigh, yLow);
  94.     /*  Must complete the rectangle or flood will leak.  */
  95.     Draw(rastPort, xLow, yLow);
  96.     SetAPen(rastPort, COLOR1);
  97.     /*  Start Flood() in the middle of the rectangle,
  98.         and replace all pixels of the same color as x,y).
  99.     */
  100.     Flood(rastPort, 1L, (xHigh-xLow)/2, (yHigh-yLow)/2);
  101.  
  102.  
  103.     Delay(5L * TICKS_PER_SECOND);
  104.     SetRast(rastPort, COLOR0);
  105.  
  106.  
  107.     /* Rectangle-fill a rectangular area. */
  108.     TITLE(window, "RectFill()");
  109.     Delay(2L * TICKS_PER_SECOND);
  110.     SetAPen(rastPort, COLOR1);
  111.     SetOPen(rastPort, COLOR3);
  112.     RectFill(rastPort, xLow, yLow, xHigh, yHigh);
  113.  
  114.     FreeRaster(planePtr, width, height);
  115.     }
  116.  
  117.     return(WAIT_FOR_CLOSE);
  118. }
  119.  
  120.