home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / gnu / aplusplus-1.01-src.lha / src / amiga / aplusplus-1.01 / include / aplusplus / graphics / Canvas.h < prev    next >
C/C++ Source or Header  |  1994-05-04  |  6KB  |  134 lines

  1. #ifndef APP_Canvas_H
  2. /******************************************************************************
  3.  **
  4.  **    C++ Class Library for the Amiga© system software.
  5.  **
  6.  **    Copyright (C) 1994 by Armin Vogt  **  EMail: armin@uni-paderborn.de
  7.  **    All Rights Reserved.
  8.  **
  9.  **    $VER: apphome:APlusPlus/graphics/Canvas.h 1.04 (04.05.94) $
  10.  **    
  11.  ******************************************************************************/
  12.  
  13. #include <APlusPlus/graphics/AutoDrawArea.h>
  14.  
  15.  
  16. /******************************************************************************************
  17.       » Canvas class «  virtual base class
  18.        
  19.    The Canvas class expands the AutoDrawArea class to a virtual draw space that can easily 
  20.    be bigger than the dimensions of the AutoDrawArea. The AutoDrawArea acts as a view hole
  21.    through which only a portion of the whole draw space is visible. This view can be moved
  22.    over the draw space.
  23.    All drawing goes into the virtual draw space and is clipped properly.
  24.     The canvas is divided into GranularityX/Y units counting from 0 to CNV_Width/Height-1.
  25.     
  26.  ******************************************************************************************/
  27. class Canvas : public AutoDrawArea
  28. {
  29.    private:
  30.       XYVAL xOffset,yOffset;        // coords of the upper left corner of the visible canvas.
  31.         UWORD heightG,widthG;        // width,height of the canvas in GranularityX/Y units
  32.       UWORD iGranularityX,iGranularityY;  // multiply CNV_ViewX/Y value with granularity to get offset
  33.         UWORD iViewX,iViewY;            // internal storage for CNV_ViewX/Y
  34.         UWORD iVisibleX,iVisibleY;    // view dimensions in Granularity units
  35.         UWORD iMouseX,iMouseY;            // mouse position on the virtual canvas
  36.         UBYTE scrollGratingX,scrollGratingY;
  37.         
  38.    protected:   
  39.       APTR redrawSelf(GWindow *home,ULONG& returnType);   // inherited from GraphicObject
  40.  
  41.       XYVAL cx2ax(XYVAL x) { return x-xOffset; }   // convert canvas x coords to DrawArea x coords.
  42.       XYVAL cy2ay(XYVAL y) { return y-yOffset; }   // convert canvas y coords to DrawArea y coords.
  43.  
  44.         UWORD granularityX() { return iGranularityX; }    // pixel per Granularity unit
  45.         UWORD granularityY() { return iGranularityY; }
  46.         UWORD viewX() { return iViewX; }        // offset of the view in Granularity units (0-..)
  47.         UWORD viewY() { return iViewY; }        
  48.         UWORD visibleX() { return iVisibleX; }        // view extension in Granularity units
  49.         UWORD visibleY() { return iVisibleY; }
  50.         UWORD mouseX()    { return iMouseX; }            // mouse position on the canvas in Granularity units
  51.         UWORD mouseY() { return iMouseY; }
  52.  
  53.         BOOL scrollGratX() { return scrollGratingX; }
  54.         BOOL scrollGratY() { return scrollGratingY; }
  55.     
  56.    public:
  57.       Canvas(GOB_OWNER,AttrList& attrs);
  58.       ~Canvas();
  59.       
  60.         void callback(const IntuiMessageC *imsg);
  61.         /** overwrite with your own IDCMP event handler.
  62.          ** Call Canvas::calback(msg) somewhere in your callback method.
  63.          **/
  64.          
  65.       virtual void drawSelf()=0;
  66.         /** overwrite here to make your own drawing
  67.        ** The area which has to be redrawn is described by the view/visibleXY() values and should
  68.          ** be regarded for efficiency reason. Although it is allowed to draw anywhere within the 
  69.          ** canvas since all drawing is clipped.
  70.          **/
  71.          
  72.       ULONG setAttributes(AttrList& attrs);         // inherited from IntuiObject
  73.         ULONG getAttribute(Tag tag,ULONG& dataStore);
  74.         
  75.       /** draw routines according to the graphics library; coords become relative to the
  76.        ** Canvas draw space upper, left edge.
  77.        **/
  78.       void draw(XYVAL x,XYVAL y) { AutoDrawArea::draw(cx2ax(x),cy2ay(y)); }
  79.       void drawEllipse(XYVAL x,XYVAL y,WHVAL hr,WHVAL vr)
  80.       { AutoDrawArea::drawEllipse(cx2ax(x),cy2ay(y),hr,vr); }
  81.  
  82.       void move(XYVAL x,XYVAL y) { AutoDrawArea::move(cx2ax(x),cy2ay(y)); }
  83.         void moveTx(XYVAL x,XYVAL y) { AutoDrawArea::moveTx(cx2ax(x),cy2ay(y)); }
  84.  
  85.       void rectFill(XYVAL xmin,XYVAL ymin,XYVAL xmax,XYVAL ymax)
  86.       { AutoDrawArea::rectFill(cx2ax(xmin),cy2ay(ymin),cx2ax(xmax),cy2ay(ymax)); }
  87.  
  88. };
  89.  
  90. #define CNV_Dummy    (TAG_USER| (IOTYPE_CANVAS + 1))
  91.  
  92. #define CNV_ViewX    (CNV_Dummy + 1)
  93.    /* (UWORD). Set the canvas pixel position of the left edge of the view in GranularityX steps.
  94.       The minimum value is 0. The maximum value is the width of the draw space -1.
  95.    */
  96.    
  97. #define CNV_ViewY    (CNV_Dummy + 2)
  98.    /* (UWORD). Set the canvas pixel position of the top edge of the view in GranularityY steps.
  99.       The minimum value is 0. The maximum value is the height of the draw space -1.
  100.    */
  101.  
  102. #define CNV_GranularityX        (CNV_Dummy + 3)
  103.    /* (UWORD). Specify granularity of the ViewX value. Default is 1 pixel.
  104.    */
  105.    
  106. #define CNV_GranularityY        (CNV_Dummy + 4)
  107.    /* (UWORD). Specify granularity of the ViewY value. Default is 1 pixel.
  108.    */
  109.  
  110. #define CNV_Width    (CNV_Dummy + 5)
  111.     /* (UWORD). Specify the width of the canvas in GranularityX units.
  112.     */
  113.     
  114. #define CNV_Height   (CNV_Dummy + 6)  
  115.     /* (UWORD). Specify the height of the canvas in GranularityY units.
  116.     */
  117.  
  118. #define CNV_VisibleX        (CNV_Dummy + 7)
  119. #define CNV_VisibleY     (CNV_Dummy + 8)
  120.     /* (UWORD). The CNV_Visible tags are READ ONLY. They represent the dimension of the 
  121.         canvas view in CNV_GranularityX/Y units. They can directly be transposed to get 
  122.         PGA_Visible tag data for a connected Proportional gadget or Slider.
  123.     */
  124.  
  125. #define CNV_ScrollGratX        (CNV_Dummy + 9)
  126. #define CNV_ScrollGratY     (CNV_Dummy + 10)
  127.     /* (BOOL). The view can be scrolled in multiples of CNV_Granularity values only.
  128.         This tag defines wether the right/bottom border that is left over when dividing 
  129.         the view    into granularity units shall be included when scrolling (FALSE) or 
  130.         excluded (TRUE). The default is FALSE.
  131.     */
  132.  
  133. #endif   /* Canvas.h */
  134.