home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / gnu / aplusplus-1.01-src.lha / GNU / src / amiga / APlusPlus-1.01 / libsource / Canvas.cxx < prev    next >
C/C++ Source or Header  |  1994-05-08  |  7KB  |  215 lines

  1. /******************************************************************************
  2.  **
  3.  **    C++ Class Library for the Amiga© system software.
  4.  **
  5.  **    Copyright (C) 1994 by Armin Vogt  **  EMail: armin@uni-paderborn.de
  6.  **    All Rights Reserved.
  7.  **
  8.  **    $Source: apphome:APlusPlus/RCS/libsource/Canvas.cxx,v $
  9.  **    $Revision: 1.4 $
  10.  **    $Date: 1994/05/08 13:40:16 $
  11.  **    $Author: Armin_Vogt $
  12.  **
  13.  ******************************************************************************/
  14.  
  15.  
  16. #include <APlusPlus/graphics/Canvas.h>
  17.  
  18.  
  19. volatile static char rcs_id[] = "$Id: Canvas.cxx,v 1.4 1994/05/08 13:40:16 Armin_Vogt Exp Armin_Vogt $";
  20.  
  21.  
  22. #define VISIBLE_X (iWidth()/iGranularityX)
  23. #define VISIBLE_Y (iHeight()/iGranularityY)
  24. #define SCROLLWIDTH (iWidth()-(scrollGratX()==TRUE?(iWidth()%granularityX()):0))
  25. #define SCROLLHEIGHT (iHeight()-(scrollGratY()==TRUE?(iHeight()%granularityY()):0))
  26.  
  27.  
  28. Canvas::Canvas(GOB_OWNER,AttrList& attrs) : AutoDrawArea(gob_owner,attrs)
  29.    /* Note that ViewX and ViewY values are only stored in the IntuiObject attributes.
  30.       The relation is: xy_offset = xy_view * xy_granularity.
  31.    */      
  32. {
  33.     if (Ok())
  34.     {
  35.    _dout("Canvas::create()\n");
  36.    xOffset = yOffset = 0;
  37.    
  38.    // read init values. If no were specified use default values.
  39.    widthG  = (UWORD)intuiAttrs().getTagData(CNV_Width,iWidth()); 
  40.    heightG = (UWORD)intuiAttrs().getTagData(CNV_Height,iHeight());
  41.    iGranularityX = (UWORD)intuiAttrs().getTagData(CNV_GranularityX,1);
  42.    iGranularityY = (UWORD)intuiAttrs().getTagData(CNV_GranularityY,1);         
  43.     iViewX = (UWORD)intuiAttrs().getTagData(CNV_ViewX);   if (iViewX >= widthG) iViewX = widthG;
  44.    iViewY = (UWORD)intuiAttrs().getTagData(CNV_ViewY);   if (iViewY >= heightG) iViewY = heightG;    
  45.     scrollGratingX = (UBYTE)intuiAttrs().getTagData(CNV_ScrollGratX,FALSE);
  46.     scrollGratingY = (UBYTE)intuiAttrs().getTagData(CNV_ScrollGratY,FALSE);
  47.     iVisibleX = 0;
  48.     iVisibleY = 0;
  49.             
  50.     setIOType(IOTYPE_CANVAS);                                
  51.     }                    
  52. }
  53.  
  54. Canvas::~Canvas()
  55. {
  56. }
  57.  
  58. APTR Canvas::redrawSelf(GWindow *home,ULONG& returnType)
  59.    /* Computes CNV_VisibleX/Y values and propagates 'redrawSelf' request to base classes.
  60.    */
  61. {
  62.     setAttrs( AttrList(CNV_VisibleX,iVisibleX=(UWORD)VISIBLE_X,
  63.                       CNV_VisibleY,iVisibleY=(UWORD)VISIBLE_Y, TAG_END));
  64.    return AutoDrawArea::redrawSelf(home,returnType);
  65. }   
  66.  
  67. ULONG Canvas::setAttributes(AttrList& attrs)
  68. {
  69.     if (notificationLoop()) return 0L;
  70.  
  71.    AttrManipulator next(attrs);
  72.    while (next())
  73.    {
  74.       LONG data = next.data();
  75.       switch (next.tag())
  76.       {
  77.          case CNV_ViewX : // gets data as amount of granularityX units
  78.                {  
  79.                   if (data != iViewX && data >= 0 && data < widthG)
  80.                   {                     
  81.                             adjustStdClip(); 
  82.                             setStdClip();
  83.                             UWORD deltaViewX = (UWORD)abs((data-(LONG)viewX()));
  84.                             UWORD org_iViewX = iViewX = (UWORD)data;
  85.                             LONG deltaPix = (data*=iGranularityX)-xOffset;
  86.                             xOffset = data;
  87.                      if (deltaViewX < visibleX())
  88.                      {
  89.                         scrollRaster(deltaPix,0,0,0,SCROLLWIDTH-1,SCROLLHEIGHT-1);  // scroll the view rectangle
  90.                         if (deltaPix > 0)        // scroll left, move right
  91.                                 {
  92.                            andRectRegion(iWidth()-deltaPix-1,0,iWidth()-1,iHeight()-1);
  93.                                     iViewX += visibleX()-deltaViewX;
  94.                                 }
  95.                         else
  96.                                 {
  97.                            andRectRegion(0,0,-deltaPix,iHeight()-1);                                    
  98.                                 }                                
  99.                      }
  100.                             else
  101.                             { 
  102.                                 deltaViewX = visibleX();
  103.                                 AutoDrawArea::clear();    // clear draw area
  104.                             }
  105.                             UWORD org_iVisibleX = iVisibleX;
  106.                             iVisibleX = deltaViewX;
  107.                             drawSelf();
  108.                             iViewX = org_iViewX;
  109.                             iVisibleX = org_iVisibleX;
  110.                             resetStdClip();
  111.                   } 
  112.                }
  113.                break;
  114.          
  115.          case CNV_ViewY :
  116.                {
  117.                   if (data != iViewY && data >= 0 && data < heightG)
  118.                   {                                          
  119.                      adjustStdClip();   
  120.                             setStdClip();
  121.                             UWORD deltaViewY = (UWORD)abs(data-(LONG)viewY());
  122.                             UWORD org_iViewY = iViewY = (UWORD)data;
  123.                      LONG deltaPix = (data*=iGranularityY)-yOffset;
  124.                      yOffset = data;
  125.                      if (deltaViewY < visibleY())
  126.                      {
  127.                         scrollRaster(0,deltaPix,0,0,SCROLLWIDTH-1,SCROLLHEIGHT-1);  // scroll the view rectangle
  128.                         if (deltaPix > 0)
  129.                                 {
  130.                            andRectRegion(0,iHeight()-deltaPix-1,iWidth()-1,iHeight()-1);
  131.                                     iViewY += visibleY()-deltaViewY;
  132.                                 }
  133.                         else
  134.                                 {
  135.                            andRectRegion(0,0,iWidth()-1,-deltaPix);
  136.                                 }
  137.                      }
  138.                             else
  139.                             { 
  140.                                 deltaViewY = visibleY();
  141.                                 AutoDrawArea::clear();    // clear draw area
  142.                             }
  143.                             UWORD org_iVisibleY = iVisibleY;
  144.                             iVisibleY = deltaViewY;
  145.                      drawSelf();
  146.                             iViewY = org_iViewY;
  147.                             iVisibleY = org_iVisibleY;
  148.                             resetStdClip();
  149.                   }  
  150.                } 
  151.                break;
  152.                
  153.          case CNV_Width  : 
  154.                next.writeData(widthG = (UWORD)((data > MAXPOT)?MAXPOT:data));
  155.                break;
  156.                
  157.          case CNV_Height : 
  158.                next.writeData(heightG = (UWORD)((data > MAXPOT)?MAXPOT:data));
  159.                break;
  160.                
  161.          case CNV_GranularityX :
  162.                if (data==0) data = 1;
  163.                iGranularityX = (UWORD)data;
  164.                break;
  165.                
  166.          case CNV_GranularityY :
  167.                if (data==0) data = 1;
  168.                iGranularityY = (UWORD)data;
  169.                break;
  170.                     
  171.             case CNV_ScrollGratX :
  172.                     scrollGratingX = (UBYTE)data;
  173.                     break;
  174.             
  175.             case CNV_ScrollGratY :
  176.                     scrollGratingY = (UBYTE)data;
  177.                     break;
  178.                               
  179.       }
  180.                                 
  181.       _dout("Canvas: y-offset="<<yOffset<<endl);
  182.    }     
  183.    return AutoDrawArea::setAttributes(attrs);    
  184. }        
  185.  
  186. ULONG Canvas::getAttribute(Tag tag,ULONG& dataStore)
  187. {    
  188.     switch (tag)
  189.     {
  190.         case CNV_ViewX : return (dataStore=iViewX);
  191.         case CNV_ViewY : return (dataStore=iViewY);
  192.         case CNV_VisibleX : return (dataStore=iVisibleX);
  193.         case CNV_VisibleY : return (dataStore=iVisibleY);
  194.         case CNV_Width : return (dataStore=widthG);
  195.         case CNV_Height : return (dataStore=heightG);
  196.         case CNV_GranularityX : return (dataStore=iGranularityX);
  197.         case CNV_GranularityY : return (dataStore=iGranularityY);
  198.         case CNV_ScrollGratX : return (dataStore=scrollGratingX);
  199.         case CNV_ScrollGratY : return (dataStore=scrollGratingY);
  200.         
  201.         default:
  202.             return AutoDrawArea::getAttribute(tag,dataStore);
  203.     }
  204. }
  205.  
  206. void Canvas::callback(const IntuiMessageC *imsg)
  207. {
  208.     AutoDrawArea::callback(imsg);
  209.     
  210.     LONG m = ((LONG)imsg->MouseX + xOffset)/iGranularityX;
  211.     iMouseX = (UWORD) (m<0?0:(m>=widthG?widthG-1:m));
  212.     m = ((LONG)imsg->MouseY + yOffset)/iGranularityY;
  213.     iMouseY = (UWORD) (m<0?0:(m>=heightG?heightG-1:m));
  214. }
  215.