home *** CD-ROM | disk | FTP | other *** search
/ Dream 57 / Amiga_Dream_57.iso / Amiga / Programmation / c / Extensions / APPSource.lha / APlusPlus / libsource / GraphicObject.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-29  |  4.9 KB  |  158 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:RCS/libsource/GraphicObject.cxx,v $
  9.  **   $Revision: 1.13 $
  10.  **   $Date: 1994/08/02 17:49:25 $
  11.  **   $Author: Armin_Vogt $
  12.  **
  13.  ******************************************************************************/
  14.  
  15. #include <APlusPlus/intuition/Intui_TypeInfo.h>
  16. #include <APlusPlus/graphics/GraphicObject.h>
  17. #include <APlusPlus/graphics/GBorder.h>
  18. #include <APlusPlus/intuition/GadgetCV.h>
  19.  
  20.  
  21. static const char rcs_id[] = "$Id: GraphicObject.cxx,v 1.13 1994/08/02 17:49:25 Armin_Vogt Exp Armin_Vogt $";
  22.  
  23.  
  24. //runtime type inquiry support
  25. intui_typeinfo(GraphicObject, derived(from(IntuiObject)), rcs_id)
  26.  
  27.  
  28. GraphicObject::GraphicObject(GraphicObject* owner,AttrList& attrs)
  29.    : IntuiObject(owner,attrs)
  30. {
  31.    if (Ok())
  32.    {
  33.       setIOType(GRAPHICOBJECT);
  34.       GBorder* gbObj = (GBorder*)intuiAttrs().getTagData(GOB_Border);
  35.       if (gbObj) gbObj->makeBorder(this);    // fill in border dimensions
  36.  
  37.       setRectWH(0,0, // upper left corner will be set by adjustChilds()
  38.          intuiAttrs().getTagData(GOB_Width,0),
  39.          intuiAttrs().getTagData(GOB_Height,0) );
  40.    }
  41. }
  42.  
  43. GraphicObject::~GraphicObject()
  44. {
  45.  
  46. }
  47.  
  48.  
  49. ULONG GraphicObject::setAttributes(AttrList& attrs)
  50.    /* only propagates the update attrs to the base class.
  51.    */
  52. {
  53.    GBorder* gbObj = (GBorder*)attrs.getTagData(GOB_Border);
  54.    if (gbObj) gbObj->makeBorder(this);
  55.  
  56.    return IntuiObject::setAttributes(attrs);
  57. }
  58.  
  59. ULONG GraphicObject::getAttribute(Tag tag,ULONG& dataStore)
  60. {
  61.    return IntuiObject::getAttribute(tag,dataStore);
  62. }
  63.  
  64. APTR GraphicObject::redrawSelf(GWindow* homeWindow,ULONG& returnType)
  65. {
  66.    GBorder* gbObj = (GBorder*)intuiAttrs().getTagData(GOB_Border);
  67.    if (gbObj) gbObj->drawBorder(this,homeWindow);
  68.  
  69.    returnType = 0L;
  70.    return NULL;
  71. }
  72.  
  73. void GraphicObject::adjustChilds()
  74.    /* Adjust graphical dimensions of the GraphicObject childs of 'this' GraphicObject
  75.       according to the GOB_ tags defined in GraphicObject.h, depending on the dimensions
  76.       of 'this'. The adjustment of each child will cause adjustments of all its GraphicObject
  77.       childs down the IntuiObject tree.
  78.       'adjustChilds' needs to be invoked on every window since each invokation only
  79.       regards non-window childs.
  80.    */
  81. {
  82.    GraphicObject* pred = NULL;
  83.  
  84.    FOREACHOF(GraphicObject,this)
  85.    {
  86.    if (ptr_cast(GadgetCV,node))  
  87.    {   
  88.       
  89.       WHVAL oldWidth=node->width(),oldHeight=node->height();   // preserve the former width/height
  90.  
  91.       AttrIterator next(node->intuiAttrs());
  92.       XYVAL minx=0,miny=0,maxx=0,maxy=0;
  93.       while (next())
  94.       {
  95.          LONG data = (LONG)next.data();
  96.          ULONG tagID = next.tag() - GOB_Spec_Dummy;
  97.  
  98.          if (tagID < 16)
  99.          {
  100.             GraphicObject* relative = tagID&gob_relative ? (pred==NULL?this:pred) : this;
  101.  
  102.             _dprintf("relative has (%ld,%ld,%ld,%ld)\n",relative->iLeft(),relative->iTop(),relative->iRight(),relative->iBottom());
  103.             WHVAL distance;
  104.  
  105.             if (tagID & gob_orient)
  106.             {
  107.                distance = ((tagID & gob_reledge)?
  108.                      ((tagID & gob_relative)?relative->bottom():relative->iBottom())
  109.                      :
  110.                      ((tagID & gob_relative)?relative->top():relative->iTop())
  111.                      ) + (WHVAL)GOB_Absolute(iHeight(),data);
  112.                if (tagID & gob_edge)
  113.                   maxy = distance;
  114.                else
  115.                   miny = distance;
  116.             }
  117.             else
  118.             {
  119.                distance = ((tagID & gob_reledge) ?
  120.                   ((tagID & gob_relative)?relative->right():relative->iRight())
  121.                   :
  122.                   ((tagID & gob_relative)?relative->left():relative->iLeft())
  123.                   ) + (WHVAL)GOB_Absolute(iWidth(),data);
  124.                if (tagID & gob_edge)
  125.                   maxx = distance;
  126.                else
  127.                   minx = distance;
  128.             }
  129.          }
  130.          else switch(next.tag())       // other GraphicObject tags
  131.          {
  132.  
  133.             default: break;
  134.          }
  135.       }
  136.  
  137.       // if there were not sufficient GOB_Tags declared to fully specify the rectangle
  138.       // missing values are deduced from the former width/height plus the specified corner
  139.       if (oldWidth != 0)
  140.       {
  141.          if (maxx==0) maxx = minx + oldWidth;
  142.          if (minx==0) minx = maxx - oldWidth;
  143.       }
  144.       if (oldHeight != 0)
  145.       {
  146.          if (maxy==0) maxy = miny + oldHeight;
  147.          if (miny==0) miny = maxy - oldHeight;
  148.       }
  149.  
  150.       node->setRect(minx,miny,maxx,maxy);
  151.  
  152.       pred = node;
  153.       _dprintf("adjustChild to: (%ld/%ld,%ld/%ld,%ld/%ld,%ld/%ld)\n",node->left(),node->iLeft(),node->top(),node->iTop(),node->right(),node->iRight(),node->bottom(),node->iBottom());
  154.       node->adjustChilds();
  155.    } /* if */
  156.    } /* FOREACHOF */
  157. }
  158.